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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 18 | EXPECT_EQ(rc, PLDM_SUCCESS); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 39 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 40 | EXPECT_EQ(completionCode, response->payload[0]); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 41 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 42 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]), |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 43 | &seconds, sizeof(seconds))); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 44 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 45 | sizeof(seconds), |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 46 | &minutes, sizeof(minutes))); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 47 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 48 | sizeof(seconds) + sizeof(minutes), |
| 49 | &hours, sizeof(hours))); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 50 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 51 | sizeof(seconds) + sizeof(minutes) + sizeof(hours), |
| 52 | &day, sizeof(day))); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 53 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 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))); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 57 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 108 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 109 | EXPECT_EQ(seconds, retSeconds); |
| 110 | EXPECT_EQ(minutes, retMinutes); |
| 111 | EXPECT_EQ(hours, retHours); |
| 112 | EXPECT_EQ(day, retDay); |
| 113 | EXPECT_EQ(month, retMonth); |
| 114 | EXPECT_EQ(year, retYear); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 346 | EXPECT_EQ(rc, PLDM_SUCCESS); |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 347 | |
| 348 | struct pldm_get_bios_table_resp* resp = |
| 349 | reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload); |
| 350 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 351 | EXPECT_EQ(completionCode, resp->completion_code); |
| 352 | EXPECT_EQ(nextTransferHandle, resp->next_transfer_handle); |
| 353 | EXPECT_EQ(transferFlag, resp->transfer_flag); |
| 354 | EXPECT_EQ(0, memcmp(tableData.data(), resp->table_data, tableData.size())); |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 366 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 381 | EXPECT_EQ(rc, PLDM_SUCCESS); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 382 | |
| 383 | struct pldm_get_bios_table_req* req = |
| 384 | reinterpret_cast<struct pldm_get_bios_table_req*>(request->payload); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 385 | EXPECT_EQ(transferHandle, le32toh(req->transfer_handle)); |
| 386 | EXPECT_EQ(transferOpFlag, req->transfer_op_flag); |
| 387 | EXPECT_EQ(tableType, req->table_type); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 399 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 425 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 426 | EXPECT_EQ(transferHandle, retTransferHandle); |
| 427 | EXPECT_EQ(transferOpFlag, retTransferOpFlag); |
| 428 | EXPECT_EQ(tableType, retTableType); |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 453 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 454 | EXPECT_EQ(transferHandle, retTransferHandle); |
| 455 | EXPECT_EQ(transferOpFlag, retTransferOpFlag); |
| 456 | EXPECT_EQ(tableType, retTableType); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 482 | EXPECT_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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 511 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 512 | EXPECT_EQ(transferHandle, retTransferHandle); |
| 513 | EXPECT_EQ(transferOpFlag, retTransferOpFlag); |
| 514 | EXPECT_EQ(attributehandle, retattributehandle); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 543 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 551 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 572 | EXPECT_EQ(rc, PLDM_SUCCESS); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 579 | EXPECT_EQ(completionCode, resp->completion_code); |
| 580 | EXPECT_EQ(nextTransferHandle, resp->next_transfer_handle); |
| 581 | EXPECT_EQ(transferFlag, resp->transfer_flag); |
| 582 | EXPECT_EQ( |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 595 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 605 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 623 | EXPECT_EQ(rc, PLDM_SUCCESS); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 628 | EXPECT_EQ(htole32(transferHandle), req->transfer_handle); |
| 629 | EXPECT_EQ(transferFlag, req->transfer_flag); |
| 630 | EXPECT_EQ( |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 646 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 652 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 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; |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 674 | struct variable_field attribute; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 675 | auto rc = decode_set_bios_attribute_current_value_req( |
| 676 | request, requestMsg.size() - hdrSize, &retTransferHandle, |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 677 | &retTransferFlag, &attribute); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 678 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 679 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 680 | EXPECT_EQ(retTransferHandle, transferHandle); |
| 681 | EXPECT_EQ(retTransferFlag, transferFlag); |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 682 | EXPECT_EQ(attribute.length, sizeof(attributeData)); |
| 683 | EXPECT_EQ(0, memcmp(attribute.ptr, &attributeData, sizeof(attributeData))); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | TEST(SetBiosAttributeCurrentValue, testBadDecodeRequest) |
| 687 | { |
| 688 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 689 | uint8_t transferFlag = PLDM_START_AND_END; |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 690 | struct variable_field attribute; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 691 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES - 1> |
| 692 | requestMsg{}; |
| 693 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 694 | |
| 695 | auto rc = decode_set_bios_attribute_current_value_req( |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 696 | nullptr, 0, &transferHandle, &transferFlag, &attribute); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 697 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 698 | rc = decode_set_bios_attribute_current_value_req( |
| 699 | request, requestMsg.size() - hdrSize, &transferHandle, &transferFlag, |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 700 | &attribute); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 701 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeResponse) |
| 705 | { |
| 706 | uint8_t instanceId = 10; |
| 707 | uint32_t nextTransferHandle = 32; |
| 708 | uint8_t completionCode = PLDM_SUCCESS; |
| 709 | |
| 710 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 711 | responseMsg{}; |
| 712 | struct pldm_msg* response = |
| 713 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 714 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 715 | instanceId, completionCode, nextTransferHandle, response); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 716 | EXPECT_EQ(rc, PLDM_SUCCESS); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 717 | |
| 718 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 719 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 720 | response->payload); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 721 | EXPECT_EQ(completionCode, resp->completion_code); |
| 722 | EXPECT_EQ(htole32(nextTransferHandle), resp->next_transfer_handle); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | TEST(SetBiosAttributeCurrentValue, testBadEncodeResponse) |
| 726 | { |
| 727 | uint8_t instanceId = 10; |
| 728 | uint32_t nextTransferHandle = 32; |
| 729 | uint8_t completionCode = PLDM_SUCCESS; |
| 730 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 731 | instanceId, completionCode, nextTransferHandle, nullptr); |
| 732 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 733 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 734 | } |
| 735 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeResponse) |
| 736 | { |
| 737 | uint32_t nextTransferHandle = 32; |
| 738 | uint8_t completionCode = PLDM_SUCCESS; |
| 739 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 740 | responseMsg{}; |
| 741 | struct pldm_msg* response = |
| 742 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 743 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 744 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 745 | response->payload); |
| 746 | |
| 747 | resp->completion_code = completionCode; |
| 748 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 749 | |
| 750 | uint8_t retCompletionCode; |
| 751 | uint32_t retNextTransferHandle; |
| 752 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 753 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 754 | &retNextTransferHandle); |
| 755 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 756 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 757 | EXPECT_EQ(completionCode, retCompletionCode); |
| 758 | EXPECT_EQ(nextTransferHandle, retNextTransferHandle); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | TEST(SetBiosAttributeCurrentValue, testBadDecodeResponse) |
| 762 | { |
| 763 | uint32_t nextTransferHandle = 32; |
| 764 | uint8_t completionCode = PLDM_SUCCESS; |
| 765 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 766 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 767 | responseMsg{}; |
| 768 | struct pldm_msg* response = |
| 769 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 770 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 771 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 772 | response->payload); |
| 773 | |
| 774 | resp->completion_code = completionCode; |
| 775 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 776 | |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 777 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 778 | nullptr, 0, &completionCode, &nextTransferHandle); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 779 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 780 | |
| 781 | rc = decode_set_bios_attribute_current_value_resp( |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 782 | response, responseMsg.size() - hdrSize - 1, &completionCode, |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 783 | &nextTransferHandle); |
| 784 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 785 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 786 | } |
Sridevi Ramesh | 08efc7b | 2019-12-05 05:39:46 -0600 | [diff] [blame] | 787 | |
| 788 | TEST(GetBIOSTable, testDecodeResponse) |
| 789 | { |
| 790 | uint32_t nextTransferHandle = 32; |
| 791 | uint8_t completionCode = PLDM_SUCCESS; |
| 792 | uint8_t transfer_flag = PLDM_START_AND_END; |
| 793 | |
| 794 | std::array<uint8_t, hdrSize + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES> |
| 795 | responseMsg{}; |
| 796 | struct pldm_msg* response = |
| 797 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 798 | |
| 799 | struct pldm_get_bios_table_resp* resp = |
| 800 | reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload); |
| 801 | |
| 802 | resp->completion_code = completionCode; |
| 803 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 804 | resp->transfer_flag = transfer_flag; |
| 805 | size_t biosTableOffset = sizeof(completionCode) + |
| 806 | sizeof(nextTransferHandle) + sizeof(transfer_flag); |
| 807 | |
| 808 | uint8_t retCompletionCode; |
| 809 | uint32_t retNextTransferHandle; |
| 810 | uint8_t retransfer_flag; |
| 811 | size_t rebiosTableOffset = 0; |
| 812 | auto rc = decode_get_bios_table_resp( |
| 813 | response, responseMsg.size(), &retCompletionCode, |
| 814 | &retNextTransferHandle, &retransfer_flag, &rebiosTableOffset); |
| 815 | |
| 816 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 817 | ASSERT_EQ(completionCode, retCompletionCode); |
| 818 | ASSERT_EQ(nextTransferHandle, retNextTransferHandle); |
| 819 | ASSERT_EQ(transfer_flag, retransfer_flag); |
| 820 | ASSERT_EQ(biosTableOffset, rebiosTableOffset); |
| 821 | } |