Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 6 | #include "SendCounterPacketTests.hpp" |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 7 | #include "../CommandThread.hpp" |
Teresa Charlin | 9bab496 | 2019-09-06 12:28:35 +0100 | [diff] [blame] | 8 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 9 | #include <CommandHandlerKey.hpp> |
| 10 | #include <CommandHandlerFunctor.hpp> |
| 11 | #include <CommandHandlerRegistry.hpp> |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 12 | #include <ConnectionAcknowledgedCommandHandler.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 13 | #include <CounterDirectory.hpp> |
| 14 | #include <EncodeVersion.hpp> |
| 15 | #include <Holder.hpp> |
| 16 | #include <Packet.hpp> |
| 17 | #include <PacketVersionResolver.hpp> |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 18 | #include <PeriodicCounterCapture.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 19 | #include <PeriodicCounterSelectionCommandHandler.hpp> |
| 20 | #include <ProfilingStateMachine.hpp> |
| 21 | #include <ProfilingService.hpp> |
| 22 | #include <ProfilingUtils.hpp> |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 23 | #include <RequestCounterDirectoryCommandHandler.hpp> |
Teresa Charlin | 9bab496 | 2019-09-06 12:28:35 +0100 | [diff] [blame] | 24 | #include <Runtime.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 25 | #include <SocketProfilingConnection.hpp> |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 26 | #include <IReadCounterValue.hpp> |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 27 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 28 | #include <armnn/Conversion.hpp> |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 29 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 30 | #include <boost/test/unit_test.hpp> |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 31 | #include <boost/numeric/conversion/cast.hpp> |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 32 | |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 33 | #include <cstdint> |
| 34 | #include <cstring> |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 35 | #include <limits> |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 36 | #include <map> |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 37 | #include <random> |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 38 | #include <thread> |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 39 | |
| 40 | BOOST_AUTO_TEST_SUITE(ExternalProfiling) |
| 41 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 42 | using namespace armnn::profiling; |
| 43 | |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 44 | BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons) |
| 45 | { |
| 46 | CommandHandlerKey testKey0(1, 1); |
| 47 | CommandHandlerKey testKey1(1, 1); |
| 48 | CommandHandlerKey testKey2(1, 1); |
| 49 | CommandHandlerKey testKey3(0, 0); |
| 50 | CommandHandlerKey testKey4(2, 2); |
| 51 | CommandHandlerKey testKey5(0, 2); |
| 52 | |
| 53 | BOOST_CHECK(testKey1<testKey4); |
| 54 | BOOST_CHECK(testKey1>testKey3); |
| 55 | BOOST_CHECK(testKey1<=testKey4); |
| 56 | BOOST_CHECK(testKey1>=testKey3); |
| 57 | BOOST_CHECK(testKey1<=testKey2); |
| 58 | BOOST_CHECK(testKey1>=testKey2); |
| 59 | BOOST_CHECK(testKey1==testKey2); |
| 60 | BOOST_CHECK(testKey1==testKey1); |
| 61 | |
| 62 | BOOST_CHECK(!(testKey1==testKey5)); |
| 63 | BOOST_CHECK(!(testKey1!=testKey1)); |
| 64 | BOOST_CHECK(testKey1!=testKey5); |
| 65 | |
| 66 | BOOST_CHECK(testKey1==testKey2 && testKey2==testKey1); |
| 67 | BOOST_CHECK(testKey0==testKey1 && testKey1==testKey2 && testKey0==testKey2); |
| 68 | |
| 69 | BOOST_CHECK(testKey1.GetPacketId()==1); |
| 70 | BOOST_CHECK(testKey1.GetVersion()==1); |
| 71 | |
| 72 | std::vector<CommandHandlerKey> vect = |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 73 | { |
| 74 | CommandHandlerKey(0,1), CommandHandlerKey(2,0), CommandHandlerKey(1,0), |
| 75 | CommandHandlerKey(2,1), CommandHandlerKey(1,1), CommandHandlerKey(0,1), |
| 76 | CommandHandlerKey(2,0), CommandHandlerKey(0,0) |
| 77 | }; |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 78 | |
| 79 | std::sort(vect.begin(), vect.end()); |
| 80 | |
| 81 | std::vector<CommandHandlerKey> expectedVect = |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 82 | { |
| 83 | CommandHandlerKey(0,0), CommandHandlerKey(0,1), CommandHandlerKey(0,1), |
| 84 | CommandHandlerKey(1,0), CommandHandlerKey(1,1), CommandHandlerKey(2,0), |
| 85 | CommandHandlerKey(2,0), CommandHandlerKey(2,1) |
| 86 | }; |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 87 | |
| 88 | BOOST_CHECK(vect == expectedVect); |
| 89 | } |
| 90 | |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 91 | class TestProfilingConnectionBase :public IProfilingConnection |
| 92 | { |
| 93 | public: |
| 94 | TestProfilingConnectionBase() = default; |
| 95 | ~TestProfilingConnectionBase() = default; |
| 96 | |
| 97 | bool IsOpen() |
| 98 | { |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | void Close(){} |
| 103 | |
| 104 | bool WritePacket(const char* buffer, uint32_t length) |
| 105 | { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | Packet ReadPacket(uint32_t timeout) |
| 110 | { |
| 111 | std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); |
| 112 | std::unique_ptr<char[]> packetData; |
| 113 | //Return connection acknowledged packet |
| 114 | return {65536 ,0 , packetData}; |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | class TestProfilingConnectionTimeoutError :public TestProfilingConnectionBase |
| 119 | { |
| 120 | int readRequests = 0; |
| 121 | public: |
| 122 | Packet ReadPacket(uint32_t timeout) { |
| 123 | if (readRequests < 3) |
| 124 | { |
| 125 | readRequests++; |
| 126 | throw armnn::TimeoutException(": Simulate a timeout"); |
| 127 | } |
| 128 | std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); |
| 129 | std::unique_ptr<char[]> packetData; |
| 130 | //Return connection acknowledged packet after three timeouts |
| 131 | return {65536 ,0 , packetData}; |
| 132 | } |
| 133 | }; |
| 134 | |
| 135 | class TestProfilingConnectionArmnnError :public TestProfilingConnectionBase |
| 136 | { |
| 137 | public: |
| 138 | |
| 139 | Packet ReadPacket(uint32_t timeout) |
| 140 | { |
| 141 | std::this_thread::sleep_for(std::chrono::milliseconds(timeout)); |
| 142 | throw armnn::Exception(": Simulate a non timeout error"); |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | BOOST_AUTO_TEST_CASE(CheckCommandThread) |
| 147 | { |
| 148 | PacketVersionResolver packetVersionResolver; |
| 149 | ProfilingStateMachine profilingStateMachine; |
| 150 | |
| 151 | TestProfilingConnectionBase testProfilingConnectionBase; |
| 152 | TestProfilingConnectionTimeoutError testProfilingConnectionTimeOutError; |
| 153 | TestProfilingConnectionArmnnError testProfilingConnectionArmnnError; |
| 154 | |
| 155 | ConnectionAcknowledgedCommandHandler connectionAcknowledgedCommandHandler(1, 4194304, profilingStateMachine); |
| 156 | CommandHandlerRegistry commandHandlerRegistry; |
| 157 | |
| 158 | commandHandlerRegistry.RegisterFunctor(&connectionAcknowledgedCommandHandler, 1, 4194304); |
| 159 | |
| 160 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
| 161 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
| 162 | |
| 163 | CommandThread commandThread0(1, |
| 164 | true, |
| 165 | commandHandlerRegistry, |
| 166 | packetVersionResolver, |
| 167 | testProfilingConnectionBase); |
| 168 | |
| 169 | commandThread0.Start(); |
| 170 | commandThread0.Start(); |
| 171 | commandThread0.Start(); |
| 172 | |
| 173 | commandThread0.Stop(); |
| 174 | commandThread0.Join(); |
| 175 | |
| 176 | BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active); |
| 177 | |
| 178 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
| 179 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
| 180 | //commandThread1 should give up after one timeout |
| 181 | CommandThread commandThread1(1, |
| 182 | true, |
| 183 | commandHandlerRegistry, |
| 184 | packetVersionResolver, |
| 185 | testProfilingConnectionTimeOutError); |
| 186 | |
| 187 | commandThread1.Start(); |
| 188 | commandThread1.Join(); |
| 189 | |
| 190 | BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck); |
| 191 | //now commandThread1 should persist after a timeout |
| 192 | commandThread1.StopAfterTimeout(false); |
| 193 | commandThread1.Start(); |
| 194 | |
| 195 | for (int i = 0; i < 100; i++) |
| 196 | { |
| 197 | if (profilingStateMachine.GetCurrentState() == ProfilingState::Active) |
| 198 | { |
| 199 | break; |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | commandThread1.Stop(); |
| 208 | commandThread1.Join(); |
| 209 | |
| 210 | BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active); |
| 211 | |
| 212 | |
| 213 | CommandThread commandThread2(1, |
| 214 | false, |
| 215 | commandHandlerRegistry, |
| 216 | packetVersionResolver, |
| 217 | testProfilingConnectionArmnnError); |
| 218 | |
| 219 | commandThread2.Start(); |
| 220 | |
| 221 | for (int i = 0; i < 100; i++) |
| 222 | { |
| 223 | if (!commandThread2.IsRunning()) |
| 224 | { |
| 225 | //commandThread2 should stop once it encounters a non timing error |
| 226 | commandThread2.Join(); |
| 227 | return; |
| 228 | } |
| 229 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
| 230 | } |
| 231 | |
| 232 | BOOST_ERROR("commandThread2 has failed to stop"); |
| 233 | } |
| 234 | |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 235 | BOOST_AUTO_TEST_CASE(CheckEncodeVersion) |
| 236 | { |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 237 | Version version1(12); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 238 | |
| 239 | BOOST_CHECK(version1.GetMajor() == 0); |
| 240 | BOOST_CHECK(version1.GetMinor() == 0); |
| 241 | BOOST_CHECK(version1.GetPatch() == 12); |
| 242 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 243 | Version version2(4108); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 244 | |
| 245 | BOOST_CHECK(version2.GetMajor() == 0); |
| 246 | BOOST_CHECK(version2.GetMinor() == 1); |
| 247 | BOOST_CHECK(version2.GetPatch() == 12); |
| 248 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 249 | Version version3(4198412); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 250 | |
| 251 | BOOST_CHECK(version3.GetMajor() == 1); |
| 252 | BOOST_CHECK(version3.GetMinor() == 1); |
| 253 | BOOST_CHECK(version3.GetPatch() == 12); |
| 254 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 255 | Version version4(0); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 256 | |
| 257 | BOOST_CHECK(version4.GetMajor() == 0); |
| 258 | BOOST_CHECK(version4.GetMinor() == 0); |
| 259 | BOOST_CHECK(version4.GetPatch() == 0); |
| 260 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 261 | Version version5(1, 0, 0); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 262 | BOOST_CHECK(version5.GetEncodedValue() == 4194304); |
| 263 | } |
| 264 | |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 265 | BOOST_AUTO_TEST_CASE(CheckPacketClass) |
| 266 | { |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 267 | uint32_t length = 4; |
| 268 | std::unique_ptr<char[]> packetData0 = std::make_unique<char[]>(length); |
| 269 | std::unique_ptr<char[]> packetData1 = std::make_unique<char[]>(0); |
| 270 | std::unique_ptr<char[]> nullPacketData; |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 271 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 272 | Packet packetTest0(472580096, length, packetData0); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 273 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 274 | BOOST_CHECK(packetTest0.GetHeader() == 472580096); |
| 275 | BOOST_CHECK(packetTest0.GetPacketFamily() == 7); |
| 276 | BOOST_CHECK(packetTest0.GetPacketId() == 43); |
| 277 | BOOST_CHECK(packetTest0.GetLength() == length); |
| 278 | BOOST_CHECK(packetTest0.GetPacketType() == 3); |
| 279 | BOOST_CHECK(packetTest0.GetPacketClass() == 5); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 280 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 281 | BOOST_CHECK_THROW(Packet packetTest1(472580096, 0, packetData1), armnn::Exception); |
| 282 | BOOST_CHECK_NO_THROW(Packet packetTest2(472580096, 0, nullPacketData)); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 283 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 284 | Packet packetTest3(472580096, 0, nullPacketData); |
| 285 | BOOST_CHECK(packetTest3.GetLength() == 0); |
| 286 | BOOST_CHECK(packetTest3.GetData() == nullptr); |
| 287 | |
| 288 | const char* packetTest0Data = packetTest0.GetData(); |
| 289 | Packet packetTest4(std::move(packetTest0)); |
| 290 | |
| 291 | BOOST_CHECK(packetTest0.GetData() == nullptr); |
| 292 | BOOST_CHECK(packetTest4.GetData() == packetTest0Data); |
| 293 | |
| 294 | BOOST_CHECK(packetTest4.GetHeader() == 472580096); |
| 295 | BOOST_CHECK(packetTest4.GetPacketFamily() == 7); |
| 296 | BOOST_CHECK(packetTest4.GetPacketId() == 43); |
| 297 | BOOST_CHECK(packetTest4.GetLength() == length); |
| 298 | BOOST_CHECK(packetTest4.GetPacketType() == 3); |
| 299 | BOOST_CHECK(packetTest4.GetPacketClass() == 5); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 300 | } |
| 301 | |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 302 | // Create Derived Classes |
| 303 | class TestFunctorA : public CommandHandlerFunctor |
| 304 | { |
| 305 | public: |
| 306 | using CommandHandlerFunctor::CommandHandlerFunctor; |
| 307 | |
| 308 | int GetCount() { return m_Count; } |
| 309 | |
| 310 | void operator()(const Packet& packet) override |
| 311 | { |
| 312 | m_Count++; |
| 313 | } |
| 314 | |
| 315 | private: |
| 316 | int m_Count = 0; |
| 317 | }; |
| 318 | |
| 319 | class TestFunctorB : public TestFunctorA |
| 320 | { |
| 321 | using TestFunctorA::TestFunctorA; |
| 322 | }; |
| 323 | |
| 324 | class TestFunctorC : public TestFunctorA |
| 325 | { |
| 326 | using TestFunctorA::TestFunctorA; |
| 327 | }; |
| 328 | |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 329 | BOOST_AUTO_TEST_CASE(CheckCommandHandlerFunctor) |
| 330 | { |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 331 | // Hard code the version as it will be the same during a single profiling session |
| 332 | uint32_t version = 1; |
| 333 | |
| 334 | TestFunctorA testFunctorA(461, version); |
| 335 | TestFunctorB testFunctorB(963, version); |
| 336 | TestFunctorC testFunctorC(983, version); |
| 337 | |
| 338 | CommandHandlerKey keyA(testFunctorA.GetPacketId(), testFunctorA.GetVersion()); |
| 339 | CommandHandlerKey keyB(testFunctorB.GetPacketId(), testFunctorB.GetVersion()); |
| 340 | CommandHandlerKey keyC(testFunctorC.GetPacketId(), testFunctorC.GetVersion()); |
| 341 | |
| 342 | // Create the unwrapped map to simulate the Command Handler Registry |
| 343 | std::map<CommandHandlerKey, CommandHandlerFunctor*> registry; |
| 344 | |
| 345 | registry.insert(std::make_pair(keyB, &testFunctorB)); |
| 346 | registry.insert(std::make_pair(keyA, &testFunctorA)); |
| 347 | registry.insert(std::make_pair(keyC, &testFunctorC)); |
| 348 | |
| 349 | // Check the order of the map is correct |
| 350 | auto it = registry.begin(); |
| 351 | BOOST_CHECK(it->first==keyA); |
| 352 | it++; |
| 353 | BOOST_CHECK(it->first==keyB); |
| 354 | it++; |
| 355 | BOOST_CHECK(it->first==keyC); |
| 356 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 357 | std::unique_ptr<char[]> packetDataA; |
| 358 | std::unique_ptr<char[]> packetDataB; |
| 359 | std::unique_ptr<char[]> packetDataC; |
| 360 | |
| 361 | Packet packetA(500000000, 0, packetDataA); |
| 362 | Packet packetB(600000000, 0, packetDataB); |
| 363 | Packet packetC(400000000, 0, packetDataC); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 364 | |
| 365 | // Check the correct operator of derived class is called |
| 366 | registry.at(CommandHandlerKey(packetA.GetPacketId(), version))->operator()(packetA); |
| 367 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 368 | BOOST_CHECK(testFunctorB.GetCount() == 0); |
| 369 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 370 | |
| 371 | registry.at(CommandHandlerKey(packetB.GetPacketId(), version))->operator()(packetB); |
| 372 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 373 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 374 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 375 | |
| 376 | registry.at(CommandHandlerKey(packetC.GetPacketId(), version))->operator()(packetC); |
| 377 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 378 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 379 | BOOST_CHECK(testFunctorC.GetCount() == 1); |
| 380 | } |
| 381 | |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 382 | BOOST_AUTO_TEST_CASE(CheckCommandHandlerRegistry) |
| 383 | { |
| 384 | // Hard code the version as it will be the same during a single profiling session |
| 385 | uint32_t version = 1; |
| 386 | |
| 387 | TestFunctorA testFunctorA(461, version); |
| 388 | TestFunctorB testFunctorB(963, version); |
| 389 | TestFunctorC testFunctorC(983, version); |
| 390 | |
| 391 | // Create the Command Handler Registry |
| 392 | CommandHandlerRegistry registry; |
| 393 | |
| 394 | // Register multiple different derived classes |
| 395 | registry.RegisterFunctor(&testFunctorA, testFunctorA.GetPacketId(), testFunctorA.GetVersion()); |
| 396 | registry.RegisterFunctor(&testFunctorB, testFunctorB.GetPacketId(), testFunctorB.GetVersion()); |
| 397 | registry.RegisterFunctor(&testFunctorC, testFunctorC.GetPacketId(), testFunctorC.GetVersion()); |
| 398 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 399 | std::unique_ptr<char[]> packetDataA; |
| 400 | std::unique_ptr<char[]> packetDataB; |
| 401 | std::unique_ptr<char[]> packetDataC; |
| 402 | |
| 403 | Packet packetA(500000000, 0, packetDataA); |
| 404 | Packet packetB(600000000, 0, packetDataB); |
| 405 | Packet packetC(400000000, 0, packetDataC); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 406 | |
| 407 | // Check the correct operator of derived class is called |
| 408 | registry.GetFunctor(packetA.GetPacketId(), version)->operator()(packetA); |
| 409 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 410 | BOOST_CHECK(testFunctorB.GetCount() == 0); |
| 411 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 412 | |
| 413 | registry.GetFunctor(packetB.GetPacketId(), version)->operator()(packetB); |
| 414 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 415 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 416 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 417 | |
| 418 | registry.GetFunctor(packetC.GetPacketId(), version)->operator()(packetC); |
| 419 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 420 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 421 | BOOST_CHECK(testFunctorC.GetCount() == 1); |
| 422 | |
| 423 | // Re-register an existing key with a new function |
| 424 | registry.RegisterFunctor(&testFunctorC, testFunctorA.GetPacketId(), version); |
| 425 | registry.GetFunctor(packetA.GetPacketId(), version)->operator()(packetC); |
| 426 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 427 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 428 | BOOST_CHECK(testFunctorC.GetCount() == 2); |
| 429 | |
| 430 | // Check that non-existent key returns nullptr for its functor |
| 431 | BOOST_CHECK_THROW(registry.GetFunctor(0, 0), armnn::Exception); |
| 432 | } |
| 433 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 434 | BOOST_AUTO_TEST_CASE(CheckPacketVersionResolver) |
| 435 | { |
| 436 | // Set up random number generator for generating packetId values |
| 437 | std::random_device device; |
| 438 | std::mt19937 generator(device()); |
| 439 | std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(), |
| 440 | std::numeric_limits<uint32_t>::max()); |
| 441 | |
| 442 | // NOTE: Expected version is always 1.0.0, regardless of packetId |
| 443 | const Version expectedVersion(1, 0, 0); |
| 444 | |
| 445 | PacketVersionResolver packetVersionResolver; |
| 446 | |
| 447 | constexpr unsigned int numTests = 10u; |
| 448 | |
| 449 | for (unsigned int i = 0u; i < numTests; ++i) |
| 450 | { |
| 451 | const uint32_t packetId = distribution(generator); |
| 452 | Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(packetId); |
| 453 | |
| 454 | BOOST_TEST(resolvedVersion == expectedVersion); |
| 455 | } |
| 456 | } |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 457 | void ProfilingCurrentStateThreadImpl(ProfilingStateMachine& states) |
| 458 | { |
| 459 | ProfilingState newState = ProfilingState::NotConnected; |
| 460 | states.GetCurrentState(); |
| 461 | states.TransitionToState(newState); |
| 462 | } |
| 463 | |
| 464 | BOOST_AUTO_TEST_CASE(CheckProfilingStateMachine) |
| 465 | { |
| 466 | ProfilingStateMachine profilingState1(ProfilingState::Uninitialised); |
| 467 | profilingState1.TransitionToState(ProfilingState::Uninitialised); |
| 468 | BOOST_CHECK(profilingState1.GetCurrentState() == ProfilingState::Uninitialised); |
| 469 | |
| 470 | ProfilingStateMachine profilingState2(ProfilingState::Uninitialised); |
| 471 | profilingState2.TransitionToState(ProfilingState::NotConnected); |
| 472 | BOOST_CHECK(profilingState2.GetCurrentState() == ProfilingState::NotConnected); |
| 473 | |
| 474 | ProfilingStateMachine profilingState3(ProfilingState::NotConnected); |
| 475 | profilingState3.TransitionToState(ProfilingState::NotConnected); |
| 476 | BOOST_CHECK(profilingState3.GetCurrentState() == ProfilingState::NotConnected); |
| 477 | |
| 478 | ProfilingStateMachine profilingState4(ProfilingState::NotConnected); |
| 479 | profilingState4.TransitionToState(ProfilingState::WaitingForAck); |
| 480 | BOOST_CHECK(profilingState4.GetCurrentState() == ProfilingState::WaitingForAck); |
| 481 | |
| 482 | ProfilingStateMachine profilingState5(ProfilingState::WaitingForAck); |
| 483 | profilingState5.TransitionToState(ProfilingState::WaitingForAck); |
| 484 | BOOST_CHECK(profilingState5.GetCurrentState() == ProfilingState::WaitingForAck); |
| 485 | |
| 486 | ProfilingStateMachine profilingState6(ProfilingState::WaitingForAck); |
| 487 | profilingState6.TransitionToState(ProfilingState::Active); |
| 488 | BOOST_CHECK(profilingState6.GetCurrentState() == ProfilingState::Active); |
| 489 | |
| 490 | ProfilingStateMachine profilingState7(ProfilingState::Active); |
| 491 | profilingState7.TransitionToState(ProfilingState::NotConnected); |
| 492 | BOOST_CHECK(profilingState7.GetCurrentState() == ProfilingState::NotConnected); |
| 493 | |
| 494 | ProfilingStateMachine profilingState8(ProfilingState::Active); |
| 495 | profilingState8.TransitionToState(ProfilingState::Active); |
| 496 | BOOST_CHECK(profilingState8.GetCurrentState() == ProfilingState::Active); |
| 497 | |
| 498 | ProfilingStateMachine profilingState9(ProfilingState::Uninitialised); |
| 499 | BOOST_CHECK_THROW(profilingState9.TransitionToState(ProfilingState::WaitingForAck), |
| 500 | armnn::Exception); |
| 501 | |
| 502 | ProfilingStateMachine profilingState10(ProfilingState::Uninitialised); |
| 503 | BOOST_CHECK_THROW(profilingState10.TransitionToState(ProfilingState::Active), |
| 504 | armnn::Exception); |
| 505 | |
| 506 | ProfilingStateMachine profilingState11(ProfilingState::NotConnected); |
| 507 | BOOST_CHECK_THROW(profilingState11.TransitionToState(ProfilingState::Uninitialised), |
| 508 | armnn::Exception); |
| 509 | |
| 510 | ProfilingStateMachine profilingState12(ProfilingState::NotConnected); |
| 511 | BOOST_CHECK_THROW(profilingState12.TransitionToState(ProfilingState::Active), |
| 512 | armnn::Exception); |
| 513 | |
| 514 | ProfilingStateMachine profilingState13(ProfilingState::WaitingForAck); |
| 515 | BOOST_CHECK_THROW(profilingState13.TransitionToState(ProfilingState::Uninitialised), |
| 516 | armnn::Exception); |
| 517 | |
| 518 | ProfilingStateMachine profilingState14(ProfilingState::WaitingForAck); |
| 519 | BOOST_CHECK_THROW(profilingState14.TransitionToState(ProfilingState::NotConnected), |
| 520 | armnn::Exception); |
| 521 | |
| 522 | ProfilingStateMachine profilingState15(ProfilingState::Active); |
| 523 | BOOST_CHECK_THROW(profilingState15.TransitionToState(ProfilingState::Uninitialised), |
| 524 | armnn::Exception); |
| 525 | |
| 526 | ProfilingStateMachine profilingState16(armnn::profiling::ProfilingState::Active); |
| 527 | BOOST_CHECK_THROW(profilingState16.TransitionToState(ProfilingState::WaitingForAck), |
| 528 | armnn::Exception); |
| 529 | |
| 530 | ProfilingStateMachine profilingState17(ProfilingState::Uninitialised); |
| 531 | |
| 532 | std::thread thread1 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17)); |
| 533 | std::thread thread2 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17)); |
| 534 | std::thread thread3 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17)); |
| 535 | std::thread thread4 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17)); |
| 536 | std::thread thread5 (ProfilingCurrentStateThreadImpl,std::ref(profilingState17)); |
| 537 | |
| 538 | thread1.join(); |
| 539 | thread2.join(); |
| 540 | thread3.join(); |
| 541 | thread4.join(); |
| 542 | thread5.join(); |
| 543 | |
| 544 | BOOST_TEST((profilingState17.GetCurrentState() == ProfilingState::NotConnected)); |
| 545 | } |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 546 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 547 | void CaptureDataWriteThreadImpl(Holder& holder, uint32_t capturePeriod, const std::vector<uint16_t>& counterIds) |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 548 | { |
| 549 | holder.SetCaptureData(capturePeriod, counterIds); |
| 550 | } |
| 551 | |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 552 | void CaptureDataReadThreadImpl(const Holder& holder, CaptureData& captureData) |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 553 | { |
| 554 | captureData = holder.GetCaptureData(); |
| 555 | } |
| 556 | |
| 557 | BOOST_AUTO_TEST_CASE(CheckCaptureDataHolder) |
| 558 | { |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 559 | std::map<uint32_t, std::vector<uint16_t>> periodIdMap; |
| 560 | std::vector<uint16_t> counterIds; |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 561 | uint32_t numThreads = 10; |
| 562 | for (uint32_t i = 0; i < numThreads; ++i) |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 563 | { |
| 564 | counterIds.emplace_back(i); |
| 565 | periodIdMap.insert(std::make_pair(i, counterIds)); |
| 566 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 567 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 568 | // Verify the read and write threads set the holder correctly |
| 569 | // and retrieve the expected values |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 570 | Holder holder; |
| 571 | BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 0); |
| 572 | BOOST_CHECK(((holder.GetCaptureData()).GetCounterIds()).empty()); |
| 573 | |
| 574 | // Check Holder functions |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 575 | std::thread thread1(CaptureDataWriteThreadImpl, std::ref(holder), 2, std::ref(periodIdMap[2])); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 576 | thread1.join(); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 577 | BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 2); |
| 578 | BOOST_CHECK((holder.GetCaptureData()).GetCounterIds() == periodIdMap[2]); |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 579 | // NOTE: now that we have some initial values in the holder we don't have to worry |
| 580 | // in the multi-threaded section below about a read thread accessing the holder |
| 581 | // before any write thread has gotten to it so we read period = 0, counterIds empty |
| 582 | // instead of period = 0, counterIds = {0} as will the case when write thread 0 |
| 583 | // has executed. |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 584 | |
| 585 | CaptureData captureData; |
| 586 | std::thread thread2(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData)); |
| 587 | thread2.join(); |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 588 | BOOST_CHECK(captureData.GetCapturePeriod() == 2); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 589 | BOOST_CHECK(captureData.GetCounterIds() == periodIdMap[2]); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 590 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 591 | std::map<uint32_t, CaptureData> captureDataIdMap; |
| 592 | for (uint32_t i = 0; i < numThreads; ++i) |
| 593 | { |
| 594 | CaptureData perThreadCaptureData; |
| 595 | captureDataIdMap.insert(std::make_pair(i, perThreadCaptureData)); |
| 596 | } |
| 597 | |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 598 | std::vector<std::thread> threadsVect; |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 599 | std::vector<std::thread> readThreadsVect; |
| 600 | for (uint32_t i = 0; i < numThreads; ++i) |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 601 | { |
| 602 | threadsVect.emplace_back(std::thread(CaptureDataWriteThreadImpl, |
| 603 | std::ref(holder), |
| 604 | i, |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 605 | std::ref(periodIdMap[i]))); |
Francis Murtagh | 0696569 | 2019-09-05 16:29:01 +0100 | [diff] [blame] | 606 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 607 | // Verify that the CaptureData goes into the thread in a virgin state |
| 608 | BOOST_CHECK(captureDataIdMap.at(i).GetCapturePeriod() == 0); |
| 609 | BOOST_CHECK(captureDataIdMap.at(i).GetCounterIds().empty()); |
| 610 | readThreadsVect.emplace_back(std::thread(CaptureDataReadThreadImpl, |
| 611 | std::ref(holder), |
| 612 | std::ref(captureDataIdMap.at(i)))); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 613 | } |
| 614 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 615 | for (uint32_t i = 0; i < numThreads; ++i) |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 616 | { |
| 617 | threadsVect[i].join(); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 618 | readThreadsVect[i].join(); |
| 619 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 620 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 621 | // Look at the CaptureData that each read thread has filled |
| 622 | // the capture period it read should match the counter ids entry |
| 623 | for (uint32_t i = 0; i < numThreads; ++i) |
| 624 | { |
| 625 | CaptureData perThreadCaptureData = captureDataIdMap.at(i); |
| 626 | BOOST_CHECK(perThreadCaptureData.GetCounterIds() == periodIdMap.at(perThreadCaptureData.GetCapturePeriod())); |
| 627 | } |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 628 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 629 | |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 630 | BOOST_AUTO_TEST_CASE(CaptureDataMethods) |
| 631 | { |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 632 | // Check CaptureData setter and getter functions |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 633 | std::vector<uint16_t> counterIds = {42, 29, 13}; |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 634 | CaptureData captureData; |
| 635 | BOOST_CHECK(captureData.GetCapturePeriod() == 0); |
| 636 | BOOST_CHECK((captureData.GetCounterIds()).empty()); |
| 637 | captureData.SetCapturePeriod(150); |
| 638 | captureData.SetCounterIds(counterIds); |
| 639 | BOOST_CHECK(captureData.GetCapturePeriod() == 150); |
| 640 | BOOST_CHECK(captureData.GetCounterIds() == counterIds); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 641 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 642 | // Check assignment operator |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 643 | CaptureData secondCaptureData; |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 644 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 645 | secondCaptureData = captureData; |
| 646 | BOOST_CHECK(secondCaptureData.GetCapturePeriod() == 150); |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 647 | BOOST_CHECK(secondCaptureData.GetCounterIds() == counterIds); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 648 | |
| 649 | // Check copy constructor |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 650 | CaptureData copyConstructedCaptureData(captureData); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 651 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 652 | BOOST_CHECK(copyConstructedCaptureData.GetCapturePeriod() == 150); |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 653 | BOOST_CHECK(copyConstructedCaptureData.GetCounterIds() == counterIds); |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 654 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 655 | |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 656 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisabled) |
| 657 | { |
| 658 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 659 | ProfilingService service(options); |
| 660 | BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised); |
| 661 | service.Run(); |
| 662 | BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised); |
| 663 | } |
| 664 | |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 665 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabled) |
| 666 | { |
| 667 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 668 | options.m_EnableProfiling = true; |
| 669 | ProfilingService service(options); |
| 670 | BOOST_CHECK(service.GetCurrentState() == ProfilingState::NotConnected); |
| 671 | service.Run(); |
| 672 | BOOST_CHECK(service.GetCurrentState() == ProfilingState::WaitingForAck); |
| 673 | } |
| 674 | |
| 675 | |
| 676 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabledRuntime) |
| 677 | { |
| 678 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 679 | ProfilingService service(options); |
| 680 | BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised); |
| 681 | service.Run(); |
| 682 | BOOST_CHECK(service.GetCurrentState() == ProfilingState::Uninitialised); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 683 | options.m_EnableProfiling = true; |
| 684 | service.ResetExternalProfilingOptions(options); |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 685 | BOOST_CHECK(service.GetCurrentState() == ProfilingState::NotConnected); |
| 686 | service.Run(); |
| 687 | BOOST_CHECK(service.GetCurrentState() == ProfilingState::WaitingForAck); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 688 | } |
| 689 | |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 690 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceCounterDirectory) |
| 691 | { |
| 692 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 693 | ProfilingService service(options); |
| 694 | |
| 695 | const ICounterDirectory& counterDirectory0 = service.GetCounterDirectory(); |
| 696 | BOOST_CHECK(counterDirectory0.GetCounterCount() == 0); |
| 697 | |
| 698 | options.m_EnableProfiling = true; |
| 699 | service.ResetExternalProfilingOptions(options); |
| 700 | |
| 701 | const ICounterDirectory& counterDirectory1 = service.GetCounterDirectory(); |
| 702 | BOOST_CHECK(counterDirectory1.GetCounterCount() != 0); |
| 703 | } |
| 704 | |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame^] | 705 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceCounterValues) |
| 706 | { |
| 707 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 708 | options.m_EnableProfiling = true; |
| 709 | ProfilingService profilingService(options); |
| 710 | |
| 711 | ProfilingService* profilingServicePtr = &profilingService; |
| 712 | std::vector<std::thread> writers; |
| 713 | |
| 714 | for(int i = 0; i < 100 ; ++i) |
| 715 | { |
| 716 | // Increment and decrement counter 0 |
| 717 | writers.push_back(std::thread(&ProfilingService::IncrementCounterValue, profilingServicePtr, 0)); |
| 718 | writers.push_back(std::thread(&ProfilingService::DecrementCounterValue, profilingServicePtr, 0)); |
| 719 | // Add 10 to counter 0 and subtract 5 from counter 0 |
| 720 | writers.push_back(std::thread(&ProfilingService::AddCounterValue, profilingServicePtr, 0, 10)); |
| 721 | writers.push_back(std::thread(&ProfilingService::SubtractCounterValue, profilingServicePtr, 0, 5)); |
| 722 | } |
| 723 | |
| 724 | std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join)); |
| 725 | |
| 726 | uint32_t counterValue; |
| 727 | profilingService.GetCounterValue(0, counterValue); |
| 728 | BOOST_CHECK(counterValue == 500); |
| 729 | |
| 730 | profilingService.SetCounterValue(0, 0); |
| 731 | profilingService.GetCounterValue(0, counterValue); |
| 732 | BOOST_CHECK(counterValue == 0); |
| 733 | |
| 734 | BOOST_CHECK_THROW(profilingService.SetCounterValue(profilingService.GetCounterCount(), 1), armnn::Exception); |
| 735 | } |
| 736 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 737 | BOOST_AUTO_TEST_CASE(CheckProfilingObjectUids) |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 738 | { |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 739 | uint16_t uid = 0; |
| 740 | BOOST_CHECK_NO_THROW(uid = GetNextUid()); |
| 741 | BOOST_CHECK(uid >= 1); |
| 742 | |
| 743 | uint16_t nextUid = 0; |
| 744 | BOOST_CHECK_NO_THROW(nextUid = GetNextUid()); |
| 745 | BOOST_CHECK(nextUid > uid); |
| 746 | |
| 747 | std::vector<uint16_t> counterUids; |
| 748 | BOOST_CHECK_NO_THROW(counterUids = GetNextCounterUids(0)); |
| 749 | BOOST_CHECK(counterUids.size() == 1); |
| 750 | BOOST_CHECK(counterUids[0] >= 0); |
| 751 | |
| 752 | std::vector<uint16_t> nextCounterUids; |
| 753 | BOOST_CHECK_NO_THROW(nextCounterUids = GetNextCounterUids(1)); |
| 754 | BOOST_CHECK(nextCounterUids.size() == 1); |
| 755 | BOOST_CHECK(nextCounterUids[0] > counterUids[0]); |
| 756 | |
| 757 | std::vector<uint16_t> counterUidsMultiCore; |
| 758 | uint16_t numberOfCores = 13; |
| 759 | BOOST_CHECK_NO_THROW(counterUidsMultiCore = GetNextCounterUids(numberOfCores)); |
| 760 | BOOST_CHECK(counterUidsMultiCore.size() == numberOfCores); |
| 761 | BOOST_CHECK(counterUidsMultiCore.front() >= nextCounterUids[0]); |
| 762 | for (size_t i = 1; i < numberOfCores; i ++) |
| 763 | { |
| 764 | BOOST_CHECK(counterUidsMultiCore[i] == counterUidsMultiCore[i - 1] + 1); |
| 765 | } |
| 766 | BOOST_CHECK(counterUidsMultiCore.back() == counterUidsMultiCore.front() + numberOfCores - 1); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 767 | } |
| 768 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 769 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCategory) |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 770 | { |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 771 | CounterDirectory counterDirectory; |
| 772 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 773 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
| 774 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
| 775 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 776 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 777 | // Register a category with an invalid name |
| 778 | const Category* noCategory = nullptr; |
| 779 | BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory(""), armnn::InvalidArgumentException); |
| 780 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 781 | BOOST_CHECK(!noCategory); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 782 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 783 | // Register a category with an invalid name |
| 784 | BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory("invalid category"), |
| 785 | armnn::InvalidArgumentException); |
| 786 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 787 | BOOST_CHECK(!noCategory); |
| 788 | |
| 789 | // Register a new category |
| 790 | const std::string categoryName = "some_category"; |
| 791 | const Category* category = nullptr; |
| 792 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 793 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 794 | BOOST_CHECK(category); |
| 795 | BOOST_CHECK(category->m_Name == categoryName); |
| 796 | BOOST_CHECK(category->m_Counters.empty()); |
| 797 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 798 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 799 | |
| 800 | // Get the registered category |
| 801 | const Category* registeredCategory = counterDirectory.GetCategory(categoryName); |
| 802 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 803 | BOOST_CHECK(registeredCategory); |
| 804 | BOOST_CHECK(registeredCategory == category); |
| 805 | |
| 806 | // Try to get a category not registered |
| 807 | const Category* notRegisteredCategory = counterDirectory.GetCategory("not_registered_category"); |
| 808 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 809 | BOOST_CHECK(!notRegisteredCategory); |
| 810 | |
| 811 | // Register a category already registered |
| 812 | const Category* anotherCategory = nullptr; |
| 813 | BOOST_CHECK_THROW(anotherCategory = counterDirectory.RegisterCategory(categoryName), |
| 814 | armnn::InvalidArgumentException); |
| 815 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 816 | BOOST_CHECK(!anotherCategory); |
| 817 | |
| 818 | // Register a device for testing |
| 819 | const std::string deviceName = "some_device"; |
| 820 | const Device* device = nullptr; |
| 821 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName)); |
| 822 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 823 | BOOST_CHECK(device); |
| 824 | BOOST_CHECK(device->m_Uid >= 1); |
| 825 | BOOST_CHECK(device->m_Name == deviceName); |
| 826 | BOOST_CHECK(device->m_Cores == 0); |
| 827 | |
| 828 | // Register a new category not associated to any device |
| 829 | const std::string categoryWoDeviceName = "some_category_without_device"; |
| 830 | const Category* categoryWoDevice = nullptr; |
| 831 | BOOST_CHECK_NO_THROW(categoryWoDevice = counterDirectory.RegisterCategory(categoryWoDeviceName, 0)); |
| 832 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 833 | BOOST_CHECK(categoryWoDevice); |
| 834 | BOOST_CHECK(categoryWoDevice->m_Name == categoryWoDeviceName); |
| 835 | BOOST_CHECK(categoryWoDevice->m_Counters.empty()); |
| 836 | BOOST_CHECK(categoryWoDevice->m_DeviceUid == 0); |
| 837 | BOOST_CHECK(categoryWoDevice->m_CounterSetUid == 0); |
| 838 | |
| 839 | // Register a new category associated to an invalid device |
| 840 | const std::string categoryWInvalidDeviceName = "some_category_with_invalid_device"; |
| 841 | |
| 842 | ARMNN_NO_CONVERSION_WARN_BEGIN |
| 843 | uint16_t invalidDeviceUid = device->m_Uid + 10; |
| 844 | ARMNN_NO_CONVERSION_WARN_END |
| 845 | |
| 846 | const Category* categoryWInvalidDevice = nullptr; |
| 847 | BOOST_CHECK_THROW(categoryWInvalidDevice |
| 848 | = counterDirectory.RegisterCategory(categoryWInvalidDeviceName, |
| 849 | invalidDeviceUid), |
| 850 | armnn::InvalidArgumentException); |
| 851 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 852 | BOOST_CHECK(!categoryWInvalidDevice); |
| 853 | |
| 854 | // Register a new category associated to a valid device |
| 855 | const std::string categoryWValidDeviceName = "some_category_with_valid_device"; |
| 856 | const Category* categoryWValidDevice = nullptr; |
| 857 | BOOST_CHECK_NO_THROW(categoryWValidDevice |
| 858 | = counterDirectory.RegisterCategory(categoryWValidDeviceName, |
| 859 | device->m_Uid)); |
| 860 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 3); |
| 861 | BOOST_CHECK(categoryWValidDevice); |
| 862 | BOOST_CHECK(categoryWValidDevice != category); |
| 863 | BOOST_CHECK(categoryWValidDevice->m_Name == categoryWValidDeviceName); |
| 864 | BOOST_CHECK(categoryWValidDevice->m_DeviceUid == device->m_Uid); |
| 865 | BOOST_CHECK(categoryWValidDevice->m_CounterSetUid == 0); |
| 866 | |
| 867 | // Register a counter set for testing |
| 868 | const std::string counterSetName = "some_counter_set"; |
| 869 | const CounterSet* counterSet = nullptr; |
| 870 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 871 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 872 | BOOST_CHECK(counterSet); |
| 873 | BOOST_CHECK(counterSet->m_Uid >= 1); |
| 874 | BOOST_CHECK(counterSet->m_Name == counterSetName); |
| 875 | BOOST_CHECK(counterSet->m_Count == 0); |
| 876 | |
| 877 | // Register a new category not associated to any counter set |
| 878 | const std::string categoryWoCounterSetName = "some_category_without_counter_set"; |
| 879 | const Category* categoryWoCounterSet = nullptr; |
| 880 | BOOST_CHECK_NO_THROW(categoryWoCounterSet |
| 881 | = counterDirectory.RegisterCategory(categoryWoCounterSetName, |
| 882 | armnn::EmptyOptional(), |
| 883 | 0)); |
| 884 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 4); |
| 885 | BOOST_CHECK(categoryWoCounterSet); |
| 886 | BOOST_CHECK(categoryWoCounterSet->m_Name == categoryWoCounterSetName); |
| 887 | BOOST_CHECK(categoryWoCounterSet->m_DeviceUid == 0); |
| 888 | BOOST_CHECK(categoryWoCounterSet->m_CounterSetUid == 0); |
| 889 | |
| 890 | // Register a new category associated to an invalid counter set |
| 891 | const std::string categoryWInvalidCounterSetName = "some_category_with_invalid_counter_set"; |
| 892 | |
| 893 | ARMNN_NO_CONVERSION_WARN_BEGIN |
| 894 | uint16_t invalidCunterSetUid = counterSet->m_Uid + 10; |
| 895 | ARMNN_NO_CONVERSION_WARN_END |
| 896 | |
| 897 | const Category* categoryWInvalidCounterSet = nullptr; |
| 898 | BOOST_CHECK_THROW(categoryWInvalidCounterSet |
| 899 | = counterDirectory.RegisterCategory(categoryWInvalidCounterSetName, |
| 900 | armnn::EmptyOptional(), |
| 901 | invalidCunterSetUid), |
| 902 | armnn::InvalidArgumentException); |
| 903 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 4); |
| 904 | BOOST_CHECK(!categoryWInvalidCounterSet); |
| 905 | |
| 906 | // Register a new category associated to a valid counter set |
| 907 | const std::string categoryWValidCounterSetName = "some_category_with_valid_counter_set"; |
| 908 | const Category* categoryWValidCounterSet = nullptr; |
| 909 | BOOST_CHECK_NO_THROW(categoryWValidCounterSet |
| 910 | = counterDirectory.RegisterCategory(categoryWValidCounterSetName, |
| 911 | armnn::EmptyOptional(), |
| 912 | counterSet->m_Uid)); |
| 913 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 5); |
| 914 | BOOST_CHECK(categoryWValidCounterSet); |
| 915 | BOOST_CHECK(categoryWValidCounterSet != category); |
| 916 | BOOST_CHECK(categoryWValidCounterSet->m_Name == categoryWValidCounterSetName); |
| 917 | BOOST_CHECK(categoryWValidCounterSet->m_DeviceUid == 0); |
| 918 | BOOST_CHECK(categoryWValidCounterSet->m_CounterSetUid == counterSet->m_Uid); |
| 919 | |
| 920 | // Register a new category associated to a valid device and counter set |
| 921 | const std::string categoryWValidDeviceAndValidCounterSetName = "some_category_with_valid_device_and_counter_set"; |
| 922 | const Category* categoryWValidDeviceAndValidCounterSet = nullptr; |
| 923 | BOOST_CHECK_NO_THROW(categoryWValidDeviceAndValidCounterSet |
| 924 | = counterDirectory.RegisterCategory(categoryWValidDeviceAndValidCounterSetName, |
| 925 | device->m_Uid, |
| 926 | counterSet->m_Uid)); |
| 927 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 6); |
| 928 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet); |
| 929 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet != category); |
| 930 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_Name == categoryWValidDeviceAndValidCounterSetName); |
| 931 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_DeviceUid == device->m_Uid); |
| 932 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_CounterSetUid == counterSet->m_Uid); |
| 933 | } |
| 934 | |
| 935 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterDevice) |
| 936 | { |
| 937 | CounterDirectory counterDirectory; |
| 938 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 939 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
| 940 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
| 941 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 942 | |
| 943 | // Register a device with an invalid name |
| 944 | const Device* noDevice = nullptr; |
| 945 | BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice(""), armnn::InvalidArgumentException); |
| 946 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
| 947 | BOOST_CHECK(!noDevice); |
| 948 | |
| 949 | // Register a device with an invalid name |
| 950 | BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice("inv@lid nam€"), armnn::InvalidArgumentException); |
| 951 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
| 952 | BOOST_CHECK(!noDevice); |
| 953 | |
| 954 | // Register a new device with no cores or parent category |
| 955 | const std::string deviceName = "some_device"; |
| 956 | const Device* device = nullptr; |
| 957 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName)); |
| 958 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 959 | BOOST_CHECK(device); |
| 960 | BOOST_CHECK(device->m_Name == deviceName); |
| 961 | BOOST_CHECK(device->m_Uid >= 1); |
| 962 | BOOST_CHECK(device->m_Cores == 0); |
| 963 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 964 | // Try getting an unregistered device |
| 965 | const Device* unregisteredDevice = counterDirectory.GetDevice(9999); |
| 966 | BOOST_CHECK(!unregisteredDevice); |
| 967 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 968 | // Get the registered device |
| 969 | const Device* registeredDevice = counterDirectory.GetDevice(device->m_Uid); |
| 970 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 971 | BOOST_CHECK(registeredDevice); |
| 972 | BOOST_CHECK(registeredDevice == device); |
| 973 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 974 | // Register a device with the name of a device already registered |
| 975 | const Device* deviceSameName = nullptr; |
| 976 | BOOST_CHECK_THROW(deviceSameName = counterDirectory.RegisterDevice(deviceName), armnn::InvalidArgumentException); |
| 977 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 978 | BOOST_CHECK(!deviceSameName); |
| 979 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 980 | // Register a new device with cores and no parent category |
| 981 | const std::string deviceWCoresName = "some_device_with_cores"; |
| 982 | const Device* deviceWCores = nullptr; |
| 983 | BOOST_CHECK_NO_THROW(deviceWCores = counterDirectory.RegisterDevice(deviceWCoresName, 2)); |
| 984 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 985 | BOOST_CHECK(deviceWCores); |
| 986 | BOOST_CHECK(deviceWCores->m_Name == deviceWCoresName); |
| 987 | BOOST_CHECK(deviceWCores->m_Uid >= 1); |
| 988 | BOOST_CHECK(deviceWCores->m_Uid > device->m_Uid); |
| 989 | BOOST_CHECK(deviceWCores->m_Cores == 2); |
| 990 | |
| 991 | // Get the registered device |
| 992 | const Device* registeredDeviceWCores = counterDirectory.GetDevice(deviceWCores->m_Uid); |
| 993 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 994 | BOOST_CHECK(registeredDeviceWCores); |
| 995 | BOOST_CHECK(registeredDeviceWCores == deviceWCores); |
| 996 | BOOST_CHECK(registeredDeviceWCores != device); |
| 997 | |
| 998 | // Register a new device with cores and invalid parent category |
| 999 | const std::string deviceWCoresWInvalidParentCategoryName = "some_device_with_cores_with_invalid_parent_category"; |
| 1000 | const Device* deviceWCoresWInvalidParentCategory = nullptr; |
| 1001 | BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory |
| 1002 | = counterDirectory.RegisterDevice(deviceWCoresWInvalidParentCategoryName, |
| 1003 | 3, |
| 1004 | std::string("")), |
| 1005 | armnn::InvalidArgumentException); |
| 1006 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 1007 | BOOST_CHECK(!deviceWCoresWInvalidParentCategory); |
| 1008 | |
| 1009 | // Register a new device with cores and invalid parent category |
| 1010 | const std::string deviceWCoresWInvalidParentCategoryName2 = "some_device_with_cores_with_invalid_parent_category2"; |
| 1011 | const Device* deviceWCoresWInvalidParentCategory2 = nullptr; |
| 1012 | BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory2 |
| 1013 | = counterDirectory.RegisterDevice(deviceWCoresWInvalidParentCategoryName2, |
| 1014 | 3, |
| 1015 | std::string("invalid_parent_category")), |
| 1016 | armnn::InvalidArgumentException); |
| 1017 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 1018 | BOOST_CHECK(!deviceWCoresWInvalidParentCategory2); |
| 1019 | |
| 1020 | // Register a category for testing |
| 1021 | const std::string categoryName = "some_category"; |
| 1022 | const Category* category = nullptr; |
| 1023 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 1024 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1025 | BOOST_CHECK(category); |
| 1026 | BOOST_CHECK(category->m_Name == categoryName); |
| 1027 | BOOST_CHECK(category->m_Counters.empty()); |
| 1028 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 1029 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 1030 | |
| 1031 | // Register a new device with cores and valid parent category |
| 1032 | const std::string deviceWCoresWValidParentCategoryName = "some_device_with_cores_with_valid_parent_category"; |
| 1033 | const Device* deviceWCoresWValidParentCategory = nullptr; |
| 1034 | BOOST_CHECK_NO_THROW(deviceWCoresWValidParentCategory |
| 1035 | = counterDirectory.RegisterDevice(deviceWCoresWValidParentCategoryName, |
| 1036 | 4, |
| 1037 | categoryName)); |
| 1038 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 3); |
| 1039 | BOOST_CHECK(deviceWCoresWValidParentCategory); |
| 1040 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Name == deviceWCoresWValidParentCategoryName); |
| 1041 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid >= 1); |
| 1042 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > device->m_Uid); |
| 1043 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > deviceWCores->m_Uid); |
| 1044 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Cores == 4); |
| 1045 | BOOST_CHECK(category->m_DeviceUid == deviceWCoresWValidParentCategory->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1046 | |
| 1047 | // Register a device associated to a category already associated to a different device |
| 1048 | const std::string deviceSameCategoryName = "some_device_with_invalid_parent_category"; |
| 1049 | const Device* deviceSameCategory = nullptr; |
| 1050 | BOOST_CHECK_THROW(deviceSameCategory = counterDirectory.RegisterDevice(deviceSameCategoryName, 0, categoryName), |
| 1051 | armnn::InvalidArgumentException); |
| 1052 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 3); |
| 1053 | BOOST_CHECK(!deviceSameCategory); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCounterSet) |
| 1057 | { |
| 1058 | CounterDirectory counterDirectory; |
| 1059 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 1060 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
| 1061 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
| 1062 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1063 | |
| 1064 | // Register a counter set with an invalid name |
| 1065 | const CounterSet* noCounterSet = nullptr; |
| 1066 | BOOST_CHECK_THROW(noCounterSet = counterDirectory.RegisterCounterSet(""), armnn::InvalidArgumentException); |
| 1067 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
| 1068 | BOOST_CHECK(!noCounterSet); |
| 1069 | |
| 1070 | // Register a counter set with an invalid name |
| 1071 | BOOST_CHECK_THROW(noCounterSet = counterDirectory.RegisterCounterSet("invalid name"), |
| 1072 | armnn::InvalidArgumentException); |
| 1073 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
| 1074 | BOOST_CHECK(!noCounterSet); |
| 1075 | |
| 1076 | // Register a new counter set with no count or parent category |
| 1077 | const std::string counterSetName = "some_counter_set"; |
| 1078 | const CounterSet* counterSet = nullptr; |
| 1079 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1080 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1081 | BOOST_CHECK(counterSet); |
| 1082 | BOOST_CHECK(counterSet->m_Name == counterSetName); |
| 1083 | BOOST_CHECK(counterSet->m_Uid >= 1); |
| 1084 | BOOST_CHECK(counterSet->m_Count == 0); |
| 1085 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1086 | // Try getting an unregistered counter set |
| 1087 | const CounterSet* unregisteredCounterSet = counterDirectory.GetCounterSet(9999); |
| 1088 | BOOST_CHECK(!unregisteredCounterSet); |
| 1089 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1090 | // Get the registered counter set |
| 1091 | const CounterSet* registeredCounterSet = counterDirectory.GetCounterSet(counterSet->m_Uid); |
| 1092 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1093 | BOOST_CHECK(registeredCounterSet); |
| 1094 | BOOST_CHECK(registeredCounterSet == counterSet); |
| 1095 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1096 | // Register a counter set with the name of a counter set already registered |
| 1097 | const CounterSet* counterSetSameName = nullptr; |
| 1098 | BOOST_CHECK_THROW(counterSetSameName = counterDirectory.RegisterCounterSet(counterSetName), |
| 1099 | armnn::InvalidArgumentException); |
| 1100 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1101 | BOOST_CHECK(!counterSetSameName); |
| 1102 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1103 | // Register a new counter set with count and no parent category |
| 1104 | const std::string counterSetWCountName = "some_counter_set_with_count"; |
| 1105 | const CounterSet* counterSetWCount = nullptr; |
| 1106 | BOOST_CHECK_NO_THROW(counterSetWCount = counterDirectory.RegisterCounterSet(counterSetWCountName, 37)); |
| 1107 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1108 | BOOST_CHECK(counterSetWCount); |
| 1109 | BOOST_CHECK(counterSetWCount->m_Name == counterSetWCountName); |
| 1110 | BOOST_CHECK(counterSetWCount->m_Uid >= 1); |
| 1111 | BOOST_CHECK(counterSetWCount->m_Uid > counterSet->m_Uid); |
| 1112 | BOOST_CHECK(counterSetWCount->m_Count == 37); |
| 1113 | |
| 1114 | // Get the registered counter set |
| 1115 | const CounterSet* registeredCounterSetWCount = counterDirectory.GetCounterSet(counterSetWCount->m_Uid); |
| 1116 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1117 | BOOST_CHECK(registeredCounterSetWCount); |
| 1118 | BOOST_CHECK(registeredCounterSetWCount == counterSetWCount); |
| 1119 | BOOST_CHECK(registeredCounterSetWCount != counterSet); |
| 1120 | |
| 1121 | // Register a new counter set with count and invalid parent category |
| 1122 | const std::string counterSetWCountWInvalidParentCategoryName = "some_counter_set_with_count_" |
| 1123 | "with_invalid_parent_category"; |
| 1124 | const CounterSet* counterSetWCountWInvalidParentCategory = nullptr; |
| 1125 | BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory |
| 1126 | = counterDirectory.RegisterCounterSet(counterSetWCountWInvalidParentCategoryName, |
| 1127 | 42, |
| 1128 | std::string("")), |
| 1129 | armnn::InvalidArgumentException); |
| 1130 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1131 | BOOST_CHECK(!counterSetWCountWInvalidParentCategory); |
| 1132 | |
| 1133 | // Register a new counter set with count and invalid parent category |
| 1134 | const std::string counterSetWCountWInvalidParentCategoryName2 = "some_counter_set_with_count_" |
| 1135 | "with_invalid_parent_category2"; |
| 1136 | const CounterSet* counterSetWCountWInvalidParentCategory2 = nullptr; |
| 1137 | BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory2 |
| 1138 | = counterDirectory.RegisterCounterSet(counterSetWCountWInvalidParentCategoryName2, |
| 1139 | 42, |
| 1140 | std::string("invalid_parent_category")), |
| 1141 | armnn::InvalidArgumentException); |
| 1142 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1143 | BOOST_CHECK(!counterSetWCountWInvalidParentCategory2); |
| 1144 | |
| 1145 | // Register a category for testing |
| 1146 | const std::string categoryName = "some_category"; |
| 1147 | const Category* category = nullptr; |
| 1148 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 1149 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1150 | BOOST_CHECK(category); |
| 1151 | BOOST_CHECK(category->m_Name == categoryName); |
| 1152 | BOOST_CHECK(category->m_Counters.empty()); |
| 1153 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 1154 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 1155 | |
| 1156 | // Register a new counter set with count and valid parent category |
| 1157 | const std::string counterSetWCountWValidParentCategoryName = "some_counter_set_with_count_" |
| 1158 | "with_valid_parent_category"; |
| 1159 | const CounterSet* counterSetWCountWValidParentCategory = nullptr; |
| 1160 | BOOST_CHECK_NO_THROW(counterSetWCountWValidParentCategory |
| 1161 | = counterDirectory.RegisterCounterSet(counterSetWCountWValidParentCategoryName, |
| 1162 | 42, |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1163 | categoryName)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1164 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 3); |
| 1165 | BOOST_CHECK(counterSetWCountWValidParentCategory); |
| 1166 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Name == counterSetWCountWValidParentCategoryName); |
| 1167 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid >= 1); |
| 1168 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSet->m_Uid); |
| 1169 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSetWCount->m_Uid); |
| 1170 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Count == 42); |
| 1171 | BOOST_CHECK(category->m_CounterSetUid == counterSetWCountWValidParentCategory->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1172 | |
| 1173 | // Register a counter set associated to a category already associated to a different counter set |
| 1174 | const std::string counterSetSameCategoryName = "some_counter_set_with_invalid_parent_category"; |
| 1175 | const CounterSet* counterSetSameCategory = nullptr; |
| 1176 | BOOST_CHECK_THROW(counterSetSameCategory = counterDirectory.RegisterCounterSet(counterSetSameCategoryName, |
| 1177 | 0, |
| 1178 | categoryName), |
| 1179 | armnn::InvalidArgumentException); |
| 1180 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 3); |
| 1181 | BOOST_CHECK(!counterSetSameCategory); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCounter) |
| 1185 | { |
| 1186 | CounterDirectory counterDirectory; |
| 1187 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 1188 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
| 1189 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
| 1190 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1191 | |
| 1192 | // Register a counter with an invalid parent category name |
| 1193 | const Counter* noCounter = nullptr; |
| 1194 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("", |
| 1195 | 0, |
| 1196 | 1, |
| 1197 | 123.45f, |
| 1198 | "valid name", |
| 1199 | "valid description"), |
| 1200 | armnn::InvalidArgumentException); |
| 1201 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1202 | BOOST_CHECK(!noCounter); |
| 1203 | |
| 1204 | // Register a counter with an invalid parent category name |
| 1205 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("invalid parent category", |
| 1206 | 0, |
| 1207 | 1, |
| 1208 | 123.45f, |
| 1209 | "valid name", |
| 1210 | "valid description"), |
| 1211 | armnn::InvalidArgumentException); |
| 1212 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1213 | BOOST_CHECK(!noCounter); |
| 1214 | |
| 1215 | // Register a counter with an invalid class |
| 1216 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", |
| 1217 | 2, |
| 1218 | 1, |
| 1219 | 123.45f, |
| 1220 | "valid name", |
| 1221 | "valid description"), |
| 1222 | armnn::InvalidArgumentException); |
| 1223 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1224 | BOOST_CHECK(!noCounter); |
| 1225 | |
| 1226 | // Register a counter with an invalid interpolation |
| 1227 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", |
| 1228 | 0, |
| 1229 | 3, |
| 1230 | 123.45f, |
| 1231 | "valid name", |
| 1232 | "valid description"), |
| 1233 | armnn::InvalidArgumentException); |
| 1234 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1235 | BOOST_CHECK(!noCounter); |
| 1236 | |
| 1237 | // Register a counter with an invalid multiplier |
| 1238 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", |
| 1239 | 0, |
| 1240 | 1, |
| 1241 | .0f, |
| 1242 | "valid name", |
| 1243 | "valid description"), |
| 1244 | armnn::InvalidArgumentException); |
| 1245 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1246 | BOOST_CHECK(!noCounter); |
| 1247 | |
| 1248 | // Register a counter with an invalid name |
| 1249 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", |
| 1250 | 0, |
| 1251 | 1, |
| 1252 | 123.45f, |
| 1253 | "", |
| 1254 | "valid description"), |
| 1255 | armnn::InvalidArgumentException); |
| 1256 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1257 | BOOST_CHECK(!noCounter); |
| 1258 | |
| 1259 | // Register a counter with an invalid name |
| 1260 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", |
| 1261 | 0, |
| 1262 | 1, |
| 1263 | 123.45f, |
| 1264 | "invalid nam€", |
| 1265 | "valid description"), |
| 1266 | armnn::InvalidArgumentException); |
| 1267 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1268 | BOOST_CHECK(!noCounter); |
| 1269 | |
| 1270 | // Register a counter with an invalid description |
| 1271 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", |
| 1272 | 0, |
| 1273 | 1, |
| 1274 | 123.45f, |
| 1275 | "valid name", |
| 1276 | ""), |
| 1277 | armnn::InvalidArgumentException); |
| 1278 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1279 | BOOST_CHECK(!noCounter); |
| 1280 | |
| 1281 | // Register a counter with an invalid description |
| 1282 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", |
| 1283 | 0, |
| 1284 | 1, |
| 1285 | 123.45f, |
| 1286 | "valid name", |
| 1287 | "inv@lid description"), |
| 1288 | armnn::InvalidArgumentException); |
| 1289 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1290 | BOOST_CHECK(!noCounter); |
| 1291 | |
| 1292 | // Register a counter with an invalid unit2 |
| 1293 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", |
| 1294 | 0, |
| 1295 | 1, |
| 1296 | 123.45f, |
| 1297 | "valid name", |
| 1298 | "valid description", |
| 1299 | std::string("Mb/s2")), |
| 1300 | armnn::InvalidArgumentException); |
| 1301 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1302 | BOOST_CHECK(!noCounter); |
| 1303 | |
| 1304 | // Register a counter with a non-existing parent category name |
| 1305 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("invalid_parent_category", |
| 1306 | 0, |
| 1307 | 1, |
| 1308 | 123.45f, |
| 1309 | "valid name", |
| 1310 | "valid description"), |
| 1311 | armnn::InvalidArgumentException); |
| 1312 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1313 | BOOST_CHECK(!noCounter); |
| 1314 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1315 | // Try getting an unregistered counter |
| 1316 | const Counter* unregisteredCounter = counterDirectory.GetCounter(9999); |
| 1317 | BOOST_CHECK(!unregisteredCounter); |
| 1318 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1319 | // Register a category for testing |
| 1320 | const std::string categoryName = "some_category"; |
| 1321 | const Category* category = nullptr; |
| 1322 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 1323 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1324 | BOOST_CHECK(category); |
| 1325 | BOOST_CHECK(category->m_Name == categoryName); |
| 1326 | BOOST_CHECK(category->m_Counters.empty()); |
| 1327 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 1328 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 1329 | |
| 1330 | // Register a counter with a valid parent category name |
| 1331 | const Counter* counter = nullptr; |
| 1332 | BOOST_CHECK_NO_THROW(counter = counterDirectory.RegisterCounter(categoryName, |
| 1333 | 0, |
| 1334 | 1, |
| 1335 | 123.45f, |
| 1336 | "valid name", |
| 1337 | "valid description")); |
| 1338 | BOOST_CHECK(counterDirectory.GetCounterCount() == 1); |
| 1339 | BOOST_CHECK(counter); |
| 1340 | BOOST_CHECK(counter->m_Uid >= 0); |
| 1341 | BOOST_CHECK(counter->m_MaxCounterUid == counter->m_Uid); |
| 1342 | BOOST_CHECK(counter->m_Class == 0); |
| 1343 | BOOST_CHECK(counter->m_Interpolation == 1); |
| 1344 | BOOST_CHECK(counter->m_Multiplier == 123.45f); |
| 1345 | BOOST_CHECK(counter->m_Name == "valid name"); |
| 1346 | BOOST_CHECK(counter->m_Description == "valid description"); |
| 1347 | BOOST_CHECK(counter->m_Units == ""); |
| 1348 | BOOST_CHECK(counter->m_DeviceUid == 0); |
| 1349 | BOOST_CHECK(counter->m_CounterSetUid == 0); |
| 1350 | BOOST_CHECK(category->m_Counters.size() == 1); |
| 1351 | BOOST_CHECK(category->m_Counters.back() == counter->m_Uid); |
| 1352 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1353 | // Register a counter with a name of a counter already registered for the given parent category name |
| 1354 | const Counter* counterSameName = nullptr; |
| 1355 | BOOST_CHECK_THROW(counterSameName = counterDirectory.RegisterCounter(categoryName, |
| 1356 | 0, |
| 1357 | 0, |
| 1358 | 1.0f, |
| 1359 | "valid name", |
| 1360 | "valid description"), |
| 1361 | armnn::InvalidArgumentException); |
| 1362 | BOOST_CHECK(counterDirectory.GetCounterCount() == 1); |
| 1363 | BOOST_CHECK(!counterSameName); |
| 1364 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1365 | // Register a counter with a valid parent category name and units |
| 1366 | const Counter* counterWUnits = nullptr; |
| 1367 | BOOST_CHECK_NO_THROW(counterWUnits = counterDirectory.RegisterCounter(categoryName, |
| 1368 | 0, |
| 1369 | 1, |
| 1370 | 123.45f, |
| 1371 | "valid name 2", |
| 1372 | "valid description", |
| 1373 | std::string("Mnnsq2"))); // Units |
| 1374 | BOOST_CHECK(counterDirectory.GetCounterCount() == 2); |
| 1375 | BOOST_CHECK(counterWUnits); |
| 1376 | BOOST_CHECK(counterWUnits->m_Uid >= 0); |
| 1377 | BOOST_CHECK(counterWUnits->m_Uid > counter->m_Uid); |
| 1378 | BOOST_CHECK(counterWUnits->m_MaxCounterUid == counterWUnits->m_Uid); |
| 1379 | BOOST_CHECK(counterWUnits->m_Class == 0); |
| 1380 | BOOST_CHECK(counterWUnits->m_Interpolation == 1); |
| 1381 | BOOST_CHECK(counterWUnits->m_Multiplier == 123.45f); |
| 1382 | BOOST_CHECK(counterWUnits->m_Name == "valid name 2"); |
| 1383 | BOOST_CHECK(counterWUnits->m_Description == "valid description"); |
| 1384 | BOOST_CHECK(counterWUnits->m_Units == "Mnnsq2"); |
| 1385 | BOOST_CHECK(counterWUnits->m_DeviceUid == 0); |
| 1386 | BOOST_CHECK(counterWUnits->m_CounterSetUid == 0); |
| 1387 | BOOST_CHECK(category->m_Counters.size() == 2); |
| 1388 | BOOST_CHECK(category->m_Counters.back() == counterWUnits->m_Uid); |
| 1389 | |
| 1390 | // Register a counter with a valid parent category name and not associated with a device |
| 1391 | const Counter* counterWoDevice = nullptr; |
| 1392 | BOOST_CHECK_NO_THROW(counterWoDevice = counterDirectory.RegisterCounter(categoryName, |
| 1393 | 0, |
| 1394 | 1, |
| 1395 | 123.45f, |
| 1396 | "valid name 3", |
| 1397 | "valid description", |
| 1398 | armnn::EmptyOptional(), // Units |
| 1399 | armnn::EmptyOptional(), // Number of cores |
| 1400 | 0)); // Device UID |
| 1401 | BOOST_CHECK(counterDirectory.GetCounterCount() == 3); |
| 1402 | BOOST_CHECK(counterWoDevice); |
| 1403 | BOOST_CHECK(counterWoDevice->m_Uid >= 0); |
| 1404 | BOOST_CHECK(counterWoDevice->m_Uid > counter->m_Uid); |
| 1405 | BOOST_CHECK(counterWoDevice->m_MaxCounterUid == counterWoDevice->m_Uid); |
| 1406 | BOOST_CHECK(counterWoDevice->m_Class == 0); |
| 1407 | BOOST_CHECK(counterWoDevice->m_Interpolation == 1); |
| 1408 | BOOST_CHECK(counterWoDevice->m_Multiplier == 123.45f); |
| 1409 | BOOST_CHECK(counterWoDevice->m_Name == "valid name 3"); |
| 1410 | BOOST_CHECK(counterWoDevice->m_Description == "valid description"); |
| 1411 | BOOST_CHECK(counterWoDevice->m_Units == ""); |
| 1412 | BOOST_CHECK(counterWoDevice->m_DeviceUid == 0); |
| 1413 | BOOST_CHECK(counterWoDevice->m_CounterSetUid == 0); |
| 1414 | BOOST_CHECK(category->m_Counters.size() == 3); |
| 1415 | BOOST_CHECK(category->m_Counters.back() == counterWoDevice->m_Uid); |
| 1416 | |
| 1417 | // Register a counter with a valid parent category name and associated to an invalid device |
| 1418 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(categoryName, |
| 1419 | 0, |
| 1420 | 1, |
| 1421 | 123.45f, |
| 1422 | "valid name 4", |
| 1423 | "valid description", |
| 1424 | armnn::EmptyOptional(), // Units |
| 1425 | armnn::EmptyOptional(), // Number of cores |
| 1426 | 100), // Device UID |
| 1427 | armnn::InvalidArgumentException); |
| 1428 | BOOST_CHECK(counterDirectory.GetCounterCount() == 3); |
| 1429 | BOOST_CHECK(!noCounter); |
| 1430 | |
| 1431 | // Register a device for testing |
| 1432 | const std::string deviceName = "some_device"; |
| 1433 | const Device* device = nullptr; |
| 1434 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName)); |
| 1435 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1436 | BOOST_CHECK(device); |
| 1437 | BOOST_CHECK(device->m_Name == deviceName); |
| 1438 | BOOST_CHECK(device->m_Uid >= 1); |
| 1439 | BOOST_CHECK(device->m_Cores == 0); |
| 1440 | |
| 1441 | // Register a counter with a valid parent category name and associated to a device |
| 1442 | const Counter* counterWDevice = nullptr; |
| 1443 | BOOST_CHECK_NO_THROW(counterWDevice = counterDirectory.RegisterCounter(categoryName, |
| 1444 | 0, |
| 1445 | 1, |
| 1446 | 123.45f, |
| 1447 | "valid name 5", |
| 1448 | "valid description", |
| 1449 | armnn::EmptyOptional(), // Units |
| 1450 | armnn::EmptyOptional(), // Number of cores |
| 1451 | device->m_Uid)); // Device UID |
| 1452 | BOOST_CHECK(counterDirectory.GetCounterCount() == 4); |
| 1453 | BOOST_CHECK(counterWDevice); |
| 1454 | BOOST_CHECK(counterWDevice->m_Uid >= 0); |
| 1455 | BOOST_CHECK(counterWDevice->m_Uid > counter->m_Uid); |
| 1456 | BOOST_CHECK(counterWDevice->m_MaxCounterUid == counterWDevice->m_Uid); |
| 1457 | BOOST_CHECK(counterWDevice->m_Class == 0); |
| 1458 | BOOST_CHECK(counterWDevice->m_Interpolation == 1); |
| 1459 | BOOST_CHECK(counterWDevice->m_Multiplier == 123.45f); |
| 1460 | BOOST_CHECK(counterWDevice->m_Name == "valid name 5"); |
| 1461 | BOOST_CHECK(counterWDevice->m_Description == "valid description"); |
| 1462 | BOOST_CHECK(counterWDevice->m_Units == ""); |
| 1463 | BOOST_CHECK(counterWDevice->m_DeviceUid == device->m_Uid); |
| 1464 | BOOST_CHECK(counterWDevice->m_CounterSetUid == 0); |
| 1465 | BOOST_CHECK(category->m_Counters.size() == 4); |
| 1466 | BOOST_CHECK(category->m_Counters.back() == counterWDevice->m_Uid); |
| 1467 | |
| 1468 | // Register a counter with a valid parent category name and not associated with a counter set |
| 1469 | const Counter* counterWoCounterSet = nullptr; |
| 1470 | BOOST_CHECK_NO_THROW(counterWoCounterSet |
| 1471 | = counterDirectory.RegisterCounter(categoryName, |
| 1472 | 0, |
| 1473 | 1, |
| 1474 | 123.45f, |
| 1475 | "valid name 6", |
| 1476 | "valid description", |
| 1477 | armnn::EmptyOptional(), // Units |
| 1478 | armnn::EmptyOptional(), // Number of cores |
| 1479 | armnn::EmptyOptional(), // Device UID |
| 1480 | 0)); // Counter set UID |
| 1481 | BOOST_CHECK(counterDirectory.GetCounterCount() == 5); |
| 1482 | BOOST_CHECK(counterWoCounterSet); |
| 1483 | BOOST_CHECK(counterWoCounterSet->m_Uid >= 0); |
| 1484 | BOOST_CHECK(counterWoCounterSet->m_Uid > counter->m_Uid); |
| 1485 | BOOST_CHECK(counterWoCounterSet->m_MaxCounterUid == counterWoCounterSet->m_Uid); |
| 1486 | BOOST_CHECK(counterWoCounterSet->m_Class == 0); |
| 1487 | BOOST_CHECK(counterWoCounterSet->m_Interpolation == 1); |
| 1488 | BOOST_CHECK(counterWoCounterSet->m_Multiplier == 123.45f); |
| 1489 | BOOST_CHECK(counterWoCounterSet->m_Name == "valid name 6"); |
| 1490 | BOOST_CHECK(counterWoCounterSet->m_Description == "valid description"); |
| 1491 | BOOST_CHECK(counterWoCounterSet->m_Units == ""); |
| 1492 | BOOST_CHECK(counterWoCounterSet->m_DeviceUid == 0); |
| 1493 | BOOST_CHECK(counterWoCounterSet->m_CounterSetUid == 0); |
| 1494 | BOOST_CHECK(category->m_Counters.size() == 5); |
| 1495 | BOOST_CHECK(category->m_Counters.back() == counterWoCounterSet->m_Uid); |
| 1496 | |
| 1497 | // Register a counter with a valid parent category name and associated to an invalid counter set |
| 1498 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(categoryName, |
| 1499 | 0, |
| 1500 | 1, |
| 1501 | 123.45f, |
| 1502 | "valid name 7", |
| 1503 | "valid description", |
| 1504 | armnn::EmptyOptional(), // Units |
| 1505 | armnn::EmptyOptional(), // Number of cores |
| 1506 | armnn::EmptyOptional(), // Device UID |
| 1507 | 100), // Counter set UID |
| 1508 | armnn::InvalidArgumentException); |
| 1509 | BOOST_CHECK(counterDirectory.GetCounterCount() == 5); |
| 1510 | BOOST_CHECK(!noCounter); |
| 1511 | |
| 1512 | // Register a counter with a valid parent category name and with a given number of cores |
| 1513 | const Counter* counterWNumberOfCores = nullptr; |
| 1514 | uint16_t numberOfCores = 15; |
| 1515 | BOOST_CHECK_NO_THROW(counterWNumberOfCores |
| 1516 | = counterDirectory.RegisterCounter(categoryName, |
| 1517 | 0, |
| 1518 | 1, |
| 1519 | 123.45f, |
| 1520 | "valid name 8", |
| 1521 | "valid description", |
| 1522 | armnn::EmptyOptional(), // Units |
| 1523 | numberOfCores, // Number of cores |
| 1524 | armnn::EmptyOptional(), // Device UID |
| 1525 | armnn::EmptyOptional())); // Counter set UID |
| 1526 | BOOST_CHECK(counterDirectory.GetCounterCount() == 20); |
| 1527 | BOOST_CHECK(counterWNumberOfCores); |
| 1528 | BOOST_CHECK(counterWNumberOfCores->m_Uid >= 0); |
| 1529 | BOOST_CHECK(counterWNumberOfCores->m_Uid > counter->m_Uid); |
| 1530 | BOOST_CHECK(counterWNumberOfCores->m_MaxCounterUid == counterWNumberOfCores->m_Uid + numberOfCores - 1); |
| 1531 | BOOST_CHECK(counterWNumberOfCores->m_Class == 0); |
| 1532 | BOOST_CHECK(counterWNumberOfCores->m_Interpolation == 1); |
| 1533 | BOOST_CHECK(counterWNumberOfCores->m_Multiplier == 123.45f); |
| 1534 | BOOST_CHECK(counterWNumberOfCores->m_Name == "valid name 8"); |
| 1535 | BOOST_CHECK(counterWNumberOfCores->m_Description == "valid description"); |
| 1536 | BOOST_CHECK(counterWNumberOfCores->m_Units == ""); |
| 1537 | BOOST_CHECK(counterWNumberOfCores->m_DeviceUid == 0); |
| 1538 | BOOST_CHECK(counterWNumberOfCores->m_CounterSetUid == 0); |
| 1539 | BOOST_CHECK(category->m_Counters.size() == 20); |
| 1540 | for (size_t i = 0; i < numberOfCores; i ++) |
| 1541 | { |
| 1542 | BOOST_CHECK(category->m_Counters[category->m_Counters.size() - numberOfCores + i] == |
| 1543 | counterWNumberOfCores->m_Uid + i); |
| 1544 | } |
| 1545 | |
| 1546 | // Register a multi-core device for testing |
| 1547 | const std::string multiCoreDeviceName = "some_multi_core_device"; |
| 1548 | const Device* multiCoreDevice = nullptr; |
| 1549 | BOOST_CHECK_NO_THROW(multiCoreDevice = counterDirectory.RegisterDevice(multiCoreDeviceName, 4)); |
| 1550 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 1551 | BOOST_CHECK(multiCoreDevice); |
| 1552 | BOOST_CHECK(multiCoreDevice->m_Name == multiCoreDeviceName); |
| 1553 | BOOST_CHECK(multiCoreDevice->m_Uid >= 1); |
| 1554 | BOOST_CHECK(multiCoreDevice->m_Cores == 4); |
| 1555 | |
| 1556 | // Register a counter with a valid parent category name and associated to the multi-core device |
| 1557 | const Counter* counterWMultiCoreDevice = nullptr; |
| 1558 | BOOST_CHECK_NO_THROW(counterWMultiCoreDevice |
| 1559 | = counterDirectory.RegisterCounter(categoryName, |
| 1560 | 0, |
| 1561 | 1, |
| 1562 | 123.45f, |
| 1563 | "valid name 9", |
| 1564 | "valid description", |
| 1565 | armnn::EmptyOptional(), // Units |
| 1566 | armnn::EmptyOptional(), // Number of cores |
| 1567 | multiCoreDevice->m_Uid, // Device UID |
| 1568 | armnn::EmptyOptional())); // Counter set UID |
| 1569 | BOOST_CHECK(counterDirectory.GetCounterCount() == 24); |
| 1570 | BOOST_CHECK(counterWMultiCoreDevice); |
| 1571 | BOOST_CHECK(counterWMultiCoreDevice->m_Uid >= 0); |
| 1572 | BOOST_CHECK(counterWMultiCoreDevice->m_Uid > counter->m_Uid); |
| 1573 | BOOST_CHECK(counterWMultiCoreDevice->m_MaxCounterUid == |
| 1574 | counterWMultiCoreDevice->m_Uid + multiCoreDevice->m_Cores - 1); |
| 1575 | BOOST_CHECK(counterWMultiCoreDevice->m_Class == 0); |
| 1576 | BOOST_CHECK(counterWMultiCoreDevice->m_Interpolation == 1); |
| 1577 | BOOST_CHECK(counterWMultiCoreDevice->m_Multiplier == 123.45f); |
| 1578 | BOOST_CHECK(counterWMultiCoreDevice->m_Name == "valid name 9"); |
| 1579 | BOOST_CHECK(counterWMultiCoreDevice->m_Description == "valid description"); |
| 1580 | BOOST_CHECK(counterWMultiCoreDevice->m_Units == ""); |
| 1581 | BOOST_CHECK(counterWMultiCoreDevice->m_DeviceUid == multiCoreDevice->m_Uid); |
| 1582 | BOOST_CHECK(counterWMultiCoreDevice->m_CounterSetUid == 0); |
| 1583 | BOOST_CHECK(category->m_Counters.size() == 24); |
| 1584 | for (size_t i = 0; i < 4; i ++) |
| 1585 | { |
| 1586 | BOOST_CHECK(category->m_Counters[category->m_Counters.size() - 4 + i] == counterWMultiCoreDevice->m_Uid + i); |
| 1587 | } |
| 1588 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1589 | // Register a multi-core device associate to a parent category for testing |
| 1590 | const std::string multiCoreDeviceNameWParentCategory = "some_multi_core_device_with_parent_category"; |
| 1591 | const Device* multiCoreDeviceWParentCategory = nullptr; |
| 1592 | BOOST_CHECK_NO_THROW(multiCoreDeviceWParentCategory = |
| 1593 | counterDirectory.RegisterDevice(multiCoreDeviceNameWParentCategory, 2, categoryName)); |
| 1594 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 3); |
| 1595 | BOOST_CHECK(multiCoreDeviceWParentCategory); |
| 1596 | BOOST_CHECK(multiCoreDeviceWParentCategory->m_Name == multiCoreDeviceNameWParentCategory); |
| 1597 | BOOST_CHECK(multiCoreDeviceWParentCategory->m_Uid >= 1); |
| 1598 | BOOST_CHECK(multiCoreDeviceWParentCategory->m_Cores == 2); |
| 1599 | |
| 1600 | // Register a counter with a valid parent category name and getting the number of cores of the multi-core device |
| 1601 | // associated to that category |
| 1602 | const Counter* counterWMultiCoreDeviceWParentCategory = nullptr; |
| 1603 | BOOST_CHECK_NO_THROW(counterWMultiCoreDeviceWParentCategory |
| 1604 | = counterDirectory.RegisterCounter(categoryName, |
| 1605 | 0, |
| 1606 | 1, |
| 1607 | 123.45f, |
| 1608 | "valid name 10", |
| 1609 | "valid description", |
| 1610 | armnn::EmptyOptional(), // Units |
| 1611 | armnn::EmptyOptional(), // Number of cores |
| 1612 | armnn::EmptyOptional(), // Device UID |
| 1613 | armnn::EmptyOptional())); // Counter set UID |
| 1614 | BOOST_CHECK(counterDirectory.GetCounterCount() == 26); |
| 1615 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory); |
| 1616 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Uid >= 0); |
| 1617 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Uid > counter->m_Uid); |
| 1618 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_MaxCounterUid == |
| 1619 | counterWMultiCoreDeviceWParentCategory->m_Uid + multiCoreDeviceWParentCategory->m_Cores - 1); |
| 1620 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Class == 0); |
| 1621 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Interpolation == 1); |
| 1622 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Multiplier == 123.45f); |
| 1623 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Name == "valid name 10"); |
| 1624 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Description == "valid description"); |
| 1625 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Units == ""); |
| 1626 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_DeviceUid == 0); |
| 1627 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_CounterSetUid == 0); |
| 1628 | BOOST_CHECK(category->m_Counters.size() == 26); |
| 1629 | for (size_t i = 0; i < 2; i ++) |
| 1630 | { |
| 1631 | BOOST_CHECK(category->m_Counters[category->m_Counters.size() - 2 + i] == |
| 1632 | counterWMultiCoreDeviceWParentCategory->m_Uid + i); |
| 1633 | } |
| 1634 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1635 | // Register a counter set for testing |
| 1636 | const std::string counterSetName = "some_counter_set"; |
| 1637 | const CounterSet* counterSet = nullptr; |
| 1638 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1639 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1640 | BOOST_CHECK(counterSet); |
| 1641 | BOOST_CHECK(counterSet->m_Name == counterSetName); |
| 1642 | BOOST_CHECK(counterSet->m_Uid >= 1); |
| 1643 | BOOST_CHECK(counterSet->m_Count == 0); |
| 1644 | |
| 1645 | // Register a counter with a valid parent category name and associated to a counter set |
| 1646 | const Counter* counterWCounterSet = nullptr; |
| 1647 | BOOST_CHECK_NO_THROW(counterWCounterSet |
| 1648 | = counterDirectory.RegisterCounter(categoryName, |
| 1649 | 0, |
| 1650 | 1, |
| 1651 | 123.45f, |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1652 | "valid name 11", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1653 | "valid description", |
| 1654 | armnn::EmptyOptional(), // Units |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1655 | 0, // Number of cores |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1656 | armnn::EmptyOptional(), // Device UID |
| 1657 | counterSet->m_Uid)); // Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1658 | BOOST_CHECK(counterDirectory.GetCounterCount() == 27); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1659 | BOOST_CHECK(counterWCounterSet); |
| 1660 | BOOST_CHECK(counterWCounterSet->m_Uid >= 0); |
| 1661 | BOOST_CHECK(counterWCounterSet->m_Uid > counter->m_Uid); |
| 1662 | BOOST_CHECK(counterWCounterSet->m_MaxCounterUid == counterWCounterSet->m_Uid); |
| 1663 | BOOST_CHECK(counterWCounterSet->m_Class == 0); |
| 1664 | BOOST_CHECK(counterWCounterSet->m_Interpolation == 1); |
| 1665 | BOOST_CHECK(counterWCounterSet->m_Multiplier == 123.45f); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1666 | BOOST_CHECK(counterWCounterSet->m_Name == "valid name 11"); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1667 | BOOST_CHECK(counterWCounterSet->m_Description == "valid description"); |
| 1668 | BOOST_CHECK(counterWCounterSet->m_Units == ""); |
| 1669 | BOOST_CHECK(counterWCounterSet->m_DeviceUid == 0); |
| 1670 | BOOST_CHECK(counterWCounterSet->m_CounterSetUid == counterSet->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1671 | BOOST_CHECK(category->m_Counters.size() == 27); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1672 | BOOST_CHECK(category->m_Counters.back() == counterWCounterSet->m_Uid); |
| 1673 | |
| 1674 | // Register a counter with a valid parent category name and associated to a device and a counter set |
| 1675 | const Counter* counterWDeviceWCounterSet = nullptr; |
| 1676 | BOOST_CHECK_NO_THROW(counterWDeviceWCounterSet |
| 1677 | = counterDirectory.RegisterCounter(categoryName, |
| 1678 | 0, |
| 1679 | 1, |
| 1680 | 123.45f, |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1681 | "valid name 12", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1682 | "valid description", |
| 1683 | armnn::EmptyOptional(), // Units |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1684 | 1, // Number of cores |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1685 | device->m_Uid, // Device UID |
| 1686 | counterSet->m_Uid)); // Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1687 | BOOST_CHECK(counterDirectory.GetCounterCount() == 28); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1688 | BOOST_CHECK(counterWDeviceWCounterSet); |
| 1689 | BOOST_CHECK(counterWDeviceWCounterSet->m_Uid >= 0); |
| 1690 | BOOST_CHECK(counterWDeviceWCounterSet->m_Uid > counter->m_Uid); |
| 1691 | BOOST_CHECK(counterWDeviceWCounterSet->m_MaxCounterUid == counterWDeviceWCounterSet->m_Uid); |
| 1692 | BOOST_CHECK(counterWDeviceWCounterSet->m_Class == 0); |
| 1693 | BOOST_CHECK(counterWDeviceWCounterSet->m_Interpolation == 1); |
| 1694 | BOOST_CHECK(counterWDeviceWCounterSet->m_Multiplier == 123.45f); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1695 | BOOST_CHECK(counterWDeviceWCounterSet->m_Name == "valid name 12"); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1696 | BOOST_CHECK(counterWDeviceWCounterSet->m_Description == "valid description"); |
| 1697 | BOOST_CHECK(counterWDeviceWCounterSet->m_Units == ""); |
| 1698 | BOOST_CHECK(counterWDeviceWCounterSet->m_DeviceUid == device->m_Uid); |
| 1699 | BOOST_CHECK(counterWDeviceWCounterSet->m_CounterSetUid == counterSet->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1700 | BOOST_CHECK(category->m_Counters.size() == 28); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1701 | BOOST_CHECK(category->m_Counters.back() == counterWDeviceWCounterSet->m_Uid); |
| 1702 | |
| 1703 | // Register another category for testing |
| 1704 | const std::string anotherCategoryName = "some_other_category"; |
| 1705 | const Category* anotherCategory = nullptr; |
| 1706 | BOOST_CHECK_NO_THROW(anotherCategory = counterDirectory.RegisterCategory(anotherCategoryName)); |
| 1707 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 1708 | BOOST_CHECK(anotherCategory); |
| 1709 | BOOST_CHECK(anotherCategory != category); |
| 1710 | BOOST_CHECK(anotherCategory->m_Name == anotherCategoryName); |
| 1711 | BOOST_CHECK(anotherCategory->m_Counters.empty()); |
| 1712 | BOOST_CHECK(anotherCategory->m_DeviceUid == 0); |
| 1713 | BOOST_CHECK(anotherCategory->m_CounterSetUid == 0); |
| 1714 | |
| 1715 | // Register a counter to the other category |
| 1716 | const Counter* anotherCounter = nullptr; |
| 1717 | BOOST_CHECK_NO_THROW(anotherCounter = counterDirectory.RegisterCounter(anotherCategoryName, |
| 1718 | 1, |
| 1719 | 0, |
| 1720 | .00043f, |
| 1721 | "valid name", |
| 1722 | "valid description", |
| 1723 | armnn::EmptyOptional(), // Units |
| 1724 | armnn::EmptyOptional(), // Number of cores |
| 1725 | device->m_Uid, // Device UID |
| 1726 | counterSet->m_Uid)); // Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1727 | BOOST_CHECK(counterDirectory.GetCounterCount() == 29); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1728 | BOOST_CHECK(anotherCounter); |
| 1729 | BOOST_CHECK(anotherCounter->m_Uid >= 0); |
| 1730 | BOOST_CHECK(anotherCounter->m_MaxCounterUid == anotherCounter->m_Uid); |
| 1731 | BOOST_CHECK(anotherCounter->m_Class == 1); |
| 1732 | BOOST_CHECK(anotherCounter->m_Interpolation == 0); |
| 1733 | BOOST_CHECK(anotherCounter->m_Multiplier == .00043f); |
| 1734 | BOOST_CHECK(anotherCounter->m_Name == "valid name"); |
| 1735 | BOOST_CHECK(anotherCounter->m_Description == "valid description"); |
| 1736 | BOOST_CHECK(anotherCounter->m_Units == ""); |
| 1737 | BOOST_CHECK(anotherCounter->m_DeviceUid == device->m_Uid); |
| 1738 | BOOST_CHECK(anotherCounter->m_CounterSetUid == counterSet->m_Uid); |
| 1739 | BOOST_CHECK(anotherCategory->m_Counters.size() == 1); |
| 1740 | BOOST_CHECK(anotherCategory->m_Counters.back() == anotherCounter->m_Uid); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1741 | } |
| 1742 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1743 | BOOST_AUTO_TEST_CASE(CounterSelectionCommandHandlerParseData) |
| 1744 | { |
| 1745 | using boost::numeric_cast; |
| 1746 | |
| 1747 | class TestCaptureThread : public IPeriodicCounterCapture |
| 1748 | { |
| 1749 | void Start() override {}; |
| 1750 | }; |
| 1751 | |
| 1752 | const uint32_t packetId = 0x40000; |
| 1753 | |
| 1754 | uint32_t version = 1; |
| 1755 | Holder holder; |
| 1756 | TestCaptureThread captureThread; |
| 1757 | MockBuffer mockBuffer(512); |
| 1758 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 1759 | |
| 1760 | uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t)); |
| 1761 | uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t)); |
| 1762 | |
| 1763 | // Data with period and counters |
| 1764 | uint32_t period1 = 10; |
| 1765 | uint32_t dataLength1 = 8; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1766 | uint32_t offset = 0; |
| 1767 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 1768 | std::unique_ptr<char[]> uniqueData1 = std::make_unique<char[]>(dataLength1); |
| 1769 | unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get()); |
| 1770 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1771 | WriteUint32(data1, offset, period1); |
| 1772 | offset += sizeOfUint32; |
| 1773 | WriteUint16(data1, offset, 4000); |
| 1774 | offset += sizeOfUint16; |
| 1775 | WriteUint16(data1, offset, 5000); |
| 1776 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 1777 | Packet packetA(packetId, dataLength1, uniqueData1); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1778 | |
| 1779 | PeriodicCounterSelectionCommandHandler commandHandler(packetId, version, holder, captureThread, |
| 1780 | sendCounterPacket); |
| 1781 | commandHandler(packetA); |
| 1782 | |
| 1783 | std::vector<uint16_t> counterIds = holder.GetCaptureData().GetCounterIds(); |
| 1784 | |
| 1785 | BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == period1); |
| 1786 | BOOST_TEST(counterIds.size() == 2); |
| 1787 | BOOST_TEST(counterIds[0] == 4000); |
| 1788 | BOOST_TEST(counterIds[1] == 5000); |
| 1789 | |
| 1790 | unsigned int size = 0; |
| 1791 | |
| 1792 | const unsigned char* readBuffer = mockBuffer.GetReadBuffer(size); |
| 1793 | |
| 1794 | offset = 0; |
| 1795 | |
| 1796 | uint32_t headerWord0 = ReadUint32(readBuffer, offset); |
| 1797 | offset += sizeOfUint32; |
| 1798 | uint32_t headerWord1 = ReadUint32(readBuffer, offset); |
| 1799 | offset += sizeOfUint32; |
| 1800 | uint32_t period = ReadUint32(readBuffer, offset); |
| 1801 | |
| 1802 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 1803 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id |
| 1804 | BOOST_TEST(headerWord1 == 8); // data lenght |
| 1805 | BOOST_TEST(period == 10); // capture period |
| 1806 | |
| 1807 | uint16_t counterId = 0; |
| 1808 | offset += sizeOfUint32; |
| 1809 | counterId = ReadUint16(readBuffer, offset); |
| 1810 | BOOST_TEST(counterId == 4000); |
| 1811 | offset += sizeOfUint16; |
| 1812 | counterId = ReadUint16(readBuffer, offset); |
| 1813 | BOOST_TEST(counterId == 5000); |
| 1814 | |
| 1815 | // Data with period only |
| 1816 | uint32_t period2 = 11; |
| 1817 | uint32_t dataLength2 = 4; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1818 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 1819 | std::unique_ptr<char[]> uniqueData2 = std::make_unique<char[]>(dataLength2); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1820 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 1821 | WriteUint32(reinterpret_cast<unsigned char*>(uniqueData2.get()), 0, period2); |
| 1822 | |
| 1823 | Packet packetB(packetId, dataLength2, uniqueData2); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1824 | |
| 1825 | commandHandler(packetB); |
| 1826 | |
| 1827 | counterIds = holder.GetCaptureData().GetCounterIds(); |
| 1828 | |
| 1829 | BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == period2); |
| 1830 | BOOST_TEST(counterIds.size() == 0); |
| 1831 | |
| 1832 | readBuffer = mockBuffer.GetReadBuffer(size); |
| 1833 | |
| 1834 | offset = 0; |
| 1835 | |
| 1836 | headerWord0 = ReadUint32(readBuffer, offset); |
| 1837 | offset += sizeOfUint32; |
| 1838 | headerWord1 = ReadUint32(readBuffer, offset); |
| 1839 | offset += sizeOfUint32; |
| 1840 | period = ReadUint32(readBuffer, offset); |
| 1841 | |
| 1842 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 1843 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id |
| 1844 | BOOST_TEST(headerWord1 == 4); // data lenght |
| 1845 | BOOST_TEST(period == 11); // capture period |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1846 | } |
| 1847 | |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1848 | BOOST_AUTO_TEST_CASE(CheckConnectionAcknowledged) |
| 1849 | { |
| 1850 | using boost::numeric_cast; |
| 1851 | |
| 1852 | const uint32_t connectionPacketId = 0x10000; |
| 1853 | const uint32_t version = 1; |
| 1854 | |
| 1855 | uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t)); |
| 1856 | uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t)); |
| 1857 | |
| 1858 | // Data with period and counters |
| 1859 | uint32_t period1 = 10; |
| 1860 | uint32_t dataLength1 = 8; |
| 1861 | uint32_t offset = 0; |
| 1862 | |
| 1863 | std::unique_ptr<char[]> uniqueData1 = std::make_unique<char[]>(dataLength1); |
| 1864 | unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get()); |
| 1865 | |
| 1866 | WriteUint32(data1, offset, period1); |
| 1867 | offset += sizeOfUint32; |
| 1868 | WriteUint16(data1, offset, 4000); |
| 1869 | offset += sizeOfUint16; |
| 1870 | WriteUint16(data1, offset, 5000); |
| 1871 | |
| 1872 | Packet packetA(connectionPacketId, dataLength1, uniqueData1); |
| 1873 | |
| 1874 | ProfilingStateMachine profilingState(ProfilingState::Uninitialised); |
| 1875 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Uninitialised); |
| 1876 | |
| 1877 | ConnectionAcknowledgedCommandHandler commandHandler(connectionPacketId, version, profilingState); |
| 1878 | |
| 1879 | // command handler received packet on ProfilingState::Uninitialised |
| 1880 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception); |
| 1881 | |
| 1882 | profilingState.TransitionToState(ProfilingState::NotConnected); |
| 1883 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::NotConnected); |
| 1884 | // command handler received packet on ProfilingState::NotConnected |
| 1885 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception); |
| 1886 | |
| 1887 | profilingState.TransitionToState(ProfilingState::WaitingForAck); |
| 1888 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::WaitingForAck); |
| 1889 | // command handler received packet on ProfilingState::WaitingForAck |
| 1890 | commandHandler(packetA); |
| 1891 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active); |
| 1892 | |
| 1893 | // command handler received packet on ProfilingState::Active |
| 1894 | commandHandler(packetA); |
| 1895 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active); |
| 1896 | |
| 1897 | // command handler received different packet |
| 1898 | const uint32_t differentPacketId = 0x40000; |
| 1899 | Packet packetB(differentPacketId, dataLength1, uniqueData1); |
| 1900 | ConnectionAcknowledgedCommandHandler differentCommandHandler(differentPacketId, version, profilingState); |
| 1901 | BOOST_CHECK_THROW(differentCommandHandler(packetB), armnn::Exception); |
| 1902 | } |
| 1903 | |
Teresa Charlin | 9bab496 | 2019-09-06 12:28:35 +0100 | [diff] [blame] | 1904 | BOOST_AUTO_TEST_CASE(CheckSocketProfilingConnection) |
| 1905 | { |
| 1906 | // Check that creating a SocketProfilingConnection results in an exception as the Gator UDS doesn't exist. |
| 1907 | BOOST_CHECK_THROW(new SocketProfilingConnection(), armnn::Exception); |
| 1908 | } |
| 1909 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1910 | BOOST_AUTO_TEST_CASE(SwTraceIsValidCharTest) |
| 1911 | { |
| 1912 | // Only ASCII 7-bit encoding supported |
| 1913 | for (unsigned char c = 0; c < 128; c++) |
| 1914 | { |
| 1915 | BOOST_CHECK(SwTraceCharPolicy::IsValidChar(c)); |
| 1916 | } |
| 1917 | |
| 1918 | // Not ASCII |
| 1919 | for (unsigned char c = 255; c >= 128; c++) |
| 1920 | { |
| 1921 | BOOST_CHECK(!SwTraceCharPolicy::IsValidChar(c)); |
| 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | BOOST_AUTO_TEST_CASE(SwTraceIsValidNameCharTest) |
| 1926 | { |
| 1927 | // Only alpha-numeric and underscore ASCII 7-bit encoding supported |
| 1928 | const unsigned char validChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; |
| 1929 | for (unsigned char i = 0; i < sizeof(validChars) / sizeof(validChars[0]) - 1; i++) |
| 1930 | { |
| 1931 | BOOST_CHECK(SwTraceNameCharPolicy::IsValidChar(validChars[i])); |
| 1932 | } |
| 1933 | |
| 1934 | // Non alpha-numeric chars |
| 1935 | for (unsigned char c = 0; c < 48; c++) |
| 1936 | { |
| 1937 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1938 | } |
| 1939 | for (unsigned char c = 58; c < 65; c++) |
| 1940 | { |
| 1941 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1942 | } |
| 1943 | for (unsigned char c = 91; c < 95; c++) |
| 1944 | { |
| 1945 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1946 | } |
| 1947 | for (unsigned char c = 96; c < 97; c++) |
| 1948 | { |
| 1949 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1950 | } |
| 1951 | for (unsigned char c = 123; c < 128; c++) |
| 1952 | { |
| 1953 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1954 | } |
| 1955 | |
| 1956 | // Not ASCII |
| 1957 | for (unsigned char c = 255; c >= 128; c++) |
| 1958 | { |
| 1959 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | BOOST_AUTO_TEST_CASE(IsValidSwTraceStringTest) |
| 1964 | { |
| 1965 | // Valid SWTrace strings |
| 1966 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("")); |
| 1967 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("_")); |
| 1968 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("0123")); |
| 1969 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid_string")); |
| 1970 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("VALID_string_456")); |
| 1971 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(" ")); |
| 1972 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid string")); |
| 1973 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("!$%")); |
| 1974 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid|\\~string#123")); |
| 1975 | |
| 1976 | // Invalid SWTrace strings |
| 1977 | BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("€£")); |
| 1978 | BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("invalid‡string")); |
| 1979 | BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("12Ž34")); |
| 1980 | } |
| 1981 | |
| 1982 | BOOST_AUTO_TEST_CASE(IsValidSwTraceNameStringTest) |
| 1983 | { |
| 1984 | // Valid SWTrace name strings |
| 1985 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("")); |
| 1986 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("_")); |
| 1987 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("0123")); |
| 1988 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("valid_string")); |
| 1989 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("VALID_string_456")); |
| 1990 | |
| 1991 | // Invalid SWTrace name strings |
| 1992 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(" ")); |
| 1993 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid string")); |
| 1994 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("!$%")); |
| 1995 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123")); |
| 1996 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("€£")); |
| 1997 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid‡string")); |
| 1998 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("12Ž34")); |
| 1999 | } |
| 2000 | |
| 2001 | template <typename SwTracePolicy> |
| 2002 | void StringToSwTraceStringTestHelper(const std::string& testString, std::vector<uint32_t> buffer, size_t expectedSize) |
| 2003 | { |
| 2004 | // Convert the test string to a SWTrace string |
| 2005 | BOOST_CHECK(StringToSwTraceString<SwTracePolicy>(testString, buffer)); |
| 2006 | |
| 2007 | // The buffer must contain at least the length of the string |
| 2008 | BOOST_CHECK(!buffer.empty()); |
| 2009 | |
| 2010 | // The buffer must be of the expected size (in words) |
| 2011 | BOOST_CHECK(buffer.size() == expectedSize); |
| 2012 | |
| 2013 | // The first word of the byte must be the length of the string including the null-terminator |
| 2014 | BOOST_CHECK(buffer[0] == testString.size() + 1); |
| 2015 | |
| 2016 | // The contents of the buffer must match the test string |
| 2017 | BOOST_CHECK(std::memcmp(testString.data(), buffer.data() + 1, testString.size()) == 0); |
| 2018 | |
| 2019 | // The buffer must include the null-terminator at the end of the string |
| 2020 | size_t nullTerminatorIndex = sizeof(uint32_t) + testString.size(); |
| 2021 | BOOST_CHECK(reinterpret_cast<unsigned char*>(buffer.data())[nullTerminatorIndex] == '\0'); |
| 2022 | } |
| 2023 | |
| 2024 | BOOST_AUTO_TEST_CASE(StringToSwTraceStringTest) |
| 2025 | { |
| 2026 | std::vector<uint32_t> buffer; |
| 2027 | |
| 2028 | // Valid SWTrace strings (expected size in words) |
| 2029 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("", buffer, 2); |
| 2030 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("_", buffer, 2); |
| 2031 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("0123", buffer, 3); |
| 2032 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid_string", buffer, 5); |
| 2033 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("VALID_string_456", buffer, 6); |
| 2034 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>(" ", buffer, 2); |
| 2035 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid string", buffer, 5); |
| 2036 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("!$%", buffer, 2); |
| 2037 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid|\\~string#123", buffer, 6); |
| 2038 | |
| 2039 | // Invalid SWTrace strings |
| 2040 | BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("€£", buffer)); |
| 2041 | BOOST_CHECK(buffer.empty()); |
| 2042 | BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("invalid‡string", buffer)); |
| 2043 | BOOST_CHECK(buffer.empty()); |
| 2044 | BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("12Ž34", buffer)); |
| 2045 | BOOST_CHECK(buffer.empty()); |
| 2046 | } |
| 2047 | |
| 2048 | BOOST_AUTO_TEST_CASE(StringToSwTraceNameStringTest) |
| 2049 | { |
| 2050 | std::vector<uint32_t> buffer; |
| 2051 | |
| 2052 | // Valid SWTrace namestrings (expected size in words) |
| 2053 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("", buffer, 2); |
| 2054 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("_", buffer, 2); |
| 2055 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("0123", buffer, 3); |
| 2056 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("valid_string", buffer, 5); |
| 2057 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("VALID_string_456", buffer, 6); |
| 2058 | |
| 2059 | // Invalid SWTrace namestrings |
| 2060 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(" ", buffer)); |
| 2061 | BOOST_CHECK(buffer.empty()); |
| 2062 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid string", buffer)); |
| 2063 | BOOST_CHECK(buffer.empty()); |
| 2064 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("!$%", buffer)); |
| 2065 | BOOST_CHECK(buffer.empty()); |
| 2066 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123", buffer)); |
| 2067 | BOOST_CHECK(buffer.empty()); |
| 2068 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("€£", buffer)); |
| 2069 | BOOST_CHECK(buffer.empty()); |
| 2070 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid‡string", buffer)); |
| 2071 | BOOST_CHECK(buffer.empty()); |
| 2072 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("12Ž34", buffer)); |
| 2073 | BOOST_CHECK(buffer.empty()); |
| 2074 | } |
| 2075 | |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2076 | BOOST_AUTO_TEST_CASE(CheckPeriodicCounterCaptureThread) |
| 2077 | { |
| 2078 | class CaptureReader : public IReadCounterValue |
| 2079 | { |
| 2080 | public: |
| 2081 | CaptureReader() {} |
| 2082 | |
| 2083 | void GetCounterValue(uint16_t index, uint32_t &value) const override |
| 2084 | { |
| 2085 | if (m_Data.count(index)) |
| 2086 | { |
| 2087 | value = m_Data.at(index); |
| 2088 | } |
| 2089 | else |
| 2090 | { |
| 2091 | value = 0; |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | void SetCounterValue(uint16_t index, uint32_t value) |
| 2096 | { |
| 2097 | if (!m_Data.count(index)) |
| 2098 | { |
| 2099 | m_Data.insert(std::pair<uint16_t, uint32_t>(index, value)); |
| 2100 | } |
| 2101 | else |
| 2102 | { |
| 2103 | m_Data.at(index) = value; |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | private: |
| 2108 | std::map<uint16_t, uint32_t> m_Data; |
| 2109 | }; |
| 2110 | |
| 2111 | Holder data; |
| 2112 | std::vector<uint16_t> captureIds1 = { 0, 1 }; |
| 2113 | std::vector<uint16_t> captureIds2; |
| 2114 | |
| 2115 | MockBuffer mockBuffer(512); |
| 2116 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 2117 | |
| 2118 | std::vector<uint16_t> counterIds; |
| 2119 | CaptureReader captureReader; |
| 2120 | |
| 2121 | unsigned int valueA = 10; |
| 2122 | unsigned int valueB = 15; |
| 2123 | unsigned int numSteps = 5; |
| 2124 | |
| 2125 | PeriodicCounterCapture periodicCounterCapture(std::ref(data), std::ref(sendCounterPacket), captureReader); |
| 2126 | |
| 2127 | for(unsigned int i = 0; i < numSteps; ++i) |
| 2128 | { |
| 2129 | data.SetCaptureData(1, captureIds1); |
| 2130 | captureReader.SetCounterValue(0, valueA * (i + 1)); |
| 2131 | captureReader.SetCounterValue(1, valueB * (i + 1)); |
| 2132 | |
| 2133 | periodicCounterCapture.Start(); |
| 2134 | |
| 2135 | std::this_thread::sleep_for(std::chrono::milliseconds(200)); |
| 2136 | |
| 2137 | periodicCounterCapture.Start(); |
| 2138 | |
| 2139 | data.SetCaptureData(0, captureIds2); |
| 2140 | |
| 2141 | periodicCounterCapture.Start(); |
| 2142 | } |
| 2143 | |
| 2144 | periodicCounterCapture.Join(); |
| 2145 | |
| 2146 | unsigned int size = 0; |
| 2147 | |
| 2148 | const unsigned char* buffer = mockBuffer.GetReadBuffer(size); |
| 2149 | |
| 2150 | uint32_t headerWord0 = ReadUint32(buffer, 0); |
| 2151 | uint32_t headerWord1 = ReadUint32(buffer, 4); |
| 2152 | |
| 2153 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 1); // packet family |
| 2154 | BOOST_TEST(((headerWord0 >> 19) & 0x3F) == 0); // packet class |
| 2155 | BOOST_TEST(((headerWord0 >> 16) & 0x3) == 0); // packet type |
| 2156 | BOOST_TEST(headerWord1 == 20); // data length |
| 2157 | |
| 2158 | uint32_t offset = 16; |
| 2159 | uint16_t readIndex = ReadUint16(buffer, offset); |
| 2160 | BOOST_TEST(0 == readIndex); |
| 2161 | |
| 2162 | offset += 2; |
| 2163 | uint32_t readValue = ReadUint32(buffer, offset); |
| 2164 | BOOST_TEST((valueA * numSteps) == readValue); |
| 2165 | |
| 2166 | offset += 4; |
| 2167 | readIndex = ReadUint16(buffer, offset); |
| 2168 | BOOST_TEST(1 == readIndex); |
| 2169 | |
| 2170 | offset += 2; |
| 2171 | readValue = ReadUint32(buffer, offset); |
| 2172 | BOOST_TEST((valueB * numSteps) == readValue); |
| 2173 | } |
| 2174 | |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2175 | BOOST_AUTO_TEST_CASE(RequestCounterDirectoryCommandHandlerTest0) |
| 2176 | { |
| 2177 | using boost::numeric_cast; |
| 2178 | |
| 2179 | const uint32_t packetId = 0x30000; |
| 2180 | const uint32_t version = 1; |
| 2181 | |
| 2182 | std::unique_ptr<char[]> packetData; |
| 2183 | |
| 2184 | Packet packetA(packetId, 0, packetData); |
| 2185 | |
| 2186 | MockBuffer mockBuffer(1024); |
| 2187 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 2188 | |
| 2189 | CounterDirectory counterDirectory; |
| 2190 | |
| 2191 | RequestCounterDirectoryCommandHandler commandHandler(packetId, version, counterDirectory, sendCounterPacket); |
| 2192 | commandHandler(packetA); |
| 2193 | |
| 2194 | unsigned int size = 0; |
| 2195 | const unsigned char* readBuffer = mockBuffer.GetReadBuffer(size); |
| 2196 | |
| 2197 | uint32_t headerWord0 = ReadUint32(readBuffer, 0); |
| 2198 | uint32_t headerWord1 = ReadUint32(readBuffer, 4); |
| 2199 | |
| 2200 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 2201 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 2); // packet id |
Matteo Martincigh | f74ff2f | 2019-09-24 11:38:32 +0100 | [diff] [blame] | 2202 | BOOST_TEST(headerWord1 == 24); // data length |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2203 | |
| 2204 | uint32_t bodyHeaderWord0 = ReadUint32(readBuffer, 8); |
| 2205 | uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeaderWord0 >> 16); |
| 2206 | BOOST_TEST(deviceRecordCount == 0); // device_records_count |
| 2207 | } |
| 2208 | |
| 2209 | BOOST_AUTO_TEST_CASE(RequestCounterDirectoryCommandHandlerTest1) |
| 2210 | { |
| 2211 | using boost::numeric_cast; |
| 2212 | |
| 2213 | const uint32_t packetId = 0x30000; |
| 2214 | const uint32_t version = 1; |
| 2215 | |
| 2216 | std::unique_ptr<char[]> packetData; |
| 2217 | |
| 2218 | Packet packetA(packetId, 0, packetData); |
| 2219 | |
| 2220 | MockBuffer mockBuffer(1024); |
| 2221 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 2222 | |
| 2223 | CounterDirectory counterDirectory; |
| 2224 | const Device* device = counterDirectory.RegisterDevice("deviceA", 1); |
| 2225 | const CounterSet* counterSet = counterDirectory.RegisterCounterSet("countersetA"); |
| 2226 | counterDirectory.RegisterCategory("categoryA", device->m_Uid, counterSet->m_Uid); |
| 2227 | counterDirectory.RegisterCounter("categoryA", 0, 1, 2.0f, "counterA", "descA"); |
| 2228 | counterDirectory.RegisterCounter("categoryA", 1, 1, 3.0f, "counterB", "descB"); |
| 2229 | |
| 2230 | RequestCounterDirectoryCommandHandler commandHandler(packetId, version, counterDirectory, sendCounterPacket); |
| 2231 | commandHandler(packetA); |
| 2232 | |
| 2233 | unsigned int size = 0; |
| 2234 | const unsigned char* readBuffer = mockBuffer.GetReadBuffer(size); |
| 2235 | |
| 2236 | uint32_t headerWord0 = ReadUint32(readBuffer, 0); |
| 2237 | uint32_t headerWord1 = ReadUint32(readBuffer, 4); |
| 2238 | |
| 2239 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 2240 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 2); // packet id |
Matteo Martincigh | f74ff2f | 2019-09-24 11:38:32 +0100 | [diff] [blame] | 2241 | BOOST_TEST(headerWord1 == 240); // data length |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2242 | |
| 2243 | uint32_t bodyHeaderWord0 = ReadUint32(readBuffer, 8); |
| 2244 | uint32_t bodyHeaderWord1 = ReadUint32(readBuffer, 12); |
| 2245 | uint32_t bodyHeaderWord2 = ReadUint32(readBuffer, 16); |
| 2246 | uint32_t bodyHeaderWord3 = ReadUint32(readBuffer, 20); |
| 2247 | uint32_t bodyHeaderWord4 = ReadUint32(readBuffer, 24); |
| 2248 | uint32_t bodyHeaderWord5 = ReadUint32(readBuffer, 28); |
| 2249 | uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeaderWord0 >> 16); |
| 2250 | uint16_t counterSetRecordCount = numeric_cast<uint16_t>(bodyHeaderWord2 >> 16); |
| 2251 | uint16_t categoryRecordCount = numeric_cast<uint16_t>(bodyHeaderWord4 >> 16); |
| 2252 | BOOST_TEST(deviceRecordCount == 1); // device_records_count |
| 2253 | BOOST_TEST(bodyHeaderWord1 == 0); // device_records_pointer_table_offset |
| 2254 | BOOST_TEST(counterSetRecordCount == 1); // counter_set_count |
| 2255 | BOOST_TEST(bodyHeaderWord3 == 4); // counter_set_pointer_table_offset |
| 2256 | BOOST_TEST(categoryRecordCount == 1); // categories_count |
| 2257 | BOOST_TEST(bodyHeaderWord5 == 8); // categories_pointer_table_offset |
| 2258 | |
| 2259 | uint32_t deviceRecordOffset = ReadUint32(readBuffer, 32); |
| 2260 | BOOST_TEST(deviceRecordOffset == 0); |
| 2261 | |
| 2262 | uint32_t counterSetRecordOffset = ReadUint32(readBuffer, 36); |
| 2263 | BOOST_TEST(counterSetRecordOffset == 20); |
| 2264 | |
| 2265 | uint32_t categoryRecordOffset = ReadUint32(readBuffer, 40); |
| 2266 | BOOST_TEST(categoryRecordOffset == 44); |
| 2267 | } |
| 2268 | |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 2269 | BOOST_AUTO_TEST_SUITE_END() |