blob: d8f8e73b365244bcb8aaca46f6353c3f00bd5a81 [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#include <string.h>
2
3#include <array>
4
5#include "libpldm/base.h"
6#include "libpldm/bios.h"
Xiaochao Ma39ae2a92019-11-12 20:30:34 +08007#include "libpldm/utils.h"
Sampa Misra032bd502019-03-06 05:03:22 -06008
9#include <gtest/gtest.h>
10
Zahed Hossain223a73d2019-07-04 12:46:18 -050011constexpr auto hdrSize = sizeof(pldm_msg_hdr);
12
Sampa Misra032bd502019-03-06 05:03:22 -060013TEST(GetDateTime, testEncodeRequest)
14{
15 pldm_msg request{};
Sampa Misra032bd502019-03-06 05:03:22 -060016
17 auto rc = encode_get_date_time_req(0, &request);
George Liu684a7162019-12-06 15:10:52 +080018 EXPECT_EQ(rc, PLDM_SUCCESS);
Sampa Misra032bd502019-03-06 05:03:22 -060019}
20
21TEST(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
vkaverapa6575b82019-04-03 05:33:52 -050031 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_DATE_TIME_RESP_BYTES>
32 responseMsg{};
Sampa Misra032bd502019-03-06 05:03:22 -060033
vkaverapa6575b82019-04-03 05:33:52 -050034 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
Sampa Misra032bd502019-03-06 05:03:22 -060035
36 auto rc = encode_get_date_time_resp(0, PLDM_SUCCESS, seconds, minutes,
vkaverapa6575b82019-04-03 05:33:52 -050037 hours, day, month, year, response);
Sampa Misra032bd502019-03-06 05:03:22 -060038
George Liu684a7162019-12-06 15:10:52 +080039 EXPECT_EQ(rc, PLDM_SUCCESS);
40 EXPECT_EQ(completionCode, response->payload[0]);
Sampa Misra032bd502019-03-06 05:03:22 -060041
George Liu684a7162019-12-06 15:10:52 +080042 EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
vkaverapa6575b82019-04-03 05:33:52 -050043 &seconds, sizeof(seconds)));
George Liu684a7162019-12-06 15:10:52 +080044 EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
vkaverapa6575b82019-04-03 05:33:52 -050045 sizeof(seconds),
Sampa Misra032bd502019-03-06 05:03:22 -060046 &minutes, sizeof(minutes)));
George Liu684a7162019-12-06 15:10:52 +080047 EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
vkaverapa6575b82019-04-03 05:33:52 -050048 sizeof(seconds) + sizeof(minutes),
49 &hours, sizeof(hours)));
George Liu684a7162019-12-06 15:10:52 +080050 EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
vkaverapa6575b82019-04-03 05:33:52 -050051 sizeof(seconds) + sizeof(minutes) + sizeof(hours),
52 &day, sizeof(day)));
George Liu684a7162019-12-06 15:10:52 +080053 EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
vkaverapa6575b82019-04-03 05:33:52 -050054 sizeof(seconds) + sizeof(minutes) + sizeof(hours) +
55 sizeof(day),
Sampa Misra032bd502019-03-06 05:03:22 -060056 &month, sizeof(month)));
Lei YUf02454e2020-02-28 17:24:06 +080057 uint16_t yearLe = htole16(year);
George Liu684a7162019-12-06 15:10:52 +080058 EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
vkaverapa6575b82019-04-03 05:33:52 -050059 sizeof(seconds) + sizeof(minutes) + sizeof(hours) +
60 sizeof(day) + sizeof(month),
Lei YUf02454e2020-02-28 17:24:06 +080061 &yearLe, sizeof(yearLe)));
Sampa Misra032bd502019-03-06 05:03:22 -060062}
63
64TEST(GetDateTime, testDecodeResponse)
65{
Zahed Hossain223a73d2019-07-04 12:46:18 -050066 std::array<uint8_t, hdrSize + PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{};
Sampa Misra032bd502019-03-06 05:03:22 -060067
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 YUf02454e2020-02-28 17:24:06 +080076 uint16_t yearLe = htole16(year);
Sampa Misra032bd502019-03-06 05:03:22 -060077
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 Hossain223a73d2019-07-04 12:46:18 -050085 memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &seconds,
Sampa Misra032bd502019-03-06 05:03:22 -060086 sizeof(seconds));
Zahed Hossain223a73d2019-07-04 12:46:18 -050087 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
88 hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060089 &minutes, sizeof(minutes));
vkaverapa6575b82019-04-03 05:33:52 -050090 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050091 sizeof(minutes) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060092 &hours, sizeof(hours));
vkaverapa6575b82019-04-03 05:33:52 -050093 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050094 sizeof(minutes) + sizeof(hours) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060095 &day, sizeof(day));
vkaverapa6575b82019-04-03 05:33:52 -050096 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050097 sizeof(minutes) + sizeof(hours) + sizeof(day) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060098 &month, sizeof(month));
vkaverapa6575b82019-04-03 05:33:52 -050099 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -0500100 sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month) +
101 hdrSize,
Lei YUf02454e2020-02-28 17:24:06 +0800102 &yearLe, sizeof(yearLe));
Sampa Misra032bd502019-03-06 05:03:22 -0600103
Zahed Hossain223a73d2019-07-04 12:46:18 -0500104 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
105
vkaverapa6575b82019-04-03 05:33:52 -0500106 auto rc = decode_get_date_time_resp(
Zahed Hossain223a73d2019-07-04 12:46:18 -0500107 response, responseMsg.size() - hdrSize, &completionCode, &retSeconds,
vkaverapa6575b82019-04-03 05:33:52 -0500108 &retMinutes, &retHours, &retDay, &retMonth, &retYear);
Sampa Misra032bd502019-03-06 05:03:22 -0600109
George Liu684a7162019-12-06 15:10:52 +0800110 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 Misra032bd502019-03-06 05:03:22 -0600117}
Sampa Misrab37be312019-07-03 02:26:41 -0500118
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800119TEST(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
138TEST(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
157TEST(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
177TEST(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
195TEST(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 YUf02454e2020-02-28 17:24:06 +0800222 EXPECT_EQ(year, bcd2dec16(le16toh(req->year)));
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800223}
224
225TEST(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
259TEST(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 YUf02454e2020-02-28 17:24:06 +0800268 uint16_t year = 0x2019;
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800269
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
300TEST(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 YU7cfeb8e2020-02-27 18:24:18 +0800307 uint16_t year = htole16(0x2019);
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800308
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 Misrab37be312019-07-03 02:26:41 -0500332TEST(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 Liu684a7162019-12-06 15:10:52 +0800348 EXPECT_EQ(rc, PLDM_SUCCESS);
Sampa Misrab37be312019-07-03 02:26:41 -0500349
350 struct pldm_get_bios_table_resp* resp =
351 reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload);
352
George Liu684a7162019-12-06 15:10:52 +0800353 EXPECT_EQ(completionCode, resp->completion_code);
Lei YUf02454e2020-02-28 17:24:06 +0800354 EXPECT_EQ(nextTransferHandle, le32toh(resp->next_transfer_handle));
George Liu684a7162019-12-06 15:10:52 +0800355 EXPECT_EQ(transferFlag, resp->transfer_flag);
356 EXPECT_EQ(0, memcmp(tableData.data(), resp->table_data, tableData.size()));
Sampa Misrab37be312019-07-03 02:26:41 -0500357}
358
359TEST(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 Liu684a7162019-12-06 15:10:52 +0800368 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Sampa Misrab37be312019-07-03 02:26:41 -0500369}
370
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500371TEST(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 Liu684a7162019-12-06 15:10:52 +0800383 EXPECT_EQ(rc, PLDM_SUCCESS);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500384
385 struct pldm_get_bios_table_req* req =
386 reinterpret_cast<struct pldm_get_bios_table_req*>(request->payload);
George Liu684a7162019-12-06 15:10:52 +0800387 EXPECT_EQ(transferHandle, le32toh(req->transfer_handle));
388 EXPECT_EQ(transferOpFlag, req->transfer_op_flag);
389 EXPECT_EQ(tableType, req->table_type);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500390}
391
392TEST(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 Liu684a7162019-12-06 15:10:52 +0800401 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500402}
403
Sampa Misrab37be312019-07-03 02:26:41 -0500404TEST(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 YUf02454e2020-02-28 17:24:06 +0800419 request->transfer_handle = htole32(transferHandle);
Sampa Misrab37be312019-07-03 02:26:41 -0500420 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 Liu684a7162019-12-06 15:10:52 +0800427 EXPECT_EQ(rc, PLDM_SUCCESS);
428 EXPECT_EQ(transferHandle, retTransferHandle);
429 EXPECT_EQ(transferOpFlag, retTransferOpFlag);
430 EXPECT_EQ(tableType, retTableType);
Sampa Misrab37be312019-07-03 02:26:41 -0500431}
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500432TEST(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 Misrab37be312019-07-03 02:26:41 -0500442
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500443 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 YUf02454e2020-02-28 17:24:06 +0800447 request->transfer_handle = htole32(transferHandle);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500448 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 Liu684a7162019-12-06 15:10:52 +0800455 EXPECT_EQ(rc, PLDM_SUCCESS);
456 EXPECT_EQ(transferHandle, retTransferHandle);
457 EXPECT_EQ(transferOpFlag, retTransferOpFlag);
458 EXPECT_EQ(tableType, retTableType);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500459}
460/*
Sampa Misrab37be312019-07-03 02:26:41 -0500461TEST(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 YUf02454e2020-02-28 17:24:06 +0800476 request->transfer_handle = htole32(transferHandle);
Sampa Misrab37be312019-07-03 02:26:41 -0500477 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 Liu684a7162019-12-06 15:10:52 +0800484 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500485}*/
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500486
487TEST(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 YUf02454e2020-02-28 17:24:06 +0800505 request->transfer_handle = htole32(transferHandle);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500506 request->transfer_op_flag = transferOpFlag;
Lei YUf02454e2020-02-28 17:24:06 +0800507 request->attribute_handle = htole16(attributehandle);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500508
509 auto rc = decode_get_bios_attribute_current_value_by_handle_req(
510 req, requestMsg.size() - hdrSize, &retTransferHandle,
511 &retTransferOpFlag, &retattributehandle);
512
George Liu684a7162019-12-06 15:10:52 +0800513 EXPECT_EQ(rc, PLDM_SUCCESS);
514 EXPECT_EQ(transferHandle, retTransferHandle);
515 EXPECT_EQ(transferOpFlag, retTransferOpFlag);
516 EXPECT_EQ(attributehandle, retattributehandle);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500517}
518
519TEST(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 YUf02454e2020-02-28 17:24:06 +0800538 request->transfer_handle = htole32(transferHandle);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500539 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 Liu684a7162019-12-06 15:10:52 +0800545 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500546
547 transferHandle = 31;
Lei YUf02454e2020-02-28 17:24:06 +0800548 request->transfer_handle = htole32(transferHandle);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500549
550 rc = decode_get_bios_attribute_current_value_by_handle_req(
551 req, 0, &retTransferHandle, &retTransferOpFlag, &retattribute_handle);
552
George Liu684a7162019-12-06 15:10:52 +0800553 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500554}
555
Adair Lica37ccb2020-04-24 14:32:58 +0800556TEST(GetBIOSAttributeCurrentValueByHandle, testGoodEncodeRequest)
557{
558 std::array<uint8_t, sizeof(pldm_msg_hdr) +
559 PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES>
560 requestMsg{};
561 uint32_t transferHandle = 45;
562 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
563 uint8_t attributeHandle = 10;
564
565 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
566 auto rc = encode_get_bios_attribute_current_value_by_handle_req(
567 0, transferHandle, transferOpFlag, attributeHandle, request);
568
569 EXPECT_EQ(rc, PLDM_SUCCESS);
570
571 struct pldm_get_bios_attribute_current_value_by_handle_req* req =
572 reinterpret_cast<
573 struct pldm_get_bios_attribute_current_value_by_handle_req*>(
574 request->payload);
575 EXPECT_EQ(transferHandle, le32toh(req->transfer_handle));
576 EXPECT_EQ(transferOpFlag, req->transfer_op_flag);
577 EXPECT_EQ(attributeHandle, le16toh(req->attribute_handle));
578}
579
580TEST(GetBIOSAttributeCurrentValueByHandle, testBadEncodeRequest)
581{
582 uint32_t transferHandle = 0;
583 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
584 uint8_t attributeHandle = 0;
585
586 auto rc = encode_get_bios_attribute_current_value_by_handle_req(
587 0, transferHandle, transferOpFlag, attributeHandle, nullptr);
588
589 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
590}
591
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500592TEST(GetBIOSAttributeCurrentValueByHandle, testGoodEncodeResponse)
593{
594
595 uint8_t instanceId = 10;
596 uint8_t completionCode = PLDM_SUCCESS;
597 uint32_t nextTransferHandle = 32;
598 uint8_t transferFlag = PLDM_START_AND_END;
599 uint8_t attributeData = 44;
600 std::array<uint8_t,
601 hdrSize +
602 sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)>
603 responseMsg{};
604 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
605
606 auto rc = encode_get_bios_current_value_by_handle_resp(
607 instanceId, completionCode, nextTransferHandle, transferFlag,
608 &attributeData, sizeof(attributeData), response);
609
George Liu684a7162019-12-06 15:10:52 +0800610 EXPECT_EQ(rc, PLDM_SUCCESS);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500611
612 struct pldm_get_bios_attribute_current_value_by_handle_resp* resp =
613 reinterpret_cast<
614 struct pldm_get_bios_attribute_current_value_by_handle_resp*>(
615 response->payload);
616
George Liu684a7162019-12-06 15:10:52 +0800617 EXPECT_EQ(completionCode, resp->completion_code);
Lei YUf02454e2020-02-28 17:24:06 +0800618 EXPECT_EQ(nextTransferHandle, le32toh(resp->next_transfer_handle));
George Liu684a7162019-12-06 15:10:52 +0800619 EXPECT_EQ(transferFlag, resp->transfer_flag);
620 EXPECT_EQ(
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500621 0, memcmp(&attributeData, resp->attribute_data, sizeof(attributeData)));
622}
623
624TEST(GetBIOSAttributeCurrentValueByHandle, testBadEncodeResponse)
625{
626 uint32_t nextTransferHandle = 32;
627 uint8_t transferFlag = PLDM_START_AND_END;
628 uint8_t attributeData = 44;
629
630 auto rc = encode_get_bios_current_value_by_handle_resp(
631 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, &attributeData,
632 sizeof(attributeData), nullptr);
George Liu684a7162019-12-06 15:10:52 +0800633 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500634
635 std::array<uint8_t,
636 hdrSize +
637 sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)>
638 responseMsg{};
639 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
640 rc = encode_get_bios_current_value_by_handle_resp(
641 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, nullptr,
642 sizeof(attributeData), response);
George Liu684a7162019-12-06 15:10:52 +0800643 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500644}
John Wang4d844792019-08-15 15:51:40 +0800645
646TEST(SetBiosAttributeCurrentValue, testGoodEncodeRequest)
647{
648 uint8_t instanceId = 10;
649 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800650 uint8_t transferFlag = PLDM_START_AND_END;
651 uint32_t attributeData = 44;
John Wang4d844792019-08-15 15:51:40 +0800652 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES +
653 sizeof(attributeData)>
654 requestMsg{};
655 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
656 auto rc = encode_set_bios_attribute_current_value_req(
657 instanceId, transferHandle, transferFlag,
658 reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData),
659 request, requestMsg.size() - hdrSize);
660
George Liu684a7162019-12-06 15:10:52 +0800661 EXPECT_EQ(rc, PLDM_SUCCESS);
John Wang4d844792019-08-15 15:51:40 +0800662
663 struct pldm_set_bios_attribute_current_value_req* req =
664 reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>(
665 request->payload);
George Liu684a7162019-12-06 15:10:52 +0800666 EXPECT_EQ(htole32(transferHandle), req->transfer_handle);
667 EXPECT_EQ(transferFlag, req->transfer_flag);
668 EXPECT_EQ(
John Wang4d844792019-08-15 15:51:40 +0800669 0, memcmp(&attributeData, req->attribute_data, sizeof(attributeData)));
670}
671
672TEST(SetBiosAttributeCurrentValue, testBadEncodeRequest)
673{
674 uint8_t instanceId = 10;
675 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800676 uint8_t transferFlag = PLDM_START_AND_END;
677 uint32_t attributeData = 44;
John Wang4d844792019-08-15 15:51:40 +0800678 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES>
679 requestMsg{};
680 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
681
682 auto rc = encode_set_bios_attribute_current_value_req(
683 instanceId, transferHandle, transferFlag, nullptr, 0, nullptr, 0);
George Liu684a7162019-12-06 15:10:52 +0800684 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Wang4d844792019-08-15 15:51:40 +0800685 rc = encode_set_bios_attribute_current_value_req(
686 instanceId, transferHandle, transferFlag,
687 reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData),
688 request, requestMsg.size() - hdrSize);
689
George Liu684a7162019-12-06 15:10:52 +0800690 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
John Wang4d844792019-08-15 15:51:40 +0800691}
692
693TEST(SetBiosAttributeCurrentValue, testGoodDecodeRequest)
694{
695 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800696 uint8_t transferFlag = PLDM_START_AND_END;
697 uint32_t attributeData = 44;
John Wang4d844792019-08-15 15:51:40 +0800698
699 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES +
700 sizeof(attributeData)>
701 requestMsg{};
702 auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data());
703 struct pldm_set_bios_attribute_current_value_req* req =
704 reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>(
705 request->payload);
706 req->transfer_handle = htole32(transferHandle);
707 req->transfer_flag = transferFlag;
708 memcpy(req->attribute_data, &attributeData, sizeof(attributeData));
709
710 uint32_t retTransferHandle;
711 uint8_t retTransferFlag;
John Wang08c05952019-12-20 15:40:39 +0800712 struct variable_field attribute;
John Wang4d844792019-08-15 15:51:40 +0800713 auto rc = decode_set_bios_attribute_current_value_req(
714 request, requestMsg.size() - hdrSize, &retTransferHandle,
John Wang08c05952019-12-20 15:40:39 +0800715 &retTransferFlag, &attribute);
John Wang4d844792019-08-15 15:51:40 +0800716
George Liu684a7162019-12-06 15:10:52 +0800717 EXPECT_EQ(rc, PLDM_SUCCESS);
718 EXPECT_EQ(retTransferHandle, transferHandle);
719 EXPECT_EQ(retTransferFlag, transferFlag);
John Wang08c05952019-12-20 15:40:39 +0800720 EXPECT_EQ(attribute.length, sizeof(attributeData));
721 EXPECT_EQ(0, memcmp(attribute.ptr, &attributeData, sizeof(attributeData)));
John Wang4d844792019-08-15 15:51:40 +0800722}
723
724TEST(SetBiosAttributeCurrentValue, testBadDecodeRequest)
725{
726 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800727 uint8_t transferFlag = PLDM_START_AND_END;
John Wang08c05952019-12-20 15:40:39 +0800728 struct variable_field attribute;
John Wang4d844792019-08-15 15:51:40 +0800729 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES - 1>
730 requestMsg{};
731 auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data());
732
733 auto rc = decode_set_bios_attribute_current_value_req(
John Wang08c05952019-12-20 15:40:39 +0800734 nullptr, 0, &transferHandle, &transferFlag, &attribute);
George Liu684a7162019-12-06 15:10:52 +0800735 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Wang4d844792019-08-15 15:51:40 +0800736 rc = decode_set_bios_attribute_current_value_req(
737 request, requestMsg.size() - hdrSize, &transferHandle, &transferFlag,
John Wang08c05952019-12-20 15:40:39 +0800738 &attribute);
George Liu684a7162019-12-06 15:10:52 +0800739 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
John Wang4d844792019-08-15 15:51:40 +0800740}
741
742TEST(SetBiosAttributeCurrentValue, testGoodEncodeResponse)
743{
744 uint8_t instanceId = 10;
745 uint32_t nextTransferHandle = 32;
746 uint8_t completionCode = PLDM_SUCCESS;
747
748 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES>
749 responseMsg{};
750 struct pldm_msg* response =
751 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
752 auto rc = encode_set_bios_attribute_current_value_resp(
753 instanceId, completionCode, nextTransferHandle, response);
George Liu684a7162019-12-06 15:10:52 +0800754 EXPECT_EQ(rc, PLDM_SUCCESS);
John Wang4d844792019-08-15 15:51:40 +0800755
756 struct pldm_set_bios_attribute_current_value_resp* resp =
757 reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>(
758 response->payload);
George Liu684a7162019-12-06 15:10:52 +0800759 EXPECT_EQ(completionCode, resp->completion_code);
760 EXPECT_EQ(htole32(nextTransferHandle), resp->next_transfer_handle);
John Wang4d844792019-08-15 15:51:40 +0800761}
762
763TEST(SetBiosAttributeCurrentValue, testBadEncodeResponse)
764{
765 uint8_t instanceId = 10;
766 uint32_t nextTransferHandle = 32;
767 uint8_t completionCode = PLDM_SUCCESS;
768 auto rc = encode_set_bios_attribute_current_value_resp(
769 instanceId, completionCode, nextTransferHandle, nullptr);
770
George Liu684a7162019-12-06 15:10:52 +0800771 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Wang4d844792019-08-15 15:51:40 +0800772}
773TEST(SetBiosAttributeCurrentValue, testGoodDecodeResponse)
774{
775 uint32_t nextTransferHandle = 32;
776 uint8_t completionCode = PLDM_SUCCESS;
777 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES>
778 responseMsg{};
779 struct pldm_msg* response =
780 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
781 struct pldm_set_bios_attribute_current_value_resp* resp =
782 reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>(
783 response->payload);
784
785 resp->completion_code = completionCode;
786 resp->next_transfer_handle = htole32(nextTransferHandle);
787
788 uint8_t retCompletionCode;
789 uint32_t retNextTransferHandle;
790 auto rc = decode_set_bios_attribute_current_value_resp(
791 response, responseMsg.size() - hdrSize, &retCompletionCode,
792 &retNextTransferHandle);
793
George Liu684a7162019-12-06 15:10:52 +0800794 EXPECT_EQ(rc, PLDM_SUCCESS);
795 EXPECT_EQ(completionCode, retCompletionCode);
796 EXPECT_EQ(nextTransferHandle, retNextTransferHandle);
John Wang4d844792019-08-15 15:51:40 +0800797}
798
799TEST(SetBiosAttributeCurrentValue, testBadDecodeResponse)
800{
801 uint32_t nextTransferHandle = 32;
802 uint8_t completionCode = PLDM_SUCCESS;
803
George Liu684a7162019-12-06 15:10:52 +0800804 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES>
John Wang4d844792019-08-15 15:51:40 +0800805 responseMsg{};
806 struct pldm_msg* response =
807 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
George Liu684a7162019-12-06 15:10:52 +0800808 struct pldm_set_bios_attribute_current_value_resp* resp =
809 reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>(
810 response->payload);
811
812 resp->completion_code = completionCode;
813 resp->next_transfer_handle = htole32(nextTransferHandle);
814
John Wang4d844792019-08-15 15:51:40 +0800815 auto rc = decode_set_bios_attribute_current_value_resp(
816 nullptr, 0, &completionCode, &nextTransferHandle);
George Liu684a7162019-12-06 15:10:52 +0800817 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Wang4d844792019-08-15 15:51:40 +0800818
819 rc = decode_set_bios_attribute_current_value_resp(
George Liu684a7162019-12-06 15:10:52 +0800820 response, responseMsg.size() - hdrSize - 1, &completionCode,
John Wang4d844792019-08-15 15:51:40 +0800821 &nextTransferHandle);
822
George Liu684a7162019-12-06 15:10:52 +0800823 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
John Wang81796c22019-09-06 11:18:57 +0800824}
Sridevi Ramesh08efc7b2019-12-05 05:39:46 -0600825
826TEST(GetBIOSTable, testDecodeResponse)
827{
828 uint32_t nextTransferHandle = 32;
829 uint8_t completionCode = PLDM_SUCCESS;
830 uint8_t transfer_flag = PLDM_START_AND_END;
831
832 std::array<uint8_t, hdrSize + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES>
833 responseMsg{};
834 struct pldm_msg* response =
835 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
836
837 struct pldm_get_bios_table_resp* resp =
838 reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload);
839
840 resp->completion_code = completionCode;
841 resp->next_transfer_handle = htole32(nextTransferHandle);
842 resp->transfer_flag = transfer_flag;
843 size_t biosTableOffset = sizeof(completionCode) +
844 sizeof(nextTransferHandle) + sizeof(transfer_flag);
845
846 uint8_t retCompletionCode;
847 uint32_t retNextTransferHandle;
848 uint8_t retransfer_flag;
849 size_t rebiosTableOffset = 0;
850 auto rc = decode_get_bios_table_resp(
851 response, responseMsg.size(), &retCompletionCode,
852 &retNextTransferHandle, &retransfer_flag, &rebiosTableOffset);
853
854 ASSERT_EQ(rc, PLDM_SUCCESS);
855 ASSERT_EQ(completionCode, retCompletionCode);
856 ASSERT_EQ(nextTransferHandle, retNextTransferHandle);
857 ASSERT_EQ(transfer_flag, retransfer_flag);
858 ASSERT_EQ(biosTableOffset, rebiosTableOffset);
859}
Adair Lica37ccb2020-04-24 14:32:58 +0800860
861TEST(GetBIOSAttributeCurrentValueByHandle, testDecodeResponse)
862{
863 uint32_t nextTransferHandle = 32;
864 uint8_t completionCode = PLDM_SUCCESS;
865 uint8_t transfer_flag = PLDM_START_AND_END;
866 uint32_t attributeData = 44;
867
868 std::array<uint8_t,
869 hdrSize + PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES +
870 sizeof(attributeData)>
871 responseMsg{};
872 struct pldm_msg* response =
873 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
874
875 struct pldm_get_bios_attribute_current_value_by_handle_resp* resp =
876 reinterpret_cast<
877 struct pldm_get_bios_attribute_current_value_by_handle_resp*>(
878 response->payload);
879
880 resp->completion_code = completionCode;
881 resp->next_transfer_handle = htole32(nextTransferHandle);
882 resp->transfer_flag = transfer_flag;
883 memcpy(resp->attribute_data, &attributeData, sizeof(attributeData));
884
885 uint8_t retCompletionCode;
886 uint32_t retNextTransferHandle;
887 uint8_t retransfer_flag;
888 struct variable_field retAttributeData;
889 auto rc = decode_get_bios_attribute_current_value_by_handle_resp(
890 response, responseMsg.size() - hdrSize, &retCompletionCode,
891 &retNextTransferHandle, &retransfer_flag, &retAttributeData);
892
893 EXPECT_EQ(rc, PLDM_SUCCESS);
894 EXPECT_EQ(completionCode, retCompletionCode);
895 EXPECT_EQ(nextTransferHandle, retNextTransferHandle);
896 EXPECT_EQ(transfer_flag, retransfer_flag);
897 EXPECT_EQ(sizeof(attributeData), retAttributeData.length);
898 EXPECT_EQ(
899 0, memcmp(retAttributeData.ptr, &attributeData, sizeof(attributeData)));
900}