| #include "config.h" |
| |
| #include "common/utils.hpp" |
| #include "requester/test/mock_mctp_discovery_handler_intf.hpp" |
| |
| #include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| |
| using ::testing::_; |
| |
| TEST(MctpEndpointDiscoveryTest, SingleHandleMctpEndpoint) |
| { |
| auto& bus = pldm::utils::DBusHandler::getBus(); |
| pldm::MockManager manager; |
| |
| EXPECT_CALL(manager, handleMctpEndpoints(_)).Times(1); |
| |
| auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>( |
| bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager}); |
| mctpDiscoveryHandler = nullptr; |
| } |
| |
| TEST(MctpEndpointDiscoveryTest, MultipleHandleMctpEndpoints) |
| { |
| auto& bus = pldm::utils::DBusHandler::getBus(); |
| pldm::MockManager manager1; |
| pldm::MockManager manager2; |
| |
| EXPECT_CALL(manager1, handleMctpEndpoints(_)).Times(1); |
| EXPECT_CALL(manager2, handleMctpEndpoints(_)).Times(1); |
| |
| auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>( |
| bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{ |
| &manager1, &manager2}); |
| mctpDiscoveryHandler = nullptr; |
| } |
| |
| TEST(MctpEndpointDiscoveryTest, goodGetMctpInfos) |
| { |
| auto& bus = pldm::utils::DBusHandler::getBus(); |
| pldm::MockManager manager; |
| pldm::MctpInfos mctpInfos; |
| |
| auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>( |
| bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager}); |
| mctpDiscoveryHandler->getMctpInfos(mctpInfos); |
| EXPECT_EQ(mctpInfos.size(), 0); |
| } |
| |
| TEST(MctpEndpointDiscoveryTest, goodAddToExistingMctpInfos) |
| { |
| 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)}; |
| |
| auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>( |
| bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager}); |
| mctpDiscoveryHandler->addToExistingMctpInfos(mctpInfos); |
| EXPECT_EQ(mctpDiscoveryHandler->existingMctpInfos.size(), 2); |
| pldm::MctpInfo mctpInfo = mctpDiscoveryHandler->existingMctpInfos.back(); |
| EXPECT_EQ(std::get<0>(mctpInfo), 12); |
| EXPECT_EQ(std::get<2>(mctpInfo), "abc"); |
| EXPECT_EQ(std::get<3>(mctpInfo), 1); |
| } |
| |
| TEST(MctpEndpointDiscoveryTest, badAddToExistingMctpInfos) |
| { |
| auto& bus = pldm::utils::DBusHandler::getBus(); |
| pldm::MockManager manager; |
| const pldm::MctpInfos& mctpInfos = { |
| pldm::MctpInfo(11, pldm::emptyUUID, "", 1)}; |
| |
| auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>( |
| bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager}); |
| mctpDiscoveryHandler->addToExistingMctpInfos(mctpInfos); |
| EXPECT_NE(mctpDiscoveryHandler->existingMctpInfos.size(), 2); |
| } |
| |
| TEST(MctpEndpointDiscoveryTest, goodRemoveFromExistingMctpInfos) |
| { |
| 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)}; |
| |
| auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>( |
| bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager}); |
| mctpDiscoveryHandler->addToExistingMctpInfos(mctpInfos); |
| EXPECT_EQ(mctpDiscoveryHandler->existingMctpInfos.size(), 2); |
| pldm::MctpInfo mctpInfo = mctpDiscoveryHandler->existingMctpInfos.back(); |
| EXPECT_EQ(std::get<0>(mctpInfo), 12); |
| EXPECT_EQ(std::get<2>(mctpInfo), "abc"); |
| EXPECT_EQ(std::get<3>(mctpInfo), 1); |
| pldm::MctpInfos removedInfos; |
| pldm::MctpInfos remainMctpInfos; |
| remainMctpInfos.emplace_back(pldm::MctpInfo(12, pldm::emptyUUID, "abc", 1)); |
| |
| mctpDiscoveryHandler->removeFromExistingMctpInfos(remainMctpInfos, |
| removedInfos); |
| EXPECT_EQ(mctpDiscoveryHandler->existingMctpInfos.size(), 1); |
| mctpInfo = mctpDiscoveryHandler->existingMctpInfos.back(); |
| EXPECT_EQ(std::get<0>(mctpInfo), 12); |
| EXPECT_EQ(std::get<2>(mctpInfo), "abc"); |
| EXPECT_EQ(std::get<3>(mctpInfo), 1); |
| EXPECT_EQ(removedInfos.size(), 1); |
| mctpInfo = removedInfos.back(); |
| EXPECT_EQ(std::get<0>(mctpInfo), 11); |
| EXPECT_EQ(std::get<2>(mctpInfo), "def"); |
| EXPECT_EQ(std::get<3>(mctpInfo), 2); |
| } |
| |
| TEST(MctpEndpointDiscoveryTest, goodRemoveEndpoints) |
| { |
| 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)}; |
| |
| auto mctpDiscoveryHandler = std::make_unique<pldm::MctpDiscovery>( |
| bus, std::initializer_list<pldm::MctpDiscoveryHandlerIntf*>{&manager}); |
| mctpDiscoveryHandler->addToExistingMctpInfos(mctpInfos); |
| EXPECT_EQ(mctpDiscoveryHandler->existingMctpInfos.size(), 2); |
| pldm::MctpInfo mctpInfo = mctpDiscoveryHandler->existingMctpInfos.back(); |
| EXPECT_EQ(std::get<0>(mctpInfo), 12); |
| EXPECT_EQ(std::get<2>(mctpInfo), "abc"); |
| EXPECT_EQ(std::get<3>(mctpInfo), 1); |
| sdbusplus::message_t msg = sdbusplus::bus::new_default().new_method_call( |
| "xyz.openbmc_project.sdbusplus.test.Object", |
| "/xyz/openbmc_project/sdbusplus/test/object", |
| "xyz.openbmc_project.sdbusplus.test.Object", "Unused"); |
| mctpDiscoveryHandler->removeEndpoints(msg); |
| EXPECT_EQ(mctpDiscoveryHandler->existingMctpInfos.size(), 0); |
| } |