blob: 68cd948bdd8e41453aebe4c699ec23b0680d0bc6 [file] [log] [blame]
Matteo Martincigh0aed4f92019-10-01 14:25:34 +01001//
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
11using namespace armnn::profiling;
12
13BOOST_AUTO_TEST_SUITE(TimelinePacketTests)
14
15BOOST_AUTO_TEST_CASE(TimelineLabelPacketTest1)
16{
17 const uint64_t profilingGuid = 123456u;
18 const std::string label = "some label";
19 unsigned int numberOfBytesWritten = 789u;
20 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
21 label,
22 nullptr,
23 512u,
24 numberOfBytesWritten);
25 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
26 BOOST_CHECK(numberOfBytesWritten == 0);
27}
28
29BOOST_AUTO_TEST_CASE(TimelineLabelPacketTest2)
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;
36 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
37 label,
38 buffer.data(),
39 0,
40 numberOfBytesWritten);
41 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
42 BOOST_CHECK(numberOfBytesWritten == 0);
43}
44
45BOOST_AUTO_TEST_CASE(TimelineLabelPacketTest3)
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;
52 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
53 label,
54 buffer.data(),
55 boost::numeric_cast<unsigned int>(buffer.size()),
56 numberOfBytesWritten);
57 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
58 BOOST_CHECK(numberOfBytesWritten == 0);
59}
60
61BOOST_AUTO_TEST_CASE(TimelineLabelPacketTest4)
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;
68 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
69 label,
70 buffer.data(),
71 boost::numeric_cast<unsigned int>(buffer.size()),
72 numberOfBytesWritten);
73 BOOST_CHECK(result == TimelinePacketStatus::Error);
74 BOOST_CHECK(numberOfBytesWritten == 0);
75}
76
77BOOST_AUTO_TEST_CASE(TimelineLabelPacketTest5)
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;
84 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
85 label,
86 buffer.data(),
87 boost::numeric_cast<unsigned int>(buffer.size()),
88 numberOfBytesWritten);
89 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Jan Eilersb884ea42019-10-16 09:54:15 +010090 BOOST_CHECK(numberOfBytesWritten == 36);
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010091
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 packetHeaderWord0 = ReadUint32(buffer.data(), offset);
98 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
99 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
100 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
101 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
102 BOOST_CHECK(packetFamily == 1);
103 BOOST_CHECK(packetClass == 0);
104 BOOST_CHECK(packetType == 1);
105 BOOST_CHECK(streamId == 0);
106
107 offset += uint32_t_size;
108 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
109 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
110 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
111 BOOST_CHECK(sequenceNumbered == 0);
Jan Eilersb884ea42019-10-16 09:54:15 +0100112 BOOST_CHECK(dataLength == 28);
113
114 // Check decl_Id
115 offset += uint32_t_size;
116 uint32_t decl_Id = ReadUint32(buffer.data(), offset);
117 BOOST_CHECK(decl_Id == uint32_t(0));
Matteo Martincigh0aed4f92019-10-01 14:25:34 +0100118
119 // Check the profiling GUID
120 offset += uint32_t_size;
121 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
122 BOOST_CHECK(readProfilingGuid == profilingGuid);
123
124 // Check the SWTrace label
125 offset += uint64_t_size;
126 uint32_t swTraceLabelLength = ReadUint32(buffer.data(), offset);
127 BOOST_CHECK(swTraceLabelLength == 11); // Label length including the null-terminator
128
129 offset += uint32_t_size;
130 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
131 label.data(), // The original label
132 swTraceLabelLength - 1) == 0); // The length of the label
133
134 offset += swTraceLabelLength * uint32_t_size;
135 BOOST_CHECK(buffer[offset] == '\0'); // The null-terminator at the end of the SWTrace label
136}
137
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100138BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketNullBufferTest)
139{
140 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
141 const uint64_t relationshipGuid = 123456u;
142 const uint64_t headGuid = 234567u;
143 const uint64_t tailGuid = 345678u;
144 unsigned int numberOfBytesWritten = 789u;
145 TimelinePacketStatus result = WriteTimelineRelationshipBinaryPacket(relationshipType,
146 relationshipGuid,
147 headGuid,
148 tailGuid,
149 nullptr,
150 512u,
151 numberOfBytesWritten);
152 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
153 BOOST_CHECK(numberOfBytesWritten == 0);
154}
155
156BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketZeroBufferSizeTest)
157{
158 std::vector<unsigned char> buffer(512, 0);
159
160 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
161 const uint64_t relationshipGuid = 123456u;
162 const uint64_t headGuid = 234567u;
163 const uint64_t tailGuid = 345678u;
164 unsigned int numberOfBytesWritten = 789u;
165 TimelinePacketStatus result = WriteTimelineRelationshipBinaryPacket(relationshipType,
166 relationshipGuid,
167 headGuid,
168 tailGuid,
169 buffer.data(),
170 0,
171 numberOfBytesWritten);
172 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
173 BOOST_CHECK(numberOfBytesWritten == 0);
174}
175
176BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketSmallBufferSizeTest)
177{
178 std::vector<unsigned char> buffer(10, 0);
179
180 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
181 const uint64_t relationshipGuid = 123456u;
182 const uint64_t headGuid = 234567u;
183 const uint64_t tailGuid = 345678u;
184 unsigned int numberOfBytesWritten = 789u;
185 TimelinePacketStatus result =
186 WriteTimelineRelationshipBinaryPacket(relationshipType,
187 relationshipGuid,
188 headGuid,
189 tailGuid,
190 buffer.data(),
191 boost::numeric_cast<unsigned int>(buffer.size()),
192 numberOfBytesWritten);
193 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
194 BOOST_CHECK(numberOfBytesWritten == 0);
195}
196
197BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketInvalidRelationTest)
198{
199 std::vector<unsigned char> buffer(512, 0);
200 ProfilingRelationshipType relationshipType = static_cast<ProfilingRelationshipType>(5);
201 const uint64_t relationshipGuid = 123456u;
202 const uint64_t headGuid = 234567u;
203 const uint64_t tailGuid = 345678u;
204 unsigned int numberOfBytesWritten = 789u;
205
206 BOOST_CHECK_THROW(WriteTimelineRelationshipBinaryPacket(relationshipType,
207 relationshipGuid,
208 headGuid,
209 tailGuid,
210 buffer.data(),
211 boost::numeric_cast<unsigned int>(buffer.size()),
212 numberOfBytesWritten),
213 armnn::InvalidArgumentException);
214
215 BOOST_CHECK(numberOfBytesWritten == 0);
216}
217
218BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketTest)
219{
220 std::vector<unsigned char> buffer(512, 0);
221
222 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::RetentionLink;
223 const uint64_t relationshipGuid = 123456u;
224 const uint64_t headGuid = 234567u;
225 const uint64_t tailGuid = 345678u;
226 unsigned int numberOfBytesWritten = 789u;
227 TimelinePacketStatus result =
228 WriteTimelineRelationshipBinaryPacket(relationshipType,
229 relationshipGuid,
230 headGuid,
231 tailGuid,
232 buffer.data(),
233 boost::numeric_cast<unsigned int>(buffer.size()),
234 numberOfBytesWritten);
235 BOOST_CHECK(result == TimelinePacketStatus::Ok);
236 BOOST_CHECK(numberOfBytesWritten == 40);
237
238 unsigned int uint32_t_size = sizeof(uint32_t);
239 unsigned int uint64_t_size = sizeof(uint64_t);
240
241 // Check the packet header
242 unsigned int offset = 0;
243 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
244 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
245 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
246 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
247 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
248 BOOST_CHECK(packetFamily == 1);
249 BOOST_CHECK(packetClass == 0);
250 BOOST_CHECK(packetType == 1);
251 BOOST_CHECK(streamId == 0);
252
253 offset += uint32_t_size;
254 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
255 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
256 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
257 BOOST_CHECK(sequenceNumbered == 0);
258 BOOST_CHECK(dataLength == 32);
259
260 // Check the decl_id
261 offset += uint32_t_size;
262 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
263 BOOST_CHECK(readDeclId == 3);
264
265 // Check the relationship type
266 offset += uint32_t_size;
267 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
268 BOOST_CHECK(readRelationshipType == 0);
269
270 // Check the relationship GUID
271 offset += uint32_t_size;
272 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
273 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
274
275 // Check the head GUID
276 offset += uint64_t_size;
277 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
278 BOOST_CHECK(readHeadGuid == headGuid);
279
280 // Check the tail GUID
281 offset += uint64_t_size;
282 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
283 BOOST_CHECK(readTailGuid == tailGuid);
284}
285
286BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketExecutionLinkTest)
287{
288 std::vector<unsigned char> buffer(512, 0);
289
290 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::ExecutionLink;
291 const uint64_t relationshipGuid = 123456u;
292 const uint64_t headGuid = 234567u;
293 const uint64_t tailGuid = 345678u;
294 unsigned int numberOfBytesWritten = 789u;
295 TimelinePacketStatus result =
296 WriteTimelineRelationshipBinaryPacket(relationshipType,
297 relationshipGuid,
298 headGuid,
299 tailGuid,
300 buffer.data(),
301 boost::numeric_cast<unsigned int>(buffer.size()),
302 numberOfBytesWritten);
303 BOOST_CHECK(result == TimelinePacketStatus::Ok);
304 BOOST_CHECK(numberOfBytesWritten == 40);
305
306 unsigned int uint32_t_size = sizeof(uint32_t);
307 unsigned int uint64_t_size = sizeof(uint64_t);
308
309 // Check the packet header
310 unsigned int offset = 0;
311 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
312 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
313 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
314 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
315 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
316 BOOST_CHECK(packetFamily == 1);
317 BOOST_CHECK(packetClass == 0);
318 BOOST_CHECK(packetType == 1);
319 BOOST_CHECK(streamId == 0);
320
321 offset += uint32_t_size;
322 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
323 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
324 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
325 BOOST_CHECK(sequenceNumbered == 0);
326 BOOST_CHECK(dataLength == 32);
327
328 // Check the decl_id
329 offset += uint32_t_size;
330 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
331 BOOST_CHECK(readDeclId == 3);
332
333 // Check the relationship type
334 offset += uint32_t_size;
335 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
336 BOOST_CHECK(readRelationshipType == 1);
337
338 // Check the relationship GUID
339 offset += uint32_t_size;
340 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
341 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
342
343 // Check the head GUID
344 offset += uint64_t_size;
345 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
346 BOOST_CHECK(readHeadGuid == headGuid);
347
348 // Check the tail GUID
349 offset += uint64_t_size;
350 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
351 BOOST_CHECK(readTailGuid == tailGuid);
352}
353
354
355BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketDataLinkTest)
356{
357 std::vector<unsigned char> buffer(512, 0);
358
359 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
360 const uint64_t relationshipGuid = 123456u;
361 const uint64_t headGuid = 234567u;
362 const uint64_t tailGuid = 345678u;
363 unsigned int numberOfBytesWritten = 789u;
364 TimelinePacketStatus result =
365 WriteTimelineRelationshipBinaryPacket(relationshipType,
366 relationshipGuid,
367 headGuid,
368 tailGuid,
369 buffer.data(),
370 boost::numeric_cast<unsigned int>(buffer.size()),
371 numberOfBytesWritten);
372 BOOST_CHECK(result == TimelinePacketStatus::Ok);
373 BOOST_CHECK(numberOfBytesWritten == 40);
374
375 unsigned int uint32_t_size = sizeof(uint32_t);
376 unsigned int uint64_t_size = sizeof(uint64_t);
377
378 // Check the packet header
379 unsigned int offset = 0;
380 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
381 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
382 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
383 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
384 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
385 BOOST_CHECK(packetFamily == 1);
386 BOOST_CHECK(packetClass == 0);
387 BOOST_CHECK(packetType == 1);
388 BOOST_CHECK(streamId == 0);
389
390 offset += uint32_t_size;
391 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
392 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
393 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
394 BOOST_CHECK(sequenceNumbered == 0);
395 BOOST_CHECK(dataLength == 32);
396
397 // Check the decl_id
398 offset += uint32_t_size;
399 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
400 BOOST_CHECK(readDeclId == 3);
401
402 // Check the relationship type
403 offset += uint32_t_size;
404 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
405 BOOST_CHECK(readRelationshipType == 2);
406
407 // Check the relationship GUID
408 offset += uint32_t_size;
409 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
410 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
411
412 // Check the head GUID
413 offset += uint64_t_size;
414 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
415 BOOST_CHECK(readHeadGuid == headGuid);
416
417 // Check the tail GUID
418 offset += uint64_t_size;
419 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
420 BOOST_CHECK(readTailGuid == tailGuid);
421}
422
423
424BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketLabelLinkTest)
425{
426 std::vector<unsigned char> buffer(512, 0);
427
428 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::LabelLink;
429 const uint64_t relationshipGuid = 123456u;
430 const uint64_t headGuid = 234567u;
431 const uint64_t tailGuid = 345678u;
432 unsigned int numberOfBytesWritten = 789u;
433 TimelinePacketStatus result =
434 WriteTimelineRelationshipBinaryPacket(relationshipType,
435 relationshipGuid,
436 headGuid,
437 tailGuid,
438 buffer.data(),
439 boost::numeric_cast<unsigned int>(buffer.size()),
440 numberOfBytesWritten);
441 BOOST_CHECK(result == TimelinePacketStatus::Ok);
442 BOOST_CHECK(numberOfBytesWritten == 40);
443
444 unsigned int uint32_t_size = sizeof(uint32_t);
445 unsigned int uint64_t_size = sizeof(uint64_t);
446
447 // Check the packet header
448 unsigned int offset = 0;
449 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
450 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
451 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
452 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
453 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
454 BOOST_CHECK(packetFamily == 1);
455 BOOST_CHECK(packetClass == 0);
456 BOOST_CHECK(packetType == 1);
457 BOOST_CHECK(streamId == 0);
458
459 offset += uint32_t_size;
460 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
461 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
462 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
463 BOOST_CHECK(sequenceNumbered == 0);
464 BOOST_CHECK(dataLength == 32);
465
466 // Check the decl_id
467 offset += uint32_t_size;
468 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
469 BOOST_CHECK(readDeclId == 3);
470
471 // Check the relationship type
472 offset += uint32_t_size;
473 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
474 BOOST_CHECK(readRelationshipType == 3);
475
476 // Check the relationship GUID
477 offset += uint32_t_size;
478 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
479 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
480
481 // Check the head GUID
482 offset += uint64_t_size;
483 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
484 BOOST_CHECK(readHeadGuid == headGuid);
485
486 // Check the tail GUID
487 offset += uint64_t_size;
488 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
489 BOOST_CHECK(readTailGuid == tailGuid);
490}
491
Sadik Armagan784db772019-10-08 15:05:38 +0100492BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTest1)
493{
494 unsigned int numberOfBytesWritten = 789u;
495 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(nullptr,
496 512u,
497 numberOfBytesWritten);
498 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
499 BOOST_CHECK(numberOfBytesWritten == 0);
500}
501
502BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTest2)
503{
504 std::vector<unsigned char> buffer(512, 0);
505
506 unsigned int numberOfBytesWritten = 789u;
507 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(),
508 0,
509 numberOfBytesWritten);
510 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
511 BOOST_CHECK(numberOfBytesWritten == 0);
512}
513
514BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTest3)
515{
516 std::vector<unsigned char> buffer(512, 0);
517 unsigned int numberOfBytesWritten = 789u;
518 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(),
519 boost::numeric_cast<unsigned int>(buffer.size()),
520 numberOfBytesWritten);
521 BOOST_CHECK(result == TimelinePacketStatus::Ok);
522
523 BOOST_CHECK(numberOfBytesWritten == 424);
524
525 unsigned int uint32_t_size = sizeof(uint32_t);
526
527 // Check the packet header
528 unsigned int offset = 0;
529 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
530 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
531 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
532 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
533 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
534 BOOST_CHECK(packetFamily == 1);
535 BOOST_CHECK(packetClass == 0);
536 BOOST_CHECK(packetType == 0);
537 BOOST_CHECK(streamId == 0);
538
539 offset += uint32_t_size;
540 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
541 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
542 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
543 BOOST_CHECK(sequenceNumbered == 0);
544 BOOST_CHECK(dataLength == 416);
545
Finn Williamse63a0262019-10-22 10:30:49 +0100546 // Check the number of declarations
547 offset += uint32_t_size;
548 uint32_t declCount = ReadUint32(buffer.data(), offset);
549 BOOST_CHECK(declCount == 5);
550
Sadik Armagan784db772019-10-08 15:05:38 +0100551 // Check the decl_id
552 offset += uint32_t_size;
553 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
554 BOOST_CHECK(readDeclId == 0);
555
556 // SWTrace "namestring" format
557 // length of the string (first 4 bytes) + string + null terminator
558
559 // Check the decl_name
560 offset += uint32_t_size;
561 uint32_t swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
562 BOOST_CHECK(swTraceDeclNameLength == 13); // decl_name length including the null-terminator
563
564 std::string label = "declareLabel";
565 offset += uint32_t_size;
566 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
567 label.data(), // The original label
568 swTraceDeclNameLength - 1) == 0); // The length of the label
569
570 // Check the ui_name
571 std::vector<uint32_t> swTraceString;
572 StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
573 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
574 uint32_t swTraceUINameLength = ReadUint32(buffer.data(), offset);
575 BOOST_CHECK(swTraceUINameLength == 14); // ui_name length including the null-terminator
576
577 label = "declare label";
578 offset += uint32_t_size;
579 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
580 label.data(), // The original label
581 swTraceUINameLength - 1) == 0); // The length of the label
582
583 // Check arg_types
584 StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
585 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
586 uint32_t swTraceArgTypesLength = ReadUint32(buffer.data(), offset);
587 BOOST_CHECK(swTraceArgTypesLength == 3); // arg_types length including the null-terminator
588
589 label = "ps";
590 offset += uint32_t_size;
591 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
592 label.data(), // The original label
593 swTraceArgTypesLength - 1) == 0); // The length of the label
594
595 // Check arg_names
596 StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
597 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
598 uint32_t swTraceArgNamesLength = ReadUint32(buffer.data(), offset);
599 BOOST_CHECK(swTraceArgNamesLength == 11); // arg_names length including the null-terminator
600
601 label = "guid,value";
602 offset += uint32_t_size;
603 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
604 label.data(), // The original label
605 swTraceArgNamesLength - 1) == 0); // The length of the label
606
607 // Check second message decl_id
608 StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
609 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
610 readDeclId = ReadUint32(buffer.data(), offset);
611 BOOST_CHECK(readDeclId == 1);
612
613 // Check second decl_name
614 offset += uint32_t_size;
615 swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
616 BOOST_CHECK(swTraceDeclNameLength == 14); // decl_name length including the null-terminator
617
618 label = "declareEntity";
619 offset += uint32_t_size;
620 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
621 label.data(), // The original label
622 swTraceDeclNameLength - 1) == 0); // The length of the label
623}
624
David Monahanf21f6062019-10-07 15:11:15 +0100625BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest1)
626{
627 const uint64_t profilingGuid = 123456u;
628 unsigned int numberOfBytesWritten = 789u;
629 TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid,
630 nullptr,
631 512u,
632 numberOfBytesWritten);
633 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
634 BOOST_CHECK(numberOfBytesWritten == 0);
635}
636
637BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest2)
638{
639 std::vector<unsigned char> buffer(512, 0);
640
641 const uint64_t profilingGuid = 123456u;
642 unsigned int numberOfBytesWritten = 789u;
643 TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid,
644 buffer.data(),
645 0,
646 numberOfBytesWritten);
647 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
648 BOOST_CHECK(numberOfBytesWritten == 0);
649}
650
651BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest3)
652{
653 std::vector<unsigned char> buffer(10, 0);
654
655 const uint64_t profilingGuid = 123456u;
656 unsigned int numberOfBytesWritten = 789u;
657 TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid,
658 buffer.data(),
659 boost::numeric_cast<unsigned int>(buffer.size()),
660 numberOfBytesWritten);
661 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
662 BOOST_CHECK(numberOfBytesWritten == 0);
663}
664
665BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest4)
666{
667 std::vector<unsigned char> buffer(512, 0);
668
669 const uint64_t profilingGuid = 123456u;
670 unsigned int numberOfBytesWritten = 789u;
671 TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid,
672 buffer.data(),
673 boost::numeric_cast<unsigned int>(buffer.size()),
674 numberOfBytesWritten);
675 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Jan Eilersb884ea42019-10-16 09:54:15 +0100676 BOOST_CHECK(numberOfBytesWritten == 20);
David Monahanf21f6062019-10-07 15:11:15 +0100677
678 unsigned int uint32_t_size = sizeof(uint32_t);
679
680 // Check the packet header
681 unsigned int offset = 0;
682 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
683 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
684 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
685 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
686 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
687 BOOST_CHECK(packetFamily == 1);
688 BOOST_CHECK(packetClass == 0);
689 BOOST_CHECK(packetType == 1);
690 BOOST_CHECK(streamId == 0);
691
692 offset += uint32_t_size;
693 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
694 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
695 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
696 BOOST_CHECK(sequenceNumbered == 0);
Finn Williamse63a0262019-10-22 10:30:49 +0100697 BOOST_CHECK(dataLength == 12);
David Monahanf21f6062019-10-07 15:11:15 +0100698
Jan Eilersb884ea42019-10-16 09:54:15 +0100699 // Check decl_Id
700 offset += uint32_t_size;
701 uint32_t decl_Id = ReadUint32(buffer.data(), offset);
702 BOOST_CHECK(decl_Id == uint32_t(1));
703
David Monahanf21f6062019-10-07 15:11:15 +0100704 // Check the profiling GUID
705 offset += uint32_t_size;
706 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
707 BOOST_CHECK(readProfilingGuid == profilingGuid);
708}
709
Jan Eilers92fa15b2019-10-15 15:23:25 +0100710BOOST_AUTO_TEST_CASE(TimelineEventClassTest1)
711{
712 const uint64_t profilingGuid = 123456u;
713 unsigned int numberOfBytesWritten = 789u;
714 TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid,
715 nullptr,
716 512u,
717 numberOfBytesWritten);
718 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
719 BOOST_CHECK(numberOfBytesWritten == 0);
720}
721
722BOOST_AUTO_TEST_CASE(TimelineEventClassTest2)
723{
724 std::vector<unsigned char> buffer(512, 0);
725
726 const uint64_t profilingGuid = 123456u;
727 unsigned int numberOfBytesWritten = 789u;
728 TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid,
729 buffer.data(),
730 0,
731 numberOfBytesWritten);
732 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
733 BOOST_CHECK(numberOfBytesWritten == 0);
734}
735
736BOOST_AUTO_TEST_CASE(TimelineEventClassTest3)
737{
738 std::vector<unsigned char> buffer(10, 0);
739
740 const uint64_t profilingGuid = 123456u;
741 unsigned int numberOfBytesWritten = 789u;
742 TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid,
743 buffer.data(),
744 boost::numeric_cast<unsigned int>(buffer.size()),
745 numberOfBytesWritten);
746 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
747 BOOST_CHECK(numberOfBytesWritten == 0);
748}
749
750BOOST_AUTO_TEST_CASE(TimelineEventClassTest4)
751{
752 std::vector<unsigned char> buffer(512, 0);
753
754 const uint64_t profilingGuid = 123456u;
755 unsigned int numberOfBytesWritten = 789u;
756 TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid,
757 buffer.data(),
758 boost::numeric_cast<unsigned int>(buffer.size()),
759 numberOfBytesWritten);
760 BOOST_CHECK(result == TimelinePacketStatus::Ok);
761 BOOST_CHECK(numberOfBytesWritten == 20);
762
763 unsigned int uint32_t_size = sizeof(uint32_t);
764
765 // Check the packet header
766 unsigned int offset = 0;
767 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
768 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
769 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
770 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
771 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
772 BOOST_CHECK(packetFamily == 1);
773 BOOST_CHECK(packetClass == 0);
774 BOOST_CHECK(packetType == 1);
775 BOOST_CHECK(streamId == 0);
776
777 offset += uint32_t_size;
778 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
779 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
780 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
781 BOOST_CHECK(sequenceNumbered == 0);
782 BOOST_CHECK(dataLength == 12);
783
784 // Check the decl_id
785 offset += uint32_t_size;
786 uint32_t declId = ReadUint32(buffer.data(), offset);
787 BOOST_CHECK(declId == uint32_t(2));
788
789 // Check the profiling GUID
790 offset += uint32_t_size;
791 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
792 BOOST_CHECK(readProfilingGuid == profilingGuid);
793}
794
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100795BOOST_AUTO_TEST_CASE(TimelineEventPacketTest1)
796{
797 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000798 const std::thread::id threadId = std::this_thread::get_id();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100799 const uint64_t profilingGuid = 123456u;
800 unsigned int numberOfBytesWritten = 789u;
801 TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp,
802 threadId,
803 profilingGuid,
804 nullptr,
805 512u,
806 numberOfBytesWritten);
807 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
808 BOOST_CHECK(numberOfBytesWritten == 0);
809}
810
811BOOST_AUTO_TEST_CASE(TimelineEventPacketTest2)
812{
813 std::vector<unsigned char> buffer(512, 0);
814
815 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000816 const std::thread::id threadId = std::this_thread::get_id();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100817 const uint64_t profilingGuid = 123456u;
818 unsigned int numberOfBytesWritten = 789u;
819 TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp,
820 threadId,
821 profilingGuid,
822 buffer.data(),
823 0,
824 numberOfBytesWritten);
825 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
826 BOOST_CHECK(numberOfBytesWritten == 0);
827}
828
829BOOST_AUTO_TEST_CASE(TimelineEventPacketTest3)
830{
831 std::vector<unsigned char> buffer(10, 0);
832
833 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000834 const std::thread::id threadId = std::this_thread::get_id();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100835 const uint64_t profilingGuid = 123456u;
836 unsigned int numberOfBytesWritten = 789u;
837 TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp,
838 threadId,
839 profilingGuid,
840 buffer.data(),
841 boost::numeric_cast<unsigned int>(buffer.size()),
842 numberOfBytesWritten);
843 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
844 BOOST_CHECK(numberOfBytesWritten == 0);
845}
846
847BOOST_AUTO_TEST_CASE(TimelineEventPacketTest4)
848{
849 std::vector<unsigned char> buffer(512, 0);
850
851 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000852 const std::thread::id threadId = std::this_thread::get_id();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100853 const uint64_t profilingGuid = 123456u;
854 unsigned int numberOfBytesWritten = 789u;
855 TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp,
856 threadId,
857 profilingGuid,
858 buffer.data(),
859 boost::numeric_cast<unsigned int>(buffer.size()),
860 numberOfBytesWritten);
861 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000862 BOOST_CHECK(numberOfBytesWritten == 36);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100863
864 unsigned int uint32_t_size = sizeof(uint32_t);
865 unsigned int uint64_t_size = sizeof(uint64_t);
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000866 unsigned int threadId_size = sizeof(std::thread::id);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100867
868 // Check the packet header
869 unsigned int offset = 0;
870 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
871 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
872 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
873 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
874 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
875 BOOST_CHECK(packetFamily == 1);
876 BOOST_CHECK(packetClass == 0);
877 BOOST_CHECK(packetType == 1);
878 BOOST_CHECK(streamId == 0);
879
880 offset += uint32_t_size;
881 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
882 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
883 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
884 BOOST_CHECK(sequenceNumbered == 0);
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000885 BOOST_CHECK(dataLength == 28);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100886
887 // Check the decl_id
888 offset += uint32_t_size;
889 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
890 BOOST_CHECK(readDeclId == 4);
891
892 // Check the timestamp
893 offset += uint32_t_size;
894 uint64_t readTimestamp = ReadUint64(buffer.data(), offset);
895 BOOST_CHECK(readTimestamp == timestamp);
896
897 // Check the thread id
898 offset += uint64_t_size;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000899 std::vector<uint8_t> readThreadId(threadId_size, 0);
900 ReadBytes(buffer.data(), offset, threadId_size, readThreadId.data());
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100901 BOOST_CHECK(readThreadId == threadId);
902
903 // Check the profiling GUID
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000904 offset += threadId_size;
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100905 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
906 BOOST_CHECK(readProfilingGuid == profilingGuid);
907}
908
909BOOST_AUTO_TEST_SUITE_END()