regulators: Create error log entries
Create error log entries when the following regulator operations fail:
* configuration
* presence detection
* sensor monitoring
* closing I2C devices
Use the recently created error_logging_utils namespace to create error
logs based on caught exceptions.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I25824ecfdaa270abbce92b52bdea0602271d926d
diff --git a/phosphor-regulators/test/presence_detection_tests.cpp b/phosphor-regulators/test/presence_detection_tests.cpp
index f489b7f..e89af2c 100644
--- a/phosphor-regulators/test/presence_detection_tests.cpp
+++ b/phosphor-regulators/test/presence_detection_tests.cpp
@@ -19,6 +19,7 @@
#include "device.hpp"
#include "i2c_interface.hpp"
#include "mock_action.hpp"
+#include "mock_error_logging.hpp"
#include "mock_journal.hpp"
#include "mock_presence_service.hpp"
#include "mock_services.hpp"
@@ -27,6 +28,8 @@
#include "rule.hpp"
#include "system.hpp"
+#include <sdbusplus/exception.hpp>
+
#include <memory>
#include <stdexcept>
#include <string>
@@ -39,10 +42,40 @@
using namespace phosphor::power::regulators;
+using ::testing::Ref;
using ::testing::Return;
using ::testing::Throw;
/**
+ * Concrete subclass of sdbusplus::exception_t abstract base class.
+ */
+class TestSDBusError : public sdbusplus::exception_t
+{
+ public:
+ TestSDBusError(const std::string& error) : error{error}
+ {
+ }
+
+ const char* what() const noexcept override
+ {
+ return error.c_str();
+ }
+
+ const char* name() const noexcept override
+ {
+ return "";
+ }
+
+ const char* description() const noexcept override
+ {
+ return "";
+ }
+
+ private:
+ const std::string error{};
+};
+
+/**
* Creates the parent objects that normally contain a PresenceDetection object.
*
* A PresenceDetection object is normally contained within a hierarchy of
@@ -239,8 +272,7 @@
isPresent("/xyz/openbmc_project/inventory/system/chassis/"
"motherboard/cpu2"))
.Times(1)
- .WillOnce(
- Throw(std::runtime_error{"DBusError: Invalid object path."}));
+ .WillOnce(Throw(TestSDBusError{"DBusError: Invalid object path."}));
// Define expected journal messages that should be passed to MockJournal
MockJournal& journal = services.getMockJournal();
@@ -254,6 +286,12 @@
logError("Unable to determine presence of vdd_reg"))
.Times(1);
+ // Expect logDBusError() to be called
+ MockErrorLogging& errorLogging = services.getMockErrorLogging();
+ EXPECT_CALL(errorLogging,
+ logDBusError(Entry::Level::Warning, Ref(journal)))
+ .Times(1);
+
// Execute PresenceDetection. Should return true when an error occurs.
EXPECT_TRUE(detection->execute(services, *system, *chassis, *device));