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 | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 5 | #include "src/test/util/debug_output.hpp" |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 6 | |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 7 | #include <sdbusplus/asio/connection.hpp> |
| 8 | #include <sdbusplus/asio/object_server.hpp> |
| 9 | |
| 10 | #include <gtest/gtest.h> |
| 11 | |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 12 | class TestAssociations : public AsioServerClassTest |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 13 | { |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 14 | }; |
Andrew Geissler | b04f033 | 2019-02-08 14:07:56 -0600 | [diff] [blame] | 15 | sdbusplus::asio::object_server* TestAssociations::AsioServerClassTest::server = |
| 16 | nullptr; |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 17 | |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 18 | // Verify call when path is not in associated owners |
| 19 | TEST_F(TestAssociations, SourcePathNotInAssociations) |
| 20 | { |
| 21 | EXPECT_NE(nullptr, server); |
| 22 | std::string sourcePath = "/xyz/openbmc_project/no/association"; |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 23 | AssociationMaps assocMaps; |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 24 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 25 | removeAssociation(sourcePath, DEFAULT_DBUS_SVC, *server, assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | // Verify call when owner is not in associated owners |
| 29 | TEST_F(TestAssociations, OwnerNotInAssociations) |
| 30 | { |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 31 | AssociationMaps assocMaps; |
| 32 | assocMaps.owners = createDefaultOwnerAssociation(); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 33 | |
| 34 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 35 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | // Verify call when path is not in associated interfaces |
| 39 | TEST_F(TestAssociations, PathNotInAssocInterfaces) |
| 40 | { |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 41 | AssociationMaps assocMaps; |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 42 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 43 | assocMaps.owners = createDefaultOwnerAssociation(); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 44 | |
| 45 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 46 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 47 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 48 | EXPECT_TRUE(assocMaps.owners.empty()); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | // Verify call when path is in associated interfaces |
| 52 | TEST_F(TestAssociations, PathIsInAssociatedInterfaces) |
| 53 | { |
| 54 | // Build up these objects so that an associated interface will match |
| 55 | // with the associated owner being removed |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 56 | AssociationMaps assocMaps; |
| 57 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 58 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 59 | |
| 60 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 61 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 62 | |
| 63 | // Verify owner association was deleted |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 64 | EXPECT_TRUE(assocMaps.owners.empty()); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 65 | |
| 66 | // Verify endpoint was deleted from interface association |
| 67 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 68 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 69 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 70 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 71 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 72 | } |
| 73 | |
| 74 | // Verify call when path is in associated interfaces, with extra endpoints |
| 75 | TEST_F(TestAssociations, PathIsInAssociatedInterfacesExtraEndpoints) |
| 76 | { |
| 77 | // Build up these objects so that an associated interface will match |
| 78 | // with the associated owner being removed |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 79 | AssociationMaps assocMaps; |
| 80 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 81 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 82 | |
| 83 | // Add another endpoint to the assoc interfaces |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 84 | addEndpointToInterfaceAssociation(assocMaps.ifaces); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 85 | |
| 86 | removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 87 | assocMaps); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 88 | |
| 89 | // Verify owner association was deleted |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 90 | EXPECT_TRUE(assocMaps.owners.empty()); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 91 | |
| 92 | // Verify all endpoints are deleted since source path was deleted |
| 93 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 94 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 95 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 96 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | 271b7dd | 2019-02-05 11:23:30 -0600 | [diff] [blame] | 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 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 108 | AssociationMaps assocMaps; |
| 109 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 110 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 111 | |
| 112 | checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 113 | newAssocPaths, *server, assocMaps); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 114 | |
| 115 | // Verify endpoints were not deleted because they matche with what was |
| 116 | // in the original |
| 117 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 118 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 119 | EXPECT_EQ(intfEndpoints.size(), 1); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 120 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 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 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 129 | AssociationMaps assocMaps; |
| 130 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 131 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 132 | |
| 133 | checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 134 | newAssocPaths, *server, assocMaps); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 135 | |
| 136 | // Verify initial endpoints were deleted because the new path |
| 137 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 138 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 139 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 140 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 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 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 151 | AssociationMaps assocMaps; |
| 152 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 153 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 154 | |
| 155 | checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 156 | newAssocPaths, *server, assocMaps); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 157 | |
| 158 | // Verify initial endpoints were deleted because of different endpoints |
| 159 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 160 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 161 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 162 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | e4ab6c9 | 2019-02-21 15:07:27 -0600 | [diff] [blame] | 163 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 164 | } |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 165 | |
| 166 | // Verify existing endpoint deleted when empty endpoint is provided |
| 167 | TEST_F(TestAssociations, associationChangedEmptyEndpoint) |
| 168 | { |
| 169 | std::vector<Association> associations = {{"inventory", "error", ""}}; |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 170 | interface_map_type interfaceMap; |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 171 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 172 | AssociationMaps assocMaps; |
| 173 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 174 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 175 | |
| 176 | // Empty endpoint will result in deletion of corresponding assocInterface |
| 177 | associationChanged(*server, associations, DEFAULT_SOURCE_PATH, |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 178 | DEFAULT_DBUS_SVC, interfaceMap, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 179 | |
Andrew Geissler | 0a560a5 | 2019-03-22 10:59:07 -0500 | [diff] [blame] | 180 | // Both of these should be 0 since we have an invalid endpoint |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 181 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 182 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 0a560a5 | 2019-03-22 10:59:07 -0500 | [diff] [blame] | 183 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 184 | intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 185 | EXPECT_EQ(intfEndpoints.size(), 0); |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 186 | |
| 187 | EXPECT_EQ(assocMaps.pending.size(), 0); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | // Add a new association with endpoint |
| 191 | TEST_F(TestAssociations, associationChangedAddNewAssoc) |
| 192 | { |
| 193 | std::vector<Association> associations = { |
| 194 | {"abc", "def", "/xyz/openbmc_project/new/endpoint"}}; |
| 195 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 196 | AssociationMaps assocMaps; |
| 197 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 198 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 199 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 200 | // Make it look like the assoc endpoints are on D-Bus |
| 201 | interface_map_type interfaceMap = { |
| 202 | {"/new/source/path", {{DEFAULT_DBUS_SVC, {"a"}}}}, |
| 203 | {"/xyz/openbmc_project/new/endpoint", {{DEFAULT_DBUS_SVC, {"a"}}}}}; |
| 204 | |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 205 | associationChanged(*server, associations, "/new/source/path", |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 206 | DEFAULT_DBUS_SVC, interfaceMap, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 207 | |
| 208 | // Two source paths |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 209 | EXPECT_EQ(assocMaps.owners.size(), 2); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 210 | |
| 211 | // Four interfaces |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 212 | EXPECT_EQ(assocMaps.ifaces.size(), 4); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 213 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 214 | // Nothing pending |
| 215 | EXPECT_EQ(assocMaps.pending.size(), 0); |
| 216 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 217 | // New endpoint so assocMaps.ifaces should be same size |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 218 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 219 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 220 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 221 | } |
| 222 | |
| 223 | // Add a new association to empty objects |
| 224 | TEST_F(TestAssociations, associationChangedAddNewAssocEmptyObj) |
| 225 | { |
| 226 | std::string sourcePath = "/logging/entry/1"; |
| 227 | std::string owner = "xyz.openbmc_project.Test"; |
| 228 | std::vector<Association> associations = { |
| 229 | {"inventory", "error", |
| 230 | "/xyz/openbmc_project/inventory/system/chassis"}}; |
| 231 | |
| 232 | // Empty objects because this test will ensure assocOwners adds the |
| 233 | // changed association and interface |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 234 | AssociationMaps assocMaps; |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 235 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 236 | // Make it look like the assoc endpoints are on D-Bus |
| 237 | interface_map_type interfaceMap = createDefaultInterfaceMap(); |
| 238 | |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 239 | associationChanged(*server, associations, DEFAULT_SOURCE_PATH, |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 240 | DEFAULT_DBUS_SVC, interfaceMap, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 241 | |
| 242 | // New associations so ensure it now contains a single entry |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 243 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 244 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 245 | // Nothing pending |
| 246 | EXPECT_EQ(assocMaps.pending.size(), 0); |
| 247 | |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 248 | // Verify corresponding assoc paths each have one endpoint in assoc |
| 249 | // interfaces and that those endpoints match |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 250 | auto singleOwner = assocMaps.owners[DEFAULT_SOURCE_PATH]; |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 251 | auto singleIntf = singleOwner[DEFAULT_DBUS_SVC]; |
| 252 | for (auto i : singleIntf) |
| 253 | { |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 254 | auto intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[i.first]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 255 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 256 | EXPECT_EQ(intfEndpoints[0], *i.second.begin()); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | // Add a new association to same source path but with new owner |
| 261 | TEST_F(TestAssociations, associationChangedAddNewAssocNewOwner) |
| 262 | { |
| 263 | std::string newOwner = "xyz.openbmc_project.Test2"; |
| 264 | std::vector<Association> associations = { |
| 265 | {"inventory", "error", |
| 266 | "/xyz/openbmc_project/inventory/system/chassis"}}; |
| 267 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 268 | // Make it look like the assoc endpoints are on D-Bus |
| 269 | interface_map_type interfaceMap = createDefaultInterfaceMap(); |
| 270 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 271 | AssociationMaps assocMaps; |
| 272 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 273 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 274 | |
| 275 | associationChanged(*server, associations, DEFAULT_SOURCE_PATH, newOwner, |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 276 | interfaceMap, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 277 | |
| 278 | // New endpoint so assocOwners should be same size |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 279 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 280 | |
| 281 | // Ensure only one endpoint under first path |
| 282 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 283 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 284 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 285 | |
| 286 | // Ensure the 2 new association endpoints are under the new owner |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 287 | auto a = assocMaps.owners.find(DEFAULT_SOURCE_PATH); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 288 | auto o = a->second.find(newOwner); |
| 289 | EXPECT_EQ(o->second.size(), 2); |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 290 | |
| 291 | // Nothing pending |
| 292 | EXPECT_EQ(assocMaps.pending.size(), 0); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | // Add a new association to existing interface path |
| 296 | TEST_F(TestAssociations, associationChangedAddNewAssocSameInterface) |
| 297 | { |
| 298 | std::vector<Association> associations = { |
| 299 | {"abc", "error", "/xyz/openbmc_project/inventory/system/chassis"}}; |
| 300 | |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 301 | // Make it look like the assoc endpoints are on D-Bus |
| 302 | interface_map_type interfaceMap = createDefaultInterfaceMap(); |
| 303 | |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 304 | AssociationMaps assocMaps; |
| 305 | assocMaps.owners = createDefaultOwnerAssociation(); |
| 306 | assocMaps.ifaces = createDefaultInterfaceAssociation(server); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 307 | |
| 308 | associationChanged(*server, associations, DEFAULT_SOURCE_PATH, |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 309 | DEFAULT_DBUS_SVC, interfaceMap, assocMaps); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 310 | |
| 311 | // Should have 3 entries in AssociationInterfaces, one is just missing an |
| 312 | // endpoint |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 313 | EXPECT_EQ(assocMaps.ifaces.size(), 3); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 314 | |
| 315 | // Change to existing interface so it will be removed here |
| 316 | auto intfEndpoints = |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 317 | std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 318 | EXPECT_EQ(intfEndpoints.size(), 0); |
| 319 | |
| 320 | // The new endpoint should exist though in it's place |
| 321 | intfEndpoints = std::get<endpointsPos>( |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 322 | assocMaps.ifaces[DEFAULT_SOURCE_PATH + "/" + "abc"]); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 323 | EXPECT_EQ(intfEndpoints.size(), 1); |
| 324 | |
| 325 | // Added to an existing owner path so still 1 |
Matt Spinler | e2359fb | 2019-04-05 14:11:33 -0500 | [diff] [blame] | 326 | EXPECT_EQ(assocMaps.owners.size(), 1); |
Matt Spinler | e0b0e3a | 2019-04-08 10:39:23 -0500 | [diff] [blame] | 327 | |
| 328 | EXPECT_EQ(assocMaps.pending.size(), 0); |
Andrew Geissler | 491f9ac | 2019-02-22 15:23:33 -0600 | [diff] [blame] | 329 | } |
Matt Spinler | 9f1adbc | 2019-04-08 10:47:19 -0500 | [diff] [blame^] | 330 | |
| 331 | // Add 2 pending associations |
| 332 | TEST_F(TestAssociations, addPendingAssocs) |
| 333 | { |
| 334 | AssociationMaps assocMaps; |
| 335 | |
| 336 | addPendingAssociation(DEFAULT_SOURCE_PATH, "inventory", DEFAULT_ENDPOINT, |
| 337 | "error", DEFAULT_DBUS_SVC, assocMaps); |
| 338 | |
| 339 | EXPECT_TRUE(assocMaps.ifaces.empty()); |
| 340 | EXPECT_TRUE(assocMaps.owners.empty()); |
| 341 | |
| 342 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 343 | |
| 344 | addPendingAssociation("some/other/path", "inventory", DEFAULT_ENDPOINT, |
| 345 | "error", DEFAULT_DBUS_SVC, assocMaps); |
| 346 | |
| 347 | EXPECT_TRUE(assocMaps.ifaces.empty()); |
| 348 | EXPECT_TRUE(assocMaps.owners.empty()); |
| 349 | |
| 350 | EXPECT_EQ(assocMaps.pending.size(), 2); |
| 351 | } |
| 352 | |
| 353 | // Test adding a new endpoint to a pending association |
| 354 | TEST_F(TestAssociations, addPendingAssocsNewEndpoints) |
| 355 | { |
| 356 | AssociationMaps assocMaps; |
| 357 | |
| 358 | addPendingAssociation(DEFAULT_SOURCE_PATH, "inventory", DEFAULT_ENDPOINT, |
| 359 | "error", DEFAULT_DBUS_SVC, assocMaps); |
| 360 | |
| 361 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 362 | |
| 363 | addPendingAssociation(DEFAULT_SOURCE_PATH, "inventory", |
| 364 | "some/other/endpoint", "error", DEFAULT_DBUS_SVC, |
| 365 | assocMaps); |
| 366 | |
| 367 | // Same pending path, so still just 1 entry |
| 368 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 369 | |
| 370 | auto assoc = assocMaps.pending.find(DEFAULT_SOURCE_PATH); |
| 371 | EXPECT_NE(assoc, assocMaps.pending.end()); |
| 372 | |
| 373 | auto& endpoints = assoc->second; |
| 374 | EXPECT_EQ(endpoints.size(), 2); |
| 375 | } |
| 376 | |
| 377 | // Test adding a new owner to a pending association |
| 378 | TEST_F(TestAssociations, addPendingAssocsNewOwner) |
| 379 | { |
| 380 | AssociationMaps assocMaps; |
| 381 | |
| 382 | addPendingAssociation(DEFAULT_SOURCE_PATH, "inventory", DEFAULT_ENDPOINT, |
| 383 | "error", DEFAULT_DBUS_SVC, assocMaps); |
| 384 | |
| 385 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 386 | |
| 387 | addPendingAssociation(DEFAULT_SOURCE_PATH, "inventory", DEFAULT_ENDPOINT, |
| 388 | "error", "new owner", assocMaps); |
| 389 | |
| 390 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 391 | |
| 392 | auto assoc = assocMaps.pending.find(DEFAULT_SOURCE_PATH); |
| 393 | EXPECT_NE(assoc, assocMaps.pending.end()); |
| 394 | |
| 395 | auto& endpoints = assoc->second; |
| 396 | EXPECT_EQ(endpoints.size(), 2); |
| 397 | } |
| 398 | |
| 399 | // Add a pending association inside associationChanged |
| 400 | TEST_F(TestAssociations, associationChangedPending) |
| 401 | { |
| 402 | std::vector<Association> associations = { |
| 403 | {"abc", "def", "/xyz/openbmc_project/new/endpoint"}}; |
| 404 | |
| 405 | AssociationMaps assocMaps; |
| 406 | interface_map_type interfaceMap; |
| 407 | |
| 408 | associationChanged(*server, associations, "/new/source/path", |
| 409 | DEFAULT_DBUS_SVC, interfaceMap, assocMaps); |
| 410 | |
| 411 | // No associations were actually added |
| 412 | EXPECT_EQ(assocMaps.owners.size(), 0); |
| 413 | EXPECT_EQ(assocMaps.ifaces.size(), 0); |
| 414 | |
| 415 | // 1 pending association |
| 416 | EXPECT_EQ(assocMaps.pending.size(), 1); |
| 417 | } |