1 #include <sdbusplus/bus.hpp> 2 #include <sdeventplus/event.hpp> 3 #include <systemd_target_signal.hpp> 4 5 #include <iostream> 6 7 #include <gtest/gtest.h> 8 9 // Enable debug by default for debug when needed 10 bool gVerbose = true; 11 12 TEST(TargetSignalData, BasicPaths) 13 { 14 // Create default data structure for testing 15 TargetErrorData targetData = { 16 {"multi-user.target", 17 {"xyz.openbmc_project.State.BMC.Error.MultiUserTargetFailure", 18 {"default"}}}, 19 {"obmc-chassis-poweron@0.target", 20 {"xyz.openbmc_project.State.Chassis.Error.PowerOnTargetFailure", 21 {"timeout", "failed"}}}}; 22 23 ServiceMonitorData serviceData = { 24 "xyz.openbmc_project.biosconfig_manager.service", 25 "xyz.openbmc_project.Dump.Manager.service"}; 26 27 auto bus = sdbusplus::bus::new_default(); 28 auto event = sdeventplus::Event::get_default(); 29 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 30 31 phosphor::state::manager::SystemdTargetLogging targetMon(targetData, 32 serviceData, bus); 33 34 std::string invalidUnit = "invalid_unit"; 35 std::string validError = "timeout"; 36 std::string errorToLog = targetMon.processError(invalidUnit, validError); 37 EXPECT_TRUE(errorToLog.empty()); 38 39 std::string validUnit = "obmc-chassis-poweron@0.target"; 40 std::string invalidError = "invalid_error"; 41 errorToLog = targetMon.processError(validUnit, invalidError); 42 EXPECT_TRUE(errorToLog.empty()); 43 44 errorToLog = targetMon.processError(validUnit, validError); 45 EXPECT_FALSE(errorToLog.empty()); 46 EXPECT_EQ(errorToLog, 47 "xyz.openbmc_project.State.Chassis.Error.PowerOnTargetFailure"); 48 } 49