blob: afd4505cbeef031a335e25adbb80e75211dc5c84 [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";
13 std::string enclosureIdentify = objPath + "/enclosure_identify";
14
George Liu7f53a032021-05-04 11:18:21 +080015 ASSERT_EQ(ledMap.contains(bmcBooted), true);
16 ASSERT_EQ(ledMap.contains(powerOn), true);
17 ASSERT_EQ(ledMap.contains(enclosureIdentify), true);
George Liudef5f5a2020-04-10 11:23:52 +080018
Alexander Hansen7ba70c82024-07-23 13:46:25 +020019 auto& bmcBootedActions = ledMap.at(bmcBooted).actionSet;
20 auto& powerOnActions = ledMap.at(powerOn).actionSet;
21 auto& enclosureIdentifyActions = ledMap.at(enclosureIdentify).actionSet;
George Liudef5f5a2020-04-10 11:23:52 +080022
23 for (const auto& group : bmcBootedActions)
24 {
25 ASSERT_EQ(group.name, "heartbeat");
Patrick Williamsed80e882022-03-17 05:03:51 -050026 ASSERT_EQ(group.action, phosphor::led::Layout::Action::On);
George Liudef5f5a2020-04-10 11:23:52 +080027 ASSERT_EQ(group.dutyOn, 50);
28 ASSERT_EQ(group.period, 0);
Alexander Hansen55badf72024-07-24 14:35:13 +020029 ASSERT_EQ(group.priority, std::nullopt);
George Liudef5f5a2020-04-10 11:23:52 +080030 }
31
32 for (const auto& group : powerOnActions)
33 {
34 ASSERT_EQ(group.name, "power");
Patrick Williamsed80e882022-03-17 05:03:51 -050035 ASSERT_EQ(group.action, phosphor::led::Layout::Action::On);
George Liudef5f5a2020-04-10 11:23:52 +080036 ASSERT_EQ(group.dutyOn, 50);
37 ASSERT_EQ(group.period, 0);
Patrick Williamsed80e882022-03-17 05:03:51 -050038 ASSERT_EQ(group.priority, phosphor::led::Layout::Action::On);
George Liudef5f5a2020-04-10 11:23:52 +080039 }
40
41 for (const auto& group : enclosureIdentifyActions)
42 {
43 if (group.name == "front_id")
44 {
Patrick Williamsed80e882022-03-17 05:03:51 -050045 ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink);
George Liudef5f5a2020-04-10 11:23:52 +080046 ASSERT_EQ(group.dutyOn, 50);
47 ASSERT_EQ(group.period, 1000);
Alexander Hansen55badf72024-07-24 14:35:13 +020048 ASSERT_EQ(group.priority, std::nullopt);
George Liudef5f5a2020-04-10 11:23:52 +080049 }
50 else if (group.name == "rear_id")
51 {
Patrick Williamsed80e882022-03-17 05:03:51 -050052 ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink);
George Liudef5f5a2020-04-10 11:23:52 +080053 ASSERT_EQ(group.dutyOn, 50);
54 ASSERT_EQ(group.period, 1000);
Alexander Hansen55badf72024-07-24 14:35:13 +020055 ASSERT_EQ(group.priority, std::nullopt);
George Liudef5f5a2020-04-10 11:23:52 +080056 }
57 else
58 {
59 ASSERT_TRUE(false);
60 }
61 }
62}
63
64TEST(loadJsonConfig, testBadPath)
65{
66 static constexpr auto jsonPath = "config/led-group-config-malformed.json";
67 ASSERT_THROW(loadJsonConfig(jsonPath), std::exception);
George Liu17fcb4d2020-06-30 18:12:53 +080068}
69
70TEST(validatePriority, testGoodPriority)
71{
72 PriorityMap priorityMap{};
Patrick Williamsed80e882022-03-17 05:03:51 -050073 validatePriority("heartbeat", phosphor::led::Layout::Action::Blink,
74 priorityMap);
75 validatePriority("power", phosphor::led::Layout::Action::On, priorityMap);
George Liu17fcb4d2020-06-30 18:12:53 +080076
Patrick Williamsed80e882022-03-17 05:03:51 -050077 ASSERT_EQ(priorityMap.at("heartbeat"),
78 phosphor::led::Layout::Action::Blink);
79 ASSERT_EQ(priorityMap.at("power"), phosphor::led::Layout::Action::On);
George Liu17fcb4d2020-06-30 18:12:53 +080080}
81
82TEST(validatePriority, testBadPriority)
83{
84 PriorityMap priorityMap{};
Patrick Williamsed80e882022-03-17 05:03:51 -050085 validatePriority("heartbeat", phosphor::led::Layout::Action::Blink,
86 priorityMap);
George Liu17fcb4d2020-06-30 18:12:53 +080087
Patrick Williamsed80e882022-03-17 05:03:51 -050088 ASSERT_EQ(priorityMap.at("heartbeat"),
89 phosphor::led::Layout::Action::Blink);
90 ASSERT_THROW(validatePriority("heartbeat",
91 phosphor::led::Layout::Action::On,
92 priorityMap),
93 std::runtime_error);
Patrick Williams158b2c12022-03-17 05:57:44 -050094}