psu-ng: Updates for clearFaults

It was discovered that the power supplies may not always have the
in1_crit "file" available in the HWMON directory. This file may be
missing if certain commands are not supported. It was also discovered
that it can be missing if the power supply falsely indicates it supports
PEC, but actually does not. Changing the readString call to read from
the in1_input file, which typically should be present (READ_VIN).

Move the clearFaults function from the hpp file to the cpp file, as:
1. It is getting a bit lengthy.
2. Adding a try/catch for ReadFailure to avoid crashing the application
   if there is a ReadFailure, which is in the phosphor::logging
   namespace already used in the cpp file.

Update the test case to expect a read from in1_input, and return a value
that more closely resembles an actual READ_VIN value.

Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
Change-Id: I9747317c68040cdce6bb80922e3928be55376c44
diff --git a/phosphor-power-supply/power_supply.cpp b/phosphor-power-supply/power_supply.cpp
index 6df3e3e..37e5666 100644
--- a/phosphor-power-supply/power_supply.cpp
+++ b/phosphor-power-supply/power_supply.cpp
@@ -93,6 +93,33 @@
     }
 }
 
+void PowerSupply::clearFaults()
+{
+    faultFound = false;
+    inputFault = false;
+    mfrFault = false;
+    vinUVFault = false;
+
+    // The PMBus device driver does not allow for writing CLEAR_FAULTS
+    // directly. However, the pmbus hwmon device driver code will send a
+    // CLEAR_FAULTS after reading from any of the hwmon "files" in sysfs, so
+    // reading in1_input should result in clearing the fault bits in
+    // STATUS_BYTE/STATUS_WORD.
+    // I do not care what the return value is.
+    try
+    {
+        static_cast<void>(
+            pmbusIntf->read("in1_input", phosphor::pmbus::Type::Hwmon));
+    }
+    catch (ReadFailure& e)
+    {
+        // Since I do not care what the return value is, I really do not
+        // care much if it gets a ReadFailure either. However, this should not
+        // prevent the application from continuing to run, so catching the read
+        // failure.
+    }
+}
+
 void PowerSupply::inventoryChanged(sdbusplus::message::message& msg)
 {
     std::string msgSensor;
diff --git a/phosphor-power-supply/power_supply.hpp b/phosphor-power-supply/power_supply.hpp
index fdbb94f..707a745 100644
--- a/phosphor-power-supply/power_supply.hpp
+++ b/phosphor-power-supply/power_supply.hpp
@@ -72,22 +72,7 @@
      * with a clean state. Presence changes and power state changes will
      * want to clear any faults logged.
      */
-    void clearFaults()
-    {
-        faultFound = false;
-        inputFault = false;
-        mfrFault = false;
-        vinUVFault = false;
-
-        // The PMBus device driver does not allow for writing CLEAR_FAULTS
-        // directly. However, the pmbus hwmon device driver code will send a
-        // CLEAR_FAULTS after reading from any of the hwmon "files" in sysfs, so
-        // reading in1_crit should result in clearing the fault bits in
-        // STATUS_BYTE/STATUS_WORD.
-        // I do not care what the return value is.
-        static_cast<void>(
-            pmbusIntf->read("in1_crit", phosphor::pmbus::Type::Hwmon));
-    }
+    void clearFaults();
 
     /**
      * @brief Adds properties to the inventory.
diff --git a/phosphor-power-supply/test/power_supply_tests.cpp b/phosphor-power-supply/test/power_supply_tests.cpp
index dda38f5..c6d4814 100644
--- a/phosphor-power-supply/test/power_supply_tests.cpp
+++ b/phosphor-power-supply/test/power_supply_tests.cpp
@@ -168,7 +168,9 @@
     EXPECT_EQ(psu.hasInputFault(), true);
     EXPECT_EQ(psu.hasMFRFault(), true);
     EXPECT_EQ(psu.hasVINUVFault(), true);
-    EXPECT_CALL(mockPMBus, read("in1_crit", _)).Times(1).WillOnce(Return(0x01));
+    EXPECT_CALL(mockPMBus, read("in1_input", _))
+        .Times(1)
+        .WillOnce(Return(209000));
     psu.clearFaults();
     EXPECT_EQ(psu.isPresent(), true);
     EXPECT_EQ(psu.isFaulted(), false);