IVGCVSW-2093 Add SpaceToBatchNd layer and corresponding no-op factory implementations
[platform/upstream/armnn.git] / src / backends / backendsCommon / test / BackendRegistryTests.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include <armnn/Types.hpp>
7
8 #include <backendsCommon/BackendRegistry.hpp>
9
10 #include <boost/test/unit_test.hpp>
11
12 namespace
13 {
14
15 class SwapRegistryStorage : public armnn::BackendRegistry
16 {
17 public:
18     SwapRegistryStorage() : armnn::BackendRegistry()
19     {
20         Swap(armnn::BackendRegistryInstance(),  m_TempStorage);
21     }
22
23     ~SwapRegistryStorage()
24     {
25         Swap(armnn::BackendRegistryInstance(),m_TempStorage);
26     }
27
28 private:
29     FactoryStorage m_TempStorage;
30 };
31
32 }
33
34 BOOST_AUTO_TEST_SUITE(BackendRegistryTests)
35
36 BOOST_AUTO_TEST_CASE(SwapRegistry)
37 {
38     using namespace armnn;
39     auto nFactories = BackendRegistryInstance().Size();
40     {
41         SwapRegistryStorage helper;
42         BOOST_TEST(BackendRegistryInstance().Size() == 0);
43     }
44     BOOST_TEST(BackendRegistryInstance().Size() == nFactories);
45 }
46
47 BOOST_AUTO_TEST_CASE(TestRegistryHelper)
48 {
49     using namespace armnn;
50     SwapRegistryStorage helper;
51
52     bool called = false;
53
54     StaticRegistryInitializer<BackendRegistry> factoryHelper(
55         BackendRegistryInstance(),
56         "HelloWorld",
57         [&called](const EmptyInitializer&)
58         {
59             called = true;
60             return armnn::IBackendInternalUniquePtr(nullptr);
61         }
62     );
63
64     // sanity check: the factory has not been called yet
65     BOOST_TEST(called == false);
66
67     auto factoryFunction = BackendRegistryInstance().GetFactory("HelloWorld");
68
69     // sanity check: the factory still not called
70     BOOST_TEST(called == false);
71
72     factoryFunction(EmptyInitializer());
73     BOOST_TEST(called == true);
74 }
75
76 BOOST_AUTO_TEST_CASE(TestDirectCallToRegistry)
77 {
78     using namespace armnn;
79     SwapRegistryStorage helper;
80
81     bool called = false;
82     BackendRegistryInstance().Register(
83         "HelloWorld",
84         [&called](const EmptyInitializer&)
85         {
86             called = true;
87             return armnn::IBackendInternalUniquePtr(nullptr);
88         }
89     );
90
91     // sanity check: the factory has not been called yet
92     BOOST_TEST(called == false);
93
94     auto factoryFunction = BackendRegistryInstance().GetFactory("HelloWorld");
95
96     // sanity check: the factory still not called
97     BOOST_TEST(called == false);
98
99     factoryFunction(EmptyInitializer());
100     BOOST_TEST(called == true);
101 }
102
103 BOOST_AUTO_TEST_SUITE_END()