diff options
author | Colm Donelan <Colm.Donelan@arm.com> | 2021-05-17 13:01:52 +0100 |
---|---|---|
committer | Colm Donelan <Colm.Donelan@arm.com> | 2021-05-18 11:25:13 +0100 |
commit | 25ab3a8326a9e2c52c84b2747fa72907109a695d (patch) | |
tree | 1d4eaaf5b41c68a4e3b3ce2cc400c3ffd76d510c /src/armnn | |
parent | 1d239f5717e6e4adc47683e30a48b05e7511c734 (diff) | |
download | armnn-25ab3a8326a9e2c52c84b2747fa72907109a695d.tar.gz |
IVGCVSW-5964 Removing some remaining boost utility usages from tests.
* Adding a basic PredicateResult class to replace
boost::test_tools::predicate_result
* Replacing all uses of boost::test_tools::predicate_result with
the new armnn::PredicateResult class
* Replacing use of boost::test_tools::output_test_stream output
with std::ostringstream in ProfilerTests.cpp
Signed-off-by: Colm Donelan <Colm.Donelan@arm.com>
Change-Id: I75cdbbff98d984e26e4a50c125386b2988516fad
Diffstat (limited to 'src/armnn')
-rw-r--r-- | src/armnn/test/PredicateResult.hpp | 48 | ||||
-rw-r--r-- | src/armnn/test/ProfilerTests.cpp | 5 | ||||
-rw-r--r-- | src/armnn/test/TensorHelpers.hpp | 15 | ||||
-rw-r--r-- | src/armnn/test/UnitTests.hpp | 6 |
4 files changed, 62 insertions, 12 deletions
diff --git a/src/armnn/test/PredicateResult.hpp b/src/armnn/test/PredicateResult.hpp new file mode 100644 index 0000000000..a344c8e3ad --- /dev/null +++ b/src/armnn/test/PredicateResult.hpp @@ -0,0 +1,48 @@ +// +// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include <sstream> + +namespace armnn +{ + +class PredicateResult +{ +public: + explicit PredicateResult(bool result) + : m_Result(result) + {} + + PredicateResult(const PredicateResult& predicateResult) + : m_Result(predicateResult.m_Result) + , m_Message(predicateResult.m_Message.str()) + {} + + void SetResult(bool newResult) + { + m_Result = newResult; + } + + std::stringstream& Message() + { + return m_Message; + } + + bool operator!() const + { + return !m_Result; + } + + void operator=(PredicateResult otherPredicateResult) + { + otherPredicateResult.m_Result = m_Result; + } + + bool m_Result; + std::stringstream m_Message; +}; + +} // namespace armnn
\ No newline at end of file diff --git a/src/armnn/test/ProfilerTests.cpp b/src/armnn/test/ProfilerTests.cpp index a0df3b6b62..21900ffb9a 100644 --- a/src/armnn/test/ProfilerTests.cpp +++ b/src/armnn/test/ProfilerTests.cpp @@ -8,7 +8,6 @@ #include <armnn/utility/IgnoreUnused.hpp> #include <boost/test/unit_test.hpp> -#include <boost/test/tools/output_test_stream.hpp> #include <memory> #include <thread> @@ -225,9 +224,9 @@ BOOST_AUTO_TEST_CASE(WriteEventResults) size_t eventSequenceSizeAfter = armnn::GetProfilerEventSequenceSize(profiler.get()); BOOST_TEST(eventSequenceSizeAfter == eventSequenceSizeBefore + 1); - boost::test_tools::output_test_stream output; + std::ostringstream output; profiler->AnalyzeEventsAndWriteResults(output); - BOOST_TEST(!output.is_empty(false)); + BOOST_TEST(!output.str().empty()); // output should contain event name 'test' BOOST_CHECK(output.str().find("test") != std::string::npos); diff --git a/src/armnn/test/TensorHelpers.hpp b/src/armnn/test/TensorHelpers.hpp index fd9dd83770..ceb6d0f9d7 100644 --- a/src/armnn/test/TensorHelpers.hpp +++ b/src/armnn/test/TensorHelpers.hpp @@ -4,6 +4,7 @@ // #pragma once +#include "PredicateResult.hpp" #include <armnn/Tensor.hpp> #include <armnn/utility/Assert.hpp> #include <armnnUtils/FloatingPointComparison.hpp> @@ -70,7 +71,7 @@ bool SelectiveCompareBoolean(T a, T b) }; template <typename T, std::size_t n> -boost::test_tools::predicate_result CompareTensors(const boost::multi_array<T, n>& a, +armnn::PredicateResult CompareTensors(const boost::multi_array<T, n>& a, const boost::multi_array<T, n>& b, bool compareBoolean = false, bool isDynamic = false) @@ -84,8 +85,8 @@ boost::test_tools::predicate_result CompareTensors(const boost::multi_array<T, n { if (a.shape()[i] != b.shape()[i]) { - boost::test_tools::predicate_result res(false); - res.message() << "Different shapes [" + armnn::PredicateResult res(false); + res.Message() << "Different shapes [" << a.shape()[i] << "!=" << b.shape()[i] @@ -162,16 +163,16 @@ boost::test_tools::predicate_result CompareTensors(const boost::multi_array<T, n } } - boost::test_tools::predicate_result comparisonResult(true); + armnn::PredicateResult comparisonResult(true); if (numFailedElements > 0) { - comparisonResult = false; - comparisonResult.message() << numFailedElements << " different values at: "; + comparisonResult.SetResult(false); + comparisonResult.Message() << numFailedElements << " different values at: "; if (numFailedElements > maxReportedDifferences) { errorString << ", ... (and " << (numFailedElements - maxReportedDifferences) << " other differences)"; } - comparisonResult.message() << errorString.str(); + comparisonResult.Message() << errorString.str(); } return comparisonResult; diff --git a/src/armnn/test/UnitTests.hpp b/src/armnn/test/UnitTests.hpp index c15477bf19..b55b13d4c8 100644 --- a/src/armnn/test/UnitTests.hpp +++ b/src/armnn/test/UnitTests.hpp @@ -42,7 +42,8 @@ void CompareTestResultIfSupported(const std::string& testName, const LayerTestRe "The test name does not match the supportedness it is reporting"); if (testResult.supported) { - BOOST_TEST(CompareTensors(testResult.output, testResult.outputExpected, testResult.compareBoolean)); + auto result = CompareTensors(testResult.output, testResult.outputExpected, testResult.compareBoolean); + BOOST_TEST(result.m_Result, result.m_Message.str()); } } @@ -56,7 +57,8 @@ void CompareTestResultIfSupported(const std::string& testName, const std::vector "The test name does not match the supportedness it is reporting"); if (testResult[i].supported) { - BOOST_TEST(CompareTensors(testResult[i].output, testResult[i].outputExpected)); + auto result = CompareTensors(testResult[i].output, testResult[i].outputExpected); + BOOST_TEST(result.m_Result, result.m_Message.str()); } } } |