blob: 841c46e620a9c111ecc05f5ab1b252d80ce69549 [file] [log] [blame]
Colm Donelan6350d272020-06-09 16:56:25 +01001//
Colm Donelan0dfb2652023-06-22 10:19:17 +01002// Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved.
Colm Donelan6350d272020-06-09 16:56:25 +01003// SPDX-License-Identifier: MIT
4//
5
Colm Donelan6350d272020-06-09 16:56:25 +01006#include "ParserFlatbuffersFixture.hpp"
Sadik Armagan1625efc2021-06-10 18:24:34 +01007#include <doctest/doctest.h>
Colm Donelan6350d272020-06-09 16:56:25 +01008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser")
10{
11TEST_CASE("ParseEmptyBinaryData")
Colm Donelan6350d272020-06-09 16:56:25 +010012{
13 ITfLiteParser::TfLiteParserOptions options;
14 ITfLiteParserPtr m_Parser(ITfLiteParser::Create(armnn::Optional<ITfLiteParser::TfLiteParserOptions>(options)));
15 // Should throw armnn::ParseException: Buffer doesn't conform to the expected Tensorflow Lite flatbuffers format.
Sadik Armagan1625efc2021-06-10 18:24:34 +010016 CHECK_THROWS_AS(m_Parser->CreateNetworkFromBinary({0}), armnn::ParseException);
Colm Donelan6350d272020-06-09 16:56:25 +010017}
18
19struct NoInputBindingsFixture : public ParserFlatbuffersFixture
20{
21 explicit NoInputBindingsFixture()
22 {
23 m_JsonString = R"(
24 {
25 "version": 3,
26 "operator_codes": [ { "builtin_code": "CONV_2D" } ],
27 "subgraphs": [ { } ]
28 }
29 )";
30 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
31 }
32};
33
Sadik Armagan1625efc2021-06-10 18:24:34 +010034TEST_CASE_FIXTURE(NoInputBindingsFixture, "ParseBadInputBindings")
Colm Donelan6350d272020-06-09 16:56:25 +010035{
36 // Should throw armnn::ParseException: No input binding found for subgraph:0 and name:inputTensor.
Sadik Armagan1625efc2021-06-10 18:24:34 +010037 CHECK_THROWS_AS((RunTest<4, armnn::DataType::QAsymmU8>(0, { }, { 0 })), armnn::ParseException);
Colm Donelan6350d272020-06-09 16:56:25 +010038}
39
Colm Donelan0dfb2652023-06-22 10:19:17 +010040TEST_CASE("ParseInvalidFileName")
41{
42 // Nullptr should throw InvalidArgumentException
43 CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile(nullptr), armnn::InvalidArgumentException);
44 // Empty string should throw FileNotFoundException.
45 CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile(""), armnn::FileNotFoundException);
46 // Garbage string should throw FileNotFoundException.
47 CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile("askjfhseuirwqeuiy"),
48 armnn::FileNotFoundException);
49 // Valid directory should throw InvalidArgumentException
50 CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile("."), armnn::InvalidArgumentException);
51 // Valid file but not a regular file should throw InvalidArgumentException
52 CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile("/dev/null"),
53 armnn::InvalidArgumentException);
54}
55
Sadik Armagan1625efc2021-06-10 18:24:34 +010056}