1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include <Threads.hpp>
7 #include <ProfilingUtils.hpp>
8
9 #include <armnn/utility/NumericCast.hpp>
10
11 #include <common/include/SwTrace.hpp>
12
13 #include <boost/test/unit_test.hpp>
14
15 using namespace armnn::profiling;
16
17 BOOST_AUTO_TEST_SUITE(TimelinePacketTests)
18
BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestNoBuffer)19 BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestNoBuffer)
20 {
21 const uint64_t profilingGuid = 123456u;
22 const std::string label = "some label";
23 unsigned int numberOfBytesWritten = 789u;
24 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
25 label,
26 nullptr,
27 512u,
28 numberOfBytesWritten);
29 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
30 BOOST_CHECK(numberOfBytesWritten == 0);
31 }
32
BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestBufferExhaustionZeroValue)33 BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestBufferExhaustionZeroValue)
34 {
35 std::vector<unsigned char> buffer(512, 0);
36
37 const uint64_t profilingGuid = 123456u;
38 const std::string label = "some label";
39 unsigned int numberOfBytesWritten = 789u;
40 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
41 label,
42 buffer.data(),
43 0,
44 numberOfBytesWritten);
45 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
46 BOOST_CHECK(numberOfBytesWritten == 0);
47 }
48
BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestBufferExhaustionFixedValue)49 BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestBufferExhaustionFixedValue)
50 {
51 std::vector<unsigned char> buffer(10, 0);
52
53 const uint64_t profilingGuid = 123456u;
54 const std::string label = "some label";
55 unsigned int numberOfBytesWritten = 789u;
56 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
57 label,
58 buffer.data(),
59 armnn::numeric_cast<unsigned int>(buffer.size()),
60 numberOfBytesWritten);
61 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
62 BOOST_CHECK(numberOfBytesWritten == 0);
63 }
64
BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestInvalidLabel)65 BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestInvalidLabel)
66 {
67 std::vector<unsigned char> buffer(512, 0);
68
69 const uint64_t profilingGuid = 123456u;
70 const std::string label = "s0m€ l@b€l";
71 unsigned int numberOfBytesWritten = 789u;
72 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
73 label,
74 buffer.data(),
75 armnn::numeric_cast<unsigned int>(buffer.size()),
76 numberOfBytesWritten);
77 BOOST_CHECK(result == TimelinePacketStatus::Error);
78 BOOST_CHECK(numberOfBytesWritten == 0);
79 }
80
BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestSingleConstructionOfData)81 BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestSingleConstructionOfData)
82 {
83 std::vector<unsigned char> buffer(512, 0);
84
85 const uint64_t profilingGuid = 123456u;
86 const std::string label = "some label";
87 unsigned int numberOfBytesWritten = 789u;
88 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
89 label,
90 buffer.data(),
91 armnn::numeric_cast<unsigned int>(buffer.size()),
92 numberOfBytesWritten);
93 BOOST_CHECK(result == TimelinePacketStatus::Ok);
94 BOOST_CHECK(numberOfBytesWritten == 28);
95
96 unsigned int uint32_t_size = sizeof(uint32_t);
97 unsigned int uint64_t_size = sizeof(uint64_t);
98
99 // Check the packet header
100 unsigned int offset = 0;
101 uint32_t decl_Id = ReadUint32(buffer.data(), offset);
102 BOOST_CHECK(decl_Id == uint32_t(0));
103
104 // Check the profiling GUID
105 offset += uint32_t_size;
106 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
107 BOOST_CHECK(readProfilingGuid == profilingGuid);
108
109 // Check the SWTrace label
110 offset += uint64_t_size;
111 uint32_t swTraceLabelLength = ReadUint32(buffer.data(), offset);
112 BOOST_CHECK(swTraceLabelLength == 11); // Label length including the null-terminator
113
114 offset += uint32_t_size;
115 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
116 label.data(), // The original label
117 swTraceLabelLength - 1) == 0); // The length of the label
118
119 offset += swTraceLabelLength * uint32_t_size;
120 BOOST_CHECK(buffer[offset] == '\0'); // The null-terminator at the end of the SWTrace label
121 }
122
BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketNullBufferTest)123 BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketNullBufferTest)
124 {
125 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
126 const uint64_t relationshipGuid = 123456u;
127 const uint64_t headGuid = 234567u;
128 const uint64_t tailGuid = 345678u;
129 const uint64_t attributeGuid = 876345u;
130 unsigned int numberOfBytesWritten = 789u;
131 TimelinePacketStatus result = WriteTimelineRelationshipBinary(relationshipType,
132 relationshipGuid,
133 headGuid,
134 tailGuid,
135 attributeGuid,
136 nullptr,
137 512u,
138 numberOfBytesWritten);
139 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
140 BOOST_CHECK(numberOfBytesWritten == 0);
141 }
142
BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketZeroBufferSizeTest)143 BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketZeroBufferSizeTest)
144 {
145 std::vector<unsigned char> buffer(512, 0);
146
147 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
148 const uint64_t relationshipGuid = 123456u;
149 const uint64_t headGuid = 234567u;
150 const uint64_t tailGuid = 345678u;
151 const uint64_t attributeGuid = 876345u;
152 unsigned int numberOfBytesWritten = 789u;
153 TimelinePacketStatus result = WriteTimelineRelationshipBinary(relationshipType,
154 relationshipGuid,
155 headGuid,
156 tailGuid,
157 attributeGuid,
158 buffer.data(),
159 0,
160 numberOfBytesWritten);
161 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
162 BOOST_CHECK(numberOfBytesWritten == 0);
163 }
164
BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketSmallBufferSizeTest)165 BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketSmallBufferSizeTest)
166 {
167 std::vector<unsigned char> buffer(10, 0);
168
169 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
170 const uint64_t relationshipGuid = 123456u;
171 const uint64_t headGuid = 234567u;
172 const uint64_t tailGuid = 345678u;
173 const uint64_t attributeGuid = 876345u;
174 unsigned int numberOfBytesWritten = 789u;
175 TimelinePacketStatus result =
176 WriteTimelineRelationshipBinary(relationshipType,
177 relationshipGuid,
178 headGuid,
179 tailGuid,
180 attributeGuid,
181 buffer.data(),
182 armnn::numeric_cast<unsigned int>(buffer.size()),
183 numberOfBytesWritten);
184 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
185 BOOST_CHECK(numberOfBytesWritten == 0);
186 }
187
BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketInvalidRelationTest)188 BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketInvalidRelationTest)
189 {
190 std::vector<unsigned char> buffer(512, 0);
191 ProfilingRelationshipType relationshipType = static_cast<ProfilingRelationshipType>(5);
192 const uint64_t relationshipGuid = 123456u;
193 const uint64_t headGuid = 234567u;
194 const uint64_t tailGuid = 345678u;
195 const uint64_t attributeGuid = 876345u;
196
197 unsigned int numberOfBytesWritten = 789u;
198
199 BOOST_CHECK_THROW(WriteTimelineRelationshipBinary(relationshipType,
200 relationshipGuid,
201 headGuid,
202 tailGuid,
203 attributeGuid,
204 buffer.data(),
205 armnn::numeric_cast<unsigned int>(buffer.size()),
206 numberOfBytesWritten),
207 armnn::InvalidArgumentException);
208
209 BOOST_CHECK(numberOfBytesWritten == 0);
210 }
211
BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketTestDataConstruction)212 BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketTestDataConstruction)
213 {
214 std::vector<unsigned char> buffer(512, 0);
215
216 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::RetentionLink;
217 const uint64_t relationshipGuid = 123456u;
218 const uint64_t headGuid = 234567u;
219 const uint64_t tailGuid = 345678u;
220 const uint64_t attributeGuid = 876345u;
221 unsigned int numberOfBytesWritten = 789u;
222 TimelinePacketStatus result =
223 WriteTimelineRelationshipBinary(relationshipType,
224 relationshipGuid,
225 headGuid,
226 tailGuid,
227 attributeGuid,
228 buffer.data(),
229 armnn::numeric_cast<unsigned int>(buffer.size()),
230 numberOfBytesWritten);
231 BOOST_CHECK(result == TimelinePacketStatus::Ok);
232 BOOST_CHECK(numberOfBytesWritten == 40);
233
234 unsigned int uint32_t_size = sizeof(uint32_t);
235 unsigned int uint64_t_size = sizeof(uint64_t);
236
237 // Check the packet header
238 unsigned int offset = 0;
239 // Check the decl_id
240 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
241 BOOST_CHECK(readDeclId == 3);
242
243 // Check the relationship type
244 offset += uint32_t_size;
245 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
246 BOOST_CHECK(readRelationshipType == 0);
247
248 // Check the relationship GUID
249 offset += uint32_t_size;
250 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
251 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
252
253 // Check the head GUID
254 offset += uint64_t_size;
255 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
256 BOOST_CHECK(readHeadGuid == headGuid);
257
258 // Check the tail GUID
259 offset += uint64_t_size;
260 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
261 BOOST_CHECK(readTailGuid == tailGuid);
262
263 // Check the attribute GUID
264 offset += uint64_t_size;
265 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
266 BOOST_CHECK(readAttributeGuid == attributeGuid);
267 }
268
BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketExecutionLinkTestDataConstruction)269 BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketExecutionLinkTestDataConstruction)
270 {
271 std::vector<unsigned char> buffer(512, 0);
272
273 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::ExecutionLink;
274 const uint64_t relationshipGuid = 123456u;
275 const uint64_t headGuid = 234567u;
276 const uint64_t tailGuid = 345678u;
277 const uint64_t attributeGuid = 876345u;
278 unsigned int numberOfBytesWritten = 789u;
279 TimelinePacketStatus result =
280 WriteTimelineRelationshipBinary(relationshipType,
281 relationshipGuid,
282 headGuid,
283 tailGuid,
284 attributeGuid,
285 buffer.data(),
286 armnn::numeric_cast<unsigned int>(buffer.size()),
287 numberOfBytesWritten);
288 BOOST_CHECK(result == TimelinePacketStatus::Ok);
289 BOOST_CHECK(numberOfBytesWritten == 40);
290
291 unsigned int uint32_t_size = sizeof(uint32_t);
292 unsigned int uint64_t_size = sizeof(uint64_t);
293
294 unsigned int offset = 0;
295 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
296 BOOST_CHECK(readDeclId == 3);
297
298 // Check the relationship type
299 offset += uint32_t_size;
300 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
301 BOOST_CHECK(readRelationshipType == 1);
302
303 // Check the relationship GUID
304 offset += uint32_t_size;
305 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
306 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
307
308 // Check the head GUID
309 offset += uint64_t_size;
310 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
311 BOOST_CHECK(readHeadGuid == headGuid);
312
313 // Check the tail GUID
314 offset += uint64_t_size;
315 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
316 BOOST_CHECK(readTailGuid == tailGuid);
317
318 // Check the attribute GUID
319 offset += uint64_t_size;
320 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
321 BOOST_CHECK(readAttributeGuid == attributeGuid);
322 }
323
324
BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketDataLinkTestDataConstruction)325 BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketDataLinkTestDataConstruction)
326 {
327 std::vector<unsigned char> buffer(512, 0);
328
329 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
330 const uint64_t relationshipGuid = 123456u;
331 const uint64_t headGuid = 234567u;
332 const uint64_t tailGuid = 345678u;
333 const uint64_t attributeGuid = 876345u;
334 unsigned int numberOfBytesWritten = 789u;
335 TimelinePacketStatus result =
336 WriteTimelineRelationshipBinary(relationshipType,
337 relationshipGuid,
338 headGuid,
339 tailGuid,
340 attributeGuid,
341 buffer.data(),
342 armnn::numeric_cast<unsigned int>(buffer.size()),
343 numberOfBytesWritten);
344 BOOST_CHECK(result == TimelinePacketStatus::Ok);
345 BOOST_CHECK(numberOfBytesWritten == 40);
346
347 unsigned int uint32_t_size = sizeof(uint32_t);
348 unsigned int uint64_t_size = sizeof(uint64_t);
349
350 unsigned int offset = 0;
351 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
352 BOOST_CHECK(readDeclId == 3);
353
354 // Check the relationship type
355 offset += uint32_t_size;
356 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
357 BOOST_CHECK(readRelationshipType == 2);
358
359 // Check the relationship GUID
360 offset += uint32_t_size;
361 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
362 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
363
364 // Check the head GUID
365 offset += uint64_t_size;
366 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
367 BOOST_CHECK(readHeadGuid == headGuid);
368
369 // Check the tail GUID
370 offset += uint64_t_size;
371 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
372 BOOST_CHECK(readTailGuid == tailGuid);
373
374 // Check the attribute GUID
375 offset += uint64_t_size;
376 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
377 BOOST_CHECK(readAttributeGuid == attributeGuid);
378 }
379
380
BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketLabelLinkTestDataConstruction)381 BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketLabelLinkTestDataConstruction)
382 {
383 std::vector<unsigned char> buffer(512, 0);
384
385 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::LabelLink;
386 const uint64_t relationshipGuid = 123456u;
387 const uint64_t headGuid = 234567u;
388 const uint64_t tailGuid = 345678u;
389 const uint64_t attributeGuid = 876345u;
390 unsigned int numberOfBytesWritten = 789u;
391 TimelinePacketStatus result =
392 WriteTimelineRelationshipBinary(relationshipType,
393 relationshipGuid,
394 headGuid,
395 tailGuid,
396 attributeGuid,
397 buffer.data(),
398 armnn::numeric_cast<unsigned int>(buffer.size()),
399 numberOfBytesWritten);
400 BOOST_CHECK(result == TimelinePacketStatus::Ok);
401 BOOST_CHECK(numberOfBytesWritten == 40);
402
403 unsigned int uint32_t_size = sizeof(uint32_t);
404 unsigned int uint64_t_size = sizeof(uint64_t);
405
406 // Check the packet header
407 unsigned int offset = 0;
408 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
409 BOOST_CHECK(readDeclId == 3);
410
411 // Check the relationship type
412 offset += uint32_t_size;
413 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
414 BOOST_CHECK(readRelationshipType == 3);
415
416 // Check the relationship GUID
417 offset += uint32_t_size;
418 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
419 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
420
421 // Check the head GUID
422 offset += uint64_t_size;
423 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
424 BOOST_CHECK(readHeadGuid == headGuid);
425
426 // Check the tail GUID
427 offset += uint64_t_size;
428 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
429 BOOST_CHECK(readTailGuid == tailGuid);
430
431 // Check the attribute GUID
432 offset += uint64_t_size;
433 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
434 BOOST_CHECK(readAttributeGuid == attributeGuid);
435 }
436
BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestNoBuffer)437 BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestNoBuffer)
438 {
439 unsigned int numberOfBytesWritten = 789u;
440 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(nullptr,
441 512u,
442 numberOfBytesWritten);
443 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
444 BOOST_CHECK(numberOfBytesWritten == 0);
445 }
446
BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestBufferExhausted)447 BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestBufferExhausted)
448 {
449 std::vector<unsigned char> buffer(512, 0);
450
451 unsigned int numberOfBytesWritten = 789u;
452 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(),
453 0,
454 numberOfBytesWritten);
455 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
456 BOOST_CHECK(numberOfBytesWritten == 0);
457 }
458
BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestFullConstruction)459 BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestFullConstruction)
460 {
461 std::vector<unsigned char> buffer(512, 0);
462 unsigned int numberOfBytesWritten = 789u;
463 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(),
464 armnn::numeric_cast<unsigned int>(buffer.size()),
465 numberOfBytesWritten);
466 BOOST_CHECK(result == TimelinePacketStatus::Ok);
467
468 BOOST_CHECK(numberOfBytesWritten == 451);
469
470 unsigned int uint8_t_size = sizeof(uint8_t);
471 unsigned int uint32_t_size = sizeof(uint32_t);
472 unsigned int uint64_t_size = sizeof(uint64_t);
473
474 // Check the packet header
475 unsigned int offset = 0;
476 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
477 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
478 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
479 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
480 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
481 BOOST_CHECK(packetFamily == 1);
482 BOOST_CHECK(packetClass == 0);
483 BOOST_CHECK(packetType == 0);
484 BOOST_CHECK(streamId == 0);
485
486 offset += uint32_t_size;
487 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
488 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
489 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
490 BOOST_CHECK(sequenceNumbered == 0);
491 BOOST_CHECK(dataLength == 443);
492
493 // Check the stream header
494 offset += uint32_t_size;
495 uint8_t readStreamVersion = ReadUint8(buffer.data(), offset);
496 BOOST_CHECK(readStreamVersion == 4);
497 offset += uint8_t_size;
498 uint8_t readPointerBytes = ReadUint8(buffer.data(), offset);
499 BOOST_CHECK(readPointerBytes == uint64_t_size);
500 offset += uint8_t_size;
501 uint8_t readThreadIdBytes = ReadUint8(buffer.data(), offset);
502 BOOST_CHECK(readThreadIdBytes == ThreadIdSize);
503
504 // Check the number of declarations
505 offset += uint8_t_size;
506 uint32_t declCount = ReadUint32(buffer.data(), offset);
507 BOOST_CHECK(declCount == 5);
508
509 // Check the decl_id
510 offset += uint32_t_size;
511 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
512 BOOST_CHECK(readDeclId == 0);
513
514 // SWTrace "namestring" format
515 // length of the string (first 4 bytes) + string + null terminator
516
517 // Check the decl_name
518 offset += uint32_t_size;
519 uint32_t swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
520 BOOST_CHECK(swTraceDeclNameLength == 13); // decl_name length including the null-terminator
521
522 std::string label = "declareLabel";
523 offset += uint32_t_size;
524 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
525 label.data(), // The original label
526 swTraceDeclNameLength - 1) == 0); // The length of the label
527
528 // Check the ui_name
529 std::vector<uint32_t> swTraceString;
530 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
531 offset += (armnn::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
532 uint32_t swTraceUINameLength = ReadUint32(buffer.data(), offset);
533 BOOST_CHECK(swTraceUINameLength == 14); // ui_name length including the null-terminator
534
535 label = "declare label";
536 offset += uint32_t_size;
537 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
538 label.data(), // The original label
539 swTraceUINameLength - 1) == 0); // The length of the label
540
541 // Check arg_types
542 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
543 offset += (armnn::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
544 uint32_t swTraceArgTypesLength = ReadUint32(buffer.data(), offset);
545 BOOST_CHECK(swTraceArgTypesLength == 3); // arg_types length including the null-terminator
546
547 label = "ps";
548 offset += uint32_t_size;
549 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
550 label.data(), // The original label
551 swTraceArgTypesLength - 1) == 0); // The length of the label
552
553 // Check arg_names
554 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
555 offset += (armnn::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
556 uint32_t swTraceArgNamesLength = ReadUint32(buffer.data(), offset);
557 BOOST_CHECK(swTraceArgNamesLength == 11); // arg_names length including the null-terminator
558
559 label = "guid,value";
560 offset += uint32_t_size;
561 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
562 label.data(), // The original label
563 swTraceArgNamesLength - 1) == 0); // The length of the label
564
565 // Check second message decl_id
566 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
567 offset += (armnn::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
568 readDeclId = ReadUint32(buffer.data(), offset);
569 BOOST_CHECK(readDeclId == 1);
570
571 // Check second decl_name
572 offset += uint32_t_size;
573 swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
574 BOOST_CHECK(swTraceDeclNameLength == 14); // decl_name length including the null-terminator
575
576 label = "declareEntity";
577 offset += uint32_t_size;
578 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
579 label.data(), // The original label
580 swTraceDeclNameLength - 1) == 0); // The length of the label
581 }
582
BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestNoBuffer)583 BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestNoBuffer)
584 {
585 const uint64_t profilingGuid = 123456u;
586 unsigned int numberOfBytesWritten = 789u;
587 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
588 nullptr,
589 512u,
590 numberOfBytesWritten);
591 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
592 BOOST_CHECK(numberOfBytesWritten == 0);
593 }
594
BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithZeroBufferSize)595 BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithZeroBufferSize)
596 {
597 std::vector<unsigned char> buffer(512, 0);
598
599 const uint64_t profilingGuid = 123456u;
600 unsigned int numberOfBytesWritten = 789u;
601 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
602 buffer.data(),
603 0,
604 numberOfBytesWritten);
605 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
606 BOOST_CHECK(numberOfBytesWritten == 0);
607 }
608
BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithFixedBufferSize)609 BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithFixedBufferSize)
610 {
611 std::vector<unsigned char> buffer(10, 0);
612
613 const uint64_t profilingGuid = 123456u;
614 unsigned int numberOfBytesWritten = 789u;
615 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
616 buffer.data(),
617 armnn::numeric_cast<unsigned int>(buffer.size()),
618 numberOfBytesWritten);
619 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
620 BOOST_CHECK(numberOfBytesWritten == 0);
621 }
622
BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestFullConstructionOfData)623 BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestFullConstructionOfData)
624 {
625 std::vector<unsigned char> buffer(512, 0);
626
627 const uint64_t profilingGuid = 123456u;
628 unsigned int numberOfBytesWritten = 789u;
629 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
630 buffer.data(),
631 armnn::numeric_cast<unsigned int>(buffer.size()),
632 numberOfBytesWritten);
633 BOOST_CHECK(result == TimelinePacketStatus::Ok);
634 BOOST_CHECK(numberOfBytesWritten == 12);
635
636 unsigned int uint32_t_size = sizeof(uint32_t);
637
638 unsigned int offset = 0;
639 // Check decl_Id
640 uint32_t decl_Id = ReadUint32(buffer.data(), offset);
641 BOOST_CHECK(decl_Id == uint32_t(1));
642
643 // Check the profiling GUID
644 offset += uint32_t_size;
645 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
646 BOOST_CHECK(readProfilingGuid == profilingGuid);
647 }
648
BOOST_AUTO_TEST_CASE(TimelineEventClassTestNoBuffer)649 BOOST_AUTO_TEST_CASE(TimelineEventClassTestNoBuffer)
650 {
651 const uint64_t profilingGuid = 123456u;
652 const uint64_t profilingNameGuid = 3345u;
653 unsigned int numberOfBytesWritten = 789u;
654 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
655 profilingNameGuid,
656 nullptr,
657 512u,
658 numberOfBytesWritten);
659 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
660 BOOST_CHECK(numberOfBytesWritten == 0);
661 }
662
BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionZeroValue)663 BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionZeroValue)
664 {
665 std::vector<unsigned char> buffer(512, 0);
666
667 const uint64_t profilingGuid = 123456u;
668 const uint64_t profilingNameGuid = 3345u;
669 unsigned int numberOfBytesWritten = 789u;
670 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
671 profilingNameGuid,
672 buffer.data(),
673 0,
674 numberOfBytesWritten);
675 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
676 BOOST_CHECK(numberOfBytesWritten == 0);
677 }
678
BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionFixedValue)679 BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionFixedValue)
680 {
681 std::vector<unsigned char> buffer(10, 0);
682
683 const uint64_t profilingGuid = 123456u;
684 const uint64_t profilingNameGuid = 5564u;
685 unsigned int numberOfBytesWritten = 789u;
686 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
687 profilingNameGuid,
688 buffer.data(),
689 armnn::numeric_cast<unsigned int>(buffer.size()),
690 numberOfBytesWritten);
691 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
692 BOOST_CHECK(numberOfBytesWritten == 0);
693 }
694
BOOST_AUTO_TEST_CASE(TimelineEventClassTestFullConstructionOfData)695 BOOST_AUTO_TEST_CASE(TimelineEventClassTestFullConstructionOfData)
696 {
697 std::vector<unsigned char> buffer(512, 0);
698
699 const uint64_t profilingGuid = 123456u;
700 const uint64_t profilingNameGuid = 654321u;
701 unsigned int numberOfBytesWritten = 789u;
702 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
703 profilingNameGuid,
704 buffer.data(),
705 armnn::numeric_cast<unsigned int>(buffer.size()),
706 numberOfBytesWritten);
707 BOOST_CHECK(result == TimelinePacketStatus::Ok);
708 BOOST_CHECK(numberOfBytesWritten == 20);
709
710 unsigned int uint32_t_size = sizeof(uint32_t);
711 unsigned int uint64_t_size = sizeof(uint64_t);
712
713 unsigned int offset = 0;
714 // Check the decl_id
715 uint32_t declId = ReadUint32(buffer.data(), offset);
716 BOOST_CHECK(declId == uint32_t(2));
717
718 // Check the profiling GUID
719 offset += uint32_t_size;
720 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
721 BOOST_CHECK(readProfilingGuid == profilingGuid);
722
723 offset += uint64_t_size;
724 uint64_t readProfilingNameGuid = ReadUint64(buffer.data(), offset);
725 BOOST_CHECK(readProfilingNameGuid == profilingNameGuid);
726 }
727
BOOST_AUTO_TEST_CASE(TimelineEventPacketTestNoBuffer)728 BOOST_AUTO_TEST_CASE(TimelineEventPacketTestNoBuffer)
729 {
730 const uint64_t timestamp = 456789u;
731 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
732 const uint64_t profilingGuid = 123456u;
733 unsigned int numberOfBytesWritten = 789u;
734 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
735 threadId,
736 profilingGuid,
737 nullptr,
738 512u,
739 numberOfBytesWritten);
740 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
741 BOOST_CHECK(numberOfBytesWritten == 0);
742 }
743
BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionZeroValue)744 BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionZeroValue)
745 {
746 std::vector<unsigned char> buffer(512, 0);
747
748 const uint64_t timestamp = 456789u;
749 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
750 const uint64_t profilingGuid = 123456u;
751 unsigned int numberOfBytesWritten = 789u;
752 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
753 threadId,
754 profilingGuid,
755 buffer.data(),
756 0,
757 numberOfBytesWritten);
758 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
759 BOOST_CHECK(numberOfBytesWritten == 0);
760 }
761
BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionFixedValue)762 BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionFixedValue)
763 {
764 std::vector<unsigned char> buffer(10, 0);
765
766 const uint64_t timestamp = 456789u;
767 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
768 const uint64_t profilingGuid = 123456u;
769 unsigned int numberOfBytesWritten = 789u;
770 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
771 threadId,
772 profilingGuid,
773 buffer.data(),
774 armnn::numeric_cast<unsigned int>(buffer.size()),
775 numberOfBytesWritten);
776 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
777 BOOST_CHECK(numberOfBytesWritten == 0);
778 }
779
BOOST_AUTO_TEST_CASE(TimelineEventPacketTestFullConstructionOfData)780 BOOST_AUTO_TEST_CASE(TimelineEventPacketTestFullConstructionOfData)
781 {
782 std::vector<unsigned char> buffer(512, 0);
783
784 const uint64_t timestamp = 456789u;
785 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
786 const uint64_t profilingGuid = 123456u;
787 unsigned int numberOfBytesWritten = 789u;
788 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
789 threadId,
790 profilingGuid,
791 buffer.data(),
792 armnn::numeric_cast<unsigned int>(buffer.size()),
793 numberOfBytesWritten);
794 BOOST_CHECK(result == TimelinePacketStatus::Ok);
795
796 unsigned int uint32_t_size = sizeof(uint32_t);
797 unsigned int uint64_t_size = sizeof(uint64_t);
798 BOOST_CHECK(numberOfBytesWritten == 20 + ThreadIdSize);
799
800 unsigned int offset = 0;
801 // Check the decl_id
802 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
803 BOOST_CHECK(readDeclId == 4);
804
805 // Check the timestamp
806 offset += uint32_t_size;
807 uint64_t readTimestamp = ReadUint64(buffer.data(), offset);
808 BOOST_CHECK(readTimestamp == timestamp);
809
810 // Check the thread id
811 offset += uint64_t_size;
812 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
813 ReadBytes(buffer.data(), offset, ThreadIdSize, readThreadId.data());
814 BOOST_CHECK(readThreadId == threadId);
815
816 // Check the profiling GUID
817 offset += ThreadIdSize;
818 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
819 BOOST_CHECK(readProfilingGuid == profilingGuid);
820 }
821
822 BOOST_AUTO_TEST_SUITE_END()
823