summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-12-19 08:13:41 -0800
committerPatrick Venture <venture@google.com>2018-12-19 08:43:56 -0800
commit2864b0637f6a826dd2919e533100f9c18afda1cd (patch)
tree60f0b5362cfeb53d8cecc5085637c4ed6416bd8a
parent5a842c3e3931993bcb184300b289c8a82ecd6322 (diff)
downloadphosphor-hwmon-2864b0637f6a826dd2919e533100f9c18afda1cd.tar.gz
phosphor-hwmon-2864b0637f6a826dd2919e533100f9c18afda1cd.zip
sensor: to enable testing receive hwmonio interface pointer
The sensor objects all share a reference to the mainloop's ioAccess object. To enable testing, the sensor object needs to expect the base pointer to this object. Change-Id: I1d7f2841528776c8d4f1166e20874ddeb4b8554a Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r--mainloop.cpp3
-rw-r--r--sensor.cpp15
-rw-r--r--sensor.hpp5
3 files changed, 13 insertions, 10 deletions
diff --git a/mainloop.cpp b/mainloop.cpp
index 29bd378..b6d44b7 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -148,8 +148,9 @@ std::optional<ObjectStateData>
return {};
}
+ /* Note: The sensor objects all share the same ioAccess object. */
auto sensorObj =
- std::make_unique<sensor::Sensor>(sensor.first, ioAccess, _devPath);
+ std::make_unique<sensor::Sensor>(sensor.first, &ioAccess, _devPath);
// Get list of return codes for removing sensors on device
auto devRmRCs = env::getEnv("REMOVERCS");
diff --git a/sensor.cpp b/sensor.cpp
index 5c97e0c..2a2148c 100644
--- a/sensor.cpp
+++ b/sensor.cpp
@@ -36,7 +36,8 @@ void setScale(T& iface, int64_t value, int64_t)
// todo: this can be simplified once we move to the double interface
Sensor::Sensor(const SensorSet::key_type& sensor,
- const hwmonio::HwmonIO& ioAccess, const std::string& devPath) :
+ const hwmonio::HwmonIOInterface* ioAccess,
+ const std::string& devPath) :
sensor(sensor),
ioAccess(ioAccess), devPath(devPath)
{
@@ -148,9 +149,9 @@ std::shared_ptr<ValueObject> Sensor::addValue(const RetryIO& retryIO,
// Retry for up to a second if device is busy
// or has a transient error.
- val = ioAccess.read(sensor.first, sensor.second, hwmon::entry::cinput,
- std::get<size_t>(retryIO),
- std::get<std::chrono::milliseconds>(retryIO));
+ val = ioAccess->read(sensor.first, sensor.second, hwmon::entry::cinput,
+ std::get<size_t>(retryIO),
+ std::get<std::chrono::milliseconds>(retryIO));
lockGpio();
val = adjustValue(val);
@@ -199,14 +200,14 @@ std::shared_ptr<StatusObject> Sensor::addStatus(ObjectInfo& info)
std::string entry = hwmon::entry::fault;
auto sysfsFullPath =
- sysfs::make_sysfs_path(ioAccess.path(), faultName, faultID, entry);
+ sysfs::make_sysfs_path(ioAccess->path(), faultName, faultID, entry);
if (fs::exists(sysfsFullPath))
{
bool functional = true;
try
{
- uint32_t fault = ioAccess.read(faultName, faultID, entry,
- hwmonio::retries, hwmonio::delay);
+ uint32_t fault = ioAccess->read(faultName, faultID, entry,
+ hwmonio::retries, hwmonio::delay);
if (fault != 0)
{
functional = false;
diff --git a/sensor.hpp b/sensor.hpp
index 37cf035..3bcfc82 100644
--- a/sensor.hpp
+++ b/sensor.hpp
@@ -6,6 +6,7 @@
#include <chrono>
#include <gpioplus/handle.hpp>
+#include <memory>
#include <unordered_set>
namespace sensor
@@ -42,7 +43,7 @@ class Sensor
* @param[in] devPath - Device sysfs path
*/
explicit Sensor(const SensorSet::key_type& sensor,
- const hwmonio::HwmonIO& ioAccess,
+ const hwmonio::HwmonIOInterface* ioAccess,
const std::string& devPath);
/**
@@ -128,7 +129,7 @@ class Sensor
SensorSet::key_type sensor;
/** @brief Hwmon sysfs access. */
- const hwmonio::HwmonIO& ioAccess;
+ const hwmonio::HwmonIOInterface* ioAccess;
/** @brief Physical device sysfs path. */
const std::string& devPath;
OpenPOWER on IntegriCloud