blob: bee978f1a8f7d9eefc7c727976307af20f7aa5ec [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
12{
13};
14sdbusplus::asio::object_server*
15 TestInterfacesAdded::AsioServerClassTest::server = nullptr;
16
17// This is the data structure that comes in via the InterfacesAdded
18// signal
Matt Spinler8f876a52019-04-15 13:22:50 -050019InterfacesAdded createInterfacesAdded(const std::string& interface,
20 const std::string& property)
Andrew Geissler7f838372019-02-27 10:14:31 -060021{
22 std::vector<Association> associations = {
23 {"inventory", "error",
24 "/xyz/openbmc_project/inventory/system/chassis"}};
25 sdbusplus::message::variant<std::vector<Association>> sdbVecAssoc = {
26 associations};
27 std::vector<std::pair<
28 std::string, sdbusplus::message::variant<std::vector<Association>>>>
Matt Spinler8f876a52019-04-15 13:22:50 -050029 vecMethToAssoc = {{property, sdbVecAssoc}};
30 InterfacesAdded intfAdded = {{interface, vecMethToAssoc}};
Andrew Geissler7f838372019-02-27 10:14:31 -060031 return intfAdded;
32}
33
34// Verify good path of interfaces added function
35TEST_F(TestInterfacesAdded, InterfacesAddedGoodPath)
36{
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050037 auto interfaceMap = createDefaultInterfaceMap();
Matt Spinlere2359fb2019-04-05 14:11:33 -050038 AssociationMaps assocMaps;
39
Matt Spinler8f876a52019-04-15 13:22:50 -050040 auto intfAdded = createInterfacesAdded(
41 assocDefsInterface, getAssocDefPropName(assocDefsInterface));
42
43 processInterfaceAdded(interfaceMap, DEFAULT_SOURCE_PATH, intfAdded,
Matt Spinlere2359fb2019-04-05 14:11:33 -050044 DEFAULT_DBUS_SVC, assocMaps, *server);
Matt Spinler8f876a52019-04-15 13:22:50 -050045
46 // Interface map will get the following:
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050047 // /logging/entry/1 /logging/entry /logging/ / system/chassis
Matt Spinler8f876a52019-04-15 13:22:50 -050048 // dump_InterfaceMapType(interfaceMap);
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050049 EXPECT_EQ(interfaceMap.size(), 5);
Matt Spinler8f876a52019-04-15 13:22:50 -050050
51 // New association ower created so ensure it now contains a single entry
52 // dump_AssociationOwnersType(assocOwners);
Matt Spinlere2359fb2019-04-05 14:11:33 -050053 EXPECT_EQ(assocMaps.owners.size(), 1);
Matt Spinler8f876a52019-04-15 13:22:50 -050054
55 // Ensure the 2 association interfaces were created
56 // dump_AssociationInterfaces(assocInterfaces);
Matt Spinlere2359fb2019-04-05 14:11:33 -050057 EXPECT_EQ(assocMaps.ifaces.size(), 2);
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050058
59 // No pending associations
60 EXPECT_EQ(assocMaps.pending.size(), 0);
Matt Spinler8f876a52019-04-15 13:22:50 -050061}
62
63TEST_F(TestInterfacesAdded, OrgOpenBmcInterfacesAddedGoodPath)
64{
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050065 auto interfaceMap = createDefaultInterfaceMap();
Matt Spinlere2359fb2019-04-05 14:11:33 -050066 AssociationMaps assocMaps;
67
Matt Spinler8f876a52019-04-15 13:22:50 -050068 auto intfAdded = createInterfacesAdded(
69 orgOpenBMCAssocDefsInterface,
70 getAssocDefPropName(orgOpenBMCAssocDefsInterface));
Andrew Geissler7f838372019-02-27 10:14:31 -060071
72 processInterfaceAdded(interfaceMap, DEFAULT_SOURCE_PATH, intfAdded,
Matt Spinlere2359fb2019-04-05 14:11:33 -050073 DEFAULT_DBUS_SVC, assocMaps, *server);
Andrew Geissler7f838372019-02-27 10:14:31 -060074
75 // Interface map will get the following:
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050076 // /logging/entry/1 /logging/entry /logging/ / system/chassis
77 EXPECT_EQ(interfaceMap.size(), 5);
Andrew Geissler7f838372019-02-27 10:14:31 -060078
79 // New association ower created so ensure it now contains a single entry
80 // dump_AssociationOwnersType(assocOwners);
Matt Spinlere2359fb2019-04-05 14:11:33 -050081 EXPECT_EQ(assocMaps.owners.size(), 1);
Andrew Geissler7f838372019-02-27 10:14:31 -060082
83 // Ensure the 2 association interfaces were created
84 // dump_AssociationInterfaces(assocInterfaces);
Matt Spinlere2359fb2019-04-05 14:11:33 -050085 EXPECT_EQ(assocMaps.ifaces.size(), 2);
Matt Spinlere0b0e3a2019-04-08 10:39:23 -050086
87 // No pending associations
88 EXPECT_EQ(assocMaps.pending.size(), 0);
Andrew Geissler7f838372019-02-27 10:14:31 -060089}