diff options
author | Colm Donelan <Colm.Donelan@arm.com> | 2020-06-09 16:56:25 +0100 |
---|---|---|
committer | Colm Donelan <Colm.Donelan@arm.com> | 2020-06-09 16:56:46 +0100 |
commit | 6350d27286114dfdae5f65ae1823ba1150087efb (patch) | |
tree | b2941db6a0d1cfff1bdb9005e1a7b1c1c3149844 /src/armnnTfLiteParser/test/TfLiteParser.cpp | |
parent | b22a75e2aaec1175bbacba54e1a33a83f9749ce2 (diff) | |
download | armnn-6350d27286114dfdae5f65ae1823ba1150087efb.tar.gz |
IVGCVSW-4968 Fix exception handling in TfLiteParser.
* The function TfLiteParser::CreateNetworkFromModel was continuing
to parse the input file even after a fatal exception was encountered.
restructure catch exceptions outside the for loop.
* Add simple unit tests to test some exception handling.
Signed-off-by: Colm Donelan <Colm.Donelan@arm.com>
Change-Id: I202ca6819d40a47159b4ac8f2847958f945666c2
Diffstat (limited to 'src/armnnTfLiteParser/test/TfLiteParser.cpp')
-rw-r--r-- | src/armnnTfLiteParser/test/TfLiteParser.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/armnnTfLiteParser/test/TfLiteParser.cpp b/src/armnnTfLiteParser/test/TfLiteParser.cpp new file mode 100644 index 0000000000..36827c0586 --- /dev/null +++ b/src/armnnTfLiteParser/test/TfLiteParser.cpp @@ -0,0 +1,41 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <boost/test/unit_test.hpp> +#include "ParserFlatbuffersFixture.hpp" +#include "../TfLiteParser.hpp" + +BOOST_AUTO_TEST_SUITE(TensorflowLiteParser) + +BOOST_AUTO_TEST_CASE(ParseEmptyBinaryData) +{ + ITfLiteParser::TfLiteParserOptions options; + ITfLiteParserPtr m_Parser(ITfLiteParser::Create(armnn::Optional<ITfLiteParser::TfLiteParserOptions>(options))); + // Should throw armnn::ParseException: Buffer doesn't conform to the expected Tensorflow Lite flatbuffers format. + BOOST_CHECK_THROW(m_Parser->CreateNetworkFromBinary({0}), armnn::ParseException); +} + +struct NoInputBindingsFixture : public ParserFlatbuffersFixture +{ + explicit NoInputBindingsFixture() + { + m_JsonString = R"( + { + "version": 3, + "operator_codes": [ { "builtin_code": "CONV_2D" } ], + "subgraphs": [ { } ] + } + )"; + SetupSingleInputSingleOutput("inputTensor", "outputTensor"); + } +}; + +BOOST_FIXTURE_TEST_CASE( ParseBadInputBindings, NoInputBindingsFixture ) +{ + // Should throw armnn::ParseException: No input binding found for subgraph:0 and name:inputTensor. + BOOST_CHECK_THROW( (RunTest<4, armnn::DataType::QAsymmU8>(0, { }, { 0 })), armnn::ParseException); +} + +BOOST_AUTO_TEST_SUITE_END() |