requester: associate Entity Manager configs with MCTP endpoints
Currently, pldmd listens for new MCTP endpoint exposed by mctpd, but
they only shows their EID, Network Id, and SupportedMessageTypes, which
cannot fulfill some requirements, e.g., get the device's name or which
board it belongs to.
In openbmc, the additional information are exposed by Entity
Manager[1][2], so add this ability to `MctpDiscovery, it queries the
association between MCTP endpoints and Entity Manager configurations
from MCTP Reactor, when a new MCTP endpoint has been register by mctpd.
Added unit test for this commit to validate the association does work,
passed.
[1]: https://github.com/openbmc/entity-manager/blob/master/schemas/mctp.json
[2]: https://gerrit.openbmc.org/c/openbmc/dbus-sensors/+/69111
Change-Id: Ibf1717f1840e527f21bd8397e747ae121e2dcd25
Signed-off-by: Unive Tien <unive.tien.wiwynn@gmail.com>
diff --git a/requester/test/mctp_endpoint_discovery_test.cpp b/requester/test/mctp_endpoint_discovery_test.cpp
index 01e5eb0..3647d11 100644
--- a/requester/test/mctp_endpoint_discovery_test.cpp
+++ b/requester/test/mctp_endpoint_discovery_test.cpp
@@ -1,5 +1,6 @@
#include "config.h"
+#include "common/test/mocked_utils.hpp"
#include "common/types.hpp"
#include "common/utils.hpp"
#include "requester/test/mock_mctp_discovery_handler_intf.hpp"
@@ -9,6 +10,22 @@
using ::testing::_;
+class TestMctpDiscovery : public ::testing::Test
+{
+ public:
+ static const pldm::Configurations& getConfigurations(
+ const pldm::MctpDiscovery& mctpDiscovery)
+ {
+ return mctpDiscovery.configurations;
+ }
+ static void searchConfigurationFor(pldm::MctpDiscovery& mctpDiscovery,
+ pldm::utils::DBusHandler& handler,
+ pldm::MctpInfo& mctpInfo)
+ {
+ mctpDiscovery.searchConfigurationFor(handler, mctpInfo);
+ }
+};
+
TEST(MctpEndpointDiscoveryTest, SingleHandleMctpEndpoint)
{
auto& bus = pldm::utils::DBusHandler::getBus();
@@ -53,8 +70,8 @@
auto& bus = pldm::utils::DBusHandler::getBus();
pldm::MockManager manager;
const pldm::MctpInfos& mctpInfos = {
- pldm::MctpInfo(11, pldm::emptyUUID, "", 1),
- pldm::MctpInfo(12, pldm::emptyUUID, "abc", 1)};
+ pldm::MctpInfo(11, pldm::emptyUUID, "", 1, std::nullopt),
+ pldm::MctpInfo(12, pldm::emptyUUID, "abc", 1, std::nullopt)};
auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>(
bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager});
@@ -71,7 +88,7 @@
auto& bus = pldm::utils::DBusHandler::getBus();
pldm::MockManager manager;
const pldm::MctpInfos& mctpInfos = {
- pldm::MctpInfo(11, pldm::emptyUUID, "", 1)};
+ pldm::MctpInfo(11, pldm::emptyUUID, "", 1, std::nullopt)};
auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>(
bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager});
@@ -84,8 +101,8 @@
auto& bus = pldm::utils::DBusHandler::getBus();
pldm::MockManager manager;
const pldm::MctpInfos& mctpInfos = {
- pldm::MctpInfo(11, pldm::emptyUUID, "def", 2),
- pldm::MctpInfo(12, pldm::emptyUUID, "abc", 1)};
+ pldm::MctpInfo(11, pldm::emptyUUID, "def", 2, std::nullopt),
+ pldm::MctpInfo(12, pldm::emptyUUID, "abc", 1, std::nullopt)};
auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>(
bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager});
@@ -97,7 +114,8 @@
EXPECT_EQ(std::get<3>(mctpInfo), 1);
pldm::MctpInfos removedInfos;
pldm::MctpInfos remainMctpInfos;
- remainMctpInfos.emplace_back(pldm::MctpInfo(12, pldm::emptyUUID, "abc", 1));
+ remainMctpInfos.emplace_back(
+ pldm::MctpInfo(12, pldm::emptyUUID, "abc", 1, std::nullopt));
mctpDiscoveryHandler->removeFromExistingMctpInfos(remainMctpInfos,
removedInfos);
@@ -118,8 +136,8 @@
auto& bus = pldm::utils::DBusHandler::getBus();
pldm::MockManager manager;
const pldm::MctpInfos& mctpInfos = {
- pldm::MctpInfo(11, pldm::emptyUUID, "def", 2),
- pldm::MctpInfo(12, pldm::emptyUUID, "abc", 1)};
+ pldm::MctpInfo(11, pldm::emptyUUID, "def", 2, std::nullopt),
+ pldm::MctpInfo(12, pldm::emptyUUID, "abc", 1, std::nullopt)};
auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>(
bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager});
@@ -136,3 +154,90 @@
mctpDiscoveryHandler->removeEndpoints(msg);
EXPECT_EQ(mctpDiscoveryHandler->existingMctpInfos.size(), 0);
}
+
+TEST(MctpEndpointDiscoveryTest, goodSearchConfigurationFor)
+{
+ MockdBusHandler mockedDbusHandler;
+ auto& bus = mockedDbusHandler.getBus();
+ pldm::MockManager manager;
+ const pldm::MctpInfos& mctpInfos = {
+ pldm::MctpInfo(10, pldm::emptyUUID, "abc", 1, std::nullopt)};
+
+ constexpr auto mockedDbusPath =
+ "/xyz/openbmc_project/inventory/system/board/Mocked_Board_Slot_1/MockedDevice";
+ constexpr auto mockedService = "xyz.openbmc_project.EntityManager";
+ std::vector<std::string> mockedInterfaces{
+ "xyz.openbmc_project.Configuration.MCTPI2CTarget",
+ "xyz.openbmc_project.Configuration.MCTPI3CTarget"};
+
+ pldm::utils::GetAssociatedSubTreeResponse
+ mockedGetAssociatedSubTreeResponse{
+ {mockedDbusPath, {{mockedService, mockedInterfaces}}}};
+
+ EXPECT_CALL(mockedDbusHandler, getAssociatedSubTree(_, _, _, _))
+ .WillOnce(testing::Return(mockedGetAssociatedSubTreeResponse));
+
+ pldm::utils::PropertyMap mockGetI2CTargetPropertiesResponse{
+ {"Address", uint64_t(0x1)},
+ {"Bus", uint64_t(0)},
+ {"Name", std::string("MockedDevice")}};
+
+ EXPECT_CALL(mockedDbusHandler, getDbusPropertiesVariant(_, _, _))
+ .WillOnce(testing::Return(mockGetI2CTargetPropertiesResponse));
+
+ auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>(
+ bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager});
+ mctpDiscoveryHandler->addToExistingMctpInfos(mctpInfos);
+ EXPECT_EQ(mctpDiscoveryHandler->existingMctpInfos.size(), 1);
+ pldm::MctpInfo mctpInfo = mctpDiscoveryHandler->existingMctpInfos.back();
+ EXPECT_EQ(std::get<0>(mctpInfo), 10);
+ EXPECT_EQ(std::get<2>(mctpInfo), "abc");
+ EXPECT_EQ(std::get<3>(mctpInfo), 1);
+ TestMctpDiscovery::searchConfigurationFor(*mctpDiscoveryHandler,
+ mockedDbusHandler, mctpInfo);
+ EXPECT_EQ(std::get<4>(mctpInfo),
+ std::optional<std::string>("MockedDevice"));
+ auto configuration =
+ TestMctpDiscovery::getConfigurations(*mctpDiscoveryHandler);
+ EXPECT_EQ(configuration.size(), 1);
+}
+
+TEST(MctpEndpointDiscoveryTest, badSearchConfigurationFor)
+{
+ MockdBusHandler mockedDbusHandler;
+ auto& bus = mockedDbusHandler.getBus();
+ pldm::MockManager manager;
+ const pldm::MctpInfos& mctpInfos = {
+ pldm::MctpInfo(10, pldm::emptyUUID, "abc", 1, std::nullopt)};
+
+ constexpr auto mockedDbusPath =
+ "/xyz/openbmc_project/inventory/system/board/Mocked_Board_Slot_1/MockedDevice";
+ constexpr auto mockedService = "xyz.openbmc_project.EntityManager";
+ std::vector<std::string> mockedInterfaces{
+ "xyz.openbmc_project.Configuration.MCTPPCIETarget",
+ "xyz.openbmc_project.Configuration.MCTPUSBTarget"};
+
+ pldm::utils::GetAssociatedSubTreeResponse
+ mockedGetAssociatedSubTreeResponse{
+ {mockedDbusPath, {{mockedService, mockedInterfaces}}}};
+
+ EXPECT_CALL(mockedDbusHandler, getAssociatedSubTree(_, _, _, _))
+ .WillOnce(testing::Return(mockedGetAssociatedSubTreeResponse));
+
+ pldm::utils::PropertyMap mockGetI2CTargetPropertiesResponse{
+ {"Address", uint64_t(0x1)}, {"Bus", uint64_t(0)}};
+
+ auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>(
+ bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager});
+ mctpDiscoveryHandler->addToExistingMctpInfos(mctpInfos);
+ EXPECT_EQ(mctpDiscoveryHandler->existingMctpInfos.size(), 1);
+ pldm::MctpInfo mctpInfo = mctpDiscoveryHandler->existingMctpInfos.back();
+ EXPECT_EQ(std::get<0>(mctpInfo), 10);
+ EXPECT_EQ(std::get<2>(mctpInfo), "abc");
+ EXPECT_EQ(std::get<3>(mctpInfo), 1);
+ TestMctpDiscovery::searchConfigurationFor(*mctpDiscoveryHandler,
+ mockedDbusHandler, mctpInfo);
+ auto configuration =
+ TestMctpDiscovery::getConfigurations(*mctpDiscoveryHandler);
+ EXPECT_EQ(configuration.size(), 0);
+}