1 // 2 // Copyright © 2017 Arm Ltd. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #include "armnnOnnxParser/IOnnxParser.hpp" 7 #include "ParserPrototxtFixture.hpp" 8 9 TEST_SUITE("OnnxParser_Const") 10 { 11 struct ConstMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser> 12 { ConstMainFixtureConstMainFixture13 ConstMainFixture(const std::string& dataType) 14 { 15 m_Prototext = R"( 16 ir_version: 3 17 producer_name: "CNTK " 18 producer_version: "2.5.1 " 19 domain: "ai.cntk " 20 model_version: 1 21 graph { 22 name: "CNTKGraph " 23 node { 24 output: "Output" 25 attribute { 26 name: "value" 27 t { 28 dims: 7 29 data_type: )" + dataType + R"( 30 float_data: 0.0 31 float_data: 1.0 32 float_data: 2.0 33 float_data: 3.0 34 float_data: 4.0 35 float_data: 5.0 36 float_data: 6.0 37 38 } 39 type: 1 40 } 41 name: "constantNode" 42 op_type: "Constant" 43 } 44 output { 45 name: "Output" 46 type { 47 tensor_type { 48 elem_type: 1 49 shape { 50 dim { 51 dim_value: 7 52 } 53 } 54 } 55 } 56 } 57 } 58 opset_import { 59 version: 7 60 })"; 61 } 62 }; 63 64 struct ConstValidFixture : ConstMainFixture 65 { ConstValidFixtureConstValidFixture66 ConstValidFixture() : ConstMainFixture("1") { 67 Setup(); 68 } 69 }; 70 71 struct ConstInvalidFixture : ConstMainFixture 72 { ConstInvalidFixtureConstInvalidFixture73 ConstInvalidFixture() : ConstMainFixture("10") { } 74 }; 75 76 TEST_CASE_FIXTURE(ConstValidFixture, "ValidConstTest") 77 { 78 RunTest<1>({ }, {{ "Output" , {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0}}}); 79 } 80 81 TEST_CASE_FIXTURE(ConstInvalidFixture, "IncorrectDataTypeConst") 82 { 83 CHECK_THROWS_AS( Setup(), armnn::ParseException); 84 } 85 86 } 87