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))); |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 57 | uint16_t yearLe = htole16(year); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 58 | EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) + |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 59 | sizeof(seconds) + sizeof(minutes) + sizeof(hours) + |
| 60 | sizeof(day) + sizeof(month), |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 61 | &yearLe, sizeof(yearLe))); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | TEST(GetDateTime, testDecodeResponse) |
| 65 | { |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 66 | std::array<uint8_t, hdrSize + PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{}; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 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; |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 76 | uint16_t yearLe = htole16(year); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 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 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 85 | memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &seconds, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 86 | sizeof(seconds)); |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 87 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
| 88 | hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 89 | &minutes, sizeof(minutes)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 90 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 91 | sizeof(minutes) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 92 | &hours, sizeof(hours)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 93 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 94 | sizeof(minutes) + sizeof(hours) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 95 | &day, sizeof(day)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 96 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 97 | sizeof(minutes) + sizeof(hours) + sizeof(day) + hdrSize, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 98 | &month, sizeof(month)); |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 99 | memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) + |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 100 | sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month) + |
| 101 | hdrSize, |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 102 | &yearLe, sizeof(yearLe)); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 103 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 104 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 105 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 106 | auto rc = decode_get_date_time_resp( |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 107 | response, responseMsg.size() - hdrSize, &completionCode, &retSeconds, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 108 | &retMinutes, &retHours, &retDay, &retMonth, &retYear); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 109 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 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); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 117 | } |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 118 | |
Xiaochao Ma | 39ae2a9 | 2019-11-12 20:30:34 +0800 | [diff] [blame] | 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)); |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 222 | EXPECT_EQ(year, bcd2dec16(le16toh(req->year))); |
Xiaochao Ma | 39ae2a9 | 2019-11-12 20:30:34 +0800 | [diff] [blame] | 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; |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 268 | uint16_t year = 0x2019; |
Xiaochao Ma | 39ae2a9 | 2019-11-12 20:30:34 +0800 | [diff] [blame] | 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; |
Lei YU | 7cfeb8e | 2020-02-27 18:24:18 +0800 | [diff] [blame] | 307 | uint16_t year = htole16(0x2019); |
Xiaochao Ma | 39ae2a9 | 2019-11-12 20:30:34 +0800 | [diff] [blame] | 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 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 348 | EXPECT_EQ(rc, PLDM_SUCCESS); |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 349 | |
| 350 | struct pldm_get_bios_table_resp* resp = |
| 351 | reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload); |
| 352 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 353 | EXPECT_EQ(completionCode, resp->completion_code); |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 354 | EXPECT_EQ(nextTransferHandle, le32toh(resp->next_transfer_handle)); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 355 | EXPECT_EQ(transferFlag, resp->transfer_flag); |
| 356 | EXPECT_EQ(0, memcmp(tableData.data(), resp->table_data, tableData.size())); |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 368 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 369 | } |
| 370 | |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 383 | EXPECT_EQ(rc, PLDM_SUCCESS); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 384 | |
| 385 | struct pldm_get_bios_table_req* req = |
| 386 | reinterpret_cast<struct pldm_get_bios_table_req*>(request->payload); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 387 | EXPECT_EQ(transferHandle, le32toh(req->transfer_handle)); |
| 388 | EXPECT_EQ(transferOpFlag, req->transfer_op_flag); |
| 389 | EXPECT_EQ(tableType, req->table_type); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 401 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 402 | } |
| 403 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 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 | |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 419 | request->transfer_handle = htole32(transferHandle); |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 427 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 428 | EXPECT_EQ(transferHandle, retTransferHandle); |
| 429 | EXPECT_EQ(transferOpFlag, retTransferOpFlag); |
| 430 | EXPECT_EQ(tableType, retTableType); |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 431 | } |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 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; |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 442 | |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 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 | |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 447 | request->transfer_handle = htole32(transferHandle); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 455 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 456 | EXPECT_EQ(transferHandle, retTransferHandle); |
| 457 | EXPECT_EQ(transferOpFlag, retTransferOpFlag); |
| 458 | EXPECT_EQ(tableType, retTableType); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 459 | } |
| 460 | /* |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 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 | |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 476 | request->transfer_handle = htole32(transferHandle); |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 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 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 484 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
Sridevi Ramesh | d3d5fa8 | 2019-10-29 11:45:16 -0500 | [diff] [blame] | 485 | }*/ |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 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 | |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 505 | request->transfer_handle = htole32(transferHandle); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 506 | request->transfer_op_flag = transferOpFlag; |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 507 | request->attribute_handle = htole16(attributehandle); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 508 | |
| 509 | auto rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 510 | req, requestMsg.size() - hdrSize, &retTransferHandle, |
| 511 | &retTransferOpFlag, &retattributehandle); |
| 512 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 513 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 514 | EXPECT_EQ(transferHandle, retTransferHandle); |
| 515 | EXPECT_EQ(transferOpFlag, retTransferOpFlag); |
| 516 | EXPECT_EQ(attributehandle, retattributehandle); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 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 | |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 538 | request->transfer_handle = htole32(transferHandle); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 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); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 545 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 546 | |
| 547 | transferHandle = 31; |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 548 | request->transfer_handle = htole32(transferHandle); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 549 | |
| 550 | rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 551 | req, 0, &retTransferHandle, &retTransferOpFlag, &retattribute_handle); |
| 552 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 553 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | TEST(GetBIOSAttributeCurrentValueByHandle, testGoodEncodeResponse) |
| 557 | { |
| 558 | |
| 559 | uint8_t instanceId = 10; |
| 560 | uint8_t completionCode = PLDM_SUCCESS; |
| 561 | uint32_t nextTransferHandle = 32; |
| 562 | uint8_t transferFlag = PLDM_START_AND_END; |
| 563 | uint8_t attributeData = 44; |
| 564 | std::array<uint8_t, |
| 565 | hdrSize + |
| 566 | sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)> |
| 567 | responseMsg{}; |
| 568 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 569 | |
| 570 | auto rc = encode_get_bios_current_value_by_handle_resp( |
| 571 | instanceId, completionCode, nextTransferHandle, transferFlag, |
| 572 | &attributeData, sizeof(attributeData), response); |
| 573 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 574 | EXPECT_EQ(rc, PLDM_SUCCESS); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 575 | |
| 576 | struct pldm_get_bios_attribute_current_value_by_handle_resp* resp = |
| 577 | reinterpret_cast< |
| 578 | struct pldm_get_bios_attribute_current_value_by_handle_resp*>( |
| 579 | response->payload); |
| 580 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 581 | EXPECT_EQ(completionCode, resp->completion_code); |
Lei YU | f02454e | 2020-02-28 17:24:06 +0800 | [diff] [blame] | 582 | EXPECT_EQ(nextTransferHandle, le32toh(resp->next_transfer_handle)); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 583 | EXPECT_EQ(transferFlag, resp->transfer_flag); |
| 584 | EXPECT_EQ( |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 585 | 0, memcmp(&attributeData, resp->attribute_data, sizeof(attributeData))); |
| 586 | } |
| 587 | |
| 588 | TEST(GetBIOSAttributeCurrentValueByHandle, testBadEncodeResponse) |
| 589 | { |
| 590 | uint32_t nextTransferHandle = 32; |
| 591 | uint8_t transferFlag = PLDM_START_AND_END; |
| 592 | uint8_t attributeData = 44; |
| 593 | |
| 594 | auto rc = encode_get_bios_current_value_by_handle_resp( |
| 595 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, &attributeData, |
| 596 | sizeof(attributeData), nullptr); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 597 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 598 | |
| 599 | std::array<uint8_t, |
| 600 | hdrSize + |
| 601 | sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)> |
| 602 | responseMsg{}; |
| 603 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 604 | rc = encode_get_bios_current_value_by_handle_resp( |
| 605 | 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, nullptr, |
| 606 | sizeof(attributeData), response); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 607 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
Zahed Hossain | d69af0b | 2019-07-30 01:33:31 -0500 | [diff] [blame] | 608 | } |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 609 | |
| 610 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeRequest) |
| 611 | { |
| 612 | uint8_t instanceId = 10; |
| 613 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 614 | uint8_t transferFlag = PLDM_START_AND_END; |
| 615 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 616 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + |
| 617 | sizeof(attributeData)> |
| 618 | requestMsg{}; |
| 619 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 620 | auto rc = encode_set_bios_attribute_current_value_req( |
| 621 | instanceId, transferHandle, transferFlag, |
| 622 | reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData), |
| 623 | request, requestMsg.size() - hdrSize); |
| 624 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 625 | EXPECT_EQ(rc, PLDM_SUCCESS); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 626 | |
| 627 | struct pldm_set_bios_attribute_current_value_req* req = |
| 628 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>( |
| 629 | request->payload); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 630 | EXPECT_EQ(htole32(transferHandle), req->transfer_handle); |
| 631 | EXPECT_EQ(transferFlag, req->transfer_flag); |
| 632 | EXPECT_EQ( |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 633 | 0, memcmp(&attributeData, req->attribute_data, sizeof(attributeData))); |
| 634 | } |
| 635 | |
| 636 | TEST(SetBiosAttributeCurrentValue, testBadEncodeRequest) |
| 637 | { |
| 638 | uint8_t instanceId = 10; |
| 639 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 640 | uint8_t transferFlag = PLDM_START_AND_END; |
| 641 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 642 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES> |
| 643 | requestMsg{}; |
| 644 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 645 | |
| 646 | auto rc = encode_set_bios_attribute_current_value_req( |
| 647 | instanceId, transferHandle, transferFlag, nullptr, 0, nullptr, 0); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 648 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 649 | rc = encode_set_bios_attribute_current_value_req( |
| 650 | instanceId, transferHandle, transferFlag, |
| 651 | reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData), |
| 652 | request, requestMsg.size() - hdrSize); |
| 653 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 654 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeRequest) |
| 658 | { |
| 659 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 660 | uint8_t transferFlag = PLDM_START_AND_END; |
| 661 | uint32_t attributeData = 44; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 662 | |
| 663 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + |
| 664 | sizeof(attributeData)> |
| 665 | requestMsg{}; |
| 666 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 667 | struct pldm_set_bios_attribute_current_value_req* req = |
| 668 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>( |
| 669 | request->payload); |
| 670 | req->transfer_handle = htole32(transferHandle); |
| 671 | req->transfer_flag = transferFlag; |
| 672 | memcpy(req->attribute_data, &attributeData, sizeof(attributeData)); |
| 673 | |
| 674 | uint32_t retTransferHandle; |
| 675 | uint8_t retTransferFlag; |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 676 | struct variable_field attribute; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 677 | auto rc = decode_set_bios_attribute_current_value_req( |
| 678 | request, requestMsg.size() - hdrSize, &retTransferHandle, |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 679 | &retTransferFlag, &attribute); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 680 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 681 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 682 | EXPECT_EQ(retTransferHandle, transferHandle); |
| 683 | EXPECT_EQ(retTransferFlag, transferFlag); |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 684 | EXPECT_EQ(attribute.length, sizeof(attributeData)); |
| 685 | EXPECT_EQ(0, memcmp(attribute.ptr, &attributeData, sizeof(attributeData))); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | TEST(SetBiosAttributeCurrentValue, testBadDecodeRequest) |
| 689 | { |
| 690 | uint32_t transferHandle = 32; |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 691 | uint8_t transferFlag = PLDM_START_AND_END; |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 692 | struct variable_field attribute; |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 693 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES - 1> |
| 694 | requestMsg{}; |
| 695 | auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data()); |
| 696 | |
| 697 | auto rc = decode_set_bios_attribute_current_value_req( |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 698 | nullptr, 0, &transferHandle, &transferFlag, &attribute); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 699 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 700 | rc = decode_set_bios_attribute_current_value_req( |
| 701 | request, requestMsg.size() - hdrSize, &transferHandle, &transferFlag, |
John Wang | 08c0595 | 2019-12-20 15:40:39 +0800 | [diff] [blame] | 702 | &attribute); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 703 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | TEST(SetBiosAttributeCurrentValue, testGoodEncodeResponse) |
| 707 | { |
| 708 | uint8_t instanceId = 10; |
| 709 | uint32_t nextTransferHandle = 32; |
| 710 | uint8_t completionCode = PLDM_SUCCESS; |
| 711 | |
| 712 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 713 | responseMsg{}; |
| 714 | struct pldm_msg* response = |
| 715 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 716 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 717 | instanceId, completionCode, nextTransferHandle, response); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 718 | EXPECT_EQ(rc, PLDM_SUCCESS); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 719 | |
| 720 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 721 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 722 | response->payload); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 723 | EXPECT_EQ(completionCode, resp->completion_code); |
| 724 | EXPECT_EQ(htole32(nextTransferHandle), resp->next_transfer_handle); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | TEST(SetBiosAttributeCurrentValue, testBadEncodeResponse) |
| 728 | { |
| 729 | uint8_t instanceId = 10; |
| 730 | uint32_t nextTransferHandle = 32; |
| 731 | uint8_t completionCode = PLDM_SUCCESS; |
| 732 | auto rc = encode_set_bios_attribute_current_value_resp( |
| 733 | instanceId, completionCode, nextTransferHandle, nullptr); |
| 734 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 735 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 736 | } |
| 737 | TEST(SetBiosAttributeCurrentValue, testGoodDecodeResponse) |
| 738 | { |
| 739 | uint32_t nextTransferHandle = 32; |
| 740 | uint8_t completionCode = PLDM_SUCCESS; |
| 741 | std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES> |
| 742 | responseMsg{}; |
| 743 | struct pldm_msg* response = |
| 744 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 745 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 746 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 747 | response->payload); |
| 748 | |
| 749 | resp->completion_code = completionCode; |
| 750 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 751 | |
| 752 | uint8_t retCompletionCode; |
| 753 | uint32_t retNextTransferHandle; |
| 754 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 755 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 756 | &retNextTransferHandle); |
| 757 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 758 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 759 | EXPECT_EQ(completionCode, retCompletionCode); |
| 760 | EXPECT_EQ(nextTransferHandle, retNextTransferHandle); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | TEST(SetBiosAttributeCurrentValue, testBadDecodeResponse) |
| 764 | { |
| 765 | uint32_t nextTransferHandle = 32; |
| 766 | uint8_t completionCode = PLDM_SUCCESS; |
| 767 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 768 | 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] | 769 | responseMsg{}; |
| 770 | struct pldm_msg* response = |
| 771 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 772 | struct pldm_set_bios_attribute_current_value_resp* resp = |
| 773 | reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>( |
| 774 | response->payload); |
| 775 | |
| 776 | resp->completion_code = completionCode; |
| 777 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 778 | |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 779 | auto rc = decode_set_bios_attribute_current_value_resp( |
| 780 | nullptr, 0, &completionCode, &nextTransferHandle); |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 781 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 782 | |
| 783 | rc = decode_set_bios_attribute_current_value_resp( |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 784 | response, responseMsg.size() - hdrSize - 1, &completionCode, |
John Wang | 4d84479 | 2019-08-15 15:51:40 +0800 | [diff] [blame] | 785 | &nextTransferHandle); |
| 786 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 787 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
John Wang | 81796c2 | 2019-09-06 11:18:57 +0800 | [diff] [blame] | 788 | } |
Sridevi Ramesh | 08efc7b | 2019-12-05 05:39:46 -0600 | [diff] [blame] | 789 | |
| 790 | TEST(GetBIOSTable, testDecodeResponse) |
| 791 | { |
| 792 | uint32_t nextTransferHandle = 32; |
| 793 | uint8_t completionCode = PLDM_SUCCESS; |
| 794 | uint8_t transfer_flag = PLDM_START_AND_END; |
| 795 | |
| 796 | std::array<uint8_t, hdrSize + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES> |
| 797 | responseMsg{}; |
| 798 | struct pldm_msg* response = |
| 799 | reinterpret_cast<struct pldm_msg*>(responseMsg.data()); |
| 800 | |
| 801 | struct pldm_get_bios_table_resp* resp = |
| 802 | reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload); |
| 803 | |
| 804 | resp->completion_code = completionCode; |
| 805 | resp->next_transfer_handle = htole32(nextTransferHandle); |
| 806 | resp->transfer_flag = transfer_flag; |
| 807 | size_t biosTableOffset = sizeof(completionCode) + |
| 808 | sizeof(nextTransferHandle) + sizeof(transfer_flag); |
| 809 | |
| 810 | uint8_t retCompletionCode; |
| 811 | uint32_t retNextTransferHandle; |
| 812 | uint8_t retransfer_flag; |
| 813 | size_t rebiosTableOffset = 0; |
| 814 | auto rc = decode_get_bios_table_resp( |
| 815 | response, responseMsg.size(), &retCompletionCode, |
| 816 | &retNextTransferHandle, &retransfer_flag, &rebiosTableOffset); |
| 817 | |
| 818 | ASSERT_EQ(rc, PLDM_SUCCESS); |
| 819 | ASSERT_EQ(completionCode, retCompletionCode); |
| 820 | ASSERT_EQ(nextTransferHandle, retNextTransferHandle); |
| 821 | ASSERT_EQ(transfer_flag, retransfer_flag); |
| 822 | ASSERT_EQ(biosTableOffset, rebiosTableOffset); |
| 823 | } |