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}; |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 194 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_REQ_BYTES> |
| 195 | requestMsg{}; |
| 196 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 197 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 198 | auto rc = encode_get_commands_req(0, pldmType, version, request); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 199 | ASSERT_EQ(rc, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 200 | ASSERT_EQ(0, memcmp(request->payload, &pldmType, sizeof(pldmType))); |
| 201 | ASSERT_EQ(0, memcmp(request->payload + sizeof(pldmType), &version, |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 202 | sizeof(version))); |
| 203 | } |
| 204 | |
| 205 | TEST(GetPLDMCommands, testDecodeRequest) |
| 206 | { |
| 207 | uint8_t pldmType = 0x05; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 208 | ver32_t version{0xFF, 0xFF, 0xFF, 0xFF}; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 209 | uint8_t pldmTypeOut{}; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 210 | ver32_t versionOut{0xFF, 0xFF, 0xFF, 0xFF}; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 211 | std::array<uint8_t, PLDM_GET_COMMANDS_REQ_BYTES> requestMsg{}; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 212 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 213 | memcpy(requestMsg.data(), &pldmType, sizeof(pldmType)); |
| 214 | memcpy(requestMsg.data() + sizeof(pldmType), &version, sizeof(version)); |
| 215 | auto rc = decode_get_commands_req(requestMsg.data(), requestMsg.size(), |
| 216 | &pldmTypeOut, &versionOut); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 217 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 218 | ASSERT_EQ(pldmTypeOut, pldmType); |
| 219 | ASSERT_EQ(0, memcmp(&versionOut, &version, sizeof(version))); |
| 220 | } |
| 221 | |
| 222 | TEST(GetPLDMCommands, testEncodeResponse) |
| 223 | { |
| 224 | uint8_t completionCode = 0; |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 225 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_RESP_BYTES> |
| 226 | responseMsg{}; |
| 227 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 228 | std::array<bitfield8_t, PLDM_MAX_CMDS_PER_TYPE / 8> commands{}; |
| 229 | commands[0].byte = 1; |
| 230 | commands[1].byte = 2; |
| 231 | commands[2].byte = 3; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 232 | |
| 233 | auto rc = |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 234 | encode_get_commands_resp(0, PLDM_SUCCESS, commands.data(), response); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 235 | ASSERT_EQ(rc, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 236 | uint8_t* payload_ptr = response->payload; |
| 237 | ASSERT_EQ(completionCode, payload_ptr[0]); |
| 238 | ASSERT_EQ(1, payload_ptr[sizeof(completionCode)]); |
| 239 | ASSERT_EQ(2, |
| 240 | payload_ptr[sizeof(completionCode) + sizeof(commands[0].byte)]); |
| 241 | ASSERT_EQ(3, payload_ptr[sizeof(completionCode) + sizeof(commands[0].byte) + |
| 242 | sizeof(commands[1].byte)]); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | TEST(GetPLDMTypes, testEncodeResponse) |
| 246 | { |
| 247 | uint8_t completionCode = 0; |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 248 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_TYPES_RESP_BYTES> |
| 249 | responseMsg{}; |
| 250 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 251 | std::array<bitfield8_t, PLDM_MAX_TYPES / 8> types{}; |
| 252 | types[0].byte = 1; |
| 253 | types[1].byte = 2; |
| 254 | types[2].byte = 3; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 255 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 256 | auto rc = encode_get_types_resp(0, PLDM_SUCCESS, types.data(), response); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 257 | ASSERT_EQ(rc, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 258 | uint8_t* payload_ptr = response->payload; |
| 259 | ASSERT_EQ(completionCode, payload_ptr[0]); |
| 260 | ASSERT_EQ(1, payload_ptr[sizeof(completionCode)]); |
| 261 | ASSERT_EQ(2, payload_ptr[sizeof(completionCode) + sizeof(types[0].byte)]); |
| 262 | ASSERT_EQ(3, payload_ptr[sizeof(completionCode) + sizeof(types[0].byte) + |
| 263 | sizeof(types[1].byte)]); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | TEST(GetPLDMTypes, testDecodeResponse) |
| 267 | { |
| 268 | std::array<uint8_t, PLDM_GET_TYPES_RESP_BYTES> responseMsg{}; |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 269 | responseMsg[1] = 1; |
| 270 | responseMsg[2] = 2; |
| 271 | responseMsg[3] = 3; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 272 | std::array<bitfield8_t, PLDM_MAX_TYPES / 8> outTypes{}; |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 273 | uint8_t completion_code; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 274 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 275 | auto rc = decode_get_types_resp(responseMsg.data(), responseMsg.size(), |
| 276 | &completion_code, outTypes.data()); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 277 | |
| 278 | ASSERT_EQ(rc, PLDM_SUCCESS); |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 279 | ASSERT_EQ(completion_code, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 280 | ASSERT_EQ(responseMsg[1], outTypes[0].byte); |
| 281 | ASSERT_EQ(responseMsg[2], outTypes[1].byte); |
| 282 | ASSERT_EQ(responseMsg[3], outTypes[2].byte); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | TEST(GetPLDMCommands, testDecodeResponse) |
| 286 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 287 | std::array<uint8_t, PLDM_GET_COMMANDS_RESP_BYTES> responseMsg{}; |
| 288 | responseMsg[1] = 1; |
| 289 | responseMsg[2] = 2; |
| 290 | responseMsg[3] = 3; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 291 | std::array<bitfield8_t, PLDM_MAX_CMDS_PER_TYPE / 8> outTypes{}; |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 292 | uint8_t completion_code; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 293 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 294 | auto rc = decode_get_commands_resp(responseMsg.data(), responseMsg.size(), |
| 295 | &completion_code, outTypes.data()); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 296 | |
| 297 | ASSERT_EQ(rc, PLDM_SUCCESS); |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 298 | ASSERT_EQ(completion_code, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 299 | ASSERT_EQ(responseMsg[1], outTypes[0].byte); |
| 300 | ASSERT_EQ(responseMsg[2], outTypes[1].byte); |
| 301 | ASSERT_EQ(responseMsg[3], outTypes[2].byte); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 302 | } |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 303 | |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 304 | TEST(GetPLDMVersion, testGoodEncodeRequest) |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 305 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 306 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_REQ_BYTES> |
| 307 | requestMsg{}; |
| 308 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 309 | uint8_t pldmType = 0x03; |
| 310 | uint32_t transferHandle = 0x0; |
| 311 | uint8_t opFlag = 0x01; |
| 312 | |
| 313 | auto rc = |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 314 | encode_get_version_req(0, transferHandle, opFlag, pldmType, request); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 315 | ASSERT_EQ(rc, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 316 | ASSERT_EQ( |
| 317 | 0, memcmp(request->payload, &transferHandle, sizeof(transferHandle))); |
| 318 | ASSERT_EQ(0, memcmp(request->payload + sizeof(transferHandle), &opFlag, |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 319 | sizeof(opFlag))); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 320 | ASSERT_EQ(0, |
| 321 | memcmp(request->payload + sizeof(transferHandle) + sizeof(opFlag), |
| 322 | &pldmType, sizeof(pldmType))); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 323 | } |
| 324 | |
Sampa Misra | 94d704b | 2019-02-22 03:36:02 -0600 | [diff] [blame] | 325 | TEST(GetPLDMVersion, testBadEncodeRequest) |
| 326 | { |
| 327 | uint8_t pldmType = 0x03; |
| 328 | uint32_t transferHandle = 0x0; |
| 329 | uint8_t opFlag = 0x01; |
| 330 | |
| 331 | auto rc = |
| 332 | encode_get_version_req(0, transferHandle, opFlag, pldmType, nullptr); |
| 333 | |
| 334 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 335 | } |
| 336 | |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 337 | TEST(GetPLDMVersion, testEncodeResponse) |
| 338 | { |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 339 | uint8_t completionCode = 0; |
| 340 | uint32_t transferHandle = 0; |
| 341 | uint8_t flag = PLDM_START_AND_END; |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 342 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_RESP_BYTES> |
| 343 | responseMsg{}; |
| 344 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 345 | ver32_t version = {0xFF, 0xFF, 0xFF, 0xFF}; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 346 | |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 347 | auto rc = encode_get_version_resp(0, PLDM_SUCCESS, 0, PLDM_START_AND_END, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 348 | &version, sizeof(ver32_t), response); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 349 | |
| 350 | ASSERT_EQ(rc, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 351 | ASSERT_EQ(completionCode, response->payload[0]); |
| 352 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 353 | &transferHandle, sizeof(transferHandle))); |
| 354 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 355 | sizeof(transferHandle), |
| 356 | &flag, sizeof(flag))); |
| 357 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 358 | sizeof(transferHandle) + sizeof(flag), |
| 359 | &version, sizeof(version))); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | TEST(GetPLDMVersion, testDecodeRequest) |
| 363 | { |
| 364 | std::array<uint8_t, PLDM_GET_VERSION_REQ_BYTES> requestMsg{}; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 365 | uint32_t transferHandle = 0x0; |
| 366 | uint32_t retTransferHandle = 0x0; |
| 367 | uint8_t flag = PLDM_GET_FIRSTPART; |
| 368 | uint8_t retFlag = PLDM_GET_FIRSTPART; |
| 369 | uint8_t pldmType = PLDM_BASE; |
| 370 | uint8_t retType = PLDM_BASE; |
| 371 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 372 | memcpy(requestMsg.data(), &transferHandle, sizeof(transferHandle)); |
| 373 | memcpy(requestMsg.data() + sizeof(transferHandle), &flag, sizeof(flag)); |
| 374 | memcpy(requestMsg.data() + sizeof(transferHandle) + sizeof(flag), &pldmType, |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 375 | sizeof(pldmType)); |
| 376 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 377 | auto rc = decode_get_version_req(requestMsg.data(), requestMsg.size(), |
| 378 | &retTransferHandle, &retFlag, &retType); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 379 | |
| 380 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 381 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 382 | ASSERT_EQ(flag, retFlag); |
| 383 | ASSERT_EQ(pldmType, retType); |
| 384 | } |
| 385 | |
| 386 | TEST(GetPLDMVersion, testDecodeResponse) |
| 387 | { |
| 388 | std::array<uint8_t, PLDM_GET_VERSION_RESP_BYTES> responseMsg{}; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 389 | uint32_t transferHandle = 0x0; |
| 390 | uint32_t retTransferHandle = 0x0; |
| 391 | uint8_t flag = PLDM_START_AND_END; |
| 392 | uint8_t retFlag = PLDM_START_AND_END; |
| 393 | uint8_t completionCode = 0; |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 394 | ver32_t version = {0xFF, 0xFF, 0xFF, 0xFF}; |
| 395 | ver32_t versionOut; |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 396 | uint8_t completion_code; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 397 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 398 | memcpy(responseMsg.data() + sizeof(completionCode), &transferHandle, |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 399 | sizeof(transferHandle)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 400 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(transferHandle), |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 401 | &flag, sizeof(flag)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 402 | memcpy(responseMsg.data() + sizeof(completionCode) + |
| 403 | sizeof(transferHandle) + sizeof(flag), |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 404 | &version, sizeof(version)); |
| 405 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 406 | auto rc = decode_get_version_resp(responseMsg.data(), responseMsg.size(), |
| 407 | &completion_code, &retTransferHandle, |
| 408 | &retFlag, &versionOut); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 409 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 410 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 411 | ASSERT_EQ(flag, retFlag); |
| 412 | |
| 413 | ASSERT_EQ(versionOut.major, version.major); |
| 414 | ASSERT_EQ(versionOut.minor, version.minor); |
| 415 | ASSERT_EQ(versionOut.update, version.update); |
| 416 | ASSERT_EQ(versionOut.alpha, version.alpha); |
| 417 | } |