blob: 4f056ce7617948d2f8b83af6965f3815774aa408 [file] [log] [blame]
Matteo Martincigh0aed4f92019-10-01 14:25:34 +01001//
Jim Flynn6398a982020-05-27 17:05:21 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Matteo Martincigh0aed4f92019-10-01 14:25:34 +01003// SPDX-License-Identifier: MIT
4//
5
Jim Flynn1fdeb992020-07-09 07:28:37 +01006#include <Threads.hpp>
Matteo Martincigh0aed4f92019-10-01 14:25:34 +01007#include <ProfilingUtils.hpp>
8
Jim Flynnbbfe6032020-07-20 16:57:44 +01009#include <common/include/SwTrace.hpp>
10
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010011#include <boost/test/unit_test.hpp>
12#include <boost/numeric/conversion/cast.hpp>
13
14using namespace armnn::profiling;
15
16BOOST_AUTO_TEST_SUITE(TimelinePacketTests)
17
Keith Davis97da5e22020-03-05 16:25:28 +000018BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestNoBuffer)
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010019{
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 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
29 BOOST_CHECK(numberOfBytesWritten == 0);
30}
31
Keith Davis97da5e22020-03-05 16:25:28 +000032BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestBufferExhaustionZeroValue)
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010033{
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 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
45 BOOST_CHECK(numberOfBytesWritten == 0);
46}
47
Keith Davis97da5e22020-03-05 16:25:28 +000048BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestBufferExhaustionFixedValue)
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010049{
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 boost::numeric_cast<unsigned int>(buffer.size()),
59 numberOfBytesWritten);
60 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
61 BOOST_CHECK(numberOfBytesWritten == 0);
62}
63
Keith Davis97da5e22020-03-05 16:25:28 +000064BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestInvalidLabel)
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010065{
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 boost::numeric_cast<unsigned int>(buffer.size()),
75 numberOfBytesWritten);
76 BOOST_CHECK(result == TimelinePacketStatus::Error);
77 BOOST_CHECK(numberOfBytesWritten == 0);
78}
79
Keith Davis97da5e22020-03-05 16:25:28 +000080BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestSingleConstructionOfData)
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010081{
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 boost::numeric_cast<unsigned int>(buffer.size()),
91 numberOfBytesWritten);
92 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Keith Davis97da5e22020-03-05 16:25:28 +000093 BOOST_CHECK(numberOfBytesWritten == 28);
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010094
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;
Jan Eilersb884ea42019-10-16 09:54:15 +0100100 uint32_t decl_Id = ReadUint32(buffer.data(), offset);
101 BOOST_CHECK(decl_Id == uint32_t(0));
Matteo Martincigh0aed4f92019-10-01 14:25:34 +0100102
103 // Check the profiling GUID
104 offset += uint32_t_size;
105 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
106 BOOST_CHECK(readProfilingGuid == profilingGuid);
107
108 // Check the SWTrace label
109 offset += uint64_t_size;
110 uint32_t swTraceLabelLength = ReadUint32(buffer.data(), offset);
111 BOOST_CHECK(swTraceLabelLength == 11); // Label length including the null-terminator
112
113 offset += uint32_t_size;
114 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
115 label.data(), // The original label
116 swTraceLabelLength - 1) == 0); // The length of the label
117
118 offset += swTraceLabelLength * uint32_t_size;
119 BOOST_CHECK(buffer[offset] == '\0'); // The null-terminator at the end of the SWTrace label
120}
121
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100122BOOST_AUTO_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;
Finn Williams0a336dc2020-05-11 15:39:58 +0100128 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100129 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000130 TimelinePacketStatus result = WriteTimelineRelationshipBinary(relationshipType,
131 relationshipGuid,
132 headGuid,
133 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100134 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000135 nullptr,
136 512u,
137 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100138 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
139 BOOST_CHECK(numberOfBytesWritten == 0);
140}
141
142BOOST_AUTO_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;
Finn Williams0a336dc2020-05-11 15:39:58 +0100150 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100151 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000152 TimelinePacketStatus result = WriteTimelineRelationshipBinary(relationshipType,
153 relationshipGuid,
154 headGuid,
155 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100156 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000157 buffer.data(),
158 0,
159 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100160 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
161 BOOST_CHECK(numberOfBytesWritten == 0);
162}
163
164BOOST_AUTO_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;
Finn Williams0a336dc2020-05-11 15:39:58 +0100172 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100173 unsigned int numberOfBytesWritten = 789u;
174 TimelinePacketStatus result =
Keith Davis97da5e22020-03-05 16:25:28 +0000175 WriteTimelineRelationshipBinary(relationshipType,
176 relationshipGuid,
177 headGuid,
178 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100179 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000180 buffer.data(),
181 boost::numeric_cast<unsigned int>(buffer.size()),
182 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100183 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
184 BOOST_CHECK(numberOfBytesWritten == 0);
185}
186
187BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketInvalidRelationTest)
188{
189 std::vector<unsigned char> buffer(512, 0);
190 ProfilingRelationshipType relationshipType = static_cast<ProfilingRelationshipType>(5);
191 const uint64_t relationshipGuid = 123456u;
192 const uint64_t headGuid = 234567u;
193 const uint64_t tailGuid = 345678u;
Finn Williams0a336dc2020-05-11 15:39:58 +0100194 const uint64_t attributeGuid = 876345u;
195
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100196 unsigned int numberOfBytesWritten = 789u;
197
Keith Davis97da5e22020-03-05 16:25:28 +0000198 BOOST_CHECK_THROW(WriteTimelineRelationshipBinary(relationshipType,
199 relationshipGuid,
200 headGuid,
201 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100202 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000203 buffer.data(),
204 boost::numeric_cast<unsigned int>(buffer.size()),
205 numberOfBytesWritten),
206 armnn::InvalidArgumentException);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100207
208 BOOST_CHECK(numberOfBytesWritten == 0);
209}
210
Keith Davis97da5e22020-03-05 16:25:28 +0000211BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketTestDataConstruction)
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100212{
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;
Finn Williams0a336dc2020-05-11 15:39:58 +0100219 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100220 unsigned int numberOfBytesWritten = 789u;
221 TimelinePacketStatus result =
Keith Davis97da5e22020-03-05 16:25:28 +0000222 WriteTimelineRelationshipBinary(relationshipType,
223 relationshipGuid,
224 headGuid,
225 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100226 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000227 buffer.data(),
228 boost::numeric_cast<unsigned int>(buffer.size()),
229 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100230 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Finn Williams0a336dc2020-05-11 15:39:58 +0100231 BOOST_CHECK(numberOfBytesWritten == 40);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100232
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;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100238 // Check the decl_id
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100239 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
240 BOOST_CHECK(readDeclId == 3);
241
242 // Check the relationship type
243 offset += uint32_t_size;
244 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
245 BOOST_CHECK(readRelationshipType == 0);
246
247 // Check the relationship GUID
248 offset += uint32_t_size;
249 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
250 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
251
252 // Check the head GUID
253 offset += uint64_t_size;
254 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
255 BOOST_CHECK(readHeadGuid == headGuid);
256
257 // Check the tail GUID
258 offset += uint64_t_size;
259 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
260 BOOST_CHECK(readTailGuid == tailGuid);
Finn Williams0a336dc2020-05-11 15:39:58 +0100261
262 // Check the attribute GUID
263 offset += uint64_t_size;
264 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
265 BOOST_CHECK(readAttributeGuid == attributeGuid);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100266}
267
Keith Davis97da5e22020-03-05 16:25:28 +0000268BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketExecutionLinkTestDataConstruction)
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100269{
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;
Finn Williams0a336dc2020-05-11 15:39:58 +0100276 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100277 unsigned int numberOfBytesWritten = 789u;
278 TimelinePacketStatus result =
Keith Davis97da5e22020-03-05 16:25:28 +0000279 WriteTimelineRelationshipBinary(relationshipType,
280 relationshipGuid,
281 headGuid,
282 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100283 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000284 buffer.data(),
285 boost::numeric_cast<unsigned int>(buffer.size()),
286 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100287 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Finn Williams0a336dc2020-05-11 15:39:58 +0100288 BOOST_CHECK(numberOfBytesWritten == 40);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100289
290 unsigned int uint32_t_size = sizeof(uint32_t);
291 unsigned int uint64_t_size = sizeof(uint64_t);
292
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100293 unsigned int offset = 0;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100294 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
295 BOOST_CHECK(readDeclId == 3);
296
297 // Check the relationship type
298 offset += uint32_t_size;
299 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
300 BOOST_CHECK(readRelationshipType == 1);
301
302 // Check the relationship GUID
303 offset += uint32_t_size;
304 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
305 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
306
307 // Check the head GUID
308 offset += uint64_t_size;
309 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
310 BOOST_CHECK(readHeadGuid == headGuid);
311
312 // Check the tail GUID
313 offset += uint64_t_size;
314 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
315 BOOST_CHECK(readTailGuid == tailGuid);
Finn Williams0a336dc2020-05-11 15:39:58 +0100316
317 // Check the attribute GUID
318 offset += uint64_t_size;
319 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
320 BOOST_CHECK(readAttributeGuid == attributeGuid);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100321}
322
323
Keith Davis97da5e22020-03-05 16:25:28 +0000324BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketDataLinkTestDataConstruction)
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100325{
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;
Finn Williams0a336dc2020-05-11 15:39:58 +0100332 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100333 unsigned int numberOfBytesWritten = 789u;
334 TimelinePacketStatus result =
Keith Davis97da5e22020-03-05 16:25:28 +0000335 WriteTimelineRelationshipBinary(relationshipType,
336 relationshipGuid,
337 headGuid,
338 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100339 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000340 buffer.data(),
341 boost::numeric_cast<unsigned int>(buffer.size()),
342 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100343 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Finn Williams0a336dc2020-05-11 15:39:58 +0100344 BOOST_CHECK(numberOfBytesWritten == 40);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100345
346 unsigned int uint32_t_size = sizeof(uint32_t);
347 unsigned int uint64_t_size = sizeof(uint64_t);
348
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100349 unsigned int offset = 0;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100350 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
351 BOOST_CHECK(readDeclId == 3);
352
353 // Check the relationship type
354 offset += uint32_t_size;
355 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
356 BOOST_CHECK(readRelationshipType == 2);
357
358 // Check the relationship GUID
359 offset += uint32_t_size;
360 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
361 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
362
363 // Check the head GUID
364 offset += uint64_t_size;
365 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
366 BOOST_CHECK(readHeadGuid == headGuid);
367
368 // Check the tail GUID
369 offset += uint64_t_size;
370 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
371 BOOST_CHECK(readTailGuid == tailGuid);
Finn Williams0a336dc2020-05-11 15:39:58 +0100372
373 // Check the attribute GUID
374 offset += uint64_t_size;
375 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
376 BOOST_CHECK(readAttributeGuid == attributeGuid);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100377}
378
379
Keith Davis97da5e22020-03-05 16:25:28 +0000380BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketLabelLinkTestDataConstruction)
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100381{
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;
Finn Williams0a336dc2020-05-11 15:39:58 +0100388 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100389 unsigned int numberOfBytesWritten = 789u;
390 TimelinePacketStatus result =
Keith Davis97da5e22020-03-05 16:25:28 +0000391 WriteTimelineRelationshipBinary(relationshipType,
392 relationshipGuid,
393 headGuid,
394 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100395 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000396 buffer.data(),
397 boost::numeric_cast<unsigned int>(buffer.size()),
398 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100399 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Finn Williams0a336dc2020-05-11 15:39:58 +0100400 BOOST_CHECK(numberOfBytesWritten == 40);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100401
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;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100407 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
408 BOOST_CHECK(readDeclId == 3);
409
410 // Check the relationship type
411 offset += uint32_t_size;
412 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
413 BOOST_CHECK(readRelationshipType == 3);
414
415 // Check the relationship GUID
416 offset += uint32_t_size;
417 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
418 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
419
420 // Check the head GUID
421 offset += uint64_t_size;
422 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
423 BOOST_CHECK(readHeadGuid == headGuid);
424
425 // Check the tail GUID
426 offset += uint64_t_size;
427 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
428 BOOST_CHECK(readTailGuid == tailGuid);
Finn Williams0a336dc2020-05-11 15:39:58 +0100429
430 // Check the attribute GUID
431 offset += uint64_t_size;
432 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
433 BOOST_CHECK(readAttributeGuid == attributeGuid);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100434}
435
Keith Davis97da5e22020-03-05 16:25:28 +0000436BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestNoBuffer)
Sadik Armagan784db772019-10-08 15:05:38 +0100437{
438 unsigned int numberOfBytesWritten = 789u;
439 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(nullptr,
440 512u,
441 numberOfBytesWritten);
442 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
443 BOOST_CHECK(numberOfBytesWritten == 0);
444}
445
Keith Davis97da5e22020-03-05 16:25:28 +0000446BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestBufferExhausted)
Sadik Armagan784db772019-10-08 15:05:38 +0100447{
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 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
455 BOOST_CHECK(numberOfBytesWritten == 0);
456}
457
Keith Davis97da5e22020-03-05 16:25:28 +0000458BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestFullConstruction)
Sadik Armagan784db772019-10-08 15:05:38 +0100459{
460 std::vector<unsigned char> buffer(512, 0);
461 unsigned int numberOfBytesWritten = 789u;
462 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(),
463 boost::numeric_cast<unsigned int>(buffer.size()),
464 numberOfBytesWritten);
465 BOOST_CHECK(result == TimelinePacketStatus::Ok);
466
Jim Flynn6398a982020-05-27 17:05:21 +0100467 BOOST_CHECK(numberOfBytesWritten == 451);
Sadik Armagan784db772019-10-08 15:05:38 +0100468
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000469 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan784db772019-10-08 15:05:38 +0100470 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000471 unsigned int uint64_t_size = sizeof(uint64_t);
Sadik Armagan784db772019-10-08 15:05:38 +0100472
473 // Check the packet header
474 unsigned int offset = 0;
475 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
476 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
477 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
478 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
479 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
480 BOOST_CHECK(packetFamily == 1);
481 BOOST_CHECK(packetClass == 0);
482 BOOST_CHECK(packetType == 0);
483 BOOST_CHECK(streamId == 0);
484
485 offset += uint32_t_size;
486 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
487 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
488 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
489 BOOST_CHECK(sequenceNumbered == 0);
Jim Flynn6398a982020-05-27 17:05:21 +0100490 BOOST_CHECK(dataLength == 443);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000491
492 // Check the stream header
493 offset += uint32_t_size;
494 uint8_t readStreamVersion = ReadUint8(buffer.data(), offset);
495 BOOST_CHECK(readStreamVersion == 4);
496 offset += uint8_t_size;
497 uint8_t readPointerBytes = ReadUint8(buffer.data(), offset);
498 BOOST_CHECK(readPointerBytes == uint64_t_size);
499 offset += uint8_t_size;
500 uint8_t readThreadIdBytes = ReadUint8(buffer.data(), offset);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100501 BOOST_CHECK(readThreadIdBytes == ThreadIdSize);
Sadik Armagan784db772019-10-08 15:05:38 +0100502
Finn Williamse63a0262019-10-22 10:30:49 +0100503 // Check the number of declarations
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000504 offset += uint8_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +0100505 uint32_t declCount = ReadUint32(buffer.data(), offset);
506 BOOST_CHECK(declCount == 5);
507
Sadik Armagan784db772019-10-08 15:05:38 +0100508 // Check the decl_id
509 offset += uint32_t_size;
510 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
511 BOOST_CHECK(readDeclId == 0);
512
513 // SWTrace "namestring" format
514 // length of the string (first 4 bytes) + string + null terminator
515
516 // Check the decl_name
517 offset += uint32_t_size;
518 uint32_t swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
519 BOOST_CHECK(swTraceDeclNameLength == 13); // decl_name length including the null-terminator
520
521 std::string label = "declareLabel";
522 offset += uint32_t_size;
523 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000524 label.data(), // The original label
Sadik Armagan784db772019-10-08 15:05:38 +0100525 swTraceDeclNameLength - 1) == 0); // The length of the label
526
527 // Check the ui_name
528 std::vector<uint32_t> swTraceString;
Jim Flynnbbfe6032020-07-20 16:57:44 +0100529 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
Sadik Armagan784db772019-10-08 15:05:38 +0100530 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
531 uint32_t swTraceUINameLength = ReadUint32(buffer.data(), offset);
532 BOOST_CHECK(swTraceUINameLength == 14); // ui_name length including the null-terminator
533
534 label = "declare label";
535 offset += uint32_t_size;
536 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
537 label.data(), // The original label
538 swTraceUINameLength - 1) == 0); // The length of the label
539
540 // Check arg_types
Jim Flynnbbfe6032020-07-20 16:57:44 +0100541 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
Sadik Armagan784db772019-10-08 15:05:38 +0100542 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
543 uint32_t swTraceArgTypesLength = ReadUint32(buffer.data(), offset);
544 BOOST_CHECK(swTraceArgTypesLength == 3); // arg_types length including the null-terminator
545
546 label = "ps";
547 offset += uint32_t_size;
548 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
549 label.data(), // The original label
550 swTraceArgTypesLength - 1) == 0); // The length of the label
551
552 // Check arg_names
Jim Flynnbbfe6032020-07-20 16:57:44 +0100553 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
Sadik Armagan784db772019-10-08 15:05:38 +0100554 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
555 uint32_t swTraceArgNamesLength = ReadUint32(buffer.data(), offset);
556 BOOST_CHECK(swTraceArgNamesLength == 11); // arg_names length including the null-terminator
557
558 label = "guid,value";
559 offset += uint32_t_size;
560 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
561 label.data(), // The original label
562 swTraceArgNamesLength - 1) == 0); // The length of the label
563
564 // Check second message decl_id
Jim Flynnbbfe6032020-07-20 16:57:44 +0100565 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
Sadik Armagan784db772019-10-08 15:05:38 +0100566 offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
567 readDeclId = ReadUint32(buffer.data(), offset);
568 BOOST_CHECK(readDeclId == 1);
569
570 // Check second decl_name
571 offset += uint32_t_size;
572 swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
573 BOOST_CHECK(swTraceDeclNameLength == 14); // decl_name length including the null-terminator
574
575 label = "declareEntity";
576 offset += uint32_t_size;
577 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
578 label.data(), // The original label
579 swTraceDeclNameLength - 1) == 0); // The length of the label
580}
581
Keith Davis97da5e22020-03-05 16:25:28 +0000582BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestNoBuffer)
David Monahanf21f6062019-10-07 15:11:15 +0100583{
584 const uint64_t profilingGuid = 123456u;
585 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000586 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
587 nullptr,
588 512u,
589 numberOfBytesWritten);
David Monahanf21f6062019-10-07 15:11:15 +0100590 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
591 BOOST_CHECK(numberOfBytesWritten == 0);
592}
593
Keith Davis97da5e22020-03-05 16:25:28 +0000594BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithZeroBufferSize)
David Monahanf21f6062019-10-07 15:11:15 +0100595{
596 std::vector<unsigned char> buffer(512, 0);
597
598 const uint64_t profilingGuid = 123456u;
599 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000600 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
601 buffer.data(),
602 0,
603 numberOfBytesWritten);
David Monahanf21f6062019-10-07 15:11:15 +0100604 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
605 BOOST_CHECK(numberOfBytesWritten == 0);
606}
607
Keith Davis97da5e22020-03-05 16:25:28 +0000608BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithFixedBufferSize)
David Monahanf21f6062019-10-07 15:11:15 +0100609{
610 std::vector<unsigned char> buffer(10, 0);
611
612 const uint64_t profilingGuid = 123456u;
613 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000614 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
615 buffer.data(),
616 boost::numeric_cast<unsigned int>(buffer.size()),
617 numberOfBytesWritten);
David Monahanf21f6062019-10-07 15:11:15 +0100618 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
619 BOOST_CHECK(numberOfBytesWritten == 0);
620}
621
Keith Davis97da5e22020-03-05 16:25:28 +0000622BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestFullConstructionOfData)
David Monahanf21f6062019-10-07 15:11:15 +0100623{
624 std::vector<unsigned char> buffer(512, 0);
625
626 const uint64_t profilingGuid = 123456u;
627 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000628 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
629 buffer.data(),
630 boost::numeric_cast<unsigned int>(buffer.size()),
631 numberOfBytesWritten);
David Monahanf21f6062019-10-07 15:11:15 +0100632 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Keith Davis97da5e22020-03-05 16:25:28 +0000633 BOOST_CHECK(numberOfBytesWritten == 12);
David Monahanf21f6062019-10-07 15:11:15 +0100634
635 unsigned int uint32_t_size = sizeof(uint32_t);
636
David Monahanf21f6062019-10-07 15:11:15 +0100637 unsigned int offset = 0;
Jan Eilersb884ea42019-10-16 09:54:15 +0100638 // Check decl_Id
Jan Eilersb884ea42019-10-16 09:54:15 +0100639 uint32_t decl_Id = ReadUint32(buffer.data(), offset);
640 BOOST_CHECK(decl_Id == uint32_t(1));
641
David Monahanf21f6062019-10-07 15:11:15 +0100642 // Check the profiling GUID
643 offset += uint32_t_size;
644 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
645 BOOST_CHECK(readProfilingGuid == profilingGuid);
646}
647
Keith Davis97da5e22020-03-05 16:25:28 +0000648BOOST_AUTO_TEST_CASE(TimelineEventClassTestNoBuffer)
Jan Eilers92fa15b2019-10-15 15:23:25 +0100649{
650 const uint64_t profilingGuid = 123456u;
Jim Flynn1892d212020-05-26 21:10:49 +0100651 const uint64_t profilingNameGuid = 3345u;
Jan Eilers92fa15b2019-10-15 15:23:25 +0100652 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000653 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
Jim Flynn1892d212020-05-26 21:10:49 +0100654 profilingNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000655 nullptr,
656 512u,
657 numberOfBytesWritten);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100658 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
659 BOOST_CHECK(numberOfBytesWritten == 0);
660}
661
Keith Davis97da5e22020-03-05 16:25:28 +0000662BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionZeroValue)
Jan Eilers92fa15b2019-10-15 15:23:25 +0100663{
664 std::vector<unsigned char> buffer(512, 0);
665
666 const uint64_t profilingGuid = 123456u;
Jim Flynn1892d212020-05-26 21:10:49 +0100667 const uint64_t profilingNameGuid = 3345u;
Jan Eilers92fa15b2019-10-15 15:23:25 +0100668 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000669 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
Jim Flynn1892d212020-05-26 21:10:49 +0100670 profilingNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000671 buffer.data(),
672 0,
673 numberOfBytesWritten);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100674 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
675 BOOST_CHECK(numberOfBytesWritten == 0);
676}
677
Keith Davis97da5e22020-03-05 16:25:28 +0000678BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionFixedValue)
Jan Eilers92fa15b2019-10-15 15:23:25 +0100679{
680 std::vector<unsigned char> buffer(10, 0);
681
682 const uint64_t profilingGuid = 123456u;
Jim Flynn1892d212020-05-26 21:10:49 +0100683 const uint64_t profilingNameGuid = 5564u;
Jan Eilers92fa15b2019-10-15 15:23:25 +0100684 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000685 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
Jim Flynn1892d212020-05-26 21:10:49 +0100686 profilingNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000687 buffer.data(),
688 boost::numeric_cast<unsigned int>(buffer.size()),
689 numberOfBytesWritten);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100690 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
691 BOOST_CHECK(numberOfBytesWritten == 0);
692}
693
Keith Davis97da5e22020-03-05 16:25:28 +0000694BOOST_AUTO_TEST_CASE(TimelineEventClassTestFullConstructionOfData)
Jan Eilers92fa15b2019-10-15 15:23:25 +0100695{
696 std::vector<unsigned char> buffer(512, 0);
697
698 const uint64_t profilingGuid = 123456u;
Jim Flynn1892d212020-05-26 21:10:49 +0100699 const uint64_t profilingNameGuid = 654321u;
Jan Eilers92fa15b2019-10-15 15:23:25 +0100700 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000701 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
Jim Flynn1892d212020-05-26 21:10:49 +0100702 profilingNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000703 buffer.data(),
704 boost::numeric_cast<unsigned int>(buffer.size()),
705 numberOfBytesWritten);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100706 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Jim Flynn1892d212020-05-26 21:10:49 +0100707 BOOST_CHECK(numberOfBytesWritten == 20);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100708
709 unsigned int uint32_t_size = sizeof(uint32_t);
Jim Flynn1892d212020-05-26 21:10:49 +0100710 unsigned int uint64_t_size = sizeof(uint64_t);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100711
Jan Eilers92fa15b2019-10-15 15:23:25 +0100712 unsigned int offset = 0;
Jan Eilers92fa15b2019-10-15 15:23:25 +0100713 // Check the decl_id
Jan Eilers92fa15b2019-10-15 15:23:25 +0100714 uint32_t declId = ReadUint32(buffer.data(), offset);
715 BOOST_CHECK(declId == uint32_t(2));
716
717 // Check the profiling GUID
718 offset += uint32_t_size;
719 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
720 BOOST_CHECK(readProfilingGuid == profilingGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100721
722 offset += uint64_t_size;
723 uint64_t readProfilingNameGuid = ReadUint64(buffer.data(), offset);
724 BOOST_CHECK(readProfilingNameGuid == profilingNameGuid);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100725}
726
Keith Davis97da5e22020-03-05 16:25:28 +0000727BOOST_AUTO_TEST_CASE(TimelineEventPacketTestNoBuffer)
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100728{
729 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100730 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100731 const uint64_t profilingGuid = 123456u;
732 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000733 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
734 threadId,
735 profilingGuid,
736 nullptr,
737 512u,
738 numberOfBytesWritten);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100739 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
740 BOOST_CHECK(numberOfBytesWritten == 0);
741}
742
Keith Davis97da5e22020-03-05 16:25:28 +0000743BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionZeroValue)
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100744{
745 std::vector<unsigned char> buffer(512, 0);
746
747 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100748 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100749 const uint64_t profilingGuid = 123456u;
750 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000751 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
752 threadId,
753 profilingGuid,
754 buffer.data(),
755 0,
756 numberOfBytesWritten);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100757 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
758 BOOST_CHECK(numberOfBytesWritten == 0);
759}
760
Keith Davis97da5e22020-03-05 16:25:28 +0000761BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionFixedValue)
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100762{
763 std::vector<unsigned char> buffer(10, 0);
764
765 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100766 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100767 const uint64_t profilingGuid = 123456u;
768 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000769 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
770 threadId,
771 profilingGuid,
772 buffer.data(),
773 boost::numeric_cast<unsigned int>(buffer.size()),
774 numberOfBytesWritten);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100775 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
776 BOOST_CHECK(numberOfBytesWritten == 0);
777}
778
Keith Davis97da5e22020-03-05 16:25:28 +0000779BOOST_AUTO_TEST_CASE(TimelineEventPacketTestFullConstructionOfData)
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100780{
781 std::vector<unsigned char> buffer(512, 0);
782
783 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100784 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100785 const uint64_t profilingGuid = 123456u;
786 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000787 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
788 threadId,
789 profilingGuid,
790 buffer.data(),
791 boost::numeric_cast<unsigned int>(buffer.size()),
792 numberOfBytesWritten);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100793 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100794
795 unsigned int uint32_t_size = sizeof(uint32_t);
796 unsigned int uint64_t_size = sizeof(uint64_t);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100797 BOOST_CHECK(numberOfBytesWritten == 20 + ThreadIdSize);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100798
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100799 unsigned int offset = 0;
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100800 // Check the decl_id
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100801 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
802 BOOST_CHECK(readDeclId == 4);
803
804 // Check the timestamp
805 offset += uint32_t_size;
806 uint64_t readTimestamp = ReadUint64(buffer.data(), offset);
807 BOOST_CHECK(readTimestamp == timestamp);
808
809 // Check the thread id
810 offset += uint64_t_size;
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100811 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
812 ReadBytes(buffer.data(), offset, ThreadIdSize, readThreadId.data());
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100813 BOOST_CHECK(readThreadId == threadId);
814
815 // Check the profiling GUID
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100816 offset += ThreadIdSize;
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100817 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
818 BOOST_CHECK(readProfilingGuid == profilingGuid);
819}
820
821BOOST_AUTO_TEST_SUITE_END()