ArmNN
 24.02
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. 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.

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

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

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

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

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

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

◆ ARMNN_SIMPLE_TEST_CASE

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

Definition at line 111 of file UnitTests.hpp.

Function Documentation

◆ CompareRefTestFunction()

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 }

References CompareTestResultIfSupported().

◆ CompareRefTestFunctionUsingTensorHandleFactory()

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]

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]

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 }

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

◆ RunTestFunction()

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 }

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

◆ RunTestFunctionUsingTensorHandleFactory()

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

armnn::ProfilerManager::RegisterProfiler
void RegisterProfiler(IProfiler *profiler)
Definition: Profiling.cpp:600
armnn::ConfigureLogging
void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity)
Configures the logging behaviour of the ARMNN library.
Definition: Utils.cpp:18
armnn::RefWorkloadFactory
Definition: RefWorkloadFactory.hpp:27
armnn::LogSeverity::Fatal
@ Fatal
armnn::ProfilerManager::GetInstance
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:593
CompareTestResultIfSupported
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