ArmNN
 25.11
Loading...
Searching...
No Matches
UnitTests.hpp File Reference
#include "armnnTestUtils/TensorHelpers.hpp"
#include <armnn/Logging.hpp>
#include <armnn/Utils.hpp>
#include <reference/RefWorkloadFactory.hpp>
#include <reference/test/RefWorkloadFactoryHelper.hpp>
#include <backendsCommon/test/WorkloadFactoryHelper.hpp>
#include <armnnTestUtils/LayerTestResult.hpp>
#include <armnnTestUtils/TensorCopyUtils.hpp>
#include <armnnTestUtils/WorkloadTestUtils.hpp>
#include <doctest/doctest.h>
Include dependency graph for UnitTests.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ARMNN_SIMPLE_TEST_CASE(TestName, TestFunction)
#define ARMNN_AUTO_TEST_CASE(TestName, TestFunction, ...)
#define ARMNN_AUTO_TEST_FIXTURE(TestName, Fixture, TestFunction, ...)
#define ARMNN_AUTO_TEST_CASE_WITH_THF(TestName, TestFunction, ...)
#define ARMNN_AUTO_TEST_FIXTURE_WITH_THF(TestName, Fixture, TestFunction, ...)
#define ARMNN_COMPARE_REF_AUTO_TEST_CASE(TestName, TestFunction, ...)
#define ARMNN_COMPARE_REF_AUTO_TEST_CASE_WITH_THF(TestName, TestFunction, ...)
#define ARMNN_COMPARE_REF_FIXTURE_TEST_CASE(TestName, Fixture, TestFunction, ...)
#define ARMNN_COMPARE_REF_FIXTURE_TEST_CASE_WITH_THF(TestName, Fixture, TestFunction, ...)

Functions

void ConfigureLoggingTest ()
template<typename T, std::size_t n>
void CompareTestResultIfSupported (const std::string &testName, const LayerTestResult< T, n > &testResult)
 Executes CHECK_MESSAGE on CompareTensors() return value so that the predicate_result message is reported.
template<typename T, std::size_t n>
void CompareTestResultIfSupported (const std::string &testName, const std::vector< LayerTestResult< T, n > > &testResult)
template<typename FactoryType, typename TFuncPtr, typename... Args>
void RunTestFunction (const char *testName, TFuncPtr testFunction, Args... args)
template<typename FactoryType, typename TFuncPtr, typename... Args>
void RunTestFunctionUsingTensorHandleFactory (const char *testName, TFuncPtr testFunction, Args... args)
template<typename FactoryType, typename TFuncPtr, typename... Args>
void CompareRefTestFunction (const char *testName, TFuncPtr testFunction, Args... args)
template<typename FactoryType, typename TFuncPtr, typename... Args>
void CompareRefTestFunctionUsingTensorHandleFactory (const char *testName, TFuncPtr testFunction, Args... args)

Macro Definition Documentation

◆ ARMNN_AUTO_TEST_CASE

