Support numeric effecters in dbus-to-host-effecter
Adds support of the numeric effecter PDR (section `28.11 Numeric
Effecter PDR` DSP0248 V1.3.0) type in dbus-to-host-effecter handler.
This handler will be applied for all PLDM termini but not only host.
The setting for one numeric effecter of one device can be:
{
"mctp_eid": 20,
"effecter_info": {
"effecterPdrType": 9,
"effecterID": 2,
"entityType": 32903,
"entityInstance": 2,
"containerID": 2,
"compositeEffecterCount": 1,
"checkHostState": false
},
"effecters": [
{
"dbus_info": {
"object_path": "/xyz/openbmc_project/sensors/power/A",
"interface": "xyz.openbmc_project.Sensor.Value",
"property_name": "Value",
"property_type": "double"
},
"effecterDataSize": 5,
"resolution": 1,
"offset": 0,
"unitModifier": 0
}
]
}
Where:
+ effecterPdrType to difference state/numeric effecter type. Default
is state effecter.
+ effecterID should be effecter ID and should not empty.
+ checkHostState can be set to false to bypass checking host state.
+ effecterDataSize, resolution, offset, unitModifier are from numeric
effecter PDR (section `28.11 Numeric Effecter PDR` DSP0248 V1.3.0)
Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Change-Id: I438d7f204643edd4066e8a6ba28d53a97503fc4b
diff --git a/host-bmc/test/dbus_to_host_effecter_test.cpp b/host-bmc/test/dbus_to_host_effecter_test.cpp
deleted file mode 100644
index 00653ce..0000000
--- a/host-bmc/test/dbus_to_host_effecter_test.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-#include "common/test/mocked_utils.hpp"
-#include "common/utils.hpp"
-#include "host-bmc/dbus_to_host_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)
- {}
-
- 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(), 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/host-bmc/test/dbus_to_terminus_effecter_test.cpp b/host-bmc/test/dbus_to_terminus_effecter_test.cpp
new file mode 100644
index 0000000..f8ff8d6
--- /dev/null
+++ b/host-bmc/test/dbus_to_terminus_effecter_test.cpp
@@ -0,0 +1,143 @@
+#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)
+ {}
+
+ 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_host_effecter.json b/host-bmc/test/host_effecter_jsons/good/dbus_to_host_effecter.json
deleted file mode 100644
index 5ae694c..0000000
--- a/host-bmc/test/host_effecter_jsons/good/dbus_to_host_effecter.json
+++ /dev/null
@@ -1,31 +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]
- }
- }
- ]
- }
- ]
-}
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
new file mode 100644
index 0000000..2bc789a
--- /dev/null
+++ b/host-bmc/test/host_effecter_jsons/good/dbus_to_terminus_effecter.json
@@ -0,0 +1,57 @@
+{
+ "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_host_effecter.json b/host-bmc/test/host_effecter_jsons/malformed/dbus_to_terminus_effecter.json
similarity index 100%
rename from host-bmc/test/host_effecter_jsons/malformed/dbus_to_host_effecter.json
rename to host-bmc/test/host_effecter_jsons/malformed/dbus_to_terminus_effecter.json
diff --git a/host-bmc/test/meson.build b/host-bmc/test/meson.build
index 9f762ed..c1d429d 100644
--- a/host-bmc/test/meson.build
+++ b/host-bmc/test/meson.build
@@ -1,5 +1,5 @@
host_bmc_test_src = declare_dependency(
- sources: ['../dbus_to_host_effecters.cpp'],
+ sources: ['../dbus_to_terminus_effecters.cpp'],
include_directories: '../../requester',
)
@@ -13,7 +13,7 @@
'../dbus/pcie_slot.cpp',
]
-tests = ['dbus_to_host_effecter_test', 'utils_test', 'custom_dbus_test']
+tests = ['dbus_to_terminus_effecter_test', 'utils_test', 'custom_dbus_test']
foreach t : tests
test(