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
diff --git a/src/backends/backendsCommon/test/BackendRegistryTests.cpp b/src/backends/backendsCommon/test/BackendRegistryTests.cpp
index 213d114..ce8acbb 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 @@
     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()