Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [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 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 10 | constexpr auto hdrSize = sizeof(pldm_msg_hdr); |
| 11 | |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 12 | TEST(ReadWriteFileMemory, testGoodDecodeRequest) |
| 13 | { |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 14 | std::array<uint8_t, PLDM_RW_FILE_MEM_REQ_BYTES + hdrSize> requestMsg{}; |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 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 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 22 | memcpy(requestMsg.data() + hdrSize, &fileHandle, sizeof(fileHandle)); |
| 23 | memcpy(requestMsg.data() + sizeof(fileHandle) + hdrSize, &offset, |
| 24 | sizeof(offset)); |
| 25 | memcpy(requestMsg.data() + sizeof(fileHandle) + sizeof(offset) + hdrSize, |
| 26 | &length, sizeof(length)); |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 27 | memcpy(requestMsg.data() + sizeof(fileHandle) + sizeof(offset) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 28 | sizeof(length) + hdrSize, |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 29 | &address, sizeof(address)); |
| 30 | |
| 31 | uint32_t retFileHandle = 0; |
| 32 | uint32_t retOffset = 0; |
| 33 | uint32_t retLength = 0; |
| 34 | uint64_t retAddress = 0; |
| 35 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 36 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 37 | |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 38 | // Invoke decode the read file memory request |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 39 | auto rc = decode_rw_file_memory_req(request, requestMsg.size() - hdrSize, |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 40 | &retFileHandle, &retOffset, &retLength, |
| 41 | &retAddress); |
| 42 | |
| 43 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 44 | ASSERT_EQ(fileHandle, retFileHandle); |
| 45 | ASSERT_EQ(offset, retOffset); |
| 46 | ASSERT_EQ(length, retLength); |
| 47 | ASSERT_EQ(address, retAddress); |
| 48 | } |
| 49 | |
| 50 | TEST(ReadWriteFileMemory, testBadDecodeRequest) |
| 51 | { |
| 52 | uint32_t fileHandle = 0; |
| 53 | uint32_t offset = 0; |
| 54 | uint32_t length = 0; |
| 55 | uint64_t address = 0; |
| 56 | |
| 57 | // Request payload message is missing |
| 58 | auto rc = decode_rw_file_memory_req(NULL, 0, &fileHandle, &offset, &length, |
| 59 | &address); |
| 60 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 61 | |
| 62 | std::array<uint8_t, PLDM_RW_FILE_MEM_REQ_BYTES> requestMsg{}; |
| 63 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 64 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 65 | |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 66 | // Address is NULL |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 67 | rc = decode_rw_file_memory_req(request, requestMsg.size() - hdrSize, |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 68 | &fileHandle, &offset, &length, NULL); |
| 69 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 70 | |
| 71 | // Payload length is invalid |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 72 | rc = decode_rw_file_memory_req(request, 0, &fileHandle, &offset, &length, |
| 73 | &address); |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 74 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 75 | } |
| 76 | |
| 77 | TEST(ReadWriteFileMemory, testGoodEncodeResponse) |
| 78 | { |
| 79 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES> |
| 80 | responseMsg{}; |
| 81 | uint32_t length = 0xFF00EE11; |
| 82 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 83 | |
| 84 | // ReadFileIntoMemory |
| 85 | auto rc = encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY, |
| 86 | PLDM_SUCCESS, length, response); |
| 87 | |
| 88 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 89 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 90 | ASSERT_EQ(response->hdr.instance_id, 0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 91 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 92 | ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_INTO_MEMORY); |
| 93 | ASSERT_EQ(response->payload[0], PLDM_SUCCESS); |
| 94 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 95 | &length, sizeof(length))); |
| 96 | |
| 97 | // WriteFileFromMemory |
| 98 | rc = encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY, |
| 99 | PLDM_SUCCESS, length, response); |
| 100 | |
| 101 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 102 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 103 | ASSERT_EQ(response->hdr.instance_id, 0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 104 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 105 | ASSERT_EQ(response->hdr.command, PLDM_WRITE_FILE_FROM_MEMORY); |
| 106 | ASSERT_EQ(response->payload[0], PLDM_SUCCESS); |
| 107 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 108 | &length, sizeof(length))); |
| 109 | } |
| 110 | |
| 111 | TEST(ReadWriteFileMemory, testBadEncodeResponse) |
| 112 | { |
| 113 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_RESP_BYTES> |
| 114 | responseMsg{}; |
| 115 | uint32_t length = 0; |
| 116 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 117 | |
| 118 | // ReadFileIntoMemory |
| 119 | auto rc = encode_rw_file_memory_resp(0, PLDM_READ_FILE_INTO_MEMORY, |
| 120 | PLDM_ERROR, length, response); |
| 121 | |
| 122 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 123 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 124 | ASSERT_EQ(response->hdr.instance_id, 0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 125 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 126 | ASSERT_EQ(response->hdr.command, PLDM_READ_FILE_INTO_MEMORY); |
| 127 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 128 | |
| 129 | // WriteFileFromMemory |
| 130 | rc = encode_rw_file_memory_resp(0, PLDM_WRITE_FILE_FROM_MEMORY, PLDM_ERROR, |
| 131 | length, response); |
| 132 | |
| 133 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 134 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 135 | ASSERT_EQ(response->hdr.instance_id, 0); |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 136 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 137 | ASSERT_EQ(response->hdr.command, PLDM_WRITE_FILE_FROM_MEMORY); |
| 138 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 139 | } |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 140 | |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 141 | TEST(ReadWriteFileIntoMemory, testGoodDecodeResponse) |
| 142 | { |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 143 | std::array<uint8_t, PLDM_RW_FILE_MEM_RESP_BYTES + hdrSize> responseMsg{}; |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 144 | // Random value for length |
| 145 | uint32_t length = 0xFF00EE12; |
| 146 | uint8_t completionCode = 0; |
| 147 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 148 | memcpy(responseMsg.data() + hdrSize, &completionCode, |
| 149 | sizeof(completionCode)); |
| 150 | memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &length, |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 151 | sizeof(length)); |
| 152 | |
| 153 | uint8_t retCompletionCode = 0; |
| 154 | uint32_t retLength = 0; |
| 155 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 156 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 157 | |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 158 | // Invoke decode the read file memory response |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 159 | auto rc = decode_rw_file_memory_resp(response, responseMsg.size() - hdrSize, |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 160 | &retCompletionCode, &retLength); |
| 161 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 162 | ASSERT_EQ(completionCode, retCompletionCode); |
| 163 | ASSERT_EQ(length, retLength); |
| 164 | } |
| 165 | |
| 166 | TEST(ReadWriteFileIntoMemory, testBadDecodeResponse) |
| 167 | { |
| 168 | uint32_t length = 0; |
| 169 | uint8_t completionCode = 0; |
| 170 | |
| 171 | // Request payload message is missing |
| 172 | auto rc = decode_rw_file_memory_resp(NULL, 0, &completionCode, &length); |
| 173 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 174 | |
| 175 | std::array<uint8_t, PLDM_RW_FILE_MEM_RESP_BYTES> responseMsg{}; |
| 176 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 177 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 178 | |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 179 | // Payload length is invalid |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 180 | rc = decode_rw_file_memory_resp(response, 0, &completionCode, &length); |
Priyanga | 8b97665 | 2019-06-27 11:30:33 -0500 | [diff] [blame] | 181 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 182 | } |
| 183 | |
| 184 | TEST(ReadWriteFileIntoMemory, testGoodEncodeRequest) |
| 185 | { |
| 186 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_RW_FILE_MEM_REQ_BYTES> |
| 187 | requestMsg{}; |
| 188 | |
| 189 | uint32_t fileHandle = 0x12345678; |
| 190 | uint32_t offset = 0x87654321; |
| 191 | uint32_t length = 0x13245768; |
| 192 | uint64_t address = 0x124356879ACBDE0F; |
| 193 | |
| 194 | pldm_msg* request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 195 | |
| 196 | auto rc = |
| 197 | encode_rw_file_memory_req(0, PLDM_READ_FILE_INTO_MEMORY, fileHandle, |
| 198 | offset, length, address, request); |
| 199 | |
| 200 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 201 | ASSERT_EQ(request->hdr.request, PLDM_REQUEST); |
| 202 | ASSERT_EQ(request->hdr.instance_id, 0); |
| 203 | ASSERT_EQ(request->hdr.type, PLDM_OEM); |
| 204 | ASSERT_EQ(request->hdr.command, PLDM_READ_FILE_INTO_MEMORY); |
| 205 | |
| 206 | ASSERT_EQ(0, memcmp(request->payload, &fileHandle, sizeof(fileHandle))); |
| 207 | |
| 208 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandle), &offset, |
| 209 | sizeof(offset))); |
| 210 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandle) + sizeof(offset), |
| 211 | &length, sizeof(length))); |
| 212 | ASSERT_EQ(0, memcmp(request->payload + sizeof(fileHandle) + sizeof(offset) + |
| 213 | sizeof(length), |
| 214 | &address, sizeof(address))); |
| 215 | } |
| 216 | |
| 217 | TEST(ReadWriteFileIntoMemory, testBadEncodeRequest) |
| 218 | { |
| 219 | uint32_t fileHandle = 0; |
| 220 | uint32_t offset = 0; |
| 221 | uint32_t length = 0; |
| 222 | uint64_t address = 0; |
| 223 | |
| 224 | auto rc = |
| 225 | encode_rw_file_memory_req(0, PLDM_READ_FILE_INTO_MEMORY, fileHandle, |
| 226 | offset, length, address, NULL); |
| 227 | |
| 228 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 229 | } |
| 230 | |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 231 | TEST(GetFileTable, GoodDecodeRequest) |
| 232 | { |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 233 | std::array<uint8_t, PLDM_GET_FILE_TABLE_REQ_BYTES + hdrSize> requestMsg{}; |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 234 | |
| 235 | // Random value for DataTransferHandle, TransferOperationFlag, TableType |
| 236 | uint32_t transferHandle = 0x12345678; |
| 237 | uint8_t transferOpFlag = 1; |
| 238 | uint8_t tableType = 1; |
| 239 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 240 | memcpy(requestMsg.data() + hdrSize, &transferHandle, |
| 241 | sizeof(transferHandle)); |
| 242 | memcpy(requestMsg.data() + sizeof(transferHandle) + hdrSize, |
| 243 | &transferOpFlag, sizeof(transferOpFlag)); |
| 244 | memcpy(requestMsg.data() + sizeof(transferHandle) + sizeof(transferOpFlag) + |
| 245 | hdrSize, |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 246 | &tableType, sizeof(tableType)); |
| 247 | |
| 248 | uint32_t retTransferHandle = 0; |
| 249 | uint8_t retTransferOpFlag = 0; |
| 250 | uint8_t retTableType = 0; |
| 251 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 252 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 253 | |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 254 | // Invoke decode get file table request |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 255 | auto rc = decode_get_file_table_req(request, requestMsg.size() - hdrSize, |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 256 | &retTransferHandle, &retTransferOpFlag, |
| 257 | &retTableType); |
| 258 | |
| 259 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 260 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 261 | ASSERT_EQ(transferOpFlag, retTransferOpFlag); |
| 262 | ASSERT_EQ(tableType, retTableType); |
| 263 | } |
| 264 | |
| 265 | TEST(GetFileTable, BadDecodeRequest) |
| 266 | { |
| 267 | uint32_t transferHandle = 0; |
| 268 | uint8_t transferOpFlag = 0; |
| 269 | uint8_t tableType = 0; |
| 270 | |
| 271 | // Request payload message is missing |
| 272 | auto rc = decode_get_file_table_req(nullptr, 0, &transferHandle, |
| 273 | &transferOpFlag, &tableType); |
| 274 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 275 | |
| 276 | std::array<uint8_t, PLDM_GET_FILE_TABLE_REQ_BYTES> requestMsg{}; |
| 277 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 278 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 279 | |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 280 | // TableType is NULL |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 281 | rc = decode_get_file_table_req(request, requestMsg.size() - hdrSize, |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 282 | &transferHandle, &transferOpFlag, nullptr); |
| 283 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 284 | |
| 285 | // Payload length is invalid |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame^] | 286 | rc = decode_get_file_table_req(request, 0, &transferHandle, &transferOpFlag, |
| 287 | &tableType); |
Tom Joseph | 0c6d22c | 2019-06-26 09:58:41 +0530 | [diff] [blame] | 288 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 289 | } |
| 290 | |
| 291 | TEST(GetFileTable, GoodEncodeResponse) |
| 292 | { |
| 293 | // Random value for NextDataTransferHandle and TransferFlag |
| 294 | uint8_t completionCode = 0; |
| 295 | uint32_t nextTransferHandle = 0x87654321; |
| 296 | uint8_t transferFlag = 5; |
| 297 | // Mock file table contents of size 5 |
| 298 | std::array<uint8_t, 5> fileTable = {1, 2, 3, 4, 5}; |
| 299 | constexpr size_t responseSize = sizeof(completionCode) + |
| 300 | sizeof(nextTransferHandle) + |
| 301 | sizeof(transferFlag) + fileTable.size(); |
| 302 | |
| 303 | std::array<uint8_t, sizeof(pldm_msg_hdr) + responseSize> responseMsg{}; |
| 304 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 305 | |
| 306 | // GetFileTable |
| 307 | auto rc = encode_get_file_table_resp(0, PLDM_SUCCESS, nextTransferHandle, |
| 308 | transferFlag, fileTable.data(), |
| 309 | fileTable.size(), response); |
| 310 | |
| 311 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 312 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 313 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 314 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 315 | ASSERT_EQ(response->hdr.command, PLDM_GET_FILE_TABLE); |
| 316 | ASSERT_EQ(response->payload[0], PLDM_SUCCESS); |
| 317 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 318 | &nextTransferHandle, sizeof(nextTransferHandle))); |
| 319 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 320 | sizeof(nextTransferHandle), |
| 321 | &transferFlag, sizeof(transferFlag))); |
| 322 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 323 | sizeof(nextTransferHandle), |
| 324 | &transferFlag, sizeof(transferFlag))); |
| 325 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 326 | sizeof(nextTransferHandle) + sizeof(transferFlag), |
| 327 | fileTable.data(), fileTable.size())); |
| 328 | } |
| 329 | |
| 330 | TEST(GetFileTable, BadEncodeResponse) |
| 331 | { |
| 332 | uint8_t completionCode = 0; |
| 333 | uint32_t nextTransferHandle = 0; |
| 334 | uint8_t transferFlag = 0; |
| 335 | constexpr size_t responseSize = sizeof(completionCode) + |
| 336 | sizeof(nextTransferHandle) + |
| 337 | sizeof(transferFlag); |
| 338 | |
| 339 | std::array<uint8_t, sizeof(pldm_msg_hdr) + responseSize> responseMsg{}; |
| 340 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 341 | |
| 342 | // GetFileTable |
| 343 | auto rc = encode_get_file_table_resp(0, PLDM_ERROR, nextTransferHandle, |
| 344 | transferFlag, nullptr, 0, response); |
| 345 | |
| 346 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 347 | ASSERT_EQ(response->hdr.request, PLDM_RESPONSE); |
| 348 | ASSERT_EQ(response->hdr.instance_id, 0); |
| 349 | ASSERT_EQ(response->hdr.type, PLDM_OEM); |
| 350 | ASSERT_EQ(response->hdr.command, PLDM_GET_FILE_TABLE); |
| 351 | ASSERT_EQ(response->payload[0], PLDM_ERROR); |
| 352 | } |