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 | |
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')
-rw-r--r-- | src/profiling/CommandHandlerFunctor.cpp | 16 | ||||
-rw-r--r-- | src/profiling/CommandHandlerFunctor.hpp | 25 | ||||
-rw-r--r-- | src/profiling/test/ProfilingTests.cpp | 78 |
3 files changed, 119 insertions, 0 deletions
diff --git a/src/profiling/CommandHandlerFunctor.cpp b/src/profiling/CommandHandlerFunctor.cpp new file mode 100644 index 0000000000..7289221db8 --- /dev/null +++ b/src/profiling/CommandHandlerFunctor.cpp @@ -0,0 +1,16 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "CommandHandlerFunctor.hpp" + +uint32_t CommandHandlerFunctor::GetPacketId() const +{ + return m_PacketId; +} + +uint32_t CommandHandlerFunctor::GetVersion() const +{ + return m_Version; +}
\ No newline at end of file diff --git a/src/profiling/CommandHandlerFunctor.hpp b/src/profiling/CommandHandlerFunctor.hpp new file mode 100644 index 0000000000..fce6e3f8bb --- /dev/null +++ b/src/profiling/CommandHandlerFunctor.hpp @@ -0,0 +1,25 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "Packet.hpp" + +#include <cstdint> + +#pragma once + +class CommandHandlerFunctor +{ +public: + CommandHandlerFunctor(uint32_t packetId, uint32_t version) : m_PacketId(packetId), m_Version(version) {}; + + uint32_t GetPacketId() const; + uint32_t GetVersion() const; + + virtual void operator()(const Packet& packet) {}; + +private: + uint32_t m_PacketId; + uint32_t m_Version; +};
\ No newline at end of file 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() |