conf: add ignoreDbusMinMax option
Add an optional field to the sensor configuration, s.t. it'll tell a
dbus passive sensor to ignore the MinValue and MaxValue properties from
dbus.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ia6a8c802c2dc5bf41e5e860b21d7764cc09e6b6b
diff --git a/test/dbus_passive_unittest.cpp b/test/dbus_passive_unittest.cpp
index 84557ee..7b82c74 100644
--- a/test/dbus_passive_unittest.cpp
+++ b/test/dbus_passive_unittest.cpp
@@ -2,6 +2,7 @@
#include "dbus/dbuspassive.hpp"
#include "test/dbushelper_mock.hpp"
+#include <functional>
#include <sdbusplus/test/sdbus_mock.hpp>
#include <string>
#include <variant>
@@ -72,6 +73,8 @@
prop->scale = _scale;
prop->value = _value;
prop->unit = "x";
+ prop->min = 0;
+ prop->max = 0;
}));
EXPECT_CALL(helper, thresholdsAsserted(_, StrEq("asdf"), StrEq(path)))
.WillOnce(Return(false));
@@ -131,6 +134,11 @@
EXPECT_EQ(id, passive->getID());
}
+TEST_F(DbusPassiveTestObj, GetMinValueReturnsExpectedValue)
+{
+ EXPECT_DOUBLE_EQ(0, passive->getMin());
+}
+
TEST_F(DbusPassiveTestObj, VerifyHandlesDbusSignal)
{
// The dbus passive sensor listens for updates and if it's the Value
@@ -418,3 +426,105 @@
bool failed = passive->getFailed();
EXPECT_EQ(failed, false);
}
+
+void GetPropertiesMax3k(sdbusplus::bus::bus& bus, const std::string& service,
+ const std::string& path, SensorProperties* prop)
+{
+ prop->scale = -3;
+ prop->value = 10;
+ prop->unit = "x";
+ prop->min = 0;
+ prop->max = 3000;
+}
+
+using GetPropertiesFunction =
+ std::function<void(sdbusplus::bus::bus&, const std::string&,
+ const std::string&, SensorProperties*)>;
+
+// TODO: There is definitely a cleaner way to do this.
+class DbusPassiveTest3kMaxObj : public ::testing::Test
+{
+ protected:
+ DbusPassiveTest3kMaxObj() :
+ sdbus_mock(),
+ bus_mock(std::move(sdbusplus::get_mocked_new(&sdbus_mock))), helper()
+ {
+ EXPECT_CALL(helper, getService(_, StrEq(SensorIntf), StrEq(path)))
+ .WillOnce(Return("asdf"));
+
+ EXPECT_CALL(helper,
+ getProperties(_, StrEq("asdf"), StrEq(path), NotNull()))
+ .WillOnce(_getProps);
+ EXPECT_CALL(helper, thresholdsAsserted(_, StrEq("asdf"), StrEq(path)))
+ .WillOnce(Return(false));
+
+ auto info = conf::SensorConfig();
+ ri = DbusPassive::createDbusPassive(bus_mock, type, id, &helper, &info,
+ nullptr);
+ passive = reinterpret_cast<DbusPassive*>(ri.get());
+ EXPECT_FALSE(passive == nullptr);
+ }
+
+ sdbusplus::SdBusMock sdbus_mock;
+ sdbusplus::bus::bus bus_mock;
+ DbusHelperMock helper;
+ std::string type = "temp";
+ std::string id = "id";
+ std::string path = "/xyz/openbmc_project/sensors/temperature/id";
+ int64_t _scale = -3;
+ int64_t _value = 10;
+
+ std::unique_ptr<ReadInterface> ri;
+ DbusPassive* passive;
+ GetPropertiesFunction _getProps = &GetPropertiesMax3k;
+};
+
+TEST_F(DbusPassiveTest3kMaxObj, ReadMinAndMaxReturnsExpected)
+{
+ EXPECT_DOUBLE_EQ(0, passive->getMin());
+ EXPECT_DOUBLE_EQ(3, passive->getMax());
+}
+
+class DbusPassiveTest3kMaxIgnoredObj : public ::testing::Test
+{
+ protected:
+ DbusPassiveTest3kMaxIgnoredObj() :
+ sdbus_mock(),
+ bus_mock(std::move(sdbusplus::get_mocked_new(&sdbus_mock))), helper()
+ {
+ EXPECT_CALL(helper, getService(_, StrEq(SensorIntf), StrEq(path)))
+ .WillOnce(Return("asdf"));
+
+ EXPECT_CALL(helper,
+ getProperties(_, StrEq("asdf"), StrEq(path), NotNull()))
+ .WillOnce(_getProps);
+ EXPECT_CALL(helper, thresholdsAsserted(_, StrEq("asdf"), StrEq(path)))
+ .WillOnce(Return(false));
+
+ auto info = conf::SensorConfig();
+ info.ignoreDbusMinMax = true;
+ ri = DbusPassive::createDbusPassive(bus_mock, type, id, &helper, &info,
+ nullptr);
+ passive = reinterpret_cast<DbusPassive*>(ri.get());
+ EXPECT_FALSE(passive == nullptr);
+ }
+
+ sdbusplus::SdBusMock sdbus_mock;
+ sdbusplus::bus::bus bus_mock;
+ DbusHelperMock helper;
+ std::string type = "temp";
+ std::string id = "id";
+ std::string path = "/xyz/openbmc_project/sensors/temperature/id";
+ int64_t _scale = -3;
+ int64_t _value = 10;
+
+ std::unique_ptr<ReadInterface> ri;
+ DbusPassive* passive;
+ GetPropertiesFunction _getProps = &GetPropertiesMax3k;
+};
+
+TEST_F(DbusPassiveTest3kMaxIgnoredObj, ReadMinAndMaxReturnsExpected)
+{
+ EXPECT_DOUBLE_EQ(0, passive->getMin());
+ EXPECT_DOUBLE_EQ(0, passive->getMax());
+}