blob: 2b43b769f75cec2b677d4a9ba248030be41398e9 [file] [log] [blame]
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05301#include <endian.h>
Andrew Jefferyb0c1d202023-11-07 22:08:44 +10302#include <libpldm/base.h>
3#include <libpldm/entity.h>
4#include <libpldm/platform.h>
5#include <libpldm/pldm_types.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +09306
7#include <array>
Tal Yacobif490a382024-05-31 09:57:36 +03008#include <cerrno>
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05309#include <cstdint>
Andrew Jeffery5a706072023-04-05 19:45:31 +093010#include <cstring>
Manojkiran Eda9a8e4972022-11-28 16:38:21 +053011#include <vector>
Andrew Jeffery9c766792022-08-10 23:12:49 +093012
Thu Nguyen159a98b2022-11-02 10:00:10 +070013#include "msgbuf.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +093014
15#include <gtest/gtest.h>
16
17constexpr auto hdrSize = sizeof(pldm_msg_hdr);
18
19TEST(SetStateEffecterStates, testEncodeResponse)
20{
21 std::array<uint8_t,
22 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
23 responseMsg{};
24 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
25 uint8_t completionCode = 0;
26
27 auto rc = encode_set_state_effecter_states_resp(0, PLDM_SUCCESS, response);
28
29 EXPECT_EQ(rc, PLDM_SUCCESS);
30 EXPECT_EQ(completionCode, response->payload[0]);
31}
32
33TEST(SetStateEffecterStates, testEncodeRequest)
34{
35 std::array<uint8_t,
36 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES>
37 requestMsg{};
38 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
39
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -060040 uint16_t effecterId = 0x0a;
Andrew Jeffery9c766792022-08-10 23:12:49 +093041 uint8_t compEffecterCnt = 0x2;
42 std::array<set_effecter_state_field, 8> stateField{};
43 stateField[0] = {PLDM_REQUEST_SET, 2};
44 stateField[1] = {PLDM_REQUEST_SET, 3};
45
46 auto rc = encode_set_state_effecter_states_req(
47 0, effecterId, compEffecterCnt, stateField.data(), request);
48
49 EXPECT_EQ(rc, PLDM_SUCCESS);
50 EXPECT_EQ(effecterId, request->payload[0]);
51 EXPECT_EQ(compEffecterCnt, request->payload[sizeof(effecterId)]);
52 EXPECT_EQ(stateField[0].set_request,
53 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt)]);
54 EXPECT_EQ(stateField[0].effecter_state,
55 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
56 sizeof(stateField[0].set_request)]);
57 EXPECT_EQ(stateField[1].set_request,
58 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
59 sizeof(stateField[0])]);
60 EXPECT_EQ(stateField[1].effecter_state,
61 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
62 sizeof(stateField[0]) +
63 sizeof(stateField[1].set_request)]);
64}
65
66TEST(SetStateEffecterStates, testGoodDecodeResponse)
67{
68 std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
69 responseMsg{};
70
71 uint8_t retcompletion_code = 0;
72
73 responseMsg[hdrSize] = PLDM_SUCCESS;
74
75 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
76
77 auto rc = decode_set_state_effecter_states_resp(
78 response, responseMsg.size() - hdrSize, &retcompletion_code);
79
80 EXPECT_EQ(rc, PLDM_SUCCESS);
81 EXPECT_EQ(PLDM_SUCCESS, retcompletion_code);
82}
83
84TEST(SetStateEffecterStates, testGoodDecodeRequest)
85{
86 std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES>
87 requestMsg{};
88
89 uint16_t effecterId = 0x32;
90 uint16_t effecterIdLE = htole16(effecterId);
91 uint8_t compEffecterCnt = 0x2;
92
93 std::array<set_effecter_state_field, 8> stateField{};
94 stateField[0] = {PLDM_REQUEST_SET, 3};
95 stateField[1] = {PLDM_REQUEST_SET, 4};
96
97 uint16_t retEffecterId = 0;
98 uint8_t retCompEffecterCnt = 0;
99
100 std::array<set_effecter_state_field, 8> retStateField{};
101
102 memcpy(requestMsg.data() + hdrSize, &effecterIdLE, sizeof(effecterIdLE));
103 memcpy(requestMsg.data() + sizeof(effecterIdLE) + hdrSize, &compEffecterCnt,
104 sizeof(compEffecterCnt));
105 memcpy(requestMsg.data() + sizeof(effecterIdLE) + sizeof(compEffecterCnt) +
106 hdrSize,
107 &stateField, sizeof(stateField));
108
109 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
110
111 auto rc = decode_set_state_effecter_states_req(
112 request, requestMsg.size() - hdrSize, &retEffecterId,
113 &retCompEffecterCnt, retStateField.data());
114
115 EXPECT_EQ(rc, PLDM_SUCCESS);
116 EXPECT_EQ(effecterId, retEffecterId);
117 EXPECT_EQ(retCompEffecterCnt, compEffecterCnt);
118 EXPECT_EQ(retStateField[0].set_request, stateField[0].set_request);
119 EXPECT_EQ(retStateField[0].effecter_state, stateField[0].effecter_state);
120 EXPECT_EQ(retStateField[1].set_request, stateField[1].set_request);
121 EXPECT_EQ(retStateField[1].effecter_state, stateField[1].effecter_state);
122}
123
124TEST(SetStateEffecterStates, testBadDecodeRequest)
125{
126 const struct pldm_msg* msg = NULL;
127
128 auto rc = decode_set_state_effecter_states_req(msg, sizeof(*msg), NULL,
129 NULL, NULL);
130
131 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
132}
133
134TEST(SetStateEffecterStates, testBadDecodeResponse)
135{
136 std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
137 responseMsg{};
138
139 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
140
141 auto rc = decode_set_state_effecter_states_resp(response,
142 responseMsg.size(), NULL);
143
144 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
145}
146
147TEST(GetPDR, testGoodEncodeResponse)
148{
149 uint8_t completionCode = 0;
150 uint32_t nextRecordHndl = 0x12;
151 uint32_t nextDataTransferHndl = 0x13;
152 uint8_t transferFlag = PLDM_END;
153 uint16_t respCnt = 0x5;
154 std::vector<uint8_t> recordData{1, 2, 3, 4, 5};
155 uint8_t transferCRC = 6;
156
157 // + size of record data and transfer CRC
158 std::vector<uint8_t> responseMsg(hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES +
159 recordData.size() + 1);
160 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
161
162 auto rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl,
163 nextDataTransferHndl, transferFlag, respCnt,
164 recordData.data(), transferCRC, response);
165
166 EXPECT_EQ(rc, PLDM_SUCCESS);
167 struct pldm_get_pdr_resp* resp =
168 reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload);
169
170 EXPECT_EQ(completionCode, resp->completion_code);
171 EXPECT_EQ(nextRecordHndl, le32toh(resp->next_record_handle));
172 EXPECT_EQ(nextDataTransferHndl, le32toh(resp->next_data_transfer_handle));
173 EXPECT_EQ(transferFlag, resp->transfer_flag);
174 EXPECT_EQ(respCnt, le16toh(resp->response_count));
175 EXPECT_EQ(0,
176 memcmp(recordData.data(), resp->record_data, recordData.size()));
177 EXPECT_EQ(*(response->payload + sizeof(pldm_get_pdr_resp) - 1 +
178 recordData.size()),
179 transferCRC);
180
181 transferFlag = PLDM_START_AND_END; // No CRC in this case
182 responseMsg.resize(responseMsg.size() - sizeof(transferCRC));
183 rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl,
184 nextDataTransferHndl, transferFlag, respCnt,
185 recordData.data(), transferCRC, response);
186 EXPECT_EQ(rc, PLDM_SUCCESS);
187}
188
189TEST(GetPDR, testBadEncodeResponse)
190{
191 uint32_t nextRecordHndl = 0x12;
192 uint32_t nextDataTransferHndl = 0x13;
193 uint8_t transferFlag = PLDM_START_AND_END;
194 uint16_t respCnt = 0x5;
195 std::vector<uint8_t> recordData{1, 2, 3, 4, 5};
196 uint8_t transferCRC = 0;
197
198 auto rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl,
199 nextDataTransferHndl, transferFlag, respCnt,
200 recordData.data(), transferCRC, nullptr);
201
202 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
203}
204
205TEST(GetPDR, testGoodDecodeRequest)
206{
207 std::array<uint8_t, hdrSize + PLDM_GET_PDR_REQ_BYTES> requestMsg{};
208
209 uint32_t recordHndl = 0x32;
210 uint32_t dataTransferHndl = 0x11;
211 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
212 uint16_t requestCnt = 0x5;
213 uint16_t recordChangeNum = 0x01;
214
215 uint32_t retRecordHndl = 0;
216 uint32_t retDataTransferHndl = 0;
217 uint8_t retTransferOpFlag = 0;
218 uint16_t retRequestCnt = 0;
219 uint16_t retRecordChangeNum = 0;
220
221 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
222 struct pldm_get_pdr_req* request =
223 reinterpret_cast<struct pldm_get_pdr_req*>(req->payload);
224
225 request->record_handle = htole32(recordHndl);
226 request->data_transfer_handle = htole32(dataTransferHndl);
227 request->transfer_op_flag = transferOpFlag;
228 request->request_count = htole16(requestCnt);
229 request->record_change_number = htole16(recordChangeNum);
230
231 auto rc = decode_get_pdr_req(
232 req, requestMsg.size() - hdrSize, &retRecordHndl, &retDataTransferHndl,
233 &retTransferOpFlag, &retRequestCnt, &retRecordChangeNum);
234
235 EXPECT_EQ(rc, PLDM_SUCCESS);
236 EXPECT_EQ(retRecordHndl, recordHndl);
237 EXPECT_EQ(retDataTransferHndl, dataTransferHndl);
238 EXPECT_EQ(retTransferOpFlag, transferOpFlag);
239 EXPECT_EQ(retRequestCnt, requestCnt);
240 EXPECT_EQ(retRecordChangeNum, recordChangeNum);
241}
242
243TEST(GetPDR, testBadDecodeRequest)
244{
245 std::array<uint8_t, PLDM_GET_PDR_REQ_BYTES> requestMsg{};
246 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
247
248 auto rc = decode_get_pdr_req(req, requestMsg.size(), NULL, NULL, NULL, NULL,
249 NULL);
250
251 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
252}
253
254TEST(GetPDR, testGoodEncodeRequest)
255{
256 uint32_t record_hndl = 0;
257 uint32_t data_transfer_hndl = 0;
258 uint8_t transfer_op_flag = PLDM_GET_FIRSTPART;
259 uint16_t request_cnt = 20;
260 uint16_t record_chg_num = 0;
261
262 std::vector<uint8_t> requestMsg(hdrSize + PLDM_GET_PDR_REQ_BYTES);
263 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
264
265 auto rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl,
266 transfer_op_flag, request_cnt, record_chg_num,
267 request, PLDM_GET_PDR_REQ_BYTES);
268 EXPECT_EQ(rc, PLDM_SUCCESS);
269 struct pldm_get_pdr_req* req =
270 reinterpret_cast<struct pldm_get_pdr_req*>(request->payload);
271 EXPECT_EQ(record_hndl, le32toh(req->record_handle));
272 EXPECT_EQ(data_transfer_hndl, le32toh(req->data_transfer_handle));
273 EXPECT_EQ(transfer_op_flag, req->transfer_op_flag);
274 EXPECT_EQ(request_cnt, le16toh(req->request_count));
275 EXPECT_EQ(record_chg_num, le16toh(req->record_change_number));
276}
277
278TEST(GetPDR, testBadEncodeRequest)
279{
280 uint32_t record_hndl = 0;
281 uint32_t data_transfer_hndl = 0;
282 uint8_t transfer_op_flag = PLDM_GET_FIRSTPART;
283 uint16_t request_cnt = 32;
284 uint16_t record_chg_num = 0;
285
286 std::vector<uint8_t> requestMsg(hdrSize + PLDM_GET_PDR_REQ_BYTES);
287 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
288
289 auto rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl,
290 transfer_op_flag, request_cnt, record_chg_num,
291 nullptr, PLDM_GET_PDR_REQ_BYTES);
292 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
293
294 rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl,
295 transfer_op_flag, request_cnt, record_chg_num,
296 request, PLDM_GET_PDR_REQ_BYTES + 1);
297 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
298}
299
300TEST(GetPDR, testGoodDecodeResponse)
301{
302 const char* recordData = "123456789";
303 uint8_t completionCode = PLDM_SUCCESS;
304 uint32_t nextRecordHndl = 0;
305 uint32_t nextDataTransferHndl = 0;
306 uint8_t transferFlag = PLDM_END;
307 constexpr uint16_t respCnt = 9;
308 uint8_t transferCRC = 96;
309 size_t recordDataLength = 32;
310 std::array<uint8_t, hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES + respCnt +
311 sizeof(transferCRC)>
312 responseMsg{};
313
314 uint8_t retCompletionCode = 0;
315 uint8_t retRecordData[32] = {0};
316 uint32_t retNextRecordHndl = 0;
317 uint32_t retNextDataTransferHndl = 0;
318 uint8_t retTransferFlag = 0;
319 uint16_t retRespCnt = 0;
320 uint8_t retTransferCRC = 0;
321
322 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
323 struct pldm_get_pdr_resp* resp =
324 reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload);
325 resp->completion_code = completionCode;
326 resp->next_record_handle = htole32(nextRecordHndl);
327 resp->next_data_transfer_handle = htole32(nextDataTransferHndl);
328 resp->transfer_flag = transferFlag;
329 resp->response_count = htole16(respCnt);
330 memcpy(resp->record_data, recordData, respCnt);
331 response->payload[PLDM_GET_PDR_MIN_RESP_BYTES + respCnt] = transferCRC;
332
333 auto rc = decode_get_pdr_resp(
334 response, responseMsg.size() - hdrSize, &retCompletionCode,
335 &retNextRecordHndl, &retNextDataTransferHndl, &retTransferFlag,
336 &retRespCnt, retRecordData, recordDataLength, &retTransferCRC);
337 EXPECT_EQ(rc, PLDM_SUCCESS);
338 EXPECT_EQ(retCompletionCode, completionCode);
339 EXPECT_EQ(retNextRecordHndl, nextRecordHndl);
340 EXPECT_EQ(retNextDataTransferHndl, nextDataTransferHndl);
341 EXPECT_EQ(retTransferFlag, transferFlag);
342 EXPECT_EQ(retRespCnt, respCnt);
343 EXPECT_EQ(retTransferCRC, transferCRC);
344 EXPECT_EQ(0, memcmp(recordData, resp->record_data, respCnt));
345}
346
347TEST(GetPDR, testBadDecodeResponse)
348{
349 const char* recordData = "123456789";
350 uint8_t completionCode = PLDM_SUCCESS;
351 uint32_t nextRecordHndl = 0;
352 uint32_t nextDataTransferHndl = 0;
353 uint8_t transferFlag = PLDM_END;
354 constexpr uint16_t respCnt = 9;
355 uint8_t transferCRC = 96;
Andrew Jeffery4e5e8a22023-04-04 11:58:45 +0930356 size_t recordDataLength = respCnt - 1;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930357 std::array<uint8_t, hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES + respCnt +
358 sizeof(transferCRC)>
359 responseMsg{};
360
361 uint8_t retCompletionCode = 0;
362 uint8_t retRecordData[32] = {0};
363 uint32_t retNextRecordHndl = 0;
364 uint32_t retNextDataTransferHndl = 0;
365 uint8_t retTransferFlag = 0;
366 uint16_t retRespCnt = 0;
367 uint8_t retTransferCRC = 0;
368
369 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
370 struct pldm_get_pdr_resp* resp =
371 reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload);
372 resp->completion_code = completionCode;
373 resp->next_record_handle = htole32(nextRecordHndl);
374 resp->next_data_transfer_handle = htole32(nextDataTransferHndl);
375 resp->transfer_flag = transferFlag;
376 resp->response_count = htole16(respCnt);
377 memcpy(resp->record_data, recordData, respCnt);
378 response->payload[PLDM_GET_PDR_MIN_RESP_BYTES + respCnt] = transferCRC;
379
380 auto rc = decode_get_pdr_resp(response, responseMsg.size() - hdrSize, NULL,
381 NULL, NULL, NULL, NULL, NULL, 0, NULL);
382 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
383
384 rc = decode_get_pdr_resp(
385 response, responseMsg.size() - hdrSize - 1, &retCompletionCode,
386 &retNextRecordHndl, &retNextDataTransferHndl, &retTransferFlag,
387 &retRespCnt, retRecordData, recordDataLength, &retTransferCRC);
388 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
389}
390
391TEST(GetPDRRepositoryInfo, testGoodEncodeResponse)
392{
393 uint8_t completionCode = 0;
394 uint8_t repositoryState = PLDM_AVAILABLE;
395 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
396 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
397 uint32_t recordCount = 100;
398 uint32_t repositorySize = 100;
399 uint32_t largestRecordSize = UINT32_MAX;
400 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
401
402 std::vector<uint8_t> responseMsg(hdrSize +
403 PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES);
404 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
405
406 auto rc = encode_get_pdr_repository_info_resp(
407 0, PLDM_SUCCESS, repositoryState, updateTime, oemUpdateTime,
408 recordCount, repositorySize, largestRecordSize,
409 dataTransferHandleTimeout, response);
410
411 EXPECT_EQ(rc, PLDM_SUCCESS);
412 struct pldm_pdr_repository_info_resp* resp =
413 reinterpret_cast<struct pldm_pdr_repository_info_resp*>(
414 response->payload);
415
416 EXPECT_EQ(completionCode, resp->completion_code);
417 EXPECT_EQ(repositoryState, resp->repository_state);
418 EXPECT_EQ(0, memcmp(updateTime, resp->update_time, PLDM_TIMESTAMP104_SIZE));
419 EXPECT_EQ(0, memcmp(oemUpdateTime, resp->oem_update_time,
420 PLDM_TIMESTAMP104_SIZE));
421 EXPECT_EQ(recordCount, le32toh(resp->record_count));
422 EXPECT_EQ(repositorySize, le32toh(resp->repository_size));
423 EXPECT_EQ(largestRecordSize, le32toh(resp->largest_record_size));
424 EXPECT_EQ(dataTransferHandleTimeout, resp->data_transfer_handle_timeout);
425}
426
427TEST(GetPDRRepositoryInfo, testBadEncodeResponse)
428{
429 uint8_t repositoryState = PLDM_AVAILABLE;
430 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
431 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
432 uint32_t recordCount = 100;
433 uint32_t repositorySize = 100;
434 uint32_t largestRecordSize = UINT32_MAX;
435 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
436
437 auto rc = encode_get_pdr_repository_info_resp(
438 0, PLDM_SUCCESS, repositoryState, updateTime, oemUpdateTime,
439 recordCount, repositorySize, largestRecordSize,
440 dataTransferHandleTimeout, nullptr);
441 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
442}
443
Gilbert Chenb7c73e52022-11-10 11:29:52 +0800444TEST(GetPDRRepositoryInfo, testGoodDecodeResponse)
445{
446 uint8_t completionCode = PLDM_SUCCESS;
447 uint8_t repositoryState = PLDM_AVAILABLE;
448 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
449 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
450 uint32_t recordCount = 100;
451 uint32_t repositorySize = 100;
452 uint32_t largestRecordSize = UINT32_MAX;
453 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
454
455 std::array<uint8_t, hdrSize + PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES>
456 responseMsg{};
457 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
458 struct pldm_pdr_repository_info_resp* resp =
459 reinterpret_cast<struct pldm_pdr_repository_info_resp*>(
460 response->payload);
461 resp->completion_code = completionCode;
462 resp->repository_state = repositoryState;
463 memcpy(resp->update_time, updateTime, PLDM_TIMESTAMP104_SIZE);
464 memcpy(resp->oem_update_time, oemUpdateTime, PLDM_TIMESTAMP104_SIZE);
465 resp->record_count = htole32(recordCount);
466 resp->repository_size = htole32(repositorySize);
467 resp->largest_record_size = htole32(largestRecordSize);
468 resp->data_transfer_handle_timeout = dataTransferHandleTimeout;
469
470 uint8_t retCompletionCode = 0;
471 uint8_t retRepositoryState = 0;
472 uint8_t retUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
473 uint8_t retOemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
474 uint32_t retRecordCount = 0;
475 uint32_t retRepositorySize = 0;
476 uint32_t retLargestRecordSize = 0;
477 uint8_t retDataTransferHandleTimeout = 0;
478
479 auto rc = decode_get_pdr_repository_info_resp(
480 response, responseMsg.size() - hdrSize, &retCompletionCode,
481 &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount,
482 &retRepositorySize, &retLargestRecordSize,
483 &retDataTransferHandleTimeout);
484
485 EXPECT_EQ(rc, PLDM_SUCCESS);
486 EXPECT_EQ(completionCode, retCompletionCode);
487 EXPECT_EQ(repositoryState, retRepositoryState);
488 EXPECT_EQ(0, memcmp(updateTime, retUpdateTime, PLDM_TIMESTAMP104_SIZE));
489 EXPECT_EQ(0,
490 memcmp(oemUpdateTime, retOemUpdateTime, PLDM_TIMESTAMP104_SIZE));
491 EXPECT_EQ(recordCount, recordCount);
492 EXPECT_EQ(repositorySize, repositorySize);
493 EXPECT_EQ(largestRecordSize, largestRecordSize);
494 EXPECT_EQ(dataTransferHandleTimeout, dataTransferHandleTimeout);
495}
496
497TEST(GetPDRRepositoryInfo, testBadDecodeResponse)
498{
499 uint8_t completionCode = PLDM_SUCCESS;
500 uint8_t repositoryState = PLDM_AVAILABLE;
501 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
502 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
503 uint32_t recordCount = htole32(100);
504 uint32_t repositorySize = htole32(100);
505 uint32_t largestRecordSize = htole32(UINT32_MAX);
506 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
507
508 std::array<uint8_t, hdrSize + PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES>
509 responseMsg{};
510 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
511 struct pldm_pdr_repository_info_resp* resp =
512 reinterpret_cast<struct pldm_pdr_repository_info_resp*>(
513 response->payload);
514 resp->completion_code = completionCode;
515 resp->repository_state = repositoryState;
516 memcpy(resp->update_time, updateTime, PLDM_TIMESTAMP104_SIZE);
517 memcpy(resp->oem_update_time, oemUpdateTime, PLDM_TIMESTAMP104_SIZE);
518 resp->record_count = recordCount;
519 resp->repository_size = repositorySize;
520 resp->largest_record_size = largestRecordSize;
521 resp->data_transfer_handle_timeout = dataTransferHandleTimeout;
522
523 uint8_t retCompletionCode = 0;
524 uint8_t retRepositoryState = 0;
525 uint8_t retUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
526 uint8_t retOemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
527 uint32_t retRecordCount = 0;
528 uint32_t retRepositorySize = 0;
529 uint32_t retLargestRecordSize = 0;
530 uint8_t retDataTransferHandleTimeout = 0;
531
532 auto rc = decode_get_pdr_repository_info_resp(
533 response, responseMsg.size() - hdrSize, NULL, NULL, NULL, NULL, NULL,
534 NULL, NULL, NULL);
535 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
536
537 rc = decode_get_pdr_repository_info_resp(
538 response, responseMsg.size() - hdrSize - 1, &retCompletionCode,
539 &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount,
540 &retRepositorySize, &retLargestRecordSize,
541 &retDataTransferHandleTimeout);
542 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
543
544 resp->repository_state = PLDM_FAILED + 1;
545 rc = decode_get_pdr_repository_info_resp(
546 response, responseMsg.size() - hdrSize, &retCompletionCode,
547 &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount,
548 &retRepositorySize, &retLargestRecordSize,
549 &retDataTransferHandleTimeout);
550 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
551}
552
Andrew Jeffery9c766792022-08-10 23:12:49 +0930553TEST(SetNumericEffecterValue, testGoodDecodeRequest)
554{
555 std::array<uint8_t,
556 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3>
557 requestMsg{};
558
559 uint16_t effecter_id = 32768;
560 uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT32;
561 uint32_t effecter_value = 123456789;
562
563 uint16_t reteffecter_id;
564 uint8_t reteffecter_data_size;
565 uint8_t reteffecter_value[4];
566
567 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
568 struct pldm_set_numeric_effecter_value_req* request =
569 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
570 req->payload);
571
572 request->effecter_id = htole16(effecter_id);
573 request->effecter_data_size = effecter_data_size;
574 uint32_t effecter_value_le = htole32(effecter_value);
575 memcpy(request->effecter_value, &effecter_value_le,
576 sizeof(effecter_value_le));
577
578 auto rc = decode_set_numeric_effecter_value_req(
579 req, requestMsg.size() - hdrSize, &reteffecter_id,
580 &reteffecter_data_size, reteffecter_value);
581
582 uint32_t value = *(reinterpret_cast<uint32_t*>(reteffecter_value));
583 EXPECT_EQ(rc, PLDM_SUCCESS);
584 EXPECT_EQ(reteffecter_id, effecter_id);
585 EXPECT_EQ(reteffecter_data_size, effecter_data_size);
586 EXPECT_EQ(value, effecter_value);
587}
588
589TEST(SetNumericEffecterValue, testBadDecodeRequest)
590{
591 std::array<uint8_t, hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES>
592 requestMsg{};
593
594 auto rc = decode_set_numeric_effecter_value_req(
595 NULL, requestMsg.size() - hdrSize, NULL, NULL, NULL);
596 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
597
598 uint16_t effecter_id = 0x10;
599 uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT8;
600 uint8_t effecter_value = 1;
601
602 uint16_t reteffecter_id;
603 uint8_t reteffecter_data_size;
604 uint8_t reteffecter_value[4];
605
606 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
607 struct pldm_set_numeric_effecter_value_req* request =
608 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
609 req->payload);
610
611 request->effecter_id = effecter_id;
612 request->effecter_data_size = effecter_data_size;
613 memcpy(request->effecter_value, &effecter_value, sizeof(effecter_value));
614
615 rc = decode_set_numeric_effecter_value_req(
616 req, requestMsg.size() - hdrSize - 1, &reteffecter_id,
617 &reteffecter_data_size, reinterpret_cast<uint8_t*>(&reteffecter_value));
618 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
619}
620
621TEST(SetNumericEffecterValue, testGoodEncodeRequest)
622{
623 uint16_t effecter_id = 0;
624 uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT16;
625 uint16_t effecter_value = 65534;
626
627 std::vector<uint8_t> requestMsg(
628 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1);
629 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
630
631 auto rc = encode_set_numeric_effecter_value_req(
632 0, effecter_id, effecter_data_size,
633 reinterpret_cast<uint8_t*>(&effecter_value), request,
634 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1);
635 EXPECT_EQ(rc, PLDM_SUCCESS);
636
637 struct pldm_set_numeric_effecter_value_req* req =
638 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
639 request->payload);
640 EXPECT_EQ(effecter_id, req->effecter_id);
641 EXPECT_EQ(effecter_data_size, req->effecter_data_size);
642 uint16_t* val = (uint16_t*)req->effecter_value;
643 *val = le16toh(*val);
644 EXPECT_EQ(effecter_value, *val);
645}
646
647TEST(SetNumericEffecterValue, testBadEncodeRequest)
648{
649 std::vector<uint8_t> requestMsg(
650 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
651 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
652
653 auto rc = encode_set_numeric_effecter_value_req(
654 0, 0, 0, NULL, NULL, PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
655 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
656
657 uint16_t effecter_value;
658 rc = encode_set_numeric_effecter_value_req(
659 0, 0, 6, reinterpret_cast<uint8_t*>(&effecter_value), request,
660 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
661 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
662}
663
664TEST(SetNumericEffecterValue, testGoodDecodeResponse)
665{
666 std::array<uint8_t, hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES>
667 responseMsg{};
668
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -0600669 uint8_t completion_code = 0xa0;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930670
671 uint8_t retcompletion_code;
672
673 memcpy(responseMsg.data() + hdrSize, &completion_code,
674 sizeof(completion_code));
675
676 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
677
678 auto rc = decode_set_numeric_effecter_value_resp(
679 response, responseMsg.size() - hdrSize, &retcompletion_code);
680
681 EXPECT_EQ(rc, PLDM_SUCCESS);
682 EXPECT_EQ(completion_code, retcompletion_code);
683}
684
685TEST(SetNumericEffecterValue, testBadDecodeResponse)
686{
687 std::array<uint8_t, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES>
688 responseMsg{};
689
690 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
691
692 auto rc = decode_set_numeric_effecter_value_resp(response,
693 responseMsg.size(), NULL);
694
695 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
696}
697
698TEST(SetNumericEffecterValue, testGoodEncodeResponse)
699{
700 std::array<uint8_t, sizeof(pldm_msg_hdr) +
701 PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES>
702 responseMsg{};
703 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
704 uint8_t completionCode = 0;
705
706 auto rc = encode_set_numeric_effecter_value_resp(
707 0, PLDM_SUCCESS, response, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES);
708
709 EXPECT_EQ(rc, PLDM_SUCCESS);
710 EXPECT_EQ(completionCode, response->payload[0]);
711}
712
713TEST(SetNumericEffecterValue, testBadEncodeResponse)
714{
715 auto rc = encode_set_numeric_effecter_value_resp(
716 0, PLDM_SUCCESS, NULL, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES);
717 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
718}
719
720TEST(GetStateSensorReadings, testGoodEncodeResponse)
721{
722 std::array<uint8_t, hdrSize +
723 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
724 sizeof(get_sensor_state_field) * 2>
725 responseMsg{};
726
727 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
728 uint8_t completionCode = 0;
729 uint8_t comp_sensorCnt = 0x2;
730
731 std::array<get_sensor_state_field, 2> stateField{};
732 stateField[0] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_NORMAL,
733 PLDM_SENSOR_WARNING, PLDM_SENSOR_UNKNOWN};
734 stateField[1] = {PLDM_SENSOR_FAILED, PLDM_SENSOR_UPPERFATAL,
735 PLDM_SENSOR_UPPERCRITICAL, PLDM_SENSOR_FATAL};
736
737 auto rc = encode_get_state_sensor_readings_resp(
738 0, PLDM_SUCCESS, comp_sensorCnt, stateField.data(), response);
739
740 struct pldm_get_state_sensor_readings_resp* resp =
741 reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>(
742 response->payload);
743
744 EXPECT_EQ(rc, PLDM_SUCCESS);
745 EXPECT_EQ(completionCode, resp->completion_code);
746 EXPECT_EQ(comp_sensorCnt, resp->comp_sensor_count);
747 EXPECT_EQ(stateField[0].sensor_op_state, resp->field->sensor_op_state);
748 EXPECT_EQ(stateField[0].present_state, resp->field->present_state);
749 EXPECT_EQ(stateField[0].previous_state, resp->field->previous_state);
750 EXPECT_EQ(stateField[0].event_state, resp->field->event_state);
751 EXPECT_EQ(stateField[1].sensor_op_state, resp->field[1].sensor_op_state);
752 EXPECT_EQ(stateField[1].present_state, resp->field[1].present_state);
753 EXPECT_EQ(stateField[1].previous_state, resp->field[1].previous_state);
754 EXPECT_EQ(stateField[1].event_state, resp->field[1].event_state);
755}
756
757TEST(GetStateSensorReadings, testBadEncodeResponse)
758{
759 auto rc = encode_get_state_sensor_readings_resp(0, PLDM_SUCCESS, 0, nullptr,
760 nullptr);
761
762 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
763}
764
765TEST(GetStateSensorReadings, testGoodDecodeResponse)
766{
767 std::array<uint8_t, hdrSize +
768 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
769 sizeof(get_sensor_state_field) * 2>
770 responseMsg{};
771
772 uint8_t completionCode = 0;
773 uint8_t comp_sensorCnt = 2;
774
775 std::array<get_sensor_state_field, 2> stateField{};
776 stateField[0] = {PLDM_SENSOR_DISABLED, PLDM_SENSOR_UNKNOWN,
777 PLDM_SENSOR_UNKNOWN, PLDM_SENSOR_UNKNOWN};
778 stateField[1] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_LOWERFATAL,
779 PLDM_SENSOR_LOWERCRITICAL, PLDM_SENSOR_WARNING};
780
781 uint8_t retcompletion_code = 0;
782 uint8_t retcomp_sensorCnt = 0;
783 std::array<get_sensor_state_field, 2> retstateField{};
784
785 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
786 struct pldm_get_state_sensor_readings_resp* resp =
787 reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>(
788 response->payload);
789
790 resp->completion_code = completionCode;
791 resp->comp_sensor_count = comp_sensorCnt;
792 memcpy(resp->field, &stateField,
793 (sizeof(get_sensor_state_field) * comp_sensorCnt));
794
795 auto rc = decode_get_state_sensor_readings_resp(
796 response, responseMsg.size() - hdrSize, &retcompletion_code,
797 &retcomp_sensorCnt, retstateField.data());
798
799 EXPECT_EQ(rc, PLDM_SUCCESS);
800 EXPECT_EQ(completionCode, retcompletion_code);
801 EXPECT_EQ(comp_sensorCnt, retcomp_sensorCnt);
802 EXPECT_EQ(stateField[0].sensor_op_state, retstateField[0].sensor_op_state);
803 EXPECT_EQ(stateField[0].present_state, retstateField[0].present_state);
804 EXPECT_EQ(stateField[0].previous_state, retstateField[0].previous_state);
805 EXPECT_EQ(stateField[0].event_state, retstateField[0].event_state);
806 EXPECT_EQ(stateField[1].sensor_op_state, retstateField[1].sensor_op_state);
807 EXPECT_EQ(stateField[1].present_state, retstateField[1].present_state);
808 EXPECT_EQ(stateField[1].previous_state, retstateField[1].previous_state);
809 EXPECT_EQ(stateField[1].event_state, retstateField[1].event_state);
810}
811
812TEST(GetStateSensorReadings, testBadDecodeResponse)
813{
814 std::array<uint8_t, hdrSize +
815 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
816 sizeof(get_sensor_state_field) * 2>
817 responseMsg{};
818
819 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
820
821 auto rc = decode_get_state_sensor_readings_resp(
822 response, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr);
823
824 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
825
826 uint8_t completionCode = 0;
827 uint8_t comp_sensorCnt = 1;
828
829 std::array<get_sensor_state_field, 1> stateField{};
830 stateField[0] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_UPPERFATAL,
831 PLDM_SENSOR_UPPERCRITICAL, PLDM_SENSOR_WARNING};
832
833 uint8_t retcompletion_code = 0;
834 uint8_t retcomp_sensorCnt = 0;
835 std::array<get_sensor_state_field, 1> retstateField{};
836
837 struct pldm_get_state_sensor_readings_resp* resp =
838 reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>(
839 response->payload);
840
841 resp->completion_code = completionCode;
842 resp->comp_sensor_count = comp_sensorCnt;
843 memcpy(resp->field, &stateField,
844 (sizeof(get_sensor_state_field) * comp_sensorCnt));
845
846 rc = decode_get_state_sensor_readings_resp(
Andrew Jeffery6ad4dc02023-04-12 15:56:45 +0930847 response, responseMsg.size() - hdrSize, &retcompletion_code,
Andrew Jeffery9c766792022-08-10 23:12:49 +0930848 &retcomp_sensorCnt, retstateField.data());
849
850 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
851}
852
853TEST(GetStateSensorReadings, testGoodEncodeRequest)
854{
855 std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES>
856 requestMsg{};
857
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -0600858 uint16_t sensorId = 0xab;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930859 bitfield8_t sensorRearm;
860 sensorRearm.byte = 0x03;
861
862 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
863 auto rc = encode_get_state_sensor_readings_req(0, sensorId, sensorRearm, 0,
864 request);
865
866 struct pldm_get_state_sensor_readings_req* req =
867 reinterpret_cast<struct pldm_get_state_sensor_readings_req*>(
868 request->payload);
869
870 EXPECT_EQ(rc, PLDM_SUCCESS);
871 EXPECT_EQ(sensorId, le16toh(req->sensor_id));
872 EXPECT_EQ(sensorRearm.byte, req->sensor_rearm.byte);
873}
874
875TEST(GetStateSensorReadings, testBadEncodeRequest)
876{
877 bitfield8_t sensorRearm;
878 sensorRearm.byte = 0x0;
879
880 auto rc =
881 encode_get_state_sensor_readings_req(0, 0, sensorRearm, 0, nullptr);
882
883 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
884}
885
886TEST(GetStateSensorReadings, testGoodDecodeRequest)
887{
888 std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES>
889 requestMsg{};
890
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -0600891 uint16_t sensorId = 0xcd;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930892 bitfield8_t sensorRearm;
893 sensorRearm.byte = 0x10;
894
895 uint16_t retsensorId;
896 bitfield8_t retsensorRearm;
897 uint8_t retreserved;
898
899 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
900
901 struct pldm_get_state_sensor_readings_req* req =
902 reinterpret_cast<struct pldm_get_state_sensor_readings_req*>(
903 request->payload);
904
905 req->sensor_id = htole16(sensorId);
906 req->sensor_rearm.byte = sensorRearm.byte;
907
908 auto rc = decode_get_state_sensor_readings_req(
909 request, requestMsg.size() - hdrSize, &retsensorId, &retsensorRearm,
910 &retreserved);
911
912 EXPECT_EQ(rc, PLDM_SUCCESS);
913 EXPECT_EQ(sensorId, retsensorId);
914 EXPECT_EQ(sensorRearm.byte, retsensorRearm.byte);
915 EXPECT_EQ(0, retreserved);
916}
917
918TEST(GetStateSensorReadings, testBadDecodeRequest)
919{
920 std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES>
921 requestMsg{};
922
923 auto rc = decode_get_state_sensor_readings_req(
924 nullptr, requestMsg.size() - hdrSize, nullptr, nullptr, nullptr);
925
926 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
927 uint16_t sensorId = 0x11;
928 bitfield8_t sensorRearm;
929 sensorRearm.byte = 0x04;
930
931 uint16_t retsensorId;
932 bitfield8_t retsensorRearm;
933 uint8_t retreserved;
934
935 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
936
937 struct pldm_get_state_sensor_readings_req* req =
938 reinterpret_cast<struct pldm_get_state_sensor_readings_req*>(
939 request->payload);
940
941 req->sensor_id = htole16(sensorId);
942 req->sensor_rearm.byte = sensorRearm.byte;
943
944 rc = decode_get_state_sensor_readings_req(
945 request, requestMsg.size() - hdrSize - 1, &retsensorId, &retsensorRearm,
946 &retreserved);
947
948 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
949}
950
Dung Caod6ae8982022-11-02 10:00:10 +0700951TEST(EventMessageBufferSize, testGoodEventMessageBufferSizeRequest)
952{
953 uint8_t eventBufferSize = 32;
954
955 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_REQ_BYTES>
956 requestMsg{};
957 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
958
959 auto rc = encode_event_message_buffer_size_req(0, eventBufferSize, request);
960
961 EXPECT_EQ(rc, PLDM_SUCCESS);
962}
963
964TEST(EventMessageBufferSize, testGoodEventMessageBufferSizeResponse)
965{
966 uint8_t completionCode = PLDM_SUCCESS;
967 uint16_t terminusMaxBufferSize = 256;
968
969 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES>
970 responseMsg{};
971
972 uint8_t retCompletionCode;
973 uint16_t retMaxBufferSize = 0;
974
975 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
976 struct pldm_event_message_buffer_size_resp* resp =
977 reinterpret_cast<struct pldm_event_message_buffer_size_resp*>(
978 response->payload);
979
980 resp->completion_code = completionCode;
981 resp->terminus_max_buffer_size = terminusMaxBufferSize;
982
983 auto rc = decode_event_message_buffer_size_resp(
984 response, responseMsg.size() - hdrSize, &retCompletionCode,
985 &retMaxBufferSize);
986
987 EXPECT_EQ(rc, PLDM_SUCCESS);
988 EXPECT_EQ(retCompletionCode, completionCode);
989 EXPECT_EQ(terminusMaxBufferSize, retMaxBufferSize);
990}
991
992TEST(EventMessageBufferSize, testBadEventMessageBufferSizeResponse)
993{
994 uint8_t completionCode = PLDM_SUCCESS;
995 uint16_t terminusMaxBufferSize = 256;
996
997 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES>
998 responseMsg{};
999
1000 uint8_t retCompletionCode;
1001 uint16_t retMaxBufferSize = 0;
1002
1003 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1004 struct pldm_event_message_buffer_size_resp* resp =
1005 reinterpret_cast<struct pldm_event_message_buffer_size_resp*>(
1006 response->payload);
1007 resp->completion_code = completionCode;
1008 resp->terminus_max_buffer_size = terminusMaxBufferSize;
1009
1010 auto rc =
1011 decode_event_message_buffer_size_resp(response, 0, nullptr, nullptr);
1012 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1013
1014 rc = decode_event_message_buffer_size_resp(
1015 response, responseMsg.size(), &retCompletionCode, &retMaxBufferSize);
1016 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1017}
1018
Dung Cao1bf8c872022-11-29 05:32:58 +07001019TEST(PlatformEventMessageSupported, testGoodEncodeRequest)
1020{
1021 uint8_t formatVersion = 0x01;
1022
1023 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_REQ_BYTES>
1024 requestMsg{};
1025
1026 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1027
1028 auto rc = encode_event_message_supported_req(0, formatVersion, request);
1029
1030 struct pldm_event_message_supported_req* req =
1031 reinterpret_cast<struct pldm_event_message_supported_req*>(
1032 request->payload);
1033
1034 EXPECT_EQ(rc, PLDM_SUCCESS);
1035 EXPECT_EQ(formatVersion, req->format_version);
1036}
1037
1038TEST(PlatformEventMessageSupported, testBadEncodeRequest)
1039{
1040 uint8_t eventData = 34;
1041 uint8_t formatVersion = 0x0;
1042
1043 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_REQ_BYTES +
1044 sizeof(eventData)>
1045 requestMsg{};
1046 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1047
1048 auto rc = encode_event_message_supported_req(0, formatVersion, request);
1049 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1050
1051 rc = encode_event_message_supported_req(0, formatVersion, nullptr);
1052 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1053}
1054
1055TEST(PlatformEventMessageSupported, testGoodDecodeRespond)
1056{
1057 uint8_t completionCode = PLDM_SUCCESS;
1058 uint8_t synchConfiguration = PLDM_MESSAGE_TYPE_SYNCHRONOUS;
1059 bitfield8_t synchConfigSupported;
1060 synchConfigSupported.byte = 0xe;
1061 uint8_t numberEventClassReturned = 0x3;
1062 std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa};
1063 constexpr uint8_t eventClassCount = 3;
1064
1065 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES +
1066 eventClassCount>
1067 responseMsg{};
1068
1069 uint8_t retCompletionCode;
1070 uint8_t retSynchConfig = 0;
1071 uint8_t retNumberEventClass = 0;
1072 bitfield8_t retSynchConfigSupport;
1073 uint8_t retEventClass[eventClassCount] = {0};
1074
1075 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1076 struct pldm_event_message_supported_resp* resp =
1077 reinterpret_cast<struct pldm_event_message_supported_resp*>(
1078 response->payload);
1079
1080 resp->completion_code = completionCode;
1081 resp->synchrony_configuration = synchConfiguration;
1082 resp->synchrony_configuration_supported.byte = synchConfigSupported.byte;
1083 resp->number_event_class_returned = numberEventClassReturned;
1084 memcpy(resp->event_class, eventClass.data(), numberEventClassReturned);
1085
1086 auto rc = decode_event_message_supported_resp(
1087 response, responseMsg.size() - hdrSize, &retCompletionCode,
1088 &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass,
1089 retEventClass, eventClassCount);
1090
1091 EXPECT_EQ(rc, PLDM_SUCCESS);
1092 EXPECT_EQ(retCompletionCode, completionCode);
1093 EXPECT_EQ(retSynchConfig, synchConfiguration);
1094 EXPECT_EQ(retNumberEventClass, numberEventClassReturned);
1095 EXPECT_EQ(retSynchConfigSupport.byte, synchConfigSupported.byte);
1096 EXPECT_EQ(0, memcmp(eventClass.data(), resp->event_class,
1097 numberEventClassReturned));
1098}
1099
1100TEST(PlatformEventMessageSupported, testBadSynchConfiguration)
1101{
1102 uint8_t completionCode = PLDM_SUCCESS;
1103 uint8_t synchConfiguration = 0x4;
1104 bitfield8_t synchConfigSupported;
1105 synchConfigSupported.byte = 0xe;
1106 uint8_t numberEventClassReturned = 0x3;
1107 std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa};
1108 constexpr uint8_t eventClassCount = 3;
1109
1110 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES +
1111 eventClassCount>
1112 responseMsg{};
1113
1114 uint8_t retCompletionCode;
1115 uint8_t retSynchConfig = 0;
1116 uint8_t retNumberEventClass = 0;
1117 bitfield8_t retSynchConfigSupport;
1118 uint8_t retEventClass[eventClassCount] = {0};
1119
1120 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1121 struct pldm_event_message_supported_resp* resp =
1122 reinterpret_cast<struct pldm_event_message_supported_resp*>(
1123 response->payload);
1124
1125 resp->completion_code = completionCode;
1126 resp->synchrony_configuration = synchConfiguration;
1127 resp->synchrony_configuration_supported.byte = synchConfigSupported.byte;
1128 resp->number_event_class_returned = numberEventClassReturned;
1129 memcpy(resp->event_class, eventClass.data(), numberEventClassReturned);
1130
1131 auto rc = decode_event_message_supported_resp(
1132 response, responseMsg.size() - hdrSize, &retCompletionCode,
1133 &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass,
1134 retEventClass, eventClassCount);
1135
1136 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1137}
1138
1139TEST(PlatformEventMessageSupported, testBadDecodeRespond)
1140{
1141 uint8_t completionCode = PLDM_SUCCESS;
1142 uint8_t synchConfiguration = PLDM_MESSAGE_TYPE_SYNCHRONOUS;
1143 bitfield8_t synchConfigSupported;
1144 synchConfigSupported.byte = 0xe;
1145 uint8_t numberEventClassReturned = 0x3;
1146 std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa};
1147 constexpr uint8_t eventClassCount = 3;
1148
1149 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES +
1150 eventClassCount>
1151 responseMsg{};
1152
1153 uint8_t retCompletionCode;
1154 uint8_t retSynchConfig = 0;
1155 uint8_t retNumberEventClass = 0;
1156 bitfield8_t retSynchConfigSupport;
1157 uint8_t retEventClass[eventClassCount] = {0};
1158
1159 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1160 struct pldm_event_message_supported_resp* resp =
1161 reinterpret_cast<struct pldm_event_message_supported_resp*>(
1162 response->payload);
1163 resp->completion_code = completionCode;
1164 resp->synchrony_configuration = synchConfiguration;
1165 resp->synchrony_configuration_supported.byte = synchConfigSupported.byte;
1166 resp->number_event_class_returned = numberEventClassReturned;
1167 memcpy(resp->event_class, eventClass.data(), numberEventClassReturned);
1168
1169 auto rc = decode_event_message_supported_resp(response, 0, nullptr, nullptr,
1170 nullptr, nullptr, nullptr, 0);
1171 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1172
1173 rc = decode_event_message_supported_resp(
1174 response, PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES - 1,
1175 &retCompletionCode, &retSynchConfig, &retSynchConfigSupport,
1176 &retNumberEventClass, retEventClass, eventClassCount);
1177 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1178
1179 rc = decode_event_message_supported_resp(
1180 response, responseMsg.size() - hdrSize, &retCompletionCode,
1181 &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass,
1182 retEventClass, 1);
1183 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1184}
1185
Thu Nguyen159a98b2022-11-02 10:00:10 +07001186TEST(PollForPlatformEventMessage, testGoodEncodeRequest)
1187{
1188 uint8_t formatVersion = 0x01;
1189 uint8_t transferOperationFlag = 0x1;
1190 uint32_t dataTransferHandle = 0xffffffff;
1191 uint16_t eventIdToAcknowledge = 0x0;
1192
1193 std::array<uint8_t,
1194 hdrSize + PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES>
1195 requestMsg{};
1196 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1197
1198 auto rc = encode_poll_for_platform_event_message_req(
1199 0, formatVersion, transferOperationFlag, dataTransferHandle,
1200 eventIdToAcknowledge, request,
1201 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1202 EXPECT_EQ(rc, PLDM_SUCCESS);
1203
1204 struct pldm_msgbuf _buf;
1205 struct pldm_msgbuf* buf = &_buf;
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09301206 rc = pldm_msgbuf_init_cc(
1207 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES, request->payload,
1208 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
Thu Nguyen159a98b2022-11-02 10:00:10 +07001209 EXPECT_EQ(rc, PLDM_SUCCESS);
1210
1211 uint8_t retFormatVersion;
1212 uint8_t retTransferOperationFlag;
1213 uint32_t retDataTransferHandle;
1214 uint16_t retEventIdToAcknowledge;
1215
1216 pldm_msgbuf_extract_uint8(buf, &retFormatVersion);
1217 pldm_msgbuf_extract_uint8(buf, &retTransferOperationFlag);
1218 pldm_msgbuf_extract_uint32(buf, &retDataTransferHandle);
1219 pldm_msgbuf_extract_uint16(buf, &retEventIdToAcknowledge);
1220
1221 EXPECT_EQ(retFormatVersion, formatVersion);
1222 EXPECT_EQ(retTransferOperationFlag, transferOperationFlag);
1223 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
1224 EXPECT_EQ(retEventIdToAcknowledge, eventIdToAcknowledge);
1225 EXPECT_EQ(pldm_msgbuf_destroy(buf), PLDM_SUCCESS);
1226}
1227
1228TEST(PollForPlatformEventMessage, testBadEncodeRequest)
1229{
1230 uint8_t formatVersion = 0x01;
1231 uint8_t transferOperationFlag = 0x1;
1232 uint32_t dataTransferHandle = 0xffffffff;
1233 uint16_t eventIdToAcknowledge = 0x0;
1234
1235 std::array<uint8_t,
1236 hdrSize + PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES>
1237 requestMsg{};
1238 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1239
1240 auto rc = encode_poll_for_platform_event_message_req(
1241 0, formatVersion, transferOperationFlag, dataTransferHandle,
1242 eventIdToAcknowledge, nullptr,
1243 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1244
1245 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1246
1247 encode_poll_for_platform_event_message_req(
1248 0, formatVersion, transferOperationFlag, dataTransferHandle,
1249 eventIdToAcknowledge, request, hdrSize);
1250}
1251
1252TEST(PollForPlatformEventMessage, testGoodDecodeRespond)
1253{
1254 uint8_t completionCode = PLDM_SUCCESS;
1255 uint8_t tId = 0x9;
1256 uint16_t eventId = 159;
1257 uint32_t nextDataTransferHandle = 0x11223344;
1258 uint8_t transferFlag = PLDM_START_AND_END;
1259 uint8_t eventClass = 0x5;
1260 uint8_t eventData[5] = {0x55, 0x44, 0x33, 0x22, 0x11};
1261 constexpr uint32_t eventDataSize = 0x00000005;
1262 uint32_t eventDataIntegrityChecksum = 0x66778899;
1263
1264 std::vector<uint8_t> responseMsg{
1265 0x1,
1266 0x0,
1267 0x0,
1268 PLDM_SUCCESS,
1269 0x9, // tid
1270 159,
1271 0x0, // event id
1272 0x44,
1273 0x33,
1274 0x22,
1275 0x11, // next_data_transfer_handle
1276 PLDM_START_AND_END, // transfer_flag
1277 0x05, // event class
1278 0x05,
1279 0x00,
1280 0x00,
1281 0x00, // event_data_size
1282 0x55,
1283 0x44,
1284 0x33,
1285 0x22,
1286 0x11, // event_data[5]
1287 0x99,
1288 0x88,
1289 0x77,
1290 0x66 // event_data_integrity_checksum
1291 };
1292 const uint32_t respMsgLen = 23;
1293
1294 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1295
1296 uint8_t retCompletionCode;
1297 uint8_t retTid = 0;
1298 uint16_t retEventId = 0;
1299 uint32_t retNextDataTransferHandle = 0;
1300 uint8_t retTransferFlag = 0;
1301 uint8_t retEventClass = 0;
1302 uint32_t retEventDataSize = 0;
1303 uint8_t* retEventData = nullptr;
1304 uint32_t retEventDataIntegrityChecksum = 0;
1305
1306 auto rc = decode_poll_for_platform_event_message_resp(
1307 response, respMsgLen, &retCompletionCode, &retTid, &retEventId,
1308 &retNextDataTransferHandle, &retTransferFlag, &retEventClass,
1309 &retEventDataSize, (void**)&retEventData,
1310 &retEventDataIntegrityChecksum);
1311
1312 EXPECT_EQ(rc, PLDM_SUCCESS);
1313 EXPECT_EQ(retCompletionCode, completionCode);
1314 EXPECT_EQ(retTid, tId);
1315 EXPECT_EQ(retEventId, eventId);
1316 EXPECT_EQ(retNextDataTransferHandle, nextDataTransferHandle);
1317 EXPECT_EQ(retTransferFlag, transferFlag);
1318 EXPECT_EQ(retEventClass, eventClass);
1319 EXPECT_EQ(retEventDataSize, eventDataSize);
1320 EXPECT_EQ(retEventDataIntegrityChecksum, eventDataIntegrityChecksum);
1321 EXPECT_EQ(0, memcmp(eventData, retEventData, eventDataSize));
1322}
1323
1324TEST(PollForPlatformEventMessage, testGoodDecodeAckOnlyRespond)
1325{
1326 uint8_t completionCode = PLDM_SUCCESS;
1327 uint8_t tId = 0x9;
1328 uint16_t eventId = 0xffff;
1329
1330 std::vector<uint8_t> responseMsg{
1331 0x1, 0x0, 0x0, PLDM_SUCCESS,
1332 0x9, // tid
1333 0xff,
1334 0xff // event id
1335 };
1336 const uint32_t respMsgLen = 4;
1337
1338 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1339
1340 uint8_t retCompletionCode;
1341 uint8_t retTid = 0;
1342 uint16_t retEventId = 0;
1343 uint32_t retNextDataTransferHandle = 0;
1344 uint8_t retTransferFlag = 0;
1345 uint8_t retEventClass = 0;
1346 uint32_t retEventDataSize = 0;
1347 uint8_t* retEventData = nullptr;
1348 uint32_t retEventDataIntegrityChecksum = 0;
1349
1350 auto rc = decode_poll_for_platform_event_message_resp(
1351 response, respMsgLen, &retCompletionCode, &retTid, &retEventId,
1352 &retNextDataTransferHandle, &retTransferFlag, &retEventClass,
1353 &retEventDataSize, (void**)&retEventData,
1354 &retEventDataIntegrityChecksum);
1355
1356 EXPECT_EQ(rc, PLDM_SUCCESS);
1357 EXPECT_EQ(retCompletionCode, completionCode);
1358 EXPECT_EQ(retTid, tId);
1359 EXPECT_EQ(retEventId, eventId);
1360
1361 eventId = 0x0000;
1362 responseMsg[5] = 0x00;
1363 responseMsg[6] = 0x00;
1364 response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1365
1366 rc = decode_poll_for_platform_event_message_resp(
1367 response, respMsgLen, &retCompletionCode, &retTid, &retEventId,
1368 &retNextDataTransferHandle, &retTransferFlag, &retEventClass,
1369 &retEventDataSize, (void**)&retEventData,
1370 &retEventDataIntegrityChecksum);
1371
1372 EXPECT_EQ(rc, PLDM_SUCCESS);
1373 EXPECT_EQ(retCompletionCode, completionCode);
1374 EXPECT_EQ(retTid, tId);
1375 EXPECT_EQ(retEventId, eventId);
1376}
1377
1378TEST(PollForPlatformEventMessage, testBadDecodeRespond)
1379{
1380 std::vector<uint8_t> responseMsg{
1381 0x1,
1382 0x0,
1383 0x0,
1384 PLDM_SUCCESS,
1385 0x9, // tid
1386 159,
1387 0x0, // event id
1388 0x44,
1389 0x33,
1390 0x22,
1391 0x11, // next_data_transfer_handle
1392 PLDM_START_AND_END, // transfer_flag
1393 0x05, // event class
1394 0x05,
1395 0x00,
1396 0x00,
1397 0x00, // event_data_size
1398 0x55,
1399 0x44,
1400 0x33,
1401 0x22,
1402 0x11, // event_data[5]
1403 0x99,
1404 0x88,
1405 0x77,
1406 0x66 // event_data_integrity_checksum
1407 };
1408 // const uint32_t respMsgLen = 23;
1409
1410 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1411
1412 auto rc = decode_poll_for_platform_event_message_resp(
1413 nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1414 nullptr, nullptr, nullptr);
1415
1416 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1417
1418 uint8_t retCompletionCode;
1419 uint8_t retTid = 0;
1420 uint16_t retEventId = 0;
1421 uint32_t retNextDataTransferHandle = 0;
1422 uint8_t retTransferFlag = 0;
1423 uint8_t retEventClass = 0;
1424 uint32_t retEventDataSize = 0;
1425 uint8_t* retEventData = nullptr;
1426 uint32_t retEventDataIntegrityChecksum = 0;
1427
1428 rc = decode_poll_for_platform_event_message_resp(
1429 response, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES - 1,
1430 &retCompletionCode, &retTid, &retEventId, &retNextDataTransferHandle,
1431 &retTransferFlag, &retEventClass, &retEventDataSize,
1432 (void**)&retEventData, &retEventDataIntegrityChecksum);
1433
1434 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1435}
1436
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001437TEST(PollForPlatformEventMessage, testGoodDecodeRequestFirstPart)
1438{
1439 uint8_t formatVersion = 0x1;
1440 uint8_t transferOperationFlag = PLDM_GET_FIRSTPART;
1441 uint32_t dataTransferHandle = 0x11223344;
1442 uint16_t eventIdToAcknowledge = 0x0;
1443 std::vector<uint8_t> requestMsg{0x1, 0x0, 0x0, 0x1, PLDM_GET_FIRSTPART,
1444 0x44, 0x33, 0x22, 0x11, 0x00,
1445 0x00};
1446 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1447
1448 uint8_t retFormatVersion;
1449 uint8_t retTransferOperationFlag;
1450 uint32_t retDataTransferHandle;
1451 uint16_t retEventIdToAcknowledge;
1452
1453 auto rc = decode_poll_for_platform_event_message_req(
1454 request, requestMsg.size() - hdrSize, &retFormatVersion,
1455 &retTransferOperationFlag, &retDataTransferHandle,
1456 &retEventIdToAcknowledge);
1457
1458 EXPECT_EQ(rc, PLDM_SUCCESS);
1459 EXPECT_EQ(retFormatVersion, formatVersion);
1460 EXPECT_EQ(retTransferOperationFlag, transferOperationFlag);
1461 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
1462 EXPECT_EQ(retEventIdToAcknowledge, eventIdToAcknowledge);
1463}
1464
1465TEST(PollForPlatformEventMessage, testGoodDecodeRequestNextPart)
1466{
1467 uint8_t formatVersion = 0x1;
1468 uint8_t transferOperationFlag = PLDM_GET_NEXTPART;
1469 uint32_t dataTransferHandle = 0x11223344;
1470 uint16_t eventIdToAcknowledge = 0xffff;
1471 std::vector<uint8_t> requestMsg{0x1, 0x0, 0x0, 0x1, PLDM_GET_NEXTPART,
1472 0x44, 0x33, 0x22, 0x11, 0xff,
1473 0xff};
1474 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1475
1476 uint8_t retFormatVersion;
1477 uint8_t retTransferOperationFlag;
1478 uint32_t retDataTransferHandle;
1479 uint16_t retEventIdToAcknowledge;
1480
1481 auto rc = decode_poll_for_platform_event_message_req(
1482 request, requestMsg.size() - hdrSize, &retFormatVersion,
1483 &retTransferOperationFlag, &retDataTransferHandle,
1484 &retEventIdToAcknowledge);
1485
1486 EXPECT_EQ(rc, PLDM_SUCCESS);
1487 EXPECT_EQ(retFormatVersion, formatVersion);
1488 EXPECT_EQ(retTransferOperationFlag, transferOperationFlag);
1489 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
1490 EXPECT_EQ(retEventIdToAcknowledge, eventIdToAcknowledge);
1491}
1492
1493TEST(PollForPlatformEventMessage, testGoodDecodeRequestAck)
1494{
1495 uint8_t formatVersion = 0x1;
1496 uint8_t transferOperationFlag = PLDM_ACKNOWLEDGEMENT_ONLY;
1497 uint32_t dataTransferHandle = 0x11223344;
1498 uint16_t eventIdToAcknowledge = 0xffff;
1499 std::vector<uint8_t> requestMsg{
1500 0x1, 0x0, 0x0, 0x1, PLDM_ACKNOWLEDGEMENT_ONLY, 0x44, 0x33,
1501 0x22, 0x11, 0xff, 0xff};
1502 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1503
1504 uint8_t retFormatVersion;
1505 uint8_t retTransferOperationFlag;
1506 uint32_t retDataTransferHandle;
1507 uint16_t retEventIdToAcknowledge;
1508
1509 auto rc = decode_poll_for_platform_event_message_req(
1510 request, requestMsg.size() - hdrSize, &retFormatVersion,
1511 &retTransferOperationFlag, &retDataTransferHandle,
1512 &retEventIdToAcknowledge);
1513
1514 EXPECT_EQ(rc, PLDM_SUCCESS);
1515 EXPECT_EQ(retFormatVersion, formatVersion);
1516 EXPECT_EQ(retTransferOperationFlag, transferOperationFlag);
1517 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
1518 EXPECT_EQ(retEventIdToAcknowledge, eventIdToAcknowledge);
1519}
1520
1521TEST(PollForPlatformEventMessage, testBadDecodeRequest)
1522{
1523 std::vector<uint8_t> requestMsg{0x1, 0x0, 0x0, 0x1, PLDM_GET_FIRSTPART,
1524 0x44, 0x33, 0x22, 0x11, 0x66,
1525 0x55};
1526 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1527
1528 uint8_t retFormatVersion;
1529 uint8_t retTransferOperationFlag;
1530 uint32_t retDataTransferHandle;
1531 uint16_t retEventIdToAcknowledge;
1532
1533 auto rc = decode_poll_for_platform_event_message_req(
1534 NULL, requestMsg.size() - hdrSize, &retFormatVersion,
1535 &retTransferOperationFlag, &retDataTransferHandle,
1536 &retEventIdToAcknowledge);
1537 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1538
1539 /*
1540 * transfer_operation_flag is not PLDM_GET_FIRSTPART or PLDM_GET_NEXTPART or
1541 * PLDM_ACKNOWLEDGEMENT_ONLY
1542 */
1543
1544 requestMsg[4] = PLDM_ACKNOWLEDGEMENT_ONLY + 1;
1545
1546 rc = decode_poll_for_platform_event_message_req(
1547 request, requestMsg.size() - hdrSize, &retFormatVersion,
1548 &retTransferOperationFlag, &retDataTransferHandle,
1549 &retEventIdToAcknowledge);
1550
1551 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1552 /*
1553 * transfer_operation_flag is PLDM_GET_FIRSTPART and
1554 * event_id_to_acknowledge not 0x0000
1555 */
1556 requestMsg[4] = PLDM_GET_FIRSTPART;
1557 requestMsg[9] = 0x0;
1558 requestMsg[10] = 0x1;
1559
1560 rc = decode_poll_for_platform_event_message_req(
1561 request, requestMsg.size() - hdrSize, &retFormatVersion,
1562 &retTransferOperationFlag, &retDataTransferHandle,
1563 &retEventIdToAcknowledge);
1564
1565 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1566
1567 /*
1568 * transfer_operation_flag is not PLDM_GET_FIRSTPART and
1569 * event_id_to_acknowledge is 0x0000
1570 */
1571 requestMsg[4] = PLDM_GET_NEXTPART;
1572 requestMsg[9] = 0x0;
1573 requestMsg[10] = 0x0;
1574
1575 rc = decode_poll_for_platform_event_message_req(
1576 request, requestMsg.size() - hdrSize, &retFormatVersion,
1577 &retTransferOperationFlag, &retDataTransferHandle,
1578 &retEventIdToAcknowledge);
1579
1580 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1581
1582 /*
1583 * transfer_operation_flag is PLDM_GET_NEXTPART and
1584 * event_id_to_acknowledge not 0xffff
1585 */
1586 requestMsg[4] = PLDM_GET_NEXTPART;
1587 requestMsg[9] = 0x0;
1588 requestMsg[10] = 0x1;
1589
1590 rc = decode_poll_for_platform_event_message_req(
1591 request, requestMsg.size() - hdrSize, &retFormatVersion,
1592 &retTransferOperationFlag, &retDataTransferHandle,
1593 &retEventIdToAcknowledge);
1594
1595 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1596
1597 /*
1598 * transfer_operation_flag is not PLDM_GET_NEXTPART and
1599 * event_id_to_acknowledge is 0xffff
1600 */
1601 requestMsg[4] = PLDM_GET_FIRSTPART;
1602 requestMsg[9] = 0xff;
1603 requestMsg[10] = 0xff;
1604
1605 rc = decode_poll_for_platform_event_message_req(
1606 request, requestMsg.size() - hdrSize, &retFormatVersion,
1607 &retTransferOperationFlag, &retDataTransferHandle,
1608 &retEventIdToAcknowledge);
1609
1610 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1611}
1612
1613TEST(PollForPlatformEventMessage, testGoodEncodeResposeP1)
1614{
1615 uint8_t completionCode = PLDM_SUCCESS;
1616 uint8_t instance_id = 0;
1617 uint8_t tId = 0x9;
1618 uint16_t eventId = 0x1;
1619 uint32_t nextDataTransferHandle = 0xffff;
1620 uint8_t transferFlag = PLDM_END;
1621 uint8_t eventClass = 0x5;
1622 constexpr uint32_t eventDataSize = 9;
1623 uint8_t pEventData[eventDataSize] = {0x31, 0x32, 0x33, 0x34, 0x35,
1624 0x36, 0x37, 0x38, 0x39};
1625 uint32_t eventDataIntegrityChecksum = 0x11223344;
1626 constexpr size_t payloadLength =
1627 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_RESP_BYTES + eventDataSize + 4;
1628
1629 std::array<uint8_t, hdrSize + payloadLength> responseMsg{};
1630 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1631
1632 auto rc = encode_poll_for_platform_event_message_resp(
1633 instance_id, completionCode, tId, eventId, nextDataTransferHandle,
1634 transferFlag, eventClass, eventDataSize, pEventData,
1635 eventDataIntegrityChecksum, response, payloadLength);
1636 EXPECT_EQ(rc, PLDM_SUCCESS);
1637
1638 struct pldm_msgbuf _buf;
1639 struct pldm_msgbuf* buf = &_buf;
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09301640 rc = pldm_msgbuf_init_cc(
1641 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
1642 response->payload, payloadLength);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001643 EXPECT_EQ(rc, PLDM_SUCCESS);
1644
1645 uint8_t retCompletionCode;
1646 uint8_t retTid = 0;
1647 uint16_t retEventId = 0;
1648 uint32_t retNextDataTransferHandle = 0;
1649 uint8_t retTransferFlag = 0;
1650 uint8_t retEventClass = 0;
1651 uint32_t retEventDataSize = 0;
1652 uint8_t retEventData[payloadLength] = {0};
1653 uint32_t retEventDataIntegrityChecksum = 0;
1654
1655 pldm_msgbuf_extract_uint8(buf, &retCompletionCode);
1656 pldm_msgbuf_extract_uint8(buf, &retTid);
1657 pldm_msgbuf_extract_uint16(buf, &retEventId);
1658 pldm_msgbuf_extract_uint32(buf, &retNextDataTransferHandle);
1659 pldm_msgbuf_extract_uint8(buf, &retTransferFlag);
1660 pldm_msgbuf_extract_uint8(buf, &retEventClass);
1661 pldm_msgbuf_extract_uint32(buf, &retEventDataSize);
1662 pldm_msgbuf_extract_array_uint8(buf, retEventData, retEventDataSize);
1663 pldm_msgbuf_extract_uint32(buf, &retEventDataIntegrityChecksum);
1664
1665 EXPECT_EQ(rc, PLDM_SUCCESS);
1666 EXPECT_EQ(retCompletionCode, completionCode);
1667 EXPECT_EQ(retTid, tId);
1668 EXPECT_EQ(retEventId, eventId);
1669 EXPECT_EQ(retNextDataTransferHandle, nextDataTransferHandle);
1670 EXPECT_EQ(retTransferFlag, transferFlag);
1671 EXPECT_EQ(retEventClass, eventClass);
1672 EXPECT_EQ(retEventDataSize, eventDataSize);
1673 EXPECT_EQ(retEventDataIntegrityChecksum, eventDataIntegrityChecksum);
1674 EXPECT_EQ(0, memcmp(pEventData, retEventData, eventDataSize));
1675
1676 EXPECT_EQ(pldm_msgbuf_destroy(buf), PLDM_SUCCESS);
1677}
1678
1679TEST(PollForPlatformEventMessage, testGoodEncodeResposeP2)
1680{
1681 uint8_t completionCode = PLDM_SUCCESS;
1682 uint8_t instance_id = 0;
1683 uint8_t tId = 0x9;
1684 uint16_t eventId = 0x0000;
1685 constexpr size_t payloadLength =
1686 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES;
1687
1688 std::array<uint8_t, hdrSize + payloadLength> responseMsg{};
1689 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1690
1691 auto rc = encode_poll_for_platform_event_message_resp(
1692 instance_id, completionCode, tId, eventId, 0, 0, 0, 0, NULL, 0,
1693 response, payloadLength);
1694 EXPECT_EQ(rc, PLDM_SUCCESS);
1695
1696 struct pldm_msgbuf _buf;
1697 struct pldm_msgbuf* buf = &_buf;
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09301698 rc = pldm_msgbuf_init_cc(
1699 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
1700 response->payload, payloadLength);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001701 EXPECT_EQ(rc, PLDM_SUCCESS);
1702
1703 uint8_t retCompletionCode;
1704 uint8_t retTid = 0;
1705 uint16_t retEventId = 0;
1706
1707 pldm_msgbuf_extract_uint8(buf, &retCompletionCode);
1708 pldm_msgbuf_extract_uint8(buf, &retTid);
1709 pldm_msgbuf_extract_uint16(buf, &retEventId);
1710
1711 EXPECT_EQ(rc, PLDM_SUCCESS);
1712 EXPECT_EQ(retCompletionCode, completionCode);
1713 EXPECT_EQ(retTid, tId);
1714 EXPECT_EQ(retEventId, eventId);
1715 EXPECT_EQ(pldm_msgbuf_destroy(buf), PLDM_SUCCESS);
1716}
1717
1718TEST(PollForPlatformEventMessage, testGoodEncodeResposeP3)
1719{
1720 uint8_t completionCode = PLDM_SUCCESS;
1721 uint8_t instance_id = 0;
1722 uint8_t tId = 0x9;
1723 uint16_t eventId = 0xffff;
1724 constexpr size_t payloadLength =
1725 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES;
1726
1727 std::array<uint8_t, hdrSize + payloadLength> responseMsg{};
1728 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1729
1730 auto rc = encode_poll_for_platform_event_message_resp(
1731 instance_id, completionCode, tId, eventId, 0, 0, 0, 0, NULL, 0,
1732 response, payloadLength);
1733 EXPECT_EQ(rc, PLDM_SUCCESS);
1734
1735 struct pldm_msgbuf _buf;
1736 struct pldm_msgbuf* buf = &_buf;
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09301737 rc = pldm_msgbuf_init_cc(
1738 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
1739 response->payload, payloadLength);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001740 EXPECT_EQ(rc, PLDM_SUCCESS);
1741
1742 uint8_t retCompletionCode;
1743 uint8_t retTid = 0;
1744 uint16_t retEventId = 0;
1745
1746 pldm_msgbuf_extract_uint8(buf, &retCompletionCode);
1747 pldm_msgbuf_extract_uint8(buf, &retTid);
1748 pldm_msgbuf_extract_uint16(buf, &retEventId);
1749
1750 EXPECT_EQ(rc, PLDM_SUCCESS);
1751 EXPECT_EQ(retCompletionCode, completionCode);
1752 EXPECT_EQ(retTid, tId);
1753 EXPECT_EQ(retEventId, eventId);
1754 EXPECT_EQ(pldm_msgbuf_destroy(buf), PLDM_SUCCESS);
1755}
1756
1757TEST(PollForPlatformEventMessage, testGoodEncodeResposeP4)
1758{
1759 uint8_t completionCode = PLDM_SUCCESS;
1760 uint8_t instance_id = 0;
1761 uint8_t tId = 0x9;
1762 uint16_t eventId = 0x1;
1763 uint32_t nextDataTransferHandle = 0xffff;
1764 uint8_t transferFlag = PLDM_END;
1765 uint8_t eventClass = 0x5;
1766 constexpr uint32_t eventDataSize = 0;
1767 uint32_t eventDataIntegrityChecksum = 0x11223344;
1768 size_t payloadLength =
1769 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_RESP_BYTES + eventDataSize + 4;
1770
1771 std::array<uint8_t, hdrSize +
1772 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_RESP_BYTES +
1773 eventDataSize + 4>
1774 responseMsg{};
1775 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1776
1777 auto rc = encode_poll_for_platform_event_message_resp(
1778 instance_id, completionCode, tId, eventId, nextDataTransferHandle,
1779 transferFlag, eventClass, eventDataSize, NULL,
1780 eventDataIntegrityChecksum, response, payloadLength);
1781 EXPECT_EQ(rc, PLDM_SUCCESS);
1782
1783 struct pldm_msgbuf _buf;
1784 struct pldm_msgbuf* buf = &_buf;
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09301785 rc = pldm_msgbuf_init_cc(
1786 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
1787 response->payload, payloadLength);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001788 EXPECT_EQ(rc, PLDM_SUCCESS);
1789
1790 uint8_t retCompletionCode;
1791 uint8_t retTid = 0;
1792 uint16_t retEventId = 0;
1793 uint32_t retNextDataTransferHandle = 0;
1794 uint8_t retTransferFlag = 0;
1795 uint8_t retEventClass = 0;
1796 uint32_t retEventDataSize = 0;
1797 uint32_t retEventDataIntegrityChecksum = 0;
1798
1799 pldm_msgbuf_extract_uint8(buf, &retCompletionCode);
1800 pldm_msgbuf_extract_uint8(buf, &retTid);
1801 pldm_msgbuf_extract_uint16(buf, &retEventId);
1802 pldm_msgbuf_extract_uint32(buf, &retNextDataTransferHandle);
1803 pldm_msgbuf_extract_uint8(buf, &retTransferFlag);
1804 pldm_msgbuf_extract_uint8(buf, &retEventClass);
1805 pldm_msgbuf_extract_uint32(buf, &retEventDataSize);
1806 pldm_msgbuf_extract_uint32(buf, &retEventDataIntegrityChecksum);
1807
1808 EXPECT_EQ(rc, PLDM_SUCCESS);
1809 EXPECT_EQ(retCompletionCode, completionCode);
1810 EXPECT_EQ(retTid, tId);
1811 EXPECT_EQ(retEventId, eventId);
1812 EXPECT_EQ(retNextDataTransferHandle, nextDataTransferHandle);
1813 EXPECT_EQ(retTransferFlag, transferFlag);
1814 EXPECT_EQ(retEventClass, eventClass);
1815 EXPECT_EQ(retEventDataSize, eventDataSize);
1816 EXPECT_EQ(retEventDataIntegrityChecksum, eventDataIntegrityChecksum);
1817
1818 EXPECT_EQ(pldm_msgbuf_destroy(buf), PLDM_SUCCESS);
1819}
1820
1821TEST(PollForPlatformEventMessage, testBadEncodeResponse)
1822{
1823 uint8_t completionCode = PLDM_SUCCESS;
1824 uint8_t instance_id = 0;
1825 uint8_t tId = 0x9;
1826 uint16_t eventId = 0x1;
1827 uint32_t nextDataTransferHandle = 0xffff;
1828 uint8_t transferFlag = 0x0;
1829 uint8_t eventClass = 0x5;
1830 const uint32_t eventDataSize = 0;
1831 uint32_t eventDataIntegrityChecksum = 0x11223344;
1832 constexpr size_t payloadLength =
1833 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_RESP_BYTES + eventDataSize + 4;
1834
1835 std::array<uint8_t, hdrSize + payloadLength> responseMsg{};
1836 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1837
1838 auto rc = encode_poll_for_platform_event_message_resp(
1839 instance_id, completionCode, tId, eventId, nextDataTransferHandle,
1840 transferFlag, eventClass, eventDataSize, NULL,
1841 eventDataIntegrityChecksum, NULL, payloadLength);
1842
1843 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1844
1845 rc = encode_poll_for_platform_event_message_resp(
1846 instance_id, completionCode, tId, eventId, nextDataTransferHandle,
1847 transferFlag, eventClass, 1, NULL, eventDataIntegrityChecksum, response,
1848 payloadLength);
1849 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1850}
1851
Andrew Jeffery9c766792022-08-10 23:12:49 +09301852TEST(PlatformEventMessage, testGoodStateSensorDecodeRequest)
1853{
1854 std::array<uint8_t,
1855 hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
1856 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES>
1857 requestMsg{};
1858
1859 uint8_t retFormatVersion = 0;
1860 uint8_t retTid = 0;
1861 uint8_t retEventClass = 0;
1862 size_t retEventDataOffset = 0;
1863
1864 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
1865 struct pldm_platform_event_message_req* request =
1866 reinterpret_cast<struct pldm_platform_event_message_req*>(req->payload);
1867
1868 uint8_t formatVersion = 0x01;
1869 uint8_t tid = 0x02;
1870 // Sensor Event
1871 uint8_t eventClass = 0x00;
1872
1873 request->format_version = formatVersion;
1874 request->tid = tid;
1875 request->event_class = eventClass;
1876 size_t eventDataOffset =
1877 sizeof(formatVersion) + sizeof(tid) + sizeof(eventClass);
1878
1879 auto rc = decode_platform_event_message_req(
1880 req, requestMsg.size() - hdrSize, &retFormatVersion, &retTid,
1881 &retEventClass, &retEventDataOffset);
1882
1883 EXPECT_EQ(rc, PLDM_SUCCESS);
1884 EXPECT_EQ(retFormatVersion, formatVersion);
1885 EXPECT_EQ(retTid, tid);
1886 EXPECT_EQ(retEventClass, eventClass);
1887 EXPECT_EQ(retEventDataOffset, eventDataOffset);
1888}
1889
1890TEST(PlatformEventMessage, testBadDecodeRequest)
1891{
1892 const struct pldm_msg* msg = NULL;
1893 std::array<uint8_t,
1894 hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
1895 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES - 1>
1896 requestMsg{};
1897 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
1898 uint8_t retFormatVersion;
1899 uint8_t retTid = 0;
1900 uint8_t retEventClass = 0;
1901 size_t retEventDataOffset;
1902
1903 auto rc = decode_platform_event_message_req(msg, sizeof(*msg), NULL, NULL,
1904 NULL, NULL);
1905 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1906
1907 rc = decode_platform_event_message_req(
1908 req,
1909 requestMsg.size() - hdrSize -
1910 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES,
1911 &retFormatVersion, &retTid, &retEventClass, &retEventDataOffset);
1912 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1913}
1914
1915TEST(PlatformEventMessage, testGoodEncodeResponse)
1916{
1917 std::array<uint8_t,
1918 hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
1919 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES - 1>
1920 responseMsg{};
1921 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1922 uint8_t completionCode = 0;
1923 uint8_t instanceId = 0x01;
1924 uint8_t platformEventStatus = 0x01;
1925
1926 auto rc = encode_platform_event_message_resp(instanceId, PLDM_SUCCESS,
1927 platformEventStatus, response);
1928
1929 EXPECT_EQ(rc, PLDM_SUCCESS);
1930 EXPECT_EQ(completionCode, response->payload[0]);
1931 EXPECT_EQ(platformEventStatus, response->payload[1]);
1932}
1933
1934TEST(PlatformEventMessage, testBadEncodeResponse)
1935{
1936 auto rc = encode_platform_event_message_resp(0, PLDM_SUCCESS, 1, NULL);
1937 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1938}
1939
1940TEST(PlatformEventMessage, testGoodEncodeRequest)
1941{
1942 uint8_t formatVersion = 0x01;
1943 uint8_t Tid = 0x03;
1944 uint8_t eventClass = 0x00;
1945 uint8_t eventData = 34;
1946
1947 std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
1948 sizeof(eventData)>
1949 requestMsg{};
1950
1951 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1952 auto rc = encode_platform_event_message_req(
1953 0, formatVersion, Tid, eventClass,
1954 reinterpret_cast<uint8_t*>(&eventData), sizeof(eventData), request,
1955 sizeof(eventData) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES);
1956
1957 struct pldm_platform_event_message_req* req =
1958 reinterpret_cast<struct pldm_platform_event_message_req*>(
1959 request->payload);
1960
1961 EXPECT_EQ(rc, PLDM_SUCCESS);
1962 EXPECT_EQ(formatVersion, req->format_version);
1963 EXPECT_EQ(Tid, req->tid);
1964 EXPECT_EQ(eventClass, req->event_class);
1965 EXPECT_EQ(0, memcmp(&eventData, req->event_data, sizeof(eventData)));
1966}
1967
1968TEST(PlatformEventMessage, testBadEncodeRequest)
1969{
1970 uint8_t Tid = 0x03;
1971 uint8_t eventClass = 0x00;
1972 uint8_t eventData = 34;
1973 size_t sz_eventData = sizeof(eventData);
1974 size_t payloadLen =
1975 sz_eventData + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES;
1976 uint8_t formatVersion = 0x01;
1977
1978 std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
1979 sizeof(eventData)>
1980 requestMsg{};
1981 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1982
1983 auto rc = encode_platform_event_message_req(
1984 0, formatVersion, Tid, eventClass,
1985 reinterpret_cast<uint8_t*>(&eventData), sz_eventData, nullptr,
1986 payloadLen);
1987 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1988 rc = encode_platform_event_message_req(
1989 0, 0, Tid, eventClass, reinterpret_cast<uint8_t*>(&eventData),
1990 sz_eventData, request, payloadLen);
1991 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1992 rc = encode_platform_event_message_req(0, formatVersion, Tid, eventClass,
1993 nullptr, 0, request, payloadLen);
1994 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1995 rc = encode_platform_event_message_req(
1996 0, formatVersion, Tid, eventClass,
1997 reinterpret_cast<uint8_t*>(&eventData), sz_eventData, request, 0);
1998 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1999}
2000
2001TEST(PlatformEventMessage, testGoodDecodeResponse)
2002{
2003 std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES>
2004 responseMsg{};
2005
2006 uint8_t completionCode = PLDM_SUCCESS;
2007 uint8_t platformEventStatus = 0x01;
2008
2009 uint8_t retcompletionCode;
2010 uint8_t retplatformEventStatus;
2011
2012 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2013 struct pldm_platform_event_message_resp* resp =
2014 reinterpret_cast<struct pldm_platform_event_message_resp*>(
2015 response->payload);
2016
2017 resp->completion_code = completionCode;
2018 resp->platform_event_status = platformEventStatus;
2019
2020 auto rc = decode_platform_event_message_resp(
2021 response, responseMsg.size() - hdrSize, &retcompletionCode,
2022 &retplatformEventStatus);
2023
2024 EXPECT_EQ(rc, PLDM_SUCCESS);
2025 EXPECT_EQ(completionCode, retcompletionCode);
2026 EXPECT_EQ(platformEventStatus, retplatformEventStatus);
2027}
2028
2029TEST(PlatformEventMessage, testBadDecodeResponse)
2030{
2031 std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES>
2032 responseMsg{};
2033
2034 uint8_t completionCode = PLDM_SUCCESS;
2035 uint8_t platformEventStatus = 0x01;
2036
2037 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2038 struct pldm_platform_event_message_resp* resp =
2039 reinterpret_cast<struct pldm_platform_event_message_resp*>(
2040 response->payload);
2041 resp->completion_code = completionCode;
2042 resp->platform_event_status = platformEventStatus;
2043
2044 auto rc = decode_platform_event_message_resp(
2045 nullptr, responseMsg.size() - hdrSize, nullptr, nullptr);
2046
2047 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2048
2049 rc = decode_platform_event_message_resp(
2050 response, responseMsg.size() - hdrSize - 1, &completionCode,
2051 &platformEventStatus);
2052
2053 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2054}
2055
2056TEST(PlatformEventMessage, testGoodSensorEventDataDecodeRequest)
2057{
2058 std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH +
2059 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES>
2060 eventDataArr{};
2061 uint16_t sensorId = 0x1234;
2062 uint8_t sensorEventClassType = PLDM_SENSOR_OP_STATE;
2063
2064 struct pldm_sensor_event_data* eventData =
2065 (struct pldm_sensor_event_data*)eventDataArr.data();
2066 eventData->sensor_id = sensorId;
2067 eventData->sensor_event_class_type = sensorEventClassType;
2068
2069 size_t retSensorOpDataOffset;
2070 uint16_t retSensorId = 0;
2071 uint8_t retSensorEventClassType;
2072 size_t sensorOpDataOffset = sizeof(sensorId) + sizeof(sensorEventClassType);
2073 auto rc = decode_sensor_event_data(
2074 reinterpret_cast<uint8_t*>(eventData), eventDataArr.size(),
2075 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
2076 EXPECT_EQ(rc, PLDM_SUCCESS);
2077 EXPECT_EQ(retSensorId, sensorId);
2078 EXPECT_EQ(retSensorEventClassType, sensorEventClassType);
2079 EXPECT_EQ(retSensorOpDataOffset, sensorOpDataOffset);
2080}
2081
2082TEST(PlatformEventMessage, testBadSensorEventDataDecodeRequest)
2083{
2084
2085 std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH +
2086 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES>
2087 eventDataArr{};
2088
2089 struct pldm_sensor_event_data* eventData =
2090 (struct pldm_sensor_event_data*)eventDataArr.data();
2091
2092 size_t retSensorOpDataOffset;
2093 uint16_t retSensorId = 0;
2094 uint8_t retSensorEventClassType;
2095 auto rc = decode_sensor_event_data(NULL, eventDataArr.size(), &retSensorId,
2096 &retSensorEventClassType,
2097 &retSensorOpDataOffset);
2098 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2099
2100 rc = decode_sensor_event_data(
2101 reinterpret_cast<uint8_t*>(eventDataArr.data()),
2102 eventDataArr.size() -
2103 PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH,
2104 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
2105 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2106
2107 eventData->sensor_event_class_type = PLDM_SENSOR_OP_STATE;
2108
2109 rc = decode_sensor_event_data(
2110 reinterpret_cast<uint8_t*>(eventDataArr.data()), eventDataArr.size(),
2111 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
2112 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2113
2114 eventData->sensor_event_class_type = PLDM_STATE_SENSOR_STATE;
2115 rc = decode_sensor_event_data(
2116 reinterpret_cast<uint8_t*>(eventDataArr.data()), eventDataArr.size(),
2117 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
2118 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2119
2120 eventData->sensor_event_class_type = PLDM_NUMERIC_SENSOR_STATE;
2121 rc = decode_sensor_event_data(
2122 reinterpret_cast<uint8_t*>(eventDataArr.data()),
2123 eventDataArr.size() + 1, &retSensorId, &retSensorEventClassType,
2124 &retSensorOpDataOffset);
2125 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2126}
2127
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302128#ifdef LIBPLDM_API_TESTING
Dung Cao7c250342022-11-16 22:40:37 +07002129TEST(PlatformEventMessage, testGoodPldmMsgPollEventDataDecodeRequest)
2130{
2131 std::array<uint8_t, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION +
2132 PLDM_PLATFORM_EVENT_MESSAGE_EVENT_ID +
2133 PLDM_PLATFORM_EVENT_MESSAGE_TRANFER_HANDLE>
2134 eventData{
2135 0x1, // version
2136 0x88, 0x77, // Event Id
Manojkiran Eda9e3a5d42024-06-17 16:06:42 +05302137 0x44, 0x33, 0x22, 0x11 // Transfer Handle
Dung Cao7c250342022-11-16 22:40:37 +07002138 };
2139
2140 uint8_t formatVersion = 0x01;
2141 uint16_t eventID = 0x7788;
2142 uint32_t dataTransferHandle = 0x11223344;
2143
Thu Nguyen7739d122024-07-26 11:36:39 +00002144 struct pldm_message_poll_event poll_event = {};
Dung Cao7c250342022-11-16 22:40:37 +07002145
2146 auto rc = decode_pldm_message_poll_event_data(
2147 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
Thu Nguyen7739d122024-07-26 11:36:39 +00002148 &poll_event);
Dung Cao7c250342022-11-16 22:40:37 +07002149
2150 EXPECT_EQ(rc, PLDM_SUCCESS);
Thu Nguyen7739d122024-07-26 11:36:39 +00002151 EXPECT_EQ(poll_event.format_version, formatVersion);
2152 EXPECT_EQ(poll_event.event_id, eventID);
2153 EXPECT_EQ(poll_event.data_transfer_handle, dataTransferHandle);
Dung Cao7c250342022-11-16 22:40:37 +07002154}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302155#endif
Dung Cao7c250342022-11-16 22:40:37 +07002156
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302157#ifdef LIBPLDM_API_TESTING
Dung Cao7c250342022-11-16 22:40:37 +07002158TEST(PlatformEventMessage, testBadPldmMsgPollEventDataDecodeRequest)
2159{
2160
2161 std::array<uint8_t, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION +
2162 PLDM_PLATFORM_EVENT_MESSAGE_EVENT_ID +
2163 PLDM_PLATFORM_EVENT_MESSAGE_TRANFER_HANDLE>
2164 eventData{
2165 0x1, // version
2166 0x88, 0x77, // Event Id
Manojkiran Eda9e3a5d42024-06-17 16:06:42 +05302167 0x44, 0x33, 0x22, 0x11 // Transfer Handle
Dung Cao7c250342022-11-16 22:40:37 +07002168 };
2169
Thu Nguyen7739d122024-07-26 11:36:39 +00002170 struct pldm_message_poll_event poll_event = {};
Dung Cao7c250342022-11-16 22:40:37 +07002171
Thu Nguyen7739d122024-07-26 11:36:39 +00002172 auto rc = decode_pldm_message_poll_event_data(NULL, eventData.size(),
2173 &poll_event);
2174 EXPECT_EQ(rc, -EINVAL);
2175
2176 rc = decode_pldm_message_poll_event_data(
2177 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(), NULL);
2178 EXPECT_EQ(rc, -EINVAL);
Dung Cao7c250342022-11-16 22:40:37 +07002179
2180 rc = decode_pldm_message_poll_event_data(
2181 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size() - 1,
Thu Nguyen7739d122024-07-26 11:36:39 +00002182 &poll_event);
2183 EXPECT_EQ(rc, -EOVERFLOW);
Dung Cao7c250342022-11-16 22:40:37 +07002184
2185 // Event id is 0x0000
2186 eventData[1] = 0x00;
2187 eventData[2] = 0x00;
2188 rc = decode_pldm_message_poll_event_data(
2189 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
Thu Nguyen7739d122024-07-26 11:36:39 +00002190 &poll_event);
Dung Cao7c250342022-11-16 22:40:37 +07002191
Thu Nguyen7739d122024-07-26 11:36:39 +00002192 EXPECT_EQ(rc, -EPROTO);
Dung Cao7c250342022-11-16 22:40:37 +07002193
2194 // Event id is 0xffff
2195 eventData[1] = 0xff;
2196 eventData[2] = 0xff;
2197 rc = decode_pldm_message_poll_event_data(
2198 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
Thu Nguyen7739d122024-07-26 11:36:39 +00002199 &poll_event);
Dung Cao7c250342022-11-16 22:40:37 +07002200
Thu Nguyen7739d122024-07-26 11:36:39 +00002201 EXPECT_EQ(rc, -EPROTO);
Dung Cao7c250342022-11-16 22:40:37 +07002202}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302203#endif
Dung Cao7c250342022-11-16 22:40:37 +07002204
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302205#ifdef LIBPLDM_API_TESTING
Dung Cao7c250342022-11-16 22:40:37 +07002206TEST(PlatformEventMessage, testGoodPldmMsgPollEventDataEncode)
2207{
2208 std::array<uint8_t, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION +
2209 PLDM_PLATFORM_EVENT_MESSAGE_EVENT_ID +
2210 PLDM_PLATFORM_EVENT_MESSAGE_TRANFER_HANDLE>
2211 eventData{};
2212
Thu Nguyen7739d122024-07-26 11:36:39 +00002213 struct pldm_message_poll_event poll_event = {};
2214 poll_event.format_version = 0x01;
2215 poll_event.event_id = 0x7788;
2216 poll_event.data_transfer_handle = 0x11223344;
Dung Cao7c250342022-11-16 22:40:37 +07002217
2218 int rc = encode_pldm_message_poll_event_data(
Thu Nguyen7739d122024-07-26 11:36:39 +00002219 &poll_event, reinterpret_cast<uint8_t*>(eventData.data()),
2220 eventData.size());
Dung Cao7c250342022-11-16 22:40:37 +07002221
2222 EXPECT_EQ(rc, PLDM_SUCCESS);
2223
2224 struct pldm_msgbuf _buf;
2225 struct pldm_msgbuf* buf = &_buf;
2226
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09302227 rc = pldm_msgbuf_init_cc(buf, PLDM_MSG_POLL_EVENT_LENGTH,
2228 reinterpret_cast<uint8_t*>(eventData.data()),
2229 eventData.size());
Dung Cao7c250342022-11-16 22:40:37 +07002230 EXPECT_EQ(rc, PLDM_SUCCESS);
2231
2232 uint8_t retFormatVersion;
2233 uint16_t reteventID;
2234 uint32_t retDataTransferHandle;
2235
2236 EXPECT_EQ(pldm_msgbuf_extract_uint8(buf, &retFormatVersion), PLDM_SUCCESS);
2237 EXPECT_EQ(pldm_msgbuf_extract_uint16(buf, &reteventID), PLDM_SUCCESS);
2238 EXPECT_EQ(pldm_msgbuf_extract_uint32(buf, &retDataTransferHandle),
2239 PLDM_SUCCESS);
Thu Nguyen7739d122024-07-26 11:36:39 +00002240 EXPECT_EQ(retFormatVersion, poll_event.format_version);
2241 EXPECT_EQ(reteventID, poll_event.event_id);
2242 EXPECT_EQ(retDataTransferHandle, poll_event.data_transfer_handle);
Dung Cao7c250342022-11-16 22:40:37 +07002243 EXPECT_EQ(pldm_msgbuf_destroy_consumed(buf), PLDM_SUCCESS);
2244}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302245#endif
Dung Cao7c250342022-11-16 22:40:37 +07002246
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302247#ifdef LIBPLDM_API_TESTING
Dung Cao7c250342022-11-16 22:40:37 +07002248TEST(PlatformEventMessage, testBadPldmMsgPollEventDataEncode)
2249{
2250 std::array<uint8_t, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION +
2251 PLDM_PLATFORM_EVENT_MESSAGE_EVENT_ID +
2252 PLDM_PLATFORM_EVENT_MESSAGE_TRANFER_HANDLE>
2253 eventData{};
2254
Thu Nguyen7739d122024-07-26 11:36:39 +00002255 struct pldm_message_poll_event poll_event = {};
2256 poll_event.format_version = 0x01;
2257 poll_event.event_id = 0x7788;
2258 poll_event.data_transfer_handle = 0x11223344;
Dung Cao7c250342022-11-16 22:40:37 +07002259
Thu Nguyen7739d122024-07-26 11:36:39 +00002260 int rc = encode_pldm_message_poll_event_data(&poll_event, NULL,
2261 eventData.size());
2262 EXPECT_EQ(rc, -EINVAL);
Dung Cao7c250342022-11-16 22:40:37 +07002263
Thu Nguyen7739d122024-07-26 11:36:39 +00002264 poll_event.event_id = 0x0000;
Dung Cao7c250342022-11-16 22:40:37 +07002265 rc = encode_pldm_message_poll_event_data(
Thu Nguyen7739d122024-07-26 11:36:39 +00002266 &poll_event, reinterpret_cast<uint8_t*>(eventData.data()),
2267 eventData.size());
2268 EXPECT_EQ(rc, -EPROTO);
Dung Cao7c250342022-11-16 22:40:37 +07002269
Thu Nguyen7739d122024-07-26 11:36:39 +00002270 poll_event.event_id = 0xffff;
Dung Cao7c250342022-11-16 22:40:37 +07002271 rc = encode_pldm_message_poll_event_data(
Thu Nguyen7739d122024-07-26 11:36:39 +00002272 &poll_event, reinterpret_cast<uint8_t*>(eventData.data()),
2273 eventData.size());
2274 EXPECT_EQ(rc, -EPROTO);
Dung Cao7c250342022-11-16 22:40:37 +07002275}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302276#endif
Dung Cao7c250342022-11-16 22:40:37 +07002277
Andrew Jeffery9c766792022-08-10 23:12:49 +09302278TEST(PlatformEventMessage, testGoodSensorOpEventDataDecodeRequest)
2279{
2280 std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH>
2281 eventDataArr{};
2282
2283 struct pldm_sensor_event_sensor_op_state* sensorData =
2284 (struct pldm_sensor_event_sensor_op_state*)eventDataArr.data();
2285 uint8_t presentState = PLDM_SENSOR_ENABLED;
2286 uint8_t previousState = PLDM_SENSOR_INITIALIZING;
2287 sensorData->present_op_state = presentState;
2288 sensorData->previous_op_state = previousState;
2289
2290 uint8_t retPresentState;
2291 uint8_t retPreviousState;
2292 auto rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData),
2293 eventDataArr.size(), &retPresentState,
2294 &retPreviousState);
2295 EXPECT_EQ(rc, PLDM_SUCCESS);
2296 EXPECT_EQ(retPresentState, presentState);
2297 EXPECT_EQ(retPreviousState, previousState);
2298}
2299
2300TEST(PlatformEventMessage, testBadSensorOpEventDataDecodeRequest)
2301{
2302 uint8_t presentOpState;
2303 uint8_t previousOpState;
2304 size_t sensorDataLength = PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH;
2305 auto rc = decode_sensor_op_data(NULL, sensorDataLength, &presentOpState,
2306 &previousOpState);
2307 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2308
2309 std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH>
2310 sensorData{};
2311 rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData.data()),
2312 sensorDataLength + 1, &presentOpState,
2313 &previousOpState);
2314 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2315
2316 rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData.data()),
2317 sensorDataLength, nullptr, &previousOpState);
2318 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2319}
2320
2321TEST(PlatformEventMessage, testGoodSensorStateEventDataDecodeRequest)
2322{
2323 std::array<uint8_t, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH>
2324 eventDataArr{};
2325
2326 struct pldm_sensor_event_state_sensor_state* sensorData =
2327 (struct pldm_sensor_event_state_sensor_state*)eventDataArr.data();
2328 uint8_t sensorOffset = 0x02;
2329 uint8_t eventState = PLDM_SENSOR_SHUTTINGDOWN;
2330 uint8_t previousEventState = PLDM_SENSOR_INTEST;
2331 sensorData->sensor_offset = sensorOffset;
2332 sensorData->event_state = eventState;
2333 sensorData->previous_event_state = previousEventState;
2334
2335 uint8_t retSensorOffset;
2336 uint8_t retEventState;
2337 uint8_t retPreviousState;
2338 auto rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData),
2339 eventDataArr.size(), &retSensorOffset,
2340 &retEventState, &retPreviousState);
2341 EXPECT_EQ(rc, PLDM_SUCCESS);
2342 EXPECT_EQ(retSensorOffset, sensorOffset);
2343 EXPECT_EQ(retEventState, eventState);
2344 EXPECT_EQ(retPreviousState, previousEventState);
2345}
2346
2347TEST(PlatformEventMessage, testBadStateSensorEventDataDecodeRequest)
2348{
2349 uint8_t sensorOffset;
2350 uint8_t eventState;
2351 uint8_t previousEventState;
2352 size_t sensorDataLength = PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH;
2353 auto rc = decode_state_sensor_data(NULL, sensorDataLength, &sensorOffset,
2354 &eventState, &previousEventState);
2355 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2356
2357 std::array<uint8_t, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH>
2358 sensorData{};
2359 rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData.data()),
2360 sensorDataLength - 1, &sensorOffset,
2361 &eventState, &previousEventState);
2362 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2363
2364 rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData.data()),
2365 sensorDataLength, &sensorOffset, nullptr,
2366 &previousEventState);
2367 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2368}
2369
2370TEST(PlatformEventMessage, testGoodNumericSensorEventDataDecodeRequest)
2371{
2372 std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH>
2373 eventDataArr{};
2374 struct pldm_sensor_event_numeric_sensor_state* sensorData =
2375 (struct pldm_sensor_event_numeric_sensor_state*)eventDataArr.data();
2376
2377 size_t sensorDataLength =
2378 PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_32BIT_DATA_LENGTH;
2379 uint8_t eventState = PLDM_SENSOR_SHUTTINGDOWN;
2380 uint8_t previousEventState = PLDM_SENSOR_INTEST;
2381 uint8_t sensorDataSize = PLDM_SENSOR_DATA_SIZE_UINT32;
2382 uint32_t presentReading = 305441741;
2383 sensorData->event_state = eventState;
2384 sensorData->previous_event_state = previousEventState;
2385 sensorData->sensor_data_size = sensorDataSize;
Andrew Jeffery92f6c3c2023-04-13 15:50:10 +09302386 {
2387 uint32_t presentReadingLE = htole32(presentReading);
2388 memcpy(&sensorData->present_reading, &presentReadingLE,
2389 sizeof(presentReadingLE));
2390 }
Andrew Jeffery9c766792022-08-10 23:12:49 +09302391
2392 uint8_t retEventState;
2393 uint8_t retPreviousEventState;
2394 uint8_t retSensorDataSize;
2395 uint32_t retPresentReading;
2396
2397 auto rc = decode_numeric_sensor_data(
2398 reinterpret_cast<uint8_t*>(sensorData), sensorDataLength,
2399 &retEventState, &retPreviousEventState, &retSensorDataSize,
2400 &retPresentReading);
2401 EXPECT_EQ(rc, PLDM_SUCCESS);
2402 EXPECT_EQ(retEventState, eventState);
2403 EXPECT_EQ(retPreviousEventState, previousEventState);
2404 EXPECT_EQ(retSensorDataSize, sensorDataSize);
2405 EXPECT_EQ(retPresentReading, presentReading);
2406
2407 int16_t presentReadingNew = -31432;
Andrew Jeffery92f6c3c2023-04-13 15:50:10 +09302408 {
2409 int16_t presentReadingNewLE = htole16(presentReadingNew);
2410 memcpy(&sensorData->present_reading, &presentReadingNewLE,
2411 sizeof(presentReadingNewLE));
2412 }
Andrew Jeffery9c766792022-08-10 23:12:49 +09302413 sensorDataSize = PLDM_SENSOR_DATA_SIZE_SINT16;
2414 sensorData->sensor_data_size = sensorDataSize;
2415 sensorDataLength = PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_16BIT_DATA_LENGTH;
2416
2417 rc = decode_numeric_sensor_data(reinterpret_cast<uint8_t*>(sensorData),
2418 sensorDataLength, &retEventState,
2419 &retPreviousEventState, &retSensorDataSize,
2420 &retPresentReading);
2421 EXPECT_EQ(rc, PLDM_SUCCESS);
2422 EXPECT_EQ(retEventState, eventState);
2423 EXPECT_EQ(retPreviousEventState, previousEventState);
2424 EXPECT_EQ(retSensorDataSize, sensorDataSize);
2425 EXPECT_EQ(static_cast<int16_t>(retPresentReading), presentReadingNew);
2426}
2427
2428TEST(PlatformEventMessage, testBadNumericSensorEventDataDecodeRequest)
2429{
2430 uint8_t eventState;
2431 uint8_t previousEventState;
2432 uint8_t sensorDataSize;
2433 uint32_t presentReading;
2434 size_t sensorDataLength =
2435 PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH;
2436 auto rc = decode_numeric_sensor_data(NULL, sensorDataLength, &eventState,
2437 &previousEventState, &sensorDataSize,
2438 &presentReading);
2439 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2440
2441 std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH>
2442 sensorData{};
2443 rc = decode_numeric_sensor_data(
2444 reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength - 1,
2445 &eventState, &previousEventState, &sensorDataSize, &presentReading);
2446 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2447
2448 struct pldm_sensor_event_numeric_sensor_state* numericSensorData =
2449 (struct pldm_sensor_event_numeric_sensor_state*)sensorData.data();
2450 numericSensorData->sensor_data_size = PLDM_SENSOR_DATA_SIZE_UINT8;
2451 rc = decode_numeric_sensor_data(
2452 reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength,
2453 &eventState, &previousEventState, &sensorDataSize, &presentReading);
2454 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2455
2456 numericSensorData->sensor_data_size = PLDM_SENSOR_DATA_SIZE_UINT16;
2457 rc = decode_numeric_sensor_data(
2458 reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength,
2459 &eventState, &previousEventState, &sensorDataSize, &presentReading);
2460 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302461}
2462
2463TEST(GetNumericEffecterValue, testGoodEncodeRequest)
2464{
2465 std::vector<uint8_t> requestMsg(hdrSize +
2466 PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES);
2467
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002468 uint16_t effecter_id = 0xab01;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302469
2470 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2471
2472 auto rc = encode_get_numeric_effecter_value_req(0, effecter_id, request);
2473
2474 struct pldm_get_numeric_effecter_value_req* req =
2475 reinterpret_cast<struct pldm_get_numeric_effecter_value_req*>(
2476 request->payload);
2477
2478 EXPECT_EQ(rc, PLDM_SUCCESS);
2479 EXPECT_EQ(effecter_id, le16toh(req->effecter_id));
2480}
2481
2482TEST(GetNumericEffecterValue, testBadEncodeRequest)
2483{
2484 std::vector<uint8_t> requestMsg(
2485 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
2486
2487 auto rc = encode_get_numeric_effecter_value_req(0, 0, nullptr);
2488 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2489}
2490
2491TEST(GetNumericEffecterValue, testGoodDecodeRequest)
2492{
2493 std::array<uint8_t, hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES>
2494 requestMsg{};
2495
2496 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2497 struct pldm_get_numeric_effecter_value_req* req =
2498 reinterpret_cast<struct pldm_get_numeric_effecter_value_req*>(
2499 request->payload);
2500
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002501 uint16_t effecter_id = 0x12ab;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302502 req->effecter_id = htole16(effecter_id);
2503
2504 uint16_t reteffecter_id;
2505
2506 auto rc = decode_get_numeric_effecter_value_req(
2507 request, requestMsg.size() - hdrSize, &reteffecter_id);
2508
2509 EXPECT_EQ(rc, PLDM_SUCCESS);
2510 EXPECT_EQ(effecter_id, reteffecter_id);
2511}
2512
2513TEST(GetNumericEffecterValue, testBadDecodeRequest)
2514{
2515 std::array<uint8_t, hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES>
2516 requestMsg{};
2517
2518 auto rc = decode_get_numeric_effecter_value_req(
2519 nullptr, requestMsg.size() - hdrSize, nullptr);
2520
2521 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2522
2523 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2524 struct pldm_set_numeric_effecter_value_req* req =
2525 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
2526 request->payload);
2527
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002528 uint16_t effecter_id = 0x1a;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302529 req->effecter_id = htole16(effecter_id);
2530 uint16_t reteffecter_id;
2531
2532 rc = decode_get_numeric_effecter_value_req(
2533 request, requestMsg.size() - hdrSize - 1, &reteffecter_id);
2534
2535 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2536}
2537
2538TEST(GetNumericEffecterValue, testGoodEncodeResponse)
2539{
2540 uint8_t completionCode = 0;
2541 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT32;
2542 uint8_t effecter_operState = EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING;
2543 uint32_t pendingValue = 0x12345678;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002544 uint32_t presentValue = 0xabcdef11;
Andrew Jefferyf990dcf2023-04-12 20:54:48 +09302545 uint32_t val_pending;
2546 uint32_t val_present;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302547
2548 std::array<uint8_t,
2549 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6>
2550 responseMsg{};
2551 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2552
2553 auto rc = encode_get_numeric_effecter_value_resp(
2554 0, completionCode, effecter_dataSize, effecter_operState,
2555 reinterpret_cast<uint8_t*>(&pendingValue),
2556 reinterpret_cast<uint8_t*>(&presentValue), response,
2557 responseMsg.size() - hdrSize);
2558
2559 struct pldm_get_numeric_effecter_value_resp* resp =
2560 reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>(
2561 response->payload);
2562
Andrew Jefferyf990dcf2023-04-12 20:54:48 +09302563 memcpy(&val_pending, &resp->pending_and_present_values[0],
2564 sizeof(val_pending));
2565 val_pending = le32toh(val_pending);
2566 memcpy(&val_present, &resp->pending_and_present_values[4],
2567 sizeof(val_present));
2568 val_present = le32toh(val_present);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302569
2570 EXPECT_EQ(rc, PLDM_SUCCESS);
2571 EXPECT_EQ(effecter_dataSize, resp->effecter_data_size);
2572 EXPECT_EQ(effecter_operState, resp->effecter_oper_state);
Andrew Jefferyf990dcf2023-04-12 20:54:48 +09302573 EXPECT_EQ(pendingValue, val_pending);
2574 EXPECT_EQ(presentValue, val_present);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302575}
2576
2577TEST(GetNumericEffecterValue, testBadEncodeResponse)
2578{
2579 std::array<uint8_t,
2580 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2>
2581 responseMsg{};
2582 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2583
2584 uint8_t pendingValue = 0x01;
2585 uint8_t presentValue = 0x02;
2586
2587 auto rc = encode_get_numeric_effecter_value_resp(
2588 0, PLDM_SUCCESS, 0, 0, nullptr, nullptr, nullptr,
2589 responseMsg.size() - hdrSize);
2590 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2591
2592 rc = encode_get_numeric_effecter_value_resp(
2593 0, PLDM_SUCCESS, 6, 9, reinterpret_cast<uint8_t*>(&pendingValue),
2594 reinterpret_cast<uint8_t*>(&presentValue), response,
2595 responseMsg.size() - hdrSize);
2596 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2597
2598 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
2599 uint8_t effecter_operState = EFFECTER_OPER_STATE_FAILED;
2600
2601 rc = encode_get_numeric_effecter_value_resp(
2602 0, PLDM_SUCCESS, effecter_dataSize, effecter_operState,
2603 reinterpret_cast<uint8_t*>(&pendingValue),
2604 reinterpret_cast<uint8_t*>(&presentValue), response,
2605 responseMsg.size() - hdrSize);
2606 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2607}
2608
2609TEST(GetNumericEffecterValue, testGoodDecodeResponse)
2610{
2611 std::array<uint8_t,
2612 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2>
2613 responseMsg{};
2614
2615 uint8_t completionCode = 0;
2616 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT16;
2617 uint8_t effecter_operState = EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING;
2618 uint16_t pendingValue = 0x4321;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002619 uint16_t presentValue = 0xdcba;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302620
2621 uint8_t retcompletionCode;
2622 uint8_t reteffecter_dataSize;
2623 uint8_t reteffecter_operState;
2624 uint8_t retpendingValue[2];
2625 uint8_t retpresentValue[2];
2626
2627 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2628 struct pldm_get_numeric_effecter_value_resp* resp =
2629 reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>(
2630 response->payload);
2631
2632 resp->completion_code = completionCode;
2633 resp->effecter_data_size = effecter_dataSize;
2634 resp->effecter_oper_state = effecter_operState;
2635
2636 uint16_t pendingValue_le = htole16(pendingValue);
2637 memcpy(resp->pending_and_present_values, &pendingValue_le,
2638 sizeof(pendingValue_le));
2639 uint16_t presentValue_le = htole16(presentValue);
2640 memcpy(&resp->pending_and_present_values[2], &presentValue_le,
2641 sizeof(presentValue_le));
2642
2643 auto rc = decode_get_numeric_effecter_value_resp(
2644 response, responseMsg.size() - hdrSize, &retcompletionCode,
2645 &reteffecter_dataSize, &reteffecter_operState, retpendingValue,
2646 retpresentValue);
2647
2648 EXPECT_EQ(rc, PLDM_SUCCESS);
2649 EXPECT_EQ(completionCode, retcompletionCode);
2650 EXPECT_EQ(effecter_dataSize, reteffecter_dataSize);
2651 EXPECT_EQ(effecter_operState, reteffecter_operState);
2652 EXPECT_EQ(pendingValue, *(reinterpret_cast<uint16_t*>(retpendingValue)));
2653 EXPECT_EQ(presentValue, *(reinterpret_cast<uint16_t*>(retpresentValue)));
2654}
2655
2656TEST(GetNumericEffecterValue, testBadDecodeResponse)
2657{
2658 std::array<uint8_t,
2659 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6>
2660 responseMsg{};
2661
2662 auto rc = decode_get_numeric_effecter_value_resp(
2663 nullptr, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr,
2664 nullptr, nullptr);
2665
2666 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2667
2668 uint8_t completionCode = 0;
2669 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_SINT16;
2670 uint8_t effecter_operState = EFFECTER_OPER_STATE_DISABLED;
2671 uint16_t pendingValue = 0x5678;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002672 uint16_t presentValue = 0xcdef;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302673
2674 uint8_t retcompletionCode;
2675 uint8_t reteffecter_dataSize;
2676 uint8_t reteffecter_operState;
2677 uint8_t retpendingValue[2];
2678 uint8_t retpresentValue[2];
2679
2680 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2681 struct pldm_get_numeric_effecter_value_resp* resp =
2682 reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>(
2683 response->payload);
2684
2685 resp->completion_code = completionCode;
2686 resp->effecter_data_size = effecter_dataSize;
2687 resp->effecter_oper_state = effecter_operState;
2688
2689 uint16_t pendingValue_le = htole16(pendingValue);
2690 memcpy(resp->pending_and_present_values, &pendingValue_le,
2691 sizeof(pendingValue_le));
2692 uint16_t presentValue_le = htole16(presentValue);
2693 memcpy(&resp->pending_and_present_values[2], &presentValue_le,
2694 sizeof(presentValue_le));
2695
2696 rc = decode_get_numeric_effecter_value_resp(
2697 response, responseMsg.size() - hdrSize, &retcompletionCode,
2698 &reteffecter_dataSize, &reteffecter_operState, retpendingValue,
2699 retpresentValue);
2700
2701 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2702}
2703
2704TEST(PldmPDRRepositoryChgEventEvent, testGoodDecodeRequest)
2705{
2706 const uint8_t eventDataFormat = FORMAT_IS_PDR_HANDLES;
2707 const uint8_t numberOfChangeRecords = 2;
2708 uint8_t eventDataOperation1 = PLDM_RECORDS_DELETED;
2709 const uint8_t numberOfChangeEntries1 = 2;
2710 std::array<uint32_t, numberOfChangeEntries1> changeRecordArr1{
2711 {0x00000000, 0x12345678}};
2712 uint8_t eventDataOperation2 = PLDM_RECORDS_ADDED;
2713 const uint8_t numberOfChangeEntries2 = 5;
2714 std::array<uint32_t, numberOfChangeEntries2> changeRecordArr2{
2715 {0x01234567, 0x11223344, 0x45678901, 0x21222324, 0x98765432}};
2716 std::array<uint8_t, PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH +
2717 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH *
2718 numberOfChangeRecords +
2719 (numberOfChangeEntries1 + numberOfChangeEntries2) *
2720 sizeof(uint32_t)>
2721 eventDataArr{};
2722
2723 struct pldm_pdr_repository_chg_event_data* eventData =
2724 reinterpret_cast<struct pldm_pdr_repository_chg_event_data*>(
2725 eventDataArr.data());
2726 eventData->event_data_format = eventDataFormat;
2727 eventData->number_of_change_records = numberOfChangeRecords;
2728 struct pldm_pdr_repository_change_record_data* changeRecord1 =
2729 reinterpret_cast<struct pldm_pdr_repository_change_record_data*>(
2730 eventData->change_records);
2731 changeRecord1->event_data_operation = eventDataOperation1;
2732 changeRecord1->number_of_change_entries = numberOfChangeEntries1;
2733 memcpy(changeRecord1->change_entry, &changeRecordArr1[0],
2734 changeRecordArr1.size() * sizeof(uint32_t));
2735 struct pldm_pdr_repository_change_record_data* changeRecord2 =
2736 reinterpret_cast<struct pldm_pdr_repository_change_record_data*>(
2737 eventData->change_records +
2738 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH +
2739 (changeRecordArr1.size() * sizeof(uint32_t)));
2740 changeRecord2->event_data_operation = eventDataOperation2;
2741 changeRecord2->number_of_change_entries = numberOfChangeEntries2;
2742 memcpy(changeRecord2->change_entry, &changeRecordArr2[0],
2743 changeRecordArr2.size() * sizeof(uint32_t));
2744
2745 uint8_t retEventDataFormat{};
2746 uint8_t retNumberOfChangeRecords{};
2747 size_t retChangeRecordDataOffset{0};
2748 auto rc = decode_pldm_pdr_repository_chg_event_data(
2749 reinterpret_cast<const uint8_t*>(eventData), eventDataArr.size(),
2750 &retEventDataFormat, &retNumberOfChangeRecords,
2751 &retChangeRecordDataOffset);
2752 EXPECT_EQ(rc, PLDM_SUCCESS);
2753 EXPECT_EQ(retEventDataFormat, FORMAT_IS_PDR_HANDLES);
2754 EXPECT_EQ(retNumberOfChangeRecords, numberOfChangeRecords);
2755
2756 const uint8_t* changeRecordData =
2757 reinterpret_cast<const uint8_t*>(changeRecord1);
2758 size_t changeRecordDataSize =
2759 eventDataArr.size() - PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH;
2760 uint8_t retEventDataOperation;
2761 uint8_t retNumberOfChangeEntries;
2762 size_t retChangeEntryDataOffset;
2763
2764 rc = decode_pldm_pdr_repository_change_record_data(
2765 reinterpret_cast<const uint8_t*>(changeRecordData),
2766 changeRecordDataSize, &retEventDataOperation, &retNumberOfChangeEntries,
2767 &retChangeEntryDataOffset);
2768 EXPECT_EQ(rc, PLDM_SUCCESS);
2769 EXPECT_EQ(retEventDataOperation, eventDataOperation1);
2770 EXPECT_EQ(retNumberOfChangeEntries, numberOfChangeEntries1);
2771 changeRecordData += retChangeEntryDataOffset;
2772 EXPECT_EQ(0, memcmp(changeRecordData, &changeRecordArr1[0],
2773 sizeof(uint32_t) * retNumberOfChangeEntries));
2774
2775 changeRecordData += sizeof(uint32_t) * retNumberOfChangeEntries;
2776 changeRecordDataSize -= sizeof(uint32_t) * retNumberOfChangeEntries -
2777 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH;
2778 rc = decode_pldm_pdr_repository_change_record_data(
2779 reinterpret_cast<const uint8_t*>(changeRecordData),
2780 changeRecordDataSize, &retEventDataOperation, &retNumberOfChangeEntries,
2781 &retChangeEntryDataOffset);
2782 EXPECT_EQ(rc, PLDM_SUCCESS);
2783 EXPECT_EQ(retEventDataOperation, eventDataOperation2);
2784 EXPECT_EQ(retNumberOfChangeEntries, numberOfChangeEntries2);
2785 changeRecordData += retChangeEntryDataOffset;
2786 EXPECT_EQ(0, memcmp(changeRecordData, &changeRecordArr2[0],
2787 sizeof(uint32_t) * retNumberOfChangeEntries));
2788}
2789
2790TEST(PldmPDRRepositoryChgEventEvent, testBadDecodeRequest)
2791{
2792 uint8_t eventDataFormat{};
2793 uint8_t numberOfChangeRecords{};
2794 size_t changeRecordDataOffset{};
2795 auto rc = decode_pldm_pdr_repository_chg_event_data(
2796 NULL, 0, &eventDataFormat, &numberOfChangeRecords,
2797 &changeRecordDataOffset);
2798 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2799
2800 std::array<uint8_t, 2> eventData{};
2801 rc = decode_pldm_pdr_repository_chg_event_data(
2802 reinterpret_cast<const uint8_t*>(eventData.data()), 0, &eventDataFormat,
2803 &numberOfChangeRecords, &changeRecordDataOffset);
2804 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2805
2806 uint8_t eventDataOperation{};
2807 uint8_t numberOfChangeEntries{};
2808 size_t changeEntryDataOffset{};
2809 rc = decode_pldm_pdr_repository_change_record_data(
2810 NULL, 0, &eventDataOperation, &numberOfChangeEntries,
2811 &changeEntryDataOffset);
2812 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2813
2814 std::array<uint8_t, 2> changeRecord{};
2815 rc = decode_pldm_pdr_repository_change_record_data(
2816 reinterpret_cast<const uint8_t*>(changeRecord.data()), 0,
2817 &eventDataOperation, &numberOfChangeEntries, &changeEntryDataOffset);
2818 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2819}
2820
2821TEST(GetSensorReading, testGoodEncodeRequest)
2822{
2823 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES>
2824 requestMsg{};
2825
2826 uint16_t sensorId = 0x1234;
2827 bool8_t rearmEventState = 0x01;
2828
2829 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2830 auto rc =
2831 encode_get_sensor_reading_req(0, sensorId, rearmEventState, request);
2832
2833 struct pldm_get_sensor_reading_req* req =
2834 reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload);
2835
2836 EXPECT_EQ(rc, PLDM_SUCCESS);
2837 EXPECT_EQ(sensorId, le16toh(req->sensor_id));
2838 EXPECT_EQ(rearmEventState, req->rearm_event_state);
2839}
2840
2841TEST(GetSensorReading, testBadEncodeRequest)
2842{
2843 auto rc = encode_get_sensor_reading_req(0, 0, 0, nullptr);
2844
2845 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2846}
2847
2848TEST(GetSensorReading, testGoodDecodeRequest)
2849{
2850 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES>
2851 requestMsg{};
2852
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002853 uint16_t sensorId = 0xabcd;
2854 bool8_t rearmEventState = 0xa;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302855
2856 uint16_t retsensorId;
2857 bool8_t retrearmEventState;
2858
2859 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2860
2861 struct pldm_get_sensor_reading_req* req =
2862 reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload);
2863
2864 req->sensor_id = htole16(sensorId);
2865 req->rearm_event_state = rearmEventState;
2866
2867 auto rc =
2868 decode_get_sensor_reading_req(request, requestMsg.size() - hdrSize,
2869 &retsensorId, &retrearmEventState);
2870
2871 EXPECT_EQ(rc, PLDM_SUCCESS);
2872 EXPECT_EQ(sensorId, retsensorId);
2873 EXPECT_EQ(rearmEventState, retrearmEventState);
2874}
2875
2876TEST(GetSensorReading, testBadDecodeRequest)
2877{
2878 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES>
2879 requestMsg{};
2880
2881 auto rc = decode_get_sensor_reading_req(
2882 nullptr, requestMsg.size() - hdrSize, nullptr, nullptr);
2883 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2884
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002885 uint16_t sensorId = 0xabcd;
2886 bool8_t rearmEventState = 0xa;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302887
2888 uint16_t retsensorId;
2889 bool8_t retrearmEventState;
2890
2891 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2892
2893 struct pldm_get_sensor_reading_req* req =
2894 reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload);
2895
2896 req->sensor_id = htole16(sensorId);
2897 req->rearm_event_state = rearmEventState;
2898
2899 rc = decode_get_sensor_reading_req(request, requestMsg.size() - hdrSize - 1,
2900 &retsensorId, &retrearmEventState);
2901
2902 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2903}
2904
2905TEST(GetSensorReading, testGoodEncodeResponse)
2906{
2907 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES>
2908 responseMsg{};
2909
2910 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2911
2912 uint8_t completionCode = 0;
2913 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
2914 uint8_t sensor_operationalState = PLDM_SENSOR_ENABLED;
2915 uint8_t sensor_event_messageEnable = PLDM_NO_EVENT_GENERATION;
2916 uint8_t presentState = PLDM_SENSOR_NORMAL;
2917 uint8_t previousState = PLDM_SENSOR_WARNING;
2918 uint8_t eventState = PLDM_SENSOR_UPPERWARNING;
2919 uint8_t presentReading = 0x21;
2920
2921 auto rc = encode_get_sensor_reading_resp(
2922 0, completionCode, sensor_dataSize, sensor_operationalState,
2923 sensor_event_messageEnable, presentState, previousState, eventState,
2924 reinterpret_cast<uint8_t*>(&presentReading), response,
2925 responseMsg.size() - hdrSize);
2926
2927 struct pldm_get_sensor_reading_resp* resp =
2928 reinterpret_cast<struct pldm_get_sensor_reading_resp*>(
2929 response->payload);
2930
2931 EXPECT_EQ(rc, PLDM_SUCCESS);
2932 EXPECT_EQ(completionCode, resp->completion_code);
2933 EXPECT_EQ(sensor_dataSize, resp->sensor_data_size);
2934 EXPECT_EQ(sensor_operationalState, resp->sensor_operational_state);
2935 EXPECT_EQ(sensor_event_messageEnable, resp->sensor_event_message_enable);
2936 EXPECT_EQ(presentState, resp->present_state);
2937 EXPECT_EQ(previousState, resp->previous_state);
2938 EXPECT_EQ(eventState, resp->event_state);
2939 EXPECT_EQ(presentReading,
2940 *(reinterpret_cast<uint8_t*>(&resp->present_reading[0])));
2941}
2942
2943TEST(GetSensorReading, testBadEncodeResponse)
2944{
2945 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3>
2946 responseMsg{};
2947
2948 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2949
2950 uint8_t presentReading = 0x1;
2951
2952 auto rc = encode_get_sensor_reading_resp(0, PLDM_SUCCESS, 0, 0, 0, 0, 0, 0,
2953 nullptr, nullptr,
2954 responseMsg.size() - hdrSize);
2955 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2956
2957 rc = encode_get_sensor_reading_resp(
2958 0, PLDM_SUCCESS, 6, 1, 1, 1, 1, 1,
2959 reinterpret_cast<uint8_t*>(&presentReading), response,
2960 responseMsg.size() - hdrSize);
2961 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2962
2963 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
2964
2965 rc = encode_get_sensor_reading_resp(
2966 0, PLDM_SUCCESS, sensor_dataSize, 1, 1, 1, 1, 1,
2967 reinterpret_cast<uint8_t*>(&presentReading), response,
2968 responseMsg.size() - hdrSize);
2969 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2970}
2971
2972TEST(GetSensorReading, testGoodDecodeResponse)
2973{
2974 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3>
2975 responseMsg{};
2976
2977 uint8_t completionCode = 0;
2978 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT32;
2979 uint8_t sensor_operationalState = PLDM_SENSOR_STATUSUNKOWN;
2980 uint8_t sensor_event_messageEnable = PLDM_EVENTS_ENABLED;
2981 uint8_t presentState = PLDM_SENSOR_CRITICAL;
2982 uint8_t previousState = PLDM_SENSOR_UPPERCRITICAL;
2983 uint8_t eventState = PLDM_SENSOR_WARNING;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002984 uint32_t presentReading = 0xabcdef11;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302985
2986 uint8_t retcompletionCode;
2987 uint8_t retsensor_dataSize = PLDM_SENSOR_DATA_SIZE_UINT32;
2988 uint8_t retsensor_operationalState;
2989 uint8_t retsensor_event_messageEnable;
2990 uint8_t retpresentState;
2991 uint8_t retpreviousState;
2992 uint8_t reteventState;
2993 uint8_t retpresentReading[4];
2994
2995 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2996 struct pldm_get_sensor_reading_resp* resp =
2997 reinterpret_cast<struct pldm_get_sensor_reading_resp*>(
2998 response->payload);
2999
3000 resp->completion_code = completionCode;
3001 resp->sensor_data_size = sensor_dataSize;
3002 resp->sensor_operational_state = sensor_operationalState;
3003 resp->sensor_event_message_enable = sensor_event_messageEnable;
3004 resp->present_state = presentState;
3005 resp->previous_state = previousState;
3006 resp->event_state = eventState;
3007
3008 uint32_t presentReading_le = htole32(presentReading);
3009 memcpy(resp->present_reading, &presentReading_le,
3010 sizeof(presentReading_le));
3011
3012 auto rc = decode_get_sensor_reading_resp(
3013 response, responseMsg.size() - hdrSize, &retcompletionCode,
3014 &retsensor_dataSize, &retsensor_operationalState,
3015 &retsensor_event_messageEnable, &retpresentState, &retpreviousState,
3016 &reteventState, retpresentReading);
3017
3018 EXPECT_EQ(rc, PLDM_SUCCESS);
3019 EXPECT_EQ(completionCode, retcompletionCode);
3020 EXPECT_EQ(sensor_dataSize, retsensor_dataSize);
3021 EXPECT_EQ(sensor_operationalState, retsensor_operationalState);
3022 EXPECT_EQ(sensor_event_messageEnable, retsensor_event_messageEnable);
3023 EXPECT_EQ(presentState, retpresentState);
3024 EXPECT_EQ(previousState, retpreviousState);
3025 EXPECT_EQ(eventState, reteventState);
3026 EXPECT_EQ(presentReading,
3027 *(reinterpret_cast<uint32_t*>(retpresentReading)));
3028}
3029
3030TEST(GetSensorReading, testBadDecodeResponse)
3031{
3032 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 1>
3033 responseMsg{};
3034
3035 auto rc = decode_get_sensor_reading_resp(
3036 nullptr, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr,
3037 nullptr, nullptr, nullptr, nullptr, nullptr);
3038
3039 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3040
3041 uint8_t completionCode = 0;
3042 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
3043 uint8_t sensor_operationalState = PLDM_SENSOR_INTEST;
3044 uint8_t sensor_event_messageEnable = PLDM_EVENTS_DISABLED;
3045 uint8_t presentState = PLDM_SENSOR_FATAL;
3046 uint8_t previousState = PLDM_SENSOR_UPPERFATAL;
3047 uint8_t eventState = PLDM_SENSOR_WARNING;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06003048 uint8_t presentReading = 0xa;
Andrew Jeffery9c766792022-08-10 23:12:49 +09303049
3050 uint8_t retcompletionCode;
3051 uint8_t retsensor_dataSize = PLDM_SENSOR_DATA_SIZE_SINT16;
3052 uint8_t retsensor_operationalState;
3053 uint8_t retsensor_event_messageEnable;
3054 uint8_t retpresent_state;
3055 uint8_t retprevious_state;
3056 uint8_t retevent_state;
3057 uint8_t retpresentReading;
3058
3059 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3060 struct pldm_get_sensor_reading_resp* resp =
3061 reinterpret_cast<struct pldm_get_sensor_reading_resp*>(
3062 response->payload);
3063
3064 resp->completion_code = completionCode;
3065 resp->sensor_data_size = sensor_dataSize;
3066 resp->sensor_operational_state = sensor_operationalState;
3067 resp->sensor_event_message_enable = sensor_event_messageEnable;
3068 resp->present_state = presentState;
3069 resp->previous_state = previousState;
3070 resp->event_state = eventState;
3071 resp->present_reading[0] = presentReading;
3072
3073 rc = decode_get_sensor_reading_resp(
3074 response, responseMsg.size() - hdrSize, &retcompletionCode,
3075 &retsensor_dataSize, &retsensor_operationalState,
3076 &retsensor_event_messageEnable, &retpresent_state, &retprevious_state,
3077 &retevent_state, reinterpret_cast<uint8_t*>(&retpresentReading));
3078
3079 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3080}
3081
3082TEST(SetEventReceiver, testGoodEncodeRequest)
3083{
3084 uint8_t eventMessageGlobalEnable =
3085 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
3086 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
3087 uint8_t eventReceiverAddressInfo = 0x08;
3088 uint16_t heartbeatTimer = 0x78;
3089
3090 std::vector<uint8_t> requestMsg(hdrSize +
3091 PLDM_SET_EVENT_RECEIVER_REQ_BYTES);
3092 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
3093
3094 auto rc = encode_set_event_receiver_req(
3095 0, eventMessageGlobalEnable, transportProtocolType,
3096 eventReceiverAddressInfo, heartbeatTimer, request);
3097
3098 EXPECT_EQ(rc, PLDM_SUCCESS);
3099 struct pldm_set_event_receiver_req* req =
3100 reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
3101 EXPECT_EQ(eventMessageGlobalEnable, req->event_message_global_enable);
3102 EXPECT_EQ(transportProtocolType, req->transport_protocol_type);
3103 EXPECT_EQ(eventReceiverAddressInfo, req->event_receiver_address_info);
3104 EXPECT_EQ(heartbeatTimer, le16toh(req->heartbeat_timer));
3105}
3106
3107TEST(SetEventReceiver, testBadEncodeRequest)
3108{
3109 uint8_t eventMessageGlobalEnable =
3110 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
3111 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
3112 uint8_t eventReceiverAddressInfo = 0x08;
3113 uint16_t heartbeatTimer = 0;
3114
3115 std::vector<uint8_t> requestMsg(hdrSize +
3116 PLDM_SET_EVENT_RECEIVER_REQ_BYTES);
3117 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
3118
3119 auto rc = encode_set_event_receiver_req(
3120 0, eventMessageGlobalEnable, transportProtocolType,
3121 eventReceiverAddressInfo, heartbeatTimer, request);
3122
3123 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3124}
3125
3126TEST(SetEventReceiver, testGoodDecodeResponse)
3127{
3128 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_RESP_BYTES>
3129 responseMsg{};
3130
3131 uint8_t retcompletion_code = 0;
3132 responseMsg[hdrSize] = PLDM_SUCCESS;
3133
3134 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3135 auto rc = decode_set_event_receiver_resp(
3136 response, responseMsg.size() - sizeof(pldm_msg_hdr),
3137 &retcompletion_code);
3138
3139 EXPECT_EQ(rc, PLDM_SUCCESS);
3140 EXPECT_EQ(PLDM_SUCCESS, retcompletion_code);
3141}
3142
3143TEST(SetEventReceiver, testBadDecodeResponse)
3144{
3145 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_RESP_BYTES>
3146 responseMsg{};
3147 uint8_t retcompletion_code = 0;
3148 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3149
3150 auto rc = decode_set_event_receiver_resp(
3151 response, responseMsg.size() - sizeof(pldm_msg_hdr), NULL);
3152
3153 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3154
3155 rc = decode_set_event_receiver_resp(
3156 nullptr, responseMsg.size() - sizeof(pldm_msg_hdr),
3157 &retcompletion_code);
3158
3159 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3160}
3161
3162TEST(SetEventReceiver, testGoodEncodeResponse)
3163{
3164 std::array<uint8_t,
3165 sizeof(pldm_msg_hdr) + PLDM_SET_EVENT_RECEIVER_RESP_BYTES>
3166 responseMsg{};
3167 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3168 uint8_t completionCode = 0;
3169
3170 auto rc = encode_set_event_receiver_resp(0, PLDM_SUCCESS, response);
3171
3172 EXPECT_EQ(rc, PLDM_SUCCESS);
3173 EXPECT_EQ(completionCode, response->payload[0]);
3174}
3175
3176TEST(SetEventReceiver, testBadEncodeResponse)
3177{
3178 auto rc = encode_set_event_receiver_resp(0, PLDM_SUCCESS, NULL);
3179 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3180}
3181
3182TEST(SetEventReceiver, testGoodDecodeRequest)
3183{
3184
3185 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_REQ_BYTES>
3186 requestMsg{};
3187
3188 uint8_t eventMessageGlobalEnable =
3189 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
3190 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
3191 uint8_t eventReceiverAddressInfo = 0x08;
3192 uint16_t heartbeatTimer = 0x78;
3193
3194 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
3195 struct pldm_set_event_receiver_req* req =
3196 reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
3197
3198 req->event_message_global_enable = eventMessageGlobalEnable;
3199 req->transport_protocol_type = transportProtocolType;
3200 req->event_receiver_address_info = eventReceiverAddressInfo;
3201 req->heartbeat_timer = htole16(heartbeatTimer);
3202
3203 uint8_t reteventMessageGlobalEnable;
3204 uint8_t rettransportProtocolType;
3205 uint8_t reteventReceiverAddressInfo;
3206 uint16_t retheartbeatTimer;
3207 auto rc = decode_set_event_receiver_req(
3208 request, requestMsg.size() - hdrSize, &reteventMessageGlobalEnable,
3209 &rettransportProtocolType, &reteventReceiverAddressInfo,
3210 &retheartbeatTimer);
3211
3212 EXPECT_EQ(rc, PLDM_SUCCESS);
3213 EXPECT_EQ(eventMessageGlobalEnable, reteventMessageGlobalEnable);
3214 EXPECT_EQ(transportProtocolType, rettransportProtocolType);
3215 EXPECT_EQ(eventReceiverAddressInfo, reteventReceiverAddressInfo);
3216 EXPECT_EQ(heartbeatTimer, retheartbeatTimer);
3217}
3218
3219TEST(SetEventReceiver, testBadDecodeRequest)
3220{
3221 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_REQ_BYTES>
3222 requestMsg{};
3223
3224 auto rc = decode_set_event_receiver_req(NULL, requestMsg.size() - hdrSize,
3225 NULL, NULL, NULL, NULL);
3226 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3227
3228 uint8_t eventMessageGlobalEnable =
3229 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
3230 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
3231 uint8_t eventReceiverAddressInfo = 0x08;
3232 uint16_t heartbeatTimer = 0x78;
3233
3234 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
3235 struct pldm_set_event_receiver_req* req =
3236 reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
3237
3238 req->event_message_global_enable = eventMessageGlobalEnable;
3239 req->transport_protocol_type = transportProtocolType;
3240 req->event_receiver_address_info = eventReceiverAddressInfo;
3241 req->heartbeat_timer = htole16(heartbeatTimer);
3242
3243 uint8_t reteventMessageGlobalEnable;
3244 uint8_t rettransportProtocolType;
3245 uint8_t reteventReceiverAddressInfo;
3246 uint16_t retheartbeatTimer;
3247 rc = decode_set_event_receiver_req(
3248 request, requestMsg.size() - hdrSize - 1, &reteventMessageGlobalEnable,
3249 &rettransportProtocolType, &reteventReceiverAddressInfo,
3250 &retheartbeatTimer);
3251 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3252}
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303253
3254TEST(decodeNumericSensorPdrData, Uint8Test)
3255{
3256 std::vector<uint8_t> pdr1{
3257 0x1,
3258 0x0,
3259 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303260 0x0, // record handle
3261 0x1, // PDRHeaderVersion
3262 PLDM_NUMERIC_SENSOR_PDR, // PDRType
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303263 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303264 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303265 PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH,
Andrew Jeffery01731472023-06-13 10:33:18 +09303266 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303267 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303268 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303269 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303270 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303271 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09303272 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303273 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303274 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303275 1,
3276 0, // containerID=1
3277 PLDM_NO_INIT, // sensorInit
3278 false, // sensorAuxiliaryNamesPDR
3279 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
3280 0, // unitModifier
3281 0, // rateUnit
3282 0, // baseOEMUnitHandle
3283 0, // auxUnit
3284 0, // auxUnitModifier
3285 0, // auxRateUnit
3286 0, // rel
3287 0, // auxOEMUnitHandle
3288 true, // isLinear
3289 PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize
3290 0,
3291 0,
3292 0xc0,
3293 0x3f, // resolution=1.5
3294 0,
3295 0,
3296 0x80,
3297 0x3f, // offset=1.0
3298 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303299 0, // accuracy
3300 0, // plusTolerance
3301 0, // minusTolerance
3302 3, // hysteresis = 3
3303 0, // supportedThresholds
3304 0, // thresholdAndHysteresisVolatility
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303305 0,
3306 0,
3307 0x80,
3308 0x3f, // stateTransistionInterval=1.0
3309 0,
3310 0,
3311 0x80,
3312 0x3f, // updateInverval=1.0
3313 255, // maxReadable
3314 0, // minReadable
3315 PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
3316 0, // rangeFieldsupport
3317 50, // nominalValue = 50
3318 60, // normalMax = 60
3319 40, // normalMin = 40
3320 70, // warningHigh = 70
3321 30, // warningLow = 30
3322 80, // criticalHigh = 80
3323 20, // criticalLow = 20
3324 90, // fatalHigh = 90
3325 10 // fatalLow = 10
3326 };
3327
3328 struct pldm_numeric_sensor_value_pdr decodedPdr;
3329 auto rc =
3330 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
3331 EXPECT_EQ(PLDM_SUCCESS, rc);
3332 EXPECT_EQ(1, decodedPdr.hdr.record_handle);
3333 EXPECT_EQ(1, decodedPdr.hdr.version);
3334 EXPECT_EQ(PLDM_NUMERIC_SENSOR_PDR, decodedPdr.hdr.type);
3335 EXPECT_EQ(0, decodedPdr.hdr.record_change_num);
3336 EXPECT_EQ(PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH, decodedPdr.hdr.length);
3337 EXPECT_EQ(1, decodedPdr.sensor_id);
3338 EXPECT_EQ(PLDM_ENTITY_POWER_SUPPLY, decodedPdr.entity_type);
3339 EXPECT_EQ(1, decodedPdr.entity_instance_num);
3340 EXPECT_EQ(1, decodedPdr.container_id);
3341 EXPECT_EQ(PLDM_NO_INIT, decodedPdr.sensor_init);
3342 EXPECT_EQ(false, decodedPdr.sensor_auxiliary_names_pdr);
3343 EXPECT_EQ(PLDM_SENSOR_UNIT_DEGRESS_C, decodedPdr.base_unit);
3344 EXPECT_EQ(0, decodedPdr.unit_modifier);
3345 EXPECT_EQ(0, decodedPdr.rate_unit);
3346 EXPECT_EQ(0, decodedPdr.base_oem_unit_handle);
3347 EXPECT_EQ(0, decodedPdr.aux_unit);
3348 EXPECT_EQ(0, decodedPdr.aux_unit_modifier);
3349 EXPECT_EQ(0, decodedPdr.aux_rate_unit);
3350 EXPECT_EQ(0, decodedPdr.rel);
3351 EXPECT_EQ(0, decodedPdr.aux_oem_unit_handle);
3352 EXPECT_EQ(true, decodedPdr.is_linear);
3353 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_UINT8, decodedPdr.sensor_data_size);
3354 EXPECT_FLOAT_EQ(1.5f, decodedPdr.resolution);
3355 EXPECT_FLOAT_EQ(1.0f, decodedPdr.offset);
3356 EXPECT_EQ(0, decodedPdr.accuracy);
3357 EXPECT_EQ(0, decodedPdr.plus_tolerance);
3358 EXPECT_EQ(0, decodedPdr.minus_tolerance);
3359 EXPECT_EQ(3, decodedPdr.hysteresis.value_u8);
3360 EXPECT_EQ(0, decodedPdr.supported_thresholds.byte);
3361 EXPECT_EQ(0, decodedPdr.threshold_and_hysteresis_volatility.byte);
3362 EXPECT_FLOAT_EQ(1.0f, decodedPdr.state_transition_interval);
3363 EXPECT_FLOAT_EQ(1.0f, decodedPdr.update_interval);
3364 EXPECT_EQ(255, decodedPdr.max_readable.value_u8);
3365 EXPECT_EQ(0, decodedPdr.min_readable.value_u8);
3366 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT8, decodedPdr.range_field_format);
3367 EXPECT_EQ(0, decodedPdr.range_field_support.byte);
3368 EXPECT_EQ(50, decodedPdr.nominal_value.value_u8);
3369 EXPECT_EQ(60, decodedPdr.normal_max.value_u8);
3370 EXPECT_EQ(40, decodedPdr.normal_min.value_u8);
3371 EXPECT_EQ(70, decodedPdr.warning_high.value_u8);
3372 EXPECT_EQ(30, decodedPdr.warning_low.value_u8);
3373 EXPECT_EQ(80, decodedPdr.critical_high.value_u8);
3374 EXPECT_EQ(20, decodedPdr.critical_low.value_u8);
3375 EXPECT_EQ(90, decodedPdr.fatal_high.value_u8);
3376 EXPECT_EQ(10, decodedPdr.fatal_low.value_u8);
3377}
3378
3379TEST(decodeNumericSensorPdrData, Sint8Test)
3380{
3381 std::vector<uint8_t> pdr1{
3382 0x1,
3383 0x0,
3384 0x0,
3385 0x0, // record handle
3386 0x1, // PDRHeaderVersion
3387 PLDM_NUMERIC_SENSOR_PDR, // PDRType
3388 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303389 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303390 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
3391 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
3392 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
Andrew Jeffery01731472023-06-13 10:33:18 +09303393 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303394 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303395 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303396 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303397 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303398 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09303399 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303400 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303401 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303402 0x1,
3403 0x0, // containerID=1
3404 PLDM_NO_INIT, // sensorInit
3405 false, // sensorAuxiliaryNamesPDR
3406 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
3407 0, // unitModifier
3408 0, // rateUnit
3409 0, // baseOEMUnitHandle
3410 0, // auxUnit
3411 0, // auxUnitModifier
3412 0, // auxRateUnit
3413 0, // rel
3414 0, // auxOEMUnitHandle
3415 true, // isLinear
3416 PLDM_RANGE_FIELD_FORMAT_SINT8, // sensorDataSize
3417 0,
3418 0,
3419 0,
3420 0, // resolution
3421 0,
3422 0,
3423 0,
3424 0, // offset
3425 0,
3426 0, // accuracy
3427 0, // plusTolerance
3428 0, // minusTolerance
3429 3, // hysteresis = 3
3430 0, // supportedThresholds
3431 0, // thresholdAndHysteresisVolatility
3432 0,
3433 0,
3434 0x80,
3435 0x3f, // stateTransistionInterval=1.0
3436 0,
3437 0,
3438 0x80,
3439 0x3f, // updateInverval=1.0
3440 0x64, // maxReadable = 100
3441 0x9c, // minReadable = -100
3442 PLDM_RANGE_FIELD_FORMAT_SINT8, // rangeFieldFormat
3443 0, // rangeFieldsupport
3444 0, // nominalValue = 0
3445 5, // normalMax = 5
3446 0xfb, // normalMin = -5
3447 10, // warningHigh = 10
3448 0xf6, // warningLow = -10
3449 20, // criticalHigh = 20
3450 0xec, // criticalLow = -20
3451 30, // fatalHigh = 30
3452 0xe2 // fatalLow = -30
3453 };
3454
3455 struct pldm_numeric_sensor_value_pdr decodedPdr;
3456 auto rc =
3457 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
3458 EXPECT_EQ(PLDM_SUCCESS, rc);
3459
3460 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT8, decodedPdr.sensor_data_size);
3461 EXPECT_EQ(100, decodedPdr.max_readable.value_s8);
3462 EXPECT_EQ(-100, decodedPdr.min_readable.value_s8);
3463 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT8, decodedPdr.range_field_format);
3464 EXPECT_EQ(0, decodedPdr.nominal_value.value_s8);
3465 EXPECT_EQ(5, decodedPdr.normal_max.value_s8);
3466 EXPECT_EQ(-5, decodedPdr.normal_min.value_s8);
3467 EXPECT_EQ(10, decodedPdr.warning_high.value_s8);
3468 EXPECT_EQ(-10, decodedPdr.warning_low.value_s8);
3469 EXPECT_EQ(20, decodedPdr.critical_high.value_s8);
3470 EXPECT_EQ(-20, decodedPdr.critical_low.value_s8);
3471 EXPECT_EQ(30, decodedPdr.fatal_high.value_s8);
3472 EXPECT_EQ(-30, decodedPdr.fatal_low.value_s8);
3473}
3474
3475TEST(decodeNumericSensorPdrData, Uint16Test)
3476{
3477 std::vector<uint8_t> pdr1{
3478 0x1,
3479 0x0,
3480 0x0,
3481 0x0, // record handle
3482 0x1, // PDRHeaderVersion
3483 PLDM_NUMERIC_SENSOR_PDR, // PDRType
3484 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303485 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303486 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
3487 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 2 +
3488 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 2,
Andrew Jeffery01731472023-06-13 10:33:18 +09303489 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303490 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303491 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303492 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303493 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303494 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09303495 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303496 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303497 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303498 0x1,
3499 0x0, // containerID=1
3500 PLDM_NO_INIT, // sensorInit
3501 false, // sensorAuxiliaryNamesPDR
3502 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
3503 0, // unitModifier
3504 0, // rateUnit
3505 0, // baseOEMUnitHandle
3506 0, // auxUnit
3507 0, // auxUnitModifier
3508 0, // auxRateUnit
3509 0, // rel
3510 0, // auxOEMUnitHandle
3511 true, // isLinear
3512 PLDM_SENSOR_DATA_SIZE_UINT16, // sensorDataSize
3513 0,
3514 0,
3515 0,
3516 0, // resolution
3517 0,
3518 0,
3519 0,
3520 0, // offset
3521 0,
3522 0, // accuracy
3523 0, // plusTolerance
3524 0, // minusTolerance
3525 3,
3526 0, // hysteresis = 3
3527 0, // supportedThresholds
3528 0, // thresholdAndHysteresisVolatility
3529 0,
3530 0,
3531 0x80,
3532 0x3f, // stateTransistionInterval=1.0
3533 0,
3534 0,
3535 0x80,
Andrew Jeffery01731472023-06-13 10:33:18 +09303536 0x3f, // updateInverval=1.0
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303537 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303538 0x10, // maxReadable = 4096
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303539 0,
3540 0, // minReadable = 0
3541 PLDM_RANGE_FIELD_FORMAT_UINT16, // rangeFieldFormat
3542 0, // rangeFieldsupport
3543 0x88,
Andrew Jeffery01731472023-06-13 10:33:18 +09303544 0x13, // nominalValue = 5,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303545 0x70,
Andrew Jeffery01731472023-06-13 10:33:18 +09303546 0x17, // normalMax = 6,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303547 0xa0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303548 0x0f, // normalMin = 4,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303549 0x58,
Andrew Jeffery01731472023-06-13 10:33:18 +09303550 0x1b, // warningHigh = 7,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303551 0xb8,
Andrew Jeffery01731472023-06-13 10:33:18 +09303552 0x0b, // warningLow = 3,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303553 0x40,
Andrew Jeffery01731472023-06-13 10:33:18 +09303554 0x1f, // criticalHigh = 8,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303555 0xd0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303556 0x07, // criticalLow = 2,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303557 0x28,
Andrew Jeffery01731472023-06-13 10:33:18 +09303558 0x23, // fatalHigh = 9,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303559 0xe8,
Andrew Jeffery01731472023-06-13 10:33:18 +09303560 0x03 // fatalLow = 1,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303561 };
3562
3563 struct pldm_numeric_sensor_value_pdr decodedPdr;
3564 auto rc =
3565 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
3566 EXPECT_EQ(PLDM_SUCCESS, rc);
3567
3568 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_UINT16, decodedPdr.sensor_data_size);
3569 EXPECT_EQ(4096, decodedPdr.max_readable.value_u16);
3570 EXPECT_EQ(0, decodedPdr.min_readable.value_u16);
3571 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT16, decodedPdr.range_field_format);
3572 EXPECT_EQ(5000, decodedPdr.nominal_value.value_u16);
3573 EXPECT_EQ(6000, decodedPdr.normal_max.value_u16);
3574 EXPECT_EQ(4000, decodedPdr.normal_min.value_u16);
3575 EXPECT_EQ(7000, decodedPdr.warning_high.value_u16);
3576 EXPECT_EQ(3000, decodedPdr.warning_low.value_u16);
3577 EXPECT_EQ(8000, decodedPdr.critical_high.value_u16);
3578 EXPECT_EQ(2000, decodedPdr.critical_low.value_u16);
3579 EXPECT_EQ(9000, decodedPdr.fatal_high.value_u16);
3580 EXPECT_EQ(1000, decodedPdr.fatal_low.value_u16);
3581}
3582
3583TEST(decodeNumericSensorPdrData, Sint16Test)
3584{
3585 std::vector<uint8_t> pdr1{
3586 0x1,
3587 0x0,
3588 0x0,
3589 0x0, // record handle
3590 0x1, // PDRHeaderVersion
3591 PLDM_NUMERIC_SENSOR_PDR, // PDRType
3592 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303593 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303594 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
3595 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 2 +
3596 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 2,
Andrew Jeffery01731472023-06-13 10:33:18 +09303597 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303598 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303599 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303600 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303601 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303602 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09303603 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303604 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303605 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303606 0x1,
3607 0x0, // containerID=1
3608 PLDM_NO_INIT, // sensorInit
3609 false, // sensorAuxiliaryNamesPDR
3610 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
3611 0, // unitModifier
3612 0, // rateUnit
3613 0, // baseOEMUnitHandle
3614 0, // auxUnit
3615 0, // auxUnitModifier
3616 0, // auxRateUnit
3617 0, // rel
3618 0, // auxOEMUnitHandle
3619 true, // isLinear
3620 PLDM_SENSOR_DATA_SIZE_SINT16, // sensorDataSize
3621 0,
3622 0,
3623 0,
3624 0, // resolution
3625 0,
3626 0,
3627 0,
3628 0, // offset
3629 0,
3630 0, // accuracy
3631 0, // plusTolerance
3632 0, // minusTolerance
3633 3,
3634 0, // hysteresis
3635 0, // supportedThresholds
3636 0, // thresholdAndHysteresisVolatility
3637 0,
3638 0,
3639 0x80,
3640 0x3f, // stateTransistionInterval=1.0
3641 0,
3642 0,
3643 0x80,
Andrew Jeffery01731472023-06-13 10:33:18 +09303644 0x3f, // updateInverval=1.0
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303645 0xe8,
Andrew Jeffery01731472023-06-13 10:33:18 +09303646 0x03, // maxReadable = 1000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303647 0x18,
3648 0xfc, // minReadable = -1000
3649 PLDM_RANGE_FIELD_FORMAT_SINT16, // rangeFieldFormat
3650 0, // rangeFieldsupport
3651 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303652 0, // nominalValue = 0
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303653 0xf4,
Andrew Jeffery01731472023-06-13 10:33:18 +09303654 0x01, // normalMax = 500
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303655 0x0c,
Andrew Jeffery01731472023-06-13 10:33:18 +09303656 0xfe, // normalMin = -500
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303657 0xe8,
Andrew Jeffery01731472023-06-13 10:33:18 +09303658 0x03, // warningHigh = 1,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303659 0x18,
Andrew Jeffery01731472023-06-13 10:33:18 +09303660 0xfc, // warningLow = -1,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303661 0xd0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303662 0x07, // criticalHigh = 2,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303663 0x30,
Andrew Jeffery01731472023-06-13 10:33:18 +09303664 0xf8, // criticalLow = -2,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303665 0xb8,
Andrew Jeffery01731472023-06-13 10:33:18 +09303666 0x0b, // fatalHigh = 3,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303667 0x48,
Andrew Jeffery01731472023-06-13 10:33:18 +09303668 0xf4 // fatalLow = -3,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303669 };
3670
3671 struct pldm_numeric_sensor_value_pdr decodedPdr;
3672 auto rc =
3673 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
3674 EXPECT_EQ(PLDM_SUCCESS, rc);
3675
3676 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT16, decodedPdr.sensor_data_size);
3677 EXPECT_EQ(1000, decodedPdr.max_readable.value_s16);
3678 EXPECT_EQ(-1000, decodedPdr.min_readable.value_s16);
3679 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT16, decodedPdr.range_field_format);
3680 EXPECT_EQ(0, decodedPdr.nominal_value.value_s16);
3681 EXPECT_EQ(500, decodedPdr.normal_max.value_s16);
3682 EXPECT_EQ(-500, decodedPdr.normal_min.value_s16);
3683 EXPECT_EQ(1000, decodedPdr.warning_high.value_s16);
3684 EXPECT_EQ(-1000, decodedPdr.warning_low.value_s16);
3685 EXPECT_EQ(2000, decodedPdr.critical_high.value_s16);
3686 EXPECT_EQ(-2000, decodedPdr.critical_low.value_s16);
3687 EXPECT_EQ(3000, decodedPdr.fatal_high.value_s16);
3688 EXPECT_EQ(-3000, decodedPdr.fatal_low.value_s16);
3689}
3690
3691TEST(decodeNumericSensorPdrData, Uint32Test)
3692{
3693 std::vector<uint8_t> pdr1{
3694 0x1,
3695 0x0,
3696 0x0,
3697 0x0, // record handle
3698 0x1, // PDRHeaderVersion
3699 PLDM_NUMERIC_SENSOR_PDR, // PDRType
3700 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303701 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303702 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
3703 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 4 +
3704 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
Andrew Jeffery01731472023-06-13 10:33:18 +09303705 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303706 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303707 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303708 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303709 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303710 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09303711 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303712 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303713 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303714 0x1,
3715 0x0, // containerID=1
3716 PLDM_NO_INIT, // sensorInit
3717 false, // sensorAuxiliaryNamesPDR
3718 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
3719 0, // unitModifier
3720 0, // rateUnit
3721 0, // baseOEMUnitHandle
3722 0, // auxUnit
3723 0, // auxUnitModifier
3724 0, // auxRateUnit
3725 0, // rel
3726 0, // auxOEMUnitHandle
3727 true, // isLinear
3728 PLDM_SENSOR_DATA_SIZE_UINT32, // sensorDataSize
3729 0,
3730 0,
3731 0,
3732 0, // resolution
3733 0,
3734 0,
3735 0,
3736 0, // offset
3737 0,
3738 0, // accuracy
3739 0, // plusTolerance
3740 0, // minusTolerance
3741 3,
3742 0,
3743 0,
3744 0, // hysteresis
3745 0, // supportedThresholds
3746 0, // thresholdAndHysteresisVolatility
3747 0,
3748 0,
3749 0x80,
3750 0x3f, // stateTransistionInterval=1.0
3751 0,
3752 0,
3753 0x80,
3754 0x3f, // updateInverval=1.0
3755 0,
3756 0x10,
3757 0,
3758 0, // maxReadable = 4096
3759 0,
3760 0,
3761 0,
3762 0, // minReadable = 0
3763 PLDM_RANGE_FIELD_FORMAT_UINT32, // rangeFieldFormat
3764 0, // rangeFieldsupport
3765 0x40,
3766 0x4b,
3767 0x4c,
3768 0x00, // nominalValue = 5,000,000
3769 0x80,
3770 0x8d,
3771 0x5b,
3772 0x00, // normalMax = 6,000,000
3773 0x00,
3774 0x09,
3775 0x3d,
3776 0x00, // normalMin = 4,000,000
3777 0xc0,
3778 0xcf,
3779 0x6a,
3780 0x00, // warningHigh = 7,000,000
3781 0xc0,
3782 0xc6,
3783 0x2d,
3784 0x00, // warningLow = 3,000,000
3785 0x00,
3786 0x12,
3787 0x7a,
3788 0x00, // criticalHigh = 8,000,000
3789 0x80,
3790 0x84,
3791 0x1e,
3792 0x00, // criticalLow = 2,000,000
3793 0x40,
3794 0x54,
3795 0x89,
3796 0x00, // fatalHigh = 9,000,000
3797 0x40,
3798 0x42,
3799 0x0f,
3800 0x00 // fatalLow = 1,000,000
3801 };
3802
3803 struct pldm_numeric_sensor_value_pdr decodedPdr;
3804 auto rc =
3805 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
3806 EXPECT_EQ(PLDM_SUCCESS, rc);
3807
3808 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_UINT32, decodedPdr.sensor_data_size);
3809 EXPECT_EQ(4096, decodedPdr.max_readable.value_u32);
3810 EXPECT_EQ(0, decodedPdr.min_readable.value_u32);
3811 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT32, decodedPdr.range_field_format);
3812 EXPECT_EQ(5000000, decodedPdr.nominal_value.value_u32);
3813 EXPECT_EQ(6000000, decodedPdr.normal_max.value_u32);
3814 EXPECT_EQ(4000000, decodedPdr.normal_min.value_u32);
3815 EXPECT_EQ(7000000, decodedPdr.warning_high.value_u32);
3816 EXPECT_EQ(3000000, decodedPdr.warning_low.value_u32);
3817 EXPECT_EQ(8000000, decodedPdr.critical_high.value_u32);
3818 EXPECT_EQ(2000000, decodedPdr.critical_low.value_u32);
3819 EXPECT_EQ(9000000, decodedPdr.fatal_high.value_u32);
3820 EXPECT_EQ(1000000, decodedPdr.fatal_low.value_u32);
3821}
3822
3823TEST(decodeNumericSensorPdrData, Sint32Test)
3824{
3825 std::vector<uint8_t> pdr1{
3826 0x1,
3827 0x0,
3828 0x0,
3829 0x0, // record handle
3830 0x1, // PDRHeaderVersion
3831 PLDM_NUMERIC_SENSOR_PDR, // PDRType
3832 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303833 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303834 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
3835 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 4 +
3836 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
Andrew Jeffery01731472023-06-13 10:33:18 +09303837 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303838 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303839 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303840 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303841 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303842 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09303843 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303844 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303845 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303846 0x1,
3847 0x0, // containerID=1
3848 PLDM_NO_INIT, // sensorInit
3849 false, // sensorAuxiliaryNamesPDR
3850 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
3851 0, // unitModifier
3852 0, // rateUnit
3853 0, // baseOEMUnitHandle
3854 0, // auxUnit
3855 0, // auxUnitModifier
3856 0, // auxRateUnit
3857 0, // rel
3858 0, // auxOEMUnitHandle
3859 true, // isLinear
3860 PLDM_SENSOR_DATA_SIZE_SINT32, // sensorDataSize
3861 0,
3862 0,
3863 0,
3864 0, // resolution
3865 0,
3866 0,
3867 0,
3868 0, // offset
3869 0,
3870 0, // accuracy
3871 0, // plusTolerance
3872 0, // minusTolerance
3873 3,
3874 0,
3875 0,
3876 0, // hysteresis
3877 0, // supportedThresholds
3878 0, // thresholdAndHysteresisVolatility
3879 0,
3880 0,
3881 0x80,
3882 0x3f, // stateTransistionInterval=1.0
3883 0,
3884 0,
3885 0x80,
3886 0x3f, // updateInverval=1.0
3887 0xa0,
3888 0x86,
3889 0x01,
3890 0x00, // maxReadable = 100000
3891 0x60,
3892 0x79,
3893 0xfe,
3894 0xff, // minReadable = -10000
3895 PLDM_RANGE_FIELD_FORMAT_SINT32, // rangeFieldFormat
3896 0, // rangeFieldsupport
3897 0,
3898 0,
3899 0,
3900 0, // nominalValue = 0
3901 0x20,
3902 0xa1,
3903 0x07,
3904 0x00, // normalMax = 500,000
3905 0xe0,
3906 0x5e,
3907 0xf8,
3908 0xff, // normalMin = -500,000
3909 0x40,
3910 0x42,
3911 0x0f,
3912 0x00, // warningHigh = 1,000,000
3913 0xc0,
3914 0xbd,
3915 0xf0,
3916 0xff, // warningLow = -1,000,000
3917 0x80,
3918 0x84,
3919 0x1e,
3920 0x00, // criticalHigh = 2,000,000
3921 0x80,
3922 0x7b,
3923 0xe1,
3924 0xff, // criticalLow = -2,000,000
3925 0xc0,
3926 0xc6,
3927 0x2d,
3928 0x00, // fatalHigh = 3,000,000
3929 0x40,
3930 0x39,
3931 0xd2,
3932 0xff // fatalLow = -3,000,000
3933 };
3934
3935 struct pldm_numeric_sensor_value_pdr decodedPdr;
3936 auto rc =
3937 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
3938 EXPECT_EQ(PLDM_SUCCESS, rc);
3939
3940 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT32, decodedPdr.sensor_data_size);
3941 EXPECT_EQ(100000, decodedPdr.max_readable.value_s32);
3942 EXPECT_EQ(-100000, decodedPdr.min_readable.value_s32);
3943 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT32, decodedPdr.range_field_format);
3944 EXPECT_EQ(0, decodedPdr.nominal_value.value_s32);
3945 EXPECT_EQ(500000, decodedPdr.normal_max.value_s32);
3946 EXPECT_EQ(-500000, decodedPdr.normal_min.value_s32);
3947 EXPECT_EQ(1000000, decodedPdr.warning_high.value_s32);
3948 EXPECT_EQ(-1000000, decodedPdr.warning_low.value_s32);
3949 EXPECT_EQ(2000000, decodedPdr.critical_high.value_s32);
3950 EXPECT_EQ(-2000000, decodedPdr.critical_low.value_s32);
3951 EXPECT_EQ(3000000, decodedPdr.fatal_high.value_s32);
3952 EXPECT_EQ(-3000000, decodedPdr.fatal_low.value_s32);
3953}
3954
3955TEST(decodeNumericSensorPdrData, Real32Test)
3956{
3957 std::vector<uint8_t> pdr1{
3958 0x1,
3959 0x0,
3960 0x0,
3961 0x0, // record handle
3962 0x1, // PDRHeaderVersion
3963 PLDM_NUMERIC_SENSOR_PDR, // PDRType
3964 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303965 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303966 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
3967 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 4 +
3968 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
Andrew Jeffery01731472023-06-13 10:33:18 +09303969 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303970 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303971 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303972 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303973 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303974 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09303975 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303976 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303977 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303978 0x1,
3979 0x0, // containerID=1
3980 PLDM_NO_INIT, // sensorInit
3981 false, // sensorAuxiliaryNamesPDR
3982 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
3983 0, // unitModifier
3984 0, // rateUnit
3985 0, // baseOEMUnitHandle
3986 0, // auxUnit
3987 0, // auxUnitModifier
3988 0, // auxRateUnit
3989 0, // rel
3990 0, // auxOEMUnitHandle
3991 true, // isLinear
3992 PLDM_SENSOR_DATA_SIZE_SINT32, // sensorDataSize
3993 0,
3994 0,
3995 0,
3996 0, // resolution
3997 0,
3998 0,
3999 0,
4000 0, // offset
4001 0,
4002 0, // accuracy
4003 0, // plusTolerance
4004 0, // minusTolerance
4005 3,
4006 0,
4007 0,
4008 0, // hysteresis
4009 0, // supportedThresholds
4010 0, // thresholdAndHysteresisVolatility
4011 0,
4012 0,
4013 0x80,
4014 0x3f, // stateTransistionInterval=1.0
4015 0,
4016 0,
4017 0x80,
4018 0x3f, // updateInverval=1.0
4019 0xa0,
4020 0x86,
4021 0x01,
4022 0x00, // maxReadable = 100000
4023 0x60,
4024 0x79,
4025 0xfe,
4026 0xff, // minReadable = -10000
4027 PLDM_RANGE_FIELD_FORMAT_REAL32, // rangeFieldFormat
4028 0, // rangeFieldsupport
4029 0,
4030 0,
4031 0,
4032 0, // nominalValue = 0.0
4033 0x33,
4034 0x33,
4035 0x48,
4036 0x42, // normalMax = 50.05
4037 0x33,
4038 0x33,
4039 0x48,
4040 0xc2, // normalMin = -50.05
4041 0x83,
4042 0x00,
4043 0xc8,
4044 0x42, // warningHigh = 100.001
4045 0x83,
4046 0x00,
4047 0xc8,
4048 0xc2, // warningLow = -100.001
4049 0x83,
4050 0x00,
4051 0x48,
4052 0x43, // criticalHigh = 200.002
4053 0x83,
4054 0x00,
4055 0x48,
4056 0xc3, // criticalLow = -200.002
4057 0x62,
4058 0x00,
4059 0x96,
4060 0x43, // fatalHigh = 300.003
4061 0x62,
4062 0x00,
4063 0x96,
4064 0xc3 // fatalLow = -300.003
4065 };
4066
4067 struct pldm_numeric_sensor_value_pdr decodedPdr;
4068 auto rc =
4069 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4070 EXPECT_EQ(PLDM_SUCCESS, rc);
4071
4072 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT32, decodedPdr.sensor_data_size);
4073 EXPECT_EQ(100000, decodedPdr.max_readable.value_s32);
4074 EXPECT_EQ(-100000, decodedPdr.min_readable.value_s32);
4075 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_REAL32, decodedPdr.range_field_format);
4076 EXPECT_FLOAT_EQ(0, decodedPdr.nominal_value.value_f32);
4077 EXPECT_FLOAT_EQ(50.05f, decodedPdr.normal_max.value_f32);
4078 EXPECT_FLOAT_EQ(-50.05f, decodedPdr.normal_min.value_f32);
4079 EXPECT_FLOAT_EQ(100.001f, decodedPdr.warning_high.value_f32);
4080 EXPECT_FLOAT_EQ(-100.001f, decodedPdr.warning_low.value_f32);
4081 EXPECT_FLOAT_EQ(200.002f, decodedPdr.critical_high.value_f32);
4082 EXPECT_FLOAT_EQ(-200.002f, decodedPdr.critical_low.value_f32);
4083 EXPECT_FLOAT_EQ(300.003f, decodedPdr.fatal_high.value_f32);
4084 EXPECT_FLOAT_EQ(-300.003f, decodedPdr.fatal_low.value_f32);
4085}
4086
4087TEST(decodeNumericSensorPdrDataDeathTest, InvalidSizeTest)
4088{
4089 // A corrupted PDR. The data after plusTolerance missed.
4090 std::vector<uint8_t> pdr1{
4091 0x1,
4092 0x0,
4093 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304094 0x0, // record handle
4095 0x1, // PDRHeaderVersion
4096 PLDM_NUMERIC_SENSOR_PDR, // PDRType
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304097 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304098 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304099 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH,
Andrew Jeffery01731472023-06-13 10:33:18 +09304100 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304101 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304102 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304103 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304104 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304105 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09304106 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304107 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304108 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304109 0x1,
4110 0x0, // containerID=1
4111 PLDM_NO_INIT, // sensorInit
4112 false, // sensorAuxiliaryNamesPDR
4113 2, // baseUint(2)=degrees C
4114 0, // unitModifier
4115 0, // rateUnit
4116 0, // baseOEMUnitHandle
4117 0, // auxUnit
4118 0, // auxUnitModifier
4119 0, // auxRateUnit
4120 0, // rel
4121 0, // auxOEMUnitHandle
4122 true, // isLinear
4123 PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize
4124 0,
4125 0,
4126 0,
4127 0, // resolution
4128 0,
4129 0,
4130 0,
4131 0, // offset
4132 0,
4133 0, // accuracy
4134 0 // plusTolerance
4135 };
4136
4137 struct pldm_numeric_sensor_value_pdr decodedPdr;
4138 int rc =
4139 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4140 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
4141}
Thu Nguyend4878cd2023-11-09 10:18:33 +07004142
Andrew Jeffery688be622024-05-23 11:22:51 +09304143#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004144TEST(decodeNumericEffecterPdrData, Uint8Test)
4145{
4146 std::vector<uint8_t> pdr1{
4147 0x1,
4148 0x0,
4149 0x0,
4150 0x0, // record handle
4151 0x1, // PDRHeaderVersion
4152 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4153 0x0,
4154 0x0, // recordChangeNumber
4155 PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH,
4156 0, // dataLength
4157 0,
4158 0, // PLDMTerminusHandle
4159 0x1,
4160 0x0, // effecterID=1
4161 PLDM_ENTITY_POWER_SUPPLY,
4162 0, // entityType=Power Supply(120)
4163 1,
4164 0, // entityInstanceNumber
4165 1,
4166 0, // containerID=1
4167 0x2,
4168 0x0, // effecter_semantic_id=2
4169 PLDM_NO_INIT, // effecterInit
4170 false, // effecterAuxiliaryNames
4171 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4172 0, // unitModifier
4173 0, // rateUnit
4174 0, // baseOEMUnitHandle
4175 0, // auxUnit
4176 0, // auxUnitModifier
4177 4, // auxRateUnit
4178 0, // auxOEMUnitHandle
4179 true, // isLinear
4180 PLDM_EFFECTER_DATA_SIZE_UINT8, // effecterDataSize
4181 0,
4182 0,
4183 0xc0,
4184 0x3f, // resolution=1.5
4185 0,
4186 0,
4187 0x80,
4188 0x3f, // offset=1.0
4189 0,
4190 0, // accuracy
4191 0, // plusTolerance
4192 0, // minusTolerance
4193 0,
4194 0,
4195 0x80,
4196 0x3f, // stateTransistionInterval=1.0
4197 0,
4198 0,
4199 0x80,
4200 0x3f, // transition_interval=1.0
4201 255, // maxSetdable
4202 0, // minSetable
4203 PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
4204 0x1f, // rangeFieldsupport
4205 50, // nominalValue = 50
4206 60, // normalMax = 60
4207 40, // normalMin = 40
4208 90, // rated_max = 90
4209 10 // rated_min = 10
4210 };
4211
4212 struct pldm_numeric_effecter_value_pdr decodedPdr;
4213 auto rc =
4214 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4215 EXPECT_EQ(PLDM_SUCCESS, rc);
4216 EXPECT_EQ(1, decodedPdr.hdr.record_handle);
4217 EXPECT_EQ(1, decodedPdr.hdr.version);
4218 EXPECT_EQ(PLDM_NUMERIC_EFFECTER_PDR, decodedPdr.hdr.type);
4219 EXPECT_EQ(0, decodedPdr.hdr.record_change_num);
4220 EXPECT_EQ(PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH, decodedPdr.hdr.length);
4221 EXPECT_EQ(1, decodedPdr.effecter_id);
4222 EXPECT_EQ(PLDM_ENTITY_POWER_SUPPLY, decodedPdr.entity_type);
4223 EXPECT_EQ(1, decodedPdr.entity_instance);
4224 EXPECT_EQ(1, decodedPdr.container_id);
4225 EXPECT_EQ(2, decodedPdr.effecter_semantic_id);
4226 EXPECT_EQ(PLDM_NO_INIT, decodedPdr.effecter_init);
4227 EXPECT_EQ(false, decodedPdr.effecter_auxiliary_names);
4228 EXPECT_EQ(PLDM_SENSOR_UNIT_DEGRESS_C, decodedPdr.base_unit);
4229 EXPECT_EQ(0, decodedPdr.unit_modifier);
4230 EXPECT_EQ(0, decodedPdr.rate_unit);
4231 EXPECT_EQ(0, decodedPdr.base_oem_unit_handle);
4232 EXPECT_EQ(0, decodedPdr.aux_unit);
4233 EXPECT_EQ(0, decodedPdr.aux_unit_modifier);
4234 EXPECT_EQ(4, decodedPdr.aux_rate_unit);
4235 EXPECT_EQ(0, decodedPdr.aux_oem_unit_handle);
4236 EXPECT_EQ(true, decodedPdr.is_linear);
4237 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_UINT8, decodedPdr.effecter_data_size);
4238 EXPECT_FLOAT_EQ(1.5f, decodedPdr.resolution);
4239 EXPECT_FLOAT_EQ(1.0f, decodedPdr.offset);
4240 EXPECT_EQ(0, decodedPdr.accuracy);
4241 EXPECT_EQ(0, decodedPdr.plus_tolerance);
4242 EXPECT_EQ(0, decodedPdr.minus_tolerance);
4243 EXPECT_FLOAT_EQ(1.0f, decodedPdr.state_transition_interval);
4244 EXPECT_FLOAT_EQ(1.0f, decodedPdr.transition_interval);
4245 EXPECT_EQ(255, decodedPdr.max_settable.value_u8);
4246 EXPECT_EQ(0, decodedPdr.min_settable.value_u8);
4247 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT8, decodedPdr.range_field_format);
4248 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4249 EXPECT_EQ(50, decodedPdr.nominal_value.value_u8);
4250 EXPECT_EQ(60, decodedPdr.normal_max.value_u8);
4251 EXPECT_EQ(40, decodedPdr.normal_min.value_u8);
4252 EXPECT_EQ(90, decodedPdr.rated_max.value_u8);
4253 EXPECT_EQ(10, decodedPdr.rated_min.value_u8);
4254}
Andrew Jeffery688be622024-05-23 11:22:51 +09304255#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07004256
Andrew Jeffery688be622024-05-23 11:22:51 +09304257#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004258TEST(decodeNumericEffecterPdrData, Sint8Test)
4259{
4260 std::vector<uint8_t> pdr1{
4261 0x1,
4262 0x0,
4263 0x0,
4264 0x0, // record handle
4265 0x1, // PDRHeaderVersion
4266 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4267 0x0,
4268 0x0, // recordChangeNumber
4269 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
4270 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH +
4271 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
4272 0, // dataLength
4273 0,
4274 0, // PLDMTerminusHandle
4275 0x1,
4276 0x0, // effecterID=1
4277 PLDM_ENTITY_POWER_SUPPLY,
4278 0, // entityType=Power Supply(120)
4279 1,
4280 0, // entityInstanceNumber
4281 0x1,
4282 0x0, // containerID=1
4283 0x2,
4284 0x0, // effecter_semantic_id=2
4285 PLDM_NO_INIT, // effecterInit
4286 false, // effecterAuxiliaryNames
4287 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4288 0, // unitModifier
4289 0, // rateUnit
4290 0, // baseOEMUnitHandle
4291 0, // auxUnit
4292 0, // auxUnitModifier
4293 0, // auxRateUnit
4294 0, // auxOEMUnitHandle
4295 true, // isLinear
4296 PLDM_RANGE_FIELD_FORMAT_SINT8, // effecterDataSize
4297 0,
4298 0,
4299 0,
4300 0, // resolution
4301 0,
4302 0,
4303 0,
4304 0, // offset
4305 0,
4306 0, // accuracy
4307 0, // plusTolerance
4308 0, // minusTolerance
4309 0,
4310 0,
4311 0x80,
4312 0x3f, // stateTransistionInterval=1.0
4313 0,
4314 0,
4315 0x80,
4316 0x3f, // transition_interval=1.0
4317 0x64, // maxSetdable = 100
4318 0x9c, // minSetable = -100
4319 PLDM_RANGE_FIELD_FORMAT_SINT8, // rangeFieldFormat
4320 0x1f, // rangeFieldsupport
4321 0, // nominalValue = 0
4322 5, // normalMax = 5
4323 0xfb, // normalMin = -5
4324 30, // rated_max = 30
4325 0xe2 // rated_min = -30
4326 };
4327
4328 struct pldm_numeric_effecter_value_pdr decodedPdr;
4329 auto rc =
4330 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4331 EXPECT_EQ(PLDM_SUCCESS, rc);
4332
4333 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_SINT8, decodedPdr.effecter_data_size);
4334 EXPECT_EQ(100, decodedPdr.max_settable.value_s8);
4335 EXPECT_EQ(-100, decodedPdr.min_settable.value_s8);
4336 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT8, decodedPdr.range_field_format);
4337 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4338 EXPECT_EQ(0, decodedPdr.nominal_value.value_s8);
4339 EXPECT_EQ(5, decodedPdr.normal_max.value_s8);
4340 EXPECT_EQ(-5, decodedPdr.normal_min.value_s8);
4341 EXPECT_EQ(30, decodedPdr.rated_max.value_s8);
4342 EXPECT_EQ(-30, decodedPdr.rated_min.value_s8);
4343}
Andrew Jeffery688be622024-05-23 11:22:51 +09304344#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07004345
Andrew Jeffery688be622024-05-23 11:22:51 +09304346#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004347TEST(decodeNumericEffecterPdrData, Uint16Test)
4348{
4349 std::vector<uint8_t> pdr1{
4350 0x1,
4351 0x0,
4352 0x0,
4353 0x0, // record handle
4354 0x1, // PDRHeaderVersion
4355 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4356 0x0,
4357 0x0, // recordChangeNumber
4358 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
4359 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH *
4360 2 +
4361 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 2,
4362 0, // dataLength
4363 0,
4364 0, // PLDMTerminusHandle
4365 0x1,
4366 0x0, // effecterID=1
4367 PLDM_ENTITY_POWER_SUPPLY,
4368 0, // entityType=Power Supply(120)
4369 1,
4370 0, // entityInstanceNumber
4371 0x1,
4372 0x0, // containerID=1
4373 0x2,
4374 0x0, // effecter_semantic_id=2
4375 PLDM_NO_INIT, // effecterInit
4376 false, // effecterAuxiliaryNames
4377 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4378 0, // unitModifier
4379 0, // rateUnit
4380 0, // baseOEMUnitHandle
4381 0, // auxUnit
4382 0, // auxUnitModifier
4383 0, // auxRateUnit
4384 0, // auxOEMUnitHandle
4385 true, // isLinear
4386 PLDM_EFFECTER_DATA_SIZE_UINT16, // effecterDataSize
4387 0,
4388 0,
4389 0,
4390 0, // resolution
4391 0,
4392 0,
4393 0,
4394 0, // offset
4395 0,
4396 0, // accuracy
4397 0, // plusTolerance
4398 0, // minusTolerance
4399 0,
4400 0,
4401 0x80,
4402 0x3f, // stateTransistionInterval=1.0
4403 0,
4404 0,
4405 0x80,
4406 0x3f, // transition_interval=1.0
4407 0,
4408 0x10, // maxSetdable = 4096
4409 0,
4410 0, // minSetable = 0
4411 PLDM_RANGE_FIELD_FORMAT_UINT16, // rangeFieldFormat
4412 0x1f, // rangeFieldsupport
4413 0x88,
4414 0x13, // nominalValue = 5,000
4415 0x70,
4416 0x17, // normalMax = 6,000
4417 0xa0,
4418 0x0f, // normalMin = 4,000
4419 0x28,
4420 0x23, // rated_max = 9,000
4421 0xe8,
4422 0x03 // rated_min = 1,000
4423 };
4424
4425 struct pldm_numeric_effecter_value_pdr decodedPdr;
4426 auto rc =
4427 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4428 EXPECT_EQ(PLDM_SUCCESS, rc);
4429
4430 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_UINT16, decodedPdr.effecter_data_size);
4431 EXPECT_EQ(4096, decodedPdr.max_settable.value_u16);
4432 EXPECT_EQ(0, decodedPdr.min_settable.value_u16);
4433 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT16, decodedPdr.range_field_format);
4434 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4435 EXPECT_EQ(5000, decodedPdr.nominal_value.value_u16);
4436 EXPECT_EQ(6000, decodedPdr.normal_max.value_u16);
4437 EXPECT_EQ(4000, decodedPdr.normal_min.value_u16);
4438 EXPECT_EQ(9000, decodedPdr.rated_max.value_u16);
4439 EXPECT_EQ(1000, decodedPdr.rated_min.value_u16);
4440}
Andrew Jeffery688be622024-05-23 11:22:51 +09304441#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07004442
Andrew Jeffery688be622024-05-23 11:22:51 +09304443#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004444TEST(decodeNumericEffecterPdrData, Sint16Test)
4445{
4446 std::vector<uint8_t> pdr1{
4447 0x1,
4448 0x0,
4449 0x0,
4450 0x0, // record handle
4451 0x1, // PDRHeaderVersion
4452 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4453 0x0,
4454 0x0, // recordChangeNumber
4455 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
4456 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH *
4457 2 +
4458 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 2,
4459 0, // dataLength
4460 0,
4461 0, // PLDMTerminusHandle
4462 0x1,
4463 0x0, // effecterID=1
4464 PLDM_ENTITY_POWER_SUPPLY,
4465 0, // entityType=Power Supply(120)
4466 1,
4467 0, // entityInstanceNumber
4468 0x1,
4469 0x0, // containerID=1
4470 0x2,
4471 0x0, // effecter_semantic_id=2
4472 PLDM_NO_INIT, // effecterInit
4473 false, // effecterAuxiliaryNames
4474 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4475 0, // unitModifier
4476 0, // rateUnit
4477 0, // baseOEMUnitHandle
4478 0, // auxUnit
4479 0, // auxUnitModifier
4480 0, // auxRateUnit
4481 0, // auxOEMUnitHandle
4482 true, // isLinear
4483 PLDM_EFFECTER_DATA_SIZE_SINT16, // effecterDataSize
4484 0,
4485 0,
4486 0,
4487 0, // resolution
4488 0,
4489 0,
4490 0,
4491 0, // offset
4492 0,
4493 0, // accuracy
4494 0, // plusTolerance
4495 0, // minusTolerance
4496 0,
4497 0,
4498 0x80,
4499 0x3f, // stateTransistionInterval=1.0
4500 0,
4501 0,
4502 0x80,
4503 0x3f, // transition_interval=1.0
4504 0xe8,
4505 0x03, // maxSetdable = 1000
4506 0x18,
4507 0xfc, // minSetable = -1000
4508 PLDM_RANGE_FIELD_FORMAT_SINT16, // rangeFieldFormat
4509 0x1f, // rangeFieldsupport
4510 0,
4511 0, // nominalValue = 0
4512 0xf4,
4513 0x01, // normalMax = 500
4514 0x0c,
4515 0xfe, // normalMin = -500
4516 0xb8,
4517 0x0b, // rated_max = 3,000
4518 0x48,
4519 0xf4 // rated_min = -3,000
4520 };
4521
4522 struct pldm_numeric_effecter_value_pdr decodedPdr;
4523 auto rc =
4524 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4525 EXPECT_EQ(PLDM_SUCCESS, rc);
4526
4527 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_SINT16, decodedPdr.effecter_data_size);
4528 EXPECT_EQ(1000, decodedPdr.max_settable.value_s16);
4529 EXPECT_EQ(-1000, decodedPdr.min_settable.value_s16);
4530 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT16, decodedPdr.range_field_format);
4531 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4532 EXPECT_EQ(0, decodedPdr.nominal_value.value_s16);
4533 EXPECT_EQ(500, decodedPdr.normal_max.value_s16);
4534 EXPECT_EQ(-500, decodedPdr.normal_min.value_s16);
4535 EXPECT_EQ(3000, decodedPdr.rated_max.value_s16);
4536 EXPECT_EQ(-3000, decodedPdr.rated_min.value_s16);
4537}
Andrew Jeffery688be622024-05-23 11:22:51 +09304538#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07004539
Andrew Jeffery688be622024-05-23 11:22:51 +09304540#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004541TEST(decodeNumericEffecterPdrData, Uint32Test)
4542{
4543 std::vector<uint8_t> pdr1{
4544 0x1,
4545 0x0,
4546 0x0,
4547 0x0, // record handle
4548 0x1, // PDRHeaderVersion
4549 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4550 0x0,
4551 0x0, // recordChangeNumber
4552 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
4553 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH *
4554 4 +
4555 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
4556 0, // dataLength
4557 0,
4558 0, // PLDMTerminusHandle
4559 0x1,
4560 0x0, // effecterID=1
4561 PLDM_ENTITY_POWER_SUPPLY,
4562 0, // entityType=Power Supply(120)
4563 1,
4564 0, // entityInstanceNumber
4565 0x1,
4566 0x0, // containerID=1
4567 0x2,
4568 0x0, // effecter_semantic_id=2
4569 PLDM_NO_INIT, // effecterInit
4570 false, // effecterAuxiliaryNames
4571 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4572 0, // unitModifier
4573 0, // rateUnit
4574 0, // baseOEMUnitHandle
4575 0, // auxUnit
4576 0, // auxUnitModifier
4577 0, // auxRateUnit
4578 0, // auxOEMUnitHandle
4579 true, // isLinear
4580 PLDM_EFFECTER_DATA_SIZE_UINT32, // effecterDataSize
4581 0,
4582 0,
4583 0,
4584 0, // resolution
4585 0,
4586 0,
4587 0,
4588 0, // offset
4589 0,
4590 0, // accuracy
4591 0, // plusTolerance
4592 0, // minusTolerance
4593 0,
4594 0,
4595 0x80,
4596 0x3f, // stateTransistionInterval=1.0
4597 0,
4598 0,
4599 0x80,
4600 0x3f, // transition_interval=1.0
4601 0,
4602 0x10,
4603 0,
4604 0, // maxSetdable = 4096
4605 0,
4606 0,
4607 0,
4608 0, // minSetable = 0
4609 PLDM_RANGE_FIELD_FORMAT_UINT32, // rangeFieldFormat
4610 0x1f, // rangeFieldsupport
4611 0x40,
4612 0x4b,
4613 0x4c,
4614 0x00, // nominalValue = 5,000,000
4615 0x80,
4616 0x8d,
4617 0x5b,
4618 0x00, // normalMax = 6,000,000
4619 0x00,
4620 0x09,
4621 0x3d,
4622 0x00, // normalMin = 4,000,000
4623 0x40,
4624 0x54,
4625 0x89,
4626 0x00, // rated_max = 9,000,000
4627 0x40,
4628 0x42,
4629 0x0f,
4630 0x00 // rated_min = 1,000,000
4631 };
4632
4633 struct pldm_numeric_effecter_value_pdr decodedPdr;
4634 auto rc =
4635 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4636 EXPECT_EQ(PLDM_SUCCESS, rc);
4637
4638 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_UINT32, decodedPdr.effecter_data_size);
4639 EXPECT_EQ(4096, decodedPdr.max_settable.value_u32);
4640 EXPECT_EQ(0, decodedPdr.min_settable.value_u32);
4641 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT32, decodedPdr.range_field_format);
4642 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4643 EXPECT_EQ(5000000, decodedPdr.nominal_value.value_u32);
4644 EXPECT_EQ(6000000, decodedPdr.normal_max.value_u32);
4645 EXPECT_EQ(4000000, decodedPdr.normal_min.value_u32);
4646 EXPECT_EQ(9000000, decodedPdr.rated_max.value_u32);
4647 EXPECT_EQ(1000000, decodedPdr.rated_min.value_u32);
4648}
Andrew Jeffery688be622024-05-23 11:22:51 +09304649#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07004650
Andrew Jeffery688be622024-05-23 11:22:51 +09304651#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004652TEST(decodeNumericEffecterPdrData, Sint32Test)
4653{
4654 std::vector<uint8_t> pdr1{
4655 0x1,
4656 0x0,
4657 0x0,
4658 0x0, // record handle
4659 0x1, // PDRHeaderVersion
4660 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4661 0x0,
4662 0x0, // recordChangeNumber
4663 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
4664 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH *
4665 4 +
4666 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
4667 0, // dataLength
4668 0,
4669 0, // PLDMTerminusHandle
4670 0x1,
4671 0x0, // effecterID=1
4672 PLDM_ENTITY_POWER_SUPPLY,
4673 0, // entityType=Power Supply(120)
4674 1,
4675 0, // entityInstanceNumber
4676 0x1,
4677 0x0, // containerID=1
4678 0x2,
4679 0x0, // effecter_semantic_id=2
4680 PLDM_NO_INIT, // effecterInit
4681 false, // effecterAuxiliaryNames
4682 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4683 0, // unitModifier
4684 0, // rateUnit
4685 0, // baseOEMUnitHandle
4686 0, // auxUnit
4687 0, // auxUnitModifier
4688 0, // auxRateUnit
4689 0, // auxOEMUnitHandle
4690 true, // isLinear
4691 PLDM_EFFECTER_DATA_SIZE_SINT32, // effecterDataSize
4692 0,
4693 0,
4694 0,
4695 0, // resolution
4696 0,
4697 0,
4698 0,
4699 0, // offset
4700 0,
4701 0, // accuracy
4702 0, // plusTolerance
4703 0, // minusTolerance
4704 0,
4705 0,
4706 0x80,
4707 0x3f, // stateTransistionInterval=1.0
4708 0,
4709 0,
4710 0x80,
4711 0x3f, // transition_interval=1.0
4712 0xa0,
4713 0x86,
4714 0x01,
4715 0x00, // maxSetdable = 100000
4716 0x60,
4717 0x79,
4718 0xfe,
4719 0xff, // minSetable = -10000
4720 PLDM_RANGE_FIELD_FORMAT_SINT32, // rangeFieldFormat
4721 0x1f, // rangeFieldsupport
4722 0,
4723 0,
4724 0,
4725 0, // nominalValue = 0
4726 0x20,
4727 0xa1,
4728 0x07,
4729 0x00, // normalMax = 500,000
4730 0xe0,
4731 0x5e,
4732 0xf8,
4733 0xff, // normalMin = -500,000
4734 0xc0,
4735 0xc6,
4736 0x2d,
4737 0x00, // rated_max = 3,000,000
4738 0x40,
4739 0x39,
4740 0xd2,
4741 0xff // rated_min = -3,000,000
4742 };
4743
4744 struct pldm_numeric_effecter_value_pdr decodedPdr;
4745 auto rc =
4746 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4747 EXPECT_EQ(PLDM_SUCCESS, rc);
4748 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_SINT32, decodedPdr.effecter_data_size);
4749 EXPECT_EQ(100000, decodedPdr.max_settable.value_s32);
4750 EXPECT_EQ(-100000, decodedPdr.min_settable.value_s32);
4751 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT32, decodedPdr.range_field_format);
4752 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4753 EXPECT_EQ(0, decodedPdr.nominal_value.value_s32);
4754 EXPECT_EQ(500000, decodedPdr.normal_max.value_s32);
4755 EXPECT_EQ(-500000, decodedPdr.normal_min.value_s32);
4756 EXPECT_EQ(3000000, decodedPdr.rated_max.value_s32);
4757 EXPECT_EQ(-3000000, decodedPdr.rated_min.value_s32);
4758}
Andrew Jeffery688be622024-05-23 11:22:51 +09304759#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07004760
Andrew Jeffery688be622024-05-23 11:22:51 +09304761#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004762TEST(decodeNumericEffecterPdrData, Real32Test)
4763{
4764 std::vector<uint8_t> pdr1{
4765 0x1,
4766 0x0,
4767 0x0,
4768 0x0, // record handle
4769 0x1, // PDRHeaderVersion
4770 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4771 0x0,
4772 0x0, // recordChangeNumber
4773 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
4774 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH *
4775 4 +
4776 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
4777 0, // dataLength
4778 0,
4779
4780 0, // PLDMTerminusHandle
4781 0x1,
4782 0x0, // effecterID=1
4783 PLDM_ENTITY_POWER_SUPPLY,
4784 0, // entityType=Power Supply(120)
4785 1,
4786 0, // entityInstanceNumber
4787 0x1,
4788 0x0, // containerID=1
4789 0x2,
4790 0x0, // effecter_semantic_id=2
4791 PLDM_NO_INIT, // effecterInit
4792 false, // effecterAuxiliaryNames
4793 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4794 0, // unitModifier
4795 0, // rateUnit
4796 0, // baseOEMUnitHandle
4797 0, // auxUnit
4798 0, // auxUnitModifier
4799 0, // auxRateUnit
4800 0, // auxOEMUnitHandle
4801 true, // isLinear
4802 PLDM_EFFECTER_DATA_SIZE_SINT32, // effecterDataSize
4803 0,
4804 0,
4805 0,
4806 0, // resolution
4807 0,
4808 0,
4809 0,
4810 0, // offset
4811 0,
4812 0, // accuracy
4813 0, // plusTolerance
4814 0, // minusTolerance
4815 0,
4816 0,
4817 0x80,
4818 0x3f, // stateTransistionInterval=1.0
4819 0,
4820 0,
4821 0x80,
4822 0x3f, // transition_interval=1.0
4823 0xa0,
4824 0x86,
4825 0x01,
4826 0x00, // maxSetdable = 100000
4827 0x60,
4828 0x79,
4829 0xfe,
4830 0xff, // minSetable = -10000
4831 PLDM_RANGE_FIELD_FORMAT_REAL32, // rangeFieldFormat
4832 0x1f, // rangeFieldsupport
4833 0,
4834 0,
4835 0,
4836 0, // nominalValue = 0.0
4837 0x33,
4838 0x33,
4839 0x48,
4840 0x42, // normalMax = 50.05
4841 0x33,
4842 0x33,
4843 0x48,
4844 0xc2, // normalMin = -50.05
4845 0x62,
4846 0x00,
4847 0x96,
4848 0x43, // rated_max = 300.003
4849 0x62,
4850 0x00,
4851 0x96,
4852 0xc3 // rated_min = -300.003
4853 };
4854
4855 struct pldm_numeric_effecter_value_pdr decodedPdr;
4856 auto rc =
4857 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4858 EXPECT_EQ(PLDM_SUCCESS, rc);
4859
4860 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_SINT32, decodedPdr.effecter_data_size);
4861 EXPECT_FLOAT_EQ(1.0f, decodedPdr.state_transition_interval);
4862 EXPECT_FLOAT_EQ(1.0f, decodedPdr.transition_interval);
4863 EXPECT_EQ(100000, decodedPdr.max_settable.value_s32);
4864 EXPECT_EQ(-100000, decodedPdr.min_settable.value_s32);
4865 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_REAL32, decodedPdr.range_field_format);
4866 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4867 EXPECT_FLOAT_EQ(0, decodedPdr.nominal_value.value_f32);
4868 EXPECT_FLOAT_EQ(50.05f, decodedPdr.normal_max.value_f32);
4869 EXPECT_FLOAT_EQ(-50.05f, decodedPdr.normal_min.value_f32);
4870 EXPECT_FLOAT_EQ(300.003f, decodedPdr.rated_max.value_f32);
4871 EXPECT_FLOAT_EQ(-300.003f, decodedPdr.rated_min.value_f32);
4872}
Andrew Jeffery688be622024-05-23 11:22:51 +09304873#endif
Tal Yacobia6fa5552024-05-05 16:57:38 +03004874
Tal Yacobia6fa5552024-05-05 16:57:38 +03004875TEST(GetStateEffecterStates, testEncodeAndDecodeRequest)
4876{
4877 std::array<uint8_t, hdrSize + PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES>
4878 requestMsg{};
4879
4880 constexpr std::array<uint8_t,
4881 hdrSize + PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES>
4882 expectedRequestMsg{
4883 {0x80, PLDM_PLATFORM, PLDM_GET_STATE_EFFECTER_STATES, 1, 0xab}};
4884
4885 constexpr uint16_t effecter_id = 0xab01;
4886
4887 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
4888
4889 auto rc = encode_get_state_effecter_states_req(
4890 0, effecter_id, request, PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
4891
4892 EXPECT_EQ(rc, PLDM_SUCCESS);
4893 EXPECT_EQ(requestMsg, expectedRequestMsg);
4894
4895 uint16_t ret_effecter_id;
4896
4897 rc = decode_get_state_effecter_states_req(
4898 request, requestMsg.size() - hdrSize, &ret_effecter_id);
4899
4900 EXPECT_EQ(rc, PLDM_SUCCESS);
4901 EXPECT_EQ(effecter_id, ret_effecter_id);
4902
4903 // Test invalid length decode request
4904
4905 rc = decode_get_state_effecter_states_req(
4906 request, requestMsg.size() - hdrSize - 1, &ret_effecter_id);
4907
Tal Yacobif490a382024-05-31 09:57:36 +03004908 EXPECT_EQ(rc, -EOVERFLOW);
Tal Yacobia6fa5552024-05-05 16:57:38 +03004909}
Tal Yacobia6fa5552024-05-05 16:57:38 +03004910
Tal Yacobia6fa5552024-05-05 16:57:38 +03004911TEST(GetStateEffecterStates, testBadEncodeRequest)
4912{
4913 std::vector<uint8_t> requestMsg(hdrSize +
4914 PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
4915
4916 auto rc = encode_get_state_effecter_states_req(
4917 0, 0, nullptr, PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
Tal Yacobif490a382024-05-31 09:57:36 +03004918 EXPECT_EQ(rc, -EINVAL);
Tal Yacobia6fa5552024-05-05 16:57:38 +03004919}
Tal Yacobia6fa5552024-05-05 16:57:38 +03004920
Tal Yacobia6fa5552024-05-05 16:57:38 +03004921TEST(GetStateEffecterStates, testBadDecodeRequest)
4922{
4923 std::array<uint8_t, hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES>
4924 requestMsg{};
4925
4926 auto rc = decode_get_state_effecter_states_req(
4927 nullptr, requestMsg.size() - hdrSize, nullptr);
4928
Tal Yacobif490a382024-05-31 09:57:36 +03004929 EXPECT_EQ(rc, -EINVAL);
Tal Yacobia6fa5552024-05-05 16:57:38 +03004930}
Tal Yacobia6fa5552024-05-05 16:57:38 +03004931
Tal Yacobia6fa5552024-05-05 16:57:38 +03004932TEST(GetStateEffecterStates, testEncodeAndDecodeResponse)
4933{
4934 constexpr uint8_t comp_effecterCnt = 0x2;
4935 constexpr uint8_t completionCode = 0;
4936 std::array<uint8_t,
4937 hdrSize + PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES +
4938 PLDM_GET_EFFECTER_STATE_FIELD_SIZE * comp_effecterCnt>
4939 expectedResponseMsg{{0, PLDM_PLATFORM, PLDM_GET_STATE_EFFECTER_STATES,
4940 completionCode, comp_effecterCnt,
4941 EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING, 2, 2,
4942 EFFECTER_OPER_STATE_ENABLED_UPDATEPENDING, 2, 3}};
4943
4944 decltype(expectedResponseMsg) responseMsg{};
4945
4946 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
4947
4948 std::array<get_effecter_state_field, comp_effecterCnt> stateField{
4949 {{EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING, 2, 2},
4950 {EFFECTER_OPER_STATE_ENABLED_UPDATEPENDING, 2, 3}}};
4951
4952 struct pldm_get_state_effecter_states_resp resp_fields
4953 {
4954 PLDM_SUCCESS, comp_effecterCnt,
4955 {
4956 stateField[0], stateField[1]
4957 }
4958 };
4959
4960 auto rc = encode_get_state_effecter_states_resp(
4961 0, &resp_fields, response, responseMsg.size() - hdrSize);
4962
4963 EXPECT_EQ(rc, PLDM_SUCCESS);
4964 EXPECT_EQ(expectedResponseMsg, responseMsg);
4965
4966 struct pldm_get_state_effecter_states_resp ret_resp_fields;
4967
4968 rc = decode_get_state_effecter_states_resp(
4969 response, responseMsg.size() - hdrSize, &ret_resp_fields);
4970
4971 EXPECT_EQ(rc, PLDM_SUCCESS);
4972 EXPECT_EQ(completionCode, ret_resp_fields.completion_code);
4973 EXPECT_EQ(comp_effecterCnt, ret_resp_fields.comp_effecter_count);
4974 EXPECT_EQ(stateField[0].effecter_op_state,
4975 ret_resp_fields.field[0].effecter_op_state);
4976 EXPECT_EQ(stateField[0].pending_state,
4977 ret_resp_fields.field[0].pending_state);
4978 EXPECT_EQ(stateField[0].present_state,
4979 ret_resp_fields.field[0].present_state);
4980 EXPECT_EQ(stateField[1].effecter_op_state,
4981 ret_resp_fields.field[1].effecter_op_state);
4982 EXPECT_EQ(stateField[1].pending_state,
4983 ret_resp_fields.field[1].pending_state);
4984 EXPECT_EQ(stateField[1].present_state,
4985 ret_resp_fields.field[1].present_state);
4986
4987 // Test invalid length decode
4988
4989 rc = decode_get_state_effecter_states_resp(
4990 response,
4991 responseMsg.size() - hdrSize + PLDM_GET_EFFECTER_STATE_FIELD_SIZE,
4992 &ret_resp_fields);
4993
Tal Yacobif490a382024-05-31 09:57:36 +03004994 EXPECT_EQ(rc, -EBADMSG);
Tal Yacobia6fa5552024-05-05 16:57:38 +03004995}
Tal Yacobia6fa5552024-05-05 16:57:38 +03004996
Tal Yacobia6fa5552024-05-05 16:57:38 +03004997TEST(GetStateEffecterStates, testBadEncodeResponse)
4998{
4999 struct pldm_get_state_effecter_states_resp resp
5000 {
5001 PLDM_SUCCESS, 0,
5002 {
5003 }
5004 };
5005 auto rc = decode_get_state_effecter_states_resp(nullptr, 0, &resp);
5006
Tal Yacobif490a382024-05-31 09:57:36 +03005007 EXPECT_EQ(rc, -EINVAL);
Tal Yacobia6fa5552024-05-05 16:57:38 +03005008}
Tal Yacobia6fa5552024-05-05 16:57:38 +03005009
Tal Yacobia6fa5552024-05-05 16:57:38 +03005010TEST(GetStateEffecterStates, testBadDecodeResponse)
5011{
5012 std::array<uint8_t, hdrSize +
5013 PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES +
5014 PLDM_GET_EFFECTER_STATE_FIELD_SIZE * 2>
5015 responseMsg{};
5016
5017 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
5018
5019 auto rc = decode_get_state_effecter_states_resp(
5020 response, responseMsg.size() - hdrSize, nullptr);
5021
Tal Yacobif490a382024-05-31 09:57:36 +03005022 EXPECT_EQ(rc, -EINVAL);
Tal Yacobia6fa5552024-05-05 16:57:38 +03005023}
Thu Nguyendacfa352024-06-22 09:53:15 +00005024
5025[[maybe_unused]] static size_t str16len(char16_t* startptr)
5026{
5027 char16_t* endptr = startptr;
5028 while (*endptr)
5029 {
5030 endptr++;
5031 }
5032 return endptr - startptr;
5033}
5034
Thu Nguyendacfa352024-06-22 09:53:15 +00005035TEST(decodeEntityAuxNamePdrData, GoodTest)
5036{
5037 std::vector<uint8_t> pdr1{
5038 // Common PDR Header
5039 0x1, 0x0, 0x0, 0x0, // record handle
5040 0x1, // PDRHeaderVersion
5041 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
5042 0x1,
5043 0x0, // recordChangeNumber
5044 0x27,
5045 0, // dataLength
5046 /* Entity Auxiliary Names PDR Data*/
5047 3,
5048 0, // entityType system software
5049 0x1,
5050 0x0, // Entity instance number =1
5051 PLDM_PLATFORM_ENTITY_SYSTEM_CONTAINER_ID,
5052 0, // Overal system
5053 0, // shared Name Count one name only
5054 03, // nameStringCount
5055 0x65, 0x6e, 0x00, // Language Tag "en"
5056 0x00, 0x53, 0x00, 0x30, 0x00, 0x53, 0x00, 0x00, // Entity Name "S0S"
5057 0x66, 0x6e, 0x00, // Language Tag "en"
5058 0x00, 0x53, 0x00, 0x31, 0x00, 0x00, // Entity Name "S1"
5059 0x67, 0x6e, 0x00, // Language Tag "en"
5060 0x00, 0x52, 0x00, 0x52, 0x00, 0x33, 0x00, 0x00 // Entity Name "RR3"
5061 };
5062
5063 const char expectTag0[] = {0x65, 0x6e, 0x00};
5064 const char expectTag1[] = {0x66, 0x6e, 0x00};
5065 const char expectTag2[] = {0x67, 0x6e, 0x00};
5066 const char expectName0[] = {0x00, 0x53, 0x00, 0x30, 0x00, 0x53, 0x00, 0x00};
5067 const char expectName1[] = {0x00, 0x53, 0x00, 0x31, 0x00, 0x00};
5068 const char expectName2[] = {0x00, 0x52, 0x00, 0x52, 0x00, 0x33, 0x00, 0x00};
5069 auto names_offset = sizeof(struct pldm_pdr_hdr) +
5070 PLDM_PDR_ENTITY_AUXILIARY_NAME_PDR_MIN_LENGTH;
5071 auto names_size = pdr1.size() - names_offset;
5072 size_t length = 0;
5073
5074 size_t decodedPdrSize =
5075 sizeof(struct pldm_entity_auxiliary_names_pdr) + names_size;
5076 auto decodedPdr =
5077 (struct pldm_entity_auxiliary_names_pdr*)malloc(decodedPdrSize);
5078 EXPECT_NE(nullptr, decodedPdr);
5079
5080 auto rc = decode_entity_auxiliary_names_pdr(pdr1.data(), pdr1.size(),
5081 decodedPdr, decodedPdrSize);
5082
5083 EXPECT_EQ(0, rc);
5084 EXPECT_EQ(1, decodedPdr->hdr.record_handle);
5085 EXPECT_EQ(1, decodedPdr->hdr.version);
5086 EXPECT_EQ(PLDM_ENTITY_AUXILIARY_NAMES_PDR, decodedPdr->hdr.type);
5087 EXPECT_EQ(1, decodedPdr->hdr.record_change_num);
5088 EXPECT_EQ(pdr1.size() - sizeof(struct pldm_pdr_hdr),
5089 decodedPdr->hdr.length);
5090 EXPECT_EQ(3, decodedPdr->container.entity_type);
5091 EXPECT_EQ(1, decodedPdr->container.entity_instance_num);
5092 EXPECT_EQ(PLDM_PLATFORM_ENTITY_SYSTEM_CONTAINER_ID,
5093 decodedPdr->container.entity_container_id);
5094 EXPECT_EQ(0, decodedPdr->shared_name_count);
5095 EXPECT_EQ(3, decodedPdr->name_string_count);
5096
5097 decodedPdr->names = (struct pldm_entity_auxiliary_name*)calloc(
5098 decodedPdr->name_string_count,
5099 sizeof(struct pldm_entity_auxiliary_name));
5100 EXPECT_NE(nullptr, decodedPdr->names);
5101
5102 rc = decode_pldm_entity_auxiliary_names_pdr_index(decodedPdr);
5103 EXPECT_EQ(0, rc);
5104
5105 length = strlen(decodedPdr->names[0].tag);
5106 EXPECT_EQ(strlen(expectTag0), length);
5107 EXPECT_EQ(strncmp(expectTag0, decodedPdr->names[0].tag, length + 1), 0);
5108
5109 // NOLINTBEGIN(clang-analyzer-unix.Malloc)
5110 ASSERT_EQ(0,
5111 (uintptr_t)decodedPdr->names[0].name & (alignof(char16_t) - 1));
5112 // NOLINTEND(clang-analyzer-unix.Malloc)
5113 length = str16len((char16_t*)decodedPdr->names[0].name);
5114 EXPECT_EQ(str16len((char16_t*)expectName0), length);
5115 EXPECT_EQ(3, str16len((char16_t*)expectName0));
5116 EXPECT_EQ(memcmp(expectName0, decodedPdr->names[0].name,
5117 sizeof(char16_t) * (length + 1)),
5118 0);
5119
5120 length = strlen(decodedPdr->names[1].tag);
5121 EXPECT_EQ(strlen(expectTag1), length);
5122 EXPECT_EQ(strncmp(expectTag1, decodedPdr->names[1].tag, length + 1), 0);
5123
5124 // NOLINTBEGIN(clang-analyzer-unix.Malloc)
5125 ASSERT_EQ(0,
5126 (uintptr_t)decodedPdr->names[1].name & (alignof(char16_t) - 1));
5127 // NOLINTEND(clang-analyzer-unix.Malloc)
5128 length = str16len((char16_t*)decodedPdr->names[1].name);
5129 EXPECT_EQ(str16len((char16_t*)expectName1), length);
5130 EXPECT_EQ(2, str16len((char16_t*)expectName1));
5131 EXPECT_EQ(memcmp(expectName1, decodedPdr->names[1].name,
5132 sizeof(char16_t) * (length + 1)),
5133 0);
5134
5135 length = strlen(decodedPdr->names[2].tag);
5136 EXPECT_EQ(strlen(expectTag2), length);
5137 EXPECT_EQ(strncmp(expectTag2, decodedPdr->names[2].tag, length + 1), 0);
5138
5139 // NOLINTBEGIN(clang-analyzer-unix.Malloc)
5140 ASSERT_EQ(0,
5141 (uintptr_t)decodedPdr->names[2].name & (alignof(char16_t) - 1));
5142 // NOLINTEND(clang-analyzer-unix.Malloc)
5143 length = str16len((char16_t*)decodedPdr->names[2].name);
5144 EXPECT_EQ(str16len((char16_t*)expectName2), length);
5145 EXPECT_EQ(3, str16len((char16_t*)expectName2));
5146 EXPECT_EQ(memcmp(expectName2, decodedPdr->names[2].name,
5147 sizeof(char16_t) * (length + 1)),
5148 0);
5149
5150 free(decodedPdr->names);
5151 free(decodedPdr);
5152}
Thu Nguyendacfa352024-06-22 09:53:15 +00005153
Thu Nguyendacfa352024-06-22 09:53:15 +00005154TEST(decodeEntityAuxNamePdrData, BadTest)
5155{
5156 std::vector<uint8_t> pdr1{
5157 // Common PDR Header
5158 0x1, 0x0, 0x0, 0x0, // record handle
5159 0x1, // PDRHeaderVersion
5160 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
5161 0x1,
5162 0x0, // recordChangeNumber
5163 0x25, // correct size is 0x27, input invalid size
5164 0, // dataLength
5165 /* Entity Auxiliary Names PDR Data*/
5166 3,
5167 0, // entityType system software
5168 0x1,
5169 0x0, // Entity instance number =1
5170 PLDM_PLATFORM_ENTITY_SYSTEM_CONTAINER_ID,
5171 0, // Overal system
5172 0, // shared Name Count one name only
5173 0, // Invalid nameStringCount
5174 0x65, 0x6e, 0x00, // Language Tag "en"
5175 0x00, 0x53, 0x00, 0x30, 0x00, 0x53, 0x00, 0x00, // Entity Name "S0S"
5176 0x66, 0x6e, 0x00, // Language Tag "en"
5177 0x00, 0x53, 0x00, 0x31, 0x00, 0x00, // Entity Name "S1"
5178 0x67, 0x6e, 0x00, // Language Tag "en"
5179 0x00, 0x52, 0x00, 0x52, 0x00, 0x33, 0x00, 0x00 // Entity Name "RR3"
5180 };
5181
5182 auto names_offset = sizeof(struct pldm_pdr_hdr) +
5183 PLDM_PDR_ENTITY_AUXILIARY_NAME_PDR_MIN_LENGTH;
5184 auto names_size = pdr1.size() - names_offset;
5185
5186 size_t decodedPdrSize =
5187 sizeof(struct pldm_entity_auxiliary_names_pdr) + names_size;
5188 auto decodedPdr =
5189 (struct pldm_entity_auxiliary_names_pdr*)malloc(decodedPdrSize);
5190
5191 auto rc = decode_entity_auxiliary_names_pdr(pdr1.data(), pdr1.size(),
5192 decodedPdr, decodedPdrSize);
5193
5194 EXPECT_EQ(-EBADMSG, rc);
5195 free(decodedPdr);
5196}