Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 1 | // |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 6 | #include "SendCounterPacketTests.hpp" |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 7 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 8 | #include <EncodeVersion.hpp> |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 9 | #include <ProfilingUtils.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 10 | #include <SendCounterPacket.hpp> |
| 11 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 12 | #include <armnn/Exceptions.hpp> |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 13 | #include <armnn/Conversion.hpp> |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 14 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 15 | #include <boost/test/unit_test.hpp> |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 16 | #include <boost/numeric/conversion/cast.hpp> |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 17 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 18 | #include <chrono> |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 19 | #include <iostream> |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 20 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 21 | using namespace armnn::profiling; |
| 22 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 23 | BOOST_AUTO_TEST_SUITE(SendCounterPacketTests) |
| 24 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 25 | BOOST_AUTO_TEST_CASE(MockSendCounterPacketTest) |
| 26 | { |
| 27 | unsigned int size = 0; |
| 28 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 29 | MockBuffer mockBuffer(512); |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 30 | MockSendCounterPacket sendCounterPacket(mockBuffer); |
| 31 | |
| 32 | sendCounterPacket.SendStreamMetaDataPacket(); |
| 33 | const char* buffer = reinterpret_cast<const char*>(mockBuffer.GetReadBuffer(size)); |
| 34 | |
| 35 | BOOST_TEST(strcmp(buffer, "SendStreamMetaDataPacket") == 0); |
| 36 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 37 | CounterDirectory counterDirectory; |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 38 | sendCounterPacket.SendCounterDirectoryPacket(counterDirectory); |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 39 | |
| 40 | BOOST_TEST(strcmp(buffer, "SendCounterDirectoryPacket") == 0); |
| 41 | |
| 42 | uint64_t timestamp = 0; |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 43 | std::vector<std::pair<uint16_t, uint32_t>> indexValuePairs; |
| 44 | |
| 45 | sendCounterPacket.SendPeriodicCounterCapturePacket(timestamp, indexValuePairs); |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 46 | |
| 47 | BOOST_TEST(strcmp(buffer, "SendPeriodicCounterCapturePacket") == 0); |
| 48 | |
| 49 | uint32_t capturePeriod = 0; |
| 50 | std::vector<uint16_t> selectedCounterIds; |
| 51 | sendCounterPacket.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds); |
| 52 | |
| 53 | BOOST_TEST(strcmp(buffer, "SendPeriodicCounterSelectionPacket") == 0); |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 56 | BOOST_AUTO_TEST_CASE(SendPeriodicCounterSelectionPacketTest) |
| 57 | { |
| 58 | // Error no space left in buffer |
| 59 | MockBuffer mockBuffer1(10); |
| 60 | SendCounterPacket sendPacket1(mockBuffer1); |
| 61 | |
| 62 | uint32_t capturePeriod = 1000; |
| 63 | std::vector<uint16_t> selectedCounterIds; |
| 64 | BOOST_CHECK_THROW(sendPacket1.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds), |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 65 | armnn::profiling::BufferExhaustion); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 66 | |
| 67 | // Packet without any counters |
| 68 | MockBuffer mockBuffer2(512); |
| 69 | SendCounterPacket sendPacket2(mockBuffer2); |
| 70 | |
| 71 | sendPacket2.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds); |
| 72 | unsigned int sizeRead = 0; |
| 73 | const unsigned char* readBuffer2 = mockBuffer2.GetReadBuffer(sizeRead); |
| 74 | |
| 75 | uint32_t headerWord0 = ReadUint32(readBuffer2, 0); |
| 76 | uint32_t headerWord1 = ReadUint32(readBuffer2, 4); |
| 77 | uint32_t period = ReadUint32(readBuffer2, 8); |
| 78 | |
| 79 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 80 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id |
| 81 | BOOST_TEST(headerWord1 == 4); // data lenght |
| 82 | BOOST_TEST(period == 1000); // capture period |
| 83 | |
| 84 | // Full packet message |
| 85 | MockBuffer mockBuffer3(512); |
| 86 | SendCounterPacket sendPacket3(mockBuffer3); |
| 87 | |
| 88 | selectedCounterIds.reserve(5); |
| 89 | selectedCounterIds.emplace_back(100); |
| 90 | selectedCounterIds.emplace_back(200); |
| 91 | selectedCounterIds.emplace_back(300); |
| 92 | selectedCounterIds.emplace_back(400); |
| 93 | selectedCounterIds.emplace_back(500); |
| 94 | sendPacket3.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds); |
| 95 | sizeRead = 0; |
| 96 | const unsigned char* readBuffer3 = mockBuffer3.GetReadBuffer(sizeRead); |
| 97 | |
| 98 | headerWord0 = ReadUint32(readBuffer3, 0); |
| 99 | headerWord1 = ReadUint32(readBuffer3, 4); |
| 100 | period = ReadUint32(readBuffer3, 8); |
| 101 | |
| 102 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 103 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id |
| 104 | BOOST_TEST(headerWord1 == 14); // data lenght |
| 105 | BOOST_TEST(period == 1000); // capture period |
| 106 | |
| 107 | uint16_t counterId = 0; |
| 108 | uint32_t offset = 12; |
| 109 | |
| 110 | // Counter Ids |
| 111 | for(const uint16_t& id : selectedCounterIds) |
| 112 | { |
| 113 | counterId = ReadUint16(readBuffer3, offset); |
| 114 | BOOST_TEST(counterId == id); |
| 115 | offset += 2; |
| 116 | } |
| 117 | } |
| 118 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 119 | BOOST_AUTO_TEST_CASE(SendPeriodicCounterCapturePacketTest) |
| 120 | { |
| 121 | // Error no space left in buffer |
| 122 | MockBuffer mockBuffer1(10); |
| 123 | SendCounterPacket sendPacket1(mockBuffer1); |
| 124 | |
| 125 | auto captureTimestamp = std::chrono::steady_clock::now(); |
| 126 | uint64_t time = static_cast<uint64_t >(captureTimestamp.time_since_epoch().count()); |
| 127 | std::vector<std::pair<uint16_t, uint32_t>> indexValuePairs; |
| 128 | |
| 129 | BOOST_CHECK_THROW(sendPacket1.SendPeriodicCounterCapturePacket(time, indexValuePairs), |
| 130 | BufferExhaustion); |
| 131 | |
| 132 | // Packet without any counters |
| 133 | MockBuffer mockBuffer2(512); |
| 134 | SendCounterPacket sendPacket2(mockBuffer2); |
| 135 | |
| 136 | sendPacket2.SendPeriodicCounterCapturePacket(time, indexValuePairs); |
| 137 | unsigned int sizeRead = 0; |
| 138 | const unsigned char* readBuffer2 = mockBuffer2.GetReadBuffer(sizeRead); |
| 139 | |
| 140 | uint32_t headerWord0 = ReadUint32(readBuffer2, 0); |
| 141 | uint32_t headerWord1 = ReadUint32(readBuffer2, 4); |
| 142 | uint64_t readTimestamp = ReadUint64(readBuffer2, 8); |
| 143 | |
| 144 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 1); // packet family |
| 145 | BOOST_TEST(((headerWord0 >> 19) & 0x3F) == 0); // packet class |
| 146 | BOOST_TEST(((headerWord0 >> 16) & 0x3) == 0); // packet type |
| 147 | BOOST_TEST(headerWord1 == 8); // data length |
| 148 | BOOST_TEST(time == readTimestamp); // capture period |
| 149 | |
| 150 | // Full packet message |
| 151 | MockBuffer mockBuffer3(512); |
| 152 | SendCounterPacket sendPacket3(mockBuffer3); |
| 153 | |
| 154 | indexValuePairs.reserve(5); |
| 155 | indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t >(0, 100)); |
| 156 | indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t >(1, 200)); |
| 157 | indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t >(2, 300)); |
| 158 | indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t >(3, 400)); |
| 159 | indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t >(4, 500)); |
| 160 | sendPacket3.SendPeriodicCounterCapturePacket(time, indexValuePairs); |
| 161 | sizeRead = 0; |
| 162 | const unsigned char* readBuffer3 = mockBuffer3.GetReadBuffer(sizeRead); |
| 163 | |
| 164 | headerWord0 = ReadUint32(readBuffer3, 0); |
| 165 | headerWord1 = ReadUint32(readBuffer3, 4); |
| 166 | uint64_t readTimestamp2 = ReadUint64(readBuffer3, 8); |
| 167 | |
| 168 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 1); // packet family |
| 169 | BOOST_TEST(((headerWord0 >> 19) & 0x3F) == 0); // packet class |
| 170 | BOOST_TEST(((headerWord0 >> 16) & 0x3) == 0); // packet type |
| 171 | BOOST_TEST(headerWord1 == 38); // data length |
| 172 | BOOST_TEST(time == readTimestamp2); // capture period |
| 173 | |
| 174 | uint16_t counterIndex = 0; |
| 175 | uint32_t counterValue = 100; |
| 176 | uint32_t offset = 16; |
| 177 | |
| 178 | // Counter Ids |
| 179 | for (auto it = indexValuePairs.begin(), end = indexValuePairs.end(); it != end; ++it) |
| 180 | { |
| 181 | // Check Counter Index |
| 182 | uint16_t readIndex = ReadUint16(readBuffer3, offset); |
| 183 | BOOST_TEST(counterIndex == readIndex); |
| 184 | counterIndex++; |
| 185 | offset += 2; |
| 186 | |
| 187 | // Check Counter Value |
| 188 | uint32_t readValue = ReadUint32(readBuffer3, offset); |
| 189 | BOOST_TEST(counterValue == readValue); |
| 190 | counterValue += 100; |
| 191 | offset += 4; |
| 192 | } |
| 193 | |
| 194 | } |
| 195 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 196 | BOOST_AUTO_TEST_CASE(SendStreamMetaDataPacketTest) |
| 197 | { |
| 198 | using boost::numeric_cast; |
| 199 | |
| 200 | uint32_t sizeUint32 = numeric_cast<uint32_t>(sizeof(uint32_t)); |
| 201 | |
| 202 | // Error no space left in buffer |
| 203 | MockBuffer mockBuffer1(10); |
| 204 | SendCounterPacket sendPacket1(mockBuffer1); |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 205 | BOOST_CHECK_THROW(sendPacket1.SendStreamMetaDataPacket(), armnn::profiling::BufferExhaustion); |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 206 | |
| 207 | // Full metadata packet |
| 208 | |
| 209 | std::string processName = GetProcessName().substr(0, 60); |
| 210 | |
| 211 | uint32_t infoSize = numeric_cast<uint32_t>(GetSoftwareInfo().size()) > 0 ? |
| 212 | numeric_cast<uint32_t>(GetSoftwareInfo().size()) + 1 : 0; |
| 213 | uint32_t hardwareVersionSize = numeric_cast<uint32_t>(GetHardwareVersion().size()) > 0 ? |
| 214 | numeric_cast<uint32_t>(GetHardwareVersion().size()) + 1 : 0; |
| 215 | uint32_t softwareVersionSize = numeric_cast<uint32_t>(GetSoftwareVersion().size()) > 0 ? |
| 216 | numeric_cast<uint32_t>(GetSoftwareVersion().size()) + 1 : 0; |
| 217 | uint32_t processNameSize = numeric_cast<uint32_t>(processName.size()) > 0 ? |
| 218 | numeric_cast<uint32_t>(processName.size()) + 1 : 0; |
| 219 | |
Ferran Balaguer | 5bf1d32 | 2019-09-13 13:31:40 +0100 | [diff] [blame] | 220 | uint32_t packetEntries = 6; |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 221 | |
| 222 | MockBuffer mockBuffer2(512); |
| 223 | SendCounterPacket sendPacket2(mockBuffer2); |
| 224 | sendPacket2.SendStreamMetaDataPacket(); |
| 225 | unsigned int sizeRead = 0; |
| 226 | const unsigned char* readBuffer2 = mockBuffer2.GetReadBuffer(sizeRead); |
| 227 | |
| 228 | uint32_t headerWord0 = ReadUint32(readBuffer2, 0); |
| 229 | uint32_t headerWord1 = ReadUint32(readBuffer2, sizeUint32); |
| 230 | |
| 231 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 232 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 0); // packet id |
| 233 | |
| 234 | uint32_t totalLength = numeric_cast<uint32_t>(2 * sizeUint32 + 10 * sizeUint32 + infoSize + hardwareVersionSize + |
| 235 | softwareVersionSize + processNameSize + sizeUint32 + |
| 236 | 2 * packetEntries * sizeUint32); |
| 237 | |
| 238 | BOOST_TEST(headerWord1 == totalLength - (2 * sizeUint32)); // data length |
| 239 | |
| 240 | uint32_t offset = sizeUint32 * 2; |
| 241 | BOOST_TEST(ReadUint32(readBuffer2, offset) == SendCounterPacket::PIPE_MAGIC); // pipe_magic |
| 242 | offset += sizeUint32; |
| 243 | BOOST_TEST(ReadUint32(readBuffer2, offset) == EncodeVersion(1, 0, 0)); // stream_metadata_version |
| 244 | offset += sizeUint32; |
| 245 | BOOST_TEST(ReadUint32(readBuffer2, offset) == SendCounterPacket::MAX_METADATA_PACKET_LENGTH); // max_data_len |
| 246 | offset += sizeUint32; |
| 247 | BOOST_TEST(ReadUint32(readBuffer2, offset) == numeric_cast<uint32_t>(getpid())); // pid |
| 248 | offset += sizeUint32; |
| 249 | uint32_t poolOffset = 10 * sizeUint32; |
| 250 | BOOST_TEST(ReadUint32(readBuffer2, offset) == (infoSize ? poolOffset : 0)); // offset_info |
| 251 | offset += sizeUint32; |
| 252 | poolOffset += infoSize; |
| 253 | BOOST_TEST(ReadUint32(readBuffer2, offset) == (hardwareVersionSize ? poolOffset : 0)); // offset_hw_version |
| 254 | offset += sizeUint32; |
| 255 | poolOffset += hardwareVersionSize; |
| 256 | BOOST_TEST(ReadUint32(readBuffer2, offset) == (softwareVersionSize ? poolOffset : 0)); // offset_sw_version |
| 257 | offset += sizeUint32; |
| 258 | poolOffset += softwareVersionSize; |
| 259 | BOOST_TEST(ReadUint32(readBuffer2, offset) == (processNameSize ? poolOffset : 0)); // offset_process_name |
| 260 | offset += sizeUint32; |
| 261 | poolOffset += processNameSize; |
| 262 | BOOST_TEST(ReadUint32(readBuffer2, offset) == (packetEntries ? poolOffset : 0)); // offset_packet_version_table |
| 263 | offset += sizeUint32; |
| 264 | BOOST_TEST(ReadUint32(readBuffer2, offset) == 0); // reserved |
| 265 | |
| 266 | offset += sizeUint32; |
| 267 | if (infoSize) |
| 268 | { |
| 269 | BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readBuffer2[offset]), GetSoftwareInfo().c_str()) == 0); |
| 270 | offset += infoSize; |
| 271 | } |
| 272 | |
| 273 | if (hardwareVersionSize) |
| 274 | { |
| 275 | BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readBuffer2[offset]), GetHardwareVersion().c_str()) == 0); |
| 276 | offset += hardwareVersionSize; |
| 277 | } |
| 278 | |
| 279 | if (softwareVersionSize) |
| 280 | { |
| 281 | BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readBuffer2[offset]), GetSoftwareVersion().c_str()) == 0); |
| 282 | offset += softwareVersionSize; |
| 283 | } |
| 284 | |
| 285 | if (processNameSize) |
| 286 | { |
| 287 | BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readBuffer2[offset]), GetProcessName().c_str()) == 0); |
| 288 | offset += processNameSize; |
| 289 | } |
| 290 | |
| 291 | if (packetEntries) |
| 292 | { |
| 293 | BOOST_TEST((ReadUint32(readBuffer2, offset) >> 16) == packetEntries); |
| 294 | offset += sizeUint32; |
Ferran Balaguer | 5bf1d32 | 2019-09-13 13:31:40 +0100 | [diff] [blame] | 295 | for (uint32_t i = 0; i < packetEntries - 1; ++i) |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 296 | { |
| 297 | BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 26) & 0x3F) == 0); |
| 298 | BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 16) & 0x3FF) == i); |
| 299 | offset += sizeUint32; |
| 300 | BOOST_TEST(ReadUint32(readBuffer2, offset) == EncodeVersion(1, 0, 0)); |
| 301 | offset += sizeUint32; |
| 302 | } |
Ferran Balaguer | 5bf1d32 | 2019-09-13 13:31:40 +0100 | [diff] [blame] | 303 | |
| 304 | BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 26) & 0x3F) == 1); |
| 305 | BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 16) & 0x3FF) == 0); |
| 306 | offset += sizeUint32; |
| 307 | BOOST_TEST(ReadUint32(readBuffer2, offset) == EncodeVersion(1, 0, 0)); |
| 308 | offset += sizeUint32; |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | BOOST_TEST(offset == totalLength); |
| 312 | } |
| 313 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 314 | BOOST_AUTO_TEST_CASE(CreateDeviceRecordTest) |
| 315 | { |
| 316 | MockBuffer mockBuffer(0); |
| 317 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 318 | |
| 319 | // Create a device for testing |
| 320 | uint16_t deviceUid = 27; |
| 321 | const std::string deviceName = "some_device"; |
| 322 | uint16_t deviceCores = 3; |
| 323 | const DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, deviceCores); |
| 324 | |
| 325 | // Create a device record |
| 326 | SendCounterPacket::DeviceRecord deviceRecord; |
| 327 | std::string errorMessage; |
| 328 | bool result = sendCounterPacketTest.CreateDeviceRecordTest(device, deviceRecord, errorMessage); |
| 329 | |
| 330 | BOOST_CHECK(result); |
| 331 | BOOST_CHECK(errorMessage.empty()); |
| 332 | BOOST_CHECK(deviceRecord.size() == 6); // Size in words: header [2] + device name [4] |
| 333 | |
| 334 | uint16_t deviceRecordWord0[] |
| 335 | { |
| 336 | static_cast<uint16_t>(deviceRecord[0] >> 16), |
| 337 | static_cast<uint16_t>(deviceRecord[0]) |
| 338 | }; |
| 339 | BOOST_CHECK(deviceRecordWord0[0] == deviceUid); // uid |
| 340 | BOOST_CHECK(deviceRecordWord0[1] == deviceCores); // cores |
| 341 | BOOST_CHECK(deviceRecord[1] == 0); // name_offset |
| 342 | BOOST_CHECK(deviceRecord[2] == deviceName.size() + 1); // The length of the SWTrace string (name) |
| 343 | BOOST_CHECK(std::memcmp(deviceRecord.data() + 3, deviceName.data(), deviceName.size()) == 0); // name |
| 344 | } |
| 345 | |
| 346 | BOOST_AUTO_TEST_CASE(CreateInvalidDeviceRecordTest) |
| 347 | { |
| 348 | MockBuffer mockBuffer(0); |
| 349 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 350 | |
| 351 | // Create a device for testing |
| 352 | uint16_t deviceUid = 27; |
| 353 | const std::string deviceName = "some€£invalid‡device"; |
| 354 | uint16_t deviceCores = 3; |
| 355 | const DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, deviceCores); |
| 356 | |
| 357 | // Create a device record |
| 358 | SendCounterPacket::DeviceRecord deviceRecord; |
| 359 | std::string errorMessage; |
| 360 | bool result = sendCounterPacketTest.CreateDeviceRecordTest(device, deviceRecord, errorMessage); |
| 361 | |
| 362 | BOOST_CHECK(!result); |
| 363 | BOOST_CHECK(!errorMessage.empty()); |
| 364 | BOOST_CHECK(deviceRecord.empty()); |
| 365 | } |
| 366 | |
| 367 | BOOST_AUTO_TEST_CASE(CreateCounterSetRecordTest) |
| 368 | { |
| 369 | MockBuffer mockBuffer(0); |
| 370 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 371 | |
| 372 | // Create a counter set for testing |
| 373 | uint16_t counterSetUid = 27; |
| 374 | const std::string counterSetName = "some_counter_set"; |
| 375 | uint16_t counterSetCount = 3421; |
| 376 | const CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, counterSetCount); |
| 377 | |
| 378 | // Create a counter set record |
| 379 | SendCounterPacket::CounterSetRecord counterSetRecord; |
| 380 | std::string errorMessage; |
| 381 | bool result = sendCounterPacketTest.CreateCounterSetRecordTest(counterSet, counterSetRecord, errorMessage); |
| 382 | |
| 383 | BOOST_CHECK(result); |
| 384 | BOOST_CHECK(errorMessage.empty()); |
| 385 | BOOST_CHECK(counterSetRecord.size() == 8); // Size in words: header [2] + counter set name [6] |
| 386 | |
| 387 | uint16_t counterSetRecordWord0[] |
| 388 | { |
| 389 | static_cast<uint16_t>(counterSetRecord[0] >> 16), |
| 390 | static_cast<uint16_t>(counterSetRecord[0]) |
| 391 | }; |
| 392 | BOOST_CHECK(counterSetRecordWord0[0] == counterSetUid); // uid |
| 393 | BOOST_CHECK(counterSetRecordWord0[1] == counterSetCount); // cores |
| 394 | BOOST_CHECK(counterSetRecord[1] == 0); // name_offset |
| 395 | BOOST_CHECK(counterSetRecord[2] == counterSetName.size() + 1); // The length of the SWTrace string (name) |
| 396 | BOOST_CHECK(std::memcmp(counterSetRecord.data() + 3, counterSetName.data(), counterSetName.size()) == 0); // name |
| 397 | } |
| 398 | |
| 399 | BOOST_AUTO_TEST_CASE(CreateInvalidCounterSetRecordTest) |
| 400 | { |
| 401 | MockBuffer mockBuffer(0); |
| 402 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 403 | |
| 404 | // Create a counter set for testing |
| 405 | uint16_t counterSetUid = 27; |
| 406 | const std::string counterSetName = "some invalid_counter€£set"; |
| 407 | uint16_t counterSetCount = 3421; |
| 408 | const CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, counterSetCount); |
| 409 | |
| 410 | // Create a counter set record |
| 411 | SendCounterPacket::CounterSetRecord counterSetRecord; |
| 412 | std::string errorMessage; |
| 413 | bool result = sendCounterPacketTest.CreateCounterSetRecordTest(counterSet, counterSetRecord, errorMessage); |
| 414 | |
| 415 | BOOST_CHECK(!result); |
| 416 | BOOST_CHECK(!errorMessage.empty()); |
| 417 | BOOST_CHECK(counterSetRecord.empty()); |
| 418 | } |
| 419 | |
| 420 | BOOST_AUTO_TEST_CASE(CreateEventRecordTest) |
| 421 | { |
| 422 | MockBuffer mockBuffer(0); |
| 423 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 424 | |
| 425 | // Create a counter for testing |
| 426 | uint16_t counterUid = 7256; |
| 427 | uint16_t maxCounterUid = 132; |
| 428 | uint16_t deviceUid = 132; |
| 429 | uint16_t counterSetUid = 4497; |
| 430 | uint16_t counterClass = 1; |
| 431 | uint16_t counterInterpolation = 1; |
| 432 | double counterMultiplier = 1234.567f; |
| 433 | const std::string counterName = "some_valid_counter"; |
| 434 | const std::string counterDescription = "a_counter_for_testing"; |
| 435 | const std::string counterUnits = "Mrads2"; |
| 436 | const CounterPtr counter = std::make_unique<Counter>(counterUid, |
| 437 | maxCounterUid, |
| 438 | counterClass, |
| 439 | counterInterpolation, |
| 440 | counterMultiplier, |
| 441 | counterName, |
| 442 | counterDescription, |
| 443 | counterUnits, |
| 444 | deviceUid, |
| 445 | counterSetUid); |
| 446 | BOOST_ASSERT(counter); |
| 447 | |
| 448 | // Create an event record |
| 449 | SendCounterPacket::EventRecord eventRecord; |
| 450 | std::string errorMessage; |
| 451 | bool result = sendCounterPacketTest.CreateEventRecordTest(counter, eventRecord, errorMessage); |
| 452 | |
| 453 | BOOST_CHECK(result); |
| 454 | BOOST_CHECK(errorMessage.empty()); |
| 455 | BOOST_CHECK(eventRecord.size() == 24); // Size in words: header [8] + counter name [6] + description [7] + units [3] |
| 456 | |
| 457 | uint16_t eventRecordWord0[] |
| 458 | { |
| 459 | static_cast<uint16_t>(eventRecord[0] >> 16), |
| 460 | static_cast<uint16_t>(eventRecord[0]) |
| 461 | }; |
| 462 | uint16_t eventRecordWord1[] |
| 463 | { |
| 464 | static_cast<uint16_t>(eventRecord[1] >> 16), |
| 465 | static_cast<uint16_t>(eventRecord[1]) |
| 466 | }; |
| 467 | uint16_t eventRecordWord2[] |
| 468 | { |
| 469 | static_cast<uint16_t>(eventRecord[2] >> 16), |
| 470 | static_cast<uint16_t>(eventRecord[2]) |
| 471 | }; |
| 472 | uint32_t eventRecordWord34[] |
| 473 | { |
| 474 | eventRecord[3], |
| 475 | eventRecord[4] |
| 476 | }; |
| 477 | BOOST_CHECK(eventRecordWord0[0] == maxCounterUid); // max_counter_uid |
| 478 | BOOST_CHECK(eventRecordWord0[1] == counterUid); // counter_uid |
| 479 | BOOST_CHECK(eventRecordWord1[0] == deviceUid); // device |
| 480 | BOOST_CHECK(eventRecordWord1[1] == counterSetUid); // counter_set |
| 481 | BOOST_CHECK(eventRecordWord2[0] == counterClass); // class |
| 482 | BOOST_CHECK(eventRecordWord2[1] == counterInterpolation); // interpolation |
| 483 | BOOST_CHECK(std::memcmp(eventRecordWord34, &counterMultiplier, sizeof(counterMultiplier)) == 0); // multiplier |
| 484 | |
| 485 | ARMNN_NO_CONVERSION_WARN_BEGIN |
| 486 | uint32_t counterNameOffset = 0; // The name is the first item in pool |
| 487 | uint32_t counterDescriptionOffset = counterNameOffset + // Counter name offset |
| 488 | 4u + // Counter name length (uint32_t) |
| 489 | counterName.size() + // 18u |
| 490 | 1u + // Null-terminator |
| 491 | 1u; // Rounding to the next word |
| 492 | size_t counterUnitsOffset = counterDescriptionOffset + // Counter description offset |
| 493 | 4u + // Counter description length (uint32_t) |
| 494 | counterDescription.size() + // 21u |
| 495 | 1u + // Null-terminator |
| 496 | 2u; // Rounding to the next word |
| 497 | ARMNN_NO_CONVERSION_WARN_END |
| 498 | |
| 499 | BOOST_CHECK(eventRecord[5] == counterNameOffset); // name_offset |
| 500 | BOOST_CHECK(eventRecord[6] == counterDescriptionOffset); // description_offset |
| 501 | BOOST_CHECK(eventRecord[7] == counterUnitsOffset); // units_offset |
| 502 | |
| 503 | auto eventRecordPool = reinterpret_cast<unsigned char*>(eventRecord.data() + 8u); // The start of the pool |
| 504 | size_t uint32_t_size = sizeof(uint32_t); |
| 505 | |
| 506 | // The length of the SWTrace string (name) |
| 507 | BOOST_CHECK(eventRecordPool[counterNameOffset] == counterName.size() + 1); |
| 508 | // The counter name |
| 509 | BOOST_CHECK(std::memcmp(eventRecordPool + |
| 510 | counterNameOffset + // Offset |
| 511 | uint32_t_size /* The length of the name */, |
| 512 | counterName.data(), |
| 513 | counterName.size()) == 0); // name |
| 514 | // The null-terminator at the end of the name |
| 515 | BOOST_CHECK(eventRecordPool[counterNameOffset + uint32_t_size + counterName.size()] == '\0'); |
| 516 | |
| 517 | // The length of the SWTrace string (description) |
| 518 | BOOST_CHECK(eventRecordPool[counterDescriptionOffset] == counterDescription.size() + 1); |
| 519 | // The counter description |
| 520 | BOOST_CHECK(std::memcmp(eventRecordPool + |
| 521 | counterDescriptionOffset + // Offset |
| 522 | uint32_t_size /* The length of the description */, |
| 523 | counterDescription.data(), |
| 524 | counterDescription.size()) == 0); // description |
| 525 | // The null-terminator at the end of the description |
| 526 | BOOST_CHECK(eventRecordPool[counterDescriptionOffset + uint32_t_size + counterDescription.size()] == '\0'); |
| 527 | |
| 528 | // The length of the SWTrace namestring (units) |
| 529 | BOOST_CHECK(eventRecordPool[counterUnitsOffset] == counterUnits.size() + 1); |
| 530 | // The counter units |
| 531 | BOOST_CHECK(std::memcmp(eventRecordPool + |
| 532 | counterUnitsOffset + // Offset |
| 533 | uint32_t_size /* The length of the units */, |
| 534 | counterUnits.data(), |
| 535 | counterUnits.size()) == 0); // units |
| 536 | // The null-terminator at the end of the units |
| 537 | BOOST_CHECK(eventRecordPool[counterUnitsOffset + uint32_t_size + counterUnits.size()] == '\0'); |
| 538 | } |
| 539 | |
| 540 | BOOST_AUTO_TEST_CASE(CreateEventRecordNoUnitsTest) |
| 541 | { |
| 542 | MockBuffer mockBuffer(0); |
| 543 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 544 | |
| 545 | // Create a counter for testing |
| 546 | uint16_t counterUid = 44312; |
| 547 | uint16_t maxCounterUid = 345; |
| 548 | uint16_t deviceUid = 101; |
| 549 | uint16_t counterSetUid = 34035; |
| 550 | uint16_t counterClass = 0; |
| 551 | uint16_t counterInterpolation = 1; |
| 552 | double counterMultiplier = 4435.0023f; |
| 553 | const std::string counterName = "some_valid_counter"; |
| 554 | const std::string counterDescription = "a_counter_for_testing"; |
| 555 | const CounterPtr counter = std::make_unique<Counter>(counterUid, |
| 556 | maxCounterUid, |
| 557 | counterClass, |
| 558 | counterInterpolation, |
| 559 | counterMultiplier, |
| 560 | counterName, |
| 561 | counterDescription, |
| 562 | "", |
| 563 | deviceUid, |
| 564 | counterSetUid); |
| 565 | BOOST_ASSERT(counter); |
| 566 | |
| 567 | // Create an event record |
| 568 | SendCounterPacket::EventRecord eventRecord; |
| 569 | std::string errorMessage; |
| 570 | bool result = sendCounterPacketTest.CreateEventRecordTest(counter, eventRecord, errorMessage); |
| 571 | |
| 572 | BOOST_CHECK(result); |
| 573 | BOOST_CHECK(errorMessage.empty()); |
| 574 | BOOST_CHECK(eventRecord.size() == 21); // Size in words: header [8] + counter name [6] + description [7] |
| 575 | |
| 576 | uint16_t eventRecordWord0[] |
| 577 | { |
| 578 | static_cast<uint16_t>(eventRecord[0] >> 16), |
| 579 | static_cast<uint16_t>(eventRecord[0]) |
| 580 | }; |
| 581 | uint16_t eventRecordWord1[] |
| 582 | { |
| 583 | static_cast<uint16_t>(eventRecord[1] >> 16), |
| 584 | static_cast<uint16_t>(eventRecord[1]) |
| 585 | }; |
| 586 | uint16_t eventRecordWord2[] |
| 587 | { |
| 588 | static_cast<uint16_t>(eventRecord[2] >> 16), |
| 589 | static_cast<uint16_t>(eventRecord[2]) |
| 590 | }; |
| 591 | uint32_t eventRecordWord34[] |
| 592 | { |
| 593 | eventRecord[3], |
| 594 | eventRecord[4] |
| 595 | }; |
| 596 | BOOST_CHECK(eventRecordWord0[0] == maxCounterUid); // max_counter_uid |
| 597 | BOOST_CHECK(eventRecordWord0[1] == counterUid); // counter_uid |
| 598 | BOOST_CHECK(eventRecordWord1[0] == deviceUid); // device |
| 599 | BOOST_CHECK(eventRecordWord1[1] == counterSetUid); // counter_set |
| 600 | BOOST_CHECK(eventRecordWord2[0] == counterClass); // class |
| 601 | BOOST_CHECK(eventRecordWord2[1] == counterInterpolation); // interpolation |
| 602 | BOOST_CHECK(std::memcmp(eventRecordWord34, &counterMultiplier, sizeof(counterMultiplier)) == 0); // multiplier |
| 603 | |
| 604 | ARMNN_NO_CONVERSION_WARN_BEGIN |
| 605 | uint32_t counterNameOffset = 0; // The name is the first item in pool |
| 606 | uint32_t counterDescriptionOffset = counterNameOffset + // Counter name offset |
| 607 | 4u + // Counter name length (uint32_t) |
| 608 | counterName.size() + // 18u |
| 609 | 1u + // Null-terminator |
| 610 | 1u; // Rounding to the next word |
| 611 | ARMNN_NO_CONVERSION_WARN_END |
| 612 | |
| 613 | BOOST_CHECK(eventRecord[5] == counterNameOffset); // name_offset |
| 614 | BOOST_CHECK(eventRecord[6] == counterDescriptionOffset); // description_offset |
| 615 | BOOST_CHECK(eventRecord[7] == 0); // units_offset |
| 616 | |
| 617 | auto eventRecordPool = reinterpret_cast<unsigned char*>(eventRecord.data() + 8u); // The start of the pool |
| 618 | size_t uint32_t_size = sizeof(uint32_t); |
| 619 | |
| 620 | // The length of the SWTrace string (name) |
| 621 | BOOST_CHECK(eventRecordPool[counterNameOffset] == counterName.size() + 1); |
| 622 | // The counter name |
| 623 | BOOST_CHECK(std::memcmp(eventRecordPool + |
| 624 | counterNameOffset + // Offset |
| 625 | uint32_t_size, // The length of the name |
| 626 | counterName.data(), |
| 627 | counterName.size()) == 0); // name |
| 628 | // The null-terminator at the end of the name |
| 629 | BOOST_CHECK(eventRecordPool[counterNameOffset + uint32_t_size + counterName.size()] == '\0'); |
| 630 | |
| 631 | // The length of the SWTrace string (description) |
| 632 | BOOST_CHECK(eventRecordPool[counterDescriptionOffset] == counterDescription.size() + 1); |
| 633 | // The counter description |
| 634 | BOOST_CHECK(std::memcmp(eventRecordPool + |
| 635 | counterDescriptionOffset + // Offset |
| 636 | uint32_t_size, // The length of the description |
| 637 | counterDescription.data(), |
| 638 | counterDescription.size()) == 0); // description |
| 639 | // The null-terminator at the end of the description |
| 640 | BOOST_CHECK(eventRecordPool[counterDescriptionOffset + uint32_t_size + counterDescription.size()] == '\0'); |
| 641 | } |
| 642 | |
| 643 | BOOST_AUTO_TEST_CASE(CreateInvalidEventRecordTest1) |
| 644 | { |
| 645 | MockBuffer mockBuffer(0); |
| 646 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 647 | |
| 648 | // Create a counter for testing |
| 649 | uint16_t counterUid = 7256; |
| 650 | uint16_t maxCounterUid = 132; |
| 651 | uint16_t deviceUid = 132; |
| 652 | uint16_t counterSetUid = 4497; |
| 653 | uint16_t counterClass = 1; |
| 654 | uint16_t counterInterpolation = 1; |
| 655 | double counterMultiplier = 1234.567f; |
| 656 | const std::string counterName = "some_invalid_counter £££"; // Invalid name |
| 657 | const std::string counterDescription = "a_counter_for_testing"; |
| 658 | const std::string counterUnits = "Mrads2"; |
| 659 | const CounterPtr counter = std::make_unique<Counter>(counterUid, |
| 660 | maxCounterUid, |
| 661 | counterClass, |
| 662 | counterInterpolation, |
| 663 | counterMultiplier, |
| 664 | counterName, |
| 665 | counterDescription, |
| 666 | counterUnits, |
| 667 | deviceUid, |
| 668 | counterSetUid); |
| 669 | BOOST_ASSERT(counter); |
| 670 | |
| 671 | // Create an event record |
| 672 | SendCounterPacket::EventRecord eventRecord; |
| 673 | std::string errorMessage; |
| 674 | bool result = sendCounterPacketTest.CreateEventRecordTest(counter, eventRecord, errorMessage); |
| 675 | |
| 676 | BOOST_CHECK(!result); |
| 677 | BOOST_CHECK(!errorMessage.empty()); |
| 678 | BOOST_CHECK(eventRecord.empty()); |
| 679 | } |
| 680 | |
| 681 | BOOST_AUTO_TEST_CASE(CreateInvalidEventRecordTest2) |
| 682 | { |
| 683 | MockBuffer mockBuffer(0); |
| 684 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 685 | |
| 686 | // Create a counter for testing |
| 687 | uint16_t counterUid = 7256; |
| 688 | uint16_t maxCounterUid = 132; |
| 689 | uint16_t deviceUid = 132; |
| 690 | uint16_t counterSetUid = 4497; |
| 691 | uint16_t counterClass = 1; |
| 692 | uint16_t counterInterpolation = 1; |
| 693 | double counterMultiplier = 1234.567f; |
| 694 | const std::string counterName = "some_invalid_counter"; |
| 695 | const std::string counterDescription = "an invalid d€scription"; // Invalid description |
| 696 | const std::string counterUnits = "Mrads2"; |
| 697 | const CounterPtr counter = std::make_unique<Counter>(counterUid, |
| 698 | maxCounterUid, |
| 699 | counterClass, |
| 700 | counterInterpolation, |
| 701 | counterMultiplier, |
| 702 | counterName, |
| 703 | counterDescription, |
| 704 | counterUnits, |
| 705 | deviceUid, |
| 706 | counterSetUid); |
| 707 | BOOST_ASSERT(counter); |
| 708 | |
| 709 | // Create an event record |
| 710 | SendCounterPacket::EventRecord eventRecord; |
| 711 | std::string errorMessage; |
| 712 | bool result = sendCounterPacketTest.CreateEventRecordTest(counter, eventRecord, errorMessage); |
| 713 | |
| 714 | BOOST_CHECK(!result); |
| 715 | BOOST_CHECK(!errorMessage.empty()); |
| 716 | BOOST_CHECK(eventRecord.empty()); |
| 717 | } |
| 718 | |
| 719 | BOOST_AUTO_TEST_CASE(CreateInvalidEventRecordTest3) |
| 720 | { |
| 721 | MockBuffer mockBuffer(0); |
| 722 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 723 | |
| 724 | // Create a counter for testing |
| 725 | uint16_t counterUid = 7256; |
| 726 | uint16_t maxCounterUid = 132; |
| 727 | uint16_t deviceUid = 132; |
| 728 | uint16_t counterSetUid = 4497; |
| 729 | uint16_t counterClass = 1; |
| 730 | uint16_t counterInterpolation = 1; |
| 731 | double counterMultiplier = 1234.567f; |
| 732 | const std::string counterName = "some_invalid_counter"; |
| 733 | const std::string counterDescription = "a valid description"; |
| 734 | const std::string counterUnits = "Mrad s2"; // Invalid units |
| 735 | const CounterPtr counter = std::make_unique<Counter>(counterUid, |
| 736 | maxCounterUid, |
| 737 | counterClass, |
| 738 | counterInterpolation, |
| 739 | counterMultiplier, |
| 740 | counterName, |
| 741 | counterDescription, |
| 742 | counterUnits, |
| 743 | deviceUid, |
| 744 | counterSetUid); |
| 745 | BOOST_ASSERT(counter); |
| 746 | |
| 747 | // Create an event record |
| 748 | SendCounterPacket::EventRecord eventRecord; |
| 749 | std::string errorMessage; |
| 750 | bool result = sendCounterPacketTest.CreateEventRecordTest(counter, eventRecord, errorMessage); |
| 751 | |
| 752 | BOOST_CHECK(!result); |
| 753 | BOOST_CHECK(!errorMessage.empty()); |
| 754 | BOOST_CHECK(eventRecord.empty()); |
| 755 | } |
| 756 | |
| 757 | BOOST_AUTO_TEST_CASE(CreateCategoryRecordTest) |
| 758 | { |
| 759 | MockBuffer mockBuffer(0); |
| 760 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 761 | |
| 762 | // Create a category for testing |
| 763 | const std::string categoryName = "some_category"; |
| 764 | uint16_t deviceUid = 1302; |
| 765 | uint16_t counterSetUid = 20734; |
| 766 | const CategoryPtr category = std::make_unique<Category>(categoryName, deviceUid, counterSetUid); |
| 767 | BOOST_ASSERT(category); |
| 768 | category->m_Counters = { 11u, 23u, 5670u }; |
| 769 | |
| 770 | // Create a collection of counters |
| 771 | Counters counters; |
| 772 | counters.insert(std::make_pair<uint16_t, CounterPtr>(11, |
| 773 | CounterPtr(new Counter(11, |
| 774 | 1234, |
| 775 | 0, |
| 776 | 1, |
| 777 | 534.0003f, |
| 778 | "counter1", |
| 779 | "the first counter", |
| 780 | "millipi2", |
| 781 | 0, |
| 782 | 0)))); |
| 783 | counters.insert(std::make_pair<uint16_t, CounterPtr>(23, |
| 784 | CounterPtr(new Counter(23, |
| 785 | 344, |
| 786 | 1, |
| 787 | 1, |
| 788 | 534.0003f, |
| 789 | "this is counter 2", |
| 790 | "the second counter", |
| 791 | "", |
| 792 | 0, |
| 793 | 0)))); |
| 794 | counters.insert(std::make_pair<uint16_t, CounterPtr>(5670, |
| 795 | CounterPtr(new Counter(5670, |
| 796 | 31, |
| 797 | 0, |
| 798 | 0, |
| 799 | 534.0003f, |
| 800 | "and this is number 3", |
| 801 | "the third counter", |
| 802 | "blah_per_second", |
| 803 | 0, |
| 804 | 0)))); |
| 805 | Counter* counter1 = counters.find(11)->second.get(); |
| 806 | Counter* counter2 = counters.find(23)->second.get(); |
| 807 | Counter* counter3 = counters.find(5670)->second.get(); |
| 808 | BOOST_ASSERT(counter1); |
| 809 | BOOST_ASSERT(counter2); |
| 810 | BOOST_ASSERT(counter3); |
| 811 | uint16_t categoryEventCount = boost::numeric_cast<uint16_t>(counters.size()); |
| 812 | |
| 813 | // Create a category record |
| 814 | SendCounterPacket::CategoryRecord categoryRecord; |
| 815 | std::string errorMessage; |
| 816 | bool result = sendCounterPacketTest.CreateCategoryRecordTest(category, counters, categoryRecord, errorMessage); |
| 817 | |
| 818 | BOOST_CHECK(result); |
| 819 | BOOST_CHECK(errorMessage.empty()); |
| 820 | BOOST_CHECK(categoryRecord.size() == 80); // Size in words: header [4] + event pointer table [3] + |
| 821 | // category name [5] + event records [68 = 22 + 20 + 26] |
| 822 | |
| 823 | uint16_t categoryRecordWord0[] |
| 824 | { |
| 825 | static_cast<uint16_t>(categoryRecord[0] >> 16), |
| 826 | static_cast<uint16_t>(categoryRecord[0]) |
| 827 | }; |
| 828 | uint16_t categoryRecordWord1[] |
| 829 | { |
| 830 | static_cast<uint16_t>(categoryRecord[1] >> 16), |
| 831 | static_cast<uint16_t>(categoryRecord[1]) |
| 832 | }; |
| 833 | BOOST_CHECK(categoryRecordWord0[0] == deviceUid); // device |
| 834 | BOOST_CHECK(categoryRecordWord0[1] == counterSetUid); // counter_set |
| 835 | BOOST_CHECK(categoryRecordWord1[0] == categoryEventCount); // event_count |
| 836 | BOOST_CHECK(categoryRecordWord1[1] == 0); // reserved |
| 837 | |
| 838 | size_t uint32_t_size = sizeof(uint32_t); |
| 839 | |
| 840 | ARMNN_NO_CONVERSION_WARN_BEGIN |
| 841 | uint32_t eventPointerTableOffset = 0; // The event pointer table is the first item in pool |
| 842 | uint32_t categoryNameOffset = eventPointerTableOffset + // Event pointer table offset |
| 843 | categoryEventCount * uint32_t_size; // The size of the event pointer table |
| 844 | ARMNN_NO_CONVERSION_WARN_END |
| 845 | |
| 846 | BOOST_CHECK(categoryRecord[2] == eventPointerTableOffset); // event_pointer_table_offset |
| 847 | BOOST_CHECK(categoryRecord[3] == categoryNameOffset); // name_offset |
| 848 | |
| 849 | auto categoryRecordPool = reinterpret_cast<unsigned char*>(categoryRecord.data() + 4u); // The start of the pool |
| 850 | |
| 851 | // The event pointer table |
| 852 | uint32_t eventRecord0Offset = categoryRecordPool[eventPointerTableOffset + 0 * uint32_t_size]; |
| 853 | uint32_t eventRecord1Offset = categoryRecordPool[eventPointerTableOffset + 1 * uint32_t_size]; |
| 854 | uint32_t eventRecord2Offset = categoryRecordPool[eventPointerTableOffset + 2 * uint32_t_size]; |
| 855 | BOOST_CHECK(eventRecord0Offset == 32); |
| 856 | BOOST_CHECK(eventRecord1Offset == 120); |
| 857 | BOOST_CHECK(eventRecord2Offset == 200); |
| 858 | |
| 859 | // The length of the SWTrace namestring (name) |
| 860 | BOOST_CHECK(categoryRecordPool[categoryNameOffset] == categoryName.size() + 1); |
| 861 | // The category name |
| 862 | BOOST_CHECK(std::memcmp(categoryRecordPool + |
| 863 | categoryNameOffset + // Offset |
| 864 | uint32_t_size, // The length of the name |
| 865 | categoryName.data(), |
| 866 | categoryName.size()) == 0); // name |
| 867 | // The null-terminator at the end of the name |
| 868 | BOOST_CHECK(categoryRecordPool[categoryNameOffset + uint32_t_size + categoryName.size()] == '\0'); |
| 869 | |
| 870 | // For brevity, checking only the UIDs, max counter UIDs and names of the counters in the event records, |
| 871 | // as the event records already have a number of unit tests dedicated to them |
| 872 | |
| 873 | // Counter1 UID and max counter UID |
| 874 | uint16_t eventRecord0Word0[2] = { 0u, 0u }; |
| 875 | std::memcpy(eventRecord0Word0, categoryRecordPool + eventRecord0Offset, sizeof(eventRecord0Word0)); |
| 876 | BOOST_CHECK(eventRecord0Word0[0] == counter1->m_Uid); |
| 877 | BOOST_CHECK(eventRecord0Word0[1] == counter1->m_MaxCounterUid); |
| 878 | |
| 879 | // Counter1 name |
| 880 | uint32_t counter1NameOffset = 0; |
| 881 | std::memcpy(&counter1NameOffset, categoryRecordPool + eventRecord0Offset + 5u * uint32_t_size, uint32_t_size); |
| 882 | BOOST_CHECK(counter1NameOffset == 0); |
| 883 | // The length of the SWTrace string (name) |
| 884 | BOOST_CHECK(categoryRecordPool[eventRecord0Offset + // Offset to the event record |
| 885 | 8u * uint32_t_size + // Offset to the event record pool |
| 886 | counter1NameOffset // Offset to the name of the counter |
| 887 | ] == counter1->m_Name.size() + 1); // The length of the name including the |
| 888 | // null-terminator |
| 889 | // The counter1 name |
| 890 | BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool |
| 891 | eventRecord0Offset + // Offset to the event record |
| 892 | 8u * uint32_t_size + // Offset to the event record pool |
| 893 | counter1NameOffset + // Offset to the name of the counter |
| 894 | uint32_t_size, // The length of the name |
| 895 | counter1->m_Name.data(), |
| 896 | counter1->m_Name.size()) == 0); // name |
| 897 | // The null-terminator at the end of the counter1 name |
| 898 | BOOST_CHECK(categoryRecordPool[eventRecord0Offset + // Offset to the event record |
| 899 | 8u * uint32_t_size + // Offset to the event record pool |
| 900 | counter1NameOffset + // Offset to the name of the counter |
| 901 | uint32_t_size + // The length of the name |
| 902 | counter1->m_Name.size() // The name of the counter |
| 903 | ] == '\0'); |
| 904 | |
| 905 | // Counter2 name |
| 906 | uint32_t counter2NameOffset = 0; |
| 907 | std::memcpy(&counter2NameOffset, categoryRecordPool + eventRecord1Offset + 5u * uint32_t_size, uint32_t_size); |
| 908 | BOOST_CHECK(counter2NameOffset == 0); |
| 909 | // The length of the SWTrace string (name) |
| 910 | BOOST_CHECK(categoryRecordPool[eventRecord1Offset + // Offset to the event record |
| 911 | 8u * uint32_t_size + // Offset to the event record pool |
| 912 | counter2NameOffset // Offset to the name of the counter |
| 913 | ] == counter2->m_Name.size() + 1); // The length of the name including the |
| 914 | // null-terminator |
| 915 | // The counter2 name |
| 916 | BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool |
| 917 | eventRecord1Offset + // Offset to the event record |
| 918 | 8u * uint32_t_size + // Offset to the event record pool |
| 919 | counter2NameOffset + // Offset to the name of the counter |
| 920 | uint32_t_size, // The length of the name |
| 921 | counter2->m_Name.data(), |
| 922 | counter2->m_Name.size()) == 0); // name |
| 923 | // The null-terminator at the end of the counter2 name |
| 924 | BOOST_CHECK(categoryRecordPool[eventRecord1Offset + // Offset to the event record |
| 925 | 8u * uint32_t_size + // Offset to the event record pool |
| 926 | counter2NameOffset + // Offset to the name of the counter |
| 927 | uint32_t_size + // The length of the name |
| 928 | counter2->m_Name.size() // The name of the counter |
| 929 | ] == '\0'); |
| 930 | |
| 931 | // Counter3 name |
| 932 | uint32_t counter3NameOffset = 0; |
| 933 | std::memcpy(&counter3NameOffset, categoryRecordPool + eventRecord2Offset + 5u * uint32_t_size, uint32_t_size); |
| 934 | BOOST_CHECK(counter3NameOffset == 0); |
| 935 | // The length of the SWTrace string (name) |
| 936 | BOOST_CHECK(categoryRecordPool[eventRecord2Offset + // Offset to the event record |
| 937 | 8u * uint32_t_size + // Offset to the event record pool |
| 938 | counter3NameOffset // Offset to the name of the counter |
| 939 | ] == counter3->m_Name.size() + 1); // The length of the name including the |
| 940 | // null-terminator |
| 941 | // The counter3 name |
| 942 | BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool |
| 943 | eventRecord2Offset + // Offset to the event record |
| 944 | 8u * uint32_t_size + // Offset to the event record pool |
| 945 | counter3NameOffset + // Offset to the name of the counter |
| 946 | uint32_t_size, // The length of the name |
| 947 | counter3->m_Name.data(), |
| 948 | counter3->m_Name.size()) == 0); // name |
| 949 | // The null-terminator at the end of the counter3 name |
| 950 | BOOST_CHECK(categoryRecordPool[eventRecord2Offset + // Offset to the event record |
| 951 | 8u * uint32_t_size + // Offset to the event record pool |
| 952 | counter3NameOffset + // Offset to the name of the counter |
| 953 | uint32_t_size + // The length of the name |
| 954 | counter3->m_Name.size() // The name of the counter |
| 955 | ] == '\0'); |
| 956 | } |
| 957 | |
| 958 | BOOST_AUTO_TEST_CASE(CreateInvalidCategoryRecordTest1) |
| 959 | { |
| 960 | MockBuffer mockBuffer(0); |
| 961 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 962 | |
| 963 | // Create a category for testing |
| 964 | const std::string categoryName = "some invalid category"; |
| 965 | uint16_t deviceUid = 1302; |
| 966 | uint16_t counterSetUid = 20734; |
| 967 | const CategoryPtr category = std::make_unique<Category>(categoryName, deviceUid, counterSetUid); |
| 968 | BOOST_CHECK(category); |
| 969 | |
| 970 | // Create a category record |
| 971 | Counters counters; |
| 972 | SendCounterPacket::CategoryRecord categoryRecord; |
| 973 | std::string errorMessage; |
| 974 | bool result = sendCounterPacketTest.CreateCategoryRecordTest(category, counters, categoryRecord, errorMessage); |
| 975 | |
| 976 | BOOST_CHECK(!result); |
| 977 | BOOST_CHECK(!errorMessage.empty()); |
| 978 | BOOST_CHECK(categoryRecord.empty()); |
| 979 | } |
| 980 | |
| 981 | BOOST_AUTO_TEST_CASE(CreateInvalidCategoryRecordTest2) |
| 982 | { |
| 983 | MockBuffer mockBuffer(0); |
| 984 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
| 985 | |
| 986 | // Create a category for testing |
| 987 | const std::string categoryName = "some_category"; |
| 988 | uint16_t deviceUid = 1302; |
| 989 | uint16_t counterSetUid = 20734; |
| 990 | const CategoryPtr category = std::make_unique<Category>(categoryName, deviceUid, counterSetUid); |
| 991 | BOOST_CHECK(category); |
| 992 | category->m_Counters = { 11u, 23u, 5670u }; |
| 993 | |
| 994 | // Create a collection of counters |
| 995 | Counters counters; |
| 996 | counters.insert(std::make_pair<uint16_t, CounterPtr>(11, |
| 997 | CounterPtr(new Counter(11, |
| 998 | 1234, |
| 999 | 0, |
| 1000 | 1, |
| 1001 | 534.0003f, |
| 1002 | "count€r1", // Invalid name |
| 1003 | "the first counter", |
| 1004 | "millipi2", |
| 1005 | 0, |
| 1006 | 0)))); |
| 1007 | |
| 1008 | Counter* counter1 = counters.find(11)->second.get(); |
| 1009 | BOOST_CHECK(counter1); |
| 1010 | |
| 1011 | // Create a category record |
| 1012 | SendCounterPacket::CategoryRecord categoryRecord; |
| 1013 | std::string errorMessage; |
| 1014 | bool result = sendCounterPacketTest.CreateCategoryRecordTest(category, counters, categoryRecord, errorMessage); |
| 1015 | |
| 1016 | BOOST_CHECK(!result); |
| 1017 | BOOST_CHECK(!errorMessage.empty()); |
| 1018 | BOOST_CHECK(categoryRecord.empty()); |
| 1019 | } |
| 1020 | |
| 1021 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest1) |
| 1022 | { |
| 1023 | // The counter directory used for testing |
| 1024 | CounterDirectory counterDirectory; |
| 1025 | |
| 1026 | // Register a device |
| 1027 | const std::string device1Name = "device1"; |
| 1028 | const Device* device1 = nullptr; |
| 1029 | BOOST_CHECK_NO_THROW(device1 = counterDirectory.RegisterDevice(device1Name, 3)); |
| 1030 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1031 | BOOST_CHECK(device1); |
| 1032 | |
| 1033 | // Register a device |
| 1034 | const std::string device2Name = "device2"; |
| 1035 | const Device* device2 = nullptr; |
| 1036 | BOOST_CHECK_NO_THROW(device2 = counterDirectory.RegisterDevice(device2Name)); |
| 1037 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 1038 | BOOST_CHECK(device2); |
| 1039 | |
| 1040 | // Buffer with not enough space |
| 1041 | MockBuffer mockBuffer(10); |
| 1042 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 1043 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), |
| 1044 | armnn::profiling::BufferExhaustion); |
| 1045 | } |
| 1046 | |
| 1047 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2) |
| 1048 | { |
| 1049 | // The counter directory used for testing |
| 1050 | CounterDirectory counterDirectory; |
| 1051 | |
| 1052 | // Register a device |
| 1053 | const std::string device1Name = "device1"; |
| 1054 | const Device* device1 = nullptr; |
| 1055 | BOOST_CHECK_NO_THROW(device1 = counterDirectory.RegisterDevice(device1Name, 3)); |
| 1056 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1057 | BOOST_CHECK(device1); |
| 1058 | |
| 1059 | // Register a device |
| 1060 | const std::string device2Name = "device2"; |
| 1061 | const Device* device2 = nullptr; |
| 1062 | BOOST_CHECK_NO_THROW(device2 = counterDirectory.RegisterDevice(device2Name)); |
| 1063 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 1064 | BOOST_CHECK(device2); |
| 1065 | |
| 1066 | // Register a counter set |
| 1067 | const std::string counterSet1Name = "counterset1"; |
| 1068 | const CounterSet* counterSet1 = nullptr; |
| 1069 | BOOST_CHECK_NO_THROW(counterSet1 = counterDirectory.RegisterCounterSet(counterSet1Name)); |
| 1070 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1071 | BOOST_CHECK(counterSet1); |
| 1072 | |
| 1073 | // Register a category associated to "device1" and "counterset1" |
| 1074 | const std::string category1Name = "category1"; |
| 1075 | const Category* category1 = nullptr; |
| 1076 | BOOST_CHECK_NO_THROW(category1 = counterDirectory.RegisterCategory(category1Name, |
| 1077 | device1->m_Uid, |
| 1078 | counterSet1->m_Uid)); |
| 1079 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1080 | BOOST_CHECK(category1); |
| 1081 | |
| 1082 | // Register a category not associated to "device2" but no counter set |
| 1083 | const std::string category2Name = "category2"; |
| 1084 | const Category* category2 = nullptr; |
| 1085 | BOOST_CHECK_NO_THROW(category2 = counterDirectory.RegisterCategory(category2Name, |
| 1086 | device2->m_Uid)); |
| 1087 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 1088 | BOOST_CHECK(category2); |
| 1089 | |
| 1090 | // Register a counter associated to "category1" |
| 1091 | const Counter* counter1 = nullptr; |
| 1092 | BOOST_CHECK_NO_THROW(counter1 = counterDirectory.RegisterCounter(category1Name, |
| 1093 | 0, |
| 1094 | 1, |
| 1095 | 123.45f, |
| 1096 | "counter1", |
| 1097 | "counter1description", |
| 1098 | std::string("counter1units"))); |
| 1099 | BOOST_CHECK(counterDirectory.GetCounterCount() == 3); |
| 1100 | BOOST_CHECK(counter1); |
| 1101 | |
| 1102 | // Register a counter associated to "category1" |
| 1103 | const Counter* counter2 = nullptr; |
| 1104 | BOOST_CHECK_NO_THROW(counter2 = counterDirectory.RegisterCounter(category1Name, |
| 1105 | 1, |
| 1106 | 0, |
| 1107 | 330.1245656765f, |
| 1108 | "counter2", |
| 1109 | "counter2description", |
| 1110 | std::string("counter2units"), |
| 1111 | armnn::EmptyOptional(), |
| 1112 | device2->m_Uid, |
| 1113 | 0)); |
| 1114 | BOOST_CHECK(counterDirectory.GetCounterCount() == 4); |
| 1115 | BOOST_CHECK(counter2); |
| 1116 | |
| 1117 | // Register a counter associated to "category2" |
| 1118 | const Counter* counter3 = nullptr; |
| 1119 | BOOST_CHECK_NO_THROW(counter3 = counterDirectory.RegisterCounter(category2Name, |
| 1120 | 1, |
| 1121 | 1, |
| 1122 | 0.0000045399f, |
| 1123 | "counter3", |
| 1124 | "counter3description", |
| 1125 | armnn::EmptyOptional(), |
| 1126 | 5, |
| 1127 | device2->m_Uid, |
| 1128 | counterSet1->m_Uid)); |
| 1129 | BOOST_CHECK(counterDirectory.GetCounterCount() == 9); |
| 1130 | BOOST_CHECK(counter3); |
| 1131 | |
| 1132 | // Buffer with enough space |
| 1133 | MockBuffer mockBuffer(1024); |
| 1134 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 1135 | BOOST_CHECK_NO_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory)); |
| 1136 | |
| 1137 | // Get the read buffer |
| 1138 | unsigned int sizeRead = 0; |
| 1139 | const unsigned char* readBuffer = mockBuffer.GetReadBuffer(sizeRead); |
| 1140 | |
| 1141 | // Check the packet header |
| 1142 | uint32_t packetHeaderWord0 = ReadUint32(readBuffer, 0); |
| 1143 | uint32_t packetHeaderWord1 = ReadUint32(readBuffer, 4); |
| 1144 | BOOST_TEST(((packetHeaderWord0 >> 26) & 0x3F) == 0); // packet_family |
| 1145 | BOOST_TEST(((packetHeaderWord0 >> 16) & 0x3FF) == 2); // packet_id |
| 1146 | BOOST_TEST(packetHeaderWord1 == 944); // data_length |
| 1147 | |
| 1148 | // Check the body header |
| 1149 | uint32_t bodyHeaderWord0 = ReadUint32(readBuffer, 8); |
| 1150 | uint32_t bodyHeaderWord1 = ReadUint32(readBuffer, 12); |
| 1151 | uint32_t bodyHeaderWord2 = ReadUint32(readBuffer, 16); |
| 1152 | uint32_t bodyHeaderWord3 = ReadUint32(readBuffer, 20); |
| 1153 | uint32_t bodyHeaderWord4 = ReadUint32(readBuffer, 24); |
| 1154 | uint32_t bodyHeaderWord5 = ReadUint32(readBuffer, 28); |
| 1155 | uint16_t deviceRecordCount = static_cast<uint16_t>(bodyHeaderWord0 >> 16); |
| 1156 | uint16_t counterSetRecordCount = static_cast<uint16_t>(bodyHeaderWord2 >> 16); |
| 1157 | uint16_t categoryRecordCount = static_cast<uint16_t>(bodyHeaderWord4 >> 16); |
| 1158 | BOOST_TEST(deviceRecordCount == 2); // device_records_count |
| 1159 | BOOST_TEST(bodyHeaderWord1 == 0); // device_records_pointer_table_offset |
| 1160 | BOOST_TEST(counterSetRecordCount == 1); // counter_set_count |
| 1161 | BOOST_TEST(bodyHeaderWord3 == 8); // counter_set_pointer_table_offset |
| 1162 | BOOST_TEST(categoryRecordCount == 2); // categories_count |
| 1163 | BOOST_TEST(bodyHeaderWord5 == 12); // categories_pointer_table_offset |
| 1164 | |
| 1165 | // Check the device records pointer table |
| 1166 | uint32_t deviceRecordOffset0 = ReadUint32(readBuffer, 32); |
| 1167 | uint32_t deviceRecordOffset1 = ReadUint32(readBuffer, 36); |
| 1168 | BOOST_TEST(deviceRecordOffset0 == 0); // Device record offset for "device1" |
| 1169 | BOOST_TEST(deviceRecordOffset1 == 20); // Device record offset for "device2" |
| 1170 | |
| 1171 | // Check the counter set pointer table |
| 1172 | uint32_t counterSetRecordOffset0 = ReadUint32(readBuffer, 40); |
| 1173 | BOOST_TEST(counterSetRecordOffset0 == 40); // Counter set record offset for "counterset1" |
| 1174 | |
| 1175 | // Check the category pointer table |
| 1176 | uint32_t categoryRecordOffset0 = ReadUint32(readBuffer, 44); |
| 1177 | uint32_t categoryRecordOffset1 = ReadUint32(readBuffer, 48); |
| 1178 | BOOST_TEST(categoryRecordOffset0 == 64); // Category record offset for "category1" |
| 1179 | BOOST_TEST(categoryRecordOffset1 == 476); // Category record offset for "category2" |
| 1180 | |
| 1181 | // Get the device record pool offset |
| 1182 | uint32_t uint32_t_size = sizeof(uint32_t); |
| 1183 | uint32_t packetBodyPoolOffset = 2u * uint32_t_size + // packet_header |
| 1184 | 6u * uint32_t_size + // body_header |
| 1185 | deviceRecordCount * uint32_t_size + // Size of device_records_pointer_table |
| 1186 | counterSetRecordCount * uint32_t_size + // Size of counter_set_pointer_table |
| 1187 | categoryRecordCount * uint32_t_size; // Size of categories_pointer_table |
| 1188 | |
| 1189 | // Device record structure/collection used for testing |
| 1190 | struct DeviceRecord |
| 1191 | { |
| 1192 | uint16_t uid; |
| 1193 | uint16_t cores; |
| 1194 | uint32_t name_offset; |
| 1195 | uint32_t name_length; |
| 1196 | std::string name; |
| 1197 | }; |
| 1198 | std::vector<DeviceRecord> deviceRecords; |
| 1199 | uint32_t deviceRecordsPointerTableOffset = 2u * uint32_t_size + // packet_header |
| 1200 | 6u * uint32_t_size + // body_header |
| 1201 | bodyHeaderWord1; // device_records_pointer_table_offset |
| 1202 | for (uint32_t i = 0; i < deviceRecordCount; i++) |
| 1203 | { |
| 1204 | // Get the device record offset |
| 1205 | uint32_t deviceRecordOffset = ReadUint32(readBuffer, deviceRecordsPointerTableOffset + i * uint32_t_size); |
| 1206 | |
| 1207 | // Collect the data for the device record |
| 1208 | uint32_t deviceRecordWord0 = ReadUint32(readBuffer, |
| 1209 | packetBodyPoolOffset + deviceRecordOffset + 0 * uint32_t_size); |
| 1210 | uint32_t deviceRecordWord1 = ReadUint32(readBuffer, |
| 1211 | packetBodyPoolOffset + deviceRecordOffset + 1 * uint32_t_size); |
| 1212 | DeviceRecord deviceRecord; |
| 1213 | deviceRecord.uid = static_cast<uint16_t>(deviceRecordWord0 >> 16); // uid |
| 1214 | deviceRecord.cores = static_cast<uint16_t>(deviceRecordWord0); // cores |
| 1215 | deviceRecord.name_offset = deviceRecordWord1; // name_offset |
| 1216 | |
| 1217 | uint32_t deviceRecordPoolOffset = packetBodyPoolOffset + // Packet body offset |
| 1218 | deviceRecordOffset + // Device record offset |
| 1219 | 2 * uint32_t_size + // Device record header |
| 1220 | deviceRecord.name_offset; // Device name offset |
| 1221 | uint32_t deviceRecordNameLength = ReadUint32(readBuffer, deviceRecordPoolOffset); |
| 1222 | deviceRecord.name_length = deviceRecordNameLength; // name_length |
| 1223 | unsigned char deviceRecordNameNullTerminator = // name null-terminator |
| 1224 | ReadUint8(readBuffer, deviceRecordPoolOffset + uint32_t_size + deviceRecordNameLength - 1); |
| 1225 | BOOST_CHECK(deviceRecordNameNullTerminator == '\0'); |
| 1226 | std::vector<unsigned char> deviceRecordNameBuffer(deviceRecord.name_length - 1); |
| 1227 | std::memcpy(deviceRecordNameBuffer.data(), |
| 1228 | readBuffer + deviceRecordPoolOffset + uint32_t_size, deviceRecordNameBuffer.size()); |
| 1229 | deviceRecord.name.assign(deviceRecordNameBuffer.begin(), deviceRecordNameBuffer.end()); // name |
| 1230 | |
| 1231 | deviceRecords.push_back(deviceRecord); |
| 1232 | } |
| 1233 | |
| 1234 | // Check that the device records are correct |
| 1235 | BOOST_CHECK(deviceRecords.size() == 2); |
| 1236 | for (const DeviceRecord& deviceRecord : deviceRecords) |
| 1237 | { |
| 1238 | const Device* device = counterDirectory.GetDevice(deviceRecord.uid); |
| 1239 | BOOST_CHECK(device); |
| 1240 | BOOST_CHECK(device->m_Uid == deviceRecord.uid); |
| 1241 | BOOST_CHECK(device->m_Cores == deviceRecord.cores); |
| 1242 | BOOST_CHECK(device->m_Name == deviceRecord.name); |
| 1243 | } |
| 1244 | |
| 1245 | // Counter set record structure/collection used for testing |
| 1246 | struct CounterSetRecord |
| 1247 | { |
| 1248 | uint16_t uid; |
| 1249 | uint16_t count; |
| 1250 | uint32_t name_offset; |
| 1251 | uint32_t name_length; |
| 1252 | std::string name; |
| 1253 | }; |
| 1254 | std::vector<CounterSetRecord> counterSetRecords; |
| 1255 | uint32_t counterSetRecordsPointerTableOffset = 2u * uint32_t_size + // packet_header |
| 1256 | 6u * uint32_t_size + // body_header |
| 1257 | bodyHeaderWord3; // counter_set_pointer_table_offset |
| 1258 | for (uint32_t i = 0; i < counterSetRecordCount; i++) |
| 1259 | { |
| 1260 | // Get the counter set record offset |
| 1261 | uint32_t counterSetRecordOffset = ReadUint32(readBuffer, |
| 1262 | counterSetRecordsPointerTableOffset + i * uint32_t_size); |
| 1263 | |
| 1264 | // Collect the data for the counter set record |
| 1265 | uint32_t counterSetRecordWord0 = ReadUint32(readBuffer, |
| 1266 | packetBodyPoolOffset + counterSetRecordOffset + 0 * uint32_t_size); |
| 1267 | uint32_t counterSetRecordWord1 = ReadUint32(readBuffer, |
| 1268 | packetBodyPoolOffset + counterSetRecordOffset + 1 * uint32_t_size); |
| 1269 | CounterSetRecord counterSetRecord; |
| 1270 | counterSetRecord.uid = static_cast<uint16_t>(counterSetRecordWord0 >> 16); // uid |
| 1271 | counterSetRecord.count = static_cast<uint16_t>(counterSetRecordWord0); // count |
| 1272 | counterSetRecord.name_offset = counterSetRecordWord1; // name_offset |
| 1273 | |
| 1274 | uint32_t counterSetRecordPoolOffset = packetBodyPoolOffset + // Packet body offset |
| 1275 | counterSetRecordOffset + // Counter set record offset |
| 1276 | 2 * uint32_t_size + // Counter set record header |
| 1277 | counterSetRecord.name_offset; // Counter set name offset |
| 1278 | uint32_t counterSetRecordNameLength = ReadUint32(readBuffer, counterSetRecordPoolOffset); |
| 1279 | counterSetRecord.name_length = counterSetRecordNameLength; // name_length |
| 1280 | unsigned char counterSetRecordNameNullTerminator = // name null-terminator |
| 1281 | ReadUint8(readBuffer, counterSetRecordPoolOffset + uint32_t_size + counterSetRecordNameLength - 1); |
| 1282 | BOOST_CHECK(counterSetRecordNameNullTerminator == '\0'); |
| 1283 | std::vector<unsigned char> counterSetRecordNameBuffer(counterSetRecord.name_length - 1); |
| 1284 | std::memcpy(counterSetRecordNameBuffer.data(), |
| 1285 | readBuffer + counterSetRecordPoolOffset + uint32_t_size, counterSetRecordNameBuffer.size()); |
| 1286 | counterSetRecord.name.assign(counterSetRecordNameBuffer.begin(), counterSetRecordNameBuffer.end()); // name |
| 1287 | |
| 1288 | counterSetRecords.push_back(counterSetRecord); |
| 1289 | } |
| 1290 | |
| 1291 | // Check that the counter set records are correct |
| 1292 | BOOST_CHECK(counterSetRecords.size() == 1); |
| 1293 | for (const CounterSetRecord& counterSetRecord : counterSetRecords) |
| 1294 | { |
| 1295 | const CounterSet* counterSet = counterDirectory.GetCounterSet(counterSetRecord.uid); |
| 1296 | BOOST_CHECK(counterSet); |
| 1297 | BOOST_CHECK(counterSet->m_Uid == counterSetRecord.uid); |
| 1298 | BOOST_CHECK(counterSet->m_Count == counterSetRecord.count); |
| 1299 | BOOST_CHECK(counterSet->m_Name == counterSetRecord.name); |
| 1300 | } |
| 1301 | |
| 1302 | // Event record structure/collection used for testing |
| 1303 | struct EventRecord |
| 1304 | { |
| 1305 | uint16_t counter_uid; |
| 1306 | uint16_t max_counter_uid; |
| 1307 | uint16_t device; |
| 1308 | uint16_t counter_set; |
| 1309 | uint16_t counter_class; |
| 1310 | uint16_t interpolation; |
| 1311 | double multiplier; |
| 1312 | uint32_t name_offset; |
| 1313 | uint32_t name_length; |
| 1314 | std::string name; |
| 1315 | uint32_t description_offset; |
| 1316 | uint32_t description_length; |
| 1317 | std::string description; |
| 1318 | uint32_t units_offset; |
| 1319 | uint32_t units_length; |
| 1320 | std::string units; |
| 1321 | }; |
| 1322 | // Category record structure/collection used for testing |
| 1323 | struct CategoryRecord |
| 1324 | { |
| 1325 | uint16_t device; |
| 1326 | uint16_t counter_set; |
| 1327 | uint16_t event_count; |
| 1328 | uint32_t event_pointer_table_offset; |
| 1329 | uint32_t name_offset; |
| 1330 | uint32_t name_length; |
| 1331 | std::string name; |
| 1332 | std::vector<uint32_t> event_pointer_table; |
| 1333 | std::vector<EventRecord> event_records; |
| 1334 | }; |
| 1335 | std::vector<CategoryRecord> categoryRecords; |
| 1336 | uint32_t categoryRecordsPointerTableOffset = 2u * uint32_t_size + // packet_header |
| 1337 | 6u * uint32_t_size + // body_header |
| 1338 | bodyHeaderWord5; // categories_pointer_table_offset |
| 1339 | for (uint32_t i = 0; i < categoryRecordCount; i++) |
| 1340 | { |
| 1341 | // Get the category record offset |
| 1342 | uint32_t categoryRecordOffset = ReadUint32(readBuffer, categoryRecordsPointerTableOffset + i * uint32_t_size); |
| 1343 | |
| 1344 | // Collect the data for the category record |
| 1345 | uint32_t categoryRecordWord0 = ReadUint32(readBuffer, |
| 1346 | packetBodyPoolOffset + categoryRecordOffset + 0 * uint32_t_size); |
| 1347 | uint32_t categoryRecordWord1 = ReadUint32(readBuffer, |
| 1348 | packetBodyPoolOffset + categoryRecordOffset + 1 * uint32_t_size); |
| 1349 | uint32_t categoryRecordWord2 = ReadUint32(readBuffer, |
| 1350 | packetBodyPoolOffset + categoryRecordOffset + 2 * uint32_t_size); |
| 1351 | uint32_t categoryRecordWord3 = ReadUint32(readBuffer, |
| 1352 | packetBodyPoolOffset + categoryRecordOffset + 3 * uint32_t_size); |
| 1353 | CategoryRecord categoryRecord; |
| 1354 | categoryRecord.device = static_cast<uint16_t>(categoryRecordWord0 >> 16); // device |
| 1355 | categoryRecord.counter_set = static_cast<uint16_t>(categoryRecordWord0); // counter_set |
| 1356 | categoryRecord.event_count = static_cast<uint16_t>(categoryRecordWord1 >> 16); // event_count |
| 1357 | categoryRecord.event_pointer_table_offset = categoryRecordWord2; // event_pointer_table_offset |
| 1358 | categoryRecord.name_offset = categoryRecordWord3; // name_offset |
| 1359 | |
| 1360 | uint32_t categoryRecordPoolOffset = packetBodyPoolOffset + // Packet body offset |
| 1361 | categoryRecordOffset + // Category record offset |
| 1362 | 4 * uint32_t_size; // Category record header |
| 1363 | |
| 1364 | uint32_t categoryRecordNameLength = ReadUint32(readBuffer, |
| 1365 | categoryRecordPoolOffset + categoryRecord.name_offset); |
| 1366 | categoryRecord.name_length = categoryRecordNameLength; // name_length |
| 1367 | unsigned char categoryRecordNameNullTerminator = |
| 1368 | ReadUint8(readBuffer, |
| 1369 | categoryRecordPoolOffset + |
| 1370 | categoryRecord.name_offset + |
| 1371 | uint32_t_size + |
| 1372 | categoryRecordNameLength - 1); // name null-terminator |
| 1373 | BOOST_CHECK(categoryRecordNameNullTerminator == '\0'); |
| 1374 | std::vector<unsigned char> categoryRecordNameBuffer(categoryRecord.name_length - 1); |
| 1375 | std::memcpy(categoryRecordNameBuffer.data(), |
| 1376 | readBuffer + |
| 1377 | categoryRecordPoolOffset + |
| 1378 | categoryRecord.name_offset + |
| 1379 | uint32_t_size, |
| 1380 | categoryRecordNameBuffer.size()); |
| 1381 | categoryRecord.name.assign(categoryRecordNameBuffer.begin(), categoryRecordNameBuffer.end()); // name |
| 1382 | |
| 1383 | categoryRecord.event_pointer_table.resize(categoryRecord.event_count); |
| 1384 | for (uint32_t eventIndex = 0; eventIndex < categoryRecord.event_count; eventIndex++) |
| 1385 | { |
| 1386 | uint32_t eventRecordOffset = ReadUint32(readBuffer, |
| 1387 | categoryRecordPoolOffset + |
| 1388 | categoryRecord.event_pointer_table_offset + |
| 1389 | eventIndex * uint32_t_size); |
| 1390 | categoryRecord.event_pointer_table[eventIndex] = eventRecordOffset; |
| 1391 | |
| 1392 | // Collect the data for the event record |
| 1393 | uint32_t eventRecordWord0 = ReadUint32(readBuffer, |
| 1394 | categoryRecordPoolOffset + eventRecordOffset + 0 * uint32_t_size); |
| 1395 | uint32_t eventRecordWord1 = ReadUint32(readBuffer, |
| 1396 | categoryRecordPoolOffset + eventRecordOffset + 1 * uint32_t_size); |
| 1397 | uint32_t eventRecordWord2 = ReadUint32(readBuffer, |
| 1398 | categoryRecordPoolOffset + eventRecordOffset + 2 * uint32_t_size); |
| 1399 | uint64_t eventRecordWord34 = ReadUint64(readBuffer, |
| 1400 | categoryRecordPoolOffset + eventRecordOffset + 3 * uint32_t_size); |
| 1401 | uint32_t eventRecordWord5 = ReadUint32(readBuffer, |
| 1402 | categoryRecordPoolOffset + eventRecordOffset + 5 * uint32_t_size); |
| 1403 | uint32_t eventRecordWord6 = ReadUint32(readBuffer, |
| 1404 | categoryRecordPoolOffset + eventRecordOffset + 6 * uint32_t_size); |
| 1405 | uint32_t eventRecordWord7 = ReadUint32(readBuffer, |
| 1406 | categoryRecordPoolOffset + eventRecordOffset + 7 * uint32_t_size); |
| 1407 | EventRecord eventRecord; |
| 1408 | eventRecord.counter_uid = static_cast<uint16_t>(eventRecordWord0); // counter_uid |
| 1409 | eventRecord.max_counter_uid = static_cast<uint16_t>(eventRecordWord0 >> 16); // max_counter_uid |
| 1410 | eventRecord.device = static_cast<uint16_t>(eventRecordWord1 >> 16); // device |
| 1411 | eventRecord.counter_set = static_cast<uint16_t>(eventRecordWord1); // counter_set |
| 1412 | eventRecord.counter_class = static_cast<uint16_t>(eventRecordWord2 >> 16); // class |
| 1413 | eventRecord.interpolation = static_cast<uint16_t>(eventRecordWord2); // interpolation |
| 1414 | std::memcpy(&eventRecord.multiplier, &eventRecordWord34, sizeof(eventRecord.multiplier)); // multiplier |
| 1415 | eventRecord.name_offset = static_cast<uint32_t>(eventRecordWord5); // name_offset |
| 1416 | eventRecord.description_offset = static_cast<uint32_t>(eventRecordWord6); // description_offset |
| 1417 | eventRecord.units_offset = static_cast<uint32_t>(eventRecordWord7); // units_offset |
| 1418 | |
| 1419 | uint32_t eventRecordPoolOffset = categoryRecordPoolOffset + // Category record pool offset |
| 1420 | eventRecordOffset + // Event record offset |
| 1421 | 8 * uint32_t_size; // Event record header |
| 1422 | |
| 1423 | uint32_t eventRecordNameLength = ReadUint32(readBuffer, |
| 1424 | eventRecordPoolOffset + eventRecord.name_offset); |
| 1425 | eventRecord.name_length = eventRecordNameLength; // name_length |
| 1426 | unsigned char eventRecordNameNullTerminator = |
| 1427 | ReadUint8(readBuffer, |
| 1428 | eventRecordPoolOffset + |
| 1429 | eventRecord.name_offset + |
| 1430 | uint32_t_size + |
| 1431 | eventRecordNameLength - 1); // name null-terminator |
| 1432 | BOOST_CHECK(eventRecordNameNullTerminator == '\0'); |
| 1433 | std::vector<unsigned char> eventRecordNameBuffer(eventRecord.name_length - 1); |
| 1434 | std::memcpy(eventRecordNameBuffer.data(), |
| 1435 | readBuffer + |
| 1436 | eventRecordPoolOffset + |
| 1437 | eventRecord.name_offset + |
| 1438 | uint32_t_size, |
| 1439 | eventRecordNameBuffer.size()); |
| 1440 | eventRecord.name.assign(eventRecordNameBuffer.begin(), eventRecordNameBuffer.end()); // name |
| 1441 | |
| 1442 | uint32_t eventRecordDescriptionLength = ReadUint32(readBuffer, |
| 1443 | eventRecordPoolOffset + eventRecord.description_offset); |
| 1444 | eventRecord.description_length = eventRecordDescriptionLength; // description_length |
| 1445 | unsigned char eventRecordDescriptionNullTerminator = |
| 1446 | ReadUint8(readBuffer, |
| 1447 | eventRecordPoolOffset + |
| 1448 | eventRecord.description_offset + |
| 1449 | uint32_t_size + |
| 1450 | eventRecordDescriptionLength - 1); // description null-terminator |
| 1451 | BOOST_CHECK(eventRecordDescriptionNullTerminator == '\0'); |
| 1452 | std::vector<unsigned char> eventRecordDescriptionBuffer(eventRecord.description_length - 1); |
| 1453 | std::memcpy(eventRecordDescriptionBuffer.data(), |
| 1454 | readBuffer + |
| 1455 | eventRecordPoolOffset + |
| 1456 | eventRecord.description_offset + |
| 1457 | uint32_t_size, |
| 1458 | eventRecordDescriptionBuffer.size()); |
| 1459 | eventRecord.description.assign(eventRecordDescriptionBuffer.begin(), |
| 1460 | eventRecordDescriptionBuffer.end()); // description |
| 1461 | |
| 1462 | if (eventRecord.units_offset > 0) |
| 1463 | { |
| 1464 | uint32_t eventRecordUnitsLength = ReadUint32(readBuffer, |
| 1465 | eventRecordPoolOffset + eventRecord.units_offset); |
| 1466 | eventRecord.units_length = eventRecordUnitsLength; // units_length |
| 1467 | unsigned char eventRecordUnitsNullTerminator = |
| 1468 | ReadUint8(readBuffer, |
| 1469 | eventRecordPoolOffset + |
| 1470 | eventRecord.units_offset + |
| 1471 | uint32_t_size + |
| 1472 | eventRecordUnitsLength - 1); // units null-terminator |
| 1473 | BOOST_CHECK(eventRecordUnitsNullTerminator == '\0'); |
| 1474 | std::vector<unsigned char> eventRecordUnitsBuffer(eventRecord.units_length - 1); |
| 1475 | std::memcpy(eventRecordUnitsBuffer.data(), |
| 1476 | readBuffer + |
| 1477 | eventRecordPoolOffset + |
| 1478 | eventRecord.units_offset + |
| 1479 | uint32_t_size, |
| 1480 | eventRecordUnitsBuffer.size()); |
| 1481 | eventRecord.units.assign(eventRecordUnitsBuffer.begin(), eventRecordUnitsBuffer.end()); // units |
| 1482 | } |
| 1483 | |
| 1484 | categoryRecord.event_records.push_back(eventRecord); |
| 1485 | } |
| 1486 | |
| 1487 | categoryRecords.push_back(categoryRecord); |
| 1488 | } |
| 1489 | |
| 1490 | // Check that the category records are correct |
| 1491 | BOOST_CHECK(categoryRecords.size() == 2); |
| 1492 | for (const CategoryRecord& categoryRecord : categoryRecords) |
| 1493 | { |
| 1494 | const Category* category = counterDirectory.GetCategory(categoryRecord.name); |
| 1495 | BOOST_CHECK(category); |
| 1496 | BOOST_CHECK(category->m_Name == categoryRecord.name); |
| 1497 | BOOST_CHECK(category->m_DeviceUid == categoryRecord.device); |
| 1498 | BOOST_CHECK(category->m_CounterSetUid == categoryRecord.counter_set); |
| 1499 | BOOST_CHECK(category->m_Counters.size() == categoryRecord.event_count); |
| 1500 | |
| 1501 | // Check that the event records are correct |
| 1502 | for (const EventRecord& eventRecord : categoryRecord.event_records) |
| 1503 | { |
| 1504 | const Counter* counter = counterDirectory.GetCounter(eventRecord.counter_uid); |
| 1505 | BOOST_CHECK(counter); |
| 1506 | BOOST_CHECK(counter->m_MaxCounterUid == eventRecord.max_counter_uid); |
| 1507 | BOOST_CHECK(counter->m_DeviceUid == eventRecord.device); |
| 1508 | BOOST_CHECK(counter->m_CounterSetUid == eventRecord.counter_set); |
| 1509 | BOOST_CHECK(counter->m_Class == eventRecord.counter_class); |
| 1510 | BOOST_CHECK(counter->m_Interpolation == eventRecord.interpolation); |
| 1511 | BOOST_CHECK(counter->m_Multiplier == eventRecord.multiplier); |
| 1512 | BOOST_CHECK(counter->m_Name == eventRecord.name); |
| 1513 | BOOST_CHECK(counter->m_Description == eventRecord.description); |
| 1514 | BOOST_CHECK(counter->m_Units == eventRecord.units); |
| 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest3) |
| 1520 | { |
| 1521 | // Using a mock counter directory that allows to register invalid objects |
| 1522 | MockCounterDirectory counterDirectory; |
| 1523 | |
| 1524 | // Register an invalid device |
| 1525 | const std::string deviceName = "inv@lid dev!c€"; |
| 1526 | const Device* device = nullptr; |
| 1527 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName, 3)); |
| 1528 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1529 | BOOST_CHECK(device); |
| 1530 | |
| 1531 | // Buffer with enough space |
| 1532 | MockBuffer mockBuffer(1024); |
| 1533 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 1534 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), armnn::RuntimeException); |
| 1535 | } |
| 1536 | |
| 1537 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest4) |
| 1538 | { |
| 1539 | // Using a mock counter directory that allows to register invalid objects |
| 1540 | MockCounterDirectory counterDirectory; |
| 1541 | |
| 1542 | // Register an invalid counter set |
| 1543 | const std::string counterSetName = "inv@lid count€rs€t"; |
| 1544 | const CounterSet* counterSet = nullptr; |
| 1545 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1546 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1547 | BOOST_CHECK(counterSet); |
| 1548 | |
| 1549 | // Buffer with enough space |
| 1550 | MockBuffer mockBuffer(1024); |
| 1551 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 1552 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), armnn::RuntimeException); |
| 1553 | } |
| 1554 | |
| 1555 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest5) |
| 1556 | { |
| 1557 | // Using a mock counter directory that allows to register invalid objects |
| 1558 | MockCounterDirectory counterDirectory; |
| 1559 | |
| 1560 | // Register an invalid category |
| 1561 | const std::string categoryName = "c@t€gory"; |
| 1562 | const Category* category = nullptr; |
| 1563 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 1564 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1565 | BOOST_CHECK(category); |
| 1566 | |
| 1567 | // Buffer with enough space |
| 1568 | MockBuffer mockBuffer(1024); |
| 1569 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 1570 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), armnn::RuntimeException); |
| 1571 | } |
| 1572 | |
| 1573 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest6) |
| 1574 | { |
| 1575 | // Using a mock counter directory that allows to register invalid objects |
| 1576 | MockCounterDirectory counterDirectory; |
| 1577 | |
| 1578 | // Register an invalid device |
| 1579 | const std::string deviceName = "inv@lid dev!c€"; |
| 1580 | const Device* device = nullptr; |
| 1581 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName, 3)); |
| 1582 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1583 | BOOST_CHECK(device); |
| 1584 | |
| 1585 | // Register an invalid counter set |
| 1586 | const std::string counterSetName = "inv@lid count€rs€t"; |
| 1587 | const CounterSet* counterSet = nullptr; |
| 1588 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1589 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1590 | BOOST_CHECK(counterSet); |
| 1591 | |
| 1592 | // Register an invalid category associated to an invalid device and an invalid counter set |
| 1593 | const std::string categoryName = "c@t€gory"; |
| 1594 | const Category* category = nullptr; |
| 1595 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName, |
| 1596 | device->m_Uid, |
| 1597 | counterSet->m_Uid)); |
| 1598 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1599 | BOOST_CHECK(category); |
| 1600 | |
| 1601 | // Buffer with enough space |
| 1602 | MockBuffer mockBuffer(1024); |
| 1603 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 1604 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), armnn::RuntimeException); |
| 1605 | } |
| 1606 | |
| 1607 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest7) |
| 1608 | { |
| 1609 | // Using a mock counter directory that allows to register invalid objects |
| 1610 | MockCounterDirectory counterDirectory; |
| 1611 | |
| 1612 | // Register an valid device |
| 1613 | const std::string deviceName = "valid device"; |
| 1614 | const Device* device = nullptr; |
| 1615 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName, 3)); |
| 1616 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1617 | BOOST_CHECK(device); |
| 1618 | |
| 1619 | // Register an valid counter set |
| 1620 | const std::string counterSetName = "valid counterset"; |
| 1621 | const CounterSet* counterSet = nullptr; |
| 1622 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1623 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1624 | BOOST_CHECK(counterSet); |
| 1625 | |
| 1626 | // Register an valid category associated to a valid device and a valid counter set |
| 1627 | const std::string categoryName = "category"; |
| 1628 | const Category* category = nullptr; |
| 1629 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName, |
| 1630 | device->m_Uid, |
| 1631 | counterSet->m_Uid)); |
| 1632 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1633 | BOOST_CHECK(category); |
| 1634 | |
| 1635 | // Register an invalid counter associated to a valid category |
| 1636 | const Counter* counter = nullptr; |
| 1637 | BOOST_CHECK_NO_THROW(counter = counterDirectory.RegisterCounter(categoryName, |
| 1638 | 0, |
| 1639 | 1, |
| 1640 | 123.45f, |
| 1641 | "counter", |
| 1642 | "counter description", |
| 1643 | std::string("invalid counter units"), |
| 1644 | 5, |
| 1645 | device->m_Uid, |
| 1646 | counterSet->m_Uid)); |
| 1647 | BOOST_CHECK(counterDirectory.GetCounterCount() == 5); |
| 1648 | BOOST_CHECK(counter); |
| 1649 | |
| 1650 | // Buffer with enough space |
| 1651 | MockBuffer mockBuffer(1024); |
| 1652 | SendCounterPacket sendCounterPacket(mockBuffer); |
| 1653 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), armnn::RuntimeException); |
| 1654 | } |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 1655 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 1656 | BOOST_AUTO_TEST_SUITE_END() |