blob: 26e13ec1678d94a62cd0fef05e673910cda826cb [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
Patrick Venture91ac8d32018-11-01 17:03:22 -07004#include <sdbusplus/bus.hpp>
George Liua6c18f82020-06-22 10:50:04 +08005
6#include <algorithm>
Patrick Venture91ac8d32018-11-01 17:03:22 -07007#include <set>
8
9#include <gtest/gtest.h>
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053010using namespace phosphor::led;
11class LedTest : public ::testing::Test
12{
Patrick Venture91ac8d32018-11-01 17:03:22 -070013 public:
14 sdbusplus::bus::bus bus;
15 LedTest() : bus(sdbusplus::bus::new_default())
16 {
17 // Nothing here
18 }
19 ~LedTest()
20 {
21 // Leaving up to auto cleanup.
22 }
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053023};
24
25/** @brief Assert Single LED to On */
26TEST_F(LedTest, assertSingleLedOn)
27{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053028 Manager manager(bus, singleLedOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053029 {
30 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -070031 Manager::group ledsAssert{};
32 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053033
34 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -070035 auto result =
36 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053037 EXPECT_EQ(true, result);
38
39 // Need just the ledsAssserted populated with these.
40 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -070041 {"One", phosphor::led::Layout::On, 0, 0,
42 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053043 };
44 EXPECT_EQ(refAssert.size(), ledsAssert.size());
45 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053046
47 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -070048 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053049 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
50 refAssert.begin(), refAssert.end(),
51 std::inserter(temp, temp.begin()));
52 EXPECT_EQ(0, temp.size());
53 }
54}
55
56/** @brief Assert Single LED to Blink */
57TEST_F(LedTest, assertSingleLedBlink)
58{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053059 Manager manager(bus, singleLedBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053060 {
61 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -070062 Manager::group ledsAssert{};
63 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053064
65 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -070066 auto result =
67 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053068 EXPECT_EQ(true, result);
69
70 // Need just the ledsAssserted populated with these.
71 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -070072 {"One", phosphor::led::Layout::Blink, 0, 0,
73 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053074 };
75 EXPECT_EQ(refAssert.size(), ledsAssert.size());
76 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053077
78 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -070079 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053080 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
81 refAssert.begin(), refAssert.end(),
82 std::inserter(temp, temp.begin()));
83 EXPECT_EQ(0, temp.size());
84 }
85}
86
87/** @brief Assert Single LED to On and Try Assert Again */
88TEST_F(LedTest, assertSingleLedOnAndreAssert)
89{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053090 Manager manager(bus, singleLedOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053091 {
92 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -070093 Manager::group ledsAssert{};
94 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053095
96 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -070097 auto result =
98 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053099 EXPECT_EQ(true, result);
100
101 // Need just the ledsAssserted populated with these.
102 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700103 {"One", phosphor::led::Layout::On, 0, 0,
104 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530105 };
106 EXPECT_EQ(refAssert.size(), ledsAssert.size());
107 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530108
109 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700110 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530111 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
112 refAssert.begin(), refAssert.end(),
113 std::inserter(temp, temp.begin()));
114 EXPECT_EQ(0, temp.size());
115 }
116 {
117 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700118 Manager::group ledsAssert{};
119 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530120
121 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700122 auto result =
123 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530124 EXPECT_EQ(true, result);
125
126 EXPECT_EQ(0, ledsAssert.size());
127 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530128 }
129}
130
131/** @brief Assert Multiple LEDs to On */
132TEST_F(LedTest, assertMultipleLedOn)
133{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530134 Manager manager(bus, multipleLedsOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530135 {
136 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700137 Manager::group ledsAssert{};
138 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530139
140 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700141 auto result =
142 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530143 EXPECT_EQ(true, result);
144
145 // Need just the ledsAssserted populated with these.
146 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700147 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
148 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
149 {"Three", phosphor::led::Layout::On, 0, 0,
150 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530151 };
152 EXPECT_EQ(refAssert.size(), ledsAssert.size());
153 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530154
155 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700156 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530157 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
158 refAssert.begin(), refAssert.end(),
159 std::inserter(temp, temp.begin()));
160 EXPECT_EQ(0, temp.size());
161 }
162}
163
164/** @brief Assert Multiple LEDs to Blink */
165TEST_F(LedTest, assertMultipleLedBlink)
166{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530167 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530168 {
169 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700170 Manager::group ledsAssert{};
171 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530172
173 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700174 auto result =
175 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530176 EXPECT_EQ(true, result);
177
178 // Need just the ledsAssserted populated with these.
179 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700180 {"One", phosphor::led::Layout::Blink, 0, 0,
181 phosphor::led::Layout::Blink},
182 {"Two", phosphor::led::Layout::Blink, 0, 0,
183 phosphor::led::Layout::Blink},
184 {"Three", phosphor::led::Layout::Blink, 0, 0,
185 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530186 };
187 EXPECT_EQ(refAssert.size(), ledsAssert.size());
188 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530189
190 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700191 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530192 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
193 refAssert.begin(), refAssert.end(),
194 std::inserter(temp, temp.begin()));
195 EXPECT_EQ(0, temp.size());
196 }
197}
198
199/** @brief Assert Multiple LEDs to Blink, DeAssert */
200TEST_F(LedTest, assertMultipleLedBlinkAndDeAssert)
201{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530202 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530203 {
204 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700205 Manager::group ledsAssert{};
206 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530207
208 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700209 auto result =
210 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530211 EXPECT_EQ(true, result);
212
213 // Need just the ledsAssserted populated with these.
214 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700215 {"One", phosphor::led::Layout::Blink, 0, 0,
216 phosphor::led::Layout::Blink},
217 {"Two", phosphor::led::Layout::Blink, 0, 0,
218 phosphor::led::Layout::Blink},
219 {"Three", phosphor::led::Layout::Blink, 0, 0,
220 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530221 };
222 EXPECT_EQ(refAssert.size(), ledsAssert.size());
223 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530224
225 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700226 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530227 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
228 refAssert.begin(), refAssert.end(),
229 std::inserter(temp, temp.begin()));
230 EXPECT_EQ(0, temp.size());
231 }
232 {
233 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700234 Manager::group ledsAssert{};
235 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530236
237 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700238 auto result =
239 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530240 EXPECT_EQ(false, result);
241
242 // Need just the ledsAssserted populated with these.
243 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700244 {"One", phosphor::led::Layout::Blink, 0, 0,
245 phosphor::led::Layout::Blink},
246 {"Two", phosphor::led::Layout::Blink, 0, 0,
247 phosphor::led::Layout::Blink},
248 {"Three", phosphor::led::Layout::Blink, 0, 0,
249 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530250 };
251 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
252 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530253
254 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700255 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530256 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
257 refDeAssert.begin(), refDeAssert.end(),
258 std::inserter(temp, temp.begin()));
259 EXPECT_EQ(0, temp.size());
260 }
261}
262
263/** @brief Assert Multiple LEDs to Blink, DeAssert Twice */
264TEST_F(LedTest, assertMultipleLedBlinkAndDeAssertTwice)
265{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530266 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530267 {
268 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700269 Manager::group ledsAssert{};
270 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530271
272 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700273 auto result =
274 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530275 EXPECT_EQ(true, result);
276
277 // Need just the ledsAssserted populated with these.
278 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700279 {"One", phosphor::led::Layout::Blink, 0, 0,
280 phosphor::led::Layout::Blink},
281 {"Two", phosphor::led::Layout::Blink, 0, 0,
282 phosphor::led::Layout::Blink},
283 {"Three", phosphor::led::Layout::Blink, 0, 0,
284 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530285 };
286 EXPECT_EQ(refAssert.size(), ledsAssert.size());
287 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530288
289 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700290 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530291 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
292 refAssert.begin(), refAssert.end(),
293 std::inserter(temp, temp.begin()));
294 EXPECT_EQ(0, temp.size());
295 }
296 {
297 // DeAssert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700298 Manager::group ledsAssert{};
299 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530300
301 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700302 auto result =
303 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530304 EXPECT_EQ(false, result);
305
306 // Need just the ledsAssserted populated with these.
307 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700308 {"One", phosphor::led::Layout::Blink, 0, 0,
309 phosphor::led::Layout::Blink},
310 {"Two", phosphor::led::Layout::Blink, 0, 0,
311 phosphor::led::Layout::Blink},
312 {"Three", phosphor::led::Layout::Blink, 0, 0,
313 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530314 };
315 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
316 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530317
318 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700319 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530320 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
321 refDeAssert.begin(), refDeAssert.end(),
322 std::inserter(temp, temp.begin()));
323 EXPECT_EQ(0, temp.size());
324 }
325 {
326 // DeAssert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700327 Manager::group ledsAssert{};
328 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530329
330 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700331 auto result =
332 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530333 EXPECT_EQ(false, result);
334 EXPECT_EQ(0, ledsDeAssert.size());
335 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530336 }
337}
338
339/** @brief Assert Multiple LEDs to mix of On and Blink */
340TEST_F(LedTest, assertMultipleLedOnAndBlink)
341{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530342 Manager manager(bus, multipleLedsOnAndBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530343 {
344 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700345 Manager::group ledsAssert{};
346 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530347
348 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsMix";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700349 auto result =
350 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530351 EXPECT_EQ(true, result);
352
353 // Need just the ledsAssserted populated with these.
354 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700355 {"One", phosphor::led::Layout::Blink, 0, 0,
356 phosphor::led::Layout::Blink},
George Liu4b062012020-10-13 15:26:58 +0800357 {"Two", phosphor::led::Layout::On, 0, 0,
Patrick Venture91ac8d32018-11-01 17:03:22 -0700358 phosphor::led::Layout::Blink},
George Liu4b062012020-10-13 15:26:58 +0800359 {"Three", phosphor::led::Layout::Blink, 0, 0,
360 phosphor::led::Layout::On},
361 {"Four", phosphor::led::Layout::On, 0, 0,
362 phosphor::led::Layout::Blink},
363 {"Five", phosphor::led::Layout::On, 0, 0,
Patrick Venture91ac8d32018-11-01 17:03:22 -0700364 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530365 };
366 EXPECT_EQ(refAssert.size(), ledsAssert.size());
367 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530368
369 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700370 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530371 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
372 refAssert.begin(), refAssert.end(),
373 std::inserter(temp, temp.begin()));
374 EXPECT_EQ(0, temp.size());
375 }
376}
377
378/** @brief Assert 2 groups having distinct LEDs */
379TEST_F(LedTest, assertTwoGroupsOnWithDistinctLEDOn)
380{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530381 Manager manager(bus, twoGroupsWithDistinctLEDsOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530382 {
383 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700384 Manager::group ledsAssert{};
385 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530386
Patrick Venture91ac8d32018-11-01 17:03:22 -0700387 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
388 auto result =
389 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530390 EXPECT_EQ(true, result);
391
392 // Need just the ledsAssserted populated with these.
393 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700394 {"One", phosphor::led::Layout::On, 0, 0,
395 phosphor::led::Layout::Blink},
396 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
397 {"Three", phosphor::led::Layout::On, 0, 0,
398 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530399 };
400 EXPECT_EQ(refAssert.size(), ledsAssert.size());
401 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530402
403 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700404 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530405 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
406 refAssert.begin(), refAssert.end(),
407 std::inserter(temp, temp.begin()));
408 EXPECT_EQ(0, temp.size());
409 }
410 {
411 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700412 Manager::group ledsAssert{};
413 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530414
Patrick Venture91ac8d32018-11-01 17:03:22 -0700415 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
416 auto result =
417 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530418 EXPECT_EQ(true, result);
419
420 // Need just the ledsAssserted populated with these.
421 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700422 {"Four", phosphor::led::Layout::On, 0, 0,
423 phosphor::led::Layout::Blink},
424 {"Five", phosphor::led::Layout::On, 0, 0,
425 phosphor::led::Layout::Blink},
426 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530427 };
428 EXPECT_EQ(refAssert.size(), ledsAssert.size());
429 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530430
431 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700432 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530433 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
434 refAssert.begin(), refAssert.end(),
435 std::inserter(temp, temp.begin()));
436 EXPECT_EQ(0, temp.size());
437 }
438}
439
440/** @brief Assert 2 groups having one of the LEDs common */
441TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOn)
442{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530443 Manager manager(bus, twoGroupsWithOneComonLEDOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530444 {
445 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700446 Manager::group ledsAssert{};
447 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530448
Patrick Venture91ac8d32018-11-01 17:03:22 -0700449 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
450 auto result =
451 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530452 EXPECT_EQ(true, result);
453
454 // Need just the ledsAssserted populated with these.
455 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700456 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
457 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
458 {"Three", phosphor::led::Layout::On, 0, 0,
459 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530460 };
461 EXPECT_EQ(refAssert.size(), ledsAssert.size());
462 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530463
464 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700465 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530466 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
467 refAssert.begin(), refAssert.end(),
468 std::inserter(temp, temp.begin()));
469 EXPECT_EQ(0, temp.size());
470 }
471 {
472 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700473 Manager::group ledsAssert{};
474 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530475
Patrick Venture91ac8d32018-11-01 17:03:22 -0700476 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
477 auto result =
478 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530479 EXPECT_EQ(true, result);
480
481 // Need just the ledsAssserted populated with these.
482 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700483 {"Four", phosphor::led::Layout::On, 0, 0,
484 phosphor::led::Layout::On},
485 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530486 };
487 EXPECT_EQ(refAssert.size(), ledsAssert.size());
488 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530489
490 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700491 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530492 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
493 refAssert.begin(), refAssert.end(),
494 std::inserter(temp, temp.begin()));
495 EXPECT_EQ(0, temp.size());
496 }
497}
498
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530499/** @brief Assert 2 groups having one of the LEDs common but having Blink as
500 * priority and Deassert*/
501TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDBlinkPriorityAndDeAssertB)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530502{
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530503 Manager manager(bus, twoGroupsWithOneComonLEDOnOneLEDBlinkPriority);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530504 {
505 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700506 Manager::group ledsAssert{};
507 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530508
Patrick Venture91ac8d32018-11-01 17:03:22 -0700509 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
510 auto result =
511 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530512 EXPECT_EQ(true, result);
513
514 // Need just the ledsAssserted populated with these.
515 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700516 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
517 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
518 {"Three", phosphor::led::Layout::Blink, 0, 0,
519 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530520 };
521 EXPECT_EQ(refAssert.size(), ledsAssert.size());
522 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530523
524 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700525 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530526 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
527 refAssert.begin(), refAssert.end(),
528 std::inserter(temp, temp.begin()));
529 EXPECT_EQ(0, temp.size());
530 }
531 {
532 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700533 Manager::group ledsAssert{};
534 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530535
Patrick Venture91ac8d32018-11-01 17:03:22 -0700536 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
537 auto result =
538 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530539 EXPECT_EQ(true, result);
540
541 // Need just the ledsAssserted populated with these.
542 // Does not action on [Three] since priority is [Blink]
543 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700544 {"Four", phosphor::led::Layout::On, 0, 0,
545 phosphor::led::Layout::On},
546 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530547 };
548 EXPECT_EQ(refAssert.size(), ledsAssert.size());
549 EXPECT_EQ(0, ledsDeAssert.size());
550
551 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700552 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530553 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
554 refAssert.begin(), refAssert.end(),
555 std::inserter(temp, temp.begin()));
556 EXPECT_EQ(0, temp.size());
557 }
558 {
559 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700560 Manager::group ledsAssert{};
561 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530562
Patrick Venture91ac8d32018-11-01 17:03:22 -0700563 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
564 auto result =
565 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530566 EXPECT_EQ(false, result);
567
568 // Need just the ledsDeAssserted populated with these.
569 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700570 {"Four", phosphor::led::Layout::On, 0, 0,
571 phosphor::led::Layout::On},
572 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530573 };
574 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
575 EXPECT_EQ(0, ledsAssert.size());
576
577 // difference of refDeAssert and ledsDeAssert must be null.
578 // [Three] is not touched since its already [Blink]
Patrick Venture91ac8d32018-11-01 17:03:22 -0700579 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530580 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
581 refDeAssert.begin(), refDeAssert.end(),
582 std::inserter(temp, temp.begin()));
583 EXPECT_EQ(0, temp.size());
584 }
585}
586
587/** @brief Assert 2 groups having one of the LEDs common but having Blink as
588 * priority and Deassert A */
589TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDBlinkPriorityAndDeAssertA)
590{
591 Manager manager(bus, twoGroupsWithOneComonLEDOnOneLEDBlinkPriority);
592 {
593 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700594 Manager::group ledsAssert{};
595 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530596
Patrick Venture91ac8d32018-11-01 17:03:22 -0700597 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
598 auto result =
599 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530600 EXPECT_EQ(true, result);
601
602 // Need just the ledsAssserted populated with these.
603 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700604 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
605 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
606 {"Three", phosphor::led::Layout::Blink, 0, 0,
607 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530608 };
609 EXPECT_EQ(refAssert.size(), ledsAssert.size());
610 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530611
612 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700613 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530614 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
615 refAssert.begin(), refAssert.end(),
616 std::inserter(temp, temp.begin()));
617 EXPECT_EQ(0, temp.size());
618 }
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530619 {
620 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700621 Manager::group ledsAssert{};
622 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530623
Patrick Venture91ac8d32018-11-01 17:03:22 -0700624 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
625 auto result =
626 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530627 EXPECT_EQ(true, result);
628
629 // Need just the ledsAssserted populated with these.
630 // [Three] does not get actioned since it has Blink priority
631 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700632 {"Four", phosphor::led::Layout::On, 0, 0,
633 phosphor::led::Layout::On},
634 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530635 };
636 EXPECT_EQ(refAssert.size(), ledsAssert.size());
637 EXPECT_EQ(0, ledsDeAssert.size());
638
639 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700640 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530641 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
642 refAssert.begin(), refAssert.end(),
643 std::inserter(temp, temp.begin()));
644 EXPECT_EQ(0, temp.size());
645 }
646 {
647 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700648 Manager::group ledsAssert{};
649 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530650
Patrick Venture91ac8d32018-11-01 17:03:22 -0700651 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
652 auto result =
653 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530654 EXPECT_EQ(false, result);
655
656 // Need just the ledsDeAssserted populated with these.
657 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700658 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
659 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530660 };
661 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
662
663 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700664 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530665 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
666 refDeAssert.begin(), refDeAssert.end(),
667 std::inserter(temp, temp.begin()));
668 EXPECT_EQ(0, temp.size());
669
670 // Need just the ledsAssert populated with these.
671 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700672 {"Three", phosphor::led::Layout::On, 0, 0,
673 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530674 };
675 EXPECT_EQ(refAssert.size(), ledsAssert.size());
676
677 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700678 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530679 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
680 refAssert.begin(), refAssert.end(),
681 std::inserter(temp1, temp1.begin()));
682 EXPECT_EQ(0, temp1.size());
683 }
684}
685
686/** @brief Assert 2 groups having one of the LEDs common but having ON as
687 * priority And Deassert A */
688TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDOnPriorityAndDeAssertA)
689{
690 Manager manager(bus, twoGroupsWithOneComonLEDOnPriority);
691 {
692 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700693 Manager::group ledsAssert{};
694 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530695
Patrick Venture91ac8d32018-11-01 17:03:22 -0700696 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
697 auto result =
698 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530699 EXPECT_EQ(true, result);
700
701 // Need just the ledsAssserted populated with these.
702 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700703 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
704 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
705 {"Three", phosphor::led::Layout::Blink, 0, 0,
706 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530707 };
708 EXPECT_EQ(refAssert.size(), ledsAssert.size());
709 EXPECT_EQ(0, ledsDeAssert.size());
710
711 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700712 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530713 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
714 refAssert.begin(), refAssert.end(),
715 std::inserter(temp, temp.begin()));
716 EXPECT_EQ(0, temp.size());
717 }
718 {
719 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700720 Manager::group ledsAssert{};
721 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530722
Patrick Venture91ac8d32018-11-01 17:03:22 -0700723 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
724 auto result =
725 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530726 EXPECT_EQ(true, result);
727
728 // Need just the ledsAssserted populated with these.
729 // Three is set to ON due to ON priority.
730 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700731 {"Three", phosphor::led::Layout::On, 0, 0,
732 phosphor::led::Layout::On},
733 {"Four", phosphor::led::Layout::On, 0, 0,
734 phosphor::led::Layout::On},
735 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530736 };
737 EXPECT_EQ(refAssert.size(), ledsAssert.size());
738 EXPECT_EQ(0, ledsDeAssert.size());
739
740 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700741 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530742 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
743 refAssert.begin(), refAssert.end(),
744 std::inserter(temp, temp.begin()));
745 }
746 {
747 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700748 Manager::group ledsAssert{};
749 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530750
Patrick Venture91ac8d32018-11-01 17:03:22 -0700751 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
752 auto result =
753 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530754 EXPECT_EQ(false, result);
755
756 // Need just the ledsDeAssserted populated with these.
757 // [Three] stays in [On] since [B] has it [On]
758 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700759 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
760 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530761 };
762 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
763 EXPECT_EQ(0, ledsAssert.size());
764
765 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700766 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530767 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
768 refDeAssert.begin(), refDeAssert.end(),
769 std::inserter(temp, temp.begin()));
770 EXPECT_EQ(0, temp.size());
771 }
772}
773
774/** @brief Assert 2 groups having one of the LEDs common but having ON as
775 * priority And Deassert B */
776TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDOnPriorityAndDeAssertB)
777{
778 Manager manager(bus, twoGroupsWithOneComonLEDOnPriority);
779 {
780 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700781 Manager::group ledsAssert{};
782 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530783
Patrick Venture91ac8d32018-11-01 17:03:22 -0700784 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
785 auto result =
786 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530787 EXPECT_EQ(true, result);
788
789 // Need just the ledsAssserted populated with these.
790 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700791 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
792 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
793 {"Three", phosphor::led::Layout::Blink, 0, 0,
794 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530795 };
796 EXPECT_EQ(refAssert.size(), ledsAssert.size());
797 EXPECT_EQ(0, ledsDeAssert.size());
798
799 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700800 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530801 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
802 refAssert.begin(), refAssert.end(),
803 std::inserter(temp, temp.begin()));
804 EXPECT_EQ(0, temp.size());
805 }
806 {
807 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700808 Manager::group ledsAssert{};
809 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530810
Patrick Venture91ac8d32018-11-01 17:03:22 -0700811 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
812 auto result =
813 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530814 EXPECT_EQ(true, result);
815
816 // Need just the ledsAssserted populated with these.
817 // Three is set to ON due to ON priority.
818 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700819 {"Three", phosphor::led::Layout::On, 0, 0,
820 phosphor::led::Layout::On},
821 {"Four", phosphor::led::Layout::On, 0, 0,
822 phosphor::led::Layout::On},
823 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530824 };
825 EXPECT_EQ(refAssert.size(), ledsAssert.size());
826 EXPECT_EQ(0, ledsDeAssert.size());
827
828 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700829 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530830 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
831 refAssert.begin(), refAssert.end(),
832 std::inserter(temp, temp.begin()));
833 }
834 {
835 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700836 Manager::group ledsAssert{};
837 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530838
Patrick Venture91ac8d32018-11-01 17:03:22 -0700839 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
840 auto result =
841 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530842 EXPECT_EQ(false, result);
843
844 // Need just the ledsDeAssserted populated with these.
845 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700846 {"Four", phosphor::led::Layout::On, 0, 0,
847 phosphor::led::Layout::On},
848 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530849 };
850 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
851
852 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700853 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530854 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
855 refDeAssert.begin(), refDeAssert.end(),
856 std::inserter(temp, temp.begin()));
857 EXPECT_EQ(0, temp.size());
858
859 // Need just the ledsAssert populated with these.
860 // Since [Three] stood [On], need to go back to [Blink]
861 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700862 {"Three", phosphor::led::Layout::Blink, 0, 0,
863 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530864 };
865 EXPECT_EQ(refAssert.size(), ledsAssert.size());
866
867 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700868 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530869 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
870 refAssert.begin(), refAssert.end(),
871 std::inserter(temp, temp.begin()));
872 EXPECT_EQ(0, temp.size());
873 }
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530874}
875
876/** @brief Assert 2 groups having multiple common LEDs in Same State */
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530877TEST_F(LedTest, assertTwoGroupsWithMultiplComonLEDOnAndDeAssert)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530878{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530879 Manager manager(bus, twoGroupsWithMultiplComonLEDOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530880 {
881 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700882 Manager::group ledsAssert{};
883 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530884
Patrick Venture91ac8d32018-11-01 17:03:22 -0700885 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
886 auto result =
887 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530888 EXPECT_EQ(true, result);
889
890 // Need just the ledsAssserted populated with these.
891 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700892 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
893 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
894 {"Three", phosphor::led::Layout::On, 0, 0,
895 phosphor::led::Layout::On},
896 {"Seven", phosphor::led::Layout::On, 0, 0,
897 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530898 };
899 EXPECT_EQ(refAssert.size(), ledsAssert.size());
900 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530901
902 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700903 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530904 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
905 refAssert.begin(), refAssert.end(),
906 std::inserter(temp, temp.begin()));
907 EXPECT_EQ(0, temp.size());
908 }
909 {
910 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700911 Manager::group ledsAssert{};
912 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530913
Patrick Venture91ac8d32018-11-01 17:03:22 -0700914 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
915 auto result =
916 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530917 EXPECT_EQ(true, result);
918
919 // Need just the ledsAssserted populated with these.
920 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700921 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530922 };
923 EXPECT_EQ(refAssert.size(), ledsAssert.size());
924 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530925
926 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700927 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530928 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
929 refAssert.begin(), refAssert.end(),
930 std::inserter(temp, temp.begin()));
931 EXPECT_EQ(0, temp.size());
932 }
933 {
934 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700935 Manager::group ledsAssert{};
936 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530937
Patrick Venture91ac8d32018-11-01 17:03:22 -0700938 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
939 auto result =
940 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530941 EXPECT_EQ(false, result);
942
943 // Need just the ledsDeAssserted populated with these.
944 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700945 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
946 {"Seven", phosphor::led::Layout::On, 0, 0,
947 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530948 };
949 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
950 EXPECT_EQ(0, ledsAssert.size());
951
952 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700953 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530954 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
955 refDeAssert.begin(), refDeAssert.end(),
956 std::inserter(temp, temp.begin()));
957 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530958 }
959}
960
961/** @brief Assert 2 groups having multiple LEDs common in different state */
962TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateBandA)
963{
964 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
965 {
966 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700967 Manager::group ledsAssert{};
968 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530969
Patrick Venture91ac8d32018-11-01 17:03:22 -0700970 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
971 auto result =
972 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530973 EXPECT_EQ(true, result);
974
975 // Need just the ledsAssserted populated with these.
976 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700977 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
978 {"Three", phosphor::led::Layout::Blink, 0, 0,
979 phosphor::led::Layout::On},
980 {"Five", phosphor::led::Layout::On, 0, 0,
981 phosphor::led::Layout::On},
982 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530983 };
984 EXPECT_EQ(refAssert.size(), ledsAssert.size());
985 EXPECT_EQ(0, ledsDeAssert.size());
986
987 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700988 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530989 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
990 refAssert.begin(), refAssert.end(),
991 std::inserter(temp, temp.begin()));
992 EXPECT_EQ(0, temp.size());
993 }
994 {
995 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700996 Manager::group ledsAssert{};
997 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530998
Patrick Venture91ac8d32018-11-01 17:03:22 -0700999 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1000 auto result =
1001 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301002 EXPECT_EQ(true, result);
1003
1004 // Need just the ledsAssserted populated with these
1005 // [Two] remains [On] due to higher priority.
1006 // [Three] remains [Blink]
1007 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001008 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1009 {"Four", phosphor::led::Layout::On, 0, 0,
1010 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301011 };
1012 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1013 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301014
1015 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001016 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301017 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1018 refAssert.begin(), refAssert.end(),
1019 std::inserter(temp, temp.begin()));
1020 EXPECT_EQ(0, temp.size());
1021 }
1022}
1023
1024/** @brief Assert 2 groups having multiple LEDs common in different state */
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301025TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateAtoB)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301026{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +05301027 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301028 {
1029 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001030 Manager::group ledsAssert{};
1031 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301032
Patrick Venture91ac8d32018-11-01 17:03:22 -07001033 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1034 auto result =
1035 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301036 EXPECT_EQ(true, result);
1037
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301038 // Need just the ledsAssserted populated with these.'Two' gets to Blink
1039 // due to higher priority.
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301040 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001041 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1042 {"Two", phosphor::led::Layout::Blink, 0, 0,
1043 phosphor::led::Layout::On},
1044 {"Three", phosphor::led::Layout::Blink, 0, 0,
1045 phosphor::led::Layout::On},
1046 {"Four", phosphor::led::Layout::On, 0, 0,
1047 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301048 };
1049 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1050 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301051
1052 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001053 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301054 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1055 refAssert.begin(), refAssert.end(),
1056 std::inserter(temp, temp.begin()));
1057 EXPECT_EQ(0, temp.size());
1058 }
1059 {
1060 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001061 Manager::group ledsAssert{};
1062 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301063
Patrick Venture91ac8d32018-11-01 17:03:22 -07001064 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1065 auto result =
1066 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301067 EXPECT_EQ(true, result);
1068
1069 // Need just the ledsAssserted populated with these.
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301070 // [Three] remains [Blink] from previous
1071 // [Two] moves to [On] from [Blink] due to [On] priority
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301072 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001073 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1074 {"Five", phosphor::led::Layout::On, 0, 0,
1075 phosphor::led::Layout::On},
1076 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301077 };
1078 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1079 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301080
1081 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001082 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301083 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1084 refAssert.begin(), refAssert.end(),
1085 std::inserter(temp, temp.begin()));
1086 EXPECT_EQ(0, temp.size());
1087 }
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301088}
1089
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301090/** @brief Assert 2 groups having multiple LEDs common in different state
1091 * DeAssert twice
1092 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001093TEST_F(LedTest,
1094 assertTwoGroupsWithMultipleComonLEDInDifferentStateAtoBDeAssertTwice)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301095{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +05301096 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301097 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301098 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001099 Manager::group ledsAssert{};
1100 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301101
Patrick Venture91ac8d32018-11-01 17:03:22 -07001102 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1103 auto result =
1104 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301105 EXPECT_EQ(true, result);
1106
1107 // Need just the ledsAssserted populated with these.
1108 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001109 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1110 {"Two", phosphor::led::Layout::Blink, 0, 0,
1111 phosphor::led::Layout::On},
1112 {"Three", phosphor::led::Layout::Blink, 0, 0,
1113 phosphor::led::Layout::On},
1114 {"Four", phosphor::led::Layout::On, 0, 0,
1115 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301116 };
1117 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1118 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301119
1120 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001121 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301122 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1123 refAssert.begin(), refAssert.end(),
1124 std::inserter(temp, temp.begin()));
1125 EXPECT_EQ(0, temp.size());
1126 }
1127 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301128 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001129 Manager::group ledsAssert{};
1130 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301131
Patrick Venture91ac8d32018-11-01 17:03:22 -07001132 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1133 auto result =
1134 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301135 EXPECT_EQ(true, result);
1136
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301137 // Need just the ledsAssserted populated with these.
1138 // [Two] turns [On] due to priority
1139 // [Three] remains [Blink]
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301140 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001141 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1142 {"Five", phosphor::led::Layout::On, 0, 0,
1143 phosphor::led::Layout::On},
1144 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301145 };
1146 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1147 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301148
1149 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001150 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301151 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1152 refAssert.begin(), refAssert.end(),
1153 std::inserter(temp, temp.begin()));
1154 EXPECT_EQ(0, temp.size());
1155 }
1156 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301157 // DeAssert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001158 Manager::group ledsAssert{};
1159 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301160
Patrick Venture91ac8d32018-11-01 17:03:22 -07001161 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1162 auto result =
1163 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301164 EXPECT_EQ(false, result);
1165
1166 // Need just the ledsAssserted populated with these.
1167 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001168 {"Five", phosphor::led::Layout::On, 0, 0,
1169 phosphor::led::Layout::On},
1170 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301171 };
1172 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1173
1174 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001175 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301176 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1177 refDeAssert.begin(), refDeAssert.end(),
1178 std::inserter(temp, temp.begin()));
1179 EXPECT_EQ(0, temp.size());
1180
1181 // Need just the ledsAssert populated with these.
1182 // [Two] will go back to [Blink] from [On]
1183 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001184 {"Two", phosphor::led::Layout::Blink, 0, 0,
1185 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301186 };
1187 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1188
1189 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001190 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301191 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1192 refAssert.begin(), refAssert.end(),
1193 std::inserter(temp1, temp1.begin()));
1194 EXPECT_EQ(0, temp1.size());
1195 }
1196 {
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301197 // DeAssert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001198 Manager::group ledsAssert{};
1199 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301200
Patrick Venture91ac8d32018-11-01 17:03:22 -07001201 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1202 auto result =
1203 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301204 EXPECT_EQ(false, result);
1205
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301206 // Need just the ledsAssserted populated with these.
1207 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001208 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1209 {"Two", phosphor::led::Layout::Blink, 0, 0,
1210 phosphor::led::Layout::On},
1211 {"Three", phosphor::led::Layout::Blink, 0, 0,
1212 phosphor::led::Layout::On},
1213 {"Four", phosphor::led::Layout::On, 0, 0,
1214 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301215 };
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301216 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301217 EXPECT_EQ(0, ledsAssert.size());
1218
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301219 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001220 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301221 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1222 refDeAssert.begin(), refDeAssert.end(),
1223 std::inserter(temp, temp.begin()));
1224 EXPECT_EQ(0, temp.size());
1225 }
1226 {
1227 // DeAssert Set-A again and make sure we get all empty
Patrick Venture91ac8d32018-11-01 17:03:22 -07001228 Manager::group ledsAssert{};
1229 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301230
Patrick Venture91ac8d32018-11-01 17:03:22 -07001231 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1232 auto result =
1233 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301234 EXPECT_EQ(false, result);
1235 EXPECT_EQ(0, ledsDeAssert.size());
1236 EXPECT_EQ(0, ledsAssert.size());
1237 }
1238}
1239
1240/** @brief Assert 2 groups having multiple LEDs common in different state and
1241 * mixed priority. DeAssert-A
1242 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001243TEST_F(LedTest,
1244 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityAandB)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301245{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001246 Manager manager(bus,
1247 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301248 {
1249 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001250 Manager::group ledsAssert{};
1251 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301252
Patrick Venture91ac8d32018-11-01 17:03:22 -07001253 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1254 auto result =
1255 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301256 EXPECT_EQ(true, result);
1257
1258 // Need just the ledsAssserted populated with these.
1259 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001260 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1261 {"Two", phosphor::led::Layout::Blink, 0, 0,
1262 phosphor::led::Layout::On},
1263 {"Three", phosphor::led::Layout::On, 0, 0,
1264 phosphor::led::Layout::Blink},
1265 {"Four", phosphor::led::Layout::On, 0, 0,
1266 phosphor::led::Layout::On},
1267 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1268 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301269 };
1270 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1271 EXPECT_EQ(0, ledsDeAssert.size());
1272
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301273 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001274 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301275 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1276 refAssert.begin(), refAssert.end(),
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301277 std::inserter(temp, temp.begin()));
1278 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301279 }
1280 {
1281 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001282 Manager::group ledsAssert{};
1283 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301284
Patrick Venture91ac8d32018-11-01 17:03:22 -07001285 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1286 auto result =
1287 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301288 EXPECT_EQ(true, result);
1289
1290 // Need just the ledsAssserted populated with these.
1291 // [Two] gets to [ON] due to higher priority.
1292 // [Three] remains on since it never was in [Blink] before
1293 // [Ten] remains [Blink] due to priority: [Blink]
1294 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001295 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1296 {"Five", phosphor::led::Layout::On, 0, 0,
1297 phosphor::led::Layout::On},
1298 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301299 };
1300 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1301 EXPECT_EQ(0, ledsDeAssert.size());
1302
1303 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001304 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301305 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1306 refAssert.begin(), refAssert.end(),
1307 std::inserter(temp, temp.begin()));
1308 EXPECT_EQ(0, temp.size());
1309 }
1310 {
1311 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001312 Manager::group ledsAssert{};
1313 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301314
Patrick Venture91ac8d32018-11-01 17:03:22 -07001315 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1316 auto result =
1317 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301318 EXPECT_EQ(false, result);
1319
1320 // Need just the ledsDeAsssert populated with these.
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301321 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001322 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1323 {"Four", phosphor::led::Layout::On, 0, 0,
1324 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301325 };
1326 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1327
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301328 // Need just the ledsAsssert populated with these.
1329 // [Ten] Moves to [On] since there is no prior [Blink]
1330 // [Three] remains [On] since it never changed state.
1331 // [Two] remains [On] since it did not go back
1332 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001333 {"Ten", phosphor::led::Layout::On, 0, 0,
1334 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301335 };
1336 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1337
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301338 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001339 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301340 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1341 refAssert.begin(), refAssert.end(),
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301342 std::inserter(temp, temp.begin()));
1343 EXPECT_EQ(0, temp.size());
1344 }
1345}
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301346
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301347/** @brief Assert 2 groups having multiple LEDs common in different state and
1348 * mixed priority. DeAssert-B
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301349 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001350TEST_F(
1351 LedTest,
1352 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityAandBDeAssertB)
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301353{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001354 Manager manager(bus,
1355 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301356 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301357 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001358 Manager::group ledsAssert{};
1359 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301360
Patrick Venture91ac8d32018-11-01 17:03:22 -07001361 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1362 auto result =
1363 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301364 EXPECT_EQ(true, result);
1365
1366 // Need just the ledsAssserted populated with these.
1367 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001368 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1369 {"Two", phosphor::led::Layout::Blink, 0, 0,
1370 phosphor::led::Layout::On},
1371 {"Three", phosphor::led::Layout::On, 0, 0,
1372 phosphor::led::Layout::Blink},
1373 {"Four", phosphor::led::Layout::On, 0, 0,
1374 phosphor::led::Layout::On},
1375 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1376 phosphor::led::Layout::Blink},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301377 };
1378 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1379 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301380
1381 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001382 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301383 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1384 refAssert.begin(), refAssert.end(),
1385 std::inserter(temp, temp.begin()));
1386 EXPECT_EQ(0, temp.size());
1387 }
1388 {
1389 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001390 Manager::group ledsAssert{};
1391 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301392
Patrick Venture91ac8d32018-11-01 17:03:22 -07001393 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1394 auto result =
1395 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301396 EXPECT_EQ(true, result);
1397
1398 // Need just the ledsAssserted populated with these.
1399 // [Two] gets to [ON] due to higher priority.
1400 // [Three] remains on since it never was in [Blink] before
1401 // [Ten] remains [Blink] due to priority: [Blink]
1402 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001403 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1404 {"Five", phosphor::led::Layout::On, 0, 0,
1405 phosphor::led::Layout::On},
1406 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301407 };
1408 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1409 EXPECT_EQ(0, ledsDeAssert.size());
1410
1411 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001412 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301413 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1414 refAssert.begin(), refAssert.end(),
1415 std::inserter(temp, temp.begin()));
1416 EXPECT_EQ(0, temp.size());
1417 }
1418 {
1419 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001420 Manager::group ledsAssert{};
1421 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301422
Patrick Venture91ac8d32018-11-01 17:03:22 -07001423 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1424 auto result =
1425 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301426 EXPECT_EQ(false, result);
1427
1428 // Need just the ledsDeAsssert populated with these.
1429 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001430 {"Five", phosphor::led::Layout::On, 0, 0,
1431 phosphor::led::Layout::On},
1432 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301433 };
1434 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1435
1436 // Need just the ledsAsssert populated with these.
1437 // [Ten] remains [Blink] since it did not move to [On]
1438 // [Three] remains [On] since it never changed state.
1439 // [Two] moves to [Blink] since there is no prior [On]
1440 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001441 {"Two", phosphor::led::Layout::Blink, 0, 0,
1442 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301443 };
1444 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1445
1446 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001447 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301448 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1449 refAssert.begin(), refAssert.end(),
1450 std::inserter(temp, temp.begin()));
1451 EXPECT_EQ(0, temp.size());
1452 }
1453}
1454
1455/** @brief Assert 2 groups having multiple LEDs common in different state and
1456 * mixed priority.
1457 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001458TEST_F(LedTest,
1459 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityBandA)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301460{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001461 Manager manager(bus,
1462 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301463 {
1464 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001465 Manager::group ledsAssert{};
1466 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301467
Patrick Venture91ac8d32018-11-01 17:03:22 -07001468 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1469 auto result =
1470 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301471 EXPECT_EQ(true, result);
1472
1473 // Need just the ledsAssserted populated with these.
1474 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001475 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1476 {"Three", phosphor::led::Layout::On, 0, 0,
1477 phosphor::led::Layout::Blink},
1478 {"Five", phosphor::led::Layout::On, 0, 0,
1479 phosphor::led::Layout::On},
1480 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1481 {"Ten", phosphor::led::Layout::On, 0, 0,
1482 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301483 };
1484 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1485 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301486
1487 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001488 Manager::group temp{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301489 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1490 refAssert.begin(), refAssert.end(),
1491 std::inserter(temp, temp.begin()));
1492 EXPECT_EQ(0, temp.size());
1493 }
1494 {
1495 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001496 Manager::group ledsAssert{};
1497 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301498
Patrick Venture91ac8d32018-11-01 17:03:22 -07001499 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1500 auto result =
1501 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301502 EXPECT_EQ(true, result);
1503
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301504 // Need just the ledsAssserted populated with these.
1505 // [Two] remains [ON] due to higher priority.
1506 // [Three] remains on since it never was in [Blink] before
1507 // [Ten] moves to [Blink] due to priority: [Blink]
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301508 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001509 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1510 {"Four", phosphor::led::Layout::On, 0, 0,
1511 phosphor::led::Layout::On},
1512 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1513 phosphor::led::Layout::Blink},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301514 };
1515 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1516 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301517
1518 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001519 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301520 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1521 refAssert.begin(), refAssert.end(),
1522 std::inserter(temp, temp.begin()));
1523 EXPECT_EQ(0, temp.size());
1524 }
1525}
1526
1527/** @brief Assert 2 groups having multiple LEDs common in different state and
1528 * mixed priority and De-Assert-A
1529 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001530TEST_F(
1531 LedTest,
1532 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityBandADeAssertA)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301533{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001534 Manager manager(bus,
1535 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301536 {
1537 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001538 Manager::group ledsAssert{};
1539 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301540
Patrick Venture91ac8d32018-11-01 17:03:22 -07001541 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1542 auto result =
1543 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301544 EXPECT_EQ(true, result);
1545
1546 // Need just the ledsAssserted populated with these.
1547 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001548 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1549 {"Three", phosphor::led::Layout::On, 0, 0,
1550 phosphor::led::Layout::Blink},
1551 {"Five", phosphor::led::Layout::On, 0, 0,
1552 phosphor::led::Layout::On},
1553 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1554 {"Ten", phosphor::led::Layout::On, 0, 0,
1555 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301556 };
1557 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1558 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301559
1560 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001561 Manager::group temp{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301562 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1563 refAssert.begin(), refAssert.end(),
1564 std::inserter(temp, temp.begin()));
1565 EXPECT_EQ(0, temp.size());
1566 }
1567 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301568 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001569 Manager::group ledsAssert{};
1570 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301571
Patrick Venture91ac8d32018-11-01 17:03:22 -07001572 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1573 auto result =
1574 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301575 EXPECT_EQ(true, result);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301576
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301577 // Need just the ledsAssserted populated with these.
1578 // [Two] remains [ON] due to higher priority.
1579 // [Three] remains on since it never was in [Blink] before
1580 // [Ten] moves to [Blink] due to priority: [Blink]
1581 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001582 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1583 {"Four", phosphor::led::Layout::On, 0, 0,
1584 phosphor::led::Layout::On},
1585 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1586 phosphor::led::Layout::Blink},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301587 };
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301588 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1589 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301590
1591 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001592 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301593 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1594 refAssert.begin(), refAssert.end(),
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301595 std::inserter(temp, temp.begin()));
1596 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301597 }
1598 {
1599 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001600 Manager::group ledsAssert{};
1601 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301602
Patrick Venture91ac8d32018-11-01 17:03:22 -07001603 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1604 auto result =
1605 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301606 EXPECT_EQ(false, result);
1607
1608 // Need just the ledsAssserted populated with these.
1609 // [Ten] remains [Blink] due to priority.
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301610 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001611 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1612 {"Four", phosphor::led::Layout::On, 0, 0,
1613 phosphor::led::Layout::On},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301614 };
1615 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1616
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301617 // Need just the ledsAssserted populated with these.
1618 // [Two] remains [ON] due to higher priority.
1619 // [Three] remains [On] since it never was in [Blink] before
1620 // [Ten] moves to [On] due to priority: [Blink]
1621 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001622 {"Ten", phosphor::led::Layout::On, 0, 0,
1623 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301624 };
1625 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1626
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301627 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001628 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301629 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1630 refAssert.begin(), refAssert.end(),
1631 std::inserter(temp, temp.begin()));
1632 EXPECT_EQ(0, temp.size());
1633 }
1634}
1635
1636/** @brief Assert 2 groups having multiple LEDs common in different state and
1637 * mixed priority and then DeAssert twice.
1638 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001639TEST_F(LedTest,
1640 assertTwoGroupsWithMultipleComonLEDInDifferentStateOnBlinkPriorityBandA)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301641{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001642 Manager manager(bus,
1643 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301644 {
1645 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001646 Manager::group ledsAssert{};
1647 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301648
Patrick Venture91ac8d32018-11-01 17:03:22 -07001649 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1650 auto result =
1651 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301652 EXPECT_EQ(true, result);
1653
1654 // Need just the ledsAssserted populated with these.
1655 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001656 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1657 {"Three", phosphor::led::Layout::On, 0, 0,
1658 phosphor::led::Layout::Blink},
1659 {"Five", phosphor::led::Layout::On, 0, 0,
1660 phosphor::led::Layout::On},
1661 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1662 {"Ten", phosphor::led::Layout::On, 0, 0,
1663 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301664 };
1665 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1666 EXPECT_EQ(0, ledsDeAssert.size());
1667
1668 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001669 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301670 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1671 refAssert.begin(), refAssert.end(),
1672 std::inserter(temp, temp.begin()));
1673 EXPECT_EQ(0, temp.size());
1674 }
1675 {
1676 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001677 Manager::group ledsAssert{};
1678 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301679
Patrick Venture91ac8d32018-11-01 17:03:22 -07001680 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1681 auto result =
1682 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301683 EXPECT_EQ(true, result);
1684
1685 // Need just the ledsAssserted populated with these.
1686 // [Two] remains [ON] due to higher priority.
1687 // [Three] remains on since it never was in [Blink] before
1688 // [Ten] moves to [Blink] due to priority: [Blink]
1689 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001690 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1691 {"Four", phosphor::led::Layout::On, 0, 0,
1692 phosphor::led::Layout::On},
1693 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1694 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301695 };
1696 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1697 EXPECT_EQ(0, ledsDeAssert.size());
1698
1699 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001700 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301701 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1702 refAssert.begin(), refAssert.end(),
1703 std::inserter(temp, temp.begin()));
1704 EXPECT_EQ(0, temp.size());
1705 }
1706 {
1707 // DeAssert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001708 Manager::group ledsAssert{};
1709 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301710
Patrick Venture91ac8d32018-11-01 17:03:22 -07001711 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1712 auto result =
1713 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301714 EXPECT_EQ(false, result);
1715
1716 // Need just the ledsAssserted populated with these.
1717 // [Ten] remains [Blink] due to priority.
1718 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001719 {"Five", phosphor::led::Layout::On, 0, 0,
1720 phosphor::led::Layout::On},
1721 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301722 };
1723 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1724
1725 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001726 Manager::group temp{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301727 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1728 refDeAssert.begin(), refDeAssert.end(),
1729 std::inserter(temp, temp.begin()));
1730 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301731
1732 // Need just the ledsAssert populated with these.
1733 // [Two] will move to [Blink]
1734 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001735 {"Two", phosphor::led::Layout::Blink, 0, 0,
1736 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301737 };
1738 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1739
1740 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001741 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301742 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1743 refAssert.begin(), refAssert.end(),
1744 std::inserter(temp1, temp1.begin()));
1745 EXPECT_EQ(0, temp1.size());
1746 }
1747 {
1748 // DeAssert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001749 Manager::group ledsAssert{};
1750 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301751
Patrick Venture91ac8d32018-11-01 17:03:22 -07001752 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1753 auto result =
1754 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301755 EXPECT_EQ(false, result);
1756
1757 // Need just the ledsAssserted populated with these.
1758 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001759 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1760 {"Two", phosphor::led::Layout::Blink, 0, 0,
1761 phosphor::led::Layout::On},
1762 {"Three", phosphor::led::Layout::On, 0, 0,
1763 phosphor::led::Layout::Blink},
1764 {"Four", phosphor::led::Layout::On, 0, 0,
1765 phosphor::led::Layout::On},
1766 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1767 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301768 };
1769 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1770 EXPECT_EQ(0, ledsAssert.size());
1771
1772 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001773 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301774 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1775 refDeAssert.begin(), refDeAssert.end(),
1776 std::inserter(temp, temp.begin()));
1777 EXPECT_EQ(0, temp.size());
1778 }
1779 {
1780 // DeAssert Set-B again and make sure we get all empty
Patrick Venture91ac8d32018-11-01 17:03:22 -07001781 Manager::group ledsAssert{};
1782 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301783
Patrick Venture91ac8d32018-11-01 17:03:22 -07001784 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1785 auto result =
1786 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301787 EXPECT_EQ(false, result);
1788 EXPECT_EQ(0, ledsDeAssert.size());
1789 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301790 }
1791}