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 
15     // Create default data structure for testing
16     TargetErrorData targetData = {
17         {"multi-user.target",
18          {"xyz.openbmc_project.State.BMC.Error.MultiUserTargetFailure",
19           {"default"}}},
20         {"obmc-chassis-poweron@0.target",
21          {"xyz.openbmc_project.State.Chassis.Error.PowerOnTargetFailure",
22           {"timeout", "failed"}}}};
23 
24     auto bus = sdbusplus::bus::new_default();
25     auto event = sdeventplus::Event::get_default();
26     bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
27 
28     phosphor::state::manager::SystemdTargetLogging targetMon(targetData, bus);
29 
30     std::string invalidUnit = "invalid_unit";
31     std::string validError = "timeout";
32     const std::string* errorToLog =
33         targetMon.processError(invalidUnit, validError);
34     EXPECT_EQ(errorToLog, nullptr);
35 
36     std::string validUnit = "obmc-chassis-poweron@0.target";
37     std::string invalidError = "invalid_error";
38     errorToLog = targetMon.processError(validUnit, invalidError);
39     EXPECT_EQ(errorToLog, nullptr);
40 
41     errorToLog = targetMon.processError(validUnit, validError);
42     EXPECT_NE(errorToLog, nullptr);
43     EXPECT_EQ(*errorToLog,
44               "xyz.openbmc_project.State.Chassis.Error.PowerOnTargetFailure");
45 }
46