summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorEddie James <eajames@us.ibm.com>2019-03-19 20:58:53 +0000
committerEddie James <eajames@linux.ibm.com>2019-04-09 10:51:20 -0500
commit774f9af9a2d861f49c878d9eeca9830bef44127b (patch)
tree6b77eb6565e1f937403dda58296aa0d1493bbdf8 /test
parent577a935e0261e7a316ec7f6ad76b72328d30d2ee (diff)
downloadopenpower-occ-control-774f9af9a2d861f49c878d9eeca9830bef44127b.tar.gz
openpower-occ-control-774f9af9a2d861f49c878d9eeca9830bef44127b.zip
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
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am3
-rw-r--r--test/error_files_tests.cpp103
-rw-r--r--test/utest.cpp25
3 files changed, 130 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index ff56179..0ded744 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -6,7 +6,8 @@ TESTS = $(check_PROGRAMS)
utest_LDADD = $(top_builddir)/libocc_control.la -lstdc++fs
-utest_SOURCES = utest.cpp \
+utest_SOURCES = error_files_tests.cpp \
+ utest.cpp \
TestI2cOcc.cpp
utest_CPPFLAGS = $(GTEST_CPPFLAGS) \
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();
+}
diff --git a/test/utest.cpp b/test/utest.cpp
index eb9ca0b..39e5250 100644
--- a/test/utest.cpp
+++ b/test/utest.cpp
@@ -1,5 +1,6 @@
#include "powercap.hpp"
+#include <experimental/filesystem>
#include <occ_events.hpp>
#include <occ_manager.hpp>
@@ -43,3 +44,27 @@ TEST_F(VerifyOccInput, PcapEnabled)
uint32_t occInput = pcap.getOccInput(100, true);
EXPECT_EQ(occInput, 90);
}
+
+TEST(VerifyPathParsing, EmptyPath)
+{
+ std::experimental::filesystem::path path = "";
+ std::string parsed = Device::getPathBack(path);
+
+ EXPECT_STREQ(parsed.c_str(), "");
+}
+
+TEST(VerifyPathParsing, FilenamePath)
+{
+ std::experimental::filesystem::path path = "/test/foo.bar";
+ std::string parsed = Device::getPathBack(path);
+
+ EXPECT_STREQ(parsed.c_str(), "foo.bar");
+}
+
+TEST(VerifyPathParsing, DirectoryPath)
+{
+ std::experimental::filesystem::path path = "/test/bar/";
+ std::string parsed = Device::getPathBack(path);
+
+ EXPECT_STREQ(parsed.c_str(), "bar");
+}
OpenPOWER on IntegriCloud