crit-service: create error on failed service

This enhances the existing code to support logging an error when a
monitored service fails. The same systemd event is triggered for a
target failure and a service failure so no new logic is needed in
that area.

Tested:
- Repeatedly killed the host-state service until its unit went into the
  failed state. Verified this was detected and the expected log was
  created.

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I459dd8c35ceddec986336fee635fdf691257f758
diff --git a/test/systemd_signal.cpp b/test/systemd_signal.cpp
index cd4b980..7f7ce55 100644
--- a/test/systemd_signal.cpp
+++ b/test/systemd_signal.cpp
@@ -21,25 +21,29 @@
          {"xyz.openbmc_project.State.Chassis.Error.PowerOnTargetFailure",
           {"timeout", "failed"}}}};
 
+    ServiceMonitorData serviceData = {
+        "xyz.openbmc_project.biosconfig_manager.service",
+        "xyz.openbmc_project.Dump.Manager.service"};
+
     auto bus = sdbusplus::bus::new_default();
     auto event = sdeventplus::Event::get_default();
     bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
 
-    phosphor::state::manager::SystemdTargetLogging targetMon(targetData, bus);
+    phosphor::state::manager::SystemdTargetLogging targetMon(targetData,
+                                                             serviceData, bus);
 
     std::string invalidUnit = "invalid_unit";
     std::string validError = "timeout";
-    const std::string* errorToLog =
-        targetMon.processError(invalidUnit, validError);
-    EXPECT_EQ(errorToLog, nullptr);
+    std::string errorToLog = targetMon.processError(invalidUnit, validError);
+    EXPECT_TRUE(errorToLog.empty());
 
     std::string validUnit = "obmc-chassis-poweron@0.target";
     std::string invalidError = "invalid_error";
     errorToLog = targetMon.processError(validUnit, invalidError);
-    EXPECT_EQ(errorToLog, nullptr);
+    EXPECT_TRUE(errorToLog.empty());
 
     errorToLog = targetMon.processError(validUnit, validError);
-    EXPECT_NE(errorToLog, nullptr);
-    EXPECT_EQ(*errorToLog,
+    EXPECT_FALSE(errorToLog.empty());
+    EXPECT_EQ(errorToLog,
               "xyz.openbmc_project.State.Chassis.Error.PowerOnTargetFailure");
 }