telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 6 | #include "armnnOnnxParser/IOnnxParser.hpp" |
| 7 | #include "ParserPrototxtFixture.hpp" |
| 8 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 9 | TEST_SUITE("OnnxParser_Const") |
| 10 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 11 | struct ConstMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser> |
| 12 | { |
| 13 | 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 | } |
Matteo Martincigh | 44a7167 | 2018-12-11 13:46:52 +0000 | [diff] [blame] | 39 | type: 1 |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 40 | } |
| 41 | name: "constantNode" |
| 42 | op_type: "Constant" |
| 43 | } |
| 44 | output { |
| 45 | name: "Output" |
| 46 | type { |
| 47 | tensor_type { |
Matteo Martincigh | 44a7167 | 2018-12-11 13:46:52 +0000 | [diff] [blame] | 48 | elem_type: 1 |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 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 | { |
Matteo Martincigh | 44a7167 | 2018-12-11 13:46:52 +0000 | [diff] [blame] | 66 | ConstValidFixture() : ConstMainFixture("1") { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 67 | Setup(); |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | struct ConstInvalidFixture : ConstMainFixture |
| 72 | { |
Matteo Martincigh | 44a7167 | 2018-12-11 13:46:52 +0000 | [diff] [blame] | 73 | ConstInvalidFixture() : ConstMainFixture("10") { } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 74 | }; |
| 75 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 76 | TEST_CASE_FIXTURE(ConstValidFixture, "ValidConstTest") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 77 | { |
| 78 | RunTest<1>({ }, {{ "Output" , {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0}}}); |
| 79 | } |
| 80 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 81 | TEST_CASE_FIXTURE(ConstInvalidFixture, "IncorrectDataTypeConst") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 82 | { |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 83 | CHECK_THROWS_AS( Setup(), armnn::ParseException); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 86 | } |