From 9150bff63a690caa743c471943afe509ebed1044 Mon Sep 17 00:00:00 2001 From: Sadik Armagan Date: Wed, 26 May 2021 15:40:53 +0100 Subject: IVGCVSW-4618 'Transition Units Test Suites' * Used doctest in android-nn-driver unit tests. Signed-off-by: Sadik Armagan Change-Id: I9b5d4dfd77d53c7ebee7f8c43628a1d6ff74d1a3 --- test/1.3/QLstm.cpp | 73 +++++++++++++++++++++------------------------------ test/1.3/QosTests.cpp | 26 +++++++----------- 2 files changed, 39 insertions(+), 60 deletions(-) (limited to 'test/1.3') diff --git a/test/1.3/QLstm.cpp b/test/1.3/QLstm.cpp index 27e52a60..82acba6e 100644 --- a/test/1.3/QLstm.cpp +++ b/test/1.3/QLstm.cpp @@ -10,14 +10,10 @@ #include -#include -#include -#include +#include #include -BOOST_AUTO_TEST_SUITE(QLSTMTests) - using ArmnnDriver = armnn_driver::ArmnnDriver; using DriverOptions = armnn_driver::DriverOptions; @@ -26,6 +22,8 @@ using namespace android::hardware; using HalPolicy = hal_1_3::HalPolicy; +static const float TOLERANCE = 1.0f; + namespace { @@ -42,26 +40,6 @@ RequestArgument CreateRequestArgument(const std::vector& value, unsigned int return inputRequestArgument; } -// Returns true if the relative difference between two float values is less than the tolerance value given. -// This is used because the floating point comparison tolerance (set on each BOOST_AUTO_TEST_CASE) does not work! -bool TolerantCompareEqual(float a, float b, float tolerance = 1.0f) -{ - float rd; - if (a == 0.0f) - { - rd = fabs(b); - } - else if (b == 0.0f) - { - rd = fabs(a); - } - else - { - rd = boost::math::relative_difference(a, b); - } - return rd < tolerance; -} - // Helper function to create an OperandLifeTime::NO_VALUE for testing. // To be used on optional input operands that have no values - these are valid and should be tested. HalPolicy::OperandLifeTime CreateNoValueLifeTime(const hidl_vec& dimensions) @@ -85,12 +63,6 @@ void ExecuteModel(const armnn_driver::hal_1_3::HalPolicy::Model& model, } } -#ifndef ARMCOMPUTECL_ENABLED -static const std::array COMPUTE_DEVICES = {{ armnn::Compute::CpuRef }}; -#else -static const std::array COMPUTE_DEVICES = {{ armnn::Compute::CpuRef, armnn::Compute::CpuAcc }}; -#endif - // Add our own tests here since we skip the qlstm tests which Google supplies (because of non-const weights) void QLstmTestImpl(const hidl_vec& inputDimensions, const std::vector& inputValue, @@ -527,8 +499,8 @@ void QLstmTestImpl(const hidl_vec& inputDimensions, // check the results for (size_t i = 0; i < outputStateOutValue.size(); ++i) { - BOOST_TEST(TolerantCompareEqual(outputStateOutValue[i], outputStateOutData[i]), - "outputStateOut[" << i << "]: " << outputStateOutValue[i] << " != " << outputStateOutData[i]); + CHECK_MESSAGE(outputStateOutValue[i] == doctest::Approx( outputStateOutData[i] ).epsilon(TOLERANCE), + "outputStateOut[" << i << "]: " << outputStateOutValue[i] << " != " << outputStateOutData[i]); } // CELL STATE OUTPUT Does not match currently: IVGCVSW-4860 Verify remaining VTS tests (2) for QLSTM @@ -541,8 +513,8 @@ void QLstmTestImpl(const hidl_vec& inputDimensions, for (size_t i = 0; i < outputValue.size(); ++i) { - BOOST_TEST(TolerantCompareEqual(outputValue[i], outputData[i]), - "output[" << i << "]: " << outputValue[i] << " != " << outputData[i]); + CHECK_MESSAGE(outputValue[i] == doctest::Approx( outputData[i] ).epsilon(TOLERANCE), + "output[" << i << "]: " << outputValue[i] << " != " << outputData[i]); } } @@ -1028,19 +1000,34 @@ void DynamicOutputQLstmWithNoProjection(armnn::Compute compute) } // anonymous namespace // Support is not added yet -//BOOST_DATA_TEST_CASE(QLSTMWithProjectionTest, COMPUTE_DEVICES) +//TEST_CASE(QLSTMWithProjectionTest, COMPUTE_DEVICES) //{ // QLstmWithProjection(sample); //} -BOOST_DATA_TEST_CASE(QLSTMWithNoProjectionTest, COMPUTE_DEVICES) +TEST_SUITE("QLSTMTests_CpuRef") { - QLstmWithNoProjection(sample); -} + TEST_CASE("QLSTMWithNoProjectionTest_CpuRef") + { + QLstmWithNoProjection(armnn::Compute::CpuRef); + } -BOOST_DATA_TEST_CASE(DynamicOutputQLSTMWithNoProjectionTest, COMPUTE_DEVICES) -{ - DynamicOutputQLstmWithNoProjection(sample); + TEST_CASE("DynamicOutputQLstmWithNoProjection_CpuRef") + { + DynamicOutputQLstmWithNoProjection(armnn::Compute::CpuRef); + } } +#ifdef ARMCOMPUTECL_ENABLED +TEST_SUITE("QLSTMTests_CpuAcc") +{ + TEST_CASE("QLSTMWithNoProjectionTest_CpuAcc") + { + QLstmWithNoProjection(armnn::Compute::CpuAcc); + } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file + TEST_CASE("DynamicOutputQLstmWithNoProjection_CpuAcc") + { + DynamicOutputQLstmWithNoProjection(armnn::Compute::CpuAcc); + } +} +#endif diff --git a/test/1.3/QosTests.cpp b/test/1.3/QosTests.cpp index 9fd66880..3b064052 100644 --- a/test/1.3/QosTests.cpp +++ b/test/1.3/QosTests.cpp @@ -10,12 +10,10 @@ #include -#include -#include - - -BOOST_AUTO_TEST_SUITE(QosTests) +#include +TEST_SUITE("QosTests") +{ using ArmnnDriver = armnn_driver::ArmnnDriver; using DriverOptions = armnn_driver::DriverOptions; @@ -40,13 +38,7 @@ void ExecuteModel(const armnn_driver::hal_1_3::HalPolicy::Model& model, } } -#ifndef ARMCOMPUTECL_ENABLED -static const std::array COMPUTE_DEVICES = {{ armnn::Compute::CpuRef }}; -#else -static const std::array COMPUTE_DEVICES = {{ armnn::Compute::CpuRef, armnn::Compute::CpuAcc }}; -#endif - -BOOST_AUTO_TEST_CASE(ConcurrentExecuteWithQosPriority) +TEST_CASE("ConcurrentExecuteWithQosPriority") { ALOGI("ConcurrentExecuteWithQOSPriority: entry"); @@ -102,7 +94,7 @@ BOOST_AUTO_TEST_CASE(ConcurrentExecuteWithQosPriority) preparedModelsSize++; } - BOOST_TEST(maxRequests == preparedModelsSize); + CHECK(maxRequests == preparedModelsSize); // construct the request data V1_0::DataLocation inloc = {}; @@ -172,15 +164,15 @@ BOOST_AUTO_TEST_CASE(ConcurrentExecuteWithQosPriority) { if (i < 15) { - BOOST_TEST(outdata[i][0] == 152); + CHECK(outdata[i][0] == 152); } else if (i < 30) { - BOOST_TEST(outdata[i][0] == 141); + CHECK(outdata[i][0] == 141); } else { - BOOST_TEST(outdata[i][0] == 159); + CHECK(outdata[i][0] == 159); } } @@ -189,4 +181,4 @@ BOOST_AUTO_TEST_CASE(ConcurrentExecuteWithQosPriority) } // anonymous namespace -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +} \ No newline at end of file -- cgit v1.2.1