1 #include "common/test/mocked_utils.hpp"
2 #include "common/utils.hpp"
3 #include "host-bmc/utils.hpp"
4 #include "libpldmresponder/event_parser.hpp"
5 #include "libpldmresponder/fru.hpp"
6 #include "libpldmresponder/pdr.hpp"
7 #include "libpldmresponder/pdr_utils.hpp"
8 #include "libpldmresponder/platform.hpp"
9 #include "oem/ibm/libpldmresponder/collect_slot_vpd.hpp"
10 #include "oem/ibm/libpldmresponder/inband_code_update.hpp"
11 #include "oem/ibm/libpldmresponder/oem_ibm_handler.hpp"
12 #include "oem/ibm/libpldmresponder/utils.hpp"
13 #include "test/test_instance_id.hpp"
14
15 #include <libpldm/entity.h>
16 #include <libpldm/oem/ibm/entity.h>
17 #include <libpldm/pdr.h>
18
19 #include <nlohmann/json.hpp>
20 #include <phosphor-logging/lg2.hpp>
21 #include <sdeventplus/event.hpp>
22
23 #include <filesystem>
24 #include <fstream>
25
26 using namespace pldm::utils;
27 using namespace pldm::responder;
28 using namespace pldm::responder::pdr;
29 using namespace pldm::responder::pdr_utils;
30 using namespace pldm::responder::oem_ibm_platform;
31 using ::testing::Return;
32 using ::testing::ReturnRef;
33
34 class MockOemUtilsHandler : public oem_ibm_utils::Handler
35 {
36 public:
MockOemUtilsHandler(const pldm::utils::DBusHandler * dBusIntf)37 MockOemUtilsHandler(const pldm::utils::DBusHandler* dBusIntf) :
38 oem_ibm_utils::Handler(dBusIntf)
39 {}
40 };
41
42 class MockCodeUpdate : public CodeUpdate
43 {
44 public:
MockCodeUpdate(const pldm::utils::DBusHandler * dBusIntf)45 MockCodeUpdate(const pldm::utils::DBusHandler* dBusIntf) :
46 CodeUpdate(dBusIntf)
47 {}
48
49 MOCK_METHOD(void, setVersions, (), (override));
50 };
51
52 class MockSlotHandler : public SlotHandler
53 {
54 public:
MockSlotHandler(const sdeventplus::Event & event,pldm_pdr * repo)55 MockSlotHandler(const sdeventplus::Event& event, pldm_pdr* repo) :
56 SlotHandler(event, repo)
57 {}
58 };
59
60 class MockOemPlatformHandler : public oem_ibm_platform::Handler
61 {
62 public:
MockOemPlatformHandler(const pldm::utils::DBusHandler * dBusIntf,pldm::responder::CodeUpdate * codeUpdate,pldm::responder::SlotHandler * slotHandler,int mctp_fd,uint8_t mctp_eid,pldm::InstanceIdDb & instanceIdDb,sdeventplus::Event & event)63 MockOemPlatformHandler(const pldm::utils::DBusHandler* dBusIntf,
64 pldm::responder::CodeUpdate* codeUpdate,
65 pldm::responder::SlotHandler* slotHandler,
66 int mctp_fd, uint8_t mctp_eid,
67 pldm::InstanceIdDb& instanceIdDb,
68 sdeventplus::Event& event) :
69 oem_ibm_platform::Handler(dBusIntf, codeUpdate, slotHandler, mctp_fd,
70 mctp_eid, instanceIdDb, event, nullptr)
71 {}
72 MOCK_METHOD(uint16_t, getNextEffecterId, ());
73 MOCK_METHOD(uint16_t, getNextSensorId, ());
74 MOCK_METHOD((const AssociatedEntityMap&), getAssociateEntityMap, (),
75 (override));
76 };
77
TEST(OemSetStateEffecterStatesHandler,testGoodRequest)78 TEST(OemSetStateEffecterStatesHandler, testGoodRequest)
79 {
80 uint16_t entityID_ = PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE;
81 uint16_t stateSetId_ = PLDM_OEM_IBM_BOOT_STATE;
82 uint16_t entityInstance_ = 0;
83 uint16_t containerId_ = 0;
84 uint8_t compSensorCnt_ = 1;
85 uint16_t effecterId = 0xA;
86 uint16_t sensorId = 0x1;
87 TestInstanceIdDb instanceIdDb;
88
89 sdbusplus::bus_t bus(sdbusplus::bus::new_default());
90 auto event = sdeventplus::Event::get_default();
91 std::vector<get_sensor_state_field> stateField;
92
93 auto mockDbusHandler = std::make_unique<MockdBusHandler>();
94 std::unique_ptr<CodeUpdate> mockCodeUpdate =
95 std::make_unique<MockCodeUpdate>(mockDbusHandler.get());
96 std::unique_ptr<MockOemPlatformHandler> oemPlatformHandler =
97 std::make_unique<MockOemPlatformHandler>(
98 mockDbusHandler.get(), mockCodeUpdate.get(), nullptr, 0x1, 0x9,
99 instanceIdDb, event);
100
101 const AssociatedEntityMap associateMap = {};
102 EXPECT_CALL(*oemPlatformHandler, getAssociateEntityMap())
103 .WillRepeatedly(ReturnRef(associateMap));
104
105 auto rc = oemPlatformHandler->getOemStateSensorReadingsHandler(
106 entityID_, entityInstance_, containerId_, stateSetId_, compSensorCnt_,
107 sensorId, stateField);
108
109 ASSERT_EQ(rc, PLDM_SUCCESS);
110 ASSERT_EQ(stateField.size(), 1);
111 ASSERT_EQ(stateField[0].event_state, tSideNum);
112 ASSERT_EQ(stateField[0].sensor_op_state, PLDM_SENSOR_ENABLED);
113 ASSERT_EQ(stateField[0].present_state, PLDM_SENSOR_UNKNOWN);
114 ASSERT_EQ(stateField[0].previous_state, PLDM_SENSOR_UNKNOWN);
115
116 entityInstance_ = 1;
117
118 std::vector<get_sensor_state_field> stateField1;
119 rc = oemPlatformHandler->getOemStateSensorReadingsHandler(
120 entityID_, entityInstance_, containerId_, stateSetId_, compSensorCnt_,
121 sensorId, stateField1);
122 ASSERT_EQ(rc, PLDM_SUCCESS);
123 ASSERT_EQ(stateField1.size(), 1);
124 ASSERT_EQ(stateField1[0].event_state, tSideNum);
125
126 entityInstance_ = 2;
127 rc = oemPlatformHandler->getOemStateSensorReadingsHandler(
128 entityID_, entityInstance_, containerId_, stateSetId_, compSensorCnt_,
129 sensorId, stateField1);
130 ASSERT_EQ(rc, PLDM_SUCCESS);
131 ASSERT_EQ(stateField1[0].event_state, PLDM_SENSOR_UNKNOWN);
132
133 entityID_ = 40;
134 stateSetId_ = 50;
135 rc = oemPlatformHandler->getOemStateSensorReadingsHandler(
136 entityID_, entityInstance_, containerId_, stateSetId_, compSensorCnt_,
137 sensorId, stateField1);
138 ASSERT_EQ(rc, PLDM_PLATFORM_INVALID_STATE_VALUE);
139
140 entityID_ = PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE;
141 entityInstance_ = 0;
142 stateSetId_ = PLDM_OEM_IBM_BOOT_STATE;
143 compSensorCnt_ = 1;
144
145 std::vector<set_effecter_state_field> setEffecterStateField;
146 setEffecterStateField.push_back({PLDM_REQUEST_SET, pSideNum});
147
148 rc = oemPlatformHandler->oemSetStateEffecterStatesHandler(
149 entityID_, entityInstance_, stateSetId_, compSensorCnt_,
150 setEffecterStateField, effecterId);
151 ASSERT_EQ(rc, PLDM_SUCCESS);
152
153 entityInstance_ = 2;
154 rc = oemPlatformHandler->oemSetStateEffecterStatesHandler(
155 entityID_, entityInstance_, stateSetId_, compSensorCnt_,
156 setEffecterStateField, effecterId);
157 ASSERT_EQ(rc, PLDM_PLATFORM_INVALID_STATE_VALUE);
158
159 entityID_ = 34;
160 stateSetId_ = 99;
161 entityInstance_ = 0;
162 rc = oemPlatformHandler->oemSetStateEffecterStatesHandler(
163 entityID_, entityInstance_, stateSetId_, compSensorCnt_,
164 setEffecterStateField, effecterId);
165 ASSERT_EQ(rc, PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE);
166 }
167
TEST(EncodeCodeUpdateEvent,testGoodRequest)168 TEST(EncodeCodeUpdateEvent, testGoodRequest)
169 {
170 size_t sensorEventSize = PLDM_SENSOR_EVENT_DATA_MIN_LENGTH + 1;
171 std::vector<uint8_t> sensorEventDataVec{};
172 sensorEventDataVec.resize(sensorEventSize);
173
174 auto eventData = reinterpret_cast<struct pldm_sensor_event_data*>(
175 sensorEventDataVec.data());
176 eventData->sensor_id = 0xA;
177 eventData->sensor_event_class_type = PLDM_SENSOR_OP_STATE;
178
179 auto opStateSensorEventData =
180 reinterpret_cast<struct pldm_sensor_event_sensor_op_state*>(
181 sensorEventDataVec.data());
182 opStateSensorEventData->present_op_state = uint8_t(CodeUpdateState::START);
183 opStateSensorEventData->previous_op_state = uint8_t(CodeUpdateState::END);
184
185 std::vector<uint8_t> requestMsg(
186 sizeof(pldm_msg_hdr) + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
187 sensorEventDataVec.size());
188
189 auto rc =
190 encodeEventMsg(PLDM_SENSOR_EVENT, sensorEventDataVec, requestMsg, 0x1);
191
192 EXPECT_EQ(rc, PLDM_SUCCESS);
193 }
194
TEST(EncodeCodeUpdate,testBadRequest)195 TEST(EncodeCodeUpdate, testBadRequest)
196 {
197 std::vector<uint8_t> requestMsg;
198 std::vector<uint8_t> sensorEventDataVec{};
199
200 auto rc =
201 encodeEventMsg(PLDM_SENSOR_EVENT, sensorEventDataVec, requestMsg, 0x1);
202
203 EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
204 }
205
TEST(clearDirPath,testClearDirPath)206 TEST(clearDirPath, testClearDirPath)
207 {
208 char dirPath[] = "/tmp/testClearDir/";
209 fs::path dir(dirPath);
210 fs::create_directories(dir);
211 struct stat buffer;
212 ASSERT_EQ(stat(dirPath, &buffer), 0);
213 char filePath[] = "/tmp/testClearDir/file.txt";
214 std::ofstream file(filePath);
215 ASSERT_EQ(stat(filePath, &buffer), 0);
216
217 auto mockDbusHandler = std::make_unique<MockdBusHandler>();
218 std::unique_ptr<CodeUpdate> mockCodeUpdate =
219 std::make_unique<MockCodeUpdate>(mockDbusHandler.get());
220
221 mockCodeUpdate->clearDirPath(dirPath);
222 ASSERT_EQ(stat(filePath, &buffer), -1);
223 ASSERT_EQ(stat(dirPath, &buffer), 0);
224 }
225
TEST(generateStateEffecterOEMPDR,testGoodRequest)226 TEST(generateStateEffecterOEMPDR, testGoodRequest)
227 {
228 const AssociatedEntityMap associateMap = {};
229 auto inPDRRepo = pldm_pdr_init();
230 sdbusplus::bus_t bus(sdbusplus::bus::new_default());
231 TestInstanceIdDb instanceIdDb;
232 auto mockDbusHandler = std::make_unique<MockdBusHandler>();
233 auto event = sdeventplus::Event::get_default();
234 std::unique_ptr<CodeUpdate> mockCodeUpdate =
235 std::make_unique<MockCodeUpdate>(mockDbusHandler.get());
236 std::unique_ptr<MockOemPlatformHandler> mockoemPlatformHandler =
237 std::make_unique<MockOemPlatformHandler>(
238 mockDbusHandler.get(), mockCodeUpdate.get(), nullptr, 0x1, 0x9,
239 instanceIdDb, event);
240 Repo inRepo(inPDRRepo);
241
242 EXPECT_CALL(*mockoemPlatformHandler, getAssociateEntityMap())
243 .WillRepeatedly(ReturnRef(associateMap));
244
245 mockoemPlatformHandler->buildOEMPDR(inRepo);
246 ASSERT_EQ(inRepo.empty(), false);
247
248 pdr_utils::PdrEntry e;
249
250 // Test for effecter number 1, for current boot side state
251 auto record1 = pdr::getRecordByHandle(inRepo, 1, e);
252 ASSERT_NE(record1, nullptr);
253
254 pldm_state_effecter_pdr* pdr =
255 reinterpret_cast<pldm_state_effecter_pdr*>(e.data);
256
257 ASSERT_EQ(pdr->hdr.record_handle, 1);
258 ASSERT_EQ(pdr->hdr.version, 1);
259 ASSERT_EQ(pdr->hdr.type, PLDM_STATE_EFFECTER_PDR);
260 ASSERT_EQ(pdr->hdr.record_change_num, 0);
261 ASSERT_EQ(pdr->hdr.length, 16);
262 ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
263 ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE);
264 ASSERT_EQ(pdr->entity_instance, 0);
265 ASSERT_EQ(pdr->container_id, 1);
266 ASSERT_EQ(pdr->effecter_semantic_id, 0);
267 ASSERT_EQ(pdr->effecter_init, PLDM_NO_INIT);
268 ASSERT_EQ(pdr->has_description_pdr, false);
269 ASSERT_EQ(pdr->composite_effecter_count, 1);
270 state_effecter_possible_states* states =
271 reinterpret_cast<state_effecter_possible_states*>(pdr->possible_states);
272 ASSERT_EQ(states->state_set_id, 32769);
273 ASSERT_EQ(states->possible_states_size, 2);
274 bitfield8_t bf1{};
275 bf1.byte = 6;
276 ASSERT_EQ(states->states[0].byte, bf1.byte);
277
278 // Test for effecter number 2, for next boot side state
279 auto record2 = pdr::getRecordByHandle(inRepo, 2, e);
280 ASSERT_NE(record2, nullptr);
281
282 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(e.data);
283
284 ASSERT_EQ(pdr->hdr.record_handle, 2);
285 ASSERT_EQ(pdr->hdr.version, 1);
286 ASSERT_EQ(pdr->hdr.type, PLDM_STATE_EFFECTER_PDR);
287 ASSERT_EQ(pdr->hdr.record_change_num, 0);
288 ASSERT_EQ(pdr->hdr.length, 16);
289 ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
290 ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE);
291 ASSERT_EQ(pdr->entity_instance, 1);
292 ASSERT_EQ(pdr->container_id, 1);
293 ASSERT_EQ(pdr->effecter_semantic_id, 0);
294 ASSERT_EQ(pdr->effecter_init, PLDM_NO_INIT);
295 ASSERT_EQ(pdr->has_description_pdr, false);
296 ASSERT_EQ(pdr->composite_effecter_count, 1);
297 states =
298 reinterpret_cast<state_effecter_possible_states*>(pdr->possible_states);
299 ASSERT_EQ(states->state_set_id, 32769);
300 ASSERT_EQ(states->possible_states_size, 2);
301 bitfield8_t bf2{};
302 bf2.byte = 6;
303 ASSERT_EQ(states->states[0].byte, bf2.byte);
304
305 // Test for effecter number 3, for firmware update state control
306 auto record3 = pdr::getRecordByHandle(inRepo, 3, e);
307 ASSERT_NE(record3, nullptr);
308
309 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(e.data);
310
311 ASSERT_EQ(pdr->hdr.record_handle, 3);
312 ASSERT_EQ(pdr->hdr.version, 1);
313 ASSERT_EQ(pdr->hdr.type, PLDM_STATE_EFFECTER_PDR);
314 ASSERT_EQ(pdr->hdr.record_change_num, 0);
315 ASSERT_EQ(pdr->hdr.length, 16);
316 ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
317 ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE);
318 ASSERT_EQ(pdr->entity_instance, 0);
319 ASSERT_EQ(pdr->container_id, 1);
320 ASSERT_EQ(pdr->effecter_semantic_id, 0);
321 ASSERT_EQ(pdr->effecter_init, PLDM_NO_INIT);
322 ASSERT_EQ(pdr->has_description_pdr, false);
323 ASSERT_EQ(pdr->composite_effecter_count, 1);
324 states =
325 reinterpret_cast<state_effecter_possible_states*>(pdr->possible_states);
326 ASSERT_EQ(states->state_set_id, 32768);
327 ASSERT_EQ(states->possible_states_size, 2);
328 bitfield8_t bf3{};
329 bf3.byte = 126;
330 ASSERT_EQ(states->states[0].byte, bf3.byte);
331
332 // Test for effecter number 5, to turn off Real SAI led
333 auto record4 = pdr::getRecordByHandle(inRepo, 5, e);
334 ASSERT_NE(record4, nullptr);
335
336 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(e.data);
337
338 ASSERT_EQ(pdr->hdr.record_handle, 5);
339 ASSERT_EQ(pdr->hdr.version, 1);
340 ASSERT_EQ(pdr->hdr.type, PLDM_STATE_EFFECTER_PDR);
341 ASSERT_EQ(pdr->hdr.record_change_num, 0);
342 ASSERT_EQ(pdr->hdr.length, 16);
343 ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
344 ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_REAL_SAI);
345 ASSERT_EQ(pdr->entity_instance, 1);
346 ASSERT_EQ(pdr->container_id, 1);
347 ASSERT_EQ(pdr->effecter_semantic_id, 0);
348 ASSERT_EQ(pdr->effecter_init, PLDM_NO_INIT);
349 ASSERT_EQ(pdr->has_description_pdr, false);
350 ASSERT_EQ(pdr->composite_effecter_count, 1);
351 states =
352 reinterpret_cast<state_effecter_possible_states*>(pdr->possible_states);
353 ASSERT_EQ(states->state_set_id, PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS);
354 ASSERT_EQ(states->possible_states_size, 1);
355 bitfield8_t bf4{};
356 bf4.byte = 2;
357 ASSERT_EQ(states->states[0].byte, bf4.byte);
358
359 pldm_pdr_destroy(inPDRRepo);
360 }
361
TEST(generateStateSensorOEMPDR,testGoodRequest)362 TEST(generateStateSensorOEMPDR, testGoodRequest)
363 {
364 const AssociatedEntityMap associateMap = {};
365 auto inPDRRepo = pldm_pdr_init();
366 sdbusplus::bus_t bus(sdbusplus::bus::new_default());
367 TestInstanceIdDb instanceIdDb;
368
369 auto mockDbusHandler = std::make_unique<MockdBusHandler>();
370 auto event = sdeventplus::Event::get_default();
371 std::unique_ptr<CodeUpdate> mockCodeUpdate =
372 std::make_unique<MockCodeUpdate>(mockDbusHandler.get());
373 std::unique_ptr<MockOemPlatformHandler> mockoemPlatformHandler =
374 std::make_unique<MockOemPlatformHandler>(
375 mockDbusHandler.get(), mockCodeUpdate.get(), nullptr, 0x1, 0x9,
376 instanceIdDb, event);
377 EXPECT_CALL(*mockoemPlatformHandler, getAssociateEntityMap())
378 .WillRepeatedly(ReturnRef(associateMap));
379 Repo inRepo(inPDRRepo);
380 mockoemPlatformHandler->buildOEMPDR(inRepo);
381 ASSERT_EQ(inRepo.empty(), false);
382
383 pdr_utils::PdrEntry e;
384
385 // Test for sensor number 1, for current boot side state
386 auto record1 = pdr::getRecordByHandle(inRepo, 6, e);
387 ASSERT_NE(record1, nullptr);
388
389 pldm_state_sensor_pdr* pdr =
390 reinterpret_cast<pldm_state_sensor_pdr*>(e.data);
391
392 ASSERT_EQ(pdr->hdr.record_handle, 6);
393 ASSERT_EQ(pdr->hdr.version, 1);
394 ASSERT_EQ(pdr->hdr.type, PLDM_STATE_SENSOR_PDR);
395 ASSERT_EQ(pdr->hdr.record_change_num, 0);
396 ASSERT_EQ(pdr->hdr.length, 14);
397 ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
398 ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE);
399 ASSERT_EQ(pdr->entity_instance, 0);
400 ASSERT_EQ(pdr->container_id, 1);
401 ASSERT_EQ(pdr->sensor_init, PLDM_NO_INIT);
402 ASSERT_EQ(pdr->sensor_auxiliary_names_pdr, false);
403 ASSERT_EQ(pdr->composite_sensor_count, 1);
404 state_sensor_possible_states* states =
405 reinterpret_cast<state_sensor_possible_states*>(pdr->possible_states);
406 ASSERT_EQ(states->state_set_id, 32769);
407 ASSERT_EQ(states->possible_states_size, 2);
408 bitfield8_t bf1{};
409 bf1.byte = 6;
410 ASSERT_EQ(states->states[0].byte, bf1.byte);
411
412 // Test for sensor number 2, for next boot side state
413 auto record2 = pdr::getRecordByHandle(inRepo, 7, e);
414 ASSERT_NE(record2, nullptr);
415
416 pdr = reinterpret_cast<pldm_state_sensor_pdr*>(e.data);
417
418 ASSERT_EQ(pdr->hdr.record_handle, 7);
419 ASSERT_EQ(pdr->hdr.version, 1);
420 ASSERT_EQ(pdr->hdr.type, PLDM_STATE_SENSOR_PDR);
421 ASSERT_EQ(pdr->hdr.record_change_num, 0);
422 ASSERT_EQ(pdr->hdr.length, 14);
423 ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
424 ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE);
425 ASSERT_EQ(pdr->entity_instance, 1);
426 ASSERT_EQ(pdr->container_id, 1);
427 ASSERT_EQ(pdr->sensor_init, PLDM_NO_INIT);
428 ASSERT_EQ(pdr->sensor_auxiliary_names_pdr, false);
429 ASSERT_EQ(pdr->composite_sensor_count, 1);
430 states =
431 reinterpret_cast<state_sensor_possible_states*>(pdr->possible_states);
432 ASSERT_EQ(states->state_set_id, 32769);
433 ASSERT_EQ(states->possible_states_size, 2);
434 bitfield8_t bf2{};
435 bf2.byte = 6;
436 ASSERT_EQ(states->states[0].byte, bf2.byte);
437
438 // Test for sensor number 3, for firmware update state control
439 auto record3 = pdr::getRecordByHandle(inRepo, 8, e);
440 ASSERT_NE(record3, nullptr);
441
442 pdr = reinterpret_cast<pldm_state_sensor_pdr*>(e.data);
443
444 ASSERT_EQ(pdr->hdr.record_handle, 8);
445 ASSERT_EQ(pdr->hdr.version, 1);
446 ASSERT_EQ(pdr->hdr.type, PLDM_STATE_SENSOR_PDR);
447 ASSERT_EQ(pdr->hdr.record_change_num, 0);
448 ASSERT_EQ(pdr->hdr.length, 14);
449 ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
450 ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE);
451 ASSERT_EQ(pdr->entity_instance, 0);
452 ASSERT_EQ(pdr->container_id, 1);
453 ASSERT_EQ(pdr->sensor_init, PLDM_NO_INIT);
454 ASSERT_EQ(pdr->sensor_auxiliary_names_pdr, false);
455 ASSERT_EQ(pdr->composite_sensor_count, 1);
456 states =
457 reinterpret_cast<state_sensor_possible_states*>(pdr->possible_states);
458 ASSERT_EQ(states->state_set_id, 32768);
459 ASSERT_EQ(states->possible_states_size, 2);
460 bitfield8_t bf3{};
461 bf3.byte = 126;
462 ASSERT_EQ(states->states[0].byte, bf3.byte);
463
464 // Test for sensor number 6, for Real SAI sensor states
465 auto record4 = pdr::getRecordByHandle(inRepo, 11, e);
466 ASSERT_NE(record4, nullptr);
467
468 pdr = reinterpret_cast<pldm_state_sensor_pdr*>(e.data);
469
470 ASSERT_EQ(pdr->hdr.record_handle, 11);
471 ASSERT_EQ(pdr->hdr.version, 1);
472 ASSERT_EQ(pdr->hdr.type, PLDM_STATE_SENSOR_PDR);
473 ASSERT_EQ(pdr->hdr.record_change_num, 0);
474 ASSERT_EQ(pdr->hdr.length, 14);
475 ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
476 ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_REAL_SAI);
477 ASSERT_EQ(pdr->entity_instance, 1);
478 ASSERT_EQ(pdr->container_id, 1);
479 ASSERT_EQ(pdr->sensor_init, PLDM_NO_INIT);
480 ASSERT_EQ(pdr->sensor_auxiliary_names_pdr, false);
481 ASSERT_EQ(pdr->composite_sensor_count, 1);
482 states =
483 reinterpret_cast<state_sensor_possible_states*>(pdr->possible_states);
484 ASSERT_EQ(states->state_set_id, PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS);
485 ASSERT_EQ(states->possible_states_size, 2);
486 bitfield8_t bf4{};
487 bf4.byte = 6;
488 ASSERT_EQ(states->states[0].byte, bf4.byte);
489
490 pldm_pdr_destroy(inPDRRepo);
491 }
492
TEST(updateOemDbusPath,testgoodpath)493 TEST(updateOemDbusPath, testgoodpath)
494 {
495 TestInstanceIdDb instanceIdDb;
496 auto mockDbusHandler = std::make_unique<MockdBusHandler>();
497 auto event = sdeventplus::Event::get_default();
498 std::unique_ptr<CodeUpdate> mockCodeUpdate =
499 std::make_unique<MockCodeUpdate>(mockDbusHandler.get());
500 std::unique_ptr<oem_ibm_platform::Handler> mockoemPlatformHandler =
501 std::make_unique<MockOemPlatformHandler>(
502 mockDbusHandler.get(), mockCodeUpdate.get(), nullptr, 0x1, 0x9,
503 instanceIdDb, event);
504 std::string dbuspath = "/inventory/system1/chassis1/motherboard1/dcm0";
505 mockoemPlatformHandler->updateOemDbusPaths(dbuspath);
506 EXPECT_EQ(dbuspath, "/inventory/system/chassis/motherboard/dcm0");
507
508 dbuspath = "/inventory/system/chassis/socket1/motherboard/dcm0";
509 mockoemPlatformHandler->updateOemDbusPaths(dbuspath);
510 EXPECT_EQ(dbuspath, "/inventory/system/chassis/motherboard/dcm0");
511 }
512
TEST(SetCoreCount,testgoodpath)513 TEST(SetCoreCount, testgoodpath)
514 {
515 pldm::utils::EntityMaps entityMaps = pldm::hostbmc::utils::parseEntityMap(
516 "../../oem/ibm/test/entitymap_test.json");
517 MockdBusHandler mockedDbusUtils;
518 pldm_entity entities[9]{};
519
520 entities[0].entity_type = 45;
521 entities[0].entity_container_id = 0;
522
523 entities[1].entity_type = 64;
524 entities[1].entity_container_id = 1;
525
526 entities[2].entity_type = 67;
527 entities[2].entity_container_id = 2;
528 entities[3].entity_type = 67;
529 entities[3].entity_container_id = 2;
530
531 entities[4].entity_type = 135;
532 entities[4].entity_container_id = 3;
533 entities[5].entity_type = 135;
534 entities[5].entity_container_id = 3;
535 entities[6].entity_type = 135;
536 entities[6].entity_container_id = 3;
537 entities[7].entity_type = 135;
538 entities[7].entity_container_id = 3;
539 entities[8].entity_type = 32903;
540 entities[8].entity_container_id = 3;
541
542 auto tree = pldm_entity_association_tree_init();
543
544 auto l1 = pldm_entity_association_tree_add_entity(
545 tree, &entities[0], 1, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true,
546 true, 0xFFFF);
547
548 auto l2 = pldm_entity_association_tree_add_entity(
549 tree, &entities[1], 1, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
550 0xFFFF);
551
552 auto l3a = pldm_entity_association_tree_add_entity(
553 tree, &entities[2], 0, l2, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
554 0xFFFF);
555 auto l3b = pldm_entity_association_tree_add_entity(
556 tree, &entities[3], 1, l2, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
557 0xFFFF);
558
559 auto l4a = pldm_entity_association_tree_add_entity(
560 tree, &entities[4], 0, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
561 0xFFFF);
562 auto l4b = pldm_entity_association_tree_add_entity(
563 tree, &entities[5], 1, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
564 0xFFFF);
565
566 auto l5a = pldm_entity_association_tree_add_entity(
567 tree, &entities[6], 0, l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
568 0xFFFF);
569 auto l5b = pldm_entity_association_tree_add_entity(
570 tree, &entities[7], 1, l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
571 0xFFFF);
572
573 auto l5c = pldm_entity_association_tree_add_entity(
574 tree, &entities[8], 0, l5a, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
575 0xFFFF);
576
577 auto l5ca = pldm_entity_association_tree_add_entity(
578 tree, &entities[8], 0, l5b, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
579 0xFFFF);
580
581 pldm::utils::EntityAssociations entityAssociations = {
582 {l1, l2}, {l2, l3a, l3b}, {l3a, l4a, l4b},
583 {l3b, l5a, l5b}, {l5a, l5c}, {l5b, l5ca}};
584
585 DBusMapping dbusMapping{"/foo/bar", "xyz.openbmc_project.Foo.Bar",
586 "propertyName", "uint64_t"};
587 std::vector<std::string> cpuInterface = {"xyz.openbmc_project.Foo.Bar"};
588 auto oemMockedUtils =
589 std::make_unique<MockOemUtilsHandler>(&mockedDbusUtils);
590 int coreCount =
591 oemMockedUtils->setCoreCount(entityAssociations, entityMaps);
592 EXPECT_EQ(coreCount, 2);
593 pldm_entity_association_tree_destroy(tree);
594 }
595