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