Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 1 | #include "src/associations.hpp" |
| 2 | |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 3 | #include "src/test/util/asio_server_class.hpp" |
Andrew Geissler | bb7b592 | 2019-02-08 14:16:48 -0600 | [diff] [blame] | 4 | #include "src/test/util/association_objects.hpp" |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 5 | |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 6 | #include <sdbusplus/asio/connection.hpp> |
| 7 | #include <sdbusplus/asio/object_server.hpp> |
| 8 | |
| 9 | #include <gtest/gtest.h> |
| 10 | |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 11 | class TestAssociations : public AsioServerClassTest |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 12 | { |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 13 | }; |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 14 | sdbusplus::asio::object_server* TestAssociations::AsioServerClassTest::server = |
| 15 | nullptr; |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 16 | |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 17 | // Verify call when path is not in associated owners |
| 18 | TEST_F(TestAssociations, SourcePathNotInAssociations) |
| 19 | { |
| 20 | EXPECT_NE(nullptr, server); |
| 21 | std::string sourcePath = "/xyz/openbmc_project/no/association"; |
| 22 | AssociationOwnersType assocOwners; |
| 23 | AssociationInterfaces assocInterfaces; |
| 24 | |
| 25 | removeAssociation(sourcePath, DEFAULT_DBUS_SVC, *server, assocOwners, |
| 26 | assocInterfaces); |
| 27 | } |
| 28 | |
| 29 | // Verify call when owner is not in associated owners |
| 30 | TEST_F(TestAssociations, OwnerNotInAssociations) |
| 31 | { |
| 32 | AssociationInterfaces assocInterfaces; |
| 33 | |
| 34 | auto assocOwners = createDefaultOwnerAssociation(); |
| 35 | |
| 36 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
| 37 | assocOwners, assocInterfaces); |
| 38 | } |
| 39 | |
| 40 | // Verify call when path is not in associated interfaces |
| 41 | TEST_F(TestAssociations, PathNotInAssocInterfaces) |
| 42 | { |
| 43 | AssociationInterfaces assocInterfaces; |
| 44 | |
| 45 | auto assocOwners = createDefaultOwnerAssociation(); |
| 46 | |
| 47 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
| 48 | assocOwners, assocInterfaces); |
| 49 | |
| 50 | EXPECT_TRUE(assocOwners.empty()); |
| 51 | } |
| 52 | |
| 53 | // Verify call when path is in associated interfaces |
| 54 | TEST_F(TestAssociations, PathIsInAssociatedInterfaces) |
| 55 | { |
| 56 | // Build up these objects so that an associated interface will match |
| 57 | // with the associated owner being removed |
| 58 | auto assocOwners = createDefaultOwnerAssociation(); |
| 59 | auto assocInterfaces = createDefaultInterfaceAssociation(server); |
| 60 | |
| 61 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
| 62 | assocOwners, assocInterfaces); |
| 63 | |
| 64 | // Verify owner association was deleted |
| 65 | EXPECT_TRUE(assocOwners.empty()); |
| 66 | |
| 67 | // Verify endpoint was deleted from interface association |
| 68 | auto intfEndpoints = |
| 69 | std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]); |
| 70 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 71 | intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]); |
| 72 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 73 | } |
| 74 | |
| 75 | // Verify call when path is in associated interfaces, with extra endpoints |
| 76 | TEST_F(TestAssociations, PathIsInAssociatedInterfacesExtraEndpoints) |
| 77 | { |
| 78 | // Build up these objects so that an associated interface will match |
| 79 | // with the associated owner being removed |
| 80 | auto assocOwners = createDefaultOwnerAssociation(); |
| 81 | auto assocInterfaces = createDefaultInterfaceAssociation(server); |
| 82 | |
| 83 | // Add another endpoint to the assoc interfaces |
| 84 | addEndpointToInterfaceAssociation(assocInterfaces); |
| 85 | |
| 86 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
| 87 | assocOwners, assocInterfaces); |
| 88 | |
| 89 | // Verify owner association was deleted |
| 90 | EXPECT_TRUE(assocOwners.empty()); |
| 91 | |
| 92 | // Verify all endpoints are deleted since source path was deleted |
| 93 | auto intfEndpoints = |
| 94 | std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]); |
| 95 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 96 | intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]); |
| 97 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 98 | } |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 99 | |
| 100 | // Verify no associations or endpoints removed when the change is identical |
| 101 | TEST_F(TestAssociations, checkAssociationEndpointRemovesNoEpRemove) |
| 102 | { |
| 103 | |
| 104 | AssociationPaths newAssocPaths = { |
| 105 | {DEFAULT_FWD_PATH, {DEFAULT_ENDPOINT}}, |
| 106 | {DEFAULT_REV_PATH, {DEFAULT_SOURCE_PATH}}}; |
| 107 | |
| 108 | auto assocOwners = createDefaultOwnerAssociation(); |
| 109 | auto assocInterfaces = createDefaultInterfaceAssociation(server); |
| 110 | |
| 111 | checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, |
| 112 | newAssocPaths, *server, assocOwners, |
| 113 | assocInterfaces); |
| 114 | |
| 115 | // Verify endpoints were not deleted because they matche with what was |
| 116 | // in the original |
| 117 | auto intfEndpoints = |
| 118 | std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]); |
| 119 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 120 | intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]); |
| 121 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 122 | } |
| 123 | |
| 124 | // Verify endpoint is removed when assoc path is different |
| 125 | TEST_F(TestAssociations, checkAssociationEndpointRemovesEpRemoveApDiff) |
| 126 | { |
| 127 | AssociationPaths newAssocPaths = {{"/different/path", {DEFAULT_ENDPOINT}}}; |
| 128 | |
| 129 | auto assocOwners = createDefaultOwnerAssociation(); |
| 130 | auto assocInterfaces = createDefaultInterfaceAssociation(server); |
| 131 | |
| 132 | checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, |
| 133 | newAssocPaths, *server, assocOwners, |
| 134 | assocInterfaces); |
| 135 | |
| 136 | // Verify initial endpoints were deleted because the new path |
| 137 | auto intfEndpoints = |
| 138 | std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]); |
| 139 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 140 | intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]); |
| 141 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 142 | } |
| 143 | |
| 144 | // Verify endpoint is removed when endpoint is different |
| 145 | TEST_F(TestAssociations, checkAssociationEndpointRemovesEpRemoveEpChanged) |
| 146 | { |
| 147 | AssociationPaths newAssocPaths = { |
| 148 | {DEFAULT_FWD_PATH, {DEFAULT_ENDPOINT + "/different"}}, |
| 149 | {DEFAULT_REV_PATH, {DEFAULT_SOURCE_PATH + "/different"}}}; |
| 150 | |
| 151 | auto assocOwners = createDefaultOwnerAssociation(); |
| 152 | auto assocInterfaces = createDefaultInterfaceAssociation(server); |
| 153 | |
| 154 | checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, |
| 155 | newAssocPaths, *server, assocOwners, |
| 156 | assocInterfaces); |
| 157 | |
| 158 | // Verify initial endpoints were deleted because of different endpoints |
| 159 | auto intfEndpoints = |
| 160 | std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]); |
| 161 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 162 | intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]); |
| 163 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 164 | } |