Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 1 | #include <string.h> |
| 2 | |
| 3 | #include <array> |
| 4 | |
| 5 | #include "libpldm/base.h" |
| 6 | #include "libpldm/bios.h" |
Xiaochao Ma | 39ae2a9 | 2019-11-12 20:30:34 +0800 | [diff] [blame] | 7 | #include "libpldm/utils.h" |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 8 | |
| 9 | #include <gtest/gtest.h> |
| 10 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 11 | constexpr auto hdrSize = sizeof(pldm_msg_hdr); |
| 12 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 13 | TEST(GetDateTime, testEncodeRequest) |
| 14 | { |
| 15 | pldm_msg request{}; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 16 | |
| 17 | auto rc = encode_get_date_time_req(0, &request); |
| 18 | ASSERT_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 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 31 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_DATE_TIME_RESP_BYTES> |
| 32 | responseMsg{}; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 33 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 34 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 35 | |
| 36 | auto rc = encode_get_date_time_resp(0, PLDM_SUCCESS, seconds, minutes, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 37 | hours, day, month, year, response); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 38 | |
| 39 | ASSERT_EQ(rc, PLDM_SUCCESS); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 40 | ASSERT_EQ(completionCode, response->payload[0]); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 41 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 42 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
| 43 | &seconds, sizeof(seconds))); |
| 44 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 45 | sizeof(seconds), |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 46 | &minutes, sizeof(minutes))); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 47 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 48 | sizeof(seconds) + sizeof(minutes), |
| 49 | &hours, sizeof(hours))); |
| 50 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 51 | sizeof(seconds) + sizeof(minutes) + sizeof(hours), |
| 52 | &day, sizeof(day))); |
| 53 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 54 | sizeof(seconds) + sizeof(minutes) + sizeof(hours) + |
| 55 | sizeof(day), |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 56 | &month, sizeof(month))); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 57 | ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
| 58 | sizeof(seconds) + sizeof(minutes) + sizeof(hours) + |
| 59 | sizeof(day) + sizeof(month), |
| 60 | &year, sizeof(year))); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | TEST(GetDateTime, testDecodeResponse) |
| 64 | { |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 65 | std::array<uint8_t, hdrSize + PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{}; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 66 | |
| 67 | uint8_t completionCode = 0; |
| 68 | |
| 69 | uint8_t seconds = 55; |
| 70 | uint8_t minutes = 2; |
| 71 | uint8_t hours = 8; |
| 72 | uint8_t day = 9; |
| 73 | uint8_t month = 7; |
| 74 | uint16_t year = 2020; |
| 75 | |
| 76 | uint8_t retSeconds = 0; |
| 77 | uint8_t retMinutes = 0; |
| 78 | uint8_t retHours = 0; |
| 79 | uint8_t retDay = 0; |
| 80 | uint8_t retMonth = 0; |
| 81 | uint16_t retYear = 0; |
| 82 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 83 | memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &seconds, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 84 | sizeof(seconds)); |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 85 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
| 86 | hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 87 | &minutes, sizeof(minutes)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 88 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 89 | sizeof(minutes) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 90 | &hours, sizeof(hours)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 91 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 92 | sizeof(minutes) + sizeof(hours) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 93 | &day, sizeof(day)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 94 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 95 | sizeof(minutes) + sizeof(hours) + sizeof(day) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 96 | &month, sizeof(month)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 97 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 98 | sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month) + |
| 99 | hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 100 | &year, sizeof(year)); |
| 101 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 102 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 103 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 104 | auto rc = decode_get_date_time_resp( |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 105 | response, responseMsg.size() - hdrSize, &completionCode, &retSeconds, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 106 | &retMinutes, &retHours, &retDay, &retMonth, &retYear); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 107 | |
| 108 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 109 | ASSERT_EQ(seconds, retSeconds); |
| 110 | ASSERT_EQ(minutes, retMinutes); |
| 111 | ASSERT_EQ(hours, retHours); |
| 112 | ASSERT_EQ(day, retDay); |
| 113 | ASSERT_EQ(month, retMonth); |
| 114 | ASSERT_EQ(year, retYear); |
| 115 | } |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 116 | |
Xiaochao Ma | 39ae2a9 | 2019-11-12 20:30:34 +0800 | [diff] [blame] | 117 | TEST(SetDateTime, testGoodEncodeResponse) |
| 118 | { |
| 119 | uint8_t instanceId = 0; |
| 120 | uint8_t completionCode = PLDM_SUCCESS; |
| 121 | |
| 122 | std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)> |
| 123 | responseMsg{}; |
| 124 | struct pldm_msg* response = |
| 125 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 126 | |
| 127 | auto rc = encode_set_date_time_resp(instanceId, completionCode, response, |
| 128 | responseMsg.size() - hdrSize); |
| 129 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 130 | |
| 131 | struct pldm_only_cc_resp* resp = |
| 132 | reinterpret_cast<struct pldm_only_cc_resp*>(response->payload); |
| 133 | EXPECT_EQ(completionCode, resp->completion_code); |
| 134 | } |
| 135 | |
| 136 | TEST(SetDateTime, testBadEncodeResponse) |
| 137 | { |
| 138 | |
| 139 | uint8_t instanceId = 10; |
| 140 | uint8_t completionCode = PLDM_SUCCESS; |
| 141 | std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)> |
| 142 | responseMsg{}; |
| 143 | struct pldm_msg* response = |
| 144 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 145 | auto rc = encode_set_date_time_resp(instanceId, completionCode, nullptr, |
| 146 | responseMsg.size() - hdrSize); |
| 147 | |
| 148 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 149 | rc = encode_set_date_time_resp(instanceId, completionCode, response, |
| 150 | responseMsg.size() - hdrSize - 1); |
| 151 | |
| 152 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 153 | } |
| 154 | |
| 155 | TEST(SetDateTime, testGoodDecodeResponse) |
| 156 | { |
| 157 | uint8_t completionCode = PLDM_SUCCESS; |
| 158 | std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)> |
| 159 | responseMsg{}; |
| 160 | struct pldm_msg* response = |
| 161 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 162 | struct pldm_only_cc_resp* resp = |
| 163 | reinterpret_cast<struct pldm_only_cc_resp*>(response->payload); |
| 164 | |
| 165 | resp->completion_code = completionCode; |
| 166 | |
| 167 | uint8_t retCompletionCode; |
| 168 | auto rc = decode_set_date_time_resp(response, responseMsg.size() - hdrSize, |
| 169 | &retCompletionCode); |
| 170 | |
| 171 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 172 | EXPECT_EQ(completionCode, retCompletionCode); |
| 173 | } |
| 174 | |
| 175 | TEST(SetDateTime, testBadDecodeResponse) |
| 176 | { |
| 177 | uint8_t completionCode = PLDM_SUCCESS; |
| 178 | |
| 179 | std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)> |
| 180 | responseMsg{}; |
| 181 | struct pldm_msg* response = |
| 182 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 183 | auto rc = decode_set_date_time_resp(nullptr, responseMsg.size() - hdrSize, |
| 184 | &completionCode); |
| 185 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 186 | |
| 187 | rc = decode_set_date_time_resp(response, responseMsg.size() - hdrSize - 1, |
| 188 | &completionCode); |
| 189 | |
| 190 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 191 | } |
| 192 | |
| 193 | TEST(SetDateTime, testGoodEncodeRequset) |
| 194 | { |
| 195 | uint8_t instanceId = 0; |
| 196 | uint8_t seconds = 50; |
| 197 | uint8_t minutes = 20; |
| 198 | uint8_t hours = 10; |
| 199 | uint8_t day = 11; |
| 200 | uint8_t month = 11; |
| 201 | uint16_t year = 2019; |
| 202 | |
| 203 | std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)> |
| 204 | requestMsg{}; |
| 205 | |
| 206 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 207 | auto rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, day, |
| 208 | month, year, request, |
| 209 | requestMsg.size() - hdrSize); |
| 210 | |
| 211 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 212 | |
| 213 | struct pldm_set_date_time_req* req = |
| 214 | reinterpret_cast<struct pldm_set_date_time_req*>(request->payload); |
| 215 | EXPECT_EQ(seconds, bcd2dec8(req->seconds)); |
| 216 | EXPECT_EQ(minutes, bcd2dec8(req->minutes)); |
| 217 | EXPECT_EQ(hours, bcd2dec8(req->hours)); |
| 218 | EXPECT_EQ(day, bcd2dec8(req->day)); |
| 219 | EXPECT_EQ(month, bcd2dec8(req->month)); |
| 220 | EXPECT_EQ(year, le16toh(bcd2dec16(req->year))); |
| 221 | } |
| 222 | |
| 223 | TEST(SetDateTime, testBadEncodeRequset) |
| 224 | { |
| 225 | uint8_t instanceId = 0; |
| 226 | |
| 227 | uint8_t seconds = 50; |
| 228 | uint8_t minutes = 20; |
| 229 | uint8_t hours = 10; |
| 230 | uint8_t day = 13; |
| 231 | uint8_t month = 11; |
| 232 | uint16_t year = 2019; |
| 233 | |
| 234 | uint8_t erday = 43; |
| 235 | |
| 236 | std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)> |
| 237 | requestMsg{}; |
| 238 | |
| 239 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 240 | |
| 241 | auto rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, day, |
| 242 | month, year, nullptr, |
| 243 | requestMsg.size() - hdrSize); |
| 244 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 245 | |
| 246 | rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, erday, |
| 247 | month, year, request, |
| 248 | requestMsg.size() - hdrSize); |
| 249 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 250 | |
| 251 | rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, day, |
| 252 | month, year, request, |
| 253 | requestMsg.size() - hdrSize - 4); |
| 254 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 255 | } |
| 256 | |
| 257 | TEST(SetDateTime, testGoodDecodeRequest) |
| 258 | { |
| 259 | std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)> |
| 260 | requestMsg{}; |
| 261 | uint8_t seconds = 0x50; |
| 262 | uint8_t minutes = 0x20; |
| 263 | uint8_t hours = 0x10; |
| 264 | uint8_t day = 0x11; |
| 265 | uint8_t month = 0x11; |
| 266 | uint16_t year = 0x2019; |
| 267 | |
| 268 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 269 | struct pldm_set_date_time_req* req = |
| 270 | reinterpret_cast<struct pldm_set_date_time_req*>(request->payload); |
| 271 | req->seconds = seconds; |
| 272 | req->minutes = minutes; |
| 273 | req->hours = hours; |
| 274 | req->day = day; |
| 275 | req->month = month; |
| 276 | req->year = htole16(year); |
| 277 | |
| 278 | uint8_t retseconds; |
| 279 | uint8_t retminutes; |
| 280 | uint8_t rethours; |
| 281 | uint8_t retday; |
| 282 | uint8_t retmonth; |
| 283 | uint16_t retyear; |
| 284 | |
| 285 | auto rc = decode_set_date_time_req(request, requestMsg.size() - hdrSize, |
| 286 | &retseconds, &retminutes, &rethours, |
| 287 | &retday, &retmonth, &retyear); |
| 288 | |
| 289 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 290 | EXPECT_EQ(retseconds, 50); |
| 291 | EXPECT_EQ(retminutes, 20); |
| 292 | EXPECT_EQ(rethours, 10); |
| 293 | EXPECT_EQ(retday, 11); |
| 294 | EXPECT_EQ(retmonth, 11); |
| 295 | EXPECT_EQ(retyear, 2019); |
| 296 | } |
| 297 | |
| 298 | TEST(SetDateTime, testBadDecodeRequest) |
| 299 | { |
| 300 | uint8_t seconds = 0x50; |
| 301 | uint8_t minutes = 0x20; |
| 302 | uint8_t hours = 0x10; |
| 303 | uint8_t day = 0x11; |
| 304 | uint8_t month = 0x11; |
| 305 | uint16_t year = 0x2019; |
| 306 | |
| 307 | std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)> |
| 308 | requestMsg{}; |
| 309 | |
| 310 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 311 | |
| 312 | decode_set_date_time_req(request, requestMsg.size() - hdrSize, &seconds, |
| 313 | &minutes, &hours, &day, &month, &year); |
| 314 | |
| 315 | auto rc = |
| 316 | decode_set_date_time_req(nullptr, requestMsg.size() - hdrSize, &seconds, |
| 317 | &minutes, &hours, &day, &month, &year); |
| 318 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 319 | |
| 320 | rc = decode_set_date_time_req(request, requestMsg.size() - hdrSize, nullptr, |
| 321 | nullptr, nullptr, nullptr, nullptr, nullptr); |
| 322 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 323 | |
| 324 | rc = decode_set_date_time_req(request, requestMsg.size() - hdrSize - 4, |
| 325 | &seconds, &minutes, &hours, &day, &month, |
| 326 | &year); |
| 327 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 328 | } |
| 329 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 330 | TEST(GetBIOSTable, testGoodEncodeResponse) |
| 331 | { |
| 332 | std::array<uint8_t, |
| 333 | sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4> |
| 334 | responseMsg{}; |
| 335 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 336 | |
| 337 | uint8_t completionCode = PLDM_SUCCESS; |
| 338 | uint32_t nextTransferHandle = 32; |
| 339 | uint8_t transferFlag = PLDM_START_AND_END; |
| 340 | std::array<uint8_t, 4> tableData{1, 2, 3, 4}; |
| 341 | |
| 342 | auto rc = encode_get_bios_table_resp( |
| 343 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, tableData.data(), |
| 344 | sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4, |
| 345 | response); |
| 346 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 347 | |
| 348 | struct pldm_get_bios_table_resp* resp = |
| 349 | reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload); |
| 350 | |
| 351 | ASSERT_EQ(completionCode, resp->completion_code); |
| 352 | ASSERT_EQ(nextTransferHandle, resp->next_transfer_handle); |
| 353 | ASSERT_EQ(transferFlag, resp->transfer_flag); |
| 354 | ASSERT_EQ(0, memcmp(tableData.data(), resp->table_data, tableData.size())); |
| 355 | } |
| 356 | |
| 357 | TEST(GetBIOSTable, testBadEncodeResponse) |
| 358 | { |
| 359 | uint32_t nextTransferHandle = 32; |
| 360 | uint8_t transferFlag = PLDM_START_AND_END; |
| 361 | std::array<uint8_t, 4> tableData{1, 2, 3, 4}; |
| 362 | |
| 363 | auto rc = encode_get_bios_table_resp( |
| 364 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, tableData.data(), |
| 365 | sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4, nullptr); |
| 366 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 367 | } |
| 368 | |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 369 | TEST(GetBIOSTable, testGoodEncodeRequest) |
| 370 | { |
| 371 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_REQ_BYTES> |
| 372 | requestMsg{}; |
| 373 | uint32_t transferHandle = 0x0; |
| 374 | uint8_t transferOpFlag = 0x01; |
| 375 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 376 | |
| 377 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 378 | auto rc = encode_get_bios_table_req(0, transferHandle, transferOpFlag, |
| 379 | tableType, request); |
| 380 | |
| 381 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 382 | |
| 383 | struct pldm_get_bios_table_req* req = |
| 384 | reinterpret_cast<struct pldm_get_bios_table_req*>(request->payload); |
| 385 | ASSERT_EQ(transferHandle, le32toh(req->transfer_handle)); |
| 386 | ASSERT_EQ(transferOpFlag, req->transfer_op_flag); |
| 387 | ASSERT_EQ(tableType, req->table_type); |
| 388 | } |
| 389 | |
| 390 | TEST(GetBIOSTable, testBadEncodeRequest) |
| 391 | { |
| 392 | uint32_t transferHandle = 0x0; |
| 393 | uint8_t transferOpFlag = 0x01; |
| 394 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 395 | |
| 396 | auto rc = encode_get_bios_table_req(0, transferHandle, transferOpFlag, |
| 397 | tableType, nullptr); |
| 398 | |
| 399 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 400 | } |
| 401 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 402 | TEST(GetBIOSTable, testGoodDecodeRequest) |
| 403 | { |
| 404 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 405 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 406 | uint32_t transferHandle = 31; |
| 407 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 408 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 409 | uint32_t retTransferHandle = 0; |
| 410 | uint8_t retTransferOpFlag = 0; |
| 411 | uint8_t retTableType = 0; |
| 412 | |
| 413 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 414 | struct pldm_get_bios_table_req* request = |
| 415 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 416 | |
| 417 | request->transfer_handle = transferHandle; |
| 418 | request->transfer_op_flag = transferOpFlag; |
| 419 | request->table_type = tableType; |
| 420 | |
| 421 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size, |
| 422 | &retTransferHandle, &retTransferOpFlag, |
| 423 | &retTableType); |
| 424 | |
| 425 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 426 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 427 | ASSERT_EQ(transferOpFlag, retTransferOpFlag); |
| 428 | ASSERT_EQ(tableType, retTableType); |
| 429 | } |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 430 | TEST(GetBIOSTable, testBadDecodeRequest) |
| 431 | { |
| 432 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 433 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 434 | uint32_t transferHandle = 31; |
| 435 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 436 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 437 | uint32_t retTransferHandle = 0; |
| 438 | uint8_t retTransferOpFlag = 0; |
| 439 | uint8_t retTableType = 0; |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 440 | |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 441 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 442 | struct pldm_get_bios_table_req* request = |
| 443 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 444 | |
| 445 | request->transfer_handle = transferHandle; |
| 446 | request->transfer_op_flag = transferOpFlag; |
| 447 | request->table_type = tableType; |
| 448 | |
| 449 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size, |
| 450 | &retTransferHandle, &retTransferOpFlag, |
| 451 | &retTableType); |
| 452 | |
| 453 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 454 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 455 | ASSERT_EQ(transferOpFlag, retTransferOpFlag); |
| 456 | ASSERT_EQ(tableType, retTableType); |
| 457 | } |
| 458 | /* |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 459 | TEST(GetBIOSTable, testBadDecodeRequest) |
| 460 | { |
| 461 | const auto hdr_size = sizeof(pldm_msg_hdr); |
| 462 | std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{}; |
| 463 | uint32_t transferHandle = 31; |
| 464 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 465 | uint8_t tableType = PLDM_BIOS_ATTR_TABLE; |
| 466 | uint32_t retTransferHandle = 0; |
| 467 | uint8_t retTransferOpFlag = 0; |
| 468 | uint8_t retTableType = 0; |
| 469 | |
| 470 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 471 | struct pldm_get_bios_table_req* request = |
| 472 | reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload); |
| 473 | |
| 474 | request->transfer_handle = transferHandle; |
| 475 | request->transfer_op_flag = transferOpFlag; |
| 476 | request->table_type = tableType; |
| 477 | |
| 478 | auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size - 3, |
| 479 | &retTransferHandle, &retTransferOpFlag, |
| 480 | &retTableType); |
| 481 | |
| 482 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 483 | }*/ |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 484 | |
| 485 | TEST(GetBIOSAttributeCurrentValueByHandle, testGoodDecodeRequest) |
| 486 | { |
| 487 | uint32_t transferHandle = 45; |
| 488 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 489 | uint16_t attributehandle = 10; |
| 490 | uint32_t retTransferHandle = 0; |
| 491 | uint8_t retTransferOpFlag = 0; |
| 492 | uint16_t retattributehandle = 0; |
| 493 | std::array<uint8_t, hdrSize + sizeof(transferHandle) + |
| 494 | sizeof(transferOpFlag) + sizeof(attributehandle)> |
| 495 | requestMsg{}; |
| 496 | |
| 497 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 498 | struct pldm_get_bios_attribute_current_value_by_handle_req* request = |
| 499 | reinterpret_cast< |
| 500 | struct pldm_get_bios_attribute_current_value_by_handle_req*>( |
| 501 | req->payload); |
| 502 | |
| 503 | request->transfer_handle = transferHandle; |
| 504 | request->transfer_op_flag = transferOpFlag; |
| 505 | request->attribute_handle = attributehandle; |
| 506 | |
| 507 | auto rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 508 | req, requestMsg.size() - hdrSize, &retTransferHandle, |
| 509 | &retTransferOpFlag, &retattributehandle); |
| 510 | |
| 511 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 512 | ASSERT_EQ(transferHandle, retTransferHandle); |
| 513 | ASSERT_EQ(transferOpFlag, retTransferOpFlag); |
| 514 | ASSERT_EQ(attributehandle, retattributehandle); |
| 515 | } |
| 516 | |
| 517 | TEST(GetBIOSAttributeCurrentValueByHandle, testBadDecodeRequest) |
| 518 | { |
| 519 | |
| 520 | uint32_t transferHandle = 0; |
| 521 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 522 | uint16_t attribute_handle = 0; |
| 523 | uint32_t retTransferHandle = 0; |
| 524 | uint8_t retTransferOpFlag = 0; |
| 525 | uint16_t retattribute_handle = 0; |
| 526 | std::array<uint8_t, hdrSize + sizeof(transferHandle) + |
| 527 | sizeof(transferOpFlag) + sizeof(attribute_handle)> |
| 528 | requestMsg{}; |
| 529 | |
| 530 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 531 | struct pldm_get_bios_attribute_current_value_by_handle_req* request = |
| 532 | reinterpret_cast< |
| 533 | struct pldm_get_bios_attribute_current_value_by_handle_req*>( |
| 534 | req->payload); |
| 535 | |
| 536 | request->transfer_handle = transferHandle; |
| 537 | request->transfer_op_flag = transferOpFlag; |
| 538 | request->attribute_handle = attribute_handle; |
| 539 | |
| 540 | auto rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 541 | NULL, requestMsg.size() - hdrSize, &retTransferHandle, |
| 542 | &retTransferOpFlag, &retattribute_handle); |
| 543 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 544 | |
| 545 | transferHandle = 31; |
| 546 | request->transfer_handle = transferHandle; |
| 547 | |
| 548 | rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 549 | req, 0, &retTransferHandle, &retTransferOpFlag, &retattribute_handle); |
| 550 | |
| 551 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 552 | } |
| 553 | |
| 554 | TEST(GetBIOSAttributeCurrentValueByHandle, testGoodEncodeResponse) |
| 555 | { |
| 556 | |
| 557 | uint8_t instanceId = 10; |
| 558 | uint8_t completionCode = PLDM_SUCCESS; |
| 559 | uint32_t nextTransferHandle = 32; |
| 560 | uint8_t transferFlag = PLDM_START_AND_END; |
| 561 | uint8_t attributeData = 44; |
| 562 | std::array<uint8_t, |
| 563 | hdrSize + |
| 564 | sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)> |
| 565 | responseMsg{}; |
| 566 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 567 | |
| 568 | auto rc = encode_get_bios_current_value_by_handle_resp( |
| 569 | instanceId, completionCode, nextTransferHandle, transferFlag, |
| 570 | &attributeData, sizeof(attributeData), response); |
| 571 | |
| 572 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 573 | |
| 574 | struct pldm_get_bios_attribute_current_value_by_handle_resp* resp = |
| 575 | reinterpret_cast< |
| 576 | struct pldm_get_bios_attribute_current_value_by_handle_resp*>( |
| 577 | response->payload); |
| 578 | |
| 579 | ASSERT_EQ(completionCode, resp->completion_code); |
| 580 | ASSERT_EQ(nextTransferHandle, resp->next_transfer_handle); |
| 581 | ASSERT_EQ(transferFlag, resp->transfer_flag); |
| 582 | ASSERT_EQ( |
| 583 | 0, memcmp(&attributeData, resp->attribute_data, sizeof(attributeData))); |
| 584 | } |
| 585 | |
| 586 | TEST(GetBIOSAttributeCurrentValueByHandle, testBadEncodeResponse) |
| 587 | { |
| 588 | uint32_t nextTransferHandle = 32; |
| 589 | uint8_t transferFlag = PLDM_START_AND_END; |
| 590 | uint8_t attributeData = 44; |
| 591 | |
| 592 | auto rc = encode_get_bios_current_value_by_handle_resp( |
| 593 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, &attributeData, |
| 594 | sizeof(attributeData), nullptr); |
| 595 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 596 | |
| 597 | std::array<uint8_t, |
| 598 | hdrSize + |
| 599 | sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)> |
| 600 | responseMsg{}; |
| 601 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 602 | rc = encode_get_bios_current_value_by_handle_resp( |
| 603 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, nullptr, |
| 604 | sizeof(attributeData), response); |
| 605 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 606 | } |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 607 | |
| 608 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeRequest) |
| 609 | { |
| 610 | uint8_t instanceId = 10; |
| 611 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 612 | uint8_t transferFlag = PLDM_START_AND_END; |
| 613 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 614 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + |
| 615 | sizeof(attributeData)> |
| 616 | requestMsg{}; |
| 617 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 618 | auto rc = encode_set_bios_attribute_current_value_req( |
| 619 | instanceId, transferHandle, transferFlag, |
| 620 | reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData), |
| 621 | request, requestMsg.size() - hdrSize); |
| 622 | |
| 623 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 624 | |
| 625 | struct pldm_set_bios_attribute_current_value_req* req = |
| 626 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>( |
| 627 | request->payload); |
| 628 | ASSERT_EQ(htole32(transferHandle), req->transfer_handle); |
| 629 | ASSERT_EQ(transferFlag, req->transfer_flag); |
| 630 | ASSERT_EQ( |
| 631 | 0, memcmp(&attributeData, req->attribute_data, sizeof(attributeData))); |
| 632 | } |
| 633 | |
| 634 | TEST(SetBiosAttributeCurrentValue, testBadEncodeRequest) |
| 635 | { |
| 636 | uint8_t instanceId = 10; |
| 637 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 638 | uint8_t transferFlag = PLDM_START_AND_END; |
| 639 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 640 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES> |
| 641 | requestMsg{}; |
| 642 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 643 | |
| 644 | auto rc = encode_set_bios_attribute_current_value_req( |
| 645 | instanceId, transferHandle, transferFlag, nullptr, 0, nullptr, 0); |
| 646 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 647 | rc = encode_set_bios_attribute_current_value_req( |
| 648 | instanceId, transferHandle, transferFlag, |
| 649 | reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData), |
| 650 | request, requestMsg.size() - hdrSize); |
| 651 | |
| 652 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 653 | } |
| 654 | |
| 655 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeRequest) |
| 656 | { |
| 657 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 658 | uint8_t transferFlag = PLDM_START_AND_END; |
| 659 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 660 | |
| 661 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + |
| 662 | sizeof(attributeData)> |
| 663 | requestMsg{}; |
| 664 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 665 | struct pldm_set_bios_attribute_current_value_req* req = |
| 666 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>( |
| 667 | request->payload); |
| 668 | req->transfer_handle = htole32(transferHandle); |
| 669 | req->transfer_flag = transferFlag; |
| 670 | memcpy(req->attribute_data, &attributeData, sizeof(attributeData)); |
| 671 | |
| 672 | uint32_t retTransferHandle; |
| 673 | uint8_t retTransferFlag; |
| 674 | uint32_t retAttributeData; |
| 675 | size_t retAttributeDataLength; |
| 676 | auto rc = decode_set_bios_attribute_current_value_req( |
| 677 | request, requestMsg.size() - hdrSize, &retTransferHandle, |
| 678 | &retTransferFlag, reinterpret_cast<uint8_t*>(&retAttributeData), |
| 679 | &retAttributeDataLength); |
| 680 | |
| 681 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 682 | ASSERT_EQ(retTransferHandle, transferHandle); |
| 683 | ASSERT_EQ(retTransferFlag, transferFlag); |
| 684 | ASSERT_EQ(retAttributeDataLength, sizeof(attributeData)); |
| 685 | ASSERT_EQ(0, |
| 686 | memcmp(&retAttributeData, &attributeData, sizeof(attributeData))); |
| 687 | } |
| 688 | |
| 689 | TEST(SetBiosAttributeCurrentValue, testBadDecodeRequest) |
| 690 | { |
| 691 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 692 | uint8_t transferFlag = PLDM_START_AND_END; |
| 693 | uint32_t attributeData = 44; |
| 694 | size_t attributeDataLength = sizeof(attributeData); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 695 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES - 1> |
| 696 | requestMsg{}; |
| 697 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 698 | |
| 699 | auto rc = decode_set_bios_attribute_current_value_req( |
| 700 | nullptr, 0, &transferHandle, &transferFlag, |
| 701 | reinterpret_cast<uint8_t*>(&attributeData), &attributeDataLength); |
| 702 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 703 | rc = decode_set_bios_attribute_current_value_req( |
| 704 | request, requestMsg.size() - hdrSize, &transferHandle, &transferFlag, |
| 705 | reinterpret_cast<uint8_t*>(&attributeData), &attributeDataLength); |
| 706 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 707 | } |
| 708 | |
| 709 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeResponse) |
| 710 | { |
| 711 | uint8_t instanceId = 10; |
| 712 | uint32_t nextTransferHandle = 32; |
| 713 | uint8_t completionCode = PLDM_SUCCESS; |
| 714 | |
| 715 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 716 | responseMsg{}; |
| 717 | struct pldm_msg* response = |
| 718 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 719 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 720 | instanceId, completionCode, nextTransferHandle, response); |
| 721 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 722 | |
| 723 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 724 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 725 | response->payload); |
| 726 | ASSERT_EQ(completionCode, resp->completion_code); |
| 727 | ASSERT_EQ(htole32(nextTransferHandle), resp->next_transfer_handle); |
| 728 | } |
| 729 | |
| 730 | TEST(SetBiosAttributeCurrentValue, testBadEncodeResponse) |
| 731 | { |
| 732 | uint8_t instanceId = 10; |
| 733 | uint32_t nextTransferHandle = 32; |
| 734 | uint8_t completionCode = PLDM_SUCCESS; |
| 735 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 736 | instanceId, completionCode, nextTransferHandle, nullptr); |
| 737 | |
| 738 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 739 | } |
| 740 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeResponse) |
| 741 | { |
| 742 | uint32_t nextTransferHandle = 32; |
| 743 | uint8_t completionCode = PLDM_SUCCESS; |
| 744 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 745 | responseMsg{}; |
| 746 | struct pldm_msg* response = |
| 747 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 748 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 749 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 750 | response->payload); |
| 751 | |
| 752 | resp->completion_code = completionCode; |
| 753 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 754 | |
| 755 | uint8_t retCompletionCode; |
| 756 | uint32_t retNextTransferHandle; |
| 757 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 758 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 759 | &retNextTransferHandle); |
| 760 | |
| 761 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 762 | ASSERT_EQ(completionCode, retCompletionCode); |
| 763 | ASSERT_EQ(nextTransferHandle, retNextTransferHandle); |
| 764 | } |
| 765 | |
| 766 | TEST(SetBiosAttributeCurrentValue, testBadDecodeResponse) |
| 767 | { |
| 768 | uint32_t nextTransferHandle = 32; |
| 769 | uint8_t completionCode = PLDM_SUCCESS; |
| 770 | |
| 771 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES - 1> |
| 772 | responseMsg{}; |
| 773 | struct pldm_msg* response = |
| 774 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 775 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 776 | nullptr, 0, &completionCode, &nextTransferHandle); |
| 777 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 778 | |
| 779 | rc = decode_set_bios_attribute_current_value_resp( |
| 780 | response, responseMsg.size() - hdrSize, &completionCode, |
| 781 | &nextTransferHandle); |
| 782 | |
| 783 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 784 | } |