Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 1 | #include <sdbusplus/bus.hpp> |
| 2 | #include <sdeventplus/event.hpp> |
| 3 | #include <systemd_target_signal.hpp> |
| 4 | |
| 5 | #include <iostream> |
| 6 | |
Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 7 | #include <gtest/gtest.h> |
| 8 | |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 9 | // Enable debug by default for debug when needed |
| 10 | bool gVerbose = true; |
| 11 | |
| 12 | TEST(TargetSignalData, BasicPaths) |
| 13 | { |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 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 | |
Andrew Geissler | f3870c6 | 2022-02-10 16:15:28 -0600 | [diff] [blame] | 23 | ServiceMonitorData serviceData = { |
| 24 | "xyz.openbmc_project.biosconfig_manager.service", |
| 25 | "xyz.openbmc_project.Dump.Manager.service"}; |
| 26 | |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 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 | |
Andrew Geissler | f3870c6 | 2022-02-10 16:15:28 -0600 | [diff] [blame] | 31 | phosphor::state::manager::SystemdTargetLogging targetMon(targetData, |
| 32 | serviceData, bus); |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 33 | |
| 34 | std::string invalidUnit = "invalid_unit"; |
| 35 | std::string validError = "timeout"; |
Andrew Geissler | f3870c6 | 2022-02-10 16:15:28 -0600 | [diff] [blame] | 36 | std::string errorToLog = targetMon.processError(invalidUnit, validError); |
| 37 | EXPECT_TRUE(errorToLog.empty()); |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 38 | |
| 39 | std::string validUnit = "obmc-chassis-poweron@0.target"; |
| 40 | std::string invalidError = "invalid_error"; |
| 41 | errorToLog = targetMon.processError(validUnit, invalidError); |
Andrew Geissler | f3870c6 | 2022-02-10 16:15:28 -0600 | [diff] [blame] | 42 | EXPECT_TRUE(errorToLog.empty()); |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 43 | |
| 44 | errorToLog = targetMon.processError(validUnit, validError); |
Andrew Geissler | f3870c6 | 2022-02-10 16:15:28 -0600 | [diff] [blame] | 45 | EXPECT_FALSE(errorToLog.empty()); |
| 46 | EXPECT_EQ(errorToLog, |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 47 | "xyz.openbmc_project.State.Chassis.Error.PowerOnTargetFailure"); |
| 48 | } |