diff options
author | Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> | 2018-11-01 16:15:57 +0000 |
---|---|---|
committer | Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> | 2018-11-02 14:49:21 +0000 |
commit | c9cc80455ff29fd2c8622c9487ec9c57ade6ea30 (patch) | |
tree | 41b1491312fe6082b39d5d37ffa0dcf0ab0f2817 /src/backends/backendsCommon/test/BackendRegistryTests.cpp | |
parent | 207ef9a6b8b3ea0afe9a095639f67b5dedd095d7 (diff) | |
download | armnn-c9cc80455ff29fd2c8622c9487ec9c57ade6ea30.tar.gz |
IVGCVSW-1946: Remove armnn/src from the include paths
Change-Id: I663a0a0fccb43ee960ec070121a59df9db0bb04e
Diffstat (limited to 'src/backends/backendsCommon/test/BackendRegistryTests.cpp')
-rw-r--r-- | src/backends/backendsCommon/test/BackendRegistryTests.cpp | 103 |
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() |