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