diff options
author | Colm Donelan <colm.donelan@arm.com> | 2023-06-22 10:19:17 +0100 |
---|---|---|
committer | Colm Donelan <colm.donelan@arm.com> | 2023-06-30 14:20:56 +0100 |
commit | 0dfb2658ce521571aa0f9e859f813c60fda9d8d6 (patch) | |
tree | ef4605cebb29c6754da8dfea0decd4250288e2a5 /tests/ExecuteNetwork/test/FileComparisonExecutorTests.cpp | |
parent | 16e27cf81424dcad05d129f9ba368a8c446cd25f (diff) | |
download | armnn-0dfb2658ce521571aa0f9e859f813c60fda9d8d6.tar.gz |
IVGCVSW-7666 Add a FileComparisonExecutor to ExecuteNetwork.
* Implement the "-C" command line option of executenetwork.
* Add a FileComparisonExecutorFile which will read tensors from
a previously written text file and compare them to the execution
output.
Signed-off-by: Colm Donelan <colm.donelan@arm.com>
Change-Id: I8380fd263028af13d65a67fb6afd89626d1b07b8
Diffstat (limited to 'tests/ExecuteNetwork/test/FileComparisonExecutorTests.cpp')
-rw-r--r-- | tests/ExecuteNetwork/test/FileComparisonExecutorTests.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/ExecuteNetwork/test/FileComparisonExecutorTests.cpp b/tests/ExecuteNetwork/test/FileComparisonExecutorTests.cpp new file mode 100644 index 0000000000..c8a7171107 --- /dev/null +++ b/tests/ExecuteNetwork/test/FileComparisonExecutorTests.cpp @@ -0,0 +1,74 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <ExecuteNetwork/FileComparisonExecutor.hpp> +#include <doctest/doctest.h> +#include <filesystem> +#include <fstream> +namespace +{ + +namespace fs = std::filesystem; + +TEST_SUITE("FileComparisonExecutorTests") +{ + + TEST_CASE("EmptyComparisonThrowsException") + { + ExecuteNetworkParams params; + FileComparisonExecutor classToTest(params); + // The comparison file is not set in the parameters. This should throw an exception. + CHECK_THROWS_AS(classToTest.Execute(), armnn::InvalidArgumentException); + } + + TEST_CASE("InvalidComparisonFilesThrowsException") + { + ExecuteNetworkParams params; + params.m_ComparisonFile = "Balh,Blah,Blah"; + FileComparisonExecutor classToTest(params); + // None of the files in the parameter exist. + CHECK_THROWS_AS(classToTest.Execute(), armnn::FileNotFoundException); + } + + TEST_CASE("ComparisonFileIsEmpty") + { + std::filesystem::path fileName = fs::temp_directory_path().append("ComparisonFileIsEmpty.tmp"); + std::fstream tmpFile; + tmpFile.open(fileName, std::ios::out); + ExecuteNetworkParams params; + params.m_ComparisonFile = fileName; + FileComparisonExecutor classToTest(params); + // The comparison file is empty. This exception should happen in ExtractHeader when it realises it + // can't read a header. + CHECK_THROWS_AS(classToTest.Execute(), armnn::ParseException); + tmpFile.close(); + std::filesystem::remove(fileName); + } + + TEST_CASE("ComparisonFileHasValidHeaderAndData") + { + std::filesystem::path fileName = fs::temp_directory_path().append("ComparisonFileHasValidHeaderAndData.tmp"); + std::fstream tmpFile; + tmpFile.open(fileName, std::ios::out); + // Write a valid header. + tmpFile << "TensorName, Float32 : 1.1000"; + tmpFile.close(); + ExecuteNetworkParams params; + params.m_ComparisonFile = fileName; + FileComparisonExecutor classToTest(params); + // The read in tensor should consist of 1 float. + std::vector<const void*> results = classToTest.Execute(); + std::filesystem::remove(fileName); + // Should be one tensor in the data. + CHECK_EQ(1, results.size()); + // We expect there to be 1 element of value 1.1f. + const float* floatPtr = static_cast<const float*>(results[0]); + CHECK_EQ(*floatPtr, 1.1f); + } + + +} // End of TEST_SUITE("FileComparisonExecutorTests") + +} // anonymous namespace
\ No newline at end of file |