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