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