diff options
author | Francis Murtagh <francis.murtagh@arm.com> | 2019-08-16 11:28:52 +0100 |
---|---|---|
committer | Francis Murtagh <francis.murtagh@arm.com> | 2019-08-16 11:28:52 +0100 |
commit | 11f99b4e72a92051329b23af7ded759463380086 (patch) | |
tree | a6e86079c43869dcf8c03f3e810894473ccf6d12 /src/profiling/test | |
parent | bc62605b8f4592881dcc6eb74b5d7af089ae3fd0 (diff) | |
download | armnn-11f99b4e72a92051329b23af7ded759463380086.tar.gz |
IVGCVSW-3425 Create the Command Handler Functor base class
Change-Id: I59ac9b32ac594161bdc5e1de2cdee02d79fc1992
Signed-off-by: Francis Murtagh <francis.murtagh@arm.com>
Diffstat (limited to 'src/profiling/test')
-rw-r--r-- | src/profiling/test/ProfilingTests.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp index 1ea8ab96a2..26cbfd7183 100644 --- a/src/profiling/test/ProfilingTests.cpp +++ b/src/profiling/test/ProfilingTests.cpp @@ -4,11 +4,13 @@ // #include "../CommandHandlerKey.hpp" +#include "../CommandHandlerFunctor.hpp" #include "../Packet.hpp" #include <cstdint> #include <cstring> #include <boost/test/unit_test.hpp> +#include <map> BOOST_AUTO_TEST_SUITE(ExternalProfiling) @@ -78,4 +80,80 @@ BOOST_AUTO_TEST_CASE(CheckPacketClass) BOOST_CHECK(packetTest1.GetPacketClass() == 5); } +BOOST_AUTO_TEST_CASE(CheckCommandHandlerFunctor) +{ + // Create Derived Classes + class TestFunctorA : public CommandHandlerFunctor + { + public: + using CommandHandlerFunctor::CommandHandlerFunctor; + + int GetCount() { return m_Count; } + + void operator()(const Packet& packet) override + { + m_Count++; + } + + private: + int m_Count = 0; + }; + + class TestFunctorB : public TestFunctorA + { + using TestFunctorA::TestFunctorA; + }; + + class TestFunctorC : public TestFunctorA + { + using TestFunctorA::TestFunctorA; + }; + + // Hard code the version as it will be the same during a single profiling session + uint32_t version = 1; + + TestFunctorA testFunctorA(461, version); + TestFunctorB testFunctorB(963, version); + TestFunctorC testFunctorC(983, version); + + CommandHandlerKey keyA(testFunctorA.GetPacketId(), testFunctorA.GetVersion()); + CommandHandlerKey keyB(testFunctorB.GetPacketId(), testFunctorB.GetVersion()); + CommandHandlerKey keyC(testFunctorC.GetPacketId(), testFunctorC.GetVersion()); + + // Create the unwrapped map to simulate the Command Handler Registry + std::map<CommandHandlerKey, CommandHandlerFunctor*> registry; + + registry.insert(std::make_pair(keyB, &testFunctorB)); + registry.insert(std::make_pair(keyA, &testFunctorA)); + registry.insert(std::make_pair(keyC, &testFunctorC)); + + // Check the order of the map is correct + auto it = registry.begin(); + BOOST_CHECK(it->first==keyA); + it++; + BOOST_CHECK(it->first==keyB); + it++; + BOOST_CHECK(it->first==keyC); + + Packet packetA(500000000, 0, nullptr); + Packet packetB(600000000, 0, nullptr); + Packet packetC(400000000, 0, nullptr); + + // Check the correct operator of derived class is called + registry.at(CommandHandlerKey(packetA.GetPacketId(), version))->operator()(packetA); + BOOST_CHECK(testFunctorA.GetCount() == 1); + BOOST_CHECK(testFunctorB.GetCount() == 0); + BOOST_CHECK(testFunctorC.GetCount() == 0); + + registry.at(CommandHandlerKey(packetB.GetPacketId(), version))->operator()(packetB); + BOOST_CHECK(testFunctorA.GetCount() == 1); + BOOST_CHECK(testFunctorB.GetCount() == 1); + BOOST_CHECK(testFunctorC.GetCount() == 0); + + registry.at(CommandHandlerKey(packetC.GetPacketId(), version))->operator()(packetC); + BOOST_CHECK(testFunctorA.GetCount() == 1); + BOOST_CHECK(testFunctorB.GetCount() == 1); + BOOST_CHECK(testFunctorC.GetCount() == 1); +} + BOOST_AUTO_TEST_SUITE_END() |