From f30d7413b2ba6625dc0f86ca540694a2a349dd54 Mon Sep 17 00:00:00 2001 From: Liam Barry Date: Wed, 27 Sep 2023 12:48:35 +0100 Subject: MLECO-4365: Add CI Test for insufficient tensor arena and update common tests. Previously, execution path following failed tensor allocation was not covered by tests. Minor amendment added to make ~Model virtual. During testing it was noticed that intentional errors simulated in certain common tests would result in misleading output for subsequent tests as the error messages appear in the console output of the next failing test. Documentation and print statements added until a solution is found. Change-Id: Iaf3e0f32ce9e0505921251cd41f73030108d2cb1 Signed-off-by: Liam Barry --- source/application/api/common/include/Model.hpp | 2 +- source/application/api/common/source/Model.cc | 2 - tests/common/ClassifierTests.cc | 7 ++- tests/common/ProfilerTests.cc | 11 ++++- .../inference_runner/InferenceRunnerTests.cc | 18 ++++++++ .../InferenceTestInferenceRunner.cc | 50 ++++++++++++++++++++++ 6 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 tests/use_case/inference_runner/InferenceRunnerTests.cc create mode 100644 tests/use_case/inference_runner/InferenceTestInferenceRunner.cc diff --git a/source/application/api/common/include/Model.hpp b/source/application/api/common/include/Model.hpp index 1728e1f..6eefd02 100644 --- a/source/application/api/common/include/Model.hpp +++ b/source/application/api/common/include/Model.hpp @@ -33,7 +33,7 @@ namespace app { Model(); /** @brief Destructor. */ - ~Model(); + virtual ~Model() = default; /** @brief Gets the pointer to the model's input tensor at given input index. */ TfLiteTensor* GetInputTensor(size_t index) const; diff --git a/source/application/api/common/source/Model.cc b/source/application/api/common/source/Model.cc index b344a53..3675c5b 100644 --- a/source/application/api/common/source/Model.cc +++ b/source/application/api/common/source/Model.cc @@ -20,8 +20,6 @@ #include #include -arm::app::Model::~Model() = default; - arm::app::Model::Model() : m_inited(false), m_type(kTfLiteNoType) {} /* Initialise the model */ diff --git a/tests/common/ClassifierTests.cc b/tests/common/ClassifierTests.cc index 0abaa15..7df4242 100644 --- a/tests/common/ClassifierTests.cc +++ b/tests/common/ClassifierTests.cc @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates + * SPDX-FileCopyrightText: Copyright 2021, 2023 Arm Limited and/or its affiliates * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -47,10 +47,15 @@ TEST_CASE("Common classifier") { SECTION("Test invalid classifier") { + /* Note: Errors or warnings generated by this test will appear in output of any subsequent + * failing tests causing misleading output. Give warning until solution is found */ + printf("Invalid classifier common test output:\n"); TfLiteTensor* outputTens = nullptr; std::vector resultVec; arm::app::Classifier classifier; REQUIRE(!classifier.GetClassificationResults(outputTens, resultVec, {}, 5, true)); + printf("End of invalid classifier common test output. \nERROR messages above this line are " + "expected and can be ignored.\n\n"); } SECTION("Test classification results") diff --git a/tests/common/ProfilerTests.cc b/tests/common/ProfilerTests.cc index 62c7347..0b487e5 100644 --- a/tests/common/ProfilerTests.cc +++ b/tests/common/ProfilerTests.cc @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates + * SPDX-FileCopyrightText: Copyright 2021, 2023 Arm Limited and/or its affiliates * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,10 +41,17 @@ TEST_CASE("Common: Test Profiler") profilerValid.GetAllResultsAndReset(results); REQUIRE(results.size() == 1); REQUIRE(results[0].name == "test_valid"); - /* Abuse should still fail: */ + + /* Improper usage should cause failure. + * Note: Errors or warnings generated by this test will appear in output of any subsequent + * failing tests causing misleading output. Give warning until solution is found */ + printf("Invalid profiler usage common test output:\n"); REQUIRE(false == profilerValid.StopProfiling()); /* We need to start it first */ + REQUIRE(true == profilerValid.StartProfiling()); /* Should be able to start it fine */ REQUIRE(false == profilerValid.StartProfiling()); /* Can't restart it without resetting */ + printf("End of Invalid profiler usage common test output. \nERROR messages above this line " + "are expected and can be ignored.\n\n"); profilerValid.Reset(); REQUIRE(true == profilerValid.StartProfiling()); /* Can start it again now.. */ REQUIRE(true == profilerValid.StopProfiling()); diff --git a/tests/use_case/inference_runner/InferenceRunnerTests.cc b/tests/use_case/inference_runner/InferenceRunnerTests.cc new file mode 100644 index 0000000..400bd9c --- /dev/null +++ b/tests/use_case/inference_runner/InferenceRunnerTests.cc @@ -0,0 +1,18 @@ +/* + * SPDX-FileCopyrightText: Copyright 2023 Arm Limited and/or its affiliates + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define CATCH_CONFIG_MAIN +#include diff --git a/tests/use_case/inference_runner/InferenceTestInferenceRunner.cc b/tests/use_case/inference_runner/InferenceTestInferenceRunner.cc new file mode 100644 index 0000000..7988ae1 --- /dev/null +++ b/tests/use_case/inference_runner/InferenceTestInferenceRunner.cc @@ -0,0 +1,50 @@ +/* + * SPDX-FileCopyrightText: Copyright 2023 Arm Limited and/or its affiliates + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "BufAttributes.hpp" +#include "TensorFlowLiteMicro.hpp" +#include "TestModel.hpp" /* Model class for running inference. */ + +#include +#include + +namespace arm { +namespace app { + static uint8_t tensorArena[ACTIVATION_BUF_SZ] ACTIVATION_BUF_ATTRIBUTE; + namespace inference_runner { + extern uint8_t* GetModelPointer(); + extern size_t GetModelLen(); + } /* namespace inference_runner */ +} /* namespace app */ +} /* namespace arm */ + +TEST_CASE("Testing Init failure due to insufficient tensor arena inf runner", "[inf runner]") +{ + /* Note: Errors or warnings generated by this test will appear in output of any subsequent + * failing tests causing misleading output. Give warning until solution is found */ + printf("Insufficient tensor arena test output:\n"); + arm::app::TestModel model{}; + REQUIRE_FALSE(model.IsInited()); + size_t insufficientTensorArenaSz = 1000; + REQUIRE_FALSE(model.Init(arm::app::tensorArena, + insufficientTensorArenaSz, + arm::app::inference_runner::GetModelPointer(), + arm::app::inference_runner::GetModelLen())); + + printf("End of insufficient tensor arena test output. \nERROR messages above this line are " + "expected and can be ignored.\n\n"); + REQUIRE_FALSE(model.IsInited()); +} -- cgit v1.2.1