#define ARMNN_AUTO_TEST_CASE ( TestName,
TestFunction,
... )
Value:
TEST_CASE(#TestName) \
{ \
RunTestFunction<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
}

Definition at line 117 of file UnitTests.hpp.

117#define ARMNN_AUTO_TEST_CASE(TestName, TestFunction, ...) \
118 TEST_CASE(#TestName) \
119 { \
120 RunTestFunction<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
121 }

◆ ARMNN_AUTO_TEST_CASE_WITH_THF

#define ARMNN_AUTO_TEST_CASE_WITH_THF ( TestName,
TestFunction,
... )
Value:
TEST_CASE(#TestName) \
{ \
RunTestFunctionUsingTensorHandleFactory<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
}

Definition at line 129 of file UnitTests.hpp.

129#define ARMNN_AUTO_TEST_CASE_WITH_THF(TestName, TestFunction, ...) \
130 TEST_CASE(#TestName) \
131 { \
132 RunTestFunctionUsingTensorHandleFactory<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
133 }

◆ ARMNN_AUTO_TEST_FIXTURE

#define ARMNN_AUTO_TEST_FIXTURE ( TestName,
Fixture,
TestFunction,
... )
Value:
TEST_CASE_FIXTURE(Fixture, #TestName) \
{ \
RunTestFunction<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
}

Definition at line 123 of file UnitTests.hpp.

123#define ARMNN_AUTO_TEST_FIXTURE(TestName, Fixture, TestFunction, ...) \
124 TEST_CASE_FIXTURE(Fixture, #TestName) \
125 { \
126 RunTestFunction<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
127 }

◆ ARMNN_AUTO_TEST_FIXTURE_WITH_THF

#define ARMNN_AUTO_TEST_FIXTURE_WITH_THF ( TestName,
Fixture,
TestFunction,
... )
Value:
TEST_CASE_FIXTURE(Fixture, #TestName) \
{ \
RunTestFunctionUsingTensorHandleFactory<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
}

Definition at line 135 of file UnitTests.hpp.

135#define ARMNN_AUTO_TEST_FIXTURE_WITH_THF(TestName, Fixture, TestFunction, ...) \
136 TEST_CASE_FIXTURE(Fixture, #TestName) \
137 { \
138 RunTestFunctionUsingTensorHandleFactory<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
139 }

◆ ARMNN_COMPARE_REF_AUTO_TEST_CASE

#define ARMNN_COMPARE_REF_AUTO_TEST_CASE ( TestName,
TestFunction,
... )
Value:
TEST_CASE(#TestName) \
{ \
CompareRefTestFunction<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
}

Definition at line 169 of file UnitTests.hpp.

169#define ARMNN_COMPARE_REF_AUTO_TEST_CASE(TestName, TestFunction, ...) \
170 TEST_CASE(#TestName) \
171 { \
172 CompareRefTestFunction<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
173 }

◆ ARMNN_COMPARE_REF_AUTO_TEST_CASE_WITH_THF

#define ARMNN_COMPARE_REF_AUTO_TEST_CASE_WITH_THF ( TestName,
TestFunction,
... )
Value:
TEST_CASE(#TestName) \
{ \
CompareRefTestFunctionUsingTensorHandleFactory<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
}

Definition at line 175 of file UnitTests.hpp.

175#define ARMNN_COMPARE_REF_AUTO_TEST_CASE_WITH_THF(TestName, TestFunction, ...) \
176 TEST_CASE(#TestName) \
177 { \
178 CompareRefTestFunctionUsingTensorHandleFactory<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
179 }

◆ ARMNN_COMPARE_REF_FIXTURE_TEST_CASE

#define ARMNN_COMPARE_REF_FIXTURE_TEST_CASE ( TestName,
Fixture,
TestFunction,
... )
Value:
TEST_CASE_FIXTURE(Fixture, #TestName) \
{ \
CompareRefTestFunction<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
}

Definition at line 181 of file UnitTests.hpp.

181#define ARMNN_COMPARE_REF_FIXTURE_TEST_CASE(TestName, Fixture, TestFunction, ...) \
182 TEST_CASE_FIXTURE(Fixture, #TestName) \
183 { \
184 CompareRefTestFunction<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
185 }

◆ ARMNN_COMPARE_REF_FIXTURE_TEST_CASE_WITH_THF

#define ARMNN_COMPARE_REF_FIXTURE_TEST_CASE_WITH_THF ( TestName,
Fixture,
TestFunction,
... )
Value:
TEST_CASE_FIXTURE(Fixture, #TestName) \
{ \
CompareRefTestFunctionUsingTensorHandleFactory<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
}

Definition at line 187 of file UnitTests.hpp.

187#define ARMNN_COMPARE_REF_FIXTURE_TEST_CASE_WITH_THF(TestName, Fixture, TestFunction, ...) \
188 TEST_CASE_FIXTURE(Fixture, #TestName) \
189 { \
190 CompareRefTestFunctionUsingTensorHandleFactory<FactoryType>(#TestName, &TestFunction, ##__VA_ARGS__); \
191 }

◆ ARMNN_SIMPLE_TEST_CASE

#define ARMNN_SIMPLE_TEST_CASE ( TestName,
TestFunction )
Value:
TEST_CASE(#TestName) \
{ \
TestFunction(); \
}

Definition at line 111 of file UnitTests.hpp.

111#define ARMNN_SIMPLE_TEST_CASE(TestName, TestFunction) \
112 TEST_CASE(#TestName) \
113 { \
114 TestFunction(); \
115 }

Function Documentation

◆ CompareRefTestFunction()

template<typename FactoryType, typename TFuncPtr, typename... Args>
void CompareRefTestFunction ( const char * testName,
TFuncPtr testFunction,
Args... args )

Definition at line 142 of file UnitTests.hpp.

143{
144 auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
145 FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
146
147 armnn::RefWorkloadFactory refWorkloadFactory;
148
149 auto testResult = (*testFunction)(workloadFactory, memoryManager, refWorkloadFactory, args...);
150 CompareTestResultIfSupported(testName, testResult);
151}
void CompareTestResultIfSupported(const std::string &testName, const LayerTestResult< T, n > &testResult)
Executes CHECK_MESSAGE on CompareTensors() return value so that the predicate_result message is repor...
Definition UnitTests.hpp:43

References CompareTestResultIfSupported().

◆ CompareRefTestFunctionUsingTensorHandleFactory()

template<typename FactoryType, typename TFuncPtr, typename... Args>
void CompareRefTestFunctionUsingTensorHandleFactory ( const char * testName,
TFuncPtr testFunction,
Args... args )

Definition at line 154 of file UnitTests.hpp.

155{
156 auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
157 FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
158 auto tensorHandleFactory = WorkloadFactoryHelper<FactoryType>::GetTensorHandleFactory(memoryManager);
159
160 armnn::RefWorkloadFactory refWorkloadFactory;
161 auto refMemoryManager = WorkloadFactoryHelper<armnn::RefWorkloadFactory>::GetMemoryManager();
162 auto refTensorHandleFactory = RefWorkloadFactoryHelper::GetTensorHandleFactory(refMemoryManager);
163
164 auto testResult = (*testFunction)(
165 workloadFactory, memoryManager, refWorkloadFactory, tensorHandleFactory, refTensorHandleFactory, args...);
166 CompareTestResultIfSupported(testName, testResult);
167}

References CompareTestResultIfSupported().

◆ CompareTestResultIfSupported() [1/2]

template<typename T, std::size_t n>
void CompareTestResultIfSupported ( const std::string & testName,
const LayerTestResult< T, n > & testResult )

Executes CHECK_MESSAGE on CompareTensors() return value so that the predicate_result message is reported.

If the test reports itself as not supported then the tensors are not compared. Additionally this checks that the supportedness reported by the test matches the name of the test. Unsupported tests must be 'tagged' by including "UNSUPPORTED" in their name. This is useful because it clarifies that the feature being tested is not actually supported (a passed test with the name of a feature would imply that feature was supported). If support is added for a feature, the test case will fail because the name incorrectly contains UNSUPPORTED. If support is removed for a feature, the test case will fail because the name doesn't contain UNSUPPORTED.

Definition at line 43 of file UnitTests.hpp.

44{
45 bool testNameIndicatesUnsupported = testName.find("UNSUPPORTED") != std::string::npos;
46 CHECK_MESSAGE(testNameIndicatesUnsupported != testResult.m_Supported,
47 "The test name does not match the supportedness it is reporting");
48 if (testResult.m_Supported)
49 {
50 auto result = CompareTensors(testResult.m_ActualData,
51 testResult.m_ExpectedData,
52 testResult.m_ActualShape,
53 testResult.m_ExpectedShape,
54 testResult.m_CompareBoolean);
55 CHECK_MESSAGE(result.m_Result, result.m_Message.str());
56 }
57}

Referenced by CompareRefTestFunction(), CompareRefTestFunctionUsingTensorHandleFactory(), RunTestFunction(), and RunTestFunctionUsingTensorHandleFactory().

◆ CompareTestResultIfSupported() [2/2]

template<typename T, std::size_t n>
void CompareTestResultIfSupported ( const std::string & testName,
const std::vector< LayerTestResult< T, n > > & testResult )

Definition at line 60 of file UnitTests.hpp.

61{
62 bool testNameIndicatesUnsupported = testName.find("UNSUPPORTED") != std::string::npos;
63 for (unsigned int i = 0; i < testResult.size(); ++i)
64 {
65 CHECK_MESSAGE(testNameIndicatesUnsupported != testResult[i].m_Supported,
66 "The test name does not match the supportedness it is reporting");
67 if (testResult[i].m_Supported)
68 {
69 auto result = CompareTensors(testResult[i].m_ActualData,
70 testResult[i].m_ExpectedData,
71 testResult[i].m_ActualShape,
72 testResult[i].m_ExpectedShape);
73 CHECK_MESSAGE(result.m_Result, result.m_Message.str());
74 }
75 }
76}

◆ ConfigureLoggingTest()

void ConfigureLoggingTest ( )
inline

Definition at line 22 of file UnitTests.hpp.

23{
24 // Configures logging for both the ARMNN library and this test program.
26}
void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity)
Configures the logging behaviour of the ARMNN library.
Definition Utils.cpp:20

References armnn::ConfigureLogging(), and armnn::Fatal.

◆ RunTestFunction()

template<typename FactoryType, typename TFuncPtr, typename... Args>
void RunTestFunction ( const char * testName,
TFuncPtr testFunction,
Args... args )

Definition at line 79 of file UnitTests.hpp.

80{
81 std::unique_ptr<armnn::IProfiler> profiler = std::make_unique<armnn::IProfiler>();
83
84 auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
85 FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
86
87 auto testResult = (*testFunction)(workloadFactory, memoryManager, args...);
88 CompareTestResultIfSupported(testName, testResult);
89
91}
void RegisterProfiler(IProfiler *profiler)
static ProfilerManager & GetInstance()

References CompareTestResultIfSupported(), ProfilerManager::GetInstance(), and ProfilerManager::RegisterProfiler().

◆ RunTestFunctionUsingTensorHandleFactory()

template<typename FactoryType, typename TFuncPtr, typename... Args>
void RunTestFunctionUsingTensorHandleFactory ( const char * testName,
TFuncPtr testFunction,
Args... args )

Definition at line 95 of file UnitTests.hpp.

96{
97 std::unique_ptr<armnn::IProfiler> profiler = std::make_unique<armnn::IProfiler>();
99
100 auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
101 FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
102
103 auto tensorHandleFactory = WorkloadFactoryHelper<FactoryType>::GetTensorHandleFactory(memoryManager);
104
105 auto testResult = (*testFunction)(workloadFactory, memoryManager, tensorHandleFactory, args...);
106 CompareTestResultIfSupported(testName, testResult);
107
109}

References CompareTestResultIfSupported(), ProfilerManager::GetInstance(), and ProfilerManager::RegisterProfiler().