ArmNN
 20.05
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 
433  // Check the packet header
434  unsigned int offset = 0;
435  uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
436  uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
437  uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
438  uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
439  uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
440  BOOST_CHECK(packetFamily == 1);
441  BOOST_CHECK(packetClass == 0);
442  BOOST_CHECK(packetType == 0);
443  BOOST_CHECK(streamId == 0);
444 
445  offset += uint32_t_size;
446  uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
447  uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
448  uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
449  BOOST_CHECK(sequenceNumbered == 0);
450  BOOST_CHECK(dataLength == 419);
451 
452  // Check the stream header
453  offset += uint32_t_size;
454  uint8_t readStreamVersion = ReadUint8(buffer.data(), offset);
455  BOOST_CHECK(readStreamVersion == 4);
456  offset += uint8_t_size;
457  uint8_t readPointerBytes = ReadUint8(buffer.data(), offset);
458  BOOST_CHECK(readPointerBytes == uint64_t_size);
459  offset += uint8_t_size;
460  uint8_t readThreadIdBytes = ReadUint8(buffer.data(), offset);
461  BOOST_CHECK(readThreadIdBytes == ThreadIdSize);
462 
463  // Check the number of declarations
464  offset += uint8_t_size;
465  uint32_t declCount = ReadUint32(buffer.data(), offset);
466  BOOST_CHECK(declCount == 5);
467 
468  // Check the decl_id
469  offset += uint32_t_size;
470  uint32_t readDeclId = ReadUint32(buffer.data(), offset);
471  BOOST_CHECK(readDeclId == 0);
472 
473  // SWTrace "namestring" format
474  // length of the string (first 4 bytes) + string + null terminator
475 
476  // Check the decl_name
477  offset += uint32_t_size;
478  uint32_t swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
479  BOOST_CHECK(swTraceDeclNameLength == 13); // decl_name length including the null-terminator
480 
481  std::string label = "declareLabel";
482  offset += uint32_t_size;
483  BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
484  label.data(), // The original label
485  swTraceDeclNameLength - 1) == 0); // The length of the label
486 
487  // Check the ui_name
488  std::vector<uint32_t> swTraceString;
489  StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
490  offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
491  uint32_t swTraceUINameLength = ReadUint32(buffer.data(), offset);
492  BOOST_CHECK(swTraceUINameLength == 14); // ui_name length including the null-terminator
493 
494  label = "declare label";
495  offset += uint32_t_size;
496  BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
497  label.data(), // The original label
498  swTraceUINameLength - 1) == 0); // The length of the label
499 
500  // Check arg_types
501  StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
502  offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
503  uint32_t swTraceArgTypesLength = ReadUint32(buffer.data(), offset);
504  BOOST_CHECK(swTraceArgTypesLength == 3); // arg_types length including the null-terminator
505 
506  label = "ps";
507  offset += uint32_t_size;
508  BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
509  label.data(), // The original label
510  swTraceArgTypesLength - 1) == 0); // The length of the label
511 
512  // Check arg_names
513  StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
514  offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
515  uint32_t swTraceArgNamesLength = ReadUint32(buffer.data(), offset);
516  BOOST_CHECK(swTraceArgNamesLength == 11); // arg_names length including the null-terminator
517 
518  label = "guid,value";
519  offset += uint32_t_size;
520  BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
521  label.data(), // The original label
522  swTraceArgNamesLength - 1) == 0); // The length of the label
523 
524  // Check second message decl_id
525  StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
526  offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
527  readDeclId = ReadUint32(buffer.data(), offset);
528  BOOST_CHECK(readDeclId == 1);
529 
530  // Check second decl_name
531  offset += uint32_t_size;
532  swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
533  BOOST_CHECK(swTraceDeclNameLength == 14); // decl_name length including the null-terminator
534 
535  label = "declareEntity";
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  swTraceDeclNameLength - 1) == 0); // The length of the label
540 }
541 
542 BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestNoBuffer)
543 {
544  const uint64_t profilingGuid = 123456u;
545  unsigned int numberOfBytesWritten = 789u;
546  TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
547  nullptr,
548  512u,
549  numberOfBytesWritten);
551  BOOST_CHECK(numberOfBytesWritten == 0);
552 }
553 
554 BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithZeroBufferSize)
555 {
556  std::vector<unsigned char> buffer(512, 0);
557 
558  const uint64_t profilingGuid = 123456u;
559  unsigned int numberOfBytesWritten = 789u;
560  TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
561  buffer.data(),
562  0,
563  numberOfBytesWritten);
565  BOOST_CHECK(numberOfBytesWritten == 0);
566 }
567 
568 BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithFixedBufferSize)
569 {
570  std::vector<unsigned char> buffer(10, 0);
571 
572  const uint64_t profilingGuid = 123456u;
573  unsigned int numberOfBytesWritten = 789u;
574  TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
575  buffer.data(),
576  boost::numeric_cast<unsigned int>(buffer.size()),
577  numberOfBytesWritten);
579  BOOST_CHECK(numberOfBytesWritten == 0);
580 }
581 
582 BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestFullConstructionOfData)
583 {
584  std::vector<unsigned char> buffer(512, 0);
585 
586  const uint64_t profilingGuid = 123456u;
587  unsigned int numberOfBytesWritten = 789u;
588  TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
589  buffer.data(),
590  boost::numeric_cast<unsigned int>(buffer.size()),
591  numberOfBytesWritten);
593  BOOST_CHECK(numberOfBytesWritten == 12);
594 
595  unsigned int uint32_t_size = sizeof(uint32_t);
596 
597  unsigned int offset = 0;
598  // Check decl_Id
599  uint32_t decl_Id = ReadUint32(buffer.data(), offset);
600  BOOST_CHECK(decl_Id == uint32_t(1));
601 
602  // Check the profiling GUID
603  offset += uint32_t_size;
604  uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
605  BOOST_CHECK(readProfilingGuid == profilingGuid);
606 }
607 
608 BOOST_AUTO_TEST_CASE(TimelineEventClassTestNoBuffer)
609 {
610  const uint64_t profilingGuid = 123456u;
611  unsigned int numberOfBytesWritten = 789u;
613  nullptr,
614  512u,
615  numberOfBytesWritten);
617  BOOST_CHECK(numberOfBytesWritten == 0);
618 }
619 
620 BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionZeroValue)
621 {
622  std::vector<unsigned char> buffer(512, 0);
623 
624  const uint64_t profilingGuid = 123456u;
625  unsigned int numberOfBytesWritten = 789u;
627  buffer.data(),
628  0,
629  numberOfBytesWritten);
631  BOOST_CHECK(numberOfBytesWritten == 0);
632 }
633 
634 BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionFixedValue)
635 {
636  std::vector<unsigned char> buffer(10, 0);
637 
638  const uint64_t profilingGuid = 123456u;
639  unsigned int numberOfBytesWritten = 789u;
641  buffer.data(),
642  boost::numeric_cast<unsigned int>(buffer.size()),
643  numberOfBytesWritten);
645  BOOST_CHECK(numberOfBytesWritten == 0);
646 }
647 
648 BOOST_AUTO_TEST_CASE(TimelineEventClassTestFullConstructionOfData)
649 {
650  std::vector<unsigned char> buffer(512, 0);
651 
652  const uint64_t profilingGuid = 123456u;
653  unsigned int numberOfBytesWritten = 789u;
655  buffer.data(),
656  boost::numeric_cast<unsigned int>(buffer.size()),
657  numberOfBytesWritten);
659  BOOST_CHECK(numberOfBytesWritten == 12);
660 
661  unsigned int uint32_t_size = sizeof(uint32_t);
662 
663  unsigned int offset = 0;
664  // Check the decl_id
665  uint32_t declId = ReadUint32(buffer.data(), offset);
666  BOOST_CHECK(declId == uint32_t(2));
667 
668  // Check the profiling GUID
669  offset += uint32_t_size;
670  uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
671  BOOST_CHECK(readProfilingGuid == profilingGuid);
672 }
673 
674 BOOST_AUTO_TEST_CASE(TimelineEventPacketTestNoBuffer)
675 {
676  const uint64_t timestamp = 456789u;
677  const std::thread::id threadId = std::this_thread::get_id();
678  const uint64_t profilingGuid = 123456u;
679  unsigned int numberOfBytesWritten = 789u;
681  threadId,
682  profilingGuid,
683  nullptr,
684  512u,
685  numberOfBytesWritten);
687  BOOST_CHECK(numberOfBytesWritten == 0);
688 }
689 
690 BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionZeroValue)
691 {
692  std::vector<unsigned char> buffer(512, 0);
693 
694  const uint64_t timestamp = 456789u;
695  const std::thread::id threadId = std::this_thread::get_id();
696  const uint64_t profilingGuid = 123456u;
697  unsigned int numberOfBytesWritten = 789u;
699  threadId,
700  profilingGuid,
701  buffer.data(),
702  0,
703  numberOfBytesWritten);
705  BOOST_CHECK(numberOfBytesWritten == 0);
706 }
707 
708 BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionFixedValue)
709 {
710  std::vector<unsigned char> buffer(10, 0);
711 
712  const uint64_t timestamp = 456789u;
713  const std::thread::id threadId = std::this_thread::get_id();
714  const uint64_t profilingGuid = 123456u;
715  unsigned int numberOfBytesWritten = 789u;
717  threadId,
718  profilingGuid,
719  buffer.data(),
720  boost::numeric_cast<unsigned int>(buffer.size()),
721  numberOfBytesWritten);
723  BOOST_CHECK(numberOfBytesWritten == 0);
724 }
725 
726 BOOST_AUTO_TEST_CASE(TimelineEventPacketTestFullConstructionOfData)
727 {
728  std::vector<unsigned char> buffer(512, 0);
729 
730  const uint64_t timestamp = 456789u;
731  const std::thread::id threadId = std::this_thread::get_id();
732  const uint64_t profilingGuid = 123456u;
733  unsigned int numberOfBytesWritten = 789u;
735  threadId,
736  profilingGuid,
737  buffer.data(),
738  boost::numeric_cast<unsigned int>(buffer.size()),
739  numberOfBytesWritten);
741 
742  unsigned int uint32_t_size = sizeof(uint32_t);
743  unsigned int uint64_t_size = sizeof(uint64_t);
744  BOOST_CHECK(numberOfBytesWritten == 20 + ThreadIdSize);
745 
746  unsigned int offset = 0;
747  // Check the decl_id
748  uint32_t readDeclId = ReadUint32(buffer.data(), offset);
749  BOOST_CHECK(readDeclId == 4);
750 
751  // Check the timestamp
752  offset += uint32_t_size;
753  uint64_t readTimestamp = ReadUint64(buffer.data(), offset);
754  BOOST_CHECK(readTimestamp == timestamp);
755 
756  // Check the thread id
757  offset += uint64_t_size;
758  std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
759  ReadBytes(buffer.data(), offset, ThreadIdSize, readThreadId.data());
760  BOOST_CHECK(readThreadId == threadId);
761 
762  // Check the profiling GUID
763  offset += ThreadIdSize;
764  uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
765  BOOST_CHECK(readProfilingGuid == profilingGuid);
766 }
767 
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)
constexpr unsigned int ThreadIdSize
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)