diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/profiling/Packet.cpp | 41 | ||||
-rw-r--r-- | src/profiling/Packet.hpp | 45 | ||||
-rw-r--r-- | src/profiling/test/ProfilingTests.cpp | 22 |
3 files changed, 108 insertions, 0 deletions
diff --git a/src/profiling/Packet.cpp b/src/profiling/Packet.cpp new file mode 100644 index 0000000000..97cb89b517 --- /dev/null +++ b/src/profiling/Packet.cpp @@ -0,0 +1,41 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "Packet.hpp" + +std::uint32_t Packet::GetHeader() const +{ + return m_Header; +} + +std::uint32_t Packet::GetPacketFamily() const +{ + return m_PacketFamily; +} + +std::uint32_t Packet::GetPacketId() const +{ + return m_PacketId; +} + +std::uint32_t Packet::GetLength() const +{ + return m_Length; +} + +const char* Packet::GetData() +{ + return m_Data; +} + +std::uint32_t Packet::GetPacketClass() const +{ + return (m_PacketId >> 3); +} + +std::uint32_t Packet::GetPacketType() const +{ + return (m_PacketId & 7); +}
\ No newline at end of file diff --git a/src/profiling/Packet.hpp b/src/profiling/Packet.hpp new file mode 100644 index 0000000000..0d2ba42af5 --- /dev/null +++ b/src/profiling/Packet.hpp @@ -0,0 +1,45 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + + +#include <boost/log/trivial.hpp> + +#include <armnn/Exceptions.hpp> + +class Packet +{ +public: + Packet(uint32_t header, uint32_t length, const char* data) + : m_Header(header), m_Length(length), m_Data(data) + { + m_PacketId = ((header >> 16) & 1023); + m_PacketFamily = (header >> 26); + + if (length == 0) + { + if (m_Data != nullptr) + { + throw armnn::Exception("Data should be null"); + } + } + }; + + uint32_t GetHeader() const; + uint32_t GetPacketFamily() const; + uint32_t GetPacketId() const; + uint32_t GetLength() const; + const char* GetData(); + + uint32_t GetPacketClass() const; + uint32_t GetPacketType() const; + +private: + uint32_t m_Header; + uint32_t m_PacketFamily; + uint32_t m_PacketId; + uint32_t m_Length; + const char* m_Data; +};
\ No newline at end of file diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp index 5abab2fb78..1ea8ab96a2 100644 --- a/src/profiling/test/ProfilingTests.cpp +++ b/src/profiling/test/ProfilingTests.cpp @@ -4,7 +4,10 @@ // #include "../CommandHandlerKey.hpp" +#include "../Packet.hpp" +#include <cstdint> +#include <cstring> #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_SUITE(ExternalProfiling) @@ -56,4 +59,23 @@ BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons) BOOST_CHECK(vect == expectedVect); } +BOOST_AUTO_TEST_CASE(CheckPacketClass) +{ + const char* data = "test"; + unsigned int length = static_cast<unsigned int>(std::strlen(data)); + + Packet packetTest1(472580096,length,data); + BOOST_CHECK_THROW(Packet packetTest2(472580096,0,""), armnn::Exception); + + Packet packetTest3(472580096,0, nullptr); + + BOOST_CHECK(packetTest1.GetLength() == length); + BOOST_CHECK(packetTest1.GetData() == data); + + BOOST_CHECK(packetTest1.GetPacketFamily() == 7); + BOOST_CHECK(packetTest1.GetPacketId() == 43); + BOOST_CHECK(packetTest1.GetPacketType() == 3); + BOOST_CHECK(packetTest1.GetPacketClass() == 5); +} + BOOST_AUTO_TEST_SUITE_END() |