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