George Liu | 616a071 | 2021-02-18 10:50:24 +0800 | [diff] [blame] | 1 | #include "json-parser.hpp" |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 2 | |
| 3 | #include <gtest/gtest.h> |
| 4 | |
| 5 | TEST(loadJsonConfig, testGoodPath) |
| 6 | { |
| 7 | static constexpr auto jsonPath = "config/led-group-config.json"; |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame] | 8 | auto ledMap = loadJsonConfig(jsonPath); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 9 | |
| 10 | std::string objPath = "/xyz/openbmc_project/led/groups"; |
| 11 | std::string bmcBooted = objPath + "/bmc_booted"; |
| 12 | std::string powerOn = objPath + "/power_on"; |
Alexander Hansen | 4d44a55 | 2024-07-24 14:55:24 +0200 | [diff] [blame] | 13 | std::string powerOff = objPath + "/power_off"; |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 14 | std::string enclosureIdentify = objPath + "/enclosure_identify"; |
| 15 | |
George Liu | 7f53a03 | 2021-05-04 11:18:21 +0800 | [diff] [blame] | 16 | ASSERT_EQ(ledMap.contains(bmcBooted), true); |
| 17 | ASSERT_EQ(ledMap.contains(powerOn), true); |
Alexander Hansen | 4d44a55 | 2024-07-24 14:55:24 +0200 | [diff] [blame] | 18 | ASSERT_EQ(ledMap.contains(powerOff), true); |
George Liu | 7f53a03 | 2021-05-04 11:18:21 +0800 | [diff] [blame] | 19 | ASSERT_EQ(ledMap.contains(enclosureIdentify), true); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 20 | |
Alexander Hansen | 7ba70c8 | 2024-07-23 13:46:25 +0200 | [diff] [blame] | 21 | auto& bmcBootedActions = ledMap.at(bmcBooted).actionSet; |
| 22 | auto& powerOnActions = ledMap.at(powerOn).actionSet; |
Alexander Hansen | 4d44a55 | 2024-07-24 14:55:24 +0200 | [diff] [blame] | 23 | auto& powerOffActions = ledMap.at(powerOff).actionSet; |
Alexander Hansen | 7ba70c8 | 2024-07-23 13:46:25 +0200 | [diff] [blame] | 24 | auto& enclosureIdentifyActions = ledMap.at(enclosureIdentify).actionSet; |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 25 | |
| 26 | for (const auto& group : bmcBootedActions) |
| 27 | { |
| 28 | ASSERT_EQ(group.name, "heartbeat"); |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 29 | ASSERT_EQ(group.action, phosphor::led::Layout::Action::On); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 30 | ASSERT_EQ(group.dutyOn, 50); |
| 31 | ASSERT_EQ(group.period, 0); |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 32 | ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | for (const auto& group : powerOnActions) |
| 36 | { |
| 37 | ASSERT_EQ(group.name, "power"); |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 38 | ASSERT_EQ(group.action, phosphor::led::Layout::Action::On); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 39 | ASSERT_EQ(group.dutyOn, 50); |
| 40 | ASSERT_EQ(group.period, 0); |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 41 | ASSERT_EQ(group.priority, phosphor::led::Layout::Action::On); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 42 | } |
Alexander Hansen | 4d44a55 | 2024-07-24 14:55:24 +0200 | [diff] [blame] | 43 | 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 Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 49 | |
| 50 | for (const auto& group : enclosureIdentifyActions) |
| 51 | { |
| 52 | if (group.name == "front_id") |
| 53 | { |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 54 | ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 55 | ASSERT_EQ(group.dutyOn, 50); |
| 56 | ASSERT_EQ(group.period, 1000); |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 57 | ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 58 | } |
| 59 | else if (group.name == "rear_id") |
| 60 | { |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 61 | ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 62 | ASSERT_EQ(group.dutyOn, 50); |
| 63 | ASSERT_EQ(group.period, 1000); |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 64 | ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 65 | } |
| 66 | else |
| 67 | { |
| 68 | ASSERT_TRUE(false); |
| 69 | } |
| 70 | } |
| 71 | } |