ArmNN
 20.02
ProfilingConnectionDumpToFileDecoratorTests.cpp File Reference
#include "../ProfilingConnectionDumpToFileDecorator.hpp"
#include <Runtime.hpp>
#include <armnn/utility/IgnoreUnused.hpp>
#include <fstream>
#include <sstream>
#include <boost/filesystem.hpp>
#include <boost/numeric/conversion/cast.hpp>
#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 ( DumpIncomingInvalidFile  )

Definition at line 79 of file ProfilingConnectionDumpToFileDecoratorTests.cpp.

References options, and ProfilingConnectionDumpToFileDecorator::ReadPacket().

80 {
81  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
82  options.m_IncomingCaptureFile = "/";
83  options.m_OutgoingCaptureFile = "";
84  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
85  BOOST_CHECK_THROW(decorator.ReadPacket(0), armnn::RuntimeException);
86 }
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [2/6]

BOOST_AUTO_TEST_CASE ( DumpIncomingInvalidFileIgnoreErrors  )

Definition at line 88 of file ProfilingConnectionDumpToFileDecoratorTests.cpp.

References options, and ProfilingConnectionDumpToFileDecorator::ReadPacket().

89 {
90  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
91  options.m_IncomingCaptureFile = "/";
92  options.m_OutgoingCaptureFile = "";
93  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, true);
94  BOOST_CHECK_NO_THROW(decorator.ReadPacket(0));
95 }
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [3/6]

BOOST_AUTO_TEST_CASE ( DumpIncomingValidFile  )

Definition at line 97 of file ProfilingConnectionDumpToFileDecoratorTests.cpp.

References BOOST_CHECK(), ProfilingConnectionDumpToFileDecorator::Close(), options, and ProfilingConnectionDumpToFileDecorator::ReadPacket().

98 {
99  boost::filesystem::path fileName =
100  boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
101 
102  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
103  options.m_IncomingCaptureFile = fileName.string();
104  options.m_OutgoingCaptureFile = "";
105 
106  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
107 
108  // NOTE: unique_ptr is needed here because operator=() is deleted for Packet
109  std::unique_ptr<Packet> packet;
110  BOOST_CHECK_NO_THROW(packet = std::make_unique<Packet>(decorator.ReadPacket(0)));
111 
112  decorator.Close();
113 
114  std::vector<char> data = ReadDumpFile(options.m_IncomingCaptureFile);
115  const char* packetData = reinterpret_cast<const char*>(packet->GetData());
116 
117  // check if the data read back from the dump file matches the original
118  constexpr unsigned int bytesToSkip = 2u * sizeof(uint32_t); // skip header and packet length
119  int diff = std::strncmp(data.data() + bytesToSkip, packetData, g_DataLength);
120  BOOST_CHECK(diff == 0);
121 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [4/6]

BOOST_AUTO_TEST_CASE ( DumpOutgoingInvalidFile  )

Definition at line 123 of file ProfilingConnectionDumpToFileDecoratorTests.cpp.

References options, and ProfilingConnectionDumpToFileDecorator::WritePacket().

124 {
125  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
126  options.m_IncomingCaptureFile = "";
127  options.m_OutgoingCaptureFile = "/";
128  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
129  BOOST_CHECK_THROW(decorator.WritePacket(g_DataPtr, g_DataLength), armnn::RuntimeException);
130 }
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [5/6]

BOOST_AUTO_TEST_CASE ( DumpOutgoingInvalidFileIgnoreErrors  )

Definition at line 132 of file ProfilingConnectionDumpToFileDecoratorTests.cpp.

References BOOST_CHECK(), options, and ProfilingConnectionDumpToFileDecorator::WritePacket().

133 {
134  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
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_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ 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(), BOOST_CHECK(), ProfilingConnectionDumpToFileDecorator::Close(), options, and ProfilingConnectionDumpToFileDecorator::WritePacket().

146 {
147  boost::filesystem::path fileName =
148  boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
149 
150  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
151  options.m_IncomingCaptureFile = "";
152  options.m_OutgoingCaptureFile = fileName.string();
153 
154  ProfilingConnectionDumpToFileDecorator decorator(std::make_unique<DummyProfilingConnection>(), options, false);
155 
156  bool success = false;
157  BOOST_CHECK_NO_THROW(success = decorator.WritePacket(g_DataPtr, g_DataLength));
158  BOOST_CHECK(success);
159 
160  decorator.Close();
161 
162  std::vector<char> data = ReadDumpFile(options.m_OutgoingCaptureFile);
163 
164  // check if the data read back from the dump file matches the original
165  int diff = std::strncmp(data.data(), g_Data.data(), g_DataLength);
166  BOOST_CHECK(diff == 0);
167 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options