blob: cd4b9806f42ae9bc70ac05ad16f83ed8e7f4e1a1 [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
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}