Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1 | #include <string.h> |
| 2 | |
| 3 | #include <array> |
| 4 | |
| 5 | #include "libpldm/base.h" |
| 6 | #include "libpldm/bios.h" |
| 7 | #include "libpldm/utils.h" |
| 8 | |
| 9 | #include <gtest/gtest.h> |
| 10 | |
| 11 | constexpr auto hdrSize = sizeof(pldm_msg_hdr); |
| 12 | |
| 13 | TEST(GetDateTime, testEncodeRequest) |
| 14 | { |
| 15 | pldm_msg request{}; |
| 16 | |
| 17 | auto rc = encode_get_date_time_req(0, &request); |
| 18 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 19 | } |
| 20 | |
| 21 | TEST(GetDateTime, testEncodeResponse) |
| 22 | { |
| 23 | uint8_t completionCode = 0; |
| 24 | uint8_t seconds = 50; |
| 25 | uint8_t minutes = 20; |
| 26 | uint8_t hours = 5; |
| 27 | uint8_t day = 23; |
| 28 | uint8_t month = 11; |
| 29 | uint16_t year = 2019; |
| 30 | |
| 31 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_DATE_TIME_RESP_BYTES> |
| 32 | responseMsg{}; |
| 33 | |
| 34 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 35 | |
| 36 | auto rc = encode_get_date_time_resp(0, PLDM_SUCCESS, seconds, minutes, |
| 37 | hours, day, month, year, response); |
| 38 | |
| 39 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 40 | EXPECT_EQ(completionCode, response->payload[0]); |
| 41 | |
| 42 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 43 | &seconds, sizeof(seconds))); |
| 44 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 45 | sizeof(seconds), |
| 46 | &minutes, sizeof(minutes))); |
| 47 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 48 | sizeof(seconds) + sizeof(minutes), |
| 49 | &hours, sizeof(hours))); |
| 50 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 51 | sizeof(seconds) + sizeof(minutes) + sizeof(hours), |
| 52 | &day, sizeof(day))); |
| 53 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 54 | sizeof(seconds) + sizeof(minutes) + sizeof(hours) + |
| 55 | sizeof(day), |
| 56 | &month, sizeof(month))); |
| 57 | uint16_t yearLe = htole16(year); |
| 58 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 59 | sizeof(seconds) + sizeof(minutes) + sizeof(hours) + |
| 60 | sizeof(day) + sizeof(month), |
| 61 | &yearLe, sizeof(yearLe))); |
| 62 | } |
| 63 | |
| 64 | TEST(GetDateTime, testDecodeResponse) |
| 65 | { |
| 66 | std::array<uint8_t, hdrSize + PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{}; |
| 67 | |
| 68 | uint8_t completionCode = 0; |
| 69 | |
| 70 | uint8_t seconds = 55; |
| 71 | uint8_t minutes = 2; |
| 72 | uint8_t hours = 8; |
| 73 | uint8_t day = 9; |
| 74 | uint8_t month = 7; |
| 75 | uint16_t year = 2020; |
| 76 | uint16_t yearLe = htole16(year); |
| 77 | |
| 78 | uint8_t retSeconds = 0; |
| 79 | uint8_t retMinutes = 0; |
| 80 | uint8_t retHours = 0; |
| 81 | uint8_t retDay = 0; |
| 82 | uint8_t retMonth = 0; |
| 83 | uint16_t retYear = 0; |
| 84 | |
| 85 | memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &seconds, |
| 86 | sizeof(seconds)); |
| 87 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
| 88 | hdrSize, |
| 89 | &minutes, sizeof(minutes)); |
| 90 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
| 91 | sizeof(minutes) + hdrSize, |
| 92 | &hours, sizeof(hours)); |
| 93 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
| 94 | sizeof(minutes) + sizeof(hours) + hdrSize, |
| 95 | &day, sizeof(day)); |
| 96 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
| 97 | sizeof(minutes) + sizeof(hours) + sizeof(day) + hdrSize, |
| 98 | &month, sizeof(month)); |
| 99 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
| 100 | sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month) + |
| 101 | hdrSize, |
| 102 | &yearLe, sizeof(yearLe)); |
| 103 | |
| 104 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 105 | |
| 106 | auto rc = decode_get_date_time_resp( |
| 107 | response, responseMsg.size() - hdrSize, &completionCode, &retSeconds, |
| 108 | &retMinutes, &retHours, &retDay, &retMonth, &retYear); |
| 109 | |
| 110 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 111 | EXPECT_EQ(seconds, retSeconds); |
| 112 | EXPECT_EQ(minutes, retMinutes); |
| 113 | EXPECT_EQ(hours, retHours); |
| 114 | EXPECT_EQ(day, retDay); |
| 115 | EXPECT_EQ(month, retMonth); |
| 116 | EXPECT_EQ(year, retYear); |
| 117 | } |
| 118 | |
| 119 | TEST(SetDateTime, testGoodEncodeResponse) |
| 120 | { |
| 121 | uint8_t instanceId = 0; |
| 122 | uint8_t completionCode = PLDM_SUCCESS; |
| 123 | |
| 124 | std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)> |
| 125 | responseMsg{}; |
| 126 | struct pldm_msg* response = |
| 127 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 128 | |
| 129 | auto rc = encode_set_date_time_resp(instanceId, completionCode, response, |
| 130 | responseMsg.size() - hdrSize); |
| 131 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 132 | |
| 133 | struct pldm_only_cc_resp* resp = |
| 134 | reinterpret_cast<struct pldm_only_cc_resp*>(response->payload); |
| 135 | EXPECT_EQ(completionCode, resp->completion_code); |
| 136 | } |
| 137 | |
| 138 | TEST(SetDateTime, testBadEncodeResponse) |
| 139 | { |
| 140 | |
| 141 | uint8_t instanceId = 10; |
| 142 | uint8_t completionCode = PLDM_SUCCESS; |
| 143 | std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)> |
| 144 | responseMsg{}; |
| 145 | struct pldm_msg* response = |
| 146 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 147 | auto rc = encode_set_date_time_resp(instanceId, completionCode, nullptr, |
| 148 | responseMsg.size() - hdrSize); |
| 149 | |
| 150 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 151 | rc = encode_set_date_time_resp(instanceId, completionCode, response, |
| 152 | responseMsg.size() - hdrSize - 1); |
| 153 | |
| 154 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 155 | } |
| 156 | |
| 157 | TEST(SetDateTime, testGoodDecodeResponse) |
| 158 | { |
| 159 | uint8_t completionCode = PLDM_SUCCESS; |
| 160 | std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)> |
| 161 | responseMsg{}; |
| 162 | struct pldm_msg* response = |
| 163 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 164 | struct pldm_only_cc_resp* resp = |
| 165 | reinterpret_cast<struct pldm_only_cc_resp*>(response->payload); |
| 166 | |
| 167 | resp->completion_code = completionCode; |
| 168 | |
| 169 | uint8_t retCompletionCode; |
| 170 | auto rc = decode_set_date_time_resp(response, responseMsg.size() - hdrSize, |
| 171 | &retCompletionCode); |
| 172 | |
| 173 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 174 | EXPECT_EQ(completionCode, retCompletionCode); |
| 175 | } |
| 176 | |
| 177 | TEST(SetDateTime, testBadDecodeResponse) |
| 178 | { |
| 179 | uint8_t completionCode = PLDM_SUCCESS; |
| 180 | |
| 181 | std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)> |
| 182 | responseMsg{}; |
| 183 | struct pldm_msg* response = |
| 184 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 185 | auto rc = decode_set_date_time_resp(nullptr, responseMsg.size() - hdrSize, |
| 186 | &completionCode); |
| 187 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 188 | |
| 189 | rc = decode_set_date_time_resp(response, responseMsg.size() - hdrSize - 1, |
| 190 | &completionCode); |
| 191 | |
| 192 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 193 | } |
| 194 | |
| 195 | TEST(SetDateTime, testGoodEncodeRequset) |
| 196 | { |
| 197 | uint8_t instanceId = 0; |
| 198 | uint8_t seconds = 50; |
| 199 | uint8_t minutes = 20; |
| 200 | uint8_t hours = 10; |
| 201 | uint8_t day = 11; |
| 202 | uint8_t month = 11; |
| 203 | uint16_t year = 2019; |
| 204 | |
| 205 | std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)> |
| 206 | requestMsg{}; |
| 207 | |
| 208 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 209 | auto rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, day, |
| 210 | month, year, request, |
| 211 | requestMsg.size() - hdrSize); |
| 212 | |
| 213 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 214 | |
| 215 | struct pldm_set_date_time_req* req = |
| 216 | reinterpret_cast<struct pldm_set_date_time_req*>(request->payload); |
| 217 | EXPECT_EQ(seconds, bcd2dec8(req->seconds)); |
| 218 | EXPECT_EQ(minutes, bcd2dec8(req->minutes)); |
| 219 | EXPECT_EQ(hours, bcd2dec8(req->hours)); |
| 220 | EXPECT_EQ(day, bcd2dec8(req->day)); |
| 221 | EXPECT_EQ(month, bcd2dec8(req->month)); |
| 222 | EXPECT_EQ(year, bcd2dec16(le16toh(req->year))); |
| 223 | } |
| 224 | |
| 225 | TEST(SetDateTime, testBadEncodeRequset) |
| 226 | { |
| 227 | uint8_t instanceId = 0; |
| 228 | |
| 229 | uint8_t seconds = 50; |
| 230 | uint8_t minutes = 20; |
| 231 | uint8_t hours = 10; |
| 232 | uint8_t day = 13; |
| 233 | uint8_t month = 11; |
| 234 | uint16_t year = 2019; |
| 235 | |
| 236 | uint8_t erday = 43; |
| 237 | |
| 238 | std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)> |
| 239 | requestMsg{}; |
| 240 | |
| 241 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 242 | |
| 243 | auto rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, day, |
| 244 | month, year, nullptr, |
| 245 | requestMsg.size() - hdrSize); |
| 246 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 247 | |
| 248 | rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, erday, |
| 249 | month, year, request, |
| 250 | requestMsg.size() - hdrSize); |
| 251 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 252 | |
| 253 | rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, day, |
| 254 | month, year, request, |
| 255 | requestMsg.size() - hdrSize - 4); |
| 256 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 257 | } |
| 258 | |
| 259 | TEST(SetDateTime, testGoodDecodeRequest) |
| 260 | { |
| 261 | std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)> |
| 262 | requestMsg{}; |
| 263 | uint8_t seconds = 0x50; |
| 264 | uint8_t minutes = 0x20; |
| 265 | uint8_t hours = 0x10; |
| 266 | uint8_t day = 0x11; |
| 267 | uint8_t month = 0x11; |
| 268 | uint16_t year = 0x2019; |
| 269 | |
| 270 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 271 | struct pldm_set_date_time_req* req = |
| 272 | reinterpret_cast<struct pldm_set_date_time_req*>(request->payload); |
| 273 | req->seconds = seconds; |
| 274 | req->minutes = minutes; |
| 275 | req->hours = hours; |
| 276 | req->day = day; |
| 277 | req->month = month; |
| 278 | req->year = htole16(year); |
| 279 | |
| 280 | uint8_t retseconds; |
| 281 | uint8_t retminutes; |
| 282 | uint8_t rethours; |
| 283 | uint8_t retday; |
| 284 | uint8_t retmonth; |
| 285 | uint16_t retyear; |
| 286 | |
| 287 | auto rc = decode_set_date_time_req(request, requestMsg.size() - hdrSize, |
| 288 | &retseconds, &retminutes, &rethours, |
| 289 | &retday, &retmonth, &retyear); |
| 290 | |
| 291 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 292 | EXPECT_EQ(retseconds, 50); |
| 293 | EXPECT_EQ(retminutes, 20); |
| 294 | EXPECT_EQ(rethours, 10); |
| 295 | EXPECT_EQ(retday, 11); |
| 296 | EXPECT_EQ(retmonth, 11); |
| 297 | EXPECT_EQ(retyear, 2019); |
| 298 | } |
| 299 | |
| 300 | TEST(SetDateTime, testBadDecodeRequest) |
| 301 | { |
| 302 | uint8_t seconds = 0x50; |
| 303 | uint8_t minutes = 0x20; |
| 304 | uint8_t hours = 0x10; |
| 305 | uint8_t day = 0x11; |
| 306 | uint8_t month = 0x11; |
| 307 | uint16_t year = htole16(0x2019); |
| 308 | |
| 309 | std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)> |
| 310 | requestMsg{}; |
| 311 | |
| 312 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 313 | |
| 314 | decode_set_date_time_req(request, requestMsg.size() - hdrSize, &seconds, |
| 315 | &minutes, &hours, &day, &month, &year); |
| 316 | |
| 317 | auto rc = |
| 318 | decode_set_date_time_req(nullptr, requestMsg.size() - hdrSize, &seconds, |
| 319 | &minutes, &hours, &day, &month, &year); |
| 320 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 321 | |
| 322 | rc = decode_set_date_time_req(request, requestMsg.size() - hdrSize, nullptr, |
| 323 | nullptr, nullptr, nullptr, nullptr, nullptr); |
| 324 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 325 | |
| 326 | rc = decode_set_date_time_req(request, requestMsg.size() - hdrSize - 4, |
| 327 | &seconds, &minutes, &hours, &day, &month, |
| 328 | &year); |
| 329 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 330 | } |
| 331 | |
| 332 | TEST(GetBIOSTable, testGoodEncodeResponse) |
| 333 | { |
| 334 | std::array<uint8_t, |
| 335 | sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4> |
| 336 | responseMsg{}; |
| 337 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 338 | |
| 339 | uint8_t completionCode = PLDM_SUCCESS; |
| 340 | uint32_t nextTransferHandle = 32; |
| 341 | uint8_t transferFlag = PLDM_START_AND_END; |
| 342 | std::array<uint8_t, 4> tableData{1, 2, 3, 4}; |
| 343 | |
| 344 | auto rc = encode_get_bios_table_resp( |
| 345 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, tableData.data(), |
| 346 | sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4, |
| 347 | response); |
| 348 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 349 | |
| 350 | struct pldm_get_bios_table_resp* resp = |
| 351 | reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload); |
| 352 | |
| 353 | EXPECT_EQ(completionCode, resp->completion_code); |
| 354 | EXPECT_EQ(nextTransferHandle, le32toh(resp->next_transfer_handle)); |
| 355 | EXPECT_EQ(transferFlag, resp->transfer_flag); |
| 356 | EXPECT_EQ(0, memcmp(tableData.data(), resp->table_data, tableData.size())); |
| 357 | } |
| 358 | |
| 359 | TEST(GetBIOSTable, testBadEncodeResponse) |
| 360 | { |
| 361 | uint32_t nextTransferHandle = 32; |
| 362 | uint8_t transferFlag = PLDM_START_AND_END; |
| 363 | std::array<uint8_t, 4> tableData{1, 2, 3, 4}; |
| 364 | |
| 365 | auto rc = encode_get_bios_table_resp( |
| 366 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, tableData.data(), |
| 367 | sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4, nullptr); |
| 368 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 369 | } |
| 370 | |
| 371 | TEST(GetBIOSTable, testGoodEncodeRequest) |
| 372 | { |
| 373 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_REQ_BYTES> |
| 374 | requestMsg{}; |
| 375 | uint32_t transferHandle = 0x0; |
| 376 | uint8_t transferOpFlag = 0x01; |
| 377 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 378 | |
| 379 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 380 | auto rc = encode_get_bios_table_req(0, transferHandle, transferOpFlag, |
| 381 | tableType, request); |
| 382 | |
| 383 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 384 | |
| 385 | struct pldm_get_bios_table_req* req = |
| 386 | reinterpret_cast<struct pldm_get_bios_table_req*>(request->payload); |
| 387 | EXPECT_EQ(transferHandle, le32toh(req->transfer_handle)); |
| 388 | EXPECT_EQ(transferOpFlag, req->transfer_op_flag); |
| 389 | EXPECT_EQ(tableType, req->table_type); |
| 390 | } |
| 391 | |
| 392 | TEST(GetBIOSTable, testBadEncodeRequest) |
| 393 | { |
| 394 | uint32_t transferHandle = 0x0; |
| 395 | uint8_t transferOpFlag = 0x01; |
| 396 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 397 | |
| 398 | auto rc = encode_get_bios_table_req(0, transferHandle, transferOpFlag, |
| 399 | tableType, nullptr); |
| 400 | |
| 401 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 402 | } |
| 403 | |
| 404 | TEST(GetBIOSTable, testGoodDecodeRequest) |
| 405 | { |
| 406 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 407 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 408 | uint32_t transferHandle = 31; |
| 409 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 410 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 411 | uint32_t retTransferHandle = 0; |
| 412 | uint8_t retTransferOpFlag = 0; |
| 413 | uint8_t retTableType = 0; |
| 414 | |
| 415 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 416 | struct pldm_get_bios_table_req* request = |
| 417 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 418 | |
| 419 | request->transfer_handle = htole32(transferHandle); |
| 420 | request->transfer_op_flag = transferOpFlag; |
| 421 | request->table_type = tableType; |
| 422 | |
| 423 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size, |
| 424 | &retTransferHandle, &retTransferOpFlag, |
| 425 | &retTableType); |
| 426 | |
| 427 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 428 | EXPECT_EQ(transferHandle, retTransferHandle); |
| 429 | EXPECT_EQ(transferOpFlag, retTransferOpFlag); |
| 430 | EXPECT_EQ(tableType, retTableType); |
| 431 | } |
| 432 | TEST(GetBIOSTable, testBadDecodeRequest) |
| 433 | { |
| 434 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 435 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 436 | uint32_t transferHandle = 31; |
| 437 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 438 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 439 | uint32_t retTransferHandle = 0; |
| 440 | uint8_t retTransferOpFlag = 0; |
| 441 | uint8_t retTableType = 0; |
| 442 | |
| 443 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 444 | struct pldm_get_bios_table_req* request = |
| 445 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 446 | |
| 447 | request->transfer_handle = htole32(transferHandle); |
| 448 | request->transfer_op_flag = transferOpFlag; |
| 449 | request->table_type = tableType; |
| 450 | |
| 451 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size, |
| 452 | &retTransferHandle, &retTransferOpFlag, |
| 453 | &retTableType); |
| 454 | |
| 455 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 456 | EXPECT_EQ(transferHandle, retTransferHandle); |
| 457 | EXPECT_EQ(transferOpFlag, retTransferOpFlag); |
| 458 | EXPECT_EQ(tableType, retTableType); |
| 459 | } |
| 460 | /* |
| 461 | TEST(GetBIOSTable, testBadDecodeRequest) |
| 462 | { |
| 463 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 464 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 465 | uint32_t transferHandle = 31; |
| 466 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 467 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 468 | uint32_t retTransferHandle = 0; |
| 469 | uint8_t retTransferOpFlag = 0; |
| 470 | uint8_t retTableType = 0; |
| 471 | |
| 472 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 473 | struct pldm_get_bios_table_req* request = |
| 474 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 475 | |
| 476 | request->transfer_handle = htole32(transferHandle); |
| 477 | request->transfer_op_flag = transferOpFlag; |
| 478 | request->table_type = tableType; |
| 479 | |
| 480 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size - 3, |
| 481 | &retTransferHandle, &retTransferOpFlag, |
| 482 | &retTableType); |
| 483 | |
| 484 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 485 | }*/ |
| 486 | |
| 487 | TEST(GetBIOSAttributeCurrentValueByHandle, testGoodDecodeRequest) |
| 488 | { |
| 489 | uint32_t transferHandle = 45; |
| 490 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 491 | uint16_t attributehandle = 10; |
| 492 | uint32_t retTransferHandle = 0; |
| 493 | uint8_t retTransferOpFlag = 0; |
| 494 | uint16_t retattributehandle = 0; |
| 495 | std::array<uint8_t, hdrSize + sizeof(transferHandle) + |
| 496 | sizeof(transferOpFlag) + sizeof(attributehandle)> |
| 497 | requestMsg{}; |
| 498 | |
| 499 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 500 | struct pldm_get_bios_attribute_current_value_by_handle_req* request = |
| 501 | reinterpret_cast< |
| 502 | struct pldm_get_bios_attribute_current_value_by_handle_req*>( |
| 503 | req->payload); |
| 504 | |
| 505 | request->transfer_handle = htole32(transferHandle); |
| 506 | request->transfer_op_flag = transferOpFlag; |
| 507 | request->attribute_handle = htole16(attributehandle); |
| 508 | |
| 509 | auto rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 510 | req, requestMsg.size() - hdrSize, &retTransferHandle, |
| 511 | &retTransferOpFlag, &retattributehandle); |
| 512 | |
| 513 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 514 | EXPECT_EQ(transferHandle, retTransferHandle); |
| 515 | EXPECT_EQ(transferOpFlag, retTransferOpFlag); |
| 516 | EXPECT_EQ(attributehandle, retattributehandle); |
| 517 | } |
| 518 | |
| 519 | TEST(GetBIOSAttributeCurrentValueByHandle, testBadDecodeRequest) |
| 520 | { |
| 521 | |
| 522 | uint32_t transferHandle = 0; |
| 523 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 524 | uint16_t attribute_handle = 0; |
| 525 | uint32_t retTransferHandle = 0; |
| 526 | uint8_t retTransferOpFlag = 0; |
| 527 | uint16_t retattribute_handle = 0; |
| 528 | std::array<uint8_t, hdrSize + sizeof(transferHandle) + |
| 529 | sizeof(transferOpFlag) + sizeof(attribute_handle)> |
| 530 | requestMsg{}; |
| 531 | |
| 532 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 533 | struct pldm_get_bios_attribute_current_value_by_handle_req* request = |
| 534 | reinterpret_cast< |
| 535 | struct pldm_get_bios_attribute_current_value_by_handle_req*>( |
| 536 | req->payload); |
| 537 | |
| 538 | request->transfer_handle = htole32(transferHandle); |
| 539 | request->transfer_op_flag = transferOpFlag; |
| 540 | request->attribute_handle = attribute_handle; |
| 541 | |
| 542 | auto rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 543 | NULL, requestMsg.size() - hdrSize, &retTransferHandle, |
| 544 | &retTransferOpFlag, &retattribute_handle); |
| 545 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 546 | |
| 547 | transferHandle = 31; |
| 548 | request->transfer_handle = htole32(transferHandle); |
| 549 | |
| 550 | rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 551 | req, 0, &retTransferHandle, &retTransferOpFlag, &retattribute_handle); |
| 552 | |
| 553 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 554 | } |
| 555 | |
| 556 | TEST(GetBIOSAttributeCurrentValueByHandle, testGoodEncodeRequest) |
| 557 | { |
| 558 | std::array<uint8_t, sizeof(pldm_msg_hdr) + |
| 559 | PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES> |
| 560 | requestMsg{}; |
| 561 | uint32_t transferHandle = 45; |
| 562 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 563 | uint8_t attributeHandle = 10; |
| 564 | |
| 565 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 566 | auto rc = encode_get_bios_attribute_current_value_by_handle_req( |
| 567 | 0, transferHandle, transferOpFlag, attributeHandle, request); |
| 568 | |
| 569 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 570 | |
| 571 | struct pldm_get_bios_attribute_current_value_by_handle_req* req = |
| 572 | reinterpret_cast< |
| 573 | struct pldm_get_bios_attribute_current_value_by_handle_req*>( |
| 574 | request->payload); |
| 575 | EXPECT_EQ(transferHandle, le32toh(req->transfer_handle)); |
| 576 | EXPECT_EQ(transferOpFlag, req->transfer_op_flag); |
| 577 | EXPECT_EQ(attributeHandle, le16toh(req->attribute_handle)); |
| 578 | } |
| 579 | |
| 580 | TEST(GetBIOSAttributeCurrentValueByHandle, testBadEncodeRequest) |
| 581 | { |
| 582 | uint32_t transferHandle = 0; |
| 583 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 584 | uint8_t attributeHandle = 0; |
| 585 | |
| 586 | auto rc = encode_get_bios_attribute_current_value_by_handle_req( |
| 587 | 0, transferHandle, transferOpFlag, attributeHandle, nullptr); |
| 588 | |
| 589 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 590 | } |
| 591 | |
| 592 | TEST(GetBIOSAttributeCurrentValueByHandle, testGoodEncodeResponse) |
| 593 | { |
| 594 | |
| 595 | uint8_t instanceId = 10; |
| 596 | uint8_t completionCode = PLDM_SUCCESS; |
| 597 | uint32_t nextTransferHandle = 32; |
| 598 | uint8_t transferFlag = PLDM_START_AND_END; |
| 599 | uint8_t attributeData = 44; |
| 600 | std::array<uint8_t, |
| 601 | hdrSize + |
| 602 | sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)> |
| 603 | responseMsg{}; |
| 604 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 605 | |
| 606 | auto rc = encode_get_bios_current_value_by_handle_resp( |
| 607 | instanceId, completionCode, nextTransferHandle, transferFlag, |
| 608 | &attributeData, sizeof(attributeData), response); |
| 609 | |
| 610 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 611 | |
| 612 | struct pldm_get_bios_attribute_current_value_by_handle_resp* resp = |
| 613 | reinterpret_cast< |
| 614 | struct pldm_get_bios_attribute_current_value_by_handle_resp*>( |
| 615 | response->payload); |
| 616 | |
| 617 | EXPECT_EQ(completionCode, resp->completion_code); |
| 618 | EXPECT_EQ(nextTransferHandle, le32toh(resp->next_transfer_handle)); |
| 619 | EXPECT_EQ(transferFlag, resp->transfer_flag); |
| 620 | EXPECT_EQ( |
| 621 | 0, memcmp(&attributeData, resp->attribute_data, sizeof(attributeData))); |
| 622 | } |
| 623 | |
| 624 | TEST(GetBIOSAttributeCurrentValueByHandle, testBadEncodeResponse) |
| 625 | { |
| 626 | uint32_t nextTransferHandle = 32; |
| 627 | uint8_t transferFlag = PLDM_START_AND_END; |
| 628 | uint8_t attributeData = 44; |
| 629 | |
| 630 | auto rc = encode_get_bios_current_value_by_handle_resp( |
| 631 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, &attributeData, |
| 632 | sizeof(attributeData), nullptr); |
| 633 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 634 | |
| 635 | std::array<uint8_t, |
| 636 | hdrSize + |
| 637 | sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)> |
| 638 | responseMsg{}; |
| 639 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 640 | rc = encode_get_bios_current_value_by_handle_resp( |
| 641 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, nullptr, |
| 642 | sizeof(attributeData), response); |
| 643 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 644 | } |
| 645 | |
| 646 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeRequest) |
| 647 | { |
| 648 | uint8_t instanceId = 10; |
| 649 | uint32_t transferHandle = 32; |
| 650 | uint8_t transferFlag = PLDM_START_AND_END; |
| 651 | uint32_t attributeData = 44; |
| 652 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + |
| 653 | sizeof(attributeData)> |
| 654 | requestMsg{}; |
| 655 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 656 | auto rc = encode_set_bios_attribute_current_value_req( |
| 657 | instanceId, transferHandle, transferFlag, |
| 658 | reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData), |
| 659 | request, requestMsg.size() - hdrSize); |
| 660 | |
| 661 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 662 | |
| 663 | struct pldm_set_bios_attribute_current_value_req* req = |
| 664 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>( |
| 665 | request->payload); |
| 666 | EXPECT_EQ(htole32(transferHandle), req->transfer_handle); |
| 667 | EXPECT_EQ(transferFlag, req->transfer_flag); |
| 668 | EXPECT_EQ( |
| 669 | 0, memcmp(&attributeData, req->attribute_data, sizeof(attributeData))); |
| 670 | } |
| 671 | |
| 672 | TEST(SetBiosAttributeCurrentValue, testBadEncodeRequest) |
| 673 | { |
| 674 | uint8_t instanceId = 10; |
| 675 | uint32_t transferHandle = 32; |
| 676 | uint8_t transferFlag = PLDM_START_AND_END; |
| 677 | uint32_t attributeData = 44; |
| 678 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES> |
| 679 | requestMsg{}; |
| 680 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 681 | |
| 682 | auto rc = encode_set_bios_attribute_current_value_req( |
| 683 | instanceId, transferHandle, transferFlag, nullptr, 0, nullptr, 0); |
| 684 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 685 | rc = encode_set_bios_attribute_current_value_req( |
| 686 | instanceId, transferHandle, transferFlag, |
| 687 | reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData), |
| 688 | request, requestMsg.size() - hdrSize); |
| 689 | |
| 690 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 691 | } |
| 692 | |
| 693 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeRequest) |
| 694 | { |
| 695 | uint32_t transferHandle = 32; |
| 696 | uint8_t transferFlag = PLDM_START_AND_END; |
| 697 | uint32_t attributeData = 44; |
| 698 | |
| 699 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + |
| 700 | sizeof(attributeData)> |
| 701 | requestMsg{}; |
| 702 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 703 | struct pldm_set_bios_attribute_current_value_req* req = |
| 704 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>( |
| 705 | request->payload); |
| 706 | req->transfer_handle = htole32(transferHandle); |
| 707 | req->transfer_flag = transferFlag; |
| 708 | memcpy(req->attribute_data, &attributeData, sizeof(attributeData)); |
| 709 | |
| 710 | uint32_t retTransferHandle; |
| 711 | uint8_t retTransferFlag; |
| 712 | struct variable_field attribute; |
| 713 | auto rc = decode_set_bios_attribute_current_value_req( |
| 714 | request, requestMsg.size() - hdrSize, &retTransferHandle, |
| 715 | &retTransferFlag, &attribute); |
| 716 | |
| 717 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 718 | EXPECT_EQ(retTransferHandle, transferHandle); |
| 719 | EXPECT_EQ(retTransferFlag, transferFlag); |
| 720 | EXPECT_EQ(attribute.length, sizeof(attributeData)); |
| 721 | EXPECT_EQ(0, memcmp(attribute.ptr, &attributeData, sizeof(attributeData))); |
| 722 | } |
| 723 | |
| 724 | TEST(SetBiosAttributeCurrentValue, testBadDecodeRequest) |
| 725 | { |
| 726 | uint32_t transferHandle = 32; |
| 727 | uint8_t transferFlag = PLDM_START_AND_END; |
| 728 | struct variable_field attribute; |
| 729 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES - 1> |
| 730 | requestMsg{}; |
| 731 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 732 | |
| 733 | auto rc = decode_set_bios_attribute_current_value_req( |
| 734 | nullptr, 0, &transferHandle, &transferFlag, &attribute); |
| 735 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 736 | rc = decode_set_bios_attribute_current_value_req( |
| 737 | request, requestMsg.size() - hdrSize, &transferHandle, &transferFlag, |
| 738 | &attribute); |
| 739 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 740 | } |
| 741 | |
| 742 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeResponse) |
| 743 | { |
| 744 | uint8_t instanceId = 10; |
| 745 | uint32_t nextTransferHandle = 32; |
| 746 | uint8_t completionCode = PLDM_SUCCESS; |
| 747 | |
| 748 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 749 | responseMsg{}; |
| 750 | struct pldm_msg* response = |
| 751 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 752 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 753 | instanceId, completionCode, nextTransferHandle, response); |
| 754 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 755 | |
| 756 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 757 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 758 | response->payload); |
| 759 | EXPECT_EQ(completionCode, resp->completion_code); |
| 760 | EXPECT_EQ(htole32(nextTransferHandle), resp->next_transfer_handle); |
| 761 | } |
| 762 | |
| 763 | TEST(SetBiosAttributeCurrentValue, testBadEncodeResponse) |
| 764 | { |
| 765 | uint8_t instanceId = 10; |
| 766 | uint32_t nextTransferHandle = 32; |
| 767 | uint8_t completionCode = PLDM_SUCCESS; |
| 768 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 769 | instanceId, completionCode, nextTransferHandle, nullptr); |
| 770 | |
| 771 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 772 | } |
| 773 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeResponse) |
| 774 | { |
| 775 | uint32_t nextTransferHandle = 32; |
| 776 | uint8_t completionCode = PLDM_SUCCESS; |
| 777 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 778 | responseMsg{}; |
| 779 | struct pldm_msg* response = |
| 780 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 781 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 782 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 783 | response->payload); |
| 784 | |
| 785 | resp->completion_code = completionCode; |
| 786 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 787 | |
| 788 | uint8_t retCompletionCode; |
| 789 | uint32_t retNextTransferHandle; |
| 790 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 791 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 792 | &retNextTransferHandle); |
| 793 | |
| 794 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 795 | EXPECT_EQ(completionCode, retCompletionCode); |
| 796 | EXPECT_EQ(nextTransferHandle, retNextTransferHandle); |
| 797 | } |
| 798 | |
| 799 | TEST(SetBiosAttributeCurrentValue, testBadDecodeResponse) |
| 800 | { |
| 801 | uint32_t nextTransferHandle = 32; |
| 802 | uint8_t completionCode = PLDM_SUCCESS; |
| 803 | |
| 804 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 805 | responseMsg{}; |
| 806 | struct pldm_msg* response = |
| 807 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 808 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 809 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 810 | response->payload); |
| 811 | |
| 812 | resp->completion_code = completionCode; |
| 813 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 814 | |
| 815 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 816 | nullptr, 0, &completionCode, &nextTransferHandle); |
| 817 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 818 | |
| 819 | rc = decode_set_bios_attribute_current_value_resp( |
| 820 | response, responseMsg.size() - hdrSize - 1, &completionCode, |
| 821 | &nextTransferHandle); |
| 822 | |
| 823 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 824 | } |
| 825 | |
| 826 | TEST(GetBIOSTable, testDecodeResponse) |
| 827 | { |
| 828 | uint32_t nextTransferHandle = 32; |
| 829 | uint8_t completionCode = PLDM_SUCCESS; |
| 830 | uint8_t transfer_flag = PLDM_START_AND_END; |
| 831 | |
| 832 | std::array<uint8_t, hdrSize + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES> |
| 833 | responseMsg{}; |
| 834 | struct pldm_msg* response = |
| 835 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 836 | |
| 837 | struct pldm_get_bios_table_resp* resp = |
| 838 | reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload); |
| 839 | |
| 840 | resp->completion_code = completionCode; |
| 841 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 842 | resp->transfer_flag = transfer_flag; |
| 843 | size_t biosTableOffset = sizeof(completionCode) + |
| 844 | sizeof(nextTransferHandle) + sizeof(transfer_flag); |
| 845 | |
| 846 | uint8_t retCompletionCode; |
| 847 | uint32_t retNextTransferHandle; |
| 848 | uint8_t retransfer_flag; |
| 849 | size_t rebiosTableOffset = 0; |
| 850 | auto rc = decode_get_bios_table_resp( |
| 851 | response, responseMsg.size(), &retCompletionCode, |
| 852 | &retNextTransferHandle, &retransfer_flag, &rebiosTableOffset); |
| 853 | |
| 854 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 855 | ASSERT_EQ(completionCode, retCompletionCode); |
| 856 | ASSERT_EQ(nextTransferHandle, retNextTransferHandle); |
| 857 | ASSERT_EQ(transfer_flag, retransfer_flag); |
| 858 | ASSERT_EQ(biosTableOffset, rebiosTableOffset); |
| 859 | } |
| 860 | |
| 861 | TEST(GetBIOSAttributeCurrentValueByHandle, testDecodeResponse) |
| 862 | { |
| 863 | uint32_t nextTransferHandle = 32; |
| 864 | uint8_t completionCode = PLDM_SUCCESS; |
| 865 | uint8_t transfer_flag = PLDM_START_AND_END; |
| 866 | uint32_t attributeData = 44; |
| 867 | |
| 868 | std::array<uint8_t, |
| 869 | hdrSize + PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES + |
| 870 | sizeof(attributeData)> |
| 871 | responseMsg{}; |
| 872 | struct pldm_msg* response = |
| 873 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 874 | |
| 875 | struct pldm_get_bios_attribute_current_value_by_handle_resp* resp = |
| 876 | reinterpret_cast< |
| 877 | struct pldm_get_bios_attribute_current_value_by_handle_resp*>( |
| 878 | response->payload); |
| 879 | |
| 880 | resp->completion_code = completionCode; |
| 881 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 882 | resp->transfer_flag = transfer_flag; |
| 883 | memcpy(resp->attribute_data, &attributeData, sizeof(attributeData)); |
| 884 | |
| 885 | uint8_t retCompletionCode; |
| 886 | uint32_t retNextTransferHandle; |
| 887 | uint8_t retransfer_flag; |
| 888 | struct variable_field retAttributeData; |
| 889 | auto rc = decode_get_bios_attribute_current_value_by_handle_resp( |
| 890 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 891 | &retNextTransferHandle, &retransfer_flag, &retAttributeData); |
| 892 | |
| 893 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 894 | EXPECT_EQ(completionCode, retCompletionCode); |
| 895 | EXPECT_EQ(nextTransferHandle, retNextTransferHandle); |
| 896 | EXPECT_EQ(transfer_flag, retransfer_flag); |
| 897 | EXPECT_EQ(sizeof(attributeData), retAttributeData.length); |
| 898 | EXPECT_EQ( |
| 899 | 0, memcmp(retAttributeData.ptr, &attributeData, sizeof(attributeData))); |
| 900 | } |
| 901 | |
| 902 | TEST(SetBIOSTable, testGoodEncodeRequest) |
| 903 | { |
| 904 | uint8_t instanceId = 10; |
| 905 | uint32_t transferHandle = 32; |
| 906 | uint8_t transferFlag = PLDM_START_AND_END; |
| 907 | uint8_t tableType = PLDM_BIOS_STRING_TABLE; |
| 908 | uint32_t tableData = 44; |
| 909 | std::array<uint8_t, |
| 910 | hdrSize + PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + sizeof(tableData)> |
| 911 | requestMsg{}; |
| 912 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 913 | auto rc = encode_set_bios_table_req( |
| 914 | instanceId, transferHandle, transferFlag, tableType, |
| 915 | reinterpret_cast<uint8_t*>(&tableData), sizeof(tableData), request, |
| 916 | requestMsg.size() - hdrSize); |
| 917 | |
| 918 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 919 | |
| 920 | struct pldm_set_bios_table_req* req = |
| 921 | reinterpret_cast<struct pldm_set_bios_table_req*>(request->payload); |
| 922 | |
| 923 | EXPECT_EQ(htole32(transferHandle), req->transfer_handle); |
| 924 | EXPECT_EQ(transferFlag, req->transfer_flag); |
| 925 | EXPECT_EQ(tableType, req->table_type); |
| 926 | EXPECT_EQ(0, memcmp(&tableData, req->table_data, sizeof(tableData))); |
| 927 | } |
| 928 | |
| 929 | TEST(SetBIOSTable, testBadEncodeRequest) |
| 930 | { |
| 931 | uint8_t instanceId = 10; |
| 932 | uint32_t transferHandle = 32; |
| 933 | uint8_t transferFlag = PLDM_START_AND_END; |
| 934 | uint8_t tableType = PLDM_BIOS_STRING_TABLE; |
| 935 | uint32_t tableData = 44; |
| 936 | std::array<uint8_t, |
| 937 | hdrSize + PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + sizeof(tableData)> |
| 938 | requestMsg{}; |
| 939 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 940 | |
| 941 | auto rc = encode_set_bios_table_req( |
| 942 | instanceId, transferHandle, transferFlag, tableType, NULL, |
| 943 | sizeof(tableData), request, requestMsg.size() - hdrSize); |
| 944 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 945 | |
| 946 | rc = encode_set_bios_table_req( |
| 947 | instanceId, transferHandle, transferFlag, tableType, |
| 948 | reinterpret_cast<uint8_t*>(&tableData), sizeof(tableData), request, |
| 949 | requestMsg.size() - hdrSize + 1); |
| 950 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 951 | } |
| 952 | |
| 953 | TEST(SetBIOSTable, testGoodDecodeResponse) |
| 954 | { |
| 955 | uint32_t nextTransferHandle = 32; |
| 956 | uint8_t completionCode = PLDM_SUCCESS; |
| 957 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_TABLE_RESP_BYTES> responseMsg{}; |
| 958 | struct pldm_msg* response = |
| 959 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 960 | struct pldm_set_bios_table_resp* resp = |
| 961 | reinterpret_cast<struct pldm_set_bios_table_resp*>(response->payload); |
| 962 | |
| 963 | resp->completion_code = completionCode; |
| 964 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 965 | |
| 966 | uint8_t retCompletionCode; |
| 967 | uint32_t retNextTransferHandle; |
| 968 | auto rc = |
| 969 | decode_set_bios_table_resp(response, responseMsg.size() - hdrSize, |
| 970 | &retCompletionCode, &retNextTransferHandle); |
| 971 | |
| 972 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 973 | EXPECT_EQ(completionCode, retCompletionCode); |
| 974 | EXPECT_EQ(nextTransferHandle, retNextTransferHandle); |
| 975 | } |
| 976 | |
| 977 | TEST(SetBIOSTable, testBadDecodeResponse) |
| 978 | { |
| 979 | uint32_t nextTransferHandle = 32; |
| 980 | uint8_t completionCode = PLDM_SUCCESS; |
| 981 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_TABLE_RESP_BYTES> responseMsg{}; |
| 982 | struct pldm_msg* response = |
| 983 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 984 | struct pldm_set_bios_table_resp* resp = |
| 985 | reinterpret_cast<struct pldm_set_bios_table_resp*>(response->payload); |
| 986 | |
| 987 | resp->completion_code = completionCode; |
| 988 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 989 | |
| 990 | uint8_t retCompletionCode; |
| 991 | uint32_t retNextTransferHandle; |
| 992 | |
| 993 | auto rc = decode_set_bios_table_resp(NULL, responseMsg.size() - hdrSize, |
| 994 | NULL, NULL); |
| 995 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 996 | |
| 997 | rc = decode_set_bios_table_resp(response, responseMsg.size() - hdrSize + 1, |
| 998 | &retCompletionCode, &retNextTransferHandle); |
| 999 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1000 | } |
| 1001 | |
| 1002 | TEST(SetBIOSTable, testGoodEncodeResponse) |
| 1003 | { |
| 1004 | uint8_t instanceId = 10; |
| 1005 | uint32_t nextTransferHandle = 32; |
| 1006 | uint8_t completionCode = PLDM_SUCCESS; |
| 1007 | |
| 1008 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_TABLE_RESP_BYTES> responseMsg{}; |
| 1009 | struct pldm_msg* response = |
| 1010 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 1011 | auto rc = encode_set_bios_table_resp(instanceId, completionCode, |
| 1012 | nextTransferHandle, response); |
| 1013 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1014 | |
| 1015 | struct pldm_set_bios_table_resp* resp = |
| 1016 | reinterpret_cast<struct pldm_set_bios_table_resp*>(response->payload); |
| 1017 | EXPECT_EQ(completionCode, resp->completion_code); |
| 1018 | EXPECT_EQ(htole32(nextTransferHandle), resp->next_transfer_handle); |
| 1019 | } |
| 1020 | |
| 1021 | TEST(SetBIOSTable, testBadEncodeResponse) |
| 1022 | { |
| 1023 | auto rc = encode_set_bios_table_resp(0, PLDM_SUCCESS, 1, NULL); |
| 1024 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1025 | } |
| 1026 | |
| 1027 | TEST(SetBIOSTable, testGoodDecodeRequest) |
| 1028 | { |
| 1029 | uint32_t transferHandle = 32; |
| 1030 | uint8_t transferFlag = PLDM_START_AND_END; |
| 1031 | uint8_t tableType = PLDM_BIOS_STRING_TABLE; |
| 1032 | uint32_t tableData = 44; |
| 1033 | |
| 1034 | std::array<uint8_t, |
| 1035 | hdrSize + PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + sizeof(tableData)> |
| 1036 | requestMsg{}; |
| 1037 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 1038 | struct pldm_set_bios_table_req* req = |
| 1039 | reinterpret_cast<struct pldm_set_bios_table_req*>(request->payload); |
| 1040 | req->transfer_handle = htole32(transferHandle); |
| 1041 | req->transfer_flag = transferFlag; |
| 1042 | req->table_type = tableType; |
| 1043 | memcpy(req->table_data, &tableData, sizeof(tableData)); |
| 1044 | |
| 1045 | uint32_t retTransferHandle; |
| 1046 | uint8_t retTransferFlag; |
| 1047 | uint8_t retTableType; |
| 1048 | struct variable_field table; |
| 1049 | auto rc = decode_set_bios_table_req(request, requestMsg.size() - hdrSize, |
| 1050 | &retTransferHandle, &retTransferFlag, |
| 1051 | &retTableType, &table); |
| 1052 | |
| 1053 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1054 | EXPECT_EQ(retTransferHandle, transferHandle); |
| 1055 | EXPECT_EQ(retTransferFlag, transferFlag); |
| 1056 | EXPECT_EQ(retTableType, tableType); |
| 1057 | EXPECT_EQ(table.length, sizeof(tableData)); |
| 1058 | EXPECT_EQ(0, memcmp(table.ptr, &tableData, sizeof(tableData))); |
| 1059 | } |
| 1060 | |
| 1061 | TEST(SetBIOSTable, testBadDecodeRequest) |
| 1062 | { |
| 1063 | uint32_t transferHandle = 32; |
| 1064 | uint8_t transferFlag = PLDM_START_AND_END; |
| 1065 | uint8_t tableType = PLDM_BIOS_STRING_TABLE; |
| 1066 | uint32_t tableData = 44; |
| 1067 | |
| 1068 | std::array<uint8_t, |
| 1069 | hdrSize + PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + sizeof(tableData)> |
| 1070 | requestMsg{}; |
| 1071 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 1072 | struct pldm_set_bios_table_req* req = |
| 1073 | reinterpret_cast<struct pldm_set_bios_table_req*>(request->payload); |
| 1074 | req->transfer_handle = htole32(transferHandle); |
| 1075 | req->transfer_flag = transferFlag; |
| 1076 | req->table_type = tableType; |
| 1077 | memcpy(req->table_data, &tableData, sizeof(tableData)); |
| 1078 | |
| 1079 | uint32_t retTransferHandle; |
| 1080 | uint8_t retTransferFlag; |
| 1081 | uint8_t retTableType; |
| 1082 | |
| 1083 | auto rc = decode_set_bios_table_req(request, requestMsg.size() - hdrSize, |
| 1084 | &retTransferHandle, &retTransferFlag, |
| 1085 | &retTableType, NULL); |
| 1086 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1087 | |
| 1088 | struct variable_field table; |
| 1089 | rc = decode_set_bios_table_req( |
| 1090 | request, requestMsg.size() - hdrSize - sizeof(tableData) - 1, |
| 1091 | &retTransferHandle, &retTransferFlag, &retTableType, &table); |
| 1092 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1093 | } |