aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/test/BackendRegistryTests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/backends/backendsCommon/test/BackendRegistryTests.cpp')
-rw-r--r--src/backends/backendsCommon/test/BackendRegistryTests.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/backends/backendsCommon/test/BackendRegistryTests.cpp b/src/backends/backendsCommon/test/BackendRegistryTests.cpp
new file mode 100644
index 0000000000..4afe273de4
--- /dev/null
+++ b/src/backends/backendsCommon/test/BackendRegistryTests.cpp
@@ -0,0 +1,103 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <armnn/Types.hpp>
+
+#include <backendsCommon/BackendRegistry.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+namespace
+{
+
+class SwapRegistryStorage : public armnn::BackendRegistry
+{
+public:
+ SwapRegistryStorage() : armnn::BackendRegistry()
+ {
+ Swap(armnn::BackendRegistryInstance(), m_TempStorage);
+ }
+
+ ~SwapRegistryStorage()
+ {
+ Swap(armnn::BackendRegistryInstance(),m_TempStorage);
+ }
+
+private:
+ FactoryStorage m_TempStorage;
+};
+
+}
+
+BOOST_AUTO_TEST_SUITE(BackendRegistryTests)
+
+BOOST_AUTO_TEST_CASE(SwapRegistry)
+{
+ using namespace armnn;
+ auto nFactories = BackendRegistryInstance().Size();
+ {
+ SwapRegistryStorage helper;
+ BOOST_TEST(BackendRegistryInstance().Size() == 0);
+ }
+ BOOST_TEST(BackendRegistryInstance().Size() == nFactories);
+}
+
+BOOST_AUTO_TEST_CASE(TestRegistryHelper)
+{
+ using namespace armnn;
+ SwapRegistryStorage helper;
+
+ bool called = false;
+
+ StaticRegistryInitializer<BackendRegistry> factoryHelper(
+ BackendRegistryInstance(),
+ "HelloWorld",
+ [&called](const EmptyInitializer&)
+ {
+ called = true;
+ return armnn::IBackendInternalUniquePtr(nullptr);
+ }
+ );
+
+ // sanity check: the factory has not been called yet
+ BOOST_TEST(called == false);
+
+ auto factoryFunction = BackendRegistryInstance().GetFactory("HelloWorld");
+
+ // sanity check: the factory still not called
+ BOOST_TEST(called == false);
+
+ factoryFunction(EmptyInitializer());
+ BOOST_TEST(called == true);
+}
+
+BOOST_AUTO_TEST_CASE(TestDirectCallToRegistry)
+{
+ using namespace armnn;
+ SwapRegistryStorage helper;
+
+ bool called = false;
+ BackendRegistryInstance().Register(
+ "HelloWorld",
+ [&called](const EmptyInitializer&)
+ {
+ called = true;
+ return armnn::IBackendInternalUniquePtr(nullptr);
+ }
+ );
+
+ // sanity check: the factory has not been called yet
+ BOOST_TEST(called == false);
+
+ auto factoryFunction = BackendRegistryInstance().GetFactory("HelloWorld");
+
+ // sanity check: the factory still not called
+ BOOST_TEST(called == false);
+
+ factoryFunction(EmptyInitializer());
+ BOOST_TEST(called == true);
+}
+
+BOOST_AUTO_TEST_SUITE_END()