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