blob: ad07877ea2a541c707bc86efe2b011a91e4cd6a0 [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)));
George Liu684a7162019-12-06 15:10:52 +080057 EXPECT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
vkaverapa6575b82019-04-03 05:33:52 -050058 sizeof(seconds) + sizeof(minutes) + sizeof(hours) +
59 sizeof(day) + sizeof(month),
60 &year, sizeof(year)));
Sampa Misra032bd502019-03-06 05:03:22 -060061}
62
63TEST(GetDateTime, testDecodeResponse)
64{
Zahed Hossain223a73d2019-07-04 12:46:18 -050065 std::array<uint8_t, hdrSize + PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{};
Sampa Misra032bd502019-03-06 05:03:22 -060066
67 uint8_t completionCode = 0;
68
69 uint8_t seconds = 55;
70 uint8_t minutes = 2;
71 uint8_t hours = 8;
72 uint8_t day = 9;
73 uint8_t month = 7;
74 uint16_t year = 2020;
75
76 uint8_t retSeconds = 0;
77 uint8_t retMinutes = 0;
78 uint8_t retHours = 0;
79 uint8_t retDay = 0;
80 uint8_t retMonth = 0;
81 uint16_t retYear = 0;
82
Zahed Hossain223a73d2019-07-04 12:46:18 -050083 memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &seconds,
Sampa Misra032bd502019-03-06 05:03:22 -060084 sizeof(seconds));
Zahed Hossain223a73d2019-07-04 12:46:18 -050085 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
86 hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060087 &minutes, sizeof(minutes));
vkaverapa6575b82019-04-03 05:33:52 -050088 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050089 sizeof(minutes) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060090 &hours, sizeof(hours));
vkaverapa6575b82019-04-03 05:33:52 -050091 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050092 sizeof(minutes) + sizeof(hours) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060093 &day, sizeof(day));
vkaverapa6575b82019-04-03 05:33:52 -050094 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050095 sizeof(minutes) + sizeof(hours) + sizeof(day) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060096 &month, sizeof(month));
vkaverapa6575b82019-04-03 05:33:52 -050097 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050098 sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month) +
99 hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -0600100 &year, sizeof(year));
101
Zahed Hossain223a73d2019-07-04 12:46:18 -0500102 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
103
vkaverapa6575b82019-04-03 05:33:52 -0500104 auto rc = decode_get_date_time_resp(
Zahed Hossain223a73d2019-07-04 12:46:18 -0500105 response, responseMsg.size() - hdrSize, &completionCode, &retSeconds,
vkaverapa6575b82019-04-03 05:33:52 -0500106 &retMinutes, &retHours, &retDay, &retMonth, &retYear);
Sampa Misra032bd502019-03-06 05:03:22 -0600107
George Liu684a7162019-12-06 15:10:52 +0800108 EXPECT_EQ(rc, PLDM_SUCCESS);
109 EXPECT_EQ(seconds, retSeconds);
110 EXPECT_EQ(minutes, retMinutes);
111 EXPECT_EQ(hours, retHours);
112 EXPECT_EQ(day, retDay);
113 EXPECT_EQ(month, retMonth);
114 EXPECT_EQ(year, retYear);
Sampa Misra032bd502019-03-06 05:03:22 -0600115}
Sampa Misrab37be312019-07-03 02:26:41 -0500116
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800117TEST(SetDateTime, testGoodEncodeResponse)
118{
119 uint8_t instanceId = 0;
120 uint8_t completionCode = PLDM_SUCCESS;
121
122 std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)>
123 responseMsg{};
124 struct pldm_msg* response =
125 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
126
127 auto rc = encode_set_date_time_resp(instanceId, completionCode, response,
128 responseMsg.size() - hdrSize);
129 EXPECT_EQ(rc, PLDM_SUCCESS);
130
131 struct pldm_only_cc_resp* resp =
132 reinterpret_cast<struct pldm_only_cc_resp*>(response->payload);
133 EXPECT_EQ(completionCode, resp->completion_code);
134}
135
136TEST(SetDateTime, testBadEncodeResponse)
137{
138
139 uint8_t instanceId = 10;
140 uint8_t completionCode = PLDM_SUCCESS;
141 std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)>
142 responseMsg{};
143 struct pldm_msg* response =
144 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
145 auto rc = encode_set_date_time_resp(instanceId, completionCode, nullptr,
146 responseMsg.size() - hdrSize);
147
148 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
149 rc = encode_set_date_time_resp(instanceId, completionCode, response,
150 responseMsg.size() - hdrSize - 1);
151
152 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
153}
154
155TEST(SetDateTime, testGoodDecodeResponse)
156{
157 uint8_t completionCode = PLDM_SUCCESS;
158 std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)>
159 responseMsg{};
160 struct pldm_msg* response =
161 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
162 struct pldm_only_cc_resp* resp =
163 reinterpret_cast<struct pldm_only_cc_resp*>(response->payload);
164
165 resp->completion_code = completionCode;
166
167 uint8_t retCompletionCode;
168 auto rc = decode_set_date_time_resp(response, responseMsg.size() - hdrSize,
169 &retCompletionCode);
170
171 EXPECT_EQ(rc, PLDM_SUCCESS);
172 EXPECT_EQ(completionCode, retCompletionCode);
173}
174
175TEST(SetDateTime, testBadDecodeResponse)
176{
177 uint8_t completionCode = PLDM_SUCCESS;
178
179 std::array<uint8_t, hdrSize + sizeof(struct pldm_only_cc_resp)>
180 responseMsg{};
181 struct pldm_msg* response =
182 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
183 auto rc = decode_set_date_time_resp(nullptr, responseMsg.size() - hdrSize,
184 &completionCode);
185 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
186
187 rc = decode_set_date_time_resp(response, responseMsg.size() - hdrSize - 1,
188 &completionCode);
189
190 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
191}
192
193TEST(SetDateTime, testGoodEncodeRequset)
194{
195 uint8_t instanceId = 0;
196 uint8_t seconds = 50;
197 uint8_t minutes = 20;
198 uint8_t hours = 10;
199 uint8_t day = 11;
200 uint8_t month = 11;
201 uint16_t year = 2019;
202
203 std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)>
204 requestMsg{};
205
206 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
207 auto rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, day,
208 month, year, request,
209 requestMsg.size() - hdrSize);
210
211 EXPECT_EQ(rc, PLDM_SUCCESS);
212
213 struct pldm_set_date_time_req* req =
214 reinterpret_cast<struct pldm_set_date_time_req*>(request->payload);
215 EXPECT_EQ(seconds, bcd2dec8(req->seconds));
216 EXPECT_EQ(minutes, bcd2dec8(req->minutes));
217 EXPECT_EQ(hours, bcd2dec8(req->hours));
218 EXPECT_EQ(day, bcd2dec8(req->day));
219 EXPECT_EQ(month, bcd2dec8(req->month));
220 EXPECT_EQ(year, le16toh(bcd2dec16(req->year)));
221}
222
223TEST(SetDateTime, testBadEncodeRequset)
224{
225 uint8_t instanceId = 0;
226
227 uint8_t seconds = 50;
228 uint8_t minutes = 20;
229 uint8_t hours = 10;
230 uint8_t day = 13;
231 uint8_t month = 11;
232 uint16_t year = 2019;
233
234 uint8_t erday = 43;
235
236 std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)>
237 requestMsg{};
238
239 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
240
241 auto rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, day,
242 month, year, nullptr,
243 requestMsg.size() - hdrSize);
244 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
245
246 rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, erday,
247 month, year, request,
248 requestMsg.size() - hdrSize);
249 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
250
251 rc = encode_set_date_time_req(instanceId, seconds, minutes, hours, day,
252 month, year, request,
253 requestMsg.size() - hdrSize - 4);
254 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
255}
256
257TEST(SetDateTime, testGoodDecodeRequest)
258{
259 std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)>
260 requestMsg{};
261 uint8_t seconds = 0x50;
262 uint8_t minutes = 0x20;
263 uint8_t hours = 0x10;
264 uint8_t day = 0x11;
265 uint8_t month = 0x11;
266 uint16_t year = 0x2019;
267
268 auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data());
269 struct pldm_set_date_time_req* req =
270 reinterpret_cast<struct pldm_set_date_time_req*>(request->payload);
271 req->seconds = seconds;
272 req->minutes = minutes;
273 req->hours = hours;
274 req->day = day;
275 req->month = month;
276 req->year = htole16(year);
277
278 uint8_t retseconds;
279 uint8_t retminutes;
280 uint8_t rethours;
281 uint8_t retday;
282 uint8_t retmonth;
283 uint16_t retyear;
284
285 auto rc = decode_set_date_time_req(request, requestMsg.size() - hdrSize,
286 &retseconds, &retminutes, &rethours,
287 &retday, &retmonth, &retyear);
288
289 EXPECT_EQ(rc, PLDM_SUCCESS);
290 EXPECT_EQ(retseconds, 50);
291 EXPECT_EQ(retminutes, 20);
292 EXPECT_EQ(rethours, 10);
293 EXPECT_EQ(retday, 11);
294 EXPECT_EQ(retmonth, 11);
295 EXPECT_EQ(retyear, 2019);
296}
297
298TEST(SetDateTime, testBadDecodeRequest)
299{
300 uint8_t seconds = 0x50;
301 uint8_t minutes = 0x20;
302 uint8_t hours = 0x10;
303 uint8_t day = 0x11;
304 uint8_t month = 0x11;
305 uint16_t year = 0x2019;
306
307 std::array<uint8_t, hdrSize + sizeof(struct pldm_set_date_time_req)>
308 requestMsg{};
309
310 auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data());
311
312 decode_set_date_time_req(request, requestMsg.size() - hdrSize, &seconds,
313 &minutes, &hours, &day, &month, &year);
314
315 auto rc =
316 decode_set_date_time_req(nullptr, requestMsg.size() - hdrSize, &seconds,
317 &minutes, &hours, &day, &month, &year);
318 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
319
320 rc = decode_set_date_time_req(request, requestMsg.size() - hdrSize, nullptr,
321 nullptr, nullptr, nullptr, nullptr, nullptr);
322 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
323
324 rc = decode_set_date_time_req(request, requestMsg.size() - hdrSize - 4,
325 &seconds, &minutes, &hours, &day, &month,
326 &year);
327 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
328}
329
Sampa Misrab37be312019-07-03 02:26:41 -0500330TEST(GetBIOSTable, testGoodEncodeResponse)
331{
332 std::array<uint8_t,
333 sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4>
334 responseMsg{};
335 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
336
337 uint8_t completionCode = PLDM_SUCCESS;
338 uint32_t nextTransferHandle = 32;
339 uint8_t transferFlag = PLDM_START_AND_END;
340 std::array<uint8_t, 4> tableData{1, 2, 3, 4};
341
342 auto rc = encode_get_bios_table_resp(
343 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, tableData.data(),
344 sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4,
345 response);
George Liu684a7162019-12-06 15:10:52 +0800346 EXPECT_EQ(rc, PLDM_SUCCESS);
Sampa Misrab37be312019-07-03 02:26:41 -0500347
348 struct pldm_get_bios_table_resp* resp =
349 reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload);
350
George Liu684a7162019-12-06 15:10:52 +0800351 EXPECT_EQ(completionCode, resp->completion_code);
352 EXPECT_EQ(nextTransferHandle, resp->next_transfer_handle);
353 EXPECT_EQ(transferFlag, resp->transfer_flag);
354 EXPECT_EQ(0, memcmp(tableData.data(), resp->table_data, tableData.size()));
Sampa Misrab37be312019-07-03 02:26:41 -0500355}
356
357TEST(GetBIOSTable, testBadEncodeResponse)
358{
359 uint32_t nextTransferHandle = 32;
360 uint8_t transferFlag = PLDM_START_AND_END;
361 std::array<uint8_t, 4> tableData{1, 2, 3, 4};
362
363 auto rc = encode_get_bios_table_resp(
364 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, tableData.data(),
365 sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4, nullptr);
George Liu684a7162019-12-06 15:10:52 +0800366 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Sampa Misrab37be312019-07-03 02:26:41 -0500367}
368
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500369TEST(GetBIOSTable, testGoodEncodeRequest)
370{
371 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_REQ_BYTES>
372 requestMsg{};
373 uint32_t transferHandle = 0x0;
374 uint8_t transferOpFlag = 0x01;
375 uint8_t tableType = PLDM_BIOS_ATTR_TABLE;
376
377 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
378 auto rc = encode_get_bios_table_req(0, transferHandle, transferOpFlag,
379 tableType, request);
380
George Liu684a7162019-12-06 15:10:52 +0800381 EXPECT_EQ(rc, PLDM_SUCCESS);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500382
383 struct pldm_get_bios_table_req* req =
384 reinterpret_cast<struct pldm_get_bios_table_req*>(request->payload);
George Liu684a7162019-12-06 15:10:52 +0800385 EXPECT_EQ(transferHandle, le32toh(req->transfer_handle));
386 EXPECT_EQ(transferOpFlag, req->transfer_op_flag);
387 EXPECT_EQ(tableType, req->table_type);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500388}
389
390TEST(GetBIOSTable, testBadEncodeRequest)
391{
392 uint32_t transferHandle = 0x0;
393 uint8_t transferOpFlag = 0x01;
394 uint8_t tableType = PLDM_BIOS_ATTR_TABLE;
395
396 auto rc = encode_get_bios_table_req(0, transferHandle, transferOpFlag,
397 tableType, nullptr);
398
George Liu684a7162019-12-06 15:10:52 +0800399 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500400}
401
Sampa Misrab37be312019-07-03 02:26:41 -0500402TEST(GetBIOSTable, testGoodDecodeRequest)
403{
404 const auto hdr_size = sizeof(pldm_msg_hdr);
405 std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{};
406 uint32_t transferHandle = 31;
407 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
408 uint8_t tableType = PLDM_BIOS_ATTR_TABLE;
409 uint32_t retTransferHandle = 0;
410 uint8_t retTransferOpFlag = 0;
411 uint8_t retTableType = 0;
412
413 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
414 struct pldm_get_bios_table_req* request =
415 reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload);
416
417 request->transfer_handle = transferHandle;
418 request->transfer_op_flag = transferOpFlag;
419 request->table_type = tableType;
420
421 auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size,
422 &retTransferHandle, &retTransferOpFlag,
423 &retTableType);
424
George Liu684a7162019-12-06 15:10:52 +0800425 EXPECT_EQ(rc, PLDM_SUCCESS);
426 EXPECT_EQ(transferHandle, retTransferHandle);
427 EXPECT_EQ(transferOpFlag, retTransferOpFlag);
428 EXPECT_EQ(tableType, retTableType);
Sampa Misrab37be312019-07-03 02:26:41 -0500429}
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500430TEST(GetBIOSTable, testBadDecodeRequest)
431{
432 const auto hdr_size = sizeof(pldm_msg_hdr);
433 std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{};
434 uint32_t transferHandle = 31;
435 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
436 uint8_t tableType = PLDM_BIOS_ATTR_TABLE;
437 uint32_t retTransferHandle = 0;
438 uint8_t retTransferOpFlag = 0;
439 uint8_t retTableType = 0;
Sampa Misrab37be312019-07-03 02:26:41 -0500440
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500441 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
442 struct pldm_get_bios_table_req* request =
443 reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload);
444
445 request->transfer_handle = transferHandle;
446 request->transfer_op_flag = transferOpFlag;
447 request->table_type = tableType;
448
449 auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size,
450 &retTransferHandle, &retTransferOpFlag,
451 &retTableType);
452
George Liu684a7162019-12-06 15:10:52 +0800453 EXPECT_EQ(rc, PLDM_SUCCESS);
454 EXPECT_EQ(transferHandle, retTransferHandle);
455 EXPECT_EQ(transferOpFlag, retTransferOpFlag);
456 EXPECT_EQ(tableType, retTableType);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500457}
458/*
Sampa Misrab37be312019-07-03 02:26:41 -0500459TEST(GetBIOSTable, testBadDecodeRequest)
460{
461 const auto hdr_size = sizeof(pldm_msg_hdr);
462 std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{};
463 uint32_t transferHandle = 31;
464 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
465 uint8_t tableType = PLDM_BIOS_ATTR_TABLE;
466 uint32_t retTransferHandle = 0;
467 uint8_t retTransferOpFlag = 0;
468 uint8_t retTableType = 0;
469
470 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
471 struct pldm_get_bios_table_req* request =
472 reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload);
473
474 request->transfer_handle = transferHandle;
475 request->transfer_op_flag = transferOpFlag;
476 request->table_type = tableType;
477
478 auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size - 3,
479 &retTransferHandle, &retTransferOpFlag,
480 &retTableType);
481
George Liu684a7162019-12-06 15:10:52 +0800482 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500483}*/
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500484
485TEST(GetBIOSAttributeCurrentValueByHandle, testGoodDecodeRequest)
486{
487 uint32_t transferHandle = 45;
488 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
489 uint16_t attributehandle = 10;
490 uint32_t retTransferHandle = 0;
491 uint8_t retTransferOpFlag = 0;
492 uint16_t retattributehandle = 0;
493 std::array<uint8_t, hdrSize + sizeof(transferHandle) +
494 sizeof(transferOpFlag) + sizeof(attributehandle)>
495 requestMsg{};
496
497 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
498 struct pldm_get_bios_attribute_current_value_by_handle_req* request =
499 reinterpret_cast<
500 struct pldm_get_bios_attribute_current_value_by_handle_req*>(
501 req->payload);
502
503 request->transfer_handle = transferHandle;
504 request->transfer_op_flag = transferOpFlag;
505 request->attribute_handle = attributehandle;
506
507 auto rc = decode_get_bios_attribute_current_value_by_handle_req(
508 req, requestMsg.size() - hdrSize, &retTransferHandle,
509 &retTransferOpFlag, &retattributehandle);
510
George Liu684a7162019-12-06 15:10:52 +0800511 EXPECT_EQ(rc, PLDM_SUCCESS);
512 EXPECT_EQ(transferHandle, retTransferHandle);
513 EXPECT_EQ(transferOpFlag, retTransferOpFlag);
514 EXPECT_EQ(attributehandle, retattributehandle);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500515}
516
517TEST(GetBIOSAttributeCurrentValueByHandle, testBadDecodeRequest)
518{
519
520 uint32_t transferHandle = 0;
521 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
522 uint16_t attribute_handle = 0;
523 uint32_t retTransferHandle = 0;
524 uint8_t retTransferOpFlag = 0;
525 uint16_t retattribute_handle = 0;
526 std::array<uint8_t, hdrSize + sizeof(transferHandle) +
527 sizeof(transferOpFlag) + sizeof(attribute_handle)>
528 requestMsg{};
529
530 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
531 struct pldm_get_bios_attribute_current_value_by_handle_req* request =
532 reinterpret_cast<
533 struct pldm_get_bios_attribute_current_value_by_handle_req*>(
534 req->payload);
535
536 request->transfer_handle = transferHandle;
537 request->transfer_op_flag = transferOpFlag;
538 request->attribute_handle = attribute_handle;
539
540 auto rc = decode_get_bios_attribute_current_value_by_handle_req(
541 NULL, requestMsg.size() - hdrSize, &retTransferHandle,
542 &retTransferOpFlag, &retattribute_handle);
George Liu684a7162019-12-06 15:10:52 +0800543 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500544
545 transferHandle = 31;
546 request->transfer_handle = transferHandle;
547
548 rc = decode_get_bios_attribute_current_value_by_handle_req(
549 req, 0, &retTransferHandle, &retTransferOpFlag, &retattribute_handle);
550
George Liu684a7162019-12-06 15:10:52 +0800551 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500552}
553
554TEST(GetBIOSAttributeCurrentValueByHandle, testGoodEncodeResponse)
555{
556
557 uint8_t instanceId = 10;
558 uint8_t completionCode = PLDM_SUCCESS;
559 uint32_t nextTransferHandle = 32;
560 uint8_t transferFlag = PLDM_START_AND_END;
561 uint8_t attributeData = 44;
562 std::array<uint8_t,
563 hdrSize +
564 sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)>
565 responseMsg{};
566 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
567
568 auto rc = encode_get_bios_current_value_by_handle_resp(
569 instanceId, completionCode, nextTransferHandle, transferFlag,
570 &attributeData, sizeof(attributeData), response);
571
George Liu684a7162019-12-06 15:10:52 +0800572 EXPECT_EQ(rc, PLDM_SUCCESS);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500573
574 struct pldm_get_bios_attribute_current_value_by_handle_resp* resp =
575 reinterpret_cast<
576 struct pldm_get_bios_attribute_current_value_by_handle_resp*>(
577 response->payload);
578
George Liu684a7162019-12-06 15:10:52 +0800579 EXPECT_EQ(completionCode, resp->completion_code);
580 EXPECT_EQ(nextTransferHandle, resp->next_transfer_handle);
581 EXPECT_EQ(transferFlag, resp->transfer_flag);
582 EXPECT_EQ(
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500583 0, memcmp(&attributeData, resp->attribute_data, sizeof(attributeData)));
584}
585
586TEST(GetBIOSAttributeCurrentValueByHandle, testBadEncodeResponse)
587{
588 uint32_t nextTransferHandle = 32;
589 uint8_t transferFlag = PLDM_START_AND_END;
590 uint8_t attributeData = 44;
591
592 auto rc = encode_get_bios_current_value_by_handle_resp(
593 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, &attributeData,
594 sizeof(attributeData), nullptr);
George Liu684a7162019-12-06 15:10:52 +0800595 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500596
597 std::array<uint8_t,
598 hdrSize +
599 sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)>
600 responseMsg{};
601 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
602 rc = encode_get_bios_current_value_by_handle_resp(
603 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, nullptr,
604 sizeof(attributeData), response);
George Liu684a7162019-12-06 15:10:52 +0800605 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500606}
John Wang4d844792019-08-15 15:51:40 +0800607
608TEST(SetBiosAttributeCurrentValue, testGoodEncodeRequest)
609{
610 uint8_t instanceId = 10;
611 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800612 uint8_t transferFlag = PLDM_START_AND_END;
613 uint32_t attributeData = 44;
John Wang4d844792019-08-15 15:51:40 +0800614 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES +
615 sizeof(attributeData)>
616 requestMsg{};
617 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
618 auto rc = encode_set_bios_attribute_current_value_req(
619 instanceId, transferHandle, transferFlag,
620 reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData),
621 request, requestMsg.size() - hdrSize);
622
George Liu684a7162019-12-06 15:10:52 +0800623 EXPECT_EQ(rc, PLDM_SUCCESS);
John Wang4d844792019-08-15 15:51:40 +0800624
625 struct pldm_set_bios_attribute_current_value_req* req =
626 reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>(
627 request->payload);
George Liu684a7162019-12-06 15:10:52 +0800628 EXPECT_EQ(htole32(transferHandle), req->transfer_handle);
629 EXPECT_EQ(transferFlag, req->transfer_flag);
630 EXPECT_EQ(
John Wang4d844792019-08-15 15:51:40 +0800631 0, memcmp(&attributeData, req->attribute_data, sizeof(attributeData)));
632}
633
634TEST(SetBiosAttributeCurrentValue, testBadEncodeRequest)
635{
636 uint8_t instanceId = 10;
637 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800638 uint8_t transferFlag = PLDM_START_AND_END;
639 uint32_t attributeData = 44;
John Wang4d844792019-08-15 15:51:40 +0800640 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES>
641 requestMsg{};
642 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
643
644 auto rc = encode_set_bios_attribute_current_value_req(
645 instanceId, transferHandle, transferFlag, nullptr, 0, nullptr, 0);
George Liu684a7162019-12-06 15:10:52 +0800646 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Wang4d844792019-08-15 15:51:40 +0800647 rc = encode_set_bios_attribute_current_value_req(
648 instanceId, transferHandle, transferFlag,
649 reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData),
650 request, requestMsg.size() - hdrSize);
651
George Liu684a7162019-12-06 15:10:52 +0800652 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
John Wang4d844792019-08-15 15:51:40 +0800653}
654
655TEST(SetBiosAttributeCurrentValue, testGoodDecodeRequest)
656{
657 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800658 uint8_t transferFlag = PLDM_START_AND_END;
659 uint32_t attributeData = 44;
John Wang4d844792019-08-15 15:51:40 +0800660
661 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES +
662 sizeof(attributeData)>
663 requestMsg{};
664 auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data());
665 struct pldm_set_bios_attribute_current_value_req* req =
666 reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>(
667 request->payload);
668 req->transfer_handle = htole32(transferHandle);
669 req->transfer_flag = transferFlag;
670 memcpy(req->attribute_data, &attributeData, sizeof(attributeData));
671
672 uint32_t retTransferHandle;
673 uint8_t retTransferFlag;
John Wang08c05952019-12-20 15:40:39 +0800674 struct variable_field attribute;
John Wang4d844792019-08-15 15:51:40 +0800675 auto rc = decode_set_bios_attribute_current_value_req(
676 request, requestMsg.size() - hdrSize, &retTransferHandle,
John Wang08c05952019-12-20 15:40:39 +0800677 &retTransferFlag, &attribute);
John Wang4d844792019-08-15 15:51:40 +0800678
George Liu684a7162019-12-06 15:10:52 +0800679 EXPECT_EQ(rc, PLDM_SUCCESS);
680 EXPECT_EQ(retTransferHandle, transferHandle);
681 EXPECT_EQ(retTransferFlag, transferFlag);
John Wang08c05952019-12-20 15:40:39 +0800682 EXPECT_EQ(attribute.length, sizeof(attributeData));
683 EXPECT_EQ(0, memcmp(attribute.ptr, &attributeData, sizeof(attributeData)));
John Wang4d844792019-08-15 15:51:40 +0800684}
685
686TEST(SetBiosAttributeCurrentValue, testBadDecodeRequest)
687{
688 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800689 uint8_t transferFlag = PLDM_START_AND_END;
John Wang08c05952019-12-20 15:40:39 +0800690 struct variable_field attribute;
John Wang4d844792019-08-15 15:51:40 +0800691 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES - 1>
692 requestMsg{};
693 auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data());
694
695 auto rc = decode_set_bios_attribute_current_value_req(
John Wang08c05952019-12-20 15:40:39 +0800696 nullptr, 0, &transferHandle, &transferFlag, &attribute);
George Liu684a7162019-12-06 15:10:52 +0800697 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Wang4d844792019-08-15 15:51:40 +0800698 rc = decode_set_bios_attribute_current_value_req(
699 request, requestMsg.size() - hdrSize, &transferHandle, &transferFlag,
John Wang08c05952019-12-20 15:40:39 +0800700 &attribute);
George Liu684a7162019-12-06 15:10:52 +0800701 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
John Wang4d844792019-08-15 15:51:40 +0800702}
703
704TEST(SetBiosAttributeCurrentValue, testGoodEncodeResponse)
705{
706 uint8_t instanceId = 10;
707 uint32_t nextTransferHandle = 32;
708 uint8_t completionCode = PLDM_SUCCESS;
709
710 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES>
711 responseMsg{};
712 struct pldm_msg* response =
713 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
714 auto rc = encode_set_bios_attribute_current_value_resp(
715 instanceId, completionCode, nextTransferHandle, response);
George Liu684a7162019-12-06 15:10:52 +0800716 EXPECT_EQ(rc, PLDM_SUCCESS);
John Wang4d844792019-08-15 15:51:40 +0800717
718 struct pldm_set_bios_attribute_current_value_resp* resp =
719 reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>(
720 response->payload);
George Liu684a7162019-12-06 15:10:52 +0800721 EXPECT_EQ(completionCode, resp->completion_code);
722 EXPECT_EQ(htole32(nextTransferHandle), resp->next_transfer_handle);
John Wang4d844792019-08-15 15:51:40 +0800723}
724
725TEST(SetBiosAttributeCurrentValue, testBadEncodeResponse)
726{
727 uint8_t instanceId = 10;
728 uint32_t nextTransferHandle = 32;
729 uint8_t completionCode = PLDM_SUCCESS;
730 auto rc = encode_set_bios_attribute_current_value_resp(
731 instanceId, completionCode, nextTransferHandle, nullptr);
732
George Liu684a7162019-12-06 15:10:52 +0800733 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Wang4d844792019-08-15 15:51:40 +0800734}
735TEST(SetBiosAttributeCurrentValue, testGoodDecodeResponse)
736{
737 uint32_t nextTransferHandle = 32;
738 uint8_t completionCode = PLDM_SUCCESS;
739 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES>
740 responseMsg{};
741 struct pldm_msg* response =
742 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
743 struct pldm_set_bios_attribute_current_value_resp* resp =
744 reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>(
745 response->payload);
746
747 resp->completion_code = completionCode;
748 resp->next_transfer_handle = htole32(nextTransferHandle);
749
750 uint8_t retCompletionCode;
751 uint32_t retNextTransferHandle;
752 auto rc = decode_set_bios_attribute_current_value_resp(
753 response, responseMsg.size() - hdrSize, &retCompletionCode,
754 &retNextTransferHandle);
755
George Liu684a7162019-12-06 15:10:52 +0800756 EXPECT_EQ(rc, PLDM_SUCCESS);
757 EXPECT_EQ(completionCode, retCompletionCode);
758 EXPECT_EQ(nextTransferHandle, retNextTransferHandle);
John Wang4d844792019-08-15 15:51:40 +0800759}
760
761TEST(SetBiosAttributeCurrentValue, testBadDecodeResponse)
762{
763 uint32_t nextTransferHandle = 32;
764 uint8_t completionCode = PLDM_SUCCESS;
765
George Liu684a7162019-12-06 15:10:52 +0800766 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES>
John Wang4d844792019-08-15 15:51:40 +0800767 responseMsg{};
768 struct pldm_msg* response =
769 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
George Liu684a7162019-12-06 15:10:52 +0800770 struct pldm_set_bios_attribute_current_value_resp* resp =
771 reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>(
772 response->payload);
773
774 resp->completion_code = completionCode;
775 resp->next_transfer_handle = htole32(nextTransferHandle);
776
John Wang4d844792019-08-15 15:51:40 +0800777 auto rc = decode_set_bios_attribute_current_value_resp(
778 nullptr, 0, &completionCode, &nextTransferHandle);
George Liu684a7162019-12-06 15:10:52 +0800779 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Wang4d844792019-08-15 15:51:40 +0800780
781 rc = decode_set_bios_attribute_current_value_resp(
George Liu684a7162019-12-06 15:10:52 +0800782 response, responseMsg.size() - hdrSize - 1, &completionCode,
John Wang4d844792019-08-15 15:51:40 +0800783 &nextTransferHandle);
784
George Liu684a7162019-12-06 15:10:52 +0800785 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
John Wang81796c22019-09-06 11:18:57 +0800786}
Sridevi Ramesh08efc7b2019-12-05 05:39:46 -0600787
788TEST(GetBIOSTable, testDecodeResponse)
789{
790 uint32_t nextTransferHandle = 32;
791 uint8_t completionCode = PLDM_SUCCESS;
792 uint8_t transfer_flag = PLDM_START_AND_END;
793
794 std::array<uint8_t, hdrSize + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES>
795 responseMsg{};
796 struct pldm_msg* response =
797 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
798
799 struct pldm_get_bios_table_resp* resp =
800 reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload);
801
802 resp->completion_code = completionCode;
803 resp->next_transfer_handle = htole32(nextTransferHandle);
804 resp->transfer_flag = transfer_flag;
805 size_t biosTableOffset = sizeof(completionCode) +
806 sizeof(nextTransferHandle) + sizeof(transfer_flag);
807
808 uint8_t retCompletionCode;
809 uint32_t retNextTransferHandle;
810 uint8_t retransfer_flag;
811 size_t rebiosTableOffset = 0;
812 auto rc = decode_get_bios_table_resp(
813 response, responseMsg.size(), &retCompletionCode,
814 &retNextTransferHandle, &retransfer_flag, &rebiosTableOffset);
815
816 ASSERT_EQ(rc, PLDM_SUCCESS);
817 ASSERT_EQ(completionCode, retCompletionCode);
818 ASSERT_EQ(nextTransferHandle, retNextTransferHandle);
819 ASSERT_EQ(transfer_flag, retransfer_flag);
820 ASSERT_EQ(biosTableOffset, rebiosTableOffset);
821}