pldmd: D-Bus to host effecter translation
This commit implements a mechanism to move the Host's boot state
from 'not started' to 'boot complete' by setting the relevant
Host effecter when the associated D-Bus property is set in the BMC.
Also added an example JSON to match D-Bus to host effecters
Change-Id: I41025d99d2b4b3452d4c51b03efe3750e159328b
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/test/host_effecter_jsons/good/dbus_to_host_effecter.json b/test/host_effecter_jsons/good/dbus_to_host_effecter.json
new file mode 100644
index 0000000..dd95b17
--- /dev/null
+++ b/test/host_effecter_jsons/good/dbus_to_host_effecter.json
@@ -0,0 +1,37 @@
+{
+ "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
+ ]
+ }
+ }
+
+ ]
+
+ }
+
+ ]
+
+}
diff --git a/test/host_effecter_jsons/malformed/dbus_to_host_effecter.json b/test/host_effecter_jsons/malformed/dbus_to_host_effecter.json
new file mode 100644
index 0000000..9db2505
--- /dev/null
+++ b/test/host_effecter_jsons/malformed/dbus_to_host_effecter.json
@@ -0,0 +1,10 @@
+"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/test/host_effecter_jsons/no_json/dummy.json b/test/host_effecter_jsons/no_json/dummy.json
new file mode 100644
index 0000000..401832d
--- /dev/null
+++ b/test/host_effecter_jsons/no_json/dummy.json
@@ -0,0 +1,5 @@
+"record_details":
+ {
+ "fru_record_type" : 1,
+ "encoding_type": 1
+ }
diff --git a/test/libpldmresponder_dbus_to_host_effecter_test.cpp b/test/libpldmresponder_dbus_to_host_effecter_test.cpp
new file mode 100644
index 0000000..e9ca8cc
--- /dev/null
+++ b/test/libpldmresponder_dbus_to_host_effecter_test.cpp
@@ -0,0 +1,92 @@
+#include "dbus_to_host_effecters.hpp"
+#include "mocked_utils.hpp"
+#include "utils.hpp"
+
+#include <nlohmann/json.hpp>
+
+#include <iostream>
+
+#include <gtest/gtest.h>
+
+using namespace pldm::host_effecters;
+using namespace pldm::utils;
+using namespace pldm::dbus_api;
+
+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)
+ {}
+
+ MOCK_METHOD(void, setHostStateEffecter,
+ (size_t, std::vector<set_effecter_state_field>&, uint16_t),
+ (const override));
+
+ MOCK_METHOD(void, createHostEffecterMatch,
+ (const std::string&, const std::string&, size_t, size_t,
+ uint16_t),
+ (const 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(), 1);
+ ASSERT_EQ(hostEffecterInfo[0].entityInstance, 0);
+ ASSERT_EQ(hostEffecterInfo[0].entityType, 33);
+ ASSERT_EQ(hostEffecterInfo[0].dbusInfo.size(), 1);
+ 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);
+}
+
+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);
+}
diff --git a/test/libpldmresponder_pdr_effecter_test.cpp b/test/libpldmresponder_pdr_effecter_test.cpp
index 98b31ea..9d98c1f 100644
--- a/test/libpldmresponder_pdr_effecter_test.cpp
+++ b/test/libpldmresponder_pdr_effecter_test.cpp
@@ -172,3 +172,21 @@
pldm_pdr_destroy(inPDRRepo);
pldm_pdr_destroy(outPDRRepo);
}
+
+TEST(findStateEffecterId, goodJson)
+{
+ auto inPDRRepo = pldm_pdr_init();
+ Handler handler("./pdr_jsons/state_effecter/good", "", inPDRRepo, nullptr);
+ uint16_t entityType = 33;
+ uint16_t entityInstance = 0;
+ uint16_t containerId = 0;
+ uint16_t stateSetId = 196;
+ auto effecterId = findStateEffecterId(inPDRRepo, entityType, entityInstance,
+ containerId, stateSetId);
+ ASSERT_EQ(effecterId, 1);
+ stateSetId = 300;
+ effecterId = findStateEffecterId(inPDRRepo, entityType, entityInstance,
+ containerId, stateSetId);
+ ASSERT_EQ(effecterId, PLDM_INVALID_EFFECTER_ID);
+ pldm_pdr_destroy(inPDRRepo);
+}
diff --git a/test/meson.build b/test/meson.build
index 4bbdbc5..9bef526 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -18,7 +18,8 @@
sources: [
'../instance_id.cpp',
'../dbus_impl_requester.cpp',
- '../host_pdr_handler.cpp'])
+ '../host_pdr_handler.cpp',
+ '../dbus_to_host_effecters.cpp'])
tests = [
'libpldmresponder_base_test',
@@ -35,6 +36,7 @@
'pldmd_registration_test',
'pldm_utils_test',
'libpldmresponder_fru_test',
+ 'libpldmresponder_dbus_to_host_effecter_test',
]
if get_option('oem-ibm').enabled()