diff options
author | Ferran Balaguer <ferran.balaguer@arm.com> | 2019-08-28 16:57:18 +0100 |
---|---|---|
committer | Ferran Balaguer <ferran.balaguer@arm.com> | 2019-09-13 09:50:20 +0100 |
commit | 1b941728caa2cd7e2148d0872a6b7dda4947b641 (patch) | |
tree | 0820663b520604256554f55e4f4bf07ebc6a3fa3 /src/profiling/test/SendCounterPacketTests.hpp | |
parent | 9bff14458f9950a5d31b9523c62c0bbf79a65fcf (diff) | |
download | armnn-1b941728caa2cd7e2148d0872a6b7dda4947b641.tar.gz |
IVGCVSW-3436 Create the Periodic Counter Selection Command Handler
Change-Id: Ia6fe19db5aebe82bb00dcbab17e16633befda0a5
Signed-off-by: Ferran Balaguer <ferran.balaguer@arm.com>
Diffstat (limited to 'src/profiling/test/SendCounterPacketTests.hpp')
-rw-r--r-- | src/profiling/test/SendCounterPacketTests.hpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/profiling/test/SendCounterPacketTests.hpp b/src/profiling/test/SendCounterPacketTests.hpp new file mode 100644 index 0000000000..a22d02bd63 --- /dev/null +++ b/src/profiling/test/SendCounterPacketTests.hpp @@ -0,0 +1,101 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "../SendCounterPacket.hpp" +#include "../ProfilingUtils.hpp" + +#include <armnn/Exceptions.hpp> + +#include <boost/test/unit_test.hpp> + +#include <chrono> +#include <iostream> + +using namespace armnn::profiling; + +class MockBuffer : public IBufferWrapper +{ +public: + MockBuffer(unsigned int size) + : m_BufferSize(size), + m_Buffer(std::make_unique<unsigned char[]>(size)) {} + + unsigned char* Reserve(unsigned int requestedSize, unsigned int& reservedSize) override + { + if (requestedSize > m_BufferSize) + { + reservedSize = m_BufferSize; + } + else + { + reservedSize = requestedSize; + } + + return m_Buffer.get(); + } + + void Commit(unsigned int size) override {} + + const unsigned char* GetReadBuffer(unsigned int& size) override + { + size = static_cast<unsigned int>(strlen(reinterpret_cast<const char*>(m_Buffer.get())) + 1); + return m_Buffer.get(); + } + + void Release( unsigned int size) override {} + +private: + unsigned int m_BufferSize; + std::unique_ptr<unsigned char[]> m_Buffer; +}; + +class MockSendCounterPacket : public ISendCounterPacket +{ +public: + MockSendCounterPacket(IBufferWrapper& sendBuffer) : m_Buffer(sendBuffer) {} + + void SendStreamMetaDataPacket() override + { + std::string message("SendStreamMetaDataPacket"); + unsigned int reserved = 0; + unsigned char* buffer = m_Buffer.Reserve(1024, reserved); + memcpy(buffer, message.c_str(), static_cast<unsigned int>(message.size()) + 1); + } + + void SendCounterDirectoryPacket(const CounterDirectory& counterDirectory) override + { + std::string message("SendCounterDirectoryPacket"); + unsigned int reserved = 0; + unsigned char* buffer = m_Buffer.Reserve(1024, reserved); + memcpy(buffer, message.c_str(), static_cast<unsigned int>(message.size()) + 1); + } + + void SendPeriodicCounterCapturePacket(uint64_t timestamp, + const std::vector<std::pair<uint16_t, uint32_t>>& values) override + { + std::string message("SendPeriodicCounterCapturePacket"); + unsigned int reserved = 0; + unsigned char* buffer = m_Buffer.Reserve(1024, reserved); + memcpy(buffer, message.c_str(), static_cast<unsigned int>(message.size()) + 1); + } + + void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod, + const std::vector<uint16_t>& selectedCounterIds) override + { + std::string message("SendPeriodicCounterSelectionPacket"); + unsigned int reserved = 0; + unsigned char* buffer = m_Buffer.Reserve(1024, reserved); + memcpy(buffer, message.c_str(), static_cast<unsigned int>(message.size()) + 1); + m_Buffer.Commit(reserved); + } + + void SetReadyToRead() override + {} + +private: + IBufferWrapper& m_Buffer; +}; |