Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 1 | #include <endian.h> |
Andrew Jeffery | b0c1d20 | 2023-11-07 22:08:44 +1030 | [diff] [blame] | 2 | #include <libpldm/base.h> |
Pavithra Barithaya | a7989cd | 2023-10-30 08:52:28 -0500 | [diff] [blame] | 3 | #include <libpldm/oem/ibm/file_io.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 4 | |
| 5 | #include <array> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 6 | #include <cstdint> |
Andrew Jeffery | 5a70607 | 2023-04-05 19:45:31 +0930 | [diff] [blame] | 7 | #include <cstring> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 8 | #include <vector> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 9 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 10 | #include <gtest/gtest.h> |
| 11 | |
| 12 | constexpr auto hdrSize = sizeof(pldm_msg_hdr); |
| 13 | |
| 14 | TEST(ReadWriteFileMemory, testGoodDecodeRequest) |
| 15 | { |
| 16 | std::array<uint8_t, PLDM_RW_FILE_MEM_REQ_BYTES + hdrSize> requestMsg{}; |
| 17 | |
| 18 | // Random value for fileHandle, offset, length, address |
| 19 | uint32_t fileHandle = 0x12345678; |
| 20 | uint32_t offset = 0x87654321; |
| 21 | uint32_t length = 0x13245768; |
| 22 | uint64_t address = 0x124356879ACBDE0F; |
| 23 | uint32_t fileHandleLe = htole32(fileHandle); |
| 24 | uint32_t offsetLe = htole32(offset); |
| 25 | uint32_t lengthLe = htole32(length); |
| 26 | uint64_t addressLe = htole64(address); |
| 27 | |
| 28 | memcpy(requestMsg.data() + hdrSize, &fileHandleLe, sizeof(fileHandleLe)); |
| 29 | memcpy(requestMsg.data() + sizeof(fileHandleLe) + hdrSize, &offsetLe, |
| 30 | sizeof(offsetLe)); |
| 31 | memcpy(requestMsg.data() + sizeof(fileHandleLe) + sizeof(offsetLe) + |
| 32 | hdrSize, |
| 33 | &lengthLe, sizeof(lengthLe)); |
| 34 | memcpy(requestMsg.data() + sizeof(fileHandleLe) + sizeof(offsetLe) + |
| 35 | sizeof(lengthLe) + hdrSize, |
| 36 | &addressLe, sizeof(addressLe)); |
| 37 | |
| 38 | uint32_t retFileHandle = 0; |
| 39 | uint32_t retOffset = 0; |
| 40 | uint32_t retLength = 0; |
| 41 | uint64_t retAddress = 0; |
| 42 | |
| 43 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 44 | |
| 45 | // Invoke decode the read file memory request |
| 46 | auto rc = decode_rw_file_memory_req(request, requestMsg.size() - hdrSize, |
| 47 | &retFileHandle, &retOffset, &retLength, |
| 48 | &retAddress); |
| 49 | |
| 50 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 51 | ASSERT_EQ(fileHandle, retFileHandle); |
| 52 | ASSERT_EQ(offset, retOffset); |
| 53 | ASSERT_EQ(length, retLength); |
| 54 | ASSERT_EQ(address, retAddress); |
| 55 | } |
| 56 | |
| 57 | TEST(ReadWriteFileMemory, testBadDecodeRequest) |
| 58 | { |
| 59 | uint32_t fileHandle = 0; |
| 60 | uint32_t offset = 0; |
| 61 | uint32_t length = 0; |
| 62 | uint64_t address = 0; |
| 63 | |
| 64 | // Request payload message is missing |
| 65 | auto rc = decode_rw_file_memory_req(NULL, 0, &fileHandle, &offset, &length, |
| 66 | &address); |
| 67 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 68 | |
| 69 | std::array<uint8_t, PLDM_RW_FILE_MEM_REQ_BYTES> requestMsg{}; |
| 70 | |
| 71 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 72 | |
| 73 | // Address is NULL |
| 74 | rc = decode_rw_file_memory_req(request, requestMsg.size() - hdrSize, |
| 75 | &fileHandle, &offset, &length, NULL); |
| 76 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 77 | |
| 78 | // Payload length is invalid |
| 79 | rc = decode_rw_file_memory_req(request, 0, &fileHandle, &offset, &length, |
| 80 | &address); |
| 81 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 82 | } |
| 83 | |
| 84 | TEST(ReadWriteFileMemory, testGoodEncodeResponse) |
| 85 | { |
| 86 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES> |
| 87 | responseMsg{}; |
| 88 | uint32_t length = 0xFF00EE11; |
| 89 | uint32_t lengthLe = htole32(length); |
| 90 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 91 | |
| 92 | // ReadFileIntoMemory |
| 93 | auto rc = encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY, |
| 94 | PLDM_SUCCESS, length, response); |
| 95 | |
| 96 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 97 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 98 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 99 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 100 | ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_INTO_MEMORY); |
| 101 | ASSERT_EQ(response->payload[0], PLDM_SUCCESS); |
| 102 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 103 | &lengthLe, sizeof(lengthLe))); |
| 104 | |
| 105 | // WriteFileFromMemory |
| 106 | rc = encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY, |
| 107 | PLDM_SUCCESS, length, response); |
| 108 | |
| 109 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 110 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 111 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 112 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 113 | ASSERT_EQ(response->hdr.command, PLDM_WRITE_FILE_FROM_MEMORY); |
| 114 | ASSERT_EQ(response->payload[0], PLDM_SUCCESS); |
| 115 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 116 | &lengthLe, sizeof(lengthLe))); |
| 117 | } |
| 118 | |
| 119 | TEST(ReadWriteFileMemory, testBadEncodeResponse) |
| 120 | { |
| 121 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES> |
| 122 | responseMsg{}; |
| 123 | uint32_t length = 0; |
| 124 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 125 | |
| 126 | // ReadFileIntoMemory |
| 127 | auto rc = encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY, |
| 128 | PLDM_ERROR, length, response); |
| 129 | |
| 130 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 131 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 132 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 133 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 134 | ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_INTO_MEMORY); |
| 135 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 136 | |
| 137 | // WriteFileFromMemory |
| 138 | rc = encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY, PLDM_ERROR, |
| 139 | length, response); |
| 140 | |
| 141 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 142 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 143 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 144 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 145 | ASSERT_EQ(response->hdr.command, PLDM_WRITE_FILE_FROM_MEMORY); |
| 146 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 147 | } |
| 148 | |
| 149 | TEST(ReadWriteFileIntoMemory, testGoodDecodeResponse) |
| 150 | { |
| 151 | std::array<uint8_t, PLDM_RW_FILE_MEM_RESP_BYTES + hdrSize> responseMsg{}; |
| 152 | // Random value for length |
| 153 | uint32_t length = 0xFF00EE12; |
| 154 | uint32_t lengthLe = htole32(length); |
| 155 | uint8_t completionCode = 0; |
| 156 | |
| 157 | memcpy(responseMsg.data() + hdrSize, &completionCode, |
| 158 | sizeof(completionCode)); |
| 159 | memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &lengthLe, |
| 160 | sizeof(lengthLe)); |
| 161 | |
| 162 | uint8_t retCompletionCode = 0; |
| 163 | uint32_t retLength = 0; |
| 164 | |
| 165 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 166 | |
| 167 | // Invoke decode the read file memory response |
| 168 | auto rc = decode_rw_file_memory_resp(response, responseMsg.size() - hdrSize, |
| 169 | &retCompletionCode, &retLength); |
| 170 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 171 | ASSERT_EQ(completionCode, retCompletionCode); |
| 172 | ASSERT_EQ(length, retLength); |
| 173 | } |
| 174 | |
| 175 | TEST(ReadWriteFileIntoMemory, testBadDecodeResponse) |
| 176 | { |
| 177 | uint32_t length = 0; |
| 178 | uint8_t completionCode = 0; |
| 179 | |
| 180 | // Request payload message is missing |
| 181 | auto rc = decode_rw_file_memory_resp(NULL, 0, &completionCode, &length); |
| 182 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 183 | |
| 184 | std::array<uint8_t, PLDM_RW_FILE_MEM_RESP_BYTES> responseMsg{}; |
| 185 | |
| 186 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 187 | |
| 188 | // Payload length is invalid |
| 189 | rc = decode_rw_file_memory_resp(response, 0, &completionCode, &length); |
| 190 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 191 | } |
| 192 | |
| 193 | TEST(ReadWriteFileIntoMemory, testGoodEncodeRequest) |
| 194 | { |
| 195 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_REQ_BYTES> |
| 196 | requestMsg{}; |
| 197 | |
| 198 | uint32_t fileHandle = 0x12345678; |
| 199 | uint32_t offset = 0x87654321; |
| 200 | uint32_t length = 0x13245768; |
| 201 | uint64_t address = 0x124356879ACBDE0F; |
| 202 | uint32_t fileHandleLe = htole32(fileHandle); |
| 203 | uint32_t offsetLe = htole32(offset); |
| 204 | uint32_t lengthLe = htole32(length); |
| 205 | uint64_t addressLe = htole64(address); |
| 206 | |
| 207 | pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 208 | |
| 209 | auto rc = |
| 210 | encode_rw_file_memory_req(0, PLDM_READ_FILE_INTO_MEMORY, fileHandle, |
| 211 | offset, length, address, request); |
| 212 | |
| 213 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 214 | ASSERT_EQ(request->hdr.request, PLDM_REQUEST); |
| 215 | ASSERT_EQ(request->hdr.instance_id, 0); |
| 216 | ASSERT_EQ(request->hdr.type, PLDM_OEM); |
| 217 | ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_INTO_MEMORY); |
| 218 | |
| 219 | ASSERT_EQ(0, memcmp(request->payload, &fileHandleLe, sizeof(fileHandleLe))); |
| 220 | |
| 221 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandleLe), &offsetLe, |
| 222 | sizeof(offsetLe))); |
| 223 | ASSERT_EQ(0, |
| 224 | memcmp(request->payload + sizeof(fileHandleLe) + sizeof(offsetLe), |
| 225 | &lengthLe, sizeof(lengthLe))); |
| 226 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandleLe) + |
| 227 | sizeof(offsetLe) + sizeof(lengthLe), |
| 228 | &addressLe, sizeof(addressLe))); |
| 229 | } |
| 230 | |
| 231 | TEST(ReadWriteFileIntoMemory, testBadEncodeRequest) |
| 232 | { |
| 233 | uint32_t fileHandle = 0; |
| 234 | uint32_t offset = 0; |
| 235 | uint32_t length = 0; |
| 236 | uint64_t address = 0; |
| 237 | |
| 238 | auto rc = |
| 239 | encode_rw_file_memory_req(0, PLDM_READ_FILE_INTO_MEMORY, fileHandle, |
| 240 | offset, length, address, NULL); |
| 241 | |
| 242 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 243 | } |
| 244 | |
| 245 | TEST(GetFileTable, GoodDecodeRequest) |
| 246 | { |
| 247 | std::array<uint8_t, PLDM_GET_FILE_TABLE_REQ_BYTES + hdrSize> requestMsg{}; |
| 248 | |
| 249 | // Random value for DataTransferHandle, TransferOperationFlag, TableType |
| 250 | uint32_t transferHandle = 0x12345678; |
| 251 | uint32_t transferHandleLe = htole32(transferHandle); |
| 252 | uint8_t transferOpFlag = 1; |
| 253 | uint8_t tableType = 1; |
| 254 | |
| 255 | memcpy(requestMsg.data() + hdrSize, &transferHandleLe, |
| 256 | sizeof(transferHandleLe)); |
| 257 | memcpy(requestMsg.data() + sizeof(transferHandle) + hdrSize, |
| 258 | &transferOpFlag, sizeof(transferOpFlag)); |
| 259 | memcpy(requestMsg.data() + sizeof(transferHandle) + sizeof(transferOpFlag) + |
| 260 | hdrSize, |
| 261 | &tableType, sizeof(tableType)); |
| 262 | |
| 263 | uint32_t retTransferHandle = 0; |
| 264 | uint8_t retTransferOpFlag = 0; |
| 265 | uint8_t retTableType = 0; |
| 266 | |
| 267 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 268 | |
| 269 | // Invoke decode get file table request |
| 270 | auto rc = decode_get_file_table_req(request, requestMsg.size() - hdrSize, |
| 271 | &retTransferHandle, &retTransferOpFlag, |
| 272 | &retTableType); |
| 273 | |
| 274 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 275 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 276 | ASSERT_EQ(transferOpFlag, retTransferOpFlag); |
| 277 | ASSERT_EQ(tableType, retTableType); |
| 278 | } |
| 279 | |
| 280 | TEST(GetFileTable, BadDecodeRequest) |
| 281 | { |
| 282 | uint32_t transferHandle = 0; |
| 283 | uint8_t transferOpFlag = 0; |
| 284 | uint8_t tableType = 0; |
| 285 | |
| 286 | // Request payload message is missing |
| 287 | auto rc = decode_get_file_table_req(nullptr, 0, &transferHandle, |
| 288 | &transferOpFlag, &tableType); |
| 289 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 290 | |
| 291 | std::array<uint8_t, PLDM_GET_FILE_TABLE_REQ_BYTES> requestMsg{}; |
| 292 | |
| 293 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 294 | |
| 295 | // TableType is NULL |
| 296 | rc = decode_get_file_table_req(request, requestMsg.size() - hdrSize, |
| 297 | &transferHandle, &transferOpFlag, nullptr); |
| 298 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 299 | |
| 300 | // Payload length is invalid |
| 301 | rc = decode_get_file_table_req(request, 0, &transferHandle, &transferOpFlag, |
| 302 | &tableType); |
| 303 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 304 | } |
| 305 | |
| 306 | TEST(GetFileTable, GoodEncodeResponse) |
| 307 | { |
| 308 | // Random value for NextDataTransferHandle and TransferFlag |
| 309 | uint8_t completionCode = 0; |
| 310 | uint32_t nextTransferHandle = 0x87654321; |
| 311 | uint32_t nextTransferHandleLe = htole32(nextTransferHandle); |
| 312 | uint8_t transferFlag = 5; |
| 313 | // Mock file table contents of size 5 |
| 314 | std::array<uint8_t, 5> fileTable = {1, 2, 3, 4, 5}; |
| 315 | constexpr size_t responseSize = sizeof(completionCode) + |
| 316 | sizeof(nextTransferHandle) + |
| 317 | sizeof(transferFlag) + fileTable.size(); |
| 318 | |
| 319 | std::array<uint8_t, sizeof(pldm_msg_hdr) + responseSize> responseMsg{}; |
| 320 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 321 | |
| 322 | // GetFileTable |
| 323 | auto rc = encode_get_file_table_resp(0, PLDM_SUCCESS, nextTransferHandle, |
| 324 | transferFlag, fileTable.data(), |
| 325 | fileTable.size(), response); |
| 326 | |
| 327 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 328 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 329 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 330 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 331 | ASSERT_EQ(response->hdr.command, PLDM_GET_FILE_TABLE); |
| 332 | ASSERT_EQ(response->payload[0], PLDM_SUCCESS); |
| 333 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 334 | &nextTransferHandleLe, sizeof(nextTransferHandle))); |
| 335 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 336 | sizeof(nextTransferHandle), |
| 337 | &transferFlag, sizeof(transferFlag))); |
| 338 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 339 | sizeof(nextTransferHandle), |
| 340 | &transferFlag, sizeof(transferFlag))); |
| 341 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 342 | sizeof(nextTransferHandle) + sizeof(transferFlag), |
| 343 | fileTable.data(), fileTable.size())); |
| 344 | } |
| 345 | |
| 346 | TEST(GetFileTable, BadEncodeResponse) |
| 347 | { |
| 348 | uint8_t completionCode = 0; |
| 349 | uint32_t nextTransferHandle = 0; |
| 350 | uint8_t transferFlag = 0; |
| 351 | constexpr size_t responseSize = sizeof(completionCode) + |
| 352 | sizeof(nextTransferHandle) + |
| 353 | sizeof(transferFlag); |
| 354 | |
| 355 | std::array<uint8_t, sizeof(pldm_msg_hdr) + responseSize> responseMsg{}; |
| 356 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 357 | |
| 358 | // GetFileTable |
| 359 | auto rc = encode_get_file_table_resp(0, PLDM_ERROR, nextTransferHandle, |
| 360 | transferFlag, nullptr, 0, response); |
| 361 | |
| 362 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 363 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 364 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 365 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 366 | ASSERT_EQ(response->hdr.command, PLDM_GET_FILE_TABLE); |
| 367 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 368 | } |
| 369 | |
| 370 | TEST(GetFileTable, GoodEncodeRequest) |
| 371 | { |
| 372 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_FILE_TABLE_REQ_BYTES> |
| 373 | requestMsg{}; |
| 374 | uint32_t transferHandle = 0x0; |
| 375 | uint8_t transferOpFlag = 0x01; |
| 376 | uint8_t tableType = PLDM_FILE_ATTRIBUTE_TABLE; |
| 377 | |
| 378 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 379 | auto rc = encode_get_file_table_req(0, transferHandle, transferOpFlag, |
| 380 | tableType, request); |
| 381 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 382 | |
| 383 | struct pldm_get_file_table_req* req = |
| 384 | reinterpret_cast<struct pldm_get_file_table_req*>(request->payload); |
| 385 | EXPECT_EQ(transferHandle, le32toh(req->transfer_handle)); |
| 386 | EXPECT_EQ(transferOpFlag, req->operation_flag); |
| 387 | EXPECT_EQ(tableType, req->table_type); |
| 388 | } |
| 389 | |
| 390 | TEST(GetFileTable, BadEncodeRequest) |
| 391 | { |
| 392 | uint32_t transferHandle = 0x0; |
| 393 | uint8_t transferOpFlag = 0x01; |
| 394 | uint8_t tableType = PLDM_FILE_ATTRIBUTE_TABLE; |
| 395 | |
| 396 | auto rc = encode_get_file_table_req(0, transferHandle, transferOpFlag, |
| 397 | tableType, nullptr); |
| 398 | |
| 399 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 400 | } |
| 401 | |
| 402 | TEST(GetFileTable, GoodDecodeResponse) |
| 403 | { |
| 404 | uint32_t nextTransferHandle = 32; |
| 405 | uint8_t completionCode = PLDM_SUCCESS; |
| 406 | uint8_t transferFlag = PLDM_START_AND_END; |
| 407 | std::vector<uint8_t> fileTableData = {1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 408 | |
| 409 | std::vector<uint8_t> responseMsg( |
| 410 | hdrSize + PLDM_GET_FILE_TABLE_MIN_RESP_BYTES + fileTableData.size()); |
| 411 | |
| 412 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 413 | size_t payload_length = responseMsg.size() - hdrSize; |
| 414 | |
| 415 | auto resp = reinterpret_cast<struct pldm_get_file_table_resp*>( |
| 416 | responsePtr->payload); |
| 417 | |
| 418 | resp->completion_code = completionCode; |
| 419 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 420 | resp->transfer_flag = transferFlag; |
| 421 | memcpy(resp->table_data, fileTableData.data(), fileTableData.size()); |
| 422 | |
| 423 | uint8_t retCompletionCode; |
| 424 | uint32_t retNextTransferHandle; |
| 425 | uint8_t retTransferFlag; |
| 426 | std::vector<uint8_t> retFileTableData(9, 0); |
| 427 | size_t retFileTableDataLength = 0; |
| 428 | |
| 429 | auto rc = decode_get_file_table_resp( |
| 430 | responsePtr, payload_length, &retCompletionCode, &retNextTransferHandle, |
| 431 | &retTransferFlag, retFileTableData.data(), &retFileTableDataLength); |
| 432 | |
| 433 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 434 | ASSERT_EQ(completionCode, retCompletionCode); |
| 435 | ASSERT_EQ(nextTransferHandle, retNextTransferHandle); |
| 436 | ASSERT_EQ(transferFlag, retTransferFlag); |
| 437 | ASSERT_EQ(0, memcmp(fileTableData.data(), resp->table_data, |
| 438 | retFileTableDataLength)); |
| 439 | ASSERT_EQ(fileTableData.size(), retFileTableDataLength); |
| 440 | } |
| 441 | |
| 442 | TEST(GetFileTable, BadDecodeResponse) |
| 443 | { |
| 444 | uint32_t nextTransferHandle = 32; |
| 445 | uint8_t completionCode = PLDM_SUCCESS; |
| 446 | uint8_t transferFlag = PLDM_START_AND_END; |
| 447 | std::vector<uint8_t> fileTableData(9, 0); |
| 448 | size_t file_table_data_length = 0; |
| 449 | |
| 450 | std::vector<uint8_t> responseMsg( |
| 451 | hdrSize + PLDM_GET_FILE_TABLE_MIN_RESP_BYTES + fileTableData.size()); |
| 452 | |
| 453 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 454 | |
| 455 | auto rc = decode_get_file_table_resp( |
| 456 | nullptr, 0, &completionCode, &nextTransferHandle, &transferFlag, |
| 457 | fileTableData.data(), &file_table_data_length); |
| 458 | |
| 459 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 460 | |
| 461 | rc = decode_get_file_table_resp( |
| 462 | responsePtr, 0, &completionCode, &nextTransferHandle, &transferFlag, |
| 463 | fileTableData.data(), &file_table_data_length); |
| 464 | |
| 465 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 466 | } |
| 467 | |
| 468 | TEST(ReadFile, testGoodDecodeRequest) |
| 469 | { |
| 470 | std::array<uint8_t, PLDM_READ_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 471 | requestMsg{}; |
| 472 | |
| 473 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 474 | size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr); |
| 475 | auto request = reinterpret_cast<pldm_read_file_req*>(requestPtr->payload); |
| 476 | |
| 477 | // Random value for fileHandle, offset and length |
| 478 | uint32_t fileHandle = 0x12345678; |
| 479 | uint32_t offset = 0x87654321; |
| 480 | uint32_t length = 0x13245768; |
| 481 | |
| 482 | request->file_handle = htole32(fileHandle); |
| 483 | request->offset = htole32(offset); |
| 484 | request->length = htole32(length); |
| 485 | |
| 486 | uint32_t retFileHandle = 0; |
| 487 | uint32_t retOffset = 0; |
| 488 | uint32_t retLength = 0; |
| 489 | |
| 490 | // Invoke decode the read file request |
| 491 | auto rc = decode_read_file_req(requestPtr, payload_length, &retFileHandle, |
| 492 | &retOffset, &retLength); |
| 493 | |
| 494 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 495 | ASSERT_EQ(fileHandle, retFileHandle); |
| 496 | ASSERT_EQ(offset, retOffset); |
| 497 | ASSERT_EQ(length, retLength); |
| 498 | } |
| 499 | |
| 500 | TEST(WriteFile, testGoodDecodeRequest) |
| 501 | { |
| 502 | // Random value for fileHandle, offset, length and file data |
| 503 | uint32_t fileHandle = 0x12345678; |
| 504 | uint32_t offset = 0x87654321; |
| 505 | uint32_t length = 0x467; |
| 506 | |
| 507 | std::vector<uint8_t> requestMsg(PLDM_WRITE_FILE_REQ_BYTES + |
| 508 | sizeof(pldm_msg_hdr) + length); |
| 509 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 510 | size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr); |
| 511 | auto request = reinterpret_cast<pldm_write_file_req*>(requestPtr->payload); |
| 512 | |
| 513 | size_t fileDataOffset = |
| 514 | sizeof(fileHandle) + sizeof(offset) + sizeof(length); |
| 515 | |
| 516 | request->file_handle = htole32(fileHandle); |
| 517 | request->offset = htole32(offset); |
| 518 | request->length = htole32(length); |
| 519 | |
| 520 | uint32_t retFileHandle = 0; |
| 521 | uint32_t retOffset = 0; |
| 522 | uint32_t retLength = 0; |
| 523 | size_t retFileDataOffset = 0; |
| 524 | |
| 525 | // Invoke decode the write file request |
| 526 | auto rc = decode_write_file_req(requestPtr, payload_length, &retFileHandle, |
| 527 | &retOffset, &retLength, &retFileDataOffset); |
| 528 | |
| 529 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 530 | ASSERT_EQ(fileHandle, retFileHandle); |
| 531 | ASSERT_EQ(offset, retOffset); |
| 532 | ASSERT_EQ(length, retLength); |
| 533 | ASSERT_EQ(fileDataOffset, retFileDataOffset); |
| 534 | } |
| 535 | |
| 536 | TEST(ReadFile, testGoodDecodeResponse) |
| 537 | { |
| 538 | // Random value for length |
| 539 | uint32_t length = 0x10; |
| 540 | uint8_t completionCode = PLDM_SUCCESS; |
| 541 | |
| 542 | std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES + |
| 543 | sizeof(pldm_msg_hdr) + length); |
| 544 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 545 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 546 | auto response = |
| 547 | reinterpret_cast<pldm_read_file_resp*>(responsePtr->payload); |
| 548 | |
| 549 | response->completion_code = completionCode; |
| 550 | response->length = htole32(length); |
| 551 | |
| 552 | size_t fileDataOffset = sizeof(completionCode) + sizeof(length); |
| 553 | |
| 554 | uint32_t retLength = 0; |
| 555 | uint8_t retCompletionCode = 0; |
| 556 | size_t retFileDataOffset = 0; |
| 557 | |
| 558 | // Invoke decode the read file response |
| 559 | auto rc = |
| 560 | decode_read_file_resp(responsePtr, payload_length, &retCompletionCode, |
| 561 | &retLength, &retFileDataOffset); |
| 562 | |
| 563 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 564 | ASSERT_EQ(completionCode, retCompletionCode); |
| 565 | ASSERT_EQ(length, retLength); |
| 566 | ASSERT_EQ(fileDataOffset, retFileDataOffset); |
| 567 | } |
| 568 | |
| 569 | TEST(WriteFile, testGoodDecodeResponse) |
| 570 | { |
| 571 | std::array<uint8_t, PLDM_WRITE_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 572 | responseMsg{}; |
| 573 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 574 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 575 | auto response = |
| 576 | reinterpret_cast<pldm_write_file_resp*>(responsePtr->payload); |
| 577 | |
| 578 | uint8_t completionCode = PLDM_SUCCESS; |
| 579 | uint32_t length = 0x4678; |
| 580 | |
| 581 | response->completion_code = completionCode; |
| 582 | response->length = htole32(length); |
| 583 | |
| 584 | uint32_t retLength = 0; |
| 585 | uint8_t retCompletionCode = 0; |
| 586 | |
| 587 | // Invoke decode the write file response |
| 588 | auto rc = decode_write_file_resp(responsePtr, payload_length, |
| 589 | &retCompletionCode, &retLength); |
| 590 | |
| 591 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 592 | ASSERT_EQ(completionCode, retCompletionCode); |
| 593 | ASSERT_EQ(length, retLength); |
| 594 | } |
| 595 | |
| 596 | TEST(ReadWriteFile, testBadDecodeResponse) |
| 597 | { |
| 598 | uint32_t length = 0; |
| 599 | uint8_t completionCode = 0; |
| 600 | size_t fileDataOffset = 0; |
| 601 | |
| 602 | // Bad decode response for read file |
| 603 | std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES + |
| 604 | sizeof(pldm_msg_hdr) + length); |
| 605 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 606 | |
| 607 | // Request payload message is missing |
| 608 | auto rc = decode_read_file_resp(NULL, 0, &completionCode, &length, |
| 609 | &fileDataOffset); |
| 610 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 611 | |
| 612 | // Payload length is invalid |
| 613 | rc = decode_read_file_resp(responsePtr, 0, &completionCode, &length, |
| 614 | &fileDataOffset); |
| 615 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 616 | |
| 617 | // Bad decode response for write file |
| 618 | std::array<uint8_t, PLDM_WRITE_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 619 | responseMsgWr{}; |
| 620 | auto responseWr = reinterpret_cast<pldm_msg*>(responseMsgWr.data()); |
| 621 | |
| 622 | // Request payload message is missing |
| 623 | rc = decode_write_file_resp(NULL, 0, &completionCode, &length); |
| 624 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 625 | |
| 626 | // Payload length is invalid |
| 627 | rc = decode_write_file_resp(responseWr, 0, &completionCode, &length); |
| 628 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 629 | } |
| 630 | |
| 631 | TEST(ReadWriteFile, testBadDecodeRequest) |
| 632 | { |
| 633 | uint32_t fileHandle = 0; |
| 634 | uint32_t offset = 0; |
| 635 | uint32_t length = 0; |
| 636 | |
| 637 | // Bad decode request for read file |
| 638 | std::array<uint8_t, PLDM_READ_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 639 | requestMsg{}; |
| 640 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 641 | |
| 642 | // Request payload message is missing |
| 643 | auto rc = decode_read_file_req(NULL, 0, &fileHandle, &offset, &length); |
| 644 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 645 | |
| 646 | // Payload length is invalid |
| 647 | rc = decode_read_file_req(requestPtr, 0, &fileHandle, &offset, &length); |
| 648 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 649 | |
| 650 | // Bad decode request for write file |
| 651 | size_t fileDataOffset = 0; |
| 652 | std::array<uint8_t, PLDM_WRITE_FILE_REQ_BYTES> requestMsgWr{}; |
| 653 | auto requestWr = reinterpret_cast<pldm_msg*>(requestMsgWr.data()); |
| 654 | |
| 655 | // Request payload message is missing |
| 656 | rc = decode_write_file_req(NULL, 0, &fileHandle, &offset, &length, |
| 657 | &fileDataOffset); |
| 658 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 659 | |
| 660 | // Payload length is invalid |
| 661 | rc = decode_write_file_req(requestWr, 0, &fileHandle, &offset, &length, |
| 662 | &fileDataOffset); |
| 663 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 664 | } |
| 665 | |
| 666 | TEST(ReadFile, testGoodEncodeResponse) |
| 667 | { |
| 668 | // Good encode response for read file |
| 669 | uint32_t length = 0x4; |
| 670 | |
| 671 | std::vector<uint8_t> responseMsg(PLDM_READ_FILE_RESP_BYTES + |
| 672 | sizeof(pldm_msg_hdr) + length); |
| 673 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 674 | auto response = |
| 675 | reinterpret_cast<pldm_read_file_resp*>(responsePtr->payload); |
| 676 | |
| 677 | // ReadFile |
| 678 | auto rc = encode_read_file_resp(0, PLDM_SUCCESS, length, responsePtr); |
| 679 | |
| 680 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 681 | ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE); |
| 682 | ASSERT_EQ(responsePtr->hdr.instance_id, 0); |
| 683 | ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM); |
| 684 | ASSERT_EQ(responsePtr->hdr.command, PLDM_READ_FILE); |
| 685 | ASSERT_EQ(response->completion_code, PLDM_SUCCESS); |
| 686 | ASSERT_EQ(le32toh(response->length), length); |
| 687 | } |
| 688 | |
| 689 | TEST(WriteFile, testGoodEncodeResponse) |
| 690 | { |
| 691 | uint32_t length = 0x467; |
| 692 | |
| 693 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_RESP_BYTES> |
| 694 | responseMsg{}; |
| 695 | |
| 696 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 697 | auto response = |
| 698 | reinterpret_cast<pldm_write_file_resp*>(responsePtr->payload); |
| 699 | |
| 700 | // WriteFile |
| 701 | auto rc = encode_write_file_resp(0, PLDM_SUCCESS, length, responsePtr); |
| 702 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 703 | ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE); |
| 704 | ASSERT_EQ(responsePtr->hdr.instance_id, 0); |
| 705 | ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM); |
| 706 | ASSERT_EQ(responsePtr->hdr.command, PLDM_WRITE_FILE); |
| 707 | ASSERT_EQ(response->completion_code, PLDM_SUCCESS); |
| 708 | ASSERT_EQ(le32toh(response->length), length); |
| 709 | } |
| 710 | |
| 711 | TEST(ReadFile, testGoodEncodeRequest) |
| 712 | { |
| 713 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_REQ_BYTES> |
| 714 | requestMsg{}; |
| 715 | |
| 716 | uint32_t fileHandle = 0x12345678; |
| 717 | uint32_t offset = 0x87654321; |
| 718 | uint32_t length = 0x13245768; |
| 719 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 720 | auto request = reinterpret_cast<pldm_read_file_req*>(requestPtr->payload); |
| 721 | |
| 722 | // ReadFile |
| 723 | auto rc = encode_read_file_req(0, fileHandle, offset, length, requestPtr); |
| 724 | |
| 725 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 726 | ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST); |
| 727 | ASSERT_EQ(requestPtr->hdr.instance_id, 0); |
| 728 | ASSERT_EQ(requestPtr->hdr.type, PLDM_OEM); |
| 729 | ASSERT_EQ(requestPtr->hdr.command, PLDM_READ_FILE); |
| 730 | ASSERT_EQ(le32toh(request->file_handle), fileHandle); |
| 731 | ASSERT_EQ(le32toh(request->offset), offset); |
| 732 | ASSERT_EQ(le32toh(request->length), length); |
| 733 | } |
| 734 | |
| 735 | TEST(WriteFile, testGoodEncodeRequest) |
| 736 | { |
| 737 | uint32_t fileHandle = 0x12345678; |
| 738 | uint32_t offset = 0x87654321; |
| 739 | uint32_t length = 0x456; |
| 740 | |
| 741 | std::vector<uint8_t> requestMsg(PLDM_WRITE_FILE_REQ_BYTES + |
| 742 | sizeof(pldm_msg_hdr) + length); |
| 743 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 744 | auto request = reinterpret_cast<pldm_write_file_req*>(requestPtr->payload); |
| 745 | |
| 746 | // WriteFile |
| 747 | auto rc = encode_write_file_req(0, fileHandle, offset, length, requestPtr); |
| 748 | |
| 749 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 750 | ASSERT_EQ(requestPtr->hdr.request, PLDM_REQUEST); |
| 751 | ASSERT_EQ(requestPtr->hdr.instance_id, 0); |
| 752 | ASSERT_EQ(requestPtr->hdr.type, PLDM_OEM); |
| 753 | ASSERT_EQ(requestPtr->hdr.command, PLDM_WRITE_FILE); |
| 754 | ASSERT_EQ(le32toh(request->file_handle), fileHandle); |
| 755 | ASSERT_EQ(le32toh(request->offset), offset); |
| 756 | ASSERT_EQ(le32toh(request->length), length); |
| 757 | } |
| 758 | |
| 759 | TEST(ReadWriteFile, testBadEncodeRequest) |
| 760 | { |
| 761 | // Bad encode request for read file |
| 762 | uint32_t fileHandle = 0; |
| 763 | uint32_t offset = 0; |
| 764 | uint32_t length = 0; |
| 765 | |
| 766 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_REQ_BYTES> |
| 767 | requestMsg{}; |
| 768 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 769 | |
| 770 | // ReadFile check invalid file length |
| 771 | auto rc = encode_read_file_req(0, fileHandle, offset, length, requestPtr); |
| 772 | |
| 773 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 774 | |
| 775 | // Bad encode request for write file |
| 776 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_REQ_BYTES> |
| 777 | requestMsgWr{}; |
| 778 | auto requestWr = reinterpret_cast<pldm_msg*>(requestMsgWr.data()); |
| 779 | |
| 780 | // WriteFile check for invalid file length |
| 781 | rc = encode_write_file_req(0, fileHandle, offset, length, requestWr); |
| 782 | |
| 783 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 784 | } |
| 785 | |
| 786 | TEST(ReadWriteFile, testBadEncodeResponse) |
| 787 | { |
| 788 | // Bad encode response for read file |
| 789 | uint32_t length = 0; |
| 790 | |
| 791 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_READ_FILE_RESP_BYTES> |
| 792 | responseMsg{}; |
| 793 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 794 | |
| 795 | // ReadFile |
| 796 | auto rc = encode_read_file_resp(0, PLDM_ERROR, length, responsePtr); |
| 797 | |
| 798 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 799 | ASSERT_EQ(responsePtr->hdr.request, PLDM_RESPONSE); |
| 800 | ASSERT_EQ(responsePtr->hdr.instance_id, 0); |
| 801 | ASSERT_EQ(responsePtr->hdr.type, PLDM_OEM); |
| 802 | ASSERT_EQ(responsePtr->hdr.command, PLDM_READ_FILE); |
| 803 | ASSERT_EQ(responsePtr->payload[0], PLDM_ERROR); |
| 804 | |
| 805 | // Bad encode response for write file |
| 806 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_WRITE_FILE_RESP_BYTES> |
| 807 | responseMsgWr{}; |
| 808 | auto responseWr = reinterpret_cast<pldm_msg*>(responseMsgWr.data()); |
| 809 | |
| 810 | // WriteFile |
| 811 | rc = encode_write_file_resp(0, PLDM_ERROR, length, responseWr); |
| 812 | |
| 813 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 814 | ASSERT_EQ(responseWr->hdr.request, PLDM_RESPONSE); |
| 815 | ASSERT_EQ(responseWr->hdr.instance_id, 0); |
| 816 | ASSERT_EQ(responseWr->hdr.type, PLDM_OEM); |
| 817 | ASSERT_EQ(responseWr->hdr.command, PLDM_WRITE_FILE); |
| 818 | ASSERT_EQ(responseWr->payload[0], PLDM_ERROR); |
| 819 | } |
| 820 | |
| 821 | TEST(ReadWriteFileByTypeMemory, testGoodDecodeRequest) |
| 822 | { |
| 823 | std::array<uint8_t, |
| 824 | PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 825 | requestMsg{}; |
| 826 | |
| 827 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 828 | size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr); |
| 829 | auto request = reinterpret_cast<pldm_read_write_file_by_type_memory_req*>( |
| 830 | requestPtr->payload); |
| 831 | |
| 832 | // Random value for fileHandle, offset and length |
| 833 | uint16_t fileType = 0; |
| 834 | uint32_t fileHandle = 0x12345678; |
| 835 | uint32_t offset = 0x87654321; |
| 836 | uint32_t length = 0x13245768; |
| 837 | uint64_t address = 0x124356879ACBD456; |
| 838 | |
| 839 | request->file_type = htole16(fileType); |
| 840 | request->file_handle = htole32(fileHandle); |
| 841 | request->offset = htole32(offset); |
| 842 | request->length = htole32(length); |
| 843 | request->address = htole64(address); |
| 844 | |
| 845 | uint16_t retFileType = 0x1; |
| 846 | uint32_t retFileHandle = 0; |
| 847 | uint32_t retOffset = 0; |
| 848 | uint32_t retLength = 0; |
| 849 | uint64_t retAddress = 0; |
| 850 | |
| 851 | // Invoke decode the read file request |
| 852 | auto rc = decode_rw_file_by_type_memory_req( |
| 853 | requestPtr, payload_length, &retFileType, &retFileHandle, &retOffset, |
| 854 | &retLength, &retAddress); |
| 855 | |
| 856 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 857 | ASSERT_EQ(fileType, retFileType); |
| 858 | ASSERT_EQ(fileHandle, retFileHandle); |
| 859 | ASSERT_EQ(offset, retOffset); |
| 860 | ASSERT_EQ(length, retLength); |
| 861 | ASSERT_EQ(address, retAddress); |
| 862 | } |
| 863 | |
| 864 | TEST(ReadWriteFileByTypeMemory, testGoodDecodeResponse) |
| 865 | { |
| 866 | std::array<uint8_t, |
| 867 | PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 868 | responseMsg{}; |
| 869 | |
| 870 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 871 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 872 | auto response = reinterpret_cast<pldm_read_write_file_by_type_memory_resp*>( |
| 873 | responsePtr->payload); |
| 874 | |
| 875 | // Random value for completion code and length |
| 876 | uint8_t completionCode = 0x0; |
| 877 | uint32_t length = 0x13245768; |
| 878 | |
| 879 | response->completion_code = completionCode; |
| 880 | response->length = htole32(length); |
| 881 | |
| 882 | uint8_t retCompletionCode = 0x1; |
| 883 | uint32_t retLength = 0; |
| 884 | |
| 885 | // Invoke decode the read/write file response |
| 886 | auto rc = decode_rw_file_by_type_memory_resp( |
| 887 | responsePtr, payload_length, &retCompletionCode, &retLength); |
| 888 | |
| 889 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 890 | ASSERT_EQ(completionCode, retCompletionCode); |
| 891 | ASSERT_EQ(length, retLength); |
| 892 | } |
| 893 | |
| 894 | TEST(ReadWriteFileByTypeMemory, testBadDecodeRequest) |
| 895 | { |
| 896 | uint16_t fileType = 0; |
| 897 | uint32_t fileHandle = 0; |
| 898 | uint32_t offset = 0; |
| 899 | uint32_t length = 0; |
| 900 | uint64_t address = 0; |
| 901 | |
| 902 | // Request payload message is missing |
| 903 | auto rc = decode_rw_file_by_type_memory_req(NULL, 0, &fileType, &fileHandle, |
| 904 | &offset, &length, &address); |
| 905 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 906 | |
| 907 | std::array<uint8_t, |
| 908 | PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 909 | requestMsg{}; |
| 910 | |
| 911 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 912 | |
| 913 | // Address is NULL |
| 914 | rc = decode_rw_file_by_type_memory_req( |
| 915 | requestPtr, requestMsg.size() - hdrSize, &fileType, &fileHandle, |
| 916 | &offset, &length, NULL); |
| 917 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 918 | |
| 919 | // Payload length is invalid |
| 920 | rc = decode_rw_file_by_type_memory_req( |
| 921 | requestPtr, 0, &fileType, &fileHandle, &offset, &length, &address); |
| 922 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 923 | } |
| 924 | |
| 925 | TEST(ReadWriteFileByTypeMemory, testBadDecodeResponse) |
| 926 | { |
| 927 | uint32_t length = 0; |
| 928 | uint8_t completionCode = 0; |
| 929 | |
| 930 | // Request payload message is missing |
| 931 | auto rc = |
| 932 | decode_rw_file_by_type_memory_resp(NULL, 0, &completionCode, &length); |
| 933 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 934 | |
| 935 | std::array<uint8_t, |
| 936 | PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 937 | responseMsg{}; |
| 938 | |
| 939 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 940 | |
| 941 | // Length is NULL |
| 942 | rc = decode_rw_file_by_type_memory_resp( |
| 943 | responsePtr, responseMsg.size() - hdrSize, &completionCode, NULL); |
| 944 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 945 | |
| 946 | // Payload length is invalid |
| 947 | rc = decode_rw_file_by_type_memory_resp(responsePtr, 0, &completionCode, |
| 948 | &length); |
| 949 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 950 | } |
| 951 | |
| 952 | TEST(ReadWriteFileByTypeMemory, testGoodEncodeRequest) |
| 953 | { |
| 954 | std::array<uint8_t, |
| 955 | sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES> |
| 956 | requestMsg{}; |
| 957 | |
| 958 | uint16_t fileType = 0; |
| 959 | uint32_t fileHandle = 0x12345678; |
| 960 | uint32_t offset = 0x87654321; |
| 961 | uint32_t length = 0x13245768; |
| 962 | uint64_t address = 0x124356879ACBDE0F; |
| 963 | uint16_t fileTypeLe = htole16(fileType); |
| 964 | uint32_t fileHandleLe = htole32(fileHandle); |
| 965 | uint32_t offsetLe = htole32(offset); |
| 966 | uint32_t lengthLe = htole32(length); |
| 967 | uint64_t addressLe = htole64(address); |
| 968 | |
| 969 | pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 970 | |
| 971 | auto rc = encode_rw_file_by_type_memory_req( |
| 972 | 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, fileType, fileHandle, offset, |
| 973 | length, address, request); |
| 974 | |
| 975 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 976 | ASSERT_EQ(request->hdr.request, PLDM_REQUEST); |
| 977 | ASSERT_EQ(request->hdr.instance_id, 0); |
| 978 | ASSERT_EQ(request->hdr.type, PLDM_OEM); |
| 979 | ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY); |
| 980 | |
| 981 | ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe))); |
| 982 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe, |
| 983 | sizeof(fileHandleLe))); |
| 984 | |
| 985 | ASSERT_EQ( |
| 986 | 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe), |
| 987 | &offsetLe, sizeof(offsetLe))); |
| 988 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 989 | sizeof(fileHandleLe) + sizeof(offsetLe), |
| 990 | &lengthLe, sizeof(lengthLe))); |
| 991 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 992 | sizeof(fileHandleLe) + sizeof(offsetLe) + |
| 993 | sizeof(lengthLe), |
| 994 | &addressLe, sizeof(addressLe))); |
| 995 | } |
| 996 | |
| 997 | TEST(ReadWriteFileByTypeMemory, testGoodEncodeResponse) |
| 998 | { |
| 999 | std::array<uint8_t, |
| 1000 | sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES> |
| 1001 | responseMsg{}; |
| 1002 | |
| 1003 | uint32_t length = 0x13245768; |
| 1004 | uint32_t lengthLe = htole32(length); |
| 1005 | uint8_t completionCode = 0x0; |
| 1006 | |
| 1007 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1008 | |
| 1009 | auto rc = encode_rw_file_by_type_memory_resp( |
| 1010 | 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, completionCode, length, |
| 1011 | response); |
| 1012 | |
| 1013 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1014 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1015 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1016 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1017 | ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY); |
| 1018 | |
| 1019 | ASSERT_EQ( |
| 1020 | 0, memcmp(response->payload, &completionCode, sizeof(completionCode))); |
| 1021 | ASSERT_EQ(0, memcmp(response->payload + sizeof(completionCode), &lengthLe, |
| 1022 | sizeof(lengthLe))); |
| 1023 | } |
| 1024 | |
| 1025 | TEST(ReadWriteFileByTypeMemory, testBadEncodeResponse) |
| 1026 | { |
| 1027 | std::array<uint8_t, |
| 1028 | sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES> |
| 1029 | responseMsg{}; |
| 1030 | uint32_t length = 0; |
| 1031 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1032 | |
| 1033 | // completion code is PLDM_ERROR |
| 1034 | auto rc = encode_rw_file_by_type_memory_resp( |
| 1035 | 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, PLDM_ERROR, length, response); |
| 1036 | |
| 1037 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1038 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1039 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1040 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1041 | ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY); |
| 1042 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 1043 | |
| 1044 | // response is NULL pointer |
| 1045 | rc = encode_rw_file_by_type_memory_resp( |
| 1046 | 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, PLDM_SUCCESS, length, NULL); |
| 1047 | |
| 1048 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1049 | } |
| 1050 | |
| 1051 | TEST(ReadWriteFileByTypeMemory, testBadEncodeRequest) |
| 1052 | { |
| 1053 | uint8_t fileType = 0; |
| 1054 | uint32_t fileHandle = 0; |
| 1055 | uint32_t offset = 0; |
| 1056 | uint32_t length = 0; |
| 1057 | uint64_t address = 0; |
| 1058 | |
| 1059 | // request is NULL pointer |
| 1060 | auto rc = encode_rw_file_by_type_memory_req( |
| 1061 | 0, PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, fileType, fileHandle, offset, |
| 1062 | length, address, NULL); |
| 1063 | |
| 1064 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1065 | } |
| 1066 | |
| 1067 | TEST(NewFile, testGoodDecodeRequest) |
| 1068 | { |
| 1069 | std::array<uint8_t, PLDM_NEW_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 1070 | requestMsg{}; |
| 1071 | |
| 1072 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1073 | size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr); |
| 1074 | auto request = reinterpret_cast<pldm_new_file_req*>(requestPtr->payload); |
| 1075 | |
| 1076 | // Random value for fileHandle and length |
| 1077 | uint16_t fileType = 0xFF; |
| 1078 | uint32_t fileHandle = 0x12345678; |
| 1079 | uint64_t length = 0x13245768; |
| 1080 | |
| 1081 | request->file_type = htole16(fileType); |
| 1082 | request->file_handle = htole32(fileHandle); |
| 1083 | request->length = htole64(length); |
| 1084 | |
| 1085 | uint16_t retFileType = 0xFF; |
| 1086 | uint32_t retFileHandle = 0; |
| 1087 | uint64_t retLength = 0; |
| 1088 | |
| 1089 | // Invoke decode the read file request |
| 1090 | auto rc = decode_new_file_req(requestPtr, payload_length, &retFileType, |
| 1091 | &retFileHandle, &retLength); |
| 1092 | |
| 1093 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1094 | ASSERT_EQ(fileType, retFileType); |
| 1095 | ASSERT_EQ(fileHandle, retFileHandle); |
| 1096 | ASSERT_EQ(length, retLength); |
| 1097 | } |
| 1098 | |
| 1099 | TEST(NewFile, testGoodDecodeResponse) |
| 1100 | { |
| 1101 | std::array<uint8_t, PLDM_NEW_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 1102 | responseMsg{}; |
| 1103 | |
| 1104 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1105 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 1106 | auto response = reinterpret_cast<pldm_new_file_resp*>(responsePtr->payload); |
| 1107 | |
| 1108 | // Random value for completion code |
| 1109 | uint8_t completionCode = 0x0; |
| 1110 | |
| 1111 | response->completion_code = completionCode; |
| 1112 | |
| 1113 | uint8_t retCompletionCode = PLDM_SUCCESS; |
| 1114 | |
| 1115 | // Invoke decode the read/write file response |
| 1116 | auto rc = |
| 1117 | decode_new_file_resp(responsePtr, payload_length, &retCompletionCode); |
| 1118 | |
| 1119 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1120 | ASSERT_EQ(completionCode, retCompletionCode); |
| 1121 | } |
| 1122 | |
| 1123 | TEST(NewFile, testBadDecodeRequest) |
| 1124 | { |
| 1125 | uint16_t fileType = 0; |
| 1126 | uint32_t fileHandle = 0; |
| 1127 | uint64_t length = 0; |
| 1128 | |
| 1129 | // Request payload message is missing |
| 1130 | auto rc = decode_new_file_req(NULL, 0, &fileType, &fileHandle, &length); |
| 1131 | |
| 1132 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1133 | |
| 1134 | std::array<uint8_t, PLDM_NEW_FILE_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 1135 | requestMsg{}; |
| 1136 | |
| 1137 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1138 | |
| 1139 | // Payload length is invalid |
| 1140 | rc = decode_new_file_req(requestPtr, 0, &fileType, &fileHandle, &length); |
| 1141 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1142 | } |
| 1143 | |
| 1144 | TEST(NewFile, testBadDecodeResponse) |
| 1145 | { |
| 1146 | uint8_t completionCode = 0; |
| 1147 | |
| 1148 | // Request payload message is missing |
| 1149 | auto rc = decode_new_file_resp(NULL, 0, &completionCode); |
| 1150 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1151 | |
| 1152 | std::array<uint8_t, PLDM_NEW_FILE_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 1153 | responseMsg{}; |
| 1154 | |
| 1155 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1156 | |
| 1157 | // Payload length is invalid |
| 1158 | rc = decode_new_file_resp(responsePtr, 0, &completionCode); |
| 1159 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1160 | } |
| 1161 | |
| 1162 | TEST(NewFile, testGoodEncodeRequest) |
| 1163 | { |
| 1164 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_REQ_BYTES> |
| 1165 | requestMsg{}; |
| 1166 | |
| 1167 | uint16_t fileType = 0xFF; |
| 1168 | uint32_t fileHandle = 0x12345678; |
| 1169 | uint32_t length = 0x13245768; |
| 1170 | uint16_t fileTypeLe = htole16(fileType); |
| 1171 | uint32_t fileHandleLe = htole32(fileHandle); |
| 1172 | uint32_t lengthLe = htole32(length); |
| 1173 | |
| 1174 | pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1175 | |
| 1176 | auto rc = encode_new_file_req(0, fileType, fileHandle, length, request); |
| 1177 | |
| 1178 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1179 | ASSERT_EQ(request->hdr.request, PLDM_REQUEST); |
| 1180 | ASSERT_EQ(request->hdr.instance_id, 0); |
| 1181 | ASSERT_EQ(request->hdr.type, PLDM_OEM); |
| 1182 | ASSERT_EQ(request->hdr.command, PLDM_NEW_FILE_AVAILABLE); |
| 1183 | ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe))); |
| 1184 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe, |
| 1185 | sizeof(fileHandleLe))); |
| 1186 | ASSERT_EQ( |
| 1187 | 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe), |
| 1188 | &lengthLe, sizeof(lengthLe))); |
| 1189 | } |
| 1190 | |
| 1191 | TEST(NewFile, testGoodEncodeResponse) |
| 1192 | { |
| 1193 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_RESP_BYTES> |
| 1194 | responseMsg{}; |
| 1195 | |
| 1196 | uint8_t completionCode = 0x0; |
| 1197 | |
| 1198 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1199 | |
| 1200 | auto rc = encode_new_file_resp(0, completionCode, response); |
| 1201 | |
| 1202 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1203 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1204 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1205 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1206 | ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE); |
| 1207 | ASSERT_EQ( |
| 1208 | 0, memcmp(response->payload, &completionCode, sizeof(completionCode))); |
| 1209 | } |
| 1210 | |
| 1211 | TEST(NewFile, testBadEncodeResponse) |
| 1212 | { |
| 1213 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_NEW_FILE_RESP_BYTES> |
| 1214 | responseMsg{}; |
| 1215 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1216 | |
| 1217 | // completion code is PLDM_ERROR |
| 1218 | auto rc = encode_new_file_resp(0, PLDM_ERROR, response); |
| 1219 | |
| 1220 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1221 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1222 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1223 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1224 | ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE); |
| 1225 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 1226 | |
| 1227 | // response is NULL pointer |
| 1228 | rc = encode_new_file_resp(0, PLDM_SUCCESS, NULL); |
| 1229 | |
| 1230 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1231 | } |
| 1232 | |
| 1233 | TEST(NewFile, testBadEncodeRequest) |
| 1234 | { |
| 1235 | uint8_t fileType = 0xFF; |
| 1236 | uint32_t fileHandle = 0; |
| 1237 | uint32_t length = 0; |
| 1238 | |
| 1239 | // request is NULL pointer |
| 1240 | auto rc = encode_new_file_req(0, fileType, fileHandle, length, NULL); |
| 1241 | |
| 1242 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1243 | } |
| 1244 | |
| 1245 | TEST(ReadWriteFileByType, testGoodDecodeRequest) |
| 1246 | { |
| 1247 | std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 1248 | requestMsg{}; |
| 1249 | |
| 1250 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1251 | size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr); |
| 1252 | auto request = reinterpret_cast<pldm_read_write_file_by_type_req*>( |
| 1253 | requestPtr->payload); |
| 1254 | |
| 1255 | // Random value for fileHandle, offset and length |
| 1256 | uint16_t fileType = 0; |
| 1257 | uint32_t fileHandle = 0x12345678; |
| 1258 | uint32_t offset = 0x87654321; |
| 1259 | uint32_t length = 0x13245768; |
| 1260 | |
| 1261 | request->file_handle = htole32(fileHandle); |
| 1262 | request->offset = htole32(offset); |
| 1263 | request->length = htole32(length); |
| 1264 | |
| 1265 | uint16_t retFileType = 0x1; |
| 1266 | uint32_t retFileHandle = 0; |
| 1267 | uint32_t retOffset = 0; |
| 1268 | uint32_t retLength = 0; |
| 1269 | |
| 1270 | // Invoke decode the read file request |
| 1271 | auto rc = |
| 1272 | decode_rw_file_by_type_req(requestPtr, payload_length, &retFileType, |
| 1273 | &retFileHandle, &retOffset, &retLength); |
| 1274 | |
| 1275 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1276 | ASSERT_EQ(fileType, retFileType); |
| 1277 | ASSERT_EQ(fileHandle, retFileHandle); |
| 1278 | ASSERT_EQ(offset, retOffset); |
| 1279 | ASSERT_EQ(length, retLength); |
| 1280 | } |
| 1281 | |
| 1282 | TEST(ReadWriteFileByType, testGoodDecodeResponse) |
| 1283 | { |
| 1284 | std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 1285 | responseMsg{}; |
| 1286 | |
| 1287 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1288 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 1289 | auto response = reinterpret_cast<pldm_read_write_file_by_type_resp*>( |
| 1290 | responsePtr->payload); |
| 1291 | |
| 1292 | // Random value for completion code and length |
| 1293 | uint8_t completionCode = 0x0; |
| 1294 | uint32_t length = 0x13245768; |
| 1295 | |
| 1296 | response->completion_code = completionCode; |
| 1297 | response->length = htole32(length); |
| 1298 | |
| 1299 | uint8_t retCompletionCode = 0x1; |
| 1300 | uint32_t retLength = 0; |
| 1301 | |
| 1302 | // Invoke decode the read/write file response |
| 1303 | auto rc = decode_rw_file_by_type_resp(responsePtr, payload_length, |
| 1304 | &retCompletionCode, &retLength); |
| 1305 | |
| 1306 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1307 | ASSERT_EQ(completionCode, retCompletionCode); |
| 1308 | ASSERT_EQ(length, retLength); |
| 1309 | } |
| 1310 | |
| 1311 | TEST(ReadWriteFileByType, testBadDecodeRequest) |
| 1312 | { |
| 1313 | uint16_t fileType = 0; |
| 1314 | uint32_t fileHandle = 0; |
| 1315 | uint32_t offset = 0; |
| 1316 | uint32_t length = 0; |
| 1317 | |
| 1318 | // Request payload message is missing |
| 1319 | auto rc = decode_rw_file_by_type_req(NULL, 0, &fileType, &fileHandle, |
| 1320 | &offset, &length); |
| 1321 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1322 | |
| 1323 | std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 1324 | requestMsg{}; |
| 1325 | |
| 1326 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1327 | |
| 1328 | // Payload length is invalid |
| 1329 | rc = decode_rw_file_by_type_req(requestPtr, 0, &fileType, &fileHandle, |
| 1330 | &offset, &length); |
| 1331 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1332 | } |
| 1333 | |
| 1334 | TEST(ReadWriteFileByType, testBadDecodeResponse) |
| 1335 | { |
| 1336 | uint32_t length = 0; |
| 1337 | uint8_t completionCode = 0; |
| 1338 | |
| 1339 | // Request payload message is missing |
| 1340 | auto rc = decode_rw_file_by_type_resp(NULL, 0, &completionCode, &length); |
| 1341 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1342 | |
| 1343 | std::array<uint8_t, PLDM_RW_FILE_BY_TYPE_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 1344 | responseMsg{}; |
| 1345 | |
| 1346 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1347 | |
| 1348 | // Length is NULL |
| 1349 | rc = decode_rw_file_by_type_resp(responsePtr, responseMsg.size() - hdrSize, |
| 1350 | &completionCode, NULL); |
| 1351 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1352 | |
| 1353 | // Payload length is invalid |
| 1354 | rc = decode_rw_file_by_type_resp(responsePtr, 0, &completionCode, &length); |
| 1355 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1356 | } |
| 1357 | |
| 1358 | TEST(ReadWriteFileByType, testGoodEncodeRequest) |
| 1359 | { |
| 1360 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_REQ_BYTES> |
| 1361 | requestMsg{}; |
| 1362 | |
| 1363 | uint16_t fileType = 0; |
| 1364 | uint32_t fileHandle = 0x12345678; |
| 1365 | uint32_t offset = 0x87654321; |
| 1366 | uint32_t length = 0x13245768; |
| 1367 | uint16_t fileTypeLe = htole16(fileType); |
| 1368 | uint32_t fileHandleLe = htole32(fileHandle); |
| 1369 | uint32_t offsetLe = htole32(offset); |
| 1370 | uint32_t lengthLe = htole32(length); |
| 1371 | |
| 1372 | pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1373 | |
| 1374 | auto rc = encode_rw_file_by_type_req(0, PLDM_READ_FILE_BY_TYPE, fileType, |
| 1375 | fileHandle, offset, length, request); |
| 1376 | |
| 1377 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1378 | ASSERT_EQ(request->hdr.request, PLDM_REQUEST); |
| 1379 | ASSERT_EQ(request->hdr.instance_id, 0); |
| 1380 | ASSERT_EQ(request->hdr.type, PLDM_OEM); |
| 1381 | ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_BY_TYPE); |
| 1382 | |
| 1383 | ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe))); |
| 1384 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe, |
| 1385 | sizeof(fileHandleLe))); |
| 1386 | |
| 1387 | ASSERT_EQ( |
| 1388 | 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe), |
| 1389 | &offsetLe, sizeof(offsetLe))); |
| 1390 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 1391 | sizeof(fileHandleLe) + sizeof(offsetLe), |
| 1392 | &lengthLe, sizeof(lengthLe))); |
| 1393 | } |
| 1394 | |
| 1395 | TEST(ReadWriteFileByType, testGoodEncodeResponse) |
| 1396 | { |
| 1397 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_RESP_BYTES> |
| 1398 | responseMsg{}; |
| 1399 | |
| 1400 | uint32_t length = 0x13245768; |
| 1401 | uint32_t lengthLe = htole32(length); |
| 1402 | uint8_t completionCode = 0x0; |
| 1403 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1404 | |
| 1405 | auto rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE, |
| 1406 | completionCode, length, response); |
| 1407 | |
| 1408 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1409 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1410 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1411 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1412 | ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE); |
| 1413 | |
| 1414 | ASSERT_EQ( |
| 1415 | 0, memcmp(response->payload, &completionCode, sizeof(completionCode))); |
| 1416 | ASSERT_EQ(0, memcmp(response->payload + sizeof(completionCode), &lengthLe, |
| 1417 | sizeof(lengthLe))); |
| 1418 | } |
| 1419 | |
| 1420 | TEST(ReadWriteFileByType, testBadEncodeResponse) |
| 1421 | { |
| 1422 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_BY_TYPE_RESP_BYTES> |
| 1423 | responseMsg{}; |
| 1424 | uint32_t length = 0; |
| 1425 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1426 | |
| 1427 | // completion code is PLDM_ERROR |
| 1428 | auto rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE, PLDM_ERROR, |
| 1429 | length, response); |
| 1430 | |
| 1431 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1432 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1433 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1434 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1435 | ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_BY_TYPE); |
| 1436 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 1437 | |
| 1438 | // response is NULL pointer |
| 1439 | rc = encode_rw_file_by_type_resp(0, PLDM_READ_FILE_BY_TYPE, PLDM_SUCCESS, |
| 1440 | length, NULL); |
| 1441 | |
| 1442 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1443 | } |
| 1444 | |
| 1445 | TEST(ReadWriteFileByType, testBadEncodeRequest) |
| 1446 | { |
| 1447 | uint8_t fileType = 0; |
| 1448 | uint32_t fileHandle = 0; |
| 1449 | uint32_t offset = 0; |
| 1450 | uint32_t length = 0; |
| 1451 | |
| 1452 | // request is NULL pointer |
| 1453 | auto rc = encode_rw_file_by_type_req(0, PLDM_READ_FILE_BY_TYPE, fileType, |
| 1454 | fileHandle, offset, length, NULL); |
| 1455 | |
| 1456 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1457 | } |
| 1458 | |
| 1459 | TEST(FileAck, testGoodDecodeRequest) |
| 1460 | { |
| 1461 | std::array<uint8_t, PLDM_FILE_ACK_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 1462 | requestMsg{}; |
| 1463 | |
| 1464 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1465 | size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr); |
| 1466 | auto request = reinterpret_cast<pldm_file_ack_req*>(requestPtr->payload); |
| 1467 | |
| 1468 | // Random value for fileHandle |
| 1469 | uint16_t fileType = 0xFFFF; |
| 1470 | uint32_t fileHandle = 0x12345678; |
| 1471 | uint8_t fileStatus = 0xFF; |
| 1472 | |
| 1473 | request->file_type = htole16(fileType); |
| 1474 | request->file_handle = htole32(fileHandle); |
| 1475 | request->file_status = fileStatus; |
| 1476 | |
| 1477 | uint16_t retFileType = 0xFF; |
| 1478 | uint32_t retFileHandle = 0; |
| 1479 | uint8_t retFileStatus = 0; |
| 1480 | |
| 1481 | // Invoke decode the read file request |
| 1482 | auto rc = decode_file_ack_req(requestPtr, payload_length, &retFileType, |
| 1483 | &retFileHandle, &retFileStatus); |
| 1484 | |
| 1485 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1486 | ASSERT_EQ(fileType, retFileType); |
| 1487 | ASSERT_EQ(fileHandle, retFileHandle); |
| 1488 | ASSERT_EQ(fileStatus, retFileStatus); |
| 1489 | } |
| 1490 | |
| 1491 | TEST(FileAck, testGoodDecodeResponse) |
| 1492 | { |
| 1493 | std::array<uint8_t, PLDM_FILE_ACK_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 1494 | responseMsg{}; |
| 1495 | |
| 1496 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1497 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 1498 | auto response = reinterpret_cast<pldm_file_ack_resp*>(responsePtr->payload); |
| 1499 | |
| 1500 | // Random value for completion code |
| 1501 | uint8_t completionCode = 0x0; |
| 1502 | |
| 1503 | response->completion_code = completionCode; |
| 1504 | |
| 1505 | uint8_t retCompletionCode = PLDM_SUCCESS; |
| 1506 | |
| 1507 | // Invoke decode the read/write file response |
| 1508 | auto rc = |
| 1509 | decode_file_ack_resp(responsePtr, payload_length, &retCompletionCode); |
| 1510 | |
| 1511 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1512 | ASSERT_EQ(completionCode, retCompletionCode); |
| 1513 | } |
| 1514 | |
| 1515 | TEST(FileAck, testBadDecodeRequest) |
| 1516 | { |
| 1517 | uint16_t fileType = 0; |
| 1518 | uint32_t fileHandle = 0; |
| 1519 | uint8_t fileStatus = 0; |
| 1520 | |
| 1521 | // Request payload message is missing |
| 1522 | auto rc = decode_file_ack_req(NULL, 0, &fileType, &fileHandle, &fileStatus); |
| 1523 | |
| 1524 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1525 | |
| 1526 | std::array<uint8_t, PLDM_FILE_ACK_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 1527 | requestMsg{}; |
| 1528 | |
| 1529 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1530 | |
| 1531 | // Payload length is invalid |
| 1532 | rc = |
| 1533 | decode_file_ack_req(requestPtr, 0, &fileType, &fileHandle, &fileStatus); |
| 1534 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1535 | } |
| 1536 | |
| 1537 | TEST(FileAck, testBadDecodeResponse) |
| 1538 | { |
| 1539 | uint8_t completionCode = 0; |
| 1540 | |
| 1541 | // Request payload message is missing |
| 1542 | auto rc = decode_file_ack_resp(NULL, 0, &completionCode); |
| 1543 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1544 | |
| 1545 | std::array<uint8_t, PLDM_FILE_ACK_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 1546 | responseMsg{}; |
| 1547 | |
| 1548 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1549 | |
| 1550 | // Payload length is invalid |
| 1551 | rc = decode_file_ack_resp(responsePtr, 0, &completionCode); |
| 1552 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1553 | } |
| 1554 | |
| 1555 | TEST(FileAck, testGoodEncodeRequest) |
| 1556 | { |
| 1557 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_REQ_BYTES> |
| 1558 | requestMsg{}; |
| 1559 | |
| 1560 | uint16_t fileType = 0xFFFF; |
| 1561 | uint32_t fileHandle = 0x12345678; |
| 1562 | uint8_t fileStatus = 0xFF; |
| 1563 | uint16_t fileTypeLe = htole16(fileType); |
| 1564 | uint32_t fileHandleLe = htole32(fileHandle); |
| 1565 | |
| 1566 | pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1567 | |
| 1568 | auto rc = encode_file_ack_req(0, fileType, fileHandle, fileStatus, request); |
| 1569 | |
| 1570 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1571 | ASSERT_EQ(request->hdr.request, PLDM_REQUEST); |
| 1572 | ASSERT_EQ(request->hdr.instance_id, 0); |
| 1573 | ASSERT_EQ(request->hdr.type, PLDM_OEM); |
| 1574 | ASSERT_EQ(request->hdr.command, PLDM_FILE_ACK); |
| 1575 | ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe))); |
| 1576 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe, |
| 1577 | sizeof(fileHandleLe))); |
| 1578 | } |
| 1579 | |
| 1580 | TEST(FileAck, testGoodEncodeResponse) |
| 1581 | { |
| 1582 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_RESP_BYTES> |
| 1583 | responseMsg{}; |
| 1584 | |
| 1585 | uint8_t completionCode = 0x0; |
| 1586 | |
| 1587 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1588 | |
| 1589 | auto rc = encode_file_ack_resp(0, completionCode, response); |
| 1590 | |
| 1591 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1592 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1593 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1594 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1595 | ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK); |
| 1596 | ASSERT_EQ( |
| 1597 | 0, memcmp(response->payload, &completionCode, sizeof(completionCode))); |
| 1598 | } |
| 1599 | |
| 1600 | TEST(FileAck, testBadEncodeResponse) |
| 1601 | { |
| 1602 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_RESP_BYTES> |
| 1603 | responseMsg{}; |
| 1604 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1605 | |
| 1606 | // completion code is PLDM_ERROR |
| 1607 | auto rc = encode_file_ack_resp(0, PLDM_ERROR, response); |
| 1608 | |
| 1609 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1610 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1611 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1612 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1613 | ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK); |
| 1614 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 1615 | |
| 1616 | // response is NULL pointer |
| 1617 | rc = encode_file_ack_resp(0, PLDM_SUCCESS, NULL); |
| 1618 | |
| 1619 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1620 | } |
| 1621 | |
| 1622 | TEST(FileAck, testBadEncodeRequest) |
| 1623 | { |
| 1624 | uint8_t fileType = 0xFF; |
| 1625 | uint32_t fileHandle = 0; |
| 1626 | uint8_t fileStatus = 0; |
| 1627 | |
| 1628 | // request is NULL pointer |
| 1629 | auto rc = encode_file_ack_req(0, fileType, fileHandle, fileStatus, nullptr); |
| 1630 | |
| 1631 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1632 | } |
| 1633 | |
| 1634 | TEST(FileAckWithMetadata, testGoodEncodeResponse) |
| 1635 | { |
| 1636 | std::array<uint8_t, |
| 1637 | sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES> |
| 1638 | responseMsg{}; |
| 1639 | |
| 1640 | uint8_t completionCode = 0x0; |
| 1641 | |
| 1642 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1643 | |
| 1644 | auto rc = encode_file_ack_with_meta_data_resp(0, completionCode, response); |
| 1645 | |
| 1646 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1647 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1648 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1649 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1650 | ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK_WITH_META_DATA); |
| 1651 | ASSERT_EQ( |
| 1652 | 0, memcmp(response->payload, &completionCode, sizeof(completionCode))); |
| 1653 | } |
| 1654 | |
| 1655 | TEST(FileAckWithMetadata, testBadEncodeResponse) |
| 1656 | { |
| 1657 | std::array<uint8_t, |
| 1658 | sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES> |
| 1659 | responseMsg{}; |
| 1660 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1661 | |
| 1662 | // completion code is PLDM_ERROR |
| 1663 | auto rc = encode_file_ack_with_meta_data_resp(0, PLDM_ERROR, response); |
| 1664 | |
| 1665 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1666 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1667 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1668 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1669 | ASSERT_EQ(response->hdr.command, PLDM_FILE_ACK_WITH_META_DATA); |
| 1670 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 1671 | |
| 1672 | // response is NULL pointer |
| 1673 | rc = encode_file_ack_with_meta_data_resp(0, PLDM_SUCCESS, NULL); |
| 1674 | |
| 1675 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1676 | } |
| 1677 | |
| 1678 | TEST(FileAckWithMetadata, testGoodDecodeResponse) |
| 1679 | { |
| 1680 | std::array<uint8_t, |
| 1681 | PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 1682 | responseMsg{}; |
| 1683 | |
| 1684 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1685 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 1686 | auto response = reinterpret_cast<pldm_file_ack_with_meta_data_resp*>( |
| 1687 | responsePtr->payload); |
| 1688 | |
| 1689 | // Random value for completion code |
| 1690 | uint8_t completionCode = 0x0; |
| 1691 | |
| 1692 | response->completion_code = completionCode; |
| 1693 | |
| 1694 | uint8_t retCompletionCode = PLDM_SUCCESS; |
| 1695 | |
| 1696 | // Invoke decode the read/write file response |
| 1697 | auto rc = decode_file_ack_with_meta_data_resp(responsePtr, payload_length, |
| 1698 | &retCompletionCode); |
| 1699 | |
| 1700 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1701 | ASSERT_EQ(completionCode, retCompletionCode); |
| 1702 | } |
| 1703 | |
| 1704 | TEST(FileAckWithMetadata, testBadDecodeResponse) |
| 1705 | { |
| 1706 | uint8_t completionCode = 0; |
| 1707 | |
| 1708 | // Request payload message is missing |
| 1709 | auto rc = decode_file_ack_with_meta_data_resp(NULL, 0, &completionCode); |
| 1710 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1711 | |
| 1712 | std::array<uint8_t, |
| 1713 | PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES + sizeof(pldm_msg_hdr)> |
| 1714 | responseMsg{}; |
| 1715 | |
| 1716 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1717 | |
| 1718 | // Payload length is invalid |
| 1719 | rc = decode_file_ack_with_meta_data_resp(responsePtr, 0, &completionCode); |
| 1720 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1721 | } |
| 1722 | |
| 1723 | TEST(FileAckWithMetadata, testGoodEncodeRequest) |
| 1724 | { |
| 1725 | std::array<uint8_t, |
| 1726 | sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES> |
| 1727 | requestMsg{}; |
| 1728 | |
| 1729 | uint16_t fileType = 0xFFFF; |
| 1730 | uint32_t fileHandle = 0x12345678; |
| 1731 | uint8_t fileStatus = 0xFF; |
| 1732 | uint32_t fileMetaData1 = 0xFFFFFFFF; |
| 1733 | uint32_t fileMetaData2 = 0xFFFFFFFF; |
| 1734 | uint32_t fileMetaData3 = 0xFFFFFFFF; |
| 1735 | uint32_t fileMetaData4 = 0xFFFFFFFF; |
| 1736 | |
| 1737 | uint16_t fileTypeLe = htole16(fileType); |
| 1738 | uint32_t fileHandleLe = htole32(fileHandle); |
| 1739 | uint32_t fileMetaData1Le = htole32(fileMetaData1); |
| 1740 | uint32_t fileMetaData2Le = htole32(fileMetaData2); |
| 1741 | uint32_t fileMetaData3Le = htole32(fileMetaData3); |
| 1742 | uint32_t fileMetaData4Le = htole32(fileMetaData4); |
| 1743 | |
| 1744 | pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1745 | |
| 1746 | auto rc = encode_file_ack_with_meta_data_req( |
| 1747 | 0, fileType, fileHandle, fileStatus, fileMetaData1, fileMetaData2, |
| 1748 | fileMetaData3, fileMetaData4, request); |
| 1749 | |
| 1750 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1751 | ASSERT_EQ(request->hdr.request, PLDM_REQUEST); |
| 1752 | ASSERT_EQ(request->hdr.instance_id, 0); |
| 1753 | ASSERT_EQ(request->hdr.type, PLDM_OEM); |
| 1754 | ASSERT_EQ(request->hdr.command, PLDM_FILE_ACK_WITH_META_DATA); |
| 1755 | ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe))); |
| 1756 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe, |
| 1757 | sizeof(fileHandleLe))); |
| 1758 | ASSERT_EQ( |
| 1759 | 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe), |
| 1760 | &fileStatus, sizeof(fileStatus))); |
| 1761 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 1762 | sizeof(fileHandleLe) + sizeof(fileStatus), |
| 1763 | &fileMetaData1Le, sizeof(fileMetaData1Le))); |
| 1764 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 1765 | sizeof(fileHandleLe) + sizeof(fileStatus) + |
| 1766 | sizeof(fileMetaData1Le), |
| 1767 | &fileMetaData2Le, sizeof(fileMetaData2Le))); |
| 1768 | |
| 1769 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 1770 | sizeof(fileHandleLe) + sizeof(fileStatus) + |
| 1771 | sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le), |
| 1772 | &fileMetaData3Le, sizeof(fileMetaData3Le))); |
| 1773 | |
| 1774 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 1775 | sizeof(fileHandleLe) + sizeof(fileStatus) + |
| 1776 | sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le) + |
| 1777 | sizeof(fileMetaData3Le), |
| 1778 | &fileMetaData4Le, sizeof(fileMetaData4Le))); |
| 1779 | } |
| 1780 | |
| 1781 | TEST(FileAckWithMetadata, testBadEncodeRequest) |
| 1782 | { |
| 1783 | uint8_t fileType = 0xFF; |
| 1784 | uint32_t fileHandle = 0; |
| 1785 | uint8_t fileStatus = 0; |
| 1786 | uint32_t fileMetaData1 = 0; |
| 1787 | uint32_t fileMetaData2 = 0; |
| 1788 | uint32_t fileMetaData3 = 0; |
| 1789 | uint32_t fileMetaData4 = 0; |
| 1790 | |
| 1791 | // request is NULL pointer |
| 1792 | auto rc = encode_file_ack_with_meta_data_req( |
| 1793 | 0, fileType, fileHandle, fileStatus, fileMetaData1, fileMetaData2, |
| 1794 | fileMetaData3, fileMetaData4, nullptr); |
| 1795 | |
| 1796 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1797 | } |
| 1798 | |
| 1799 | TEST(FileAckWithMetadata, testGoodDecodeRequest) |
| 1800 | { |
| 1801 | std::array<uint8_t, |
| 1802 | sizeof(pldm_msg_hdr) + PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES> |
| 1803 | requestMsg{}; |
| 1804 | |
| 1805 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1806 | size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr); |
| 1807 | auto request = reinterpret_cast<pldm_file_ack_with_meta_data_req*>( |
| 1808 | requestPtr->payload); |
| 1809 | |
| 1810 | uint16_t fileType = 0xFFFF; |
| 1811 | uint32_t fileHandle = 0x12345678; |
| 1812 | uint8_t fileStatus = 0xFF; |
| 1813 | uint32_t fileMetaData1 = 0x12345678; |
| 1814 | uint32_t fileMetaData2 = 0x87654321; |
| 1815 | uint32_t fileMetaData3 = 0x22121117; |
| 1816 | uint32_t fileMetaData4 = 0x12334345; |
| 1817 | |
| 1818 | request->file_type = htole16(fileType); |
| 1819 | request->file_handle = htole32(fileHandle); |
| 1820 | request->file_status = fileStatus; |
| 1821 | request->file_meta_data_1 = htole32(fileMetaData1); |
| 1822 | request->file_meta_data_2 = htole32(fileMetaData2); |
| 1823 | request->file_meta_data_3 = htole32(fileMetaData3); |
| 1824 | request->file_meta_data_4 = htole32(fileMetaData4); |
| 1825 | |
| 1826 | uint16_t retFileType = 0xFFFF; |
| 1827 | uint32_t retFileHandle = 0; |
| 1828 | uint8_t retFileStatus = 0; |
| 1829 | uint32_t retFileMetaData1 = 0; |
| 1830 | uint32_t retFileMetaData2 = 0; |
| 1831 | uint32_t retFileMetaData3 = 0; |
| 1832 | uint32_t retFileMetaData4 = 0; |
| 1833 | |
| 1834 | auto rc = decode_file_ack_with_meta_data_req( |
| 1835 | requestPtr, payload_length, &retFileType, &retFileHandle, |
| 1836 | &retFileStatus, &retFileMetaData1, &retFileMetaData2, &retFileMetaData3, |
| 1837 | &retFileMetaData4); |
| 1838 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1839 | ASSERT_EQ(fileType, retFileType); |
| 1840 | ASSERT_EQ(fileHandle, retFileHandle); |
| 1841 | ASSERT_EQ(fileStatus, retFileStatus); |
| 1842 | ASSERT_EQ(fileMetaData1, retFileMetaData1); |
| 1843 | ASSERT_EQ(fileMetaData2, retFileMetaData2); |
| 1844 | ASSERT_EQ(fileMetaData3, retFileMetaData3); |
| 1845 | ASSERT_EQ(fileMetaData4, retFileMetaData4); |
| 1846 | } |
| 1847 | |
| 1848 | TEST(FileAckWithMetadata, testBadDecodeRequest) |
| 1849 | { |
| 1850 | uint16_t fileType = 0; |
| 1851 | uint32_t fileHandle = 0; |
| 1852 | uint8_t fileStatus = 0; |
| 1853 | uint32_t fileMetaData1 = 0; |
| 1854 | uint32_t fileMetaData2 = 0; |
| 1855 | uint32_t fileMetaData3 = 0; |
| 1856 | uint32_t fileMetaData4 = 0; |
| 1857 | |
| 1858 | // Request payload message is missing |
| 1859 | auto rc = decode_file_ack_with_meta_data_req( |
| 1860 | NULL, 0, &fileType, &fileHandle, &fileStatus, &fileMetaData1, |
| 1861 | &fileMetaData2, &fileMetaData3, &fileMetaData4); |
| 1862 | |
| 1863 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1864 | |
| 1865 | std::array<uint8_t, |
| 1866 | PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES + sizeof(pldm_msg_hdr)> |
| 1867 | requestMsg{}; |
| 1868 | |
| 1869 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1870 | |
| 1871 | // Payload length is invalid |
| 1872 | rc = decode_file_ack_with_meta_data_req( |
| 1873 | requestPtr, 0, &fileType, &fileHandle, &fileStatus, &fileMetaData1, |
| 1874 | &fileMetaData2, &fileMetaData3, &fileMetaData4); |
| 1875 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1876 | } |
| 1877 | |
| 1878 | TEST(NewFileAvailableWithMetaData, testGoodEncodeResponse) |
| 1879 | { |
| 1880 | std::array<uint8_t, sizeof(pldm_msg_hdr) + |
| 1881 | PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES> |
| 1882 | responseMsg{}; |
| 1883 | |
| 1884 | uint8_t completionCode = 0x0; |
| 1885 | |
| 1886 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1887 | |
| 1888 | auto rc = encode_new_file_with_metadata_resp(0, completionCode, response); |
| 1889 | |
| 1890 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1891 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1892 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1893 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1894 | ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA); |
| 1895 | ASSERT_EQ( |
| 1896 | 0, memcmp(response->payload, &completionCode, sizeof(completionCode))); |
| 1897 | } |
| 1898 | |
| 1899 | TEST(NewFileAvailableWithMetaData, testBadEncodeResponse) |
| 1900 | { |
| 1901 | std::array<uint8_t, sizeof(pldm_msg_hdr) + |
| 1902 | PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES> |
| 1903 | responseMsg{}; |
| 1904 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1905 | |
| 1906 | // completion code is PLDM_ERROR |
| 1907 | auto rc = encode_new_file_with_metadata_resp(0, PLDM_ERROR, response); |
| 1908 | |
| 1909 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1910 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 1911 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 1912 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 1913 | ASSERT_EQ(response->hdr.command, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA); |
| 1914 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 1915 | |
| 1916 | // response is NULL pointer |
| 1917 | rc = encode_new_file_resp(0, PLDM_SUCCESS, NULL); |
| 1918 | |
| 1919 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1920 | } |
| 1921 | |
| 1922 | TEST(NewFileAvailableWithMetaData, testGoodDecodeResponse) |
| 1923 | { |
| 1924 | std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES + |
| 1925 | sizeof(pldm_msg_hdr)> |
| 1926 | responseMsg{}; |
| 1927 | |
| 1928 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1929 | size_t payload_length = responseMsg.size() - sizeof(pldm_msg_hdr); |
| 1930 | auto response = reinterpret_cast<pldm_file_ack_with_meta_data_resp*>( |
| 1931 | responsePtr->payload); |
| 1932 | |
| 1933 | // Random value for completion code |
| 1934 | uint8_t completionCode = 0x0; |
| 1935 | |
| 1936 | response->completion_code = completionCode; |
| 1937 | |
| 1938 | uint8_t retCompletionCode = PLDM_SUCCESS; |
| 1939 | |
| 1940 | // Invoke decode the read/write file response |
| 1941 | auto rc = decode_new_file_with_metadata_resp(responsePtr, payload_length, |
| 1942 | &retCompletionCode); |
| 1943 | |
| 1944 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1945 | ASSERT_EQ(completionCode, retCompletionCode); |
| 1946 | } |
| 1947 | |
| 1948 | TEST(NewFileAvailableWithMetaData, testBadDecodeResponse) |
| 1949 | { |
| 1950 | uint8_t completionCode = 0; |
| 1951 | |
| 1952 | // Request payload message is missing |
| 1953 | auto rc = decode_new_file_with_metadata_resp(NULL, 0, &completionCode); |
| 1954 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1955 | |
| 1956 | std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES + |
| 1957 | sizeof(pldm_msg_hdr)> |
| 1958 | responseMsg{}; |
| 1959 | |
| 1960 | auto responsePtr = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1961 | |
| 1962 | // Payload length is invalid |
| 1963 | rc = decode_new_file_with_metadata_resp(responsePtr, 0, &completionCode); |
| 1964 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1965 | } |
| 1966 | |
| 1967 | TEST(NewFileAvailableWithMetaData, testGoodEncodeRequest) |
| 1968 | { |
| 1969 | std::array<uint8_t, sizeof(pldm_msg_hdr) + |
| 1970 | PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES> |
| 1971 | requestMsg{}; |
| 1972 | |
| 1973 | uint16_t fileType = 0xFFFF; |
| 1974 | uint32_t fileHandle = 0x12345678; |
| 1975 | uint32_t length = 0x13245768; |
| 1976 | uint64_t fileMetaData1 = 0xFFFFFFFF; |
| 1977 | uint32_t fileMetaData2 = 0xFFFFFFFF; |
| 1978 | uint32_t fileMetaData3 = 0xFFFFFFFF; |
| 1979 | uint32_t fileMetaData4 = 0xFFFFFFFF; |
| 1980 | |
| 1981 | uint16_t fileTypeLe = htole16(fileType); |
| 1982 | uint32_t fileHandleLe = htole32(fileHandle); |
| 1983 | uint64_t lengthLe = htole64(length); |
| 1984 | uint32_t fileMetaData1Le = htole32(fileMetaData1); |
| 1985 | uint32_t fileMetaData2Le = htole32(fileMetaData2); |
| 1986 | uint32_t fileMetaData3Le = htole32(fileMetaData3); |
| 1987 | uint32_t fileMetaData4Le = htole32(fileMetaData4); |
| 1988 | |
| 1989 | pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1990 | |
| 1991 | auto rc = encode_new_file_with_metadata_req( |
| 1992 | 0, fileType, fileHandle, length, fileMetaData1, fileMetaData2, |
| 1993 | fileMetaData3, fileMetaData4, request); |
| 1994 | |
| 1995 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 1996 | ASSERT_EQ(request->hdr.request, PLDM_REQUEST); |
| 1997 | ASSERT_EQ(request->hdr.instance_id, 0); |
| 1998 | ASSERT_EQ(request->hdr.type, PLDM_OEM); |
| 1999 | ASSERT_EQ(request->hdr.command, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA); |
| 2000 | ASSERT_EQ(0, memcmp(request->payload, &fileTypeLe, sizeof(fileTypeLe))); |
| 2001 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe), &fileHandleLe, |
| 2002 | sizeof(fileHandleLe))); |
| 2003 | ASSERT_EQ( |
| 2004 | 0, memcmp(request->payload + sizeof(fileTypeLe) + sizeof(fileHandleLe), |
| 2005 | &lengthLe, sizeof(lengthLe))); |
| 2006 | |
| 2007 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 2008 | sizeof(fileHandleLe) + sizeof(lengthLe), |
| 2009 | &fileMetaData1Le, sizeof(fileMetaData1Le))); |
| 2010 | |
| 2011 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 2012 | sizeof(fileHandleLe) + sizeof(lengthLe) + |
| 2013 | sizeof(fileMetaData1Le), |
| 2014 | &fileMetaData2Le, sizeof(fileMetaData2Le))); |
| 2015 | |
| 2016 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 2017 | sizeof(fileHandleLe) + sizeof(lengthLe) + |
| 2018 | sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le), |
| 2019 | &fileMetaData3Le, sizeof(fileMetaData3Le))); |
| 2020 | |
| 2021 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileTypeLe) + |
| 2022 | sizeof(fileHandleLe) + sizeof(lengthLe) + |
| 2023 | sizeof(fileMetaData1Le) + sizeof(fileMetaData2Le) + |
| 2024 | sizeof(fileMetaData3Le), |
| 2025 | &fileMetaData4Le, sizeof(fileMetaData4Le))); |
| 2026 | } |
| 2027 | |
| 2028 | TEST(NewFileAvailableWithMetaData, testBadEncodeRequest) |
| 2029 | { |
| 2030 | uint8_t fileType = 0xFF; |
| 2031 | uint32_t fileHandle = 0; |
| 2032 | uint32_t length = 0; |
| 2033 | uint32_t fileMetaData1 = 0; |
| 2034 | uint32_t fileMetaData2 = 0; |
| 2035 | uint32_t fileMetaData3 = 0; |
| 2036 | uint32_t fileMetaData4 = 0; |
| 2037 | |
| 2038 | // request is NULL pointer |
| 2039 | auto rc = encode_new_file_with_metadata_req( |
| 2040 | 0, fileType, fileHandle, length, fileMetaData1, fileMetaData2, |
| 2041 | fileMetaData3, fileMetaData4, NULL); |
| 2042 | |
| 2043 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2044 | } |
| 2045 | |
| 2046 | TEST(NewFileAvailableWithMetaData, testGoodDecodeRequest) |
| 2047 | { |
| 2048 | std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES + |
| 2049 | sizeof(pldm_msg_hdr)> |
| 2050 | requestMsg{}; |
| 2051 | |
| 2052 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 2053 | size_t payload_length = requestMsg.size() - sizeof(pldm_msg_hdr); |
| 2054 | auto request = |
| 2055 | reinterpret_cast<pldm_new_file_with_metadata_req*>(requestPtr->payload); |
| 2056 | |
| 2057 | // Random value for fileHandle and length |
| 2058 | uint16_t fileType = 0xFFFF; |
| 2059 | uint32_t fileHandle = 0x12345678; |
| 2060 | uint64_t length = 0x13245768; |
| 2061 | uint32_t fileMetaData1 = 0x12345678; |
| 2062 | uint32_t fileMetaData2 = 0x87654321; |
| 2063 | uint32_t fileMetaData3 = 0x22121117; |
| 2064 | uint32_t fileMetaData4 = 0x12334345; |
| 2065 | |
| 2066 | request->file_type = htole16(fileType); |
| 2067 | request->file_handle = htole32(fileHandle); |
| 2068 | request->length = htole64(length); |
| 2069 | request->file_meta_data_1 = htole32(fileMetaData1); |
| 2070 | request->file_meta_data_2 = htole32(fileMetaData2); |
| 2071 | request->file_meta_data_3 = htole32(fileMetaData3); |
| 2072 | request->file_meta_data_4 = htole32(fileMetaData4); |
| 2073 | |
| 2074 | uint16_t retFileType = 0xFFFF; |
| 2075 | uint32_t retFileHandle = 0; |
| 2076 | uint64_t retLength = 0; |
| 2077 | uint32_t retFileMetaData1 = 0; |
| 2078 | uint32_t retFileMetaData2 = 0; |
| 2079 | uint32_t retFileMetaData3 = 0; |
| 2080 | uint32_t retFileMetaData4 = 0; |
| 2081 | |
| 2082 | // Invoke decode the read file request |
| 2083 | auto rc = decode_new_file_with_metadata_req( |
| 2084 | requestPtr, payload_length, &retFileType, &retFileHandle, &retLength, |
| 2085 | &retFileMetaData1, &retFileMetaData2, &retFileMetaData3, |
| 2086 | &retFileMetaData4); |
| 2087 | |
| 2088 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 2089 | ASSERT_EQ(fileType, retFileType); |
| 2090 | ASSERT_EQ(fileHandle, retFileHandle); |
| 2091 | ASSERT_EQ(length, retLength); |
| 2092 | ASSERT_EQ(fileMetaData1, retFileMetaData1); |
| 2093 | ASSERT_EQ(fileMetaData2, retFileMetaData2); |
| 2094 | ASSERT_EQ(fileMetaData3, retFileMetaData3); |
| 2095 | ASSERT_EQ(fileMetaData4, retFileMetaData4); |
| 2096 | } |
| 2097 | |
| 2098 | TEST(NewFileAvailableWithMetaData, testBadDecodeRequest) |
| 2099 | { |
| 2100 | uint16_t fileType = 0; |
| 2101 | uint32_t fileHandle = 0; |
| 2102 | uint64_t length = 0; |
| 2103 | uint32_t fileMetaData1 = 0; |
| 2104 | uint32_t fileMetaData2 = 0; |
| 2105 | uint32_t fileMetaData3 = 0; |
| 2106 | uint32_t fileMetaData4 = 0; |
| 2107 | |
| 2108 | // Request payload message is missing |
| 2109 | auto rc = decode_new_file_with_metadata_req( |
| 2110 | NULL, 0, &fileType, &fileHandle, &length, &fileMetaData1, |
| 2111 | &fileMetaData2, &fileMetaData3, &fileMetaData4); |
| 2112 | |
| 2113 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2114 | |
| 2115 | std::array<uint8_t, PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES + |
| 2116 | sizeof(pldm_msg_hdr)> |
| 2117 | requestMsg{}; |
| 2118 | |
| 2119 | auto requestPtr = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 2120 | |
| 2121 | // Payload length is invalid |
| 2122 | rc = decode_new_file_with_metadata_req( |
| 2123 | requestPtr, 0, &fileType, &fileHandle, &length, &fileMetaData1, |
| 2124 | &fileMetaData2, &fileMetaData3, &fileMetaData4); |
| 2125 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2126 | } |