Fix error attribute naming for Linux 5.0

There was a slight change to one of the error attributes as part of the
OCC driver upstreaming process. This commit also adds unit tests for the
error attributes. This required some refactoring to support the unit
tests.

Resolves openbmc/openbmc#3505

Signed-off-by: Eddie James <eajames@us.ibm.com>
Change-Id: I665b46e44b18befc8a728f7246bcda82f1f1a71c
diff --git a/test/error_files_tests.cpp b/test/error_files_tests.cpp
new file mode 100644
index 0000000..532818a
--- /dev/null
+++ b/test/error_files_tests.cpp
@@ -0,0 +1,103 @@
+#include "occ_manager.hpp"
+
+#include <stdlib.h>
+
+#include <filesystem>
+#include <fstream>
+
+#include <gtest/gtest.h>
+
+constexpr auto num_error_files = 8;
+constexpr auto device = "occ-hwmon.1";
+constexpr auto error = "occ_error";
+constexpr auto errorMem = "occ_mem_throttle";
+constexpr auto errorPower = "occ_dvfs_power";
+constexpr auto errorTemp = "occ_dvfs_overtemp";
+constexpr auto legacyDevice = "occ-hwmon.2";
+constexpr auto legacyErrorTemp = "occ_dvfs_ot";
+constexpr auto noError = "0";
+
+namespace fs = std::experimental::filesystem;
+using namespace open_power::occ;
+
+class ErrorFiles : public ::testing::Test
+{
+  public:
+    ErrorFiles() :
+        bus(sdbusplus::bus::new_default()), rc(sd_event_default(&event)),
+        pEvent(event), manager(bus, pEvent),
+        status(bus, pEvent, "/dummy1", manager)
+    {
+        EXPECT_GE(rc, 0);
+        event = nullptr;
+    }
+
+    virtual void SetUp()
+    {
+        fs::path files[num_error_files];
+        char tmpDirTemplate[64];
+
+        strcpy(tmpDirTemplate, "/tmp/occXXXXXX");
+        auto path = mkdtemp(tmpDirTemplate);
+        assert(path != nullptr);
+
+        occPath = path;
+        devicePath = occPath / device;
+        legacyDevicePath = occPath / legacyDevice;
+
+        fs::create_directory(devicePath);
+        fs::create_directory(legacyDevicePath);
+
+        files[0] = devicePath / error;
+        files[1] = devicePath / errorMem;
+        files[2] = devicePath / errorPower;
+        files[3] = devicePath / errorTemp;
+        files[4] = legacyDevicePath / error;
+        files[5] = legacyDevicePath / errorMem;
+        files[6] = legacyDevicePath / errorPower;
+        files[7] = legacyDevicePath / legacyErrorTemp;
+
+        for (const fs::path& f : files)
+        {
+            auto stream = std::ofstream(f.c_str());
+
+            if (stream)
+            {
+                stream << noError;
+            }
+        }
+    }
+
+    virtual void TearDown()
+    {
+        fs::remove_all(occPath);
+    }
+
+    sdbusplus::bus::bus bus;
+    sd_event* event;
+    int rc;
+    open_power::occ::EventPtr pEvent;
+
+    Manager manager;
+    Status status;
+
+    fs::path devicePath;
+    fs::path legacyDevicePath;
+    fs::path occPath;
+};
+
+TEST_F(ErrorFiles, AddDeviceErrorWatch)
+{
+    Device occDevice(pEvent, devicePath, manager, status);
+
+    occDevice.addErrorWatch(false);
+    occDevice.removeErrorWatch();
+}
+
+TEST_F(ErrorFiles, AddLegacyDeviceErrorWatch)
+{
+    Device legacyOccDevice(pEvent, legacyDevicePath, manager, status);
+
+    legacyOccDevice.addErrorWatch(false);
+    legacyOccDevice.removeErrorWatch();
+}