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