Add failsafe logger for zones
Tested:
...
Nov 23 21:40:06 tmddp10-nfd01.prod.google.com swampd[4893]:
Zone `0` is in failsafe mode.
With update at `fleeting0`: The sensor has bad readings.
Nov 23 21:40:06 tmddp10-nfd01.prod.google.com swampd[4893]:
Zone `1` is in failsafe mode.
With update at `fleeting1`: The sensor has bad readings.
Nov 23 21:40:06 tmddp10-nfd01.prod.google.com swampd[4893]:
Zone `1` leaves failsafe mode.
With update at `hotswap_in_Input_Power`: The sensor has recovered.
Nov 23 21:40:06 tmddp10-nfd01.prod.google.com swampd[4893]:
Zone `0` leaves failsafe mode.
With update at `hotswap_in_Input_Power`: The sensor has recovered.
...
Change-Id: I2c296addb7ad117c03c04a27de91204796cda036
Signed-off-by: James Zheng <alphetis@google.com>
diff --git a/test/dbus_passive_unittest.cpp b/test/dbus_passive_unittest.cpp
index 3066ab7..f37addf 100644
--- a/test/dbus_passive_unittest.cpp
+++ b/test/dbus_passive_unittest.cpp
@@ -1,5 +1,8 @@
#include "conf.hpp"
#include "dbus/dbuspassive.hpp"
+#include "failsafeloggers/builder.hpp"
+#include "failsafeloggers/failsafe_logger.hpp"
+#include "failsafeloggers/failsafe_logger_utility.hpp"
#include "test/dbushelper_mock.hpp"
#include <sdbusplus/test/sdbus_mock.hpp>
diff --git a/test/meson.build b/test/meson.build
index 50f71a3..61b8b26 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -39,7 +39,8 @@
'dbus_active_unittest': ['../dbus/dbusactiveread.cpp'],
'dbus_passive_unittest': ['../dbus/dbuspassive.cpp',
'../dbus/dbuspassiveredundancy.cpp',
- '../dbus/dbusutil.cpp'],
+ '../dbus/dbusutil.cpp',
+ '../failsafeloggers/failsafe_logger_utility.cpp'],
'dbus_util_unittest': ['../dbus/dbusutil.cpp'],
'json_parse_unittest': ['../buildjson/buildjson.cpp'],
'pid_json_unittest': ['../pid/buildjson.cpp',
@@ -60,13 +61,18 @@
'../pid/thermalcontroller.cpp',
'../pid/tuning.cpp',
'../pid/util.cpp'],
- 'pid_zone_unittest': ['../pid/ec/pid.cpp',
+ 'pid_zone_unittest': ['../failsafeloggers/builder.cpp',
+ '../failsafeloggers/failsafe_logger.cpp',
+ '../failsafeloggers/failsafe_logger_utility.cpp',
+ '../pid/ec/pid.cpp',
'../pid/ec/logging.cpp',
'../pid/pidcontroller.cpp',
'../pid/tuning.cpp',
'../pid/zone.cpp',
'../sensors/manager.cpp'],
- 'sensor_host_unittest': ['../sensors/host.cpp'],
+ 'sensor_host_unittest': ['../failsafeloggers/failsafe_logger.cpp',
+ '../failsafeloggers/failsafe_logger_utility.cpp',
+ '../sensors/host.cpp'],
'sensor_manager_unittest': ['../sensors/manager.cpp'],
'sensor_pluggable_unittest': ['../sensors/pluggable.cpp'],
'sensors_json_unittest': ['../sensors/buildjson.cpp'],
diff --git a/test/pid_fancontroller_unittest.cpp b/test/pid_fancontroller_unittest.cpp
index 6075a95..97dda0a 100644
--- a/test/pid_fancontroller_unittest.cpp
+++ b/test/pid_fancontroller_unittest.cpp
@@ -1,5 +1,8 @@
#include "config.h"
+#include "failsafeloggers/builder.hpp"
+#include "failsafeloggers/failsafe_logger.hpp"
+#include "failsafeloggers/failsafe_logger_utility.hpp"
#include "pid/ec/logging.hpp"
#include "pid/ec/pid.hpp"
#include "pid/fancontroller.hpp"
diff --git a/test/pid_zone_unittest.cpp b/test/pid_zone_unittest.cpp
index 5155971..47b3f97 100644
--- a/test/pid_zone_unittest.cpp
+++ b/test/pid_zone_unittest.cpp
@@ -1,3 +1,6 @@
+#include "failsafeloggers/builder.hpp"
+#include "failsafeloggers/failsafe_logger.hpp"
+#include "failsafeloggers/failsafe_logger_utility.hpp"
#include "pid/ec/logging.hpp"
#include "pid/ec/pid.hpp"
#include "pid/zone.hpp"
@@ -10,6 +13,7 @@
#include <chrono>
#include <cstring>
+#include <unordered_map>
#include <vector>
#include <gmock/gmock.h>
@@ -344,6 +348,10 @@
// This test will add a couple thermal inputs, and verify that the zone
// initializes into failsafe mode, and will read each sensor.
+ // Disable failsafe logger for the unit test.
+ std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map;
+ buildFailsafeLoggers(empty_zone_map, 0);
+
std::string name1 = "temp1";
int64_t timeout = 1;
@@ -396,6 +404,10 @@
{
// This will add a couple fan inputs, and verify the values are cached.
+ // Disable failsafe logger for the unit test.
+ std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map;
+ buildFailsafeLoggers(empty_zone_map, 0);
+
std::string name1 = "fan1";
int64_t timeout = 2;
@@ -444,6 +456,10 @@
// On the second updateSensors call, the updated timestamp will be beyond
// the timeout limit.
+ // Disable failsafe logger for the unit test.
+ std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map;
+ buildFailsafeLoggers(empty_zone_map, 0);
+
int64_t timeout = 1;
std::string name1 = "temp1";
@@ -506,6 +522,10 @@
// only sensor1 goes missing.
// However, sensor2 going missing should still trigger failsafe mode.
+ // Disable failsafe logger for the unit test.
+ std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map;
+ buildFailsafeLoggers(empty_zone_map, 0);
+
int64_t timeout = 1;
std::string name1 = "temp1";
@@ -602,6 +622,10 @@
{
// This will add a couple fan inputs, and verify the values are cached.
+ // Disable failsafe logger for the unit test.
+ std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map;
+ buildFailsafeLoggers(empty_zone_map, 0);
+
std::string name1 = "fan1";
int64_t timeout = 2;
@@ -655,6 +679,10 @@
{
// This will add a couple fan inputs, and verify the values are cached.
+ // Disable failsafe logger for the unit test.
+ std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map;
+ buildFailsafeLoggers(empty_zone_map, 0);
+
std::string name1 = "fan1";
int64_t timeout = 2;
@@ -714,6 +742,10 @@
{
// One can grab a sensor from the manager through the zone.
+ // Disable failsafe logger for the unit test.
+ std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map;
+ buildFailsafeLoggers(empty_zone_map, 0);
+
int64_t timeout = 1;
std::string name1 = "temp1";
@@ -804,6 +836,11 @@
{
// This property is implemented by us as read-only, such that trying to
// write to it will have no effect.
+
+ // Disable failsafe logger for the unit test.
+ std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map;
+ buildFailsafeLoggers(empty_zone_map, 0);
+
EXPECT_EQ(zone->failSafe(), zone->getFailSafeMode());
}
diff --git a/test/sensor_host_unittest.cpp b/test/sensor_host_unittest.cpp
index e9800cf..5e958c0 100644
--- a/test/sensor_host_unittest.cpp
+++ b/test/sensor_host_unittest.cpp
@@ -1,3 +1,6 @@
+#include "failsafeloggers/builder.hpp"
+#include "failsafeloggers/failsafe_logger.hpp"
+#include "failsafeloggers/failsafe_logger_utility.hpp"
#include "sensors/host.hpp"
#include "test/helpers.hpp"
diff --git a/test/zone_mock.hpp b/test/zone_mock.hpp
index a5f105b..885a2c4 100644
--- a/test/zone_mock.hpp
+++ b/test/zone_mock.hpp
@@ -3,6 +3,7 @@
#include "pid/zone_interface.hpp"
#include <string>
+#include <vector>
#include <gmock/gmock.h>
@@ -49,6 +50,7 @@
MOCK_CONST_METHOD0(getAccSetPoint, bool());
MOCK_METHOD1(getSensor, Sensor*(const std::string&));
+ MOCK_METHOD0(getSensorNames, std::vector<std::string>());
MOCK_METHOD0(initializeLog, void());
MOCK_METHOD1(writeLog, void(const std::string&));