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