2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
6 #include <boost/test/unit_test.hpp>
7 #include "armnnTfParser/ITfParser.hpp"
8 #include "ParserPrototxtFixture.hpp"
10 BOOST_AUTO_TEST_SUITE(TensorflowParser)
12 // Graph which tests that nodes are re-ordered in the queue when they are encountered a second time.
13 // In this case R0 will be encountered first via R1 and then via R2. At that time
14 // we need to make sure that R0 (and the I on which it is dependent) is moved to the front again
15 // so that it is before both R1 and R2.
25 struct RediscoveredDependenciesFixture : public ParserPrototxtFixture<armnnTfParser::ITfParser>
27 RediscoveredDependenciesFixture()
29 // input = tf.placeholder(tf.float32, 1, "input")
30 // relu0 = tf.nn.relu(input, "relu0")
31 // relu1 = tf.nn.relu(relu0, "relu1")
32 // relu2 = tf.nn.relu(relu0, "relu2")
33 // relu3 = tf.nn.relu(relu2, "relu3")
34 // output = tf.add(relu1, relu3, "output")
113 SetupSingleInputSingleOutput({ 1 }, "input", "output");
117 BOOST_FIXTURE_TEST_CASE(RediscoveredDependencies, RediscoveredDependenciesFixture)
119 RunTest<1>({1}, {2});
122 // Tests that a simple cycle in the tensorflow graph will be detected and an exception thrown, rather than the TfParser
123 // getting stuck in an infinite loop.
124 BOOST_AUTO_TEST_CASE(SimpleCycle)
126 const char* prototext = R"(
150 armnnTfParser::ITfParserPtr parser = armnnTfParser::ITfParser::Create();
151 BOOST_CHECK_THROW(parser->CreateNetworkFromString(prototext, {}, { "r2" }), armnn::ParseException);
154 // Similar to the above SimpleCycle test, but has a single node which connects to itself.
155 BOOST_AUTO_TEST_CASE(SingleNodeCycle)
157 const char* prototext = R"(
170 armnnTfParser::ITfParserPtr parser = armnnTfParser::ITfParser::Create();
171 BOOST_CHECK_THROW(parser->CreateNetworkFromString(prototext, {}, { "r1" }), armnn::ParseException);
174 // Similar to the above SimpleCycle test, but with a more complicated graph.
185 BOOST_AUTO_TEST_CASE(ComplexCycle)
187 // input = tf.placeholder(tf.float32, 1, "input")
188 // add2 = tf.nn.relu(input, add1, "add2") // This line won't actually run in TF, because add1 is not yet defined
189 // relu1 = tf.nn.relu(relu0, "relu1")
190 // relu2 = tf.nn.relu(relu0, "relu2")
191 // relu3 = tf.nn.relu(relu2, "relu3")
192 // add1 = tf.add(relu1, relu3, "add1")
193 const char* prototext = R"(
272 armnnTfParser::ITfParserPtr parser = armnnTfParser::ITfParser::Create();
273 BOOST_CHECK_THROW(parser->CreateNetworkFromString(prototext, {}, { "add1" }), armnn::ParseException);
276 // Tests that a graph with an input that is not present throws a ParseException.
277 BOOST_AUTO_TEST_CASE(InvalidInput)
279 const char* prototext = R"(
283 input: "a-node-that-does-not-exist"
292 armnnTfParser::ITfParserPtr parser = armnnTfParser::ITfParser::Create();
293 BOOST_CHECK_THROW(parser->CreateNetworkFromString(prototext, {}, { "r1" }), armnn::ParseException);
296 BOOST_AUTO_TEST_SUITE_END()