Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 1 | #include <string.h> |
| 2 | |
| 3 | #include <array> |
| 4 | |
| 5 | #include "libpldm/base.h" |
| 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
Tom Joseph | 4125104 | 2019-02-07 16:17:07 +0530 | [diff] [blame] | 9 | TEST(PackPLDMMessage, BadPathTest) |
| 10 | { |
| 11 | struct pldm_header_info hdr; |
| 12 | struct pldm_header_info* hdr_ptr = NULL; |
| 13 | pldm_msg_hdr msg{}; |
| 14 | |
| 15 | // PLDM header information pointer is NULL |
| 16 | auto rc = pack_pldm_header(hdr_ptr, &msg); |
| 17 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 18 | |
| 19 | // PLDM message pointer is NULL |
| 20 | rc = pack_pldm_header(&hdr, nullptr); |
| 21 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 22 | |
| 23 | // PLDM header information pointer and PLDM message pointer is NULL |
| 24 | rc = pack_pldm_header(hdr_ptr, nullptr); |
| 25 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 26 | |
| 27 | // RESERVED message type |
| 28 | hdr.msg_type = PLDM_RESERVED; |
| 29 | rc = pack_pldm_header(&hdr, &msg); |
| 30 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 31 | |
| 32 | // Instance ID out of range |
| 33 | hdr.msg_type = PLDM_REQUEST; |
| 34 | hdr.instance = 32; |
| 35 | rc = pack_pldm_header(&hdr, &msg); |
| 36 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 37 | |
| 38 | // PLDM type out of range |
| 39 | hdr.msg_type = PLDM_REQUEST; |
| 40 | hdr.instance = 31; |
| 41 | hdr.pldm_type = 64; |
| 42 | rc = pack_pldm_header(&hdr, &msg); |
| 43 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_PLDM_TYPE); |
| 44 | } |
| 45 | |
| 46 | TEST(PackPLDMMessage, RequestMessageGoodPath) |
| 47 | { |
| 48 | struct pldm_header_info hdr; |
| 49 | pldm_msg_hdr msg{}; |
| 50 | |
| 51 | // Message type is REQUEST and lower range of the field values |
| 52 | hdr.msg_type = PLDM_REQUEST; |
| 53 | hdr.instance = 0; |
| 54 | hdr.pldm_type = 0; |
| 55 | hdr.command = 0; |
| 56 | |
| 57 | auto rc = pack_pldm_header(&hdr, &msg); |
| 58 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 59 | ASSERT_EQ(msg.request, 1); |
| 60 | ASSERT_EQ(msg.datagram, 0); |
| 61 | ASSERT_EQ(msg.instance_id, 0); |
| 62 | ASSERT_EQ(msg.type, 0); |
| 63 | ASSERT_EQ(msg.command, 0); |
| 64 | |
| 65 | // Message type is REQUEST and upper range of the field values |
| 66 | hdr.instance = 31; |
| 67 | hdr.pldm_type = 63; |
| 68 | hdr.command = 255; |
| 69 | |
| 70 | rc = pack_pldm_header(&hdr, &msg); |
| 71 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 72 | ASSERT_EQ(msg.request, 1); |
| 73 | ASSERT_EQ(msg.datagram, 0); |
| 74 | ASSERT_EQ(msg.instance_id, 31); |
| 75 | ASSERT_EQ(msg.type, 63); |
| 76 | ASSERT_EQ(msg.command, 255); |
| 77 | |
| 78 | // Message type is PLDM_ASYNC_REQUEST_NOTIFY |
| 79 | hdr.msg_type = PLDM_ASYNC_REQUEST_NOTIFY; |
| 80 | |
| 81 | rc = pack_pldm_header(&hdr, &msg); |
| 82 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 83 | ASSERT_EQ(msg.request, 1); |
| 84 | ASSERT_EQ(msg.datagram, 1); |
| 85 | ASSERT_EQ(msg.instance_id, 31); |
| 86 | ASSERT_EQ(msg.type, 63); |
| 87 | ASSERT_EQ(msg.command, 255); |
| 88 | } |
| 89 | |
| 90 | TEST(PackPLDMMessage, ResponseMessageGoodPath) |
| 91 | { |
| 92 | struct pldm_header_info hdr; |
| 93 | pldm_msg_hdr msg{}; |
| 94 | |
| 95 | // Message type is PLDM_RESPONSE and lower range of the field values |
| 96 | hdr.msg_type = PLDM_RESPONSE; |
| 97 | hdr.instance = 0; |
| 98 | hdr.pldm_type = 0; |
| 99 | hdr.command = 0; |
| 100 | |
| 101 | auto rc = pack_pldm_header(&hdr, &msg); |
| 102 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 103 | ASSERT_EQ(msg.request, 0); |
| 104 | ASSERT_EQ(msg.datagram, 0); |
| 105 | ASSERT_EQ(msg.instance_id, 0); |
| 106 | ASSERT_EQ(msg.type, 0); |
| 107 | ASSERT_EQ(msg.command, 0); |
| 108 | |
| 109 | // Message type is PLDM_RESPONSE and upper range of the field values |
| 110 | hdr.instance = 31; |
| 111 | hdr.pldm_type = 63; |
| 112 | hdr.command = 255; |
| 113 | |
| 114 | rc = pack_pldm_header(&hdr, &msg); |
| 115 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 116 | ASSERT_EQ(msg.request, 0); |
| 117 | ASSERT_EQ(msg.datagram, 0); |
| 118 | ASSERT_EQ(msg.instance_id, 31); |
| 119 | ASSERT_EQ(msg.type, 63); |
| 120 | ASSERT_EQ(msg.command, 255); |
| 121 | } |
| 122 | |
| 123 | TEST(UnpackPLDMMessage, BadPathTest) |
| 124 | { |
| 125 | struct pldm_header_info hdr; |
| 126 | |
| 127 | // PLDM message pointer is NULL |
| 128 | auto rc = unpack_pldm_header(nullptr, &hdr); |
| 129 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 130 | } |
| 131 | |
| 132 | TEST(UnpackPLDMMessage, RequestMessageGoodPath) |
| 133 | { |
| 134 | struct pldm_header_info hdr; |
| 135 | pldm_msg_hdr msg{}; |
| 136 | |
| 137 | // Unpack PLDM request message and lower range of field values |
| 138 | msg.request = 1; |
| 139 | auto rc = unpack_pldm_header(&msg, &hdr); |
| 140 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 141 | ASSERT_EQ(hdr.msg_type, PLDM_REQUEST); |
| 142 | ASSERT_EQ(hdr.instance, 0); |
| 143 | ASSERT_EQ(hdr.pldm_type, 0); |
| 144 | ASSERT_EQ(hdr.command, 0); |
| 145 | |
| 146 | // Unpack PLDM async request message and lower range of field values |
| 147 | msg.datagram = 1; |
| 148 | rc = unpack_pldm_header(&msg, &hdr); |
| 149 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 150 | ASSERT_EQ(hdr.msg_type, PLDM_ASYNC_REQUEST_NOTIFY); |
| 151 | |
| 152 | // Unpack PLDM request message and upper range of field values |
| 153 | msg.datagram = 0; |
| 154 | msg.instance_id = 31; |
| 155 | msg.type = 63; |
| 156 | msg.command = 255; |
| 157 | rc = unpack_pldm_header(&msg, &hdr); |
| 158 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 159 | ASSERT_EQ(hdr.msg_type, PLDM_REQUEST); |
| 160 | ASSERT_EQ(hdr.instance, 31); |
| 161 | ASSERT_EQ(hdr.pldm_type, 63); |
| 162 | ASSERT_EQ(hdr.command, 255); |
| 163 | } |
| 164 | |
| 165 | TEST(UnpackPLDMMessage, ResponseMessageGoodPath) |
| 166 | { |
| 167 | struct pldm_header_info hdr; |
| 168 | pldm_msg_hdr msg{}; |
| 169 | |
| 170 | // Unpack PLDM response message and lower range of field values |
| 171 | auto rc = unpack_pldm_header(&msg, &hdr); |
| 172 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 173 | ASSERT_EQ(hdr.msg_type, PLDM_RESPONSE); |
| 174 | ASSERT_EQ(hdr.instance, 0); |
| 175 | ASSERT_EQ(hdr.pldm_type, 0); |
| 176 | ASSERT_EQ(hdr.command, 0); |
| 177 | |
| 178 | // Unpack PLDM response message and upper range of field values |
| 179 | msg.instance_id = 31; |
| 180 | msg.type = 63; |
| 181 | msg.command = 255; |
| 182 | rc = unpack_pldm_header(&msg, &hdr); |
| 183 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 184 | ASSERT_EQ(hdr.msg_type, PLDM_RESPONSE); |
| 185 | ASSERT_EQ(hdr.instance, 31); |
| 186 | ASSERT_EQ(hdr.pldm_type, 63); |
| 187 | ASSERT_EQ(hdr.command, 255); |
| 188 | } |
| 189 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 190 | TEST(GetPLDMCommands, testEncodeRequest) |
| 191 | { |
| 192 | uint8_t pldmType = 0x05; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 193 | ver32_t version{0xFF, 0xFF, 0xFF, 0xFF}; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 194 | std::array<uint8_t, PLDM_GET_COMMANDS_REQ_BYTES> requestMsg{}; |
| 195 | pldm_msg request{}; |
| 196 | request.body.payload = requestMsg.data(); |
| 197 | request.body.payload_length = requestMsg.size(); |
| 198 | |
| 199 | auto rc = encode_get_commands_req(0, pldmType, version, &request); |
| 200 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 201 | ASSERT_EQ(0, memcmp(request.body.payload, &pldmType, sizeof(pldmType))); |
| 202 | ASSERT_EQ(0, memcmp(request.body.payload + sizeof(pldmType), &version, |
| 203 | sizeof(version))); |
| 204 | } |
| 205 | |
| 206 | TEST(GetPLDMCommands, testDecodeRequest) |
| 207 | { |
| 208 | uint8_t pldmType = 0x05; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 209 | ver32_t version{0xFF, 0xFF, 0xFF, 0xFF}; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 210 | uint8_t pldmTypeOut{}; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 211 | ver32_t versionOut{0xFF, 0xFF, 0xFF, 0xFF}; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 212 | std::array<uint8_t, PLDM_GET_COMMANDS_REQ_BYTES> requestMsg{}; |
| 213 | pldm_msg_payload request{}; |
| 214 | request.payload = requestMsg.data(); |
| 215 | request.payload_length = requestMsg.size(); |
| 216 | |
| 217 | memcpy(request.payload, &pldmType, sizeof(pldmType)); |
| 218 | memcpy(request.payload + sizeof(pldmType), &version, sizeof(version)); |
| 219 | auto rc = decode_get_commands_req(&request, &pldmTypeOut, &versionOut); |
| 220 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 221 | ASSERT_EQ(pldmTypeOut, pldmType); |
| 222 | ASSERT_EQ(0, memcmp(&versionOut, &version, sizeof(version))); |
| 223 | } |
| 224 | |
| 225 | TEST(GetPLDMCommands, testEncodeResponse) |
| 226 | { |
| 227 | uint8_t completionCode = 0; |
| 228 | std::array<uint8_t, PLDM_GET_COMMANDS_RESP_BYTES> responseMsg{}; |
| 229 | pldm_msg response{}; |
| 230 | response.body.payload = responseMsg.data(); |
| 231 | response.body.payload_length = responseMsg.size(); |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 232 | std::array<bitfield8_t, PLDM_MAX_CMDS_PER_TYPE / 8> commands{}; |
| 233 | commands[0].byte = 1; |
| 234 | commands[1].byte = 2; |
| 235 | commands[2].byte = 3; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 236 | |
| 237 | auto rc = |
| 238 | encode_get_commands_resp(0, PLDM_SUCCESS, commands.data(), &response); |
| 239 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 240 | ASSERT_EQ(completionCode, response.body.payload[0]); |
| 241 | ASSERT_EQ(1, response.body.payload[1]); |
| 242 | ASSERT_EQ(2, response.body.payload[2]); |
| 243 | ASSERT_EQ(3, response.body.payload[3]); |
| 244 | } |
| 245 | |
| 246 | TEST(GetPLDMTypes, testEncodeResponse) |
| 247 | { |
| 248 | uint8_t completionCode = 0; |
| 249 | std::array<uint8_t, PLDM_GET_TYPES_RESP_BYTES> responseMsg{}; |
| 250 | pldm_msg response{}; |
| 251 | response.body.payload = responseMsg.data(); |
| 252 | response.body.payload_length = responseMsg.size(); |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 253 | std::array<bitfield8_t, PLDM_MAX_TYPES / 8> types{}; |
| 254 | types[0].byte = 1; |
| 255 | types[1].byte = 2; |
| 256 | types[2].byte = 3; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 257 | |
| 258 | auto rc = encode_get_types_resp(0, PLDM_SUCCESS, types.data(), &response); |
| 259 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 260 | ASSERT_EQ(completionCode, response.body.payload[0]); |
| 261 | ASSERT_EQ(1, response.body.payload[1]); |
| 262 | ASSERT_EQ(2, response.body.payload[2]); |
| 263 | ASSERT_EQ(3, response.body.payload[3]); |
| 264 | } |
| 265 | |
| 266 | TEST(GetPLDMTypes, testDecodeResponse) |
| 267 | { |
| 268 | std::array<uint8_t, PLDM_GET_TYPES_RESP_BYTES> responseMsg{}; |
| 269 | pldm_msg_payload response{}; |
| 270 | response.payload = responseMsg.data(); |
| 271 | response.payload_length = responseMsg.size(); |
| 272 | response.payload[1] = 1; |
| 273 | response.payload[2] = 2; |
| 274 | response.payload[3] = 3; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 275 | std::array<bitfield8_t, PLDM_MAX_TYPES / 8> outTypes{}; |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 276 | uint8_t completion_code; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 277 | |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 278 | auto rc = |
| 279 | decode_get_types_resp(&response, &completion_code, outTypes.data()); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 280 | |
| 281 | ASSERT_EQ(rc, PLDM_SUCCESS); |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 282 | ASSERT_EQ(completion_code, PLDM_SUCCESS); |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 283 | ASSERT_EQ(response.payload[1], outTypes[0].byte); |
| 284 | ASSERT_EQ(response.payload[2], outTypes[1].byte); |
| 285 | ASSERT_EQ(response.payload[3], outTypes[2].byte); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | TEST(GetPLDMCommands, testDecodeResponse) |
| 289 | { |
| 290 | std::array<uint8_t, PLDM_MAX_CMDS_PER_TYPE> responseMsg{}; |
| 291 | pldm_msg_payload response{}; |
| 292 | response.payload = responseMsg.data(); |
| 293 | response.payload_length = responseMsg.size(); |
| 294 | response.payload[1] = 1; |
| 295 | response.payload[2] = 2; |
| 296 | response.payload[3] = 3; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 297 | std::array<bitfield8_t, PLDM_MAX_CMDS_PER_TYPE / 8> outTypes{}; |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 298 | uint8_t completion_code; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 299 | |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 300 | auto rc = |
| 301 | decode_get_commands_resp(&response, &completion_code, outTypes.data()); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 302 | |
| 303 | ASSERT_EQ(rc, PLDM_SUCCESS); |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 304 | ASSERT_EQ(completion_code, PLDM_SUCCESS); |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 305 | ASSERT_EQ(response.payload[1], outTypes[0].byte); |
| 306 | ASSERT_EQ(response.payload[2], outTypes[1].byte); |
| 307 | ASSERT_EQ(response.payload[3], outTypes[2].byte); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 308 | } |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 309 | |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame^] | 310 | TEST(GetPLDMVersion, testGoodEncodeRequest) |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 311 | { |
| 312 | std::array<uint8_t, PLDM_GET_VERSION_REQ_BYTES> requestMsg{}; |
| 313 | pldm_msg request{}; |
| 314 | request.body.payload = requestMsg.data(); |
| 315 | request.body.payload_length = requestMsg.size(); |
| 316 | uint8_t pldmType = 0x03; |
| 317 | uint32_t transferHandle = 0x0; |
| 318 | uint8_t opFlag = 0x01; |
| 319 | |
| 320 | auto rc = |
| 321 | encode_get_version_req(0, transferHandle, opFlag, pldmType, &request); |
| 322 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 323 | ASSERT_EQ(0, memcmp(request.body.payload, &transferHandle, |
| 324 | sizeof(transferHandle))); |
| 325 | ASSERT_EQ(0, memcmp(request.body.payload + sizeof(transferHandle), &opFlag, |
| 326 | sizeof(opFlag))); |
| 327 | ASSERT_EQ(0, memcmp(request.body.payload + sizeof(transferHandle) + |
| 328 | sizeof(opFlag), |
| 329 | &pldmType, sizeof(pldmType))); |
| 330 | } |
| 331 | |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame^] | 332 | TEST(GetPLDMVersion, testBadEncodeRequest) |
| 333 | { |
| 334 | uint8_t pldmType = 0x03; |
| 335 | uint32_t transferHandle = 0x0; |
| 336 | uint8_t opFlag = 0x01; |
| 337 | |
| 338 | auto rc = |
| 339 | encode_get_version_req(0, transferHandle, opFlag, pldmType, nullptr); |
| 340 | |
| 341 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 342 | } |
| 343 | |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 344 | TEST(GetPLDMVersion, testEncodeResponse) |
| 345 | { |
| 346 | pldm_msg response{}; |
| 347 | uint8_t completionCode = 0; |
| 348 | uint32_t transferHandle = 0; |
| 349 | uint8_t flag = PLDM_START_AND_END; |
| 350 | std::array<uint8_t, PLDM_GET_VERSION_RESP_BYTES> responseMsg{}; |
| 351 | response.body.payload = responseMsg.data(); |
| 352 | response.body.payload_length = responseMsg.size(); |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 353 | ver32_t version = {0xFF, 0xFF, 0xFF, 0xFF}; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 354 | |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 355 | auto rc = encode_get_version_resp(0, PLDM_SUCCESS, 0, PLDM_START_AND_END, |
| 356 | &version, sizeof(ver32_t), &response); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 357 | |
| 358 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 359 | ASSERT_EQ(completionCode, response.body.payload[0]); |
| 360 | ASSERT_EQ(0, |
| 361 | memcmp(response.body.payload + sizeof(response.body.payload[0]), |
| 362 | &transferHandle, sizeof(transferHandle))); |
| 363 | ASSERT_EQ(0, |
| 364 | memcmp(response.body.payload + sizeof(response.body.payload[0]) + |
| 365 | sizeof(transferHandle), |
| 366 | &flag, sizeof(flag))); |
| 367 | ASSERT_EQ(0, |
| 368 | memcmp(response.body.payload + sizeof(response.body.payload[0]) + |
| 369 | sizeof(transferHandle) + sizeof(flag), |
| 370 | &version, sizeof(version))); |
| 371 | } |
| 372 | |
| 373 | TEST(GetPLDMVersion, testDecodeRequest) |
| 374 | { |
| 375 | std::array<uint8_t, PLDM_GET_VERSION_REQ_BYTES> requestMsg{}; |
| 376 | pldm_msg_payload request{}; |
| 377 | request.payload = requestMsg.data(); |
| 378 | request.payload_length = requestMsg.size(); |
| 379 | uint32_t transferHandle = 0x0; |
| 380 | uint32_t retTransferHandle = 0x0; |
| 381 | uint8_t flag = PLDM_GET_FIRSTPART; |
| 382 | uint8_t retFlag = PLDM_GET_FIRSTPART; |
| 383 | uint8_t pldmType = PLDM_BASE; |
| 384 | uint8_t retType = PLDM_BASE; |
| 385 | |
| 386 | memcpy(request.payload, &transferHandle, sizeof(transferHandle)); |
| 387 | memcpy(request.payload + sizeof(transferHandle), &flag, sizeof(flag)); |
| 388 | memcpy(request.payload + sizeof(transferHandle) + sizeof(flag), &pldmType, |
| 389 | sizeof(pldmType)); |
| 390 | |
| 391 | auto rc = decode_get_version_req(&request, &retTransferHandle, &retFlag, |
| 392 | &retType); |
| 393 | |
| 394 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 395 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 396 | ASSERT_EQ(flag, retFlag); |
| 397 | ASSERT_EQ(pldmType, retType); |
| 398 | } |
| 399 | |
| 400 | TEST(GetPLDMVersion, testDecodeResponse) |
| 401 | { |
| 402 | std::array<uint8_t, PLDM_GET_VERSION_RESP_BYTES> responseMsg{}; |
| 403 | pldm_msg_payload response{}; |
| 404 | response.payload = responseMsg.data(); |
| 405 | response.payload_length = responseMsg.size(); |
| 406 | uint32_t transferHandle = 0x0; |
| 407 | uint32_t retTransferHandle = 0x0; |
| 408 | uint8_t flag = PLDM_START_AND_END; |
| 409 | uint8_t retFlag = PLDM_START_AND_END; |
| 410 | uint8_t completionCode = 0; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 411 | ver32_t version = {0xFF, 0xFF, 0xFF, 0xFF}; |
| 412 | ver32_t versionOut; |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 413 | uint8_t completion_code; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 414 | |
| 415 | memcpy(response.payload + sizeof(completionCode), &transferHandle, |
| 416 | sizeof(transferHandle)); |
| 417 | memcpy(response.payload + sizeof(completionCode) + sizeof(transferHandle), |
| 418 | &flag, sizeof(flag)); |
| 419 | memcpy(response.payload + sizeof(completionCode) + sizeof(transferHandle) + |
| 420 | sizeof(flag), |
| 421 | &version, sizeof(version)); |
| 422 | |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 423 | auto rc = decode_get_version_resp( |
| 424 | &response, &completion_code, &retTransferHandle, &retFlag, &versionOut); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 425 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 426 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 427 | ASSERT_EQ(flag, retFlag); |
| 428 | |
| 429 | ASSERT_EQ(versionOut.major, version.major); |
| 430 | ASSERT_EQ(versionOut.minor, version.minor); |
| 431 | ASSERT_EQ(versionOut.update, version.update); |
| 432 | ASSERT_EQ(versionOut.alpha, version.alpha); |
| 433 | } |