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     pldm_pdr_destroy(inPDRRepo);
333 }
334 
TEST(generateStateSensorOEMPDR,testGoodRequest)335 TEST(generateStateSensorOEMPDR, testGoodRequest)
336 {
337     const AssociatedEntityMap associateMap = {};
338     auto inPDRRepo = pldm_pdr_init();
339     sdbusplus::bus_t bus(sdbusplus::bus::new_default());
340     TestInstanceIdDb instanceIdDb;
341 
342     auto mockDbusHandler = std::make_unique<MockdBusHandler>();
343     auto event = sdeventplus::Event::get_default();
344     std::unique_ptr<CodeUpdate> mockCodeUpdate =
345         std::make_unique<MockCodeUpdate>(mockDbusHandler.get());
346     std::unique_ptr<MockOemPlatformHandler> mockoemPlatformHandler =
347         std::make_unique<MockOemPlatformHandler>(
348             mockDbusHandler.get(), mockCodeUpdate.get(), nullptr, 0x1, 0x9,
349             instanceIdDb, event);
350     EXPECT_CALL(*mockoemPlatformHandler, getAssociateEntityMap())
351         .WillRepeatedly(ReturnRef(associateMap));
352     Repo inRepo(inPDRRepo);
353     mockoemPlatformHandler->buildOEMPDR(inRepo);
354     ASSERT_EQ(inRepo.empty(), false);
355 
356     pdr_utils::PdrEntry e;
357 
358     // Test for sensor number 1, for current boot side state
359     auto record1 = pdr::getRecordByHandle(inRepo, 5, e);
360     ASSERT_NE(record1, nullptr);
361 
362     pldm_state_sensor_pdr* pdr =
363         reinterpret_cast<pldm_state_sensor_pdr*>(e.data);
364 
365     ASSERT_EQ(pdr->hdr.record_handle, 5);
366     ASSERT_EQ(pdr->hdr.version, 1);
367     ASSERT_EQ(pdr->hdr.type, PLDM_STATE_SENSOR_PDR);
368     ASSERT_EQ(pdr->hdr.record_change_num, 0);
369     ASSERT_EQ(pdr->hdr.length, 14);
370     ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
371     ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE);
372     ASSERT_EQ(pdr->entity_instance, 0);
373     ASSERT_EQ(pdr->container_id, 1);
374     ASSERT_EQ(pdr->sensor_init, PLDM_NO_INIT);
375     ASSERT_EQ(pdr->sensor_auxiliary_names_pdr, false);
376     ASSERT_EQ(pdr->composite_sensor_count, 1);
377     state_sensor_possible_states* states =
378         reinterpret_cast<state_sensor_possible_states*>(pdr->possible_states);
379     ASSERT_EQ(states->state_set_id, 32769);
380     ASSERT_EQ(states->possible_states_size, 2);
381     bitfield8_t bf1{};
382     bf1.byte = 6;
383     ASSERT_EQ(states->states[0].byte, bf1.byte);
384 
385     // Test for sensor number 2, for next boot side state
386     auto record2 = pdr::getRecordByHandle(inRepo, 6, e);
387     ASSERT_NE(record2, nullptr);
388 
389     pdr = reinterpret_cast<pldm_state_sensor_pdr*>(e.data);
390 
391     ASSERT_EQ(pdr->hdr.record_handle, 6);
392     ASSERT_EQ(pdr->hdr.version, 1);
393     ASSERT_EQ(pdr->hdr.type, PLDM_STATE_SENSOR_PDR);
394     ASSERT_EQ(pdr->hdr.record_change_num, 0);
395     ASSERT_EQ(pdr->hdr.length, 14);
396     ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
397     ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE);
398     ASSERT_EQ(pdr->entity_instance, 1);
399     ASSERT_EQ(pdr->container_id, 1);
400     ASSERT_EQ(pdr->sensor_init, PLDM_NO_INIT);
401     ASSERT_EQ(pdr->sensor_auxiliary_names_pdr, false);
402     ASSERT_EQ(pdr->composite_sensor_count, 1);
403     states =
404         reinterpret_cast<state_sensor_possible_states*>(pdr->possible_states);
405     ASSERT_EQ(states->state_set_id, 32769);
406     ASSERT_EQ(states->possible_states_size, 2);
407     bitfield8_t bf2{};
408     bf2.byte = 6;
409     ASSERT_EQ(states->states[0].byte, bf2.byte);
410 
411     // Test for sensor number 3, for firmware update state control
412     auto record3 = pdr::getRecordByHandle(inRepo, 7, e);
413     ASSERT_NE(record3, nullptr);
414 
415     pdr = reinterpret_cast<pldm_state_sensor_pdr*>(e.data);
416 
417     ASSERT_EQ(pdr->hdr.record_handle, 7);
418     ASSERT_EQ(pdr->hdr.version, 1);
419     ASSERT_EQ(pdr->hdr.type, PLDM_STATE_SENSOR_PDR);
420     ASSERT_EQ(pdr->hdr.record_change_num, 0);
421     ASSERT_EQ(pdr->hdr.length, 14);
422     ASSERT_EQ(pdr->terminus_handle, TERMINUS_HANDLE);
423     ASSERT_EQ(pdr->entity_type, PLDM_OEM_IBM_ENTITY_FIRMWARE_UPDATE);
424     ASSERT_EQ(pdr->entity_instance, 0);
425     ASSERT_EQ(pdr->container_id, 1);
426     ASSERT_EQ(pdr->sensor_init, PLDM_NO_INIT);
427     ASSERT_EQ(pdr->sensor_auxiliary_names_pdr, false);
428     ASSERT_EQ(pdr->composite_sensor_count, 1);
429     states =
430         reinterpret_cast<state_sensor_possible_states*>(pdr->possible_states);
431     ASSERT_EQ(states->state_set_id, 32768);
432     ASSERT_EQ(states->possible_states_size, 2);
433     bitfield8_t bf3{};
434     bf3.byte = 126;
435     ASSERT_EQ(states->states[0].byte, bf3.byte);
436 
437     pldm_pdr_destroy(inPDRRepo);
438 }
439 
TEST(updateOemDbusPath,testgoodpath)440 TEST(updateOemDbusPath, testgoodpath)
441 {
442     TestInstanceIdDb instanceIdDb;
443     auto mockDbusHandler = std::make_unique<MockdBusHandler>();
444     auto event = sdeventplus::Event::get_default();
445     std::unique_ptr<CodeUpdate> mockCodeUpdate =
446         std::make_unique<MockCodeUpdate>(mockDbusHandler.get());
447     std::unique_ptr<oem_ibm_platform::Handler> mockoemPlatformHandler =
448         std::make_unique<MockOemPlatformHandler>(
449             mockDbusHandler.get(), mockCodeUpdate.get(), nullptr, 0x1, 0x9,
450             instanceIdDb, event);
451     std::string dbuspath = "/inventory/system1/chassis1/motherboard1/dcm0";
452     mockoemPlatformHandler->updateOemDbusPaths(dbuspath);
453     EXPECT_EQ(dbuspath, "/inventory/system/chassis/motherboard/dcm0");
454 
455     dbuspath = "/inventory/system/chassis/socket1/motherboard/dcm0";
456     mockoemPlatformHandler->updateOemDbusPaths(dbuspath);
457     EXPECT_EQ(dbuspath, "/inventory/system/chassis/motherboard/dcm0");
458 }
459 
TEST(SetCoreCount,testgoodpath)460 TEST(SetCoreCount, testgoodpath)
461 {
462     pldm::utils::EntityMaps entityMaps = pldm::hostbmc::utils::parseEntityMap(
463         "../../oem/ibm/test/entitymap_test.json");
464     MockdBusHandler mockedDbusUtils;
465     pldm_entity entities[9]{};
466 
467     entities[0].entity_type = 45;
468     entities[0].entity_container_id = 0;
469 
470     entities[1].entity_type = 64;
471     entities[1].entity_container_id = 1;
472 
473     entities[2].entity_type = 67;
474     entities[2].entity_container_id = 2;
475     entities[3].entity_type = 67;
476     entities[3].entity_container_id = 2;
477 
478     entities[4].entity_type = 135;
479     entities[4].entity_container_id = 3;
480     entities[5].entity_type = 135;
481     entities[5].entity_container_id = 3;
482     entities[6].entity_type = 135;
483     entities[6].entity_container_id = 3;
484     entities[7].entity_type = 135;
485     entities[7].entity_container_id = 3;
486     entities[8].entity_type = 32903;
487     entities[8].entity_container_id = 3;
488 
489     auto tree = pldm_entity_association_tree_init();
490 
491     auto l1 = pldm_entity_association_tree_add_entity(
492         tree, &entities[0], 1, nullptr, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true,
493         true, 0xFFFF);
494 
495     auto l2 = pldm_entity_association_tree_add_entity(
496         tree, &entities[1], 1, l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
497         0xFFFF);
498 
499     auto l3a = pldm_entity_association_tree_add_entity(
500         tree, &entities[2], 0, l2, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
501         0xFFFF);
502     auto l3b = pldm_entity_association_tree_add_entity(
503         tree, &entities[3], 1, l2, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
504         0xFFFF);
505 
506     auto l4a = pldm_entity_association_tree_add_entity(
507         tree, &entities[4], 0, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
508         0xFFFF);
509     auto l4b = pldm_entity_association_tree_add_entity(
510         tree, &entities[5], 1, l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
511         0xFFFF);
512 
513     auto l5a = pldm_entity_association_tree_add_entity(
514         tree, &entities[6], 0, l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
515         0xFFFF);
516     auto l5b = pldm_entity_association_tree_add_entity(
517         tree, &entities[7], 1, l3b, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
518         0xFFFF);
519 
520     auto l5c = pldm_entity_association_tree_add_entity(
521         tree, &entities[8], 0, l5a, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
522         0xFFFF);
523 
524     auto l5ca = pldm_entity_association_tree_add_entity(
525         tree, &entities[8], 0, l5b, PLDM_ENTITY_ASSOCIAION_PHYSICAL, true, true,
526         0xFFFF);
527 
528     pldm::utils::EntityAssociations entityAssociations = {
529         {l1, l2},        {l2, l3a, l3b}, {l3a, l4a, l4b},
530         {l3b, l5a, l5b}, {l5a, l5c},     {l5b, l5ca}};
531 
532     DBusMapping dbusMapping{"/foo/bar", "xyz.openbmc_project.Foo.Bar",
533                             "propertyName", "uint64_t"};
534     std::vector<std::string> cpuInterface = {"xyz.openbmc_project.Foo.Bar"};
535     auto oemMockedUtils =
536         std::make_unique<MockOemUtilsHandler>(&mockedDbusUtils);
537     int coreCount =
538         oemMockedUtils->setCoreCount(entityAssociations, entityMaps);
539     EXPECT_EQ(coreCount, 2);
540     pldm_entity_association_tree_destroy(tree);
541 }
542