ArmNN
 22.05.01
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 <client/src/ProfilingUtils.hpp>
7 
8 #include <common/include/NumericCast.hpp>
9 #include <common/include/SwTrace.hpp>
10 #include <common/include/Threads.hpp>
11 
12 #include <doctest/doctest.h>
13 
14 using namespace arm::pipe;
15 
16 TEST_SUITE("TimelinePacketTests")
17 {
18 TEST_CASE("TimelineLabelPacketTestNoBuffer")
19 {
20  const uint64_t profilingGuid = 123456u;
21  const std::string label = "some label";
22  unsigned int numberOfBytesWritten = 789u;
23  TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
24  label,
25  nullptr,
26  512u,
27  numberOfBytesWritten);
28  CHECK(result == TimelinePacketStatus::BufferExhaustion);
29  CHECK(numberOfBytesWritten == 0);
30 }
31 
32 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;
39  TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
40  label,
41  buffer.data(),
42  0,
43  numberOfBytesWritten);
44  CHECK(result == TimelinePacketStatus::BufferExhaustion);
45  CHECK(numberOfBytesWritten == 0);
46 }
47 
48 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;
55  TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
56  label,
57  buffer.data(),
58  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
59  numberOfBytesWritten);
60  CHECK(result == TimelinePacketStatus::BufferExhaustion);
61  CHECK(numberOfBytesWritten == 0);
62 }
63 
64 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;
71  TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
72  label,
73  buffer.data(),
74  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
75  numberOfBytesWritten);
76  CHECK(result == TimelinePacketStatus::Error);
77  CHECK(numberOfBytesWritten == 0);
78 }
79 
80 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;
87  TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
88  label,
89  buffer.data(),
90  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
91  numberOfBytesWritten);
92  CHECK(result == TimelinePacketStatus::Ok);
93  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  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  CHECK(readProfilingGuid == profilingGuid);
107 
108  // Check the SWTrace label
109  offset += uint64_t_size;
110  uint32_t swTraceLabelLength = ReadUint32(buffer.data(), offset);
111  CHECK(swTraceLabelLength == 11); // Label length including the null-terminator
112 
113  offset += uint32_t_size;
114  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  CHECK(buffer[offset] == '\0'); // The null-terminator at the end of the SWTrace label
120 }
121 
122 TEST_CASE("TimelineRelationshipPacketNullBufferTest")
123 {
124  ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
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  CHECK(result == TimelinePacketStatus::BufferExhaustion);
139  CHECK(numberOfBytesWritten == 0);
140 }
141 
142 TEST_CASE("TimelineRelationshipPacketZeroBufferSizeTest")
143 {
144  std::vector<unsigned char> buffer(512, 0);
145 
146  ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
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  CHECK(result == TimelinePacketStatus::BufferExhaustion);
161  CHECK(numberOfBytesWritten == 0);
162 }
163 
164 TEST_CASE("TimelineRelationshipPacketSmallBufferSizeTest")
165 {
166  std::vector<unsigned char> buffer(10, 0);
167 
168  ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
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  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
182  numberOfBytesWritten);
183  CHECK(result == TimelinePacketStatus::BufferExhaustion);
184  CHECK(numberOfBytesWritten == 0);
185 }
186 
187 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  CHECK_THROWS_AS(WriteTimelineRelationshipBinary(relationshipType,
199  relationshipGuid,
200  headGuid,
201  tailGuid,
202  attributeGuid,
203  buffer.data(),
204  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
205  numberOfBytesWritten),
206  arm::pipe::InvalidArgumentException);
207 
208  CHECK(numberOfBytesWritten == 0);
209 }
210 
211 TEST_CASE("TimelineRelationshipPacketTestDataConstruction")
212 {
213  std::vector<unsigned char> buffer(512, 0);
214 
215  ProfilingRelationshipType relationshipType = ProfilingRelationshipType::RetentionLink;
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  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
229  numberOfBytesWritten);
230  CHECK(result == TimelinePacketStatus::Ok);
231  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  CHECK(readDeclId == 3);
241 
242  // Check the relationship type
243  offset += uint32_t_size;
244  uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
245  CHECK(readRelationshipType == 0);
246 
247  // Check the relationship GUID
248  offset += uint32_t_size;
249  uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
250  CHECK(readRelationshipGuid == relationshipGuid);
251 
252  // Check the head GUID
253  offset += uint64_t_size;
254  uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
255  CHECK(readHeadGuid == headGuid);
256 
257  // Check the tail GUID
258  offset += uint64_t_size;
259  uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
260  CHECK(readTailGuid == tailGuid);
261 
262  // Check the attribute GUID
263  offset += uint64_t_size;
264  uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
265  CHECK(readAttributeGuid == attributeGuid);
266 }
267 
268 TEST_CASE("TimelineRelationshipPacketExecutionLinkTestDataConstruction")
269 {
270  std::vector<unsigned char> buffer(512, 0);
271 
272  ProfilingRelationshipType relationshipType = ProfilingRelationshipType::ExecutionLink;
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  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
286  numberOfBytesWritten);
287  CHECK(result == TimelinePacketStatus::Ok);
288  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  CHECK(readDeclId == 3);
296 
297  // Check the relationship type
298  offset += uint32_t_size;
299  uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
300  CHECK(readRelationshipType == 1);
301 
302  // Check the relationship GUID
303  offset += uint32_t_size;
304  uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
305  CHECK(readRelationshipGuid == relationshipGuid);
306 
307  // Check the head GUID
308  offset += uint64_t_size;
309  uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
310  CHECK(readHeadGuid == headGuid);
311 
312  // Check the tail GUID
313  offset += uint64_t_size;
314  uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
315  CHECK(readTailGuid == tailGuid);
316 
317  // Check the attribute GUID
318  offset += uint64_t_size;
319  uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
320  CHECK(readAttributeGuid == attributeGuid);
321 }
322 
323 
324 TEST_CASE("TimelineRelationshipPacketDataLinkTestDataConstruction")
325 {
326  std::vector<unsigned char> buffer(512, 0);
327 
328  ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
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  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
342  numberOfBytesWritten);
343  CHECK(result == TimelinePacketStatus::Ok);
344  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  CHECK(readDeclId == 3);
352 
353  // Check the relationship type
354  offset += uint32_t_size;
355  uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
356  CHECK(readRelationshipType == 2);
357 
358  // Check the relationship GUID
359  offset += uint32_t_size;
360  uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
361  CHECK(readRelationshipGuid == relationshipGuid);
362 
363  // Check the head GUID
364  offset += uint64_t_size;
365  uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
366  CHECK(readHeadGuid == headGuid);
367 
368  // Check the tail GUID
369  offset += uint64_t_size;
370  uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
371  CHECK(readTailGuid == tailGuid);
372 
373  // Check the attribute GUID
374  offset += uint64_t_size;
375  uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
376  CHECK(readAttributeGuid == attributeGuid);
377 }
378 
379 
380 TEST_CASE("TimelineRelationshipPacketLabelLinkTestDataConstruction")
381 {
382  std::vector<unsigned char> buffer(512, 0);
383 
384  ProfilingRelationshipType relationshipType = ProfilingRelationshipType::LabelLink;
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  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
398  numberOfBytesWritten);
399  CHECK(result == TimelinePacketStatus::Ok);
400  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  CHECK(readDeclId == 3);
409 
410  // Check the relationship type
411  offset += uint32_t_size;
412  uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
413  CHECK(readRelationshipType == 3);
414 
415  // Check the relationship GUID
416  offset += uint32_t_size;
417  uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
418  CHECK(readRelationshipGuid == relationshipGuid);
419 
420  // Check the head GUID
421  offset += uint64_t_size;
422  uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
423  CHECK(readHeadGuid == headGuid);
424 
425  // Check the tail GUID
426  offset += uint64_t_size;
427  uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
428  CHECK(readTailGuid == tailGuid);
429 
430  // Check the attribute GUID
431  offset += uint64_t_size;
432  uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
433  CHECK(readAttributeGuid == attributeGuid);
434 }
435 
436 TEST_CASE("TimelineMessageDirectoryPacketTestNoBuffer")
437 {
438  unsigned int numberOfBytesWritten = 789u;
439  TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(nullptr,
440  512u,
441  numberOfBytesWritten);
442  CHECK(result == TimelinePacketStatus::BufferExhaustion);
443  CHECK(numberOfBytesWritten == 0);
444 }
445 
446 TEST_CASE("TimelineMessageDirectoryPacketTestBufferExhausted")
447 {
448  std::vector<unsigned char> buffer(512, 0);
449 
450  unsigned int numberOfBytesWritten = 789u;
451  TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(),
452  0,
453  numberOfBytesWritten);
454  CHECK(result == TimelinePacketStatus::BufferExhaustion);
455  CHECK(numberOfBytesWritten == 0);
456 }
457 
458 TEST_CASE("TimelineMessageDirectoryPacketTestFullConstruction")
459 {
460  std::vector<unsigned char> buffer(512, 0);
461  unsigned int numberOfBytesWritten = 789u;
462  TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(),
463  arm::pipe::numeric_cast<unsigned int>(
464  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  StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
531  offset += (arm::pipe::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  StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
543  offset += (arm::pipe::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  StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
555  offset += (arm::pipe::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  StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
567  offset += (arm::pipe::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);
591  CHECK(result == TimelinePacketStatus::BufferExhaustion);
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);
605  CHECK(result == TimelinePacketStatus::BufferExhaustion);
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  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
618  numberOfBytesWritten);
619  CHECK(result == TimelinePacketStatus::BufferExhaustion);
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  arm::pipe::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;
654  TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
655  profilingNameGuid,
656  nullptr,
657  512u,
658  numberOfBytesWritten);
659  CHECK(result == TimelinePacketStatus::BufferExhaustion);
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;
670  TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
671  profilingNameGuid,
672  buffer.data(),
673  0,
674  numberOfBytesWritten);
675  CHECK(result == TimelinePacketStatus::BufferExhaustion);
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;
686  TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
687  profilingNameGuid,
688  buffer.data(),
689  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
690  numberOfBytesWritten);
691  CHECK(result == TimelinePacketStatus::BufferExhaustion);
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;
702  TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
703  profilingNameGuid,
704  buffer.data(),
705  arm::pipe::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 = arm::pipe::GetCurrentThreadId();
732  const uint64_t profilingGuid = 123456u;
733  unsigned int numberOfBytesWritten = 789u;
734  TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
735  threadId,
736  profilingGuid,
737  nullptr,
738  512u,
739  numberOfBytesWritten);
740  CHECK(result == TimelinePacketStatus::BufferExhaustion);
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 = arm::pipe::GetCurrentThreadId();
750  const uint64_t profilingGuid = 123456u;
751  unsigned int numberOfBytesWritten = 789u;
752  TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
753  threadId,
754  profilingGuid,
755  buffer.data(),
756  0,
757  numberOfBytesWritten);
758  CHECK(result == TimelinePacketStatus::BufferExhaustion);
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 = arm::pipe::GetCurrentThreadId();
768  const uint64_t profilingGuid = 123456u;
769  unsigned int numberOfBytesWritten = 789u;
770  TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
771  threadId,
772  profilingGuid,
773  buffer.data(),
774  arm::pipe::numeric_cast<unsigned int>(buffer.size()),
775  numberOfBytesWritten);
776  CHECK(result == TimelinePacketStatus::BufferExhaustion);
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 = arm::pipe::GetCurrentThreadId();
786  const uint64_t profilingGuid = 123456u;
787  unsigned int numberOfBytesWritten = 789u;
788  TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
789  threadId,
790  profilingGuid,
791  buffer.data(),
792  arm::pipe::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("TimelinePacketTests")
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35