ArmNN
 22.02
ProfilingConnectionDumpToFileDecoratorTests.cpp File Reference
#include "../ProfilingConnectionDumpToFileDecorator.hpp"
#include <armnnUtils/Filesystem.hpp>
#include <Runtime.hpp>
#include <armnn/utility/IgnoreUnused.hpp>
#include <armnn/utility/NumericCast.hpp>
#include <fstream>
#include <sstream>
#include <doctest/doctest.h>

Go to the source code of this file.

Functions

 TEST_SUITE ("ProfilingConnectionDumpToFileDecoratorTests")
 

Function Documentation

◆ TEST_SUITE()

TEST_SUITE ( "ProfilingConnectionDumpToFileDecoratorTests"  )

Definition at line 77 of file ProfilingConnectionDumpToFileDecoratorTests.cpp.

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

78 {
79 TEST_CASE("DumpIncomingInvalidFile")
80 {
82  options.m_IncomingCaptureFile = "/";
83  options.m_OutgoingCaptureFile = "";
84  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
85  CHECK_THROWS_AS(decorator.ReadPacket(0), armnn::RuntimeException);
86 }
87 
88 TEST_CASE("DumpIncomingInvalidFileIgnoreErrors")
89 {
91  options.m_IncomingCaptureFile = "/";
92  options.m_OutgoingCaptureFile = "";
93  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, true);
94  CHECK_NOTHROW(decorator.ReadPacket(0));
95 }
96 
97 TEST_CASE("DumpIncomingValidFile")
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  CHECK_NOTHROW(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  CHECK(diff == 0);
120  fs::remove(fileName);
121 }
122 
123 TEST_CASE("DumpOutgoingInvalidFile")
124 {
126  options.m_IncomingCaptureFile = "";
127  options.m_OutgoingCaptureFile = "/";
128  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
129  CHECK_THROWS_AS(decorator.WritePacket(g_DataPtr, g_DataLength), armnn::RuntimeException);
130 }
131 
132 TEST_CASE("DumpOutgoingInvalidFileIgnoreErrors")
133 {
135  options.m_IncomingCaptureFile = "";
136  options.m_OutgoingCaptureFile = "/";
137 
138  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, true);
139  CHECK_NOTHROW(decorator.WritePacket(g_DataPtr, g_DataLength));
140 
141  bool success = decorator.WritePacket(g_DataPtr, g_DataLength);
142  CHECK(!success);
143 }
144 
145 TEST_CASE("DumpOutgoingValidFile")
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  CHECK_NOTHROW(success = decorator.WritePacket(g_DataPtr, g_DataLength));
157  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  CHECK(diff == 0);
166  fs::remove(fileName);
167 }
168 
169 }
std::string m_OutgoingCaptureFile
Path to a file in which outgoing timeline profiling messages will be stored.
Definition: IRuntime.hpp:140
std::string m_IncomingCaptureFile
Path to a file in which incoming timeline profiling messages will be stored.
Definition: IRuntime.hpp:142
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...
Definition: Filesystem.cpp:23