blob: e7797061c966a7fe417c13ee30124b88158ede76 [file] [log] [blame]
Finn Williamse63a0262019-10-22 10:30:49 +01001//
Jim Flynn1fdeb992020-07-09 07:28:37 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Finn Williamse63a0262019-10-22 10:30:49 +01003// SPDX-License-Identifier: MIT
4//
5
Jim Flynnbbfe6032020-07-20 16:57:44 +01006#include <common/include/CommandHandlerFunctor.hpp>
7#include <common/include/CommonProfilingUtils.hpp>
8#include <server/include/timelineDecoder/TimelineCaptureCommandHandler.hpp>
9#include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp>
10#include <server/include/timelineDecoder/TimelineDecoder.hpp>
Finn Williamse63a0262019-10-22 10:30:49 +010011
Jim Flynnbbfe6032020-07-20 16:57:44 +010012#include <BufferManager.hpp>
Jim Flynn1fdeb992020-07-09 07:28:37 +010013#include <Threads.hpp>
Finn Williamse63a0262019-10-22 10:30:49 +010014#include <ProfilingService.hpp>
15#include <PacketBuffer.hpp>
16#include <TimelinePacketWriterFactory.hpp>
17
18#include <boost/test/test_tools.hpp>
19#include <boost/test/unit_test_suite.hpp>
20
21BOOST_AUTO_TEST_SUITE(TimelineDecoderTests)
22
Finn Williamse63a0262019-10-22 10:30:49 +010023void SendTimelinePacketToCommandHandler(const unsigned char* packetBuffer,
Jim Flynnbbfe6032020-07-20 16:57:44 +010024 arm::pipe::CommandHandlerFunctor& CommandHandler)
Finn Williamse63a0262019-10-22 10:30:49 +010025{
26 uint32_t uint32_t_size = sizeof(uint32_t);
27 unsigned int offset = 0;
28
29 uint32_t header[2];
Jim Flynnbbfe6032020-07-20 16:57:44 +010030 header[0] = arm::pipe::ReadUint32(packetBuffer, offset);
Finn Williamse63a0262019-10-22 10:30:49 +010031 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010032 header[1] = arm::pipe::ReadUint32(packetBuffer, offset);
Finn Williamse63a0262019-10-22 10:30:49 +010033 offset += uint32_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +010034 uint32_t PacketDataLength = header[1] & 0x00FFFFFF;
35
Matteo Martincigh34a407d2019-11-06 15:30:54 +000036 auto uniquePacketData = std::make_unique<unsigned char[]>(PacketDataLength);
Finn Williamse63a0262019-10-22 10:30:49 +010037 std::memcpy(uniquePacketData.get(), packetBuffer + offset, PacketDataLength);
38
Jim Flynnbbfe6032020-07-20 16:57:44 +010039 arm::pipe::Packet packet(header[0], PacketDataLength, uniquePacketData);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000040
41 BOOST_CHECK(std::memcmp(packetBuffer + offset, packet.GetData(), packet.GetLength()) == 0);
Finn Williamse63a0262019-10-22 10:30:49 +010042
43 CommandHandler(packet);
44}
45
Jim Flynnbbfe6032020-07-20 16:57:44 +010046void PushEntity(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::Entity entity)
Finn Williams510f6182020-02-21 11:14:08 +000047{
48 model.m_Entities.emplace_back(entity);
49}
50
Jim Flynnbbfe6032020-07-20 16:57:44 +010051void PushEventClass(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::EventClass eventClass)
Finn Williams510f6182020-02-21 11:14:08 +000052{
53 model.m_EventClasses.emplace_back(eventClass);
54}
55
Jim Flynnbbfe6032020-07-20 16:57:44 +010056void PushEvent(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::Event event)
Finn Williams510f6182020-02-21 11:14:08 +000057{
58 model.m_Events.emplace_back(event);
59}
60
Jim Flynnbbfe6032020-07-20 16:57:44 +010061void PushLabel(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::Label label)
Finn Williams510f6182020-02-21 11:14:08 +000062{
63 model.m_Labels.emplace_back(label);
64}
65
Jim Flynnbbfe6032020-07-20 16:57:44 +010066void PushRelationship(arm::pipe::TimelineDecoder::Model& model,
67 const arm::pipe::ITimelineDecoder::Relationship relationship)
Finn Williams510f6182020-02-21 11:14:08 +000068{
69 model.m_Relationships.emplace_back(relationship);
70}
71
Matteo Martincigh34a407d2019-11-06 15:30:54 +000072BOOST_AUTO_TEST_CASE(TimelineDirectoryTest)
Finn Williamse63a0262019-10-22 10:30:49 +010073{
Matteo Martincigh34a407d2019-11-06 15:30:54 +000074 uint32_t uint8_t_size = sizeof(uint8_t);
Finn Williamse63a0262019-10-22 10:30:49 +010075 uint32_t uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000076 uint32_t uint64_t_size = sizeof(uint64_t);
Finn Williamse63a0262019-10-22 10:30:49 +010077
Jim Flynnbbfe6032020-07-20 16:57:44 +010078 armnn::profiling::BufferManager bufferManager(5);
79 armnn::profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
Finn Williamse63a0262019-10-22 10:30:49 +010080
Jim Flynnbbfe6032020-07-20 16:57:44 +010081 std::unique_ptr<armnn::profiling::ISendTimelinePacket> sendTimelinePacket =
Finn Williamse63a0262019-10-22 10:30:49 +010082 timelinePacketWriterFactory.GetSendTimelinePacket();
83
Jim Flynnbbfe6032020-07-20 16:57:44 +010084 arm::pipe::PacketVersionResolver packetVersionResolver;
Finn Williamse63a0262019-10-22 10:30:49 +010085
Jim Flynnbbfe6032020-07-20 16:57:44 +010086 arm::pipe::TimelineDecoder timelineDecoder;
87 arm::pipe::TimelineCaptureCommandHandler timelineCaptureCommandHandler(
Finn Williamse6a2ccd2020-02-27 16:21:41 +000088 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder);
89
Jim Flynnbbfe6032020-07-20 16:57:44 +010090 arm::pipe::TimelineDirectoryCaptureCommandHandler timelineDirectoryCaptureCommandHandler(
Finn Williamse6a2ccd2020-02-27 16:21:41 +000091 1, 0, packetVersionResolver.ResolvePacketVersion(1, 0).GetEncodedValue(),
92 timelineCaptureCommandHandler, true);
Finn Williamse63a0262019-10-22 10:30:49 +010093
94 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
95 sendTimelinePacket->Commit();
96
Jim Flynnbbfe6032020-07-20 16:57:44 +010097 std::vector<arm::pipe::SwTraceMessage> swTraceBufferMessages;
Finn Williamse63a0262019-10-22 10:30:49 +010098
99 unsigned int offset = uint32_t_size * 2;
100
Jim Flynnbbfe6032020-07-20 16:57:44 +0100101 std::unique_ptr<armnn::profiling::IPacketBuffer> packetBuffer = bufferManager.GetReadableBuffer();
Finn Williamse63a0262019-10-22 10:30:49 +0100102
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000103 uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
104 BOOST_CHECK(readStreamVersion == 4);
105 offset += uint8_t_size;
106 uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
107 BOOST_CHECK(readPointerBytes == uint64_t_size);
108 offset += uint8_t_size;
109 uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100110 BOOST_CHECK(readThreadIdBytes == armnn::profiling::ThreadIdSize);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000111 offset += uint8_t_size;
112
Jim Flynnbbfe6032020-07-20 16:57:44 +0100113 uint32_t declarationSize = arm::pipe::ReadUint32(packetBuffer->GetReadableData(), offset);
Finn Williamse63a0262019-10-22 10:30:49 +0100114 offset += uint32_t_size;
115 for(uint32_t i = 0; i < declarationSize; ++i)
116 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100117 swTraceBufferMessages.push_back(arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
Kevin Mayc1351792020-07-28 11:29:04 +0100118 offset,
119 packetBuffer->GetSize()));
Finn Williamse63a0262019-10-22 10:30:49 +0100120 }
121
122 SendTimelinePacketToCommandHandler(packetBuffer->GetReadableData(), timelineDirectoryCaptureCommandHandler);
123
124 for(uint32_t index = 0; index < declarationSize; ++index)
125 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100126 arm::pipe::SwTraceMessage& bufferMessage = swTraceBufferMessages[index];
127 arm::pipe::SwTraceMessage& handlerMessage = timelineDirectoryCaptureCommandHandler.m_SwTraceMessages[index];
Finn Williamse63a0262019-10-22 10:30:49 +0100128
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000129 BOOST_CHECK(bufferMessage.m_Name == handlerMessage.m_Name);
130 BOOST_CHECK(bufferMessage.m_UiName == handlerMessage.m_UiName);
131 BOOST_CHECK(bufferMessage.m_Id == handlerMessage.m_Id);
Finn Williamse63a0262019-10-22 10:30:49 +0100132
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000133 BOOST_CHECK(bufferMessage.m_ArgTypes.size() == handlerMessage.m_ArgTypes.size());
134 for(uint32_t i = 0; i < bufferMessage.m_ArgTypes.size(); ++i)
Finn Williamse63a0262019-10-22 10:30:49 +0100135 {
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000136 BOOST_CHECK(bufferMessage.m_ArgTypes[i] == handlerMessage.m_ArgTypes[i]);
Finn Williamse63a0262019-10-22 10:30:49 +0100137 }
138
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000139 BOOST_CHECK(bufferMessage.m_ArgNames.size() == handlerMessage.m_ArgNames.size());
140 for(uint32_t i = 0; i < bufferMessage.m_ArgNames.size(); ++i)
Finn Williamse63a0262019-10-22 10:30:49 +0100141 {
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000142 BOOST_CHECK(bufferMessage.m_ArgNames[i] == handlerMessage.m_ArgNames[i]);
Finn Williamse63a0262019-10-22 10:30:49 +0100143 }
144 }
145}
146
147BOOST_AUTO_TEST_CASE(TimelineCaptureTest)
148{
Jim Flynnbbfe6032020-07-20 16:57:44 +0100149 armnn::profiling::BufferManager bufferManager(50);
150 armnn::profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
Finn Williamse63a0262019-10-22 10:30:49 +0100151
Jim Flynnbbfe6032020-07-20 16:57:44 +0100152 std::unique_ptr<armnn::profiling::ISendTimelinePacket> sendTimelinePacket =
Finn Williamse63a0262019-10-22 10:30:49 +0100153 timelinePacketWriterFactory.GetSendTimelinePacket();
154
Jim Flynnbbfe6032020-07-20 16:57:44 +0100155 arm::pipe::PacketVersionResolver packetVersionResolver;
Finn Williamse63a0262019-10-22 10:30:49 +0100156
Jim Flynnbbfe6032020-07-20 16:57:44 +0100157 arm::pipe::TimelineDecoder timelineDecoder;
158 const arm::pipe::TimelineDecoder::Model& model = timelineDecoder.GetModel();
Finn Williamse63a0262019-10-22 10:30:49 +0100159
Finn Williamse6a2ccd2020-02-27 16:21:41 +0000160
Jim Flynnbbfe6032020-07-20 16:57:44 +0100161 arm::pipe::TimelineCaptureCommandHandler timelineCaptureCommandHandler(
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100162 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder,
163 armnn::profiling::ThreadIdSize);
Finn Williamse63a0262019-10-22 10:30:49 +0100164
Jim Flynnbbfe6032020-07-20 16:57:44 +0100165 using Status = arm::pipe::ITimelineDecoder::TimelineStatus;
Keith Davis97da5e22020-03-05 16:25:28 +0000166 BOOST_CHECK(timelineDecoder.SetEntityCallback(PushEntity) == Status::TimelineStatus_Success);
167 BOOST_CHECK(timelineDecoder.SetEventClassCallback(PushEventClass) == Status::TimelineStatus_Success);
168 BOOST_CHECK(timelineDecoder.SetEventCallback(PushEvent) == Status::TimelineStatus_Success);
169 BOOST_CHECK(timelineDecoder.SetLabelCallback(PushLabel) == Status::TimelineStatus_Success);
170 BOOST_CHECK(timelineDecoder.SetRelationshipCallback(PushRelationship) == Status::TimelineStatus_Success);
Finn Williamse63a0262019-10-22 10:30:49 +0100171
Keith Davis97da5e22020-03-05 16:25:28 +0000172 const uint64_t entityGuid = 111111u;
Finn Williams510f6182020-02-21 11:14:08 +0000173 const uint64_t eventClassGuid = 22222u;
Jim Flynn1892d212020-05-26 21:10:49 +0100174 const uint64_t eventClassNameGuid = 22322u;
Finn Williams510f6182020-02-21 11:14:08 +0000175 const uint64_t timestamp = 33333u;
176 const uint64_t eventGuid = 44444u;
Finn Williamse63a0262019-10-22 10:30:49 +0100177
Jim Flynn1fdeb992020-07-09 07:28:37 +0100178 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Finn Williamse63a0262019-10-22 10:30:49 +0100179
Finn Williams510f6182020-02-21 11:14:08 +0000180 // need to do a bit of work here to extract the value from threadId
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100181 unsigned char* uCharThreadId = new unsigned char[armnn::profiling::ThreadIdSize]();;
Finn Williams510f6182020-02-21 11:14:08 +0000182 uint64_t uint64ThreadId;
Finn Williamse63a0262019-10-22 10:30:49 +0100183
Jim Flynnbbfe6032020-07-20 16:57:44 +0100184 arm::pipe::WriteBytes(uCharThreadId, 0, &threadId, armnn::profiling::ThreadIdSize);
Finn Williamse63a0262019-10-22 10:30:49 +0100185
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100186 if (armnn::profiling::ThreadIdSize == 4)
Finn Williams510f6182020-02-21 11:14:08 +0000187 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100188 uint64ThreadId = arm::pipe::ReadUint32(uCharThreadId, 0);
Finn Williams510f6182020-02-21 11:14:08 +0000189 }
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100190 else if (armnn::profiling::ThreadIdSize == 8)
Finn Williams510f6182020-02-21 11:14:08 +0000191 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100192 uint64ThreadId = arm::pipe::ReadUint64(uCharThreadId, 0);
Finn Williams510f6182020-02-21 11:14:08 +0000193 }
194 delete[] uCharThreadId;
195
196 const uint64_t labelGuid = 66666u;
Finn Williamse63a0262019-10-22 10:30:49 +0100197 std::string labelName = "test_label";
198
Finn Williams510f6182020-02-21 11:14:08 +0000199 const uint64_t relationshipGuid = 77777u;
200 const uint64_t headGuid = 888888u;
201 const uint64_t tailGuid = 999999u;
Finn Williamse63a0262019-10-22 10:30:49 +0100202
203 for (int i = 0; i < 10; ++i)
204 {
205 // Send entity
206 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
207 sendTimelinePacket->Commit();
208 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
209 timelineCaptureCommandHandler);
210
211 // Send event class
Jim Flynn1892d212020-05-26 21:10:49 +0100212 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassGuid, eventClassNameGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100213 sendTimelinePacket->Commit();
214 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
215 timelineCaptureCommandHandler);
216
217 // Send event
218 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
219 sendTimelinePacket->Commit();
220 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
221 timelineCaptureCommandHandler);
222
223 // Send label
224 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
225 sendTimelinePacket->Commit();
226 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
227 timelineCaptureCommandHandler);
228
229 // Send relationship
Jim Flynnbbfe6032020-07-20 16:57:44 +0100230 armnn::profiling::ProfilingRelationshipType relationshipType =
231 armnn::profiling::ProfilingRelationshipType::DataLink;
Finn Williamse63a0262019-10-22 10:30:49 +0100232 sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
233 relationshipGuid,
234 headGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100235 tailGuid,
236 0);
Finn Williamse63a0262019-10-22 10:30:49 +0100237 sendTimelinePacket->Commit();
238 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
239 timelineCaptureCommandHandler);
240 }
241
Finn Williams510f6182020-02-21 11:14:08 +0000242 for (unsigned long i = 0; i < 10; ++i)
Finn Williamse63a0262019-10-22 10:30:49 +0100243 {
Finn Williams510f6182020-02-21 11:14:08 +0000244 BOOST_CHECK(model.m_Entities[i].m_Guid == entityGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100245
Finn Williams510f6182020-02-21 11:14:08 +0000246 BOOST_CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100247
Finn Williams510f6182020-02-21 11:14:08 +0000248 BOOST_CHECK(model.m_Events[i].m_TimeStamp == timestamp);
249 BOOST_CHECK(model.m_Events[i].m_ThreadId == uint64ThreadId);
250 BOOST_CHECK(model.m_Events[i].m_Guid == eventGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100251
Finn Williams510f6182020-02-21 11:14:08 +0000252 BOOST_CHECK(model.m_Labels[i].m_Guid == labelGuid);
253 BOOST_CHECK(model.m_Labels[i].m_Name == labelName);
Finn Williamse63a0262019-10-22 10:30:49 +0100254
Jim Flynnbbfe6032020-07-20 16:57:44 +0100255 BOOST_CHECK(model.m_Relationships[i].m_RelationshipType ==
256 arm::pipe::ITimelineDecoder::RelationshipType::DataLink);
Finn Williams510f6182020-02-21 11:14:08 +0000257 BOOST_CHECK(model.m_Relationships[i].m_Guid == relationshipGuid);
258 BOOST_CHECK(model.m_Relationships[i].m_HeadGuid == headGuid);
259 BOOST_CHECK(model.m_Relationships[i].m_TailGuid == tailGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100260 }
Finn Williamse63a0262019-10-22 10:30:49 +0100261}
262
Keith Davis5238aff2020-03-11 12:17:05 +0000263BOOST_AUTO_TEST_CASE(TimelineCaptureTestMultipleStringsInBuffer)
264{
Jim Flynnbbfe6032020-07-20 16:57:44 +0100265 armnn::profiling::BufferManager bufferManager(50);
266 armnn::profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
Keith Davis5238aff2020-03-11 12:17:05 +0000267
Jim Flynnbbfe6032020-07-20 16:57:44 +0100268 std::unique_ptr<armnn::profiling::ISendTimelinePacket> sendTimelinePacket =
Keith Davis5238aff2020-03-11 12:17:05 +0000269 timelinePacketWriterFactory.GetSendTimelinePacket();
270
Jim Flynnbbfe6032020-07-20 16:57:44 +0100271 arm::pipe::PacketVersionResolver packetVersionResolver;
Keith Davis5238aff2020-03-11 12:17:05 +0000272
Jim Flynnbbfe6032020-07-20 16:57:44 +0100273 arm::pipe::TimelineDecoder timelineDecoder;
274 const arm::pipe::TimelineDecoder::Model& model = timelineDecoder.GetModel();
Keith Davis5238aff2020-03-11 12:17:05 +0000275
Jim Flynnbbfe6032020-07-20 16:57:44 +0100276 arm::pipe::TimelineCaptureCommandHandler timelineCaptureCommandHandler(
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100277 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder,
278 armnn::profiling::ThreadIdSize);
Keith Davis5238aff2020-03-11 12:17:05 +0000279
Jim Flynnbbfe6032020-07-20 16:57:44 +0100280 using Status = arm::pipe::TimelineDecoder::TimelineStatus;
Keith Davis5238aff2020-03-11 12:17:05 +0000281 BOOST_CHECK(timelineDecoder.SetEntityCallback(PushEntity) == Status::TimelineStatus_Success);
282 BOOST_CHECK(timelineDecoder.SetEventClassCallback(PushEventClass) == Status::TimelineStatus_Success);
283 BOOST_CHECK(timelineDecoder.SetEventCallback(PushEvent) == Status::TimelineStatus_Success);
284 BOOST_CHECK(timelineDecoder.SetLabelCallback(PushLabel) == Status::TimelineStatus_Success);
285 BOOST_CHECK(timelineDecoder.SetRelationshipCallback(PushRelationship) == Status::TimelineStatus_Success);
286
Jim Flynn1892d212020-05-26 21:10:49 +0100287 const uint64_t entityGuid = 111111u;
288 const uint64_t eventClassGuid = 22222u;
289 const uint64_t eventClassNameGuid = 22322u;
290 const uint64_t timestamp = 33333u;
291 const uint64_t eventGuid = 44444u;
Keith Davis5238aff2020-03-11 12:17:05 +0000292
Jim Flynn1fdeb992020-07-09 07:28:37 +0100293 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Keith Davis5238aff2020-03-11 12:17:05 +0000294
295 // need to do a bit of work here to extract the value from threadId
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100296 unsigned char* uCharThreadId = new unsigned char[armnn::profiling::ThreadIdSize]();
Keith Davis5238aff2020-03-11 12:17:05 +0000297 uint64_t uint64ThreadId;
298
Jim Flynnbbfe6032020-07-20 16:57:44 +0100299 arm::pipe::WriteBytes(uCharThreadId, 0, &threadId, armnn::profiling::ThreadIdSize);
Keith Davis5238aff2020-03-11 12:17:05 +0000300
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100301 if ( armnn::profiling::ThreadIdSize == 4 )
Keith Davis5238aff2020-03-11 12:17:05 +0000302 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100303 uint64ThreadId = arm::pipe::ReadUint32(uCharThreadId, 0);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100304 }
305 else if ( armnn::profiling::ThreadIdSize == 8 )
Keith Davis5238aff2020-03-11 12:17:05 +0000306 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100307 uint64ThreadId = arm::pipe::ReadUint64(uCharThreadId, 0);
Keith Davis5238aff2020-03-11 12:17:05 +0000308 }
309 delete[] uCharThreadId;
310
311 const uint64_t labelGuid = 66666u;
312 std::string labelName = "test_label";
313 std::string labelName2 = "test_label2";
314 std::string labelName3 = "test_label32";
315
316 const uint64_t relationshipGuid = 77777u;
317 const uint64_t headGuid = 888888u;
318 const uint64_t tailGuid = 999999u;
319
320 // Check with multiple messages in the same buffer
321 for ( int i = 0; i < 9; ++i )
322 {
323 // Send entity
324 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
325 // Send event class
Jim Flynn1892d212020-05-26 21:10:49 +0100326 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassGuid, eventClassNameGuid);
Keith Davis5238aff2020-03-11 12:17:05 +0000327 // Send event
328 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
329 // Send label
330 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
331 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName2);
332 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName3);
333 // Send relationship
Jim Flynnbbfe6032020-07-20 16:57:44 +0100334 armnn::profiling::ProfilingRelationshipType relationshipType =
335 armnn::profiling::ProfilingRelationshipType::DataLink;
Keith Davis5238aff2020-03-11 12:17:05 +0000336 sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
337 relationshipGuid,
338 headGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100339 tailGuid,
340 0);
Keith Davis5238aff2020-03-11 12:17:05 +0000341 }
342
343 sendTimelinePacket->Commit();
344 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
345 timelineCaptureCommandHandler);
346
347 for ( unsigned long i = 0; i < 9; ++i )
348 {
349 BOOST_CHECK(model.m_Entities[i].m_Guid == entityGuid);
350
351 BOOST_CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid);
352
353 BOOST_CHECK(model.m_Labels[i].m_Guid == labelGuid);
354
355 BOOST_CHECK(model.m_Events[i].m_TimeStamp == timestamp);
356 BOOST_CHECK(model.m_Events[i].m_ThreadId == uint64ThreadId);
357 BOOST_CHECK(model.m_Events[i].m_Guid == eventGuid);
358
Jim Flynnbbfe6032020-07-20 16:57:44 +0100359 BOOST_CHECK(model.m_Relationships[i].m_RelationshipType ==
360 arm::pipe::ITimelineDecoder::RelationshipType::DataLink);
Keith Davis5238aff2020-03-11 12:17:05 +0000361 BOOST_CHECK(model.m_Relationships[i].m_Guid == relationshipGuid);
362 BOOST_CHECK(model.m_Relationships[i].m_HeadGuid == headGuid);
363 BOOST_CHECK(model.m_Relationships[i].m_TailGuid == tailGuid);
364 }
365 for ( unsigned long i = 0; i < 9; i += 3 )
366 {
367 BOOST_CHECK(model.m_Labels[i].m_Name == labelName);
368 BOOST_CHECK(model.m_Labels[i+1].m_Name == labelName2);
369 BOOST_CHECK(model.m_Labels[i+2].m_Name == labelName3);
370 }
371}
372
Finn Williamse63a0262019-10-22 10:30:49 +0100373BOOST_AUTO_TEST_SUITE_END()