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