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 | a917012 | 2020-05-14 11:59:13 +0800 | [diff] [blame] | 8 | #include "libpldmresponder/platform_state_sensor.hpp" |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 9 | #include "mocked_utils.hpp" |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 10 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 11 | #include <sdbusplus/test/sdbus_mock.hpp> |
| 12 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 13 | #include <iostream> |
| 14 | |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 15 | using namespace pldm::utils; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 16 | using namespace pldm::responder; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 17 | using namespace pldm::responder::platform; |
| 18 | using namespace pldm::responder::pdr; |
| 19 | using namespace pldm::responder::pdr_utils; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 20 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 21 | using ::testing::_; |
| 22 | using ::testing::Return; |
| 23 | using ::testing::StrEq; |
| 24 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 25 | TEST(getPDR, testGoodPath) |
| 26 | { |
| 27 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 28 | requestPayload{}; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 29 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 30 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 31 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 32 | struct pldm_get_pdr_req* request = |
| 33 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 34 | request->request_count = 100; |
| 35 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 36 | MockdBusHandler mockedUtils; |
| 37 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 38 | .Times(5) |
| 39 | .WillRepeatedly(Return("foo.bar")); |
| 40 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 41 | auto pdrRepo = pldm_pdr_init(); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 42 | Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 43 | "./event_jsons/good", pdrRepo, nullptr, nullptr, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 44 | Repo repo(pdrRepo); |
| 45 | ASSERT_EQ(repo.empty(), false); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 46 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 47 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 48 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 49 | struct pldm_get_pdr_resp* resp = |
| 50 | reinterpret_cast<struct pldm_get_pdr_resp*>(responsePtr->payload); |
| 51 | ASSERT_EQ(PLDM_SUCCESS, resp->completion_code); |
| 52 | ASSERT_EQ(2, resp->next_record_handle); |
| 53 | ASSERT_EQ(true, resp->response_count != 0); |
| 54 | |
| 55 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(resp->record_data); |
| 56 | ASSERT_EQ(hdr->record_handle, 1); |
| 57 | ASSERT_EQ(hdr->version, 1); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 58 | |
| 59 | pldm_pdr_destroy(pdrRepo); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | TEST(getPDR, testShortRead) |
| 63 | { |
| 64 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 65 | requestPayload{}; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 66 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 67 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 68 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 69 | struct pldm_get_pdr_req* request = |
| 70 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 71 | request->request_count = 1; |
| 72 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 73 | MockdBusHandler mockedUtils; |
| 74 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 75 | .Times(5) |
| 76 | .WillRepeatedly(Return("foo.bar")); |
| 77 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 78 | auto pdrRepo = pldm_pdr_init(); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 79 | Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 80 | "./event_jsons/good", pdrRepo, nullptr, nullptr, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 81 | Repo repo(pdrRepo); |
| 82 | ASSERT_EQ(repo.empty(), false); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 83 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 84 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 85 | struct pldm_get_pdr_resp* resp = |
| 86 | reinterpret_cast<struct pldm_get_pdr_resp*>(responsePtr->payload); |
| 87 | ASSERT_EQ(PLDM_SUCCESS, resp->completion_code); |
| 88 | ASSERT_EQ(1, resp->response_count); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 89 | pldm_pdr_destroy(pdrRepo); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | TEST(getPDR, testBadRecordHandle) |
| 93 | { |
| 94 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 95 | requestPayload{}; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 96 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 97 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 98 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 99 | struct pldm_get_pdr_req* request = |
| 100 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 101 | request->record_handle = 100000; |
| 102 | request->request_count = 1; |
| 103 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 104 | MockdBusHandler mockedUtils; |
| 105 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 106 | .Times(5) |
| 107 | .WillRepeatedly(Return("foo.bar")); |
| 108 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 109 | auto pdrRepo = pldm_pdr_init(); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 110 | Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 111 | "./event_jsons/good", pdrRepo, nullptr, nullptr, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 112 | Repo repo(pdrRepo); |
| 113 | ASSERT_EQ(repo.empty(), false); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 114 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 115 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 116 | |
| 117 | ASSERT_EQ(responsePtr->payload[0], PLDM_PLATFORM_INVALID_RECORD_HANDLE); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 118 | |
| 119 | pldm_pdr_destroy(pdrRepo); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | TEST(getPDR, testNoNextRecord) |
| 123 | { |
| 124 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 125 | requestPayload{}; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 126 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 127 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 128 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 129 | struct pldm_get_pdr_req* request = |
| 130 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 131 | request->record_handle = 1; |
| 132 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 133 | MockdBusHandler mockedUtils; |
| 134 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 135 | .Times(5) |
| 136 | .WillRepeatedly(Return("foo.bar")); |
| 137 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 138 | auto pdrRepo = pldm_pdr_init(); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 139 | Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 140 | "./event_jsons/good", pdrRepo, nullptr, nullptr, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 141 | Repo repo(pdrRepo); |
| 142 | ASSERT_EQ(repo.empty(), false); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 143 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 144 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 145 | struct pldm_get_pdr_resp* resp = |
| 146 | reinterpret_cast<struct pldm_get_pdr_resp*>(responsePtr->payload); |
| 147 | ASSERT_EQ(PLDM_SUCCESS, resp->completion_code); |
| 148 | ASSERT_EQ(2, resp->next_record_handle); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 149 | |
| 150 | pldm_pdr_destroy(pdrRepo); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | TEST(getPDR, testFindPDR) |
| 154 | { |
| 155 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 156 | requestPayload{}; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 157 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 158 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 159 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 160 | struct pldm_get_pdr_req* request = |
| 161 | reinterpret_cast<struct pldm_get_pdr_req*>(req->payload); |
| 162 | request->request_count = 100; |
| 163 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 164 | MockdBusHandler mockedUtils; |
| 165 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 166 | .Times(5) |
| 167 | .WillRepeatedly(Return("foo.bar")); |
| 168 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 169 | auto pdrRepo = pldm_pdr_init(); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 170 | Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 171 | "./event_jsons/good", pdrRepo, nullptr, nullptr, nullptr); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 172 | Repo repo(pdrRepo); |
| 173 | ASSERT_EQ(repo.empty(), false); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 174 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 175 | |
| 176 | // Let's try to find a PDR of type stateEffecter (= 11) and entity type = |
| 177 | // 100 |
| 178 | bool found = false; |
| 179 | uint32_t handle = 0; // start asking for PDRs from recordHandle 0 |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 180 | while (!found) |
| 181 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 182 | request->record_handle = handle; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 183 | auto response = handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 184 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 185 | struct pldm_get_pdr_resp* resp = |
| 186 | reinterpret_cast<struct pldm_get_pdr_resp*>(responsePtr->payload); |
| 187 | ASSERT_EQ(PLDM_SUCCESS, resp->completion_code); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 188 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 189 | handle = resp->next_record_handle; // point to the next pdr in case |
| 190 | // current is not what we want |
| 191 | |
| 192 | pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(resp->record_data); |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 193 | std::cerr << "PDR next record handle " << handle << "\n"; |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 194 | std::cerr << "PDR type " << hdr->type << "\n"; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 195 | if (hdr->type == PLDM_STATE_EFFECTER_PDR) |
| 196 | { |
| 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*>(resp->record_data); |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 199 | std::cerr << "PDR entity type " << pdr->entity_type << "\n"; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 200 | if (pdr->entity_type == 100) |
| 201 | { |
| 202 | found = true; |
| 203 | // Rest of the PDR can be accessed as need be |
| 204 | break; |
| 205 | } |
| 206 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 207 | if (!resp->next_record_handle) // no more records |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 208 | { |
| 209 | break; |
| 210 | } |
| 211 | } |
| 212 | ASSERT_EQ(found, true); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 213 | |
| 214 | pldm_pdr_destroy(pdrRepo); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 215 | } |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 216 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 217 | TEST(setStateEffecterStatesHandler, testGoodRequest) |
| 218 | { |
George Liu | a917012 | 2020-05-14 11:59:13 +0800 | [diff] [blame] | 219 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 220 | requestPayload{}; |
| 221 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
| 222 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 223 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 224 | MockdBusHandler mockedUtils; |
| 225 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 226 | .Times(5) |
| 227 | .WillRepeatedly(Return("foo.bar")); |
| 228 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 229 | auto inPDRRepo = pldm_pdr_init(); |
| 230 | auto outPDRRepo = pldm_pdr_init(); |
| 231 | Repo outRepo(outPDRRepo); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 232 | Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 233 | "./event_jsons/good", inPDRRepo, nullptr, nullptr, nullptr); |
George Liu | a917012 | 2020-05-14 11:59:13 +0800 | [diff] [blame] | 234 | handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 235 | Repo inRepo(inPDRRepo); |
| 236 | getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 237 | pdr_utils::PdrEntry e; |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 238 | auto record1 = pdr::getRecordByHandle(outRepo, 2, e); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 239 | ASSERT_NE(record1, nullptr); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 240 | pldm_state_effecter_pdr* pdr = |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 241 | reinterpret_cast<pldm_state_effecter_pdr*>(e.data); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 242 | EXPECT_EQ(pdr->hdr.type, PLDM_STATE_EFFECTER_PDR); |
| 243 | |
| 244 | std::vector<set_effecter_state_field> stateField; |
| 245 | stateField.push_back({PLDM_REQUEST_SET, 1}); |
| 246 | stateField.push_back({PLDM_REQUEST_SET, 1}); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 247 | std::string value = "xyz.openbmc_project.Foo.Bar.V1"; |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 248 | PropertyValue propertyValue = value; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 249 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 250 | DBusMapping dbusMapping{"/foo/bar", "xyz.openbmc_project.Foo.Bar", |
| 251 | "propertyName", "string"}; |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 252 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 253 | EXPECT_CALL(mockedUtils, setDbusProperty(dbusMapping, propertyValue)) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 254 | .Times(2); |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 255 | auto rc = platform_state_effecter::setStateEffecterStatesHandler< |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 256 | MockdBusHandler, Handler>(mockedUtils, handler, 0x1, stateField); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 257 | ASSERT_EQ(rc, 0); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 258 | |
| 259 | pldm_pdr_destroy(inPDRRepo); |
| 260 | pldm_pdr_destroy(outPDRRepo); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | TEST(setStateEffecterStatesHandler, testBadRequest) |
| 264 | { |
George Liu | a917012 | 2020-05-14 11:59:13 +0800 | [diff] [blame] | 265 | std::array<uint8_t, sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES> |
| 266 | requestPayload{}; |
| 267 | auto req = reinterpret_cast<pldm_msg*>(requestPayload.data()); |
| 268 | size_t requestPayloadLength = requestPayload.size() - sizeof(pldm_msg_hdr); |
| 269 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 270 | MockdBusHandler mockedUtils; |
| 271 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 272 | .Times(5) |
| 273 | .WillRepeatedly(Return("foo.bar")); |
| 274 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 275 | auto inPDRRepo = pldm_pdr_init(); |
| 276 | auto outPDRRepo = pldm_pdr_init(); |
| 277 | Repo outRepo(outPDRRepo); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 278 | Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 279 | "./event_jsons/good", inPDRRepo, nullptr, nullptr, nullptr); |
George Liu | a917012 | 2020-05-14 11:59:13 +0800 | [diff] [blame] | 280 | handler.getPDR(req, requestPayloadLength); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 281 | Repo inRepo(inPDRRepo); |
| 282 | getRepoByType(inRepo, outRepo, PLDM_STATE_EFFECTER_PDR); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 283 | pdr_utils::PdrEntry e; |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 284 | auto record1 = pdr::getRecordByHandle(outRepo, 2, e); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 285 | ASSERT_NE(record1, nullptr); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 286 | pldm_state_effecter_pdr* pdr = |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 287 | reinterpret_cast<pldm_state_effecter_pdr*>(e.data); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 288 | EXPECT_EQ(pdr->hdr.type, PLDM_STATE_EFFECTER_PDR); |
| 289 | |
| 290 | std::vector<set_effecter_state_field> stateField; |
| 291 | stateField.push_back({PLDM_REQUEST_SET, 3}); |
| 292 | stateField.push_back({PLDM_REQUEST_SET, 4}); |
| 293 | |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 294 | auto rc = platform_state_effecter::setStateEffecterStatesHandler< |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 295 | MockdBusHandler, Handler>(mockedUtils, handler, 0x1, stateField); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 296 | ASSERT_EQ(rc, PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE); |
| 297 | |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 298 | rc = platform_state_effecter::setStateEffecterStatesHandler<MockdBusHandler, |
| 299 | Handler>( |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 300 | mockedUtils, handler, 0x9, stateField); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 301 | ASSERT_EQ(rc, PLDM_PLATFORM_INVALID_EFFECTER_ID); |
| 302 | |
| 303 | stateField.push_back({PLDM_REQUEST_SET, 4}); |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 304 | rc = platform_state_effecter::setStateEffecterStatesHandler<MockdBusHandler, |
| 305 | Handler>( |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 306 | mockedUtils, handler, 0x1, stateField); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 307 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 308 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 309 | pldm_pdr_destroy(inPDRRepo); |
| 310 | pldm_pdr_destroy(outPDRRepo); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 311 | } |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 312 | |
| 313 | TEST(setNumericEffecterValueHandler, testGoodRequest) |
| 314 | { |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 315 | MockdBusHandler mockedUtils; |
| 316 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 317 | .Times(5) |
| 318 | .WillRepeatedly(Return("foo.bar")); |
| 319 | |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 320 | auto inPDRRepo = pldm_pdr_init(); |
| 321 | auto numericEffecterPdrRepo = pldm_pdr_init(); |
| 322 | Repo numericEffecterPDRs(numericEffecterPdrRepo); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 323 | Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", "", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 324 | inPDRRepo, nullptr, nullptr, nullptr); |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 325 | Repo inRepo(inPDRRepo); |
| 326 | getRepoByType(inRepo, numericEffecterPDRs, PLDM_NUMERIC_EFFECTER_PDR); |
| 327 | |
| 328 | pdr_utils::PdrEntry e; |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 329 | auto record4 = pdr::getRecordByHandle(numericEffecterPDRs, 4, e); |
| 330 | ASSERT_NE(record4, nullptr); |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 331 | |
| 332 | pldm_numeric_effecter_value_pdr* pdr = |
| 333 | reinterpret_cast<pldm_numeric_effecter_value_pdr*>(e.data); |
| 334 | EXPECT_EQ(pdr->hdr.type, PLDM_NUMERIC_EFFECTER_PDR); |
| 335 | |
| 336 | uint16_t effecterId = 3; |
| 337 | uint32_t effecterValue = 2100000000; // 2036-07-18 21:20:00 |
| 338 | PropertyValue propertyValue = static_cast<uint32_t>(effecterValue); |
| 339 | |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 340 | DBusMapping dbusMapping{"/foo/bar", "xyz.openbmc_project.Foo.Bar", |
| 341 | "propertyName", "uint64_t"}; |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 342 | EXPECT_CALL(mockedUtils, setDbusProperty(dbusMapping, propertyValue)) |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 343 | .Times(1); |
| 344 | |
| 345 | auto rc = platform_numeric_effecter::setNumericEffecterValueHandler< |
| 346 | MockdBusHandler, Handler>( |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 347 | mockedUtils, handler, effecterId, PLDM_EFFECTER_DATA_SIZE_UINT32, |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 348 | reinterpret_cast<uint8_t*>(&effecterValue), 4); |
| 349 | ASSERT_EQ(rc, 0); |
| 350 | |
| 351 | pldm_pdr_destroy(inPDRRepo); |
| 352 | pldm_pdr_destroy(numericEffecterPdrRepo); |
| 353 | } |
| 354 | |
| 355 | TEST(setNumericEffecterValueHandler, testBadRequest) |
| 356 | { |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 357 | MockdBusHandler mockedUtils; |
| 358 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 359 | .Times(5) |
| 360 | .WillRepeatedly(Return("foo.bar")); |
| 361 | |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 362 | auto inPDRRepo = pldm_pdr_init(); |
| 363 | auto numericEffecterPdrRepo = pldm_pdr_init(); |
| 364 | Repo numericEffecterPDRs(numericEffecterPdrRepo); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 365 | Handler handler(&mockedUtils, "./pdr_jsons/state_effecter/good", "", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 366 | inPDRRepo, nullptr, nullptr, nullptr); |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 367 | Repo inRepo(inPDRRepo); |
| 368 | getRepoByType(inRepo, numericEffecterPDRs, PLDM_NUMERIC_EFFECTER_PDR); |
| 369 | |
| 370 | pdr_utils::PdrEntry e; |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 371 | auto record4 = pdr::getRecordByHandle(numericEffecterPDRs, 4, e); |
| 372 | ASSERT_NE(record4, nullptr); |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 373 | |
| 374 | pldm_numeric_effecter_value_pdr* pdr = |
| 375 | reinterpret_cast<pldm_numeric_effecter_value_pdr*>(e.data); |
| 376 | EXPECT_EQ(pdr->hdr.type, PLDM_NUMERIC_EFFECTER_PDR); |
| 377 | |
| 378 | uint16_t effecterId = 3; |
| 379 | uint64_t effecterValue = 9876543210; |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 380 | auto rc = platform_numeric_effecter::setNumericEffecterValueHandler< |
| 381 | MockdBusHandler, Handler>( |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 382 | mockedUtils, handler, effecterId, PLDM_EFFECTER_DATA_SIZE_SINT32, |
George Liu | 64d26be | 2020-01-15 10:58:10 +0800 | [diff] [blame] | 383 | reinterpret_cast<uint8_t*>(&effecterValue), 3); |
| 384 | ASSERT_EQ(rc, PLDM_ERROR_INVALID_DATA); |
| 385 | |
| 386 | pldm_pdr_destroy(inPDRRepo); |
| 387 | pldm_pdr_destroy(numericEffecterPdrRepo); |
| 388 | } |
Tom Joseph | b426860 | 2020-04-17 17:20:45 +0530 | [diff] [blame] | 389 | |
| 390 | TEST(parseStateSensor, allScenarios) |
| 391 | { |
| 392 | // Sample state sensor with SensorID - 1, EntityType - Processor Module(67) |
| 393 | // State Set ID - Operational Running Status(11), Supported States - 3,4 |
| 394 | std::vector<uint8_t> sample1PDR{0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, |
| 395 | 0x00, 0x17, 0x00, 0x00, 0x00, 0x01, 0x00, |
| 396 | 0x43, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 397 | 0x00, 0x01, 0x0b, 0x00, 0x01, 0x18}; |
| 398 | |
| 399 | const auto& [terminusHandle1, sensorID1, sensorInfo1] = |
| 400 | parseStateSensorPDR(sample1PDR); |
| 401 | const auto& [containerID1, entityType1, entityInstance1] = |
| 402 | std::get<0>(sensorInfo1); |
| 403 | const auto& states1 = std::get<1>(sensorInfo1); |
| 404 | CompositeSensorStates statesCmp1{{3u, 4u}}; |
| 405 | |
| 406 | ASSERT_EQ(le16toh(terminusHandle1), 0u); |
| 407 | ASSERT_EQ(le16toh(sensorID1), 1u); |
| 408 | ASSERT_EQ(le16toh(containerID1), 0u); |
| 409 | ASSERT_EQ(le16toh(entityType1), 67u); |
| 410 | ASSERT_EQ(le16toh(entityInstance1), 1u); |
| 411 | ASSERT_EQ(states1, statesCmp1); |
| 412 | |
| 413 | // Sample state sensor with SensorID - 2, EntityType - System Firmware(31) |
| 414 | // State Set ID - Availability(2), Supported States - 3,4,9,10,11,13 |
| 415 | std::vector<uint8_t> sample2PDR{0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, |
| 416 | 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, |
| 417 | 0x1F, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 418 | 0x00, 0x01, 0x02, 0x00, 0x02, 0x18, 0x2E}; |
| 419 | |
| 420 | const auto& [terminusHandle2, sensorID2, sensorInfo2] = |
| 421 | parseStateSensorPDR(sample2PDR); |
| 422 | const auto& [containerID2, entityType2, entityInstance2] = |
| 423 | std::get<0>(sensorInfo2); |
| 424 | const auto& states2 = std::get<1>(sensorInfo2); |
| 425 | CompositeSensorStates statesCmp2{{3u, 4u, 9u, 10u, 11u, 13u}}; |
| 426 | |
| 427 | ASSERT_EQ(le16toh(terminusHandle2), 0u); |
| 428 | ASSERT_EQ(le16toh(sensorID2), 2u); |
| 429 | ASSERT_EQ(le16toh(containerID2), 0u); |
| 430 | ASSERT_EQ(le16toh(entityType2), 31u); |
| 431 | ASSERT_EQ(le16toh(entityInstance2), 1u); |
| 432 | ASSERT_EQ(states2, statesCmp2); |
| 433 | |
| 434 | // Sample state sensor with SensorID - 3, EntityType - Virtual Machine |
| 435 | // Manager(33), Composite State Sensor -2 , State Set ID - Link State(33), |
| 436 | // Supported States - 1,2, State Set ID - Configuration State(15), |
| 437 | // Supported States - 1,2,3,4 |
| 438 | std::vector<uint8_t> sample3PDR{ |
| 439 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x17, 0x00, 0x00, |
| 440 | 0x00, 0x03, 0x00, 0x21, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 441 | 0x02, 0x21, 0x00, 0x01, 0x06, 0x0F, 0x00, 0x01, 0x1E}; |
| 442 | |
| 443 | const auto& [terminusHandle3, sensorID3, sensorInfo3] = |
| 444 | parseStateSensorPDR(sample3PDR); |
| 445 | const auto& [containerID3, entityType3, entityInstance3] = |
| 446 | std::get<0>(sensorInfo3); |
| 447 | const auto& states3 = std::get<1>(sensorInfo3); |
| 448 | CompositeSensorStates statesCmp3{{1u, 2u}, {1u, 2u, 3u, 4u}}; |
| 449 | |
| 450 | ASSERT_EQ(le16toh(terminusHandle3), 0u); |
| 451 | ASSERT_EQ(le16toh(sensorID3), 3u); |
| 452 | ASSERT_EQ(le16toh(containerID3), 1u); |
| 453 | ASSERT_EQ(le16toh(entityType3), 33u); |
| 454 | ASSERT_EQ(le16toh(entityInstance3), 2u); |
| 455 | ASSERT_EQ(states3, statesCmp3); |
| 456 | } |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 457 | |
| 458 | TEST(StateSensorHandler, allScenarios) |
| 459 | { |
| 460 | using namespace pldm::responder::events; |
| 461 | |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 462 | StateSensorHandler handler{"./event_jsons/good"}; |
| 463 | constexpr uint8_t eventState0 = 0; |
| 464 | constexpr uint8_t eventState1 = 1; |
| 465 | constexpr uint8_t eventState2 = 2; |
| 466 | constexpr uint8_t eventState3 = 3; |
| 467 | |
| 468 | // Event Entry 1 |
| 469 | { |
| 470 | StateSensorEntry entry{1, 64, 1, 0}; |
| 471 | const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry); |
| 472 | DBusMapping mapping{"/xyz/abc/def", |
| 473 | "xyz.openbmc_project.example1.value", "value1", |
| 474 | "string"}; |
| 475 | ASSERT_EQ(mapping == dbusMapping, true); |
| 476 | |
| 477 | const auto& propValue0 = eventStateMap.at(eventState0); |
| 478 | const auto& propValue1 = eventStateMap.at(eventState1); |
| 479 | const auto& propValue2 = eventStateMap.at(eventState2); |
| 480 | PropertyValue value0{std::in_place_type<std::string>, |
| 481 | "xyz.openbmc_project.State.Normal"}; |
| 482 | PropertyValue value1{std::in_place_type<std::string>, |
| 483 | "xyz.openbmc_project.State.Critical"}; |
| 484 | PropertyValue value2{std::in_place_type<std::string>, |
| 485 | "xyz.openbmc_project.State.Fatal"}; |
| 486 | ASSERT_EQ(value0 == propValue0, true); |
| 487 | ASSERT_EQ(value1 == propValue1, true); |
| 488 | ASSERT_EQ(value2 == propValue2, true); |
| 489 | } |
| 490 | |
| 491 | // Event Entry 2 |
| 492 | { |
| 493 | StateSensorEntry entry{1, 64, 1, 1}; |
| 494 | const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry); |
| 495 | DBusMapping mapping{"/xyz/abc/def", |
| 496 | "xyz.openbmc_project.example2.value", "value2", |
| 497 | "uint8_t"}; |
| 498 | ASSERT_EQ(mapping == dbusMapping, true); |
| 499 | |
| 500 | const auto& propValue0 = eventStateMap.at(eventState2); |
| 501 | const auto& propValue1 = eventStateMap.at(eventState3); |
| 502 | PropertyValue value0{std::in_place_type<uint8_t>, 9}; |
| 503 | PropertyValue value1{std::in_place_type<uint8_t>, 10}; |
| 504 | ASSERT_EQ(value0 == propValue0, true); |
| 505 | ASSERT_EQ(value1 == propValue1, true); |
| 506 | } |
| 507 | |
| 508 | // Event Entry 3 |
| 509 | { |
| 510 | StateSensorEntry entry{2, 67, 2, 0}; |
| 511 | const auto& [dbusMapping, eventStateMap] = handler.getEventInfo(entry); |
| 512 | DBusMapping mapping{"/xyz/abc/ghi", |
| 513 | "xyz.openbmc_project.example3.value", "value3", |
| 514 | "bool"}; |
| 515 | ASSERT_EQ(mapping == dbusMapping, true); |
| 516 | |
| 517 | const auto& propValue0 = eventStateMap.at(eventState0); |
| 518 | const auto& propValue1 = eventStateMap.at(eventState1); |
| 519 | PropertyValue value0{std::in_place_type<bool>, false}; |
| 520 | PropertyValue value1{std::in_place_type<bool>, true}; |
| 521 | ASSERT_EQ(value0 == propValue0, true); |
| 522 | ASSERT_EQ(value1 == propValue1, true); |
| 523 | } |
| 524 | |
| 525 | // Invalid Entry |
| 526 | { |
| 527 | StateSensorEntry entry{0, 0, 0, 0}; |
| 528 | ASSERT_THROW(handler.getEventInfo(entry), std::out_of_range); |
| 529 | } |
| 530 | } |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 531 | |
| 532 | TEST(TerminusLocatorPDR, BMCTerminusLocatorPDR) |
| 533 | { |
| 534 | auto inPDRRepo = pldm_pdr_init(); |
| 535 | auto outPDRRepo = pldm_pdr_init(); |
| 536 | Repo outRepo(outPDRRepo); |
| 537 | MockdBusHandler mockedUtils; |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 538 | Handler handler(&mockedUtils, "", "", inPDRRepo, nullptr, nullptr, nullptr); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 539 | Repo inRepo(inPDRRepo); |
| 540 | getRepoByType(inRepo, outRepo, PLDM_TERMINUS_LOCATOR_PDR); |
| 541 | |
| 542 | // 1 BMC terminus locator PDR in the PDR repository |
| 543 | ASSERT_EQ(outRepo.getRecordCount(), 1); |
| 544 | |
| 545 | pdr_utils::PdrEntry entry; |
| 546 | auto record = pdr::getRecordByHandle(outRepo, 1, entry); |
| 547 | ASSERT_NE(record, nullptr); |
| 548 | |
| 549 | auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(entry.data); |
| 550 | EXPECT_EQ(pdr->hdr.record_handle, 1); |
| 551 | EXPECT_EQ(pdr->hdr.version, 1); |
| 552 | EXPECT_EQ(pdr->hdr.type, PLDM_TERMINUS_LOCATOR_PDR); |
| 553 | EXPECT_EQ(pdr->hdr.record_change_num, 0); |
| 554 | EXPECT_EQ(pdr->hdr.length, |
| 555 | sizeof(pldm_terminus_locator_pdr) - sizeof(pldm_pdr_hdr)); |
| 556 | EXPECT_EQ(pdr->terminus_handle, BmcPldmTerminusHandle); |
| 557 | EXPECT_EQ(pdr->validity, PLDM_TL_PDR_VALID); |
| 558 | EXPECT_EQ(pdr->tid, BmcTerminusId); |
| 559 | EXPECT_EQ(pdr->container_id, 0); |
| 560 | EXPECT_EQ(pdr->terminus_locator_type, PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID); |
| 561 | EXPECT_EQ(pdr->terminus_locator_value_size, |
| 562 | sizeof(pldm_terminus_locator_type_mctp_eid)); |
| 563 | auto locatorValue = |
| 564 | reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>( |
| 565 | pdr->terminus_locator_value); |
| 566 | EXPECT_EQ(locatorValue->eid, BmcMctpEid); |
George Liu | a917012 | 2020-05-14 11:59:13 +0800 | [diff] [blame] | 567 | pldm_pdr_destroy(inPDRRepo); |
| 568 | pldm_pdr_destroy(outPDRRepo); |
| 569 | } |
| 570 | |
| 571 | TEST(getStateSensorReadingsHandler, testGoodRequest) |
| 572 | { |
| 573 | MockdBusHandler mockedUtils; |
| 574 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 575 | .Times(1) |
| 576 | .WillRepeatedly(Return("foo.bar")); |
| 577 | |
| 578 | auto inPDRRepo = pldm_pdr_init(); |
| 579 | auto outPDRRepo = pldm_pdr_init(); |
| 580 | Repo outRepo(outPDRRepo); |
| 581 | Handler handler(&mockedUtils, "./pdr_jsons/state_sensor/good", "", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 582 | inPDRRepo, nullptr, nullptr, nullptr); |
George Liu | a917012 | 2020-05-14 11:59:13 +0800 | [diff] [blame] | 583 | Repo inRepo(inPDRRepo); |
| 584 | getRepoByType(inRepo, outRepo, PLDM_STATE_SENSOR_PDR); |
| 585 | pdr_utils::PdrEntry e; |
| 586 | auto record = pdr::getRecordByHandle(outRepo, 2, e); |
| 587 | ASSERT_NE(record, nullptr); |
| 588 | pldm_state_sensor_pdr* pdr = |
| 589 | reinterpret_cast<pldm_state_sensor_pdr*>(e.data); |
| 590 | EXPECT_EQ(pdr->hdr.type, PLDM_STATE_SENSOR_PDR); |
| 591 | |
| 592 | std::vector<get_sensor_state_field> stateField; |
| 593 | uint8_t compSensorCnt{}; |
| 594 | uint8_t sensorRearmCnt = 1; |
| 595 | |
| 596 | MockdBusHandler handlerObj; |
| 597 | EXPECT_CALL(handlerObj, |
| 598 | getDbusPropertyVariant(StrEq("/foo/bar"), StrEq("propertyName"), |
| 599 | StrEq("xyz.openbmc_project.Foo.Bar"))) |
| 600 | .WillOnce(Return( |
| 601 | PropertyValue(std::string("xyz.openbmc_project.Foo.Bar.V0")))); |
| 602 | |
| 603 | auto rc = platform_state_sensor::getStateSensorReadingsHandler< |
| 604 | MockdBusHandler, Handler>(handlerObj, handler, 0x1, sensorRearmCnt, |
| 605 | compSensorCnt, stateField); |
| 606 | ASSERT_EQ(rc, 0); |
| 607 | ASSERT_EQ(compSensorCnt, 1); |
| 608 | ASSERT_EQ(stateField[0].sensor_op_state, PLDM_SENSOR_ENABLED); |
| 609 | ASSERT_EQ(stateField[0].present_state, PLDM_SENSOR_UNKNOWN); |
| 610 | ASSERT_EQ(stateField[0].previous_state, PLDM_SENSOR_UNKNOWN); |
| 611 | ASSERT_EQ(stateField[0].event_state, PLDM_SENSOR_ENABLED); |
| 612 | |
| 613 | pldm_pdr_destroy(inPDRRepo); |
| 614 | pldm_pdr_destroy(outPDRRepo); |
| 615 | } |
| 616 | |
| 617 | TEST(getStateSensorReadingsHandler, testBadRequest) |
| 618 | { |
| 619 | MockdBusHandler mockedUtils; |
| 620 | EXPECT_CALL(mockedUtils, getService(StrEq("/foo/bar"), _)) |
| 621 | .Times(1) |
| 622 | .WillRepeatedly(Return("foo.bar")); |
| 623 | |
| 624 | auto inPDRRepo = pldm_pdr_init(); |
| 625 | auto outPDRRepo = pldm_pdr_init(); |
| 626 | Repo outRepo(outPDRRepo); |
| 627 | Handler handler(&mockedUtils, "./pdr_jsons/state_sensor/good", "", |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 628 | inPDRRepo, nullptr, nullptr, nullptr); |
George Liu | a917012 | 2020-05-14 11:59:13 +0800 | [diff] [blame] | 629 | Repo inRepo(inPDRRepo); |
| 630 | getRepoByType(inRepo, outRepo, PLDM_STATE_SENSOR_PDR); |
| 631 | pdr_utils::PdrEntry e; |
| 632 | auto record = pdr::getRecordByHandle(outRepo, 2, e); |
| 633 | ASSERT_NE(record, nullptr); |
| 634 | pldm_state_sensor_pdr* pdr = |
| 635 | reinterpret_cast<pldm_state_sensor_pdr*>(e.data); |
| 636 | EXPECT_EQ(pdr->hdr.type, PLDM_STATE_SENSOR_PDR); |
| 637 | |
| 638 | std::vector<get_sensor_state_field> stateField; |
| 639 | uint8_t compSensorCnt{}; |
| 640 | uint8_t sensorRearmCnt = 3; |
| 641 | |
| 642 | MockdBusHandler handlerObj; |
| 643 | auto rc = platform_state_sensor::getStateSensorReadingsHandler< |
| 644 | MockdBusHandler, Handler>(handlerObj, handler, 0x1, sensorRearmCnt, |
| 645 | compSensorCnt, stateField); |
| 646 | ASSERT_EQ(rc, PLDM_PLATFORM_REARM_UNAVAILABLE_IN_PRESENT_STATE); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 647 | |
| 648 | pldm_pdr_destroy(inPDRRepo); |
| 649 | pldm_pdr_destroy(outPDRRepo); |
| 650 | } |