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"; |
| 13 | std::string enclosureIdentify = objPath + "/enclosure_identify"; |
| 14 | |
George Liu | 7f53a03 | 2021-05-04 11:18:21 +0800 | [diff] [blame] | 15 | ASSERT_EQ(ledMap.contains(bmcBooted), true); |
| 16 | ASSERT_EQ(ledMap.contains(powerOn), true); |
| 17 | ASSERT_EQ(ledMap.contains(enclosureIdentify), true); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 18 | |
Patrick Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame^] | 19 | auto& bmcBootedActions = ledMap.at(bmcBooted); |
| 20 | auto& powerOnActions = ledMap.at(powerOn); |
| 21 | auto& enclosureIdentifyActions = ledMap.at(enclosureIdentify); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 22 | |
| 23 | for (const auto& group : bmcBootedActions) |
| 24 | { |
| 25 | ASSERT_EQ(group.name, "heartbeat"); |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 26 | ASSERT_EQ(group.action, phosphor::led::Layout::Action::On); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 27 | ASSERT_EQ(group.dutyOn, 50); |
| 28 | ASSERT_EQ(group.period, 0); |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 29 | ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | for (const auto& group : powerOnActions) |
| 33 | { |
| 34 | ASSERT_EQ(group.name, "power"); |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 35 | ASSERT_EQ(group.action, phosphor::led::Layout::Action::On); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 36 | ASSERT_EQ(group.dutyOn, 50); |
| 37 | ASSERT_EQ(group.period, 0); |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 38 | ASSERT_EQ(group.priority, phosphor::led::Layout::Action::On); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | for (const auto& group : enclosureIdentifyActions) |
| 42 | { |
| 43 | if (group.name == "front_id") |
| 44 | { |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 45 | ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 46 | ASSERT_EQ(group.dutyOn, 50); |
| 47 | ASSERT_EQ(group.period, 1000); |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 48 | ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 49 | } |
| 50 | else if (group.name == "rear_id") |
| 51 | { |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 52 | ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 53 | ASSERT_EQ(group.dutyOn, 50); |
| 54 | ASSERT_EQ(group.period, 1000); |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 55 | ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 56 | } |
| 57 | else |
| 58 | { |
| 59 | ASSERT_TRUE(false); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | TEST(loadJsonConfig, testBadPath) |
| 65 | { |
| 66 | static constexpr auto jsonPath = "config/led-group-config-malformed.json"; |
| 67 | ASSERT_THROW(loadJsonConfig(jsonPath), std::exception); |
George Liu | 17fcb4d | 2020-06-30 18:12:53 +0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | TEST(validatePriority, testGoodPriority) |
| 71 | { |
| 72 | PriorityMap priorityMap{}; |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 73 | validatePriority("heartbeat", phosphor::led::Layout::Action::Blink, |
| 74 | priorityMap); |
| 75 | validatePriority("power", phosphor::led::Layout::Action::On, priorityMap); |
George Liu | 17fcb4d | 2020-06-30 18:12:53 +0800 | [diff] [blame] | 76 | |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 77 | ASSERT_EQ(priorityMap.at("heartbeat"), |
| 78 | phosphor::led::Layout::Action::Blink); |
| 79 | ASSERT_EQ(priorityMap.at("power"), phosphor::led::Layout::Action::On); |
George Liu | 17fcb4d | 2020-06-30 18:12:53 +0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | TEST(validatePriority, testBadPriority) |
| 83 | { |
| 84 | PriorityMap priorityMap{}; |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 85 | validatePriority("heartbeat", phosphor::led::Layout::Action::Blink, |
| 86 | priorityMap); |
George Liu | 17fcb4d | 2020-06-30 18:12:53 +0800 | [diff] [blame] | 87 | |
Patrick Williams | ed80e88 | 2022-03-17 05:03:51 -0500 | [diff] [blame] | 88 | 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 Williams | 158b2c1 | 2022-03-17 05:57:44 -0500 | [diff] [blame^] | 94 | } |