blob: fa9161b9744586e5156e9542a4dbda7a5a213124 [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 Hansen55badf72024-07-24 14:35:13 +020032 ASSERT_EQ(group.priority, std::nullopt);
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 Hansen55badf72024-07-24 14:35:13 +020057 ASSERT_EQ(group.priority, std::nullopt);
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 Hansen55badf72024-07-24 14:35:13 +020064 ASSERT_EQ(group.priority, std::nullopt);
George Liudef5f5a2020-04-10 11:23:52 +080065 }
66 else
67 {
68 ASSERT_TRUE(false);
69 }
70 }
71}
72
73TEST(loadJsonConfig, testBadPath)
74{
75 static constexpr auto jsonPath = "config/led-group-config-malformed.json";
76 ASSERT_THROW(loadJsonConfig(jsonPath), std::exception);
George Liu17fcb4d2020-06-30 18:12:53 +080077}
78
79TEST(validatePriority, testGoodPriority)
80{
81 PriorityMap priorityMap{};
Patrick Williamsed80e882022-03-17 05:03:51 -050082 validatePriority("heartbeat", phosphor::led::Layout::Action::Blink,
83 priorityMap);
84 validatePriority("power", phosphor::led::Layout::Action::On, priorityMap);
George Liu17fcb4d2020-06-30 18:12:53 +080085
Patrick Williamsed80e882022-03-17 05:03:51 -050086 ASSERT_EQ(priorityMap.at("heartbeat"),
87 phosphor::led::Layout::Action::Blink);
88 ASSERT_EQ(priorityMap.at("power"), phosphor::led::Layout::Action::On);
George Liu17fcb4d2020-06-30 18:12:53 +080089}
90
91TEST(validatePriority, testBadPriority)
92{
93 PriorityMap priorityMap{};
Patrick Williamsed80e882022-03-17 05:03:51 -050094 validatePriority("heartbeat", phosphor::led::Layout::Action::Blink,
95 priorityMap);
George Liu17fcb4d2020-06-30 18:12:53 +080096
Patrick Williamsed80e882022-03-17 05:03:51 -050097 ASSERT_EQ(priorityMap.at("heartbeat"),
98 phosphor::led::Layout::Action::Blink);
99 ASSERT_THROW(validatePriority("heartbeat",
100 phosphor::led::Layout::Action::On,
101 priorityMap),
102 std::runtime_error);
Patrick Williams158b2c12022-03-17 05:57:44 -0500103}