regulators: Enhance ErrorHistory

Enhance the ErrorHistory class to track all error types logged by the
regulators application.  Previously the ErrorHistory class only tracked
a single error type.

This class is used to avoid logging duplicate errors.  Some regulator
operations occur repeatedly, such as reading sensors/telemetry.

The first time an error occurs, it should be logged.  But if the same
error occurs again on the same regulator, it should not be logged again.

Error history will be cleared at the beginning of each boot.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: Iba2225e635eb9b7a8fe633f117346c1fb5c9884b
diff --git a/phosphor-regulators/test/error_history_tests.cpp b/phosphor-regulators/test/error_history_tests.cpp
index 3e3cba8..55f77f5 100644
--- a/phosphor-regulators/test/error_history_tests.cpp
+++ b/phosphor-regulators/test/error_history_tests.cpp
@@ -15,46 +15,71 @@
  */
 #include "error_history.hpp"
 
-#include <cstdint>
-
 #include <gtest/gtest.h>
 
 using namespace phosphor::power::regulators;
 
+TEST(ErrorHistoryTests, ErrorType)
+{
+    EXPECT_EQ(static_cast<int>(ErrorType::internal), 3);
+    EXPECT_EQ(static_cast<int>(ErrorType::numTypes), 6);
+}
+
 TEST(ErrorHistoryTests, Constructor)
 {
     ErrorHistory history{};
-    EXPECT_EQ(history.count, 0);
-    EXPECT_EQ(history.wasLogged, false);
+    EXPECT_FALSE(history.wasLogged(ErrorType::configFile));
+    EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
+    EXPECT_FALSE(history.wasLogged(ErrorType::i2c));
+    EXPECT_FALSE(history.wasLogged(ErrorType::internal));
+    EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
+    EXPECT_FALSE(history.wasLogged(ErrorType::writeVerification));
 }
 
 TEST(ErrorHistoryTests, Clear)
 {
     ErrorHistory history{};
-    history.count = 23;
-    history.wasLogged = true;
+
+    history.setWasLogged(ErrorType::configFile, true);
+    history.setWasLogged(ErrorType::dbus, true);
+    history.setWasLogged(ErrorType::i2c, true);
+    history.setWasLogged(ErrorType::internal, true);
+    history.setWasLogged(ErrorType::pmbus, true);
+    history.setWasLogged(ErrorType::writeVerification, true);
+
+    EXPECT_TRUE(history.wasLogged(ErrorType::configFile));
+    EXPECT_TRUE(history.wasLogged(ErrorType::dbus));
+    EXPECT_TRUE(history.wasLogged(ErrorType::i2c));
+    EXPECT_TRUE(history.wasLogged(ErrorType::internal));
+    EXPECT_TRUE(history.wasLogged(ErrorType::pmbus));
+    EXPECT_TRUE(history.wasLogged(ErrorType::writeVerification));
+
     history.clear();
-    EXPECT_EQ(history.count, 0);
-    EXPECT_EQ(history.wasLogged, false);
+
+    EXPECT_FALSE(history.wasLogged(ErrorType::configFile));
+    EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
+    EXPECT_FALSE(history.wasLogged(ErrorType::i2c));
+    EXPECT_FALSE(history.wasLogged(ErrorType::internal));
+    EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
+    EXPECT_FALSE(history.wasLogged(ErrorType::writeVerification));
 }
 
-TEST(ErrorHistoryTests, IncrementCount)
+TEST(ErrorHistoryTests, SetWasLogged)
 {
     ErrorHistory history{};
+    EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
+    history.setWasLogged(ErrorType::dbus, true);
+    EXPECT_TRUE(history.wasLogged(ErrorType::dbus));
+    history.setWasLogged(ErrorType::dbus, false);
+    EXPECT_FALSE(history.wasLogged(ErrorType::dbus));
+}
 
-    // Test where count is not near the max
-    EXPECT_EQ(history.count, 0);
-    history.incrementCount();
-    EXPECT_EQ(history.count, 1);
-    history.incrementCount();
-    EXPECT_EQ(history.count, 2);
-
-    // Test where count is near the max.  Verify it does not wrap/overflow.
-    history.count = SIZE_MAX - 2;
-    history.incrementCount();
-    EXPECT_EQ(history.count, SIZE_MAX - 1);
-    history.incrementCount();
-    EXPECT_EQ(history.count, SIZE_MAX);
-    history.incrementCount();
-    EXPECT_EQ(history.count, SIZE_MAX);
+TEST(ErrorHistoryTests, WasLogged)
+{
+    ErrorHistory history{};
+    EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
+    history.setWasLogged(ErrorType::pmbus, true);
+    EXPECT_TRUE(history.wasLogged(ErrorType::pmbus));
+    history.setWasLogged(ErrorType::pmbus, false);
+    EXPECT_FALSE(history.wasLogged(ErrorType::pmbus));
 }