blob: 811918a3e38820d1a69ca1c13a7948d008f0a0eb [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
Matthew Sloyan371b70e2020-09-11 10:14:57 +01009#include <armnn/utility/NumericCast.hpp>
10
Jim Flynnbbfe6032020-07-20 16:57:44 +010011#include <common/include/SwTrace.hpp>
12
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010013#include <boost/test/unit_test.hpp>
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010014
15using namespace armnn::profiling;
16
17BOOST_AUTO_TEST_SUITE(TimelinePacketTests)
18
Keith Davis97da5e22020-03-05 16:25:28 +000019BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestNoBuffer)
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010020{
21 const uint64_t profilingGuid = 123456u;
22 const std::string label = "some label";
23 unsigned int numberOfBytesWritten = 789u;
24 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
25 label,
26 nullptr,
27 512u,
28 numberOfBytesWritten);
29 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
30 BOOST_CHECK(numberOfBytesWritten == 0);
31}
32
Keith Davis97da5e22020-03-05 16:25:28 +000033BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestBufferExhaustionZeroValue)
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010034{
35 std::vector<unsigned char> buffer(512, 0);
36
37 const uint64_t profilingGuid = 123456u;
38 const std::string label = "some label";
39 unsigned int numberOfBytesWritten = 789u;
40 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
41 label,
42 buffer.data(),
43 0,
44 numberOfBytesWritten);
45 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
46 BOOST_CHECK(numberOfBytesWritten == 0);
47}
48
Keith Davis97da5e22020-03-05 16:25:28 +000049BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestBufferExhaustionFixedValue)
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010050{
51 std::vector<unsigned char> buffer(10, 0);
52
53 const uint64_t profilingGuid = 123456u;
54 const std::string label = "some label";
55 unsigned int numberOfBytesWritten = 789u;
56 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
57 label,
58 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +010059 armnn::numeric_cast<unsigned int>(buffer.size()),
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010060 numberOfBytesWritten);
61 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
62 BOOST_CHECK(numberOfBytesWritten == 0);
63}
64
Keith Davis97da5e22020-03-05 16:25:28 +000065BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestInvalidLabel)
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010066{
67 std::vector<unsigned char> buffer(512, 0);
68
69 const uint64_t profilingGuid = 123456u;
70 const std::string label = "s0m€ l@b€l";
71 unsigned int numberOfBytesWritten = 789u;
72 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
73 label,
74 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +010075 armnn::numeric_cast<unsigned int>(buffer.size()),
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010076 numberOfBytesWritten);
77 BOOST_CHECK(result == TimelinePacketStatus::Error);
78 BOOST_CHECK(numberOfBytesWritten == 0);
79}
80
Keith Davis97da5e22020-03-05 16:25:28 +000081BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestSingleConstructionOfData)
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010082{
83 std::vector<unsigned char> buffer(512, 0);
84
85 const uint64_t profilingGuid = 123456u;
86 const std::string label = "some label";
87 unsigned int numberOfBytesWritten = 789u;
88 TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid,
89 label,
90 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +010091 armnn::numeric_cast<unsigned int>(buffer.size()),
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010092 numberOfBytesWritten);
93 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Keith Davis97da5e22020-03-05 16:25:28 +000094 BOOST_CHECK(numberOfBytesWritten == 28);
Matteo Martincigh0aed4f92019-10-01 14:25:34 +010095
96 unsigned int uint32_t_size = sizeof(uint32_t);
97 unsigned int uint64_t_size = sizeof(uint64_t);
98
99 // Check the packet header
100 unsigned int offset = 0;
Jan Eilersb884ea42019-10-16 09:54:15 +0100101 uint32_t decl_Id = ReadUint32(buffer.data(), offset);
102 BOOST_CHECK(decl_Id == uint32_t(0));
Matteo Martincigh0aed4f92019-10-01 14:25:34 +0100103
104 // Check the profiling GUID
105 offset += uint32_t_size;
106 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
107 BOOST_CHECK(readProfilingGuid == profilingGuid);
108
109 // Check the SWTrace label
110 offset += uint64_t_size;
111 uint32_t swTraceLabelLength = ReadUint32(buffer.data(), offset);
112 BOOST_CHECK(swTraceLabelLength == 11); // Label length including the null-terminator
113
114 offset += uint32_t_size;
115 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
116 label.data(), // The original label
117 swTraceLabelLength - 1) == 0); // The length of the label
118
119 offset += swTraceLabelLength * uint32_t_size;
120 BOOST_CHECK(buffer[offset] == '\0'); // The null-terminator at the end of the SWTrace label
121}
122
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100123BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketNullBufferTest)
124{
125 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
126 const uint64_t relationshipGuid = 123456u;
127 const uint64_t headGuid = 234567u;
128 const uint64_t tailGuid = 345678u;
Finn Williams0a336dc2020-05-11 15:39:58 +0100129 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100130 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000131 TimelinePacketStatus result = WriteTimelineRelationshipBinary(relationshipType,
132 relationshipGuid,
133 headGuid,
134 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100135 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000136 nullptr,
137 512u,
138 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100139 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
140 BOOST_CHECK(numberOfBytesWritten == 0);
141}
142
143BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketZeroBufferSizeTest)
144{
145 std::vector<unsigned char> buffer(512, 0);
146
147 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
148 const uint64_t relationshipGuid = 123456u;
149 const uint64_t headGuid = 234567u;
150 const uint64_t tailGuid = 345678u;
Finn Williams0a336dc2020-05-11 15:39:58 +0100151 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100152 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000153 TimelinePacketStatus result = WriteTimelineRelationshipBinary(relationshipType,
154 relationshipGuid,
155 headGuid,
156 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100157 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000158 buffer.data(),
159 0,
160 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100161 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
162 BOOST_CHECK(numberOfBytesWritten == 0);
163}
164
165BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketSmallBufferSizeTest)
166{
167 std::vector<unsigned char> buffer(10, 0);
168
169 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
170 const uint64_t relationshipGuid = 123456u;
171 const uint64_t headGuid = 234567u;
172 const uint64_t tailGuid = 345678u;
Finn Williams0a336dc2020-05-11 15:39:58 +0100173 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100174 unsigned int numberOfBytesWritten = 789u;
175 TimelinePacketStatus result =
Keith Davis97da5e22020-03-05 16:25:28 +0000176 WriteTimelineRelationshipBinary(relationshipType,
177 relationshipGuid,
178 headGuid,
179 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100180 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000181 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100182 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000183 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100184 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
185 BOOST_CHECK(numberOfBytesWritten == 0);
186}
187
188BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketInvalidRelationTest)
189{
190 std::vector<unsigned char> buffer(512, 0);
191 ProfilingRelationshipType relationshipType = static_cast<ProfilingRelationshipType>(5);
192 const uint64_t relationshipGuid = 123456u;
193 const uint64_t headGuid = 234567u;
194 const uint64_t tailGuid = 345678u;
Finn Williams0a336dc2020-05-11 15:39:58 +0100195 const uint64_t attributeGuid = 876345u;
196
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100197 unsigned int numberOfBytesWritten = 789u;
198
Keith Davis97da5e22020-03-05 16:25:28 +0000199 BOOST_CHECK_THROW(WriteTimelineRelationshipBinary(relationshipType,
200 relationshipGuid,
201 headGuid,
202 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100203 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000204 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100205 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000206 numberOfBytesWritten),
207 armnn::InvalidArgumentException);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100208
209 BOOST_CHECK(numberOfBytesWritten == 0);
210}
211
Keith Davis97da5e22020-03-05 16:25:28 +0000212BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketTestDataConstruction)
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100213{
214 std::vector<unsigned char> buffer(512, 0);
215
216 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::RetentionLink;
217 const uint64_t relationshipGuid = 123456u;
218 const uint64_t headGuid = 234567u;
219 const uint64_t tailGuid = 345678u;
Finn Williams0a336dc2020-05-11 15:39:58 +0100220 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100221 unsigned int numberOfBytesWritten = 789u;
222 TimelinePacketStatus result =
Keith Davis97da5e22020-03-05 16:25:28 +0000223 WriteTimelineRelationshipBinary(relationshipType,
224 relationshipGuid,
225 headGuid,
226 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100227 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000228 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100229 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000230 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100231 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Finn Williams0a336dc2020-05-11 15:39:58 +0100232 BOOST_CHECK(numberOfBytesWritten == 40);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100233
234 unsigned int uint32_t_size = sizeof(uint32_t);
235 unsigned int uint64_t_size = sizeof(uint64_t);
236
237 // Check the packet header
238 unsigned int offset = 0;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100239 // Check the decl_id
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100240 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
241 BOOST_CHECK(readDeclId == 3);
242
243 // Check the relationship type
244 offset += uint32_t_size;
245 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
246 BOOST_CHECK(readRelationshipType == 0);
247
248 // Check the relationship GUID
249 offset += uint32_t_size;
250 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
251 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
252
253 // Check the head GUID
254 offset += uint64_t_size;
255 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
256 BOOST_CHECK(readHeadGuid == headGuid);
257
258 // Check the tail GUID
259 offset += uint64_t_size;
260 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
261 BOOST_CHECK(readTailGuid == tailGuid);
Finn Williams0a336dc2020-05-11 15:39:58 +0100262
263 // Check the attribute GUID
264 offset += uint64_t_size;
265 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
266 BOOST_CHECK(readAttributeGuid == attributeGuid);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100267}
268
Keith Davis97da5e22020-03-05 16:25:28 +0000269BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketExecutionLinkTestDataConstruction)
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100270{
271 std::vector<unsigned char> buffer(512, 0);
272
273 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::ExecutionLink;
274 const uint64_t relationshipGuid = 123456u;
275 const uint64_t headGuid = 234567u;
276 const uint64_t tailGuid = 345678u;
Finn Williams0a336dc2020-05-11 15:39:58 +0100277 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100278 unsigned int numberOfBytesWritten = 789u;
279 TimelinePacketStatus result =
Keith Davis97da5e22020-03-05 16:25:28 +0000280 WriteTimelineRelationshipBinary(relationshipType,
281 relationshipGuid,
282 headGuid,
283 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100284 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000285 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100286 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000287 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100288 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Finn Williams0a336dc2020-05-11 15:39:58 +0100289 BOOST_CHECK(numberOfBytesWritten == 40);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100290
291 unsigned int uint32_t_size = sizeof(uint32_t);
292 unsigned int uint64_t_size = sizeof(uint64_t);
293
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100294 unsigned int offset = 0;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100295 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
296 BOOST_CHECK(readDeclId == 3);
297
298 // Check the relationship type
299 offset += uint32_t_size;
300 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
301 BOOST_CHECK(readRelationshipType == 1);
302
303 // Check the relationship GUID
304 offset += uint32_t_size;
305 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
306 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
307
308 // Check the head GUID
309 offset += uint64_t_size;
310 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
311 BOOST_CHECK(readHeadGuid == headGuid);
312
313 // Check the tail GUID
314 offset += uint64_t_size;
315 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
316 BOOST_CHECK(readTailGuid == tailGuid);
Finn Williams0a336dc2020-05-11 15:39:58 +0100317
318 // Check the attribute GUID
319 offset += uint64_t_size;
320 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
321 BOOST_CHECK(readAttributeGuid == attributeGuid);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100322}
323
324
Keith Davis97da5e22020-03-05 16:25:28 +0000325BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketDataLinkTestDataConstruction)
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100326{
327 std::vector<unsigned char> buffer(512, 0);
328
329 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink;
330 const uint64_t relationshipGuid = 123456u;
331 const uint64_t headGuid = 234567u;
332 const uint64_t tailGuid = 345678u;
Finn Williams0a336dc2020-05-11 15:39:58 +0100333 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100334 unsigned int numberOfBytesWritten = 789u;
335 TimelinePacketStatus result =
Keith Davis97da5e22020-03-05 16:25:28 +0000336 WriteTimelineRelationshipBinary(relationshipType,
337 relationshipGuid,
338 headGuid,
339 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100340 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000341 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100342 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000343 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100344 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Finn Williams0a336dc2020-05-11 15:39:58 +0100345 BOOST_CHECK(numberOfBytesWritten == 40);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100346
347 unsigned int uint32_t_size = sizeof(uint32_t);
348 unsigned int uint64_t_size = sizeof(uint64_t);
349
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100350 unsigned int offset = 0;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100351 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
352 BOOST_CHECK(readDeclId == 3);
353
354 // Check the relationship type
355 offset += uint32_t_size;
356 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
357 BOOST_CHECK(readRelationshipType == 2);
358
359 // Check the relationship GUID
360 offset += uint32_t_size;
361 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
362 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
363
364 // Check the head GUID
365 offset += uint64_t_size;
366 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
367 BOOST_CHECK(readHeadGuid == headGuid);
368
369 // Check the tail GUID
370 offset += uint64_t_size;
371 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
372 BOOST_CHECK(readTailGuid == tailGuid);
Finn Williams0a336dc2020-05-11 15:39:58 +0100373
374 // Check the attribute GUID
375 offset += uint64_t_size;
376 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
377 BOOST_CHECK(readAttributeGuid == attributeGuid);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100378}
379
380
Keith Davis97da5e22020-03-05 16:25:28 +0000381BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketLabelLinkTestDataConstruction)
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100382{
383 std::vector<unsigned char> buffer(512, 0);
384
385 ProfilingRelationshipType relationshipType = ProfilingRelationshipType::LabelLink;
386 const uint64_t relationshipGuid = 123456u;
387 const uint64_t headGuid = 234567u;
388 const uint64_t tailGuid = 345678u;
Finn Williams0a336dc2020-05-11 15:39:58 +0100389 const uint64_t attributeGuid = 876345u;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100390 unsigned int numberOfBytesWritten = 789u;
391 TimelinePacketStatus result =
Keith Davis97da5e22020-03-05 16:25:28 +0000392 WriteTimelineRelationshipBinary(relationshipType,
393 relationshipGuid,
394 headGuid,
395 tailGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100396 attributeGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000397 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100398 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000399 numberOfBytesWritten);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100400 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Finn Williams0a336dc2020-05-11 15:39:58 +0100401 BOOST_CHECK(numberOfBytesWritten == 40);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100402
403 unsigned int uint32_t_size = sizeof(uint32_t);
404 unsigned int uint64_t_size = sizeof(uint64_t);
405
406 // Check the packet header
407 unsigned int offset = 0;
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100408 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
409 BOOST_CHECK(readDeclId == 3);
410
411 // Check the relationship type
412 offset += uint32_t_size;
413 uint32_t readRelationshipType = ReadUint32(buffer.data(), offset);
414 BOOST_CHECK(readRelationshipType == 3);
415
416 // Check the relationship GUID
417 offset += uint32_t_size;
418 uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset);
419 BOOST_CHECK(readRelationshipGuid == relationshipGuid);
420
421 // Check the head GUID
422 offset += uint64_t_size;
423 uint64_t readHeadGuid = ReadUint64(buffer.data(), offset);
424 BOOST_CHECK(readHeadGuid == headGuid);
425
426 // Check the tail GUID
427 offset += uint64_t_size;
428 uint64_t readTailGuid = ReadUint64(buffer.data(), offset);
429 BOOST_CHECK(readTailGuid == tailGuid);
Finn Williams0a336dc2020-05-11 15:39:58 +0100430
431 // Check the attribute GUID
432 offset += uint64_t_size;
433 uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset);
434 BOOST_CHECK(readAttributeGuid == attributeGuid);
Narumol Prangnawarat7e5eec72019-10-16 12:16:26 +0100435}
436
Keith Davis97da5e22020-03-05 16:25:28 +0000437BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestNoBuffer)
Sadik Armagan784db772019-10-08 15:05:38 +0100438{
439 unsigned int numberOfBytesWritten = 789u;
440 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(nullptr,
441 512u,
442 numberOfBytesWritten);
443 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
444 BOOST_CHECK(numberOfBytesWritten == 0);
445}
446
Keith Davis97da5e22020-03-05 16:25:28 +0000447BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestBufferExhausted)
Sadik Armagan784db772019-10-08 15:05:38 +0100448{
449 std::vector<unsigned char> buffer(512, 0);
450
451 unsigned int numberOfBytesWritten = 789u;
452 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(),
453 0,
454 numberOfBytesWritten);
455 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
456 BOOST_CHECK(numberOfBytesWritten == 0);
457}
458
Keith Davis97da5e22020-03-05 16:25:28 +0000459BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestFullConstruction)
Sadik Armagan784db772019-10-08 15:05:38 +0100460{
461 std::vector<unsigned char> buffer(512, 0);
462 unsigned int numberOfBytesWritten = 789u;
463 TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100464 armnn::numeric_cast<unsigned int>(buffer.size()),
Sadik Armagan784db772019-10-08 15:05:38 +0100465 numberOfBytesWritten);
466 BOOST_CHECK(result == TimelinePacketStatus::Ok);
467
Jim Flynn6398a982020-05-27 17:05:21 +0100468 BOOST_CHECK(numberOfBytesWritten == 451);
Sadik Armagan784db772019-10-08 15:05:38 +0100469
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000470 unsigned int uint8_t_size = sizeof(uint8_t);
Sadik Armagan784db772019-10-08 15:05:38 +0100471 unsigned int uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000472 unsigned int uint64_t_size = sizeof(uint64_t);
Sadik Armagan784db772019-10-08 15:05:38 +0100473
474 // Check the packet header
475 unsigned int offset = 0;
476 uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset);
477 uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F;
478 uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F;
479 uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007;
480 uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007;
481 BOOST_CHECK(packetFamily == 1);
482 BOOST_CHECK(packetClass == 0);
483 BOOST_CHECK(packetType == 0);
484 BOOST_CHECK(streamId == 0);
485
486 offset += uint32_t_size;
487 uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset);
488 uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001;
489 uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF;
490 BOOST_CHECK(sequenceNumbered == 0);
Jim Flynn6398a982020-05-27 17:05:21 +0100491 BOOST_CHECK(dataLength == 443);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000492
493 // Check the stream header
494 offset += uint32_t_size;
495 uint8_t readStreamVersion = ReadUint8(buffer.data(), offset);
496 BOOST_CHECK(readStreamVersion == 4);
497 offset += uint8_t_size;
498 uint8_t readPointerBytes = ReadUint8(buffer.data(), offset);
499 BOOST_CHECK(readPointerBytes == uint64_t_size);
500 offset += uint8_t_size;
501 uint8_t readThreadIdBytes = ReadUint8(buffer.data(), offset);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100502 BOOST_CHECK(readThreadIdBytes == ThreadIdSize);
Sadik Armagan784db772019-10-08 15:05:38 +0100503
Finn Williamse63a0262019-10-22 10:30:49 +0100504 // Check the number of declarations
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000505 offset += uint8_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +0100506 uint32_t declCount = ReadUint32(buffer.data(), offset);
507 BOOST_CHECK(declCount == 5);
508
Sadik Armagan784db772019-10-08 15:05:38 +0100509 // Check the decl_id
510 offset += uint32_t_size;
511 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
512 BOOST_CHECK(readDeclId == 0);
513
514 // SWTrace "namestring" format
515 // length of the string (first 4 bytes) + string + null terminator
516
517 // Check the decl_name
518 offset += uint32_t_size;
519 uint32_t swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
520 BOOST_CHECK(swTraceDeclNameLength == 13); // decl_name length including the null-terminator
521
522 std::string label = "declareLabel";
523 offset += uint32_t_size;
524 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000525 label.data(), // The original label
Sadik Armagan784db772019-10-08 15:05:38 +0100526 swTraceDeclNameLength - 1) == 0); // The length of the label
527
528 // Check the ui_name
529 std::vector<uint32_t> swTraceString;
Jim Flynnbbfe6032020-07-20 16:57:44 +0100530 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100531 offset += (armnn::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
Sadik Armagan784db772019-10-08 15:05:38 +0100532 uint32_t swTraceUINameLength = ReadUint32(buffer.data(), offset);
533 BOOST_CHECK(swTraceUINameLength == 14); // ui_name length including the null-terminator
534
535 label = "declare label";
536 offset += uint32_t_size;
537 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
538 label.data(), // The original label
539 swTraceUINameLength - 1) == 0); // The length of the label
540
541 // Check arg_types
Jim Flynnbbfe6032020-07-20 16:57:44 +0100542 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100543 offset += (armnn::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
Sadik Armagan784db772019-10-08 15:05:38 +0100544 uint32_t swTraceArgTypesLength = ReadUint32(buffer.data(), offset);
545 BOOST_CHECK(swTraceArgTypesLength == 3); // arg_types length including the null-terminator
546
547 label = "ps";
548 offset += uint32_t_size;
549 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
550 label.data(), // The original label
551 swTraceArgTypesLength - 1) == 0); // The length of the label
552
553 // Check arg_names
Jim Flynnbbfe6032020-07-20 16:57:44 +0100554 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100555 offset += (armnn::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
Sadik Armagan784db772019-10-08 15:05:38 +0100556 uint32_t swTraceArgNamesLength = ReadUint32(buffer.data(), offset);
557 BOOST_CHECK(swTraceArgNamesLength == 11); // arg_names length including the null-terminator
558
559 label = "guid,value";
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 swTraceArgNamesLength - 1) == 0); // The length of the label
564
565 // Check second message decl_id
Jim Flynnbbfe6032020-07-20 16:57:44 +0100566 arm::pipe::StringToSwTraceString<arm::pipe::SwTraceCharPolicy>(label, swTraceString);
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100567 offset += (armnn::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size;
Sadik Armagan784db772019-10-08 15:05:38 +0100568 readDeclId = ReadUint32(buffer.data(), offset);
569 BOOST_CHECK(readDeclId == 1);
570
571 // Check second decl_name
572 offset += uint32_t_size;
573 swTraceDeclNameLength = ReadUint32(buffer.data(), offset);
574 BOOST_CHECK(swTraceDeclNameLength == 14); // decl_name length including the null-terminator
575
576 label = "declareEntity";
577 offset += uint32_t_size;
578 BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer
579 label.data(), // The original label
580 swTraceDeclNameLength - 1) == 0); // The length of the label
581}
582
Keith Davis97da5e22020-03-05 16:25:28 +0000583BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestNoBuffer)
David Monahanf21f6062019-10-07 15:11:15 +0100584{
585 const uint64_t profilingGuid = 123456u;
586 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000587 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
588 nullptr,
589 512u,
590 numberOfBytesWritten);
David Monahanf21f6062019-10-07 15:11:15 +0100591 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
592 BOOST_CHECK(numberOfBytesWritten == 0);
593}
594
Keith Davis97da5e22020-03-05 16:25:28 +0000595BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithZeroBufferSize)
David Monahanf21f6062019-10-07 15:11:15 +0100596{
597 std::vector<unsigned char> buffer(512, 0);
598
599 const uint64_t profilingGuid = 123456u;
600 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000601 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
602 buffer.data(),
603 0,
604 numberOfBytesWritten);
David Monahanf21f6062019-10-07 15:11:15 +0100605 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
606 BOOST_CHECK(numberOfBytesWritten == 0);
607}
608
Keith Davis97da5e22020-03-05 16:25:28 +0000609BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithFixedBufferSize)
David Monahanf21f6062019-10-07 15:11:15 +0100610{
611 std::vector<unsigned char> buffer(10, 0);
612
613 const uint64_t profilingGuid = 123456u;
614 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000615 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
616 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100617 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000618 numberOfBytesWritten);
David Monahanf21f6062019-10-07 15:11:15 +0100619 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
620 BOOST_CHECK(numberOfBytesWritten == 0);
621}
622
Keith Davis97da5e22020-03-05 16:25:28 +0000623BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestFullConstructionOfData)
David Monahanf21f6062019-10-07 15:11:15 +0100624{
625 std::vector<unsigned char> buffer(512, 0);
626
627 const uint64_t profilingGuid = 123456u;
628 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000629 TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid,
630 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100631 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000632 numberOfBytesWritten);
David Monahanf21f6062019-10-07 15:11:15 +0100633 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Keith Davis97da5e22020-03-05 16:25:28 +0000634 BOOST_CHECK(numberOfBytesWritten == 12);
David Monahanf21f6062019-10-07 15:11:15 +0100635
636 unsigned int uint32_t_size = sizeof(uint32_t);
637
David Monahanf21f6062019-10-07 15:11:15 +0100638 unsigned int offset = 0;
Jan Eilersb884ea42019-10-16 09:54:15 +0100639 // Check decl_Id
Jan Eilersb884ea42019-10-16 09:54:15 +0100640 uint32_t decl_Id = ReadUint32(buffer.data(), offset);
641 BOOST_CHECK(decl_Id == uint32_t(1));
642
David Monahanf21f6062019-10-07 15:11:15 +0100643 // Check the profiling GUID
644 offset += uint32_t_size;
645 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
646 BOOST_CHECK(readProfilingGuid == profilingGuid);
647}
648
Keith Davis97da5e22020-03-05 16:25:28 +0000649BOOST_AUTO_TEST_CASE(TimelineEventClassTestNoBuffer)
Jan Eilers92fa15b2019-10-15 15:23:25 +0100650{
651 const uint64_t profilingGuid = 123456u;
Jim Flynn1892d212020-05-26 21:10:49 +0100652 const uint64_t profilingNameGuid = 3345u;
Jan Eilers92fa15b2019-10-15 15:23:25 +0100653 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000654 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
Jim Flynn1892d212020-05-26 21:10:49 +0100655 profilingNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000656 nullptr,
657 512u,
658 numberOfBytesWritten);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100659 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
660 BOOST_CHECK(numberOfBytesWritten == 0);
661}
662
Keith Davis97da5e22020-03-05 16:25:28 +0000663BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionZeroValue)
Jan Eilers92fa15b2019-10-15 15:23:25 +0100664{
665 std::vector<unsigned char> buffer(512, 0);
666
667 const uint64_t profilingGuid = 123456u;
Jim Flynn1892d212020-05-26 21:10:49 +0100668 const uint64_t profilingNameGuid = 3345u;
Jan Eilers92fa15b2019-10-15 15:23:25 +0100669 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000670 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
Jim Flynn1892d212020-05-26 21:10:49 +0100671 profilingNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000672 buffer.data(),
673 0,
674 numberOfBytesWritten);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100675 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
676 BOOST_CHECK(numberOfBytesWritten == 0);
677}
678
Keith Davis97da5e22020-03-05 16:25:28 +0000679BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionFixedValue)
Jan Eilers92fa15b2019-10-15 15:23:25 +0100680{
681 std::vector<unsigned char> buffer(10, 0);
682
683 const uint64_t profilingGuid = 123456u;
Jim Flynn1892d212020-05-26 21:10:49 +0100684 const uint64_t profilingNameGuid = 5564u;
Jan Eilers92fa15b2019-10-15 15:23:25 +0100685 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000686 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
Jim Flynn1892d212020-05-26 21:10:49 +0100687 profilingNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000688 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100689 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000690 numberOfBytesWritten);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100691 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
692 BOOST_CHECK(numberOfBytesWritten == 0);
693}
694
Keith Davis97da5e22020-03-05 16:25:28 +0000695BOOST_AUTO_TEST_CASE(TimelineEventClassTestFullConstructionOfData)
Jan Eilers92fa15b2019-10-15 15:23:25 +0100696{
697 std::vector<unsigned char> buffer(512, 0);
698
699 const uint64_t profilingGuid = 123456u;
Jim Flynn1892d212020-05-26 21:10:49 +0100700 const uint64_t profilingNameGuid = 654321u;
Jan Eilers92fa15b2019-10-15 15:23:25 +0100701 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000702 TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid,
Jim Flynn1892d212020-05-26 21:10:49 +0100703 profilingNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000704 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100705 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000706 numberOfBytesWritten);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100707 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Jim Flynn1892d212020-05-26 21:10:49 +0100708 BOOST_CHECK(numberOfBytesWritten == 20);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100709
710 unsigned int uint32_t_size = sizeof(uint32_t);
Jim Flynn1892d212020-05-26 21:10:49 +0100711 unsigned int uint64_t_size = sizeof(uint64_t);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100712
Jan Eilers92fa15b2019-10-15 15:23:25 +0100713 unsigned int offset = 0;
Jan Eilers92fa15b2019-10-15 15:23:25 +0100714 // Check the decl_id
Jan Eilers92fa15b2019-10-15 15:23:25 +0100715 uint32_t declId = ReadUint32(buffer.data(), offset);
716 BOOST_CHECK(declId == uint32_t(2));
717
718 // Check the profiling GUID
719 offset += uint32_t_size;
720 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
721 BOOST_CHECK(readProfilingGuid == profilingGuid);
Jim Flynn1892d212020-05-26 21:10:49 +0100722
723 offset += uint64_t_size;
724 uint64_t readProfilingNameGuid = ReadUint64(buffer.data(), offset);
725 BOOST_CHECK(readProfilingNameGuid == profilingNameGuid);
Jan Eilers92fa15b2019-10-15 15:23:25 +0100726}
727
Keith Davis97da5e22020-03-05 16:25:28 +0000728BOOST_AUTO_TEST_CASE(TimelineEventPacketTestNoBuffer)
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100729{
730 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100731 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100732 const uint64_t profilingGuid = 123456u;
733 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000734 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
735 threadId,
736 profilingGuid,
737 nullptr,
738 512u,
739 numberOfBytesWritten);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100740 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
741 BOOST_CHECK(numberOfBytesWritten == 0);
742}
743
Keith Davis97da5e22020-03-05 16:25:28 +0000744BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionZeroValue)
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100745{
746 std::vector<unsigned char> buffer(512, 0);
747
748 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100749 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100750 const uint64_t profilingGuid = 123456u;
751 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000752 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
753 threadId,
754 profilingGuid,
755 buffer.data(),
756 0,
757 numberOfBytesWritten);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100758 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
759 BOOST_CHECK(numberOfBytesWritten == 0);
760}
761
Keith Davis97da5e22020-03-05 16:25:28 +0000762BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionFixedValue)
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100763{
764 std::vector<unsigned char> buffer(10, 0);
765
766 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100767 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100768 const uint64_t profilingGuid = 123456u;
769 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000770 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
771 threadId,
772 profilingGuid,
773 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100774 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000775 numberOfBytesWritten);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100776 BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion);
777 BOOST_CHECK(numberOfBytesWritten == 0);
778}
779
Keith Davis97da5e22020-03-05 16:25:28 +0000780BOOST_AUTO_TEST_CASE(TimelineEventPacketTestFullConstructionOfData)
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100781{
782 std::vector<unsigned char> buffer(512, 0);
783
784 const uint64_t timestamp = 456789u;
Jim Flynn1fdeb992020-07-09 07:28:37 +0100785 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100786 const uint64_t profilingGuid = 123456u;
787 unsigned int numberOfBytesWritten = 789u;
Keith Davis97da5e22020-03-05 16:25:28 +0000788 TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
789 threadId,
790 profilingGuid,
791 buffer.data(),
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100792 armnn::numeric_cast<unsigned int>(buffer.size()),
Keith Davis97da5e22020-03-05 16:25:28 +0000793 numberOfBytesWritten);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100794 BOOST_CHECK(result == TimelinePacketStatus::Ok);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100795
796 unsigned int uint32_t_size = sizeof(uint32_t);
797 unsigned int uint64_t_size = sizeof(uint64_t);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100798 BOOST_CHECK(numberOfBytesWritten == 20 + ThreadIdSize);
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100799
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100800 unsigned int offset = 0;
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100801 // Check the decl_id
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100802 uint32_t readDeclId = ReadUint32(buffer.data(), offset);
803 BOOST_CHECK(readDeclId == 4);
804
805 // Check the timestamp
806 offset += uint32_t_size;
807 uint64_t readTimestamp = ReadUint64(buffer.data(), offset);
808 BOOST_CHECK(readTimestamp == timestamp);
809
810 // Check the thread id
811 offset += uint64_t_size;
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100812 std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
813 ReadBytes(buffer.data(), offset, ThreadIdSize, readThreadId.data());
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100814 BOOST_CHECK(readThreadId == threadId);
815
816 // Check the profiling GUID
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100817 offset += ThreadIdSize;
Matteo Martincigh8844c2f2019-10-16 10:29:17 +0100818 uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset);
819 BOOST_CHECK(readProfilingGuid == profilingGuid);
820}
821
822BOOST_AUTO_TEST_SUITE_END()