blob: eda45e864029f26c8f50a3e3e1a78e198af113e0 [file] [log] [blame]
Francis Murtagh1f7db452019-08-14 09:49:34 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "../CommandHandlerKey.hpp"
Francis Murtagh11f99b42019-08-16 11:28:52 +01007#include "../CommandHandlerFunctor.hpp"
Francis Murtagh94d79152019-08-16 17:45:07 +01008#include "../CommandHandlerRegistry.hpp"
Nikhil Rajd88e47c2019-08-19 10:04:23 +01009#include "../EncodeVersion.hpp"
Francis Murtagh68f78d82019-09-04 16:42:29 +010010#include "../Holder.hpp"
Nikhil Rajbc626052019-08-15 15:49:45 +010011#include "../Packet.hpp"
Aron Virginas-Tare898db92019-08-22 12:56:34 +010012#include "../PacketVersionResolver.hpp"
Nikhil Raj3ecc5102019-09-03 15:55:33 +010013#include "../ProfilingStateMachine.hpp"
Aron Virginas-Tare898db92019-08-22 12:56:34 +010014
Keith Davis02356de2019-08-26 18:28:17 +010015#include "../ProfilingService.hpp"
16
Aron Virginas-Tare898db92019-08-22 12:56:34 +010017#include <boost/test/unit_test.hpp>
Francis Murtagh1f7db452019-08-14 09:49:34 +010018
Nikhil Rajbc626052019-08-15 15:49:45 +010019#include <cstdint>
20#include <cstring>
Aron Virginas-Tare898db92019-08-22 12:56:34 +010021#include <limits>
Francis Murtagh11f99b42019-08-16 11:28:52 +010022#include <map>
Aron Virginas-Tare898db92019-08-22 12:56:34 +010023#include <random>
Nikhil Raj3ecc5102019-09-03 15:55:33 +010024#include <thread>
Francis Murtagh1f7db452019-08-14 09:49:34 +010025
26BOOST_AUTO_TEST_SUITE(ExternalProfiling)
27
Aron Virginas-Tare898db92019-08-22 12:56:34 +010028using namespace armnn::profiling;
29
Francis Murtagh1f7db452019-08-14 09:49:34 +010030BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons)
31{
32 CommandHandlerKey testKey0(1, 1);
33 CommandHandlerKey testKey1(1, 1);
34 CommandHandlerKey testKey2(1, 1);
35 CommandHandlerKey testKey3(0, 0);
36 CommandHandlerKey testKey4(2, 2);
37 CommandHandlerKey testKey5(0, 2);
38
39 BOOST_CHECK(testKey1<testKey4);
40 BOOST_CHECK(testKey1>testKey3);
41 BOOST_CHECK(testKey1<=testKey4);
42 BOOST_CHECK(testKey1>=testKey3);
43 BOOST_CHECK(testKey1<=testKey2);
44 BOOST_CHECK(testKey1>=testKey2);
45 BOOST_CHECK(testKey1==testKey2);
46 BOOST_CHECK(testKey1==testKey1);
47
48 BOOST_CHECK(!(testKey1==testKey5));
49 BOOST_CHECK(!(testKey1!=testKey1));
50 BOOST_CHECK(testKey1!=testKey5);
51
52 BOOST_CHECK(testKey1==testKey2 && testKey2==testKey1);
53 BOOST_CHECK(testKey0==testKey1 && testKey1==testKey2 && testKey0==testKey2);
54
55 BOOST_CHECK(testKey1.GetPacketId()==1);
56 BOOST_CHECK(testKey1.GetVersion()==1);
57
58 std::vector<CommandHandlerKey> vect =
Aron Virginas-Tare898db92019-08-22 12:56:34 +010059 {
60 CommandHandlerKey(0,1), CommandHandlerKey(2,0), CommandHandlerKey(1,0),
61 CommandHandlerKey(2,1), CommandHandlerKey(1,1), CommandHandlerKey(0,1),
62 CommandHandlerKey(2,0), CommandHandlerKey(0,0)
63 };
Francis Murtagh1f7db452019-08-14 09:49:34 +010064
65 std::sort(vect.begin(), vect.end());
66
67 std::vector<CommandHandlerKey> expectedVect =
Aron Virginas-Tare898db92019-08-22 12:56:34 +010068 {
69 CommandHandlerKey(0,0), CommandHandlerKey(0,1), CommandHandlerKey(0,1),
70 CommandHandlerKey(1,0), CommandHandlerKey(1,1), CommandHandlerKey(2,0),
71 CommandHandlerKey(2,0), CommandHandlerKey(2,1)
72 };
Francis Murtagh1f7db452019-08-14 09:49:34 +010073
74 BOOST_CHECK(vect == expectedVect);
75}
76
Nikhil Rajd88e47c2019-08-19 10:04:23 +010077BOOST_AUTO_TEST_CASE(CheckEncodeVersion)
78{
Aron Virginas-Tare898db92019-08-22 12:56:34 +010079 Version version1(12);
Nikhil Rajd88e47c2019-08-19 10:04:23 +010080
81 BOOST_CHECK(version1.GetMajor() == 0);
82 BOOST_CHECK(version1.GetMinor() == 0);
83 BOOST_CHECK(version1.GetPatch() == 12);
84
Aron Virginas-Tare898db92019-08-22 12:56:34 +010085 Version version2(4108);
Nikhil Rajd88e47c2019-08-19 10:04:23 +010086
87 BOOST_CHECK(version2.GetMajor() == 0);
88 BOOST_CHECK(version2.GetMinor() == 1);
89 BOOST_CHECK(version2.GetPatch() == 12);
90
Aron Virginas-Tare898db92019-08-22 12:56:34 +010091 Version version3(4198412);
Nikhil Rajd88e47c2019-08-19 10:04:23 +010092
93 BOOST_CHECK(version3.GetMajor() == 1);
94 BOOST_CHECK(version3.GetMinor() == 1);
95 BOOST_CHECK(version3.GetPatch() == 12);
96
Aron Virginas-Tare898db92019-08-22 12:56:34 +010097 Version version4(0);
Nikhil Rajd88e47c2019-08-19 10:04:23 +010098
99 BOOST_CHECK(version4.GetMajor() == 0);
100 BOOST_CHECK(version4.GetMinor() == 0);
101 BOOST_CHECK(version4.GetPatch() == 0);
102
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100103 Version version5(1, 0, 0);
Nikhil Rajd88e47c2019-08-19 10:04:23 +0100104 BOOST_CHECK(version5.GetEncodedValue() == 4194304);
105}
106
Nikhil Rajbc626052019-08-15 15:49:45 +0100107BOOST_AUTO_TEST_CASE(CheckPacketClass)
108{
109 const char* data = "test";
110 unsigned int length = static_cast<unsigned int>(std::strlen(data));
111
112 Packet packetTest1(472580096,length,data);
113 BOOST_CHECK_THROW(Packet packetTest2(472580096,0,""), armnn::Exception);
114
115 Packet packetTest3(472580096,0, nullptr);
116
117 BOOST_CHECK(packetTest1.GetLength() == length);
118 BOOST_CHECK(packetTest1.GetData() == data);
119
120 BOOST_CHECK(packetTest1.GetPacketFamily() == 7);
121 BOOST_CHECK(packetTest1.GetPacketId() == 43);
122 BOOST_CHECK(packetTest1.GetPacketType() == 3);
123 BOOST_CHECK(packetTest1.GetPacketClass() == 5);
124}
125
Francis Murtagh94d79152019-08-16 17:45:07 +0100126// Create Derived Classes
127class TestFunctorA : public CommandHandlerFunctor
128{
129public:
130 using CommandHandlerFunctor::CommandHandlerFunctor;
131
132 int GetCount() { return m_Count; }
133
134 void operator()(const Packet& packet) override
135 {
136 m_Count++;
137 }
138
139private:
140 int m_Count = 0;
141};
142
143class TestFunctorB : public TestFunctorA
144{
145 using TestFunctorA::TestFunctorA;
146};
147
148class TestFunctorC : public TestFunctorA
149{
150 using TestFunctorA::TestFunctorA;
151};
152
Francis Murtagh11f99b42019-08-16 11:28:52 +0100153BOOST_AUTO_TEST_CASE(CheckCommandHandlerFunctor)
154{
Francis Murtagh11f99b42019-08-16 11:28:52 +0100155 // Hard code the version as it will be the same during a single profiling session
156 uint32_t version = 1;
157
158 TestFunctorA testFunctorA(461, version);
159 TestFunctorB testFunctorB(963, version);
160 TestFunctorC testFunctorC(983, version);
161
162 CommandHandlerKey keyA(testFunctorA.GetPacketId(), testFunctorA.GetVersion());
163 CommandHandlerKey keyB(testFunctorB.GetPacketId(), testFunctorB.GetVersion());
164 CommandHandlerKey keyC(testFunctorC.GetPacketId(), testFunctorC.GetVersion());
165
166 // Create the unwrapped map to simulate the Command Handler Registry
167 std::map<CommandHandlerKey, CommandHandlerFunctor*> registry;
168
169 registry.insert(std::make_pair(keyB, &testFunctorB));
170 registry.insert(std::make_pair(keyA, &testFunctorA));
171 registry.insert(std::make_pair(keyC, &testFunctorC));
172
173 // Check the order of the map is correct
174 auto it = registry.begin();
175 BOOST_CHECK(it->first==keyA);
176 it++;
177 BOOST_CHECK(it->first==keyB);
178 it++;
179 BOOST_CHECK(it->first==keyC);
180
181 Packet packetA(500000000, 0, nullptr);
182 Packet packetB(600000000, 0, nullptr);
183 Packet packetC(400000000, 0, nullptr);
184
185 // Check the correct operator of derived class is called
186 registry.at(CommandHandlerKey(packetA.GetPacketId(), version))->operator()(packetA);
187 BOOST_CHECK(testFunctorA.GetCount() == 1);
188 BOOST_CHECK(testFunctorB.GetCount() == 0);
189 BOOST_CHECK(testFunctorC.GetCount() == 0);
190
191 registry.at(CommandHandlerKey(packetB.GetPacketId(), version))->operator()(packetB);
192 BOOST_CHECK(testFunctorA.GetCount() == 1);
193 BOOST_CHECK(testFunctorB.GetCount() == 1);
194 BOOST_CHECK(testFunctorC.GetCount() == 0);
195
196 registry.at(CommandHandlerKey(packetC.GetPacketId(), version))->operator()(packetC);
197 BOOST_CHECK(testFunctorA.GetCount() == 1);
198 BOOST_CHECK(testFunctorB.GetCount() == 1);
199 BOOST_CHECK(testFunctorC.GetCount() == 1);
200}
201
Francis Murtagh94d79152019-08-16 17:45:07 +0100202BOOST_AUTO_TEST_CASE(CheckCommandHandlerRegistry)
203{
204 // Hard code the version as it will be the same during a single profiling session
205 uint32_t version = 1;
206
207 TestFunctorA testFunctorA(461, version);
208 TestFunctorB testFunctorB(963, version);
209 TestFunctorC testFunctorC(983, version);
210
211 // Create the Command Handler Registry
212 CommandHandlerRegistry registry;
213
214 // Register multiple different derived classes
215 registry.RegisterFunctor(&testFunctorA, testFunctorA.GetPacketId(), testFunctorA.GetVersion());
216 registry.RegisterFunctor(&testFunctorB, testFunctorB.GetPacketId(), testFunctorB.GetVersion());
217 registry.RegisterFunctor(&testFunctorC, testFunctorC.GetPacketId(), testFunctorC.GetVersion());
218
219 Packet packetA(500000000, 0, nullptr);
220 Packet packetB(600000000, 0, nullptr);
221 Packet packetC(400000000, 0, nullptr);
222
223 // Check the correct operator of derived class is called
224 registry.GetFunctor(packetA.GetPacketId(), version)->operator()(packetA);
225 BOOST_CHECK(testFunctorA.GetCount() == 1);
226 BOOST_CHECK(testFunctorB.GetCount() == 0);
227 BOOST_CHECK(testFunctorC.GetCount() == 0);
228
229 registry.GetFunctor(packetB.GetPacketId(), version)->operator()(packetB);
230 BOOST_CHECK(testFunctorA.GetCount() == 1);
231 BOOST_CHECK(testFunctorB.GetCount() == 1);
232 BOOST_CHECK(testFunctorC.GetCount() == 0);
233
234 registry.GetFunctor(packetC.GetPacketId(), version)->operator()(packetC);
235 BOOST_CHECK(testFunctorA.GetCount() == 1);
236 BOOST_CHECK(testFunctorB.GetCount() == 1);
237 BOOST_CHECK(testFunctorC.GetCount() == 1);
238
239 // Re-register an existing key with a new function
240 registry.RegisterFunctor(&testFunctorC, testFunctorA.GetPacketId(), version);
241 registry.GetFunctor(packetA.GetPacketId(), version)->operator()(packetC);
242 BOOST_CHECK(testFunctorA.GetCount() == 1);
243 BOOST_CHECK(testFunctorB.GetCount() == 1);
244 BOOST_CHECK(testFunctorC.GetCount() == 2);
245
246 // Check that non-existent key returns nullptr for its functor
247 BOOST_CHECK_THROW(registry.GetFunctor(0, 0), armnn::Exception);
248}
249
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100250BOOST_AUTO_TEST_CASE(CheckPacketVersionResolver)
251{
252 // Set up random number generator for generating packetId values
253 std::random_device device;
254 std::mt19937 generator(device());
255 std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(),
256 std::numeric_limits<uint32_t>::max());
257
258 // NOTE: Expected version is always 1.0.0, regardless of packetId
259 const Version expectedVersion(1, 0, 0);
260
261 PacketVersionResolver packetVersionResolver;
262
263 constexpr unsigned int numTests = 10u;
264
265 for (unsigned int i = 0u; i < numTests; ++i)
266 {
267 const uint32_t packetId = distribution(generator);
268 Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(packetId);
269
270 BOOST_TEST(resolvedVersion == expectedVersion);
271 }
272}
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100273void ProfilingCurrentStateThreadImpl(ProfilingStateMachine& states)
274{
275 ProfilingState newState = ProfilingState::NotConnected;
276 states.GetCurrentState();
277 states.TransitionToState(newState);
278}
279
280BOOST_AUTO_TEST_CASE(CheckProfilingStateMachine)
281{
282 ProfilingStateMachine profilingState1(ProfilingState::Uninitialised);
283 profilingState1.TransitionToState(ProfilingState::Uninitialised);
284 BOOST_CHECK(profilingState1.GetCurrentState() == ProfilingState::Uninitialised);
285
286 ProfilingStateMachine profilingState2(ProfilingState::Uninitialised);
287 profilingState2.TransitionToState(ProfilingState::NotConnected);
288 BOOST_CHECK(profilingState2.GetCurrentState() == ProfilingState::NotConnected);
289
290 ProfilingStateMachine profilingState3(ProfilingState::NotConnected);
291 profilingState3.TransitionToState(ProfilingState::NotConnected);
292 BOOST_CHECK(profilingState3.GetCurrentState() == ProfilingState::NotConnected);
293
294 ProfilingStateMachine profilingState4(ProfilingState::NotConnected);
295 profilingState4.TransitionToState(ProfilingState::WaitingForAck);
296 BOOST_CHECK(profilingState4.GetCurrentState() == ProfilingState::WaitingForAck);
297
298 ProfilingStateMachine profilingState5(ProfilingState::WaitingForAck);
299 profilingState5.TransitionToState(ProfilingState::WaitingForAck);
300 BOOST_CHECK(profilingState5.GetCurrentState() == ProfilingState::WaitingForAck);
301
302 ProfilingStateMachine profilingState6(ProfilingState::WaitingForAck);
303 profilingState6.TransitionToState(ProfilingState::Active);
304 BOOST_CHECK(profilingState6.GetCurrentState() == ProfilingState::Active);
305
306 ProfilingStateMachine profilingState7(ProfilingState::Active);
307 profilingState7.TransitionToState(ProfilingState::NotConnected);
308 BOOST_CHECK(profilingState7.GetCurrentState() == ProfilingState::NotConnected);
309
310 ProfilingStateMachine profilingState8(ProfilingState::Active);
311 profilingState8.TransitionToState(ProfilingState::Active);
312 BOOST_CHECK(profilingState8.GetCurrentState() == ProfilingState::Active);
313
314 ProfilingStateMachine profilingState9(ProfilingState::Uninitialised);
315 BOOST_CHECK_THROW(profilingState9.TransitionToState(ProfilingState::WaitingForAck),
316 armnn::Exception);
317
318 ProfilingStateMachine profilingState10(ProfilingState::Uninitialised);
319 BOOST_CHECK_THROW(profilingState10.TransitionToState(ProfilingState::Active),
320 armnn::Exception);
321
322 ProfilingStateMachine profilingState11(ProfilingState::NotConnected);
323 BOOST_CHECK_THROW(profilingState11.TransitionToState(ProfilingState::Uninitialised),
324 armnn::Exception);
325
326 ProfilingStateMachine profilingState12(ProfilingState::NotConnected);
327 BOOST_CHECK_THROW(profilingState12.TransitionToState(ProfilingState::Active),
328 armnn::Exception);
329
330 ProfilingStateMachine profilingState13(ProfilingState::WaitingForAck);
331 BOOST_CHECK_THROW(profilingState13.TransitionToState(ProfilingState::Uninitialised),
332 armnn::Exception);
333
334 ProfilingStateMachine profilingState14(ProfilingState::WaitingForAck);
335 BOOST_CHECK_THROW(profilingState14.TransitionToState(ProfilingState::NotConnected),
336 armnn::Exception);
337
338 ProfilingStateMachine profilingState15(ProfilingState::Active);
339 BOOST_CHECK_THROW(profilingState15.TransitionToState(ProfilingState::Uninitialised),
340 armnn::Exception);
341
342 ProfilingStateMachine profilingState16(armnn::profiling::ProfilingState::Active);
343 BOOST_CHECK_THROW(profilingState16.TransitionToState(ProfilingState::WaitingForAck),
344 armnn::Exception);
345
346 ProfilingStateMachine profilingState17(ProfilingState::Uninitialised);
347
348 std::thread thread1 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17));
349 std::thread thread2 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17));
350 std::thread thread3 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17));
351 std::thread thread4 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17));
352 std::thread thread5 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17));
353
354 thread1.join();
355 thread2.join();
356 thread3.join();
357 thread4.join();
358 thread5.join();
359
360 BOOST_TEST((profilingState17.GetCurrentState() == ProfilingState::NotConnected));
361}
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100362
Francis Murtagh68f78d82019-09-04 16:42:29 +0100363void CaptureDataWriteThreadImpl(Holder &holder, uint32_t capturePeriod, std::vector<uint16_t>& counterIds)
364{
365 holder.SetCaptureData(capturePeriod, counterIds);
366}
367
Francis Murtaghbd707162019-09-09 11:26:44 +0100368void CaptureDataReadThreadImpl(const Holder& holder, CaptureData& captureData)
Francis Murtagh68f78d82019-09-04 16:42:29 +0100369{
370 captureData = holder.GetCaptureData();
371}
372
373BOOST_AUTO_TEST_CASE(CheckCaptureDataHolder)
374{
Francis Murtaghbd707162019-09-09 11:26:44 +0100375 std::map<uint32_t, std::vector<uint16_t>> periodIdMap;
376 std::vector<uint16_t> counterIds;
377 uint16_t numThreads = 50;
378 for (uint16_t i = 0; i < numThreads; ++i)
379 {
380 counterIds.emplace_back(i);
381 periodIdMap.insert(std::make_pair(i, counterIds));
382 }
Francis Murtagh68f78d82019-09-04 16:42:29 +0100383
384 // Check CaptureData functions
385 CaptureData capture;
386 BOOST_CHECK(capture.GetCapturePeriod() == 0);
387 BOOST_CHECK((capture.GetCounterIds()).empty());
Francis Murtaghbd707162019-09-09 11:26:44 +0100388 capture.SetCapturePeriod(0);
389 capture.SetCounterIds(periodIdMap[0]);
390 BOOST_CHECK(capture.GetCapturePeriod() == 0);
391 BOOST_CHECK(capture.GetCounterIds() == periodIdMap[0]);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100392
393 Holder holder;
394 BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 0);
395 BOOST_CHECK(((holder.GetCaptureData()).GetCounterIds()).empty());
396
397 // Check Holder functions
Francis Murtaghbd707162019-09-09 11:26:44 +0100398 std::thread thread1(CaptureDataWriteThreadImpl, std::ref(holder), 2, std::ref(periodIdMap[2]));
Francis Murtagh68f78d82019-09-04 16:42:29 +0100399 thread1.join();
400
Francis Murtaghbd707162019-09-09 11:26:44 +0100401 BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 2);
402 BOOST_CHECK((holder.GetCaptureData()).GetCounterIds() == periodIdMap[2]);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100403
404 CaptureData captureData;
405 std::thread thread2(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData));
406 thread2.join();
Francis Murtaghbd707162019-09-09 11:26:44 +0100407 BOOST_CHECK(captureData.GetCounterIds() == periodIdMap[2]);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100408
Francis Murtaghbd707162019-09-09 11:26:44 +0100409 std::vector<std::thread> threadsVect;
410 for (int i = 0; i < numThreads; i+=2)
411 {
412 threadsVect.emplace_back(std::thread(CaptureDataWriteThreadImpl,
413 std::ref(holder),
414 i,
415 std::ref(periodIdMap[static_cast<uint16_t >(i)])));
Francis Murtagh06965692019-09-05 16:29:01 +0100416
Francis Murtaghbd707162019-09-09 11:26:44 +0100417 threadsVect.emplace_back(std::thread(CaptureDataReadThreadImpl,
418 std::ref(holder),
419 std::ref(captureData)));
420 }
421
422 for (uint16_t i = 0; i < numThreads; ++i)
423 {
424 threadsVect[i].join();
425 }
426
427 std::vector<std::thread> readThreadsVect;
428 for (uint16_t i = 0; i < numThreads; ++i)
429 {
430 readThreadsVect.emplace_back(
431 std::thread(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData)));
432 }
433
434 for (uint16_t i = 0; i < numThreads; ++i)
435 {
436 readThreadsVect[i].join();
437 }
Francis Murtagh68f78d82019-09-04 16:42:29 +0100438
439 // Check CaptureData was written/read correctly from multiple threads
440 std::vector<uint16_t> captureIds = captureData.GetCounterIds();
441 uint32_t capturePeriod = captureData.GetCapturePeriod();
Francis Murtaghbd707162019-09-09 11:26:44 +0100442
443 BOOST_CHECK(captureIds == periodIdMap[capturePeriod]);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100444
445 std::vector<uint16_t> readIds = holder.GetCaptureData().GetCounterIds();
Francis Murtaghbd707162019-09-09 11:26:44 +0100446 BOOST_CHECK(captureIds == readIds);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100447
448 // Check assignment operator
449 CaptureData assignableCaptureData;
Francis Murtaghbd707162019-09-09 11:26:44 +0100450 assignableCaptureData.SetCapturePeriod(3);
451 assignableCaptureData.SetCounterIds(periodIdMap[3]);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100452
453 CaptureData secondCaptureData;
Francis Murtaghbd707162019-09-09 11:26:44 +0100454 secondCaptureData.SetCapturePeriod(2);
455 secondCaptureData.SetCounterIds(periodIdMap[2]);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100456
457 BOOST_CHECK(secondCaptureData.GetCapturePeriod() == 2);
Francis Murtaghbd707162019-09-09 11:26:44 +0100458 BOOST_CHECK(secondCaptureData.GetCounterIds() == periodIdMap[2]);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100459
460 secondCaptureData = assignableCaptureData;
461 BOOST_CHECK(secondCaptureData.GetCapturePeriod() == 3);
Francis Murtaghbd707162019-09-09 11:26:44 +0100462 BOOST_CHECK(secondCaptureData.GetCounterIds() == periodIdMap[3]);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100463
464 // Check copy constructor
465 CaptureData copyConstructedCaptureData(assignableCaptureData);
466
467 BOOST_CHECK(copyConstructedCaptureData.GetCapturePeriod() == 3);
Francis Murtaghbd707162019-09-09 11:26:44 +0100468 BOOST_CHECK(copyConstructedCaptureData.GetCounterIds() == periodIdMap[3]);
Keith Davis02356de2019-08-26 18:28:17 +0100469}
Francis Murtagh68f78d82019-09-04 16:42:29 +0100470
Keith Davis02356de2019-08-26 18:28:17 +0100471BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisabled)
472{
473 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
474 ProfilingService service(options);
475 BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised);
476 service.Run();
477 BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised);
478}
479
Keith Davis02356de2019-08-26 18:28:17 +0100480BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabled)
481{
482 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
483 options.m_EnableProfiling = true;
484 ProfilingService service(options);
485 BOOST_CHECK(service.GetCurrentState() == ProfilingState::NotConnected);
486 service.Run();
487 BOOST_CHECK(service.GetCurrentState() == ProfilingState::WaitingForAck);
488}
489
490
491BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabledRuntime)
492{
493 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
494 ProfilingService service(options);
495 BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised);
496 service.Run();
497 BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised);
498 service.m_Options.m_EnableProfiling = true;
499 service.Run();
500 BOOST_CHECK(service.GetCurrentState() == ProfilingState::NotConnected);
501 service.Run();
502 BOOST_CHECK(service.GetCurrentState() == ProfilingState::WaitingForAck);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100503}
504
Francis Murtagh1f7db452019-08-14 09:49:34 +0100505BOOST_AUTO_TEST_SUITE_END()