blob: 46a75ed6aadfd5b57369e06ae9b6a39c267ca3fa [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"
7
8#include <gtest/gtest.h>
9
Zahed Hossain223a73d2019-07-04 12:46:18 -050010constexpr auto hdrSize = sizeof(pldm_msg_hdr);
11
Sampa Misra032bd502019-03-06 05:03:22 -060012TEST(GetDateTime, testEncodeRequest)
13{
14 pldm_msg request{};
Sampa Misra032bd502019-03-06 05:03:22 -060015
16 auto rc = encode_get_date_time_req(0, &request);
17 ASSERT_EQ(rc, PLDM_SUCCESS);
18}
19
20TEST(GetDateTime, testEncodeResponse)
21{
22 uint8_t completionCode = 0;
23 uint8_t seconds = 50;
24 uint8_t minutes = 20;
25 uint8_t hours = 5;
26 uint8_t day = 23;
27 uint8_t month = 11;
28 uint16_t year = 2019;
29
vkaverapa6575b82019-04-03 05:33:52 -050030 std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_DATE_TIME_RESP_BYTES>
31 responseMsg{};
Sampa Misra032bd502019-03-06 05:03:22 -060032
vkaverapa6575b82019-04-03 05:33:52 -050033 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
Sampa Misra032bd502019-03-06 05:03:22 -060034
35 auto rc = encode_get_date_time_resp(0, PLDM_SUCCESS, seconds, minutes,
vkaverapa6575b82019-04-03 05:33:52 -050036 hours, day, month, year, response);
Sampa Misra032bd502019-03-06 05:03:22 -060037
38 ASSERT_EQ(rc, PLDM_SUCCESS);
vkaverapa6575b82019-04-03 05:33:52 -050039 ASSERT_EQ(completionCode, response->payload[0]);
Sampa Misra032bd502019-03-06 05:03:22 -060040
vkaverapa6575b82019-04-03 05:33:52 -050041 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]),
42 &seconds, sizeof(seconds)));
43 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
44 sizeof(seconds),
Sampa Misra032bd502019-03-06 05:03:22 -060045 &minutes, sizeof(minutes)));
vkaverapa6575b82019-04-03 05:33:52 -050046 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
47 sizeof(seconds) + sizeof(minutes),
48 &hours, sizeof(hours)));
49 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
50 sizeof(seconds) + sizeof(minutes) + sizeof(hours),
51 &day, sizeof(day)));
52 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
53 sizeof(seconds) + sizeof(minutes) + sizeof(hours) +
54 sizeof(day),
Sampa Misra032bd502019-03-06 05:03:22 -060055 &month, sizeof(month)));
vkaverapa6575b82019-04-03 05:33:52 -050056 ASSERT_EQ(0, memcmp(response->payload + sizeof(response->payload[0]) +
57 sizeof(seconds) + sizeof(minutes) + sizeof(hours) +
58 sizeof(day) + sizeof(month),
59 &year, sizeof(year)));
Sampa Misra032bd502019-03-06 05:03:22 -060060}
61
62TEST(GetDateTime, testDecodeResponse)
63{
Zahed Hossain223a73d2019-07-04 12:46:18 -050064 std::array<uint8_t, hdrSize + PLDM_GET_DATE_TIME_RESP_BYTES> responseMsg{};
Sampa Misra032bd502019-03-06 05:03:22 -060065
66 uint8_t completionCode = 0;
67
68 uint8_t seconds = 55;
69 uint8_t minutes = 2;
70 uint8_t hours = 8;
71 uint8_t day = 9;
72 uint8_t month = 7;
73 uint16_t year = 2020;
74
75 uint8_t retSeconds = 0;
76 uint8_t retMinutes = 0;
77 uint8_t retHours = 0;
78 uint8_t retDay = 0;
79 uint8_t retMonth = 0;
80 uint16_t retYear = 0;
81
Zahed Hossain223a73d2019-07-04 12:46:18 -050082 memcpy(responseMsg.data() + sizeof(completionCode) + hdrSize, &seconds,
Sampa Misra032bd502019-03-06 05:03:22 -060083 sizeof(seconds));
Zahed Hossain223a73d2019-07-04 12:46:18 -050084 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
85 hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060086 &minutes, sizeof(minutes));
vkaverapa6575b82019-04-03 05:33:52 -050087 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050088 sizeof(minutes) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060089 &hours, sizeof(hours));
vkaverapa6575b82019-04-03 05:33:52 -050090 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050091 sizeof(minutes) + sizeof(hours) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060092 &day, sizeof(day));
vkaverapa6575b82019-04-03 05:33:52 -050093 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050094 sizeof(minutes) + sizeof(hours) + sizeof(day) + hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060095 &month, sizeof(month));
vkaverapa6575b82019-04-03 05:33:52 -050096 memcpy(responseMsg.data() + sizeof(completionCode) + sizeof(seconds) +
Zahed Hossain223a73d2019-07-04 12:46:18 -050097 sizeof(minutes) + sizeof(hours) + sizeof(day) + sizeof(month) +
98 hdrSize,
Sampa Misra032bd502019-03-06 05:03:22 -060099 &year, sizeof(year));
100
Zahed Hossain223a73d2019-07-04 12:46:18 -0500101 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
102
vkaverapa6575b82019-04-03 05:33:52 -0500103 auto rc = decode_get_date_time_resp(
Zahed Hossain223a73d2019-07-04 12:46:18 -0500104 response, responseMsg.size() - hdrSize, &completionCode, &retSeconds,
vkaverapa6575b82019-04-03 05:33:52 -0500105 &retMinutes, &retHours, &retDay, &retMonth, &retYear);
Sampa Misra032bd502019-03-06 05:03:22 -0600106
107 ASSERT_EQ(rc, PLDM_SUCCESS);
108 ASSERT_EQ(seconds, retSeconds);
109 ASSERT_EQ(minutes, retMinutes);
110 ASSERT_EQ(hours, retHours);
111 ASSERT_EQ(day, retDay);
112 ASSERT_EQ(month, retMonth);
113 ASSERT_EQ(year, retYear);
114}
Sampa Misrab37be312019-07-03 02:26:41 -0500115
116TEST(GetBIOSTable, testGoodEncodeResponse)
117{
118 std::array<uint8_t,
119 sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4>
120 responseMsg{};
121 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
122
123 uint8_t completionCode = PLDM_SUCCESS;
124 uint32_t nextTransferHandle = 32;
125 uint8_t transferFlag = PLDM_START_AND_END;
126 std::array<uint8_t, 4> tableData{1, 2, 3, 4};
127
128 auto rc = encode_get_bios_table_resp(
129 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, tableData.data(),
130 sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4,
131 response);
132 ASSERT_EQ(rc, PLDM_SUCCESS);
133
134 struct pldm_get_bios_table_resp* resp =
135 reinterpret_cast<struct pldm_get_bios_table_resp*>(response->payload);
136
137 ASSERT_EQ(completionCode, resp->completion_code);
138 ASSERT_EQ(nextTransferHandle, resp->next_transfer_handle);
139 ASSERT_EQ(transferFlag, resp->transfer_flag);
140 ASSERT_EQ(0, memcmp(tableData.data(), resp->table_data, tableData.size()));
141}
142
143TEST(GetBIOSTable, testBadEncodeResponse)
144{
145 uint32_t nextTransferHandle = 32;
146 uint8_t transferFlag = PLDM_START_AND_END;
147 std::array<uint8_t, 4> tableData{1, 2, 3, 4};
148
149 auto rc = encode_get_bios_table_resp(
150 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, tableData.data(),
151 sizeof(pldm_msg_hdr) + PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + 4, nullptr);
152 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
153}
154
155TEST(GetBIOSTable, testGoodDecodeRequest)
156{
157 const auto hdr_size = sizeof(pldm_msg_hdr);
158 std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{};
159 uint32_t transferHandle = 31;
160 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
161 uint8_t tableType = PLDM_BIOS_ATTR_TABLE;
162 uint32_t retTransferHandle = 0;
163 uint8_t retTransferOpFlag = 0;
164 uint8_t retTableType = 0;
165
166 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
167 struct pldm_get_bios_table_req* request =
168 reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload);
169
170 request->transfer_handle = transferHandle;
171 request->transfer_op_flag = transferOpFlag;
172 request->table_type = tableType;
173
174 auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size,
175 &retTransferHandle, &retTransferOpFlag,
176 &retTableType);
177
178 ASSERT_EQ(rc, PLDM_SUCCESS);
179 ASSERT_EQ(transferHandle, retTransferHandle);
180 ASSERT_EQ(transferOpFlag, retTransferOpFlag);
181 ASSERT_EQ(tableType, retTableType);
182}
183
184TEST(GetBIOSTable, testBadDecodeRequest)
185{
186 const auto hdr_size = sizeof(pldm_msg_hdr);
187 std::array<uint8_t, hdr_size + PLDM_GET_BIOS_TABLE_REQ_BYTES> requestMsg{};
188 uint32_t transferHandle = 31;
189 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
190 uint8_t tableType = PLDM_BIOS_ATTR_TABLE;
191 uint32_t retTransferHandle = 0;
192 uint8_t retTransferOpFlag = 0;
193 uint8_t retTableType = 0;
194
195 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
196 struct pldm_get_bios_table_req* request =
197 reinterpret_cast<struct pldm_get_bios_table_req*>(req->payload);
198
199 request->transfer_handle = transferHandle;
200 request->transfer_op_flag = transferOpFlag;
201 request->table_type = tableType;
202
203 auto rc = decode_get_bios_table_req(req, requestMsg.size() - hdr_size - 3,
204 &retTransferHandle, &retTransferOpFlag,
205 &retTableType);
206
207 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
208}
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500209
210TEST(GetBIOSAttributeCurrentValueByHandle, testGoodDecodeRequest)
211{
212 uint32_t transferHandle = 45;
213 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
214 uint16_t attributehandle = 10;
215 uint32_t retTransferHandle = 0;
216 uint8_t retTransferOpFlag = 0;
217 uint16_t retattributehandle = 0;
218 std::array<uint8_t, hdrSize + sizeof(transferHandle) +
219 sizeof(transferOpFlag) + sizeof(attributehandle)>
220 requestMsg{};
221
222 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
223 struct pldm_get_bios_attribute_current_value_by_handle_req* request =
224 reinterpret_cast<
225 struct pldm_get_bios_attribute_current_value_by_handle_req*>(
226 req->payload);
227
228 request->transfer_handle = transferHandle;
229 request->transfer_op_flag = transferOpFlag;
230 request->attribute_handle = attributehandle;
231
232 auto rc = decode_get_bios_attribute_current_value_by_handle_req(
233 req, requestMsg.size() - hdrSize, &retTransferHandle,
234 &retTransferOpFlag, &retattributehandle);
235
236 ASSERT_EQ(rc, PLDM_SUCCESS);
237 ASSERT_EQ(transferHandle, retTransferHandle);
238 ASSERT_EQ(transferOpFlag, retTransferOpFlag);
239 ASSERT_EQ(attributehandle, retattributehandle);
240}
241
242TEST(GetBIOSAttributeCurrentValueByHandle, testBadDecodeRequest)
243{
244
245 uint32_t transferHandle = 0;
246 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
247 uint16_t attribute_handle = 0;
248 uint32_t retTransferHandle = 0;
249 uint8_t retTransferOpFlag = 0;
250 uint16_t retattribute_handle = 0;
251 std::array<uint8_t, hdrSize + sizeof(transferHandle) +
252 sizeof(transferOpFlag) + sizeof(attribute_handle)>
253 requestMsg{};
254
255 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
256 struct pldm_get_bios_attribute_current_value_by_handle_req* request =
257 reinterpret_cast<
258 struct pldm_get_bios_attribute_current_value_by_handle_req*>(
259 req->payload);
260
261 request->transfer_handle = transferHandle;
262 request->transfer_op_flag = transferOpFlag;
263 request->attribute_handle = attribute_handle;
264
265 auto rc = decode_get_bios_attribute_current_value_by_handle_req(
266 NULL, requestMsg.size() - hdrSize, &retTransferHandle,
267 &retTransferOpFlag, &retattribute_handle);
268 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
269
270 transferHandle = 31;
271 request->transfer_handle = transferHandle;
272
273 rc = decode_get_bios_attribute_current_value_by_handle_req(
274 req, 0, &retTransferHandle, &retTransferOpFlag, &retattribute_handle);
275
276 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
277}
278
279TEST(GetBIOSAttributeCurrentValueByHandle, testGoodEncodeResponse)
280{
281
282 uint8_t instanceId = 10;
283 uint8_t completionCode = PLDM_SUCCESS;
284 uint32_t nextTransferHandle = 32;
285 uint8_t transferFlag = PLDM_START_AND_END;
286 uint8_t attributeData = 44;
287 std::array<uint8_t,
288 hdrSize +
289 sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)>
290 responseMsg{};
291 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
292
293 auto rc = encode_get_bios_current_value_by_handle_resp(
294 instanceId, completionCode, nextTransferHandle, transferFlag,
295 &attributeData, sizeof(attributeData), response);
296
297 ASSERT_EQ(rc, PLDM_SUCCESS);
298
299 struct pldm_get_bios_attribute_current_value_by_handle_resp* resp =
300 reinterpret_cast<
301 struct pldm_get_bios_attribute_current_value_by_handle_resp*>(
302 response->payload);
303
304 ASSERT_EQ(completionCode, resp->completion_code);
305 ASSERT_EQ(nextTransferHandle, resp->next_transfer_handle);
306 ASSERT_EQ(transferFlag, resp->transfer_flag);
307 ASSERT_EQ(
308 0, memcmp(&attributeData, resp->attribute_data, sizeof(attributeData)));
309}
310
311TEST(GetBIOSAttributeCurrentValueByHandle, testBadEncodeResponse)
312{
313 uint32_t nextTransferHandle = 32;
314 uint8_t transferFlag = PLDM_START_AND_END;
315 uint8_t attributeData = 44;
316
317 auto rc = encode_get_bios_current_value_by_handle_resp(
318 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, &attributeData,
319 sizeof(attributeData), nullptr);
320 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
321
322 std::array<uint8_t,
323 hdrSize +
324 sizeof(pldm_get_bios_attribute_current_value_by_handle_resp)>
325 responseMsg{};
326 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
327 rc = encode_get_bios_current_value_by_handle_resp(
328 0, PLDM_SUCCESS, nextTransferHandle, transferFlag, nullptr,
329 sizeof(attributeData), response);
330 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
331}
John Wang4d844792019-08-15 15:51:40 +0800332
333TEST(SetBiosAttributeCurrentValue, testGoodEncodeRequest)
334{
335 uint8_t instanceId = 10;
336 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800337 uint8_t transferFlag = PLDM_START_AND_END;
338 uint32_t attributeData = 44;
John Wang4d844792019-08-15 15:51:40 +0800339 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES +
340 sizeof(attributeData)>
341 requestMsg{};
342 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
343 auto rc = encode_set_bios_attribute_current_value_req(
344 instanceId, transferHandle, transferFlag,
345 reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData),
346 request, requestMsg.size() - hdrSize);
347
348 ASSERT_EQ(rc, PLDM_SUCCESS);
349
350 struct pldm_set_bios_attribute_current_value_req* req =
351 reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>(
352 request->payload);
353 ASSERT_EQ(htole32(transferHandle), req->transfer_handle);
354 ASSERT_EQ(transferFlag, req->transfer_flag);
355 ASSERT_EQ(
356 0, memcmp(&attributeData, req->attribute_data, sizeof(attributeData)));
357}
358
359TEST(SetBiosAttributeCurrentValue, testBadEncodeRequest)
360{
361 uint8_t instanceId = 10;
362 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800363 uint8_t transferFlag = PLDM_START_AND_END;
364 uint32_t attributeData = 44;
John Wang4d844792019-08-15 15:51:40 +0800365 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES>
366 requestMsg{};
367 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
368
369 auto rc = encode_set_bios_attribute_current_value_req(
370 instanceId, transferHandle, transferFlag, nullptr, 0, nullptr, 0);
371 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
372 rc = encode_set_bios_attribute_current_value_req(
373 instanceId, transferHandle, transferFlag,
374 reinterpret_cast<uint8_t*>(&attributeData), sizeof(attributeData),
375 request, requestMsg.size() - hdrSize);
376
377 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
378}
379
380TEST(SetBiosAttributeCurrentValue, testGoodDecodeRequest)
381{
382 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800383 uint8_t transferFlag = PLDM_START_AND_END;
384 uint32_t attributeData = 44;
John Wang4d844792019-08-15 15:51:40 +0800385
386 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES +
387 sizeof(attributeData)>
388 requestMsg{};
389 auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data());
390 struct pldm_set_bios_attribute_current_value_req* req =
391 reinterpret_cast<struct pldm_set_bios_attribute_current_value_req*>(
392 request->payload);
393 req->transfer_handle = htole32(transferHandle);
394 req->transfer_flag = transferFlag;
395 memcpy(req->attribute_data, &attributeData, sizeof(attributeData));
396
397 uint32_t retTransferHandle;
398 uint8_t retTransferFlag;
399 uint32_t retAttributeData;
400 size_t retAttributeDataLength;
401 auto rc = decode_set_bios_attribute_current_value_req(
402 request, requestMsg.size() - hdrSize, &retTransferHandle,
403 &retTransferFlag, reinterpret_cast<uint8_t*>(&retAttributeData),
404 &retAttributeDataLength);
405
406 ASSERT_EQ(rc, PLDM_SUCCESS);
407 ASSERT_EQ(retTransferHandle, transferHandle);
408 ASSERT_EQ(retTransferFlag, transferFlag);
409 ASSERT_EQ(retAttributeDataLength, sizeof(attributeData));
410 ASSERT_EQ(0,
411 memcmp(&retAttributeData, &attributeData, sizeof(attributeData)));
412}
413
414TEST(SetBiosAttributeCurrentValue, testBadDecodeRequest)
415{
416 uint32_t transferHandle = 32;
John Wang81796c22019-09-06 11:18:57 +0800417 uint8_t transferFlag = PLDM_START_AND_END;
418 uint32_t attributeData = 44;
419 size_t attributeDataLength = sizeof(attributeData);
John Wang4d844792019-08-15 15:51:40 +0800420 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES - 1>
421 requestMsg{};
422 auto request = reinterpret_cast<struct pldm_msg*>(requestMsg.data());
423
424 auto rc = decode_set_bios_attribute_current_value_req(
425 nullptr, 0, &transferHandle, &transferFlag,
426 reinterpret_cast<uint8_t*>(&attributeData), &attributeDataLength);
427 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
428 rc = decode_set_bios_attribute_current_value_req(
429 request, requestMsg.size() - hdrSize, &transferHandle, &transferFlag,
430 reinterpret_cast<uint8_t*>(&attributeData), &attributeDataLength);
431 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
432}
433
434TEST(SetBiosAttributeCurrentValue, testGoodEncodeResponse)
435{
436 uint8_t instanceId = 10;
437 uint32_t nextTransferHandle = 32;
438 uint8_t completionCode = PLDM_SUCCESS;
439
440 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES>
441 responseMsg{};
442 struct pldm_msg* response =
443 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
444 auto rc = encode_set_bios_attribute_current_value_resp(
445 instanceId, completionCode, nextTransferHandle, response);
446 ASSERT_EQ(rc, PLDM_SUCCESS);
447
448 struct pldm_set_bios_attribute_current_value_resp* resp =
449 reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>(
450 response->payload);
451 ASSERT_EQ(completionCode, resp->completion_code);
452 ASSERT_EQ(htole32(nextTransferHandle), resp->next_transfer_handle);
453}
454
455TEST(SetBiosAttributeCurrentValue, testBadEncodeResponse)
456{
457 uint8_t instanceId = 10;
458 uint32_t nextTransferHandle = 32;
459 uint8_t completionCode = PLDM_SUCCESS;
460 auto rc = encode_set_bios_attribute_current_value_resp(
461 instanceId, completionCode, nextTransferHandle, nullptr);
462
463 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
464}
465TEST(SetBiosAttributeCurrentValue, testGoodDecodeResponse)
466{
467 uint32_t nextTransferHandle = 32;
468 uint8_t completionCode = PLDM_SUCCESS;
469 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES>
470 responseMsg{};
471 struct pldm_msg* response =
472 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
473 struct pldm_set_bios_attribute_current_value_resp* resp =
474 reinterpret_cast<struct pldm_set_bios_attribute_current_value_resp*>(
475 response->payload);
476
477 resp->completion_code = completionCode;
478 resp->next_transfer_handle = htole32(nextTransferHandle);
479
480 uint8_t retCompletionCode;
481 uint32_t retNextTransferHandle;
482 auto rc = decode_set_bios_attribute_current_value_resp(
483 response, responseMsg.size() - hdrSize, &retCompletionCode,
484 &retNextTransferHandle);
485
486 ASSERT_EQ(rc, PLDM_SUCCESS);
487 ASSERT_EQ(completionCode, retCompletionCode);
488 ASSERT_EQ(nextTransferHandle, retNextTransferHandle);
489}
490
491TEST(SetBiosAttributeCurrentValue, testBadDecodeResponse)
492{
493 uint32_t nextTransferHandle = 32;
494 uint8_t completionCode = PLDM_SUCCESS;
495
496 std::array<uint8_t, hdrSize + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES - 1>
497 responseMsg{};
498 struct pldm_msg* response =
499 reinterpret_cast<struct pldm_msg*>(responseMsg.data());
500 auto rc = decode_set_bios_attribute_current_value_resp(
501 nullptr, 0, &completionCode, &nextTransferHandle);
502 ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA);
503
504 rc = decode_set_bios_attribute_current_value_resp(
505 response, responseMsg.size() - hdrSize, &completionCode,
506 &nextTransferHandle);
507
508 ASSERT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
John Wang81796c22019-09-06 11:18:57 +0800509}