Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 1 | #include "common/utils.hpp" |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 2 | #include "libpldmresponder/event_parser.hpp" |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 3 | #include "libpldmresponder/pdr.hpp" |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 4 | #include "libpldmresponder/pdr_utils.hpp" |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 5 | #include "libpldmresponder/platform.hpp" |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 6 | #include "libpldmresponder/platform_numeric_effecter.hpp" |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 7 | #include "libpldmresponder/platform_state_effecter.hpp" |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 8 | #include "mocked_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", |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 31 | pdrRepo, nullptr, 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", |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 63 | pdrRepo, nullptr, 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", |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 89 | pdrRepo, nullptr, 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", |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 113 | pdrRepo, nullptr, 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", |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 139 | pdrRepo, nullptr, 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", |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 191 | inPDRRepo, nullptr, 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", |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 227 | inPDRRepo, nullptr, 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 | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 266 | Handler handler("./pdr_jsons/state_effecter/good", "", inPDRRepo, nullptr, |
| 267 | nullptr); |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 268 | Repo inRepo(inPDRRepo); |
| 269 | getRepoByType(inRepo, numericEffecterPDRs, PLDM_NUMERIC_EFFECTER_PDR); |
| 270 | |
| 271 | pdr_utils::PdrEntry e; |
| 272 | auto record3 = pdr::getRecordByHandle(numericEffecterPDRs, 3, e); |
| 273 | ASSERT_NE(record3, nullptr); |
| 274 | |
| 275 | pldm_numeric_effecter_value_pdr* pdr = |
| 276 | reinterpret_cast<pldm_numeric_effecter_value_pdr*>(e.data); |
| 277 | EXPECT_EQ(pdr->hdr.type, PLDM_NUMERIC_EFFECTER_PDR); |
| 278 | |
| 279 | uint16_t effecterId = 3; |
| 280 | uint32_t effecterValue = 2100000000; // 2036-07-18 21:20:00 |
| 281 | PropertyValue propertyValue = static_cast<uint32_t>(effecterValue); |
| 282 | |
| 283 | MockdBusHandler handlerObj; |
| 284 | DBusMapping dbusMapping{"/foo/bar", "xyz.openbmc_project.Foo.Bar", |
| 285 | "propertyName", "uint64_t"}; |
| 286 | EXPECT_CALL(handlerObj, setDbusProperty(dbusMapping, propertyValue)) |
| 287 | .Times(1); |
| 288 | |
| 289 | auto rc = platform_numeric_effecter::setNumericEffecterValueHandler< |
| 290 | MockdBusHandler, Handler>( |
| 291 | handlerObj, handler, effecterId, PLDM_EFFECTER_DATA_SIZE_UINT32, |
| 292 | reinterpret_cast<uint8_t*>(&effecterValue), 4); |
| 293 | ASSERT_EQ(rc, 0); |
| 294 | |
| 295 | pldm_pdr_destroy(inPDRRepo); |
| 296 | pldm_pdr_destroy(numericEffecterPdrRepo); |
| 297 | } |
| 298 | |
| 299 | TEST(setNumericEffecterValueHandler, testBadRequest) |
| 300 | { |
| 301 | auto inPDRRepo = pldm_pdr_init(); |
| 302 | auto numericEffecterPdrRepo = pldm_pdr_init(); |
| 303 | Repo numericEffecterPDRs(numericEffecterPdrRepo); |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 304 | Handler handler("./pdr_jsons/state_effecter/good", "", inPDRRepo, nullptr, |
| 305 | nullptr); |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 306 | Repo inRepo(inPDRRepo); |
| 307 | getRepoByType(inRepo, numericEffecterPDRs, PLDM_NUMERIC_EFFECTER_PDR); |
| 308 | |
| 309 | pdr_utils::PdrEntry e; |
| 310 | auto record3 = pdr::getRecordByHandle(numericEffecterPDRs, 3, e); |
| 311 | ASSERT_NE(record3, nullptr); |
| 312 | |
| 313 | pldm_numeric_effecter_value_pdr* pdr = |
| 314 | reinterpret_cast<pldm_numeric_effecter_value_pdr*>(e.data); |
| 315 | EXPECT_EQ(pdr->hdr.type, PLDM_NUMERIC_EFFECTER_PDR); |
| 316 | |
| 317 | uint16_t effecterId = 3; |
| 318 | uint64_t effecterValue = 9876543210; |
| 319 | MockdBusHandler handlerObj; |
| 320 | auto rc = platform_numeric_effecter::setNumericEffecterValueHandler< |
| 321 | MockdBusHandler, Handler>( |
| 322 | handlerObj, handler, effecterId, PLDM_EFFECTER_DATA_SIZE_SINT32, |
| 323 | reinterpret_cast<uint8_t*>(&effecterValue), 3); |
| 324 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 325 | |
| 326 | pldm_pdr_destroy(inPDRRepo); |
| 327 | pldm_pdr_destroy(numericEffecterPdrRepo); |
| 328 | } |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 329 | |
| 330 | TEST(parseStateSensor, allScenarios) |
| 331 | { |
| 332 | // Sample state sensor with SensorID - 1, EntityType - Processor Module(67) |
| 333 | // State Set ID - Operational Running Status(11), Supported States - 3,4 |
| 334 | std::vector<uint8_t> sample1PDR{0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, |
| 335 | 0x00, 0x17, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 336 | 0x43, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 337 | 0x00, 0x01, 0x0b, 0x00, 0x01, 0x18}; |
| 338 | |
| 339 | const auto& [terminusHandle1, sensorID1, sensorInfo1] = |
| 340 | parseStateSensorPDR(sample1PDR); |
| 341 | const auto& [containerID1, entityType1, entityInstance1] = |
| 342 | std::get<0>(sensorInfo1); |
| 343 | const auto& states1 = std::get<1>(sensorInfo1); |
| 344 | CompositeSensorStates statesCmp1{{3u, 4u}}; |
| 345 | |
| 346 | ASSERT_EQ(le16toh(terminusHandle1), 0u); |
| 347 | ASSERT_EQ(le16toh(sensorID1), 1u); |
| 348 | ASSERT_EQ(le16toh(containerID1), 0u); |
| 349 | ASSERT_EQ(le16toh(entityType1), 67u); |
| 350 | ASSERT_EQ(le16toh(entityInstance1), 1u); |
| 351 | ASSERT_EQ(states1, statesCmp1); |
| 352 | |
| 353 | // Sample state sensor with SensorID - 2, EntityType - System Firmware(31) |
| 354 | // State Set ID - Availability(2), Supported States - 3,4,9,10,11,13 |
| 355 | std::vector<uint8_t> sample2PDR{0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, |
| 356 | 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, |
| 357 | 0x1F, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 358 | 0x00, 0x01, 0x02, 0x00, 0x02, 0x18, 0x2E}; |
| 359 | |
| 360 | const auto& [terminusHandle2, sensorID2, sensorInfo2] = |
| 361 | parseStateSensorPDR(sample2PDR); |
| 362 | const auto& [containerID2, entityType2, entityInstance2] = |
| 363 | std::get<0>(sensorInfo2); |
| 364 | const auto& states2 = std::get<1>(sensorInfo2); |
| 365 | CompositeSensorStates statesCmp2{{3u, 4u, 9u, 10u, 11u, 13u}}; |
| 366 | |
| 367 | ASSERT_EQ(le16toh(terminusHandle2), 0u); |
| 368 | ASSERT_EQ(le16toh(sensorID2), 2u); |
| 369 | ASSERT_EQ(le16toh(containerID2), 0u); |
| 370 | ASSERT_EQ(le16toh(entityType2), 31u); |
| 371 | ASSERT_EQ(le16toh(entityInstance2), 1u); |
| 372 | ASSERT_EQ(states2, statesCmp2); |
| 373 | |
| 374 | // Sample state sensor with SensorID - 3, EntityType - Virtual Machine |
| 375 | // Manager(33), Composite State Sensor -2 , State Set ID - Link State(33), |
| 376 | // Supported States - 1,2, State Set ID - Configuration State(15), |
| 377 | // Supported States - 1,2,3,4 |
| 378 | std::vector<uint8_t> sample3PDR{ |
| 379 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x17, 0x00, 0x00, |
| 380 | 0x00, 0x03, 0x00, 0x21, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 381 | 0x02, 0x21, 0x00, 0x01, 0x06, 0x0F, 0x00, 0x01, 0x1E}; |
| 382 | |
| 383 | const auto& [terminusHandle3, sensorID3, sensorInfo3] = |
| 384 | parseStateSensorPDR(sample3PDR); |
| 385 | const auto& [containerID3, entityType3, entityInstance3] = |
| 386 | std::get<0>(sensorInfo3); |
| 387 | const auto& states3 = std::get<1>(sensorInfo3); |
| 388 | CompositeSensorStates statesCmp3{{1u, 2u}, {1u, 2u, 3u, 4u}}; |
| 389 | |
| 390 | ASSERT_EQ(le16toh(terminusHandle3), 0u); |
| 391 | ASSERT_EQ(le16toh(sensorID3), 3u); |
| 392 | ASSERT_EQ(le16toh(containerID3), 1u); |
| 393 | ASSERT_EQ(le16toh(entityType3), 33u); |
| 394 | ASSERT_EQ(le16toh(entityInstance3), 2u); |
| 395 | ASSERT_EQ(states3, statesCmp3); |
| 396 | } |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 397 | |
| 398 | TEST(StateSensorHandler, allScenarios) |
| 399 | { |
| 400 | using namespace pldm::responder::events; |
| 401 | |
| 402 | ASSERT_THROW(StateSensorHandler("./event_jsons/malformed1"), |
| 403 | std::exception); |
| 404 | ASSERT_THROW(StateSensorHandler("./event_jsons/malformed2"), |
| 405 | std::exception); |
| 406 | |
| 407 | StateSensorHandler handler{"./event_jsons/good"}; |
| 408 | constexpr uint8_t eventState0 = 0; |
| 409 | constexpr uint8_t eventState1 = 1; |
| 410 | constexpr uint8_t eventState2 = 2; |
| 411 | constexpr uint8_t eventState3 = 3; |
| 412 | |
| 413 | // Event Entry 1 |
| 414 | { |
| 415 | StateSensorEntry entry{1, 64, 1, 0}; |
| 416 | const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry); |
| 417 | DBusMapping mapping{"/xyz/abc/def", |
| 418 | "xyz.openbmc_project.example1.value", "value1", |
| 419 | "string"}; |
| 420 | ASSERT_EQ(mapping == dbusMapping, true); |
| 421 | |
| 422 | const auto& propValue0 = eventStateMap.at(eventState0); |
| 423 | const auto& propValue1 = eventStateMap.at(eventState1); |
| 424 | const auto& propValue2 = eventStateMap.at(eventState2); |
| 425 | PropertyValue value0{std::in_place_type<std::string>, |
| 426 | "xyz.openbmc_project.State.Normal"}; |
| 427 | PropertyValue value1{std::in_place_type<std::string>, |
| 428 | "xyz.openbmc_project.State.Critical"}; |
| 429 | PropertyValue value2{std::in_place_type<std::string>, |
| 430 | "xyz.openbmc_project.State.Fatal"}; |
| 431 | ASSERT_EQ(value0 == propValue0, true); |
| 432 | ASSERT_EQ(value1 == propValue1, true); |
| 433 | ASSERT_EQ(value2 == propValue2, true); |
| 434 | } |
| 435 | |
| 436 | // Event Entry 2 |
| 437 | { |
| 438 | StateSensorEntry entry{1, 64, 1, 1}; |
| 439 | const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry); |
| 440 | DBusMapping mapping{"/xyz/abc/def", |
| 441 | "xyz.openbmc_project.example2.value", "value2", |
| 442 | "uint8_t"}; |
| 443 | ASSERT_EQ(mapping == dbusMapping, true); |
| 444 | |
| 445 | const auto& propValue0 = eventStateMap.at(eventState2); |
| 446 | const auto& propValue1 = eventStateMap.at(eventState3); |
| 447 | PropertyValue value0{std::in_place_type<uint8_t>, 9}; |
| 448 | PropertyValue value1{std::in_place_type<uint8_t>, 10}; |
| 449 | ASSERT_EQ(value0 == propValue0, true); |
| 450 | ASSERT_EQ(value1 == propValue1, true); |
| 451 | } |
| 452 | |
| 453 | // Event Entry 3 |
| 454 | { |
| 455 | StateSensorEntry entry{2, 67, 2, 0}; |
| 456 | const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry); |
| 457 | DBusMapping mapping{"/xyz/abc/ghi", |
| 458 | "xyz.openbmc_project.example3.value", "value3", |
| 459 | "bool"}; |
| 460 | ASSERT_EQ(mapping == dbusMapping, true); |
| 461 | |
| 462 | const auto& propValue0 = eventStateMap.at(eventState0); |
| 463 | const auto& propValue1 = eventStateMap.at(eventState1); |
| 464 | PropertyValue value0{std::in_place_type<bool>, false}; |
| 465 | PropertyValue value1{std::in_place_type<bool>, true}; |
| 466 | ASSERT_EQ(value0 == propValue0, true); |
| 467 | ASSERT_EQ(value1 == propValue1, true); |
| 468 | } |
| 469 | |
| 470 | // Invalid Entry |
| 471 | { |
| 472 | StateSensorEntry entry{0, 0, 0, 0}; |
| 473 | ASSERT_THROW(handler.getEventInfo(entry), std::out_of_range); |
| 474 | } |
| 475 | } |