ArmNN
 20.05
UnitTests.hpp File Reference
#include <armnn/Logging.hpp>
#include <armnn/Utils.hpp>
#include <reference/RefWorkloadFactory.hpp>
#include <backendsCommon/test/LayerTests.hpp>
#include <backendsCommon/test/WorkloadFactoryHelper.hpp>
#include "TensorHelpers.hpp"
#include <boost/test/unit_test.hpp>

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_COMPARE_REF_AUTO_TEST_CASE(TestName, TestFunction, ...)
 
#define ARMNN_COMPARE_REF_FIXTURE_TEST_CASE(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 BOOST_TEST 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 CompareRefTestFunction (const char *testName, TFuncPtr testFunction, Args... args)
 

Macro Definition Documentation

◆ ARMNN_AUTO_TEST_CASE

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

Definition at line 83 of file UnitTests.hpp.

◆ ARMNN_COMPARE_REF_AUTO_TEST_CASE

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

Definition at line 101 of file UnitTests.hpp.

◆ ARMNN_COMPARE_REF_FIXTURE_TEST_CASE

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

Definition at line 107 of file UnitTests.hpp.

◆ ARMNN_SIMPLE_TEST_CASE

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

Definition at line 77 of file UnitTests.hpp.

Function Documentation

◆ CompareRefTestFunction()

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

Definition at line 90 of file UnitTests.hpp.

References CompareTestResultIfSupported().

91 {
92  auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
93  FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
94 
95  armnn::RefWorkloadFactory refWorkloadFactory;
96 
97  auto testResult = (*testFunction)(workloadFactory, memoryManager, refWorkloadFactory, args...);
98  CompareTestResultIfSupported(testName, testResult);
99 }
void CompareTestResultIfSupported(const std::string &testName, const LayerTestResult< T, n > &testResult)
Executes BOOST_TEST on CompareTensors() return value so that the predicate_result message is reported...
Definition: UnitTests.hpp:36
ClWorkloadFactory FactoryType

◆ CompareTestResultIfSupported() [1/2]

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

Executes BOOST_TEST 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 36 of file UnitTests.hpp.

References LayerTestResult< T, n >::compareBoolean, CompareTensors(), LayerTestResult< T, n >::output, LayerTestResult< T, n >::outputExpected, and LayerTestResult< T, n >::supported.

Referenced by CompareRefTestFunction(), and RunTestFunction().

37 {
38  bool testNameIndicatesUnsupported = testName.find("UNSUPPORTED") != std::string::npos;
39  BOOST_CHECK_MESSAGE(testNameIndicatesUnsupported != testResult.supported,
40  "The test name does not match the supportedness it is reporting");
41  if (testResult.supported)
42  {
43  BOOST_TEST(CompareTensors(testResult.output, testResult.outputExpected, testResult.compareBoolean));
44  }
45 }
boost::test_tools::predicate_result CompareTensors(const boost::multi_array< T, n > &a, const boost::multi_array< T, n > &b, bool compareBoolean=false)
boost::multi_array< T, n > outputExpected
boost::multi_array< T, n > output

◆ CompareTestResultIfSupported() [2/2]

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

Definition at line 48 of file UnitTests.hpp.

References CompareTensors().

49 {
50  bool testNameIndicatesUnsupported = testName.find("UNSUPPORTED") != std::string::npos;
51  for (unsigned int i = 0; i < testResult.size(); ++i)
52  {
53  BOOST_CHECK_MESSAGE(testNameIndicatesUnsupported != testResult[i].supported,
54  "The test name does not match the supportedness it is reporting");
55  if (testResult[i].supported)
56  {
57  BOOST_TEST(CompareTensors(testResult[i].output, testResult[i].outputExpected));
58  }
59  }
60 }
ISubgraphViewConverter supported
boost::test_tools::predicate_result CompareTensors(const boost::multi_array< T, n > &a, const boost::multi_array< T, n > &b, bool compareBoolean=false)

◆ ConfigureLoggingTest()

void ConfigureLoggingTest ( )
inline

Definition at line 15 of file UnitTests.hpp.

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

16 {
17  // Configures logging for both the ARMNN library and this test program.
19 }
void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity)
Configures the logging behaviour of the ARMNN library.
Definition: Utils.cpp:10

◆ RunTestFunction()

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

Definition at line 63 of file UnitTests.hpp.

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

64 {
65  std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
67 
68  auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager();
69  FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager);
70 
71  auto testResult = (*testFunction)(workloadFactory, memoryManager, args...);
72  CompareTestResultIfSupported(testName, testResult);
73 
75 }
void RegisterProfiler(Profiler *profiler)
Definition: Profiling.cpp:493
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:486
void CompareTestResultIfSupported(const std::string &testName, const LayerTestResult< T, n > &testResult)
Executes BOOST_TEST on CompareTensors() return value so that the predicate_result message is reported...
Definition: UnitTests.hpp:36
ClWorkloadFactory FactoryType