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