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