aboutsummaryrefslogtreecommitdiff
path: root/src/armnnTfLiteParser/test/TfLiteParser.cpp
blob: 841c46e620a9c111ecc05f5ab1b252d80ce69549 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "ParserFlatbuffersFixture.hpp"
#include <doctest/doctest.h>

TEST_SUITE("TensorflowLiteParser")
{
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.
    CHECK_THROWS_AS(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");
    }
};

TEST_CASE_FIXTURE(NoInputBindingsFixture, "ParseBadInputBindings")
{
    // Should throw armnn::ParseException: No input binding found for subgraph:0 and name:inputTensor.
    CHECK_THROWS_AS((RunTest<4, armnn::DataType::QAsymmU8>(0, { }, { 0 })), armnn::ParseException);
}

TEST_CASE("ParseInvalidFileName")
{
    // Nullptr should throw InvalidArgumentException
    CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile(nullptr), armnn::InvalidArgumentException);
    // Empty string should throw FileNotFoundException.
    CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile(""), armnn::FileNotFoundException);
    // Garbage string should throw FileNotFoundException.
    CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile("askjfhseuirwqeuiy"),
                    armnn::FileNotFoundException);
    // Valid directory should throw InvalidArgumentException
    CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile("."), armnn::InvalidArgumentException);
    // Valid file but not a regular file should throw InvalidArgumentException
    CHECK_THROWS_AS(armnnTfLiteParser::TfLiteParserImpl::LoadModelFromFile("/dev/null"),
                    armnn::InvalidArgumentException);
}

}