2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include <armnn/Types.hpp>
8 #include <backendsCommon/BackendRegistry.hpp>
10 #include <boost/test/unit_test.hpp>
15 class SwapRegistryStorage : public armnn::BackendRegistry
18 SwapRegistryStorage() : armnn::BackendRegistry()
20 Swap(armnn::BackendRegistryInstance(), m_TempStorage);
23 ~SwapRegistryStorage()
25 Swap(armnn::BackendRegistryInstance(),m_TempStorage);
29 FactoryStorage m_TempStorage;
34 BOOST_AUTO_TEST_SUITE(BackendRegistryTests)
36 BOOST_AUTO_TEST_CASE(SwapRegistry)
38 using namespace armnn;
39 auto nFactories = BackendRegistryInstance().Size();
41 SwapRegistryStorage helper;
42 BOOST_TEST(BackendRegistryInstance().Size() == 0);
44 BOOST_TEST(BackendRegistryInstance().Size() == nFactories);
47 BOOST_AUTO_TEST_CASE(TestRegistryHelper)
49 using namespace armnn;
50 SwapRegistryStorage helper;
54 StaticRegistryInitializer<BackendRegistry> factoryHelper(
55 BackendRegistryInstance(),
57 [&called](const EmptyInitializer&)
60 return armnn::IBackendInternalUniquePtr(nullptr);
64 // sanity check: the factory has not been called yet
65 BOOST_TEST(called == false);
67 auto factoryFunction = BackendRegistryInstance().GetFactory("HelloWorld");
69 // sanity check: the factory still not called
70 BOOST_TEST(called == false);
72 factoryFunction(EmptyInitializer());
73 BOOST_TEST(called == true);
76 BOOST_AUTO_TEST_CASE(TestDirectCallToRegistry)
78 using namespace armnn;
79 SwapRegistryStorage helper;
82 BackendRegistryInstance().Register(
84 [&called](const EmptyInitializer&)
87 return armnn::IBackendInternalUniquePtr(nullptr);
91 // sanity check: the factory has not been called yet
92 BOOST_TEST(called == false);
94 auto factoryFunction = BackendRegistryInstance().GetFactory("HelloWorld");
96 // sanity check: the factory still not called
97 BOOST_TEST(called == false);
99 factoryFunction(EmptyInitializer());
100 BOOST_TEST(called == true);
103 BOOST_AUTO_TEST_SUITE_END()