TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 1 | #include "libpldmresponder/event_parser.hpp" |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 2 | #include "libpldmresponder/pdr.hpp" |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 3 | #include "libpldmresponder/pdr_utils.hpp" |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 4 | #include "libpldmresponder/platform.hpp" |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 5 | #include "libpldmresponder/platform_numeric_effecter.hpp" |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 6 | #include "libpldmresponder/platform_state_effecter.hpp" |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 7 | #include "mocked_utils.hpp" |
| 8 | #include "utils.hpp" |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 9 | |
| 10 | #include <iostream> |
| 11 | |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 12 | using namespace pldm::utils; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 13 | using namespace pldm::responder; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 14 | using namespace pldm::responder::platform; |
| 15 | using namespace pldm::responder::pdr; |
| 16 | using namespace pldm::responder::pdr_utils; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 17 | |
| 18 | TEST(getPDR, testGoodPath) |
| 19 | { |
| 20 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 21 | requestPayload{}; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 22 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 23 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 24 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 25 | struct pldm_get_pdr_req* request = |
| 26 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 27 | request->request_count = 100; |
| 28 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 29 | auto pdrRepo = pldm_pdr_init(); |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 30 | Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good", |
| 31 | pdrRepo, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 32 | Repo repo(pdrRepo); |
| 33 | ASSERT_EQ(repo.empty(), false); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 34 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 35 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 36 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 37 | struct pldm_get_pdr_resp* resp = |
| 38 | reinterpret_cast<struct pldm_get_pdr_resp*>(responsePtr->payload); |
| 39 | ASSERT_EQ(PLDM_SUCCESS, resp->completion_code); |
| 40 | ASSERT_EQ(2, resp->next_record_handle); |
| 41 | ASSERT_EQ(true, resp->response_count != 0); |
| 42 | |
| 43 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(resp->record_data); |
| 44 | ASSERT_EQ(hdr->record_handle, 1); |
| 45 | ASSERT_EQ(hdr->version, 1); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 46 | |
| 47 | pldm_pdr_destroy(pdrRepo); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | TEST(getPDR, testShortRead) |
| 51 | { |
| 52 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 53 | requestPayload{}; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 54 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 55 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 56 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 57 | struct pldm_get_pdr_req* request = |
| 58 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 59 | request->request_count = 1; |
| 60 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 61 | auto pdrRepo = pldm_pdr_init(); |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 62 | Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good", |
| 63 | pdrRepo, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 64 | Repo repo(pdrRepo); |
| 65 | ASSERT_EQ(repo.empty(), false); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 66 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 67 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 68 | struct pldm_get_pdr_resp* resp = |
| 69 | reinterpret_cast<struct pldm_get_pdr_resp*>(responsePtr->payload); |
| 70 | ASSERT_EQ(PLDM_SUCCESS, resp->completion_code); |
| 71 | ASSERT_EQ(1, resp->response_count); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 72 | pldm_pdr_destroy(pdrRepo); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | TEST(getPDR, testBadRecordHandle) |
| 76 | { |
| 77 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 78 | requestPayload{}; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 79 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 80 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 81 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 82 | struct pldm_get_pdr_req* request = |
| 83 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 84 | request->record_handle = 100000; |
| 85 | request->request_count = 1; |
| 86 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 87 | auto pdrRepo = pldm_pdr_init(); |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 88 | Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good", |
| 89 | pdrRepo, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 90 | Repo repo(pdrRepo); |
| 91 | ASSERT_EQ(repo.empty(), false); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 92 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 93 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 94 | |
| 95 | ASSERT_EQ(responsePtr->payload[0], PLDM_PLATFORM_INVALID_RECORD_HANDLE); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 96 | |
| 97 | pldm_pdr_destroy(pdrRepo); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | TEST(getPDR, testNoNextRecord) |
| 101 | { |
| 102 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 103 | requestPayload{}; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 104 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 105 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 106 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 107 | struct pldm_get_pdr_req* request = |
| 108 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 109 | request->record_handle = 1; |
| 110 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 111 | auto pdrRepo = pldm_pdr_init(); |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 112 | Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good", |
| 113 | pdrRepo, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 114 | Repo repo(pdrRepo); |
| 115 | ASSERT_EQ(repo.empty(), false); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 116 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 117 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 118 | struct pldm_get_pdr_resp* resp = |
| 119 | reinterpret_cast<struct pldm_get_pdr_resp*>(responsePtr->payload); |
| 120 | ASSERT_EQ(PLDM_SUCCESS, resp->completion_code); |
| 121 | ASSERT_EQ(2, resp->next_record_handle); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 122 | |
| 123 | pldm_pdr_destroy(pdrRepo); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | TEST(getPDR, testFindPDR) |
| 127 | { |
| 128 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 129 | requestPayload{}; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 130 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 131 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 132 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 133 | struct pldm_get_pdr_req* request = |
| 134 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 135 | request->request_count = 100; |
| 136 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 137 | auto pdrRepo = pldm_pdr_init(); |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 138 | Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good", |
| 139 | pdrRepo, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 140 | Repo repo(pdrRepo); |
| 141 | ASSERT_EQ(repo.empty(), false); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 142 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 143 | |
| 144 | // Let's try to find a PDR of type stateEffecter (= 11) and entity type = |
| 145 | // 100 |
| 146 | bool found = false; |
| 147 | uint32_t handle = 0; // start asking for PDRs from recordHandle 0 |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 148 | while (!found) |
| 149 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 150 | request->record_handle = handle; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 151 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 152 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 153 | struct pldm_get_pdr_resp* resp = |
| 154 | reinterpret_cast<struct pldm_get_pdr_resp*>(responsePtr->payload); |
| 155 | ASSERT_EQ(PLDM_SUCCESS, resp->completion_code); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 156 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 157 | handle = resp->next_record_handle; // point to the next pdr in case |
| 158 | // current is not what we want |
| 159 | |
| 160 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(resp->record_data); |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 161 | std::cerr << "PDR next record handle " << handle << "\n"; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 162 | std::cerr << "PDR type " << hdr->type << "\n"; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 163 | if (hdr->type == PLDM_STATE_EFFECTER_PDR) |
| 164 | { |
| 165 | pldm_state_effecter_pdr* pdr = |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 166 | reinterpret_cast<pldm_state_effecter_pdr*>(resp->record_data); |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 167 | std::cerr << "PDR entity type " << pdr->entity_type << "\n"; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 168 | if (pdr->entity_type == 100) |
| 169 | { |
| 170 | found = true; |
| 171 | // Rest of the PDR can be accessed as need be |
| 172 | break; |
| 173 | } |
| 174 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 175 | if (!resp->next_record_handle) // no more records |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 176 | { |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | ASSERT_EQ(found, true); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 181 | |
| 182 | pldm_pdr_destroy(pdrRepo); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 183 | } |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 184 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 185 | TEST(setStateEffecterStatesHandler, testGoodRequest) |
| 186 | { |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 187 | auto inPDRRepo = pldm_pdr_init(); |
| 188 | auto outPDRRepo = pldm_pdr_init(); |
| 189 | Repo outRepo(outPDRRepo); |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 190 | Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good", |
| 191 | inPDRRepo, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 192 | Repo inRepo(inPDRRepo); |
| 193 | getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 194 | pdr_utils::PdrEntry e; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 195 | auto record1 = pdr::getRecordByHandle(outRepo, 1, e); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 196 | ASSERT_NE(record1, nullptr); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 197 | pldm_state_effecter_pdr* pdr = |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 198 | reinterpret_cast<pldm_state_effecter_pdr*>(e.data); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 199 | EXPECT_EQ(pdr->hdr.type, PLDM_STATE_EFFECTER_PDR); |
| 200 | |
| 201 | std::vector<set_effecter_state_field> stateField; |
| 202 | stateField.push_back({PLDM_REQUEST_SET, 1}); |
| 203 | stateField.push_back({PLDM_REQUEST_SET, 1}); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 204 | std::string value = "xyz.openbmc_project.Foo.Bar.V1"; |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 205 | PropertyValue propertyValue = value; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 206 | |
| 207 | MockdBusHandler handlerObj; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 208 | DBusMapping dbusMapping{"/foo/bar", "xyz.openbmc_project.Foo.Bar", |
| 209 | "propertyName", "string"}; |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 210 | |
| 211 | EXPECT_CALL(handlerObj, setDbusProperty(dbusMapping, propertyValue)) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 212 | .Times(2); |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 213 | auto rc = platform_state_effecter::setStateEffecterStatesHandler< |
| 214 | MockdBusHandler, Handler>(handlerObj, handler, 0x1, stateField); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 215 | ASSERT_EQ(rc, 0); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 216 | |
| 217 | pldm_pdr_destroy(inPDRRepo); |
| 218 | pldm_pdr_destroy(outPDRRepo); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | TEST(setStateEffecterStatesHandler, testBadRequest) |
| 222 | { |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 223 | auto inPDRRepo = pldm_pdr_init(); |
| 224 | auto outPDRRepo = pldm_pdr_init(); |
| 225 | Repo outRepo(outPDRRepo); |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 226 | Handler handler("./pdr_jsons/state_effecter/good", "./event_jsons/good", |
| 227 | inPDRRepo, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 228 | Repo inRepo(inPDRRepo); |
| 229 | getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 230 | pdr_utils::PdrEntry e; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 231 | auto record1 = pdr::getRecordByHandle(outRepo, 1, e); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 232 | ASSERT_NE(record1, nullptr); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 233 | pldm_state_effecter_pdr* pdr = |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 234 | reinterpret_cast<pldm_state_effecter_pdr*>(e.data); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 235 | EXPECT_EQ(pdr->hdr.type, PLDM_STATE_EFFECTER_PDR); |
| 236 | |
| 237 | std::vector<set_effecter_state_field> stateField; |
| 238 | stateField.push_back({PLDM_REQUEST_SET, 3}); |
| 239 | stateField.push_back({PLDM_REQUEST_SET, 4}); |
| 240 | |
| 241 | MockdBusHandler handlerObj; |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 242 | auto rc = platform_state_effecter::setStateEffecterStatesHandler< |
| 243 | MockdBusHandler, Handler>(handlerObj, handler, 0x1, stateField); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 244 | ASSERT_EQ(rc, PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE); |
| 245 | |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 246 | rc = platform_state_effecter::setStateEffecterStatesHandler<MockdBusHandler, |
| 247 | Handler>( |
| 248 | handlerObj, handler, 0x9, stateField); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 249 | ASSERT_EQ(rc, PLDM_PLATFORM_INVALID_EFFECTER_ID); |
| 250 | |
| 251 | stateField.push_back({PLDM_REQUEST_SET, 4}); |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 252 | rc = platform_state_effecter::setStateEffecterStatesHandler<MockdBusHandler, |
| 253 | Handler>( |
| 254 | handlerObj, handler, 0x1, stateField); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 255 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 256 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 257 | pldm_pdr_destroy(inPDRRepo); |
| 258 | pldm_pdr_destroy(outPDRRepo); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 259 | } |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 260 | |
| 261 | TEST(setNumericEffecterValueHandler, testGoodRequest) |
| 262 | { |
| 263 | auto inPDRRepo = pldm_pdr_init(); |
| 264 | auto numericEffecterPdrRepo = pldm_pdr_init(); |
| 265 | Repo numericEffecterPDRs(numericEffecterPdrRepo); |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 266 | Handler handler("./pdr_jsons/state_effecter/good", "", inPDRRepo, nullptr); |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 267 | Repo inRepo(inPDRRepo); |
| 268 | getRepoByType(inRepo, numericEffecterPDRs, PLDM_NUMERIC_EFFECTER_PDR); |
| 269 | |
| 270 | pdr_utils::PdrEntry e; |
| 271 | auto record3 = pdr::getRecordByHandle(numericEffecterPDRs, 3, e); |
| 272 | ASSERT_NE(record3, nullptr); |
| 273 | |
| 274 | pldm_numeric_effecter_value_pdr* pdr = |
| 275 | reinterpret_cast<pldm_numeric_effecter_value_pdr*>(e.data); |
| 276 | EXPECT_EQ(pdr->hdr.type, PLDM_NUMERIC_EFFECTER_PDR); |
| 277 | |
| 278 | uint16_t effecterId = 3; |
| 279 | uint32_t effecterValue = 2100000000; // 2036-07-18 21:20:00 |
| 280 | PropertyValue propertyValue = static_cast<uint32_t>(effecterValue); |
| 281 | |
| 282 | MockdBusHandler handlerObj; |
| 283 | DBusMapping dbusMapping{"/foo/bar", "xyz.openbmc_project.Foo.Bar", |
| 284 | "propertyName", "uint64_t"}; |
| 285 | EXPECT_CALL(handlerObj, setDbusProperty(dbusMapping, propertyValue)) |
| 286 | .Times(1); |
| 287 | |
| 288 | auto rc = platform_numeric_effecter::setNumericEffecterValueHandler< |
| 289 | MockdBusHandler, Handler>( |
| 290 | handlerObj, handler, effecterId, PLDM_EFFECTER_DATA_SIZE_UINT32, |
| 291 | reinterpret_cast<uint8_t*>(&effecterValue), 4); |
| 292 | ASSERT_EQ(rc, 0); |
| 293 | |
| 294 | pldm_pdr_destroy(inPDRRepo); |
| 295 | pldm_pdr_destroy(numericEffecterPdrRepo); |
| 296 | } |
| 297 | |
| 298 | TEST(setNumericEffecterValueHandler, testBadRequest) |
| 299 | { |
| 300 | auto inPDRRepo = pldm_pdr_init(); |
| 301 | auto numericEffecterPdrRepo = pldm_pdr_init(); |
| 302 | Repo numericEffecterPDRs(numericEffecterPdrRepo); |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 303 | Handler handler("./pdr_jsons/state_effecter/good", "", inPDRRepo, nullptr); |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 304 | Repo inRepo(inPDRRepo); |
| 305 | getRepoByType(inRepo, numericEffecterPDRs, PLDM_NUMERIC_EFFECTER_PDR); |
| 306 | |
| 307 | pdr_utils::PdrEntry e; |
| 308 | auto record3 = pdr::getRecordByHandle(numericEffecterPDRs, 3, e); |
| 309 | ASSERT_NE(record3, nullptr); |
| 310 | |
| 311 | pldm_numeric_effecter_value_pdr* pdr = |
| 312 | reinterpret_cast<pldm_numeric_effecter_value_pdr*>(e.data); |
| 313 | EXPECT_EQ(pdr->hdr.type, PLDM_NUMERIC_EFFECTER_PDR); |
| 314 | |
| 315 | uint16_t effecterId = 3; |
| 316 | uint64_t effecterValue = 9876543210; |
| 317 | MockdBusHandler handlerObj; |
| 318 | auto rc = platform_numeric_effecter::setNumericEffecterValueHandler< |
| 319 | MockdBusHandler, Handler>( |
| 320 | handlerObj, handler, effecterId, PLDM_EFFECTER_DATA_SIZE_SINT32, |
| 321 | reinterpret_cast<uint8_t*>(&effecterValue), 3); |
| 322 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 323 | |
| 324 | pldm_pdr_destroy(inPDRRepo); |
| 325 | pldm_pdr_destroy(numericEffecterPdrRepo); |
| 326 | } |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 327 | |
| 328 | TEST(parseStateSensor, allScenarios) |
| 329 | { |
| 330 | // Sample state sensor with SensorID - 1, EntityType - Processor Module(67) |
| 331 | // State Set ID - Operational Running Status(11), Supported States - 3,4 |
| 332 | std::vector<uint8_t> sample1PDR{0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, |
| 333 | 0x00, 0x17, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 334 | 0x43, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 335 | 0x00, 0x01, 0x0b, 0x00, 0x01, 0x18}; |
| 336 | |
| 337 | const auto& [terminusHandle1, sensorID1, sensorInfo1] = |
| 338 | parseStateSensorPDR(sample1PDR); |
| 339 | const auto& [containerID1, entityType1, entityInstance1] = |
| 340 | std::get<0>(sensorInfo1); |
| 341 | const auto& states1 = std::get<1>(sensorInfo1); |
| 342 | CompositeSensorStates statesCmp1{{3u, 4u}}; |
| 343 | |
| 344 | ASSERT_EQ(le16toh(terminusHandle1), 0u); |
| 345 | ASSERT_EQ(le16toh(sensorID1), 1u); |
| 346 | ASSERT_EQ(le16toh(containerID1), 0u); |
| 347 | ASSERT_EQ(le16toh(entityType1), 67u); |
| 348 | ASSERT_EQ(le16toh(entityInstance1), 1u); |
| 349 | ASSERT_EQ(states1, statesCmp1); |
| 350 | |
| 351 | // Sample state sensor with SensorID - 2, EntityType - System Firmware(31) |
| 352 | // State Set ID - Availability(2), Supported States - 3,4,9,10,11,13 |
| 353 | std::vector<uint8_t> sample2PDR{0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, |
| 354 | 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, |
| 355 | 0x1F, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 356 | 0x00, 0x01, 0x02, 0x00, 0x02, 0x18, 0x2E}; |
| 357 | |
| 358 | const auto& [terminusHandle2, sensorID2, sensorInfo2] = |
| 359 | parseStateSensorPDR(sample2PDR); |
| 360 | const auto& [containerID2, entityType2, entityInstance2] = |
| 361 | std::get<0>(sensorInfo2); |
| 362 | const auto& states2 = std::get<1>(sensorInfo2); |
| 363 | CompositeSensorStates statesCmp2{{3u, 4u, 9u, 10u, 11u, 13u}}; |
| 364 | |
| 365 | ASSERT_EQ(le16toh(terminusHandle2), 0u); |
| 366 | ASSERT_EQ(le16toh(sensorID2), 2u); |
| 367 | ASSERT_EQ(le16toh(containerID2), 0u); |
| 368 | ASSERT_EQ(le16toh(entityType2), 31u); |
| 369 | ASSERT_EQ(le16toh(entityInstance2), 1u); |
| 370 | ASSERT_EQ(states2, statesCmp2); |
| 371 | |
| 372 | // Sample state sensor with SensorID - 3, EntityType - Virtual Machine |
| 373 | // Manager(33), Composite State Sensor -2 , State Set ID - Link State(33), |
| 374 | // Supported States - 1,2, State Set ID - Configuration State(15), |
| 375 | // Supported States - 1,2,3,4 |
| 376 | std::vector<uint8_t> sample3PDR{ |
| 377 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x17, 0x00, 0x00, |
| 378 | 0x00, 0x03, 0x00, 0x21, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 379 | 0x02, 0x21, 0x00, 0x01, 0x06, 0x0F, 0x00, 0x01, 0x1E}; |
| 380 | |
| 381 | const auto& [terminusHandle3, sensorID3, sensorInfo3] = |
| 382 | parseStateSensorPDR(sample3PDR); |
| 383 | const auto& [containerID3, entityType3, entityInstance3] = |
| 384 | std::get<0>(sensorInfo3); |
| 385 | const auto& states3 = std::get<1>(sensorInfo3); |
| 386 | CompositeSensorStates statesCmp3{{1u, 2u}, {1u, 2u, 3u, 4u}}; |
| 387 | |
| 388 | ASSERT_EQ(le16toh(terminusHandle3), 0u); |
| 389 | ASSERT_EQ(le16toh(sensorID3), 3u); |
| 390 | ASSERT_EQ(le16toh(containerID3), 1u); |
| 391 | ASSERT_EQ(le16toh(entityType3), 33u); |
| 392 | ASSERT_EQ(le16toh(entityInstance3), 2u); |
| 393 | ASSERT_EQ(states3, statesCmp3); |
| 394 | } |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 395 | |
| 396 | TEST(StateSensorHandler, allScenarios) |
| 397 | { |
| 398 | using namespace pldm::responder::events; |
| 399 | |
| 400 | ASSERT_THROW(StateSensorHandler("./event_jsons/malformed1"), |
| 401 | std::exception); |
| 402 | ASSERT_THROW(StateSensorHandler("./event_jsons/malformed2"), |
| 403 | std::exception); |
| 404 | |
| 405 | StateSensorHandler handler{"./event_jsons/good"}; |
| 406 | constexpr uint8_t eventState0 = 0; |
| 407 | constexpr uint8_t eventState1 = 1; |
| 408 | constexpr uint8_t eventState2 = 2; |
| 409 | constexpr uint8_t eventState3 = 3; |
| 410 | |
| 411 | // Event Entry 1 |
| 412 | { |
| 413 | StateSensorEntry entry{1, 64, 1, 0}; |
| 414 | const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry); |
| 415 | DBusMapping mapping{"/xyz/abc/def", |
| 416 | "xyz.openbmc_project.example1.value", "value1", |
| 417 | "string"}; |
| 418 | ASSERT_EQ(mapping == dbusMapping, true); |
| 419 | |
| 420 | const auto& propValue0 = eventStateMap.at(eventState0); |
| 421 | const auto& propValue1 = eventStateMap.at(eventState1); |
| 422 | const auto& propValue2 = eventStateMap.at(eventState2); |
| 423 | PropertyValue value0{std::in_place_type<std::string>, |
| 424 | "xyz.openbmc_project.State.Normal"}; |
| 425 | PropertyValue value1{std::in_place_type<std::string>, |
| 426 | "xyz.openbmc_project.State.Critical"}; |
| 427 | PropertyValue value2{std::in_place_type<std::string>, |
| 428 | "xyz.openbmc_project.State.Fatal"}; |
| 429 | ASSERT_EQ(value0 == propValue0, true); |
| 430 | ASSERT_EQ(value1 == propValue1, true); |
| 431 | ASSERT_EQ(value2 == propValue2, true); |
| 432 | } |
| 433 | |
| 434 | // Event Entry 2 |
| 435 | { |
| 436 | StateSensorEntry entry{1, 64, 1, 1}; |
| 437 | const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry); |
| 438 | DBusMapping mapping{"/xyz/abc/def", |
| 439 | "xyz.openbmc_project.example2.value", "value2", |
| 440 | "uint8_t"}; |
| 441 | ASSERT_EQ(mapping == dbusMapping, true); |
| 442 | |
| 443 | const auto& propValue0 = eventStateMap.at(eventState2); |
| 444 | const auto& propValue1 = eventStateMap.at(eventState3); |
| 445 | PropertyValue value0{std::in_place_type<uint8_t>, 9}; |
| 446 | PropertyValue value1{std::in_place_type<uint8_t>, 10}; |
| 447 | ASSERT_EQ(value0 == propValue0, true); |
| 448 | ASSERT_EQ(value1 == propValue1, true); |
| 449 | } |
| 450 | |
| 451 | // Event Entry 3 |
| 452 | { |
| 453 | StateSensorEntry entry{2, 67, 2, 0}; |
| 454 | const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry); |
| 455 | DBusMapping mapping{"/xyz/abc/ghi", |
| 456 | "xyz.openbmc_project.example3.value", "value3", |
| 457 | "bool"}; |
| 458 | ASSERT_EQ(mapping == dbusMapping, true); |
| 459 | |
| 460 | const auto& propValue0 = eventStateMap.at(eventState0); |
| 461 | const auto& propValue1 = eventStateMap.at(eventState1); |
| 462 | PropertyValue value0{std::in_place_type<bool>, false}; |
| 463 | PropertyValue value1{std::in_place_type<bool>, true}; |
| 464 | ASSERT_EQ(value0 == propValue0, true); |
| 465 | ASSERT_EQ(value1 == propValue1, true); |
| 466 | } |
| 467 | |
| 468 | // Invalid Entry |
| 469 | { |
| 470 | StateSensorEntry entry{0, 0, 0, 0}; |
| 471 | ASSERT_THROW(handler.getEventInfo(entry), std::out_of_range); |
| 472 | } |
| 473 | } |