ArmNN  NotReleased
TimelineTests.cpp File Reference
#include "../TimelineCaptureCommandHandler.hpp"
#include "../TimelineDirectoryCaptureCommandHandler.hpp"
#include "../ITimelineDecoder.h"
#include "../TimelineModel.h"
#include "TimelineTestFunctions.hpp"
#include <CommandHandlerFunctor.hpp>
#include <ProfilingService.hpp>
#include <PacketBuffer.hpp>
#include <TimelinePacketWriterFactory.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test_suite.hpp>

Go to the source code of this file.

Functions

void SendTimelinePacketToCommandHandler (const unsigned char *packetBuffer, profiling::CommandHandlerFunctor &CommandHandler)
 
 BOOST_AUTO_TEST_CASE (TimelineDirectoryTest)
 
 BOOST_AUTO_TEST_CASE (TimelineCaptureTest)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( TimelineDirectoryTest  )

Definition at line 48 of file TimelineTests.cpp.

References BOOST_CHECK(), Version::GetEncodedValue(), BufferManager::GetReadableBuffer(), TimelinePacketWriterFactory::GetSendTimelinePacket(), SwTraceMessage::m_ArgNames, SwTraceMessage::m_ArgTypes, SwTraceMessage::m_Id, SwTraceMessage::m_Name, SwTraceMessage::m_UiName, armnn::profiling::ReadSwTraceMessage(), armnn::profiling::ReadUint32(), armnn::profiling::ReadUint8(), PacketVersionResolver::ResolvePacketVersion(), SendTimelinePacketToCommandHandler(), and armnn::profiling::uint32_t_size.

49 {
50  uint32_t uint8_t_size = sizeof(uint8_t);
51  uint32_t uint32_t_size = sizeof(uint32_t);
52  uint32_t uint64_t_size = sizeof(uint64_t);
53  uint32_t threadId_size = sizeof(std::thread::id);
54 
55  profiling::BufferManager bufferManager(5);
56  profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
57 
58  std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket =
59  timelinePacketWriterFactory.GetSendTimelinePacket();
60 
61  profiling::PacketVersionResolver packetVersionResolver;
62 
63  gatordmock::TimelineDirectoryCaptureCommandHandler timelineDirectoryCaptureCommandHandler(
64  1, 0, packetVersionResolver.ResolvePacketVersion(1, 0).GetEncodedValue(), true);
65 
66  sendTimelinePacket->SendTimelineMessageDirectoryPackage();
67  sendTimelinePacket->Commit();
68 
69  std::vector<profiling::SwTraceMessage> swTraceBufferMessages;
70 
71  unsigned int offset = uint32_t_size * 2;
72 
73  std::unique_ptr<profiling::IPacketBuffer> packetBuffer = bufferManager.GetReadableBuffer();
74 
75  uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
76  BOOST_CHECK(readStreamVersion == 4);
77  offset += uint8_t_size;
78  uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
79  BOOST_CHECK(readPointerBytes == uint64_t_size);
80  offset += uint8_t_size;
81  uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
82  BOOST_CHECK(readThreadIdBytes == threadId_size);
83  offset += uint8_t_size;
84 
85  uint32_t declarationSize = profiling::ReadUint32(packetBuffer, offset);
86  offset += uint32_t_size;
87  for(uint32_t i = 0; i < declarationSize; ++i)
88  {
89  swTraceBufferMessages.push_back(profiling::ReadSwTraceMessage(packetBuffer->GetReadableData(), offset));
90  }
91 
92  SendTimelinePacketToCommandHandler(packetBuffer->GetReadableData(), timelineDirectoryCaptureCommandHandler);
93 
94  for(uint32_t index = 0; index < declarationSize; ++index)
95  {
96  profiling::SwTraceMessage& bufferMessage = swTraceBufferMessages[index];
97  profiling::SwTraceMessage& handlerMessage = timelineDirectoryCaptureCommandHandler.m_SwTraceMessages[index];
98 
99  BOOST_CHECK(bufferMessage.m_Name == handlerMessage.m_Name);
100  BOOST_CHECK(bufferMessage.m_UiName == handlerMessage.m_UiName);
101  BOOST_CHECK(bufferMessage.m_Id == handlerMessage.m_Id);
102 
103  BOOST_CHECK(bufferMessage.m_ArgTypes.size() == handlerMessage.m_ArgTypes.size());
104  for(uint32_t i = 0; i < bufferMessage.m_ArgTypes.size(); ++i)
105  {
106  BOOST_CHECK(bufferMessage.m_ArgTypes[i] == handlerMessage.m_ArgTypes[i]);
107  }
108 
109  BOOST_CHECK(bufferMessage.m_ArgNames.size() == handlerMessage.m_ArgNames.size());
110  for(uint32_t i = 0; i < bufferMessage.m_ArgNames.size(); ++i)
111  {
112  BOOST_CHECK(bufferMessage.m_ArgNames[i] == handlerMessage.m_ArgNames[i]);
113  }
114  }
115 }
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
std::vector< std::string > m_ArgNames
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
void SendTimelinePacketToCommandHandler(const unsigned char *packetBuffer, profiling::CommandHandlerFunctor &CommandHandler)
uint8_t ReadUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset)
SwTraceMessage ReadSwTraceMessage(const unsigned char *packetBuffer, unsigned int &offset)

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( TimelineCaptureTest  )

