blob: eeeaca85dcd9d23322aa245e629a7ad353608e4f [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"
Sadik Armagan1625efc2021-06-10 18:24:34 +01007#include <doctest/doctest.h>
8
telsoa01c577f2c2018-08-31 09:22:23 +01009#include "google/protobuf/stubs/logging.h"
10
Sadik Armagan1625efc2021-06-10 18:24:34 +010011TEST_SUITE("OnnxParser_CreateNetwork")
12{
13TEST_CASE("CreateNetworkFromString")
telsoa01c577f2c2018-08-31 09:22:23 +010014{
15 std::string TestModel = 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 output {
24 name: "Output"
25 type {
26 tensor_type {
Matteo Martincigh44a71672018-12-11 13:46:52 +000027 elem_type: 1
telsoa01c577f2c2018-08-31 09:22:23 +010028 shape {
29 dim {
30 dim_value: 1
31 }
32 dim {
33 dim_value: 10
34 }
35 }
36 }
37 }
38 }
39 }
40 opset_import {
41 version: 7
42 })";
43
44 armnnOnnxParser::IOnnxParserPtr parser(armnnOnnxParser::IOnnxParser::Create());
45
46 armnn::INetworkPtr network = parser->CreateNetworkFromString(TestModel.c_str());
Sadik Armagan1625efc2021-06-10 18:24:34 +010047 CHECK(network.get());
telsoa01c577f2c2018-08-31 09:22:23 +010048}
49
Sadik Armagan1625efc2021-06-10 18:24:34 +010050TEST_CASE("CreateNetworkFromStringWithNullptr")
telsoa01c577f2c2018-08-31 09:22:23 +010051{
52 armnnOnnxParser::IOnnxParserPtr parser(armnnOnnxParser::IOnnxParser::Create());
Sadik Armagan1625efc2021-06-10 18:24:34 +010053 CHECK_THROWS_AS(parser->CreateNetworkFromString(""), armnn::InvalidArgumentException );
telsoa01c577f2c2018-08-31 09:22:23 +010054}
55
Sadik Armagan1625efc2021-06-10 18:24:34 +010056TEST_CASE("CreateNetworkWithInvalidString")
telsoa01c577f2c2018-08-31 09:22:23 +010057{
58 auto silencer = google::protobuf::LogSilencer(); //get rid of errors from protobuf
59 armnnOnnxParser::IOnnxParserPtr parser(armnnOnnxParser::IOnnxParser::Create());
Sadik Armagan1625efc2021-06-10 18:24:34 +010060 CHECK_THROWS_AS(parser->CreateNetworkFromString( "I'm not a model so I should raise an error" ),
telsoa01c577f2c2018-08-31 09:22:23 +010061 armnn::ParseException );
62}
63
Sadik Armagan1625efc2021-06-10 18:24:34 +010064}