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