Definition at line 117 of file TimelineTests.cpp.

References BOOST_AUTO_TEST_SUITE_END(), BOOST_CHECK(), CreateModel(), DataLink, armnn::profiling::DataLink, DestroyModel(), ErrorCode_Success, Version::GetEncodedValue(), BufferManager::GetReadableBuffer(), TimelinePacketWriterFactory::GetSendTimelinePacket(), Model::m_Entities, Model::m_EventClasses, Model::m_Events, Entity::m_Guid, EventClass::m_Guid, Label::m_Guid, Relationship::m_Guid, Relationship::m_HeadGuid, Model::m_Labels, Label::m_Name, Model::m_Relationships, Relationship::m_RelationshipType, Relationship::m_TailGuid, PushEntity(), PushEvent(), PushEventClass(), PushLabel(), PushRelationship(), armnn::profiling::ReadBytes(), PacketVersionResolver::ResolvePacketVersion(), SendTimelinePacketToCommandHandler(), SetEntityCallback(), SetEventCallback(), SetEventClassCallback(), SetLabelCallback(), and SetRelationshipCallback().

118 {
119  uint32_t threadId_size = sizeof(std::thread::id);
120 
121  profiling::BufferManager bufferManager(50);
122  profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
123 
124  std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket =
125  timelinePacketWriterFactory.GetSendTimelinePacket();
126 
127  profiling::PacketVersionResolver packetVersionResolver;
128 
129  Model* modelPtr;
130  CreateModel(&modelPtr);
131 
132  gatordmock::TimelineCaptureCommandHandler timelineCaptureCommandHandler(
133  1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), modelPtr, true);
134 
140 
141  const uint64_t entityGuid = 22222u;
142 
143  const uint64_t eventClassGuid = 33333u;
144 
145  const uint64_t timestamp = 111111u;
146  const uint64_t eventGuid = 55555u;
147 
148  const std::thread::id threadId = std::this_thread::get_id();;
149 
150  const uint64_t labelGuid = 11111u;
151  std::string labelName = "test_label";
152 
153  const uint64_t relationshipGuid = 44444u;
154  const uint64_t headGuid = 111111u;
155  const uint64_t tailGuid = 222222u;
156 
157  for (int i = 0; i < 10; ++i)
158  {
159  // Send entity
160  sendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
161  sendTimelinePacket->Commit();
162  SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
163  timelineCaptureCommandHandler);
164 
165  // Send event class
166  sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassGuid);
167  sendTimelinePacket->Commit();
168  SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
169  timelineCaptureCommandHandler);
170 
171  // Send event
172  sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
173  sendTimelinePacket->Commit();
174  SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
175  timelineCaptureCommandHandler);
176 
177  // Send label
178  sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
179  sendTimelinePacket->Commit();
180  SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
181  timelineCaptureCommandHandler);
182 
183  // Send relationship
185  sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
186  relationshipGuid,
187  headGuid,
188  tailGuid);
189  sendTimelinePacket->Commit();
190  SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
191  timelineCaptureCommandHandler);
192  }
193 
194  for (int i = 0; i < 10; ++i)
195  {
196  BOOST_CHECK(modelPtr->m_Entities[i]->m_Guid == entityGuid);
197 
198  BOOST_CHECK(modelPtr->m_EventClasses[i]->m_Guid == eventClassGuid);
199 
200  BOOST_CHECK(modelPtr->m_Events[i]->m_TimeStamp == timestamp);
201 
202  std::vector<uint8_t> readThreadId(threadId_size, 0);
203  profiling::ReadBytes(modelPtr->m_Events[i]->m_ThreadId, 0, threadId_size, readThreadId.data());
204  BOOST_CHECK(readThreadId == threadId);
205 
206  BOOST_CHECK(modelPtr->m_Events[i]->m_Guid == eventGuid);
207 
208  BOOST_CHECK(modelPtr->m_Labels[i]->m_Guid == labelGuid);
209  BOOST_CHECK(std::string(modelPtr->m_Labels[i]->m_Name) == labelName);
210 
212  BOOST_CHECK(modelPtr->m_Relationships[i]->m_Guid == relationshipGuid);
213  BOOST_CHECK(modelPtr->m_Relationships[i]->m_HeadGuid == headGuid);
214  BOOST_CHECK(modelPtr->m_Relationships[i]->m_TailGuid == tailGuid);
215  }
216 
217  DestroyModel(&modelPtr);
218 }
void PushEntity(const Entity entity, Model *model)
ErrorCode SetRelationshipCallback(OnNewRelationshipCallback cb, Model *model)
void PushRelationship(const Relationship relationship, Model *model)
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
EventClass ** m_EventClasses
Definition: TimelineModel.h:71
Event ** m_Events
Definition: TimelineModel.h:72
char * m_Name
Definition: TimelineModel.h:45
uint64_t m_Guid
Definition: TimelineModel.h:27
void PushEventClass(const EventClass eventClass, Model *model)
void PushLabel(const Label label, Model *model)
ErrorCode SetEventClassCallback(OnNewEventClassCallback cb, Model *model)
void PushEvent(const Event event, Model *model)
ErrorCode SetLabelCallback(OnNewLabelCallback cb, Model *model)
Head execution start depends on Tail execution completion.
Definition: TimelineModel.h:21
ErrorCode DestroyModel(Model **model)
uint64_t m_Guid
Definition: TimelineModel.h:44
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint64_t m_TailGuid
Definition: TimelineModel.h:53
RelationshipType m_RelationshipType
Definition: TimelineModel.h:50
ErrorCode SetEventCallback(OnNewEventCallback cb, Model *model)
void ReadBytes(const IPacketBufferPtr &packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[])
Relationship ** m_Relationships
Definition: TimelineModel.h:74
ErrorCode SetEntityCallback(OnNewEntityCallback cb, Model *model)
void SendTimelinePacketToCommandHandler(const unsigned char *packetBuffer, profiling::CommandHandlerFunctor &CommandHandler)
Entity ** m_Entities
Definition: TimelineModel.h:70
uint64_t m_Guid
Definition: TimelineModel.h:51
uint64_t m_Guid
Definition: TimelineModel.h:32
uint64_t m_HeadGuid
Definition: TimelineModel.h:52
ErrorCode CreateModel(Model **model)
Label ** m_Labels
Definition: TimelineModel.h:73

