Move dbus_to_terminus_effecter code to platform-mc
In the current state , pldm build breaks when attempting to perform
a debug-optimized build (`-O2` optimization), leading to the following
linker error:
```
undefined reference to `pldm::platform_mc::TerminusManager::getActiveEidByName
(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
```
This issue is not encountered in the CI environment, as CI uses the
`-Og` optimization flag, which does not aggressively inline functions.
Consequently, the reference to `getActiveEidByName()` is resolved
without issue. However, when building the project with default
optimizations (debugoptimized [-O2]), the build fails because the
linker cannot resolve the reference to `getActiveEidByName()`, which is
inlined by the compiler.
To address this problem, there are three potential solutions:
1. Prevent Inlining of the Function:
We could use `__attribute__((noinline))` to prevent the compiler
from inlining `getActiveEidByName()`.
2. Move Source Files into `libpldmresponder`:
We could move the `platform-mc/manager.cpp` and
`platform-mc/terminus_manager.cpp` files into the `libpldmresponder`
so the compiler can resolve the reference directly within the
library.
3. Migrate `dbus_to_terminus_effecter.cpp` to the `platform-mc` folder:
The most appropriate solution appears to be migrating the
`dbus_to_terminus_effecter.cpp` file into the `platform-mc` directory.
This file is not inherently tied to `libpldmresponder` but functions as
a requester. Additionally, there are existing community patches that
allow the system to scale from a single host terminus to multiple
terminii, further justifying this move. So, solution #3 is the most
fitting at this stage. By relocating the `dbus_to_terminus_effecter`
code to the `platform-mc` folder, we can ensure proper modularity,
while also resolving the build issue in a clean and scalable manner.
Tested By:
1. meson build -Doptimization=2 works fine with the patchset.
Change-Id: I0ac8be58253bfb0394500f1d34e8431c6103c924
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/host-bmc/test/dbus_to_terminus_effecter_test.cpp b/host-bmc/test/dbus_to_terminus_effecter_test.cpp
deleted file mode 100644
index 6b02074..0000000
--- a/host-bmc/test/dbus_to_terminus_effecter_test.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-#include "common/test/mocked_utils.hpp"
-#include "common/utils.hpp"
-#include "host-bmc/dbus_to_terminus_effecters.hpp"
-
-#include <nlohmann/json.hpp>
-
-#include <gtest/gtest.h>
-
-using namespace pldm::host_effecters;
-using namespace pldm::utils;
-
-class MockHostEffecterParser : public HostEffecterParser
-{
- public:
- MockHostEffecterParser(int fd, const pldm_pdr* repo,
- DBusHandler* const dbusHandler,
- const std::string& jsonPath) :
- HostEffecterParser(nullptr, fd, repo, dbusHandler, jsonPath, nullptr,
- nullptr)
- {}
-
- MOCK_METHOD(int, setHostStateEffecter,
- (size_t, std::vector<set_effecter_state_field>&, uint16_t),
- (override));
-
- MOCK_METHOD(void, createHostEffecterMatch,
- (const std::string&, const std::string&, size_t, size_t,
- uint16_t),
- (override));
-
- const std::vector<EffecterInfo>& gethostEffecterInfo()
- {
- return hostEffecterInfo;
- }
-};
-
-TEST(HostEffecterParser, parseEffecterJsonGoodPath)
-{
- MockdBusHandler dbusHandler;
- int sockfd{};
- MockHostEffecterParser hostEffecterParserGood(sockfd, nullptr, &dbusHandler,
- "./host_effecter_jsons/good");
- auto hostEffecterInfo = hostEffecterParserGood.gethostEffecterInfo();
- ASSERT_EQ(hostEffecterInfo.size(), 2);
- ASSERT_EQ(hostEffecterInfo[0].effecterPdrType, PLDM_STATE_EFFECTER_PDR);
- ASSERT_EQ(hostEffecterInfo[0].entityInstance, 0);
- ASSERT_EQ(hostEffecterInfo[0].entityType, 33);
- ASSERT_EQ(hostEffecterInfo[0].dbusInfo.size(), 1);
- ASSERT_EQ(hostEffecterInfo[0].checkHostState, true);
- DBusEffecterMapping dbusInfo{
- {"/xyz/openbmc_project/control/host0/boot",
- "xyz.openbmc_project.Control.Boot.Mode", "BootMode", "string"},
- {"xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"},
- {196, {2}}};
- auto& temp = hostEffecterInfo[0].dbusInfo[0];
- ASSERT_EQ(temp.dbusMap.objectPath == dbusInfo.dbusMap.objectPath, true);
- ASSERT_EQ(temp.dbusMap.interface == dbusInfo.dbusMap.interface, true);
- ASSERT_EQ(temp.dbusMap.propertyName == dbusInfo.dbusMap.propertyName, true);
- ASSERT_EQ(temp.dbusMap.propertyType == dbusInfo.dbusMap.propertyType, true);
-
- /* Check Numeric Effecter in Good Json file */
- ASSERT_EQ(hostEffecterInfo[1].effecterPdrType, PLDM_NUMERIC_EFFECTER_PDR);
- ASSERT_EQ(hostEffecterInfo[1].entityType, 32903);
- ASSERT_EQ(hostEffecterInfo[1].entityInstance, 6);
- ASSERT_EQ(hostEffecterInfo[1].containerId, 4);
- ASSERT_EQ(hostEffecterInfo[1].dbusNumericEffecterInfo.size(), 1);
- ASSERT_EQ(hostEffecterInfo[1].checkHostState, false);
- DBusNumericEffecterMapping dbusInfoNumeric{
- {"/xyz/openbmc_project/effecters/power/PLimit",
- "xyz.openbmc_project.Effecter.Value", "Value", "double"},
- 5,
- 1,
- 0,
- -3,
- 100};
- auto& tempNumeric = hostEffecterInfo[1].dbusNumericEffecterInfo[0];
- ASSERT_EQ(tempNumeric.dbusMap.objectPath ==
- dbusInfoNumeric.dbusMap.objectPath,
- true);
- ASSERT_EQ(tempNumeric.dbusMap.interface ==
- dbusInfoNumeric.dbusMap.interface,
- true);
- ASSERT_EQ(tempNumeric.dbusMap.propertyName ==
- dbusInfoNumeric.dbusMap.propertyName,
- true);
- ASSERT_EQ(tempNumeric.dbusMap.propertyType ==
- dbusInfoNumeric.dbusMap.propertyType,
- true);
- ASSERT_EQ(tempNumeric.dataSize == dbusInfoNumeric.dataSize, true);
- ASSERT_EQ(tempNumeric.resolution == dbusInfoNumeric.resolution, true);
- ASSERT_EQ(tempNumeric.offset == dbusInfoNumeric.offset, true);
- ASSERT_EQ(tempNumeric.unitModifier == dbusInfoNumeric.unitModifier, true);
-}
-
-TEST(HostEffecterParser, parseEffecterJsonBadPath)
-{
- MockdBusHandler dbusHandler;
- int sockfd{};
- MockHostEffecterParser hostEffecterParser(sockfd, nullptr, &dbusHandler,
- "./host_effecter_jsons/no_json");
- ASSERT_THROW(
- hostEffecterParser.parseEffecterJson("./host_effecter_jsons/no_json"),
- std::exception);
- ASSERT_THROW(
- hostEffecterParser.parseEffecterJson("./host_effecter_jsons/malformed"),
- std::exception);
-}
-
-TEST(HostEffecterParser, findNewStateValue)
-{
- MockdBusHandler dbusHandler;
- int sockfd{};
- MockHostEffecterParser hostEffecterParser(sockfd, nullptr, &dbusHandler,
- "./host_effecter_jsons/good");
-
- PropertyValue val1{std::in_place_type<std::string>,
- "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"};
- PropertyValue val2{std::in_place_type<std::string>,
- "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"};
- auto newState = hostEffecterParser.findNewStateValue(0, 0, val1);
- ASSERT_EQ(newState, 2);
-
- ASSERT_THROW(hostEffecterParser.findNewStateValue(0, 0, val2),
- std::exception);
-}
-
-TEST(HostEffecterParser, adjustValue)
-{
- MockdBusHandler dbusHandler;
- int sockfd{};
- MockHostEffecterParser hostEffecterParser(sockfd, nullptr, &dbusHandler,
- "./host_effecter_jsons/good");
-
- auto realVal = hostEffecterParser.adjustValue(200, -50, 0.5, -2);
- ASSERT_EQ(realVal, 12500);
- realVal = hostEffecterParser.adjustValue(0, -50, 1, 0);
- ASSERT_EQ(realVal, 50);
- realVal = hostEffecterParser.adjustValue(0, 100, 1, -1);
- ASSERT_EQ(realVal, -1000);
- realVal = hostEffecterParser.adjustValue(2.34, 0, 1, -1);
- ASSERT_EQ(realVal, 23);
- realVal = hostEffecterParser.adjustValue(2.35, 0, 1, -1);
- ASSERT_EQ(realVal, 24);
-}
diff --git a/host-bmc/test/host_effecter_jsons/good/dbus_to_terminus_effecter.json b/host-bmc/test/host_effecter_jsons/good/dbus_to_terminus_effecter.json
deleted file mode 100644
index 2bc789a..0000000
--- a/host-bmc/test/host_effecter_jsons/good/dbus_to_terminus_effecter.json
+++ /dev/null
@@ -1,57 +0,0 @@
-{
- "entries": [
- {
- "mctp_eid": 9,
- "effecter_info": {
- "effecterID": 4,
- "containerID": 0,
- "entityType": 33,
- "entityInstance": 0,
- "compositeEffecterCount": 1
- },
- "effecters": [
- {
- "dbus_info": {
- "object_path": "/xyz/openbmc_project/control/host0/boot",
- "interface": "xyz.openbmc_project.Control.Boot.Mode",
- "property_name": "BootMode",
- "property_type": "string",
- "property_values": [
- "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"
- ]
- },
- "state": {
- "id": 196,
- "state_values": [2]
- }
- }
- ]
- },
- {
- "mctp_eid": 20,
- "effecter_info": {
- "effecterPdrType": 9,
- "effecterID": 155,
- "entityType": 32903,
- "entityInstance": 6,
- "containerID": 4,
- "compositeEffecterCount": 1,
- "checkHostState": false
- },
- "effecters": [
- {
- "dbus_info": {
- "object_path": "/xyz/openbmc_project/effecters/power/PLimit",
- "interface": "xyz.openbmc_project.Effecter.Value",
- "property_name": "Value",
- "property_type": "double"
- },
- "effecterDataSize": 5,
- "resolution": 1,
- "offset": 0,
- "unitModifier": -3
- }
- ]
- }
- ]
-}
diff --git a/host-bmc/test/host_effecter_jsons/malformed/dbus_to_terminus_effecter.json b/host-bmc/test/host_effecter_jsons/malformed/dbus_to_terminus_effecter.json
deleted file mode 100644
index 9db2505..0000000
--- a/host-bmc/test/host_effecter_jsons/malformed/dbus_to_terminus_effecter.json
+++ /dev/null
@@ -1,10 +0,0 @@
-"effecters": [
- {
- "dbus_info": {
- "object_path": "/xyz/openbmc_project/control/host0/boot",
- "interface": "xyz.openbmc_project.Control.Boot.Mode",
- "property_values": [
- "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"
- ]
- }
- ]
diff --git a/host-bmc/test/host_effecter_jsons/no_json/dummy.json b/host-bmc/test/host_effecter_jsons/no_json/dummy.json
deleted file mode 100644
index 401832d..0000000
--- a/host-bmc/test/host_effecter_jsons/no_json/dummy.json
+++ /dev/null
@@ -1,5 +0,0 @@
-"record_details":
- {
- "fru_record_type" : 1,
- "encoding_type": 1
- }
diff --git a/host-bmc/test/meson.build b/host-bmc/test/meson.build
index 4ae286d..48e0b63 100644
--- a/host-bmc/test/meson.build
+++ b/host-bmc/test/meson.build
@@ -1,8 +1,3 @@
-host_bmc_test_src = declare_dependency(
- sources: ['../dbus_to_terminus_effecters.cpp'],
- include_directories: '../../requester',
-)
-
test_sources = [
'../../common/utils.cpp',
'../utils.cpp',
@@ -17,7 +12,7 @@
'../dbus/pcie_slot.cpp',
]
-tests = ['dbus_to_terminus_effecter_test', 'utils_test', 'custom_dbus_test']
+tests = ['utils_test', 'custom_dbus_test']
foreach t : tests
test(
@@ -30,7 +25,6 @@
dependencies: [
gtest,
gmock,
- host_bmc_test_src,
libpldm_dep,
libpldmutils,
nlohmann_json_dep,