blob: 2d294455d9e100d5478c0ecf0107c25a7e084446 [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{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +093024 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +093025 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
26 uint8_t completionCode = 0;
27
28 auto rc = encode_set_state_effecter_states_resp(0, PLDM_SUCCESS, response);
29
30 EXPECT_EQ(rc, PLDM_SUCCESS);
31 EXPECT_EQ(completionCode, response->payload[0]);
32}
33
34TEST(SetStateEffecterStates, testEncodeRequest)
35{
36 std::array<uint8_t,
37 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES>
38 requestMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +093039 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +093040 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
41
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -060042 uint16_t effecterId = 0x0a;
Andrew Jeffery9c766792022-08-10 23:12:49 +093043 uint8_t compEffecterCnt = 0x2;
44 std::array<set_effecter_state_field, 8> stateField{};
45 stateField[0] = {PLDM_REQUEST_SET, 2};
46 stateField[1] = {PLDM_REQUEST_SET, 3};
47
48 auto rc = encode_set_state_effecter_states_req(
49 0, effecterId, compEffecterCnt, stateField.data(), request);
50
51 EXPECT_EQ(rc, PLDM_SUCCESS);
52 EXPECT_EQ(effecterId, request->payload[0]);
53 EXPECT_EQ(compEffecterCnt, request->payload[sizeof(effecterId)]);
54 EXPECT_EQ(stateField[0].set_request,
55 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt)]);
56 EXPECT_EQ(stateField[0].effecter_state,
57 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
58 sizeof(stateField[0].set_request)]);
59 EXPECT_EQ(stateField[1].set_request,
60 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
61 sizeof(stateField[0])]);
62 EXPECT_EQ(stateField[1].effecter_state,
63 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
64 sizeof(stateField[0]) +
65 sizeof(stateField[1].set_request)]);
66}
67
68TEST(SetStateEffecterStates, testGoodDecodeResponse)
69{
70 std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
71 responseMsg{};
72
73 uint8_t retcompletion_code = 0;
74
75 responseMsg[hdrSize] = PLDM_SUCCESS;
76
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +093077 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +093078 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
79
80 auto rc = decode_set_state_effecter_states_resp(
81 response, responseMsg.size() - hdrSize, &retcompletion_code);
82
83 EXPECT_EQ(rc, PLDM_SUCCESS);
84 EXPECT_EQ(PLDM_SUCCESS, retcompletion_code);
85}
86
87TEST(SetStateEffecterStates, testGoodDecodeRequest)
88{
89 std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES>
90 requestMsg{};
91
92 uint16_t effecterId = 0x32;
93 uint16_t effecterIdLE = htole16(effecterId);
94 uint8_t compEffecterCnt = 0x2;
95
96 std::array<set_effecter_state_field, 8> stateField{};
97 stateField[0] = {PLDM_REQUEST_SET, 3};
98 stateField[1] = {PLDM_REQUEST_SET, 4};
99
100 uint16_t retEffecterId = 0;
101 uint8_t retCompEffecterCnt = 0;
102
103 std::array<set_effecter_state_field, 8> retStateField{};
104
105 memcpy(requestMsg.data() + hdrSize, &effecterIdLE, sizeof(effecterIdLE));
106 memcpy(requestMsg.data() + sizeof(effecterIdLE) + hdrSize, &compEffecterCnt,
107 sizeof(compEffecterCnt));
108 memcpy(requestMsg.data() + sizeof(effecterIdLE) + sizeof(compEffecterCnt) +
109 hdrSize,
110 &stateField, sizeof(stateField));
111
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930112 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930113 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
114
115 auto rc = decode_set_state_effecter_states_req(
116 request, requestMsg.size() - hdrSize, &retEffecterId,
117 &retCompEffecterCnt, retStateField.data());
118
119 EXPECT_EQ(rc, PLDM_SUCCESS);
120 EXPECT_EQ(effecterId, retEffecterId);
121 EXPECT_EQ(retCompEffecterCnt, compEffecterCnt);
122 EXPECT_EQ(retStateField[0].set_request, stateField[0].set_request);
123 EXPECT_EQ(retStateField[0].effecter_state, stateField[0].effecter_state);
124 EXPECT_EQ(retStateField[1].set_request, stateField[1].set_request);
125 EXPECT_EQ(retStateField[1].effecter_state, stateField[1].effecter_state);
126}
127
128TEST(SetStateEffecterStates, testBadDecodeRequest)
129{
130 const struct pldm_msg* msg = NULL;
131
132 auto rc = decode_set_state_effecter_states_req(msg, sizeof(*msg), NULL,
133 NULL, NULL);
134
135 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
136}
137
138TEST(SetStateEffecterStates, testBadDecodeResponse)
139{
140 std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
141 responseMsg{};
142
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930143 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930144 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
145
146 auto rc = decode_set_state_effecter_states_resp(response,
147 responseMsg.size(), NULL);
148
149 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
150}
151
152TEST(GetPDR, testGoodEncodeResponse)
153{
154 uint8_t completionCode = 0;
155 uint32_t nextRecordHndl = 0x12;
156 uint32_t nextDataTransferHndl = 0x13;
157 uint8_t transferFlag = PLDM_END;
158 uint16_t respCnt = 0x5;
159 std::vector<uint8_t> recordData{1, 2, 3, 4, 5};
160 uint8_t transferCRC = 6;
161
162 // + size of record data and transfer CRC
163 std::vector<uint8_t> responseMsg(hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES +
164 recordData.size() + 1);
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930165 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930166 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
167
168 auto rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl,
169 nextDataTransferHndl, transferFlag, respCnt,
170 recordData.data(), transferCRC, response);
171
172 EXPECT_EQ(rc, PLDM_SUCCESS);
173 struct pldm_get_pdr_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930174 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930175 reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload);
176
177 EXPECT_EQ(completionCode, resp->completion_code);
178 EXPECT_EQ(nextRecordHndl, le32toh(resp->next_record_handle));
179 EXPECT_EQ(nextDataTransferHndl, le32toh(resp->next_data_transfer_handle));
180 EXPECT_EQ(transferFlag, resp->transfer_flag);
181 EXPECT_EQ(respCnt, le16toh(resp->response_count));
182 EXPECT_EQ(0,
183 memcmp(recordData.data(), resp->record_data, recordData.size()));
184 EXPECT_EQ(*(response->payload + sizeof(pldm_get_pdr_resp) - 1 +
185 recordData.size()),
186 transferCRC);
187
188 transferFlag = PLDM_START_AND_END; // No CRC in this case
189 responseMsg.resize(responseMsg.size() - sizeof(transferCRC));
190 rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl,
191 nextDataTransferHndl, transferFlag, respCnt,
192 recordData.data(), transferCRC, response);
193 EXPECT_EQ(rc, PLDM_SUCCESS);
194}
195
196TEST(GetPDR, testBadEncodeResponse)
197{
198 uint32_t nextRecordHndl = 0x12;
199 uint32_t nextDataTransferHndl = 0x13;
200 uint8_t transferFlag = PLDM_START_AND_END;
201 uint16_t respCnt = 0x5;
202 std::vector<uint8_t> recordData{1, 2, 3, 4, 5};
203 uint8_t transferCRC = 0;
204
205 auto rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl,
206 nextDataTransferHndl, transferFlag, respCnt,
207 recordData.data(), transferCRC, nullptr);
208
209 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
210}
211
212TEST(GetPDR, testGoodDecodeRequest)
213{
214 std::array<uint8_t, hdrSize + PLDM_GET_PDR_REQ_BYTES> requestMsg{};
215
216 uint32_t recordHndl = 0x32;
217 uint32_t dataTransferHndl = 0x11;
218 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
219 uint16_t requestCnt = 0x5;
220 uint16_t recordChangeNum = 0x01;
221
222 uint32_t retRecordHndl = 0;
223 uint32_t retDataTransferHndl = 0;
224 uint8_t retTransferOpFlag = 0;
225 uint16_t retRequestCnt = 0;
226 uint16_t retRecordChangeNum = 0;
227
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930228 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930229 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
230 struct pldm_get_pdr_req* request =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930231 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930232 reinterpret_cast<struct pldm_get_pdr_req*>(req->payload);
233
234 request->record_handle = htole32(recordHndl);
235 request->data_transfer_handle = htole32(dataTransferHndl);
236 request->transfer_op_flag = transferOpFlag;
237 request->request_count = htole16(requestCnt);
238 request->record_change_number = htole16(recordChangeNum);
239
240 auto rc = decode_get_pdr_req(
241 req, requestMsg.size() - hdrSize, &retRecordHndl, &retDataTransferHndl,
242 &retTransferOpFlag, &retRequestCnt, &retRecordChangeNum);
243
244 EXPECT_EQ(rc, PLDM_SUCCESS);
245 EXPECT_EQ(retRecordHndl, recordHndl);
246 EXPECT_EQ(retDataTransferHndl, dataTransferHndl);
247 EXPECT_EQ(retTransferOpFlag, transferOpFlag);
248 EXPECT_EQ(retRequestCnt, requestCnt);
249 EXPECT_EQ(retRecordChangeNum, recordChangeNum);
250}
251
252TEST(GetPDR, testBadDecodeRequest)
253{
254 std::array<uint8_t, PLDM_GET_PDR_REQ_BYTES> requestMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930255 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930256 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
257
258 auto rc = decode_get_pdr_req(req, requestMsg.size(), NULL, NULL, NULL, NULL,
259 NULL);
260
261 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
262}
263
264TEST(GetPDR, testGoodEncodeRequest)
265{
266 uint32_t record_hndl = 0;
267 uint32_t data_transfer_hndl = 0;
268 uint8_t transfer_op_flag = PLDM_GET_FIRSTPART;
269 uint16_t request_cnt = 20;
270 uint16_t record_chg_num = 0;
271
272 std::vector<uint8_t> requestMsg(hdrSize + PLDM_GET_PDR_REQ_BYTES);
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930273 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930274 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
275
276 auto rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl,
277 transfer_op_flag, request_cnt, record_chg_num,
278 request, PLDM_GET_PDR_REQ_BYTES);
279 EXPECT_EQ(rc, PLDM_SUCCESS);
280 struct pldm_get_pdr_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930281 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930282 reinterpret_cast<struct pldm_get_pdr_req*>(request->payload);
283 EXPECT_EQ(record_hndl, le32toh(req->record_handle));
284 EXPECT_EQ(data_transfer_hndl, le32toh(req->data_transfer_handle));
285 EXPECT_EQ(transfer_op_flag, req->transfer_op_flag);
286 EXPECT_EQ(request_cnt, le16toh(req->request_count));
287 EXPECT_EQ(record_chg_num, le16toh(req->record_change_number));
288}
289
290TEST(GetPDR, testBadEncodeRequest)
291{
292 uint32_t record_hndl = 0;
293 uint32_t data_transfer_hndl = 0;
294 uint8_t transfer_op_flag = PLDM_GET_FIRSTPART;
295 uint16_t request_cnt = 32;
296 uint16_t record_chg_num = 0;
297
298 std::vector<uint8_t> requestMsg(hdrSize + PLDM_GET_PDR_REQ_BYTES);
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930299 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930300 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
301
302 auto rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl,
303 transfer_op_flag, request_cnt, record_chg_num,
304 nullptr, PLDM_GET_PDR_REQ_BYTES);
305 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
306
307 rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl,
308 transfer_op_flag, request_cnt, record_chg_num,
309 request, PLDM_GET_PDR_REQ_BYTES + 1);
310 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
311}
312
313TEST(GetPDR, testGoodDecodeResponse)
314{
315 const char* recordData = "123456789";
316 uint8_t completionCode = PLDM_SUCCESS;
317 uint32_t nextRecordHndl = 0;
318 uint32_t nextDataTransferHndl = 0;
319 uint8_t transferFlag = PLDM_END;
320 constexpr uint16_t respCnt = 9;
321 uint8_t transferCRC = 96;
322 size_t recordDataLength = 32;
323 std::array<uint8_t, hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES + respCnt +
324 sizeof(transferCRC)>
325 responseMsg{};
326
327 uint8_t retCompletionCode = 0;
328 uint8_t retRecordData[32] = {0};
329 uint32_t retNextRecordHndl = 0;
330 uint32_t retNextDataTransferHndl = 0;
331 uint8_t retTransferFlag = 0;
332 uint16_t retRespCnt = 0;
333 uint8_t retTransferCRC = 0;
334
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930335 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930336 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
337 struct pldm_get_pdr_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930338 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930339 reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload);
340 resp->completion_code = completionCode;
341 resp->next_record_handle = htole32(nextRecordHndl);
342 resp->next_data_transfer_handle = htole32(nextDataTransferHndl);
343 resp->transfer_flag = transferFlag;
344 resp->response_count = htole16(respCnt);
345 memcpy(resp->record_data, recordData, respCnt);
346 response->payload[PLDM_GET_PDR_MIN_RESP_BYTES + respCnt] = transferCRC;
347
348 auto rc = decode_get_pdr_resp(
349 response, responseMsg.size() - hdrSize, &retCompletionCode,
350 &retNextRecordHndl, &retNextDataTransferHndl, &retTransferFlag,
351 &retRespCnt, retRecordData, recordDataLength, &retTransferCRC);
352 EXPECT_EQ(rc, PLDM_SUCCESS);
353 EXPECT_EQ(retCompletionCode, completionCode);
354 EXPECT_EQ(retNextRecordHndl, nextRecordHndl);
355 EXPECT_EQ(retNextDataTransferHndl, nextDataTransferHndl);
356 EXPECT_EQ(retTransferFlag, transferFlag);
357 EXPECT_EQ(retRespCnt, respCnt);
358 EXPECT_EQ(retTransferCRC, transferCRC);
359 EXPECT_EQ(0, memcmp(recordData, resp->record_data, respCnt));
360}
361
362TEST(GetPDR, testBadDecodeResponse)
363{
364 const char* recordData = "123456789";
365 uint8_t completionCode = PLDM_SUCCESS;
366 uint32_t nextRecordHndl = 0;
367 uint32_t nextDataTransferHndl = 0;
368 uint8_t transferFlag = PLDM_END;
369 constexpr uint16_t respCnt = 9;
370 uint8_t transferCRC = 96;
Andrew Jeffery4e5e8a22023-04-04 11:58:45 +0930371 size_t recordDataLength = respCnt - 1;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930372 std::array<uint8_t, hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES + respCnt +
373 sizeof(transferCRC)>
374 responseMsg{};
375
376 uint8_t retCompletionCode = 0;
377 uint8_t retRecordData[32] = {0};
378 uint32_t retNextRecordHndl = 0;
379 uint32_t retNextDataTransferHndl = 0;
380 uint8_t retTransferFlag = 0;
381 uint16_t retRespCnt = 0;
382 uint8_t retTransferCRC = 0;
383
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930384 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930385 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
386 struct pldm_get_pdr_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930387 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930388 reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload);
389 resp->completion_code = completionCode;
390 resp->next_record_handle = htole32(nextRecordHndl);
391 resp->next_data_transfer_handle = htole32(nextDataTransferHndl);
392 resp->transfer_flag = transferFlag;
393 resp->response_count = htole16(respCnt);
394 memcpy(resp->record_data, recordData, respCnt);
395 response->payload[PLDM_GET_PDR_MIN_RESP_BYTES + respCnt] = transferCRC;
396
397 auto rc = decode_get_pdr_resp(response, responseMsg.size() - hdrSize, NULL,
398 NULL, NULL, NULL, NULL, NULL, 0, NULL);
399 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
400
401 rc = decode_get_pdr_resp(
402 response, responseMsg.size() - hdrSize - 1, &retCompletionCode,
403 &retNextRecordHndl, &retNextDataTransferHndl, &retTransferFlag,
404 &retRespCnt, retRecordData, recordDataLength, &retTransferCRC);
405 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
406}
407
Andrew Jeffery0a1be3c2024-08-11 08:34:10 +0000408#ifdef LIBPLDM_API_TESTING
409TEST(GetPDR, testGoodDecodeResponseSafe)
410{
411 static const char recordData[] = "123456789";
412
413 alignas(pldm_msg) unsigned char data[sizeof(pldm_msg_hdr) +
414 PLDM_GET_PDR_MIN_RESP_BYTES +
415 sizeof(recordData) - 1 + 1];
416 struct pldm_msgbuf _buf;
417 struct pldm_msgbuf* buf = &_buf;
418 int rc;
419
420 pldm_msg* msg = new (data) pldm_msg;
421
422 rc = pldm_msgbuf_init_errno(buf, PLDM_GET_PDR_MIN_RESP_BYTES, msg->payload,
423 sizeof(data) - sizeof(msg->hdr));
424 ASSERT_EQ(rc, 0);
425
426 pldm_msgbuf_insert_uint8(buf, PLDM_SUCCESS);
427 pldm_msgbuf_insert_uint32(buf, 0);
428 pldm_msgbuf_insert_uint32(buf, 0);
429 pldm_msgbuf_insert_uint8(buf, PLDM_END);
430 pldm_msgbuf_insert_uint16(buf, sizeof(recordData) - 1);
431 rc = pldm_msgbuf_insert_array_char(buf, sizeof(recordData) - 1, recordData,
432 sizeof(recordData) - 1);
433 ASSERT_EQ(rc, 0);
434 pldm_msgbuf_insert_uint8(buf, 96);
435 ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
436
437 alignas(pldm_get_pdr_resp) unsigned char
438 resp_data[sizeof(pldm_get_pdr_resp) + sizeof(recordData) - 1];
439 pldm_get_pdr_resp* resp = new (resp_data) pldm_get_pdr_resp;
440 uint8_t crc;
441 rc = decode_get_pdr_resp_safe(msg, sizeof(data) - sizeof(msg->hdr), resp,
442 sizeof(resp_data) - sizeof(*resp), &crc);
443 ASSERT_EQ(rc, 0);
444 EXPECT_EQ(resp->completion_code, PLDM_SUCCESS);
445 EXPECT_EQ(resp->next_record_handle, 0);
446 EXPECT_EQ(resp->next_data_transfer_handle, 0);
447 EXPECT_EQ(resp->transfer_flag, PLDM_END);
448 ASSERT_EQ(resp->response_count, sizeof(recordData) - 1);
449 EXPECT_EQ(crc, 96);
450 EXPECT_EQ(0, memcmp(recordData, resp->record_data, resp->response_count));
451}
452#endif
453
454#ifdef LIBPLDM_API_TESTING
455TEST(GetPDR, testBadDecodeResponseSafeTrivial)
456{
457 pldm_get_pdr_resp resp;
458 uint8_t crc;
459 int rc;
460
461 rc = decode_get_pdr_resp_safe(nullptr, PLDM_GET_PDR_MIN_RESP_BYTES, &resp,
462 sizeof(resp), &crc);
463 EXPECT_EQ(rc, -EINVAL);
464
465 alignas(pldm_msg) unsigned char
466 msg_data[sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES];
467 pldm_msg* msg = new (msg_data) pldm_msg;
468 rc = decode_get_pdr_resp_safe(msg, PLDM_GET_PDR_MIN_RESP_BYTES, nullptr,
469 sizeof(resp), &crc);
470 EXPECT_EQ(rc, -EINVAL);
471
472 rc = decode_get_pdr_resp_safe(msg, PLDM_GET_PDR_MIN_RESP_BYTES, &resp,
473 sizeof(resp), nullptr);
474 EXPECT_EQ(rc, -EINVAL);
475
476 msg->payload[0] = PLDM_ERROR_INVALID_DATA;
477 rc = decode_get_pdr_resp_safe(msg, 1, &resp, sizeof(resp), &crc);
478 EXPECT_EQ(rc, 0);
479 EXPECT_EQ(resp.completion_code, PLDM_ERROR_INVALID_DATA);
480}
481#endif
482
Andrew Jeffery9c766792022-08-10 23:12:49 +0930483TEST(GetPDRRepositoryInfo, testGoodEncodeResponse)
484{
485 uint8_t completionCode = 0;
486 uint8_t repositoryState = PLDM_AVAILABLE;
487 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
488 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
489 uint32_t recordCount = 100;
490 uint32_t repositorySize = 100;
491 uint32_t largestRecordSize = UINT32_MAX;
492 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
493
494 std::vector<uint8_t> responseMsg(hdrSize +
495 PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES);
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930496 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930497 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
498
499 auto rc = encode_get_pdr_repository_info_resp(
500 0, PLDM_SUCCESS, repositoryState, updateTime, oemUpdateTime,
501 recordCount, repositorySize, largestRecordSize,
502 dataTransferHandleTimeout, response);
503
504 EXPECT_EQ(rc, PLDM_SUCCESS);
505 struct pldm_pdr_repository_info_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930506 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930507 reinterpret_cast<struct pldm_pdr_repository_info_resp*>(
508 response->payload);
509
510 EXPECT_EQ(completionCode, resp->completion_code);
511 EXPECT_EQ(repositoryState, resp->repository_state);
512 EXPECT_EQ(0, memcmp(updateTime, resp->update_time, PLDM_TIMESTAMP104_SIZE));
513 EXPECT_EQ(0, memcmp(oemUpdateTime, resp->oem_update_time,
514 PLDM_TIMESTAMP104_SIZE));
515 EXPECT_EQ(recordCount, le32toh(resp->record_count));
516 EXPECT_EQ(repositorySize, le32toh(resp->repository_size));
517 EXPECT_EQ(largestRecordSize, le32toh(resp->largest_record_size));
518 EXPECT_EQ(dataTransferHandleTimeout, resp->data_transfer_handle_timeout);
519}
520
521TEST(GetPDRRepositoryInfo, testBadEncodeResponse)
522{
523 uint8_t repositoryState = PLDM_AVAILABLE;
524 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
525 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
526 uint32_t recordCount = 100;
527 uint32_t repositorySize = 100;
528 uint32_t largestRecordSize = UINT32_MAX;
529 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
530
531 auto rc = encode_get_pdr_repository_info_resp(
532 0, PLDM_SUCCESS, repositoryState, updateTime, oemUpdateTime,
533 recordCount, repositorySize, largestRecordSize,
534 dataTransferHandleTimeout, nullptr);
535 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
536}
537
Gilbert Chenb7c73e52022-11-10 11:29:52 +0800538TEST(GetPDRRepositoryInfo, testGoodDecodeResponse)
539{
540 uint8_t completionCode = PLDM_SUCCESS;
541 uint8_t repositoryState = PLDM_AVAILABLE;
542 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
543 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
544 uint32_t recordCount = 100;
545 uint32_t repositorySize = 100;
546 uint32_t largestRecordSize = UINT32_MAX;
547 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
548
549 std::array<uint8_t, hdrSize + PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES>
550 responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930551 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Gilbert Chenb7c73e52022-11-10 11:29:52 +0800552 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
553 struct pldm_pdr_repository_info_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930554 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Gilbert Chenb7c73e52022-11-10 11:29:52 +0800555 reinterpret_cast<struct pldm_pdr_repository_info_resp*>(
556 response->payload);
557 resp->completion_code = completionCode;
558 resp->repository_state = repositoryState;
559 memcpy(resp->update_time, updateTime, PLDM_TIMESTAMP104_SIZE);
560 memcpy(resp->oem_update_time, oemUpdateTime, PLDM_TIMESTAMP104_SIZE);
561 resp->record_count = htole32(recordCount);
562 resp->repository_size = htole32(repositorySize);
563 resp->largest_record_size = htole32(largestRecordSize);
564 resp->data_transfer_handle_timeout = dataTransferHandleTimeout;
565
566 uint8_t retCompletionCode = 0;
567 uint8_t retRepositoryState = 0;
568 uint8_t retUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
569 uint8_t retOemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
570 uint32_t retRecordCount = 0;
571 uint32_t retRepositorySize = 0;
572 uint32_t retLargestRecordSize = 0;
573 uint8_t retDataTransferHandleTimeout = 0;
574
575 auto rc = decode_get_pdr_repository_info_resp(
576 response, responseMsg.size() - hdrSize, &retCompletionCode,
577 &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount,
578 &retRepositorySize, &retLargestRecordSize,
579 &retDataTransferHandleTimeout);
580
581 EXPECT_EQ(rc, PLDM_SUCCESS);
582 EXPECT_EQ(completionCode, retCompletionCode);
583 EXPECT_EQ(repositoryState, retRepositoryState);
584 EXPECT_EQ(0, memcmp(updateTime, retUpdateTime, PLDM_TIMESTAMP104_SIZE));
585 EXPECT_EQ(0,
586 memcmp(oemUpdateTime, retOemUpdateTime, PLDM_TIMESTAMP104_SIZE));
587 EXPECT_EQ(recordCount, recordCount);
588 EXPECT_EQ(repositorySize, repositorySize);
589 EXPECT_EQ(largestRecordSize, largestRecordSize);
590 EXPECT_EQ(dataTransferHandleTimeout, dataTransferHandleTimeout);
591}
592
593TEST(GetPDRRepositoryInfo, testBadDecodeResponse)
594{
595 uint8_t completionCode = PLDM_SUCCESS;
596 uint8_t repositoryState = PLDM_AVAILABLE;
597 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
598 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
599 uint32_t recordCount = htole32(100);
600 uint32_t repositorySize = htole32(100);
601 uint32_t largestRecordSize = htole32(UINT32_MAX);
602 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
603
604 std::array<uint8_t, hdrSize + PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES>
605 responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930606 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Gilbert Chenb7c73e52022-11-10 11:29:52 +0800607 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
608 struct pldm_pdr_repository_info_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930609 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Gilbert Chenb7c73e52022-11-10 11:29:52 +0800610 reinterpret_cast<struct pldm_pdr_repository_info_resp*>(
611 response->payload);
612 resp->completion_code = completionCode;
613 resp->repository_state = repositoryState;
614 memcpy(resp->update_time, updateTime, PLDM_TIMESTAMP104_SIZE);
615 memcpy(resp->oem_update_time, oemUpdateTime, PLDM_TIMESTAMP104_SIZE);
616 resp->record_count = recordCount;
617 resp->repository_size = repositorySize;
618 resp->largest_record_size = largestRecordSize;
619 resp->data_transfer_handle_timeout = dataTransferHandleTimeout;
620
621 uint8_t retCompletionCode = 0;
622 uint8_t retRepositoryState = 0;
623 uint8_t retUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
624 uint8_t retOemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
625 uint32_t retRecordCount = 0;
626 uint32_t retRepositorySize = 0;
627 uint32_t retLargestRecordSize = 0;
628 uint8_t retDataTransferHandleTimeout = 0;
629
630 auto rc = decode_get_pdr_repository_info_resp(
631 response, responseMsg.size() - hdrSize, NULL, NULL, NULL, NULL, NULL,
632 NULL, NULL, NULL);
633 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
634
635 rc = decode_get_pdr_repository_info_resp(
636 response, responseMsg.size() - hdrSize - 1, &retCompletionCode,
637 &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount,
638 &retRepositorySize, &retLargestRecordSize,
639 &retDataTransferHandleTimeout);
640 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
641
642 resp->repository_state = PLDM_FAILED + 1;
643 rc = decode_get_pdr_repository_info_resp(
644 response, responseMsg.size() - hdrSize, &retCompletionCode,
645 &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount,
646 &retRepositorySize, &retLargestRecordSize,
647 &retDataTransferHandleTimeout);
648 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
649}
650
Andrew Jeffery0a1be3c2024-08-11 08:34:10 +0000651#ifdef LIBPLDM_API_TESTING
652TEST(GetPDRRepositoryInfo, testGoodDecodeResponseSafe)
653{
654 alignas(pldm_msg) unsigned char
655 data[sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES];
656 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
657 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
658 struct pldm_msgbuf _buf;
659 struct pldm_msgbuf* buf = &_buf;
660 int rc;
661
662 pldm_msg* msg = new (data) pldm_msg;
663
664 rc = pldm_msgbuf_init_errno(buf, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES,
665 msg->payload, sizeof(data) - sizeof(msg->hdr));
666 ASSERT_EQ(rc, 0);
667 pldm_msgbuf_insert_uint8(buf, PLDM_SUCCESS);
668 pldm_msgbuf_insert_uint8(buf, PLDM_AVAILABLE);
669 rc = pldm_msgbuf_insert_array_uint8(buf, PLDM_TIMESTAMP104_SIZE, updateTime,
670 sizeof(updateTime));
671 ASSERT_EQ(rc, 0);
672 rc = pldm_msgbuf_insert_array_uint8(buf, PLDM_TIMESTAMP104_SIZE,
673 oemUpdateTime, sizeof(oemUpdateTime));
674 ASSERT_EQ(rc, 0);
675 pldm_msgbuf_insert_uint32(buf, 100);
676 pldm_msgbuf_insert_uint32(buf, 100);
677 pldm_msgbuf_insert_uint32(buf, UINT32_MAX);
678 pldm_msgbuf_insert_uint8(buf, PLDM_NO_TIMEOUT);
679 ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
680
681 struct pldm_pdr_repository_info_resp resp;
682 rc = decode_get_pdr_repository_info_resp_safe(
683 msg, sizeof(data) - sizeof(msg->hdr), &resp);
684
685 EXPECT_EQ(rc, 0);
686 EXPECT_EQ(PLDM_SUCCESS, resp.completion_code);
687 EXPECT_EQ(PLDM_AVAILABLE, resp.repository_state);
688 EXPECT_EQ(0,
689 memcmp(updateTime, resp.update_time, sizeof(resp.update_time)));
690 EXPECT_EQ(0, memcmp(oemUpdateTime, resp.oem_update_time,
691 sizeof(resp.oem_update_time)));
692 EXPECT_EQ(100, resp.record_count);
693 EXPECT_EQ(100, resp.repository_size);
694 EXPECT_EQ(UINT32_MAX, resp.largest_record_size);
695 EXPECT_EQ(PLDM_NO_TIMEOUT, resp.data_transfer_handle_timeout);
696}
697#endif
698
699#ifdef LIBPLDM_API_TESTING
700TEST(GetPDRRepositoryInfo, testBadDecodeResponseSafeTrivial)
701{
702 struct pldm_pdr_repository_info_resp resp;
703 int rc;
704
705 rc = decode_get_pdr_repository_info_resp_safe(
706 nullptr, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES, &resp);
707 EXPECT_EQ(rc, -EINVAL);
708
709 alignas(pldm_msg) unsigned char
710 msg_data[sizeof(pldm_msg) - 1 +
711 PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES];
712 pldm_msg* msg = new (msg_data) pldm_msg;
713 rc = decode_get_pdr_repository_info_resp_safe(msg, 0, &resp);
714 EXPECT_EQ(rc, -EOVERFLOW);
715
716 rc = decode_get_pdr_repository_info_resp_safe(
717 msg, PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES, nullptr);
718 EXPECT_EQ(rc, -EINVAL);
719
720 msg->payload[0] = PLDM_ERROR_INVALID_DATA;
721 rc = decode_get_pdr_repository_info_resp_safe(msg, 1, &resp);
722 EXPECT_EQ(rc, 0);
723 EXPECT_EQ(resp.completion_code, PLDM_ERROR_INVALID_DATA);
724}
725#endif
726
Andrew Jeffery9c766792022-08-10 23:12:49 +0930727TEST(SetNumericEffecterValue, testGoodDecodeRequest)
728{
729 std::array<uint8_t,
730 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3>
731 requestMsg{};
732
733 uint16_t effecter_id = 32768;
734 uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT32;
735 uint32_t effecter_value = 123456789;
736
737 uint16_t reteffecter_id;
738 uint8_t reteffecter_data_size;
739 uint8_t reteffecter_value[4];
740
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930741 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930742 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
743 struct pldm_set_numeric_effecter_value_req* request =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930744 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930745 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
746 req->payload);
747
748 request->effecter_id = htole16(effecter_id);
749 request->effecter_data_size = effecter_data_size;
750 uint32_t effecter_value_le = htole32(effecter_value);
751 memcpy(request->effecter_value, &effecter_value_le,
752 sizeof(effecter_value_le));
753
754 auto rc = decode_set_numeric_effecter_value_req(
755 req, requestMsg.size() - hdrSize, &reteffecter_id,
756 &reteffecter_data_size, reteffecter_value);
757
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930758 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930759 uint32_t value = *(reinterpret_cast<uint32_t*>(reteffecter_value));
760 EXPECT_EQ(rc, PLDM_SUCCESS);
761 EXPECT_EQ(reteffecter_id, effecter_id);
762 EXPECT_EQ(reteffecter_data_size, effecter_data_size);
763 EXPECT_EQ(value, effecter_value);
764}
765
766TEST(SetNumericEffecterValue, testBadDecodeRequest)
767{
768 std::array<uint8_t, hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES>
769 requestMsg{};
770
771 auto rc = decode_set_numeric_effecter_value_req(
772 NULL, requestMsg.size() - hdrSize, NULL, NULL, NULL);
773 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
774
775 uint16_t effecter_id = 0x10;
776 uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT8;
777 uint8_t effecter_value = 1;
778
779 uint16_t reteffecter_id;
780 uint8_t reteffecter_data_size;
781 uint8_t reteffecter_value[4];
782
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930783 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930784 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
785 struct pldm_set_numeric_effecter_value_req* request =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930786 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930787 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
788 req->payload);
789
790 request->effecter_id = effecter_id;
791 request->effecter_data_size = effecter_data_size;
792 memcpy(request->effecter_value, &effecter_value, sizeof(effecter_value));
793
794 rc = decode_set_numeric_effecter_value_req(
795 req, requestMsg.size() - hdrSize - 1, &reteffecter_id,
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930796 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930797 &reteffecter_data_size, reinterpret_cast<uint8_t*>(&reteffecter_value));
798 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
799}
800
801TEST(SetNumericEffecterValue, testGoodEncodeRequest)
802{
803 uint16_t effecter_id = 0;
804 uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT16;
805 uint16_t effecter_value = 65534;
806
807 std::vector<uint8_t> requestMsg(
808 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1);
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930809 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930810 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
811
812 auto rc = encode_set_numeric_effecter_value_req(
813 0, effecter_id, effecter_data_size,
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930814 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930815 reinterpret_cast<uint8_t*>(&effecter_value), request,
816 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1);
817 EXPECT_EQ(rc, PLDM_SUCCESS);
818
819 struct pldm_set_numeric_effecter_value_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930820 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930821 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
822 request->payload);
823 EXPECT_EQ(effecter_id, req->effecter_id);
824 EXPECT_EQ(effecter_data_size, req->effecter_data_size);
825 uint16_t* val = (uint16_t*)req->effecter_value;
826 *val = le16toh(*val);
827 EXPECT_EQ(effecter_value, *val);
828}
829
830TEST(SetNumericEffecterValue, testBadEncodeRequest)
831{
832 std::vector<uint8_t> requestMsg(
833 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930834 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930835 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
836
837 auto rc = encode_set_numeric_effecter_value_req(
838 0, 0, 0, NULL, NULL, PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
839 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
840
841 uint16_t effecter_value;
842 rc = encode_set_numeric_effecter_value_req(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930843 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930844 0, 0, 6, reinterpret_cast<uint8_t*>(&effecter_value), request,
845 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
846 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
847}
848
849TEST(SetNumericEffecterValue, testGoodDecodeResponse)
850{
851 std::array<uint8_t, hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES>
852 responseMsg{};
853
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -0600854 uint8_t completion_code = 0xa0;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930855
856 uint8_t retcompletion_code;
857
858 memcpy(responseMsg.data() + hdrSize, &completion_code,
859 sizeof(completion_code));
860
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930861 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930862 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
863
864 auto rc = decode_set_numeric_effecter_value_resp(
865 response, responseMsg.size() - hdrSize, &retcompletion_code);
866
867 EXPECT_EQ(rc, PLDM_SUCCESS);
868 EXPECT_EQ(completion_code, retcompletion_code);
869}
870
871TEST(SetNumericEffecterValue, testBadDecodeResponse)
872{
873 std::array<uint8_t, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES>
874 responseMsg{};
875
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930876 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930877 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
878
879 auto rc = decode_set_numeric_effecter_value_resp(response,
880 responseMsg.size(), NULL);
881
882 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
883}
884
885TEST(SetNumericEffecterValue, testGoodEncodeResponse)
886{
887 std::array<uint8_t, sizeof(pldm_msg_hdr) +
888 PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES>
889 responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930890 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930891 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
892 uint8_t completionCode = 0;
893
894 auto rc = encode_set_numeric_effecter_value_resp(
895 0, PLDM_SUCCESS, response, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES);
896
897 EXPECT_EQ(rc, PLDM_SUCCESS);
898 EXPECT_EQ(completionCode, response->payload[0]);
899}
900
901TEST(SetNumericEffecterValue, testBadEncodeResponse)
902{
903 auto rc = encode_set_numeric_effecter_value_resp(
904 0, PLDM_SUCCESS, NULL, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES);
905 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
906}
907
908TEST(GetStateSensorReadings, testGoodEncodeResponse)
909{
910 std::array<uint8_t, hdrSize +
911 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
912 sizeof(get_sensor_state_field) * 2>
913 responseMsg{};
914
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930915 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930916 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
917 uint8_t completionCode = 0;
918 uint8_t comp_sensorCnt = 0x2;
919
920 std::array<get_sensor_state_field, 2> stateField{};
921 stateField[0] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_NORMAL,
922 PLDM_SENSOR_WARNING, PLDM_SENSOR_UNKNOWN};
923 stateField[1] = {PLDM_SENSOR_FAILED, PLDM_SENSOR_UPPERFATAL,
924 PLDM_SENSOR_UPPERCRITICAL, PLDM_SENSOR_FATAL};
925
926 auto rc = encode_get_state_sensor_readings_resp(
927 0, PLDM_SUCCESS, comp_sensorCnt, stateField.data(), response);
928
929 struct pldm_get_state_sensor_readings_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930930 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930931 reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>(
932 response->payload);
933
934 EXPECT_EQ(rc, PLDM_SUCCESS);
935 EXPECT_EQ(completionCode, resp->completion_code);
936 EXPECT_EQ(comp_sensorCnt, resp->comp_sensor_count);
937 EXPECT_EQ(stateField[0].sensor_op_state, resp->field->sensor_op_state);
938 EXPECT_EQ(stateField[0].present_state, resp->field->present_state);
939 EXPECT_EQ(stateField[0].previous_state, resp->field->previous_state);
940 EXPECT_EQ(stateField[0].event_state, resp->field->event_state);
941 EXPECT_EQ(stateField[1].sensor_op_state, resp->field[1].sensor_op_state);
942 EXPECT_EQ(stateField[1].present_state, resp->field[1].present_state);
943 EXPECT_EQ(stateField[1].previous_state, resp->field[1].previous_state);
944 EXPECT_EQ(stateField[1].event_state, resp->field[1].event_state);
945}
946
947TEST(GetStateSensorReadings, testBadEncodeResponse)
948{
949 auto rc = encode_get_state_sensor_readings_resp(0, PLDM_SUCCESS, 0, nullptr,
950 nullptr);
951
952 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
953}
954
955TEST(GetStateSensorReadings, testGoodDecodeResponse)
956{
957 std::array<uint8_t, hdrSize +
958 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
959 sizeof(get_sensor_state_field) * 2>
960 responseMsg{};
961
962 uint8_t completionCode = 0;
963 uint8_t comp_sensorCnt = 2;
964
965 std::array<get_sensor_state_field, 2> stateField{};
966 stateField[0] = {PLDM_SENSOR_DISABLED, PLDM_SENSOR_UNKNOWN,
967 PLDM_SENSOR_UNKNOWN, PLDM_SENSOR_UNKNOWN};
968 stateField[1] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_LOWERFATAL,
969 PLDM_SENSOR_LOWERCRITICAL, PLDM_SENSOR_WARNING};
970
971 uint8_t retcompletion_code = 0;
972 uint8_t retcomp_sensorCnt = 0;
973 std::array<get_sensor_state_field, 2> retstateField{};
974
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930975 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930976 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
977 struct pldm_get_state_sensor_readings_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +0930978 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930979 reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>(
980 response->payload);
981
982 resp->completion_code = completionCode;
983 resp->comp_sensor_count = comp_sensorCnt;
984 memcpy(resp->field, &stateField,
985 (sizeof(get_sensor_state_field) * comp_sensorCnt));
986
987 auto rc = decode_get_state_sensor_readings_resp(
988 response, responseMsg.size() - hdrSize, &retcompletion_code,
989 &retcomp_sensorCnt, retstateField.data());
990
991 EXPECT_EQ(rc, PLDM_SUCCESS);
992 EXPECT_EQ(completionCode, retcompletion_code);
993 EXPECT_EQ(comp_sensorCnt, retcomp_sensorCnt);
994 EXPECT_EQ(stateField[0].sensor_op_state, retstateField[0].sensor_op_state);
995 EXPECT_EQ(stateField[0].present_state, retstateField[0].present_state);
996 EXPECT_EQ(stateField[0].previous_state, retstateField[0].previous_state);
997 EXPECT_EQ(stateField[0].event_state, retstateField[0].event_state);
998 EXPECT_EQ(stateField[1].sensor_op_state, retstateField[1].sensor_op_state);
999 EXPECT_EQ(stateField[1].present_state, retstateField[1].present_state);
1000 EXPECT_EQ(stateField[1].previous_state, retstateField[1].previous_state);
1001 EXPECT_EQ(stateField[1].event_state, retstateField[1].event_state);
1002}
1003
1004TEST(GetStateSensorReadings, testBadDecodeResponse)
1005{
1006 std::array<uint8_t, hdrSize +
1007 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
1008 sizeof(get_sensor_state_field) * 2>
1009 responseMsg{};
1010
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301011 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09301012 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1013
1014 auto rc = decode_get_state_sensor_readings_resp(
1015 response, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr);
1016
1017 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1018
1019 uint8_t completionCode = 0;
1020 uint8_t comp_sensorCnt = 1;
1021
1022 std::array<get_sensor_state_field, 1> stateField{};
1023 stateField[0] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_UPPERFATAL,
1024 PLDM_SENSOR_UPPERCRITICAL, PLDM_SENSOR_WARNING};
1025
1026 uint8_t retcompletion_code = 0;
1027 uint8_t retcomp_sensorCnt = 0;
1028 std::array<get_sensor_state_field, 1> retstateField{};
1029
1030 struct pldm_get_state_sensor_readings_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301031 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09301032 reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>(
1033 response->payload);
1034
1035 resp->completion_code = completionCode;
1036 resp->comp_sensor_count = comp_sensorCnt;
1037 memcpy(resp->field, &stateField,
1038 (sizeof(get_sensor_state_field) * comp_sensorCnt));
1039
1040 rc = decode_get_state_sensor_readings_resp(
Andrew Jeffery6ad4dc02023-04-12 15:56:45 +09301041 response, responseMsg.size() - hdrSize, &retcompletion_code,
Andrew Jeffery9c766792022-08-10 23:12:49 +09301042 &retcomp_sensorCnt, retstateField.data());
1043
1044 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1045}
1046
1047TEST(GetStateSensorReadings, testGoodEncodeRequest)
1048{
1049 std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES>
1050 requestMsg{};
1051
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06001052 uint16_t sensorId = 0xab;
Andrew Jeffery9c766792022-08-10 23:12:49 +09301053 bitfield8_t sensorRearm;
1054 sensorRearm.byte = 0x03;
1055
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301056 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09301057 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1058 auto rc = encode_get_state_sensor_readings_req(0, sensorId, sensorRearm, 0,
1059 request);
1060
1061 struct pldm_get_state_sensor_readings_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301062 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09301063 reinterpret_cast<struct pldm_get_state_sensor_readings_req*>(
1064 request->payload);
1065
1066 EXPECT_EQ(rc, PLDM_SUCCESS);
1067 EXPECT_EQ(sensorId, le16toh(req->sensor_id));
1068 EXPECT_EQ(sensorRearm.byte, req->sensor_rearm.byte);
1069}
1070
1071TEST(GetStateSensorReadings, testBadEncodeRequest)
1072{
1073 bitfield8_t sensorRearm;
1074 sensorRearm.byte = 0x0;
1075
1076 auto rc =
1077 encode_get_state_sensor_readings_req(0, 0, sensorRearm, 0, nullptr);
1078
1079 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1080}
1081
1082TEST(GetStateSensorReadings, testGoodDecodeRequest)
1083{
1084 std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES>
1085 requestMsg{};
1086
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06001087 uint16_t sensorId = 0xcd;
Andrew Jeffery9c766792022-08-10 23:12:49 +09301088 bitfield8_t sensorRearm;
1089 sensorRearm.byte = 0x10;
1090
1091 uint16_t retsensorId;
1092 bitfield8_t retsensorRearm;
1093 uint8_t retreserved;
1094
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301095 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09301096 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1097
1098 struct pldm_get_state_sensor_readings_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301099 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09301100 reinterpret_cast<struct pldm_get_state_sensor_readings_req*>(
1101 request->payload);
1102
1103 req->sensor_id = htole16(sensorId);
1104 req->sensor_rearm.byte = sensorRearm.byte;
1105
1106 auto rc = decode_get_state_sensor_readings_req(
1107 request, requestMsg.size() - hdrSize, &retsensorId, &retsensorRearm,
1108 &retreserved);
1109
1110 EXPECT_EQ(rc, PLDM_SUCCESS);
1111 EXPECT_EQ(sensorId, retsensorId);
1112 EXPECT_EQ(sensorRearm.byte, retsensorRearm.byte);
1113 EXPECT_EQ(0, retreserved);
1114}
1115
1116TEST(GetStateSensorReadings, testBadDecodeRequest)
1117{
1118 std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES>
1119 requestMsg{};
1120
1121 auto rc = decode_get_state_sensor_readings_req(
1122 nullptr, requestMsg.size() - hdrSize, nullptr, nullptr, nullptr);
1123
1124 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1125 uint16_t sensorId = 0x11;
1126 bitfield8_t sensorRearm;
1127 sensorRearm.byte = 0x04;
1128
1129 uint16_t retsensorId;
1130 bitfield8_t retsensorRearm;
1131 uint8_t retreserved;
1132
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301133 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09301134 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1135
1136 struct pldm_get_state_sensor_readings_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301137 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09301138 reinterpret_cast<struct pldm_get_state_sensor_readings_req*>(
1139 request->payload);
1140
1141 req->sensor_id = htole16(sensorId);
1142 req->sensor_rearm.byte = sensorRearm.byte;
1143
1144 rc = decode_get_state_sensor_readings_req(
1145 request, requestMsg.size() - hdrSize - 1, &retsensorId, &retsensorRearm,
1146 &retreserved);
1147
1148 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1149}
1150
Dung Caod6ae8982022-11-02 10:00:10 +07001151TEST(EventMessageBufferSize, testGoodEventMessageBufferSizeRequest)
1152{
1153 uint8_t eventBufferSize = 32;
1154
1155 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_REQ_BYTES>
1156 requestMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301157 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Caod6ae8982022-11-02 10:00:10 +07001158 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1159
1160 auto rc = encode_event_message_buffer_size_req(0, eventBufferSize, request);
1161
1162 EXPECT_EQ(rc, PLDM_SUCCESS);
1163}
1164
1165TEST(EventMessageBufferSize, testGoodEventMessageBufferSizeResponse)
1166{
1167 uint8_t completionCode = PLDM_SUCCESS;
1168 uint16_t terminusMaxBufferSize = 256;
1169
1170 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES>
1171 responseMsg{};
1172
1173 uint8_t retCompletionCode;
1174 uint16_t retMaxBufferSize = 0;
1175
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301176 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Caod6ae8982022-11-02 10:00:10 +07001177 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1178 struct pldm_event_message_buffer_size_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301179 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Caod6ae8982022-11-02 10:00:10 +07001180 reinterpret_cast<struct pldm_event_message_buffer_size_resp*>(
1181 response->payload);
1182
1183 resp->completion_code = completionCode;
1184 resp->terminus_max_buffer_size = terminusMaxBufferSize;
1185
1186 auto rc = decode_event_message_buffer_size_resp(
1187 response, responseMsg.size() - hdrSize, &retCompletionCode,
1188 &retMaxBufferSize);
1189
1190 EXPECT_EQ(rc, PLDM_SUCCESS);
1191 EXPECT_EQ(retCompletionCode, completionCode);
1192 EXPECT_EQ(terminusMaxBufferSize, retMaxBufferSize);
1193}
1194
1195TEST(EventMessageBufferSize, testBadEventMessageBufferSizeResponse)
1196{
1197 uint8_t completionCode = PLDM_SUCCESS;
1198 uint16_t terminusMaxBufferSize = 256;
1199
1200 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES>
1201 responseMsg{};
1202
1203 uint8_t retCompletionCode;
1204 uint16_t retMaxBufferSize = 0;
1205
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301206 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Caod6ae8982022-11-02 10:00:10 +07001207 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1208 struct pldm_event_message_buffer_size_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301209 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Caod6ae8982022-11-02 10:00:10 +07001210 reinterpret_cast<struct pldm_event_message_buffer_size_resp*>(
1211 response->payload);
1212 resp->completion_code = completionCode;
1213 resp->terminus_max_buffer_size = terminusMaxBufferSize;
1214
1215 auto rc =
1216 decode_event_message_buffer_size_resp(response, 0, nullptr, nullptr);
1217 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1218
1219 rc = decode_event_message_buffer_size_resp(
1220 response, responseMsg.size(), &retCompletionCode, &retMaxBufferSize);
1221 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1222}
1223
Dung Cao1bf8c872022-11-29 05:32:58 +07001224TEST(PlatformEventMessageSupported, testGoodEncodeRequest)
1225{
1226 uint8_t formatVersion = 0x01;
1227
1228 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_REQ_BYTES>
1229 requestMsg{};
1230
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301231 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao1bf8c872022-11-29 05:32:58 +07001232 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1233
1234 auto rc = encode_event_message_supported_req(0, formatVersion, request);
1235
1236 struct pldm_event_message_supported_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301237 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao1bf8c872022-11-29 05:32:58 +07001238 reinterpret_cast<struct pldm_event_message_supported_req*>(
1239 request->payload);
1240
1241 EXPECT_EQ(rc, PLDM_SUCCESS);
1242 EXPECT_EQ(formatVersion, req->format_version);
1243}
1244
1245TEST(PlatformEventMessageSupported, testBadEncodeRequest)
1246{
1247 uint8_t eventData = 34;
1248 uint8_t formatVersion = 0x0;
1249
1250 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_REQ_BYTES +
1251 sizeof(eventData)>
1252 requestMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301253 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao1bf8c872022-11-29 05:32:58 +07001254 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1255
1256 auto rc = encode_event_message_supported_req(0, formatVersion, request);
1257 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1258
1259 rc = encode_event_message_supported_req(0, formatVersion, nullptr);
1260 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1261}
1262
1263TEST(PlatformEventMessageSupported, testGoodDecodeRespond)
1264{
1265 uint8_t completionCode = PLDM_SUCCESS;
1266 uint8_t synchConfiguration = PLDM_MESSAGE_TYPE_SYNCHRONOUS;
1267 bitfield8_t synchConfigSupported;
1268 synchConfigSupported.byte = 0xe;
1269 uint8_t numberEventClassReturned = 0x3;
1270 std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa};
1271 constexpr uint8_t eventClassCount = 3;
1272
1273 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES +
1274 eventClassCount>
1275 responseMsg{};
1276
1277 uint8_t retCompletionCode;
1278 uint8_t retSynchConfig = 0;
1279 uint8_t retNumberEventClass = 0;
1280 bitfield8_t retSynchConfigSupport;
1281 uint8_t retEventClass[eventClassCount] = {0};
1282
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301283 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao1bf8c872022-11-29 05:32:58 +07001284 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1285 struct pldm_event_message_supported_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301286 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao1bf8c872022-11-29 05:32:58 +07001287 reinterpret_cast<struct pldm_event_message_supported_resp*>(
1288 response->payload);
1289
1290 resp->completion_code = completionCode;
1291 resp->synchrony_configuration = synchConfiguration;
1292 resp->synchrony_configuration_supported.byte = synchConfigSupported.byte;
1293 resp->number_event_class_returned = numberEventClassReturned;
1294 memcpy(resp->event_class, eventClass.data(), numberEventClassReturned);
1295
1296 auto rc = decode_event_message_supported_resp(
1297 response, responseMsg.size() - hdrSize, &retCompletionCode,
1298 &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass,
1299 retEventClass, eventClassCount);
1300
1301 EXPECT_EQ(rc, PLDM_SUCCESS);
1302 EXPECT_EQ(retCompletionCode, completionCode);
1303 EXPECT_EQ(retSynchConfig, synchConfiguration);
1304 EXPECT_EQ(retNumberEventClass, numberEventClassReturned);
1305 EXPECT_EQ(retSynchConfigSupport.byte, synchConfigSupported.byte);
1306 EXPECT_EQ(0, memcmp(eventClass.data(), resp->event_class,
1307 numberEventClassReturned));
1308}
1309
1310TEST(PlatformEventMessageSupported, testBadSynchConfiguration)
1311{
1312 uint8_t completionCode = PLDM_SUCCESS;
1313 uint8_t synchConfiguration = 0x4;
1314 bitfield8_t synchConfigSupported;
1315 synchConfigSupported.byte = 0xe;
1316 uint8_t numberEventClassReturned = 0x3;
1317 std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa};
1318 constexpr uint8_t eventClassCount = 3;
1319
1320 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES +
1321 eventClassCount>
1322 responseMsg{};
1323
1324 uint8_t retCompletionCode;
1325 uint8_t retSynchConfig = 0;
1326 uint8_t retNumberEventClass = 0;
1327 bitfield8_t retSynchConfigSupport;
1328 uint8_t retEventClass[eventClassCount] = {0};
1329
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301330 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao1bf8c872022-11-29 05:32:58 +07001331 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1332 struct pldm_event_message_supported_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301333 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao1bf8c872022-11-29 05:32:58 +07001334 reinterpret_cast<struct pldm_event_message_supported_resp*>(
1335 response->payload);
1336
1337 resp->completion_code = completionCode;
1338 resp->synchrony_configuration = synchConfiguration;
1339 resp->synchrony_configuration_supported.byte = synchConfigSupported.byte;
1340 resp->number_event_class_returned = numberEventClassReturned;
1341 memcpy(resp->event_class, eventClass.data(), numberEventClassReturned);
1342
1343 auto rc = decode_event_message_supported_resp(
1344 response, responseMsg.size() - hdrSize, &retCompletionCode,
1345 &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass,
1346 retEventClass, eventClassCount);
1347
1348 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1349}
1350
1351TEST(PlatformEventMessageSupported, testBadDecodeRespond)
1352{
1353 uint8_t completionCode = PLDM_SUCCESS;
1354 uint8_t synchConfiguration = PLDM_MESSAGE_TYPE_SYNCHRONOUS;
1355 bitfield8_t synchConfigSupported;
1356 synchConfigSupported.byte = 0xe;
1357 uint8_t numberEventClassReturned = 0x3;
1358 std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa};
1359 constexpr uint8_t eventClassCount = 3;
1360
1361 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES +
1362 eventClassCount>
1363 responseMsg{};
1364
1365 uint8_t retCompletionCode;
1366 uint8_t retSynchConfig = 0;
1367 uint8_t retNumberEventClass = 0;
1368 bitfield8_t retSynchConfigSupport;
1369 uint8_t retEventClass[eventClassCount] = {0};
1370
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301371 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao1bf8c872022-11-29 05:32:58 +07001372 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1373 struct pldm_event_message_supported_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301374 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao1bf8c872022-11-29 05:32:58 +07001375 reinterpret_cast<struct pldm_event_message_supported_resp*>(
1376 response->payload);
1377 resp->completion_code = completionCode;
1378 resp->synchrony_configuration = synchConfiguration;
1379 resp->synchrony_configuration_supported.byte = synchConfigSupported.byte;
1380 resp->number_event_class_returned = numberEventClassReturned;
1381 memcpy(resp->event_class, eventClass.data(), numberEventClassReturned);
1382
1383 auto rc = decode_event_message_supported_resp(response, 0, nullptr, nullptr,
1384 nullptr, nullptr, nullptr, 0);
1385 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1386
1387 rc = decode_event_message_supported_resp(
1388 response, PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES - 1,
1389 &retCompletionCode, &retSynchConfig, &retSynchConfigSupport,
1390 &retNumberEventClass, retEventClass, eventClassCount);
1391 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1392
1393 rc = decode_event_message_supported_resp(
1394 response, responseMsg.size() - hdrSize, &retCompletionCode,
1395 &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass,
1396 retEventClass, 1);
1397 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1398}
1399
Thu Nguyen387b10f2024-09-24 11:33:16 +00001400TEST(PollForPlatformEventMessage, testGoodEncodeRequestFirstPart)
Thu Nguyen159a98b2022-11-02 10:00:10 +07001401{
1402 uint8_t formatVersion = 0x01;
Thu Nguyen387b10f2024-09-24 11:33:16 +00001403 uint8_t transferOperationFlag = PLDM_GET_FIRSTPART;
1404 uint32_t dataTransferHandle = 0xaabbccdd;
1405 uint16_t eventIdToAcknowledge = PLDM_PLATFORM_EVENT_ID_NULL;
Thu Nguyen159a98b2022-11-02 10:00:10 +07001406
Thu Nguyen387b10f2024-09-24 11:33:16 +00001407 PLDM_MSG_DEFINE_P(request, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
Thu Nguyen159a98b2022-11-02 10:00:10 +07001408
1409 auto rc = encode_poll_for_platform_event_message_req(
1410 0, formatVersion, transferOperationFlag, dataTransferHandle,
1411 eventIdToAcknowledge, request,
1412 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1413 EXPECT_EQ(rc, PLDM_SUCCESS);
1414
1415 struct pldm_msgbuf _buf;
1416 struct pldm_msgbuf* buf = &_buf;
Thu Nguyen387b10f2024-09-24 11:33:16 +00001417 rc = pldm_msgbuf_init_errno(
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09301418 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES, request->payload,
1419 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
Thu Nguyen387b10f2024-09-24 11:33:16 +00001420 EXPECT_EQ(rc, 0);
Thu Nguyen159a98b2022-11-02 10:00:10 +07001421
1422 uint8_t retFormatVersion;
1423 uint8_t retTransferOperationFlag;
1424 uint32_t retDataTransferHandle;
1425 uint16_t retEventIdToAcknowledge;
1426
Andrew Jefferye5f12532024-10-01 12:18:49 +09301427 pldm_msgbuf_extract_uint8(buf, retFormatVersion);
1428 pldm_msgbuf_extract_uint8(buf, retTransferOperationFlag);
1429 pldm_msgbuf_extract_uint32(buf, retDataTransferHandle);
1430 pldm_msgbuf_extract_uint16(buf, retEventIdToAcknowledge);
Thu Nguyen387b10f2024-09-24 11:33:16 +00001431 ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
Thu Nguyen159a98b2022-11-02 10:00:10 +07001432
1433 EXPECT_EQ(retFormatVersion, formatVersion);
1434 EXPECT_EQ(retTransferOperationFlag, transferOperationFlag);
1435 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
1436 EXPECT_EQ(retEventIdToAcknowledge, eventIdToAcknowledge);
Thu Nguyen387b10f2024-09-24 11:33:16 +00001437}
1438
1439TEST(PollForPlatformEventMessage, testGoodEncodeRequestNextPart)
1440{
1441 uint8_t formatVersion = 0x01;
1442 uint8_t transferOperationFlag = PLDM_GET_NEXTPART;
1443 uint32_t dataTransferHandle = 0xaabbccdd;
1444 uint16_t eventIdToAcknowledge = PLDM_PLATFORM_EVENT_ID_FRAGMENT;
1445
1446 PLDM_MSG_DEFINE_P(request, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1447
1448 auto rc = encode_poll_for_platform_event_message_req(
1449 0, formatVersion, transferOperationFlag, dataTransferHandle,
1450 eventIdToAcknowledge, request,
1451 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1452 EXPECT_EQ(rc, PLDM_SUCCESS);
1453
1454 struct pldm_msgbuf _buf;
1455 struct pldm_msgbuf* buf = &_buf;
1456 rc = pldm_msgbuf_init_errno(
1457 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES, request->payload,
1458 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1459 EXPECT_EQ(rc, 0);
1460
1461 uint8_t retFormatVersion;
1462 uint8_t retTransferOperationFlag;
1463 uint32_t retDataTransferHandle;
1464 uint16_t retEventIdToAcknowledge;
1465
Andrew Jefferye5f12532024-10-01 12:18:49 +09301466 pldm_msgbuf_extract_uint8(buf, retFormatVersion);
1467 pldm_msgbuf_extract_uint8(buf, retTransferOperationFlag);
1468 pldm_msgbuf_extract_uint32(buf, retDataTransferHandle);
1469 pldm_msgbuf_extract_uint16(buf, retEventIdToAcknowledge);
Thu Nguyen387b10f2024-09-24 11:33:16 +00001470 ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
1471
1472 EXPECT_EQ(retFormatVersion, formatVersion);
1473 EXPECT_EQ(retTransferOperationFlag, transferOperationFlag);
1474 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
1475 EXPECT_EQ(retEventIdToAcknowledge, eventIdToAcknowledge);
1476}
1477
1478TEST(PollForPlatformEventMessage, testGoodEncodeRequestAckOnly)
1479{
1480 uint8_t formatVersion = 0x01;
1481 uint8_t transferOperationFlag = PLDM_ACKNOWLEDGEMENT_ONLY;
1482 uint32_t dataTransferHandle = 0xaabbccdd;
Thu Nguyen9e16b182024-10-01 03:12:16 +00001483 uint16_t eventIdToAcknowledge = 0x1234;
Thu Nguyen387b10f2024-09-24 11:33:16 +00001484
1485 PLDM_MSG_DEFINE_P(request, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1486
1487 auto rc = encode_poll_for_platform_event_message_req(
1488 0, formatVersion, transferOperationFlag, dataTransferHandle,
1489 eventIdToAcknowledge, request,
1490 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1491 EXPECT_EQ(rc, PLDM_SUCCESS);
1492
1493 struct pldm_msgbuf _buf;
1494 struct pldm_msgbuf* buf = &_buf;
1495 rc = pldm_msgbuf_init_errno(
1496 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES, request->payload,
1497 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1498 EXPECT_EQ(rc, 0);
1499
1500 uint8_t retFormatVersion;
1501 uint8_t retTransferOperationFlag;
1502 uint32_t retDataTransferHandle;
1503 uint16_t retEventIdToAcknowledge;
1504
Andrew Jefferye5f12532024-10-01 12:18:49 +09301505 pldm_msgbuf_extract_uint8(buf, retFormatVersion);
1506 pldm_msgbuf_extract_uint8(buf, retTransferOperationFlag);
1507 pldm_msgbuf_extract_uint32(buf, retDataTransferHandle);
1508 pldm_msgbuf_extract_uint16(buf, retEventIdToAcknowledge);
Thu Nguyen387b10f2024-09-24 11:33:16 +00001509 ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
1510
1511 EXPECT_EQ(retFormatVersion, formatVersion);
1512 EXPECT_EQ(retTransferOperationFlag, transferOperationFlag);
1513 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
1514 EXPECT_EQ(retEventIdToAcknowledge, eventIdToAcknowledge);
Thu Nguyen159a98b2022-11-02 10:00:10 +07001515}
1516
1517TEST(PollForPlatformEventMessage, testBadEncodeRequest)
1518{
1519 uint8_t formatVersion = 0x01;
Thu Nguyen387b10f2024-09-24 11:33:16 +00001520 uint8_t transferOperationFlag = PLDM_GET_FIRSTPART;
1521 uint32_t dataTransferHandle = 0xaabbccdd;
1522 uint16_t eventIdToAcknowledge = 0x1234;
Thu Nguyen159a98b2022-11-02 10:00:10 +07001523
Thu Nguyen387b10f2024-09-24 11:33:16 +00001524 PLDM_MSG_DEFINE_P(request, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
Thu Nguyen159a98b2022-11-02 10:00:10 +07001525
1526 auto rc = encode_poll_for_platform_event_message_req(
1527 0, formatVersion, transferOperationFlag, dataTransferHandle,
1528 eventIdToAcknowledge, nullptr,
1529 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
Thu Nguyen159a98b2022-11-02 10:00:10 +07001530 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1531
Thu Nguyen387b10f2024-09-24 11:33:16 +00001532 transferOperationFlag = PLDM_GET_FIRSTPART;
1533 eventIdToAcknowledge = PLDM_PLATFORM_EVENT_ID_FRAGMENT;
1534 rc = encode_poll_for_platform_event_message_req(
Thu Nguyen159a98b2022-11-02 10:00:10 +07001535 0, formatVersion, transferOperationFlag, dataTransferHandle,
Thu Nguyen387b10f2024-09-24 11:33:16 +00001536 eventIdToAcknowledge, request,
1537 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1538 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1539
1540 transferOperationFlag = PLDM_GET_NEXTPART;
1541 eventIdToAcknowledge = 0x1234;
1542 rc = encode_poll_for_platform_event_message_req(
1543 0, formatVersion, transferOperationFlag, dataTransferHandle,
1544 eventIdToAcknowledge, request,
1545 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1546 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1547
1548 transferOperationFlag = PLDM_GET_NEXTPART;
1549 eventIdToAcknowledge = PLDM_PLATFORM_EVENT_ID_NULL;
1550 rc = encode_poll_for_platform_event_message_req(
1551 0, formatVersion, transferOperationFlag, dataTransferHandle,
1552 eventIdToAcknowledge, request,
1553 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1554 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1555
1556 transferOperationFlag = PLDM_ACKNOWLEDGEMENT_ONLY;
Thu Nguyen9e16b182024-10-01 03:12:16 +00001557 eventIdToAcknowledge = PLDM_PLATFORM_EVENT_ID_NULL;
Thu Nguyen387b10f2024-09-24 11:33:16 +00001558 rc = encode_poll_for_platform_event_message_req(
1559 0, formatVersion, transferOperationFlag, dataTransferHandle,
1560 eventIdToAcknowledge, request,
1561 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1562 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1563
1564 transferOperationFlag = PLDM_ACKNOWLEDGEMENT_ONLY;
Thu Nguyen9e16b182024-10-01 03:12:16 +00001565 eventIdToAcknowledge = PLDM_PLATFORM_EVENT_ID_FRAGMENT;
Thu Nguyen387b10f2024-09-24 11:33:16 +00001566 rc = encode_poll_for_platform_event_message_req(
1567 0, formatVersion, transferOperationFlag, dataTransferHandle,
1568 eventIdToAcknowledge, request,
1569 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1570 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1571
1572 transferOperationFlag = PLDM_ACKNOWLEDGEMENT_ONLY + 1;
1573 eventIdToAcknowledge = PLDM_PLATFORM_EVENT_ID_FRAGMENT;
1574 rc = encode_poll_for_platform_event_message_req(
1575 0, formatVersion, transferOperationFlag, dataTransferHandle,
1576 eventIdToAcknowledge, request,
1577 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES);
1578 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Thu Nguyen159a98b2022-11-02 10:00:10 +07001579}
1580
1581TEST(PollForPlatformEventMessage, testGoodDecodeRespond)
1582{
1583 uint8_t completionCode = PLDM_SUCCESS;
1584 uint8_t tId = 0x9;
1585 uint16_t eventId = 159;
1586 uint32_t nextDataTransferHandle = 0x11223344;
1587 uint8_t transferFlag = PLDM_START_AND_END;
1588 uint8_t eventClass = 0x5;
1589 uint8_t eventData[5] = {0x55, 0x44, 0x33, 0x22, 0x11};
1590 constexpr uint32_t eventDataSize = 0x00000005;
1591 uint32_t eventDataIntegrityChecksum = 0x66778899;
1592
1593 std::vector<uint8_t> responseMsg{
1594 0x1,
1595 0x0,
1596 0x0,
1597 PLDM_SUCCESS,
1598 0x9, // tid
1599 159,
1600 0x0, // event id
1601 0x44,
1602 0x33,
1603 0x22,
1604 0x11, // next_data_transfer_handle
1605 PLDM_START_AND_END, // transfer_flag
1606 0x05, // event class
1607 0x05,
1608 0x00,
1609 0x00,
1610 0x00, // event_data_size
1611 0x55,
1612 0x44,
1613 0x33,
1614 0x22,
1615 0x11, // event_data[5]
1616 0x99,
1617 0x88,
1618 0x77,
1619 0x66 // event_data_integrity_checksum
1620 };
1621 const uint32_t respMsgLen = 23;
1622
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301623 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen159a98b2022-11-02 10:00:10 +07001624 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1625
1626 uint8_t retCompletionCode;
1627 uint8_t retTid = 0;
1628 uint16_t retEventId = 0;
1629 uint32_t retNextDataTransferHandle = 0;
1630 uint8_t retTransferFlag = 0;
1631 uint8_t retEventClass = 0;
1632 uint32_t retEventDataSize = 0;
1633 uint8_t* retEventData = nullptr;
1634 uint32_t retEventDataIntegrityChecksum = 0;
1635
1636 auto rc = decode_poll_for_platform_event_message_resp(
1637 response, respMsgLen, &retCompletionCode, &retTid, &retEventId,
1638 &retNextDataTransferHandle, &retTransferFlag, &retEventClass,
1639 &retEventDataSize, (void**)&retEventData,
1640 &retEventDataIntegrityChecksum);
1641
1642 EXPECT_EQ(rc, PLDM_SUCCESS);
1643 EXPECT_EQ(retCompletionCode, completionCode);
1644 EXPECT_EQ(retTid, tId);
1645 EXPECT_EQ(retEventId, eventId);
1646 EXPECT_EQ(retNextDataTransferHandle, nextDataTransferHandle);
1647 EXPECT_EQ(retTransferFlag, transferFlag);
1648 EXPECT_EQ(retEventClass, eventClass);
1649 EXPECT_EQ(retEventDataSize, eventDataSize);
1650 EXPECT_EQ(retEventDataIntegrityChecksum, eventDataIntegrityChecksum);
1651 EXPECT_EQ(0, memcmp(eventData, retEventData, eventDataSize));
1652}
1653
1654TEST(PollForPlatformEventMessage, testGoodDecodeAckOnlyRespond)
1655{
1656 uint8_t completionCode = PLDM_SUCCESS;
1657 uint8_t tId = 0x9;
1658 uint16_t eventId = 0xffff;
1659
1660 std::vector<uint8_t> responseMsg{
1661 0x1, 0x0, 0x0, PLDM_SUCCESS,
1662 0x9, // tid
1663 0xff,
1664 0xff // event id
1665 };
1666 const uint32_t respMsgLen = 4;
1667
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301668 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen159a98b2022-11-02 10:00:10 +07001669 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1670
1671 uint8_t retCompletionCode;
1672 uint8_t retTid = 0;
1673 uint16_t retEventId = 0;
1674 uint32_t retNextDataTransferHandle = 0;
1675 uint8_t retTransferFlag = 0;
1676 uint8_t retEventClass = 0;
1677 uint32_t retEventDataSize = 0;
1678 uint8_t* retEventData = nullptr;
1679 uint32_t retEventDataIntegrityChecksum = 0;
1680
1681 auto rc = decode_poll_for_platform_event_message_resp(
1682 response, respMsgLen, &retCompletionCode, &retTid, &retEventId,
1683 &retNextDataTransferHandle, &retTransferFlag, &retEventClass,
1684 &retEventDataSize, (void**)&retEventData,
1685 &retEventDataIntegrityChecksum);
1686
1687 EXPECT_EQ(rc, PLDM_SUCCESS);
1688 EXPECT_EQ(retCompletionCode, completionCode);
1689 EXPECT_EQ(retTid, tId);
1690 EXPECT_EQ(retEventId, eventId);
1691
1692 eventId = 0x0000;
1693 responseMsg[5] = 0x00;
1694 responseMsg[6] = 0x00;
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301695 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen159a98b2022-11-02 10:00:10 +07001696 response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1697
1698 rc = decode_poll_for_platform_event_message_resp(
1699 response, respMsgLen, &retCompletionCode, &retTid, &retEventId,
1700 &retNextDataTransferHandle, &retTransferFlag, &retEventClass,
1701 &retEventDataSize, (void**)&retEventData,
1702 &retEventDataIntegrityChecksum);
1703
1704 EXPECT_EQ(rc, PLDM_SUCCESS);
1705 EXPECT_EQ(retCompletionCode, completionCode);
1706 EXPECT_EQ(retTid, tId);
1707 EXPECT_EQ(retEventId, eventId);
1708}
1709
1710TEST(PollForPlatformEventMessage, testBadDecodeRespond)
1711{
1712 std::vector<uint8_t> responseMsg{
1713 0x1,
1714 0x0,
1715 0x0,
1716 PLDM_SUCCESS,
1717 0x9, // tid
1718 159,
1719 0x0, // event id
1720 0x44,
1721 0x33,
1722 0x22,
1723 0x11, // next_data_transfer_handle
1724 PLDM_START_AND_END, // transfer_flag
1725 0x05, // event class
1726 0x05,
1727 0x00,
1728 0x00,
1729 0x00, // event_data_size
1730 0x55,
1731 0x44,
1732 0x33,
1733 0x22,
1734 0x11, // event_data[5]
1735 0x99,
1736 0x88,
1737 0x77,
1738 0x66 // event_data_integrity_checksum
1739 };
1740 // const uint32_t respMsgLen = 23;
1741
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301742 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen159a98b2022-11-02 10:00:10 +07001743 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1744
1745 auto rc = decode_poll_for_platform_event_message_resp(
1746 nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1747 nullptr, nullptr, nullptr);
1748
1749 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1750
1751 uint8_t retCompletionCode;
1752 uint8_t retTid = 0;
1753 uint16_t retEventId = 0;
1754 uint32_t retNextDataTransferHandle = 0;
1755 uint8_t retTransferFlag = 0;
1756 uint8_t retEventClass = 0;
1757 uint32_t retEventDataSize = 0;
1758 uint8_t* retEventData = nullptr;
1759 uint32_t retEventDataIntegrityChecksum = 0;
1760
1761 rc = decode_poll_for_platform_event_message_resp(
1762 response, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES - 1,
1763 &retCompletionCode, &retTid, &retEventId, &retNextDataTransferHandle,
1764 &retTransferFlag, &retEventClass, &retEventDataSize,
1765 (void**)&retEventData, &retEventDataIntegrityChecksum);
1766
1767 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1768}
1769
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001770TEST(PollForPlatformEventMessage, testGoodDecodeRequestFirstPart)
1771{
1772 uint8_t formatVersion = 0x1;
1773 uint8_t transferOperationFlag = PLDM_GET_FIRSTPART;
1774 uint32_t dataTransferHandle = 0x11223344;
Thu Nguyen387b10f2024-09-24 11:33:16 +00001775 uint16_t eventIdToAcknowledge = PLDM_PLATFORM_EVENT_ID_NULL;
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001776 std::vector<uint8_t> requestMsg{0x1, 0x0, 0x0, 0x1, PLDM_GET_FIRSTPART,
1777 0x44, 0x33, 0x22, 0x11, 0x00,
1778 0x00};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301779 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001780 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1781
1782 uint8_t retFormatVersion;
1783 uint8_t retTransferOperationFlag;
1784 uint32_t retDataTransferHandle;
1785 uint16_t retEventIdToAcknowledge;
1786
1787 auto rc = decode_poll_for_platform_event_message_req(
1788 request, requestMsg.size() - hdrSize, &retFormatVersion,
1789 &retTransferOperationFlag, &retDataTransferHandle,
1790 &retEventIdToAcknowledge);
1791
1792 EXPECT_EQ(rc, PLDM_SUCCESS);
1793 EXPECT_EQ(retFormatVersion, formatVersion);
1794 EXPECT_EQ(retTransferOperationFlag, transferOperationFlag);
1795 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
1796 EXPECT_EQ(retEventIdToAcknowledge, eventIdToAcknowledge);
1797}
1798
1799TEST(PollForPlatformEventMessage, testGoodDecodeRequestNextPart)
1800{
1801 uint8_t formatVersion = 0x1;
1802 uint8_t transferOperationFlag = PLDM_GET_NEXTPART;
1803 uint32_t dataTransferHandle = 0x11223344;
Thu Nguyen387b10f2024-09-24 11:33:16 +00001804 uint16_t eventIdToAcknowledge = PLDM_PLATFORM_EVENT_ID_FRAGMENT;
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001805 std::vector<uint8_t> requestMsg{0x1, 0x0, 0x0, 0x1, PLDM_GET_NEXTPART,
1806 0x44, 0x33, 0x22, 0x11, 0xff,
1807 0xff};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301808 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001809 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1810
1811 uint8_t retFormatVersion;
1812 uint8_t retTransferOperationFlag;
1813 uint32_t retDataTransferHandle;
1814 uint16_t retEventIdToAcknowledge;
1815
1816 auto rc = decode_poll_for_platform_event_message_req(
1817 request, requestMsg.size() - hdrSize, &retFormatVersion,
1818 &retTransferOperationFlag, &retDataTransferHandle,
1819 &retEventIdToAcknowledge);
1820
1821 EXPECT_EQ(rc, PLDM_SUCCESS);
1822 EXPECT_EQ(retFormatVersion, formatVersion);
1823 EXPECT_EQ(retTransferOperationFlag, transferOperationFlag);
1824 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
1825 EXPECT_EQ(retEventIdToAcknowledge, eventIdToAcknowledge);
1826}
1827
1828TEST(PollForPlatformEventMessage, testGoodDecodeRequestAck)
1829{
1830 uint8_t formatVersion = 0x1;
1831 uint8_t transferOperationFlag = PLDM_ACKNOWLEDGEMENT_ONLY;
1832 uint32_t dataTransferHandle = 0x11223344;
Thu Nguyen9e16b182024-10-01 03:12:16 +00001833 uint16_t eventIdToAcknowledge = 0x1234;
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001834 std::vector<uint8_t> requestMsg{
1835 0x1, 0x0, 0x0, 0x1, PLDM_ACKNOWLEDGEMENT_ONLY, 0x44, 0x33,
Thu Nguyen9e16b182024-10-01 03:12:16 +00001836 0x22, 0x11, 0x34, 0x12};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301837 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001838 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1839
1840 uint8_t retFormatVersion;
1841 uint8_t retTransferOperationFlag;
1842 uint32_t retDataTransferHandle;
1843 uint16_t retEventIdToAcknowledge;
1844
1845 auto rc = decode_poll_for_platform_event_message_req(
1846 request, requestMsg.size() - hdrSize, &retFormatVersion,
1847 &retTransferOperationFlag, &retDataTransferHandle,
1848 &retEventIdToAcknowledge);
1849
1850 EXPECT_EQ(rc, PLDM_SUCCESS);
1851 EXPECT_EQ(retFormatVersion, formatVersion);
1852 EXPECT_EQ(retTransferOperationFlag, transferOperationFlag);
1853 EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
1854 EXPECT_EQ(retEventIdToAcknowledge, eventIdToAcknowledge);
1855}
1856
1857TEST(PollForPlatformEventMessage, testBadDecodeRequest)
1858{
Thu Nguyen387b10f2024-09-24 11:33:16 +00001859 /*
1860 * transfer_operation_flag is PLDM_GET_FIRSTPART and
1861 * event_id_to_acknowledge is not PLDM_PLATFORM_EVENT_ID_NULL
1862 */
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001863 std::vector<uint8_t> requestMsg{0x1, 0x0, 0x0, 0x1, PLDM_GET_FIRSTPART,
1864 0x44, 0x33, 0x22, 0x11, 0x66,
1865 0x55};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301866 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001867 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1868
1869 uint8_t retFormatVersion;
1870 uint8_t retTransferOperationFlag;
1871 uint32_t retDataTransferHandle;
1872 uint16_t retEventIdToAcknowledge;
1873
1874 auto rc = decode_poll_for_platform_event_message_req(
1875 NULL, requestMsg.size() - hdrSize, &retFormatVersion,
1876 &retTransferOperationFlag, &retDataTransferHandle,
1877 &retEventIdToAcknowledge);
1878 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1879
1880 /*
1881 * transfer_operation_flag is not PLDM_GET_FIRSTPART or PLDM_GET_NEXTPART or
1882 * PLDM_ACKNOWLEDGEMENT_ONLY
1883 */
1884
1885 requestMsg[4] = PLDM_ACKNOWLEDGEMENT_ONLY + 1;
1886
1887 rc = decode_poll_for_platform_event_message_req(
1888 request, requestMsg.size() - hdrSize, &retFormatVersion,
1889 &retTransferOperationFlag, &retDataTransferHandle,
1890 &retEventIdToAcknowledge);
1891
1892 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001893
1894 /*
1895 * transfer_operation_flag is PLDM_GET_NEXTPART and
Thu Nguyen387b10f2024-09-24 11:33:16 +00001896 * event_id_to_acknowledge is not PLDM_PLATFORM_EVENT_ID_FRAGMENT
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001897 */
1898 requestMsg[4] = PLDM_GET_NEXTPART;
Thu Nguyen387b10f2024-09-24 11:33:16 +00001899 requestMsg[9] = 0x11;
1900 requestMsg[10] = 0x22;
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001901
1902 rc = decode_poll_for_platform_event_message_req(
1903 request, requestMsg.size() - hdrSize, &retFormatVersion,
1904 &retTransferOperationFlag, &retDataTransferHandle,
1905 &retEventIdToAcknowledge);
1906
1907 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1908
1909 /*
Thu Nguyen387b10f2024-09-24 11:33:16 +00001910 * transfer_operation_flag is PLDM_ACKNOWLEDGEMENT_ONLY and
Thu Nguyen9e16b182024-10-01 03:12:16 +00001911 * event_id_to_acknowledge is PLDM_PLATFORM_EVENT_ID_FRAGMENT
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001912 */
Thu Nguyen387b10f2024-09-24 11:33:16 +00001913 requestMsg[4] = PLDM_ACKNOWLEDGEMENT_ONLY;
Thu Nguyen9e16b182024-10-01 03:12:16 +00001914 requestMsg[9] = 0xff;
1915 requestMsg[10] = 0xff;
1916
1917 rc = decode_poll_for_platform_event_message_req(
1918 request, requestMsg.size() - hdrSize, &retFormatVersion,
1919 &retTransferOperationFlag, &retDataTransferHandle,
1920 &retEventIdToAcknowledge);
1921
1922 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1923
1924 /*
1925 * transfer_operation_flag is PLDM_ACKNOWLEDGEMENT_ONLY and
1926 * event_id_to_acknowledge is PLDM_PLATFORM_EVENT_ID_NULL
1927 */
1928 requestMsg[4] = PLDM_ACKNOWLEDGEMENT_ONLY;
1929 requestMsg[9] = 0x00;
1930 requestMsg[10] = 0x00;
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001931
1932 rc = decode_poll_for_platform_event_message_req(
1933 request, requestMsg.size() - hdrSize, &retFormatVersion,
1934 &retTransferOperationFlag, &retDataTransferHandle,
1935 &retEventIdToAcknowledge);
1936
1937 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1938}
1939
1940TEST(PollForPlatformEventMessage, testGoodEncodeResposeP1)
1941{
1942 uint8_t completionCode = PLDM_SUCCESS;
1943 uint8_t instance_id = 0;
1944 uint8_t tId = 0x9;
1945 uint16_t eventId = 0x1;
1946 uint32_t nextDataTransferHandle = 0xffff;
1947 uint8_t transferFlag = PLDM_END;
1948 uint8_t eventClass = 0x5;
1949 constexpr uint32_t eventDataSize = 9;
1950 uint8_t pEventData[eventDataSize] = {0x31, 0x32, 0x33, 0x34, 0x35,
1951 0x36, 0x37, 0x38, 0x39};
1952 uint32_t eventDataIntegrityChecksum = 0x11223344;
1953 constexpr size_t payloadLength =
1954 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_RESP_BYTES + eventDataSize + 4;
1955
1956 std::array<uint8_t, hdrSize + payloadLength> responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09301957 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001958 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1959
1960 auto rc = encode_poll_for_platform_event_message_resp(
1961 instance_id, completionCode, tId, eventId, nextDataTransferHandle,
1962 transferFlag, eventClass, eventDataSize, pEventData,
1963 eventDataIntegrityChecksum, response, payloadLength);
1964 EXPECT_EQ(rc, PLDM_SUCCESS);
1965
1966 struct pldm_msgbuf _buf;
1967 struct pldm_msgbuf* buf = &_buf;
Andrew Jeffery830c1eb2024-10-04 10:48:10 +09301968 rc = pldm_msgbuf_init_errno(
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09301969 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
1970 response->payload, payloadLength);
Andrew Jeffery830c1eb2024-10-04 10:48:10 +09301971 EXPECT_EQ(rc, 0);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001972
1973 uint8_t retCompletionCode;
1974 uint8_t retTid = 0;
1975 uint16_t retEventId = 0;
1976 uint32_t retNextDataTransferHandle = 0;
1977 uint8_t retTransferFlag = 0;
1978 uint8_t retEventClass = 0;
1979 uint32_t retEventDataSize = 0;
1980 uint8_t retEventData[payloadLength] = {0};
1981 uint32_t retEventDataIntegrityChecksum = 0;
1982
Andrew Jefferye5f12532024-10-01 12:18:49 +09301983 pldm_msgbuf_extract_uint8(buf, retCompletionCode);
1984 pldm_msgbuf_extract_uint8(buf, retTid);
1985 pldm_msgbuf_extract_uint16(buf, retEventId);
1986 pldm_msgbuf_extract_uint32(buf, retNextDataTransferHandle);
1987 pldm_msgbuf_extract_uint8(buf, retTransferFlag);
1988 pldm_msgbuf_extract_uint8(buf, retEventClass);
1989 pldm_msgbuf_extract_uint32(buf, retEventDataSize);
Andrew Jeffery0a1be3c2024-08-11 08:34:10 +00001990 rc = pldm_msgbuf_extract_array_uint8(buf, retEventDataSize, retEventData,
1991 sizeof(retEventData));
1992 ASSERT_EQ(rc, 0);
Andrew Jefferye5f12532024-10-01 12:18:49 +09301993 pldm_msgbuf_extract_uint32(buf, retEventDataIntegrityChecksum);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07001994
1995 EXPECT_EQ(rc, PLDM_SUCCESS);
1996 EXPECT_EQ(retCompletionCode, completionCode);
1997 EXPECT_EQ(retTid, tId);
1998 EXPECT_EQ(retEventId, eventId);
1999 EXPECT_EQ(retNextDataTransferHandle, nextDataTransferHandle);
2000 EXPECT_EQ(retTransferFlag, transferFlag);
2001 EXPECT_EQ(retEventClass, eventClass);
2002 EXPECT_EQ(retEventDataSize, eventDataSize);
2003 EXPECT_EQ(retEventDataIntegrityChecksum, eventDataIntegrityChecksum);
2004 EXPECT_EQ(0, memcmp(pEventData, retEventData, eventDataSize));
2005
2006 EXPECT_EQ(pldm_msgbuf_destroy(buf), PLDM_SUCCESS);
2007}
2008
2009TEST(PollForPlatformEventMessage, testGoodEncodeResposeP2)
2010{
2011 uint8_t completionCode = PLDM_SUCCESS;
2012 uint8_t instance_id = 0;
2013 uint8_t tId = 0x9;
2014 uint16_t eventId = 0x0000;
2015 constexpr size_t payloadLength =
2016 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES;
2017
2018 std::array<uint8_t, hdrSize + payloadLength> responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302019 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen8eb20f22022-11-16 22:34:55 +07002020 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2021
2022 auto rc = encode_poll_for_platform_event_message_resp(
2023 instance_id, completionCode, tId, eventId, 0, 0, 0, 0, NULL, 0,
2024 response, payloadLength);
2025 EXPECT_EQ(rc, PLDM_SUCCESS);
2026
2027 struct pldm_msgbuf _buf;
2028 struct pldm_msgbuf* buf = &_buf;
Andrew Jeffery830c1eb2024-10-04 10:48:10 +09302029 rc = pldm_msgbuf_init_errno(
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09302030 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
2031 response->payload, payloadLength);
Andrew Jeffery830c1eb2024-10-04 10:48:10 +09302032 EXPECT_EQ(rc, 0);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07002033
2034 uint8_t retCompletionCode;
2035 uint8_t retTid = 0;
2036 uint16_t retEventId = 0;
2037
Andrew Jefferye5f12532024-10-01 12:18:49 +09302038 pldm_msgbuf_extract_uint8(buf, retCompletionCode);
2039 pldm_msgbuf_extract_uint8(buf, retTid);
2040 pldm_msgbuf_extract_uint16(buf, retEventId);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07002041
2042 EXPECT_EQ(rc, PLDM_SUCCESS);
2043 EXPECT_EQ(retCompletionCode, completionCode);
2044 EXPECT_EQ(retTid, tId);
2045 EXPECT_EQ(retEventId, eventId);
2046 EXPECT_EQ(pldm_msgbuf_destroy(buf), PLDM_SUCCESS);
2047}
2048
2049TEST(PollForPlatformEventMessage, testGoodEncodeResposeP3)
2050{
2051 uint8_t completionCode = PLDM_SUCCESS;
2052 uint8_t instance_id = 0;
2053 uint8_t tId = 0x9;
2054 uint16_t eventId = 0xffff;
2055 constexpr size_t payloadLength =
2056 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES;
2057
2058 std::array<uint8_t, hdrSize + payloadLength> responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302059 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen8eb20f22022-11-16 22:34:55 +07002060 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2061
2062 auto rc = encode_poll_for_platform_event_message_resp(
2063 instance_id, completionCode, tId, eventId, 0, 0, 0, 0, NULL, 0,
2064 response, payloadLength);
2065 EXPECT_EQ(rc, PLDM_SUCCESS);
2066
2067 struct pldm_msgbuf _buf;
2068 struct pldm_msgbuf* buf = &_buf;
Andrew Jeffery830c1eb2024-10-04 10:48:10 +09302069 rc = pldm_msgbuf_init_errno(
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09302070 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
2071 response->payload, payloadLength);
Andrew Jeffery830c1eb2024-10-04 10:48:10 +09302072 EXPECT_EQ(rc, 0);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07002073
2074 uint8_t retCompletionCode;
2075 uint8_t retTid = 0;
2076 uint16_t retEventId = 0;
2077
Andrew Jefferye5f12532024-10-01 12:18:49 +09302078 pldm_msgbuf_extract_uint8(buf, retCompletionCode);
2079 pldm_msgbuf_extract_uint8(buf, retTid);
2080 pldm_msgbuf_extract_uint16(buf, retEventId);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07002081
2082 EXPECT_EQ(rc, PLDM_SUCCESS);
2083 EXPECT_EQ(retCompletionCode, completionCode);
2084 EXPECT_EQ(retTid, tId);
2085 EXPECT_EQ(retEventId, eventId);
2086 EXPECT_EQ(pldm_msgbuf_destroy(buf), PLDM_SUCCESS);
2087}
2088
2089TEST(PollForPlatformEventMessage, testGoodEncodeResposeP4)
2090{
2091 uint8_t completionCode = PLDM_SUCCESS;
2092 uint8_t instance_id = 0;
2093 uint8_t tId = 0x9;
2094 uint16_t eventId = 0x1;
2095 uint32_t nextDataTransferHandle = 0xffff;
2096 uint8_t transferFlag = PLDM_END;
2097 uint8_t eventClass = 0x5;
2098 constexpr uint32_t eventDataSize = 0;
2099 uint32_t eventDataIntegrityChecksum = 0x11223344;
2100 size_t payloadLength =
2101 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_RESP_BYTES + eventDataSize + 4;
2102
2103 std::array<uint8_t, hdrSize +
2104 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_RESP_BYTES +
2105 eventDataSize + 4>
2106 responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302107 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen8eb20f22022-11-16 22:34:55 +07002108 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2109
2110 auto rc = encode_poll_for_platform_event_message_resp(
2111 instance_id, completionCode, tId, eventId, nextDataTransferHandle,
2112 transferFlag, eventClass, eventDataSize, NULL,
2113 eventDataIntegrityChecksum, response, payloadLength);
2114 EXPECT_EQ(rc, PLDM_SUCCESS);
2115
2116 struct pldm_msgbuf _buf;
2117 struct pldm_msgbuf* buf = &_buf;
Andrew Jeffery830c1eb2024-10-04 10:48:10 +09302118 rc = pldm_msgbuf_init_errno(
Andrew Jefferyc8df31c2024-05-21 16:47:43 +09302119 buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
2120 response->payload, payloadLength);
Andrew Jeffery830c1eb2024-10-04 10:48:10 +09302121 EXPECT_EQ(rc, 0);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07002122
2123 uint8_t retCompletionCode;
2124 uint8_t retTid = 0;
2125 uint16_t retEventId = 0;
2126 uint32_t retNextDataTransferHandle = 0;
2127 uint8_t retTransferFlag = 0;
2128 uint8_t retEventClass = 0;
2129 uint32_t retEventDataSize = 0;
2130 uint32_t retEventDataIntegrityChecksum = 0;
2131
Andrew Jefferye5f12532024-10-01 12:18:49 +09302132 pldm_msgbuf_extract_uint8(buf, retCompletionCode);
2133 pldm_msgbuf_extract_uint8(buf, retTid);
2134 pldm_msgbuf_extract_uint16(buf, retEventId);
2135 pldm_msgbuf_extract_uint32(buf, retNextDataTransferHandle);
2136 pldm_msgbuf_extract_uint8(buf, retTransferFlag);
2137 pldm_msgbuf_extract_uint8(buf, retEventClass);
2138 pldm_msgbuf_extract_uint32(buf, retEventDataSize);
2139 pldm_msgbuf_extract_uint32(buf, retEventDataIntegrityChecksum);
Thu Nguyen8eb20f22022-11-16 22:34:55 +07002140
2141 EXPECT_EQ(rc, PLDM_SUCCESS);
2142 EXPECT_EQ(retCompletionCode, completionCode);
2143 EXPECT_EQ(retTid, tId);
2144 EXPECT_EQ(retEventId, eventId);
2145 EXPECT_EQ(retNextDataTransferHandle, nextDataTransferHandle);
2146 EXPECT_EQ(retTransferFlag, transferFlag);
2147 EXPECT_EQ(retEventClass, eventClass);
2148 EXPECT_EQ(retEventDataSize, eventDataSize);
2149 EXPECT_EQ(retEventDataIntegrityChecksum, eventDataIntegrityChecksum);
2150
2151 EXPECT_EQ(pldm_msgbuf_destroy(buf), PLDM_SUCCESS);
2152}
2153
2154TEST(PollForPlatformEventMessage, testBadEncodeResponse)
2155{
2156 uint8_t completionCode = PLDM_SUCCESS;
2157 uint8_t instance_id = 0;
2158 uint8_t tId = 0x9;
2159 uint16_t eventId = 0x1;
2160 uint32_t nextDataTransferHandle = 0xffff;
2161 uint8_t transferFlag = 0x0;
2162 uint8_t eventClass = 0x5;
2163 const uint32_t eventDataSize = 0;
2164 uint32_t eventDataIntegrityChecksum = 0x11223344;
2165 constexpr size_t payloadLength =
2166 PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_RESP_BYTES + eventDataSize + 4;
2167
2168 std::array<uint8_t, hdrSize + payloadLength> responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302169 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen8eb20f22022-11-16 22:34:55 +07002170 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2171
2172 auto rc = encode_poll_for_platform_event_message_resp(
2173 instance_id, completionCode, tId, eventId, nextDataTransferHandle,
2174 transferFlag, eventClass, eventDataSize, NULL,
2175 eventDataIntegrityChecksum, NULL, payloadLength);
2176
2177 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2178
2179 rc = encode_poll_for_platform_event_message_resp(
2180 instance_id, completionCode, tId, eventId, nextDataTransferHandle,
2181 transferFlag, eventClass, 1, NULL, eventDataIntegrityChecksum, response,
2182 payloadLength);
2183 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2184}
2185
Andrew Jeffery9c766792022-08-10 23:12:49 +09302186TEST(PlatformEventMessage, testGoodStateSensorDecodeRequest)
2187{
2188 std::array<uint8_t,
2189 hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
2190 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES>
2191 requestMsg{};
2192
2193 uint8_t retFormatVersion = 0;
2194 uint8_t retTid = 0;
2195 uint8_t retEventClass = 0;
2196 size_t retEventDataOffset = 0;
2197
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302198 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302199 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
2200 struct pldm_platform_event_message_req* request =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302201 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302202 reinterpret_cast<struct pldm_platform_event_message_req*>(req->payload);
2203
2204 uint8_t formatVersion = 0x01;
2205 uint8_t tid = 0x02;
2206 // Sensor Event
2207 uint8_t eventClass = 0x00;
2208
2209 request->format_version = formatVersion;
2210 request->tid = tid;
2211 request->event_class = eventClass;
2212 size_t eventDataOffset =
2213 sizeof(formatVersion) + sizeof(tid) + sizeof(eventClass);
2214
2215 auto rc = decode_platform_event_message_req(
2216 req, requestMsg.size() - hdrSize, &retFormatVersion, &retTid,
2217 &retEventClass, &retEventDataOffset);
2218
2219 EXPECT_EQ(rc, PLDM_SUCCESS);
2220 EXPECT_EQ(retFormatVersion, formatVersion);
2221 EXPECT_EQ(retTid, tid);
2222 EXPECT_EQ(retEventClass, eventClass);
2223 EXPECT_EQ(retEventDataOffset, eventDataOffset);
2224}
2225
2226TEST(PlatformEventMessage, testBadDecodeRequest)
2227{
2228 const struct pldm_msg* msg = NULL;
2229 std::array<uint8_t,
2230 hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
2231 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES - 1>
2232 requestMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302233 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302234 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
2235 uint8_t retFormatVersion;
2236 uint8_t retTid = 0;
2237 uint8_t retEventClass = 0;
2238 size_t retEventDataOffset;
2239
2240 auto rc = decode_platform_event_message_req(msg, sizeof(*msg), NULL, NULL,
2241 NULL, NULL);
2242 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2243
2244 rc = decode_platform_event_message_req(
2245 req,
2246 requestMsg.size() - hdrSize -
2247 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES,
2248 &retFormatVersion, &retTid, &retEventClass, &retEventDataOffset);
2249 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2250}
2251
2252TEST(PlatformEventMessage, testGoodEncodeResponse)
2253{
2254 std::array<uint8_t,
2255 hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
2256 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES - 1>
2257 responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302258 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302259 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2260 uint8_t completionCode = 0;
2261 uint8_t instanceId = 0x01;
2262 uint8_t platformEventStatus = 0x01;
2263
2264 auto rc = encode_platform_event_message_resp(instanceId, PLDM_SUCCESS,
2265 platformEventStatus, response);
2266
2267 EXPECT_EQ(rc, PLDM_SUCCESS);
2268 EXPECT_EQ(completionCode, response->payload[0]);
2269 EXPECT_EQ(platformEventStatus, response->payload[1]);
2270}
2271
2272TEST(PlatformEventMessage, testBadEncodeResponse)
2273{
2274 auto rc = encode_platform_event_message_resp(0, PLDM_SUCCESS, 1, NULL);
2275 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2276}
2277
2278TEST(PlatformEventMessage, testGoodEncodeRequest)
2279{
John Chungb43a7782024-09-26 22:04:27 +08002280 static constexpr const uint8_t formatVersion = 0x01;
2281 static constexpr const uint8_t eventClass = 0x00;
2282 static constexpr const uint8_t eventData = 34;
2283 static constexpr const uint8_t Tid = 0x03;
2284 struct pldm_platform_event_message_req req;
2285 struct pldm_msgbuf _buf;
2286 struct pldm_msgbuf* buf = &_buf;
2287 size_t len;
2288 void* data;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302289
John Chungb43a7782024-09-26 22:04:27 +08002290 PLDM_MSG_DEFINE_P(request, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
2291 sizeof(eventData));
Andrew Jeffery9c766792022-08-10 23:12:49 +09302292
John Chungb43a7782024-09-26 22:04:27 +08002293 /* Test with the minimum event type value */
Andrew Jeffery9c766792022-08-10 23:12:49 +09302294 auto rc = encode_platform_event_message_req(
John Chungb43a7782024-09-26 22:04:27 +08002295 0, formatVersion, Tid, eventClass, &eventData, sizeof(eventData),
2296 request, sizeof(eventData) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES);
2297 ASSERT_EQ(rc, PLDM_SUCCESS);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302298
John Chungb43a7782024-09-26 22:04:27 +08002299 rc = pldm_msgbuf_init_errno(
2300 buf, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES, request->payload,
2301 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(eventData));
2302 ASSERT_EQ(rc, 0);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302303
John Chungb43a7782024-09-26 22:04:27 +08002304 pldm_msgbuf_extract_uint8(buf, req.format_version);
2305 pldm_msgbuf_extract_uint8(buf, req.tid);
2306 pldm_msgbuf_extract_uint8(buf, req.event_class);
2307 data = nullptr;
2308 pldm_msgbuf_span_remaining(buf, &data, &len);
2309 ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
2310
2311 EXPECT_EQ(formatVersion, req.format_version);
2312 EXPECT_EQ(Tid, req.tid);
2313 EXPECT_EQ(eventClass, req.event_class);
2314 ASSERT_EQ(sizeof(eventData), len);
2315 EXPECT_EQ(0, memcmp(&eventData, data, len));
2316
2317 /* Test with the maximum event type value */
2318 rc = encode_platform_event_message_req(
2319 0, formatVersion, Tid, PLDM_CPER_EVENT, &eventData, sizeof(eventData),
2320 request, sizeof(eventData) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES);
2321 ASSERT_EQ(rc, PLDM_SUCCESS);
2322
2323 rc = pldm_msgbuf_init_errno(
2324 buf, PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES, request->payload,
2325 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(eventData));
2326 ASSERT_EQ(rc, 0);
2327
2328 pldm_msgbuf_extract_uint8(buf, req.format_version);
2329 pldm_msgbuf_extract_uint8(buf, req.tid);
2330 pldm_msgbuf_extract_uint8(buf, req.event_class);
2331
2332 data = nullptr;
2333 pldm_msgbuf_span_remaining(buf, &data, &len);
2334 ASSERT_EQ(pldm_msgbuf_destroy_consumed(buf), 0);
2335
2336 EXPECT_EQ(formatVersion, req.format_version);
2337 EXPECT_EQ(Tid, req.tid);
2338 EXPECT_EQ(PLDM_CPER_EVENT, req.event_class);
2339 ASSERT_EQ(sizeof(eventData), len);
2340 EXPECT_EQ(0, memcmp(&eventData, data, len));
Andrew Jeffery9c766792022-08-10 23:12:49 +09302341}
2342
2343TEST(PlatformEventMessage, testBadEncodeRequest)
2344{
2345 uint8_t Tid = 0x03;
2346 uint8_t eventClass = 0x00;
2347 uint8_t eventData = 34;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302348 uint8_t formatVersion = 0x01;
John Chungb43a7782024-09-26 22:04:27 +08002349 static constexpr const size_t payloadLen =
2350 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(eventData);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302351
John Chungb43a7782024-09-26 22:04:27 +08002352 PLDM_MSG_DEFINE_P(request, payloadLen);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302353
2354 auto rc = encode_platform_event_message_req(
John Chungb43a7782024-09-26 22:04:27 +08002355 0, formatVersion, Tid, eventClass, &eventData, sizeof(eventData),
2356 nullptr, payloadLen);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302357 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Chungb43a7782024-09-26 22:04:27 +08002358
2359 rc = encode_platform_event_message_req(0, 0, Tid, eventClass, &eventData,
2360 sizeof(eventData), request,
2361 payloadLen);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302362 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Chungb43a7782024-09-26 22:04:27 +08002363
Andrew Jeffery9c766792022-08-10 23:12:49 +09302364 rc = encode_platform_event_message_req(0, formatVersion, Tid, eventClass,
2365 nullptr, 0, request, payloadLen);
2366 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
John Chungb43a7782024-09-26 22:04:27 +08002367
2368 rc = encode_platform_event_message_req(0, formatVersion, Tid, eventClass,
2369 &eventData, sizeof(eventData),
2370 request, 0);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302371 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
John Chungb43a7782024-09-26 22:04:27 +08002372
2373 rc = encode_platform_event_message_req(
2374 0, formatVersion, Tid, PLDM_CPER_EVENT + 1, &eventData,
2375 sizeof(eventData), request, payloadLen);
2376 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302377}
2378
2379TEST(PlatformEventMessage, testGoodDecodeResponse)
2380{
2381 std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES>
2382 responseMsg{};
2383
2384 uint8_t completionCode = PLDM_SUCCESS;
2385 uint8_t platformEventStatus = 0x01;
2386
2387 uint8_t retcompletionCode;
2388 uint8_t retplatformEventStatus;
2389
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302390 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302391 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2392 struct pldm_platform_event_message_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302393 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302394 reinterpret_cast<struct pldm_platform_event_message_resp*>(
2395 response->payload);
2396
2397 resp->completion_code = completionCode;
2398 resp->platform_event_status = platformEventStatus;
2399
2400 auto rc = decode_platform_event_message_resp(
2401 response, responseMsg.size() - hdrSize, &retcompletionCode,
2402 &retplatformEventStatus);
2403
2404 EXPECT_EQ(rc, PLDM_SUCCESS);
2405 EXPECT_EQ(completionCode, retcompletionCode);
2406 EXPECT_EQ(platformEventStatus, retplatformEventStatus);
2407}
2408
2409TEST(PlatformEventMessage, testBadDecodeResponse)
2410{
2411 std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES>
2412 responseMsg{};
2413
2414 uint8_t completionCode = PLDM_SUCCESS;
2415 uint8_t platformEventStatus = 0x01;
2416
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302417 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302418 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2419 struct pldm_platform_event_message_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302420 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302421 reinterpret_cast<struct pldm_platform_event_message_resp*>(
2422 response->payload);
2423 resp->completion_code = completionCode;
2424 resp->platform_event_status = platformEventStatus;
2425
2426 auto rc = decode_platform_event_message_resp(
2427 nullptr, responseMsg.size() - hdrSize, nullptr, nullptr);
2428
2429 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2430
2431 rc = decode_platform_event_message_resp(
2432 response, responseMsg.size() - hdrSize - 1, &completionCode,
2433 &platformEventStatus);
2434
2435 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2436}
2437
2438TEST(PlatformEventMessage, testGoodSensorEventDataDecodeRequest)
2439{
2440 std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH +
2441 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES>
2442 eventDataArr{};
2443 uint16_t sensorId = 0x1234;
2444 uint8_t sensorEventClassType = PLDM_SENSOR_OP_STATE;
2445
2446 struct pldm_sensor_event_data* eventData =
2447 (struct pldm_sensor_event_data*)eventDataArr.data();
2448 eventData->sensor_id = sensorId;
2449 eventData->sensor_event_class_type = sensorEventClassType;
2450
2451 size_t retSensorOpDataOffset;
2452 uint16_t retSensorId = 0;
2453 uint8_t retSensorEventClassType;
2454 size_t sensorOpDataOffset = sizeof(sensorId) + sizeof(sensorEventClassType);
2455 auto rc = decode_sensor_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302456 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302457 reinterpret_cast<uint8_t*>(eventData), eventDataArr.size(),
2458 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
2459 EXPECT_EQ(rc, PLDM_SUCCESS);
2460 EXPECT_EQ(retSensorId, sensorId);
2461 EXPECT_EQ(retSensorEventClassType, sensorEventClassType);
2462 EXPECT_EQ(retSensorOpDataOffset, sensorOpDataOffset);
2463}
2464
2465TEST(PlatformEventMessage, testBadSensorEventDataDecodeRequest)
2466{
2467
2468 std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH +
2469 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES>
2470 eventDataArr{};
2471
2472 struct pldm_sensor_event_data* eventData =
2473 (struct pldm_sensor_event_data*)eventDataArr.data();
2474
2475 size_t retSensorOpDataOffset;
2476 uint16_t retSensorId = 0;
2477 uint8_t retSensorEventClassType;
2478 auto rc = decode_sensor_event_data(NULL, eventDataArr.size(), &retSensorId,
2479 &retSensorEventClassType,
2480 &retSensorOpDataOffset);
2481 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2482
2483 rc = decode_sensor_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302484 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302485 reinterpret_cast<uint8_t*>(eventDataArr.data()),
2486 eventDataArr.size() -
2487 PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH,
2488 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
2489 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2490
2491 eventData->sensor_event_class_type = PLDM_SENSOR_OP_STATE;
2492
2493 rc = decode_sensor_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302494 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302495 reinterpret_cast<uint8_t*>(eventDataArr.data()), eventDataArr.size(),
2496 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
2497 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2498
2499 eventData->sensor_event_class_type = PLDM_STATE_SENSOR_STATE;
2500 rc = decode_sensor_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302501 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302502 reinterpret_cast<uint8_t*>(eventDataArr.data()), eventDataArr.size(),
2503 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
2504 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2505
2506 eventData->sensor_event_class_type = PLDM_NUMERIC_SENSOR_STATE;
2507 rc = decode_sensor_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302508 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302509 reinterpret_cast<uint8_t*>(eventDataArr.data()),
2510 eventDataArr.size() + 1, &retSensorId, &retSensorEventClassType,
2511 &retSensorOpDataOffset);
2512 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2513}
2514
Dung Cao7c250342022-11-16 22:40:37 +07002515TEST(PlatformEventMessage, testGoodPldmMsgPollEventDataDecodeRequest)
2516{
2517 std::array<uint8_t, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION +
2518 PLDM_PLATFORM_EVENT_MESSAGE_EVENT_ID +
2519 PLDM_PLATFORM_EVENT_MESSAGE_TRANFER_HANDLE>
2520 eventData{
2521 0x1, // version
2522 0x88, 0x77, // Event Id
Manojkiran Eda9e3a5d42024-06-17 16:06:42 +05302523 0x44, 0x33, 0x22, 0x11 // Transfer Handle
Dung Cao7c250342022-11-16 22:40:37 +07002524 };
2525
2526 uint8_t formatVersion = 0x01;
2527 uint16_t eventID = 0x7788;
2528 uint32_t dataTransferHandle = 0x11223344;
2529
Thu Nguyen7739d122024-07-26 11:36:39 +00002530 struct pldm_message_poll_event poll_event = {};
Dung Cao7c250342022-11-16 22:40:37 +07002531
2532 auto rc = decode_pldm_message_poll_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302533 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao7c250342022-11-16 22:40:37 +07002534 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
Thu Nguyen7739d122024-07-26 11:36:39 +00002535 &poll_event);
Dung Cao7c250342022-11-16 22:40:37 +07002536
2537 EXPECT_EQ(rc, PLDM_SUCCESS);
Thu Nguyen7739d122024-07-26 11:36:39 +00002538 EXPECT_EQ(poll_event.format_version, formatVersion);
2539 EXPECT_EQ(poll_event.event_id, eventID);
2540 EXPECT_EQ(poll_event.data_transfer_handle, dataTransferHandle);
Dung Cao7c250342022-11-16 22:40:37 +07002541}
2542
2543TEST(PlatformEventMessage, testBadPldmMsgPollEventDataDecodeRequest)
2544{
2545
2546 std::array<uint8_t, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION +
2547 PLDM_PLATFORM_EVENT_MESSAGE_EVENT_ID +
2548 PLDM_PLATFORM_EVENT_MESSAGE_TRANFER_HANDLE>
2549 eventData{
2550 0x1, // version
2551 0x88, 0x77, // Event Id
Manojkiran Eda9e3a5d42024-06-17 16:06:42 +05302552 0x44, 0x33, 0x22, 0x11 // Transfer Handle
Dung Cao7c250342022-11-16 22:40:37 +07002553 };
2554
Thu Nguyen7739d122024-07-26 11:36:39 +00002555 struct pldm_message_poll_event poll_event = {};
Dung Cao7c250342022-11-16 22:40:37 +07002556
Thu Nguyen7739d122024-07-26 11:36:39 +00002557 auto rc = decode_pldm_message_poll_event_data(NULL, eventData.size(),
2558 &poll_event);
2559 EXPECT_EQ(rc, -EINVAL);
2560
2561 rc = decode_pldm_message_poll_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302562 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen7739d122024-07-26 11:36:39 +00002563 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(), NULL);
2564 EXPECT_EQ(rc, -EINVAL);
Dung Cao7c250342022-11-16 22:40:37 +07002565
2566 rc = decode_pldm_message_poll_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302567 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao7c250342022-11-16 22:40:37 +07002568 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size() - 1,
Thu Nguyen7739d122024-07-26 11:36:39 +00002569 &poll_event);
2570 EXPECT_EQ(rc, -EOVERFLOW);
Dung Cao7c250342022-11-16 22:40:37 +07002571
2572 // Event id is 0x0000
2573 eventData[1] = 0x00;
2574 eventData[2] = 0x00;
2575 rc = decode_pldm_message_poll_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302576 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao7c250342022-11-16 22:40:37 +07002577 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
Thu Nguyen7739d122024-07-26 11:36:39 +00002578 &poll_event);
Dung Cao7c250342022-11-16 22:40:37 +07002579
Thu Nguyen7739d122024-07-26 11:36:39 +00002580 EXPECT_EQ(rc, -EPROTO);
Dung Cao7c250342022-11-16 22:40:37 +07002581
2582 // Event id is 0xffff
2583 eventData[1] = 0xff;
2584 eventData[2] = 0xff;
2585 rc = decode_pldm_message_poll_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302586 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Dung Cao7c250342022-11-16 22:40:37 +07002587 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
Thu Nguyen7739d122024-07-26 11:36:39 +00002588 &poll_event);
Dung Cao7c250342022-11-16 22:40:37 +07002589
Thu Nguyen7739d122024-07-26 11:36:39 +00002590 EXPECT_EQ(rc, -EPROTO);
Dung Cao7c250342022-11-16 22:40:37 +07002591}
2592
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302593#ifdef LIBPLDM_API_TESTING
Dung Cao7c250342022-11-16 22:40:37 +07002594TEST(PlatformEventMessage, testGoodPldmMsgPollEventDataEncode)
2595{
2596 std::array<uint8_t, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION +
2597 PLDM_PLATFORM_EVENT_MESSAGE_EVENT_ID +
2598 PLDM_PLATFORM_EVENT_MESSAGE_TRANFER_HANDLE>
2599 eventData{};
2600
Thu Nguyen7739d122024-07-26 11:36:39 +00002601 struct pldm_message_poll_event poll_event = {};
2602 poll_event.format_version = 0x01;
2603 poll_event.event_id = 0x7788;
2604 poll_event.data_transfer_handle = 0x11223344;
Dung Cao7c250342022-11-16 22:40:37 +07002605
2606 int rc = encode_pldm_message_poll_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302607 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen7739d122024-07-26 11:36:39 +00002608 &poll_event, reinterpret_cast<uint8_t*>(eventData.data()),
2609 eventData.size());
Dung Cao7c250342022-11-16 22:40:37 +07002610
2611 EXPECT_EQ(rc, PLDM_SUCCESS);
2612
2613 struct pldm_msgbuf _buf;
2614 struct pldm_msgbuf* buf = &_buf;
2615
Andrew Jeffery830c1eb2024-10-04 10:48:10 +09302616 rc = pldm_msgbuf_init_errno(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302617 buf, PLDM_MSG_POLL_EVENT_LENGTH,
2618 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
2619 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size());
Andrew Jeffery830c1eb2024-10-04 10:48:10 +09302620 EXPECT_EQ(rc, 0);
Dung Cao7c250342022-11-16 22:40:37 +07002621
2622 uint8_t retFormatVersion;
2623 uint16_t reteventID;
2624 uint32_t retDataTransferHandle;
2625
Andrew Jefferye5f12532024-10-01 12:18:49 +09302626 EXPECT_EQ(pldm_msgbuf_extract_uint8(buf, retFormatVersion), PLDM_SUCCESS);
2627 EXPECT_EQ(pldm_msgbuf_extract_uint16(buf, reteventID), PLDM_SUCCESS);
2628 EXPECT_EQ(pldm_msgbuf_extract_uint32(buf, retDataTransferHandle),
Dung Cao7c250342022-11-16 22:40:37 +07002629 PLDM_SUCCESS);
Thu Nguyen7739d122024-07-26 11:36:39 +00002630 EXPECT_EQ(retFormatVersion, poll_event.format_version);
2631 EXPECT_EQ(reteventID, poll_event.event_id);
2632 EXPECT_EQ(retDataTransferHandle, poll_event.data_transfer_handle);
Dung Cao7c250342022-11-16 22:40:37 +07002633 EXPECT_EQ(pldm_msgbuf_destroy_consumed(buf), PLDM_SUCCESS);
2634}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302635#endif
Dung Cao7c250342022-11-16 22:40:37 +07002636
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302637#ifdef LIBPLDM_API_TESTING
Dung Cao7c250342022-11-16 22:40:37 +07002638TEST(PlatformEventMessage, testBadPldmMsgPollEventDataEncode)
2639{
2640 std::array<uint8_t, PLDM_PLATFORM_EVENT_MESSAGE_FORMAT_VERSION +
2641 PLDM_PLATFORM_EVENT_MESSAGE_EVENT_ID +
2642 PLDM_PLATFORM_EVENT_MESSAGE_TRANFER_HANDLE>
2643 eventData{};
2644
Thu Nguyen7739d122024-07-26 11:36:39 +00002645 struct pldm_message_poll_event poll_event = {};
2646 poll_event.format_version = 0x01;
2647 poll_event.event_id = 0x7788;
2648 poll_event.data_transfer_handle = 0x11223344;
Dung Cao7c250342022-11-16 22:40:37 +07002649
Thu Nguyen7739d122024-07-26 11:36:39 +00002650 int rc = encode_pldm_message_poll_event_data(&poll_event, NULL,
2651 eventData.size());
2652 EXPECT_EQ(rc, -EINVAL);
Dung Cao7c250342022-11-16 22:40:37 +07002653
Thu Nguyen7739d122024-07-26 11:36:39 +00002654 poll_event.event_id = 0x0000;
Dung Cao7c250342022-11-16 22:40:37 +07002655 rc = encode_pldm_message_poll_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302656 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen7739d122024-07-26 11:36:39 +00002657 &poll_event, reinterpret_cast<uint8_t*>(eventData.data()),
2658 eventData.size());
2659 EXPECT_EQ(rc, -EPROTO);
Dung Cao7c250342022-11-16 22:40:37 +07002660
Thu Nguyen7739d122024-07-26 11:36:39 +00002661 poll_event.event_id = 0xffff;
Dung Cao7c250342022-11-16 22:40:37 +07002662 rc = encode_pldm_message_poll_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302663 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyen7739d122024-07-26 11:36:39 +00002664 &poll_event, reinterpret_cast<uint8_t*>(eventData.data()),
2665 eventData.size());
2666 EXPECT_EQ(rc, -EPROTO);
Dung Cao7c250342022-11-16 22:40:37 +07002667}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09302668#endif
Dung Cao7c250342022-11-16 22:40:37 +07002669
Andrew Jeffery9c766792022-08-10 23:12:49 +09302670TEST(PlatformEventMessage, testGoodSensorOpEventDataDecodeRequest)
2671{
2672 std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH>
2673 eventDataArr{};
2674
2675 struct pldm_sensor_event_sensor_op_state* sensorData =
2676 (struct pldm_sensor_event_sensor_op_state*)eventDataArr.data();
2677 uint8_t presentState = PLDM_SENSOR_ENABLED;
2678 uint8_t previousState = PLDM_SENSOR_INITIALIZING;
2679 sensorData->present_op_state = presentState;
2680 sensorData->previous_op_state = previousState;
2681
2682 uint8_t retPresentState;
2683 uint8_t retPreviousState;
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302684 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302685 auto rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData),
2686 eventDataArr.size(), &retPresentState,
2687 &retPreviousState);
2688 EXPECT_EQ(rc, PLDM_SUCCESS);
2689 EXPECT_EQ(retPresentState, presentState);
2690 EXPECT_EQ(retPreviousState, previousState);
2691}
2692
2693TEST(PlatformEventMessage, testBadSensorOpEventDataDecodeRequest)
2694{
2695 uint8_t presentOpState;
2696 uint8_t previousOpState;
2697 size_t sensorDataLength = PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH;
2698 auto rc = decode_sensor_op_data(NULL, sensorDataLength, &presentOpState,
2699 &previousOpState);
2700 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2701
2702 std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH>
2703 sensorData{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302704 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302705 rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData.data()),
2706 sensorDataLength + 1, &presentOpState,
2707 &previousOpState);
2708 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2709
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302710 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302711 rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData.data()),
2712 sensorDataLength, nullptr, &previousOpState);
2713 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2714}
2715
2716TEST(PlatformEventMessage, testGoodSensorStateEventDataDecodeRequest)
2717{
2718 std::array<uint8_t, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH>
2719 eventDataArr{};
2720
2721 struct pldm_sensor_event_state_sensor_state* sensorData =
2722 (struct pldm_sensor_event_state_sensor_state*)eventDataArr.data();
2723 uint8_t sensorOffset = 0x02;
2724 uint8_t eventState = PLDM_SENSOR_SHUTTINGDOWN;
2725 uint8_t previousEventState = PLDM_SENSOR_INTEST;
2726 sensorData->sensor_offset = sensorOffset;
2727 sensorData->event_state = eventState;
2728 sensorData->previous_event_state = previousEventState;
2729
2730 uint8_t retSensorOffset;
2731 uint8_t retEventState;
2732 uint8_t retPreviousState;
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302733 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302734 auto rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData),
2735 eventDataArr.size(), &retSensorOffset,
2736 &retEventState, &retPreviousState);
2737 EXPECT_EQ(rc, PLDM_SUCCESS);
2738 EXPECT_EQ(retSensorOffset, sensorOffset);
2739 EXPECT_EQ(retEventState, eventState);
2740 EXPECT_EQ(retPreviousState, previousEventState);
2741}
2742
2743TEST(PlatformEventMessage, testBadStateSensorEventDataDecodeRequest)
2744{
2745 uint8_t sensorOffset;
2746 uint8_t eventState;
2747 uint8_t previousEventState;
2748 size_t sensorDataLength = PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH;
2749 auto rc = decode_state_sensor_data(NULL, sensorDataLength, &sensorOffset,
2750 &eventState, &previousEventState);
2751 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2752
2753 std::array<uint8_t, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH>
2754 sensorData{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302755 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302756 rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData.data()),
2757 sensorDataLength - 1, &sensorOffset,
2758 &eventState, &previousEventState);
2759 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2760
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302761 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302762 rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData.data()),
2763 sensorDataLength, &sensorOffset, nullptr,
2764 &previousEventState);
2765 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2766}
2767
2768TEST(PlatformEventMessage, testGoodNumericSensorEventDataDecodeRequest)
2769{
2770 std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH>
2771 eventDataArr{};
2772 struct pldm_sensor_event_numeric_sensor_state* sensorData =
2773 (struct pldm_sensor_event_numeric_sensor_state*)eventDataArr.data();
2774
2775 size_t sensorDataLength =
2776 PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_32BIT_DATA_LENGTH;
2777 uint8_t eventState = PLDM_SENSOR_SHUTTINGDOWN;
2778 uint8_t previousEventState = PLDM_SENSOR_INTEST;
2779 uint8_t sensorDataSize = PLDM_SENSOR_DATA_SIZE_UINT32;
2780 uint32_t presentReading = 305441741;
2781 sensorData->event_state = eventState;
2782 sensorData->previous_event_state = previousEventState;
2783 sensorData->sensor_data_size = sensorDataSize;
Andrew Jeffery92f6c3c2023-04-13 15:50:10 +09302784 {
2785 uint32_t presentReadingLE = htole32(presentReading);
2786 memcpy(&sensorData->present_reading, &presentReadingLE,
2787 sizeof(presentReadingLE));
2788 }
Andrew Jeffery9c766792022-08-10 23:12:49 +09302789
2790 uint8_t retEventState;
2791 uint8_t retPreviousEventState;
2792 uint8_t retSensorDataSize;
2793 uint32_t retPresentReading;
2794
2795 auto rc = decode_numeric_sensor_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302796 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302797 reinterpret_cast<uint8_t*>(sensorData), sensorDataLength,
2798 &retEventState, &retPreviousEventState, &retSensorDataSize,
2799 &retPresentReading);
2800 EXPECT_EQ(rc, PLDM_SUCCESS);
2801 EXPECT_EQ(retEventState, eventState);
2802 EXPECT_EQ(retPreviousEventState, previousEventState);
2803 EXPECT_EQ(retSensorDataSize, sensorDataSize);
2804 EXPECT_EQ(retPresentReading, presentReading);
2805
2806 int16_t presentReadingNew = -31432;
Andrew Jeffery92f6c3c2023-04-13 15:50:10 +09302807 {
2808 int16_t presentReadingNewLE = htole16(presentReadingNew);
2809 memcpy(&sensorData->present_reading, &presentReadingNewLE,
2810 sizeof(presentReadingNewLE));
2811 }
Andrew Jeffery9c766792022-08-10 23:12:49 +09302812 sensorDataSize = PLDM_SENSOR_DATA_SIZE_SINT16;
2813 sensorData->sensor_data_size = sensorDataSize;
2814 sensorDataLength = PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_16BIT_DATA_LENGTH;
2815
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302816 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302817 rc = decode_numeric_sensor_data(reinterpret_cast<uint8_t*>(sensorData),
2818 sensorDataLength, &retEventState,
2819 &retPreviousEventState, &retSensorDataSize,
2820 &retPresentReading);
2821 EXPECT_EQ(rc, PLDM_SUCCESS);
2822 EXPECT_EQ(retEventState, eventState);
2823 EXPECT_EQ(retPreviousEventState, previousEventState);
2824 EXPECT_EQ(retSensorDataSize, sensorDataSize);
2825 EXPECT_EQ(static_cast<int16_t>(retPresentReading), presentReadingNew);
2826}
2827
2828TEST(PlatformEventMessage, testBadNumericSensorEventDataDecodeRequest)
2829{
2830 uint8_t eventState;
2831 uint8_t previousEventState;
2832 uint8_t sensorDataSize;
2833 uint32_t presentReading;
2834 size_t sensorDataLength =
2835 PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH;
2836 auto rc = decode_numeric_sensor_data(NULL, sensorDataLength, &eventState,
2837 &previousEventState, &sensorDataSize,
2838 &presentReading);
2839 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2840
2841 std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH>
2842 sensorData{};
2843 rc = decode_numeric_sensor_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302844 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302845 reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength - 1,
2846 &eventState, &previousEventState, &sensorDataSize, &presentReading);
2847 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2848
2849 struct pldm_sensor_event_numeric_sensor_state* numericSensorData =
2850 (struct pldm_sensor_event_numeric_sensor_state*)sensorData.data();
2851 numericSensorData->sensor_data_size = PLDM_SENSOR_DATA_SIZE_UINT8;
2852 rc = decode_numeric_sensor_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302853 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302854 reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength,
2855 &eventState, &previousEventState, &sensorDataSize, &presentReading);
2856 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2857
2858 numericSensorData->sensor_data_size = PLDM_SENSOR_DATA_SIZE_UINT16;
2859 rc = decode_numeric_sensor_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302860 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302861 reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength,
2862 &eventState, &previousEventState, &sensorDataSize, &presentReading);
2863 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302864}
2865
2866TEST(GetNumericEffecterValue, testGoodEncodeRequest)
2867{
2868 std::vector<uint8_t> requestMsg(hdrSize +
2869 PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES);
2870
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002871 uint16_t effecter_id = 0xab01;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302872
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302873 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302874 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2875
2876 auto rc = encode_get_numeric_effecter_value_req(0, effecter_id, request);
2877
2878 struct pldm_get_numeric_effecter_value_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302879 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302880 reinterpret_cast<struct pldm_get_numeric_effecter_value_req*>(
2881 request->payload);
2882
2883 EXPECT_EQ(rc, PLDM_SUCCESS);
2884 EXPECT_EQ(effecter_id, le16toh(req->effecter_id));
2885}
2886
2887TEST(GetNumericEffecterValue, testBadEncodeRequest)
2888{
2889 std::vector<uint8_t> requestMsg(
2890 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
2891
2892 auto rc = encode_get_numeric_effecter_value_req(0, 0, nullptr);
2893 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2894}
2895
2896TEST(GetNumericEffecterValue, testGoodDecodeRequest)
2897{
2898 std::array<uint8_t, hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES>
2899 requestMsg{};
2900
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302901 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302902 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2903 struct pldm_get_numeric_effecter_value_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302904 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302905 reinterpret_cast<struct pldm_get_numeric_effecter_value_req*>(
2906 request->payload);
2907
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002908 uint16_t effecter_id = 0x12ab;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302909 req->effecter_id = htole16(effecter_id);
2910
2911 uint16_t reteffecter_id;
2912
2913 auto rc = decode_get_numeric_effecter_value_req(
2914 request, requestMsg.size() - hdrSize, &reteffecter_id);
2915
2916 EXPECT_EQ(rc, PLDM_SUCCESS);
2917 EXPECT_EQ(effecter_id, reteffecter_id);
2918}
2919
2920TEST(GetNumericEffecterValue, testBadDecodeRequest)
2921{
2922 std::array<uint8_t, hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES>
2923 requestMsg{};
2924
2925 auto rc = decode_get_numeric_effecter_value_req(
2926 nullptr, requestMsg.size() - hdrSize, nullptr);
2927
2928 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2929
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302930 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302931 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2932 struct pldm_set_numeric_effecter_value_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302933 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302934 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
2935 request->payload);
2936
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002937 uint16_t effecter_id = 0x1a;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302938 req->effecter_id = htole16(effecter_id);
2939 uint16_t reteffecter_id;
2940
2941 rc = decode_get_numeric_effecter_value_req(
2942 request, requestMsg.size() - hdrSize - 1, &reteffecter_id);
2943
2944 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2945}
2946
2947TEST(GetNumericEffecterValue, testGoodEncodeResponse)
2948{
2949 uint8_t completionCode = 0;
2950 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT32;
2951 uint8_t effecter_operState = EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING;
2952 uint32_t pendingValue = 0x12345678;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06002953 uint32_t presentValue = 0xabcdef11;
Andrew Jefferyf990dcf2023-04-12 20:54:48 +09302954 uint32_t val_pending;
2955 uint32_t val_present;
Andrew Jeffery9c766792022-08-10 23:12:49 +09302956
2957 std::array<uint8_t,
2958 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6>
2959 responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302960 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302961 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2962
2963 auto rc = encode_get_numeric_effecter_value_resp(
2964 0, completionCode, effecter_dataSize, effecter_operState,
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302965 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302966 reinterpret_cast<uint8_t*>(&pendingValue),
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302967 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302968 reinterpret_cast<uint8_t*>(&presentValue), response,
2969 responseMsg.size() - hdrSize);
2970
2971 struct pldm_get_numeric_effecter_value_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302972 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302973 reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>(
2974 response->payload);
2975
Andrew Jefferyf990dcf2023-04-12 20:54:48 +09302976 memcpy(&val_pending, &resp->pending_and_present_values[0],
2977 sizeof(val_pending));
2978 val_pending = le32toh(val_pending);
2979 memcpy(&val_present, &resp->pending_and_present_values[4],
2980 sizeof(val_present));
2981 val_present = le32toh(val_present);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302982
2983 EXPECT_EQ(rc, PLDM_SUCCESS);
2984 EXPECT_EQ(effecter_dataSize, resp->effecter_data_size);
2985 EXPECT_EQ(effecter_operState, resp->effecter_oper_state);
Andrew Jefferyf990dcf2023-04-12 20:54:48 +09302986 EXPECT_EQ(pendingValue, val_pending);
2987 EXPECT_EQ(presentValue, val_present);
Andrew Jeffery9c766792022-08-10 23:12:49 +09302988}
2989
2990TEST(GetNumericEffecterValue, testBadEncodeResponse)
2991{
2992 std::array<uint8_t,
2993 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2>
2994 responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09302995 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09302996 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2997
2998 uint8_t pendingValue = 0x01;
2999 uint8_t presentValue = 0x02;
3000
3001 auto rc = encode_get_numeric_effecter_value_resp(
3002 0, PLDM_SUCCESS, 0, 0, nullptr, nullptr, nullptr,
3003 responseMsg.size() - hdrSize);
3004 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3005
3006 rc = encode_get_numeric_effecter_value_resp(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303007 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303008 0, PLDM_SUCCESS, 6, 9, reinterpret_cast<uint8_t*>(&pendingValue),
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303009 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303010 reinterpret_cast<uint8_t*>(&presentValue), response,
3011 responseMsg.size() - hdrSize);
3012 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3013
3014 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
3015 uint8_t effecter_operState = EFFECTER_OPER_STATE_FAILED;
3016
3017 rc = encode_get_numeric_effecter_value_resp(
3018 0, PLDM_SUCCESS, effecter_dataSize, effecter_operState,
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303019 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303020 reinterpret_cast<uint8_t*>(&pendingValue),
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303021 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303022 reinterpret_cast<uint8_t*>(&presentValue), response,
3023 responseMsg.size() - hdrSize);
3024 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3025}
3026
3027TEST(GetNumericEffecterValue, testGoodDecodeResponse)
3028{
3029 std::array<uint8_t,
3030 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2>
3031 responseMsg{};
3032
3033 uint8_t completionCode = 0;
3034 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT16;
3035 uint8_t effecter_operState = EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING;
3036 uint16_t pendingValue = 0x4321;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06003037 uint16_t presentValue = 0xdcba;
Andrew Jeffery9c766792022-08-10 23:12:49 +09303038
3039 uint8_t retcompletionCode;
3040 uint8_t reteffecter_dataSize;
3041 uint8_t reteffecter_operState;
3042 uint8_t retpendingValue[2];
3043 uint8_t retpresentValue[2];
3044
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303045 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303046 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3047 struct pldm_get_numeric_effecter_value_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303048 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303049 reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>(
3050 response->payload);
3051
3052 resp->completion_code = completionCode;
3053 resp->effecter_data_size = effecter_dataSize;
3054 resp->effecter_oper_state = effecter_operState;
3055
3056 uint16_t pendingValue_le = htole16(pendingValue);
3057 memcpy(resp->pending_and_present_values, &pendingValue_le,
3058 sizeof(pendingValue_le));
3059 uint16_t presentValue_le = htole16(presentValue);
3060 memcpy(&resp->pending_and_present_values[2], &presentValue_le,
3061 sizeof(presentValue_le));
3062
3063 auto rc = decode_get_numeric_effecter_value_resp(
3064 response, responseMsg.size() - hdrSize, &retcompletionCode,
3065 &reteffecter_dataSize, &reteffecter_operState, retpendingValue,
3066 retpresentValue);
3067
3068 EXPECT_EQ(rc, PLDM_SUCCESS);
3069 EXPECT_EQ(completionCode, retcompletionCode);
3070 EXPECT_EQ(effecter_dataSize, reteffecter_dataSize);
3071 EXPECT_EQ(effecter_operState, reteffecter_operState);
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303072 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303073 EXPECT_EQ(pendingValue, *(reinterpret_cast<uint16_t*>(retpendingValue)));
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303074 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303075 EXPECT_EQ(presentValue, *(reinterpret_cast<uint16_t*>(retpresentValue)));
3076}
3077
3078TEST(GetNumericEffecterValue, testBadDecodeResponse)
3079{
3080 std::array<uint8_t,
3081 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6>
3082 responseMsg{};
3083
3084 auto rc = decode_get_numeric_effecter_value_resp(
3085 nullptr, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr,
3086 nullptr, nullptr);
3087
3088 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3089
3090 uint8_t completionCode = 0;
3091 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_SINT16;
3092 uint8_t effecter_operState = EFFECTER_OPER_STATE_DISABLED;
3093 uint16_t pendingValue = 0x5678;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06003094 uint16_t presentValue = 0xcdef;
Andrew Jeffery9c766792022-08-10 23:12:49 +09303095
3096 uint8_t retcompletionCode;
3097 uint8_t reteffecter_dataSize;
3098 uint8_t reteffecter_operState;
3099 uint8_t retpendingValue[2];
3100 uint8_t retpresentValue[2];
3101
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303102 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303103 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3104 struct pldm_get_numeric_effecter_value_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303105 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303106 reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>(
3107 response->payload);
3108
3109 resp->completion_code = completionCode;
3110 resp->effecter_data_size = effecter_dataSize;
3111 resp->effecter_oper_state = effecter_operState;
3112
3113 uint16_t pendingValue_le = htole16(pendingValue);
3114 memcpy(resp->pending_and_present_values, &pendingValue_le,
3115 sizeof(pendingValue_le));
3116 uint16_t presentValue_le = htole16(presentValue);
3117 memcpy(&resp->pending_and_present_values[2], &presentValue_le,
3118 sizeof(presentValue_le));
3119
3120 rc = decode_get_numeric_effecter_value_resp(
3121 response, responseMsg.size() - hdrSize, &retcompletionCode,
3122 &reteffecter_dataSize, &reteffecter_operState, retpendingValue,
3123 retpresentValue);
3124
3125 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3126}
3127
3128TEST(PldmPDRRepositoryChgEventEvent, testGoodDecodeRequest)
3129{
3130 const uint8_t eventDataFormat = FORMAT_IS_PDR_HANDLES;
3131 const uint8_t numberOfChangeRecords = 2;
3132 uint8_t eventDataOperation1 = PLDM_RECORDS_DELETED;
3133 const uint8_t numberOfChangeEntries1 = 2;
3134 std::array<uint32_t, numberOfChangeEntries1> changeRecordArr1{
3135 {0x00000000, 0x12345678}};
3136 uint8_t eventDataOperation2 = PLDM_RECORDS_ADDED;
3137 const uint8_t numberOfChangeEntries2 = 5;
3138 std::array<uint32_t, numberOfChangeEntries2> changeRecordArr2{
3139 {0x01234567, 0x11223344, 0x45678901, 0x21222324, 0x98765432}};
3140 std::array<uint8_t, PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH +
3141 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH *
3142 numberOfChangeRecords +
3143 (numberOfChangeEntries1 + numberOfChangeEntries2) *
3144 sizeof(uint32_t)>
3145 eventDataArr{};
3146
3147 struct pldm_pdr_repository_chg_event_data* eventData =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303148 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303149 reinterpret_cast<struct pldm_pdr_repository_chg_event_data*>(
3150 eventDataArr.data());
3151 eventData->event_data_format = eventDataFormat;
3152 eventData->number_of_change_records = numberOfChangeRecords;
3153 struct pldm_pdr_repository_change_record_data* changeRecord1 =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303154 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303155 reinterpret_cast<struct pldm_pdr_repository_change_record_data*>(
3156 eventData->change_records);
3157 changeRecord1->event_data_operation = eventDataOperation1;
3158 changeRecord1->number_of_change_entries = numberOfChangeEntries1;
3159 memcpy(changeRecord1->change_entry, &changeRecordArr1[0],
3160 changeRecordArr1.size() * sizeof(uint32_t));
3161 struct pldm_pdr_repository_change_record_data* changeRecord2 =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303162 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303163 reinterpret_cast<struct pldm_pdr_repository_change_record_data*>(
3164 eventData->change_records +
3165 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH +
3166 (changeRecordArr1.size() * sizeof(uint32_t)));
3167 changeRecord2->event_data_operation = eventDataOperation2;
3168 changeRecord2->number_of_change_entries = numberOfChangeEntries2;
3169 memcpy(changeRecord2->change_entry, &changeRecordArr2[0],
3170 changeRecordArr2.size() * sizeof(uint32_t));
3171
3172 uint8_t retEventDataFormat{};
3173 uint8_t retNumberOfChangeRecords{};
3174 size_t retChangeRecordDataOffset{0};
3175 auto rc = decode_pldm_pdr_repository_chg_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303176 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303177 reinterpret_cast<const uint8_t*>(eventData), eventDataArr.size(),
3178 &retEventDataFormat, &retNumberOfChangeRecords,
3179 &retChangeRecordDataOffset);
3180 EXPECT_EQ(rc, PLDM_SUCCESS);
3181 EXPECT_EQ(retEventDataFormat, FORMAT_IS_PDR_HANDLES);
3182 EXPECT_EQ(retNumberOfChangeRecords, numberOfChangeRecords);
3183
3184 const uint8_t* changeRecordData =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303185 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303186 reinterpret_cast<const uint8_t*>(changeRecord1);
3187 size_t changeRecordDataSize =
3188 eventDataArr.size() - PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH;
3189 uint8_t retEventDataOperation;
3190 uint8_t retNumberOfChangeEntries;
3191 size_t retChangeEntryDataOffset;
3192
3193 rc = decode_pldm_pdr_repository_change_record_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303194 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303195 reinterpret_cast<const uint8_t*>(changeRecordData),
3196 changeRecordDataSize, &retEventDataOperation, &retNumberOfChangeEntries,
3197 &retChangeEntryDataOffset);
3198 EXPECT_EQ(rc, PLDM_SUCCESS);
3199 EXPECT_EQ(retEventDataOperation, eventDataOperation1);
3200 EXPECT_EQ(retNumberOfChangeEntries, numberOfChangeEntries1);
3201 changeRecordData += retChangeEntryDataOffset;
3202 EXPECT_EQ(0, memcmp(changeRecordData, &changeRecordArr1[0],
3203 sizeof(uint32_t) * retNumberOfChangeEntries));
3204
3205 changeRecordData += sizeof(uint32_t) * retNumberOfChangeEntries;
3206 changeRecordDataSize -= sizeof(uint32_t) * retNumberOfChangeEntries -
3207 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH;
3208 rc = decode_pldm_pdr_repository_change_record_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303209 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303210 reinterpret_cast<const uint8_t*>(changeRecordData),
3211 changeRecordDataSize, &retEventDataOperation, &retNumberOfChangeEntries,
3212 &retChangeEntryDataOffset);
3213 EXPECT_EQ(rc, PLDM_SUCCESS);
3214 EXPECT_EQ(retEventDataOperation, eventDataOperation2);
3215 EXPECT_EQ(retNumberOfChangeEntries, numberOfChangeEntries2);
3216 changeRecordData += retChangeEntryDataOffset;
3217 EXPECT_EQ(0, memcmp(changeRecordData, &changeRecordArr2[0],
3218 sizeof(uint32_t) * retNumberOfChangeEntries));
3219}
3220
3221TEST(PldmPDRRepositoryChgEventEvent, testBadDecodeRequest)
3222{
3223 uint8_t eventDataFormat{};
3224 uint8_t numberOfChangeRecords{};
3225 size_t changeRecordDataOffset{};
3226 auto rc = decode_pldm_pdr_repository_chg_event_data(
3227 NULL, 0, &eventDataFormat, &numberOfChangeRecords,
3228 &changeRecordDataOffset);
3229 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3230
3231 std::array<uint8_t, 2> eventData{};
3232 rc = decode_pldm_pdr_repository_chg_event_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303233 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303234 reinterpret_cast<const uint8_t*>(eventData.data()), 0, &eventDataFormat,
3235 &numberOfChangeRecords, &changeRecordDataOffset);
3236 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3237
3238 uint8_t eventDataOperation{};
3239 uint8_t numberOfChangeEntries{};
3240 size_t changeEntryDataOffset{};
3241 rc = decode_pldm_pdr_repository_change_record_data(
3242 NULL, 0, &eventDataOperation, &numberOfChangeEntries,
3243 &changeEntryDataOffset);
3244 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3245
3246 std::array<uint8_t, 2> changeRecord{};
3247 rc = decode_pldm_pdr_repository_change_record_data(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303248 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303249 reinterpret_cast<const uint8_t*>(changeRecord.data()), 0,
3250 &eventDataOperation, &numberOfChangeEntries, &changeEntryDataOffset);
3251 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3252}
3253
3254TEST(GetSensorReading, testGoodEncodeRequest)
3255{
3256 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES>
3257 requestMsg{};
3258
3259 uint16_t sensorId = 0x1234;
3260 bool8_t rearmEventState = 0x01;
3261
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303262 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303263 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
3264 auto rc =
3265 encode_get_sensor_reading_req(0, sensorId, rearmEventState, request);
3266
3267 struct pldm_get_sensor_reading_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303268 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303269 reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload);
3270
3271 EXPECT_EQ(rc, PLDM_SUCCESS);
3272 EXPECT_EQ(sensorId, le16toh(req->sensor_id));
3273 EXPECT_EQ(rearmEventState, req->rearm_event_state);
3274}
3275
3276TEST(GetSensorReading, testBadEncodeRequest)
3277{
3278 auto rc = encode_get_sensor_reading_req(0, 0, 0, nullptr);
3279
3280 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3281}
3282
3283TEST(GetSensorReading, testGoodDecodeRequest)
3284{
3285 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES>
3286 requestMsg{};
3287
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06003288 uint16_t sensorId = 0xabcd;
3289 bool8_t rearmEventState = 0xa;
Andrew Jeffery9c766792022-08-10 23:12:49 +09303290
3291 uint16_t retsensorId;
3292 bool8_t retrearmEventState;
3293
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303294 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303295 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
3296
3297 struct pldm_get_sensor_reading_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303298 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303299 reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload);
3300
3301 req->sensor_id = htole16(sensorId);
3302 req->rearm_event_state = rearmEventState;
3303
3304 auto rc =
3305 decode_get_sensor_reading_req(request, requestMsg.size() - hdrSize,
3306 &retsensorId, &retrearmEventState);
3307
3308 EXPECT_EQ(rc, PLDM_SUCCESS);
3309 EXPECT_EQ(sensorId, retsensorId);
3310 EXPECT_EQ(rearmEventState, retrearmEventState);
3311}
3312
3313TEST(GetSensorReading, testBadDecodeRequest)
3314{
3315 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES>
3316 requestMsg{};
3317
3318 auto rc = decode_get_sensor_reading_req(
3319 nullptr, requestMsg.size() - hdrSize, nullptr, nullptr);
3320 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3321
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06003322 uint16_t sensorId = 0xabcd;
3323 bool8_t rearmEventState = 0xa;
Andrew Jeffery9c766792022-08-10 23:12:49 +09303324
3325 uint16_t retsensorId;
3326 bool8_t retrearmEventState;
3327
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303328 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303329 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
3330
3331 struct pldm_get_sensor_reading_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303332 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303333 reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload);
3334
3335 req->sensor_id = htole16(sensorId);
3336 req->rearm_event_state = rearmEventState;
3337
3338 rc = decode_get_sensor_reading_req(request, requestMsg.size() - hdrSize - 1,
3339 &retsensorId, &retrearmEventState);
3340
3341 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3342}
3343
3344TEST(GetSensorReading, testGoodEncodeResponse)
3345{
3346 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES>
3347 responseMsg{};
3348
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303349 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303350 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3351
3352 uint8_t completionCode = 0;
3353 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
3354 uint8_t sensor_operationalState = PLDM_SENSOR_ENABLED;
3355 uint8_t sensor_event_messageEnable = PLDM_NO_EVENT_GENERATION;
3356 uint8_t presentState = PLDM_SENSOR_NORMAL;
3357 uint8_t previousState = PLDM_SENSOR_WARNING;
3358 uint8_t eventState = PLDM_SENSOR_UPPERWARNING;
3359 uint8_t presentReading = 0x21;
3360
3361 auto rc = encode_get_sensor_reading_resp(
3362 0, completionCode, sensor_dataSize, sensor_operationalState,
3363 sensor_event_messageEnable, presentState, previousState, eventState,
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303364 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303365 reinterpret_cast<uint8_t*>(&presentReading), response,
3366 responseMsg.size() - hdrSize);
3367
3368 struct pldm_get_sensor_reading_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303369 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303370 reinterpret_cast<struct pldm_get_sensor_reading_resp*>(
3371 response->payload);
3372
3373 EXPECT_EQ(rc, PLDM_SUCCESS);
3374 EXPECT_EQ(completionCode, resp->completion_code);
3375 EXPECT_EQ(sensor_dataSize, resp->sensor_data_size);
3376 EXPECT_EQ(sensor_operationalState, resp->sensor_operational_state);
3377 EXPECT_EQ(sensor_event_messageEnable, resp->sensor_event_message_enable);
3378 EXPECT_EQ(presentState, resp->present_state);
3379 EXPECT_EQ(previousState, resp->previous_state);
3380 EXPECT_EQ(eventState, resp->event_state);
3381 EXPECT_EQ(presentReading,
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303382 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303383 *(reinterpret_cast<uint8_t*>(&resp->present_reading[0])));
3384}
3385
3386TEST(GetSensorReading, testBadEncodeResponse)
3387{
3388 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3>
3389 responseMsg{};
3390
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303391 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303392 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3393
3394 uint8_t presentReading = 0x1;
3395
3396 auto rc = encode_get_sensor_reading_resp(0, PLDM_SUCCESS, 0, 0, 0, 0, 0, 0,
3397 nullptr, nullptr,
3398 responseMsg.size() - hdrSize);
3399 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3400
3401 rc = encode_get_sensor_reading_resp(
3402 0, PLDM_SUCCESS, 6, 1, 1, 1, 1, 1,
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303403 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303404 reinterpret_cast<uint8_t*>(&presentReading), response,
3405 responseMsg.size() - hdrSize);
3406 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3407
3408 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
3409
3410 rc = encode_get_sensor_reading_resp(
3411 0, PLDM_SUCCESS, sensor_dataSize, 1, 1, 1, 1, 1,
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303412 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303413 reinterpret_cast<uint8_t*>(&presentReading), response,
3414 responseMsg.size() - hdrSize);
3415 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3416}
3417
3418TEST(GetSensorReading, testGoodDecodeResponse)
3419{
3420 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3>
3421 responseMsg{};
3422
3423 uint8_t completionCode = 0;
3424 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT32;
3425 uint8_t sensor_operationalState = PLDM_SENSOR_STATUSUNKOWN;
3426 uint8_t sensor_event_messageEnable = PLDM_EVENTS_ENABLED;
3427 uint8_t presentState = PLDM_SENSOR_CRITICAL;
3428 uint8_t previousState = PLDM_SENSOR_UPPERCRITICAL;
3429 uint8_t eventState = PLDM_SENSOR_WARNING;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06003430 uint32_t presentReading = 0xabcdef11;
Andrew Jeffery9c766792022-08-10 23:12:49 +09303431
3432 uint8_t retcompletionCode;
3433 uint8_t retsensor_dataSize = PLDM_SENSOR_DATA_SIZE_UINT32;
3434 uint8_t retsensor_operationalState;
3435 uint8_t retsensor_event_messageEnable;
3436 uint8_t retpresentState;
3437 uint8_t retpreviousState;
3438 uint8_t reteventState;
3439 uint8_t retpresentReading[4];
3440
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303441 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303442 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3443 struct pldm_get_sensor_reading_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303444 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303445 reinterpret_cast<struct pldm_get_sensor_reading_resp*>(
3446 response->payload);
3447
3448 resp->completion_code = completionCode;
3449 resp->sensor_data_size = sensor_dataSize;
3450 resp->sensor_operational_state = sensor_operationalState;
3451 resp->sensor_event_message_enable = sensor_event_messageEnable;
3452 resp->present_state = presentState;
3453 resp->previous_state = previousState;
3454 resp->event_state = eventState;
3455
3456 uint32_t presentReading_le = htole32(presentReading);
3457 memcpy(resp->present_reading, &presentReading_le,
3458 sizeof(presentReading_le));
3459
3460 auto rc = decode_get_sensor_reading_resp(
3461 response, responseMsg.size() - hdrSize, &retcompletionCode,
3462 &retsensor_dataSize, &retsensor_operationalState,
3463 &retsensor_event_messageEnable, &retpresentState, &retpreviousState,
3464 &reteventState, retpresentReading);
3465
3466 EXPECT_EQ(rc, PLDM_SUCCESS);
3467 EXPECT_EQ(completionCode, retcompletionCode);
3468 EXPECT_EQ(sensor_dataSize, retsensor_dataSize);
3469 EXPECT_EQ(sensor_operationalState, retsensor_operationalState);
3470 EXPECT_EQ(sensor_event_messageEnable, retsensor_event_messageEnable);
3471 EXPECT_EQ(presentState, retpresentState);
3472 EXPECT_EQ(previousState, retpreviousState);
3473 EXPECT_EQ(eventState, reteventState);
3474 EXPECT_EQ(presentReading,
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303475 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303476 *(reinterpret_cast<uint32_t*>(retpresentReading)));
3477}
3478
3479TEST(GetSensorReading, testBadDecodeResponse)
3480{
3481 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 1>
3482 responseMsg{};
3483
3484 auto rc = decode_get_sensor_reading_resp(
3485 nullptr, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr,
3486 nullptr, nullptr, nullptr, nullptr, nullptr);
3487
3488 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3489
3490 uint8_t completionCode = 0;
3491 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
3492 uint8_t sensor_operationalState = PLDM_SENSOR_INTEST;
3493 uint8_t sensor_event_messageEnable = PLDM_EVENTS_DISABLED;
3494 uint8_t presentState = PLDM_SENSOR_FATAL;
3495 uint8_t previousState = PLDM_SENSOR_UPPERFATAL;
3496 uint8_t eventState = PLDM_SENSOR_WARNING;
Pavithra Barithayadc7d3b52024-02-06 23:46:49 -06003497 uint8_t presentReading = 0xa;
Andrew Jeffery9c766792022-08-10 23:12:49 +09303498
3499 uint8_t retcompletionCode;
3500 uint8_t retsensor_dataSize = PLDM_SENSOR_DATA_SIZE_SINT16;
3501 uint8_t retsensor_operationalState;
3502 uint8_t retsensor_event_messageEnable;
3503 uint8_t retpresent_state;
3504 uint8_t retprevious_state;
3505 uint8_t retevent_state;
3506 uint8_t retpresentReading;
3507
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303508 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303509 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3510 struct pldm_get_sensor_reading_resp* resp =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303511 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303512 reinterpret_cast<struct pldm_get_sensor_reading_resp*>(
3513 response->payload);
3514
3515 resp->completion_code = completionCode;
3516 resp->sensor_data_size = sensor_dataSize;
3517 resp->sensor_operational_state = sensor_operationalState;
3518 resp->sensor_event_message_enable = sensor_event_messageEnable;
3519 resp->present_state = presentState;
3520 resp->previous_state = previousState;
3521 resp->event_state = eventState;
3522 resp->present_reading[0] = presentReading;
3523
3524 rc = decode_get_sensor_reading_resp(
3525 response, responseMsg.size() - hdrSize, &retcompletionCode,
3526 &retsensor_dataSize, &retsensor_operationalState,
3527 &retsensor_event_messageEnable, &retpresent_state, &retprevious_state,
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303528 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303529 &retevent_state, reinterpret_cast<uint8_t*>(&retpresentReading));
3530
3531 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3532}
3533
3534TEST(SetEventReceiver, testGoodEncodeRequest)
3535{
3536 uint8_t eventMessageGlobalEnable =
3537 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
3538 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
3539 uint8_t eventReceiverAddressInfo = 0x08;
3540 uint16_t heartbeatTimer = 0x78;
3541
Andrew Jeffery2332e052024-10-08 13:52:34 +10303542 std::vector<uint8_t> requestMsg(hdrSize +
3543 PLDM_SET_EVENT_RECEIVER_REQ_BYTES);
3544 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
3545 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Andrew Jeffery9c766792022-08-10 23:12:49 +09303546
3547 auto rc = encode_set_event_receiver_req(
3548 0, eventMessageGlobalEnable, transportProtocolType,
3549 eventReceiverAddressInfo, heartbeatTimer, request);
3550
3551 EXPECT_EQ(rc, PLDM_SUCCESS);
3552 struct pldm_set_event_receiver_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303553 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303554 reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
3555 EXPECT_EQ(eventMessageGlobalEnable, req->event_message_global_enable);
3556 EXPECT_EQ(transportProtocolType, req->transport_protocol_type);
3557 EXPECT_EQ(eventReceiverAddressInfo, req->event_receiver_address_info);
3558 EXPECT_EQ(heartbeatTimer, le16toh(req->heartbeat_timer));
3559}
3560
3561TEST(SetEventReceiver, testBadEncodeRequest)
3562{
3563 uint8_t eventMessageGlobalEnable =
3564 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
3565 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
3566 uint8_t eventReceiverAddressInfo = 0x08;
3567 uint16_t heartbeatTimer = 0;
3568
Andrew Jeffery2332e052024-10-08 13:52:34 +10303569 std::vector<uint8_t> requestMsg(hdrSize +
3570 PLDM_SET_EVENT_RECEIVER_REQ_BYTES);
3571 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
3572 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Andrew Jeffery9c766792022-08-10 23:12:49 +09303573
3574 auto rc = encode_set_event_receiver_req(
3575 0, eventMessageGlobalEnable, transportProtocolType,
3576 eventReceiverAddressInfo, heartbeatTimer, request);
3577
3578 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3579}
3580
3581TEST(SetEventReceiver, testGoodDecodeResponse)
3582{
3583 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_RESP_BYTES>
3584 responseMsg{};
3585
3586 uint8_t retcompletion_code = 0;
3587 responseMsg[hdrSize] = PLDM_SUCCESS;
3588
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303589 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303590 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3591 auto rc = decode_set_event_receiver_resp(
3592 response, responseMsg.size() - sizeof(pldm_msg_hdr),
3593 &retcompletion_code);
3594
3595 EXPECT_EQ(rc, PLDM_SUCCESS);
3596 EXPECT_EQ(PLDM_SUCCESS, retcompletion_code);
3597}
3598
3599TEST(SetEventReceiver, testBadDecodeResponse)
3600{
3601 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_RESP_BYTES>
3602 responseMsg{};
3603 uint8_t retcompletion_code = 0;
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303604 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303605 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3606
3607 auto rc = decode_set_event_receiver_resp(
3608 response, responseMsg.size() - sizeof(pldm_msg_hdr), NULL);
3609
3610 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3611
3612 rc = decode_set_event_receiver_resp(
3613 nullptr, responseMsg.size() - sizeof(pldm_msg_hdr),
3614 &retcompletion_code);
3615
3616 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3617}
3618
3619TEST(SetEventReceiver, testGoodEncodeResponse)
3620{
3621 std::array<uint8_t,
3622 sizeof(pldm_msg_hdr) + PLDM_SET_EVENT_RECEIVER_RESP_BYTES>
3623 responseMsg{};
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303624 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303625 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
3626 uint8_t completionCode = 0;
3627
3628 auto rc = encode_set_event_receiver_resp(0, PLDM_SUCCESS, response);
3629
3630 EXPECT_EQ(rc, PLDM_SUCCESS);
3631 EXPECT_EQ(completionCode, response->payload[0]);
3632}
3633
3634TEST(SetEventReceiver, testBadEncodeResponse)
3635{
3636 auto rc = encode_set_event_receiver_resp(0, PLDM_SUCCESS, NULL);
3637 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3638}
3639
3640TEST(SetEventReceiver, testGoodDecodeRequest)
3641{
Andrew Jeffery2332e052024-10-08 13:52:34 +10303642
3643 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_REQ_BYTES>
3644 requestMsg{};
Andrew Jeffery9c766792022-08-10 23:12:49 +09303645
3646 uint8_t eventMessageGlobalEnable =
3647 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
3648 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
3649 uint8_t eventReceiverAddressInfo = 0x08;
3650 uint16_t heartbeatTimer = 0x78;
3651
Andrew Jeffery2332e052024-10-08 13:52:34 +10303652 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
3653 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Andrew Jeffery9c766792022-08-10 23:12:49 +09303654 struct pldm_set_event_receiver_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303655 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303656 reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
3657
3658 req->event_message_global_enable = eventMessageGlobalEnable;
3659 req->transport_protocol_type = transportProtocolType;
3660 req->event_receiver_address_info = eventReceiverAddressInfo;
3661 req->heartbeat_timer = htole16(heartbeatTimer);
3662
3663 uint8_t reteventMessageGlobalEnable;
3664 uint8_t rettransportProtocolType;
3665 uint8_t reteventReceiverAddressInfo;
3666 uint16_t retheartbeatTimer;
3667 auto rc = decode_set_event_receiver_req(
Andrew Jeffery2332e052024-10-08 13:52:34 +10303668 request, requestMsg.size() - hdrSize, &reteventMessageGlobalEnable,
3669 &rettransportProtocolType, &reteventReceiverAddressInfo,
3670 &retheartbeatTimer);
Andrew Jeffery9c766792022-08-10 23:12:49 +09303671
3672 EXPECT_EQ(rc, PLDM_SUCCESS);
3673 EXPECT_EQ(eventMessageGlobalEnable, reteventMessageGlobalEnable);
3674 EXPECT_EQ(transportProtocolType, rettransportProtocolType);
3675 EXPECT_EQ(eventReceiverAddressInfo, reteventReceiverAddressInfo);
3676 EXPECT_EQ(heartbeatTimer, retheartbeatTimer);
3677}
3678
3679TEST(SetEventReceiver, testBadDecodeRequest)
3680{
Andrew Jeffery2332e052024-10-08 13:52:34 +10303681 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_REQ_BYTES>
3682 requestMsg{};
Andrew Jeffery9c766792022-08-10 23:12:49 +09303683
Andrew Jeffery2332e052024-10-08 13:52:34 +10303684 auto rc = decode_set_event_receiver_req(NULL, requestMsg.size() - hdrSize,
3685 NULL, NULL, NULL, NULL);
Andrew Jeffery9c766792022-08-10 23:12:49 +09303686 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
3687
3688 uint8_t eventMessageGlobalEnable =
3689 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
3690 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
3691 uint8_t eventReceiverAddressInfo = 0x08;
3692 uint16_t heartbeatTimer = 0x78;
3693
Andrew Jeffery2332e052024-10-08 13:52:34 +10303694 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
3695 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Andrew Jeffery9c766792022-08-10 23:12:49 +09303696 struct pldm_set_event_receiver_req* req =
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09303697 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Andrew Jeffery9c766792022-08-10 23:12:49 +09303698 reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
3699
3700 req->event_message_global_enable = eventMessageGlobalEnable;
3701 req->transport_protocol_type = transportProtocolType;
3702 req->event_receiver_address_info = eventReceiverAddressInfo;
3703 req->heartbeat_timer = htole16(heartbeatTimer);
3704
3705 uint8_t reteventMessageGlobalEnable;
3706 uint8_t rettransportProtocolType;
3707 uint8_t reteventReceiverAddressInfo;
3708 uint16_t retheartbeatTimer;
Andrew Jeffery4f60fb72024-09-23 13:56:44 +09303709
Andrew Jeffery9c766792022-08-10 23:12:49 +09303710 rc = decode_set_event_receiver_req(
Andrew Jeffery2332e052024-10-08 13:52:34 +10303711 request, requestMsg.size() - hdrSize - 1, &reteventMessageGlobalEnable,
3712 &rettransportProtocolType, &reteventReceiverAddressInfo,
3713 &retheartbeatTimer);
Andrew Jeffery9c766792022-08-10 23:12:49 +09303714 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
3715}
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303716
3717TEST(decodeNumericSensorPdrData, Uint8Test)
3718{
3719 std::vector<uint8_t> pdr1{
3720 0x1,
3721 0x0,
3722 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303723 0x0, // record handle
3724 0x1, // PDRHeaderVersion
3725 PLDM_NUMERIC_SENSOR_PDR, // PDRType
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303726 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303727 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303728 PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH,
Andrew Jeffery01731472023-06-13 10:33:18 +09303729 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303730 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303731 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303732 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303733 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303734 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09303735 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303736 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303737 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303738 1,
3739 0, // containerID=1
3740 PLDM_NO_INIT, // sensorInit
3741 false, // sensorAuxiliaryNamesPDR
3742 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
3743 0, // unitModifier
3744 0, // rateUnit
3745 0, // baseOEMUnitHandle
3746 0, // auxUnit
3747 0, // auxUnitModifier
3748 0, // auxRateUnit
3749 0, // rel
3750 0, // auxOEMUnitHandle
3751 true, // isLinear
3752 PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize
3753 0,
3754 0,
3755 0xc0,
3756 0x3f, // resolution=1.5
3757 0,
3758 0,
3759 0x80,
3760 0x3f, // offset=1.0
3761 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303762 0, // accuracy
3763 0, // plusTolerance
3764 0, // minusTolerance
3765 3, // hysteresis = 3
3766 0, // supportedThresholds
3767 0, // thresholdAndHysteresisVolatility
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303768 0,
3769 0,
3770 0x80,
3771 0x3f, // stateTransistionInterval=1.0
3772 0,
3773 0,
3774 0x80,
3775 0x3f, // updateInverval=1.0
3776 255, // maxReadable
3777 0, // minReadable
3778 PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
3779 0, // rangeFieldsupport
3780 50, // nominalValue = 50
3781 60, // normalMax = 60
3782 40, // normalMin = 40
3783 70, // warningHigh = 70
3784 30, // warningLow = 30
3785 80, // criticalHigh = 80
3786 20, // criticalLow = 20
3787 90, // fatalHigh = 90
3788 10 // fatalLow = 10
3789 };
3790
3791 struct pldm_numeric_sensor_value_pdr decodedPdr;
3792 auto rc =
3793 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
3794 EXPECT_EQ(PLDM_SUCCESS, rc);
3795 EXPECT_EQ(1, decodedPdr.hdr.record_handle);
3796 EXPECT_EQ(1, decodedPdr.hdr.version);
3797 EXPECT_EQ(PLDM_NUMERIC_SENSOR_PDR, decodedPdr.hdr.type);
3798 EXPECT_EQ(0, decodedPdr.hdr.record_change_num);
3799 EXPECT_EQ(PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH, decodedPdr.hdr.length);
3800 EXPECT_EQ(1, decodedPdr.sensor_id);
3801 EXPECT_EQ(PLDM_ENTITY_POWER_SUPPLY, decodedPdr.entity_type);
3802 EXPECT_EQ(1, decodedPdr.entity_instance_num);
3803 EXPECT_EQ(1, decodedPdr.container_id);
3804 EXPECT_EQ(PLDM_NO_INIT, decodedPdr.sensor_init);
3805 EXPECT_EQ(false, decodedPdr.sensor_auxiliary_names_pdr);
3806 EXPECT_EQ(PLDM_SENSOR_UNIT_DEGRESS_C, decodedPdr.base_unit);
3807 EXPECT_EQ(0, decodedPdr.unit_modifier);
3808 EXPECT_EQ(0, decodedPdr.rate_unit);
3809 EXPECT_EQ(0, decodedPdr.base_oem_unit_handle);
3810 EXPECT_EQ(0, decodedPdr.aux_unit);
3811 EXPECT_EQ(0, decodedPdr.aux_unit_modifier);
3812 EXPECT_EQ(0, decodedPdr.aux_rate_unit);
3813 EXPECT_EQ(0, decodedPdr.rel);
3814 EXPECT_EQ(0, decodedPdr.aux_oem_unit_handle);
3815 EXPECT_EQ(true, decodedPdr.is_linear);
3816 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_UINT8, decodedPdr.sensor_data_size);
3817 EXPECT_FLOAT_EQ(1.5f, decodedPdr.resolution);
3818 EXPECT_FLOAT_EQ(1.0f, decodedPdr.offset);
3819 EXPECT_EQ(0, decodedPdr.accuracy);
3820 EXPECT_EQ(0, decodedPdr.plus_tolerance);
3821 EXPECT_EQ(0, decodedPdr.minus_tolerance);
3822 EXPECT_EQ(3, decodedPdr.hysteresis.value_u8);
3823 EXPECT_EQ(0, decodedPdr.supported_thresholds.byte);
3824 EXPECT_EQ(0, decodedPdr.threshold_and_hysteresis_volatility.byte);
3825 EXPECT_FLOAT_EQ(1.0f, decodedPdr.state_transition_interval);
3826 EXPECT_FLOAT_EQ(1.0f, decodedPdr.update_interval);
3827 EXPECT_EQ(255, decodedPdr.max_readable.value_u8);
3828 EXPECT_EQ(0, decodedPdr.min_readable.value_u8);
3829 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT8, decodedPdr.range_field_format);
3830 EXPECT_EQ(0, decodedPdr.range_field_support.byte);
3831 EXPECT_EQ(50, decodedPdr.nominal_value.value_u8);
3832 EXPECT_EQ(60, decodedPdr.normal_max.value_u8);
3833 EXPECT_EQ(40, decodedPdr.normal_min.value_u8);
3834 EXPECT_EQ(70, decodedPdr.warning_high.value_u8);
3835 EXPECT_EQ(30, decodedPdr.warning_low.value_u8);
3836 EXPECT_EQ(80, decodedPdr.critical_high.value_u8);
3837 EXPECT_EQ(20, decodedPdr.critical_low.value_u8);
3838 EXPECT_EQ(90, decodedPdr.fatal_high.value_u8);
3839 EXPECT_EQ(10, decodedPdr.fatal_low.value_u8);
3840}
3841
3842TEST(decodeNumericSensorPdrData, Sint8Test)
3843{
3844 std::vector<uint8_t> pdr1{
3845 0x1,
3846 0x0,
3847 0x0,
3848 0x0, // record handle
3849 0x1, // PDRHeaderVersion
3850 PLDM_NUMERIC_SENSOR_PDR, // PDRType
3851 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303852 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303853 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
3854 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH +
3855 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
Andrew Jeffery01731472023-06-13 10:33:18 +09303856 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303857 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303858 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303859 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303860 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303861 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09303862 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303863 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303864 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303865 0x1,
3866 0x0, // containerID=1
3867 PLDM_NO_INIT, // sensorInit
3868 false, // sensorAuxiliaryNamesPDR
3869 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
3870 0, // unitModifier
3871 0, // rateUnit
3872 0, // baseOEMUnitHandle
3873 0, // auxUnit
3874 0, // auxUnitModifier
3875 0, // auxRateUnit
3876 0, // rel
3877 0, // auxOEMUnitHandle
3878 true, // isLinear
3879 PLDM_RANGE_FIELD_FORMAT_SINT8, // sensorDataSize
3880 0,
3881 0,
3882 0,
3883 0, // resolution
3884 0,
3885 0,
3886 0,
3887 0, // offset
3888 0,
3889 0, // accuracy
3890 0, // plusTolerance
3891 0, // minusTolerance
3892 3, // hysteresis = 3
3893 0, // supportedThresholds
3894 0, // thresholdAndHysteresisVolatility
3895 0,
3896 0,
3897 0x80,
3898 0x3f, // stateTransistionInterval=1.0
3899 0,
3900 0,
3901 0x80,
3902 0x3f, // updateInverval=1.0
3903 0x64, // maxReadable = 100
3904 0x9c, // minReadable = -100
3905 PLDM_RANGE_FIELD_FORMAT_SINT8, // rangeFieldFormat
3906 0, // rangeFieldsupport
3907 0, // nominalValue = 0
3908 5, // normalMax = 5
3909 0xfb, // normalMin = -5
3910 10, // warningHigh = 10
3911 0xf6, // warningLow = -10
3912 20, // criticalHigh = 20
3913 0xec, // criticalLow = -20
3914 30, // fatalHigh = 30
3915 0xe2 // fatalLow = -30
3916 };
3917
3918 struct pldm_numeric_sensor_value_pdr decodedPdr;
3919 auto rc =
3920 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
3921 EXPECT_EQ(PLDM_SUCCESS, rc);
3922
3923 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT8, decodedPdr.sensor_data_size);
3924 EXPECT_EQ(100, decodedPdr.max_readable.value_s8);
3925 EXPECT_EQ(-100, decodedPdr.min_readable.value_s8);
3926 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT8, decodedPdr.range_field_format);
3927 EXPECT_EQ(0, decodedPdr.nominal_value.value_s8);
3928 EXPECT_EQ(5, decodedPdr.normal_max.value_s8);
3929 EXPECT_EQ(-5, decodedPdr.normal_min.value_s8);
3930 EXPECT_EQ(10, decodedPdr.warning_high.value_s8);
3931 EXPECT_EQ(-10, decodedPdr.warning_low.value_s8);
3932 EXPECT_EQ(20, decodedPdr.critical_high.value_s8);
3933 EXPECT_EQ(-20, decodedPdr.critical_low.value_s8);
3934 EXPECT_EQ(30, decodedPdr.fatal_high.value_s8);
3935 EXPECT_EQ(-30, decodedPdr.fatal_low.value_s8);
3936}
3937
3938TEST(decodeNumericSensorPdrData, Uint16Test)
3939{
3940 std::vector<uint8_t> pdr1{
3941 0x1,
3942 0x0,
3943 0x0,
3944 0x0, // record handle
3945 0x1, // PDRHeaderVersion
3946 PLDM_NUMERIC_SENSOR_PDR, // PDRType
3947 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303948 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303949 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
3950 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 2 +
3951 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 2,
Andrew Jeffery01731472023-06-13 10:33:18 +09303952 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303953 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09303954 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303955 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303956 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303957 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09303958 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303959 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09303960 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09303961 0x1,
3962 0x0, // containerID=1
3963 PLDM_NO_INIT, // sensorInit
3964 false, // sensorAuxiliaryNamesPDR
3965 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
3966 0, // unitModifier
3967 0, // rateUnit
3968 0, // baseOEMUnitHandle
3969 0, // auxUnit
3970 0, // auxUnitModifier
3971 0, // auxRateUnit
3972 0, // rel
3973 0, // auxOEMUnitHandle
3974 true, // isLinear
3975 PLDM_SENSOR_DATA_SIZE_UINT16, // sensorDataSize
3976 0,
3977 0,
3978 0,
3979 0, // resolution
3980 0,
3981 0,
3982 0,
3983 0, // offset
3984 0,
3985 0, // accuracy
3986 0, // plusTolerance
3987 0, // minusTolerance
3988 3,
3989 0, // hysteresis = 3
3990 0, // supportedThresholds
3991 0, // thresholdAndHysteresisVolatility
3992 0,
3993 0,
3994 0x80,
3995 0x3f, // stateTransistionInterval=1.0
3996 0,
3997 0,
3998 0x80,
Andrew Jeffery01731472023-06-13 10:33:18 +09303999 0x3f, // updateInverval=1.0
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304000 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304001 0x10, // maxReadable = 4096
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304002 0,
4003 0, // minReadable = 0
4004 PLDM_RANGE_FIELD_FORMAT_UINT16, // rangeFieldFormat
4005 0, // rangeFieldsupport
4006 0x88,
Andrew Jeffery01731472023-06-13 10:33:18 +09304007 0x13, // nominalValue = 5,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304008 0x70,
Andrew Jeffery01731472023-06-13 10:33:18 +09304009 0x17, // normalMax = 6,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304010 0xa0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304011 0x0f, // normalMin = 4,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304012 0x58,
Andrew Jeffery01731472023-06-13 10:33:18 +09304013 0x1b, // warningHigh = 7,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304014 0xb8,
Andrew Jeffery01731472023-06-13 10:33:18 +09304015 0x0b, // warningLow = 3,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304016 0x40,
Andrew Jeffery01731472023-06-13 10:33:18 +09304017 0x1f, // criticalHigh = 8,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304018 0xd0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304019 0x07, // criticalLow = 2,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304020 0x28,
Andrew Jeffery01731472023-06-13 10:33:18 +09304021 0x23, // fatalHigh = 9,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304022 0xe8,
Andrew Jeffery01731472023-06-13 10:33:18 +09304023 0x03 // fatalLow = 1,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304024 };
4025
4026 struct pldm_numeric_sensor_value_pdr decodedPdr;
4027 auto rc =
4028 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4029 EXPECT_EQ(PLDM_SUCCESS, rc);
4030
4031 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_UINT16, decodedPdr.sensor_data_size);
4032 EXPECT_EQ(4096, decodedPdr.max_readable.value_u16);
4033 EXPECT_EQ(0, decodedPdr.min_readable.value_u16);
4034 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT16, decodedPdr.range_field_format);
4035 EXPECT_EQ(5000, decodedPdr.nominal_value.value_u16);
4036 EXPECT_EQ(6000, decodedPdr.normal_max.value_u16);
4037 EXPECT_EQ(4000, decodedPdr.normal_min.value_u16);
4038 EXPECT_EQ(7000, decodedPdr.warning_high.value_u16);
4039 EXPECT_EQ(3000, decodedPdr.warning_low.value_u16);
4040 EXPECT_EQ(8000, decodedPdr.critical_high.value_u16);
4041 EXPECT_EQ(2000, decodedPdr.critical_low.value_u16);
4042 EXPECT_EQ(9000, decodedPdr.fatal_high.value_u16);
4043 EXPECT_EQ(1000, decodedPdr.fatal_low.value_u16);
4044}
4045
4046TEST(decodeNumericSensorPdrData, Sint16Test)
4047{
4048 std::vector<uint8_t> pdr1{
4049 0x1,
4050 0x0,
4051 0x0,
4052 0x0, // record handle
4053 0x1, // PDRHeaderVersion
4054 PLDM_NUMERIC_SENSOR_PDR, // PDRType
4055 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304056 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304057 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
4058 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 2 +
4059 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 2,
Andrew Jeffery01731472023-06-13 10:33:18 +09304060 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304061 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304062 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304063 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304064 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304065 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09304066 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304067 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304068 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304069 0x1,
4070 0x0, // containerID=1
4071 PLDM_NO_INIT, // sensorInit
4072 false, // sensorAuxiliaryNamesPDR
4073 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4074 0, // unitModifier
4075 0, // rateUnit
4076 0, // baseOEMUnitHandle
4077 0, // auxUnit
4078 0, // auxUnitModifier
4079 0, // auxRateUnit
4080 0, // rel
4081 0, // auxOEMUnitHandle
4082 true, // isLinear
4083 PLDM_SENSOR_DATA_SIZE_SINT16, // sensorDataSize
4084 0,
4085 0,
4086 0,
4087 0, // resolution
4088 0,
4089 0,
4090 0,
4091 0, // offset
4092 0,
4093 0, // accuracy
4094 0, // plusTolerance
4095 0, // minusTolerance
4096 3,
4097 0, // hysteresis
4098 0, // supportedThresholds
4099 0, // thresholdAndHysteresisVolatility
4100 0,
4101 0,
4102 0x80,
4103 0x3f, // stateTransistionInterval=1.0
4104 0,
4105 0,
4106 0x80,
Andrew Jeffery01731472023-06-13 10:33:18 +09304107 0x3f, // updateInverval=1.0
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304108 0xe8,
Andrew Jeffery01731472023-06-13 10:33:18 +09304109 0x03, // maxReadable = 1000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304110 0x18,
4111 0xfc, // minReadable = -1000
4112 PLDM_RANGE_FIELD_FORMAT_SINT16, // rangeFieldFormat
4113 0, // rangeFieldsupport
4114 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304115 0, // nominalValue = 0
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304116 0xf4,
Andrew Jeffery01731472023-06-13 10:33:18 +09304117 0x01, // normalMax = 500
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304118 0x0c,
Andrew Jeffery01731472023-06-13 10:33:18 +09304119 0xfe, // normalMin = -500
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304120 0xe8,
Andrew Jeffery01731472023-06-13 10:33:18 +09304121 0x03, // warningHigh = 1,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304122 0x18,
Andrew Jeffery01731472023-06-13 10:33:18 +09304123 0xfc, // warningLow = -1,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304124 0xd0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304125 0x07, // criticalHigh = 2,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304126 0x30,
Andrew Jeffery01731472023-06-13 10:33:18 +09304127 0xf8, // criticalLow = -2,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304128 0xb8,
Andrew Jeffery01731472023-06-13 10:33:18 +09304129 0x0b, // fatalHigh = 3,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304130 0x48,
Andrew Jeffery01731472023-06-13 10:33:18 +09304131 0xf4 // fatalLow = -3,000
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304132 };
4133
4134 struct pldm_numeric_sensor_value_pdr decodedPdr;
4135 auto rc =
4136 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4137 EXPECT_EQ(PLDM_SUCCESS, rc);
4138
4139 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT16, decodedPdr.sensor_data_size);
4140 EXPECT_EQ(1000, decodedPdr.max_readable.value_s16);
4141 EXPECT_EQ(-1000, decodedPdr.min_readable.value_s16);
4142 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT16, decodedPdr.range_field_format);
4143 EXPECT_EQ(0, decodedPdr.nominal_value.value_s16);
4144 EXPECT_EQ(500, decodedPdr.normal_max.value_s16);
4145 EXPECT_EQ(-500, decodedPdr.normal_min.value_s16);
4146 EXPECT_EQ(1000, decodedPdr.warning_high.value_s16);
4147 EXPECT_EQ(-1000, decodedPdr.warning_low.value_s16);
4148 EXPECT_EQ(2000, decodedPdr.critical_high.value_s16);
4149 EXPECT_EQ(-2000, decodedPdr.critical_low.value_s16);
4150 EXPECT_EQ(3000, decodedPdr.fatal_high.value_s16);
4151 EXPECT_EQ(-3000, decodedPdr.fatal_low.value_s16);
4152}
4153
4154TEST(decodeNumericSensorPdrData, Uint32Test)
4155{
4156 std::vector<uint8_t> pdr1{
4157 0x1,
4158 0x0,
4159 0x0,
4160 0x0, // record handle
4161 0x1, // PDRHeaderVersion
4162 PLDM_NUMERIC_SENSOR_PDR, // PDRType
4163 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304164 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304165 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
4166 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 4 +
4167 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
Andrew Jeffery01731472023-06-13 10:33:18 +09304168 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304169 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304170 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304171 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304172 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304173 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09304174 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304175 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304176 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304177 0x1,
4178 0x0, // containerID=1
4179 PLDM_NO_INIT, // sensorInit
4180 false, // sensorAuxiliaryNamesPDR
4181 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4182 0, // unitModifier
4183 0, // rateUnit
4184 0, // baseOEMUnitHandle
4185 0, // auxUnit
4186 0, // auxUnitModifier
4187 0, // auxRateUnit
4188 0, // rel
4189 0, // auxOEMUnitHandle
4190 true, // isLinear
4191 PLDM_SENSOR_DATA_SIZE_UINT32, // sensorDataSize
4192 0,
4193 0,
4194 0,
4195 0, // resolution
4196 0,
4197 0,
4198 0,
4199 0, // offset
4200 0,
4201 0, // accuracy
4202 0, // plusTolerance
4203 0, // minusTolerance
4204 3,
4205 0,
4206 0,
4207 0, // hysteresis
4208 0, // supportedThresholds
4209 0, // thresholdAndHysteresisVolatility
4210 0,
4211 0,
4212 0x80,
4213 0x3f, // stateTransistionInterval=1.0
4214 0,
4215 0,
4216 0x80,
4217 0x3f, // updateInverval=1.0
4218 0,
4219 0x10,
4220 0,
4221 0, // maxReadable = 4096
4222 0,
4223 0,
4224 0,
4225 0, // minReadable = 0
4226 PLDM_RANGE_FIELD_FORMAT_UINT32, // rangeFieldFormat
4227 0, // rangeFieldsupport
4228 0x40,
4229 0x4b,
4230 0x4c,
4231 0x00, // nominalValue = 5,000,000
4232 0x80,
4233 0x8d,
4234 0x5b,
4235 0x00, // normalMax = 6,000,000
4236 0x00,
4237 0x09,
4238 0x3d,
4239 0x00, // normalMin = 4,000,000
4240 0xc0,
4241 0xcf,
4242 0x6a,
4243 0x00, // warningHigh = 7,000,000
4244 0xc0,
4245 0xc6,
4246 0x2d,
4247 0x00, // warningLow = 3,000,000
4248 0x00,
4249 0x12,
4250 0x7a,
4251 0x00, // criticalHigh = 8,000,000
4252 0x80,
4253 0x84,
4254 0x1e,
4255 0x00, // criticalLow = 2,000,000
4256 0x40,
4257 0x54,
4258 0x89,
4259 0x00, // fatalHigh = 9,000,000
4260 0x40,
4261 0x42,
4262 0x0f,
4263 0x00 // fatalLow = 1,000,000
4264 };
4265
4266 struct pldm_numeric_sensor_value_pdr decodedPdr;
4267 auto rc =
4268 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4269 EXPECT_EQ(PLDM_SUCCESS, rc);
4270
4271 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_UINT32, decodedPdr.sensor_data_size);
4272 EXPECT_EQ(4096, decodedPdr.max_readable.value_u32);
4273 EXPECT_EQ(0, decodedPdr.min_readable.value_u32);
4274 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT32, decodedPdr.range_field_format);
4275 EXPECT_EQ(5000000, decodedPdr.nominal_value.value_u32);
4276 EXPECT_EQ(6000000, decodedPdr.normal_max.value_u32);
4277 EXPECT_EQ(4000000, decodedPdr.normal_min.value_u32);
4278 EXPECT_EQ(7000000, decodedPdr.warning_high.value_u32);
4279 EXPECT_EQ(3000000, decodedPdr.warning_low.value_u32);
4280 EXPECT_EQ(8000000, decodedPdr.critical_high.value_u32);
4281 EXPECT_EQ(2000000, decodedPdr.critical_low.value_u32);
4282 EXPECT_EQ(9000000, decodedPdr.fatal_high.value_u32);
4283 EXPECT_EQ(1000000, decodedPdr.fatal_low.value_u32);
4284}
4285
4286TEST(decodeNumericSensorPdrData, Sint32Test)
4287{
4288 std::vector<uint8_t> pdr1{
4289 0x1,
4290 0x0,
4291 0x0,
4292 0x0, // record handle
4293 0x1, // PDRHeaderVersion
4294 PLDM_NUMERIC_SENSOR_PDR, // PDRType
4295 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304296 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304297 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
4298 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 4 +
4299 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
Andrew Jeffery01731472023-06-13 10:33:18 +09304300 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304301 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304302 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304303 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304304 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304305 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09304306 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304307 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304308 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304309 0x1,
4310 0x0, // containerID=1
4311 PLDM_NO_INIT, // sensorInit
4312 false, // sensorAuxiliaryNamesPDR
4313 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4314 0, // unitModifier
4315 0, // rateUnit
4316 0, // baseOEMUnitHandle
4317 0, // auxUnit
4318 0, // auxUnitModifier
4319 0, // auxRateUnit
4320 0, // rel
4321 0, // auxOEMUnitHandle
4322 true, // isLinear
4323 PLDM_SENSOR_DATA_SIZE_SINT32, // sensorDataSize
4324 0,
4325 0,
4326 0,
4327 0, // resolution
4328 0,
4329 0,
4330 0,
4331 0, // offset
4332 0,
4333 0, // accuracy
4334 0, // plusTolerance
4335 0, // minusTolerance
4336 3,
4337 0,
4338 0,
4339 0, // hysteresis
4340 0, // supportedThresholds
4341 0, // thresholdAndHysteresisVolatility
4342 0,
4343 0,
4344 0x80,
4345 0x3f, // stateTransistionInterval=1.0
4346 0,
4347 0,
4348 0x80,
4349 0x3f, // updateInverval=1.0
4350 0xa0,
4351 0x86,
4352 0x01,
4353 0x00, // maxReadable = 100000
4354 0x60,
4355 0x79,
4356 0xfe,
4357 0xff, // minReadable = -10000
4358 PLDM_RANGE_FIELD_FORMAT_SINT32, // rangeFieldFormat
4359 0, // rangeFieldsupport
4360 0,
4361 0,
4362 0,
4363 0, // nominalValue = 0
4364 0x20,
4365 0xa1,
4366 0x07,
4367 0x00, // normalMax = 500,000
4368 0xe0,
4369 0x5e,
4370 0xf8,
4371 0xff, // normalMin = -500,000
4372 0x40,
4373 0x42,
4374 0x0f,
4375 0x00, // warningHigh = 1,000,000
4376 0xc0,
4377 0xbd,
4378 0xf0,
4379 0xff, // warningLow = -1,000,000
4380 0x80,
4381 0x84,
4382 0x1e,
4383 0x00, // criticalHigh = 2,000,000
4384 0x80,
4385 0x7b,
4386 0xe1,
4387 0xff, // criticalLow = -2,000,000
4388 0xc0,
4389 0xc6,
4390 0x2d,
4391 0x00, // fatalHigh = 3,000,000
4392 0x40,
4393 0x39,
4394 0xd2,
4395 0xff // fatalLow = -3,000,000
4396 };
4397
4398 struct pldm_numeric_sensor_value_pdr decodedPdr;
4399 auto rc =
4400 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4401 EXPECT_EQ(PLDM_SUCCESS, rc);
4402
4403 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT32, decodedPdr.sensor_data_size);
4404 EXPECT_EQ(100000, decodedPdr.max_readable.value_s32);
4405 EXPECT_EQ(-100000, decodedPdr.min_readable.value_s32);
4406 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT32, decodedPdr.range_field_format);
4407 EXPECT_EQ(0, decodedPdr.nominal_value.value_s32);
4408 EXPECT_EQ(500000, decodedPdr.normal_max.value_s32);
4409 EXPECT_EQ(-500000, decodedPdr.normal_min.value_s32);
4410 EXPECT_EQ(1000000, decodedPdr.warning_high.value_s32);
4411 EXPECT_EQ(-1000000, decodedPdr.warning_low.value_s32);
4412 EXPECT_EQ(2000000, decodedPdr.critical_high.value_s32);
4413 EXPECT_EQ(-2000000, decodedPdr.critical_low.value_s32);
4414 EXPECT_EQ(3000000, decodedPdr.fatal_high.value_s32);
4415 EXPECT_EQ(-3000000, decodedPdr.fatal_low.value_s32);
4416}
4417
4418TEST(decodeNumericSensorPdrData, Real32Test)
4419{
4420 std::vector<uint8_t> pdr1{
4421 0x1,
4422 0x0,
4423 0x0,
4424 0x0, // record handle
4425 0x1, // PDRHeaderVersion
4426 PLDM_NUMERIC_SENSOR_PDR, // PDRType
4427 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304428 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304429 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH +
4430 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 4 +
4431 PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
Andrew Jeffery01731472023-06-13 10:33:18 +09304432 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304433 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304434 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304435 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304436 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304437 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09304438 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304439 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304440 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304441 0x1,
4442 0x0, // containerID=1
4443 PLDM_NO_INIT, // sensorInit
4444 false, // sensorAuxiliaryNamesPDR
4445 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4446 0, // unitModifier
4447 0, // rateUnit
4448 0, // baseOEMUnitHandle
4449 0, // auxUnit
4450 0, // auxUnitModifier
4451 0, // auxRateUnit
4452 0, // rel
4453 0, // auxOEMUnitHandle
4454 true, // isLinear
4455 PLDM_SENSOR_DATA_SIZE_SINT32, // sensorDataSize
4456 0,
4457 0,
4458 0,
4459 0, // resolution
4460 0,
4461 0,
4462 0,
4463 0, // offset
4464 0,
4465 0, // accuracy
4466 0, // plusTolerance
4467 0, // minusTolerance
4468 3,
4469 0,
4470 0,
4471 0, // hysteresis
4472 0, // supportedThresholds
4473 0, // thresholdAndHysteresisVolatility
4474 0,
4475 0,
4476 0x80,
4477 0x3f, // stateTransistionInterval=1.0
4478 0,
4479 0,
4480 0x80,
4481 0x3f, // updateInverval=1.0
4482 0xa0,
4483 0x86,
4484 0x01,
4485 0x00, // maxReadable = 100000
4486 0x60,
4487 0x79,
4488 0xfe,
4489 0xff, // minReadable = -10000
4490 PLDM_RANGE_FIELD_FORMAT_REAL32, // rangeFieldFormat
4491 0, // rangeFieldsupport
4492 0,
4493 0,
4494 0,
4495 0, // nominalValue = 0.0
4496 0x33,
4497 0x33,
4498 0x48,
4499 0x42, // normalMax = 50.05
4500 0x33,
4501 0x33,
4502 0x48,
4503 0xc2, // normalMin = -50.05
4504 0x83,
4505 0x00,
4506 0xc8,
4507 0x42, // warningHigh = 100.001
4508 0x83,
4509 0x00,
4510 0xc8,
4511 0xc2, // warningLow = -100.001
4512 0x83,
4513 0x00,
4514 0x48,
4515 0x43, // criticalHigh = 200.002
4516 0x83,
4517 0x00,
4518 0x48,
4519 0xc3, // criticalLow = -200.002
4520 0x62,
4521 0x00,
4522 0x96,
4523 0x43, // fatalHigh = 300.003
4524 0x62,
4525 0x00,
4526 0x96,
4527 0xc3 // fatalLow = -300.003
4528 };
4529
4530 struct pldm_numeric_sensor_value_pdr decodedPdr;
4531 auto rc =
4532 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4533 EXPECT_EQ(PLDM_SUCCESS, rc);
4534
4535 EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT32, decodedPdr.sensor_data_size);
4536 EXPECT_EQ(100000, decodedPdr.max_readable.value_s32);
4537 EXPECT_EQ(-100000, decodedPdr.min_readable.value_s32);
4538 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_REAL32, decodedPdr.range_field_format);
4539 EXPECT_FLOAT_EQ(0, decodedPdr.nominal_value.value_f32);
4540 EXPECT_FLOAT_EQ(50.05f, decodedPdr.normal_max.value_f32);
4541 EXPECT_FLOAT_EQ(-50.05f, decodedPdr.normal_min.value_f32);
4542 EXPECT_FLOAT_EQ(100.001f, decodedPdr.warning_high.value_f32);
4543 EXPECT_FLOAT_EQ(-100.001f, decodedPdr.warning_low.value_f32);
4544 EXPECT_FLOAT_EQ(200.002f, decodedPdr.critical_high.value_f32);
4545 EXPECT_FLOAT_EQ(-200.002f, decodedPdr.critical_low.value_f32);
4546 EXPECT_FLOAT_EQ(300.003f, decodedPdr.fatal_high.value_f32);
4547 EXPECT_FLOAT_EQ(-300.003f, decodedPdr.fatal_low.value_f32);
4548}
4549
4550TEST(decodeNumericSensorPdrDataDeathTest, InvalidSizeTest)
4551{
4552 // A corrupted PDR. The data after plusTolerance missed.
4553 std::vector<uint8_t> pdr1{
4554 0x1,
4555 0x0,
4556 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304557 0x0, // record handle
4558 0x1, // PDRHeaderVersion
4559 PLDM_NUMERIC_SENSOR_PDR, // PDRType
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304560 0x0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304561 0x0, // recordChangeNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304562 PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH,
Andrew Jeffery01731472023-06-13 10:33:18 +09304563 0, // dataLength
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304564 0,
Andrew Jeffery01731472023-06-13 10:33:18 +09304565 0, // PLDMTerminusHandle
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304566 0x1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304567 0x0, // sensorID=1
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304568 PLDM_ENTITY_POWER_SUPPLY,
Andrew Jeffery01731472023-06-13 10:33:18 +09304569 0, // entityType=Power Supply(120)
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304570 1,
Andrew Jeffery01731472023-06-13 10:33:18 +09304571 0, // entityInstanceNumber
Andrew Jeffery7992eb82023-04-06 16:13:53 +09304572 0x1,
4573 0x0, // containerID=1
4574 PLDM_NO_INIT, // sensorInit
4575 false, // sensorAuxiliaryNamesPDR
4576 2, // baseUint(2)=degrees C
4577 0, // unitModifier
4578 0, // rateUnit
4579 0, // baseOEMUnitHandle
4580 0, // auxUnit
4581 0, // auxUnitModifier
4582 0, // auxRateUnit
4583 0, // rel
4584 0, // auxOEMUnitHandle
4585 true, // isLinear
4586 PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize
4587 0,
4588 0,
4589 0,
4590 0, // resolution
4591 0,
4592 0,
4593 0,
4594 0, // offset
4595 0,
4596 0, // accuracy
4597 0 // plusTolerance
4598 };
4599
4600 struct pldm_numeric_sensor_value_pdr decodedPdr;
4601 int rc =
4602 decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4603 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
4604}
Thu Nguyend4878cd2023-11-09 10:18:33 +07004605
Andrew Jeffery688be622024-05-23 11:22:51 +09304606#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004607TEST(decodeNumericEffecterPdrData, Uint8Test)
4608{
4609 std::vector<uint8_t> pdr1{
4610 0x1,
4611 0x0,
4612 0x0,
4613 0x0, // record handle
4614 0x1, // PDRHeaderVersion
4615 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4616 0x0,
4617 0x0, // recordChangeNumber
4618 PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH,
4619 0, // dataLength
4620 0,
4621 0, // PLDMTerminusHandle
4622 0x1,
4623 0x0, // effecterID=1
4624 PLDM_ENTITY_POWER_SUPPLY,
4625 0, // entityType=Power Supply(120)
4626 1,
4627 0, // entityInstanceNumber
4628 1,
4629 0, // containerID=1
4630 0x2,
4631 0x0, // effecter_semantic_id=2
4632 PLDM_NO_INIT, // effecterInit
4633 false, // effecterAuxiliaryNames
4634 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4635 0, // unitModifier
4636 0, // rateUnit
4637 0, // baseOEMUnitHandle
4638 0, // auxUnit
4639 0, // auxUnitModifier
4640 4, // auxRateUnit
4641 0, // auxOEMUnitHandle
4642 true, // isLinear
4643 PLDM_EFFECTER_DATA_SIZE_UINT8, // effecterDataSize
4644 0,
4645 0,
4646 0xc0,
4647 0x3f, // resolution=1.5
4648 0,
4649 0,
4650 0x80,
4651 0x3f, // offset=1.0
4652 0,
4653 0, // accuracy
4654 0, // plusTolerance
4655 0, // minusTolerance
4656 0,
4657 0,
4658 0x80,
4659 0x3f, // stateTransistionInterval=1.0
4660 0,
4661 0,
4662 0x80,
4663 0x3f, // transition_interval=1.0
4664 255, // maxSetdable
4665 0, // minSetable
4666 PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat
4667 0x1f, // rangeFieldsupport
4668 50, // nominalValue = 50
4669 60, // normalMax = 60
4670 40, // normalMin = 40
4671 90, // rated_max = 90
4672 10 // rated_min = 10
4673 };
4674
4675 struct pldm_numeric_effecter_value_pdr decodedPdr;
4676 auto rc =
4677 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4678 EXPECT_EQ(PLDM_SUCCESS, rc);
4679 EXPECT_EQ(1, decodedPdr.hdr.record_handle);
4680 EXPECT_EQ(1, decodedPdr.hdr.version);
4681 EXPECT_EQ(PLDM_NUMERIC_EFFECTER_PDR, decodedPdr.hdr.type);
4682 EXPECT_EQ(0, decodedPdr.hdr.record_change_num);
4683 EXPECT_EQ(PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH, decodedPdr.hdr.length);
4684 EXPECT_EQ(1, decodedPdr.effecter_id);
4685 EXPECT_EQ(PLDM_ENTITY_POWER_SUPPLY, decodedPdr.entity_type);
4686 EXPECT_EQ(1, decodedPdr.entity_instance);
4687 EXPECT_EQ(1, decodedPdr.container_id);
4688 EXPECT_EQ(2, decodedPdr.effecter_semantic_id);
4689 EXPECT_EQ(PLDM_NO_INIT, decodedPdr.effecter_init);
4690 EXPECT_EQ(false, decodedPdr.effecter_auxiliary_names);
4691 EXPECT_EQ(PLDM_SENSOR_UNIT_DEGRESS_C, decodedPdr.base_unit);
4692 EXPECT_EQ(0, decodedPdr.unit_modifier);
4693 EXPECT_EQ(0, decodedPdr.rate_unit);
4694 EXPECT_EQ(0, decodedPdr.base_oem_unit_handle);
4695 EXPECT_EQ(0, decodedPdr.aux_unit);
4696 EXPECT_EQ(0, decodedPdr.aux_unit_modifier);
4697 EXPECT_EQ(4, decodedPdr.aux_rate_unit);
4698 EXPECT_EQ(0, decodedPdr.aux_oem_unit_handle);
4699 EXPECT_EQ(true, decodedPdr.is_linear);
4700 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_UINT8, decodedPdr.effecter_data_size);
4701 EXPECT_FLOAT_EQ(1.5f, decodedPdr.resolution);
4702 EXPECT_FLOAT_EQ(1.0f, decodedPdr.offset);
4703 EXPECT_EQ(0, decodedPdr.accuracy);
4704 EXPECT_EQ(0, decodedPdr.plus_tolerance);
4705 EXPECT_EQ(0, decodedPdr.minus_tolerance);
4706 EXPECT_FLOAT_EQ(1.0f, decodedPdr.state_transition_interval);
4707 EXPECT_FLOAT_EQ(1.0f, decodedPdr.transition_interval);
4708 EXPECT_EQ(255, decodedPdr.max_settable.value_u8);
4709 EXPECT_EQ(0, decodedPdr.min_settable.value_u8);
4710 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT8, decodedPdr.range_field_format);
4711 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4712 EXPECT_EQ(50, decodedPdr.nominal_value.value_u8);
4713 EXPECT_EQ(60, decodedPdr.normal_max.value_u8);
4714 EXPECT_EQ(40, decodedPdr.normal_min.value_u8);
4715 EXPECT_EQ(90, decodedPdr.rated_max.value_u8);
4716 EXPECT_EQ(10, decodedPdr.rated_min.value_u8);
4717}
Andrew Jeffery688be622024-05-23 11:22:51 +09304718#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07004719
Andrew Jeffery688be622024-05-23 11:22:51 +09304720#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004721TEST(decodeNumericEffecterPdrData, Sint8Test)
4722{
4723 std::vector<uint8_t> pdr1{
4724 0x1,
4725 0x0,
4726 0x0,
4727 0x0, // record handle
4728 0x1, // PDRHeaderVersion
4729 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4730 0x0,
4731 0x0, // recordChangeNumber
4732 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
4733 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH +
4734 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH,
4735 0, // dataLength
4736 0,
4737 0, // PLDMTerminusHandle
4738 0x1,
4739 0x0, // effecterID=1
4740 PLDM_ENTITY_POWER_SUPPLY,
4741 0, // entityType=Power Supply(120)
4742 1,
4743 0, // entityInstanceNumber
4744 0x1,
4745 0x0, // containerID=1
4746 0x2,
4747 0x0, // effecter_semantic_id=2
4748 PLDM_NO_INIT, // effecterInit
4749 false, // effecterAuxiliaryNames
4750 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4751 0, // unitModifier
4752 0, // rateUnit
4753 0, // baseOEMUnitHandle
4754 0, // auxUnit
4755 0, // auxUnitModifier
4756 0, // auxRateUnit
4757 0, // auxOEMUnitHandle
4758 true, // isLinear
4759 PLDM_RANGE_FIELD_FORMAT_SINT8, // effecterDataSize
4760 0,
4761 0,
4762 0,
4763 0, // resolution
4764 0,
4765 0,
4766 0,
4767 0, // offset
4768 0,
4769 0, // accuracy
4770 0, // plusTolerance
4771 0, // minusTolerance
4772 0,
4773 0,
4774 0x80,
4775 0x3f, // stateTransistionInterval=1.0
4776 0,
4777 0,
4778 0x80,
4779 0x3f, // transition_interval=1.0
4780 0x64, // maxSetdable = 100
4781 0x9c, // minSetable = -100
4782 PLDM_RANGE_FIELD_FORMAT_SINT8, // rangeFieldFormat
4783 0x1f, // rangeFieldsupport
4784 0, // nominalValue = 0
4785 5, // normalMax = 5
4786 0xfb, // normalMin = -5
4787 30, // rated_max = 30
4788 0xe2 // rated_min = -30
4789 };
4790
4791 struct pldm_numeric_effecter_value_pdr decodedPdr;
4792 auto rc =
4793 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4794 EXPECT_EQ(PLDM_SUCCESS, rc);
4795
4796 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_SINT8, decodedPdr.effecter_data_size);
4797 EXPECT_EQ(100, decodedPdr.max_settable.value_s8);
4798 EXPECT_EQ(-100, decodedPdr.min_settable.value_s8);
4799 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT8, decodedPdr.range_field_format);
4800 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4801 EXPECT_EQ(0, decodedPdr.nominal_value.value_s8);
4802 EXPECT_EQ(5, decodedPdr.normal_max.value_s8);
4803 EXPECT_EQ(-5, decodedPdr.normal_min.value_s8);
4804 EXPECT_EQ(30, decodedPdr.rated_max.value_s8);
4805 EXPECT_EQ(-30, decodedPdr.rated_min.value_s8);
4806}
Andrew Jeffery688be622024-05-23 11:22:51 +09304807#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07004808
Andrew Jeffery688be622024-05-23 11:22:51 +09304809#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004810TEST(decodeNumericEffecterPdrData, Uint16Test)
4811{
4812 std::vector<uint8_t> pdr1{
4813 0x1,
4814 0x0,
4815 0x0,
4816 0x0, // record handle
4817 0x1, // PDRHeaderVersion
4818 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4819 0x0,
4820 0x0, // recordChangeNumber
4821 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
4822 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH *
4823 2 +
4824 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 2,
4825 0, // dataLength
4826 0,
4827 0, // PLDMTerminusHandle
4828 0x1,
4829 0x0, // effecterID=1
4830 PLDM_ENTITY_POWER_SUPPLY,
4831 0, // entityType=Power Supply(120)
4832 1,
4833 0, // entityInstanceNumber
4834 0x1,
4835 0x0, // containerID=1
4836 0x2,
4837 0x0, // effecter_semantic_id=2
4838 PLDM_NO_INIT, // effecterInit
4839 false, // effecterAuxiliaryNames
4840 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4841 0, // unitModifier
4842 0, // rateUnit
4843 0, // baseOEMUnitHandle
4844 0, // auxUnit
4845 0, // auxUnitModifier
4846 0, // auxRateUnit
4847 0, // auxOEMUnitHandle
4848 true, // isLinear
4849 PLDM_EFFECTER_DATA_SIZE_UINT16, // effecterDataSize
4850 0,
4851 0,
4852 0,
4853 0, // resolution
4854 0,
4855 0,
4856 0,
4857 0, // offset
4858 0,
4859 0, // accuracy
4860 0, // plusTolerance
4861 0, // minusTolerance
4862 0,
4863 0,
4864 0x80,
4865 0x3f, // stateTransistionInterval=1.0
4866 0,
4867 0,
4868 0x80,
4869 0x3f, // transition_interval=1.0
4870 0,
4871 0x10, // maxSetdable = 4096
4872 0,
4873 0, // minSetable = 0
4874 PLDM_RANGE_FIELD_FORMAT_UINT16, // rangeFieldFormat
4875 0x1f, // rangeFieldsupport
4876 0x88,
4877 0x13, // nominalValue = 5,000
4878 0x70,
4879 0x17, // normalMax = 6,000
4880 0xa0,
4881 0x0f, // normalMin = 4,000
4882 0x28,
4883 0x23, // rated_max = 9,000
4884 0xe8,
4885 0x03 // rated_min = 1,000
4886 };
4887
4888 struct pldm_numeric_effecter_value_pdr decodedPdr;
4889 auto rc =
4890 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4891 EXPECT_EQ(PLDM_SUCCESS, rc);
4892
4893 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_UINT16, decodedPdr.effecter_data_size);
4894 EXPECT_EQ(4096, decodedPdr.max_settable.value_u16);
4895 EXPECT_EQ(0, decodedPdr.min_settable.value_u16);
4896 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT16, decodedPdr.range_field_format);
4897 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4898 EXPECT_EQ(5000, decodedPdr.nominal_value.value_u16);
4899 EXPECT_EQ(6000, decodedPdr.normal_max.value_u16);
4900 EXPECT_EQ(4000, decodedPdr.normal_min.value_u16);
4901 EXPECT_EQ(9000, decodedPdr.rated_max.value_u16);
4902 EXPECT_EQ(1000, decodedPdr.rated_min.value_u16);
4903}
Andrew Jeffery688be622024-05-23 11:22:51 +09304904#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07004905
Andrew Jeffery688be622024-05-23 11:22:51 +09304906#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07004907TEST(decodeNumericEffecterPdrData, Sint16Test)
4908{
4909 std::vector<uint8_t> pdr1{
4910 0x1,
4911 0x0,
4912 0x0,
4913 0x0, // record handle
4914 0x1, // PDRHeaderVersion
4915 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
4916 0x0,
4917 0x0, // recordChangeNumber
4918 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
4919 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH *
4920 2 +
4921 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 2,
4922 0, // dataLength
4923 0,
4924 0, // PLDMTerminusHandle
4925 0x1,
4926 0x0, // effecterID=1
4927 PLDM_ENTITY_POWER_SUPPLY,
4928 0, // entityType=Power Supply(120)
4929 1,
4930 0, // entityInstanceNumber
4931 0x1,
4932 0x0, // containerID=1
4933 0x2,
4934 0x0, // effecter_semantic_id=2
4935 PLDM_NO_INIT, // effecterInit
4936 false, // effecterAuxiliaryNames
4937 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
4938 0, // unitModifier
4939 0, // rateUnit
4940 0, // baseOEMUnitHandle
4941 0, // auxUnit
4942 0, // auxUnitModifier
4943 0, // auxRateUnit
4944 0, // auxOEMUnitHandle
4945 true, // isLinear
4946 PLDM_EFFECTER_DATA_SIZE_SINT16, // effecterDataSize
4947 0,
4948 0,
4949 0,
4950 0, // resolution
4951 0,
4952 0,
4953 0,
4954 0, // offset
4955 0,
4956 0, // accuracy
4957 0, // plusTolerance
4958 0, // minusTolerance
4959 0,
4960 0,
4961 0x80,
4962 0x3f, // stateTransistionInterval=1.0
4963 0,
4964 0,
4965 0x80,
4966 0x3f, // transition_interval=1.0
4967 0xe8,
4968 0x03, // maxSetdable = 1000
4969 0x18,
4970 0xfc, // minSetable = -1000
4971 PLDM_RANGE_FIELD_FORMAT_SINT16, // rangeFieldFormat
4972 0x1f, // rangeFieldsupport
4973 0,
4974 0, // nominalValue = 0
4975 0xf4,
4976 0x01, // normalMax = 500
4977 0x0c,
4978 0xfe, // normalMin = -500
4979 0xb8,
4980 0x0b, // rated_max = 3,000
4981 0x48,
4982 0xf4 // rated_min = -3,000
4983 };
4984
4985 struct pldm_numeric_effecter_value_pdr decodedPdr;
4986 auto rc =
4987 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
4988 EXPECT_EQ(PLDM_SUCCESS, rc);
4989
4990 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_SINT16, decodedPdr.effecter_data_size);
4991 EXPECT_EQ(1000, decodedPdr.max_settable.value_s16);
4992 EXPECT_EQ(-1000, decodedPdr.min_settable.value_s16);
4993 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT16, decodedPdr.range_field_format);
4994 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
4995 EXPECT_EQ(0, decodedPdr.nominal_value.value_s16);
4996 EXPECT_EQ(500, decodedPdr.normal_max.value_s16);
4997 EXPECT_EQ(-500, decodedPdr.normal_min.value_s16);
4998 EXPECT_EQ(3000, decodedPdr.rated_max.value_s16);
4999 EXPECT_EQ(-3000, decodedPdr.rated_min.value_s16);
5000}
Andrew Jeffery688be622024-05-23 11:22:51 +09305001#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07005002
Andrew Jeffery688be622024-05-23 11:22:51 +09305003#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07005004TEST(decodeNumericEffecterPdrData, Uint32Test)
5005{
5006 std::vector<uint8_t> pdr1{
5007 0x1,
5008 0x0,
5009 0x0,
5010 0x0, // record handle
5011 0x1, // PDRHeaderVersion
5012 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
5013 0x0,
5014 0x0, // recordChangeNumber
5015 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
5016 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH *
5017 4 +
5018 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
5019 0, // dataLength
5020 0,
5021 0, // PLDMTerminusHandle
5022 0x1,
5023 0x0, // effecterID=1
5024 PLDM_ENTITY_POWER_SUPPLY,
5025 0, // entityType=Power Supply(120)
5026 1,
5027 0, // entityInstanceNumber
5028 0x1,
5029 0x0, // containerID=1
5030 0x2,
5031 0x0, // effecter_semantic_id=2
5032 PLDM_NO_INIT, // effecterInit
5033 false, // effecterAuxiliaryNames
5034 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
5035 0, // unitModifier
5036 0, // rateUnit
5037 0, // baseOEMUnitHandle
5038 0, // auxUnit
5039 0, // auxUnitModifier
5040 0, // auxRateUnit
5041 0, // auxOEMUnitHandle
5042 true, // isLinear
5043 PLDM_EFFECTER_DATA_SIZE_UINT32, // effecterDataSize
5044 0,
5045 0,
5046 0,
5047 0, // resolution
5048 0,
5049 0,
5050 0,
5051 0, // offset
5052 0,
5053 0, // accuracy
5054 0, // plusTolerance
5055 0, // minusTolerance
5056 0,
5057 0,
5058 0x80,
5059 0x3f, // stateTransistionInterval=1.0
5060 0,
5061 0,
5062 0x80,
5063 0x3f, // transition_interval=1.0
5064 0,
5065 0x10,
5066 0,
5067 0, // maxSetdable = 4096
5068 0,
5069 0,
5070 0,
5071 0, // minSetable = 0
5072 PLDM_RANGE_FIELD_FORMAT_UINT32, // rangeFieldFormat
5073 0x1f, // rangeFieldsupport
5074 0x40,
5075 0x4b,
5076 0x4c,
5077 0x00, // nominalValue = 5,000,000
5078 0x80,
5079 0x8d,
5080 0x5b,
5081 0x00, // normalMax = 6,000,000
5082 0x00,
5083 0x09,
5084 0x3d,
5085 0x00, // normalMin = 4,000,000
5086 0x40,
5087 0x54,
5088 0x89,
5089 0x00, // rated_max = 9,000,000
5090 0x40,
5091 0x42,
5092 0x0f,
5093 0x00 // rated_min = 1,000,000
5094 };
5095
5096 struct pldm_numeric_effecter_value_pdr decodedPdr;
5097 auto rc =
5098 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
5099 EXPECT_EQ(PLDM_SUCCESS, rc);
5100
5101 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_UINT32, decodedPdr.effecter_data_size);
5102 EXPECT_EQ(4096, decodedPdr.max_settable.value_u32);
5103 EXPECT_EQ(0, decodedPdr.min_settable.value_u32);
5104 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT32, decodedPdr.range_field_format);
5105 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
5106 EXPECT_EQ(5000000, decodedPdr.nominal_value.value_u32);
5107 EXPECT_EQ(6000000, decodedPdr.normal_max.value_u32);
5108 EXPECT_EQ(4000000, decodedPdr.normal_min.value_u32);
5109 EXPECT_EQ(9000000, decodedPdr.rated_max.value_u32);
5110 EXPECT_EQ(1000000, decodedPdr.rated_min.value_u32);
5111}
Andrew Jeffery688be622024-05-23 11:22:51 +09305112#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07005113
Andrew Jeffery688be622024-05-23 11:22:51 +09305114#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07005115TEST(decodeNumericEffecterPdrData, Sint32Test)
5116{
5117 std::vector<uint8_t> pdr1{
5118 0x1,
5119 0x0,
5120 0x0,
5121 0x0, // record handle
5122 0x1, // PDRHeaderVersion
5123 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
5124 0x0,
5125 0x0, // recordChangeNumber
5126 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
5127 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH *
5128 4 +
5129 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
5130 0, // dataLength
5131 0,
5132 0, // PLDMTerminusHandle
5133 0x1,
5134 0x0, // effecterID=1
5135 PLDM_ENTITY_POWER_SUPPLY,
5136 0, // entityType=Power Supply(120)
5137 1,
5138 0, // entityInstanceNumber
5139 0x1,
5140 0x0, // containerID=1
5141 0x2,
5142 0x0, // effecter_semantic_id=2
5143 PLDM_NO_INIT, // effecterInit
5144 false, // effecterAuxiliaryNames
5145 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
5146 0, // unitModifier
5147 0, // rateUnit
5148 0, // baseOEMUnitHandle
5149 0, // auxUnit
5150 0, // auxUnitModifier
5151 0, // auxRateUnit
5152 0, // auxOEMUnitHandle
5153 true, // isLinear
5154 PLDM_EFFECTER_DATA_SIZE_SINT32, // effecterDataSize
5155 0,
5156 0,
5157 0,
5158 0, // resolution
5159 0,
5160 0,
5161 0,
5162 0, // offset
5163 0,
5164 0, // accuracy
5165 0, // plusTolerance
5166 0, // minusTolerance
5167 0,
5168 0,
5169 0x80,
5170 0x3f, // stateTransistionInterval=1.0
5171 0,
5172 0,
5173 0x80,
5174 0x3f, // transition_interval=1.0
5175 0xa0,
5176 0x86,
5177 0x01,
5178 0x00, // maxSetdable = 100000
5179 0x60,
5180 0x79,
5181 0xfe,
5182 0xff, // minSetable = -10000
5183 PLDM_RANGE_FIELD_FORMAT_SINT32, // rangeFieldFormat
5184 0x1f, // rangeFieldsupport
5185 0,
5186 0,
5187 0,
5188 0, // nominalValue = 0
5189 0x20,
5190 0xa1,
5191 0x07,
5192 0x00, // normalMax = 500,000
5193 0xe0,
5194 0x5e,
5195 0xf8,
5196 0xff, // normalMin = -500,000
5197 0xc0,
5198 0xc6,
5199 0x2d,
5200 0x00, // rated_max = 3,000,000
5201 0x40,
5202 0x39,
5203 0xd2,
5204 0xff // rated_min = -3,000,000
5205 };
5206
5207 struct pldm_numeric_effecter_value_pdr decodedPdr;
5208 auto rc =
5209 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
5210 EXPECT_EQ(PLDM_SUCCESS, rc);
5211 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_SINT32, decodedPdr.effecter_data_size);
5212 EXPECT_EQ(100000, decodedPdr.max_settable.value_s32);
5213 EXPECT_EQ(-100000, decodedPdr.min_settable.value_s32);
5214 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT32, decodedPdr.range_field_format);
5215 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
5216 EXPECT_EQ(0, decodedPdr.nominal_value.value_s32);
5217 EXPECT_EQ(500000, decodedPdr.normal_max.value_s32);
5218 EXPECT_EQ(-500000, decodedPdr.normal_min.value_s32);
5219 EXPECT_EQ(3000000, decodedPdr.rated_max.value_s32);
5220 EXPECT_EQ(-3000000, decodedPdr.rated_min.value_s32);
5221}
Andrew Jeffery688be622024-05-23 11:22:51 +09305222#endif
Thu Nguyend4878cd2023-11-09 10:18:33 +07005223
Andrew Jeffery688be622024-05-23 11:22:51 +09305224#ifdef LIBPLDM_API_TESTING
Thu Nguyend4878cd2023-11-09 10:18:33 +07005225TEST(decodeNumericEffecterPdrData, Real32Test)
5226{
5227 std::vector<uint8_t> pdr1{
5228 0x1,
5229 0x0,
5230 0x0,
5231 0x0, // record handle
5232 0x1, // PDRHeaderVersion
5233 PLDM_NUMERIC_EFFECTER_PDR, // PDRType
5234 0x0,
5235 0x0, // recordChangeNumber
5236 PLDM_PDR_NUMERIC_EFFECTER_PDR_FIXED_LENGTH +
5237 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_EFFECTER_DATA_SIZE_MIN_LENGTH *
5238 4 +
5239 PLDM_PDR_NUMERIC_EFFECTER_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4,
5240 0, // dataLength
5241 0,
5242
5243 0, // PLDMTerminusHandle
5244 0x1,
5245 0x0, // effecterID=1
5246 PLDM_ENTITY_POWER_SUPPLY,
5247 0, // entityType=Power Supply(120)
5248 1,
5249 0, // entityInstanceNumber
5250 0x1,
5251 0x0, // containerID=1
5252 0x2,
5253 0x0, // effecter_semantic_id=2
5254 PLDM_NO_INIT, // effecterInit
5255 false, // effecterAuxiliaryNames
5256 PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C
5257 0, // unitModifier
5258 0, // rateUnit
5259 0, // baseOEMUnitHandle
5260 0, // auxUnit
5261 0, // auxUnitModifier
5262 0, // auxRateUnit
5263 0, // auxOEMUnitHandle
5264 true, // isLinear
5265 PLDM_EFFECTER_DATA_SIZE_SINT32, // effecterDataSize
5266 0,
5267 0,
5268 0,
5269 0, // resolution
5270 0,
5271 0,
5272 0,
5273 0, // offset
5274 0,
5275 0, // accuracy
5276 0, // plusTolerance
5277 0, // minusTolerance
5278 0,
5279 0,
5280 0x80,
5281 0x3f, // stateTransistionInterval=1.0
5282 0,
5283 0,
5284 0x80,
5285 0x3f, // transition_interval=1.0
5286 0xa0,
5287 0x86,
5288 0x01,
5289 0x00, // maxSetdable = 100000
5290 0x60,
5291 0x79,
5292 0xfe,
5293 0xff, // minSetable = -10000
5294 PLDM_RANGE_FIELD_FORMAT_REAL32, // rangeFieldFormat
5295 0x1f, // rangeFieldsupport
5296 0,
5297 0,
5298 0,
5299 0, // nominalValue = 0.0
5300 0x33,
5301 0x33,
5302 0x48,
5303 0x42, // normalMax = 50.05
5304 0x33,
5305 0x33,
5306 0x48,
5307 0xc2, // normalMin = -50.05
5308 0x62,
5309 0x00,
5310 0x96,
5311 0x43, // rated_max = 300.003
5312 0x62,
5313 0x00,
5314 0x96,
5315 0xc3 // rated_min = -300.003
5316 };
5317
5318 struct pldm_numeric_effecter_value_pdr decodedPdr;
5319 auto rc =
5320 decode_numeric_effecter_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr);
5321 EXPECT_EQ(PLDM_SUCCESS, rc);
5322
5323 EXPECT_EQ(PLDM_EFFECTER_DATA_SIZE_SINT32, decodedPdr.effecter_data_size);
5324 EXPECT_FLOAT_EQ(1.0f, decodedPdr.state_transition_interval);
5325 EXPECT_FLOAT_EQ(1.0f, decodedPdr.transition_interval);
5326 EXPECT_EQ(100000, decodedPdr.max_settable.value_s32);
5327 EXPECT_EQ(-100000, decodedPdr.min_settable.value_s32);
5328 EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_REAL32, decodedPdr.range_field_format);
5329 EXPECT_EQ(0x1f, decodedPdr.range_field_support.byte);
5330 EXPECT_FLOAT_EQ(0, decodedPdr.nominal_value.value_f32);
5331 EXPECT_FLOAT_EQ(50.05f, decodedPdr.normal_max.value_f32);
5332 EXPECT_FLOAT_EQ(-50.05f, decodedPdr.normal_min.value_f32);
5333 EXPECT_FLOAT_EQ(300.003f, decodedPdr.rated_max.value_f32);
5334 EXPECT_FLOAT_EQ(-300.003f, decodedPdr.rated_min.value_f32);
5335}
Andrew Jeffery688be622024-05-23 11:22:51 +09305336#endif
Tal Yacobia6fa5552024-05-05 16:57:38 +03005337
Tal Yacobia6fa5552024-05-05 16:57:38 +03005338TEST(GetStateEffecterStates, testEncodeAndDecodeRequest)
5339{
5340 std::array<uint8_t, hdrSize + PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES>
5341 requestMsg{};
5342
5343 constexpr std::array<uint8_t,
5344 hdrSize + PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES>
5345 expectedRequestMsg{
5346 {0x80, PLDM_PLATFORM, PLDM_GET_STATE_EFFECTER_STATES, 1, 0xab}};
5347
5348 constexpr uint16_t effecter_id = 0xab01;
5349
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305350 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Tal Yacobia6fa5552024-05-05 16:57:38 +03005351 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
5352
5353 auto rc = encode_get_state_effecter_states_req(
5354 0, effecter_id, request, PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
5355
5356 EXPECT_EQ(rc, PLDM_SUCCESS);
5357 EXPECT_EQ(requestMsg, expectedRequestMsg);
5358
5359 uint16_t ret_effecter_id;
5360
5361 rc = decode_get_state_effecter_states_req(
5362 request, requestMsg.size() - hdrSize, &ret_effecter_id);
5363
5364 EXPECT_EQ(rc, PLDM_SUCCESS);
5365 EXPECT_EQ(effecter_id, ret_effecter_id);
5366
5367 // Test invalid length decode request
5368
5369 rc = decode_get_state_effecter_states_req(
5370 request, requestMsg.size() - hdrSize - 1, &ret_effecter_id);
5371
Tal Yacobif490a382024-05-31 09:57:36 +03005372 EXPECT_EQ(rc, -EOVERFLOW);
Tal Yacobia6fa5552024-05-05 16:57:38 +03005373}
Tal Yacobia6fa5552024-05-05 16:57:38 +03005374
Tal Yacobia6fa5552024-05-05 16:57:38 +03005375TEST(GetStateEffecterStates, testBadEncodeRequest)
5376{
5377 std::vector<uint8_t> requestMsg(hdrSize +
5378 PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
5379
5380 auto rc = encode_get_state_effecter_states_req(
5381 0, 0, nullptr, PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
Tal Yacobif490a382024-05-31 09:57:36 +03005382 EXPECT_EQ(rc, -EINVAL);
Tal Yacobia6fa5552024-05-05 16:57:38 +03005383}
Tal Yacobia6fa5552024-05-05 16:57:38 +03005384
Tal Yacobia6fa5552024-05-05 16:57:38 +03005385TEST(GetStateEffecterStates, testBadDecodeRequest)
5386{
5387 std::array<uint8_t, hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES>
5388 requestMsg{};
5389
5390 auto rc = decode_get_state_effecter_states_req(
5391 nullptr, requestMsg.size() - hdrSize, nullptr);
5392
Tal Yacobif490a382024-05-31 09:57:36 +03005393 EXPECT_EQ(rc, -EINVAL);
Tal Yacobia6fa5552024-05-05 16:57:38 +03005394}
Tal Yacobia6fa5552024-05-05 16:57:38 +03005395
Tal Yacobia6fa5552024-05-05 16:57:38 +03005396TEST(GetStateEffecterStates, testEncodeAndDecodeResponse)
5397{
5398 constexpr uint8_t comp_effecterCnt = 0x2;
5399 constexpr uint8_t completionCode = 0;
5400 std::array<uint8_t,
5401 hdrSize + PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES +
5402 PLDM_GET_EFFECTER_STATE_FIELD_SIZE * comp_effecterCnt>
5403 expectedResponseMsg{{0, PLDM_PLATFORM, PLDM_GET_STATE_EFFECTER_STATES,
5404 completionCode, comp_effecterCnt,
5405 EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING, 2, 2,
5406 EFFECTER_OPER_STATE_ENABLED_UPDATEPENDING, 2, 3}};
5407
5408 decltype(expectedResponseMsg) responseMsg{};
5409
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305410 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Tal Yacobia6fa5552024-05-05 16:57:38 +03005411 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
5412
5413 std::array<get_effecter_state_field, comp_effecterCnt> stateField{
5414 {{EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING, 2, 2},
5415 {EFFECTER_OPER_STATE_ENABLED_UPDATEPENDING, 2, 3}}};
5416
5417 struct pldm_get_state_effecter_states_resp resp_fields
5418 {
5419 PLDM_SUCCESS, comp_effecterCnt,
5420 {
5421 stateField[0], stateField[1]
5422 }
5423 };
5424
5425 auto rc = encode_get_state_effecter_states_resp(
5426 0, &resp_fields, response, responseMsg.size() - hdrSize);
5427
5428 EXPECT_EQ(rc, PLDM_SUCCESS);
5429 EXPECT_EQ(expectedResponseMsg, responseMsg);
5430
5431 struct pldm_get_state_effecter_states_resp ret_resp_fields;
5432
5433 rc = decode_get_state_effecter_states_resp(
5434 response, responseMsg.size() - hdrSize, &ret_resp_fields);
5435
5436 EXPECT_EQ(rc, PLDM_SUCCESS);
5437 EXPECT_EQ(completionCode, ret_resp_fields.completion_code);
5438 EXPECT_EQ(comp_effecterCnt, ret_resp_fields.comp_effecter_count);
5439 EXPECT_EQ(stateField[0].effecter_op_state,
5440 ret_resp_fields.field[0].effecter_op_state);
5441 EXPECT_EQ(stateField[0].pending_state,
5442 ret_resp_fields.field[0].pending_state);
5443 EXPECT_EQ(stateField[0].present_state,
5444 ret_resp_fields.field[0].present_state);
5445 EXPECT_EQ(stateField[1].effecter_op_state,
5446 ret_resp_fields.field[1].effecter_op_state);
5447 EXPECT_EQ(stateField[1].pending_state,
5448 ret_resp_fields.field[1].pending_state);
5449 EXPECT_EQ(stateField[1].present_state,
5450 ret_resp_fields.field[1].present_state);
5451
5452 // Test invalid length decode
5453
5454 rc = decode_get_state_effecter_states_resp(
5455 response,
5456 responseMsg.size() - hdrSize + PLDM_GET_EFFECTER_STATE_FIELD_SIZE,
5457 &ret_resp_fields);
5458
Tal Yacobif490a382024-05-31 09:57:36 +03005459 EXPECT_EQ(rc, -EBADMSG);
Tal Yacobia6fa5552024-05-05 16:57:38 +03005460}
Tal Yacobia6fa5552024-05-05 16:57:38 +03005461
Tal Yacobia6fa5552024-05-05 16:57:38 +03005462TEST(GetStateEffecterStates, testBadEncodeResponse)
5463{
5464 struct pldm_get_state_effecter_states_resp resp
5465 {
5466 PLDM_SUCCESS, 0,
5467 {
5468 }
5469 };
5470 auto rc = decode_get_state_effecter_states_resp(nullptr, 0, &resp);
5471
Tal Yacobif490a382024-05-31 09:57:36 +03005472 EXPECT_EQ(rc, -EINVAL);
Tal Yacobia6fa5552024-05-05 16:57:38 +03005473}
Tal Yacobia6fa5552024-05-05 16:57:38 +03005474
Tal Yacobia6fa5552024-05-05 16:57:38 +03005475TEST(GetStateEffecterStates, testBadDecodeResponse)
5476{
5477 std::array<uint8_t, hdrSize +
5478 PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES +
5479 PLDM_GET_EFFECTER_STATE_FIELD_SIZE * 2>
5480 responseMsg{};
5481
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305482 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Tal Yacobia6fa5552024-05-05 16:57:38 +03005483 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
5484
5485 auto rc = decode_get_state_effecter_states_resp(
5486 response, responseMsg.size() - hdrSize, nullptr);
5487
Tal Yacobif490a382024-05-31 09:57:36 +03005488 EXPECT_EQ(rc, -EINVAL);
Tal Yacobia6fa5552024-05-05 16:57:38 +03005489}
Thu Nguyendacfa352024-06-22 09:53:15 +00005490
5491[[maybe_unused]] static size_t str16len(char16_t* startptr)
5492{
5493 char16_t* endptr = startptr;
5494 while (*endptr)
5495 {
5496 endptr++;
5497 }
5498 return endptr - startptr;
5499}
5500
Thu Nguyendacfa352024-06-22 09:53:15 +00005501TEST(decodeEntityAuxNamePdrData, GoodTest)
5502{
5503 std::vector<uint8_t> pdr1{
5504 // Common PDR Header
5505 0x1, 0x0, 0x0, 0x0, // record handle
5506 0x1, // PDRHeaderVersion
5507 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
5508 0x1,
5509 0x0, // recordChangeNumber
5510 0x27,
5511 0, // dataLength
5512 /* Entity Auxiliary Names PDR Data*/
5513 3,
5514 0, // entityType system software
5515 0x1,
5516 0x0, // Entity instance number =1
5517 PLDM_PLATFORM_ENTITY_SYSTEM_CONTAINER_ID,
5518 0, // Overal system
5519 0, // shared Name Count one name only
5520 03, // nameStringCount
5521 0x65, 0x6e, 0x00, // Language Tag "en"
5522 0x00, 0x53, 0x00, 0x30, 0x00, 0x53, 0x00, 0x00, // Entity Name "S0S"
5523 0x66, 0x6e, 0x00, // Language Tag "en"
5524 0x00, 0x53, 0x00, 0x31, 0x00, 0x00, // Entity Name "S1"
5525 0x67, 0x6e, 0x00, // Language Tag "en"
5526 0x00, 0x52, 0x00, 0x52, 0x00, 0x33, 0x00, 0x00 // Entity Name "RR3"
5527 };
5528
5529 const char expectTag0[] = {0x65, 0x6e, 0x00};
5530 const char expectTag1[] = {0x66, 0x6e, 0x00};
5531 const char expectTag2[] = {0x67, 0x6e, 0x00};
5532 const char expectName0[] = {0x00, 0x53, 0x00, 0x30, 0x00, 0x53, 0x00, 0x00};
5533 const char expectName1[] = {0x00, 0x53, 0x00, 0x31, 0x00, 0x00};
5534 const char expectName2[] = {0x00, 0x52, 0x00, 0x52, 0x00, 0x33, 0x00, 0x00};
5535 auto names_offset = sizeof(struct pldm_pdr_hdr) +
5536 PLDM_PDR_ENTITY_AUXILIARY_NAME_PDR_MIN_LENGTH;
5537 auto names_size = pdr1.size() - names_offset;
5538 size_t length = 0;
5539
5540 size_t decodedPdrSize =
5541 sizeof(struct pldm_entity_auxiliary_names_pdr) + names_size;
5542 auto decodedPdr =
5543 (struct pldm_entity_auxiliary_names_pdr*)malloc(decodedPdrSize);
5544 EXPECT_NE(nullptr, decodedPdr);
5545
5546 auto rc = decode_entity_auxiliary_names_pdr(pdr1.data(), pdr1.size(),
5547 decodedPdr, decodedPdrSize);
5548
5549 EXPECT_EQ(0, rc);
5550 EXPECT_EQ(1, decodedPdr->hdr.record_handle);
5551 EXPECT_EQ(1, decodedPdr->hdr.version);
5552 EXPECT_EQ(PLDM_ENTITY_AUXILIARY_NAMES_PDR, decodedPdr->hdr.type);
5553 EXPECT_EQ(1, decodedPdr->hdr.record_change_num);
5554 EXPECT_EQ(pdr1.size() - sizeof(struct pldm_pdr_hdr),
5555 decodedPdr->hdr.length);
5556 EXPECT_EQ(3, decodedPdr->container.entity_type);
5557 EXPECT_EQ(1, decodedPdr->container.entity_instance_num);
5558 EXPECT_EQ(PLDM_PLATFORM_ENTITY_SYSTEM_CONTAINER_ID,
5559 decodedPdr->container.entity_container_id);
5560 EXPECT_EQ(0, decodedPdr->shared_name_count);
5561 EXPECT_EQ(3, decodedPdr->name_string_count);
5562
5563 decodedPdr->names = (struct pldm_entity_auxiliary_name*)calloc(
5564 decodedPdr->name_string_count,
5565 sizeof(struct pldm_entity_auxiliary_name));
5566 EXPECT_NE(nullptr, decodedPdr->names);
5567
5568 rc = decode_pldm_entity_auxiliary_names_pdr_index(decodedPdr);
5569 EXPECT_EQ(0, rc);
5570
5571 length = strlen(decodedPdr->names[0].tag);
5572 EXPECT_EQ(strlen(expectTag0), length);
5573 EXPECT_EQ(strncmp(expectTag0, decodedPdr->names[0].tag, length + 1), 0);
5574
5575 // NOLINTBEGIN(clang-analyzer-unix.Malloc)
5576 ASSERT_EQ(0,
5577 (uintptr_t)decodedPdr->names[0].name & (alignof(char16_t) - 1));
5578 // NOLINTEND(clang-analyzer-unix.Malloc)
5579 length = str16len((char16_t*)decodedPdr->names[0].name);
5580 EXPECT_EQ(str16len((char16_t*)expectName0), length);
5581 EXPECT_EQ(3, str16len((char16_t*)expectName0));
5582 EXPECT_EQ(memcmp(expectName0, decodedPdr->names[0].name,
5583 sizeof(char16_t) * (length + 1)),
5584 0);
5585
5586 length = strlen(decodedPdr->names[1].tag);
5587 EXPECT_EQ(strlen(expectTag1), length);
5588 EXPECT_EQ(strncmp(expectTag1, decodedPdr->names[1].tag, length + 1), 0);
5589
5590 // NOLINTBEGIN(clang-analyzer-unix.Malloc)
5591 ASSERT_EQ(0,
5592 (uintptr_t)decodedPdr->names[1].name & (alignof(char16_t) - 1));
5593 // NOLINTEND(clang-analyzer-unix.Malloc)
5594 length = str16len((char16_t*)decodedPdr->names[1].name);
5595 EXPECT_EQ(str16len((char16_t*)expectName1), length);
5596 EXPECT_EQ(2, str16len((char16_t*)expectName1));
5597 EXPECT_EQ(memcmp(expectName1, decodedPdr->names[1].name,
5598 sizeof(char16_t) * (length + 1)),
5599 0);
5600
5601 length = strlen(decodedPdr->names[2].tag);
5602 EXPECT_EQ(strlen(expectTag2), length);
5603 EXPECT_EQ(strncmp(expectTag2, decodedPdr->names[2].tag, length + 1), 0);
5604
5605 // NOLINTBEGIN(clang-analyzer-unix.Malloc)
5606 ASSERT_EQ(0,
5607 (uintptr_t)decodedPdr->names[2].name & (alignof(char16_t) - 1));
5608 // NOLINTEND(clang-analyzer-unix.Malloc)
5609 length = str16len((char16_t*)decodedPdr->names[2].name);
5610 EXPECT_EQ(str16len((char16_t*)expectName2), length);
5611 EXPECT_EQ(3, str16len((char16_t*)expectName2));
5612 EXPECT_EQ(memcmp(expectName2, decodedPdr->names[2].name,
5613 sizeof(char16_t) * (length + 1)),
5614 0);
5615
5616 free(decodedPdr->names);
5617 free(decodedPdr);
5618}
Thu Nguyendacfa352024-06-22 09:53:15 +00005619
Thu Nguyendacfa352024-06-22 09:53:15 +00005620TEST(decodeEntityAuxNamePdrData, BadTest)
5621{
5622 std::vector<uint8_t> pdr1{
5623 // Common PDR Header
5624 0x1, 0x0, 0x0, 0x0, // record handle
5625 0x1, // PDRHeaderVersion
5626 PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
5627 0x1,
5628 0x0, // recordChangeNumber
5629 0x25, // correct size is 0x27, input invalid size
5630 0, // dataLength
5631 /* Entity Auxiliary Names PDR Data*/
5632 3,
5633 0, // entityType system software
5634 0x1,
5635 0x0, // Entity instance number =1
5636 PLDM_PLATFORM_ENTITY_SYSTEM_CONTAINER_ID,
5637 0, // Overal system
5638 0, // shared Name Count one name only
5639 0, // Invalid nameStringCount
5640 0x65, 0x6e, 0x00, // Language Tag "en"
5641 0x00, 0x53, 0x00, 0x30, 0x00, 0x53, 0x00, 0x00, // Entity Name "S0S"
5642 0x66, 0x6e, 0x00, // Language Tag "en"
5643 0x00, 0x53, 0x00, 0x31, 0x00, 0x00, // Entity Name "S1"
5644 0x67, 0x6e, 0x00, // Language Tag "en"
5645 0x00, 0x52, 0x00, 0x52, 0x00, 0x33, 0x00, 0x00 // Entity Name "RR3"
5646 };
5647
5648 auto names_offset = sizeof(struct pldm_pdr_hdr) +
5649 PLDM_PDR_ENTITY_AUXILIARY_NAME_PDR_MIN_LENGTH;
5650 auto names_size = pdr1.size() - names_offset;
5651
5652 size_t decodedPdrSize =
5653 sizeof(struct pldm_entity_auxiliary_names_pdr) + names_size;
5654 auto decodedPdr =
5655 (struct pldm_entity_auxiliary_names_pdr*)malloc(decodedPdrSize);
5656
5657 auto rc = decode_entity_auxiliary_names_pdr(pdr1.data(), pdr1.size(),
5658 decodedPdr, decodedPdrSize);
5659
5660 EXPECT_EQ(-EBADMSG, rc);
5661 free(decodedPdr);
5662}
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005663
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005664TEST(PlatformEventMessage, testGoodCperEventDataDecodeRequest)
5665{
5666 constexpr const size_t eventDataSize = 4;
5667 constexpr const size_t eventSize =
5668 PLDM_PLATFORM_CPER_EVENT_MIN_LENGTH + eventDataSize;
5669 std::array<uint8_t, eventSize> eventData{
5670 0x1, // format version
5671 0x0, // format type
5672 0x4, 0x0, // event data length
5673 0x44, 0x33, 0x22, 0x11 // data
5674 };
5675
5676 uint8_t expectedFormatVersion = 1;
5677 uint8_t expectedFormatType = 0;
5678 uint16_t expectedEventDataLength = 4;
5679 uint8_t expectCperEventData[] = {0x44, 0x33, 0x22, 0x11};
5680
5681 size_t cperEventSize =
5682 sizeof(struct pldm_platform_cper_event) + eventDataSize;
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305683 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005684 auto cper_event = reinterpret_cast<struct pldm_platform_cper_event*>(
5685 malloc(cperEventSize));
5686
Thu Nguyen02903032024-09-03 06:39:50 +00005687 auto rc = decode_pldm_platform_cper_event(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305688 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005689 reinterpret_cast<const void*>(eventData.data()), eventData.size(),
5690 cper_event, cperEventSize);
5691
5692 EXPECT_EQ(rc, 0);
5693 EXPECT_EQ(cper_event->format_version, expectedFormatVersion);
5694 EXPECT_EQ(cper_event->format_type, expectedFormatType);
5695 EXPECT_EQ(cper_event->event_data_length, expectedEventDataLength);
5696
5697 auto cperEventData = pldm_platform_cper_event_event_data(cper_event);
5698 EXPECT_NE(cperEventData, nullptr);
5699 if (cperEventData)
5700 {
5701 EXPECT_EQ(0, memcmp(expectCperEventData, cperEventData,
5702 expectedEventDataLength));
5703 }
5704
5705 free(cper_event);
5706}
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005707
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005708TEST(PlatformEventMessage, testBadCperEventDataDecodeRequest)
5709{
5710
5711 constexpr const size_t eventDataSize = 4;
5712 constexpr const size_t eventSize =
5713 PLDM_PLATFORM_CPER_EVENT_MIN_LENGTH + eventDataSize;
5714 std::array<uint8_t, eventSize> eventData{
5715 0x1, // format version
5716 0x0, // format type
5717 0x4, 0x0, // event data length
5718 0x44, 0x33, 0x22, 0x11 // data
5719 };
5720
5721 size_t cperEventSize =
5722 sizeof(struct pldm_platform_cper_event) + eventDataSize;
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305723 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005724 auto cperEvent = reinterpret_cast<struct pldm_platform_cper_event*>(
5725 malloc(cperEventSize));
5726
Thu Nguyen02903032024-09-03 06:39:50 +00005727 auto rc = decode_pldm_platform_cper_event(NULL, eventData.size(), cperEvent,
5728 cperEventSize);
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005729 EXPECT_EQ(rc, -EINVAL);
5730
Thu Nguyen02903032024-09-03 06:39:50 +00005731 rc = decode_pldm_platform_cper_event(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305732 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005733 reinterpret_cast<const void*>(eventData.data()), eventData.size(), NULL,
5734 cperEventSize);
5735 EXPECT_EQ(rc, -EINVAL);
5736
Thu Nguyen02903032024-09-03 06:39:50 +00005737 rc = decode_pldm_platform_cper_event(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305738 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005739 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size() - 1,
5740 cperEvent, cperEventSize);
Andrew Jeffery0a1be3c2024-08-11 08:34:10 +00005741 EXPECT_EQ(rc, -EOVERFLOW);
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005742
Thu Nguyen02903032024-09-03 06:39:50 +00005743 rc = decode_pldm_platform_cper_event(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305744 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005745 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
5746 cperEvent, cperEventSize - 1);
5747 EXPECT_EQ(rc, -EOVERFLOW);
5748
Thu Nguyen02903032024-09-03 06:39:50 +00005749 rc = decode_pldm_platform_cper_event(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305750 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005751 reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
5752 cperEvent, cperEventSize + 1);
5753 EXPECT_EQ(rc, 0);
5754
5755 // Invalid CPER Event Format Type
5756 eventData[1] = 0x2;
Thu Nguyen02903032024-09-03 06:39:50 +00005757 rc = decode_pldm_platform_cper_event(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305758 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005759 reinterpret_cast<const void*>(eventData.data()), eventData.size(),
5760 cperEvent, cperEventSize);
5761
5762 EXPECT_EQ(rc, -EPROTO);
5763
5764 // Invalid cper event data size
5765 eventData[1] = 0x1;
5766 eventData[2] = 3;
Thu Nguyen02903032024-09-03 06:39:50 +00005767 rc = decode_pldm_platform_cper_event(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305768 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005769 reinterpret_cast<const void*>(eventData.data()), eventData.size(),
5770 cperEvent, cperEventSize);
5771
5772 EXPECT_EQ(rc, -EBADMSG);
5773
5774 eventData[2] = 5;
Thu Nguyen02903032024-09-03 06:39:50 +00005775 rc = decode_pldm_platform_cper_event(
Andrew Jefferyd0ba43a2024-09-09 15:50:17 +09305776 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
Thu Nguyena5d18dc2024-08-07 08:29:34 +00005777 reinterpret_cast<const void*>(eventData.data()), eventData.size(),
5778 cperEvent, cperEventSize);
5779
5780 EXPECT_EQ(rc, -EOVERFLOW);
5781
5782 free(cperEvent);
5783}