ArmNN
 21.08
TimelinePacketTests.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <armnnUtils/Threads.hpp>
7 #include <ProfilingUtils.hpp>
8 
10 
11 #include <common/include/SwTrace.hpp>
12 
13 #include <doctest/doctest.h>
14 
15 using namespace armnn::profiling;
16 
17 TEST_SUITE("TimelinePacketTests")
18 {
19 TEST_CASE("TimelineLabelPacketTestNoBuffer")
20 {
21  const uint64_t profilingGuid = 123456u;
22  const std::string label = "some label";
23  unsigned int numberOfBytesWritten = 789u;
25  label,
26  nullptr,
27  512u,
28  numberOfBytesWritten);
30  CHECK(numberOfBytesWritten == 0);
31 }
32 
33 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;
41  label,
42  buffer.data(),
43  0,
44  numberOfBytesWritten);
46  CHECK(numberOfBytesWritten == 0);
47 }
48 
49 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;
57  label,
58  buffer.data(),
59  armnn::numeric_cast<unsigned int>(buffer.size()),
60  numberOfBytesWritten);
62  CHECK(numberOfBytesWritten == 0);
63 }
64 
65 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;
73  label,
74  buffer.data(),
75  armnn::numeric_cast<unsigned int>(buffer.size()),
76  numberOfBytesWritten);
77  CHECK(result == TimelinePacketStatus::Error);
78  CHECK(numberOfBytesWritten == 0);
79 }
80 
81 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;
89  label,
90  buffer.data(),
91  armnn::numeric_cast<unsigned int>(buffer.size()),
92  numberOfBytesWritten);
93  CHECK(result == TimelinePacketStatus::Ok);
94  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  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  CHECK(readProfilingGuid == profilingGuid);
108 
109  // Check the SWTrace label
110  offset += uint64_t_size;
111  uint32_t swTraceLabelLength = ReadUint32(buffer.data(), offset);
112  CHECK(swTraceLabelLength == 11); // Label length including the null-terminator
113 
114  offset += uint32_t_size;
115  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  CHECK(buffer[offset] == '\0'); // The null-terminator at the end of the SWTrace label
121 }
122 
123 TEST_CASE("TimelineRelationshipPacketNullBufferTest")
124 {
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);
140  CHECK(numberOfBytesWritten == 0);
141 }
142 
143 TEST_CASE("TimelineRelationshipPacketZeroBufferSizeTest")
144 {
145  std::vector<unsigned char> buffer(512, 0);
146 
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);
162  CHECK(numberOfBytesWritten == 0);
163 }
164 
165 TEST_CASE("TimelineRelationshipPacketSmallBufferSizeTest")
166 {
167  std::vector<unsigned char> buffer(10, 0);
168 
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);
185  CHECK(numberOfBytesWritten == 0);
186 }
187 
188 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  CHECK_THROWS_AS(WriteTimelineRelationshipBinary(relationshipType,
200  relationshipGuid,
201  headGuid,
202  tailGuid,
203  attributeGuid,
204  buffer.data(),
205  armnn::numeric_cast<unsigned int>(buffer.size()),
206  numberOfBytesWritten),
208 
209  CHECK(numberOfBytesWritten == 0);
210 }
211 
212 TEST_CASE("TimelineRelationshipPacketTestDataConstruction")
213 {
214  std::vector<unsigned char> buffer(512, 0);
215 
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  CHECK(result == TimelinePacketStatus::Ok);
232  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  CHECK(readDeclId == 3);
242 
243  // Check the relationship type
244  offset += uint32_t_size;
245  uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
246  CHECK(readRelationshipType == 0);
247 
248  // Check the relationship GUID
249  offset += uint32_t_size;
250  uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
251  CHECK(readRelationshipGuid == relationshipGuid);
252 
253  // Check the head GUID
254  offset += uint64_t_size;
255  uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
256  CHECK(readHeadGuid == headGuid);
257 
258  // Check the tail GUID
259  offset += uint64_t_size;
260  uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
261  CHECK(readTailGuid == tailGuid);
262 
263  // Check the attribute GUID
264  offset += uint64_t_size;
265  uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
266  CHECK(readAttributeGuid == attributeGuid);
267 }
268 
269 TEST_CASE("TimelineRelationshipPacketExecutionLinkTestDataConstruction")
270 {
271  std::vector<unsigned char> buffer(512, 0);
272 
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  CHECK(result == TimelinePacketStatus::Ok);
289  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  CHECK(readDeclId == 3);
297 
298  // Check the relationship type
299  offset += uint32_t_size;
300  uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
301  CHECK(readRelationshipType == 1);
302 
303  // Check the relationship GUID
304  offset += uint32_t_size;
305  uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
306  CHECK(readRelationshipGuid == relationshipGuid);
307 
308  // Check the head GUID
309  offset += uint64_t_size;
310  uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
311  CHECK(readHeadGuid == headGuid);
312 
313  // Check the tail GUID
314  offset += uint64_t_size;
315  uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
316  CHECK(readTailGuid == tailGuid);
317 
318  // Check the attribute GUID
319  offset += uint64_t_size;
320  uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
321  CHECK(readAttributeGuid == attributeGuid);
322 }
323 
324 
325 TEST_CASE("TimelineRelationshipPacketDataLinkTestDataConstruction")
326 {
327  std::vector<unsigned char> buffer(512, 0);
328 
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  CHECK(result == TimelinePacketStatus::Ok);
345  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  CHECK(readDeclId == 3);
353 
354  // Check the relationship type
355  offset += uint32_t_size;
356  uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
357  CHECK(readRelationshipType == 2);
358 
359  // Check the relationship GUID
360  offset += uint32_t_size;
361  uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
362  CHECK(readRelationshipGuid == relationshipGuid);
363 
364  // Check the head GUID
365  offset += uint64_t_size;
366  uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
367  CHECK(readHeadGuid == headGuid);
368 
369  // Check the tail GUID
370  offset += uint64_t_size;
371  uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
372  CHECK(readTailGuid == tailGuid);
373 
374  // Check the attribute GUID
375  offset += uint64_t_size;
376  uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
377  CHECK(readAttributeGuid == attributeGuid);
378 }
379 
380 
381 TEST_CASE("TimelineRelationshipPacketLabelLinkTestDataConstruction")
382 {
383  std::vector<unsigned char> buffer(512, 0);
384 
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  CHECK(result == TimelinePacketStatus::Ok);
401  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  CHECK(readDeclId == 3);
410 
411  // Check the relationship type
412  offset += uint32_t_size;
413  uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
414  CHECK(readRelationshipType == 3);
415 
416  // Check the relationship GUID
417  offset += uint32_t_size;
418  uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
419  CHECK(readRelationshipGuid == relationshipGuid);
420 
421  // Check the head GUID
422  offset += uint64_t_size;
423  uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
424  CHECK(readHeadGuid == headGuid);
425 
426  // Check the tail GUID
427  offset += uint64_t_size;
428  uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
429  CHECK(readTailGuid == tailGuid);
430 
431  // Check the attribute GUID
432  offset += uint64_t_size;
433  uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
434  CHECK(readAttributeGuid == attributeGuid);
435 }
436 
437 TEST_CASE("TimelineMessageDirectoryPacketTestNoBuffer")
438 {
439  unsigned int numberOfBytesWritten = 789u;
441  512u,
442  numberOfBytesWritten);
444  CHECK(numberOfBytesWritten == 0);
445 }
446 
447 TEST_CASE("TimelineMessageDirectoryPacketTestBufferExhausted")
448 {
449  std::vector<unsigned char> buffer(512, 0);
450 
451  unsigned int numberOfBytesWritten = 789u;
453  0,
454  numberOfBytesWritten);
456  CHECK(numberOfBytesWritten == 0);
457 }
458 
459 TEST_CASE("TimelineMessageDirectoryPacketTestFullConstruction")
460 {
461  std::vector<unsigned char> buffer(512, 0);
462  unsigned int numberOfBytesWritten = 789u;
464  armnn::numeric_cast<unsigned int>(buffer.size()),
465  numberOfBytesWritten);
466  CHECK(result == TimelinePacketStatus::Ok);
467 
468  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  CHECK(packetFamily == 1);
482  CHECK(packetClass == 0);
483  CHECK(packetType == 0);
484  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  CHECK(sequenceNumbered == 0);
491  CHECK(dataLength == 443);
492 
493  // Check the stream header
494  offset += uint32_t_size;
495  uint8_t readStreamVersion = ReadUint8(buffer.data(), offset);
496  CHECK(readStreamVersion == 4);
497  offset += uint8_t_size;
498  uint8_t readPointerBytes = ReadUint8(buffer.data(), offset);
499  CHECK(readPointerBytes == uint64_t_size);
500  offset += uint8_t_size;
501  uint8_t readThreadIdBytes = ReadUint8(buffer.data(), offset);
502  CHECK(readThreadIdBytes == ThreadIdSize);
503 
504  // Check the number of declarations
505  offset += uint8_t_size;
506  uint32_t declCount = ReadUint32(buffer.data(), offset);
507  CHECK(declCount == 5);
508 
509  // Check the decl_id
510  offset += uint32_t_size;
511  uint32_t readDeclId = ReadUint32(buffer.data(), offset);
512  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  CHECK(swTraceDeclNameLength == 13); // decl_name length including the null-terminator
521 
522  std::string label = "declareLabel";
523  offset += uint32_t_size;
524  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  CHECK(swTraceUINameLength == 14); // ui_name length including the null-terminator
534 
535  label = "declare label";
536  offset += uint32_t_size;
537  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  CHECK(swTraceArgTypesLength == 3); // arg_types length including the null-terminator
546 
547  label = "ps";
548  offset += uint32_t_size;
549  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  CHECK(swTraceArgNamesLength == 11); // arg_names length including the null-terminator
558 
559  label = "guid,value";
560  offset += uint32_t_size;
561  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  CHECK(readDeclId == 1);
570 
571  // Check second decl_name
572  offset += uint32_t_size;
573  swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
574  CHECK(swTraceDeclNameLength == 14); // decl_name length including the null-terminator
575 
576  label = "declareEntity";
577  offset += uint32_t_size;
578  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 
583 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);
592  CHECK(numberOfBytesWritten == 0);
593 }
594 
595 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);
606  CHECK(numberOfBytesWritten == 0);
607 }
608 
609 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);
620  CHECK(numberOfBytesWritten == 0);
621 }
622 
623 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  CHECK(result == TimelinePacketStatus::Ok);
634  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  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  CHECK(readProfilingGuid == profilingGuid);
647 }
648 
649 TEST_CASE("TimelineEventClassTestNoBuffer")
650 {
651  const uint64_t profilingGuid = 123456u;
652  const uint64_t profilingNameGuid = 3345u;
653  unsigned int numberOfBytesWritten = 789u;
655  profilingNameGuid,
656  nullptr,
657  512u,
658  numberOfBytesWritten);
660  CHECK(numberOfBytesWritten == 0);
661 }
662 
663 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;
671  profilingNameGuid,
672  buffer.data(),
673  0,
674  numberOfBytesWritten);
676  CHECK(numberOfBytesWritten == 0);
677 }
678 
679 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;
687  profilingNameGuid,
688  buffer.data(),
689  armnn::numeric_cast<unsigned int>(buffer.size()),
690  numberOfBytesWritten);
692  CHECK(numberOfBytesWritten == 0);
693 }
694 
695 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;
703  profilingNameGuid,
704  buffer.data(),
705  armnn::numeric_cast<unsigned int>(buffer.size()),
706  numberOfBytesWritten);
707  CHECK(result == TimelinePacketStatus::Ok);
708  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  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  CHECK(readProfilingGuid == profilingGuid);
722 
723  offset += uint64_t_size;
724  uint64_t readProfilingNameGuid = ReadUint64(buffer.data(), offset);
725  CHECK(readProfilingNameGuid == profilingNameGuid);
726 }
727 
728 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;
735  threadId,
736  profilingGuid,
737  nullptr,
738  512u,
739  numberOfBytesWritten);
741  CHECK(numberOfBytesWritten == 0);
742 }
743 
744 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;
753  threadId,
754  profilingGuid,
755  buffer.data(),
756  0,
757  numberOfBytesWritten);
759  CHECK(numberOfBytesWritten == 0);
760 }
761 
762 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;
771  threadId,
772  profilingGuid,
773  buffer.data(),
774  armnn::numeric_cast<unsigned int>(buffer.size()),
775  numberOfBytesWritten);
777  CHECK(numberOfBytesWritten == 0);
778 }
779 
780 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;
789  threadId,
790  profilingGuid,
791  buffer.data(),
792  armnn::numeric_cast<unsigned int>(buffer.size()),
793  numberOfBytesWritten);
794  CHECK(result == TimelinePacketStatus::Ok);
795 
796  unsigned int uint32_t_size = sizeof(uint32_t);
797  unsigned int uint64_t_size = sizeof(uint64_t);
798  CHECK(numberOfBytesWritten == 20 + ThreadIdSize);
799 
800  unsigned int offset = 0;
801  // Check the decl_id
802  uint32_t readDeclId = ReadUint32(buffer.data(), offset);
803  CHECK(readDeclId == 4);
804 
805  // Check the timestamp
806  offset += uint32_t_size;
807  uint64_t readTimestamp = ReadUint64(buffer.data(), offset);
808  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  CHECK(readThreadId == threadId);
815 
816  // Check the profiling GUID
817  offset += ThreadIdSize;
818  uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
819  CHECK(readProfilingGuid == profilingGuid);
820 }
821 
822 }
TEST_SUITE("TestConstTensorLayerVisitor")
TimelinePacketStatus WriteTimelineMessageDirectoryPackage(unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
int GetCurrentThreadId()
Definition: Threads.cpp:27
void ReadBytes(const IPacketBufferPtr &packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[])
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
TimelinePacketStatus WriteTimelineRelationshipBinary(ProfilingRelationshipType relationshipType, uint64_t relationshipGuid, uint64_t headGuid, uint64_t tailGuid, uint64_t attributeGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
uint8_t ReadUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset)
Head execution start depends on Tail execution completion.
TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp, int threadId, uint64_t profilingGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
constexpr unsigned int ThreadIdSize
TimelinePacketStatus WriteTimelineEventClassBinary(uint64_t profilingGuid, uint64_t nameGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
TimelinePacketStatus WriteTimelineLabelBinaryPacket(uint64_t profilingGuid, const std::string &label, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
TimelinePacketStatus WriteTimelineEntityBinary(uint64_t profilingGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)