summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--i2c_occ.cpp11
-rw-r--r--occ_manager.cpp9
-rw-r--r--test/TestI2cOcc.cpp6
-rw-r--r--test/utest.cpp2
4 files changed, 22 insertions, 6 deletions
diff --git a/i2c_occ.cpp b/i2c_occ.cpp
index ffbb844..c364967 100644
--- a/i2c_occ.cpp
+++ b/i2c_occ.cpp
@@ -1,4 +1,5 @@
#include <algorithm>
+#include <cassert>
#include <fstream>
#include "config.h"
@@ -13,9 +14,12 @@ namespace fs = std::experimental::filesystem;
// The device name's length, e.g. "p8-occ-hwmon"
constexpr auto DEVICE_NAME_LENGTH = 12;
+// The occ name's length, e.g. "occ"
+constexpr auto OCC_NAME_LENGTH = 3;
// static assert to make sure the i2c occ device name is expected
static_assert(sizeof(I2C_OCC_DEVICE_NAME) -1 == DEVICE_NAME_LENGTH);
+static_assert(sizeof(OCC_NAME) -1 == OCC_NAME_LENGTH);
std::string getFileContent(const fs::path& f)
{
@@ -63,6 +67,13 @@ void dbusToI2c(std::string& path)
std::string getI2cDeviceName(const std::string& dbusPath)
{
auto name = fs::path(dbusPath).filename().string();
+
+ // Need to make sure the name starts with "occ"
+ assert(name.compare(0, OCC_NAME_LENGTH, OCC_NAME) == 0);
+
+ // Change name like occ_3_0050 to 3_0050
+ name.erase(0, OCC_NAME_LENGTH + 1);
+
dbusToI2c(name);
return name;
}
diff --git a/occ_manager.cpp b/occ_manager.cpp
index df53f7d..8b99b1f 100644
--- a/occ_manager.cpp
+++ b/occ_manager.cpp
@@ -126,12 +126,13 @@ void Manager::initStatusObjects()
for (auto& name : deviceNames)
{
i2c_occ::i2cToDbus(name);
+ name = std::string(OCC_NAME) + '_' + name;
auto path = fs::path(OCC_CONTROL_ROOT) / name;
statusObjects.emplace_back(
- std::make_unique<Status>(
- bus,
- event,
- path.c_str()));
+ std::make_unique<Status>(
+ bus,
+ event,
+ path.c_str()));
}
}
#endif
diff --git a/test/TestI2cOcc.cpp b/test/TestI2cOcc.cpp
index 3fb6e6e..c92da5b 100644
--- a/test/TestI2cOcc.cpp
+++ b/test/TestI2cOcc.cpp
@@ -144,9 +144,13 @@ TEST(TestI2cDbusNames, dbusToI2c)
TEST(TestI2cDbusNames, getI2cDeviceName)
{
- auto path = "/org/open_power/control/4_0050"s;
+ auto path = "/org/open_power/control/occ_4_0050"s;
auto name = getI2cDeviceName(path);
EXPECT_EQ(STR_4_0050, name);
+
+ // With invalid occ path, the code shall assert
+ path = "/org/open_power/control/SomeInvalidPath"s;
+ EXPECT_DEATH(getI2cDeviceName(path), "");
}
} // namespace i2c_occ
diff --git a/test/utest.cpp b/test/utest.cpp
index 44691c2..9731209 100644
--- a/test/utest.cpp
+++ b/test/utest.cpp
@@ -11,7 +11,7 @@ class VerifyOccInput : public ::testing::Test
bus(sdbusplus::bus::new_default()),
rc(sd_event_default(&event)),
eventP(event),
- occStatus(bus, eventP, "/test/path"),
+ occStatus(bus, eventP, "/test/path/occ1"),
pcap(bus,occStatus)
{
EXPECT_GE(rc, 0);
OpenPOWER on IntegriCloud