| Christopher Meis | fc9e7fd | 2025-04-03 13:13:35 +0200 | [diff] [blame] | 1 | #include "entity_manager/topology.hpp" | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 2 |  | 
|  | 3 | #include "gmock/gmock.h" | 
|  | 4 | #include "gtest/gtest.h" | 
|  | 5 |  | 
|  | 6 | using ::testing::UnorderedElementsAre; | 
|  | 7 |  | 
|  | 8 | const std::string subchassisPath = | 
|  | 9 | "/xyz/openbmc_project/inventory/system/chassis/Subchassis"; | 
|  | 10 | const std::string superchassisPath = | 
|  | 11 | "/xyz/openbmc_project/inventory/system/chassis/Superchassis"; | 
|  | 12 |  | 
|  | 13 | const Association subchassisAssoc = | 
|  | 14 | std::make_tuple("contained_by", "containing", superchassisPath); | 
| Patrick Williams | b707743 | 2024-08-16 15:22:21 -0400 | [diff] [blame] | 15 | const Association powerAssoc = | 
| Chau Ly | a454b30 | 2025-07-09 09:22:25 +0000 | [diff] [blame] | 16 | std::make_tuple("powering", "powered_by", superchassisPath); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 17 |  | 
|  | 18 | const nlohmann::json subchassisExposesItem = nlohmann::json::parse(R"( | 
|  | 19 | { | 
|  | 20 | "ConnectsToType": "BackplanePort", | 
|  | 21 | "Name": "MyDownstreamPort", | 
|  | 22 | "Type": "DownstreamPort" | 
|  | 23 | } | 
|  | 24 | )"); | 
|  | 25 |  | 
| Jeff Lin | b02752f | 2023-12-01 11:23:54 +0800 | [diff] [blame] | 26 | const nlohmann::json powerExposesItem = nlohmann::json::parse(R"( | 
|  | 27 | { | 
|  | 28 | "ConnectsToType": "BackplanePort", | 
|  | 29 | "Name": "MyDownstreamPort", | 
|  | 30 | "Type": "DownstreamPort", | 
|  | 31 | "PowerPort": true | 
|  | 32 | } | 
|  | 33 | )"); | 
|  | 34 |  | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 35 | const nlohmann::json superchassisExposesItem = nlohmann::json::parse(R"( | 
|  | 36 | { | 
|  | 37 | "Name": "MyBackplanePort", | 
|  | 38 | "Type": "BackplanePort" | 
|  | 39 | } | 
|  | 40 | )"); | 
|  | 41 |  | 
|  | 42 | const nlohmann::json otherExposesItem = nlohmann::json::parse(R"( | 
|  | 43 | { | 
|  | 44 | "Name": "MyExposes", | 
|  | 45 | "Type": "OtherType" | 
|  | 46 | } | 
|  | 47 | )"); | 
|  | 48 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 49 | using BoardMap = std::map<std::string, std::string>; | 
|  | 50 |  | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 51 | TEST(Topology, Empty) | 
|  | 52 | { | 
|  | 53 | Topology topo; | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 54 | BoardMap boards; | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 55 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 56 | auto assocs = topo.getAssocs(boards); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 57 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 58 | EXPECT_EQ(assocs.size(), 0U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 59 | } | 
|  | 60 |  | 
|  | 61 | TEST(Topology, EmptyExposes) | 
|  | 62 | { | 
|  | 63 | Topology topo; | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 64 | BoardMap boards{{subchassisPath, "BoardA"}, {superchassisPath, "BoardB"}}; | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 65 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 66 | topo.addBoard(subchassisPath, "Chassis", "BoardA", nlohmann::json()); | 
|  | 67 | topo.addBoard(superchassisPath, "Chassis", "BoardB", nlohmann::json()); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 68 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 69 | auto assocs = topo.getAssocs(boards); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 70 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 71 | EXPECT_EQ(assocs.size(), 0U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 72 | } | 
|  | 73 |  | 
|  | 74 | TEST(Topology, MissingConnectsTo) | 
|  | 75 | { | 
|  | 76 | const nlohmann::json subchassisMissingConnectsTo = nlohmann::json::parse(R"( | 
|  | 77 | { | 
|  | 78 | "Name": "MyDownstreamPort", | 
|  | 79 | "Type": "DownstreamPort" | 
|  | 80 | } | 
|  | 81 | )"); | 
|  | 82 |  | 
|  | 83 | Topology topo; | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 84 | BoardMap boards{{subchassisPath, "BoardA"}, {superchassisPath, "BoardB"}}; | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 85 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 86 | topo.addBoard(subchassisPath, "Chassis", "BoardA", | 
|  | 87 | subchassisMissingConnectsTo); | 
|  | 88 | topo.addBoard(superchassisPath, "Chassis", "BoardB", | 
|  | 89 | superchassisExposesItem); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 90 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 91 | auto assocs = topo.getAssocs(boards); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 92 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 93 | EXPECT_EQ(assocs.size(), 0U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 94 | } | 
|  | 95 |  | 
|  | 96 | TEST(Topology, OtherExposes) | 
|  | 97 | { | 
|  | 98 | Topology topo; | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 99 | BoardMap boards{{subchassisPath, "BoardA"}, {superchassisPath, "BoardB"}}; | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 100 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 101 | topo.addBoard(subchassisPath, "Chassis", "BoardA", otherExposesItem); | 
|  | 102 | topo.addBoard(superchassisPath, "Chassis", "BoardB", otherExposesItem); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 103 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 104 | auto assocs = topo.getAssocs(boards); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 105 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 106 | EXPECT_EQ(assocs.size(), 0U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 107 | } | 
|  | 108 |  | 
|  | 109 | TEST(Topology, NoMatchSubchassis) | 
|  | 110 | { | 
|  | 111 | Topology topo; | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 112 | BoardMap boards{{subchassisPath, "BoardA"}, {superchassisPath, "BoardB"}}; | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 113 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 114 | topo.addBoard(subchassisPath, "Chassis", "BoardA", otherExposesItem); | 
|  | 115 | topo.addBoard(superchassisPath, "Chassis", "BoardB", | 
|  | 116 | superchassisExposesItem); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 117 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 118 | auto assocs = topo.getAssocs(boards); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 119 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 120 | EXPECT_EQ(assocs.size(), 0U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 121 | } | 
|  | 122 |  | 
|  | 123 | TEST(Topology, NoMatchSuperchassis) | 
|  | 124 | { | 
|  | 125 | Topology topo; | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 126 | BoardMap boards{{subchassisPath, "BoardA"}, {superchassisPath, "BoardB"}}; | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 127 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 128 | topo.addBoard(subchassisPath, "Chassis", "BoardA", subchassisExposesItem); | 
|  | 129 | topo.addBoard(superchassisPath, "Chassis", "BoardB", otherExposesItem); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 130 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 131 | auto assocs = topo.getAssocs(boards); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 132 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 133 | EXPECT_EQ(assocs.size(), 0U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 134 | } | 
|  | 135 |  | 
|  | 136 | TEST(Topology, Basic) | 
|  | 137 | { | 
|  | 138 | Topology topo; | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 139 | BoardMap boards{{subchassisPath, "BoardA"}, {superchassisPath, "BoardB"}}; | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 140 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 141 | topo.addBoard(subchassisPath, "Chassis", "BoardA", subchassisExposesItem); | 
|  | 142 | topo.addBoard(superchassisPath, "Chassis", "BoardB", | 
|  | 143 | superchassisExposesItem); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 144 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 145 | auto assocs = topo.getAssocs(boards); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 146 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 147 | EXPECT_EQ(assocs.size(), 1U); | 
|  | 148 | EXPECT_EQ(assocs[subchassisPath].size(), 1U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 149 | EXPECT_EQ(assocs[subchassisPath][0], subchassisAssoc); | 
|  | 150 | } | 
|  | 151 |  | 
| Jeff Lin | b02752f | 2023-12-01 11:23:54 +0800 | [diff] [blame] | 152 | TEST(Topology, BasicPower) | 
|  | 153 | { | 
|  | 154 | Topology topo; | 
|  | 155 | BoardMap boards{{subchassisPath, "BoardA"}, {superchassisPath, "BoardB"}}; | 
|  | 156 |  | 
|  | 157 | topo.addBoard(subchassisPath, "Chassis", "BoardA", powerExposesItem); | 
|  | 158 | topo.addBoard(superchassisPath, "Chassis", "BoardB", | 
|  | 159 | superchassisExposesItem); | 
|  | 160 |  | 
|  | 161 | auto assocs = topo.getAssocs(boards); | 
|  | 162 |  | 
| Chau Ly | a454b30 | 2025-07-09 09:22:25 +0000 | [diff] [blame] | 163 | EXPECT_EQ(assocs.size(), 1U); | 
|  | 164 | EXPECT_EQ(assocs[subchassisPath].size(), 2U); | 
| Jeff Lin | b02752f | 2023-12-01 11:23:54 +0800 | [diff] [blame] | 165 | EXPECT_EQ(assocs[subchassisPath][0], subchassisAssoc); | 
| Chau Ly | a454b30 | 2025-07-09 09:22:25 +0000 | [diff] [blame] | 166 | EXPECT_EQ(assocs[subchassisPath][1], powerAssoc); | 
| Jeff Lin | b02752f | 2023-12-01 11:23:54 +0800 | [diff] [blame] | 167 | } | 
|  | 168 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 169 | TEST(Topology, NoNewBoards) | 
|  | 170 | { | 
|  | 171 | Topology topo; | 
|  | 172 | BoardMap boards; | 
|  | 173 |  | 
|  | 174 | topo.addBoard(subchassisPath, "Chassis", "BoardA", subchassisExposesItem); | 
|  | 175 | topo.addBoard(superchassisPath, "Chassis", "BoardB", | 
|  | 176 | superchassisExposesItem); | 
|  | 177 |  | 
|  | 178 | // Boards A and B aren't new, so no assocs are returned. | 
|  | 179 | auto assocs = topo.getAssocs(boards); | 
|  | 180 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 181 | EXPECT_EQ(assocs.size(), 0U); | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 182 | } | 
|  | 183 |  | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 184 | TEST(Topology, 2Subchassis) | 
|  | 185 | { | 
|  | 186 | Topology topo; | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 187 | BoardMap boards{{subchassisPath, "BoardA"}, | 
|  | 188 | {subchassisPath + "2", "BoardB"}, | 
|  | 189 | {superchassisPath, "BoardC"}}; | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 190 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 191 | topo.addBoard(subchassisPath, "Chassis", "BoardA", subchassisExposesItem); | 
|  | 192 | topo.addBoard(subchassisPath + "2", "Chassis", "BoardB", | 
|  | 193 | subchassisExposesItem); | 
|  | 194 | topo.addBoard(superchassisPath, "Chassis", "BoardC", | 
|  | 195 | superchassisExposesItem); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 196 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 197 | auto assocs = topo.getAssocs(boards); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 198 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 199 | EXPECT_EQ(assocs.size(), 2U); | 
|  | 200 | EXPECT_EQ(assocs[subchassisPath].size(), 1U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 201 | EXPECT_EQ(assocs[subchassisPath][0], subchassisAssoc); | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 202 | EXPECT_EQ(assocs[subchassisPath + "2"].size(), 1U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 203 | EXPECT_EQ(assocs[subchassisPath + "2"][0], subchassisAssoc); | 
|  | 204 | } | 
|  | 205 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 206 | TEST(Topology, OneNewBoard) | 
|  | 207 | { | 
|  | 208 | Topology topo; | 
|  | 209 | BoardMap boards{{subchassisPath, "BoardA"}}; | 
|  | 210 |  | 
|  | 211 | topo.addBoard(subchassisPath, "Chassis", "BoardA", subchassisExposesItem); | 
|  | 212 | topo.addBoard(subchassisPath + "2", "Chassis", "BoardB", | 
|  | 213 | subchassisExposesItem); | 
|  | 214 | topo.addBoard(superchassisPath, "Chassis", "BoardC", | 
|  | 215 | superchassisExposesItem); | 
|  | 216 |  | 
|  | 217 | // Only the assoc for BoardA should be returned | 
|  | 218 | auto assocs = topo.getAssocs(boards); | 
|  | 219 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 220 | EXPECT_EQ(assocs.size(), 1U); | 
|  | 221 | EXPECT_EQ(assocs[subchassisPath].size(), 1U); | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 222 | EXPECT_EQ(assocs[subchassisPath][0], subchassisAssoc); | 
|  | 223 | } | 
|  | 224 |  | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 225 | TEST(Topology, 2Superchassis) | 
|  | 226 | { | 
|  | 227 | const Association subchassisAssoc2 = | 
|  | 228 | std::make_tuple("contained_by", "containing", superchassisPath + "2"); | 
|  | 229 |  | 
|  | 230 | Topology topo; | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 231 | BoardMap boards{{subchassisPath, "BoardA"}, | 
|  | 232 | {superchassisPath, "BoardB"}, | 
|  | 233 | {superchassisPath + "2", "BoardC"}}; | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 234 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 235 | topo.addBoard(subchassisPath, "Chassis", "BoardA", subchassisExposesItem); | 
|  | 236 | topo.addBoard(superchassisPath, "Chassis", "BoardB", | 
|  | 237 | superchassisExposesItem); | 
|  | 238 | topo.addBoard(superchassisPath + "2", "Chassis", "BoardC", | 
|  | 239 | superchassisExposesItem); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 240 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 241 | auto assocs = topo.getAssocs(boards); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 242 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 243 | EXPECT_EQ(assocs.size(), 1U); | 
|  | 244 | EXPECT_EQ(assocs[subchassisPath].size(), 2U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 245 |  | 
|  | 246 | EXPECT_THAT(assocs[subchassisPath], | 
|  | 247 | UnorderedElementsAre(subchassisAssoc, subchassisAssoc2)); | 
|  | 248 | } | 
|  | 249 |  | 
|  | 250 | TEST(Topology, 2SuperchassisAnd2Subchassis) | 
|  | 251 | { | 
|  | 252 | const Association subchassisAssoc2 = | 
|  | 253 | std::make_tuple("contained_by", "containing", superchassisPath + "2"); | 
|  | 254 |  | 
|  | 255 | Topology topo; | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 256 | BoardMap boards{{subchassisPath, "BoardA"}, | 
|  | 257 | {subchassisPath + "2", "BoardB"}, | 
|  | 258 | {superchassisPath, "BoardC"}, | 
|  | 259 | {superchassisPath + "2", "BoardD"}}; | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 260 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 261 | topo.addBoard(subchassisPath, "Chassis", "BoardA", subchassisExposesItem); | 
|  | 262 | topo.addBoard(subchassisPath + "2", "Chassis", "BoardB", | 
|  | 263 | subchassisExposesItem); | 
|  | 264 | topo.addBoard(superchassisPath, "Chassis", "BoardC", | 
|  | 265 | superchassisExposesItem); | 
|  | 266 | topo.addBoard(superchassisPath + "2", "Chassis", "BoardD", | 
|  | 267 | superchassisExposesItem); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 268 |  | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 269 | auto assocs = topo.getAssocs(boards); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 270 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 271 | EXPECT_EQ(assocs.size(), 2U); | 
|  | 272 | EXPECT_EQ(assocs[subchassisPath].size(), 2U); | 
|  | 273 | EXPECT_EQ(assocs[subchassisPath + "2"].size(), 2U); | 
| Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 274 |  | 
|  | 275 | EXPECT_THAT(assocs[subchassisPath], | 
|  | 276 | UnorderedElementsAre(subchassisAssoc, subchassisAssoc2)); | 
|  | 277 | EXPECT_THAT(assocs[subchassisPath + "2"], | 
|  | 278 | UnorderedElementsAre(subchassisAssoc, subchassisAssoc2)); | 
|  | 279 | } | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 280 |  | 
|  | 281 | TEST(Topology, Remove) | 
|  | 282 | { | 
|  | 283 | Topology topo; | 
|  | 284 | BoardMap boards{{subchassisPath, "BoardA"}, | 
|  | 285 | {subchassisPath + "2", "BoardB"}, | 
|  | 286 | {superchassisPath, "BoardC"}}; | 
|  | 287 |  | 
|  | 288 | topo.addBoard(subchassisPath, "Chassis", "BoardA", subchassisExposesItem); | 
|  | 289 | topo.addBoard(subchassisPath + "2", "Chassis", "BoardB", | 
|  | 290 | subchassisExposesItem); | 
|  | 291 | topo.addBoard(superchassisPath, "Chassis", "BoardC", | 
|  | 292 | superchassisExposesItem); | 
|  | 293 |  | 
|  | 294 | { | 
|  | 295 | auto assocs = topo.getAssocs(boards); | 
|  | 296 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 297 | EXPECT_EQ(assocs.size(), 2U); | 
|  | 298 | EXPECT_EQ(assocs[subchassisPath].size(), 1U); | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 299 | EXPECT_EQ(assocs[subchassisPath][0], subchassisAssoc); | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 300 | EXPECT_EQ(assocs[subchassisPath + "2"].size(), 1U); | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 301 | EXPECT_EQ(assocs[subchassisPath + "2"][0], subchassisAssoc); | 
|  | 302 | } | 
|  | 303 |  | 
|  | 304 | { | 
|  | 305 | topo.remove("BoardA"); | 
|  | 306 | auto assocs = topo.getAssocs(boards); | 
|  | 307 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 308 | EXPECT_EQ(assocs.size(), 1U); | 
|  | 309 | EXPECT_EQ(assocs[subchassisPath + "2"].size(), 1U); | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 310 | EXPECT_EQ(assocs[subchassisPath + "2"][0], subchassisAssoc); | 
|  | 311 | } | 
|  | 312 |  | 
|  | 313 | { | 
|  | 314 | topo.remove("BoardB"); | 
|  | 315 | auto assocs = topo.getAssocs(boards); | 
|  | 316 |  | 
| Ed Tanous | c6af85c | 2025-04-08 10:13:33 -0700 | [diff] [blame] | 317 | EXPECT_EQ(assocs.size(), 0U); | 
| Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 318 | } | 
|  | 319 | } |