From f39f8d8597c59057118f67cacf70d246f95fea9b Mon Sep 17 00:00:00 2001 From: Jan Eilers Date: Tue, 26 Oct 2021 16:57:34 +0100 Subject: Move command line parsing in external delegate to DelegateOptions * Moves the creation of a DelegateOption object from armnn_external_delegate to DelegateOptions. * This allows this code to be reused elsewhere * Allow boolean values of DelegateOptions to be passed as strings e.g. 'true' or 'false' * Add unit tests Signed-off-by: Jan Eilers Change-Id: I0ada17f511027dd3f47a85142cae346464682f5a --- src/armnn/test/UtilityTests.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/armnn/test') diff --git a/src/armnn/test/UtilityTests.cpp b/src/armnn/test/UtilityTests.cpp index 7911fd2608..fba0dd9d52 100644 --- a/src/armnn/test/UtilityTests.cpp +++ b/src/armnn/test/UtilityTests.cpp @@ -3,16 +3,17 @@ // SPDX-License-Identifier: MIT // -#include #define ARMNN_POLYMORPHIC_CAST_TESTABLE #define ARMNN_NUMERIC_CAST_TESTABLE +#include #include #include #include +#include -#include +#include #include @@ -250,4 +251,28 @@ TEST_CASE("NumericCast") } +TEST_CASE("StringToBool") + { + CHECK(true == armnn::stringUtils::StringToBool("1")); + CHECK(false == armnn::stringUtils::StringToBool("0")); + // Any number larger than 1 will be a failure. + CHECK_THROWS_AS(armnn::stringUtils::StringToBool("2"), armnn::InvalidArgumentException); + CHECK_THROWS_AS(armnn::stringUtils::StringToBool("23456567"), armnn::InvalidArgumentException); + CHECK_THROWS_AS(armnn::stringUtils::StringToBool("-23456567"), armnn::InvalidArgumentException); + CHECK_THROWS_AS(armnn::stringUtils::StringToBool("Not a number"), armnn::InvalidArgumentException); + // Empty string should be a failure. + CHECK_THROWS_AS(armnn::stringUtils::StringToBool(""), armnn::InvalidArgumentException); + CHECK(true == armnn::stringUtils::StringToBool("true")); + CHECK(false == armnn::stringUtils::StringToBool("false")); + // Should be case agnostic. + CHECK(true == armnn::stringUtils::StringToBool("TrUe")); + CHECK(false == armnn::stringUtils::StringToBool("fAlSe")); + + // Same negative test cases with throw_on_error set to false. + CHECK(false == armnn::stringUtils::StringToBool("2", false)); + CHECK(false == armnn::stringUtils::StringToBool("23456567", false)); + CHECK(false == armnn::stringUtils::StringToBool("-23456567", false)); + CHECK(false == armnn::stringUtils::StringToBool("Not a number", false)); + CHECK(false == armnn::stringUtils::StringToBool("", false)); + } } -- cgit v1.2.1