aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/test/BackendRegistryTests.cpp
diff options
context:
space:
mode:
authorFrancis Murtagh <francis.murtagh@arm.com>2021-01-25 10:18:10 +0000
committerFrancis Murtagh <francis.murtagh@arm.com>2021-01-25 10:18:20 +0000
commit5dc64fe99227efece77eb7cd14abc47474a48fb8 (patch)
tree09de113127e07707ad8edb20075463696055f736 /src/backends/backendsCommon/test/BackendRegistryTests.cpp
parent2686849118217ba692439407adb53ec3849d48ac (diff)
downloadarmnn-5dc64fe99227efece77eb7cd14abc47474a48fb8.tar.gz
IVGCVSW-5525 Handle Neon optionality on 32 bit linux platforms
* Add neon detection for linux using HWCAPs * Add test to check for backend throwing BackendUnavailable exception Signed-off-by: Francis Murtagh <francis.murtagh@arm.com> Change-Id: Ib74aeb06abe5f88f21ecdd1edb2a1cd20ee2019d
Diffstat (limited to 'src/backends/backendsCommon/test/BackendRegistryTests.cpp')
-rw-r--r--src/backends/backendsCommon/test/BackendRegistryTests.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/backends/backendsCommon/test/BackendRegistryTests.cpp b/src/backends/backendsCommon/test/BackendRegistryTests.cpp
index 213d114248..ce8acbbf2a 100644
--- a/src/backends/backendsCommon/test/BackendRegistryTests.cpp
+++ b/src/backends/backendsCommon/test/BackendRegistryTests.cpp
@@ -7,6 +7,7 @@
#include <armnn/BackendRegistry.hpp>
#include <armnn/backends/IBackendInternal.hpp>
+#include <reference/RefBackend.hpp>
#include <boost/test/unit_test.hpp>
@@ -103,4 +104,47 @@ BOOST_AUTO_TEST_CASE(TestDirectCallToRegistry)
BackendRegistryInstance().Deregister("HelloWorld");
}
+// Test that backends can throw exceptions during their factory function to prevent loading in an unsuitable
+// environment. For example Neon Backend loading on armhf device without neon support.
+// In reality the dynamic backend is loaded in during the LoadDynamicBackends(options.m_DynamicBackendsPath)
+// step of runtime constructor, then the factory function is called to check if supported, in case
+// of Neon not being detected the exception is raised and so the backend is not added to the supportedBackends
+// list
+
+BOOST_AUTO_TEST_CASE(ThrowBackendUnavailableException)
+{
+ using namespace armnn;
+
+ const BackendId mockBackendId("MockDynamicBackend");
+
+ const std::string exceptionMessage("Neon support not found on device, could not register CpuAcc Backend.\n");
+
+ // Register the mock backend with a factory function lambda equivalent to NeonRegisterInitializer
+ BackendRegistryInstance().Register(mockBackendId,
+ [exceptionMessage]()
+ {
+ if (false)
+ {
+ return IBackendInternalUniquePtr(new RefBackend);
+ }
+ ARMNN_LOG(info) << "Neon support not found on device, could not register CpuAcc Backend.";
+ throw armnn::BackendUnavailableException(exceptionMessage);
+ });
+
+ // Get the factory function of the mock backend
+ auto factoryFunc = BackendRegistryInstance().GetFactory(mockBackendId);
+
+ try
+ {
+ // Call the factory function as done during runtime backend registering
+ auto backend = factoryFunc();
+ }
+ catch (const BackendUnavailableException& e)
+ {
+ // Caught
+ BOOST_CHECK_EQUAL(e.what(), exceptionMessage);
+ BOOST_TEST_MESSAGE("ThrowBackendUnavailableExceptionImpl: BackendUnavailableException caught.");
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()