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