ArmNN
 21.02
ProfilingConnectionDumpToFileDecoratorTests.cpp File Reference
#include "../ProfilingConnectionDumpToFileDecorator.hpp"
#include <Filesystem.hpp>
#include <Runtime.hpp>
#include <armnn/utility/IgnoreUnused.hpp>
#include <armnn/utility/NumericCast.hpp>
#include <fstream>
#include <sstream>
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (DumpIncomingInvalidFile)
 
 BOOST_AUTO_TEST_CASE (DumpIncomingInvalidFileIgnoreErrors)
 
 BOOST_AUTO_TEST_CASE (DumpIncomingValidFile)
 
 BOOST_AUTO_TEST_CASE (DumpOutgoingInvalidFile)
 
 BOOST_AUTO_TEST_CASE (DumpOutgoingInvalidFileIgnoreErrors)
 
 BOOST_AUTO_TEST_CASE (DumpOutgoingValidFile)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/6]

◆ BOOST_AUTO_TEST_CASE() [2/6]

◆ BOOST_AUTO_TEST_CASE() [3/6]

BOOST_AUTO_TEST_CASE ( DumpIncomingValidFile  )

Definition at line 97 of file ProfilingConnectionDumpToFileDecoratorTests.cpp.

References ProfilingConnectionDumpToFileDecorator::Close(), IRuntime::CreationOptions::ExternalProfilingOptions::m_IncomingCaptureFile, IRuntime::CreationOptions::ExternalProfilingOptions::m_OutgoingCaptureFile, armnnUtils::Filesystem::NamedTempFile(), and ProfilingConnectionDumpToFileDecorator::ReadPacket().

98 {
99  fs::path fileName = armnnUtils::Filesystem::NamedTempFile("Armnn-DumpIncomingValidFileTest-TempFile");
100 
102  options.m_IncomingCaptureFile = fileName.string();
103  options.m_OutgoingCaptureFile = "";
104 
105  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
106 
107  // NOTE: unique_ptr is needed here because operator=() is deleted for Packet
108  std::unique_ptr<arm::pipe::Packet> packet;
109  BOOST_CHECK_NO_THROW(packet = std::make_unique<arm::pipe::Packet>(decorator.ReadPacket(0)));
110 
111  decorator.Close();
112 
113  std::vector<char> data = ReadDumpFile(options.m_IncomingCaptureFile);
114  const char* packetData = reinterpret_cast<const char*>(packet->GetData());
115 
116  // check if the data read back from the dump file matches the original
117  constexpr unsigned int bytesToSkip = 2u * sizeof(uint32_t); // skip header and packet length
118  int diff = std::strncmp(data.data() + bytesToSkip, packetData, g_DataLength);
119  BOOST_CHECK(diff == 0);
120  fs::remove(fileName);
121 }
fs::path NamedTempFile(const char *fileName)
Construct a temporary file name.
Definition: Filesystem.cpp:23

◆ BOOST_AUTO_TEST_CASE() [4/6]

◆ BOOST_AUTO_TEST_CASE() [5/6]

BOOST_AUTO_TEST_CASE ( DumpOutgoingInvalidFileIgnoreErrors  )

Definition at line 132 of file ProfilingConnectionDumpToFileDecoratorTests.cpp.

References IRuntime::CreationOptions::ExternalProfilingOptions::m_IncomingCaptureFile, IRuntime::CreationOptions::ExternalProfilingOptions::m_OutgoingCaptureFile, and ProfilingConnectionDumpToFileDecorator::WritePacket().

133 {
135  options.m_IncomingCaptureFile = "";
136  options.m_OutgoingCaptureFile = "/";
137 
138  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, true);
139  BOOST_CHECK_NO_THROW(decorator.WritePacket(g_DataPtr, g_DataLength));
140 
141  bool success = decorator.WritePacket(g_DataPtr, g_DataLength);
142  BOOST_CHECK(!success);
143 }

◆ BOOST_AUTO_TEST_CASE() [6/6]

BOOST_AUTO_TEST_CASE ( DumpOutgoingValidFile  )

Definition at line 145 of file ProfilingConnectionDumpToFileDecoratorTests.cpp.

References BOOST_AUTO_TEST_SUITE_END(), ProfilingConnectionDumpToFileDecorator::Close(), IRuntime::CreationOptions::ExternalProfilingOptions::m_IncomingCaptureFile, IRuntime::CreationOptions::ExternalProfilingOptions::m_OutgoingCaptureFile, armnnUtils::Filesystem::NamedTempFile(), and ProfilingConnectionDumpToFileDecorator::WritePacket().

146 {
147  fs::path fileName = armnnUtils::Filesystem::NamedTempFile("Armnn-DumpOutgoingValidFileTest-TempFile");
148 
150  options.m_IncomingCaptureFile = "";
151  options.m_OutgoingCaptureFile = fileName.string();
152 
153  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
154 
155  bool success = false;
156  BOOST_CHECK_NO_THROW(success = decorator.WritePacket(g_DataPtr, g_DataLength));
157  BOOST_CHECK(success);
158 
159  decorator.Close();
160 
161  std::vector<char> data = ReadDumpFile(options.m_OutgoingCaptureFile);
162 
163  // check if the data read back from the dump file matches the original
164  int diff = std::strncmp(data.data(), g_Data.data(), g_DataLength);
165  BOOST_CHECK(diff == 0);
166  fs::remove(fileName);
167 }
fs::path NamedTempFile(const char *fileName)
Construct a temporary file name.
Definition: Filesystem.cpp:23