blob: 8071eece7dfd71a9149361c06def5cf84a4e9f55 [file] [log] [blame]
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "SendCounterPacketTests.hpp"
7
8#include <BufferManager.hpp>
Jim Flynn00f3aaf2019-10-24 11:58:06 +01009#include <ProfilingService.hpp>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010010#include <ProfilingUtils.hpp>
11#include <SendTimelinePacket.hpp>
12#include <TimelinePacketWriterFactory.hpp>
13
14#include <boost/test/unit_test.hpp>
Jim Flynnab845752019-10-25 13:17:30 +010015#include <LabelsAndEventClasses.hpp>
16
17#include <functional>
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010018
19using namespace armnn::profiling;
20
21BOOST_AUTO_TEST_SUITE(SendTimelinePacketTests)
22
23BOOST_AUTO_TEST_CASE(SendTimelineMessageDirectoryPackageTest)
24{
25 MockBufferManager mockBuffer(512);
26 TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer);
27 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
28
29 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
30
31 // Get the readable buffer
32 auto packetBuffer = mockBuffer.GetReadableBuffer();
33
Matteo Martincigh34a407d2019-11-06 15:30:54 +000034 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010035 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000036 unsigned int uint64_t_size = sizeof(uint64_t);
37 unsigned int threadId_size = sizeof(std::thread::id);
38
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010039 // Check the packet header
40 unsigned int offset = 0;
41 uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset);
42 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
43 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
44 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
45 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
46
47 BOOST_CHECK(packetFamily == 1);
48 BOOST_CHECK(packetClass == 0);
49 BOOST_CHECK(packetType == 0);
50 BOOST_CHECK(streamId == 0);
51
52 offset += uint32_t_size;
53 uint32_t packetHeaderWord1 = ReadUint32(packetBuffer, offset);
54 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
55 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
56 BOOST_CHECK(sequenceNumbered == 0);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000057 BOOST_CHECK(dataLength == 419);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010058
59 offset += uint32_t_size;
Matteo Martincigh34a407d2019-11-06 15:30:54 +000060 uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
61 BOOST_CHECK(readStreamVersion == 4);
62 offset += uint8_t_size;
63 uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
64 BOOST_CHECK(readPointerBytes == uint64_t_size);
65 offset += uint8_t_size;
66 uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
67 BOOST_CHECK(readThreadIdBytes == threadId_size);
68
69 offset += uint8_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +010070 uint32_t DeclCount = ReadUint32(packetBuffer, offset);
71 BOOST_CHECK(DeclCount == 5);
72
73 offset += uint32_t_size;
74 SwTraceMessage swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010075
Matteo Martincigh34a407d2019-11-06 15:30:54 +000076 BOOST_CHECK(swTraceMessage.m_Id == 0);
77 BOOST_CHECK(swTraceMessage.m_Name == "declareLabel");
78 BOOST_CHECK(swTraceMessage.m_UiName == "declare label");
79 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 2);
80 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
81 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 's');
82 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 2);
83 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid");
84 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "value");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010085
Finn Williamse63a0262019-10-22 10:30:49 +010086 swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010087
Matteo Martincigh34a407d2019-11-06 15:30:54 +000088 BOOST_CHECK(swTraceMessage.m_Id == 1);
89 BOOST_CHECK(swTraceMessage.m_Name == "declareEntity");
90 BOOST_CHECK(swTraceMessage.m_UiName == "declare entity");
91 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 1);
92 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
93 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 1);
94 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010095
Finn Williamse63a0262019-10-22 10:30:49 +010096 swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +010097
Matteo Martincigh34a407d2019-11-06 15:30:54 +000098 BOOST_CHECK(swTraceMessage.m_Id == 2);
99 BOOST_CHECK(swTraceMessage.m_Name == "declareEventClass");
100 BOOST_CHECK(swTraceMessage.m_UiName == "declare event class");
101 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 1);
102 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'p');
103 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 1);
104 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "guid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100105
Finn Williamse63a0262019-10-22 10:30:49 +0100106 swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100107
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000108 BOOST_CHECK(swTraceMessage.m_Id == 3);
109 BOOST_CHECK(swTraceMessage.m_Name == "declareRelationship");
110 BOOST_CHECK(swTraceMessage.m_UiName == "declare relationship");
111 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 4);
112 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == 'I');
113 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 'p');
114 BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
115 BOOST_CHECK(swTraceMessage.m_ArgTypes[3] == 'p');
116 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 4);
117 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "relationshipType");
118 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "relationshipGuid");
119 BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "headGuid");
120 BOOST_CHECK(swTraceMessage.m_ArgNames[3] == "tailGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100121
Finn Williamse63a0262019-10-22 10:30:49 +0100122 swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100123
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000124 BOOST_CHECK(swTraceMessage.m_Id == 4);
125 BOOST_CHECK(swTraceMessage.m_Name == "declareEvent");
126 BOOST_CHECK(swTraceMessage.m_UiName == "declare event");
127 BOOST_CHECK(swTraceMessage.m_ArgTypes.size() == 3);
128 BOOST_CHECK(swTraceMessage.m_ArgTypes[0] == '@');
129 BOOST_CHECK(swTraceMessage.m_ArgTypes[1] == 't');
130 BOOST_CHECK(swTraceMessage.m_ArgTypes[2] == 'p');
131 BOOST_CHECK(swTraceMessage.m_ArgNames.size() == 3);
132 BOOST_CHECK(swTraceMessage.m_ArgNames[0] == "timestamp");
133 BOOST_CHECK(swTraceMessage.m_ArgNames[1] == "threadId");
134 BOOST_CHECK(swTraceMessage.m_ArgNames[2] == "eventGuid");
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100135}
136
137BOOST_AUTO_TEST_CASE(SendTimelineEntityPlusEventClassBinaryPacketTest)
138{
139 MockBufferManager bufferManager(40);
140 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
141 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
142
143 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
144 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
145
146 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
147 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid);
148
149 // Commit the messages
150 sendTimelinePacket->Commit();
151
152 // Get the readable buffer
153 auto packetBuffer = bufferManager.GetReadableBuffer();
154
155 unsigned int uint32_t_size = sizeof(uint32_t);
156 unsigned int uint64_t_size = sizeof(uint64_t);
157
158 // Check the packet header
159 unsigned int offset = 0;
160
161 // Reading TimelineEntityClassBinaryPacket
162 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
163 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
164 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
165 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
166 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
167
168 BOOST_CHECK(entityBinaryPacketFamily == 1);
169 BOOST_CHECK(entityBinaryPacketClass == 0);
170 BOOST_CHECK(entityBinaryPacketType == 1);
171 BOOST_CHECK(entityBinaryPacketStreamId == 0);
172
173 offset += uint32_t_size;
174 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
175 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
176 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
177 BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0);
Finn Williamse63a0262019-10-22 10:30:49 +0100178 BOOST_CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100179
180 // Check the decl_id
181 offset += uint32_t_size;
182 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
183
184 BOOST_CHECK(entitytDecId == uint32_t(1));
185
186 // Check the profiling GUID
187 offset += uint32_t_size;
188 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
189
190 BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
191
192 // Reading TimelineEventClassBinaryPacket
193 offset += uint64_t_size;
194 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
195 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
196 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
197 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
198 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
199
200 BOOST_CHECK(eventClassBinaryPacketFamily == 1);
201 BOOST_CHECK(eventClassBinaryPacketClass == 0);
202 BOOST_CHECK(eventClassBinaryPacketType == 1);
203 BOOST_CHECK(eventClassBinaryPacketStreamId == 0);
204
205 offset += uint32_t_size;
206 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
207 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
208 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
209 BOOST_CHECK(eventClassBinaryPacketSequenceNumbered == 0);
210 BOOST_CHECK(eventClassBinaryPacketDataLength == 12);
211
212 offset += uint32_t_size;
213 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
214 BOOST_CHECK(eventClassDeclId == uint32_t(2));
215
216 // Check the profiling GUID
217 offset += uint32_t_size;
218 readProfilingGuid = ReadUint64(packetBuffer, offset);
219 BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
220
221 bufferManager.MarkRead(packetBuffer);
222}
223
224BOOST_AUTO_TEST_CASE(SendTimelinePacketTests1)
225{
226 unsigned int uint32_t_size = sizeof(uint32_t);
227 unsigned int uint64_t_size = sizeof(uint64_t);
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000228 unsigned int threadId_size = sizeof(std::thread::id);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100229
230 MockBufferManager bufferManager(512);
231 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
232 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
233
234 // Send TimelineEntityClassBinaryPacket
235 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
236 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
237
238 // Commit the buffer
239 sendTimelinePacket->Commit();
240
241 // Get the readable buffer
242 auto packetBuffer = bufferManager.GetReadableBuffer();
243
244 // Check the packet header
245 unsigned int offset = 0;
246
247 // Reading TimelineEntityClassBinaryPacket
248 uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
249 uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
250 uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
251 uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007;
252 uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007;
253
254 BOOST_CHECK(entityBinaryPacketFamily == 1);
255 BOOST_CHECK(entityBinaryPacketClass == 0);
256 BOOST_CHECK(entityBinaryPacketType == 1);
257 BOOST_CHECK(entityBinaryPacketStreamId == 0);
258
259 offset += uint32_t_size;
260 uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
261 uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001;
262 uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
263 BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0);
Finn Williamse63a0262019-10-22 10:30:49 +0100264 BOOST_CHECK(entityBinaryPacketDataLength == 12);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100265
266 // Check the decl_id
267 offset += uint32_t_size;
268 uint32_t entitytDecId = ReadUint32(packetBuffer, offset);
269
270 BOOST_CHECK(entitytDecId == uint32_t(1));
271
272 // Check the profiling GUID
273 offset += uint32_t_size;
274 uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset);
275
276 BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid);
277
278 bufferManager.MarkRead(packetBuffer);
279
280 // Send TimelineEventClassBinaryPacket
281 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
282 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid);
283
284 // Commit the buffer
285 sendTimelinePacket->Commit();
286
287 // Get the readable buffer
288 packetBuffer = bufferManager.GetReadableBuffer();
289
290 // Check the packet header
291 offset = 0;
292
293 // Reading TimelineEventClassBinaryPacket
294 uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
295 uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
296 uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
297 uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007;
298 uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007;
299
300 BOOST_CHECK(eventClassBinaryPacketFamily == 1);
301 BOOST_CHECK(eventClassBinaryPacketClass == 0);
302 BOOST_CHECK(eventClassBinaryPacketType == 1);
303 BOOST_CHECK(eventClassBinaryPacketStreamId == 0);
304
305 offset += uint32_t_size;
306 uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
307 uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001;
308 uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
309 BOOST_CHECK(eventClassBinaryPacketSequenceNumbered == 0);
310 BOOST_CHECK(eventClassBinaryPacketDataLength == 12);
311
312 offset += uint32_t_size;
313 uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset);
314 BOOST_CHECK(eventClassDeclId == uint32_t(2));
315
316 // Check the profiling GUID
317 offset += uint32_t_size;
318 readProfilingGuid = ReadUint64(packetBuffer, offset);
319 BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid);
320
321 bufferManager.MarkRead(packetBuffer);
322
323 // Send TimelineEventBinaryPacket
324 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000325 const std::thread::id threadId = std::this_thread::get_id();
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100326 const uint64_t eventProfilingGuid = 123456u;
327 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
328
329 // Commit the buffer
330 sendTimelinePacket->Commit();
331
332 // Get the readable buffer
333 packetBuffer = bufferManager.GetReadableBuffer();
334
335 // Check the packet header
336 offset = 0;
337
338 // Reading TimelineEventBinaryPacket
339 uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset);
340 uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
341 uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
342 uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007;
343 uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007;
344
345 BOOST_CHECK(eventBinaryPacketFamily == 1);
346 BOOST_CHECK(eventBinaryPacketClass == 0);
347 BOOST_CHECK(eventBinaryPacketType == 1);
348 BOOST_CHECK(eventBinaryPacketStreamId == 0);
349
350 offset += uint32_t_size;
351 uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset);
352 uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001;
353 uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
354 BOOST_CHECK(eventBinaryPacketSequenceNumbered == 0);
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000355 BOOST_CHECK(eventBinaryPacketDataLength == 28);
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100356
357 // Check the decl_id
358 offset += uint32_t_size;
359 uint32_t eventDeclId = ReadUint32(packetBuffer, offset);
360 BOOST_CHECK(eventDeclId == 4);
361
362 // Check the timestamp
363 offset += uint32_t_size;
364 uint64_t eventTimestamp = ReadUint64(packetBuffer, offset);
365 BOOST_CHECK(eventTimestamp == timestamp);
366
367 // Check the thread id
368 offset += uint64_t_size;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000369 std::vector<uint8_t> readThreadId(threadId_size, 0);
370 ReadBytes(packetBuffer, offset, threadId_size, readThreadId.data());
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100371 BOOST_CHECK(readThreadId == threadId);
372
373 // Check the profiling GUID
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000374 offset += threadId_size;
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100375 readProfilingGuid = ReadUint64(packetBuffer, offset);
376 BOOST_CHECK(readProfilingGuid == eventProfilingGuid);
377}
378
379BOOST_AUTO_TEST_CASE(SendTimelinePacketTests2)
380{
381 MockBufferManager bufferManager(40);
382 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
383 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
384
385 BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineMessageDirectoryPackage(),
386 armnn::RuntimeException);
387}
388
389BOOST_AUTO_TEST_CASE(SendTimelinePacketTests3)
390{
391 MockBufferManager bufferManager(512);
392 TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
393 std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket();
394
395 // Send TimelineEntityClassBinaryPacket
396 const uint64_t entityBinaryPacketProfilingGuid = 123456u;
397 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid);
398
399 // Commit the buffer
400 sendTimelinePacket->Commit();
401
402 // Get the readable buffer
403 auto packetBuffer = bufferManager.GetReadableBuffer();
404
405 // Send TimelineEventClassBinaryPacket
406 const uint64_t eventClassBinaryPacketProfilingGuid = 789123u;
407 BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid),
408 armnn::RuntimeException);
409}
410
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100411BOOST_AUTO_TEST_CASE(GetGuidsFromProfilingService)
412{
Narumol Prangnawarat85ad78c2019-11-18 15:34:23 +0000413 armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100414 options.m_EnableProfiling = true;
415 ProfilingService& profilingService = ProfilingService::Instance();
416 profilingService.ResetExternalProfilingOptions(options, true);
417 ProfilingStaticGuid staticGuid = profilingService.GenerateStaticId("dummy");
Jim Flynnab845752019-10-25 13:17:30 +0100418 std::hash<std::string> hasher;
419 uint64_t hash = static_cast<uint64_t>(hasher("dummy"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000420 ProfilingStaticGuid expectedStaticValue(hash | MIN_STATIC_GUID);
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100421 BOOST_CHECK(staticGuid == expectedStaticValue);
422 ProfilingDynamicGuid dynamicGuid = profilingService.NextGuid();
Jim Flynnab845752019-10-25 13:17:30 +0100423 uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid);
424 ++dynamicGuidValue;
425 ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue);
426 dynamicGuid = profilingService.NextGuid();
Jim Flynn00f3aaf2019-10-24 11:58:06 +0100427 BOOST_CHECK(dynamicGuid == expectedDynamicValue);
428}
429
Jim Flynn8b200652019-10-24 18:07:44 +0100430BOOST_AUTO_TEST_CASE(GetTimelinePackerWriterFromProfilingService)
431{
Narumol Prangnawarat85ad78c2019-11-18 15:34:23 +0000432 armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
Jim Flynn8b200652019-10-24 18:07:44 +0100433 options.m_EnableProfiling = true;
434 ProfilingService& profilingService = ProfilingService::Instance();
435 profilingService.ResetExternalProfilingOptions(options, true);
436
437 std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket();
438 BOOST_CHECK(writer != nullptr);
439}
440
Jim Flynnab845752019-10-25 13:17:30 +0100441BOOST_AUTO_TEST_CASE(CheckStaticGuidsAndEvents)
442{
443 BOOST_CHECK("name" == LabelsAndEventClasses::NAME_LABEL);
444 BOOST_CHECK("type" == LabelsAndEventClasses::TYPE_LABEL);
445 BOOST_CHECK("index" == LabelsAndEventClasses::INDEX_LABEL);
446
447 std::hash<std::string> hasher;
448
449 uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000450 ProfilingStaticGuid expectedNameGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100451 BOOST_CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid);
452
453 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000454 ProfilingStaticGuid expectedTypeGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100455 BOOST_CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid);
456
457 hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000458 ProfilingStaticGuid expectedIndexGuid(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100459 BOOST_CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid);
460
461 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000462 ProfilingStaticGuid expectedSol(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100463 BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol);
464
465 hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL"));
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +0000466 ProfilingStaticGuid expectedEol(hash | MIN_STATIC_GUID);
Jim Flynnab845752019-10-25 13:17:30 +0100467 BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol);
468}
469
Sadik Armagan7bbdf9d2019-10-24 10:26:05 +0100470BOOST_AUTO_TEST_SUITE_END()