blob: 318c9bcb84a8642e72c1ca4a0db0908bc2f9c5bc [file] [log] [blame]
George Liu616a0712021-02-18 10:50:24 +08001#include "json-parser.hpp"
George Liudef5f5a2020-04-10 11:23:52 +08002
3#include <gtest/gtest.h>
4
5TEST(loadJsonConfig, testGoodPath)
6{
7 static constexpr auto jsonPath = "config/led-group-config.json";
Patrick Williams158b2c12022-03-17 05:57:44 -05008 auto ledMap = loadJsonConfig(jsonPath);
George Liudef5f5a2020-04-10 11:23:52 +08009
10 std::string objPath = "/xyz/openbmc_project/led/groups";
11 std::string bmcBooted = objPath + "/bmc_booted";
12 std::string powerOn = objPath + "/power_on";
Alexander Hansen4d44a552024-07-24 14:55:24 +020013 std::string powerOff = objPath + "/power_off";
George Liudef5f5a2020-04-10 11:23:52 +080014 std::string enclosureIdentify = objPath + "/enclosure_identify";
15
George Liu7f53a032021-05-04 11:18:21 +080016 ASSERT_EQ(ledMap.contains(bmcBooted), true);
17 ASSERT_EQ(ledMap.contains(powerOn), true);
Alexander Hansen4d44a552024-07-24 14:55:24 +020018 ASSERT_EQ(ledMap.contains(powerOff), true);
George Liu7f53a032021-05-04 11:18:21 +080019 ASSERT_EQ(ledMap.contains(enclosureIdentify), true);
George Liudef5f5a2020-04-10 11:23:52 +080020
Alexander Hansen7ba70c82024-07-23 13:46:25 +020021 auto& bmcBootedActions = ledMap.at(bmcBooted).actionSet;
22 auto& powerOnActions = ledMap.at(powerOn).actionSet;
Alexander Hansen4d44a552024-07-24 14:55:24 +020023 auto& powerOffActions = ledMap.at(powerOff).actionSet;
Alexander Hansen7ba70c82024-07-23 13:46:25 +020024 auto& enclosureIdentifyActions = ledMap.at(enclosureIdentify).actionSet;
George Liudef5f5a2020-04-10 11:23:52 +080025
26 for (const auto& group : bmcBootedActions)
27 {
28 ASSERT_EQ(group.name, "heartbeat");
Patrick Williamsed80e882022-03-17 05:03:51 -050029 ASSERT_EQ(group.action, phosphor::led::Layout::Action::On);
George Liudef5f5a2020-04-10 11:23:52 +080030 ASSERT_EQ(group.dutyOn, 50);
31 ASSERT_EQ(group.period, 0);
Alexander Hansen638d1482024-08-21 17:39:57 +020032 ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink);
George Liudef5f5a2020-04-10 11:23:52 +080033 }
34
35 for (const auto& group : powerOnActions)
36 {
37 ASSERT_EQ(group.name, "power");
Patrick Williamsed80e882022-03-17 05:03:51 -050038 ASSERT_EQ(group.action, phosphor::led::Layout::Action::On);
George Liudef5f5a2020-04-10 11:23:52 +080039 ASSERT_EQ(group.dutyOn, 50);
40 ASSERT_EQ(group.period, 0);
Patrick Williamsed80e882022-03-17 05:03:51 -050041 ASSERT_EQ(group.priority, phosphor::led::Layout::Action::On);
George Liudef5f5a2020-04-10 11:23:52 +080042 }
Alexander Hansen4d44a552024-07-24 14:55:24 +020043 for (const auto& group : powerOffActions)
44 {
45 ASSERT_EQ(group.name, "power_off_led");
46 ASSERT_EQ(group.action, phosphor::led::Layout::Action::Off);
47 ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Off);
48 }
George Liudef5f5a2020-04-10 11:23:52 +080049
50 for (const auto& group : enclosureIdentifyActions)
51 {
52 if (group.name == "front_id")
53 {
Patrick Williamsed80e882022-03-17 05:03:51 -050054 ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink);
George Liudef5f5a2020-04-10 11:23:52 +080055 ASSERT_EQ(group.dutyOn, 50);
56 ASSERT_EQ(group.period, 1000);
Alexander Hansen638d1482024-08-21 17:39:57 +020057 ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink);
George Liudef5f5a2020-04-10 11:23:52 +080058 }
59 else if (group.name == "rear_id")
60 {
Patrick Williamsed80e882022-03-17 05:03:51 -050061 ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink);
George Liudef5f5a2020-04-10 11:23:52 +080062 ASSERT_EQ(group.dutyOn, 50);
63 ASSERT_EQ(group.period, 1000);
Alexander Hansen638d1482024-08-21 17:39:57 +020064 ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink);
George Liudef5f5a2020-04-10 11:23:52 +080065 }
66 else
67 {
68 ASSERT_TRUE(false);
69 }
70 }
71}