blob: 630d57ca9fc64bf9531a972343ec32933a1131be [file] [log] [blame]
Andrew Geissler234a3172019-08-09 14:30:02 -05001#include <sdbusplus/bus.hpp>
2#include <sdeventplus/event.hpp>
3#include <systemd_target_signal.hpp>
4
5#include <iostream>
6
Andrew Geisslere426b582020-05-28 12:40:55 -05007#include <gtest/gtest.h>
8
Andrew Geissler234a3172019-08-09 14:30:02 -05009// Enable debug by default for debug when needed
10bool gVerbose = true;
11
12TEST(TargetSignalData, BasicPaths)
13{
Andrew Geissler234a3172019-08-09 14:30:02 -050014 // 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 Geisslerf3870c62022-02-10 16:15:28 -060023 ServiceMonitorData serviceData = {
24 "xyz.openbmc_project.biosconfig_manager.service",
25 "xyz.openbmc_project.Dump.Manager.service"};
26
Andrew Geissler234a3172019-08-09 14:30:02 -050027 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 Geisslerf3870c62022-02-10 16:15:28 -060031 phosphor::state::manager::SystemdTargetLogging targetMon(targetData,
32 serviceData, bus);
Andrew Geissler234a3172019-08-09 14:30:02 -050033
34 std::string invalidUnit = "invalid_unit";
35 std::string validError = "timeout";
Andrew Geisslerf3870c62022-02-10 16:15:28 -060036 std::string errorToLog = targetMon.processError(invalidUnit, validError);
37 EXPECT_TRUE(errorToLog.empty());
Andrew Geissler234a3172019-08-09 14:30:02 -050038
39 std::string validUnit = "obmc-chassis-poweron@0.target";
40 std::string invalidError = "invalid_error";
41 errorToLog = targetMon.processError(validUnit, invalidError);
Andrew Geisslerf3870c62022-02-10 16:15:28 -060042 EXPECT_TRUE(errorToLog.empty());
Andrew Geissler234a3172019-08-09 14:30:02 -050043
44 errorToLog = targetMon.processError(validUnit, validError);
Andrew Geisslerf3870c62022-02-10 16:15:28 -060045 EXPECT_FALSE(errorToLog.empty());
46 EXPECT_EQ(errorToLog,
Andrew Geissler234a3172019-08-09 14:30:02 -050047 "xyz.openbmc_project.State.Chassis.Error.PowerOnTargetFailure");
48}