blob: ce0a29964c292f4439e948fdbb1d0244456fb1a8 [file] [log] [blame]
Andrew Geissler234a3172019-08-09 14:30:02 -05001#include <gtest/gtest.h>
2#include <sdbusplus/bus.hpp>
3#include <sdeventplus/event.hpp>
4#include <systemd_target_signal.hpp>
5
6#include <iostream>
7
8// Enable debug by default for debug when needed
9bool gVerbose = true;
10
11TEST(TargetSignalData, BasicPaths)
12{
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 auto bus = sdbusplus::bus::new_default();
24 auto event = sdeventplus::Event::get_default();
25 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
26
27 phosphor::state::manager::SystemdTargetLogging targetMon(targetData, bus);
28
29 std::string invalidUnit = "invalid_unit";
30 std::string validError = "timeout";
31 const std::string* errorToLog =
32 targetMon.processError(invalidUnit, validError);
33 EXPECT_EQ(errorToLog, nullptr);
34
35 std::string validUnit = "obmc-chassis-poweron@0.target";
36 std::string invalidError = "invalid_error";
37 errorToLog = targetMon.processError(validUnit, invalidError);
38 EXPECT_EQ(errorToLog, nullptr);
39
40 errorToLog = targetMon.processError(validUnit, validError);
41 EXPECT_NE(errorToLog, nullptr);
42 EXPECT_EQ(*errorToLog,
43 "xyz.openbmc_project.State.Chassis.Error.PowerOnTargetFailure");
44}