ArmNN
 22.02
UnitTests.hpp File Reference

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. More...
 
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.

Referenced by TEST_SUITE().

◆ 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.

Referenced by TEST_SUITE().

◆ ARMNN_AUTO_TEST_FIXTURE

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

Definition at line 123 of file UnitTests.hpp.

Referenced by TEST_SUITE().

◆ 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__); \
}
TEST_CASE_FIXTURE(ClContextControlFixture, "CopyBetweenNeonAndGpu")

Definition at line 135 of file UnitTests.hpp.

Referenced by TEST_SUITE().

◆ 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.

◆ 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.

Referenced by TEST_SUITE().

◆ 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__); \
}
TEST_CASE_FIXTURE(ClContextControlFixture, "CopyBetweenNeonAndGpu")

Definition at line 181 of file UnitTests.hpp.

◆ 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__); \
}
TEST_CASE_FIXTURE(ClContextControlFixture, "CopyBetweenNeonAndGpu")

Definition at line 187 of file UnitTests.hpp.

Referenced by TEST_SUITE().

◆ ARMNN_SIMPLE_TEST_CASE

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

Definition at line 111 of file UnitTests.hpp.

Referenced by TEST_SUITE().

Function Documentation

◆ CompareRefTestFunction()

void CompareRefTestFunction ( const char *  testName,
TFuncPtr  testFunction,
Args...  args 
)

Definition at line 142 of file UnitTests.hpp.

References CompareTestResultIfSupported().

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

◆ CompareRefTestFunctionUsingTensorHandleFactory()

void CompareRefTestFunctionUsingTensorHandleFactory ( const char *  testName,
TFuncPtr  testFunction,
Args...  args 
)

Definition at line 154 of file UnitTests.hpp.

References CompareTestResultIfSupported().

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 }
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

◆ CompareTestResultIfSupported() [1/2]

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.

References CompareTensors(), LayerTestResult< T, n >::m_ActualData, LayerTestResult< T, n >::m_ActualShape, LayerTestResult< T, n >::m_CompareBoolean, LayerTestResult< T, n >::m_ExpectedData, LayerTestResult< T, n >::m_ExpectedShape, and LayerTestResult< T, n >::m_Supported.

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

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 }
armnn::TensorShape m_ExpectedShape
std::vector< T > m_ExpectedData
armnn::PredicateResult CompareTensors(const std::vector< T > &actualData, const std::vector< T > &expectedData, const armnn::TensorShape &actualShape, const armnn::TensorShape &expectedShape, bool compareBoolean=false, bool isDynamic=false)
std::vector< T > m_ActualData
armnn::TensorShape m_ActualShape

◆ CompareTestResultIfSupported() [2/2]

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

Definition at line 60 of file UnitTests.hpp.

References CompareTensors().

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 }
armnn::PredicateResult CompareTensors(const std::vector< T > &actualData, const std::vector< T > &expectedData, const armnn::TensorShape &actualShape, const armnn::TensorShape &expectedShape, bool compareBoolean=false, bool isDynamic=false)

◆ ConfigureLoggingTest()

void ConfigureLoggingTest ( )
inline

Definition at line 22 of file UnitTests.hpp.

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

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:18

◆ RunTestFunction()

void RunTestFunction ( const char *  testName,
TFuncPtr  testFunction,
Args...  args 
)

Definition at line 79 of file UnitTests.hpp.

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

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 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
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:568
void RegisterProfiler(IProfiler *profiler)
Definition: Profiling.cpp:575

◆ RunTestFunctionUsingTensorHandleFactory()

void RunTestFunctionUsingTensorHandleFactory ( const char *  testName,
TFuncPtr  testFunction,
Args...  args 
)

Definition at line 95 of file UnitTests.hpp.

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

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 }
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
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:568
void RegisterProfiler(IProfiler *profiler)
Definition: Profiling.cpp:575