1 #include "json-parser.hpp" 2 3 #include <gtest/gtest.h> 4 5 TEST(loadJsonConfig, testGoodPath) 6 { 7 static constexpr auto jsonPath = "config/led-group-config.json"; 8 auto 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 powerOff = objPath + "/power_off"; 14 std::string enclosureIdentify = objPath + "/enclosure_identify"; 15 16 ASSERT_EQ(ledMap.contains(bmcBooted), true); 17 ASSERT_EQ(ledMap.contains(powerOn), true); 18 ASSERT_EQ(ledMap.contains(powerOff), true); 19 ASSERT_EQ(ledMap.contains(enclosureIdentify), true); 20 21 auto& bmcBootedActions = ledMap.at(bmcBooted).actionSet; 22 auto& powerOnActions = ledMap.at(powerOn).actionSet; 23 auto& powerOffActions = ledMap.at(powerOff).actionSet; 24 auto& enclosureIdentifyActions = ledMap.at(enclosureIdentify).actionSet; 25 26 for (const auto& group : bmcBootedActions) 27 { 28 ASSERT_EQ(group.name, "heartbeat"); 29 ASSERT_EQ(group.action, phosphor::led::Layout::Action::On); 30 ASSERT_EQ(group.dutyOn, 50); 31 ASSERT_EQ(group.period, 0); 32 ASSERT_EQ(group.priority, std::nullopt); 33 } 34 35 for (const auto& group : powerOnActions) 36 { 37 ASSERT_EQ(group.name, "power"); 38 ASSERT_EQ(group.action, phosphor::led::Layout::Action::On); 39 ASSERT_EQ(group.dutyOn, 50); 40 ASSERT_EQ(group.period, 0); 41 ASSERT_EQ(group.priority, phosphor::led::Layout::Action::On); 42 } 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 } 49 50 for (const auto& group : enclosureIdentifyActions) 51 { 52 if (group.name == "front_id") 53 { 54 ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink); 55 ASSERT_EQ(group.dutyOn, 50); 56 ASSERT_EQ(group.period, 1000); 57 ASSERT_EQ(group.priority, std::nullopt); 58 } 59 else if (group.name == "rear_id") 60 { 61 ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink); 62 ASSERT_EQ(group.dutyOn, 50); 63 ASSERT_EQ(group.period, 1000); 64 ASSERT_EQ(group.priority, std::nullopt); 65 } 66 else 67 { 68 ASSERT_TRUE(false); 69 } 70 } 71 } 72 73 TEST(loadJsonConfig, testBadPath) 74 { 75 static constexpr auto jsonPath = "config/led-group-config-malformed.json"; 76 ASSERT_THROW(loadJsonConfig(jsonPath), std::exception); 77 } 78 79 TEST(validatePriority, testGoodPriority) 80 { 81 PriorityMap priorityMap{}; 82 validatePriority("heartbeat", phosphor::led::Layout::Action::Blink, 83 priorityMap); 84 validatePriority("power", phosphor::led::Layout::Action::On, priorityMap); 85 86 ASSERT_EQ(priorityMap.at("heartbeat"), 87 phosphor::led::Layout::Action::Blink); 88 ASSERT_EQ(priorityMap.at("power"), phosphor::led::Layout::Action::On); 89 } 90 91 TEST(validatePriority, testBadPriority) 92 { 93 PriorityMap priorityMap{}; 94 validatePriority("heartbeat", phosphor::led::Layout::Action::Blink, 95 priorityMap); 96 97 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); 103 } 104