2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "../CommandHandlerKey.hpp"
7 #include "../CommandHandlerFunctor.hpp"
8 #include "../CommandHandlerRegistry.hpp"
9 #include "../EncodeVersion.hpp"
10 #include "../Holder.hpp"
11 #include "../Packet.hpp"
12 #include "../PacketVersionResolver.hpp"
13 #include "../ProfilingService.hpp"
14 #include "../ProfilingStateMachine.hpp"
15 #include "../PeriodicCounterSelectionCommandHandler.hpp"
16 #include "../ProfilingUtils.hpp"
17 #include "../SocketProfilingConnection.hpp"
18 #include "../IPeriodicCounterCapture.hpp"
19 #include "SendCounterPacketTests.hpp"
21 #include <Runtime.hpp>
24 #include <boost/test/unit_test.hpp>
25 #include <boost/numeric/conversion/cast.hpp>
34 BOOST_AUTO_TEST_SUITE(ExternalProfiling)
36 using namespace armnn::profiling;
38 BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons)
40 CommandHandlerKey testKey0(1, 1);
41 CommandHandlerKey testKey1(1, 1);
42 CommandHandlerKey testKey2(1, 1);
43 CommandHandlerKey testKey3(0, 0);
44 CommandHandlerKey testKey4(2, 2);
45 CommandHandlerKey testKey5(0, 2);
47 BOOST_CHECK(testKey1<testKey4);
48 BOOST_CHECK(testKey1>testKey3);
49 BOOST_CHECK(testKey1<=testKey4);
50 BOOST_CHECK(testKey1>=testKey3);
51 BOOST_CHECK(testKey1<=testKey2);
52 BOOST_CHECK(testKey1>=testKey2);
53 BOOST_CHECK(testKey1==testKey2);
54 BOOST_CHECK(testKey1==testKey1);
56 BOOST_CHECK(!(testKey1==testKey5));
57 BOOST_CHECK(!(testKey1!=testKey1));
58 BOOST_CHECK(testKey1!=testKey5);
60 BOOST_CHECK(testKey1==testKey2 && testKey2==testKey1);
61 BOOST_CHECK(testKey0==testKey1 && testKey1==testKey2 && testKey0==testKey2);
63 BOOST_CHECK(testKey1.GetPacketId()==1);
64 BOOST_CHECK(testKey1.GetVersion()==1);
66 std::vector<CommandHandlerKey> vect =
68 CommandHandlerKey(0,1), CommandHandlerKey(2,0), CommandHandlerKey(1,0),
69 CommandHandlerKey(2,1), CommandHandlerKey(1,1), CommandHandlerKey(0,1),
70 CommandHandlerKey(2,0), CommandHandlerKey(0,0)
73 std::sort(vect.begin(), vect.end());
75 std::vector<CommandHandlerKey> expectedVect =
77 CommandHandlerKey(0,0), CommandHandlerKey(0,1), CommandHandlerKey(0,1),
78 CommandHandlerKey(1,0), CommandHandlerKey(1,1), CommandHandlerKey(2,0),
79 CommandHandlerKey(2,0), CommandHandlerKey(2,1)
82 BOOST_CHECK(vect == expectedVect);
85 BOOST_AUTO_TEST_CASE(CheckEncodeVersion)
89 BOOST_CHECK(version1.GetMajor() == 0);
90 BOOST_CHECK(version1.GetMinor() == 0);
91 BOOST_CHECK(version1.GetPatch() == 12);
93 Version version2(4108);
95 BOOST_CHECK(version2.GetMajor() == 0);
96 BOOST_CHECK(version2.GetMinor() == 1);
97 BOOST_CHECK(version2.GetPatch() == 12);
99 Version version3(4198412);
101 BOOST_CHECK(version3.GetMajor() == 1);
102 BOOST_CHECK(version3.GetMinor() == 1);
103 BOOST_CHECK(version3.GetPatch() == 12);
107 BOOST_CHECK(version4.GetMajor() == 0);
108 BOOST_CHECK(version4.GetMinor() == 0);
109 BOOST_CHECK(version4.GetPatch() == 0);
111 Version version5(1, 0, 0);
112 BOOST_CHECK(version5.GetEncodedValue() == 4194304);
115 BOOST_AUTO_TEST_CASE(CheckPacketClass)
118 std::unique_ptr<char[]> packetData0 = std::make_unique<char[]>(length);
119 std::unique_ptr<char[]> packetData1 = std::make_unique<char[]>(0);
120 std::unique_ptr<char[]> nullPacketData;
122 Packet packetTest0(472580096, length, packetData0);
124 BOOST_CHECK(packetTest0.GetHeader() == 472580096);
125 BOOST_CHECK(packetTest0.GetPacketFamily() == 7);
126 BOOST_CHECK(packetTest0.GetPacketId() == 43);
127 BOOST_CHECK(packetTest0.GetLength() == length);
128 BOOST_CHECK(packetTest0.GetPacketType() == 3);
129 BOOST_CHECK(packetTest0.GetPacketClass() == 5);
131 BOOST_CHECK_THROW(Packet packetTest1(472580096, 0, packetData1), armnn::Exception);
132 BOOST_CHECK_NO_THROW(Packet packetTest2(472580096, 0, nullPacketData));
134 Packet packetTest3(472580096, 0, nullPacketData);
135 BOOST_CHECK(packetTest3.GetLength() == 0);
136 BOOST_CHECK(packetTest3.GetData() == nullptr);
138 const char* packetTest0Data = packetTest0.GetData();
139 Packet packetTest4(std::move(packetTest0));
141 BOOST_CHECK(packetTest0.GetData() == nullptr);
142 BOOST_CHECK(packetTest4.GetData() == packetTest0Data);
144 BOOST_CHECK(packetTest4.GetHeader() == 472580096);
145 BOOST_CHECK(packetTest4.GetPacketFamily() == 7);
146 BOOST_CHECK(packetTest4.GetPacketId() == 43);
147 BOOST_CHECK(packetTest4.GetLength() == length);
148 BOOST_CHECK(packetTest4.GetPacketType() == 3);
149 BOOST_CHECK(packetTest4.GetPacketClass() == 5);
152 // Create Derived Classes
153 class TestFunctorA : public CommandHandlerFunctor
156 using CommandHandlerFunctor::CommandHandlerFunctor;
158 int GetCount() { return m_Count; }
160 void operator()(const Packet& packet) override
169 class TestFunctorB : public TestFunctorA
171 using TestFunctorA::TestFunctorA;
174 class TestFunctorC : public TestFunctorA
176 using TestFunctorA::TestFunctorA;
179 BOOST_AUTO_TEST_CASE(CheckCommandHandlerFunctor)
181 // Hard code the version as it will be the same during a single profiling session
182 uint32_t version = 1;
184 TestFunctorA testFunctorA(461, version);
185 TestFunctorB testFunctorB(963, version);
186 TestFunctorC testFunctorC(983, version);
188 CommandHandlerKey keyA(testFunctorA.GetPacketId(), testFunctorA.GetVersion());
189 CommandHandlerKey keyB(testFunctorB.GetPacketId(), testFunctorB.GetVersion());
190 CommandHandlerKey keyC(testFunctorC.GetPacketId(), testFunctorC.GetVersion());
192 // Create the unwrapped map to simulate the Command Handler Registry
193 std::map<CommandHandlerKey, CommandHandlerFunctor*> registry;
195 registry.insert(std::make_pair(keyB, &testFunctorB));
196 registry.insert(std::make_pair(keyA, &testFunctorA));
197 registry.insert(std::make_pair(keyC, &testFunctorC));
199 // Check the order of the map is correct
200 auto it = registry.begin();
201 BOOST_CHECK(it->first==keyA);
203 BOOST_CHECK(it->first==keyB);
205 BOOST_CHECK(it->first==keyC);
207 std::unique_ptr<char[]> packetDataA;
208 std::unique_ptr<char[]> packetDataB;
209 std::unique_ptr<char[]> packetDataC;
211 Packet packetA(500000000, 0, packetDataA);
212 Packet packetB(600000000, 0, packetDataB);
213 Packet packetC(400000000, 0, packetDataC);
215 // Check the correct operator of derived class is called
216 registry.at(CommandHandlerKey(packetA.GetPacketId(), version))->operator()(packetA);
217 BOOST_CHECK(testFunctorA.GetCount() == 1);
218 BOOST_CHECK(testFunctorB.GetCount() == 0);
219 BOOST_CHECK(testFunctorC.GetCount() == 0);
221 registry.at(CommandHandlerKey(packetB.GetPacketId(), version))->operator()(packetB);
222 BOOST_CHECK(testFunctorA.GetCount() == 1);
223 BOOST_CHECK(testFunctorB.GetCount() == 1);
224 BOOST_CHECK(testFunctorC.GetCount() == 0);
226 registry.at(CommandHandlerKey(packetC.GetPacketId(), version))->operator()(packetC);
227 BOOST_CHECK(testFunctorA.GetCount() == 1);
228 BOOST_CHECK(testFunctorB.GetCount() == 1);
229 BOOST_CHECK(testFunctorC.GetCount() == 1);
232 BOOST_AUTO_TEST_CASE(CheckCommandHandlerRegistry)
234 // Hard code the version as it will be the same during a single profiling session
235 uint32_t version = 1;
237 TestFunctorA testFunctorA(461, version);
238 TestFunctorB testFunctorB(963, version);
239 TestFunctorC testFunctorC(983, version);
241 // Create the Command Handler Registry
242 CommandHandlerRegistry registry;
244 // Register multiple different derived classes
245 registry.RegisterFunctor(&testFunctorA, testFunctorA.GetPacketId(), testFunctorA.GetVersion());
246 registry.RegisterFunctor(&testFunctorB, testFunctorB.GetPacketId(), testFunctorB.GetVersion());
247 registry.RegisterFunctor(&testFunctorC, testFunctorC.GetPacketId(), testFunctorC.GetVersion());
249 std::unique_ptr<char[]> packetDataA;
250 std::unique_ptr<char[]> packetDataB;
251 std::unique_ptr<char[]> packetDataC;
253 Packet packetA(500000000, 0, packetDataA);
254 Packet packetB(600000000, 0, packetDataB);
255 Packet packetC(400000000, 0, packetDataC);
257 // Check the correct operator of derived class is called
258 registry.GetFunctor(packetA.GetPacketId(), version)->operator()(packetA);
259 BOOST_CHECK(testFunctorA.GetCount() == 1);
260 BOOST_CHECK(testFunctorB.GetCount() == 0);
261 BOOST_CHECK(testFunctorC.GetCount() == 0);
263 registry.GetFunctor(packetB.GetPacketId(), version)->operator()(packetB);
264 BOOST_CHECK(testFunctorA.GetCount() == 1);
265 BOOST_CHECK(testFunctorB.GetCount() == 1);
266 BOOST_CHECK(testFunctorC.GetCount() == 0);
268 registry.GetFunctor(packetC.GetPacketId(), version)->operator()(packetC);
269 BOOST_CHECK(testFunctorA.GetCount() == 1);
270 BOOST_CHECK(testFunctorB.GetCount() == 1);
271 BOOST_CHECK(testFunctorC.GetCount() == 1);
273 // Re-register an existing key with a new function
274 registry.RegisterFunctor(&testFunctorC, testFunctorA.GetPacketId(), version);
275 registry.GetFunctor(packetA.GetPacketId(), version)->operator()(packetC);
276 BOOST_CHECK(testFunctorA.GetCount() == 1);
277 BOOST_CHECK(testFunctorB.GetCount() == 1);
278 BOOST_CHECK(testFunctorC.GetCount() == 2);
280 // Check that non-existent key returns nullptr for its functor
281 BOOST_CHECK_THROW(registry.GetFunctor(0, 0), armnn::Exception);
284 BOOST_AUTO_TEST_CASE(CheckPacketVersionResolver)
286 // Set up random number generator for generating packetId values
287 std::random_device device;
288 std::mt19937 generator(device());
289 std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(),
290 std::numeric_limits<uint32_t>::max());
292 // NOTE: Expected version is always 1.0.0, regardless of packetId
293 const Version expectedVersion(1, 0, 0);
295 PacketVersionResolver packetVersionResolver;
297 constexpr unsigned int numTests = 10u;
299 for (unsigned int i = 0u; i < numTests; ++i)
301 const uint32_t packetId = distribution(generator);
302 Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(packetId);
304 BOOST_TEST(resolvedVersion == expectedVersion);
307 void ProfilingCurrentStateThreadImpl(ProfilingStateMachine& states)
309 ProfilingState newState = ProfilingState::NotConnected;
310 states.GetCurrentState();
311 states.TransitionToState(newState);
314 BOOST_AUTO_TEST_CASE(CheckProfilingStateMachine)
316 ProfilingStateMachine profilingState1(ProfilingState::Uninitialised);
317 profilingState1.TransitionToState(ProfilingState::Uninitialised);
318 BOOST_CHECK(profilingState1.GetCurrentState() == ProfilingState::Uninitialised);
320 ProfilingStateMachine profilingState2(ProfilingState::Uninitialised);
321 profilingState2.TransitionToState(ProfilingState::NotConnected);
322 BOOST_CHECK(profilingState2.GetCurrentState() == ProfilingState::NotConnected);
324 ProfilingStateMachine profilingState3(ProfilingState::NotConnected);
325 profilingState3.TransitionToState(ProfilingState::NotConnected);
326 BOOST_CHECK(profilingState3.GetCurrentState() == ProfilingState::NotConnected);
328 ProfilingStateMachine profilingState4(ProfilingState::NotConnected);
329 profilingState4.TransitionToState(ProfilingState::WaitingForAck);
330 BOOST_CHECK(profilingState4.GetCurrentState() == ProfilingState::WaitingForAck);
332 ProfilingStateMachine profilingState5(ProfilingState::WaitingForAck);
333 profilingState5.TransitionToState(ProfilingState::WaitingForAck);
334 BOOST_CHECK(profilingState5.GetCurrentState() == ProfilingState::WaitingForAck);
336 ProfilingStateMachine profilingState6(ProfilingState::WaitingForAck);
337 profilingState6.TransitionToState(ProfilingState::Active);
338 BOOST_CHECK(profilingState6.GetCurrentState() == ProfilingState::Active);
340 ProfilingStateMachine profilingState7(ProfilingState::Active);
341 profilingState7.TransitionToState(ProfilingState::NotConnected);
342 BOOST_CHECK(profilingState7.GetCurrentState() == ProfilingState::NotConnected);
344 ProfilingStateMachine profilingState8(ProfilingState::Active);
345 profilingState8.TransitionToState(ProfilingState::Active);
346 BOOST_CHECK(profilingState8.GetCurrentState() == ProfilingState::Active);
348 ProfilingStateMachine profilingState9(ProfilingState::Uninitialised);
349 BOOST_CHECK_THROW(profilingState9.TransitionToState(ProfilingState::WaitingForAck),
352 ProfilingStateMachine profilingState10(ProfilingState::Uninitialised);
353 BOOST_CHECK_THROW(profilingState10.TransitionToState(ProfilingState::Active),
356 ProfilingStateMachine profilingState11(ProfilingState::NotConnected);
357 BOOST_CHECK_THROW(profilingState11.TransitionToState(ProfilingState::Uninitialised),
360 ProfilingStateMachine profilingState12(ProfilingState::NotConnected);
361 BOOST_CHECK_THROW(profilingState12.TransitionToState(ProfilingState::Active),
364 ProfilingStateMachine profilingState13(ProfilingState::WaitingForAck);
365 BOOST_CHECK_THROW(profilingState13.TransitionToState(ProfilingState::Uninitialised),
368 ProfilingStateMachine profilingState14(ProfilingState::WaitingForAck);
369 BOOST_CHECK_THROW(profilingState14.TransitionToState(ProfilingState::NotConnected),
372 ProfilingStateMachine profilingState15(ProfilingState::Active);
373 BOOST_CHECK_THROW(profilingState15.TransitionToState(ProfilingState::Uninitialised),
376 ProfilingStateMachine profilingState16(armnn::profiling::ProfilingState::Active);
377 BOOST_CHECK_THROW(profilingState16.TransitionToState(ProfilingState::WaitingForAck),
380 ProfilingStateMachine profilingState17(ProfilingState::Uninitialised);
382 std::thread thread1 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17));
383 std::thread thread2 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17));
384 std::thread thread3 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17));
385 std::thread thread4 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17));
386 std::thread thread5 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17));
394 BOOST_TEST((profilingState17.GetCurrentState() == ProfilingState::NotConnected));
397 void CaptureDataWriteThreadImpl(Holder &holder, uint32_t capturePeriod, std::vector<uint16_t>& counterIds)
399 holder.SetCaptureData(capturePeriod, counterIds);
402 void CaptureDataReadThreadImpl(const Holder& holder, CaptureData& captureData)
404 captureData = holder.GetCaptureData();
407 BOOST_AUTO_TEST_CASE(CheckCaptureDataHolder)
409 std::map<uint32_t, std::vector<uint16_t>> periodIdMap;
410 std::vector<uint16_t> counterIds;
411 uint16_t numThreads = 50;
412 for (uint16_t i = 0; i < numThreads; ++i)
414 counterIds.emplace_back(i);
415 periodIdMap.insert(std::make_pair(i, counterIds));
418 // Check CaptureData functions
420 BOOST_CHECK(capture.GetCapturePeriod() == 0);
421 BOOST_CHECK((capture.GetCounterIds()).empty());
422 capture.SetCapturePeriod(0);
423 capture.SetCounterIds(periodIdMap[0]);
424 BOOST_CHECK(capture.GetCapturePeriod() == 0);
425 BOOST_CHECK(capture.GetCounterIds() == periodIdMap[0]);
428 BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 0);
429 BOOST_CHECK(((holder.GetCaptureData()).GetCounterIds()).empty());
431 // Check Holder functions
432 std::thread thread1(CaptureDataWriteThreadImpl, std::ref(holder), 2, std::ref(periodIdMap[2]));
435 BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 2);
436 BOOST_CHECK((holder.GetCaptureData()).GetCounterIds() == periodIdMap[2]);
438 CaptureData captureData;
439 std::thread thread2(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData));
441 BOOST_CHECK(captureData.GetCounterIds() == periodIdMap[2]);
443 std::vector<std::thread> threadsVect;
444 for (int i = 0; i < numThreads; i+=2)
446 threadsVect.emplace_back(std::thread(CaptureDataWriteThreadImpl,
449 std::ref(periodIdMap[static_cast<uint16_t >(i)])));
451 threadsVect.emplace_back(std::thread(CaptureDataReadThreadImpl,
453 std::ref(captureData)));
456 for (uint16_t i = 0; i < numThreads; ++i)
458 threadsVect[i].join();
461 std::vector<std::thread> readThreadsVect;
462 for (uint16_t i = 0; i < numThreads; ++i)
464 readThreadsVect.emplace_back(
465 std::thread(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData)));
468 for (uint16_t i = 0; i < numThreads; ++i)
470 readThreadsVect[i].join();
473 // Check CaptureData was written/read correctly from multiple threads
474 std::vector<uint16_t> captureIds = captureData.GetCounterIds();
475 uint32_t capturePeriod = captureData.GetCapturePeriod();
477 BOOST_CHECK(captureIds == periodIdMap[capturePeriod]);
479 std::vector<uint16_t> readIds = holder.GetCaptureData().GetCounterIds();
480 BOOST_CHECK(captureIds == readIds);
483 BOOST_AUTO_TEST_CASE(CaptureDataMethods)
485 // Check assignment operator
486 CaptureData assignableCaptureData;
487 std::vector<uint16_t> counterIds = {42, 29, 13};
488 assignableCaptureData.SetCapturePeriod(3);
489 assignableCaptureData.SetCounterIds(counterIds);
491 CaptureData secondCaptureData;
493 BOOST_CHECK(assignableCaptureData.GetCapturePeriod() == 3);
494 BOOST_CHECK(assignableCaptureData.GetCounterIds() == counterIds);
496 secondCaptureData = assignableCaptureData;
497 BOOST_CHECK(secondCaptureData.GetCapturePeriod() == 3);
498 BOOST_CHECK(secondCaptureData.GetCounterIds() == counterIds);
500 // Check copy constructor
501 CaptureData copyConstructedCaptureData(assignableCaptureData);
503 BOOST_CHECK(copyConstructedCaptureData.GetCapturePeriod() == 3);
504 BOOST_CHECK(copyConstructedCaptureData.GetCounterIds() == counterIds);
507 BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisabled)
509 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
510 ProfilingService service(options);
511 BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised);
513 BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised);
516 BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabled)
518 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
519 options.m_EnableProfiling = true;
520 ProfilingService service(options);
521 BOOST_CHECK(service.GetCurrentState() == ProfilingState::NotConnected);
523 BOOST_CHECK(service.GetCurrentState() == ProfilingState::WaitingForAck);
527 BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabledRuntime)
529 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
530 ProfilingService service(options);
531 BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised);
533 BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised);
534 service.m_Options.m_EnableProfiling = true;
536 BOOST_CHECK(service.GetCurrentState() == ProfilingState::NotConnected);
538 BOOST_CHECK(service.GetCurrentState() == ProfilingState::WaitingForAck);
541 void GetNextUidTestImpl(uint16_t& outUid)
543 outUid = GetNextUid();
546 BOOST_AUTO_TEST_CASE(GetNextUidTest)
552 std::thread thread1(GetNextUidTestImpl, std::ref(uid0));
553 std::thread thread2(GetNextUidTestImpl, std::ref(uid1));
554 std::thread thread3(GetNextUidTestImpl, std::ref(uid2));
559 BOOST_TEST(uid0 > 0);
560 BOOST_TEST(uid1 > 0);
561 BOOST_TEST(uid2 > 0);
562 BOOST_TEST(uid0 != uid1);
563 BOOST_TEST(uid0 != uid2);
564 BOOST_TEST(uid1 != uid2);
567 BOOST_AUTO_TEST_CASE(CounterSelectionCommandHandlerParseData)
569 using boost::numeric_cast;
571 class TestCaptureThread : public IPeriodicCounterCapture
573 void Start() override {};
576 const uint32_t packetId = 0x40000;
578 uint32_t version = 1;
580 TestCaptureThread captureThread;
581 MockBuffer mockBuffer(512);
582 SendCounterPacket sendCounterPacket(mockBuffer);
584 uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t));
585 uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t));
587 // Data with period and counters
588 uint32_t period1 = 10;
589 uint32_t dataLength1 = 8;
592 std::unique_ptr<char[]> uniqueData1 = std::make_unique<char[]>(dataLength1);
593 unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
595 WriteUint32(data1, offset, period1);
596 offset += sizeOfUint32;
597 WriteUint16(data1, offset, 4000);
598 offset += sizeOfUint16;
599 WriteUint16(data1, offset, 5000);
601 Packet packetA(packetId, dataLength1, uniqueData1);
603 PeriodicCounterSelectionCommandHandler commandHandler(packetId, version, holder, captureThread,
605 commandHandler(packetA);
607 std::vector<uint16_t> counterIds = holder.GetCaptureData().GetCounterIds();
609 BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == period1);
610 BOOST_TEST(counterIds.size() == 2);
611 BOOST_TEST(counterIds[0] == 4000);
612 BOOST_TEST(counterIds[1] == 5000);
614 unsigned int size = 0;
616 const unsigned char* readBuffer = mockBuffer.GetReadBuffer(size);
620 uint32_t headerWord0 = ReadUint32(readBuffer, offset);
621 offset += sizeOfUint32;
622 uint32_t headerWord1 = ReadUint32(readBuffer, offset);
623 offset += sizeOfUint32;
624 uint32_t period = ReadUint32(readBuffer, offset);
626 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family
627 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id
628 BOOST_TEST(headerWord1 == 8); // data lenght
629 BOOST_TEST(period == 10); // capture period
631 uint16_t counterId = 0;
632 offset += sizeOfUint32;
633 counterId = ReadUint16(readBuffer, offset);
634 BOOST_TEST(counterId == 4000);
635 offset += sizeOfUint16;
636 counterId = ReadUint16(readBuffer, offset);
637 BOOST_TEST(counterId == 5000);
639 // Data with period only
640 uint32_t period2 = 11;
641 uint32_t dataLength2 = 4;
643 std::unique_ptr<char[]> uniqueData2 = std::make_unique<char[]>(dataLength2);
645 WriteUint32(reinterpret_cast<unsigned char*>(uniqueData2.get()), 0, period2);
647 Packet packetB(packetId, dataLength2, uniqueData2);
649 commandHandler(packetB);
651 counterIds = holder.GetCaptureData().GetCounterIds();
653 BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == period2);
654 BOOST_TEST(counterIds.size() == 0);
656 readBuffer = mockBuffer.GetReadBuffer(size);
660 headerWord0 = ReadUint32(readBuffer, offset);
661 offset += sizeOfUint32;
662 headerWord1 = ReadUint32(readBuffer, offset);
663 offset += sizeOfUint32;
664 period = ReadUint32(readBuffer, offset);
666 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family
667 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id
668 BOOST_TEST(headerWord1 == 4); // data lenght
669 BOOST_TEST(period == 11); // capture period
673 BOOST_AUTO_TEST_CASE(CheckSocketProfilingConnection)
675 // Check that creating a SocketProfilingConnection results in an exception as the Gator UDS doesn't exist.
676 BOOST_CHECK_THROW(new SocketProfilingConnection(), armnn::Exception);
679 BOOST_AUTO_TEST_SUITE_END()