ArmNN
 21.08
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 114 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 126 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 120 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 132 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 166 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 172 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 178 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 184 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 108 of file UnitTests.hpp.

Referenced by TEST_SUITE().

Function Documentation

◆ CompareRefTestFunction()

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

Definition at line 139 of file UnitTests.hpp.

References CompareTestResultIfSupported().

140 {
141  auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
142  FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
143 
144  armnn::RefWorkloadFactory refWorkloadFactory;
145 
146  auto testResult = (*testFunction)(workloadFactory, memoryManager, refWorkloadFactory, args...);
147  CompareTestResultIfSupported(testName, testResult);
148 }
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:40

◆ CompareRefTestFunctionUsingTensorHandleFactory()

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

Definition at line 151 of file UnitTests.hpp.

References CompareTestResultIfSupported().

152 {
153  auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
154  FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
155 
156  armnn::RefWorkloadFactory refWorkloadFactory;
157  auto tensorHandleFactory = WorkloadFactoryHelper<FactoryType>::GetTensorHandleFactory(memoryManager);
158  auto refTensorHandleFactory =
159  RefWorkloadFactoryHelper::GetTensorHandleFactory(memoryManager);
160 
161  auto testResult = (*testFunction)(
162  workloadFactory, memoryManager, refWorkloadFactory, tensorHandleFactory, refTensorHandleFactory, args...);
163  CompareTestResultIfSupported(testName, testResult);
164 }
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:40

◆ 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 40 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().

41 {
42  bool testNameIndicatesUnsupported = testName.find("UNSUPPORTED") != std::string::npos;
43  CHECK_MESSAGE(testNameIndicatesUnsupported != testResult.m_Supported,
44  "The test name does not match the supportedness it is reporting");
45  if (testResult.m_Supported)
46  {
47  auto result = CompareTensors(testResult.m_ActualData,
48  testResult.m_ExpectedData,
49  testResult.m_ActualShape,
50  testResult.m_ExpectedShape,
51  testResult.m_CompareBoolean);
52  CHECK_MESSAGE(result.m_Result, result.m_Message.str());
53  }
54 }
armnn::TensorShape m_ExpectedShape
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_ExpectedData
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 57 of file UnitTests.hpp.

References CompareTensors().

58 {
59  bool testNameIndicatesUnsupported = testName.find("UNSUPPORTED") != std::string::npos;
60  for (unsigned int i = 0; i < testResult.size(); ++i)
61  {
62  CHECK_MESSAGE(testNameIndicatesUnsupported != testResult[i].m_Supported,
63  "The test name does not match the supportedness it is reporting");
64  if (testResult[i].m_Supported)
65  {
66  auto result = CompareTensors(testResult[i].m_ActualData,
67  testResult[i].m_ExpectedData,
68  testResult[i].m_ActualShape,
69  testResult[i].m_ExpectedShape);
70  CHECK_MESSAGE(result.m_Result, result.m_Message.str());
71  }
72  }
73 }
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 19 of file UnitTests.hpp.

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

20 {
21  // Configures logging for both the ARMNN library and this test program.
23 }
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 76 of file UnitTests.hpp.

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

77 {
78  std::unique_ptr<armnn::IProfiler> profiler = std::make_unique<armnn::IProfiler>();
80 
81  auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
82  FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
83 
84  auto testResult = (*testFunction)(workloadFactory, memoryManager, args...);
85  CompareTestResultIfSupported(testName, testResult);
86 
88 }
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:526
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:40
void RegisterProfiler(IProfiler *profiler)
Definition: Profiling.cpp:533

◆ RunTestFunctionUsingTensorHandleFactory()

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

Definition at line 92 of file UnitTests.hpp.

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

93 {
94  std::unique_ptr<armnn::IProfiler> profiler = std::make_unique<armnn::IProfiler>();
96 
97  auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
98  FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
99 
100  auto tensorHandleFactory = WorkloadFactoryHelper<FactoryType>::GetTensorHandleFactory(memoryManager);
101 
102  auto testResult = (*testFunction)(workloadFactory, memoryManager, tensorHandleFactory, args...);
103  CompareTestResultIfSupported(testName, testResult);
104 
106 }
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:526
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:40
void RegisterProfiler(IProfiler *profiler)
Definition: Profiling.cpp:533