blob: 396e9d9fbeda7ed967dcf354c06c28b73ee65d0a [file] [log] [blame]
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05301#include <endian.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +09302#include <string.h>
3
4#include <array>
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05305#include <cstdint>
6#include <vector>
Andrew Jeffery9c766792022-08-10 23:12:49 +09307
8#include "libpldm/base.h"
9#include "libpldm/platform.h"
Manojkiran Eda9a8e4972022-11-28 16:38:21 +053010#include "pldm_types.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +093011
12#include <gtest/gtest.h>
13
14constexpr auto hdrSize = sizeof(pldm_msg_hdr);
15
16TEST(SetStateEffecterStates, testEncodeResponse)
17{
18 std::array<uint8_t,
19 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
20 responseMsg{};
21 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
22 uint8_t completionCode = 0;
23
24 auto rc = encode_set_state_effecter_states_resp(0, PLDM_SUCCESS, response);
25
26 EXPECT_EQ(rc, PLDM_SUCCESS);
27 EXPECT_EQ(completionCode, response->payload[0]);
28}
29
30TEST(SetStateEffecterStates, testEncodeRequest)
31{
32 std::array<uint8_t,
33 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES>
34 requestMsg{};
35 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
36
37 uint16_t effecterId = 0x0A;
38 uint8_t compEffecterCnt = 0x2;
39 std::array<set_effecter_state_field, 8> stateField{};
40 stateField[0] = {PLDM_REQUEST_SET, 2};
41 stateField[1] = {PLDM_REQUEST_SET, 3};
42
43 auto rc = encode_set_state_effecter_states_req(
44 0, effecterId, compEffecterCnt, stateField.data(), request);
45
46 EXPECT_EQ(rc, PLDM_SUCCESS);
47 EXPECT_EQ(effecterId, request->payload[0]);
48 EXPECT_EQ(compEffecterCnt, request->payload[sizeof(effecterId)]);
49 EXPECT_EQ(stateField[0].set_request,
50 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt)]);
51 EXPECT_EQ(stateField[0].effecter_state,
52 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
53 sizeof(stateField[0].set_request)]);
54 EXPECT_EQ(stateField[1].set_request,
55 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
56 sizeof(stateField[0])]);
57 EXPECT_EQ(stateField[1].effecter_state,
58 request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) +
59 sizeof(stateField[0]) +
60 sizeof(stateField[1].set_request)]);
61}
62
63TEST(SetStateEffecterStates, testGoodDecodeResponse)
64{
65 std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
66 responseMsg{};
67
68 uint8_t retcompletion_code = 0;
69
70 responseMsg[hdrSize] = PLDM_SUCCESS;
71
72 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
73
74 auto rc = decode_set_state_effecter_states_resp(
75 response, responseMsg.size() - hdrSize, &retcompletion_code);
76
77 EXPECT_EQ(rc, PLDM_SUCCESS);
78 EXPECT_EQ(PLDM_SUCCESS, retcompletion_code);
79}
80
81TEST(SetStateEffecterStates, testGoodDecodeRequest)
82{
83 std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES>
84 requestMsg{};
85
86 uint16_t effecterId = 0x32;
87 uint16_t effecterIdLE = htole16(effecterId);
88 uint8_t compEffecterCnt = 0x2;
89
90 std::array<set_effecter_state_field, 8> stateField{};
91 stateField[0] = {PLDM_REQUEST_SET, 3};
92 stateField[1] = {PLDM_REQUEST_SET, 4};
93
94 uint16_t retEffecterId = 0;
95 uint8_t retCompEffecterCnt = 0;
96
97 std::array<set_effecter_state_field, 8> retStateField{};
98
99 memcpy(requestMsg.data() + hdrSize, &effecterIdLE, sizeof(effecterIdLE));
100 memcpy(requestMsg.data() + sizeof(effecterIdLE) + hdrSize, &compEffecterCnt,
101 sizeof(compEffecterCnt));
102 memcpy(requestMsg.data() + sizeof(effecterIdLE) + sizeof(compEffecterCnt) +
103 hdrSize,
104 &stateField, sizeof(stateField));
105
106 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
107
108 auto rc = decode_set_state_effecter_states_req(
109 request, requestMsg.size() - hdrSize, &retEffecterId,
110 &retCompEffecterCnt, retStateField.data());
111
112 EXPECT_EQ(rc, PLDM_SUCCESS);
113 EXPECT_EQ(effecterId, retEffecterId);
114 EXPECT_EQ(retCompEffecterCnt, compEffecterCnt);
115 EXPECT_EQ(retStateField[0].set_request, stateField[0].set_request);
116 EXPECT_EQ(retStateField[0].effecter_state, stateField[0].effecter_state);
117 EXPECT_EQ(retStateField[1].set_request, stateField[1].set_request);
118 EXPECT_EQ(retStateField[1].effecter_state, stateField[1].effecter_state);
119}
120
121TEST(SetStateEffecterStates, testBadDecodeRequest)
122{
123 const struct pldm_msg* msg = NULL;
124
125 auto rc = decode_set_state_effecter_states_req(msg, sizeof(*msg), NULL,
126 NULL, NULL);
127
128 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
129}
130
131TEST(SetStateEffecterStates, testBadDecodeResponse)
132{
133 std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES>
134 responseMsg{};
135
136 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
137
138 auto rc = decode_set_state_effecter_states_resp(response,
139 responseMsg.size(), NULL);
140
141 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
142}
143
144TEST(GetPDR, testGoodEncodeResponse)
145{
146 uint8_t completionCode = 0;
147 uint32_t nextRecordHndl = 0x12;
148 uint32_t nextDataTransferHndl = 0x13;
149 uint8_t transferFlag = PLDM_END;
150 uint16_t respCnt = 0x5;
151 std::vector<uint8_t> recordData{1, 2, 3, 4, 5};
152 uint8_t transferCRC = 6;
153
154 // + size of record data and transfer CRC
155 std::vector<uint8_t> responseMsg(hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES +
156 recordData.size() + 1);
157 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
158
159 auto rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl,
160 nextDataTransferHndl, transferFlag, respCnt,
161 recordData.data(), transferCRC, response);
162
163 EXPECT_EQ(rc, PLDM_SUCCESS);
164 struct pldm_get_pdr_resp* resp =
165 reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload);
166
167 EXPECT_EQ(completionCode, resp->completion_code);
168 EXPECT_EQ(nextRecordHndl, le32toh(resp->next_record_handle));
169 EXPECT_EQ(nextDataTransferHndl, le32toh(resp->next_data_transfer_handle));
170 EXPECT_EQ(transferFlag, resp->transfer_flag);
171 EXPECT_EQ(respCnt, le16toh(resp->response_count));
172 EXPECT_EQ(0,
173 memcmp(recordData.data(), resp->record_data, recordData.size()));
174 EXPECT_EQ(*(response->payload + sizeof(pldm_get_pdr_resp) - 1 +
175 recordData.size()),
176 transferCRC);
177
178 transferFlag = PLDM_START_AND_END; // No CRC in this case
179 responseMsg.resize(responseMsg.size() - sizeof(transferCRC));
180 rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl,
181 nextDataTransferHndl, transferFlag, respCnt,
182 recordData.data(), transferCRC, response);
183 EXPECT_EQ(rc, PLDM_SUCCESS);
184}
185
186TEST(GetPDR, testBadEncodeResponse)
187{
188 uint32_t nextRecordHndl = 0x12;
189 uint32_t nextDataTransferHndl = 0x13;
190 uint8_t transferFlag = PLDM_START_AND_END;
191 uint16_t respCnt = 0x5;
192 std::vector<uint8_t> recordData{1, 2, 3, 4, 5};
193 uint8_t transferCRC = 0;
194
195 auto rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl,
196 nextDataTransferHndl, transferFlag, respCnt,
197 recordData.data(), transferCRC, nullptr);
198
199 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
200}
201
202TEST(GetPDR, testGoodDecodeRequest)
203{
204 std::array<uint8_t, hdrSize + PLDM_GET_PDR_REQ_BYTES> requestMsg{};
205
206 uint32_t recordHndl = 0x32;
207 uint32_t dataTransferHndl = 0x11;
208 uint8_t transferOpFlag = PLDM_GET_FIRSTPART;
209 uint16_t requestCnt = 0x5;
210 uint16_t recordChangeNum = 0x01;
211
212 uint32_t retRecordHndl = 0;
213 uint32_t retDataTransferHndl = 0;
214 uint8_t retTransferOpFlag = 0;
215 uint16_t retRequestCnt = 0;
216 uint16_t retRecordChangeNum = 0;
217
218 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
219 struct pldm_get_pdr_req* request =
220 reinterpret_cast<struct pldm_get_pdr_req*>(req->payload);
221
222 request->record_handle = htole32(recordHndl);
223 request->data_transfer_handle = htole32(dataTransferHndl);
224 request->transfer_op_flag = transferOpFlag;
225 request->request_count = htole16(requestCnt);
226 request->record_change_number = htole16(recordChangeNum);
227
228 auto rc = decode_get_pdr_req(
229 req, requestMsg.size() - hdrSize, &retRecordHndl, &retDataTransferHndl,
230 &retTransferOpFlag, &retRequestCnt, &retRecordChangeNum);
231
232 EXPECT_EQ(rc, PLDM_SUCCESS);
233 EXPECT_EQ(retRecordHndl, recordHndl);
234 EXPECT_EQ(retDataTransferHndl, dataTransferHndl);
235 EXPECT_EQ(retTransferOpFlag, transferOpFlag);
236 EXPECT_EQ(retRequestCnt, requestCnt);
237 EXPECT_EQ(retRecordChangeNum, recordChangeNum);
238}
239
240TEST(GetPDR, testBadDecodeRequest)
241{
242 std::array<uint8_t, PLDM_GET_PDR_REQ_BYTES> requestMsg{};
243 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
244
245 auto rc = decode_get_pdr_req(req, requestMsg.size(), NULL, NULL, NULL, NULL,
246 NULL);
247
248 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
249}
250
251TEST(GetPDR, testGoodEncodeRequest)
252{
253 uint32_t record_hndl = 0;
254 uint32_t data_transfer_hndl = 0;
255 uint8_t transfer_op_flag = PLDM_GET_FIRSTPART;
256 uint16_t request_cnt = 20;
257 uint16_t record_chg_num = 0;
258
259 std::vector<uint8_t> requestMsg(hdrSize + PLDM_GET_PDR_REQ_BYTES);
260 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
261
262 auto rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl,
263 transfer_op_flag, request_cnt, record_chg_num,
264 request, PLDM_GET_PDR_REQ_BYTES);
265 EXPECT_EQ(rc, PLDM_SUCCESS);
266 struct pldm_get_pdr_req* req =
267 reinterpret_cast<struct pldm_get_pdr_req*>(request->payload);
268 EXPECT_EQ(record_hndl, le32toh(req->record_handle));
269 EXPECT_EQ(data_transfer_hndl, le32toh(req->data_transfer_handle));
270 EXPECT_EQ(transfer_op_flag, req->transfer_op_flag);
271 EXPECT_EQ(request_cnt, le16toh(req->request_count));
272 EXPECT_EQ(record_chg_num, le16toh(req->record_change_number));
273}
274
275TEST(GetPDR, testBadEncodeRequest)
276{
277 uint32_t record_hndl = 0;
278 uint32_t data_transfer_hndl = 0;
279 uint8_t transfer_op_flag = PLDM_GET_FIRSTPART;
280 uint16_t request_cnt = 32;
281 uint16_t record_chg_num = 0;
282
283 std::vector<uint8_t> requestMsg(hdrSize + PLDM_GET_PDR_REQ_BYTES);
284 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
285
286 auto rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl,
287 transfer_op_flag, request_cnt, record_chg_num,
288 nullptr, PLDM_GET_PDR_REQ_BYTES);
289 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
290
291 rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl,
292 transfer_op_flag, request_cnt, record_chg_num,
293 request, PLDM_GET_PDR_REQ_BYTES + 1);
294 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
295}
296
297TEST(GetPDR, testGoodDecodeResponse)
298{
299 const char* recordData = "123456789";
300 uint8_t completionCode = PLDM_SUCCESS;
301 uint32_t nextRecordHndl = 0;
302 uint32_t nextDataTransferHndl = 0;
303 uint8_t transferFlag = PLDM_END;
304 constexpr uint16_t respCnt = 9;
305 uint8_t transferCRC = 96;
306 size_t recordDataLength = 32;
307 std::array<uint8_t, hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES + respCnt +
308 sizeof(transferCRC)>
309 responseMsg{};
310
311 uint8_t retCompletionCode = 0;
312 uint8_t retRecordData[32] = {0};
313 uint32_t retNextRecordHndl = 0;
314 uint32_t retNextDataTransferHndl = 0;
315 uint8_t retTransferFlag = 0;
316 uint16_t retRespCnt = 0;
317 uint8_t retTransferCRC = 0;
318
319 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
320 struct pldm_get_pdr_resp* resp =
321 reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload);
322 resp->completion_code = completionCode;
323 resp->next_record_handle = htole32(nextRecordHndl);
324 resp->next_data_transfer_handle = htole32(nextDataTransferHndl);
325 resp->transfer_flag = transferFlag;
326 resp->response_count = htole16(respCnt);
327 memcpy(resp->record_data, recordData, respCnt);
328 response->payload[PLDM_GET_PDR_MIN_RESP_BYTES + respCnt] = transferCRC;
329
330 auto rc = decode_get_pdr_resp(
331 response, responseMsg.size() - hdrSize, &retCompletionCode,
332 &retNextRecordHndl, &retNextDataTransferHndl, &retTransferFlag,
333 &retRespCnt, retRecordData, recordDataLength, &retTransferCRC);
334 EXPECT_EQ(rc, PLDM_SUCCESS);
335 EXPECT_EQ(retCompletionCode, completionCode);
336 EXPECT_EQ(retNextRecordHndl, nextRecordHndl);
337 EXPECT_EQ(retNextDataTransferHndl, nextDataTransferHndl);
338 EXPECT_EQ(retTransferFlag, transferFlag);
339 EXPECT_EQ(retRespCnt, respCnt);
340 EXPECT_EQ(retTransferCRC, transferCRC);
341 EXPECT_EQ(0, memcmp(recordData, resp->record_data, respCnt));
342}
343
344TEST(GetPDR, testBadDecodeResponse)
345{
346 const char* recordData = "123456789";
347 uint8_t completionCode = PLDM_SUCCESS;
348 uint32_t nextRecordHndl = 0;
349 uint32_t nextDataTransferHndl = 0;
350 uint8_t transferFlag = PLDM_END;
351 constexpr uint16_t respCnt = 9;
352 uint8_t transferCRC = 96;
353 size_t recordDataLength = 32;
354 std::array<uint8_t, hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES + respCnt +
355 sizeof(transferCRC)>
356 responseMsg{};
357
358 uint8_t retCompletionCode = 0;
359 uint8_t retRecordData[32] = {0};
360 uint32_t retNextRecordHndl = 0;
361 uint32_t retNextDataTransferHndl = 0;
362 uint8_t retTransferFlag = 0;
363 uint16_t retRespCnt = 0;
364 uint8_t retTransferCRC = 0;
365
366 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
367 struct pldm_get_pdr_resp* resp =
368 reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload);
369 resp->completion_code = completionCode;
370 resp->next_record_handle = htole32(nextRecordHndl);
371 resp->next_data_transfer_handle = htole32(nextDataTransferHndl);
372 resp->transfer_flag = transferFlag;
373 resp->response_count = htole16(respCnt);
374 memcpy(resp->record_data, recordData, respCnt);
375 response->payload[PLDM_GET_PDR_MIN_RESP_BYTES + respCnt] = transferCRC;
376
377 auto rc = decode_get_pdr_resp(response, responseMsg.size() - hdrSize, NULL,
378 NULL, NULL, NULL, NULL, NULL, 0, NULL);
379 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
380
381 rc = decode_get_pdr_resp(
382 response, responseMsg.size() - hdrSize - 1, &retCompletionCode,
383 &retNextRecordHndl, &retNextDataTransferHndl, &retTransferFlag,
384 &retRespCnt, retRecordData, recordDataLength, &retTransferCRC);
385 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
386}
387
388TEST(GetPDRRepositoryInfo, testGoodEncodeResponse)
389{
390 uint8_t completionCode = 0;
391 uint8_t repositoryState = PLDM_AVAILABLE;
392 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
393 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
394 uint32_t recordCount = 100;
395 uint32_t repositorySize = 100;
396 uint32_t largestRecordSize = UINT32_MAX;
397 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
398
399 std::vector<uint8_t> responseMsg(hdrSize +
400 PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES);
401 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
402
403 auto rc = encode_get_pdr_repository_info_resp(
404 0, PLDM_SUCCESS, repositoryState, updateTime, oemUpdateTime,
405 recordCount, repositorySize, largestRecordSize,
406 dataTransferHandleTimeout, response);
407
408 EXPECT_EQ(rc, PLDM_SUCCESS);
409 struct pldm_pdr_repository_info_resp* resp =
410 reinterpret_cast<struct pldm_pdr_repository_info_resp*>(
411 response->payload);
412
413 EXPECT_EQ(completionCode, resp->completion_code);
414 EXPECT_EQ(repositoryState, resp->repository_state);
415 EXPECT_EQ(0, memcmp(updateTime, resp->update_time, PLDM_TIMESTAMP104_SIZE));
416 EXPECT_EQ(0, memcmp(oemUpdateTime, resp->oem_update_time,
417 PLDM_TIMESTAMP104_SIZE));
418 EXPECT_EQ(recordCount, le32toh(resp->record_count));
419 EXPECT_EQ(repositorySize, le32toh(resp->repository_size));
420 EXPECT_EQ(largestRecordSize, le32toh(resp->largest_record_size));
421 EXPECT_EQ(dataTransferHandleTimeout, resp->data_transfer_handle_timeout);
422}
423
424TEST(GetPDRRepositoryInfo, testBadEncodeResponse)
425{
426 uint8_t repositoryState = PLDM_AVAILABLE;
427 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
428 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
429 uint32_t recordCount = 100;
430 uint32_t repositorySize = 100;
431 uint32_t largestRecordSize = UINT32_MAX;
432 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
433
434 auto rc = encode_get_pdr_repository_info_resp(
435 0, PLDM_SUCCESS, repositoryState, updateTime, oemUpdateTime,
436 recordCount, repositorySize, largestRecordSize,
437 dataTransferHandleTimeout, nullptr);
438 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
439}
440
Gilbert Chenb7c73e52022-11-10 11:29:52 +0800441TEST(GetPDRRepositoryInfo, testGoodDecodeResponse)
442{
443 uint8_t completionCode = PLDM_SUCCESS;
444 uint8_t repositoryState = PLDM_AVAILABLE;
445 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
446 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
447 uint32_t recordCount = 100;
448 uint32_t repositorySize = 100;
449 uint32_t largestRecordSize = UINT32_MAX;
450 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
451
452 std::array<uint8_t, hdrSize + PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES>
453 responseMsg{};
454 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
455 struct pldm_pdr_repository_info_resp* resp =
456 reinterpret_cast<struct pldm_pdr_repository_info_resp*>(
457 response->payload);
458 resp->completion_code = completionCode;
459 resp->repository_state = repositoryState;
460 memcpy(resp->update_time, updateTime, PLDM_TIMESTAMP104_SIZE);
461 memcpy(resp->oem_update_time, oemUpdateTime, PLDM_TIMESTAMP104_SIZE);
462 resp->record_count = htole32(recordCount);
463 resp->repository_size = htole32(repositorySize);
464 resp->largest_record_size = htole32(largestRecordSize);
465 resp->data_transfer_handle_timeout = dataTransferHandleTimeout;
466
467 uint8_t retCompletionCode = 0;
468 uint8_t retRepositoryState = 0;
469 uint8_t retUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
470 uint8_t retOemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
471 uint32_t retRecordCount = 0;
472 uint32_t retRepositorySize = 0;
473 uint32_t retLargestRecordSize = 0;
474 uint8_t retDataTransferHandleTimeout = 0;
475
476 auto rc = decode_get_pdr_repository_info_resp(
477 response, responseMsg.size() - hdrSize, &retCompletionCode,
478 &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount,
479 &retRepositorySize, &retLargestRecordSize,
480 &retDataTransferHandleTimeout);
481
482 EXPECT_EQ(rc, PLDM_SUCCESS);
483 EXPECT_EQ(completionCode, retCompletionCode);
484 EXPECT_EQ(repositoryState, retRepositoryState);
485 EXPECT_EQ(0, memcmp(updateTime, retUpdateTime, PLDM_TIMESTAMP104_SIZE));
486 EXPECT_EQ(0,
487 memcmp(oemUpdateTime, retOemUpdateTime, PLDM_TIMESTAMP104_SIZE));
488 EXPECT_EQ(recordCount, recordCount);
489 EXPECT_EQ(repositorySize, repositorySize);
490 EXPECT_EQ(largestRecordSize, largestRecordSize);
491 EXPECT_EQ(dataTransferHandleTimeout, dataTransferHandleTimeout);
492}
493
494TEST(GetPDRRepositoryInfo, testBadDecodeResponse)
495{
496 uint8_t completionCode = PLDM_SUCCESS;
497 uint8_t repositoryState = PLDM_AVAILABLE;
498 uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0};
499 uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
500 uint32_t recordCount = htole32(100);
501 uint32_t repositorySize = htole32(100);
502 uint32_t largestRecordSize = htole32(UINT32_MAX);
503 uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT;
504
505 std::array<uint8_t, hdrSize + PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES>
506 responseMsg{};
507 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
508 struct pldm_pdr_repository_info_resp* resp =
509 reinterpret_cast<struct pldm_pdr_repository_info_resp*>(
510 response->payload);
511 resp->completion_code = completionCode;
512 resp->repository_state = repositoryState;
513 memcpy(resp->update_time, updateTime, PLDM_TIMESTAMP104_SIZE);
514 memcpy(resp->oem_update_time, oemUpdateTime, PLDM_TIMESTAMP104_SIZE);
515 resp->record_count = recordCount;
516 resp->repository_size = repositorySize;
517 resp->largest_record_size = largestRecordSize;
518 resp->data_transfer_handle_timeout = dataTransferHandleTimeout;
519
520 uint8_t retCompletionCode = 0;
521 uint8_t retRepositoryState = 0;
522 uint8_t retUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
523 uint8_t retOemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0};
524 uint32_t retRecordCount = 0;
525 uint32_t retRepositorySize = 0;
526 uint32_t retLargestRecordSize = 0;
527 uint8_t retDataTransferHandleTimeout = 0;
528
529 auto rc = decode_get_pdr_repository_info_resp(
530 response, responseMsg.size() - hdrSize, NULL, NULL, NULL, NULL, NULL,
531 NULL, NULL, NULL);
532 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
533
534 rc = decode_get_pdr_repository_info_resp(
535 response, responseMsg.size() - hdrSize - 1, &retCompletionCode,
536 &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount,
537 &retRepositorySize, &retLargestRecordSize,
538 &retDataTransferHandleTimeout);
539 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
540
541 resp->repository_state = PLDM_FAILED + 1;
542 rc = decode_get_pdr_repository_info_resp(
543 response, responseMsg.size() - hdrSize, &retCompletionCode,
544 &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount,
545 &retRepositorySize, &retLargestRecordSize,
546 &retDataTransferHandleTimeout);
547 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
548}
549
Andrew Jeffery9c766792022-08-10 23:12:49 +0930550TEST(SetNumericEffecterValue, testGoodDecodeRequest)
551{
552 std::array<uint8_t,
553 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3>
554 requestMsg{};
555
556 uint16_t effecter_id = 32768;
557 uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT32;
558 uint32_t effecter_value = 123456789;
559
560 uint16_t reteffecter_id;
561 uint8_t reteffecter_data_size;
562 uint8_t reteffecter_value[4];
563
564 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
565 struct pldm_set_numeric_effecter_value_req* request =
566 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
567 req->payload);
568
569 request->effecter_id = htole16(effecter_id);
570 request->effecter_data_size = effecter_data_size;
571 uint32_t effecter_value_le = htole32(effecter_value);
572 memcpy(request->effecter_value, &effecter_value_le,
573 sizeof(effecter_value_le));
574
575 auto rc = decode_set_numeric_effecter_value_req(
576 req, requestMsg.size() - hdrSize, &reteffecter_id,
577 &reteffecter_data_size, reteffecter_value);
578
579 uint32_t value = *(reinterpret_cast<uint32_t*>(reteffecter_value));
580 EXPECT_EQ(rc, PLDM_SUCCESS);
581 EXPECT_EQ(reteffecter_id, effecter_id);
582 EXPECT_EQ(reteffecter_data_size, effecter_data_size);
583 EXPECT_EQ(value, effecter_value);
584}
585
586TEST(SetNumericEffecterValue, testBadDecodeRequest)
587{
588 std::array<uint8_t, hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES>
589 requestMsg{};
590
591 auto rc = decode_set_numeric_effecter_value_req(
592 NULL, requestMsg.size() - hdrSize, NULL, NULL, NULL);
593 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
594
595 uint16_t effecter_id = 0x10;
596 uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT8;
597 uint8_t effecter_value = 1;
598
599 uint16_t reteffecter_id;
600 uint8_t reteffecter_data_size;
601 uint8_t reteffecter_value[4];
602
603 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
604 struct pldm_set_numeric_effecter_value_req* request =
605 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
606 req->payload);
607
608 request->effecter_id = effecter_id;
609 request->effecter_data_size = effecter_data_size;
610 memcpy(request->effecter_value, &effecter_value, sizeof(effecter_value));
611
612 rc = decode_set_numeric_effecter_value_req(
613 req, requestMsg.size() - hdrSize - 1, &reteffecter_id,
614 &reteffecter_data_size, reinterpret_cast<uint8_t*>(&reteffecter_value));
615 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
616}
617
618TEST(SetNumericEffecterValue, testGoodEncodeRequest)
619{
620 uint16_t effecter_id = 0;
621 uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT16;
622 uint16_t effecter_value = 65534;
623
624 std::vector<uint8_t> requestMsg(
625 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1);
626 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
627
628 auto rc = encode_set_numeric_effecter_value_req(
629 0, effecter_id, effecter_data_size,
630 reinterpret_cast<uint8_t*>(&effecter_value), request,
631 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1);
632 EXPECT_EQ(rc, PLDM_SUCCESS);
633
634 struct pldm_set_numeric_effecter_value_req* req =
635 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
636 request->payload);
637 EXPECT_EQ(effecter_id, req->effecter_id);
638 EXPECT_EQ(effecter_data_size, req->effecter_data_size);
639 uint16_t* val = (uint16_t*)req->effecter_value;
640 *val = le16toh(*val);
641 EXPECT_EQ(effecter_value, *val);
642}
643
644TEST(SetNumericEffecterValue, testBadEncodeRequest)
645{
646 std::vector<uint8_t> requestMsg(
647 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
648 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
649
650 auto rc = encode_set_numeric_effecter_value_req(
651 0, 0, 0, NULL, NULL, PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
652 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
653
654 uint16_t effecter_value;
655 rc = encode_set_numeric_effecter_value_req(
656 0, 0, 6, reinterpret_cast<uint8_t*>(&effecter_value), request,
657 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
658 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
659}
660
661TEST(SetNumericEffecterValue, testGoodDecodeResponse)
662{
663 std::array<uint8_t, hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES>
664 responseMsg{};
665
666 uint8_t completion_code = 0xA0;
667
668 uint8_t retcompletion_code;
669
670 memcpy(responseMsg.data() + hdrSize, &completion_code,
671 sizeof(completion_code));
672
673 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
674
675 auto rc = decode_set_numeric_effecter_value_resp(
676 response, responseMsg.size() - hdrSize, &retcompletion_code);
677
678 EXPECT_EQ(rc, PLDM_SUCCESS);
679 EXPECT_EQ(completion_code, retcompletion_code);
680}
681
682TEST(SetNumericEffecterValue, testBadDecodeResponse)
683{
684 std::array<uint8_t, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES>
685 responseMsg{};
686
687 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
688
689 auto rc = decode_set_numeric_effecter_value_resp(response,
690 responseMsg.size(), NULL);
691
692 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
693}
694
695TEST(SetNumericEffecterValue, testGoodEncodeResponse)
696{
697 std::array<uint8_t, sizeof(pldm_msg_hdr) +
698 PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES>
699 responseMsg{};
700 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
701 uint8_t completionCode = 0;
702
703 auto rc = encode_set_numeric_effecter_value_resp(
704 0, PLDM_SUCCESS, response, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES);
705
706 EXPECT_EQ(rc, PLDM_SUCCESS);
707 EXPECT_EQ(completionCode, response->payload[0]);
708}
709
710TEST(SetNumericEffecterValue, testBadEncodeResponse)
711{
712 auto rc = encode_set_numeric_effecter_value_resp(
713 0, PLDM_SUCCESS, NULL, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES);
714 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
715}
716
717TEST(GetStateSensorReadings, testGoodEncodeResponse)
718{
719 std::array<uint8_t, hdrSize +
720 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
721 sizeof(get_sensor_state_field) * 2>
722 responseMsg{};
723
724 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
725 uint8_t completionCode = 0;
726 uint8_t comp_sensorCnt = 0x2;
727
728 std::array<get_sensor_state_field, 2> stateField{};
729 stateField[0] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_NORMAL,
730 PLDM_SENSOR_WARNING, PLDM_SENSOR_UNKNOWN};
731 stateField[1] = {PLDM_SENSOR_FAILED, PLDM_SENSOR_UPPERFATAL,
732 PLDM_SENSOR_UPPERCRITICAL, PLDM_SENSOR_FATAL};
733
734 auto rc = encode_get_state_sensor_readings_resp(
735 0, PLDM_SUCCESS, comp_sensorCnt, stateField.data(), response);
736
737 struct pldm_get_state_sensor_readings_resp* resp =
738 reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>(
739 response->payload);
740
741 EXPECT_EQ(rc, PLDM_SUCCESS);
742 EXPECT_EQ(completionCode, resp->completion_code);
743 EXPECT_EQ(comp_sensorCnt, resp->comp_sensor_count);
744 EXPECT_EQ(stateField[0].sensor_op_state, resp->field->sensor_op_state);
745 EXPECT_EQ(stateField[0].present_state, resp->field->present_state);
746 EXPECT_EQ(stateField[0].previous_state, resp->field->previous_state);
747 EXPECT_EQ(stateField[0].event_state, resp->field->event_state);
748 EXPECT_EQ(stateField[1].sensor_op_state, resp->field[1].sensor_op_state);
749 EXPECT_EQ(stateField[1].present_state, resp->field[1].present_state);
750 EXPECT_EQ(stateField[1].previous_state, resp->field[1].previous_state);
751 EXPECT_EQ(stateField[1].event_state, resp->field[1].event_state);
752}
753
754TEST(GetStateSensorReadings, testBadEncodeResponse)
755{
756 auto rc = encode_get_state_sensor_readings_resp(0, PLDM_SUCCESS, 0, nullptr,
757 nullptr);
758
759 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
760}
761
762TEST(GetStateSensorReadings, testGoodDecodeResponse)
763{
764 std::array<uint8_t, hdrSize +
765 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
766 sizeof(get_sensor_state_field) * 2>
767 responseMsg{};
768
769 uint8_t completionCode = 0;
770 uint8_t comp_sensorCnt = 2;
771
772 std::array<get_sensor_state_field, 2> stateField{};
773 stateField[0] = {PLDM_SENSOR_DISABLED, PLDM_SENSOR_UNKNOWN,
774 PLDM_SENSOR_UNKNOWN, PLDM_SENSOR_UNKNOWN};
775 stateField[1] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_LOWERFATAL,
776 PLDM_SENSOR_LOWERCRITICAL, PLDM_SENSOR_WARNING};
777
778 uint8_t retcompletion_code = 0;
779 uint8_t retcomp_sensorCnt = 0;
780 std::array<get_sensor_state_field, 2> retstateField{};
781
782 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
783 struct pldm_get_state_sensor_readings_resp* resp =
784 reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>(
785 response->payload);
786
787 resp->completion_code = completionCode;
788 resp->comp_sensor_count = comp_sensorCnt;
789 memcpy(resp->field, &stateField,
790 (sizeof(get_sensor_state_field) * comp_sensorCnt));
791
792 auto rc = decode_get_state_sensor_readings_resp(
793 response, responseMsg.size() - hdrSize, &retcompletion_code,
794 &retcomp_sensorCnt, retstateField.data());
795
796 EXPECT_EQ(rc, PLDM_SUCCESS);
797 EXPECT_EQ(completionCode, retcompletion_code);
798 EXPECT_EQ(comp_sensorCnt, retcomp_sensorCnt);
799 EXPECT_EQ(stateField[0].sensor_op_state, retstateField[0].sensor_op_state);
800 EXPECT_EQ(stateField[0].present_state, retstateField[0].present_state);
801 EXPECT_EQ(stateField[0].previous_state, retstateField[0].previous_state);
802 EXPECT_EQ(stateField[0].event_state, retstateField[0].event_state);
803 EXPECT_EQ(stateField[1].sensor_op_state, retstateField[1].sensor_op_state);
804 EXPECT_EQ(stateField[1].present_state, retstateField[1].present_state);
805 EXPECT_EQ(stateField[1].previous_state, retstateField[1].previous_state);
806 EXPECT_EQ(stateField[1].event_state, retstateField[1].event_state);
807}
808
809TEST(GetStateSensorReadings, testBadDecodeResponse)
810{
811 std::array<uint8_t, hdrSize +
812 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
813 sizeof(get_sensor_state_field) * 2>
814 responseMsg{};
815
816 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
817
818 auto rc = decode_get_state_sensor_readings_resp(
819 response, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr);
820
821 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
822
823 uint8_t completionCode = 0;
824 uint8_t comp_sensorCnt = 1;
825
826 std::array<get_sensor_state_field, 1> stateField{};
827 stateField[0] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_UPPERFATAL,
828 PLDM_SENSOR_UPPERCRITICAL, PLDM_SENSOR_WARNING};
829
830 uint8_t retcompletion_code = 0;
831 uint8_t retcomp_sensorCnt = 0;
832 std::array<get_sensor_state_field, 1> retstateField{};
833
834 struct pldm_get_state_sensor_readings_resp* resp =
835 reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>(
836 response->payload);
837
838 resp->completion_code = completionCode;
839 resp->comp_sensor_count = comp_sensorCnt;
840 memcpy(resp->field, &stateField,
841 (sizeof(get_sensor_state_field) * comp_sensorCnt));
842
843 rc = decode_get_state_sensor_readings_resp(
844 response, responseMsg.size() - hdrSize + 1, &retcompletion_code,
845 &retcomp_sensorCnt, retstateField.data());
846
847 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
848}
849
850TEST(GetStateSensorReadings, testGoodEncodeRequest)
851{
852 std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES>
853 requestMsg{};
854
855 uint16_t sensorId = 0xAB;
856 bitfield8_t sensorRearm;
857 sensorRearm.byte = 0x03;
858
859 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
860 auto rc = encode_get_state_sensor_readings_req(0, sensorId, sensorRearm, 0,
861 request);
862
863 struct pldm_get_state_sensor_readings_req* req =
864 reinterpret_cast<struct pldm_get_state_sensor_readings_req*>(
865 request->payload);
866
867 EXPECT_EQ(rc, PLDM_SUCCESS);
868 EXPECT_EQ(sensorId, le16toh(req->sensor_id));
869 EXPECT_EQ(sensorRearm.byte, req->sensor_rearm.byte);
870}
871
872TEST(GetStateSensorReadings, testBadEncodeRequest)
873{
874 bitfield8_t sensorRearm;
875 sensorRearm.byte = 0x0;
876
877 auto rc =
878 encode_get_state_sensor_readings_req(0, 0, sensorRearm, 0, nullptr);
879
880 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
881}
882
883TEST(GetStateSensorReadings, testGoodDecodeRequest)
884{
885 std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES>
886 requestMsg{};
887
888 uint16_t sensorId = 0xCD;
889 bitfield8_t sensorRearm;
890 sensorRearm.byte = 0x10;
891
892 uint16_t retsensorId;
893 bitfield8_t retsensorRearm;
894 uint8_t retreserved;
895
896 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
897
898 struct pldm_get_state_sensor_readings_req* req =
899 reinterpret_cast<struct pldm_get_state_sensor_readings_req*>(
900 request->payload);
901
902 req->sensor_id = htole16(sensorId);
903 req->sensor_rearm.byte = sensorRearm.byte;
904
905 auto rc = decode_get_state_sensor_readings_req(
906 request, requestMsg.size() - hdrSize, &retsensorId, &retsensorRearm,
907 &retreserved);
908
909 EXPECT_EQ(rc, PLDM_SUCCESS);
910 EXPECT_EQ(sensorId, retsensorId);
911 EXPECT_EQ(sensorRearm.byte, retsensorRearm.byte);
912 EXPECT_EQ(0, retreserved);
913}
914
915TEST(GetStateSensorReadings, testBadDecodeRequest)
916{
917 std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES>
918 requestMsg{};
919
920 auto rc = decode_get_state_sensor_readings_req(
921 nullptr, requestMsg.size() - hdrSize, nullptr, nullptr, nullptr);
922
923 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
924 uint16_t sensorId = 0x11;
925 bitfield8_t sensorRearm;
926 sensorRearm.byte = 0x04;
927
928 uint16_t retsensorId;
929 bitfield8_t retsensorRearm;
930 uint8_t retreserved;
931
932 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
933
934 struct pldm_get_state_sensor_readings_req* req =
935 reinterpret_cast<struct pldm_get_state_sensor_readings_req*>(
936 request->payload);
937
938 req->sensor_id = htole16(sensorId);
939 req->sensor_rearm.byte = sensorRearm.byte;
940
941 rc = decode_get_state_sensor_readings_req(
942 request, requestMsg.size() - hdrSize - 1, &retsensorId, &retsensorRearm,
943 &retreserved);
944
945 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
946}
947
Dung Caod6ae8982022-11-02 10:00:10 +0700948TEST(EventMessageBufferSize, testGoodEventMessageBufferSizeRequest)
949{
950 uint8_t eventBufferSize = 32;
951
952 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_REQ_BYTES>
953 requestMsg{};
954 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
955
956 auto rc = encode_event_message_buffer_size_req(0, eventBufferSize, request);
957
958 EXPECT_EQ(rc, PLDM_SUCCESS);
959}
960
961TEST(EventMessageBufferSize, testGoodEventMessageBufferSizeResponse)
962{
963 uint8_t completionCode = PLDM_SUCCESS;
964 uint16_t terminusMaxBufferSize = 256;
965
966 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES>
967 responseMsg{};
968
969 uint8_t retCompletionCode;
970 uint16_t retMaxBufferSize = 0;
971
972 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
973 struct pldm_event_message_buffer_size_resp* resp =
974 reinterpret_cast<struct pldm_event_message_buffer_size_resp*>(
975 response->payload);
976
977 resp->completion_code = completionCode;
978 resp->terminus_max_buffer_size = terminusMaxBufferSize;
979
980 auto rc = decode_event_message_buffer_size_resp(
981 response, responseMsg.size() - hdrSize, &retCompletionCode,
982 &retMaxBufferSize);
983
984 EXPECT_EQ(rc, PLDM_SUCCESS);
985 EXPECT_EQ(retCompletionCode, completionCode);
986 EXPECT_EQ(terminusMaxBufferSize, retMaxBufferSize);
987}
988
989TEST(EventMessageBufferSize, testBadEventMessageBufferSizeResponse)
990{
991 uint8_t completionCode = PLDM_SUCCESS;
992 uint16_t terminusMaxBufferSize = 256;
993
994 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES>
995 responseMsg{};
996
997 uint8_t retCompletionCode;
998 uint16_t retMaxBufferSize = 0;
999
1000 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1001 struct pldm_event_message_buffer_size_resp* resp =
1002 reinterpret_cast<struct pldm_event_message_buffer_size_resp*>(
1003 response->payload);
1004 resp->completion_code = completionCode;
1005 resp->terminus_max_buffer_size = terminusMaxBufferSize;
1006
1007 auto rc =
1008 decode_event_message_buffer_size_resp(response, 0, nullptr, nullptr);
1009 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1010
1011 rc = decode_event_message_buffer_size_resp(
1012 response, responseMsg.size(), &retCompletionCode, &retMaxBufferSize);
1013 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1014}
1015
Dung Cao1bf8c872022-11-29 05:32:58 +07001016TEST(PlatformEventMessageSupported, testGoodEncodeRequest)
1017{
1018 uint8_t formatVersion = 0x01;
1019
1020 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_REQ_BYTES>
1021 requestMsg{};
1022
1023 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1024
1025 auto rc = encode_event_message_supported_req(0, formatVersion, request);
1026
1027 struct pldm_event_message_supported_req* req =
1028 reinterpret_cast<struct pldm_event_message_supported_req*>(
1029 request->payload);
1030
1031 EXPECT_EQ(rc, PLDM_SUCCESS);
1032 EXPECT_EQ(formatVersion, req->format_version);
1033}
1034
1035TEST(PlatformEventMessageSupported, testBadEncodeRequest)
1036{
1037 uint8_t eventData = 34;
1038 uint8_t formatVersion = 0x0;
1039
1040 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_REQ_BYTES +
1041 sizeof(eventData)>
1042 requestMsg{};
1043 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1044
1045 auto rc = encode_event_message_supported_req(0, formatVersion, request);
1046 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1047
1048 rc = encode_event_message_supported_req(0, formatVersion, nullptr);
1049 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1050}
1051
1052TEST(PlatformEventMessageSupported, testGoodDecodeRespond)
1053{
1054 uint8_t completionCode = PLDM_SUCCESS;
1055 uint8_t synchConfiguration = PLDM_MESSAGE_TYPE_SYNCHRONOUS;
1056 bitfield8_t synchConfigSupported;
1057 synchConfigSupported.byte = 0xe;
1058 uint8_t numberEventClassReturned = 0x3;
1059 std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa};
1060 constexpr uint8_t eventClassCount = 3;
1061
1062 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES +
1063 eventClassCount>
1064 responseMsg{};
1065
1066 uint8_t retCompletionCode;
1067 uint8_t retSynchConfig = 0;
1068 uint8_t retNumberEventClass = 0;
1069 bitfield8_t retSynchConfigSupport;
1070 uint8_t retEventClass[eventClassCount] = {0};
1071
1072 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1073 struct pldm_event_message_supported_resp* resp =
1074 reinterpret_cast<struct pldm_event_message_supported_resp*>(
1075 response->payload);
1076
1077 resp->completion_code = completionCode;
1078 resp->synchrony_configuration = synchConfiguration;
1079 resp->synchrony_configuration_supported.byte = synchConfigSupported.byte;
1080 resp->number_event_class_returned = numberEventClassReturned;
1081 memcpy(resp->event_class, eventClass.data(), numberEventClassReturned);
1082
1083 auto rc = decode_event_message_supported_resp(
1084 response, responseMsg.size() - hdrSize, &retCompletionCode,
1085 &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass,
1086 retEventClass, eventClassCount);
1087
1088 EXPECT_EQ(rc, PLDM_SUCCESS);
1089 EXPECT_EQ(retCompletionCode, completionCode);
1090 EXPECT_EQ(retSynchConfig, synchConfiguration);
1091 EXPECT_EQ(retNumberEventClass, numberEventClassReturned);
1092 EXPECT_EQ(retSynchConfigSupport.byte, synchConfigSupported.byte);
1093 EXPECT_EQ(0, memcmp(eventClass.data(), resp->event_class,
1094 numberEventClassReturned));
1095}
1096
1097TEST(PlatformEventMessageSupported, testBadSynchConfiguration)
1098{
1099 uint8_t completionCode = PLDM_SUCCESS;
1100 uint8_t synchConfiguration = 0x4;
1101 bitfield8_t synchConfigSupported;
1102 synchConfigSupported.byte = 0xe;
1103 uint8_t numberEventClassReturned = 0x3;
1104 std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa};
1105 constexpr uint8_t eventClassCount = 3;
1106
1107 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES +
1108 eventClassCount>
1109 responseMsg{};
1110
1111 uint8_t retCompletionCode;
1112 uint8_t retSynchConfig = 0;
1113 uint8_t retNumberEventClass = 0;
1114 bitfield8_t retSynchConfigSupport;
1115 uint8_t retEventClass[eventClassCount] = {0};
1116
1117 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1118 struct pldm_event_message_supported_resp* resp =
1119 reinterpret_cast<struct pldm_event_message_supported_resp*>(
1120 response->payload);
1121
1122 resp->completion_code = completionCode;
1123 resp->synchrony_configuration = synchConfiguration;
1124 resp->synchrony_configuration_supported.byte = synchConfigSupported.byte;
1125 resp->number_event_class_returned = numberEventClassReturned;
1126 memcpy(resp->event_class, eventClass.data(), numberEventClassReturned);
1127
1128 auto rc = decode_event_message_supported_resp(
1129 response, responseMsg.size() - hdrSize, &retCompletionCode,
1130 &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass,
1131 retEventClass, eventClassCount);
1132
1133 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1134}
1135
1136TEST(PlatformEventMessageSupported, testBadDecodeRespond)
1137{
1138 uint8_t completionCode = PLDM_SUCCESS;
1139 uint8_t synchConfiguration = PLDM_MESSAGE_TYPE_SYNCHRONOUS;
1140 bitfield8_t synchConfigSupported;
1141 synchConfigSupported.byte = 0xe;
1142 uint8_t numberEventClassReturned = 0x3;
1143 std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa};
1144 constexpr uint8_t eventClassCount = 3;
1145
1146 std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES +
1147 eventClassCount>
1148 responseMsg{};
1149
1150 uint8_t retCompletionCode;
1151 uint8_t retSynchConfig = 0;
1152 uint8_t retNumberEventClass = 0;
1153 bitfield8_t retSynchConfigSupport;
1154 uint8_t retEventClass[eventClassCount] = {0};
1155
1156 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1157 struct pldm_event_message_supported_resp* resp =
1158 reinterpret_cast<struct pldm_event_message_supported_resp*>(
1159 response->payload);
1160 resp->completion_code = completionCode;
1161 resp->synchrony_configuration = synchConfiguration;
1162 resp->synchrony_configuration_supported.byte = synchConfigSupported.byte;
1163 resp->number_event_class_returned = numberEventClassReturned;
1164 memcpy(resp->event_class, eventClass.data(), numberEventClassReturned);
1165
1166 auto rc = decode_event_message_supported_resp(response, 0, nullptr, nullptr,
1167 nullptr, nullptr, nullptr, 0);
1168 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1169
1170 rc = decode_event_message_supported_resp(
1171 response, PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES - 1,
1172 &retCompletionCode, &retSynchConfig, &retSynchConfigSupport,
1173 &retNumberEventClass, retEventClass, eventClassCount);
1174 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1175
1176 rc = decode_event_message_supported_resp(
1177 response, responseMsg.size() - hdrSize, &retCompletionCode,
1178 &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass,
1179 retEventClass, 1);
1180 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1181}
1182
Andrew Jeffery9c766792022-08-10 23:12:49 +09301183TEST(PlatformEventMessage, testGoodStateSensorDecodeRequest)
1184{
1185 std::array<uint8_t,
1186 hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
1187 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES>
1188 requestMsg{};
1189
1190 uint8_t retFormatVersion = 0;
1191 uint8_t retTid = 0;
1192 uint8_t retEventClass = 0;
1193 size_t retEventDataOffset = 0;
1194
1195 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
1196 struct pldm_platform_event_message_req* request =
1197 reinterpret_cast<struct pldm_platform_event_message_req*>(req->payload);
1198
1199 uint8_t formatVersion = 0x01;
1200 uint8_t tid = 0x02;
1201 // Sensor Event
1202 uint8_t eventClass = 0x00;
1203
1204 request->format_version = formatVersion;
1205 request->tid = tid;
1206 request->event_class = eventClass;
1207 size_t eventDataOffset =
1208 sizeof(formatVersion) + sizeof(tid) + sizeof(eventClass);
1209
1210 auto rc = decode_platform_event_message_req(
1211 req, requestMsg.size() - hdrSize, &retFormatVersion, &retTid,
1212 &retEventClass, &retEventDataOffset);
1213
1214 EXPECT_EQ(rc, PLDM_SUCCESS);
1215 EXPECT_EQ(retFormatVersion, formatVersion);
1216 EXPECT_EQ(retTid, tid);
1217 EXPECT_EQ(retEventClass, eventClass);
1218 EXPECT_EQ(retEventDataOffset, eventDataOffset);
1219}
1220
1221TEST(PlatformEventMessage, testBadDecodeRequest)
1222{
1223 const struct pldm_msg* msg = NULL;
1224 std::array<uint8_t,
1225 hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
1226 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES - 1>
1227 requestMsg{};
1228 auto req = reinterpret_cast<pldm_msg*>(requestMsg.data());
1229 uint8_t retFormatVersion;
1230 uint8_t retTid = 0;
1231 uint8_t retEventClass = 0;
1232 size_t retEventDataOffset;
1233
1234 auto rc = decode_platform_event_message_req(msg, sizeof(*msg), NULL, NULL,
1235 NULL, NULL);
1236 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1237
1238 rc = decode_platform_event_message_req(
1239 req,
1240 requestMsg.size() - hdrSize -
1241 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES,
1242 &retFormatVersion, &retTid, &retEventClass, &retEventDataOffset);
1243 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1244}
1245
1246TEST(PlatformEventMessage, testGoodEncodeResponse)
1247{
1248 std::array<uint8_t,
1249 hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
1250 PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES - 1>
1251 responseMsg{};
1252 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1253 uint8_t completionCode = 0;
1254 uint8_t instanceId = 0x01;
1255 uint8_t platformEventStatus = 0x01;
1256
1257 auto rc = encode_platform_event_message_resp(instanceId, PLDM_SUCCESS,
1258 platformEventStatus, response);
1259
1260 EXPECT_EQ(rc, PLDM_SUCCESS);
1261 EXPECT_EQ(completionCode, response->payload[0]);
1262 EXPECT_EQ(platformEventStatus, response->payload[1]);
1263}
1264
1265TEST(PlatformEventMessage, testBadEncodeResponse)
1266{
1267 auto rc = encode_platform_event_message_resp(0, PLDM_SUCCESS, 1, NULL);
1268 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1269}
1270
1271TEST(PlatformEventMessage, testGoodEncodeRequest)
1272{
1273 uint8_t formatVersion = 0x01;
1274 uint8_t Tid = 0x03;
1275 uint8_t eventClass = 0x00;
1276 uint8_t eventData = 34;
1277
1278 std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
1279 sizeof(eventData)>
1280 requestMsg{};
1281
1282 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1283 auto rc = encode_platform_event_message_req(
1284 0, formatVersion, Tid, eventClass,
1285 reinterpret_cast<uint8_t*>(&eventData), sizeof(eventData), request,
1286 sizeof(eventData) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES);
1287
1288 struct pldm_platform_event_message_req* req =
1289 reinterpret_cast<struct pldm_platform_event_message_req*>(
1290 request->payload);
1291
1292 EXPECT_EQ(rc, PLDM_SUCCESS);
1293 EXPECT_EQ(formatVersion, req->format_version);
1294 EXPECT_EQ(Tid, req->tid);
1295 EXPECT_EQ(eventClass, req->event_class);
1296 EXPECT_EQ(0, memcmp(&eventData, req->event_data, sizeof(eventData)));
1297}
1298
1299TEST(PlatformEventMessage, testBadEncodeRequest)
1300{
1301 uint8_t Tid = 0x03;
1302 uint8_t eventClass = 0x00;
1303 uint8_t eventData = 34;
1304 size_t sz_eventData = sizeof(eventData);
1305 size_t payloadLen =
1306 sz_eventData + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES;
1307 uint8_t formatVersion = 0x01;
1308
1309 std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
1310 sizeof(eventData)>
1311 requestMsg{};
1312 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1313
1314 auto rc = encode_platform_event_message_req(
1315 0, formatVersion, Tid, eventClass,
1316 reinterpret_cast<uint8_t*>(&eventData), sz_eventData, nullptr,
1317 payloadLen);
1318 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1319 rc = encode_platform_event_message_req(
1320 0, 0, Tid, eventClass, reinterpret_cast<uint8_t*>(&eventData),
1321 sz_eventData, request, payloadLen);
1322 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1323 rc = encode_platform_event_message_req(0, formatVersion, Tid, eventClass,
1324 nullptr, 0, request, payloadLen);
1325 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1326 rc = encode_platform_event_message_req(
1327 0, formatVersion, Tid, eventClass,
1328 reinterpret_cast<uint8_t*>(&eventData), sz_eventData, request, 0);
1329 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1330}
1331
1332TEST(PlatformEventMessage, testGoodDecodeResponse)
1333{
1334 std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES>
1335 responseMsg{};
1336
1337 uint8_t completionCode = PLDM_SUCCESS;
1338 uint8_t platformEventStatus = 0x01;
1339
1340 uint8_t retcompletionCode;
1341 uint8_t retplatformEventStatus;
1342
1343 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1344 struct pldm_platform_event_message_resp* resp =
1345 reinterpret_cast<struct pldm_platform_event_message_resp*>(
1346 response->payload);
1347
1348 resp->completion_code = completionCode;
1349 resp->platform_event_status = platformEventStatus;
1350
1351 auto rc = decode_platform_event_message_resp(
1352 response, responseMsg.size() - hdrSize, &retcompletionCode,
1353 &retplatformEventStatus);
1354
1355 EXPECT_EQ(rc, PLDM_SUCCESS);
1356 EXPECT_EQ(completionCode, retcompletionCode);
1357 EXPECT_EQ(platformEventStatus, retplatformEventStatus);
1358}
1359
1360TEST(PlatformEventMessage, testBadDecodeResponse)
1361{
1362 std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES>
1363 responseMsg{};
1364
1365 uint8_t completionCode = PLDM_SUCCESS;
1366 uint8_t platformEventStatus = 0x01;
1367
1368 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1369 struct pldm_platform_event_message_resp* resp =
1370 reinterpret_cast<struct pldm_platform_event_message_resp*>(
1371 response->payload);
1372 resp->completion_code = completionCode;
1373 resp->platform_event_status = platformEventStatus;
1374
1375 auto rc = decode_platform_event_message_resp(
1376 nullptr, responseMsg.size() - hdrSize, nullptr, nullptr);
1377
1378 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1379
1380 rc = decode_platform_event_message_resp(
1381 response, responseMsg.size() - hdrSize - 1, &completionCode,
1382 &platformEventStatus);
1383
1384 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1385}
1386
1387TEST(PlatformEventMessage, testGoodSensorEventDataDecodeRequest)
1388{
1389 std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH +
1390 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES>
1391 eventDataArr{};
1392 uint16_t sensorId = 0x1234;
1393 uint8_t sensorEventClassType = PLDM_SENSOR_OP_STATE;
1394
1395 struct pldm_sensor_event_data* eventData =
1396 (struct pldm_sensor_event_data*)eventDataArr.data();
1397 eventData->sensor_id = sensorId;
1398 eventData->sensor_event_class_type = sensorEventClassType;
1399
1400 size_t retSensorOpDataOffset;
1401 uint16_t retSensorId = 0;
1402 uint8_t retSensorEventClassType;
1403 size_t sensorOpDataOffset = sizeof(sensorId) + sizeof(sensorEventClassType);
1404 auto rc = decode_sensor_event_data(
1405 reinterpret_cast<uint8_t*>(eventData), eventDataArr.size(),
1406 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
1407 EXPECT_EQ(rc, PLDM_SUCCESS);
1408 EXPECT_EQ(retSensorId, sensorId);
1409 EXPECT_EQ(retSensorEventClassType, sensorEventClassType);
1410 EXPECT_EQ(retSensorOpDataOffset, sensorOpDataOffset);
1411}
1412
1413TEST(PlatformEventMessage, testBadSensorEventDataDecodeRequest)
1414{
1415
1416 std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH +
1417 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES>
1418 eventDataArr{};
1419
1420 struct pldm_sensor_event_data* eventData =
1421 (struct pldm_sensor_event_data*)eventDataArr.data();
1422
1423 size_t retSensorOpDataOffset;
1424 uint16_t retSensorId = 0;
1425 uint8_t retSensorEventClassType;
1426 auto rc = decode_sensor_event_data(NULL, eventDataArr.size(), &retSensorId,
1427 &retSensorEventClassType,
1428 &retSensorOpDataOffset);
1429 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1430
1431 rc = decode_sensor_event_data(
1432 reinterpret_cast<uint8_t*>(eventDataArr.data()),
1433 eventDataArr.size() -
1434 PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH,
1435 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
1436 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1437
1438 eventData->sensor_event_class_type = PLDM_SENSOR_OP_STATE;
1439
1440 rc = decode_sensor_event_data(
1441 reinterpret_cast<uint8_t*>(eventDataArr.data()), eventDataArr.size(),
1442 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
1443 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1444
1445 eventData->sensor_event_class_type = PLDM_STATE_SENSOR_STATE;
1446 rc = decode_sensor_event_data(
1447 reinterpret_cast<uint8_t*>(eventDataArr.data()), eventDataArr.size(),
1448 &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset);
1449 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1450
1451 eventData->sensor_event_class_type = PLDM_NUMERIC_SENSOR_STATE;
1452 rc = decode_sensor_event_data(
1453 reinterpret_cast<uint8_t*>(eventDataArr.data()),
1454 eventDataArr.size() + 1, &retSensorId, &retSensorEventClassType,
1455 &retSensorOpDataOffset);
1456 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1457}
1458
1459TEST(PlatformEventMessage, testGoodSensorOpEventDataDecodeRequest)
1460{
1461 std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH>
1462 eventDataArr{};
1463
1464 struct pldm_sensor_event_sensor_op_state* sensorData =
1465 (struct pldm_sensor_event_sensor_op_state*)eventDataArr.data();
1466 uint8_t presentState = PLDM_SENSOR_ENABLED;
1467 uint8_t previousState = PLDM_SENSOR_INITIALIZING;
1468 sensorData->present_op_state = presentState;
1469 sensorData->previous_op_state = previousState;
1470
1471 uint8_t retPresentState;
1472 uint8_t retPreviousState;
1473 auto rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData),
1474 eventDataArr.size(), &retPresentState,
1475 &retPreviousState);
1476 EXPECT_EQ(rc, PLDM_SUCCESS);
1477 EXPECT_EQ(retPresentState, presentState);
1478 EXPECT_EQ(retPreviousState, previousState);
1479}
1480
1481TEST(PlatformEventMessage, testBadSensorOpEventDataDecodeRequest)
1482{
1483 uint8_t presentOpState;
1484 uint8_t previousOpState;
1485 size_t sensorDataLength = PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH;
1486 auto rc = decode_sensor_op_data(NULL, sensorDataLength, &presentOpState,
1487 &previousOpState);
1488 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1489
1490 std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH>
1491 sensorData{};
1492 rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData.data()),
1493 sensorDataLength + 1, &presentOpState,
1494 &previousOpState);
1495 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1496
1497 rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData.data()),
1498 sensorDataLength, nullptr, &previousOpState);
1499 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1500}
1501
1502TEST(PlatformEventMessage, testGoodSensorStateEventDataDecodeRequest)
1503{
1504 std::array<uint8_t, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH>
1505 eventDataArr{};
1506
1507 struct pldm_sensor_event_state_sensor_state* sensorData =
1508 (struct pldm_sensor_event_state_sensor_state*)eventDataArr.data();
1509 uint8_t sensorOffset = 0x02;
1510 uint8_t eventState = PLDM_SENSOR_SHUTTINGDOWN;
1511 uint8_t previousEventState = PLDM_SENSOR_INTEST;
1512 sensorData->sensor_offset = sensorOffset;
1513 sensorData->event_state = eventState;
1514 sensorData->previous_event_state = previousEventState;
1515
1516 uint8_t retSensorOffset;
1517 uint8_t retEventState;
1518 uint8_t retPreviousState;
1519 auto rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData),
1520 eventDataArr.size(), &retSensorOffset,
1521 &retEventState, &retPreviousState);
1522 EXPECT_EQ(rc, PLDM_SUCCESS);
1523 EXPECT_EQ(retSensorOffset, sensorOffset);
1524 EXPECT_EQ(retEventState, eventState);
1525 EXPECT_EQ(retPreviousState, previousEventState);
1526}
1527
1528TEST(PlatformEventMessage, testBadStateSensorEventDataDecodeRequest)
1529{
1530 uint8_t sensorOffset;
1531 uint8_t eventState;
1532 uint8_t previousEventState;
1533 size_t sensorDataLength = PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH;
1534 auto rc = decode_state_sensor_data(NULL, sensorDataLength, &sensorOffset,
1535 &eventState, &previousEventState);
1536 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1537
1538 std::array<uint8_t, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH>
1539 sensorData{};
1540 rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData.data()),
1541 sensorDataLength - 1, &sensorOffset,
1542 &eventState, &previousEventState);
1543 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1544
1545 rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData.data()),
1546 sensorDataLength, &sensorOffset, nullptr,
1547 &previousEventState);
1548 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1549}
1550
1551TEST(PlatformEventMessage, testGoodNumericSensorEventDataDecodeRequest)
1552{
1553 std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH>
1554 eventDataArr{};
1555 struct pldm_sensor_event_numeric_sensor_state* sensorData =
1556 (struct pldm_sensor_event_numeric_sensor_state*)eventDataArr.data();
1557
1558 size_t sensorDataLength =
1559 PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_32BIT_DATA_LENGTH;
1560 uint8_t eventState = PLDM_SENSOR_SHUTTINGDOWN;
1561 uint8_t previousEventState = PLDM_SENSOR_INTEST;
1562 uint8_t sensorDataSize = PLDM_SENSOR_DATA_SIZE_UINT32;
1563 uint32_t presentReading = 305441741;
1564 sensorData->event_state = eventState;
1565 sensorData->previous_event_state = previousEventState;
1566 sensorData->sensor_data_size = sensorDataSize;
1567 sensorData->present_reading[3] =
1568 static_cast<uint8_t>(htole32(presentReading) & (0x000000ff));
1569 sensorData->present_reading[2] =
1570 static_cast<uint8_t>((htole32(presentReading) & (0x0000ff00)) >> 8);
1571 sensorData->present_reading[1] =
1572 static_cast<uint8_t>((htole32(presentReading) & (0x00ff0000)) >> 16);
1573 sensorData->present_reading[0] =
1574 static_cast<uint8_t>((htole32(presentReading) & (0xff000000)) >> 24);
1575
1576 uint8_t retEventState;
1577 uint8_t retPreviousEventState;
1578 uint8_t retSensorDataSize;
1579 uint32_t retPresentReading;
1580
1581 auto rc = decode_numeric_sensor_data(
1582 reinterpret_cast<uint8_t*>(sensorData), sensorDataLength,
1583 &retEventState, &retPreviousEventState, &retSensorDataSize,
1584 &retPresentReading);
1585 EXPECT_EQ(rc, PLDM_SUCCESS);
1586 EXPECT_EQ(retEventState, eventState);
1587 EXPECT_EQ(retPreviousEventState, previousEventState);
1588 EXPECT_EQ(retSensorDataSize, sensorDataSize);
1589 EXPECT_EQ(retPresentReading, presentReading);
1590
1591 int16_t presentReadingNew = -31432;
1592 sensorData->present_reading[1] =
1593 static_cast<uint8_t>(htole16(presentReadingNew) & (0x000000ff));
1594 sensorData->present_reading[0] =
1595 static_cast<uint8_t>((htole16(presentReadingNew) & (0x0000ff00)) >> 8);
1596 sensorDataSize = PLDM_SENSOR_DATA_SIZE_SINT16;
1597 sensorData->sensor_data_size = sensorDataSize;
1598 sensorDataLength = PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_16BIT_DATA_LENGTH;
1599
1600 rc = decode_numeric_sensor_data(reinterpret_cast<uint8_t*>(sensorData),
1601 sensorDataLength, &retEventState,
1602 &retPreviousEventState, &retSensorDataSize,
1603 &retPresentReading);
1604 EXPECT_EQ(rc, PLDM_SUCCESS);
1605 EXPECT_EQ(retEventState, eventState);
1606 EXPECT_EQ(retPreviousEventState, previousEventState);
1607 EXPECT_EQ(retSensorDataSize, sensorDataSize);
1608 EXPECT_EQ(static_cast<int16_t>(retPresentReading), presentReadingNew);
1609}
1610
1611TEST(PlatformEventMessage, testBadNumericSensorEventDataDecodeRequest)
1612{
1613 uint8_t eventState;
1614 uint8_t previousEventState;
1615 uint8_t sensorDataSize;
1616 uint32_t presentReading;
1617 size_t sensorDataLength =
1618 PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH;
1619 auto rc = decode_numeric_sensor_data(NULL, sensorDataLength, &eventState,
1620 &previousEventState, &sensorDataSize,
1621 &presentReading);
1622 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1623
1624 std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH>
1625 sensorData{};
1626 rc = decode_numeric_sensor_data(
1627 reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength - 1,
1628 &eventState, &previousEventState, &sensorDataSize, &presentReading);
1629 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1630
1631 struct pldm_sensor_event_numeric_sensor_state* numericSensorData =
1632 (struct pldm_sensor_event_numeric_sensor_state*)sensorData.data();
1633 numericSensorData->sensor_data_size = PLDM_SENSOR_DATA_SIZE_UINT8;
1634 rc = decode_numeric_sensor_data(
1635 reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength,
1636 &eventState, &previousEventState, &sensorDataSize, &presentReading);
1637 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1638
1639 numericSensorData->sensor_data_size = PLDM_SENSOR_DATA_SIZE_UINT16;
1640 rc = decode_numeric_sensor_data(
1641 reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength,
1642 &eventState, &previousEventState, &sensorDataSize, &presentReading);
1643 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1644
1645 numericSensorData->sensor_data_size = PLDM_SENSOR_DATA_SIZE_UINT32;
1646 rc = decode_numeric_sensor_data(
1647 reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength - 1,
1648 &eventState, &previousEventState, &sensorDataSize, &presentReading);
1649 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1650}
1651
1652TEST(GetNumericEffecterValue, testGoodEncodeRequest)
1653{
1654 std::vector<uint8_t> requestMsg(hdrSize +
1655 PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES);
1656
1657 uint16_t effecter_id = 0xAB01;
1658
1659 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1660
1661 auto rc = encode_get_numeric_effecter_value_req(0, effecter_id, request);
1662
1663 struct pldm_get_numeric_effecter_value_req* req =
1664 reinterpret_cast<struct pldm_get_numeric_effecter_value_req*>(
1665 request->payload);
1666
1667 EXPECT_EQ(rc, PLDM_SUCCESS);
1668 EXPECT_EQ(effecter_id, le16toh(req->effecter_id));
1669}
1670
1671TEST(GetNumericEffecterValue, testBadEncodeRequest)
1672{
1673 std::vector<uint8_t> requestMsg(
1674 hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES);
1675
1676 auto rc = encode_get_numeric_effecter_value_req(0, 0, nullptr);
1677 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1678}
1679
1680TEST(GetNumericEffecterValue, testGoodDecodeRequest)
1681{
1682 std::array<uint8_t, hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES>
1683 requestMsg{};
1684
1685 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1686 struct pldm_get_numeric_effecter_value_req* req =
1687 reinterpret_cast<struct pldm_get_numeric_effecter_value_req*>(
1688 request->payload);
1689
1690 uint16_t effecter_id = 0x12AB;
1691 req->effecter_id = htole16(effecter_id);
1692
1693 uint16_t reteffecter_id;
1694
1695 auto rc = decode_get_numeric_effecter_value_req(
1696 request, requestMsg.size() - hdrSize, &reteffecter_id);
1697
1698 EXPECT_EQ(rc, PLDM_SUCCESS);
1699 EXPECT_EQ(effecter_id, reteffecter_id);
1700}
1701
1702TEST(GetNumericEffecterValue, testBadDecodeRequest)
1703{
1704 std::array<uint8_t, hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES>
1705 requestMsg{};
1706
1707 auto rc = decode_get_numeric_effecter_value_req(
1708 nullptr, requestMsg.size() - hdrSize, nullptr);
1709
1710 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1711
1712 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1713 struct pldm_set_numeric_effecter_value_req* req =
1714 reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>(
1715 request->payload);
1716
1717 uint16_t effecter_id = 0x1A;
1718 req->effecter_id = htole16(effecter_id);
1719 uint16_t reteffecter_id;
1720
1721 rc = decode_get_numeric_effecter_value_req(
1722 request, requestMsg.size() - hdrSize - 1, &reteffecter_id);
1723
1724 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1725}
1726
1727TEST(GetNumericEffecterValue, testGoodEncodeResponse)
1728{
1729 uint8_t completionCode = 0;
1730 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT32;
1731 uint8_t effecter_operState = EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING;
1732 uint32_t pendingValue = 0x12345678;
1733 uint32_t presentValue = 0xABCDEF11;
1734
1735 std::array<uint8_t,
1736 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6>
1737 responseMsg{};
1738 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1739
1740 auto rc = encode_get_numeric_effecter_value_resp(
1741 0, completionCode, effecter_dataSize, effecter_operState,
1742 reinterpret_cast<uint8_t*>(&pendingValue),
1743 reinterpret_cast<uint8_t*>(&presentValue), response,
1744 responseMsg.size() - hdrSize);
1745
1746 struct pldm_get_numeric_effecter_value_resp* resp =
1747 reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>(
1748 response->payload);
1749
1750 uint32_t* val_pending = (uint32_t*)(&resp->pending_and_present_values[0]);
1751 *val_pending = le32toh(*val_pending);
1752 uint32_t* val_present = (uint32_t*)(&resp->pending_and_present_values[4]);
1753 *val_present = le32toh(*val_present);
1754
1755 EXPECT_EQ(rc, PLDM_SUCCESS);
1756 EXPECT_EQ(effecter_dataSize, resp->effecter_data_size);
1757 EXPECT_EQ(effecter_operState, resp->effecter_oper_state);
1758 EXPECT_EQ(pendingValue, *val_pending);
1759 EXPECT_EQ(presentValue, *val_present);
1760}
1761
1762TEST(GetNumericEffecterValue, testBadEncodeResponse)
1763{
1764 std::array<uint8_t,
1765 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2>
1766 responseMsg{};
1767 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1768
1769 uint8_t pendingValue = 0x01;
1770 uint8_t presentValue = 0x02;
1771
1772 auto rc = encode_get_numeric_effecter_value_resp(
1773 0, PLDM_SUCCESS, 0, 0, nullptr, nullptr, nullptr,
1774 responseMsg.size() - hdrSize);
1775 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1776
1777 rc = encode_get_numeric_effecter_value_resp(
1778 0, PLDM_SUCCESS, 6, 9, reinterpret_cast<uint8_t*>(&pendingValue),
1779 reinterpret_cast<uint8_t*>(&presentValue), response,
1780 responseMsg.size() - hdrSize);
1781 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1782
1783 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
1784 uint8_t effecter_operState = EFFECTER_OPER_STATE_FAILED;
1785
1786 rc = encode_get_numeric_effecter_value_resp(
1787 0, PLDM_SUCCESS, effecter_dataSize, effecter_operState,
1788 reinterpret_cast<uint8_t*>(&pendingValue),
1789 reinterpret_cast<uint8_t*>(&presentValue), response,
1790 responseMsg.size() - hdrSize);
1791 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1792}
1793
1794TEST(GetNumericEffecterValue, testGoodDecodeResponse)
1795{
1796 std::array<uint8_t,
1797 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2>
1798 responseMsg{};
1799
1800 uint8_t completionCode = 0;
1801 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT16;
1802 uint8_t effecter_operState = EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING;
1803 uint16_t pendingValue = 0x4321;
1804 uint16_t presentValue = 0xDCBA;
1805
1806 uint8_t retcompletionCode;
1807 uint8_t reteffecter_dataSize;
1808 uint8_t reteffecter_operState;
1809 uint8_t retpendingValue[2];
1810 uint8_t retpresentValue[2];
1811
1812 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1813 struct pldm_get_numeric_effecter_value_resp* resp =
1814 reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>(
1815 response->payload);
1816
1817 resp->completion_code = completionCode;
1818 resp->effecter_data_size = effecter_dataSize;
1819 resp->effecter_oper_state = effecter_operState;
1820
1821 uint16_t pendingValue_le = htole16(pendingValue);
1822 memcpy(resp->pending_and_present_values, &pendingValue_le,
1823 sizeof(pendingValue_le));
1824 uint16_t presentValue_le = htole16(presentValue);
1825 memcpy(&resp->pending_and_present_values[2], &presentValue_le,
1826 sizeof(presentValue_le));
1827
1828 auto rc = decode_get_numeric_effecter_value_resp(
1829 response, responseMsg.size() - hdrSize, &retcompletionCode,
1830 &reteffecter_dataSize, &reteffecter_operState, retpendingValue,
1831 retpresentValue);
1832
1833 EXPECT_EQ(rc, PLDM_SUCCESS);
1834 EXPECT_EQ(completionCode, retcompletionCode);
1835 EXPECT_EQ(effecter_dataSize, reteffecter_dataSize);
1836 EXPECT_EQ(effecter_operState, reteffecter_operState);
1837 EXPECT_EQ(pendingValue, *(reinterpret_cast<uint16_t*>(retpendingValue)));
1838 EXPECT_EQ(presentValue, *(reinterpret_cast<uint16_t*>(retpresentValue)));
1839}
1840
1841TEST(GetNumericEffecterValue, testBadDecodeResponse)
1842{
1843 std::array<uint8_t,
1844 hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6>
1845 responseMsg{};
1846
1847 auto rc = decode_get_numeric_effecter_value_resp(
1848 nullptr, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr,
1849 nullptr, nullptr);
1850
1851 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1852
1853 uint8_t completionCode = 0;
1854 uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_SINT16;
1855 uint8_t effecter_operState = EFFECTER_OPER_STATE_DISABLED;
1856 uint16_t pendingValue = 0x5678;
1857 uint16_t presentValue = 0xCDEF;
1858
1859 uint8_t retcompletionCode;
1860 uint8_t reteffecter_dataSize;
1861 uint8_t reteffecter_operState;
1862 uint8_t retpendingValue[2];
1863 uint8_t retpresentValue[2];
1864
1865 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
1866 struct pldm_get_numeric_effecter_value_resp* resp =
1867 reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>(
1868 response->payload);
1869
1870 resp->completion_code = completionCode;
1871 resp->effecter_data_size = effecter_dataSize;
1872 resp->effecter_oper_state = effecter_operState;
1873
1874 uint16_t pendingValue_le = htole16(pendingValue);
1875 memcpy(resp->pending_and_present_values, &pendingValue_le,
1876 sizeof(pendingValue_le));
1877 uint16_t presentValue_le = htole16(presentValue);
1878 memcpy(&resp->pending_and_present_values[2], &presentValue_le,
1879 sizeof(presentValue_le));
1880
1881 rc = decode_get_numeric_effecter_value_resp(
1882 response, responseMsg.size() - hdrSize, &retcompletionCode,
1883 &reteffecter_dataSize, &reteffecter_operState, retpendingValue,
1884 retpresentValue);
1885
1886 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1887}
1888
1889TEST(PldmPDRRepositoryChgEventEvent, testGoodDecodeRequest)
1890{
1891 const uint8_t eventDataFormat = FORMAT_IS_PDR_HANDLES;
1892 const uint8_t numberOfChangeRecords = 2;
1893 uint8_t eventDataOperation1 = PLDM_RECORDS_DELETED;
1894 const uint8_t numberOfChangeEntries1 = 2;
1895 std::array<uint32_t, numberOfChangeEntries1> changeRecordArr1{
1896 {0x00000000, 0x12345678}};
1897 uint8_t eventDataOperation2 = PLDM_RECORDS_ADDED;
1898 const uint8_t numberOfChangeEntries2 = 5;
1899 std::array<uint32_t, numberOfChangeEntries2> changeRecordArr2{
1900 {0x01234567, 0x11223344, 0x45678901, 0x21222324, 0x98765432}};
1901 std::array<uint8_t, PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH +
1902 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH *
1903 numberOfChangeRecords +
1904 (numberOfChangeEntries1 + numberOfChangeEntries2) *
1905 sizeof(uint32_t)>
1906 eventDataArr{};
1907
1908 struct pldm_pdr_repository_chg_event_data* eventData =
1909 reinterpret_cast<struct pldm_pdr_repository_chg_event_data*>(
1910 eventDataArr.data());
1911 eventData->event_data_format = eventDataFormat;
1912 eventData->number_of_change_records = numberOfChangeRecords;
1913 struct pldm_pdr_repository_change_record_data* changeRecord1 =
1914 reinterpret_cast<struct pldm_pdr_repository_change_record_data*>(
1915 eventData->change_records);
1916 changeRecord1->event_data_operation = eventDataOperation1;
1917 changeRecord1->number_of_change_entries = numberOfChangeEntries1;
1918 memcpy(changeRecord1->change_entry, &changeRecordArr1[0],
1919 changeRecordArr1.size() * sizeof(uint32_t));
1920 struct pldm_pdr_repository_change_record_data* changeRecord2 =
1921 reinterpret_cast<struct pldm_pdr_repository_change_record_data*>(
1922 eventData->change_records +
1923 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH +
1924 (changeRecordArr1.size() * sizeof(uint32_t)));
1925 changeRecord2->event_data_operation = eventDataOperation2;
1926 changeRecord2->number_of_change_entries = numberOfChangeEntries2;
1927 memcpy(changeRecord2->change_entry, &changeRecordArr2[0],
1928 changeRecordArr2.size() * sizeof(uint32_t));
1929
1930 uint8_t retEventDataFormat{};
1931 uint8_t retNumberOfChangeRecords{};
1932 size_t retChangeRecordDataOffset{0};
1933 auto rc = decode_pldm_pdr_repository_chg_event_data(
1934 reinterpret_cast<const uint8_t*>(eventData), eventDataArr.size(),
1935 &retEventDataFormat, &retNumberOfChangeRecords,
1936 &retChangeRecordDataOffset);
1937 EXPECT_EQ(rc, PLDM_SUCCESS);
1938 EXPECT_EQ(retEventDataFormat, FORMAT_IS_PDR_HANDLES);
1939 EXPECT_EQ(retNumberOfChangeRecords, numberOfChangeRecords);
1940
1941 const uint8_t* changeRecordData =
1942 reinterpret_cast<const uint8_t*>(changeRecord1);
1943 size_t changeRecordDataSize =
1944 eventDataArr.size() - PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH;
1945 uint8_t retEventDataOperation;
1946 uint8_t retNumberOfChangeEntries;
1947 size_t retChangeEntryDataOffset;
1948
1949 rc = decode_pldm_pdr_repository_change_record_data(
1950 reinterpret_cast<const uint8_t*>(changeRecordData),
1951 changeRecordDataSize, &retEventDataOperation, &retNumberOfChangeEntries,
1952 &retChangeEntryDataOffset);
1953 EXPECT_EQ(rc, PLDM_SUCCESS);
1954 EXPECT_EQ(retEventDataOperation, eventDataOperation1);
1955 EXPECT_EQ(retNumberOfChangeEntries, numberOfChangeEntries1);
1956 changeRecordData += retChangeEntryDataOffset;
1957 EXPECT_EQ(0, memcmp(changeRecordData, &changeRecordArr1[0],
1958 sizeof(uint32_t) * retNumberOfChangeEntries));
1959
1960 changeRecordData += sizeof(uint32_t) * retNumberOfChangeEntries;
1961 changeRecordDataSize -= sizeof(uint32_t) * retNumberOfChangeEntries -
1962 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH;
1963 rc = decode_pldm_pdr_repository_change_record_data(
1964 reinterpret_cast<const uint8_t*>(changeRecordData),
1965 changeRecordDataSize, &retEventDataOperation, &retNumberOfChangeEntries,
1966 &retChangeEntryDataOffset);
1967 EXPECT_EQ(rc, PLDM_SUCCESS);
1968 EXPECT_EQ(retEventDataOperation, eventDataOperation2);
1969 EXPECT_EQ(retNumberOfChangeEntries, numberOfChangeEntries2);
1970 changeRecordData += retChangeEntryDataOffset;
1971 EXPECT_EQ(0, memcmp(changeRecordData, &changeRecordArr2[0],
1972 sizeof(uint32_t) * retNumberOfChangeEntries));
1973}
1974
1975TEST(PldmPDRRepositoryChgEventEvent, testBadDecodeRequest)
1976{
1977 uint8_t eventDataFormat{};
1978 uint8_t numberOfChangeRecords{};
1979 size_t changeRecordDataOffset{};
1980 auto rc = decode_pldm_pdr_repository_chg_event_data(
1981 NULL, 0, &eventDataFormat, &numberOfChangeRecords,
1982 &changeRecordDataOffset);
1983 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1984
1985 std::array<uint8_t, 2> eventData{};
1986 rc = decode_pldm_pdr_repository_chg_event_data(
1987 reinterpret_cast<const uint8_t*>(eventData.data()), 0, &eventDataFormat,
1988 &numberOfChangeRecords, &changeRecordDataOffset);
1989 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
1990
1991 uint8_t eventDataOperation{};
1992 uint8_t numberOfChangeEntries{};
1993 size_t changeEntryDataOffset{};
1994 rc = decode_pldm_pdr_repository_change_record_data(
1995 NULL, 0, &eventDataOperation, &numberOfChangeEntries,
1996 &changeEntryDataOffset);
1997 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
1998
1999 std::array<uint8_t, 2> changeRecord{};
2000 rc = decode_pldm_pdr_repository_change_record_data(
2001 reinterpret_cast<const uint8_t*>(changeRecord.data()), 0,
2002 &eventDataOperation, &numberOfChangeEntries, &changeEntryDataOffset);
2003 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2004}
2005
2006TEST(GetSensorReading, testGoodEncodeRequest)
2007{
2008 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES>
2009 requestMsg{};
2010
2011 uint16_t sensorId = 0x1234;
2012 bool8_t rearmEventState = 0x01;
2013
2014 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2015 auto rc =
2016 encode_get_sensor_reading_req(0, sensorId, rearmEventState, request);
2017
2018 struct pldm_get_sensor_reading_req* req =
2019 reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload);
2020
2021 EXPECT_EQ(rc, PLDM_SUCCESS);
2022 EXPECT_EQ(sensorId, le16toh(req->sensor_id));
2023 EXPECT_EQ(rearmEventState, req->rearm_event_state);
2024}
2025
2026TEST(GetSensorReading, testBadEncodeRequest)
2027{
2028 auto rc = encode_get_sensor_reading_req(0, 0, 0, nullptr);
2029
2030 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2031}
2032
2033TEST(GetSensorReading, testGoodDecodeRequest)
2034{
2035 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES>
2036 requestMsg{};
2037
2038 uint16_t sensorId = 0xABCD;
2039 bool8_t rearmEventState = 0xA;
2040
2041 uint16_t retsensorId;
2042 bool8_t retrearmEventState;
2043
2044 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2045
2046 struct pldm_get_sensor_reading_req* req =
2047 reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload);
2048
2049 req->sensor_id = htole16(sensorId);
2050 req->rearm_event_state = rearmEventState;
2051
2052 auto rc =
2053 decode_get_sensor_reading_req(request, requestMsg.size() - hdrSize,
2054 &retsensorId, &retrearmEventState);
2055
2056 EXPECT_EQ(rc, PLDM_SUCCESS);
2057 EXPECT_EQ(sensorId, retsensorId);
2058 EXPECT_EQ(rearmEventState, retrearmEventState);
2059}
2060
2061TEST(GetSensorReading, testBadDecodeRequest)
2062{
2063 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES>
2064 requestMsg{};
2065
2066 auto rc = decode_get_sensor_reading_req(
2067 nullptr, requestMsg.size() - hdrSize, nullptr, nullptr);
2068 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2069
2070 uint16_t sensorId = 0xABCD;
2071 bool8_t rearmEventState = 0xA;
2072
2073 uint16_t retsensorId;
2074 bool8_t retrearmEventState;
2075
2076 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2077
2078 struct pldm_get_sensor_reading_req* req =
2079 reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload);
2080
2081 req->sensor_id = htole16(sensorId);
2082 req->rearm_event_state = rearmEventState;
2083
2084 rc = decode_get_sensor_reading_req(request, requestMsg.size() - hdrSize - 1,
2085 &retsensorId, &retrearmEventState);
2086
2087 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2088}
2089
2090TEST(GetSensorReading, testGoodEncodeResponse)
2091{
2092 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES>
2093 responseMsg{};
2094
2095 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2096
2097 uint8_t completionCode = 0;
2098 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
2099 uint8_t sensor_operationalState = PLDM_SENSOR_ENABLED;
2100 uint8_t sensor_event_messageEnable = PLDM_NO_EVENT_GENERATION;
2101 uint8_t presentState = PLDM_SENSOR_NORMAL;
2102 uint8_t previousState = PLDM_SENSOR_WARNING;
2103 uint8_t eventState = PLDM_SENSOR_UPPERWARNING;
2104 uint8_t presentReading = 0x21;
2105
2106 auto rc = encode_get_sensor_reading_resp(
2107 0, completionCode, sensor_dataSize, sensor_operationalState,
2108 sensor_event_messageEnable, presentState, previousState, eventState,
2109 reinterpret_cast<uint8_t*>(&presentReading), response,
2110 responseMsg.size() - hdrSize);
2111
2112 struct pldm_get_sensor_reading_resp* resp =
2113 reinterpret_cast<struct pldm_get_sensor_reading_resp*>(
2114 response->payload);
2115
2116 EXPECT_EQ(rc, PLDM_SUCCESS);
2117 EXPECT_EQ(completionCode, resp->completion_code);
2118 EXPECT_EQ(sensor_dataSize, resp->sensor_data_size);
2119 EXPECT_EQ(sensor_operationalState, resp->sensor_operational_state);
2120 EXPECT_EQ(sensor_event_messageEnable, resp->sensor_event_message_enable);
2121 EXPECT_EQ(presentState, resp->present_state);
2122 EXPECT_EQ(previousState, resp->previous_state);
2123 EXPECT_EQ(eventState, resp->event_state);
2124 EXPECT_EQ(presentReading,
2125 *(reinterpret_cast<uint8_t*>(&resp->present_reading[0])));
2126}
2127
2128TEST(GetSensorReading, testBadEncodeResponse)
2129{
2130 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3>
2131 responseMsg{};
2132
2133 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2134
2135 uint8_t presentReading = 0x1;
2136
2137 auto rc = encode_get_sensor_reading_resp(0, PLDM_SUCCESS, 0, 0, 0, 0, 0, 0,
2138 nullptr, nullptr,
2139 responseMsg.size() - hdrSize);
2140 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2141
2142 rc = encode_get_sensor_reading_resp(
2143 0, PLDM_SUCCESS, 6, 1, 1, 1, 1, 1,
2144 reinterpret_cast<uint8_t*>(&presentReading), response,
2145 responseMsg.size() - hdrSize);
2146 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2147
2148 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
2149
2150 rc = encode_get_sensor_reading_resp(
2151 0, PLDM_SUCCESS, sensor_dataSize, 1, 1, 1, 1, 1,
2152 reinterpret_cast<uint8_t*>(&presentReading), response,
2153 responseMsg.size() - hdrSize);
2154 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2155}
2156
2157TEST(GetSensorReading, testGoodDecodeResponse)
2158{
2159 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3>
2160 responseMsg{};
2161
2162 uint8_t completionCode = 0;
2163 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT32;
2164 uint8_t sensor_operationalState = PLDM_SENSOR_STATUSUNKOWN;
2165 uint8_t sensor_event_messageEnable = PLDM_EVENTS_ENABLED;
2166 uint8_t presentState = PLDM_SENSOR_CRITICAL;
2167 uint8_t previousState = PLDM_SENSOR_UPPERCRITICAL;
2168 uint8_t eventState = PLDM_SENSOR_WARNING;
2169 uint32_t presentReading = 0xABCDEF11;
2170
2171 uint8_t retcompletionCode;
2172 uint8_t retsensor_dataSize = PLDM_SENSOR_DATA_SIZE_UINT32;
2173 uint8_t retsensor_operationalState;
2174 uint8_t retsensor_event_messageEnable;
2175 uint8_t retpresentState;
2176 uint8_t retpreviousState;
2177 uint8_t reteventState;
2178 uint8_t retpresentReading[4];
2179
2180 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2181 struct pldm_get_sensor_reading_resp* resp =
2182 reinterpret_cast<struct pldm_get_sensor_reading_resp*>(
2183 response->payload);
2184
2185 resp->completion_code = completionCode;
2186 resp->sensor_data_size = sensor_dataSize;
2187 resp->sensor_operational_state = sensor_operationalState;
2188 resp->sensor_event_message_enable = sensor_event_messageEnable;
2189 resp->present_state = presentState;
2190 resp->previous_state = previousState;
2191 resp->event_state = eventState;
2192
2193 uint32_t presentReading_le = htole32(presentReading);
2194 memcpy(resp->present_reading, &presentReading_le,
2195 sizeof(presentReading_le));
2196
2197 auto rc = decode_get_sensor_reading_resp(
2198 response, responseMsg.size() - hdrSize, &retcompletionCode,
2199 &retsensor_dataSize, &retsensor_operationalState,
2200 &retsensor_event_messageEnable, &retpresentState, &retpreviousState,
2201 &reteventState, retpresentReading);
2202
2203 EXPECT_EQ(rc, PLDM_SUCCESS);
2204 EXPECT_EQ(completionCode, retcompletionCode);
2205 EXPECT_EQ(sensor_dataSize, retsensor_dataSize);
2206 EXPECT_EQ(sensor_operationalState, retsensor_operationalState);
2207 EXPECT_EQ(sensor_event_messageEnable, retsensor_event_messageEnable);
2208 EXPECT_EQ(presentState, retpresentState);
2209 EXPECT_EQ(previousState, retpreviousState);
2210 EXPECT_EQ(eventState, reteventState);
2211 EXPECT_EQ(presentReading,
2212 *(reinterpret_cast<uint32_t*>(retpresentReading)));
2213}
2214
2215TEST(GetSensorReading, testBadDecodeResponse)
2216{
2217 std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 1>
2218 responseMsg{};
2219
2220 auto rc = decode_get_sensor_reading_resp(
2221 nullptr, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr,
2222 nullptr, nullptr, nullptr, nullptr, nullptr);
2223
2224 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2225
2226 uint8_t completionCode = 0;
2227 uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8;
2228 uint8_t sensor_operationalState = PLDM_SENSOR_INTEST;
2229 uint8_t sensor_event_messageEnable = PLDM_EVENTS_DISABLED;
2230 uint8_t presentState = PLDM_SENSOR_FATAL;
2231 uint8_t previousState = PLDM_SENSOR_UPPERFATAL;
2232 uint8_t eventState = PLDM_SENSOR_WARNING;
2233 uint8_t presentReading = 0xA;
2234
2235 uint8_t retcompletionCode;
2236 uint8_t retsensor_dataSize = PLDM_SENSOR_DATA_SIZE_SINT16;
2237 uint8_t retsensor_operationalState;
2238 uint8_t retsensor_event_messageEnable;
2239 uint8_t retpresent_state;
2240 uint8_t retprevious_state;
2241 uint8_t retevent_state;
2242 uint8_t retpresentReading;
2243
2244 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2245 struct pldm_get_sensor_reading_resp* resp =
2246 reinterpret_cast<struct pldm_get_sensor_reading_resp*>(
2247 response->payload);
2248
2249 resp->completion_code = completionCode;
2250 resp->sensor_data_size = sensor_dataSize;
2251 resp->sensor_operational_state = sensor_operationalState;
2252 resp->sensor_event_message_enable = sensor_event_messageEnable;
2253 resp->present_state = presentState;
2254 resp->previous_state = previousState;
2255 resp->event_state = eventState;
2256 resp->present_reading[0] = presentReading;
2257
2258 rc = decode_get_sensor_reading_resp(
2259 response, responseMsg.size() - hdrSize, &retcompletionCode,
2260 &retsensor_dataSize, &retsensor_operationalState,
2261 &retsensor_event_messageEnable, &retpresent_state, &retprevious_state,
2262 &retevent_state, reinterpret_cast<uint8_t*>(&retpresentReading));
2263
2264 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2265}
2266
2267TEST(SetEventReceiver, testGoodEncodeRequest)
2268{
2269 uint8_t eventMessageGlobalEnable =
2270 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
2271 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
2272 uint8_t eventReceiverAddressInfo = 0x08;
2273 uint16_t heartbeatTimer = 0x78;
2274
2275 std::vector<uint8_t> requestMsg(hdrSize +
2276 PLDM_SET_EVENT_RECEIVER_REQ_BYTES);
2277 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2278
2279 auto rc = encode_set_event_receiver_req(
2280 0, eventMessageGlobalEnable, transportProtocolType,
2281 eventReceiverAddressInfo, heartbeatTimer, request);
2282
2283 EXPECT_EQ(rc, PLDM_SUCCESS);
2284 struct pldm_set_event_receiver_req* req =
2285 reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
2286 EXPECT_EQ(eventMessageGlobalEnable, req->event_message_global_enable);
2287 EXPECT_EQ(transportProtocolType, req->transport_protocol_type);
2288 EXPECT_EQ(eventReceiverAddressInfo, req->event_receiver_address_info);
2289 EXPECT_EQ(heartbeatTimer, le16toh(req->heartbeat_timer));
2290}
2291
2292TEST(SetEventReceiver, testBadEncodeRequest)
2293{
2294 uint8_t eventMessageGlobalEnable =
2295 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
2296 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
2297 uint8_t eventReceiverAddressInfo = 0x08;
2298 uint16_t heartbeatTimer = 0;
2299
2300 std::vector<uint8_t> requestMsg(hdrSize +
2301 PLDM_SET_EVENT_RECEIVER_REQ_BYTES);
2302 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2303
2304 auto rc = encode_set_event_receiver_req(
2305 0, eventMessageGlobalEnable, transportProtocolType,
2306 eventReceiverAddressInfo, heartbeatTimer, request);
2307
2308 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2309}
2310
2311TEST(SetEventReceiver, testGoodDecodeResponse)
2312{
2313 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_RESP_BYTES>
2314 responseMsg{};
2315
2316 uint8_t retcompletion_code = 0;
2317 responseMsg[hdrSize] = PLDM_SUCCESS;
2318
2319 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2320 auto rc = decode_set_event_receiver_resp(
2321 response, responseMsg.size() - sizeof(pldm_msg_hdr),
2322 &retcompletion_code);
2323
2324 EXPECT_EQ(rc, PLDM_SUCCESS);
2325 EXPECT_EQ(PLDM_SUCCESS, retcompletion_code);
2326}
2327
2328TEST(SetEventReceiver, testBadDecodeResponse)
2329{
2330 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_RESP_BYTES>
2331 responseMsg{};
2332 uint8_t retcompletion_code = 0;
2333 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2334
2335 auto rc = decode_set_event_receiver_resp(
2336 response, responseMsg.size() - sizeof(pldm_msg_hdr), NULL);
2337
2338 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2339
2340 rc = decode_set_event_receiver_resp(
2341 nullptr, responseMsg.size() - sizeof(pldm_msg_hdr),
2342 &retcompletion_code);
2343
2344 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2345}
2346
2347TEST(SetEventReceiver, testGoodEncodeResponse)
2348{
2349 std::array<uint8_t,
2350 sizeof(pldm_msg_hdr) + PLDM_SET_EVENT_RECEIVER_RESP_BYTES>
2351 responseMsg{};
2352 auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
2353 uint8_t completionCode = 0;
2354
2355 auto rc = encode_set_event_receiver_resp(0, PLDM_SUCCESS, response);
2356
2357 EXPECT_EQ(rc, PLDM_SUCCESS);
2358 EXPECT_EQ(completionCode, response->payload[0]);
2359}
2360
2361TEST(SetEventReceiver, testBadEncodeResponse)
2362{
2363 auto rc = encode_set_event_receiver_resp(0, PLDM_SUCCESS, NULL);
2364 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2365}
2366
2367TEST(SetEventReceiver, testGoodDecodeRequest)
2368{
2369
2370 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_REQ_BYTES>
2371 requestMsg{};
2372
2373 uint8_t eventMessageGlobalEnable =
2374 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
2375 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
2376 uint8_t eventReceiverAddressInfo = 0x08;
2377 uint16_t heartbeatTimer = 0x78;
2378
2379 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2380 struct pldm_set_event_receiver_req* req =
2381 reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
2382
2383 req->event_message_global_enable = eventMessageGlobalEnable;
2384 req->transport_protocol_type = transportProtocolType;
2385 req->event_receiver_address_info = eventReceiverAddressInfo;
2386 req->heartbeat_timer = htole16(heartbeatTimer);
2387
2388 uint8_t reteventMessageGlobalEnable;
2389 uint8_t rettransportProtocolType;
2390 uint8_t reteventReceiverAddressInfo;
2391 uint16_t retheartbeatTimer;
2392 auto rc = decode_set_event_receiver_req(
2393 request, requestMsg.size() - hdrSize, &reteventMessageGlobalEnable,
2394 &rettransportProtocolType, &reteventReceiverAddressInfo,
2395 &retheartbeatTimer);
2396
2397 EXPECT_EQ(rc, PLDM_SUCCESS);
2398 EXPECT_EQ(eventMessageGlobalEnable, reteventMessageGlobalEnable);
2399 EXPECT_EQ(transportProtocolType, rettransportProtocolType);
2400 EXPECT_EQ(eventReceiverAddressInfo, reteventReceiverAddressInfo);
2401 EXPECT_EQ(heartbeatTimer, retheartbeatTimer);
2402}
2403
2404TEST(SetEventReceiver, testBadDecodeRequest)
2405{
2406 std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_REQ_BYTES>
2407 requestMsg{};
2408
2409 auto rc = decode_set_event_receiver_req(NULL, requestMsg.size() - hdrSize,
2410 NULL, NULL, NULL, NULL);
2411 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
2412
2413 uint8_t eventMessageGlobalEnable =
2414 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
2415 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
2416 uint8_t eventReceiverAddressInfo = 0x08;
2417 uint16_t heartbeatTimer = 0x78;
2418
2419 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2420 struct pldm_set_event_receiver_req* req =
2421 reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload);
2422
2423 req->event_message_global_enable = eventMessageGlobalEnable;
2424 req->transport_protocol_type = transportProtocolType;
2425 req->event_receiver_address_info = eventReceiverAddressInfo;
2426 req->heartbeat_timer = htole16(heartbeatTimer);
2427
2428 uint8_t reteventMessageGlobalEnable;
2429 uint8_t rettransportProtocolType;
2430 uint8_t reteventReceiverAddressInfo;
2431 uint16_t retheartbeatTimer;
2432 rc = decode_set_event_receiver_req(
2433 request, requestMsg.size() - hdrSize - 1, &reteventMessageGlobalEnable,
2434 &rettransportProtocolType, &reteventReceiverAddressInfo,
2435 &retheartbeatTimer);
2436 EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
2437}