blob: 6a8aa85fc064331dce8e79b04f3d8032f9b765ec [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
546 // Check the decl_id
547 offset += uint32_t_size;
548 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
549 BOOST_CHECK(readDeclId == 0);
550
551 // SWTrace "namestring" format
552 // length of the string (first 4 bytes) + string + null terminator
553
554 // Check the decl_name
555 offset += uint32_t_size;
556 uint32_t swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
557 BOOST_CHECK(swTraceDeclNameLength == 13); // decl_name length including the null-terminator
558
559 std::string label = "declareLabel";
560 offset += uint32_t_size;
561 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
562 label.data(), // The original label
563 swTraceDeclNameLength - 1) == 0); // The length of the label
564
565 // Check the ui_name
566 std::vector<uint32_t> swTraceString;
567 StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
568 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
569 uint32_t swTraceUINameLength = ReadUint32(buffer.data(), offset);
570 BOOST_CHECK(swTraceUINameLength == 14); // ui_name length including the null-terminator
571
572 label = "declare label";
573 offset += uint32_t_size;
574 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
575 label.data(), // The original label
576 swTraceUINameLength - 1) == 0); // The length of the label
577
578 // Check arg_types
579 StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
580 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
581 uint32_t swTraceArgTypesLength = ReadUint32(buffer.data(), offset);
582 BOOST_CHECK(swTraceArgTypesLength == 3); // arg_types length including the null-terminator
583
584 label = "ps";
585 offset += uint32_t_size;
586 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
587 label.data(), // The original label
588 swTraceArgTypesLength - 1) == 0); // The length of the label
589
590 // Check arg_names
591 StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
592 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
593 uint32_t swTraceArgNamesLength = ReadUint32(buffer.data(), offset);
594 BOOST_CHECK(swTraceArgNamesLength == 11); // arg_names length including the null-terminator
595
596 label = "guid,value";
597 offset += uint32_t_size;
598 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
599 label.data(), // The original label
600 swTraceArgNamesLength - 1) == 0); // The length of the label
601
602 // Check second message decl_id
603 StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString);
604 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
605 readDeclId = ReadUint32(buffer.data(), offset);
606 BOOST_CHECK(readDeclId == 1);
607
608 // Check second decl_name
609 offset += uint32_t_size;
610 swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
611 BOOST_CHECK(swTraceDeclNameLength == 14); // decl_name length including the null-terminator
612
613 label = "declareEntity";
614 offset += uint32_t_size;
615 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
616 label.data(), // The original label
617 swTraceDeclNameLength - 1) == 0); // The length of the label
618}
619
David Monahanf21f6062019-10-07 15:11:15 +0100620BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest1)
621{
622 const uint64_t profilingGuid = 123456u;
623 unsigned int numberOfBytesWritten = 789u;
624 TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid,
625 nullptr,
626 512u,
627 numberOfBytesWritten);
628 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
629 BOOST_CHECK(numberOfBytesWritten == 0);
630}
631
632BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest2)
633{
634 std::vector<unsigned char> buffer(512, 0);
635
636 const uint64_t profilingGuid = 123456u;
637 unsigned int numberOfBytesWritten = 789u;
638 TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid,
639 buffer.data(),
640 0,
641 numberOfBytesWritten);
642 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
643 BOOST_CHECK(numberOfBytesWritten == 0);
644}
645
646BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest3)
647{
648 std::vector<unsigned char> buffer(10, 0);
649
650 const uint64_t profilingGuid = 123456u;
651 unsigned int numberOfBytesWritten = 789u;
652 TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid,
653 buffer.data(),
654 boost::numeric_cast<unsigned int>(buffer.size()),
655 numberOfBytesWritten);
656 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
657 BOOST_CHECK(numberOfBytesWritten == 0);
658}
659
660BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest4)
661{
662 std::vector<unsigned char> buffer(512, 0);
663
664 const uint64_t profilingGuid = 123456u;
665 unsigned int numberOfBytesWritten = 789u;
666 TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid,
667 buffer.data(),
668 boost::numeric_cast<unsigned int>(buffer.size()),
669 numberOfBytesWritten);
670 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Jan Eilersb884ea42019-10-16 09:54:15 +0100671 BOOST_CHECK(numberOfBytesWritten == 20);
David Monahanf21f6062019-10-07 15:11:15 +0100672
673 unsigned int uint32_t_size = sizeof(uint32_t);
674
675 // Check the packet header
676 unsigned int offset = 0;
677 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
678 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
679 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
680 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
681 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
682 BOOST_CHECK(packetFamily == 1);
683 BOOST_CHECK(packetClass == 0);
684 BOOST_CHECK(packetType == 1);
685 BOOST_CHECK(streamId == 0);
686
687 offset += uint32_t_size;
688 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
689 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
690 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
691 BOOST_CHECK(sequenceNumbered == 0);
692 BOOST_CHECK(dataLength == 8);
693
Jan Eilersb884ea42019-10-16 09:54:15 +0100694 // Check decl_Id
695 offset += uint32_t_size;
696 uint32_t decl_Id = ReadUint32(buffer.data(), offset);
697 BOOST_CHECK(decl_Id == uint32_t(1));
698
David Monahanf21f6062019-10-07 15:11:15 +0100699 // Check the profiling GUID
700 offset += uint32_t_size;
701 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
702 BOOST_CHECK(readProfilingGuid == profilingGuid);
703}
704
Jan Eilers92fa15b2019-10-15 15:23:25 +0100705BOOST_AUTO_TEST_CASE(TimelineEventClassTest1)
706{
707 const uint64_t profilingGuid = 123456u;
708 unsigned int numberOfBytesWritten = 789u;
709 TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid,
710 nullptr,
711 512u,
712 numberOfBytesWritten);
713 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
714 BOOST_CHECK(numberOfBytesWritten == 0);
715}
716
717BOOST_AUTO_TEST_CASE(TimelineEventClassTest2)
718{
719 std::vector<unsigned char> buffer(512, 0);
720
721 const uint64_t profilingGuid = 123456u;
722 unsigned int numberOfBytesWritten = 789u;
723 TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid,
724 buffer.data(),
725 0,
726 numberOfBytesWritten);
727 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
728 BOOST_CHECK(numberOfBytesWritten == 0);
729}
730
731BOOST_AUTO_TEST_CASE(TimelineEventClassTest3)
732{
733 std::vector<unsigned char> buffer(10, 0);
734
735 const uint64_t profilingGuid = 123456u;
736 unsigned int numberOfBytesWritten = 789u;
737 TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid,
738 buffer.data(),
739 boost::numeric_cast<unsigned int>(buffer.size()),
740 numberOfBytesWritten);
741 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
742 BOOST_CHECK(numberOfBytesWritten == 0);
743}
744
745BOOST_AUTO_TEST_CASE(TimelineEventClassTest4)
746{
747 std::vector<unsigned char> buffer(512, 0);
748
749 const uint64_t profilingGuid = 123456u;
750 unsigned int numberOfBytesWritten = 789u;
751 TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid,
752 buffer.data(),
753 boost::numeric_cast<unsigned int>(buffer.size()),
754 numberOfBytesWritten);
755 BOOST_CHECK(result == TimelinePacketStatus::Ok);
756 BOOST_CHECK(numberOfBytesWritten == 20);
757
758 unsigned int uint32_t_size = sizeof(uint32_t);
759
760 // Check the packet header
761 unsigned int offset = 0;
762 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
763 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
764 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
765 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
766 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
767 BOOST_CHECK(packetFamily == 1);
768 BOOST_CHECK(packetClass == 0);
769 BOOST_CHECK(packetType == 1);
770 BOOST_CHECK(streamId == 0);
771
772 offset += uint32_t_size;
773 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
774 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
775 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
776 BOOST_CHECK(sequenceNumbered == 0);
777 BOOST_CHECK(dataLength == 12);
778
779 // Check the decl_id
780 offset += uint32_t_size;
781 uint32_t declId = ReadUint32(buffer.data(), offset);
782 BOOST_CHECK(declId == uint32_t(2));
783
784 // Check the profiling GUID
785 offset += uint32_t_size;
786 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
787 BOOST_CHECK(readProfilingGuid == profilingGuid);
788}
789
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100790BOOST_AUTO_TEST_CASE(TimelineEventPacketTest1)
791{
792 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000793 const std::thread::id threadId = std::this_thread::get_id();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100794 const uint64_t profilingGuid = 123456u;
795 unsigned int numberOfBytesWritten = 789u;
796 TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp,
797 threadId,
798 profilingGuid,
799 nullptr,
800 512u,
801 numberOfBytesWritten);
802 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
803 BOOST_CHECK(numberOfBytesWritten == 0);
804}
805
806BOOST_AUTO_TEST_CASE(TimelineEventPacketTest2)
807{
808 std::vector<unsigned char> buffer(512, 0);
809
810 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000811 const std::thread::id threadId = std::this_thread::get_id();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100812 const uint64_t profilingGuid = 123456u;
813 unsigned int numberOfBytesWritten = 789u;
814 TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp,
815 threadId,
816 profilingGuid,
817 buffer.data(),
818 0,
819 numberOfBytesWritten);
820 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
821 BOOST_CHECK(numberOfBytesWritten == 0);
822}
823
824BOOST_AUTO_TEST_CASE(TimelineEventPacketTest3)
825{
826 std::vector<unsigned char> buffer(10, 0);
827
828 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000829 const std::thread::id threadId = std::this_thread::get_id();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100830 const uint64_t profilingGuid = 123456u;
831 unsigned int numberOfBytesWritten = 789u;
832 TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp,
833 threadId,
834 profilingGuid,
835 buffer.data(),
836 boost::numeric_cast<unsigned int>(buffer.size()),
837 numberOfBytesWritten);
838 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
839 BOOST_CHECK(numberOfBytesWritten == 0);
840}
841
842BOOST_AUTO_TEST_CASE(TimelineEventPacketTest4)
843{
844 std::vector<unsigned char> buffer(512, 0);
845
846 const uint64_t timestamp = 456789u;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000847 const std::thread::id threadId = std::this_thread::get_id();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100848 const uint64_t profilingGuid = 123456u;
849 unsigned int numberOfBytesWritten = 789u;
850 TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp,
851 threadId,
852 profilingGuid,
853 buffer.data(),
854 boost::numeric_cast<unsigned int>(buffer.size()),
855 numberOfBytesWritten);
856 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000857 BOOST_CHECK(numberOfBytesWritten == 36);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100858
859 unsigned int uint32_t_size = sizeof(uint32_t);
860 unsigned int uint64_t_size = sizeof(uint64_t);
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000861 unsigned int threadId_size = sizeof(std::thread::id);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100862
863 // Check the packet header
864 unsigned int offset = 0;
865 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
866 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
867 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
868 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
869 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
870 BOOST_CHECK(packetFamily == 1);
871 BOOST_CHECK(packetClass == 0);
872 BOOST_CHECK(packetType == 1);
873 BOOST_CHECK(streamId == 0);
874
875 offset += uint32_t_size;
876 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
877 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
878 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
879 BOOST_CHECK(sequenceNumbered == 0);
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000880 BOOST_CHECK(dataLength == 28);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100881
882 // Check the decl_id
883 offset += uint32_t_size;
884 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
885 BOOST_CHECK(readDeclId == 4);
886
887 // Check the timestamp
888 offset += uint32_t_size;
889 uint64_t readTimestamp = ReadUint64(buffer.data(), offset);
890 BOOST_CHECK(readTimestamp == timestamp);
891
892 // Check the thread id
893 offset += uint64_t_size;
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000894 std::vector<uint8_t> readThreadId(threadId_size, 0);
895 ReadBytes(buffer.data(), offset, threadId_size, readThreadId.data());
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100896 BOOST_CHECK(readThreadId == threadId);
897
898 // Check the profiling GUID
Matteo Martincigh378bbfc2019-11-04 14:05:28 +0000899 offset += threadId_size;
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100900 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
901 BOOST_CHECK(readProfilingGuid == profilingGuid);
902}
903
904BOOST_AUTO_TEST_SUITE_END()