blob: 7f7ce55cef9a0176881a07fa9538720f4b2e38d6 [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{
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
Andrew Geisslerf3870c62022-02-10 16:15:28 -060024 ServiceMonitorData serviceData = {
25 "xyz.openbmc_project.biosconfig_manager.service",
26 "xyz.openbmc_project.Dump.Manager.service"};
27
Andrew Geissler234a3172019-08-09 14:30:02 -050028 auto bus = sdbusplus::bus::new_default();
29 auto event = sdeventplus::Event::get_default();
30 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
31
Andrew Geisslerf3870c62022-02-10 16:15:28 -060032 phosphor::state::manager::SystemdTargetLogging targetMon(targetData,
33 serviceData, bus);
Andrew Geissler234a3172019-08-09 14:30:02 -050034
35 std::string invalidUnit = "invalid_unit";
36 std::string validError = "timeout";
Andrew Geisslerf3870c62022-02-10 16:15:28 -060037 std::string errorToLog = targetMon.processError(invalidUnit, validError);
38 EXPECT_TRUE(errorToLog.empty());
Andrew Geissler234a3172019-08-09 14:30:02 -050039
40 std::string validUnit = "obmc-chassis-poweron@0.target";
41 std::string invalidError = "invalid_error";
42 errorToLog = targetMon.processError(validUnit, invalidError);
Andrew Geisslerf3870c62022-02-10 16:15:28 -060043 EXPECT_TRUE(errorToLog.empty());
Andrew Geissler234a3172019-08-09 14:30:02 -050044
45 errorToLog = targetMon.processError(validUnit, validError);
Andrew Geisslerf3870c62022-02-10 16:15:28 -060046 EXPECT_FALSE(errorToLog.empty());
47 EXPECT_EQ(errorToLog,
Andrew Geissler234a3172019-08-09 14:30:02 -050048 "xyz.openbmc_project.State.Chassis.Error.PowerOnTargetFailure");
49}