blob: 35df4e91e0e3765ec661aa3aa98cb23bf00f779a [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5
telsoa01c577f2c2018-08-31 09:22:23 +01006#include "armnnOnnxParser/IOnnxParser.hpp"
7#include "ParserPrototxtFixture.hpp"
8
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("OnnxParser_Const")
10{
telsoa01c577f2c2018-08-31 09:22:23 +010011struct 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 Martincigh44a71672018-12-11 13:46:52 +000039 type: 1
telsoa01c577f2c2018-08-31 09:22:23 +010040 }
41 name: "constantNode"
42 op_type: "Constant"
43 }
44 output {
45 name: "Output"
46 type {
47 tensor_type {
Matteo Martincigh44a71672018-12-11 13:46:52 +000048 elem_type: 1
telsoa01c577f2c2018-08-31 09:22:23 +010049 shape {
50 dim {
51 dim_value: 7
52 }
53 }
54 }
55 }
56 }
57 }
58 opset_import {
59 version: 7
60 })";
61 }
62};
63
64struct ConstValidFixture : ConstMainFixture
65{
Matteo Martincigh44a71672018-12-11 13:46:52 +000066 ConstValidFixture() : ConstMainFixture("1") {
telsoa01c577f2c2018-08-31 09:22:23 +010067 Setup();
68 }
69};
70
71struct ConstInvalidFixture : ConstMainFixture
72{
Matteo Martincigh44a71672018-12-11 13:46:52 +000073 ConstInvalidFixture() : ConstMainFixture("10") { }
telsoa01c577f2c2018-08-31 09:22:23 +010074};
75
Sadik Armagan1625efc2021-06-10 18:24:34 +010076TEST_CASE_FIXTURE(ConstValidFixture, "ValidConstTest")
telsoa01c577f2c2018-08-31 09:22:23 +010077{
78 RunTest<1>({ }, {{ "Output" , {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0}}});
79}
80
Sadik Armagan1625efc2021-06-10 18:24:34 +010081TEST_CASE_FIXTURE(ConstInvalidFixture, "IncorrectDataTypeConst")
telsoa01c577f2c2018-08-31 09:22:23 +010082{
Sadik Armagan1625efc2021-06-10 18:24:34 +010083 CHECK_THROWS_AS( Setup(), armnn::ParseException);
telsoa01c577f2c2018-08-31 09:22:23 +010084}
85
Sadik Armagan1625efc2021-06-10 18:24:34 +010086}