Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 1 | #include <endian.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2 | |
| 3 | #include <array> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 4 | #include <cstdint> |
Andrew Jeffery | 5a70607 | 2023-04-05 19:45:31 +0930 | [diff] [blame] | 5 | #include <cstring> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 6 | #include <vector> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 7 | |
| 8 | #include "libpldm/base.h" |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 9 | #include "libpldm/entity.h" |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 10 | #include "libpldm/platform.h" |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 11 | #include "pldm_types.h" |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 12 | |
| 13 | #include <gtest/gtest.h> |
| 14 | |
| 15 | constexpr auto hdrSize = sizeof(pldm_msg_hdr); |
| 16 | |
| 17 | TEST(SetStateEffecterStates, testEncodeResponse) |
| 18 | { |
| 19 | std::array<uint8_t, |
| 20 | sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES> |
| 21 | responseMsg{}; |
| 22 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 23 | uint8_t completionCode = 0; |
| 24 | |
| 25 | auto rc = encode_set_state_effecter_states_resp(0, PLDM_SUCCESS, response); |
| 26 | |
| 27 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 28 | EXPECT_EQ(completionCode, response->payload[0]); |
| 29 | } |
| 30 | |
| 31 | TEST(SetStateEffecterStates, testEncodeRequest) |
| 32 | { |
| 33 | std::array<uint8_t, |
| 34 | sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES> |
| 35 | requestMsg{}; |
| 36 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 37 | |
| 38 | uint16_t effecterId = 0x0A; |
| 39 | uint8_t compEffecterCnt = 0x2; |
| 40 | std::array<set_effecter_state_field, 8> stateField{}; |
| 41 | stateField[0] = {PLDM_REQUEST_SET, 2}; |
| 42 | stateField[1] = {PLDM_REQUEST_SET, 3}; |
| 43 | |
| 44 | auto rc = encode_set_state_effecter_states_req( |
| 45 | 0, effecterId, compEffecterCnt, stateField.data(), request); |
| 46 | |
| 47 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 48 | EXPECT_EQ(effecterId, request->payload[0]); |
| 49 | EXPECT_EQ(compEffecterCnt, request->payload[sizeof(effecterId)]); |
| 50 | EXPECT_EQ(stateField[0].set_request, |
| 51 | request->payload[sizeof(effecterId) + sizeof(compEffecterCnt)]); |
| 52 | EXPECT_EQ(stateField[0].effecter_state, |
| 53 | request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) + |
| 54 | sizeof(stateField[0].set_request)]); |
| 55 | EXPECT_EQ(stateField[1].set_request, |
| 56 | request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) + |
| 57 | sizeof(stateField[0])]); |
| 58 | EXPECT_EQ(stateField[1].effecter_state, |
| 59 | request->payload[sizeof(effecterId) + sizeof(compEffecterCnt) + |
| 60 | sizeof(stateField[0]) + |
| 61 | sizeof(stateField[1].set_request)]); |
| 62 | } |
| 63 | |
| 64 | TEST(SetStateEffecterStates, testGoodDecodeResponse) |
| 65 | { |
| 66 | std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES> |
| 67 | responseMsg{}; |
| 68 | |
| 69 | uint8_t retcompletion_code = 0; |
| 70 | |
| 71 | responseMsg[hdrSize] = PLDM_SUCCESS; |
| 72 | |
| 73 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 74 | |
| 75 | auto rc = decode_set_state_effecter_states_resp( |
| 76 | response, responseMsg.size() - hdrSize, &retcompletion_code); |
| 77 | |
| 78 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 79 | EXPECT_EQ(PLDM_SUCCESS, retcompletion_code); |
| 80 | } |
| 81 | |
| 82 | TEST(SetStateEffecterStates, testGoodDecodeRequest) |
| 83 | { |
| 84 | std::array<uint8_t, hdrSize + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES> |
| 85 | requestMsg{}; |
| 86 | |
| 87 | uint16_t effecterId = 0x32; |
| 88 | uint16_t effecterIdLE = htole16(effecterId); |
| 89 | uint8_t compEffecterCnt = 0x2; |
| 90 | |
| 91 | std::array<set_effecter_state_field, 8> stateField{}; |
| 92 | stateField[0] = {PLDM_REQUEST_SET, 3}; |
| 93 | stateField[1] = {PLDM_REQUEST_SET, 4}; |
| 94 | |
| 95 | uint16_t retEffecterId = 0; |
| 96 | uint8_t retCompEffecterCnt = 0; |
| 97 | |
| 98 | std::array<set_effecter_state_field, 8> retStateField{}; |
| 99 | |
| 100 | memcpy(requestMsg.data() + hdrSize, &effecterIdLE, sizeof(effecterIdLE)); |
| 101 | memcpy(requestMsg.data() + sizeof(effecterIdLE) + hdrSize, &compEffecterCnt, |
| 102 | sizeof(compEffecterCnt)); |
| 103 | memcpy(requestMsg.data() + sizeof(effecterIdLE) + sizeof(compEffecterCnt) + |
| 104 | hdrSize, |
| 105 | &stateField, sizeof(stateField)); |
| 106 | |
| 107 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 108 | |
| 109 | auto rc = decode_set_state_effecter_states_req( |
| 110 | request, requestMsg.size() - hdrSize, &retEffecterId, |
| 111 | &retCompEffecterCnt, retStateField.data()); |
| 112 | |
| 113 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 114 | EXPECT_EQ(effecterId, retEffecterId); |
| 115 | EXPECT_EQ(retCompEffecterCnt, compEffecterCnt); |
| 116 | EXPECT_EQ(retStateField[0].set_request, stateField[0].set_request); |
| 117 | EXPECT_EQ(retStateField[0].effecter_state, stateField[0].effecter_state); |
| 118 | EXPECT_EQ(retStateField[1].set_request, stateField[1].set_request); |
| 119 | EXPECT_EQ(retStateField[1].effecter_state, stateField[1].effecter_state); |
| 120 | } |
| 121 | |
| 122 | TEST(SetStateEffecterStates, testBadDecodeRequest) |
| 123 | { |
| 124 | const struct pldm_msg* msg = NULL; |
| 125 | |
| 126 | auto rc = decode_set_state_effecter_states_req(msg, sizeof(*msg), NULL, |
| 127 | NULL, NULL); |
| 128 | |
| 129 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 130 | } |
| 131 | |
| 132 | TEST(SetStateEffecterStates, testBadDecodeResponse) |
| 133 | { |
| 134 | std::array<uint8_t, PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES> |
| 135 | responseMsg{}; |
| 136 | |
| 137 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 138 | |
| 139 | auto rc = decode_set_state_effecter_states_resp(response, |
| 140 | responseMsg.size(), NULL); |
| 141 | |
| 142 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 143 | } |
| 144 | |
| 145 | TEST(GetPDR, testGoodEncodeResponse) |
| 146 | { |
| 147 | uint8_t completionCode = 0; |
| 148 | uint32_t nextRecordHndl = 0x12; |
| 149 | uint32_t nextDataTransferHndl = 0x13; |
| 150 | uint8_t transferFlag = PLDM_END; |
| 151 | uint16_t respCnt = 0x5; |
| 152 | std::vector<uint8_t> recordData{1, 2, 3, 4, 5}; |
| 153 | uint8_t transferCRC = 6; |
| 154 | |
| 155 | // + size of record data and transfer CRC |
| 156 | std::vector<uint8_t> responseMsg(hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES + |
| 157 | recordData.size() + 1); |
| 158 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 159 | |
| 160 | auto rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl, |
| 161 | nextDataTransferHndl, transferFlag, respCnt, |
| 162 | recordData.data(), transferCRC, response); |
| 163 | |
| 164 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 165 | struct pldm_get_pdr_resp* resp = |
| 166 | reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload); |
| 167 | |
| 168 | EXPECT_EQ(completionCode, resp->completion_code); |
| 169 | EXPECT_EQ(nextRecordHndl, le32toh(resp->next_record_handle)); |
| 170 | EXPECT_EQ(nextDataTransferHndl, le32toh(resp->next_data_transfer_handle)); |
| 171 | EXPECT_EQ(transferFlag, resp->transfer_flag); |
| 172 | EXPECT_EQ(respCnt, le16toh(resp->response_count)); |
| 173 | EXPECT_EQ(0, |
| 174 | memcmp(recordData.data(), resp->record_data, recordData.size())); |
| 175 | EXPECT_EQ(*(response->payload + sizeof(pldm_get_pdr_resp) - 1 + |
| 176 | recordData.size()), |
| 177 | transferCRC); |
| 178 | |
| 179 | transferFlag = PLDM_START_AND_END; // No CRC in this case |
| 180 | responseMsg.resize(responseMsg.size() - sizeof(transferCRC)); |
| 181 | rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl, |
| 182 | nextDataTransferHndl, transferFlag, respCnt, |
| 183 | recordData.data(), transferCRC, response); |
| 184 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 185 | } |
| 186 | |
| 187 | TEST(GetPDR, testBadEncodeResponse) |
| 188 | { |
| 189 | uint32_t nextRecordHndl = 0x12; |
| 190 | uint32_t nextDataTransferHndl = 0x13; |
| 191 | uint8_t transferFlag = PLDM_START_AND_END; |
| 192 | uint16_t respCnt = 0x5; |
| 193 | std::vector<uint8_t> recordData{1, 2, 3, 4, 5}; |
| 194 | uint8_t transferCRC = 0; |
| 195 | |
| 196 | auto rc = encode_get_pdr_resp(0, PLDM_SUCCESS, nextRecordHndl, |
| 197 | nextDataTransferHndl, transferFlag, respCnt, |
| 198 | recordData.data(), transferCRC, nullptr); |
| 199 | |
| 200 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 201 | } |
| 202 | |
| 203 | TEST(GetPDR, testGoodDecodeRequest) |
| 204 | { |
| 205 | std::array<uint8_t, hdrSize + PLDM_GET_PDR_REQ_BYTES> requestMsg{}; |
| 206 | |
| 207 | uint32_t recordHndl = 0x32; |
| 208 | uint32_t dataTransferHndl = 0x11; |
| 209 | uint8_t transferOpFlag = PLDM_GET_FIRSTPART; |
| 210 | uint16_t requestCnt = 0x5; |
| 211 | uint16_t recordChangeNum = 0x01; |
| 212 | |
| 213 | uint32_t retRecordHndl = 0; |
| 214 | uint32_t retDataTransferHndl = 0; |
| 215 | uint8_t retTransferOpFlag = 0; |
| 216 | uint16_t retRequestCnt = 0; |
| 217 | uint16_t retRecordChangeNum = 0; |
| 218 | |
| 219 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 220 | struct pldm_get_pdr_req* request = |
| 221 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 222 | |
| 223 | request->record_handle = htole32(recordHndl); |
| 224 | request->data_transfer_handle = htole32(dataTransferHndl); |
| 225 | request->transfer_op_flag = transferOpFlag; |
| 226 | request->request_count = htole16(requestCnt); |
| 227 | request->record_change_number = htole16(recordChangeNum); |
| 228 | |
| 229 | auto rc = decode_get_pdr_req( |
| 230 | req, requestMsg.size() - hdrSize, &retRecordHndl, &retDataTransferHndl, |
| 231 | &retTransferOpFlag, &retRequestCnt, &retRecordChangeNum); |
| 232 | |
| 233 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 234 | EXPECT_EQ(retRecordHndl, recordHndl); |
| 235 | EXPECT_EQ(retDataTransferHndl, dataTransferHndl); |
| 236 | EXPECT_EQ(retTransferOpFlag, transferOpFlag); |
| 237 | EXPECT_EQ(retRequestCnt, requestCnt); |
| 238 | EXPECT_EQ(retRecordChangeNum, recordChangeNum); |
| 239 | } |
| 240 | |
| 241 | TEST(GetPDR, testBadDecodeRequest) |
| 242 | { |
| 243 | std::array<uint8_t, PLDM_GET_PDR_REQ_BYTES> requestMsg{}; |
| 244 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 245 | |
| 246 | auto rc = decode_get_pdr_req(req, requestMsg.size(), NULL, NULL, NULL, NULL, |
| 247 | NULL); |
| 248 | |
| 249 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 250 | } |
| 251 | |
| 252 | TEST(GetPDR, testGoodEncodeRequest) |
| 253 | { |
| 254 | uint32_t record_hndl = 0; |
| 255 | uint32_t data_transfer_hndl = 0; |
| 256 | uint8_t transfer_op_flag = PLDM_GET_FIRSTPART; |
| 257 | uint16_t request_cnt = 20; |
| 258 | uint16_t record_chg_num = 0; |
| 259 | |
| 260 | std::vector<uint8_t> requestMsg(hdrSize + PLDM_GET_PDR_REQ_BYTES); |
| 261 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 262 | |
| 263 | auto rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl, |
| 264 | transfer_op_flag, request_cnt, record_chg_num, |
| 265 | request, PLDM_GET_PDR_REQ_BYTES); |
| 266 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 267 | struct pldm_get_pdr_req* req = |
| 268 | reinterpret_cast<struct pldm_get_pdr_req*>(request->payload); |
| 269 | EXPECT_EQ(record_hndl, le32toh(req->record_handle)); |
| 270 | EXPECT_EQ(data_transfer_hndl, le32toh(req->data_transfer_handle)); |
| 271 | EXPECT_EQ(transfer_op_flag, req->transfer_op_flag); |
| 272 | EXPECT_EQ(request_cnt, le16toh(req->request_count)); |
| 273 | EXPECT_EQ(record_chg_num, le16toh(req->record_change_number)); |
| 274 | } |
| 275 | |
| 276 | TEST(GetPDR, testBadEncodeRequest) |
| 277 | { |
| 278 | uint32_t record_hndl = 0; |
| 279 | uint32_t data_transfer_hndl = 0; |
| 280 | uint8_t transfer_op_flag = PLDM_GET_FIRSTPART; |
| 281 | uint16_t request_cnt = 32; |
| 282 | uint16_t record_chg_num = 0; |
| 283 | |
| 284 | std::vector<uint8_t> requestMsg(hdrSize + PLDM_GET_PDR_REQ_BYTES); |
| 285 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 286 | |
| 287 | auto rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl, |
| 288 | transfer_op_flag, request_cnt, record_chg_num, |
| 289 | nullptr, PLDM_GET_PDR_REQ_BYTES); |
| 290 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 291 | |
| 292 | rc = encode_get_pdr_req(0, record_hndl, data_transfer_hndl, |
| 293 | transfer_op_flag, request_cnt, record_chg_num, |
| 294 | request, PLDM_GET_PDR_REQ_BYTES + 1); |
| 295 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 296 | } |
| 297 | |
| 298 | TEST(GetPDR, testGoodDecodeResponse) |
| 299 | { |
| 300 | const char* recordData = "123456789"; |
| 301 | uint8_t completionCode = PLDM_SUCCESS; |
| 302 | uint32_t nextRecordHndl = 0; |
| 303 | uint32_t nextDataTransferHndl = 0; |
| 304 | uint8_t transferFlag = PLDM_END; |
| 305 | constexpr uint16_t respCnt = 9; |
| 306 | uint8_t transferCRC = 96; |
| 307 | size_t recordDataLength = 32; |
| 308 | std::array<uint8_t, hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES + respCnt + |
| 309 | sizeof(transferCRC)> |
| 310 | responseMsg{}; |
| 311 | |
| 312 | uint8_t retCompletionCode = 0; |
| 313 | uint8_t retRecordData[32] = {0}; |
| 314 | uint32_t retNextRecordHndl = 0; |
| 315 | uint32_t retNextDataTransferHndl = 0; |
| 316 | uint8_t retTransferFlag = 0; |
| 317 | uint16_t retRespCnt = 0; |
| 318 | uint8_t retTransferCRC = 0; |
| 319 | |
| 320 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 321 | struct pldm_get_pdr_resp* resp = |
| 322 | reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload); |
| 323 | resp->completion_code = completionCode; |
| 324 | resp->next_record_handle = htole32(nextRecordHndl); |
| 325 | resp->next_data_transfer_handle = htole32(nextDataTransferHndl); |
| 326 | resp->transfer_flag = transferFlag; |
| 327 | resp->response_count = htole16(respCnt); |
| 328 | memcpy(resp->record_data, recordData, respCnt); |
| 329 | response->payload[PLDM_GET_PDR_MIN_RESP_BYTES + respCnt] = transferCRC; |
| 330 | |
| 331 | auto rc = decode_get_pdr_resp( |
| 332 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 333 | &retNextRecordHndl, &retNextDataTransferHndl, &retTransferFlag, |
| 334 | &retRespCnt, retRecordData, recordDataLength, &retTransferCRC); |
| 335 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 336 | EXPECT_EQ(retCompletionCode, completionCode); |
| 337 | EXPECT_EQ(retNextRecordHndl, nextRecordHndl); |
| 338 | EXPECT_EQ(retNextDataTransferHndl, nextDataTransferHndl); |
| 339 | EXPECT_EQ(retTransferFlag, transferFlag); |
| 340 | EXPECT_EQ(retRespCnt, respCnt); |
| 341 | EXPECT_EQ(retTransferCRC, transferCRC); |
| 342 | EXPECT_EQ(0, memcmp(recordData, resp->record_data, respCnt)); |
| 343 | } |
| 344 | |
| 345 | TEST(GetPDR, testBadDecodeResponse) |
| 346 | { |
| 347 | const char* recordData = "123456789"; |
| 348 | uint8_t completionCode = PLDM_SUCCESS; |
| 349 | uint32_t nextRecordHndl = 0; |
| 350 | uint32_t nextDataTransferHndl = 0; |
| 351 | uint8_t transferFlag = PLDM_END; |
| 352 | constexpr uint16_t respCnt = 9; |
| 353 | uint8_t transferCRC = 96; |
| 354 | size_t recordDataLength = 32; |
| 355 | std::array<uint8_t, hdrSize + PLDM_GET_PDR_MIN_RESP_BYTES + respCnt + |
| 356 | sizeof(transferCRC)> |
| 357 | responseMsg{}; |
| 358 | |
| 359 | uint8_t retCompletionCode = 0; |
| 360 | uint8_t retRecordData[32] = {0}; |
| 361 | uint32_t retNextRecordHndl = 0; |
| 362 | uint32_t retNextDataTransferHndl = 0; |
| 363 | uint8_t retTransferFlag = 0; |
| 364 | uint16_t retRespCnt = 0; |
| 365 | uint8_t retTransferCRC = 0; |
| 366 | |
| 367 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 368 | struct pldm_get_pdr_resp* resp = |
| 369 | reinterpret_cast<struct pldm_get_pdr_resp*>(response->payload); |
| 370 | resp->completion_code = completionCode; |
| 371 | resp->next_record_handle = htole32(nextRecordHndl); |
| 372 | resp->next_data_transfer_handle = htole32(nextDataTransferHndl); |
| 373 | resp->transfer_flag = transferFlag; |
| 374 | resp->response_count = htole16(respCnt); |
| 375 | memcpy(resp->record_data, recordData, respCnt); |
| 376 | response->payload[PLDM_GET_PDR_MIN_RESP_BYTES + respCnt] = transferCRC; |
| 377 | |
| 378 | auto rc = decode_get_pdr_resp(response, responseMsg.size() - hdrSize, NULL, |
| 379 | NULL, NULL, NULL, NULL, NULL, 0, NULL); |
| 380 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 381 | |
| 382 | rc = decode_get_pdr_resp( |
| 383 | response, responseMsg.size() - hdrSize - 1, &retCompletionCode, |
| 384 | &retNextRecordHndl, &retNextDataTransferHndl, &retTransferFlag, |
| 385 | &retRespCnt, retRecordData, recordDataLength, &retTransferCRC); |
| 386 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 387 | } |
| 388 | |
| 389 | TEST(GetPDRRepositoryInfo, testGoodEncodeResponse) |
| 390 | { |
| 391 | uint8_t completionCode = 0; |
| 392 | uint8_t repositoryState = PLDM_AVAILABLE; |
| 393 | uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 394 | uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 395 | uint32_t recordCount = 100; |
| 396 | uint32_t repositorySize = 100; |
| 397 | uint32_t largestRecordSize = UINT32_MAX; |
| 398 | uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT; |
| 399 | |
| 400 | std::vector<uint8_t> responseMsg(hdrSize + |
| 401 | PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES); |
| 402 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 403 | |
| 404 | auto rc = encode_get_pdr_repository_info_resp( |
| 405 | 0, PLDM_SUCCESS, repositoryState, updateTime, oemUpdateTime, |
| 406 | recordCount, repositorySize, largestRecordSize, |
| 407 | dataTransferHandleTimeout, response); |
| 408 | |
| 409 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 410 | struct pldm_pdr_repository_info_resp* resp = |
| 411 | reinterpret_cast<struct pldm_pdr_repository_info_resp*>( |
| 412 | response->payload); |
| 413 | |
| 414 | EXPECT_EQ(completionCode, resp->completion_code); |
| 415 | EXPECT_EQ(repositoryState, resp->repository_state); |
| 416 | EXPECT_EQ(0, memcmp(updateTime, resp->update_time, PLDM_TIMESTAMP104_SIZE)); |
| 417 | EXPECT_EQ(0, memcmp(oemUpdateTime, resp->oem_update_time, |
| 418 | PLDM_TIMESTAMP104_SIZE)); |
| 419 | EXPECT_EQ(recordCount, le32toh(resp->record_count)); |
| 420 | EXPECT_EQ(repositorySize, le32toh(resp->repository_size)); |
| 421 | EXPECT_EQ(largestRecordSize, le32toh(resp->largest_record_size)); |
| 422 | EXPECT_EQ(dataTransferHandleTimeout, resp->data_transfer_handle_timeout); |
| 423 | } |
| 424 | |
| 425 | TEST(GetPDRRepositoryInfo, testBadEncodeResponse) |
| 426 | { |
| 427 | uint8_t repositoryState = PLDM_AVAILABLE; |
| 428 | uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 429 | uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 430 | uint32_t recordCount = 100; |
| 431 | uint32_t repositorySize = 100; |
| 432 | uint32_t largestRecordSize = UINT32_MAX; |
| 433 | uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT; |
| 434 | |
| 435 | auto rc = encode_get_pdr_repository_info_resp( |
| 436 | 0, PLDM_SUCCESS, repositoryState, updateTime, oemUpdateTime, |
| 437 | recordCount, repositorySize, largestRecordSize, |
| 438 | dataTransferHandleTimeout, nullptr); |
| 439 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 440 | } |
| 441 | |
Gilbert Chen | b7c73e5 | 2022-11-10 11:29:52 +0800 | [diff] [blame] | 442 | TEST(GetPDRRepositoryInfo, testGoodDecodeResponse) |
| 443 | { |
| 444 | uint8_t completionCode = PLDM_SUCCESS; |
| 445 | uint8_t repositoryState = PLDM_AVAILABLE; |
| 446 | uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 447 | uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 448 | uint32_t recordCount = 100; |
| 449 | uint32_t repositorySize = 100; |
| 450 | uint32_t largestRecordSize = UINT32_MAX; |
| 451 | uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT; |
| 452 | |
| 453 | std::array<uint8_t, hdrSize + PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES> |
| 454 | responseMsg{}; |
| 455 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 456 | struct pldm_pdr_repository_info_resp* resp = |
| 457 | reinterpret_cast<struct pldm_pdr_repository_info_resp*>( |
| 458 | response->payload); |
| 459 | resp->completion_code = completionCode; |
| 460 | resp->repository_state = repositoryState; |
| 461 | memcpy(resp->update_time, updateTime, PLDM_TIMESTAMP104_SIZE); |
| 462 | memcpy(resp->oem_update_time, oemUpdateTime, PLDM_TIMESTAMP104_SIZE); |
| 463 | resp->record_count = htole32(recordCount); |
| 464 | resp->repository_size = htole32(repositorySize); |
| 465 | resp->largest_record_size = htole32(largestRecordSize); |
| 466 | resp->data_transfer_handle_timeout = dataTransferHandleTimeout; |
| 467 | |
| 468 | uint8_t retCompletionCode = 0; |
| 469 | uint8_t retRepositoryState = 0; |
| 470 | uint8_t retUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 471 | uint8_t retOemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 472 | uint32_t retRecordCount = 0; |
| 473 | uint32_t retRepositorySize = 0; |
| 474 | uint32_t retLargestRecordSize = 0; |
| 475 | uint8_t retDataTransferHandleTimeout = 0; |
| 476 | |
| 477 | auto rc = decode_get_pdr_repository_info_resp( |
| 478 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 479 | &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount, |
| 480 | &retRepositorySize, &retLargestRecordSize, |
| 481 | &retDataTransferHandleTimeout); |
| 482 | |
| 483 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 484 | EXPECT_EQ(completionCode, retCompletionCode); |
| 485 | EXPECT_EQ(repositoryState, retRepositoryState); |
| 486 | EXPECT_EQ(0, memcmp(updateTime, retUpdateTime, PLDM_TIMESTAMP104_SIZE)); |
| 487 | EXPECT_EQ(0, |
| 488 | memcmp(oemUpdateTime, retOemUpdateTime, PLDM_TIMESTAMP104_SIZE)); |
| 489 | EXPECT_EQ(recordCount, recordCount); |
| 490 | EXPECT_EQ(repositorySize, repositorySize); |
| 491 | EXPECT_EQ(largestRecordSize, largestRecordSize); |
| 492 | EXPECT_EQ(dataTransferHandleTimeout, dataTransferHandleTimeout); |
| 493 | } |
| 494 | |
| 495 | TEST(GetPDRRepositoryInfo, testBadDecodeResponse) |
| 496 | { |
| 497 | uint8_t completionCode = PLDM_SUCCESS; |
| 498 | uint8_t repositoryState = PLDM_AVAILABLE; |
| 499 | uint8_t updateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 500 | uint8_t oemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 501 | uint32_t recordCount = htole32(100); |
| 502 | uint32_t repositorySize = htole32(100); |
| 503 | uint32_t largestRecordSize = htole32(UINT32_MAX); |
| 504 | uint8_t dataTransferHandleTimeout = PLDM_NO_TIMEOUT; |
| 505 | |
| 506 | std::array<uint8_t, hdrSize + PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES> |
| 507 | responseMsg{}; |
| 508 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 509 | struct pldm_pdr_repository_info_resp* resp = |
| 510 | reinterpret_cast<struct pldm_pdr_repository_info_resp*>( |
| 511 | response->payload); |
| 512 | resp->completion_code = completionCode; |
| 513 | resp->repository_state = repositoryState; |
| 514 | memcpy(resp->update_time, updateTime, PLDM_TIMESTAMP104_SIZE); |
| 515 | memcpy(resp->oem_update_time, oemUpdateTime, PLDM_TIMESTAMP104_SIZE); |
| 516 | resp->record_count = recordCount; |
| 517 | resp->repository_size = repositorySize; |
| 518 | resp->largest_record_size = largestRecordSize; |
| 519 | resp->data_transfer_handle_timeout = dataTransferHandleTimeout; |
| 520 | |
| 521 | uint8_t retCompletionCode = 0; |
| 522 | uint8_t retRepositoryState = 0; |
| 523 | uint8_t retUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 524 | uint8_t retOemUpdateTime[PLDM_TIMESTAMP104_SIZE] = {0}; |
| 525 | uint32_t retRecordCount = 0; |
| 526 | uint32_t retRepositorySize = 0; |
| 527 | uint32_t retLargestRecordSize = 0; |
| 528 | uint8_t retDataTransferHandleTimeout = 0; |
| 529 | |
| 530 | auto rc = decode_get_pdr_repository_info_resp( |
| 531 | response, responseMsg.size() - hdrSize, NULL, NULL, NULL, NULL, NULL, |
| 532 | NULL, NULL, NULL); |
| 533 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 534 | |
| 535 | rc = decode_get_pdr_repository_info_resp( |
| 536 | response, responseMsg.size() - hdrSize - 1, &retCompletionCode, |
| 537 | &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount, |
| 538 | &retRepositorySize, &retLargestRecordSize, |
| 539 | &retDataTransferHandleTimeout); |
| 540 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 541 | |
| 542 | resp->repository_state = PLDM_FAILED + 1; |
| 543 | rc = decode_get_pdr_repository_info_resp( |
| 544 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 545 | &retRepositoryState, retUpdateTime, retOemUpdateTime, &retRecordCount, |
| 546 | &retRepositorySize, &retLargestRecordSize, |
| 547 | &retDataTransferHandleTimeout); |
| 548 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 549 | } |
| 550 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 551 | TEST(SetNumericEffecterValue, testGoodDecodeRequest) |
| 552 | { |
| 553 | std::array<uint8_t, |
| 554 | hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3> |
| 555 | requestMsg{}; |
| 556 | |
| 557 | uint16_t effecter_id = 32768; |
| 558 | uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT32; |
| 559 | uint32_t effecter_value = 123456789; |
| 560 | |
| 561 | uint16_t reteffecter_id; |
| 562 | uint8_t reteffecter_data_size; |
| 563 | uint8_t reteffecter_value[4]; |
| 564 | |
| 565 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 566 | struct pldm_set_numeric_effecter_value_req* request = |
| 567 | reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>( |
| 568 | req->payload); |
| 569 | |
| 570 | request->effecter_id = htole16(effecter_id); |
| 571 | request->effecter_data_size = effecter_data_size; |
| 572 | uint32_t effecter_value_le = htole32(effecter_value); |
| 573 | memcpy(request->effecter_value, &effecter_value_le, |
| 574 | sizeof(effecter_value_le)); |
| 575 | |
| 576 | auto rc = decode_set_numeric_effecter_value_req( |
| 577 | req, requestMsg.size() - hdrSize, &reteffecter_id, |
| 578 | &reteffecter_data_size, reteffecter_value); |
| 579 | |
| 580 | uint32_t value = *(reinterpret_cast<uint32_t*>(reteffecter_value)); |
| 581 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 582 | EXPECT_EQ(reteffecter_id, effecter_id); |
| 583 | EXPECT_EQ(reteffecter_data_size, effecter_data_size); |
| 584 | EXPECT_EQ(value, effecter_value); |
| 585 | } |
| 586 | |
| 587 | TEST(SetNumericEffecterValue, testBadDecodeRequest) |
| 588 | { |
| 589 | std::array<uint8_t, hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES> |
| 590 | requestMsg{}; |
| 591 | |
| 592 | auto rc = decode_set_numeric_effecter_value_req( |
| 593 | NULL, requestMsg.size() - hdrSize, NULL, NULL, NULL); |
| 594 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 595 | |
| 596 | uint16_t effecter_id = 0x10; |
| 597 | uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT8; |
| 598 | uint8_t effecter_value = 1; |
| 599 | |
| 600 | uint16_t reteffecter_id; |
| 601 | uint8_t reteffecter_data_size; |
| 602 | uint8_t reteffecter_value[4]; |
| 603 | |
| 604 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 605 | struct pldm_set_numeric_effecter_value_req* request = |
| 606 | reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>( |
| 607 | req->payload); |
| 608 | |
| 609 | request->effecter_id = effecter_id; |
| 610 | request->effecter_data_size = effecter_data_size; |
| 611 | memcpy(request->effecter_value, &effecter_value, sizeof(effecter_value)); |
| 612 | |
| 613 | rc = decode_set_numeric_effecter_value_req( |
| 614 | req, requestMsg.size() - hdrSize - 1, &reteffecter_id, |
| 615 | &reteffecter_data_size, reinterpret_cast<uint8_t*>(&reteffecter_value)); |
| 616 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 617 | } |
| 618 | |
| 619 | TEST(SetNumericEffecterValue, testGoodEncodeRequest) |
| 620 | { |
| 621 | uint16_t effecter_id = 0; |
| 622 | uint8_t effecter_data_size = PLDM_EFFECTER_DATA_SIZE_UINT16; |
| 623 | uint16_t effecter_value = 65534; |
| 624 | |
| 625 | std::vector<uint8_t> requestMsg( |
| 626 | hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1); |
| 627 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 628 | |
| 629 | auto rc = encode_set_numeric_effecter_value_req( |
| 630 | 0, effecter_id, effecter_data_size, |
| 631 | reinterpret_cast<uint8_t*>(&effecter_value), request, |
| 632 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1); |
| 633 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 634 | |
| 635 | struct pldm_set_numeric_effecter_value_req* req = |
| 636 | reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>( |
| 637 | request->payload); |
| 638 | EXPECT_EQ(effecter_id, req->effecter_id); |
| 639 | EXPECT_EQ(effecter_data_size, req->effecter_data_size); |
| 640 | uint16_t* val = (uint16_t*)req->effecter_value; |
| 641 | *val = le16toh(*val); |
| 642 | EXPECT_EQ(effecter_value, *val); |
| 643 | } |
| 644 | |
| 645 | TEST(SetNumericEffecterValue, testBadEncodeRequest) |
| 646 | { |
| 647 | std::vector<uint8_t> requestMsg( |
| 648 | hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES); |
| 649 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 650 | |
| 651 | auto rc = encode_set_numeric_effecter_value_req( |
| 652 | 0, 0, 0, NULL, NULL, PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES); |
| 653 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 654 | |
| 655 | uint16_t effecter_value; |
| 656 | rc = encode_set_numeric_effecter_value_req( |
| 657 | 0, 0, 6, reinterpret_cast<uint8_t*>(&effecter_value), request, |
| 658 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES); |
| 659 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 660 | } |
| 661 | |
| 662 | TEST(SetNumericEffecterValue, testGoodDecodeResponse) |
| 663 | { |
| 664 | std::array<uint8_t, hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES> |
| 665 | responseMsg{}; |
| 666 | |
| 667 | uint8_t completion_code = 0xA0; |
| 668 | |
| 669 | uint8_t retcompletion_code; |
| 670 | |
| 671 | memcpy(responseMsg.data() + hdrSize, &completion_code, |
| 672 | sizeof(completion_code)); |
| 673 | |
| 674 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 675 | |
| 676 | auto rc = decode_set_numeric_effecter_value_resp( |
| 677 | response, responseMsg.size() - hdrSize, &retcompletion_code); |
| 678 | |
| 679 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 680 | EXPECT_EQ(completion_code, retcompletion_code); |
| 681 | } |
| 682 | |
| 683 | TEST(SetNumericEffecterValue, testBadDecodeResponse) |
| 684 | { |
| 685 | std::array<uint8_t, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES> |
| 686 | responseMsg{}; |
| 687 | |
| 688 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 689 | |
| 690 | auto rc = decode_set_numeric_effecter_value_resp(response, |
| 691 | responseMsg.size(), NULL); |
| 692 | |
| 693 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 694 | } |
| 695 | |
| 696 | TEST(SetNumericEffecterValue, testGoodEncodeResponse) |
| 697 | { |
| 698 | std::array<uint8_t, sizeof(pldm_msg_hdr) + |
| 699 | PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES> |
| 700 | responseMsg{}; |
| 701 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 702 | uint8_t completionCode = 0; |
| 703 | |
| 704 | auto rc = encode_set_numeric_effecter_value_resp( |
| 705 | 0, PLDM_SUCCESS, response, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES); |
| 706 | |
| 707 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 708 | EXPECT_EQ(completionCode, response->payload[0]); |
| 709 | } |
| 710 | |
| 711 | TEST(SetNumericEffecterValue, testBadEncodeResponse) |
| 712 | { |
| 713 | auto rc = encode_set_numeric_effecter_value_resp( |
| 714 | 0, PLDM_SUCCESS, NULL, PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES); |
| 715 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 716 | } |
| 717 | |
| 718 | TEST(GetStateSensorReadings, testGoodEncodeResponse) |
| 719 | { |
| 720 | std::array<uint8_t, hdrSize + |
| 721 | PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES + |
| 722 | sizeof(get_sensor_state_field) * 2> |
| 723 | responseMsg{}; |
| 724 | |
| 725 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 726 | uint8_t completionCode = 0; |
| 727 | uint8_t comp_sensorCnt = 0x2; |
| 728 | |
| 729 | std::array<get_sensor_state_field, 2> stateField{}; |
| 730 | stateField[0] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_NORMAL, |
| 731 | PLDM_SENSOR_WARNING, PLDM_SENSOR_UNKNOWN}; |
| 732 | stateField[1] = {PLDM_SENSOR_FAILED, PLDM_SENSOR_UPPERFATAL, |
| 733 | PLDM_SENSOR_UPPERCRITICAL, PLDM_SENSOR_FATAL}; |
| 734 | |
| 735 | auto rc = encode_get_state_sensor_readings_resp( |
| 736 | 0, PLDM_SUCCESS, comp_sensorCnt, stateField.data(), response); |
| 737 | |
| 738 | struct pldm_get_state_sensor_readings_resp* resp = |
| 739 | reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>( |
| 740 | response->payload); |
| 741 | |
| 742 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 743 | EXPECT_EQ(completionCode, resp->completion_code); |
| 744 | EXPECT_EQ(comp_sensorCnt, resp->comp_sensor_count); |
| 745 | EXPECT_EQ(stateField[0].sensor_op_state, resp->field->sensor_op_state); |
| 746 | EXPECT_EQ(stateField[0].present_state, resp->field->present_state); |
| 747 | EXPECT_EQ(stateField[0].previous_state, resp->field->previous_state); |
| 748 | EXPECT_EQ(stateField[0].event_state, resp->field->event_state); |
| 749 | EXPECT_EQ(stateField[1].sensor_op_state, resp->field[1].sensor_op_state); |
| 750 | EXPECT_EQ(stateField[1].present_state, resp->field[1].present_state); |
| 751 | EXPECT_EQ(stateField[1].previous_state, resp->field[1].previous_state); |
| 752 | EXPECT_EQ(stateField[1].event_state, resp->field[1].event_state); |
| 753 | } |
| 754 | |
| 755 | TEST(GetStateSensorReadings, testBadEncodeResponse) |
| 756 | { |
| 757 | auto rc = encode_get_state_sensor_readings_resp(0, PLDM_SUCCESS, 0, nullptr, |
| 758 | nullptr); |
| 759 | |
| 760 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 761 | } |
| 762 | |
| 763 | TEST(GetStateSensorReadings, testGoodDecodeResponse) |
| 764 | { |
| 765 | std::array<uint8_t, hdrSize + |
| 766 | PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES + |
| 767 | sizeof(get_sensor_state_field) * 2> |
| 768 | responseMsg{}; |
| 769 | |
| 770 | uint8_t completionCode = 0; |
| 771 | uint8_t comp_sensorCnt = 2; |
| 772 | |
| 773 | std::array<get_sensor_state_field, 2> stateField{}; |
| 774 | stateField[0] = {PLDM_SENSOR_DISABLED, PLDM_SENSOR_UNKNOWN, |
| 775 | PLDM_SENSOR_UNKNOWN, PLDM_SENSOR_UNKNOWN}; |
| 776 | stateField[1] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_LOWERFATAL, |
| 777 | PLDM_SENSOR_LOWERCRITICAL, PLDM_SENSOR_WARNING}; |
| 778 | |
| 779 | uint8_t retcompletion_code = 0; |
| 780 | uint8_t retcomp_sensorCnt = 0; |
| 781 | std::array<get_sensor_state_field, 2> retstateField{}; |
| 782 | |
| 783 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 784 | struct pldm_get_state_sensor_readings_resp* resp = |
| 785 | reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>( |
| 786 | response->payload); |
| 787 | |
| 788 | resp->completion_code = completionCode; |
| 789 | resp->comp_sensor_count = comp_sensorCnt; |
| 790 | memcpy(resp->field, &stateField, |
| 791 | (sizeof(get_sensor_state_field) * comp_sensorCnt)); |
| 792 | |
| 793 | auto rc = decode_get_state_sensor_readings_resp( |
| 794 | response, responseMsg.size() - hdrSize, &retcompletion_code, |
| 795 | &retcomp_sensorCnt, retstateField.data()); |
| 796 | |
| 797 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 798 | EXPECT_EQ(completionCode, retcompletion_code); |
| 799 | EXPECT_EQ(comp_sensorCnt, retcomp_sensorCnt); |
| 800 | EXPECT_EQ(stateField[0].sensor_op_state, retstateField[0].sensor_op_state); |
| 801 | EXPECT_EQ(stateField[0].present_state, retstateField[0].present_state); |
| 802 | EXPECT_EQ(stateField[0].previous_state, retstateField[0].previous_state); |
| 803 | EXPECT_EQ(stateField[0].event_state, retstateField[0].event_state); |
| 804 | EXPECT_EQ(stateField[1].sensor_op_state, retstateField[1].sensor_op_state); |
| 805 | EXPECT_EQ(stateField[1].present_state, retstateField[1].present_state); |
| 806 | EXPECT_EQ(stateField[1].previous_state, retstateField[1].previous_state); |
| 807 | EXPECT_EQ(stateField[1].event_state, retstateField[1].event_state); |
| 808 | } |
| 809 | |
| 810 | TEST(GetStateSensorReadings, testBadDecodeResponse) |
| 811 | { |
| 812 | std::array<uint8_t, hdrSize + |
| 813 | PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES + |
| 814 | sizeof(get_sensor_state_field) * 2> |
| 815 | responseMsg{}; |
| 816 | |
| 817 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 818 | |
| 819 | auto rc = decode_get_state_sensor_readings_resp( |
| 820 | response, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr); |
| 821 | |
| 822 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 823 | |
| 824 | uint8_t completionCode = 0; |
| 825 | uint8_t comp_sensorCnt = 1; |
| 826 | |
| 827 | std::array<get_sensor_state_field, 1> stateField{}; |
| 828 | stateField[0] = {PLDM_SENSOR_ENABLED, PLDM_SENSOR_UPPERFATAL, |
| 829 | PLDM_SENSOR_UPPERCRITICAL, PLDM_SENSOR_WARNING}; |
| 830 | |
| 831 | uint8_t retcompletion_code = 0; |
| 832 | uint8_t retcomp_sensorCnt = 0; |
| 833 | std::array<get_sensor_state_field, 1> retstateField{}; |
| 834 | |
| 835 | struct pldm_get_state_sensor_readings_resp* resp = |
| 836 | reinterpret_cast<struct pldm_get_state_sensor_readings_resp*>( |
| 837 | response->payload); |
| 838 | |
| 839 | resp->completion_code = completionCode; |
| 840 | resp->comp_sensor_count = comp_sensorCnt; |
| 841 | memcpy(resp->field, &stateField, |
| 842 | (sizeof(get_sensor_state_field) * comp_sensorCnt)); |
| 843 | |
| 844 | rc = decode_get_state_sensor_readings_resp( |
Andrew Jeffery | 6ad4dc0 | 2023-04-12 15:56:45 +0930 | [diff] [blame] | 845 | response, responseMsg.size() - hdrSize, &retcompletion_code, |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 846 | &retcomp_sensorCnt, retstateField.data()); |
| 847 | |
| 848 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 849 | } |
| 850 | |
| 851 | TEST(GetStateSensorReadings, testGoodEncodeRequest) |
| 852 | { |
| 853 | std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES> |
| 854 | requestMsg{}; |
| 855 | |
| 856 | uint16_t sensorId = 0xAB; |
| 857 | bitfield8_t sensorRearm; |
| 858 | sensorRearm.byte = 0x03; |
| 859 | |
| 860 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 861 | auto rc = encode_get_state_sensor_readings_req(0, sensorId, sensorRearm, 0, |
| 862 | request); |
| 863 | |
| 864 | struct pldm_get_state_sensor_readings_req* req = |
| 865 | reinterpret_cast<struct pldm_get_state_sensor_readings_req*>( |
| 866 | request->payload); |
| 867 | |
| 868 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 869 | EXPECT_EQ(sensorId, le16toh(req->sensor_id)); |
| 870 | EXPECT_EQ(sensorRearm.byte, req->sensor_rearm.byte); |
| 871 | } |
| 872 | |
| 873 | TEST(GetStateSensorReadings, testBadEncodeRequest) |
| 874 | { |
| 875 | bitfield8_t sensorRearm; |
| 876 | sensorRearm.byte = 0x0; |
| 877 | |
| 878 | auto rc = |
| 879 | encode_get_state_sensor_readings_req(0, 0, sensorRearm, 0, nullptr); |
| 880 | |
| 881 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 882 | } |
| 883 | |
| 884 | TEST(GetStateSensorReadings, testGoodDecodeRequest) |
| 885 | { |
| 886 | std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES> |
| 887 | requestMsg{}; |
| 888 | |
| 889 | uint16_t sensorId = 0xCD; |
| 890 | bitfield8_t sensorRearm; |
| 891 | sensorRearm.byte = 0x10; |
| 892 | |
| 893 | uint16_t retsensorId; |
| 894 | bitfield8_t retsensorRearm; |
| 895 | uint8_t retreserved; |
| 896 | |
| 897 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 898 | |
| 899 | struct pldm_get_state_sensor_readings_req* req = |
| 900 | reinterpret_cast<struct pldm_get_state_sensor_readings_req*>( |
| 901 | request->payload); |
| 902 | |
| 903 | req->sensor_id = htole16(sensorId); |
| 904 | req->sensor_rearm.byte = sensorRearm.byte; |
| 905 | |
| 906 | auto rc = decode_get_state_sensor_readings_req( |
| 907 | request, requestMsg.size() - hdrSize, &retsensorId, &retsensorRearm, |
| 908 | &retreserved); |
| 909 | |
| 910 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 911 | EXPECT_EQ(sensorId, retsensorId); |
| 912 | EXPECT_EQ(sensorRearm.byte, retsensorRearm.byte); |
| 913 | EXPECT_EQ(0, retreserved); |
| 914 | } |
| 915 | |
| 916 | TEST(GetStateSensorReadings, testBadDecodeRequest) |
| 917 | { |
| 918 | std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES> |
| 919 | requestMsg{}; |
| 920 | |
| 921 | auto rc = decode_get_state_sensor_readings_req( |
| 922 | nullptr, requestMsg.size() - hdrSize, nullptr, nullptr, nullptr); |
| 923 | |
| 924 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 925 | uint16_t sensorId = 0x11; |
| 926 | bitfield8_t sensorRearm; |
| 927 | sensorRearm.byte = 0x04; |
| 928 | |
| 929 | uint16_t retsensorId; |
| 930 | bitfield8_t retsensorRearm; |
| 931 | uint8_t retreserved; |
| 932 | |
| 933 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 934 | |
| 935 | struct pldm_get_state_sensor_readings_req* req = |
| 936 | reinterpret_cast<struct pldm_get_state_sensor_readings_req*>( |
| 937 | request->payload); |
| 938 | |
| 939 | req->sensor_id = htole16(sensorId); |
| 940 | req->sensor_rearm.byte = sensorRearm.byte; |
| 941 | |
| 942 | rc = decode_get_state_sensor_readings_req( |
| 943 | request, requestMsg.size() - hdrSize - 1, &retsensorId, &retsensorRearm, |
| 944 | &retreserved); |
| 945 | |
| 946 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 947 | } |
| 948 | |
Dung Cao | d6ae898 | 2022-11-02 10:00:10 +0700 | [diff] [blame] | 949 | TEST(EventMessageBufferSize, testGoodEventMessageBufferSizeRequest) |
| 950 | { |
| 951 | uint8_t eventBufferSize = 32; |
| 952 | |
| 953 | std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_REQ_BYTES> |
| 954 | requestMsg{}; |
| 955 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 956 | |
| 957 | auto rc = encode_event_message_buffer_size_req(0, eventBufferSize, request); |
| 958 | |
| 959 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 960 | } |
| 961 | |
| 962 | TEST(EventMessageBufferSize, testGoodEventMessageBufferSizeResponse) |
| 963 | { |
| 964 | uint8_t completionCode = PLDM_SUCCESS; |
| 965 | uint16_t terminusMaxBufferSize = 256; |
| 966 | |
| 967 | std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES> |
| 968 | responseMsg{}; |
| 969 | |
| 970 | uint8_t retCompletionCode; |
| 971 | uint16_t retMaxBufferSize = 0; |
| 972 | |
| 973 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 974 | struct pldm_event_message_buffer_size_resp* resp = |
| 975 | reinterpret_cast<struct pldm_event_message_buffer_size_resp*>( |
| 976 | response->payload); |
| 977 | |
| 978 | resp->completion_code = completionCode; |
| 979 | resp->terminus_max_buffer_size = terminusMaxBufferSize; |
| 980 | |
| 981 | auto rc = decode_event_message_buffer_size_resp( |
| 982 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 983 | &retMaxBufferSize); |
| 984 | |
| 985 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 986 | EXPECT_EQ(retCompletionCode, completionCode); |
| 987 | EXPECT_EQ(terminusMaxBufferSize, retMaxBufferSize); |
| 988 | } |
| 989 | |
| 990 | TEST(EventMessageBufferSize, testBadEventMessageBufferSizeResponse) |
| 991 | { |
| 992 | uint8_t completionCode = PLDM_SUCCESS; |
| 993 | uint16_t terminusMaxBufferSize = 256; |
| 994 | |
| 995 | std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES> |
| 996 | responseMsg{}; |
| 997 | |
| 998 | uint8_t retCompletionCode; |
| 999 | uint16_t retMaxBufferSize = 0; |
| 1000 | |
| 1001 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1002 | struct pldm_event_message_buffer_size_resp* resp = |
| 1003 | reinterpret_cast<struct pldm_event_message_buffer_size_resp*>( |
| 1004 | response->payload); |
| 1005 | resp->completion_code = completionCode; |
| 1006 | resp->terminus_max_buffer_size = terminusMaxBufferSize; |
| 1007 | |
| 1008 | auto rc = |
| 1009 | decode_event_message_buffer_size_resp(response, 0, nullptr, nullptr); |
| 1010 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1011 | |
| 1012 | rc = decode_event_message_buffer_size_resp( |
| 1013 | response, responseMsg.size(), &retCompletionCode, &retMaxBufferSize); |
| 1014 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1015 | } |
| 1016 | |
Dung Cao | 1bf8c87 | 2022-11-29 05:32:58 +0700 | [diff] [blame] | 1017 | TEST(PlatformEventMessageSupported, testGoodEncodeRequest) |
| 1018 | { |
| 1019 | uint8_t formatVersion = 0x01; |
| 1020 | |
| 1021 | std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_REQ_BYTES> |
| 1022 | requestMsg{}; |
| 1023 | |
| 1024 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1025 | |
| 1026 | auto rc = encode_event_message_supported_req(0, formatVersion, request); |
| 1027 | |
| 1028 | struct pldm_event_message_supported_req* req = |
| 1029 | reinterpret_cast<struct pldm_event_message_supported_req*>( |
| 1030 | request->payload); |
| 1031 | |
| 1032 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1033 | EXPECT_EQ(formatVersion, req->format_version); |
| 1034 | } |
| 1035 | |
| 1036 | TEST(PlatformEventMessageSupported, testBadEncodeRequest) |
| 1037 | { |
| 1038 | uint8_t eventData = 34; |
| 1039 | uint8_t formatVersion = 0x0; |
| 1040 | |
| 1041 | std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_REQ_BYTES + |
| 1042 | sizeof(eventData)> |
| 1043 | requestMsg{}; |
| 1044 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1045 | |
| 1046 | auto rc = encode_event_message_supported_req(0, formatVersion, request); |
| 1047 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1048 | |
| 1049 | rc = encode_event_message_supported_req(0, formatVersion, nullptr); |
| 1050 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1051 | } |
| 1052 | |
| 1053 | TEST(PlatformEventMessageSupported, testGoodDecodeRespond) |
| 1054 | { |
| 1055 | uint8_t completionCode = PLDM_SUCCESS; |
| 1056 | uint8_t synchConfiguration = PLDM_MESSAGE_TYPE_SYNCHRONOUS; |
| 1057 | bitfield8_t synchConfigSupported; |
| 1058 | synchConfigSupported.byte = 0xe; |
| 1059 | uint8_t numberEventClassReturned = 0x3; |
| 1060 | std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa}; |
| 1061 | constexpr uint8_t eventClassCount = 3; |
| 1062 | |
| 1063 | std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES + |
| 1064 | eventClassCount> |
| 1065 | responseMsg{}; |
| 1066 | |
| 1067 | uint8_t retCompletionCode; |
| 1068 | uint8_t retSynchConfig = 0; |
| 1069 | uint8_t retNumberEventClass = 0; |
| 1070 | bitfield8_t retSynchConfigSupport; |
| 1071 | uint8_t retEventClass[eventClassCount] = {0}; |
| 1072 | |
| 1073 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1074 | struct pldm_event_message_supported_resp* resp = |
| 1075 | reinterpret_cast<struct pldm_event_message_supported_resp*>( |
| 1076 | response->payload); |
| 1077 | |
| 1078 | resp->completion_code = completionCode; |
| 1079 | resp->synchrony_configuration = synchConfiguration; |
| 1080 | resp->synchrony_configuration_supported.byte = synchConfigSupported.byte; |
| 1081 | resp->number_event_class_returned = numberEventClassReturned; |
| 1082 | memcpy(resp->event_class, eventClass.data(), numberEventClassReturned); |
| 1083 | |
| 1084 | auto rc = decode_event_message_supported_resp( |
| 1085 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 1086 | &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass, |
| 1087 | retEventClass, eventClassCount); |
| 1088 | |
| 1089 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1090 | EXPECT_EQ(retCompletionCode, completionCode); |
| 1091 | EXPECT_EQ(retSynchConfig, synchConfiguration); |
| 1092 | EXPECT_EQ(retNumberEventClass, numberEventClassReturned); |
| 1093 | EXPECT_EQ(retSynchConfigSupport.byte, synchConfigSupported.byte); |
| 1094 | EXPECT_EQ(0, memcmp(eventClass.data(), resp->event_class, |
| 1095 | numberEventClassReturned)); |
| 1096 | } |
| 1097 | |
| 1098 | TEST(PlatformEventMessageSupported, testBadSynchConfiguration) |
| 1099 | { |
| 1100 | uint8_t completionCode = PLDM_SUCCESS; |
| 1101 | uint8_t synchConfiguration = 0x4; |
| 1102 | bitfield8_t synchConfigSupported; |
| 1103 | synchConfigSupported.byte = 0xe; |
| 1104 | uint8_t numberEventClassReturned = 0x3; |
| 1105 | std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa}; |
| 1106 | constexpr uint8_t eventClassCount = 3; |
| 1107 | |
| 1108 | std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES + |
| 1109 | eventClassCount> |
| 1110 | responseMsg{}; |
| 1111 | |
| 1112 | uint8_t retCompletionCode; |
| 1113 | uint8_t retSynchConfig = 0; |
| 1114 | uint8_t retNumberEventClass = 0; |
| 1115 | bitfield8_t retSynchConfigSupport; |
| 1116 | uint8_t retEventClass[eventClassCount] = {0}; |
| 1117 | |
| 1118 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1119 | struct pldm_event_message_supported_resp* resp = |
| 1120 | reinterpret_cast<struct pldm_event_message_supported_resp*>( |
| 1121 | response->payload); |
| 1122 | |
| 1123 | resp->completion_code = completionCode; |
| 1124 | resp->synchrony_configuration = synchConfiguration; |
| 1125 | resp->synchrony_configuration_supported.byte = synchConfigSupported.byte; |
| 1126 | resp->number_event_class_returned = numberEventClassReturned; |
| 1127 | memcpy(resp->event_class, eventClass.data(), numberEventClassReturned); |
| 1128 | |
| 1129 | auto rc = decode_event_message_supported_resp( |
| 1130 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 1131 | &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass, |
| 1132 | retEventClass, eventClassCount); |
| 1133 | |
| 1134 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1135 | } |
| 1136 | |
| 1137 | TEST(PlatformEventMessageSupported, testBadDecodeRespond) |
| 1138 | { |
| 1139 | uint8_t completionCode = PLDM_SUCCESS; |
| 1140 | uint8_t synchConfiguration = PLDM_MESSAGE_TYPE_SYNCHRONOUS; |
| 1141 | bitfield8_t synchConfigSupported; |
| 1142 | synchConfigSupported.byte = 0xe; |
| 1143 | uint8_t numberEventClassReturned = 0x3; |
| 1144 | std::vector<uint8_t> eventClass{0x0, 0x5, 0xfa}; |
| 1145 | constexpr uint8_t eventClassCount = 3; |
| 1146 | |
| 1147 | std::array<uint8_t, hdrSize + PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES + |
| 1148 | eventClassCount> |
| 1149 | responseMsg{}; |
| 1150 | |
| 1151 | uint8_t retCompletionCode; |
| 1152 | uint8_t retSynchConfig = 0; |
| 1153 | uint8_t retNumberEventClass = 0; |
| 1154 | bitfield8_t retSynchConfigSupport; |
| 1155 | uint8_t retEventClass[eventClassCount] = {0}; |
| 1156 | |
| 1157 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1158 | struct pldm_event_message_supported_resp* resp = |
| 1159 | reinterpret_cast<struct pldm_event_message_supported_resp*>( |
| 1160 | response->payload); |
| 1161 | resp->completion_code = completionCode; |
| 1162 | resp->synchrony_configuration = synchConfiguration; |
| 1163 | resp->synchrony_configuration_supported.byte = synchConfigSupported.byte; |
| 1164 | resp->number_event_class_returned = numberEventClassReturned; |
| 1165 | memcpy(resp->event_class, eventClass.data(), numberEventClassReturned); |
| 1166 | |
| 1167 | auto rc = decode_event_message_supported_resp(response, 0, nullptr, nullptr, |
| 1168 | nullptr, nullptr, nullptr, 0); |
| 1169 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1170 | |
| 1171 | rc = decode_event_message_supported_resp( |
| 1172 | response, PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES - 1, |
| 1173 | &retCompletionCode, &retSynchConfig, &retSynchConfigSupport, |
| 1174 | &retNumberEventClass, retEventClass, eventClassCount); |
| 1175 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1176 | |
| 1177 | rc = decode_event_message_supported_resp( |
| 1178 | response, responseMsg.size() - hdrSize, &retCompletionCode, |
| 1179 | &retSynchConfig, &retSynchConfigSupport, &retNumberEventClass, |
| 1180 | retEventClass, 1); |
| 1181 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1182 | } |
| 1183 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1184 | TEST(PlatformEventMessage, testGoodStateSensorDecodeRequest) |
| 1185 | { |
| 1186 | std::array<uint8_t, |
| 1187 | hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + |
| 1188 | PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES> |
| 1189 | requestMsg{}; |
| 1190 | |
| 1191 | uint8_t retFormatVersion = 0; |
| 1192 | uint8_t retTid = 0; |
| 1193 | uint8_t retEventClass = 0; |
| 1194 | size_t retEventDataOffset = 0; |
| 1195 | |
| 1196 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1197 | struct pldm_platform_event_message_req* request = |
| 1198 | reinterpret_cast<struct pldm_platform_event_message_req*>(req->payload); |
| 1199 | |
| 1200 | uint8_t formatVersion = 0x01; |
| 1201 | uint8_t tid = 0x02; |
| 1202 | // Sensor Event |
| 1203 | uint8_t eventClass = 0x00; |
| 1204 | |
| 1205 | request->format_version = formatVersion; |
| 1206 | request->tid = tid; |
| 1207 | request->event_class = eventClass; |
| 1208 | size_t eventDataOffset = |
| 1209 | sizeof(formatVersion) + sizeof(tid) + sizeof(eventClass); |
| 1210 | |
| 1211 | auto rc = decode_platform_event_message_req( |
| 1212 | req, requestMsg.size() - hdrSize, &retFormatVersion, &retTid, |
| 1213 | &retEventClass, &retEventDataOffset); |
| 1214 | |
| 1215 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1216 | EXPECT_EQ(retFormatVersion, formatVersion); |
| 1217 | EXPECT_EQ(retTid, tid); |
| 1218 | EXPECT_EQ(retEventClass, eventClass); |
| 1219 | EXPECT_EQ(retEventDataOffset, eventDataOffset); |
| 1220 | } |
| 1221 | |
| 1222 | TEST(PlatformEventMessage, testBadDecodeRequest) |
| 1223 | { |
| 1224 | const struct pldm_msg* msg = NULL; |
| 1225 | std::array<uint8_t, |
| 1226 | hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + |
| 1227 | PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES - 1> |
| 1228 | requestMsg{}; |
| 1229 | auto req = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1230 | uint8_t retFormatVersion; |
| 1231 | uint8_t retTid = 0; |
| 1232 | uint8_t retEventClass = 0; |
| 1233 | size_t retEventDataOffset; |
| 1234 | |
| 1235 | auto rc = decode_platform_event_message_req(msg, sizeof(*msg), NULL, NULL, |
| 1236 | NULL, NULL); |
| 1237 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1238 | |
| 1239 | rc = decode_platform_event_message_req( |
| 1240 | req, |
| 1241 | requestMsg.size() - hdrSize - |
| 1242 | PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES, |
| 1243 | &retFormatVersion, &retTid, &retEventClass, &retEventDataOffset); |
| 1244 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1245 | } |
| 1246 | |
| 1247 | TEST(PlatformEventMessage, testGoodEncodeResponse) |
| 1248 | { |
| 1249 | std::array<uint8_t, |
| 1250 | hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + |
| 1251 | PLDM_PLATFORM_EVENT_MESSAGE_STATE_SENSOR_STATE_REQ_BYTES - 1> |
| 1252 | responseMsg{}; |
| 1253 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1254 | uint8_t completionCode = 0; |
| 1255 | uint8_t instanceId = 0x01; |
| 1256 | uint8_t platformEventStatus = 0x01; |
| 1257 | |
| 1258 | auto rc = encode_platform_event_message_resp(instanceId, PLDM_SUCCESS, |
| 1259 | platformEventStatus, response); |
| 1260 | |
| 1261 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1262 | EXPECT_EQ(completionCode, response->payload[0]); |
| 1263 | EXPECT_EQ(platformEventStatus, response->payload[1]); |
| 1264 | } |
| 1265 | |
| 1266 | TEST(PlatformEventMessage, testBadEncodeResponse) |
| 1267 | { |
| 1268 | auto rc = encode_platform_event_message_resp(0, PLDM_SUCCESS, 1, NULL); |
| 1269 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1270 | } |
| 1271 | |
| 1272 | TEST(PlatformEventMessage, testGoodEncodeRequest) |
| 1273 | { |
| 1274 | uint8_t formatVersion = 0x01; |
| 1275 | uint8_t Tid = 0x03; |
| 1276 | uint8_t eventClass = 0x00; |
| 1277 | uint8_t eventData = 34; |
| 1278 | |
| 1279 | std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + |
| 1280 | sizeof(eventData)> |
| 1281 | requestMsg{}; |
| 1282 | |
| 1283 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1284 | auto rc = encode_platform_event_message_req( |
| 1285 | 0, formatVersion, Tid, eventClass, |
| 1286 | reinterpret_cast<uint8_t*>(&eventData), sizeof(eventData), request, |
| 1287 | sizeof(eventData) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES); |
| 1288 | |
| 1289 | struct pldm_platform_event_message_req* req = |
| 1290 | reinterpret_cast<struct pldm_platform_event_message_req*>( |
| 1291 | request->payload); |
| 1292 | |
| 1293 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1294 | EXPECT_EQ(formatVersion, req->format_version); |
| 1295 | EXPECT_EQ(Tid, req->tid); |
| 1296 | EXPECT_EQ(eventClass, req->event_class); |
| 1297 | EXPECT_EQ(0, memcmp(&eventData, req->event_data, sizeof(eventData))); |
| 1298 | } |
| 1299 | |
| 1300 | TEST(PlatformEventMessage, testBadEncodeRequest) |
| 1301 | { |
| 1302 | uint8_t Tid = 0x03; |
| 1303 | uint8_t eventClass = 0x00; |
| 1304 | uint8_t eventData = 34; |
| 1305 | size_t sz_eventData = sizeof(eventData); |
| 1306 | size_t payloadLen = |
| 1307 | sz_eventData + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES; |
| 1308 | uint8_t formatVersion = 0x01; |
| 1309 | |
| 1310 | std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + |
| 1311 | sizeof(eventData)> |
| 1312 | requestMsg{}; |
| 1313 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1314 | |
| 1315 | auto rc = encode_platform_event_message_req( |
| 1316 | 0, formatVersion, Tid, eventClass, |
| 1317 | reinterpret_cast<uint8_t*>(&eventData), sz_eventData, nullptr, |
| 1318 | payloadLen); |
| 1319 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1320 | rc = encode_platform_event_message_req( |
| 1321 | 0, 0, Tid, eventClass, reinterpret_cast<uint8_t*>(&eventData), |
| 1322 | sz_eventData, request, payloadLen); |
| 1323 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1324 | rc = encode_platform_event_message_req(0, formatVersion, Tid, eventClass, |
| 1325 | nullptr, 0, request, payloadLen); |
| 1326 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1327 | rc = encode_platform_event_message_req( |
| 1328 | 0, formatVersion, Tid, eventClass, |
| 1329 | reinterpret_cast<uint8_t*>(&eventData), sz_eventData, request, 0); |
| 1330 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1331 | } |
| 1332 | |
| 1333 | TEST(PlatformEventMessage, testGoodDecodeResponse) |
| 1334 | { |
| 1335 | std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES> |
| 1336 | responseMsg{}; |
| 1337 | |
| 1338 | uint8_t completionCode = PLDM_SUCCESS; |
| 1339 | uint8_t platformEventStatus = 0x01; |
| 1340 | |
| 1341 | uint8_t retcompletionCode; |
| 1342 | uint8_t retplatformEventStatus; |
| 1343 | |
| 1344 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1345 | struct pldm_platform_event_message_resp* resp = |
| 1346 | reinterpret_cast<struct pldm_platform_event_message_resp*>( |
| 1347 | response->payload); |
| 1348 | |
| 1349 | resp->completion_code = completionCode; |
| 1350 | resp->platform_event_status = platformEventStatus; |
| 1351 | |
| 1352 | auto rc = decode_platform_event_message_resp( |
| 1353 | response, responseMsg.size() - hdrSize, &retcompletionCode, |
| 1354 | &retplatformEventStatus); |
| 1355 | |
| 1356 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1357 | EXPECT_EQ(completionCode, retcompletionCode); |
| 1358 | EXPECT_EQ(platformEventStatus, retplatformEventStatus); |
| 1359 | } |
| 1360 | |
| 1361 | TEST(PlatformEventMessage, testBadDecodeResponse) |
| 1362 | { |
| 1363 | std::array<uint8_t, hdrSize + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES> |
| 1364 | responseMsg{}; |
| 1365 | |
| 1366 | uint8_t completionCode = PLDM_SUCCESS; |
| 1367 | uint8_t platformEventStatus = 0x01; |
| 1368 | |
| 1369 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1370 | struct pldm_platform_event_message_resp* resp = |
| 1371 | reinterpret_cast<struct pldm_platform_event_message_resp*>( |
| 1372 | response->payload); |
| 1373 | resp->completion_code = completionCode; |
| 1374 | resp->platform_event_status = platformEventStatus; |
| 1375 | |
| 1376 | auto rc = decode_platform_event_message_resp( |
| 1377 | nullptr, responseMsg.size() - hdrSize, nullptr, nullptr); |
| 1378 | |
| 1379 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1380 | |
| 1381 | rc = decode_platform_event_message_resp( |
| 1382 | response, responseMsg.size() - hdrSize - 1, &completionCode, |
| 1383 | &platformEventStatus); |
| 1384 | |
| 1385 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1386 | } |
| 1387 | |
| 1388 | TEST(PlatformEventMessage, testGoodSensorEventDataDecodeRequest) |
| 1389 | { |
| 1390 | std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH + |
| 1391 | PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES> |
| 1392 | eventDataArr{}; |
| 1393 | uint16_t sensorId = 0x1234; |
| 1394 | uint8_t sensorEventClassType = PLDM_SENSOR_OP_STATE; |
| 1395 | |
| 1396 | struct pldm_sensor_event_data* eventData = |
| 1397 | (struct pldm_sensor_event_data*)eventDataArr.data(); |
| 1398 | eventData->sensor_id = sensorId; |
| 1399 | eventData->sensor_event_class_type = sensorEventClassType; |
| 1400 | |
| 1401 | size_t retSensorOpDataOffset; |
| 1402 | uint16_t retSensorId = 0; |
| 1403 | uint8_t retSensorEventClassType; |
| 1404 | size_t sensorOpDataOffset = sizeof(sensorId) + sizeof(sensorEventClassType); |
| 1405 | auto rc = decode_sensor_event_data( |
| 1406 | reinterpret_cast<uint8_t*>(eventData), eventDataArr.size(), |
| 1407 | &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset); |
| 1408 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1409 | EXPECT_EQ(retSensorId, sensorId); |
| 1410 | EXPECT_EQ(retSensorEventClassType, sensorEventClassType); |
| 1411 | EXPECT_EQ(retSensorOpDataOffset, sensorOpDataOffset); |
| 1412 | } |
| 1413 | |
| 1414 | TEST(PlatformEventMessage, testBadSensorEventDataDecodeRequest) |
| 1415 | { |
| 1416 | |
| 1417 | std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH + |
| 1418 | PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES> |
| 1419 | eventDataArr{}; |
| 1420 | |
| 1421 | struct pldm_sensor_event_data* eventData = |
| 1422 | (struct pldm_sensor_event_data*)eventDataArr.data(); |
| 1423 | |
| 1424 | size_t retSensorOpDataOffset; |
| 1425 | uint16_t retSensorId = 0; |
| 1426 | uint8_t retSensorEventClassType; |
| 1427 | auto rc = decode_sensor_event_data(NULL, eventDataArr.size(), &retSensorId, |
| 1428 | &retSensorEventClassType, |
| 1429 | &retSensorOpDataOffset); |
| 1430 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1431 | |
| 1432 | rc = decode_sensor_event_data( |
| 1433 | reinterpret_cast<uint8_t*>(eventDataArr.data()), |
| 1434 | eventDataArr.size() - |
| 1435 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH, |
| 1436 | &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset); |
| 1437 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1438 | |
| 1439 | eventData->sensor_event_class_type = PLDM_SENSOR_OP_STATE; |
| 1440 | |
| 1441 | rc = decode_sensor_event_data( |
| 1442 | reinterpret_cast<uint8_t*>(eventDataArr.data()), eventDataArr.size(), |
| 1443 | &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset); |
| 1444 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1445 | |
| 1446 | eventData->sensor_event_class_type = PLDM_STATE_SENSOR_STATE; |
| 1447 | rc = decode_sensor_event_data( |
| 1448 | reinterpret_cast<uint8_t*>(eventDataArr.data()), eventDataArr.size(), |
| 1449 | &retSensorId, &retSensorEventClassType, &retSensorOpDataOffset); |
| 1450 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1451 | |
| 1452 | eventData->sensor_event_class_type = PLDM_NUMERIC_SENSOR_STATE; |
| 1453 | rc = decode_sensor_event_data( |
| 1454 | reinterpret_cast<uint8_t*>(eventDataArr.data()), |
| 1455 | eventDataArr.size() + 1, &retSensorId, &retSensorEventClassType, |
| 1456 | &retSensorOpDataOffset); |
| 1457 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1458 | } |
| 1459 | |
| 1460 | TEST(PlatformEventMessage, testGoodSensorOpEventDataDecodeRequest) |
| 1461 | { |
| 1462 | std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH> |
| 1463 | eventDataArr{}; |
| 1464 | |
| 1465 | struct pldm_sensor_event_sensor_op_state* sensorData = |
| 1466 | (struct pldm_sensor_event_sensor_op_state*)eventDataArr.data(); |
| 1467 | uint8_t presentState = PLDM_SENSOR_ENABLED; |
| 1468 | uint8_t previousState = PLDM_SENSOR_INITIALIZING; |
| 1469 | sensorData->present_op_state = presentState; |
| 1470 | sensorData->previous_op_state = previousState; |
| 1471 | |
| 1472 | uint8_t retPresentState; |
| 1473 | uint8_t retPreviousState; |
| 1474 | auto rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData), |
| 1475 | eventDataArr.size(), &retPresentState, |
| 1476 | &retPreviousState); |
| 1477 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1478 | EXPECT_EQ(retPresentState, presentState); |
| 1479 | EXPECT_EQ(retPreviousState, previousState); |
| 1480 | } |
| 1481 | |
| 1482 | TEST(PlatformEventMessage, testBadSensorOpEventDataDecodeRequest) |
| 1483 | { |
| 1484 | uint8_t presentOpState; |
| 1485 | uint8_t previousOpState; |
| 1486 | size_t sensorDataLength = PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH; |
| 1487 | auto rc = decode_sensor_op_data(NULL, sensorDataLength, &presentOpState, |
| 1488 | &previousOpState); |
| 1489 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1490 | |
| 1491 | std::array<uint8_t, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH> |
| 1492 | sensorData{}; |
| 1493 | rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData.data()), |
| 1494 | sensorDataLength + 1, &presentOpState, |
| 1495 | &previousOpState); |
| 1496 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1497 | |
| 1498 | rc = decode_sensor_op_data(reinterpret_cast<uint8_t*>(sensorData.data()), |
| 1499 | sensorDataLength, nullptr, &previousOpState); |
| 1500 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1501 | } |
| 1502 | |
| 1503 | TEST(PlatformEventMessage, testGoodSensorStateEventDataDecodeRequest) |
| 1504 | { |
| 1505 | std::array<uint8_t, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH> |
| 1506 | eventDataArr{}; |
| 1507 | |
| 1508 | struct pldm_sensor_event_state_sensor_state* sensorData = |
| 1509 | (struct pldm_sensor_event_state_sensor_state*)eventDataArr.data(); |
| 1510 | uint8_t sensorOffset = 0x02; |
| 1511 | uint8_t eventState = PLDM_SENSOR_SHUTTINGDOWN; |
| 1512 | uint8_t previousEventState = PLDM_SENSOR_INTEST; |
| 1513 | sensorData->sensor_offset = sensorOffset; |
| 1514 | sensorData->event_state = eventState; |
| 1515 | sensorData->previous_event_state = previousEventState; |
| 1516 | |
| 1517 | uint8_t retSensorOffset; |
| 1518 | uint8_t retEventState; |
| 1519 | uint8_t retPreviousState; |
| 1520 | auto rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData), |
| 1521 | eventDataArr.size(), &retSensorOffset, |
| 1522 | &retEventState, &retPreviousState); |
| 1523 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1524 | EXPECT_EQ(retSensorOffset, sensorOffset); |
| 1525 | EXPECT_EQ(retEventState, eventState); |
| 1526 | EXPECT_EQ(retPreviousState, previousEventState); |
| 1527 | } |
| 1528 | |
| 1529 | TEST(PlatformEventMessage, testBadStateSensorEventDataDecodeRequest) |
| 1530 | { |
| 1531 | uint8_t sensorOffset; |
| 1532 | uint8_t eventState; |
| 1533 | uint8_t previousEventState; |
| 1534 | size_t sensorDataLength = PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH; |
| 1535 | auto rc = decode_state_sensor_data(NULL, sensorDataLength, &sensorOffset, |
| 1536 | &eventState, &previousEventState); |
| 1537 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1538 | |
| 1539 | std::array<uint8_t, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH> |
| 1540 | sensorData{}; |
| 1541 | rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData.data()), |
| 1542 | sensorDataLength - 1, &sensorOffset, |
| 1543 | &eventState, &previousEventState); |
| 1544 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1545 | |
| 1546 | rc = decode_state_sensor_data(reinterpret_cast<uint8_t*>(sensorData.data()), |
| 1547 | sensorDataLength, &sensorOffset, nullptr, |
| 1548 | &previousEventState); |
| 1549 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1550 | } |
| 1551 | |
| 1552 | TEST(PlatformEventMessage, testGoodNumericSensorEventDataDecodeRequest) |
| 1553 | { |
| 1554 | std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH> |
| 1555 | eventDataArr{}; |
| 1556 | struct pldm_sensor_event_numeric_sensor_state* sensorData = |
| 1557 | (struct pldm_sensor_event_numeric_sensor_state*)eventDataArr.data(); |
| 1558 | |
| 1559 | size_t sensorDataLength = |
| 1560 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_32BIT_DATA_LENGTH; |
| 1561 | uint8_t eventState = PLDM_SENSOR_SHUTTINGDOWN; |
| 1562 | uint8_t previousEventState = PLDM_SENSOR_INTEST; |
| 1563 | uint8_t sensorDataSize = PLDM_SENSOR_DATA_SIZE_UINT32; |
| 1564 | uint32_t presentReading = 305441741; |
| 1565 | sensorData->event_state = eventState; |
| 1566 | sensorData->previous_event_state = previousEventState; |
| 1567 | sensorData->sensor_data_size = sensorDataSize; |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1568 | { |
| 1569 | uint32_t presentReadingLE = htole32(presentReading); |
| 1570 | memcpy(&sensorData->present_reading, &presentReadingLE, |
| 1571 | sizeof(presentReadingLE)); |
| 1572 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1573 | |
| 1574 | uint8_t retEventState; |
| 1575 | uint8_t retPreviousEventState; |
| 1576 | uint8_t retSensorDataSize; |
| 1577 | uint32_t retPresentReading; |
| 1578 | |
| 1579 | auto rc = decode_numeric_sensor_data( |
| 1580 | reinterpret_cast<uint8_t*>(sensorData), sensorDataLength, |
| 1581 | &retEventState, &retPreviousEventState, &retSensorDataSize, |
| 1582 | &retPresentReading); |
| 1583 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1584 | EXPECT_EQ(retEventState, eventState); |
| 1585 | EXPECT_EQ(retPreviousEventState, previousEventState); |
| 1586 | EXPECT_EQ(retSensorDataSize, sensorDataSize); |
| 1587 | EXPECT_EQ(retPresentReading, presentReading); |
| 1588 | |
| 1589 | int16_t presentReadingNew = -31432; |
Andrew Jeffery | 92f6c3c | 2023-04-13 15:50:10 +0930 | [diff] [blame] | 1590 | { |
| 1591 | int16_t presentReadingNewLE = htole16(presentReadingNew); |
| 1592 | memcpy(&sensorData->present_reading, &presentReadingNewLE, |
| 1593 | sizeof(presentReadingNewLE)); |
| 1594 | } |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1595 | sensorDataSize = PLDM_SENSOR_DATA_SIZE_SINT16; |
| 1596 | sensorData->sensor_data_size = sensorDataSize; |
| 1597 | sensorDataLength = PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_16BIT_DATA_LENGTH; |
| 1598 | |
| 1599 | rc = decode_numeric_sensor_data(reinterpret_cast<uint8_t*>(sensorData), |
| 1600 | sensorDataLength, &retEventState, |
| 1601 | &retPreviousEventState, &retSensorDataSize, |
| 1602 | &retPresentReading); |
| 1603 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1604 | EXPECT_EQ(retEventState, eventState); |
| 1605 | EXPECT_EQ(retPreviousEventState, previousEventState); |
| 1606 | EXPECT_EQ(retSensorDataSize, sensorDataSize); |
| 1607 | EXPECT_EQ(static_cast<int16_t>(retPresentReading), presentReadingNew); |
| 1608 | } |
| 1609 | |
| 1610 | TEST(PlatformEventMessage, testBadNumericSensorEventDataDecodeRequest) |
| 1611 | { |
| 1612 | uint8_t eventState; |
| 1613 | uint8_t previousEventState; |
| 1614 | uint8_t sensorDataSize; |
| 1615 | uint32_t presentReading; |
| 1616 | size_t sensorDataLength = |
| 1617 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH; |
| 1618 | auto rc = decode_numeric_sensor_data(NULL, sensorDataLength, &eventState, |
| 1619 | &previousEventState, &sensorDataSize, |
| 1620 | &presentReading); |
| 1621 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1622 | |
| 1623 | std::array<uint8_t, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH> |
| 1624 | sensorData{}; |
| 1625 | rc = decode_numeric_sensor_data( |
| 1626 | reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength - 1, |
| 1627 | &eventState, &previousEventState, &sensorDataSize, &presentReading); |
| 1628 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1629 | |
| 1630 | struct pldm_sensor_event_numeric_sensor_state* numericSensorData = |
| 1631 | (struct pldm_sensor_event_numeric_sensor_state*)sensorData.data(); |
| 1632 | numericSensorData->sensor_data_size = PLDM_SENSOR_DATA_SIZE_UINT8; |
| 1633 | rc = decode_numeric_sensor_data( |
| 1634 | reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength, |
| 1635 | &eventState, &previousEventState, &sensorDataSize, &presentReading); |
| 1636 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1637 | |
| 1638 | numericSensorData->sensor_data_size = PLDM_SENSOR_DATA_SIZE_UINT16; |
| 1639 | rc = decode_numeric_sensor_data( |
| 1640 | reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength, |
| 1641 | &eventState, &previousEventState, &sensorDataSize, &presentReading); |
| 1642 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1643 | |
| 1644 | numericSensorData->sensor_data_size = PLDM_SENSOR_DATA_SIZE_UINT32; |
| 1645 | rc = decode_numeric_sensor_data( |
| 1646 | reinterpret_cast<uint8_t*>(sensorData.data()), sensorDataLength - 1, |
| 1647 | &eventState, &previousEventState, &sensorDataSize, &presentReading); |
| 1648 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1649 | } |
| 1650 | |
| 1651 | TEST(GetNumericEffecterValue, testGoodEncodeRequest) |
| 1652 | { |
| 1653 | std::vector<uint8_t> requestMsg(hdrSize + |
| 1654 | PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES); |
| 1655 | |
| 1656 | uint16_t effecter_id = 0xAB01; |
| 1657 | |
| 1658 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1659 | |
| 1660 | auto rc = encode_get_numeric_effecter_value_req(0, effecter_id, request); |
| 1661 | |
| 1662 | struct pldm_get_numeric_effecter_value_req* req = |
| 1663 | reinterpret_cast<struct pldm_get_numeric_effecter_value_req*>( |
| 1664 | request->payload); |
| 1665 | |
| 1666 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1667 | EXPECT_EQ(effecter_id, le16toh(req->effecter_id)); |
| 1668 | } |
| 1669 | |
| 1670 | TEST(GetNumericEffecterValue, testBadEncodeRequest) |
| 1671 | { |
| 1672 | std::vector<uint8_t> requestMsg( |
| 1673 | hdrSize + PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES); |
| 1674 | |
| 1675 | auto rc = encode_get_numeric_effecter_value_req(0, 0, nullptr); |
| 1676 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1677 | } |
| 1678 | |
| 1679 | TEST(GetNumericEffecterValue, testGoodDecodeRequest) |
| 1680 | { |
| 1681 | std::array<uint8_t, hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES> |
| 1682 | requestMsg{}; |
| 1683 | |
| 1684 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1685 | struct pldm_get_numeric_effecter_value_req* req = |
| 1686 | reinterpret_cast<struct pldm_get_numeric_effecter_value_req*>( |
| 1687 | request->payload); |
| 1688 | |
| 1689 | uint16_t effecter_id = 0x12AB; |
| 1690 | req->effecter_id = htole16(effecter_id); |
| 1691 | |
| 1692 | uint16_t reteffecter_id; |
| 1693 | |
| 1694 | auto rc = decode_get_numeric_effecter_value_req( |
| 1695 | request, requestMsg.size() - hdrSize, &reteffecter_id); |
| 1696 | |
| 1697 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1698 | EXPECT_EQ(effecter_id, reteffecter_id); |
| 1699 | } |
| 1700 | |
| 1701 | TEST(GetNumericEffecterValue, testBadDecodeRequest) |
| 1702 | { |
| 1703 | std::array<uint8_t, hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES> |
| 1704 | requestMsg{}; |
| 1705 | |
| 1706 | auto rc = decode_get_numeric_effecter_value_req( |
| 1707 | nullptr, requestMsg.size() - hdrSize, nullptr); |
| 1708 | |
| 1709 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1710 | |
| 1711 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1712 | struct pldm_set_numeric_effecter_value_req* req = |
| 1713 | reinterpret_cast<struct pldm_set_numeric_effecter_value_req*>( |
| 1714 | request->payload); |
| 1715 | |
| 1716 | uint16_t effecter_id = 0x1A; |
| 1717 | req->effecter_id = htole16(effecter_id); |
| 1718 | uint16_t reteffecter_id; |
| 1719 | |
| 1720 | rc = decode_get_numeric_effecter_value_req( |
| 1721 | request, requestMsg.size() - hdrSize - 1, &reteffecter_id); |
| 1722 | |
| 1723 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1724 | } |
| 1725 | |
| 1726 | TEST(GetNumericEffecterValue, testGoodEncodeResponse) |
| 1727 | { |
| 1728 | uint8_t completionCode = 0; |
| 1729 | uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT32; |
| 1730 | uint8_t effecter_operState = EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING; |
| 1731 | uint32_t pendingValue = 0x12345678; |
| 1732 | uint32_t presentValue = 0xABCDEF11; |
Andrew Jeffery | f990dcf | 2023-04-12 20:54:48 +0930 | [diff] [blame] | 1733 | uint32_t val_pending; |
| 1734 | uint32_t val_present; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1735 | |
| 1736 | std::array<uint8_t, |
| 1737 | hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6> |
| 1738 | responseMsg{}; |
| 1739 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1740 | |
| 1741 | auto rc = encode_get_numeric_effecter_value_resp( |
| 1742 | 0, completionCode, effecter_dataSize, effecter_operState, |
| 1743 | reinterpret_cast<uint8_t*>(&pendingValue), |
| 1744 | reinterpret_cast<uint8_t*>(&presentValue), response, |
| 1745 | responseMsg.size() - hdrSize); |
| 1746 | |
| 1747 | struct pldm_get_numeric_effecter_value_resp* resp = |
| 1748 | reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>( |
| 1749 | response->payload); |
| 1750 | |
Andrew Jeffery | f990dcf | 2023-04-12 20:54:48 +0930 | [diff] [blame] | 1751 | memcpy(&val_pending, &resp->pending_and_present_values[0], |
| 1752 | sizeof(val_pending)); |
| 1753 | val_pending = le32toh(val_pending); |
| 1754 | memcpy(&val_present, &resp->pending_and_present_values[4], |
| 1755 | sizeof(val_present)); |
| 1756 | val_present = le32toh(val_present); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1757 | |
| 1758 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1759 | EXPECT_EQ(effecter_dataSize, resp->effecter_data_size); |
| 1760 | EXPECT_EQ(effecter_operState, resp->effecter_oper_state); |
Andrew Jeffery | f990dcf | 2023-04-12 20:54:48 +0930 | [diff] [blame] | 1761 | EXPECT_EQ(pendingValue, val_pending); |
| 1762 | EXPECT_EQ(presentValue, val_present); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | TEST(GetNumericEffecterValue, testBadEncodeResponse) |
| 1766 | { |
| 1767 | std::array<uint8_t, |
| 1768 | hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2> |
| 1769 | responseMsg{}; |
| 1770 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1771 | |
| 1772 | uint8_t pendingValue = 0x01; |
| 1773 | uint8_t presentValue = 0x02; |
| 1774 | |
| 1775 | auto rc = encode_get_numeric_effecter_value_resp( |
| 1776 | 0, PLDM_SUCCESS, 0, 0, nullptr, nullptr, nullptr, |
| 1777 | responseMsg.size() - hdrSize); |
| 1778 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1779 | |
| 1780 | rc = encode_get_numeric_effecter_value_resp( |
| 1781 | 0, PLDM_SUCCESS, 6, 9, reinterpret_cast<uint8_t*>(&pendingValue), |
| 1782 | reinterpret_cast<uint8_t*>(&presentValue), response, |
| 1783 | responseMsg.size() - hdrSize); |
| 1784 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1785 | |
| 1786 | uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8; |
| 1787 | uint8_t effecter_operState = EFFECTER_OPER_STATE_FAILED; |
| 1788 | |
| 1789 | rc = encode_get_numeric_effecter_value_resp( |
| 1790 | 0, PLDM_SUCCESS, effecter_dataSize, effecter_operState, |
| 1791 | reinterpret_cast<uint8_t*>(&pendingValue), |
| 1792 | reinterpret_cast<uint8_t*>(&presentValue), response, |
| 1793 | responseMsg.size() - hdrSize); |
| 1794 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1795 | } |
| 1796 | |
| 1797 | TEST(GetNumericEffecterValue, testGoodDecodeResponse) |
| 1798 | { |
| 1799 | std::array<uint8_t, |
| 1800 | hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2> |
| 1801 | responseMsg{}; |
| 1802 | |
| 1803 | uint8_t completionCode = 0; |
| 1804 | uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT16; |
| 1805 | uint8_t effecter_operState = EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING; |
| 1806 | uint16_t pendingValue = 0x4321; |
| 1807 | uint16_t presentValue = 0xDCBA; |
| 1808 | |
| 1809 | uint8_t retcompletionCode; |
| 1810 | uint8_t reteffecter_dataSize; |
| 1811 | uint8_t reteffecter_operState; |
| 1812 | uint8_t retpendingValue[2]; |
| 1813 | uint8_t retpresentValue[2]; |
| 1814 | |
| 1815 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1816 | struct pldm_get_numeric_effecter_value_resp* resp = |
| 1817 | reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>( |
| 1818 | response->payload); |
| 1819 | |
| 1820 | resp->completion_code = completionCode; |
| 1821 | resp->effecter_data_size = effecter_dataSize; |
| 1822 | resp->effecter_oper_state = effecter_operState; |
| 1823 | |
| 1824 | uint16_t pendingValue_le = htole16(pendingValue); |
| 1825 | memcpy(resp->pending_and_present_values, &pendingValue_le, |
| 1826 | sizeof(pendingValue_le)); |
| 1827 | uint16_t presentValue_le = htole16(presentValue); |
| 1828 | memcpy(&resp->pending_and_present_values[2], &presentValue_le, |
| 1829 | sizeof(presentValue_le)); |
| 1830 | |
| 1831 | auto rc = decode_get_numeric_effecter_value_resp( |
| 1832 | response, responseMsg.size() - hdrSize, &retcompletionCode, |
| 1833 | &reteffecter_dataSize, &reteffecter_operState, retpendingValue, |
| 1834 | retpresentValue); |
| 1835 | |
| 1836 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1837 | EXPECT_EQ(completionCode, retcompletionCode); |
| 1838 | EXPECT_EQ(effecter_dataSize, reteffecter_dataSize); |
| 1839 | EXPECT_EQ(effecter_operState, reteffecter_operState); |
| 1840 | EXPECT_EQ(pendingValue, *(reinterpret_cast<uint16_t*>(retpendingValue))); |
| 1841 | EXPECT_EQ(presentValue, *(reinterpret_cast<uint16_t*>(retpresentValue))); |
| 1842 | } |
| 1843 | |
| 1844 | TEST(GetNumericEffecterValue, testBadDecodeResponse) |
| 1845 | { |
| 1846 | std::array<uint8_t, |
| 1847 | hdrSize + PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6> |
| 1848 | responseMsg{}; |
| 1849 | |
| 1850 | auto rc = decode_get_numeric_effecter_value_resp( |
| 1851 | nullptr, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr, |
| 1852 | nullptr, nullptr); |
| 1853 | |
| 1854 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1855 | |
| 1856 | uint8_t completionCode = 0; |
| 1857 | uint8_t effecter_dataSize = PLDM_EFFECTER_DATA_SIZE_SINT16; |
| 1858 | uint8_t effecter_operState = EFFECTER_OPER_STATE_DISABLED; |
| 1859 | uint16_t pendingValue = 0x5678; |
| 1860 | uint16_t presentValue = 0xCDEF; |
| 1861 | |
| 1862 | uint8_t retcompletionCode; |
| 1863 | uint8_t reteffecter_dataSize; |
| 1864 | uint8_t reteffecter_operState; |
| 1865 | uint8_t retpendingValue[2]; |
| 1866 | uint8_t retpresentValue[2]; |
| 1867 | |
| 1868 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 1869 | struct pldm_get_numeric_effecter_value_resp* resp = |
| 1870 | reinterpret_cast<struct pldm_get_numeric_effecter_value_resp*>( |
| 1871 | response->payload); |
| 1872 | |
| 1873 | resp->completion_code = completionCode; |
| 1874 | resp->effecter_data_size = effecter_dataSize; |
| 1875 | resp->effecter_oper_state = effecter_operState; |
| 1876 | |
| 1877 | uint16_t pendingValue_le = htole16(pendingValue); |
| 1878 | memcpy(resp->pending_and_present_values, &pendingValue_le, |
| 1879 | sizeof(pendingValue_le)); |
| 1880 | uint16_t presentValue_le = htole16(presentValue); |
| 1881 | memcpy(&resp->pending_and_present_values[2], &presentValue_le, |
| 1882 | sizeof(presentValue_le)); |
| 1883 | |
| 1884 | rc = decode_get_numeric_effecter_value_resp( |
| 1885 | response, responseMsg.size() - hdrSize, &retcompletionCode, |
| 1886 | &reteffecter_dataSize, &reteffecter_operState, retpendingValue, |
| 1887 | retpresentValue); |
| 1888 | |
| 1889 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1890 | } |
| 1891 | |
| 1892 | TEST(PldmPDRRepositoryChgEventEvent, testGoodDecodeRequest) |
| 1893 | { |
| 1894 | const uint8_t eventDataFormat = FORMAT_IS_PDR_HANDLES; |
| 1895 | const uint8_t numberOfChangeRecords = 2; |
| 1896 | uint8_t eventDataOperation1 = PLDM_RECORDS_DELETED; |
| 1897 | const uint8_t numberOfChangeEntries1 = 2; |
| 1898 | std::array<uint32_t, numberOfChangeEntries1> changeRecordArr1{ |
| 1899 | {0x00000000, 0x12345678}}; |
| 1900 | uint8_t eventDataOperation2 = PLDM_RECORDS_ADDED; |
| 1901 | const uint8_t numberOfChangeEntries2 = 5; |
| 1902 | std::array<uint32_t, numberOfChangeEntries2> changeRecordArr2{ |
| 1903 | {0x01234567, 0x11223344, 0x45678901, 0x21222324, 0x98765432}}; |
| 1904 | std::array<uint8_t, PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH + |
| 1905 | PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH * |
| 1906 | numberOfChangeRecords + |
| 1907 | (numberOfChangeEntries1 + numberOfChangeEntries2) * |
| 1908 | sizeof(uint32_t)> |
| 1909 | eventDataArr{}; |
| 1910 | |
| 1911 | struct pldm_pdr_repository_chg_event_data* eventData = |
| 1912 | reinterpret_cast<struct pldm_pdr_repository_chg_event_data*>( |
| 1913 | eventDataArr.data()); |
| 1914 | eventData->event_data_format = eventDataFormat; |
| 1915 | eventData->number_of_change_records = numberOfChangeRecords; |
| 1916 | struct pldm_pdr_repository_change_record_data* changeRecord1 = |
| 1917 | reinterpret_cast<struct pldm_pdr_repository_change_record_data*>( |
| 1918 | eventData->change_records); |
| 1919 | changeRecord1->event_data_operation = eventDataOperation1; |
| 1920 | changeRecord1->number_of_change_entries = numberOfChangeEntries1; |
| 1921 | memcpy(changeRecord1->change_entry, &changeRecordArr1[0], |
| 1922 | changeRecordArr1.size() * sizeof(uint32_t)); |
| 1923 | struct pldm_pdr_repository_change_record_data* changeRecord2 = |
| 1924 | reinterpret_cast<struct pldm_pdr_repository_change_record_data*>( |
| 1925 | eventData->change_records + |
| 1926 | PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH + |
| 1927 | (changeRecordArr1.size() * sizeof(uint32_t))); |
| 1928 | changeRecord2->event_data_operation = eventDataOperation2; |
| 1929 | changeRecord2->number_of_change_entries = numberOfChangeEntries2; |
| 1930 | memcpy(changeRecord2->change_entry, &changeRecordArr2[0], |
| 1931 | changeRecordArr2.size() * sizeof(uint32_t)); |
| 1932 | |
| 1933 | uint8_t retEventDataFormat{}; |
| 1934 | uint8_t retNumberOfChangeRecords{}; |
| 1935 | size_t retChangeRecordDataOffset{0}; |
| 1936 | auto rc = decode_pldm_pdr_repository_chg_event_data( |
| 1937 | reinterpret_cast<const uint8_t*>(eventData), eventDataArr.size(), |
| 1938 | &retEventDataFormat, &retNumberOfChangeRecords, |
| 1939 | &retChangeRecordDataOffset); |
| 1940 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1941 | EXPECT_EQ(retEventDataFormat, FORMAT_IS_PDR_HANDLES); |
| 1942 | EXPECT_EQ(retNumberOfChangeRecords, numberOfChangeRecords); |
| 1943 | |
| 1944 | const uint8_t* changeRecordData = |
| 1945 | reinterpret_cast<const uint8_t*>(changeRecord1); |
| 1946 | size_t changeRecordDataSize = |
| 1947 | eventDataArr.size() - PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH; |
| 1948 | uint8_t retEventDataOperation; |
| 1949 | uint8_t retNumberOfChangeEntries; |
| 1950 | size_t retChangeEntryDataOffset; |
| 1951 | |
| 1952 | rc = decode_pldm_pdr_repository_change_record_data( |
| 1953 | reinterpret_cast<const uint8_t*>(changeRecordData), |
| 1954 | changeRecordDataSize, &retEventDataOperation, &retNumberOfChangeEntries, |
| 1955 | &retChangeEntryDataOffset); |
| 1956 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1957 | EXPECT_EQ(retEventDataOperation, eventDataOperation1); |
| 1958 | EXPECT_EQ(retNumberOfChangeEntries, numberOfChangeEntries1); |
| 1959 | changeRecordData += retChangeEntryDataOffset; |
| 1960 | EXPECT_EQ(0, memcmp(changeRecordData, &changeRecordArr1[0], |
| 1961 | sizeof(uint32_t) * retNumberOfChangeEntries)); |
| 1962 | |
| 1963 | changeRecordData += sizeof(uint32_t) * retNumberOfChangeEntries; |
| 1964 | changeRecordDataSize -= sizeof(uint32_t) * retNumberOfChangeEntries - |
| 1965 | PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH; |
| 1966 | rc = decode_pldm_pdr_repository_change_record_data( |
| 1967 | reinterpret_cast<const uint8_t*>(changeRecordData), |
| 1968 | changeRecordDataSize, &retEventDataOperation, &retNumberOfChangeEntries, |
| 1969 | &retChangeEntryDataOffset); |
| 1970 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 1971 | EXPECT_EQ(retEventDataOperation, eventDataOperation2); |
| 1972 | EXPECT_EQ(retNumberOfChangeEntries, numberOfChangeEntries2); |
| 1973 | changeRecordData += retChangeEntryDataOffset; |
| 1974 | EXPECT_EQ(0, memcmp(changeRecordData, &changeRecordArr2[0], |
| 1975 | sizeof(uint32_t) * retNumberOfChangeEntries)); |
| 1976 | } |
| 1977 | |
| 1978 | TEST(PldmPDRRepositoryChgEventEvent, testBadDecodeRequest) |
| 1979 | { |
| 1980 | uint8_t eventDataFormat{}; |
| 1981 | uint8_t numberOfChangeRecords{}; |
| 1982 | size_t changeRecordDataOffset{}; |
| 1983 | auto rc = decode_pldm_pdr_repository_chg_event_data( |
| 1984 | NULL, 0, &eventDataFormat, &numberOfChangeRecords, |
| 1985 | &changeRecordDataOffset); |
| 1986 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 1987 | |
| 1988 | std::array<uint8_t, 2> eventData{}; |
| 1989 | rc = decode_pldm_pdr_repository_chg_event_data( |
| 1990 | reinterpret_cast<const uint8_t*>(eventData.data()), 0, &eventDataFormat, |
| 1991 | &numberOfChangeRecords, &changeRecordDataOffset); |
| 1992 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 1993 | |
| 1994 | uint8_t eventDataOperation{}; |
| 1995 | uint8_t numberOfChangeEntries{}; |
| 1996 | size_t changeEntryDataOffset{}; |
| 1997 | rc = decode_pldm_pdr_repository_change_record_data( |
| 1998 | NULL, 0, &eventDataOperation, &numberOfChangeEntries, |
| 1999 | &changeEntryDataOffset); |
| 2000 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2001 | |
| 2002 | std::array<uint8_t, 2> changeRecord{}; |
| 2003 | rc = decode_pldm_pdr_repository_change_record_data( |
| 2004 | reinterpret_cast<const uint8_t*>(changeRecord.data()), 0, |
| 2005 | &eventDataOperation, &numberOfChangeEntries, &changeEntryDataOffset); |
| 2006 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2007 | } |
| 2008 | |
| 2009 | TEST(GetSensorReading, testGoodEncodeRequest) |
| 2010 | { |
| 2011 | std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES> |
| 2012 | requestMsg{}; |
| 2013 | |
| 2014 | uint16_t sensorId = 0x1234; |
| 2015 | bool8_t rearmEventState = 0x01; |
| 2016 | |
| 2017 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 2018 | auto rc = |
| 2019 | encode_get_sensor_reading_req(0, sensorId, rearmEventState, request); |
| 2020 | |
| 2021 | struct pldm_get_sensor_reading_req* req = |
| 2022 | reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload); |
| 2023 | |
| 2024 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2025 | EXPECT_EQ(sensorId, le16toh(req->sensor_id)); |
| 2026 | EXPECT_EQ(rearmEventState, req->rearm_event_state); |
| 2027 | } |
| 2028 | |
| 2029 | TEST(GetSensorReading, testBadEncodeRequest) |
| 2030 | { |
| 2031 | auto rc = encode_get_sensor_reading_req(0, 0, 0, nullptr); |
| 2032 | |
| 2033 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2034 | } |
| 2035 | |
| 2036 | TEST(GetSensorReading, testGoodDecodeRequest) |
| 2037 | { |
| 2038 | std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES> |
| 2039 | requestMsg{}; |
| 2040 | |
| 2041 | uint16_t sensorId = 0xABCD; |
| 2042 | bool8_t rearmEventState = 0xA; |
| 2043 | |
| 2044 | uint16_t retsensorId; |
| 2045 | bool8_t retrearmEventState; |
| 2046 | |
| 2047 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 2048 | |
| 2049 | struct pldm_get_sensor_reading_req* req = |
| 2050 | reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload); |
| 2051 | |
| 2052 | req->sensor_id = htole16(sensorId); |
| 2053 | req->rearm_event_state = rearmEventState; |
| 2054 | |
| 2055 | auto rc = |
| 2056 | decode_get_sensor_reading_req(request, requestMsg.size() - hdrSize, |
| 2057 | &retsensorId, &retrearmEventState); |
| 2058 | |
| 2059 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2060 | EXPECT_EQ(sensorId, retsensorId); |
| 2061 | EXPECT_EQ(rearmEventState, retrearmEventState); |
| 2062 | } |
| 2063 | |
| 2064 | TEST(GetSensorReading, testBadDecodeRequest) |
| 2065 | { |
| 2066 | std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_REQ_BYTES> |
| 2067 | requestMsg{}; |
| 2068 | |
| 2069 | auto rc = decode_get_sensor_reading_req( |
| 2070 | nullptr, requestMsg.size() - hdrSize, nullptr, nullptr); |
| 2071 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2072 | |
| 2073 | uint16_t sensorId = 0xABCD; |
| 2074 | bool8_t rearmEventState = 0xA; |
| 2075 | |
| 2076 | uint16_t retsensorId; |
| 2077 | bool8_t retrearmEventState; |
| 2078 | |
| 2079 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 2080 | |
| 2081 | struct pldm_get_sensor_reading_req* req = |
| 2082 | reinterpret_cast<struct pldm_get_sensor_reading_req*>(request->payload); |
| 2083 | |
| 2084 | req->sensor_id = htole16(sensorId); |
| 2085 | req->rearm_event_state = rearmEventState; |
| 2086 | |
| 2087 | rc = decode_get_sensor_reading_req(request, requestMsg.size() - hdrSize - 1, |
| 2088 | &retsensorId, &retrearmEventState); |
| 2089 | |
| 2090 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2091 | } |
| 2092 | |
| 2093 | TEST(GetSensorReading, testGoodEncodeResponse) |
| 2094 | { |
| 2095 | std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES> |
| 2096 | responseMsg{}; |
| 2097 | |
| 2098 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 2099 | |
| 2100 | uint8_t completionCode = 0; |
| 2101 | uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8; |
| 2102 | uint8_t sensor_operationalState = PLDM_SENSOR_ENABLED; |
| 2103 | uint8_t sensor_event_messageEnable = PLDM_NO_EVENT_GENERATION; |
| 2104 | uint8_t presentState = PLDM_SENSOR_NORMAL; |
| 2105 | uint8_t previousState = PLDM_SENSOR_WARNING; |
| 2106 | uint8_t eventState = PLDM_SENSOR_UPPERWARNING; |
| 2107 | uint8_t presentReading = 0x21; |
| 2108 | |
| 2109 | auto rc = encode_get_sensor_reading_resp( |
| 2110 | 0, completionCode, sensor_dataSize, sensor_operationalState, |
| 2111 | sensor_event_messageEnable, presentState, previousState, eventState, |
| 2112 | reinterpret_cast<uint8_t*>(&presentReading), response, |
| 2113 | responseMsg.size() - hdrSize); |
| 2114 | |
| 2115 | struct pldm_get_sensor_reading_resp* resp = |
| 2116 | reinterpret_cast<struct pldm_get_sensor_reading_resp*>( |
| 2117 | response->payload); |
| 2118 | |
| 2119 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2120 | EXPECT_EQ(completionCode, resp->completion_code); |
| 2121 | EXPECT_EQ(sensor_dataSize, resp->sensor_data_size); |
| 2122 | EXPECT_EQ(sensor_operationalState, resp->sensor_operational_state); |
| 2123 | EXPECT_EQ(sensor_event_messageEnable, resp->sensor_event_message_enable); |
| 2124 | EXPECT_EQ(presentState, resp->present_state); |
| 2125 | EXPECT_EQ(previousState, resp->previous_state); |
| 2126 | EXPECT_EQ(eventState, resp->event_state); |
| 2127 | EXPECT_EQ(presentReading, |
| 2128 | *(reinterpret_cast<uint8_t*>(&resp->present_reading[0]))); |
| 2129 | } |
| 2130 | |
| 2131 | TEST(GetSensorReading, testBadEncodeResponse) |
| 2132 | { |
| 2133 | std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3> |
| 2134 | responseMsg{}; |
| 2135 | |
| 2136 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 2137 | |
| 2138 | uint8_t presentReading = 0x1; |
| 2139 | |
| 2140 | auto rc = encode_get_sensor_reading_resp(0, PLDM_SUCCESS, 0, 0, 0, 0, 0, 0, |
| 2141 | nullptr, nullptr, |
| 2142 | responseMsg.size() - hdrSize); |
| 2143 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2144 | |
| 2145 | rc = encode_get_sensor_reading_resp( |
| 2146 | 0, PLDM_SUCCESS, 6, 1, 1, 1, 1, 1, |
| 2147 | reinterpret_cast<uint8_t*>(&presentReading), response, |
| 2148 | responseMsg.size() - hdrSize); |
| 2149 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2150 | |
| 2151 | uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8; |
| 2152 | |
| 2153 | rc = encode_get_sensor_reading_resp( |
| 2154 | 0, PLDM_SUCCESS, sensor_dataSize, 1, 1, 1, 1, 1, |
| 2155 | reinterpret_cast<uint8_t*>(&presentReading), response, |
| 2156 | responseMsg.size() - hdrSize); |
| 2157 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2158 | } |
| 2159 | |
| 2160 | TEST(GetSensorReading, testGoodDecodeResponse) |
| 2161 | { |
| 2162 | std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3> |
| 2163 | responseMsg{}; |
| 2164 | |
| 2165 | uint8_t completionCode = 0; |
| 2166 | uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT32; |
| 2167 | uint8_t sensor_operationalState = PLDM_SENSOR_STATUSUNKOWN; |
| 2168 | uint8_t sensor_event_messageEnable = PLDM_EVENTS_ENABLED; |
| 2169 | uint8_t presentState = PLDM_SENSOR_CRITICAL; |
| 2170 | uint8_t previousState = PLDM_SENSOR_UPPERCRITICAL; |
| 2171 | uint8_t eventState = PLDM_SENSOR_WARNING; |
| 2172 | uint32_t presentReading = 0xABCDEF11; |
| 2173 | |
| 2174 | uint8_t retcompletionCode; |
| 2175 | uint8_t retsensor_dataSize = PLDM_SENSOR_DATA_SIZE_UINT32; |
| 2176 | uint8_t retsensor_operationalState; |
| 2177 | uint8_t retsensor_event_messageEnable; |
| 2178 | uint8_t retpresentState; |
| 2179 | uint8_t retpreviousState; |
| 2180 | uint8_t reteventState; |
| 2181 | uint8_t retpresentReading[4]; |
| 2182 | |
| 2183 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 2184 | struct pldm_get_sensor_reading_resp* resp = |
| 2185 | reinterpret_cast<struct pldm_get_sensor_reading_resp*>( |
| 2186 | response->payload); |
| 2187 | |
| 2188 | resp->completion_code = completionCode; |
| 2189 | resp->sensor_data_size = sensor_dataSize; |
| 2190 | resp->sensor_operational_state = sensor_operationalState; |
| 2191 | resp->sensor_event_message_enable = sensor_event_messageEnable; |
| 2192 | resp->present_state = presentState; |
| 2193 | resp->previous_state = previousState; |
| 2194 | resp->event_state = eventState; |
| 2195 | |
| 2196 | uint32_t presentReading_le = htole32(presentReading); |
| 2197 | memcpy(resp->present_reading, &presentReading_le, |
| 2198 | sizeof(presentReading_le)); |
| 2199 | |
| 2200 | auto rc = decode_get_sensor_reading_resp( |
| 2201 | response, responseMsg.size() - hdrSize, &retcompletionCode, |
| 2202 | &retsensor_dataSize, &retsensor_operationalState, |
| 2203 | &retsensor_event_messageEnable, &retpresentState, &retpreviousState, |
| 2204 | &reteventState, retpresentReading); |
| 2205 | |
| 2206 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2207 | EXPECT_EQ(completionCode, retcompletionCode); |
| 2208 | EXPECT_EQ(sensor_dataSize, retsensor_dataSize); |
| 2209 | EXPECT_EQ(sensor_operationalState, retsensor_operationalState); |
| 2210 | EXPECT_EQ(sensor_event_messageEnable, retsensor_event_messageEnable); |
| 2211 | EXPECT_EQ(presentState, retpresentState); |
| 2212 | EXPECT_EQ(previousState, retpreviousState); |
| 2213 | EXPECT_EQ(eventState, reteventState); |
| 2214 | EXPECT_EQ(presentReading, |
| 2215 | *(reinterpret_cast<uint32_t*>(retpresentReading))); |
| 2216 | } |
| 2217 | |
| 2218 | TEST(GetSensorReading, testBadDecodeResponse) |
| 2219 | { |
| 2220 | std::array<uint8_t, hdrSize + PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 1> |
| 2221 | responseMsg{}; |
| 2222 | |
| 2223 | auto rc = decode_get_sensor_reading_resp( |
| 2224 | nullptr, responseMsg.size() - hdrSize, nullptr, nullptr, nullptr, |
| 2225 | nullptr, nullptr, nullptr, nullptr, nullptr); |
| 2226 | |
| 2227 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2228 | |
| 2229 | uint8_t completionCode = 0; |
| 2230 | uint8_t sensor_dataSize = PLDM_EFFECTER_DATA_SIZE_UINT8; |
| 2231 | uint8_t sensor_operationalState = PLDM_SENSOR_INTEST; |
| 2232 | uint8_t sensor_event_messageEnable = PLDM_EVENTS_DISABLED; |
| 2233 | uint8_t presentState = PLDM_SENSOR_FATAL; |
| 2234 | uint8_t previousState = PLDM_SENSOR_UPPERFATAL; |
| 2235 | uint8_t eventState = PLDM_SENSOR_WARNING; |
| 2236 | uint8_t presentReading = 0xA; |
| 2237 | |
| 2238 | uint8_t retcompletionCode; |
| 2239 | uint8_t retsensor_dataSize = PLDM_SENSOR_DATA_SIZE_SINT16; |
| 2240 | uint8_t retsensor_operationalState; |
| 2241 | uint8_t retsensor_event_messageEnable; |
| 2242 | uint8_t retpresent_state; |
| 2243 | uint8_t retprevious_state; |
| 2244 | uint8_t retevent_state; |
| 2245 | uint8_t retpresentReading; |
| 2246 | |
| 2247 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 2248 | struct pldm_get_sensor_reading_resp* resp = |
| 2249 | reinterpret_cast<struct pldm_get_sensor_reading_resp*>( |
| 2250 | response->payload); |
| 2251 | |
| 2252 | resp->completion_code = completionCode; |
| 2253 | resp->sensor_data_size = sensor_dataSize; |
| 2254 | resp->sensor_operational_state = sensor_operationalState; |
| 2255 | resp->sensor_event_message_enable = sensor_event_messageEnable; |
| 2256 | resp->present_state = presentState; |
| 2257 | resp->previous_state = previousState; |
| 2258 | resp->event_state = eventState; |
| 2259 | resp->present_reading[0] = presentReading; |
| 2260 | |
| 2261 | rc = decode_get_sensor_reading_resp( |
| 2262 | response, responseMsg.size() - hdrSize, &retcompletionCode, |
| 2263 | &retsensor_dataSize, &retsensor_operationalState, |
| 2264 | &retsensor_event_messageEnable, &retpresent_state, &retprevious_state, |
| 2265 | &retevent_state, reinterpret_cast<uint8_t*>(&retpresentReading)); |
| 2266 | |
| 2267 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2268 | } |
| 2269 | |
| 2270 | TEST(SetEventReceiver, testGoodEncodeRequest) |
| 2271 | { |
| 2272 | uint8_t eventMessageGlobalEnable = |
| 2273 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE; |
| 2274 | uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP; |
| 2275 | uint8_t eventReceiverAddressInfo = 0x08; |
| 2276 | uint16_t heartbeatTimer = 0x78; |
| 2277 | |
| 2278 | std::vector<uint8_t> requestMsg(hdrSize + |
| 2279 | PLDM_SET_EVENT_RECEIVER_REQ_BYTES); |
| 2280 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 2281 | |
| 2282 | auto rc = encode_set_event_receiver_req( |
| 2283 | 0, eventMessageGlobalEnable, transportProtocolType, |
| 2284 | eventReceiverAddressInfo, heartbeatTimer, request); |
| 2285 | |
| 2286 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2287 | struct pldm_set_event_receiver_req* req = |
| 2288 | reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload); |
| 2289 | EXPECT_EQ(eventMessageGlobalEnable, req->event_message_global_enable); |
| 2290 | EXPECT_EQ(transportProtocolType, req->transport_protocol_type); |
| 2291 | EXPECT_EQ(eventReceiverAddressInfo, req->event_receiver_address_info); |
| 2292 | EXPECT_EQ(heartbeatTimer, le16toh(req->heartbeat_timer)); |
| 2293 | } |
| 2294 | |
| 2295 | TEST(SetEventReceiver, testBadEncodeRequest) |
| 2296 | { |
| 2297 | uint8_t eventMessageGlobalEnable = |
| 2298 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE; |
| 2299 | uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP; |
| 2300 | uint8_t eventReceiverAddressInfo = 0x08; |
| 2301 | uint16_t heartbeatTimer = 0; |
| 2302 | |
| 2303 | std::vector<uint8_t> requestMsg(hdrSize + |
| 2304 | PLDM_SET_EVENT_RECEIVER_REQ_BYTES); |
| 2305 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 2306 | |
| 2307 | auto rc = encode_set_event_receiver_req( |
| 2308 | 0, eventMessageGlobalEnable, transportProtocolType, |
| 2309 | eventReceiverAddressInfo, heartbeatTimer, request); |
| 2310 | |
| 2311 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2312 | } |
| 2313 | |
| 2314 | TEST(SetEventReceiver, testGoodDecodeResponse) |
| 2315 | { |
| 2316 | std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_RESP_BYTES> |
| 2317 | responseMsg{}; |
| 2318 | |
| 2319 | uint8_t retcompletion_code = 0; |
| 2320 | responseMsg[hdrSize] = PLDM_SUCCESS; |
| 2321 | |
| 2322 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 2323 | auto rc = decode_set_event_receiver_resp( |
| 2324 | response, responseMsg.size() - sizeof(pldm_msg_hdr), |
| 2325 | &retcompletion_code); |
| 2326 | |
| 2327 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2328 | EXPECT_EQ(PLDM_SUCCESS, retcompletion_code); |
| 2329 | } |
| 2330 | |
| 2331 | TEST(SetEventReceiver, testBadDecodeResponse) |
| 2332 | { |
| 2333 | std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_RESP_BYTES> |
| 2334 | responseMsg{}; |
| 2335 | uint8_t retcompletion_code = 0; |
| 2336 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 2337 | |
| 2338 | auto rc = decode_set_event_receiver_resp( |
| 2339 | response, responseMsg.size() - sizeof(pldm_msg_hdr), NULL); |
| 2340 | |
| 2341 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2342 | |
| 2343 | rc = decode_set_event_receiver_resp( |
| 2344 | nullptr, responseMsg.size() - sizeof(pldm_msg_hdr), |
| 2345 | &retcompletion_code); |
| 2346 | |
| 2347 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2348 | } |
| 2349 | |
| 2350 | TEST(SetEventReceiver, testGoodEncodeResponse) |
| 2351 | { |
| 2352 | std::array<uint8_t, |
| 2353 | sizeof(pldm_msg_hdr) + PLDM_SET_EVENT_RECEIVER_RESP_BYTES> |
| 2354 | responseMsg{}; |
| 2355 | auto response = reinterpret_cast<pldm_msg*>(responseMsg.data()); |
| 2356 | uint8_t completionCode = 0; |
| 2357 | |
| 2358 | auto rc = encode_set_event_receiver_resp(0, PLDM_SUCCESS, response); |
| 2359 | |
| 2360 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2361 | EXPECT_EQ(completionCode, response->payload[0]); |
| 2362 | } |
| 2363 | |
| 2364 | TEST(SetEventReceiver, testBadEncodeResponse) |
| 2365 | { |
| 2366 | auto rc = encode_set_event_receiver_resp(0, PLDM_SUCCESS, NULL); |
| 2367 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2368 | } |
| 2369 | |
| 2370 | TEST(SetEventReceiver, testGoodDecodeRequest) |
| 2371 | { |
| 2372 | |
| 2373 | std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_REQ_BYTES> |
| 2374 | requestMsg{}; |
| 2375 | |
| 2376 | uint8_t eventMessageGlobalEnable = |
| 2377 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE; |
| 2378 | uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP; |
| 2379 | uint8_t eventReceiverAddressInfo = 0x08; |
| 2380 | uint16_t heartbeatTimer = 0x78; |
| 2381 | |
| 2382 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 2383 | struct pldm_set_event_receiver_req* req = |
| 2384 | reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload); |
| 2385 | |
| 2386 | req->event_message_global_enable = eventMessageGlobalEnable; |
| 2387 | req->transport_protocol_type = transportProtocolType; |
| 2388 | req->event_receiver_address_info = eventReceiverAddressInfo; |
| 2389 | req->heartbeat_timer = htole16(heartbeatTimer); |
| 2390 | |
| 2391 | uint8_t reteventMessageGlobalEnable; |
| 2392 | uint8_t rettransportProtocolType; |
| 2393 | uint8_t reteventReceiverAddressInfo; |
| 2394 | uint16_t retheartbeatTimer; |
| 2395 | auto rc = decode_set_event_receiver_req( |
| 2396 | request, requestMsg.size() - hdrSize, &reteventMessageGlobalEnable, |
| 2397 | &rettransportProtocolType, &reteventReceiverAddressInfo, |
| 2398 | &retheartbeatTimer); |
| 2399 | |
| 2400 | EXPECT_EQ(rc, PLDM_SUCCESS); |
| 2401 | EXPECT_EQ(eventMessageGlobalEnable, reteventMessageGlobalEnable); |
| 2402 | EXPECT_EQ(transportProtocolType, rettransportProtocolType); |
| 2403 | EXPECT_EQ(eventReceiverAddressInfo, reteventReceiverAddressInfo); |
| 2404 | EXPECT_EQ(heartbeatTimer, retheartbeatTimer); |
| 2405 | } |
| 2406 | |
| 2407 | TEST(SetEventReceiver, testBadDecodeRequest) |
| 2408 | { |
| 2409 | std::array<uint8_t, hdrSize + PLDM_SET_EVENT_RECEIVER_REQ_BYTES> |
| 2410 | requestMsg{}; |
| 2411 | |
| 2412 | auto rc = decode_set_event_receiver_req(NULL, requestMsg.size() - hdrSize, |
| 2413 | NULL, NULL, NULL, NULL); |
| 2414 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 2415 | |
| 2416 | uint8_t eventMessageGlobalEnable = |
| 2417 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE; |
| 2418 | uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP; |
| 2419 | uint8_t eventReceiverAddressInfo = 0x08; |
| 2420 | uint16_t heartbeatTimer = 0x78; |
| 2421 | |
| 2422 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 2423 | struct pldm_set_event_receiver_req* req = |
| 2424 | reinterpret_cast<struct pldm_set_event_receiver_req*>(request->payload); |
| 2425 | |
| 2426 | req->event_message_global_enable = eventMessageGlobalEnable; |
| 2427 | req->transport_protocol_type = transportProtocolType; |
| 2428 | req->event_receiver_address_info = eventReceiverAddressInfo; |
| 2429 | req->heartbeat_timer = htole16(heartbeatTimer); |
| 2430 | |
| 2431 | uint8_t reteventMessageGlobalEnable; |
| 2432 | uint8_t rettransportProtocolType; |
| 2433 | uint8_t reteventReceiverAddressInfo; |
| 2434 | uint16_t retheartbeatTimer; |
| 2435 | rc = decode_set_event_receiver_req( |
| 2436 | request, requestMsg.size() - hdrSize - 1, &reteventMessageGlobalEnable, |
| 2437 | &rettransportProtocolType, &reteventReceiverAddressInfo, |
| 2438 | &retheartbeatTimer); |
| 2439 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 2440 | } |
Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 2441 | |
| 2442 | TEST(decodeNumericSensorPdrData, Uint8Test) |
| 2443 | { |
| 2444 | std::vector<uint8_t> pdr1{ |
| 2445 | 0x1, |
| 2446 | 0x0, |
| 2447 | 0x0, |
| 2448 | 0x0, // record handle |
| 2449 | 0x1, // PDRHeaderVersion |
| 2450 | PLDM_NUMERIC_SENSOR_PDR, // PDRType |
| 2451 | 0x0, |
| 2452 | 0x0, // recordChangeNumber |
| 2453 | PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH, |
| 2454 | 0, // dataLength |
| 2455 | 0, |
| 2456 | 0, // PLDMTerminusHandle |
| 2457 | 0x1, |
| 2458 | 0x0, // sensorID=1 |
| 2459 | PLDM_ENTITY_POWER_SUPPLY, |
| 2460 | 0, // entityType=Power Supply(120) |
| 2461 | 1, |
| 2462 | 0, // entityInstanceNumber |
| 2463 | 1, |
| 2464 | 0, // containerID=1 |
| 2465 | PLDM_NO_INIT, // sensorInit |
| 2466 | false, // sensorAuxiliaryNamesPDR |
| 2467 | PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C |
| 2468 | 0, // unitModifier |
| 2469 | 0, // rateUnit |
| 2470 | 0, // baseOEMUnitHandle |
| 2471 | 0, // auxUnit |
| 2472 | 0, // auxUnitModifier |
| 2473 | 0, // auxRateUnit |
| 2474 | 0, // rel |
| 2475 | 0, // auxOEMUnitHandle |
| 2476 | true, // isLinear |
| 2477 | PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize |
| 2478 | 0, |
| 2479 | 0, |
| 2480 | 0xc0, |
| 2481 | 0x3f, // resolution=1.5 |
| 2482 | 0, |
| 2483 | 0, |
| 2484 | 0x80, |
| 2485 | 0x3f, // offset=1.0 |
| 2486 | 0, |
| 2487 | 0, // accuracy |
| 2488 | 0, // plusTolerance |
| 2489 | 0, // minusTolerance |
| 2490 | 3, // hysteresis = 3 |
| 2491 | 0, // supportedThresholds |
| 2492 | 0, // thresholdAndHysteresisVolatility |
| 2493 | 0, |
| 2494 | 0, |
| 2495 | 0x80, |
| 2496 | 0x3f, // stateTransistionInterval=1.0 |
| 2497 | 0, |
| 2498 | 0, |
| 2499 | 0x80, |
| 2500 | 0x3f, // updateInverval=1.0 |
| 2501 | 255, // maxReadable |
| 2502 | 0, // minReadable |
| 2503 | PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat |
| 2504 | 0, // rangeFieldsupport |
| 2505 | 50, // nominalValue = 50 |
| 2506 | 60, // normalMax = 60 |
| 2507 | 40, // normalMin = 40 |
| 2508 | 70, // warningHigh = 70 |
| 2509 | 30, // warningLow = 30 |
| 2510 | 80, // criticalHigh = 80 |
| 2511 | 20, // criticalLow = 20 |
| 2512 | 90, // fatalHigh = 90 |
| 2513 | 10 // fatalLow = 10 |
| 2514 | }; |
| 2515 | |
| 2516 | struct pldm_numeric_sensor_value_pdr decodedPdr; |
| 2517 | auto rc = |
| 2518 | decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr); |
| 2519 | EXPECT_EQ(PLDM_SUCCESS, rc); |
| 2520 | EXPECT_EQ(1, decodedPdr.hdr.record_handle); |
| 2521 | EXPECT_EQ(1, decodedPdr.hdr.version); |
| 2522 | EXPECT_EQ(PLDM_NUMERIC_SENSOR_PDR, decodedPdr.hdr.type); |
| 2523 | EXPECT_EQ(0, decodedPdr.hdr.record_change_num); |
| 2524 | EXPECT_EQ(PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH, decodedPdr.hdr.length); |
| 2525 | EXPECT_EQ(1, decodedPdr.sensor_id); |
| 2526 | EXPECT_EQ(PLDM_ENTITY_POWER_SUPPLY, decodedPdr.entity_type); |
| 2527 | EXPECT_EQ(1, decodedPdr.entity_instance_num); |
| 2528 | EXPECT_EQ(1, decodedPdr.container_id); |
| 2529 | EXPECT_EQ(PLDM_NO_INIT, decodedPdr.sensor_init); |
| 2530 | EXPECT_EQ(false, decodedPdr.sensor_auxiliary_names_pdr); |
| 2531 | EXPECT_EQ(PLDM_SENSOR_UNIT_DEGRESS_C, decodedPdr.base_unit); |
| 2532 | EXPECT_EQ(0, decodedPdr.unit_modifier); |
| 2533 | EXPECT_EQ(0, decodedPdr.rate_unit); |
| 2534 | EXPECT_EQ(0, decodedPdr.base_oem_unit_handle); |
| 2535 | EXPECT_EQ(0, decodedPdr.aux_unit); |
| 2536 | EXPECT_EQ(0, decodedPdr.aux_unit_modifier); |
| 2537 | EXPECT_EQ(0, decodedPdr.aux_rate_unit); |
| 2538 | EXPECT_EQ(0, decodedPdr.rel); |
| 2539 | EXPECT_EQ(0, decodedPdr.aux_oem_unit_handle); |
| 2540 | EXPECT_EQ(true, decodedPdr.is_linear); |
| 2541 | EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_UINT8, decodedPdr.sensor_data_size); |
| 2542 | EXPECT_FLOAT_EQ(1.5f, decodedPdr.resolution); |
| 2543 | EXPECT_FLOAT_EQ(1.0f, decodedPdr.offset); |
| 2544 | EXPECT_EQ(0, decodedPdr.accuracy); |
| 2545 | EXPECT_EQ(0, decodedPdr.plus_tolerance); |
| 2546 | EXPECT_EQ(0, decodedPdr.minus_tolerance); |
| 2547 | EXPECT_EQ(3, decodedPdr.hysteresis.value_u8); |
| 2548 | EXPECT_EQ(0, decodedPdr.supported_thresholds.byte); |
| 2549 | EXPECT_EQ(0, decodedPdr.threshold_and_hysteresis_volatility.byte); |
| 2550 | EXPECT_FLOAT_EQ(1.0f, decodedPdr.state_transition_interval); |
| 2551 | EXPECT_FLOAT_EQ(1.0f, decodedPdr.update_interval); |
| 2552 | EXPECT_EQ(255, decodedPdr.max_readable.value_u8); |
| 2553 | EXPECT_EQ(0, decodedPdr.min_readable.value_u8); |
| 2554 | EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT8, decodedPdr.range_field_format); |
| 2555 | EXPECT_EQ(0, decodedPdr.range_field_support.byte); |
| 2556 | EXPECT_EQ(50, decodedPdr.nominal_value.value_u8); |
| 2557 | EXPECT_EQ(60, decodedPdr.normal_max.value_u8); |
| 2558 | EXPECT_EQ(40, decodedPdr.normal_min.value_u8); |
| 2559 | EXPECT_EQ(70, decodedPdr.warning_high.value_u8); |
| 2560 | EXPECT_EQ(30, decodedPdr.warning_low.value_u8); |
| 2561 | EXPECT_EQ(80, decodedPdr.critical_high.value_u8); |
| 2562 | EXPECT_EQ(20, decodedPdr.critical_low.value_u8); |
| 2563 | EXPECT_EQ(90, decodedPdr.fatal_high.value_u8); |
| 2564 | EXPECT_EQ(10, decodedPdr.fatal_low.value_u8); |
| 2565 | } |
| 2566 | |
| 2567 | TEST(decodeNumericSensorPdrData, Sint8Test) |
| 2568 | { |
| 2569 | std::vector<uint8_t> pdr1{ |
| 2570 | 0x1, |
| 2571 | 0x0, |
| 2572 | 0x0, |
| 2573 | 0x0, // record handle |
| 2574 | 0x1, // PDRHeaderVersion |
| 2575 | PLDM_NUMERIC_SENSOR_PDR, // PDRType |
| 2576 | 0x0, |
| 2577 | 0x0, // recordChangeNumber |
| 2578 | PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH + |
| 2579 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH + |
| 2580 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH, |
| 2581 | 0, // dataLength |
| 2582 | 0, |
| 2583 | 0, // PLDMTerminusHandle |
| 2584 | 0x1, |
| 2585 | 0x0, // sensorID=1 |
| 2586 | PLDM_ENTITY_POWER_SUPPLY, |
| 2587 | 0, // entityType=Power Supply(120) |
| 2588 | 1, |
| 2589 | 0, // entityInstanceNumber |
| 2590 | 0x1, |
| 2591 | 0x0, // containerID=1 |
| 2592 | PLDM_NO_INIT, // sensorInit |
| 2593 | false, // sensorAuxiliaryNamesPDR |
| 2594 | PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C |
| 2595 | 0, // unitModifier |
| 2596 | 0, // rateUnit |
| 2597 | 0, // baseOEMUnitHandle |
| 2598 | 0, // auxUnit |
| 2599 | 0, // auxUnitModifier |
| 2600 | 0, // auxRateUnit |
| 2601 | 0, // rel |
| 2602 | 0, // auxOEMUnitHandle |
| 2603 | true, // isLinear |
| 2604 | PLDM_RANGE_FIELD_FORMAT_SINT8, // sensorDataSize |
| 2605 | 0, |
| 2606 | 0, |
| 2607 | 0, |
| 2608 | 0, // resolution |
| 2609 | 0, |
| 2610 | 0, |
| 2611 | 0, |
| 2612 | 0, // offset |
| 2613 | 0, |
| 2614 | 0, // accuracy |
| 2615 | 0, // plusTolerance |
| 2616 | 0, // minusTolerance |
| 2617 | 3, // hysteresis = 3 |
| 2618 | 0, // supportedThresholds |
| 2619 | 0, // thresholdAndHysteresisVolatility |
| 2620 | 0, |
| 2621 | 0, |
| 2622 | 0x80, |
| 2623 | 0x3f, // stateTransistionInterval=1.0 |
| 2624 | 0, |
| 2625 | 0, |
| 2626 | 0x80, |
| 2627 | 0x3f, // updateInverval=1.0 |
| 2628 | 0x64, // maxReadable = 100 |
| 2629 | 0x9c, // minReadable = -100 |
| 2630 | PLDM_RANGE_FIELD_FORMAT_SINT8, // rangeFieldFormat |
| 2631 | 0, // rangeFieldsupport |
| 2632 | 0, // nominalValue = 0 |
| 2633 | 5, // normalMax = 5 |
| 2634 | 0xfb, // normalMin = -5 |
| 2635 | 10, // warningHigh = 10 |
| 2636 | 0xf6, // warningLow = -10 |
| 2637 | 20, // criticalHigh = 20 |
| 2638 | 0xec, // criticalLow = -20 |
| 2639 | 30, // fatalHigh = 30 |
| 2640 | 0xe2 // fatalLow = -30 |
| 2641 | }; |
| 2642 | |
| 2643 | struct pldm_numeric_sensor_value_pdr decodedPdr; |
| 2644 | auto rc = |
| 2645 | decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr); |
| 2646 | EXPECT_EQ(PLDM_SUCCESS, rc); |
| 2647 | |
| 2648 | EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT8, decodedPdr.sensor_data_size); |
| 2649 | EXPECT_EQ(100, decodedPdr.max_readable.value_s8); |
| 2650 | EXPECT_EQ(-100, decodedPdr.min_readable.value_s8); |
| 2651 | EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT8, decodedPdr.range_field_format); |
| 2652 | EXPECT_EQ(0, decodedPdr.nominal_value.value_s8); |
| 2653 | EXPECT_EQ(5, decodedPdr.normal_max.value_s8); |
| 2654 | EXPECT_EQ(-5, decodedPdr.normal_min.value_s8); |
| 2655 | EXPECT_EQ(10, decodedPdr.warning_high.value_s8); |
| 2656 | EXPECT_EQ(-10, decodedPdr.warning_low.value_s8); |
| 2657 | EXPECT_EQ(20, decodedPdr.critical_high.value_s8); |
| 2658 | EXPECT_EQ(-20, decodedPdr.critical_low.value_s8); |
| 2659 | EXPECT_EQ(30, decodedPdr.fatal_high.value_s8); |
| 2660 | EXPECT_EQ(-30, decodedPdr.fatal_low.value_s8); |
| 2661 | } |
| 2662 | |
| 2663 | TEST(decodeNumericSensorPdrData, Uint16Test) |
| 2664 | { |
| 2665 | std::vector<uint8_t> pdr1{ |
| 2666 | 0x1, |
| 2667 | 0x0, |
| 2668 | 0x0, |
| 2669 | 0x0, // record handle |
| 2670 | 0x1, // PDRHeaderVersion |
| 2671 | PLDM_NUMERIC_SENSOR_PDR, // PDRType |
| 2672 | 0x0, |
| 2673 | 0x0, // recordChangeNumber |
| 2674 | PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH + |
| 2675 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 2 + |
| 2676 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 2, |
| 2677 | 0, // dataLength |
| 2678 | 0, |
| 2679 | 0, // PLDMTerminusHandle |
| 2680 | 0x1, |
| 2681 | 0x0, // sensorID=1 |
| 2682 | PLDM_ENTITY_POWER_SUPPLY, |
| 2683 | 0, // entityType=Power Supply(120) |
| 2684 | 1, |
| 2685 | 0, // entityInstanceNumber |
| 2686 | 0x1, |
| 2687 | 0x0, // containerID=1 |
| 2688 | PLDM_NO_INIT, // sensorInit |
| 2689 | false, // sensorAuxiliaryNamesPDR |
| 2690 | PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C |
| 2691 | 0, // unitModifier |
| 2692 | 0, // rateUnit |
| 2693 | 0, // baseOEMUnitHandle |
| 2694 | 0, // auxUnit |
| 2695 | 0, // auxUnitModifier |
| 2696 | 0, // auxRateUnit |
| 2697 | 0, // rel |
| 2698 | 0, // auxOEMUnitHandle |
| 2699 | true, // isLinear |
| 2700 | PLDM_SENSOR_DATA_SIZE_UINT16, // sensorDataSize |
| 2701 | 0, |
| 2702 | 0, |
| 2703 | 0, |
| 2704 | 0, // resolution |
| 2705 | 0, |
| 2706 | 0, |
| 2707 | 0, |
| 2708 | 0, // offset |
| 2709 | 0, |
| 2710 | 0, // accuracy |
| 2711 | 0, // plusTolerance |
| 2712 | 0, // minusTolerance |
| 2713 | 3, |
| 2714 | 0, // hysteresis = 3 |
| 2715 | 0, // supportedThresholds |
| 2716 | 0, // thresholdAndHysteresisVolatility |
| 2717 | 0, |
| 2718 | 0, |
| 2719 | 0x80, |
| 2720 | 0x3f, // stateTransistionInterval=1.0 |
| 2721 | 0, |
| 2722 | 0, |
| 2723 | 0x80, |
| 2724 | 0x3f, // updateInverval=1.0 |
| 2725 | 0, |
| 2726 | 0x10, // maxReadable = 4096 |
| 2727 | 0, |
| 2728 | 0, // minReadable = 0 |
| 2729 | PLDM_RANGE_FIELD_FORMAT_UINT16, // rangeFieldFormat |
| 2730 | 0, // rangeFieldsupport |
| 2731 | 0x88, |
| 2732 | 0x13, // nominalValue = 5,000 |
| 2733 | 0x70, |
| 2734 | 0x17, // normalMax = 6,000 |
| 2735 | 0xa0, |
| 2736 | 0x0f, // normalMin = 4,000 |
| 2737 | 0x58, |
| 2738 | 0x1b, // warningHigh = 7,000 |
| 2739 | 0xb8, |
| 2740 | 0x0b, // warningLow = 3,000 |
| 2741 | 0x40, |
| 2742 | 0x1f, // criticalHigh = 8,000 |
| 2743 | 0xd0, |
| 2744 | 0x07, // criticalLow = 2,000 |
| 2745 | 0x28, |
| 2746 | 0x23, // fatalHigh = 9,000 |
| 2747 | 0xe8, |
| 2748 | 0x03 // fatalLow = 1,000 |
| 2749 | }; |
| 2750 | |
| 2751 | struct pldm_numeric_sensor_value_pdr decodedPdr; |
| 2752 | auto rc = |
| 2753 | decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr); |
| 2754 | EXPECT_EQ(PLDM_SUCCESS, rc); |
| 2755 | |
| 2756 | EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_UINT16, decodedPdr.sensor_data_size); |
| 2757 | EXPECT_EQ(4096, decodedPdr.max_readable.value_u16); |
| 2758 | EXPECT_EQ(0, decodedPdr.min_readable.value_u16); |
| 2759 | EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT16, decodedPdr.range_field_format); |
| 2760 | EXPECT_EQ(5000, decodedPdr.nominal_value.value_u16); |
| 2761 | EXPECT_EQ(6000, decodedPdr.normal_max.value_u16); |
| 2762 | EXPECT_EQ(4000, decodedPdr.normal_min.value_u16); |
| 2763 | EXPECT_EQ(7000, decodedPdr.warning_high.value_u16); |
| 2764 | EXPECT_EQ(3000, decodedPdr.warning_low.value_u16); |
| 2765 | EXPECT_EQ(8000, decodedPdr.critical_high.value_u16); |
| 2766 | EXPECT_EQ(2000, decodedPdr.critical_low.value_u16); |
| 2767 | EXPECT_EQ(9000, decodedPdr.fatal_high.value_u16); |
| 2768 | EXPECT_EQ(1000, decodedPdr.fatal_low.value_u16); |
| 2769 | } |
| 2770 | |
| 2771 | TEST(decodeNumericSensorPdrData, Sint16Test) |
| 2772 | { |
| 2773 | std::vector<uint8_t> pdr1{ |
| 2774 | 0x1, |
| 2775 | 0x0, |
| 2776 | 0x0, |
| 2777 | 0x0, // record handle |
| 2778 | 0x1, // PDRHeaderVersion |
| 2779 | PLDM_NUMERIC_SENSOR_PDR, // PDRType |
| 2780 | 0x0, |
| 2781 | 0x0, // recordChangeNumber |
| 2782 | PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH + |
| 2783 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 2 + |
| 2784 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 2, |
| 2785 | 0, // dataLength |
| 2786 | 0, |
| 2787 | 0, // PLDMTerminusHandle |
| 2788 | 0x1, |
| 2789 | 0x0, // sensorID=1 |
| 2790 | PLDM_ENTITY_POWER_SUPPLY, |
| 2791 | 0, // entityType=Power Supply(120) |
| 2792 | 1, |
| 2793 | 0, // entityInstanceNumber |
| 2794 | 0x1, |
| 2795 | 0x0, // containerID=1 |
| 2796 | PLDM_NO_INIT, // sensorInit |
| 2797 | false, // sensorAuxiliaryNamesPDR |
| 2798 | PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C |
| 2799 | 0, // unitModifier |
| 2800 | 0, // rateUnit |
| 2801 | 0, // baseOEMUnitHandle |
| 2802 | 0, // auxUnit |
| 2803 | 0, // auxUnitModifier |
| 2804 | 0, // auxRateUnit |
| 2805 | 0, // rel |
| 2806 | 0, // auxOEMUnitHandle |
| 2807 | true, // isLinear |
| 2808 | PLDM_SENSOR_DATA_SIZE_SINT16, // sensorDataSize |
| 2809 | 0, |
| 2810 | 0, |
| 2811 | 0, |
| 2812 | 0, // resolution |
| 2813 | 0, |
| 2814 | 0, |
| 2815 | 0, |
| 2816 | 0, // offset |
| 2817 | 0, |
| 2818 | 0, // accuracy |
| 2819 | 0, // plusTolerance |
| 2820 | 0, // minusTolerance |
| 2821 | 3, |
| 2822 | 0, // hysteresis |
| 2823 | 0, // supportedThresholds |
| 2824 | 0, // thresholdAndHysteresisVolatility |
| 2825 | 0, |
| 2826 | 0, |
| 2827 | 0x80, |
| 2828 | 0x3f, // stateTransistionInterval=1.0 |
| 2829 | 0, |
| 2830 | 0, |
| 2831 | 0x80, |
| 2832 | 0x3f, // updateInverval=1.0 |
| 2833 | 0xe8, |
| 2834 | 0x03, // maxReadable = 1000 |
| 2835 | 0x18, |
| 2836 | 0xfc, // minReadable = -1000 |
| 2837 | PLDM_RANGE_FIELD_FORMAT_SINT16, // rangeFieldFormat |
| 2838 | 0, // rangeFieldsupport |
| 2839 | 0, |
| 2840 | 0, // nominalValue = 0 |
| 2841 | 0xf4, |
| 2842 | 0x01, // normalMax = 500 |
| 2843 | 0x0c, |
| 2844 | 0xfe, // normalMin = -500 |
| 2845 | 0xe8, |
| 2846 | 0x03, // warningHigh = 1,000 |
| 2847 | 0x18, |
| 2848 | 0xfc, // warningLow = -1,000 |
| 2849 | 0xd0, |
| 2850 | 0x07, // criticalHigh = 2,000 |
| 2851 | 0x30, |
| 2852 | 0xf8, // criticalLow = -2,000 |
| 2853 | 0xb8, |
| 2854 | 0x0b, // fatalHigh = 3,000 |
| 2855 | 0x48, |
| 2856 | 0xf4 // fatalLow = -3,000 |
| 2857 | }; |
| 2858 | |
| 2859 | struct pldm_numeric_sensor_value_pdr decodedPdr; |
| 2860 | auto rc = |
| 2861 | decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr); |
| 2862 | EXPECT_EQ(PLDM_SUCCESS, rc); |
| 2863 | |
| 2864 | EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT16, decodedPdr.sensor_data_size); |
| 2865 | EXPECT_EQ(1000, decodedPdr.max_readable.value_s16); |
| 2866 | EXPECT_EQ(-1000, decodedPdr.min_readable.value_s16); |
| 2867 | EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT16, decodedPdr.range_field_format); |
| 2868 | EXPECT_EQ(0, decodedPdr.nominal_value.value_s16); |
| 2869 | EXPECT_EQ(500, decodedPdr.normal_max.value_s16); |
| 2870 | EXPECT_EQ(-500, decodedPdr.normal_min.value_s16); |
| 2871 | EXPECT_EQ(1000, decodedPdr.warning_high.value_s16); |
| 2872 | EXPECT_EQ(-1000, decodedPdr.warning_low.value_s16); |
| 2873 | EXPECT_EQ(2000, decodedPdr.critical_high.value_s16); |
| 2874 | EXPECT_EQ(-2000, decodedPdr.critical_low.value_s16); |
| 2875 | EXPECT_EQ(3000, decodedPdr.fatal_high.value_s16); |
| 2876 | EXPECT_EQ(-3000, decodedPdr.fatal_low.value_s16); |
| 2877 | } |
| 2878 | |
| 2879 | TEST(decodeNumericSensorPdrData, Uint32Test) |
| 2880 | { |
| 2881 | std::vector<uint8_t> pdr1{ |
| 2882 | 0x1, |
| 2883 | 0x0, |
| 2884 | 0x0, |
| 2885 | 0x0, // record handle |
| 2886 | 0x1, // PDRHeaderVersion |
| 2887 | PLDM_NUMERIC_SENSOR_PDR, // PDRType |
| 2888 | 0x0, |
| 2889 | 0x0, // recordChangeNumber |
| 2890 | PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH + |
| 2891 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 4 + |
| 2892 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4, |
| 2893 | 0, // dataLength |
| 2894 | 0, |
| 2895 | 0, // PLDMTerminusHandle |
| 2896 | 0x1, |
| 2897 | 0x0, // sensorID=1 |
| 2898 | PLDM_ENTITY_POWER_SUPPLY, |
| 2899 | 0, // entityType=Power Supply(120) |
| 2900 | 1, |
| 2901 | 0, // entityInstanceNumber |
| 2902 | 0x1, |
| 2903 | 0x0, // containerID=1 |
| 2904 | PLDM_NO_INIT, // sensorInit |
| 2905 | false, // sensorAuxiliaryNamesPDR |
| 2906 | PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C |
| 2907 | 0, // unitModifier |
| 2908 | 0, // rateUnit |
| 2909 | 0, // baseOEMUnitHandle |
| 2910 | 0, // auxUnit |
| 2911 | 0, // auxUnitModifier |
| 2912 | 0, // auxRateUnit |
| 2913 | 0, // rel |
| 2914 | 0, // auxOEMUnitHandle |
| 2915 | true, // isLinear |
| 2916 | PLDM_SENSOR_DATA_SIZE_UINT32, // sensorDataSize |
| 2917 | 0, |
| 2918 | 0, |
| 2919 | 0, |
| 2920 | 0, // resolution |
| 2921 | 0, |
| 2922 | 0, |
| 2923 | 0, |
| 2924 | 0, // offset |
| 2925 | 0, |
| 2926 | 0, // accuracy |
| 2927 | 0, // plusTolerance |
| 2928 | 0, // minusTolerance |
| 2929 | 3, |
| 2930 | 0, |
| 2931 | 0, |
| 2932 | 0, // hysteresis |
| 2933 | 0, // supportedThresholds |
| 2934 | 0, // thresholdAndHysteresisVolatility |
| 2935 | 0, |
| 2936 | 0, |
| 2937 | 0x80, |
| 2938 | 0x3f, // stateTransistionInterval=1.0 |
| 2939 | 0, |
| 2940 | 0, |
| 2941 | 0x80, |
| 2942 | 0x3f, // updateInverval=1.0 |
| 2943 | 0, |
| 2944 | 0x10, |
| 2945 | 0, |
| 2946 | 0, // maxReadable = 4096 |
| 2947 | 0, |
| 2948 | 0, |
| 2949 | 0, |
| 2950 | 0, // minReadable = 0 |
| 2951 | PLDM_RANGE_FIELD_FORMAT_UINT32, // rangeFieldFormat |
| 2952 | 0, // rangeFieldsupport |
| 2953 | 0x40, |
| 2954 | 0x4b, |
| 2955 | 0x4c, |
| 2956 | 0x00, // nominalValue = 5,000,000 |
| 2957 | 0x80, |
| 2958 | 0x8d, |
| 2959 | 0x5b, |
| 2960 | 0x00, // normalMax = 6,000,000 |
| 2961 | 0x00, |
| 2962 | 0x09, |
| 2963 | 0x3d, |
| 2964 | 0x00, // normalMin = 4,000,000 |
| 2965 | 0xc0, |
| 2966 | 0xcf, |
| 2967 | 0x6a, |
| 2968 | 0x00, // warningHigh = 7,000,000 |
| 2969 | 0xc0, |
| 2970 | 0xc6, |
| 2971 | 0x2d, |
| 2972 | 0x00, // warningLow = 3,000,000 |
| 2973 | 0x00, |
| 2974 | 0x12, |
| 2975 | 0x7a, |
| 2976 | 0x00, // criticalHigh = 8,000,000 |
| 2977 | 0x80, |
| 2978 | 0x84, |
| 2979 | 0x1e, |
| 2980 | 0x00, // criticalLow = 2,000,000 |
| 2981 | 0x40, |
| 2982 | 0x54, |
| 2983 | 0x89, |
| 2984 | 0x00, // fatalHigh = 9,000,000 |
| 2985 | 0x40, |
| 2986 | 0x42, |
| 2987 | 0x0f, |
| 2988 | 0x00 // fatalLow = 1,000,000 |
| 2989 | }; |
| 2990 | |
| 2991 | struct pldm_numeric_sensor_value_pdr decodedPdr; |
| 2992 | auto rc = |
| 2993 | decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr); |
| 2994 | EXPECT_EQ(PLDM_SUCCESS, rc); |
| 2995 | |
| 2996 | EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_UINT32, decodedPdr.sensor_data_size); |
| 2997 | EXPECT_EQ(4096, decodedPdr.max_readable.value_u32); |
| 2998 | EXPECT_EQ(0, decodedPdr.min_readable.value_u32); |
| 2999 | EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_UINT32, decodedPdr.range_field_format); |
| 3000 | EXPECT_EQ(5000000, decodedPdr.nominal_value.value_u32); |
| 3001 | EXPECT_EQ(6000000, decodedPdr.normal_max.value_u32); |
| 3002 | EXPECT_EQ(4000000, decodedPdr.normal_min.value_u32); |
| 3003 | EXPECT_EQ(7000000, decodedPdr.warning_high.value_u32); |
| 3004 | EXPECT_EQ(3000000, decodedPdr.warning_low.value_u32); |
| 3005 | EXPECT_EQ(8000000, decodedPdr.critical_high.value_u32); |
| 3006 | EXPECT_EQ(2000000, decodedPdr.critical_low.value_u32); |
| 3007 | EXPECT_EQ(9000000, decodedPdr.fatal_high.value_u32); |
| 3008 | EXPECT_EQ(1000000, decodedPdr.fatal_low.value_u32); |
| 3009 | } |
| 3010 | |
| 3011 | TEST(decodeNumericSensorPdrData, Sint32Test) |
| 3012 | { |
| 3013 | std::vector<uint8_t> pdr1{ |
| 3014 | 0x1, |
| 3015 | 0x0, |
| 3016 | 0x0, |
| 3017 | 0x0, // record handle |
| 3018 | 0x1, // PDRHeaderVersion |
| 3019 | PLDM_NUMERIC_SENSOR_PDR, // PDRType |
| 3020 | 0x0, |
| 3021 | 0x0, // recordChangeNumber |
| 3022 | PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH + |
| 3023 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 4 + |
| 3024 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4, |
| 3025 | 0, // dataLength |
| 3026 | 0, |
| 3027 | 0, // PLDMTerminusHandle |
| 3028 | 0x1, |
| 3029 | 0x0, // sensorID=1 |
| 3030 | PLDM_ENTITY_POWER_SUPPLY, |
| 3031 | 0, // entityType=Power Supply(120) |
| 3032 | 1, |
| 3033 | 0, // entityInstanceNumber |
| 3034 | 0x1, |
| 3035 | 0x0, // containerID=1 |
| 3036 | PLDM_NO_INIT, // sensorInit |
| 3037 | false, // sensorAuxiliaryNamesPDR |
| 3038 | PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C |
| 3039 | 0, // unitModifier |
| 3040 | 0, // rateUnit |
| 3041 | 0, // baseOEMUnitHandle |
| 3042 | 0, // auxUnit |
| 3043 | 0, // auxUnitModifier |
| 3044 | 0, // auxRateUnit |
| 3045 | 0, // rel |
| 3046 | 0, // auxOEMUnitHandle |
| 3047 | true, // isLinear |
| 3048 | PLDM_SENSOR_DATA_SIZE_SINT32, // sensorDataSize |
| 3049 | 0, |
| 3050 | 0, |
| 3051 | 0, |
| 3052 | 0, // resolution |
| 3053 | 0, |
| 3054 | 0, |
| 3055 | 0, |
| 3056 | 0, // offset |
| 3057 | 0, |
| 3058 | 0, // accuracy |
| 3059 | 0, // plusTolerance |
| 3060 | 0, // minusTolerance |
| 3061 | 3, |
| 3062 | 0, |
| 3063 | 0, |
| 3064 | 0, // hysteresis |
| 3065 | 0, // supportedThresholds |
| 3066 | 0, // thresholdAndHysteresisVolatility |
| 3067 | 0, |
| 3068 | 0, |
| 3069 | 0x80, |
| 3070 | 0x3f, // stateTransistionInterval=1.0 |
| 3071 | 0, |
| 3072 | 0, |
| 3073 | 0x80, |
| 3074 | 0x3f, // updateInverval=1.0 |
| 3075 | 0xa0, |
| 3076 | 0x86, |
| 3077 | 0x01, |
| 3078 | 0x00, // maxReadable = 100000 |
| 3079 | 0x60, |
| 3080 | 0x79, |
| 3081 | 0xfe, |
| 3082 | 0xff, // minReadable = -10000 |
| 3083 | PLDM_RANGE_FIELD_FORMAT_SINT32, // rangeFieldFormat |
| 3084 | 0, // rangeFieldsupport |
| 3085 | 0, |
| 3086 | 0, |
| 3087 | 0, |
| 3088 | 0, // nominalValue = 0 |
| 3089 | 0x20, |
| 3090 | 0xa1, |
| 3091 | 0x07, |
| 3092 | 0x00, // normalMax = 500,000 |
| 3093 | 0xe0, |
| 3094 | 0x5e, |
| 3095 | 0xf8, |
| 3096 | 0xff, // normalMin = -500,000 |
| 3097 | 0x40, |
| 3098 | 0x42, |
| 3099 | 0x0f, |
| 3100 | 0x00, // warningHigh = 1,000,000 |
| 3101 | 0xc0, |
| 3102 | 0xbd, |
| 3103 | 0xf0, |
| 3104 | 0xff, // warningLow = -1,000,000 |
| 3105 | 0x80, |
| 3106 | 0x84, |
| 3107 | 0x1e, |
| 3108 | 0x00, // criticalHigh = 2,000,000 |
| 3109 | 0x80, |
| 3110 | 0x7b, |
| 3111 | 0xe1, |
| 3112 | 0xff, // criticalLow = -2,000,000 |
| 3113 | 0xc0, |
| 3114 | 0xc6, |
| 3115 | 0x2d, |
| 3116 | 0x00, // fatalHigh = 3,000,000 |
| 3117 | 0x40, |
| 3118 | 0x39, |
| 3119 | 0xd2, |
| 3120 | 0xff // fatalLow = -3,000,000 |
| 3121 | }; |
| 3122 | |
| 3123 | struct pldm_numeric_sensor_value_pdr decodedPdr; |
| 3124 | auto rc = |
| 3125 | decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr); |
| 3126 | EXPECT_EQ(PLDM_SUCCESS, rc); |
| 3127 | |
| 3128 | EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT32, decodedPdr.sensor_data_size); |
| 3129 | EXPECT_EQ(100000, decodedPdr.max_readable.value_s32); |
| 3130 | EXPECT_EQ(-100000, decodedPdr.min_readable.value_s32); |
| 3131 | EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_SINT32, decodedPdr.range_field_format); |
| 3132 | EXPECT_EQ(0, decodedPdr.nominal_value.value_s32); |
| 3133 | EXPECT_EQ(500000, decodedPdr.normal_max.value_s32); |
| 3134 | EXPECT_EQ(-500000, decodedPdr.normal_min.value_s32); |
| 3135 | EXPECT_EQ(1000000, decodedPdr.warning_high.value_s32); |
| 3136 | EXPECT_EQ(-1000000, decodedPdr.warning_low.value_s32); |
| 3137 | EXPECT_EQ(2000000, decodedPdr.critical_high.value_s32); |
| 3138 | EXPECT_EQ(-2000000, decodedPdr.critical_low.value_s32); |
| 3139 | EXPECT_EQ(3000000, decodedPdr.fatal_high.value_s32); |
| 3140 | EXPECT_EQ(-3000000, decodedPdr.fatal_low.value_s32); |
| 3141 | } |
| 3142 | |
| 3143 | TEST(decodeNumericSensorPdrData, Real32Test) |
| 3144 | { |
| 3145 | std::vector<uint8_t> pdr1{ |
| 3146 | 0x1, |
| 3147 | 0x0, |
| 3148 | 0x0, |
| 3149 | 0x0, // record handle |
| 3150 | 0x1, // PDRHeaderVersion |
| 3151 | PLDM_NUMERIC_SENSOR_PDR, // PDRType |
| 3152 | 0x0, |
| 3153 | 0x0, // recordChangeNumber |
| 3154 | PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH + |
| 3155 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH * 4 + |
| 3156 | PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH * 4, |
| 3157 | 0, // dataLength |
| 3158 | 0, |
| 3159 | 0, // PLDMTerminusHandle |
| 3160 | 0x1, |
| 3161 | 0x0, // sensorID=1 |
| 3162 | PLDM_ENTITY_POWER_SUPPLY, |
| 3163 | 0, // entityType=Power Supply(120) |
| 3164 | 1, |
| 3165 | 0, // entityInstanceNumber |
| 3166 | 0x1, |
| 3167 | 0x0, // containerID=1 |
| 3168 | PLDM_NO_INIT, // sensorInit |
| 3169 | false, // sensorAuxiliaryNamesPDR |
| 3170 | PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C |
| 3171 | 0, // unitModifier |
| 3172 | 0, // rateUnit |
| 3173 | 0, // baseOEMUnitHandle |
| 3174 | 0, // auxUnit |
| 3175 | 0, // auxUnitModifier |
| 3176 | 0, // auxRateUnit |
| 3177 | 0, // rel |
| 3178 | 0, // auxOEMUnitHandle |
| 3179 | true, // isLinear |
| 3180 | PLDM_SENSOR_DATA_SIZE_SINT32, // sensorDataSize |
| 3181 | 0, |
| 3182 | 0, |
| 3183 | 0, |
| 3184 | 0, // resolution |
| 3185 | 0, |
| 3186 | 0, |
| 3187 | 0, |
| 3188 | 0, // offset |
| 3189 | 0, |
| 3190 | 0, // accuracy |
| 3191 | 0, // plusTolerance |
| 3192 | 0, // minusTolerance |
| 3193 | 3, |
| 3194 | 0, |
| 3195 | 0, |
| 3196 | 0, // hysteresis |
| 3197 | 0, // supportedThresholds |
| 3198 | 0, // thresholdAndHysteresisVolatility |
| 3199 | 0, |
| 3200 | 0, |
| 3201 | 0x80, |
| 3202 | 0x3f, // stateTransistionInterval=1.0 |
| 3203 | 0, |
| 3204 | 0, |
| 3205 | 0x80, |
| 3206 | 0x3f, // updateInverval=1.0 |
| 3207 | 0xa0, |
| 3208 | 0x86, |
| 3209 | 0x01, |
| 3210 | 0x00, // maxReadable = 100000 |
| 3211 | 0x60, |
| 3212 | 0x79, |
| 3213 | 0xfe, |
| 3214 | 0xff, // minReadable = -10000 |
| 3215 | PLDM_RANGE_FIELD_FORMAT_REAL32, // rangeFieldFormat |
| 3216 | 0, // rangeFieldsupport |
| 3217 | 0, |
| 3218 | 0, |
| 3219 | 0, |
| 3220 | 0, // nominalValue = 0.0 |
| 3221 | 0x33, |
| 3222 | 0x33, |
| 3223 | 0x48, |
| 3224 | 0x42, // normalMax = 50.05 |
| 3225 | 0x33, |
| 3226 | 0x33, |
| 3227 | 0x48, |
| 3228 | 0xc2, // normalMin = -50.05 |
| 3229 | 0x83, |
| 3230 | 0x00, |
| 3231 | 0xc8, |
| 3232 | 0x42, // warningHigh = 100.001 |
| 3233 | 0x83, |
| 3234 | 0x00, |
| 3235 | 0xc8, |
| 3236 | 0xc2, // warningLow = -100.001 |
| 3237 | 0x83, |
| 3238 | 0x00, |
| 3239 | 0x48, |
| 3240 | 0x43, // criticalHigh = 200.002 |
| 3241 | 0x83, |
| 3242 | 0x00, |
| 3243 | 0x48, |
| 3244 | 0xc3, // criticalLow = -200.002 |
| 3245 | 0x62, |
| 3246 | 0x00, |
| 3247 | 0x96, |
| 3248 | 0x43, // fatalHigh = 300.003 |
| 3249 | 0x62, |
| 3250 | 0x00, |
| 3251 | 0x96, |
| 3252 | 0xc3 // fatalLow = -300.003 |
| 3253 | }; |
| 3254 | |
| 3255 | struct pldm_numeric_sensor_value_pdr decodedPdr; |
| 3256 | auto rc = |
| 3257 | decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr); |
| 3258 | EXPECT_EQ(PLDM_SUCCESS, rc); |
| 3259 | |
| 3260 | EXPECT_EQ(PLDM_SENSOR_DATA_SIZE_SINT32, decodedPdr.sensor_data_size); |
| 3261 | EXPECT_EQ(100000, decodedPdr.max_readable.value_s32); |
| 3262 | EXPECT_EQ(-100000, decodedPdr.min_readable.value_s32); |
| 3263 | EXPECT_EQ(PLDM_RANGE_FIELD_FORMAT_REAL32, decodedPdr.range_field_format); |
| 3264 | EXPECT_FLOAT_EQ(0, decodedPdr.nominal_value.value_f32); |
| 3265 | EXPECT_FLOAT_EQ(50.05f, decodedPdr.normal_max.value_f32); |
| 3266 | EXPECT_FLOAT_EQ(-50.05f, decodedPdr.normal_min.value_f32); |
| 3267 | EXPECT_FLOAT_EQ(100.001f, decodedPdr.warning_high.value_f32); |
| 3268 | EXPECT_FLOAT_EQ(-100.001f, decodedPdr.warning_low.value_f32); |
| 3269 | EXPECT_FLOAT_EQ(200.002f, decodedPdr.critical_high.value_f32); |
| 3270 | EXPECT_FLOAT_EQ(-200.002f, decodedPdr.critical_low.value_f32); |
| 3271 | EXPECT_FLOAT_EQ(300.003f, decodedPdr.fatal_high.value_f32); |
| 3272 | EXPECT_FLOAT_EQ(-300.003f, decodedPdr.fatal_low.value_f32); |
| 3273 | } |
| 3274 | |
| 3275 | TEST(decodeNumericSensorPdrDataDeathTest, InvalidSizeTest) |
| 3276 | { |
| 3277 | // A corrupted PDR. The data after plusTolerance missed. |
| 3278 | std::vector<uint8_t> pdr1{ |
| 3279 | 0x1, |
| 3280 | 0x0, |
| 3281 | 0x0, |
| 3282 | 0x0, // record handle |
| 3283 | 0x1, // PDRHeaderVersion |
| 3284 | PLDM_NUMERIC_SENSOR_PDR, // PDRType |
| 3285 | 0x0, |
| 3286 | 0x0, // recordChangeNumber |
| 3287 | PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH, |
| 3288 | 0, // dataLength |
| 3289 | 0, |
| 3290 | 0, // PLDMTerminusHandle |
| 3291 | 0x1, |
| 3292 | 0x0, // sensorID=1 |
| 3293 | PLDM_ENTITY_POWER_SUPPLY, |
| 3294 | 0, // entityType=Power Supply(120) |
| 3295 | 1, |
| 3296 | 0, // entityInstanceNumber |
| 3297 | 0x1, |
| 3298 | 0x0, // containerID=1 |
| 3299 | PLDM_NO_INIT, // sensorInit |
| 3300 | false, // sensorAuxiliaryNamesPDR |
| 3301 | 2, // baseUint(2)=degrees C |
| 3302 | 0, // unitModifier |
| 3303 | 0, // rateUnit |
| 3304 | 0, // baseOEMUnitHandle |
| 3305 | 0, // auxUnit |
| 3306 | 0, // auxUnitModifier |
| 3307 | 0, // auxRateUnit |
| 3308 | 0, // rel |
| 3309 | 0, // auxOEMUnitHandle |
| 3310 | true, // isLinear |
| 3311 | PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize |
| 3312 | 0, |
| 3313 | 0, |
| 3314 | 0, |
| 3315 | 0, // resolution |
| 3316 | 0, |
| 3317 | 0, |
| 3318 | 0, |
| 3319 | 0, // offset |
| 3320 | 0, |
| 3321 | 0, // accuracy |
| 3322 | 0 // plusTolerance |
| 3323 | }; |
| 3324 | |
| 3325 | struct pldm_numeric_sensor_value_pdr decodedPdr; |
| 3326 | int rc = |
| 3327 | decode_numeric_sensor_pdr_data(pdr1.data(), pdr1.size(), &decodedPdr); |
| 3328 | EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH); |
| 3329 | } |