6 #include "../ProfilingConnectionDumpToFileDecorator.hpp" 15 #include <doctest/doctest.h> 22 const std::vector<char> g_Data = {
'd',
'u',
'm',
'm',
'y' };
24 const unsigned char* g_DataPtr =
reinterpret_cast<const unsigned char*
>(g_Data.data());
29 DummyProfilingConnection()
31 , m_PacketData(
std::make_unique<unsigned char[]>(g_DataLength))
34 std::memcpy(m_PacketData.get(), g_DataPtr, g_DataLength);
35 m_Packet = std::make_unique<arm::pipe::Packet>(0u, g_DataLength, m_PacketData);
38 ~DummyProfilingConnection() =
default;
40 bool IsOpen()
const override 50 bool WritePacket(
const unsigned char* buffer, uint32_t length)
override 57 arm::pipe::Packet ReadPacket(uint32_t timeout)
override 60 return std::move(*m_Packet);
65 std::unique_ptr<unsigned char[]> m_PacketData;
66 std::unique_ptr<arm::pipe::Packet> m_Packet;
69 std::vector<char> ReadDumpFile(
const std::string& dumpFileName)
71 std::ifstream input(dumpFileName, std::ios::binary);
72 return std::vector<char>(std::istreambuf_iterator<char>(input), {});
77 TEST_SUITE(
"ProfilingConnectionDumpToFileDecoratorTests")
79 TEST_CASE(
"DumpIncomingInvalidFile")
88 TEST_CASE(
"DumpIncomingInvalidFileIgnoreErrors")
97 TEST_CASE(
"DumpIncomingValidFile")
108 std::unique_ptr<arm::pipe::Packet> packet;
109 CHECK_NOTHROW(packet = std::make_unique<arm::pipe::Packet>(decorator.
ReadPacket(0)));
114 const char* packetData =
reinterpret_cast<const char*
>(packet->GetData());
117 constexpr
unsigned int bytesToSkip = 2u *
sizeof(uint32_t);
118 int diff = std::strncmp(data.data() + bytesToSkip, packetData, g_DataLength);
120 fs::remove(fileName);
123 TEST_CASE(
"DumpOutgoingInvalidFile")
132 TEST_CASE(
"DumpOutgoingInvalidFileIgnoreErrors")
139 CHECK_NOTHROW(decorator.
WritePacket(g_DataPtr, g_DataLength));
141 bool success = decorator.
WritePacket(g_DataPtr, g_DataLength);
145 TEST_CASE(
"DumpOutgoingValidFile")
155 bool success =
false;
156 CHECK_NOTHROW(success = decorator.
WritePacket(g_DataPtr, g_DataLength));
164 int diff = std::strncmp(data.data(), g_Data.data(), g_DataLength);
166 fs::remove(fileName);
TEST_SUITE("TestConstTensorLayerVisitor")
bool WritePacket(const unsigned char *buffer, uint32_t length) override
std::string m_OutgoingCaptureFile
Path to a file in which outgoing timeline profiling messages will be stored.
void IgnoreUnused(Ts &&...)
std::string m_IncomingCaptureFile
Path to a file in which incoming timeline profiling messages will be stored.
arm::pipe::Packet ReadPacket(uint32_t timeout) override
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
fs::path NamedTempFile(const char *fileName)
Returns a path to a file in the system temporary folder. If the file existed it will be deleted...