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