blob: 63a6a26edb79f042332123fb1123eceb82214b02 [file] [log] [blame]
Andrew Geissler7f838372019-02-27 10:14:31 -06001#include "src/processing.hpp"
2#include "src/test/util/asio_server_class.hpp"
3#include "src/test/util/association_objects.hpp"
4#include "src/test/util/debug_output.hpp"
5
6#include <sdbusplus/asio/connection.hpp>
7#include <sdbusplus/asio/object_server.hpp>
8
9#include <gtest/gtest.h>
10
11class TestInterfacesAdded : public AsioServerClassTest
Brad Bishop23520882022-05-26 21:39:53 -040012{};
Andrew Geissler7f838372019-02-27 10:14:31 -060013sdbusplus::asio::object_server*
14 TestInterfacesAdded::AsioServerClassTest::server = nullptr;
15
16// This is the data structure that comes in via the InterfacesAdded
17// signal
Matt Spinler8f876a52019-04-15 13:22:50 -050018InterfacesAdded createInterfacesAdded(const std::string& interface,
19 const std::string& property)
Andrew Geissler7f838372019-02-27 10:14:31 -060020{
21 std::vector<Association> associations = {
22 {"inventory", "error",
23 "/xyz/openbmc_project/inventory/system/chassis"}};
Patrick Williams2bb2d6b2020-05-13 17:59:02 -050024 std::variant<std::vector<Association>> sdbVecAssoc = {associations};
25 std::vector<std::pair<std::string, std::variant<std::vector<Association>>>>
Matt Spinler8f876a52019-04-15 13:22:50 -050026 vecMethToAssoc = {{property, sdbVecAssoc}};
27 InterfacesAdded intfAdded = {{interface, vecMethToAssoc}};
Andrew Geissler7f838372019-02-27 10:14:31 -060028 return intfAdded;
29}
30
31// Verify good path of interfaces added function
32TEST_F(TestInterfacesAdded, InterfacesAddedGoodPath)
33{
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050034 auto interfaceMap = createDefaultInterfaceMap();
Matt Spinlere2359fb2019-04-05 14:11:33 -050035 AssociationMaps assocMaps;
36
Patrick Williams9052ebd2024-08-16 15:22:16 -040037 auto intfAdded =
38 createInterfacesAdded(assocDefsInterface, assocDefsProperty);
Matt Spinler8f876a52019-04-15 13:22:50 -050039
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020040 boost::asio::io_context io;
41
42 processInterfaceAdded(io, interfaceMap, defaultSourcePath, intfAdded,
Brad Bishopa098a372022-05-05 15:19:04 -040043 defaultDbusSvc, assocMaps, *server);
Matt Spinler8f876a52019-04-15 13:22:50 -050044
Kallas, Pawel5b4357d2022-10-12 15:36:37 +020045 io.run();
46
Matt Spinler8f876a52019-04-15 13:22:50 -050047 // Interface map will get the following:
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050048 // /logging/entry/1 /logging/entry /logging/ / system/chassis
Brad Bishopa098a372022-05-05 15:19:04 -040049 // dumpInterfaceMapType(interfaceMap);
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050050 EXPECT_EQ(interfaceMap.size(), 5);
Matt Spinler8f876a52019-04-15 13:22:50 -050051
52 // New association ower created so ensure it now contains a single entry
Brad Bishopa098a372022-05-05 15:19:04 -040053 // dumpAssociationOwnersType(assocOwners);
Matt Spinlere2359fb2019-04-05 14:11:33 -050054 EXPECT_EQ(assocMaps.owners.size(), 1);
Matt Spinler8f876a52019-04-15 13:22:50 -050055
56 // Ensure the 2 association interfaces were created
Brad Bishopa098a372022-05-05 15:19:04 -040057 // dumpAssociationInterfaces(assocInterfaces);
Matt Spinlere2359fb2019-04-05 14:11:33 -050058 EXPECT_EQ(assocMaps.ifaces.size(), 2);
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050059
60 // No pending associations
61 EXPECT_EQ(assocMaps.pending.size(), 0);
Matt Spinler8f876a52019-04-15 13:22:50 -050062}