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"; |
| 8 | LedMap ledMap = loadJsonConfig(jsonPath); |
| 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 | |
| 15 | ASSERT_NE(ledMap.find(bmcBooted), ledMap.end()); |
| 16 | ASSERT_NE(ledMap.find(powerOn), ledMap.end()); |
| 17 | ASSERT_NE(ledMap.find(enclosureIdentify), ledMap.end()); |
| 18 | |
| 19 | LedAction bmcBootedActions = ledMap.at(bmcBooted); |
| 20 | LedAction powerOnActions = ledMap.at(powerOn); |
| 21 | LedAction enclosureIdentifyActions = ledMap.at(enclosureIdentify); |
| 22 | |
| 23 | for (const auto& group : bmcBootedActions) |
| 24 | { |
| 25 | ASSERT_EQ(group.name, "heartbeat"); |
| 26 | ASSERT_EQ(group.action, phosphor::led::Layout::On); |
| 27 | ASSERT_EQ(group.dutyOn, 50); |
| 28 | ASSERT_EQ(group.period, 0); |
| 29 | ASSERT_EQ(group.priority, phosphor::led::Layout::Blink); |
| 30 | } |
| 31 | |
| 32 | for (const auto& group : powerOnActions) |
| 33 | { |
| 34 | ASSERT_EQ(group.name, "power"); |
| 35 | ASSERT_EQ(group.action, phosphor::led::Layout::On); |
| 36 | ASSERT_EQ(group.dutyOn, 50); |
| 37 | ASSERT_EQ(group.period, 0); |
| 38 | ASSERT_EQ(group.priority, phosphor::led::Layout::On); |
| 39 | } |
| 40 | |
| 41 | for (const auto& group : enclosureIdentifyActions) |
| 42 | { |
| 43 | if (group.name == "front_id") |
| 44 | { |
| 45 | ASSERT_EQ(group.action, phosphor::led::Layout::Blink); |
| 46 | ASSERT_EQ(group.dutyOn, 50); |
| 47 | ASSERT_EQ(group.period, 1000); |
| 48 | ASSERT_EQ(group.priority, phosphor::led::Layout::Blink); |
| 49 | } |
| 50 | else if (group.name == "rear_id") |
| 51 | { |
| 52 | ASSERT_EQ(group.action, phosphor::led::Layout::Blink); |
| 53 | ASSERT_EQ(group.dutyOn, 50); |
| 54 | ASSERT_EQ(group.period, 1000); |
| 55 | ASSERT_EQ(group.priority, phosphor::led::Layout::Blink); |
| 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{}; |
| 73 | validatePriority("heartbeat", phosphor::led::Layout::Blink, priorityMap); |
| 74 | validatePriority("power", phosphor::led::Layout::On, priorityMap); |
| 75 | |
| 76 | ASSERT_EQ(priorityMap.at("heartbeat"), phosphor::led::Layout::Blink); |
| 77 | ASSERT_EQ(priorityMap.at("power"), phosphor::led::Layout::On); |
| 78 | } |
| 79 | |
| 80 | TEST(validatePriority, testBadPriority) |
| 81 | { |
| 82 | PriorityMap priorityMap{}; |
| 83 | validatePriority("heartbeat", phosphor::led::Layout::Blink, priorityMap); |
| 84 | |
| 85 | ASSERT_EQ(priorityMap.at("heartbeat"), phosphor::led::Layout::Blink); |
| 86 | ASSERT_THROW( |
| 87 | validatePriority("heartbeat", phosphor::led::Layout::On, priorityMap), |
| 88 | std::runtime_error); |
George Liu | def5f5a | 2020-04-10 11:23:52 +0800 | [diff] [blame] | 89 | } |