◆ SendTimelinePacketToCommandHandler()

void SendTimelinePacketToCommandHandler ( const unsigned char *  packetBuffer,
profiling::CommandHandlerFunctor CommandHandler 
)

Definition at line 24 of file TimelineTests.cpp.

References BOOST_CHECK(), armnn::profiling::ReadUint32(), and armnn::profiling::uint32_t_size.

Referenced by BOOST_AUTO_TEST_CASE().

26 {
27  uint32_t uint32_t_size = sizeof(uint32_t);
28  unsigned int offset = 0;
29 
30  uint32_t header[2];
31  header[0] = profiling::ReadUint32(packetBuffer, offset);
32  offset += uint32_t_size;
33  header[1] = profiling::ReadUint32(packetBuffer, offset);
34  offset += uint32_t_size;
35 
36  uint32_t PacketDataLength = header[1] & 0x00FFFFFF;
37 
38  auto uniquePacketData = std::make_unique<unsigned char[]>(PacketDataLength);
39  std::memcpy(uniquePacketData.get(), packetBuffer + offset, PacketDataLength);
40 
41  armnn::profiling::Packet packet(header[0], PacketDataLength, uniquePacketData);
42 
43  BOOST_CHECK(std::memcmp(packetBuffer + offset, packet.GetData(), packet.GetLength()) == 0);
44 
45  CommandHandler(packet);
46 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)