blob: 18a4341d0bf5e4bb8fb47716c0f865fd2d735eee [file] [log] [blame]
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301#include "led-test-map.hpp"
Patrick Venture91ac8d32018-11-01 17:03:22 -07002#include "manager.hpp"
3
4#include <algorithm>
5#include <sdbusplus/bus.hpp>
6#include <set>
7
8#include <gtest/gtest.h>
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05309using namespace phosphor::led;
10class LedTest : public ::testing::Test
11{
Patrick Venture91ac8d32018-11-01 17:03:22 -070012 public:
13 sdbusplus::bus::bus bus;
14 LedTest() : bus(sdbusplus::bus::new_default())
15 {
16 // Nothing here
17 }
18 ~LedTest()
19 {
20 // Leaving up to auto cleanup.
21 }
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053022};
23
24/** @brief Assert Single LED to On */
25TEST_F(LedTest, assertSingleLedOn)
26{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053027 Manager manager(bus, singleLedOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053028 {
29 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -070030 Manager::group ledsAssert{};
31 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053032
33 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -070034 auto result =
35 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053036 EXPECT_EQ(true, result);
37
38 // Need just the ledsAssserted populated with these.
39 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -070040 {"One", phosphor::led::Layout::On, 0, 0,
41 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053042 };
43 EXPECT_EQ(refAssert.size(), ledsAssert.size());
44 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053045
46 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -070047 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053048 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
49 refAssert.begin(), refAssert.end(),
50 std::inserter(temp, temp.begin()));
51 EXPECT_EQ(0, temp.size());
52 }
53}
54
55/** @brief Assert Single LED to Blink */
56TEST_F(LedTest, assertSingleLedBlink)
57{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053058 Manager manager(bus, singleLedBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053059 {
60 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -070061 Manager::group ledsAssert{};
62 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053063
64 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -070065 auto result =
66 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053067 EXPECT_EQ(true, result);
68
69 // Need just the ledsAssserted populated with these.
70 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -070071 {"One", phosphor::led::Layout::Blink, 0, 0,
72 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053073 };
74 EXPECT_EQ(refAssert.size(), ledsAssert.size());
75 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053076
77 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -070078 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053079 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
80 refAssert.begin(), refAssert.end(),
81 std::inserter(temp, temp.begin()));
82 EXPECT_EQ(0, temp.size());
83 }
84}
85
86/** @brief Assert Single LED to On and Try Assert Again */
87TEST_F(LedTest, assertSingleLedOnAndreAssert)
88{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053089 Manager manager(bus, singleLedOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053090 {
91 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -070092 Manager::group ledsAssert{};
93 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053094
95 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -070096 auto result =
97 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053098 EXPECT_EQ(true, result);
99
100 // Need just the ledsAssserted populated with these.
101 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700102 {"One", phosphor::led::Layout::On, 0, 0,
103 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530104 };
105 EXPECT_EQ(refAssert.size(), ledsAssert.size());
106 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530107
108 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700109 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530110 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
111 refAssert.begin(), refAssert.end(),
112 std::inserter(temp, temp.begin()));
113 EXPECT_EQ(0, temp.size());
114 }
115 {
116 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700117 Manager::group ledsAssert{};
118 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530119
120 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700121 auto result =
122 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530123 EXPECT_EQ(true, result);
124
125 EXPECT_EQ(0, ledsAssert.size());
126 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530127 }
128}
129
130/** @brief Assert Multiple LEDs to On */
131TEST_F(LedTest, assertMultipleLedOn)
132{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530133 Manager manager(bus, multipleLedsOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530134 {
135 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700136 Manager::group ledsAssert{};
137 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530138
139 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700140 auto result =
141 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530142 EXPECT_EQ(true, result);
143
144 // Need just the ledsAssserted populated with these.
145 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700146 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
147 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
148 {"Three", phosphor::led::Layout::On, 0, 0,
149 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530150 };
151 EXPECT_EQ(refAssert.size(), ledsAssert.size());
152 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530153
154 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700155 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530156 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
157 refAssert.begin(), refAssert.end(),
158 std::inserter(temp, temp.begin()));
159 EXPECT_EQ(0, temp.size());
160 }
161}
162
163/** @brief Assert Multiple LEDs to Blink */
164TEST_F(LedTest, assertMultipleLedBlink)
165{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530166 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530167 {
168 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700169 Manager::group ledsAssert{};
170 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530171
172 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700173 auto result =
174 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530175 EXPECT_EQ(true, result);
176
177 // Need just the ledsAssserted populated with these.
178 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700179 {"One", phosphor::led::Layout::Blink, 0, 0,
180 phosphor::led::Layout::Blink},
181 {"Two", phosphor::led::Layout::Blink, 0, 0,
182 phosphor::led::Layout::Blink},
183 {"Three", phosphor::led::Layout::Blink, 0, 0,
184 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530185 };
186 EXPECT_EQ(refAssert.size(), ledsAssert.size());
187 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530188
189 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700190 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530191 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
192 refAssert.begin(), refAssert.end(),
193 std::inserter(temp, temp.begin()));
194 EXPECT_EQ(0, temp.size());
195 }
196}
197
198/** @brief Assert Multiple LEDs to Blink, DeAssert */
199TEST_F(LedTest, assertMultipleLedBlinkAndDeAssert)
200{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530201 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530202 {
203 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700204 Manager::group ledsAssert{};
205 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530206
207 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700208 auto result =
209 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530210 EXPECT_EQ(true, result);
211
212 // Need just the ledsAssserted populated with these.
213 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700214 {"One", phosphor::led::Layout::Blink, 0, 0,
215 phosphor::led::Layout::Blink},
216 {"Two", phosphor::led::Layout::Blink, 0, 0,
217 phosphor::led::Layout::Blink},
218 {"Three", phosphor::led::Layout::Blink, 0, 0,
219 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530220 };
221 EXPECT_EQ(refAssert.size(), ledsAssert.size());
222 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530223
224 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700225 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530226 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
227 refAssert.begin(), refAssert.end(),
228 std::inserter(temp, temp.begin()));
229 EXPECT_EQ(0, temp.size());
230 }
231 {
232 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700233 Manager::group ledsAssert{};
234 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530235
236 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700237 auto result =
238 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530239 EXPECT_EQ(false, result);
240
241 // Need just the ledsAssserted populated with these.
242 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700243 {"One", phosphor::led::Layout::Blink, 0, 0,
244 phosphor::led::Layout::Blink},
245 {"Two", phosphor::led::Layout::Blink, 0, 0,
246 phosphor::led::Layout::Blink},
247 {"Three", phosphor::led::Layout::Blink, 0, 0,
248 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530249 };
250 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
251 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530252
253 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700254 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530255 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
256 refDeAssert.begin(), refDeAssert.end(),
257 std::inserter(temp, temp.begin()));
258 EXPECT_EQ(0, temp.size());
259 }
260}
261
262/** @brief Assert Multiple LEDs to Blink, DeAssert Twice */
263TEST_F(LedTest, assertMultipleLedBlinkAndDeAssertTwice)
264{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530265 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530266 {
267 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700268 Manager::group ledsAssert{};
269 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530270
271 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700272 auto result =
273 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530274 EXPECT_EQ(true, result);
275
276 // Need just the ledsAssserted populated with these.
277 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700278 {"One", phosphor::led::Layout::Blink, 0, 0,
279 phosphor::led::Layout::Blink},
280 {"Two", phosphor::led::Layout::Blink, 0, 0,
281 phosphor::led::Layout::Blink},
282 {"Three", phosphor::led::Layout::Blink, 0, 0,
283 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530284 };
285 EXPECT_EQ(refAssert.size(), ledsAssert.size());
286 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530287
288 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700289 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530290 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
291 refAssert.begin(), refAssert.end(),
292 std::inserter(temp, temp.begin()));
293 EXPECT_EQ(0, temp.size());
294 }
295 {
296 // DeAssert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700297 Manager::group ledsAssert{};
298 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530299
300 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700301 auto result =
302 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530303 EXPECT_EQ(false, result);
304
305 // Need just the ledsAssserted populated with these.
306 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700307 {"One", phosphor::led::Layout::Blink, 0, 0,
308 phosphor::led::Layout::Blink},
309 {"Two", phosphor::led::Layout::Blink, 0, 0,
310 phosphor::led::Layout::Blink},
311 {"Three", phosphor::led::Layout::Blink, 0, 0,
312 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530313 };
314 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
315 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530316
317 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700318 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530319 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
320 refDeAssert.begin(), refDeAssert.end(),
321 std::inserter(temp, temp.begin()));
322 EXPECT_EQ(0, temp.size());
323 }
324 {
325 // DeAssert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700326 Manager::group ledsAssert{};
327 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530328
329 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700330 auto result =
331 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530332 EXPECT_EQ(false, result);
333 EXPECT_EQ(0, ledsDeAssert.size());
334 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530335 }
336}
337
338/** @brief Assert Multiple LEDs to mix of On and Blink */
339TEST_F(LedTest, assertMultipleLedOnAndBlink)
340{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530341 Manager manager(bus, multipleLedsOnAndBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530342 {
343 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700344 Manager::group ledsAssert{};
345 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530346
347 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsMix";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700348 auto result =
349 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530350 EXPECT_EQ(true, result);
351
352 // Need just the ledsAssserted populated with these.
353 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700354 {"One", phosphor::led::Layout::Blink, 0, 0,
355 phosphor::led::Layout::Blink},
356 {"Two", phosphor::led::Layout::On, 0, phosphor::led::Layout::Blink},
357 {"Three", phosphor::led::Layout::Blink, 0,
358 phosphor::led::Layout::On},
359 {"Four", phosphor::led::Layout::On, 0,
360 phosphor::led::Layout::Blink},
361 {"Five", phosphor::led::Layout::On, 0,
362 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530363 };
364 EXPECT_EQ(refAssert.size(), ledsAssert.size());
365 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530366
367 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700368 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530369 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
370 refAssert.begin(), refAssert.end(),
371 std::inserter(temp, temp.begin()));
372 EXPECT_EQ(0, temp.size());
373 }
374}
375
376/** @brief Assert 2 groups having distinct LEDs */
377TEST_F(LedTest, assertTwoGroupsOnWithDistinctLEDOn)
378{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530379 Manager manager(bus, twoGroupsWithDistinctLEDsOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530380 {
381 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700382 Manager::group ledsAssert{};
383 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530384
Patrick Venture91ac8d32018-11-01 17:03:22 -0700385 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
386 auto result =
387 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530388 EXPECT_EQ(true, result);
389
390 // Need just the ledsAssserted populated with these.
391 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700392 {"One", phosphor::led::Layout::On, 0, 0,
393 phosphor::led::Layout::Blink},
394 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
395 {"Three", phosphor::led::Layout::On, 0, 0,
396 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530397 };
398 EXPECT_EQ(refAssert.size(), ledsAssert.size());
399 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530400
401 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700402 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530403 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
404 refAssert.begin(), refAssert.end(),
405 std::inserter(temp, temp.begin()));
406 EXPECT_EQ(0, temp.size());
407 }
408 {
409 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700410 Manager::group ledsAssert{};
411 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530412
Patrick Venture91ac8d32018-11-01 17:03:22 -0700413 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
414 auto result =
415 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530416 EXPECT_EQ(true, result);
417
418 // Need just the ledsAssserted populated with these.
419 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700420 {"Four", phosphor::led::Layout::On, 0, 0,
421 phosphor::led::Layout::Blink},
422 {"Five", phosphor::led::Layout::On, 0, 0,
423 phosphor::led::Layout::Blink},
424 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530425 };
426 EXPECT_EQ(refAssert.size(), ledsAssert.size());
427 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530428
429 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700430 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530431 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
432 refAssert.begin(), refAssert.end(),
433 std::inserter(temp, temp.begin()));
434 EXPECT_EQ(0, temp.size());
435 }
436}
437
438/** @brief Assert 2 groups having one of the LEDs common */
439TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOn)
440{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530441 Manager manager(bus, twoGroupsWithOneComonLEDOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530442 {
443 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700444 Manager::group ledsAssert{};
445 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530446
Patrick Venture91ac8d32018-11-01 17:03:22 -0700447 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
448 auto result =
449 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530450 EXPECT_EQ(true, result);
451
452 // Need just the ledsAssserted populated with these.
453 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700454 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
455 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
456 {"Three", phosphor::led::Layout::On, 0, 0,
457 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530458 };
459 EXPECT_EQ(refAssert.size(), ledsAssert.size());
460 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530461
462 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700463 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530464 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
465 refAssert.begin(), refAssert.end(),
466 std::inserter(temp, temp.begin()));
467 EXPECT_EQ(0, temp.size());
468 }
469 {
470 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700471 Manager::group ledsAssert{};
472 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530473
Patrick Venture91ac8d32018-11-01 17:03:22 -0700474 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
475 auto result =
476 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530477 EXPECT_EQ(true, result);
478
479 // Need just the ledsAssserted populated with these.
480 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700481 {"Four", phosphor::led::Layout::On, 0, 0,
482 phosphor::led::Layout::On},
483 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530484 };
485 EXPECT_EQ(refAssert.size(), ledsAssert.size());
486 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530487
488 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700489 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530490 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
491 refAssert.begin(), refAssert.end(),
492 std::inserter(temp, temp.begin()));
493 EXPECT_EQ(0, temp.size());
494 }
495}
496
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530497/** @brief Assert 2 groups having one of the LEDs common but having Blink as
498 * priority and Deassert*/
499TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDBlinkPriorityAndDeAssertB)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530500{
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530501 Manager manager(bus, twoGroupsWithOneComonLEDOnOneLEDBlinkPriority);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530502 {
503 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700504 Manager::group ledsAssert{};
505 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530506
Patrick Venture91ac8d32018-11-01 17:03:22 -0700507 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
508 auto result =
509 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530510 EXPECT_EQ(true, result);
511
512 // Need just the ledsAssserted populated with these.
513 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700514 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
515 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
516 {"Three", phosphor::led::Layout::Blink, 0, 0,
517 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530518 };
519 EXPECT_EQ(refAssert.size(), ledsAssert.size());
520 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530521
522 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700523 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530524 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
525 refAssert.begin(), refAssert.end(),
526 std::inserter(temp, temp.begin()));
527 EXPECT_EQ(0, temp.size());
528 }
529 {
530 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700531 Manager::group ledsAssert{};
532 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530533
Patrick Venture91ac8d32018-11-01 17:03:22 -0700534 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
535 auto result =
536 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530537 EXPECT_EQ(true, result);
538
539 // Need just the ledsAssserted populated with these.
540 // Does not action on [Three] since priority is [Blink]
541 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700542 {"Four", phosphor::led::Layout::On, 0, 0,
543 phosphor::led::Layout::On},
544 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530545 };
546 EXPECT_EQ(refAssert.size(), ledsAssert.size());
547 EXPECT_EQ(0, ledsDeAssert.size());
548
549 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700550 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530551 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
552 refAssert.begin(), refAssert.end(),
553 std::inserter(temp, temp.begin()));
554 EXPECT_EQ(0, temp.size());
555 }
556 {
557 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700558 Manager::group ledsAssert{};
559 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530560
Patrick Venture91ac8d32018-11-01 17:03:22 -0700561 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
562 auto result =
563 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530564 EXPECT_EQ(false, result);
565
566 // Need just the ledsDeAssserted populated with these.
567 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700568 {"Four", phosphor::led::Layout::On, 0, 0,
569 phosphor::led::Layout::On},
570 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530571 };
572 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
573 EXPECT_EQ(0, ledsAssert.size());
574
575 // difference of refDeAssert and ledsDeAssert must be null.
576 // [Three] is not touched since its already [Blink]
Patrick Venture91ac8d32018-11-01 17:03:22 -0700577 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530578 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
579 refDeAssert.begin(), refDeAssert.end(),
580 std::inserter(temp, temp.begin()));
581 EXPECT_EQ(0, temp.size());
582 }
583}
584
585/** @brief Assert 2 groups having one of the LEDs common but having Blink as
586 * priority and Deassert A */
587TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDBlinkPriorityAndDeAssertA)
588{
589 Manager manager(bus, twoGroupsWithOneComonLEDOnOneLEDBlinkPriority);
590 {
591 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700592 Manager::group ledsAssert{};
593 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530594
Patrick Venture91ac8d32018-11-01 17:03:22 -0700595 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
596 auto result =
597 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530598 EXPECT_EQ(true, result);
599
600 // Need just the ledsAssserted populated with these.
601 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700602 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
603 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
604 {"Three", phosphor::led::Layout::Blink, 0, 0,
605 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530606 };
607 EXPECT_EQ(refAssert.size(), ledsAssert.size());
608 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530609
610 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700611 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530612 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
613 refAssert.begin(), refAssert.end(),
614 std::inserter(temp, temp.begin()));
615 EXPECT_EQ(0, temp.size());
616 }
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530617 {
618 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700619 Manager::group ledsAssert{};
620 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530621
Patrick Venture91ac8d32018-11-01 17:03:22 -0700622 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
623 auto result =
624 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530625 EXPECT_EQ(true, result);
626
627 // Need just the ledsAssserted populated with these.
628 // [Three] does not get actioned since it has Blink priority
629 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700630 {"Four", phosphor::led::Layout::On, 0, 0,
631 phosphor::led::Layout::On},
632 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530633 };
634 EXPECT_EQ(refAssert.size(), ledsAssert.size());
635 EXPECT_EQ(0, ledsDeAssert.size());
636
637 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700638 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530639 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
640 refAssert.begin(), refAssert.end(),
641 std::inserter(temp, temp.begin()));
642 EXPECT_EQ(0, temp.size());
643 }
644 {
645 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700646 Manager::group ledsAssert{};
647 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530648
Patrick Venture91ac8d32018-11-01 17:03:22 -0700649 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
650 auto result =
651 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530652 EXPECT_EQ(false, result);
653
654 // Need just the ledsDeAssserted populated with these.
655 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700656 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
657 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530658 };
659 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
660
661 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700662 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530663 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
664 refDeAssert.begin(), refDeAssert.end(),
665 std::inserter(temp, temp.begin()));
666 EXPECT_EQ(0, temp.size());
667
668 // Need just the ledsAssert populated with these.
669 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700670 {"Three", phosphor::led::Layout::On, 0, 0,
671 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530672 };
673 EXPECT_EQ(refAssert.size(), ledsAssert.size());
674
675 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700676 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530677 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
678 refAssert.begin(), refAssert.end(),
679 std::inserter(temp1, temp1.begin()));
680 EXPECT_EQ(0, temp1.size());
681 }
682}
683
684/** @brief Assert 2 groups having one of the LEDs common but having ON as
685 * priority And Deassert A */
686TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDOnPriorityAndDeAssertA)
687{
688 Manager manager(bus, twoGroupsWithOneComonLEDOnPriority);
689 {
690 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700691 Manager::group ledsAssert{};
692 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530693
Patrick Venture91ac8d32018-11-01 17:03:22 -0700694 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
695 auto result =
696 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530697 EXPECT_EQ(true, result);
698
699 // Need just the ledsAssserted populated with these.
700 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700701 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
702 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
703 {"Three", phosphor::led::Layout::Blink, 0, 0,
704 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530705 };
706 EXPECT_EQ(refAssert.size(), ledsAssert.size());
707 EXPECT_EQ(0, ledsDeAssert.size());
708
709 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700710 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530711 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
712 refAssert.begin(), refAssert.end(),
713 std::inserter(temp, temp.begin()));
714 EXPECT_EQ(0, temp.size());
715 }
716 {
717 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700718 Manager::group ledsAssert{};
719 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530720
Patrick Venture91ac8d32018-11-01 17:03:22 -0700721 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
722 auto result =
723 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530724 EXPECT_EQ(true, result);
725
726 // Need just the ledsAssserted populated with these.
727 // Three is set to ON due to ON priority.
728 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700729 {"Three", phosphor::led::Layout::On, 0, 0,
730 phosphor::led::Layout::On},
731 {"Four", phosphor::led::Layout::On, 0, 0,
732 phosphor::led::Layout::On},
733 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530734 };
735 EXPECT_EQ(refAssert.size(), ledsAssert.size());
736 EXPECT_EQ(0, ledsDeAssert.size());
737
738 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700739 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530740 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
741 refAssert.begin(), refAssert.end(),
742 std::inserter(temp, temp.begin()));
743 }
744 {
745 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700746 Manager::group ledsAssert{};
747 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530748
Patrick Venture91ac8d32018-11-01 17:03:22 -0700749 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
750 auto result =
751 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530752 EXPECT_EQ(false, result);
753
754 // Need just the ledsDeAssserted populated with these.
755 // [Three] stays in [On] since [B] has it [On]
756 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700757 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
758 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530759 };
760 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
761 EXPECT_EQ(0, ledsAssert.size());
762
763 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700764 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530765 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
766 refDeAssert.begin(), refDeAssert.end(),
767 std::inserter(temp, temp.begin()));
768 EXPECT_EQ(0, temp.size());
769 }
770}
771
772/** @brief Assert 2 groups having one of the LEDs common but having ON as
773 * priority And Deassert B */
774TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDOnPriorityAndDeAssertB)
775{
776 Manager manager(bus, twoGroupsWithOneComonLEDOnPriority);
777 {
778 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700779 Manager::group ledsAssert{};
780 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530781
Patrick Venture91ac8d32018-11-01 17:03:22 -0700782 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
783 auto result =
784 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530785 EXPECT_EQ(true, result);
786
787 // Need just the ledsAssserted populated with these.
788 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700789 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
790 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
791 {"Three", phosphor::led::Layout::Blink, 0, 0,
792 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530793 };
794 EXPECT_EQ(refAssert.size(), ledsAssert.size());
795 EXPECT_EQ(0, ledsDeAssert.size());
796
797 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700798 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530799 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
800 refAssert.begin(), refAssert.end(),
801 std::inserter(temp, temp.begin()));
802 EXPECT_EQ(0, temp.size());
803 }
804 {
805 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700806 Manager::group ledsAssert{};
807 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530808
Patrick Venture91ac8d32018-11-01 17:03:22 -0700809 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
810 auto result =
811 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530812 EXPECT_EQ(true, result);
813
814 // Need just the ledsAssserted populated with these.
815 // Three is set to ON due to ON priority.
816 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700817 {"Three", phosphor::led::Layout::On, 0, 0,
818 phosphor::led::Layout::On},
819 {"Four", phosphor::led::Layout::On, 0, 0,
820 phosphor::led::Layout::On},
821 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530822 };
823 EXPECT_EQ(refAssert.size(), ledsAssert.size());
824 EXPECT_EQ(0, ledsDeAssert.size());
825
826 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700827 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530828 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
829 refAssert.begin(), refAssert.end(),
830 std::inserter(temp, temp.begin()));
831 }
832 {
833 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700834 Manager::group ledsAssert{};
835 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530836
Patrick Venture91ac8d32018-11-01 17:03:22 -0700837 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
838 auto result =
839 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530840 EXPECT_EQ(false, result);
841
842 // Need just the ledsDeAssserted populated with these.
843 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700844 {"Four", phosphor::led::Layout::On, 0, 0,
845 phosphor::led::Layout::On},
846 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530847 };
848 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
849
850 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700851 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530852 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
853 refDeAssert.begin(), refDeAssert.end(),
854 std::inserter(temp, temp.begin()));
855 EXPECT_EQ(0, temp.size());
856
857 // Need just the ledsAssert populated with these.
858 // Since [Three] stood [On], need to go back to [Blink]
859 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700860 {"Three", phosphor::led::Layout::Blink, 0, 0,
861 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530862 };
863 EXPECT_EQ(refAssert.size(), ledsAssert.size());
864
865 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700866 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530867 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
868 refAssert.begin(), refAssert.end(),
869 std::inserter(temp, temp.begin()));
870 EXPECT_EQ(0, temp.size());
871 }
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530872}
873
874/** @brief Assert 2 groups having multiple common LEDs in Same State */
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530875TEST_F(LedTest, assertTwoGroupsWithMultiplComonLEDOnAndDeAssert)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530876{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530877 Manager manager(bus, twoGroupsWithMultiplComonLEDOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530878 {
879 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700880 Manager::group ledsAssert{};
881 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530882
Patrick Venture91ac8d32018-11-01 17:03:22 -0700883 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
884 auto result =
885 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530886 EXPECT_EQ(true, result);
887
888 // Need just the ledsAssserted populated with these.
889 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700890 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
891 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
892 {"Three", phosphor::led::Layout::On, 0, 0,
893 phosphor::led::Layout::On},
894 {"Seven", phosphor::led::Layout::On, 0, 0,
895 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530896 };
897 EXPECT_EQ(refAssert.size(), ledsAssert.size());
898 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530899
900 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700901 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530902 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
903 refAssert.begin(), refAssert.end(),
904 std::inserter(temp, temp.begin()));
905 EXPECT_EQ(0, temp.size());
906 }
907 {
908 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700909 Manager::group ledsAssert{};
910 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530911
Patrick Venture91ac8d32018-11-01 17:03:22 -0700912 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
913 auto result =
914 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530915 EXPECT_EQ(true, result);
916
917 // Need just the ledsAssserted populated with these.
918 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700919 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530920 };
921 EXPECT_EQ(refAssert.size(), ledsAssert.size());
922 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530923
924 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700925 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530926 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
927 refAssert.begin(), refAssert.end(),
928 std::inserter(temp, temp.begin()));
929 EXPECT_EQ(0, temp.size());
930 }
931 {
932 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700933 Manager::group ledsAssert{};
934 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530935
Patrick Venture91ac8d32018-11-01 17:03:22 -0700936 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
937 auto result =
938 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530939 EXPECT_EQ(false, result);
940
941 // Need just the ledsDeAssserted populated with these.
942 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700943 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
944 {"Seven", phosphor::led::Layout::On, 0, 0,
945 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530946 };
947 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
948 EXPECT_EQ(0, ledsAssert.size());
949
950 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700951 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530952 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
953 refDeAssert.begin(), refDeAssert.end(),
954 std::inserter(temp, temp.begin()));
955 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530956 }
957}
958
959/** @brief Assert 2 groups having multiple LEDs common in different state */
960TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateBandA)
961{
962 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
963 {
964 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700965 Manager::group ledsAssert{};
966 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530967
Patrick Venture91ac8d32018-11-01 17:03:22 -0700968 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
969 auto result =
970 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530971 EXPECT_EQ(true, result);
972
973 // Need just the ledsAssserted populated with these.
974 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700975 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
976 {"Three", phosphor::led::Layout::Blink, 0, 0,
977 phosphor::led::Layout::On},
978 {"Five", phosphor::led::Layout::On, 0, 0,
979 phosphor::led::Layout::On},
980 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530981 };
982 EXPECT_EQ(refAssert.size(), ledsAssert.size());
983 EXPECT_EQ(0, ledsDeAssert.size());
984
985 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700986 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530987 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
988 refAssert.begin(), refAssert.end(),
989 std::inserter(temp, temp.begin()));
990 EXPECT_EQ(0, temp.size());
991 }
992 {
993 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700994 Manager::group ledsAssert{};
995 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530996
Patrick Venture91ac8d32018-11-01 17:03:22 -0700997 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
998 auto result =
999 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301000 EXPECT_EQ(true, result);
1001
1002 // Need just the ledsAssserted populated with these
1003 // [Two] remains [On] due to higher priority.
1004 // [Three] remains [Blink]
1005 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001006 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1007 {"Four", phosphor::led::Layout::On, 0, 0,
1008 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301009 };
1010 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1011 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301012
1013 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001014 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301015 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1016 refAssert.begin(), refAssert.end(),
1017 std::inserter(temp, temp.begin()));
1018 EXPECT_EQ(0, temp.size());
1019 }
1020}
1021
1022/** @brief Assert 2 groups having multiple LEDs common in different state */
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301023TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateAtoB)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301024{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +05301025 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301026 {
1027 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001028 Manager::group ledsAssert{};
1029 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301030
Patrick Venture91ac8d32018-11-01 17:03:22 -07001031 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1032 auto result =
1033 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301034 EXPECT_EQ(true, result);
1035
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301036 // Need just the ledsAssserted populated with these.'Two' gets to Blink
1037 // due to higher priority.
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301038 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001039 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1040 {"Two", phosphor::led::Layout::Blink, 0, 0,
1041 phosphor::led::Layout::On},
1042 {"Three", phosphor::led::Layout::Blink, 0, 0,
1043 phosphor::led::Layout::On},
1044 {"Four", phosphor::led::Layout::On, 0, 0,
1045 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301046 };
1047 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1048 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301049
1050 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001051 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301052 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1053 refAssert.begin(), refAssert.end(),
1054 std::inserter(temp, temp.begin()));
1055 EXPECT_EQ(0, temp.size());
1056 }
1057 {
1058 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001059 Manager::group ledsAssert{};
1060 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301061
Patrick Venture91ac8d32018-11-01 17:03:22 -07001062 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1063 auto result =
1064 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301065 EXPECT_EQ(true, result);
1066
1067 // Need just the ledsAssserted populated with these.
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301068 // [Three] remains [Blink] from previous
1069 // [Two] moves to [On] from [Blink] due to [On] priority
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301070 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001071 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1072 {"Five", phosphor::led::Layout::On, 0, 0,
1073 phosphor::led::Layout::On},
1074 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301075 };
1076 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1077 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301078
1079 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001080 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301081 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1082 refAssert.begin(), refAssert.end(),
1083 std::inserter(temp, temp.begin()));
1084 EXPECT_EQ(0, temp.size());
1085 }
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301086}
1087
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301088/** @brief Assert 2 groups having multiple LEDs common in different state
1089 * DeAssert twice
1090 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001091TEST_F(LedTest,
1092 assertTwoGroupsWithMultipleComonLEDInDifferentStateAtoBDeAssertTwice)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301093{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +05301094 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301095 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301096 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001097 Manager::group ledsAssert{};
1098 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301099
Patrick Venture91ac8d32018-11-01 17:03:22 -07001100 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1101 auto result =
1102 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301103 EXPECT_EQ(true, result);
1104
1105 // Need just the ledsAssserted populated with these.
1106 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001107 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1108 {"Two", phosphor::led::Layout::Blink, 0, 0,
1109 phosphor::led::Layout::On},
1110 {"Three", phosphor::led::Layout::Blink, 0, 0,
1111 phosphor::led::Layout::On},
1112 {"Four", phosphor::led::Layout::On, 0, 0,
1113 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301114 };
1115 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1116 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301117
1118 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001119 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301120 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1121 refAssert.begin(), refAssert.end(),
1122 std::inserter(temp, temp.begin()));
1123 EXPECT_EQ(0, temp.size());
1124 }
1125 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301126 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001127 Manager::group ledsAssert{};
1128 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301129
Patrick Venture91ac8d32018-11-01 17:03:22 -07001130 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1131 auto result =
1132 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301133 EXPECT_EQ(true, result);
1134
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301135 // Need just the ledsAssserted populated with these.
1136 // [Two] turns [On] due to priority
1137 // [Three] remains [Blink]
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301138 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001139 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1140 {"Five", phosphor::led::Layout::On, 0, 0,
1141 phosphor::led::Layout::On},
1142 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301143 };
1144 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1145 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301146
1147 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001148 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301149 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1150 refAssert.begin(), refAssert.end(),
1151 std::inserter(temp, temp.begin()));
1152 EXPECT_EQ(0, temp.size());
1153 }
1154 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301155 // DeAssert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001156 Manager::group ledsAssert{};
1157 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301158
Patrick Venture91ac8d32018-11-01 17:03:22 -07001159 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1160 auto result =
1161 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301162 EXPECT_EQ(false, result);
1163
1164 // Need just the ledsAssserted populated with these.
1165 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001166 {"Five", phosphor::led::Layout::On, 0, 0,
1167 phosphor::led::Layout::On},
1168 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301169 };
1170 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1171
1172 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001173 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301174 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1175 refDeAssert.begin(), refDeAssert.end(),
1176 std::inserter(temp, temp.begin()));
1177 EXPECT_EQ(0, temp.size());
1178
1179 // Need just the ledsAssert populated with these.
1180 // [Two] will go back to [Blink] from [On]
1181 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001182 {"Two", phosphor::led::Layout::Blink, 0, 0,
1183 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301184 };
1185 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1186
1187 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001188 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301189 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1190 refAssert.begin(), refAssert.end(),
1191 std::inserter(temp1, temp1.begin()));
1192 EXPECT_EQ(0, temp1.size());
1193 }
1194 {
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301195 // DeAssert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001196 Manager::group ledsAssert{};
1197 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301198
Patrick Venture91ac8d32018-11-01 17:03:22 -07001199 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1200 auto result =
1201 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301202 EXPECT_EQ(false, result);
1203
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301204 // Need just the ledsAssserted populated with these.
1205 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001206 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1207 {"Two", phosphor::led::Layout::Blink, 0, 0,
1208 phosphor::led::Layout::On},
1209 {"Three", phosphor::led::Layout::Blink, 0, 0,
1210 phosphor::led::Layout::On},
1211 {"Four", phosphor::led::Layout::On, 0, 0,
1212 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301213 };
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301214 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301215 EXPECT_EQ(0, ledsAssert.size());
1216
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301217 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001218 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301219 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1220 refDeAssert.begin(), refDeAssert.end(),
1221 std::inserter(temp, temp.begin()));
1222 EXPECT_EQ(0, temp.size());
1223 }
1224 {
1225 // DeAssert Set-A again and make sure we get all empty
Patrick Venture91ac8d32018-11-01 17:03:22 -07001226 Manager::group ledsAssert{};
1227 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301228
Patrick Venture91ac8d32018-11-01 17:03:22 -07001229 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1230 auto result =
1231 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301232 EXPECT_EQ(false, result);
1233 EXPECT_EQ(0, ledsDeAssert.size());
1234 EXPECT_EQ(0, ledsAssert.size());
1235 }
1236}
1237
1238/** @brief Assert 2 groups having multiple LEDs common in different state and
1239 * mixed priority. DeAssert-A
1240 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001241TEST_F(LedTest,
1242 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityAandB)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301243{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001244 Manager manager(bus,
1245 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301246 {
1247 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001248 Manager::group ledsAssert{};
1249 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301250
Patrick Venture91ac8d32018-11-01 17:03:22 -07001251 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1252 auto result =
1253 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301254 EXPECT_EQ(true, result);
1255
1256 // Need just the ledsAssserted populated with these.
1257 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001258 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1259 {"Two", phosphor::led::Layout::Blink, 0, 0,
1260 phosphor::led::Layout::On},
1261 {"Three", phosphor::led::Layout::On, 0, 0,
1262 phosphor::led::Layout::Blink},
1263 {"Four", phosphor::led::Layout::On, 0, 0,
1264 phosphor::led::Layout::On},
1265 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1266 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301267 };
1268 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1269 EXPECT_EQ(0, ledsDeAssert.size());
1270
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301271 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001272 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301273 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1274 refAssert.begin(), refAssert.end(),
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301275 std::inserter(temp, temp.begin()));
1276 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301277 }
1278 {
1279 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001280 Manager::group ledsAssert{};
1281 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301282
Patrick Venture91ac8d32018-11-01 17:03:22 -07001283 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1284 auto result =
1285 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301286 EXPECT_EQ(true, result);
1287
1288 // Need just the ledsAssserted populated with these.
1289 // [Two] gets to [ON] due to higher priority.
1290 // [Three] remains on since it never was in [Blink] before
1291 // [Ten] remains [Blink] due to priority: [Blink]
1292 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001293 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1294 {"Five", phosphor::led::Layout::On, 0, 0,
1295 phosphor::led::Layout::On},
1296 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301297 };
1298 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1299 EXPECT_EQ(0, ledsDeAssert.size());
1300
1301 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001302 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301303 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1304 refAssert.begin(), refAssert.end(),
1305 std::inserter(temp, temp.begin()));
1306 EXPECT_EQ(0, temp.size());
1307 }
1308 {
1309 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001310 Manager::group ledsAssert{};
1311 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301312
Patrick Venture91ac8d32018-11-01 17:03:22 -07001313 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1314 auto result =
1315 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301316 EXPECT_EQ(false, result);
1317
1318 // Need just the ledsDeAsssert populated with these.
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301319 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001320 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1321 {"Four", phosphor::led::Layout::On, 0, 0,
1322 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301323 };
1324 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1325
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301326 // Need just the ledsAsssert populated with these.
1327 // [Ten] Moves to [On] since there is no prior [Blink]
1328 // [Three] remains [On] since it never changed state.
1329 // [Two] remains [On] since it did not go back
1330 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001331 {"Ten", phosphor::led::Layout::On, 0, 0,
1332 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301333 };
1334 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1335
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301336 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001337 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301338 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1339 refAssert.begin(), refAssert.end(),
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301340 std::inserter(temp, temp.begin()));
1341 EXPECT_EQ(0, temp.size());
1342 }
1343}
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301344
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301345/** @brief Assert 2 groups having multiple LEDs common in different state and
1346 * mixed priority. DeAssert-B
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301347 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001348TEST_F(
1349 LedTest,
1350 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityAandBDeAssertB)
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301351{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001352 Manager manager(bus,
1353 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301354 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301355 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001356 Manager::group ledsAssert{};
1357 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301358
Patrick Venture91ac8d32018-11-01 17:03:22 -07001359 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1360 auto result =
1361 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301362 EXPECT_EQ(true, result);
1363
1364 // Need just the ledsAssserted populated with these.
1365 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001366 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1367 {"Two", phosphor::led::Layout::Blink, 0, 0,
1368 phosphor::led::Layout::On},
1369 {"Three", phosphor::led::Layout::On, 0, 0,
1370 phosphor::led::Layout::Blink},
1371 {"Four", phosphor::led::Layout::On, 0, 0,
1372 phosphor::led::Layout::On},
1373 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1374 phosphor::led::Layout::Blink},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301375 };
1376 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1377 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301378
1379 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001380 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301381 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1382 refAssert.begin(), refAssert.end(),
1383 std::inserter(temp, temp.begin()));
1384 EXPECT_EQ(0, temp.size());
1385 }
1386 {
1387 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001388 Manager::group ledsAssert{};
1389 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301390
Patrick Venture91ac8d32018-11-01 17:03:22 -07001391 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1392 auto result =
1393 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301394 EXPECT_EQ(true, result);
1395
1396 // Need just the ledsAssserted populated with these.
1397 // [Two] gets to [ON] due to higher priority.
1398 // [Three] remains on since it never was in [Blink] before
1399 // [Ten] remains [Blink] due to priority: [Blink]
1400 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001401 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1402 {"Five", phosphor::led::Layout::On, 0, 0,
1403 phosphor::led::Layout::On},
1404 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301405 };
1406 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1407 EXPECT_EQ(0, ledsDeAssert.size());
1408
1409 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001410 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301411 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1412 refAssert.begin(), refAssert.end(),
1413 std::inserter(temp, temp.begin()));
1414 EXPECT_EQ(0, temp.size());
1415 }
1416 {
1417 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001418 Manager::group ledsAssert{};
1419 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301420
Patrick Venture91ac8d32018-11-01 17:03:22 -07001421 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1422 auto result =
1423 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301424 EXPECT_EQ(false, result);
1425
1426 // Need just the ledsDeAsssert populated with these.
1427 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001428 {"Five", phosphor::led::Layout::On, 0, 0,
1429 phosphor::led::Layout::On},
1430 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301431 };
1432 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1433
1434 // Need just the ledsAsssert populated with these.
1435 // [Ten] remains [Blink] since it did not move to [On]
1436 // [Three] remains [On] since it never changed state.
1437 // [Two] moves to [Blink] since there is no prior [On]
1438 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001439 {"Two", phosphor::led::Layout::Blink, 0, 0,
1440 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301441 };
1442 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1443
1444 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001445 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301446 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1447 refAssert.begin(), refAssert.end(),
1448 std::inserter(temp, temp.begin()));
1449 EXPECT_EQ(0, temp.size());
1450 }
1451}
1452
1453/** @brief Assert 2 groups having multiple LEDs common in different state and
1454 * mixed priority.
1455 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001456TEST_F(LedTest,
1457 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityBandA)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301458{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001459 Manager manager(bus,
1460 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301461 {
1462 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001463 Manager::group ledsAssert{};
1464 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301465
Patrick Venture91ac8d32018-11-01 17:03:22 -07001466 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1467 auto result =
1468 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301469 EXPECT_EQ(true, result);
1470
1471 // Need just the ledsAssserted populated with these.
1472 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001473 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1474 {"Three", phosphor::led::Layout::On, 0, 0,
1475 phosphor::led::Layout::Blink},
1476 {"Five", phosphor::led::Layout::On, 0, 0,
1477 phosphor::led::Layout::On},
1478 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1479 {"Ten", phosphor::led::Layout::On, 0, 0,
1480 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301481 };
1482 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1483 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301484
1485 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001486 Manager::group temp{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301487 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1488 refAssert.begin(), refAssert.end(),
1489 std::inserter(temp, temp.begin()));
1490 EXPECT_EQ(0, temp.size());
1491 }
1492 {
1493 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001494 Manager::group ledsAssert{};
1495 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301496
Patrick Venture91ac8d32018-11-01 17:03:22 -07001497 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1498 auto result =
1499 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301500 EXPECT_EQ(true, result);
1501
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301502 // Need just the ledsAssserted populated with these.
1503 // [Two] remains [ON] due to higher priority.
1504 // [Three] remains on since it never was in [Blink] before
1505 // [Ten] moves to [Blink] due to priority: [Blink]
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301506 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001507 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1508 {"Four", phosphor::led::Layout::On, 0, 0,
1509 phosphor::led::Layout::On},
1510 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1511 phosphor::led::Layout::Blink},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301512 };
1513 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1514 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301515
1516 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001517 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301518 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1519 refAssert.begin(), refAssert.end(),
1520 std::inserter(temp, temp.begin()));
1521 EXPECT_EQ(0, temp.size());
1522 }
1523}
1524
1525/** @brief Assert 2 groups having multiple LEDs common in different state and
1526 * mixed priority and De-Assert-A
1527 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001528TEST_F(
1529 LedTest,
1530 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityBandADeAssertA)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301531{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001532 Manager manager(bus,
1533 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301534 {
1535 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001536 Manager::group ledsAssert{};
1537 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301538
Patrick Venture91ac8d32018-11-01 17:03:22 -07001539 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1540 auto result =
1541 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301542 EXPECT_EQ(true, result);
1543
1544 // Need just the ledsAssserted populated with these.
1545 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001546 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1547 {"Three", phosphor::led::Layout::On, 0, 0,
1548 phosphor::led::Layout::Blink},
1549 {"Five", phosphor::led::Layout::On, 0, 0,
1550 phosphor::led::Layout::On},
1551 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1552 {"Ten", phosphor::led::Layout::On, 0, 0,
1553 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301554 };
1555 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1556 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301557
1558 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001559 Manager::group temp{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301560 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1561 refAssert.begin(), refAssert.end(),
1562 std::inserter(temp, temp.begin()));
1563 EXPECT_EQ(0, temp.size());
1564 }
1565 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301566 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001567 Manager::group ledsAssert{};
1568 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301569
Patrick Venture91ac8d32018-11-01 17:03:22 -07001570 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1571 auto result =
1572 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301573 EXPECT_EQ(true, result);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301574
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301575 // Need just the ledsAssserted populated with these.
1576 // [Two] remains [ON] due to higher priority.
1577 // [Three] remains on since it never was in [Blink] before
1578 // [Ten] moves to [Blink] due to priority: [Blink]
1579 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001580 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1581 {"Four", phosphor::led::Layout::On, 0, 0,
1582 phosphor::led::Layout::On},
1583 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1584 phosphor::led::Layout::Blink},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301585 };
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301586 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1587 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301588
1589 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001590 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301591 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1592 refAssert.begin(), refAssert.end(),
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301593 std::inserter(temp, temp.begin()));
1594 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301595 }
1596 {
1597 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001598 Manager::group ledsAssert{};
1599 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301600
Patrick Venture91ac8d32018-11-01 17:03:22 -07001601 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1602 auto result =
1603 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301604 EXPECT_EQ(false, result);
1605
1606 // Need just the ledsAssserted populated with these.
1607 // [Ten] remains [Blink] due to priority.
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301608 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001609 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1610 {"Four", phosphor::led::Layout::On, 0, 0,
1611 phosphor::led::Layout::On},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301612 };
1613 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1614
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301615 // Need just the ledsAssserted populated with these.
1616 // [Two] remains [ON] due to higher priority.
1617 // [Three] remains [On] since it never was in [Blink] before
1618 // [Ten] moves to [On] due to priority: [Blink]
1619 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001620 {"Ten", phosphor::led::Layout::On, 0, 0,
1621 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301622 };
1623 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1624
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301625 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001626 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301627 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1628 refAssert.begin(), refAssert.end(),
1629 std::inserter(temp, temp.begin()));
1630 EXPECT_EQ(0, temp.size());
1631 }
1632}
1633
1634/** @brief Assert 2 groups having multiple LEDs common in different state and
1635 * mixed priority and then DeAssert twice.
1636 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001637TEST_F(LedTest,
1638 assertTwoGroupsWithMultipleComonLEDInDifferentStateOnBlinkPriorityBandA)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301639{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001640 Manager manager(bus,
1641 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301642 {
1643 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001644 Manager::group ledsAssert{};
1645 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301646
Patrick Venture91ac8d32018-11-01 17:03:22 -07001647 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1648 auto result =
1649 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301650 EXPECT_EQ(true, result);
1651
1652 // Need just the ledsAssserted populated with these.
1653 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001654 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1655 {"Three", phosphor::led::Layout::On, 0, 0,
1656 phosphor::led::Layout::Blink},
1657 {"Five", phosphor::led::Layout::On, 0, 0,
1658 phosphor::led::Layout::On},
1659 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1660 {"Ten", phosphor::led::Layout::On, 0, 0,
1661 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301662 };
1663 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1664 EXPECT_EQ(0, ledsDeAssert.size());
1665
1666 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001667 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301668 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1669 refAssert.begin(), refAssert.end(),
1670 std::inserter(temp, temp.begin()));
1671 EXPECT_EQ(0, temp.size());
1672 }
1673 {
1674 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001675 Manager::group ledsAssert{};
1676 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301677
Patrick Venture91ac8d32018-11-01 17:03:22 -07001678 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1679 auto result =
1680 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301681 EXPECT_EQ(true, result);
1682
1683 // Need just the ledsAssserted populated with these.
1684 // [Two] remains [ON] due to higher priority.
1685 // [Three] remains on since it never was in [Blink] before
1686 // [Ten] moves to [Blink] due to priority: [Blink]
1687 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001688 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1689 {"Four", phosphor::led::Layout::On, 0, 0,
1690 phosphor::led::Layout::On},
1691 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1692 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301693 };
1694 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1695 EXPECT_EQ(0, ledsDeAssert.size());
1696
1697 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001698 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301699 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1700 refAssert.begin(), refAssert.end(),
1701 std::inserter(temp, temp.begin()));
1702 EXPECT_EQ(0, temp.size());
1703 }
1704 {
1705 // DeAssert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001706 Manager::group ledsAssert{};
1707 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301708
Patrick Venture91ac8d32018-11-01 17:03:22 -07001709 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1710 auto result =
1711 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301712 EXPECT_EQ(false, result);
1713
1714 // Need just the ledsAssserted populated with these.
1715 // [Ten] remains [Blink] due to priority.
1716 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001717 {"Five", phosphor::led::Layout::On, 0, 0,
1718 phosphor::led::Layout::On},
1719 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301720 };
1721 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1722
1723 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001724 Manager::group temp{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301725 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1726 refDeAssert.begin(), refDeAssert.end(),
1727 std::inserter(temp, temp.begin()));
1728 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301729
1730 // Need just the ledsAssert populated with these.
1731 // [Two] will move to [Blink]
1732 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001733 {"Two", phosphor::led::Layout::Blink, 0, 0,
1734 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301735 };
1736 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1737
1738 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001739 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301740 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1741 refAssert.begin(), refAssert.end(),
1742 std::inserter(temp1, temp1.begin()));
1743 EXPECT_EQ(0, temp1.size());
1744 }
1745 {
1746 // DeAssert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001747 Manager::group ledsAssert{};
1748 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301749
Patrick Venture91ac8d32018-11-01 17:03:22 -07001750 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1751 auto result =
1752 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301753 EXPECT_EQ(false, result);
1754
1755 // Need just the ledsAssserted populated with these.
1756 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001757 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1758 {"Two", phosphor::led::Layout::Blink, 0, 0,
1759 phosphor::led::Layout::On},
1760 {"Three", phosphor::led::Layout::On, 0, 0,
1761 phosphor::led::Layout::Blink},
1762 {"Four", phosphor::led::Layout::On, 0, 0,
1763 phosphor::led::Layout::On},
1764 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1765 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301766 };
1767 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1768 EXPECT_EQ(0, ledsAssert.size());
1769
1770 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001771 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301772 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1773 refDeAssert.begin(), refDeAssert.end(),
1774 std::inserter(temp, temp.begin()));
1775 EXPECT_EQ(0, temp.size());
1776 }
1777 {
1778 // DeAssert Set-B again and make sure we get all empty
Patrick Venture91ac8d32018-11-01 17:03:22 -07001779 Manager::group ledsAssert{};
1780 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301781
Patrick Venture91ac8d32018-11-01 17:03:22 -07001782 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1783 auto result =
1784 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301785 EXPECT_EQ(false, result);
1786 EXPECT_EQ(0, ledsDeAssert.size());
1787 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301788 }
1789}