10ef1faf7SPatrick Venture #include "dbus/dbuspassive.hpp" 2da4a5dd1SPatrick Venture #include "test/dbushelper_mock.hpp" 30ef1faf7SPatrick Venture 40ef1faf7SPatrick Venture #include <sdbusplus/test/sdbus_mock.hpp> 50ef1faf7SPatrick Venture #include <string> 60ef1faf7SPatrick Venture 7da4a5dd1SPatrick Venture #include <gmock/gmock.h> 8da4a5dd1SPatrick Venture #include <gtest/gtest.h> 90ef1faf7SPatrick Venture 10da4a5dd1SPatrick Venture using ::testing::_; 110ef1faf7SPatrick Venture using ::testing::InSequence; 120ef1faf7SPatrick Venture using ::testing::Invoke; 130ef1faf7SPatrick Venture using ::testing::IsNull; 140ef1faf7SPatrick Venture using ::testing::NotNull; 150ef1faf7SPatrick Venture using ::testing::Return; 160ef1faf7SPatrick Venture using ::testing::StrEq; 170ef1faf7SPatrick Venture 180ef1faf7SPatrick Venture std::string SensorIntf = "xyz.openbmc_project.Sensor.Value"; 190ef1faf7SPatrick Venture 20da4a5dd1SPatrick Venture TEST(DbusPassiveTest, FactoryFailsWithInvalidType) 21da4a5dd1SPatrick Venture { 220ef1faf7SPatrick Venture // Verify the type is checked by the factory. 230ef1faf7SPatrick Venture 240ef1faf7SPatrick Venture sdbusplus::SdBusMock sdbus_mock; 250ef1faf7SPatrick Venture auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); 260ef1faf7SPatrick Venture std::string type = "invalid"; 270ef1faf7SPatrick Venture std::string id = "id"; 280ef1faf7SPatrick Venture 290ef1faf7SPatrick Venture DbusHelperMock helper; 300ef1faf7SPatrick Venture 310ef1faf7SPatrick Venture std::unique_ptr<ReadInterface> ri = 32563a356fSPatrick Venture DbusPassive::createDbusPassive(bus_mock, type, id, &helper); 330ef1faf7SPatrick Venture 340ef1faf7SPatrick Venture EXPECT_EQ(ri, nullptr); 350ef1faf7SPatrick Venture } 360ef1faf7SPatrick Venture 37da4a5dd1SPatrick Venture TEST(DbusPassiveTest, BoringConstructorTest) 38da4a5dd1SPatrick Venture { 39*f8cb4644SPatrick Venture // Simply build the object, does no error checking. 400ef1faf7SPatrick Venture 410ef1faf7SPatrick Venture sdbusplus::SdBusMock sdbus_mock; 420ef1faf7SPatrick Venture auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); 430ef1faf7SPatrick Venture std::string type = "invalid"; 440ef1faf7SPatrick Venture std::string id = "id"; 450ef1faf7SPatrick Venture std::string path = "/xyz/openbmc_project/sensors/unknown/id"; 460ef1faf7SPatrick Venture 470ef1faf7SPatrick Venture DbusHelperMock helper; 48*f8cb4644SPatrick Venture struct SensorProperties properties; 490ef1faf7SPatrick Venture 50*f8cb4644SPatrick Venture DbusPassive(bus_mock, type, id, &helper, properties, false); 510ef1faf7SPatrick Venture // Success 520ef1faf7SPatrick Venture } 530ef1faf7SPatrick Venture 54da4a5dd1SPatrick Venture class DbusPassiveTestObj : public ::testing::Test 55da4a5dd1SPatrick Venture { 560ef1faf7SPatrick Venture protected: 57da4a5dd1SPatrick Venture DbusPassiveTestObj() : 58da4a5dd1SPatrick Venture sdbus_mock(), 59da4a5dd1SPatrick Venture bus_mock(std::move(sdbusplus::get_mocked_new(&sdbus_mock))), helper() 600ef1faf7SPatrick Venture { 61563a356fSPatrick Venture EXPECT_CALL(helper, getService(_, StrEq(SensorIntf), StrEq(path))) 620ef1faf7SPatrick Venture .WillOnce(Return("asdf")); 630ef1faf7SPatrick Venture 64da4a5dd1SPatrick Venture EXPECT_CALL(helper, 65563a356fSPatrick Venture getProperties(_, StrEq("asdf"), StrEq(path), NotNull())) 66da4a5dd1SPatrick Venture .WillOnce(Invoke( 67da4a5dd1SPatrick Venture [&](sdbusplus::bus::bus& bus, const std::string& service, 68da4a5dd1SPatrick Venture const std::string& path, struct SensorProperties* prop) { 690ef1faf7SPatrick Venture prop->scale = _scale; 700ef1faf7SPatrick Venture prop->value = _value; 710ef1faf7SPatrick Venture prop->unit = "x"; 720ef1faf7SPatrick Venture })); 73563a356fSPatrick Venture EXPECT_CALL(helper, thresholdsAsserted(_, StrEq("asdf"), StrEq(path))) 7436b7d8ebSJames Feist .WillOnce(Return(false)); 750ef1faf7SPatrick Venture 76563a356fSPatrick Venture ri = DbusPassive::createDbusPassive(bus_mock, type, id, &helper); 770ef1faf7SPatrick Venture passive = reinterpret_cast<DbusPassive*>(ri.get()); 780ef1faf7SPatrick Venture EXPECT_FALSE(passive == nullptr); 790ef1faf7SPatrick Venture } 800ef1faf7SPatrick Venture 810ef1faf7SPatrick Venture sdbusplus::SdBusMock sdbus_mock; 820ef1faf7SPatrick Venture sdbusplus::bus::bus bus_mock; 830ef1faf7SPatrick Venture DbusHelperMock helper; 840ef1faf7SPatrick Venture std::string type = "temp"; 850ef1faf7SPatrick Venture std::string id = "id"; 860ef1faf7SPatrick Venture std::string path = "/xyz/openbmc_project/sensors/temperature/id"; 870ef1faf7SPatrick Venture int64_t _scale = -3; 880ef1faf7SPatrick Venture int64_t _value = 10; 890ef1faf7SPatrick Venture 900ef1faf7SPatrick Venture std::unique_ptr<ReadInterface> ri; 910ef1faf7SPatrick Venture DbusPassive* passive; 920ef1faf7SPatrick Venture }; 930ef1faf7SPatrick Venture 94da4a5dd1SPatrick Venture TEST_F(DbusPassiveTestObj, ReadReturnsExpectedValues) 95da4a5dd1SPatrick Venture { 960ef1faf7SPatrick Venture // Verify read is returning the values. 970ef1faf7SPatrick Venture ReadReturn v; 980ef1faf7SPatrick Venture v.value = 0.01; 990ef1faf7SPatrick Venture // TODO: updated is set when the value is created, so we can range check 1000ef1faf7SPatrick Venture // it. 1010ef1faf7SPatrick Venture ReadReturn r = passive->read(); 1020ef1faf7SPatrick Venture EXPECT_EQ(v.value, r.value); 1030ef1faf7SPatrick Venture } 1040ef1faf7SPatrick Venture 105da4a5dd1SPatrick Venture TEST_F(DbusPassiveTestObj, SetValueUpdatesValue) 106da4a5dd1SPatrick Venture { 1070ef1faf7SPatrick Venture // Verify setvalue does as advertised. 1080ef1faf7SPatrick Venture 1090ef1faf7SPatrick Venture double value = 0.01; 1100ef1faf7SPatrick Venture passive->setValue(value); 1110ef1faf7SPatrick Venture 1120ef1faf7SPatrick Venture // TODO: updated is set when the value is set, so we can range check it. 1130ef1faf7SPatrick Venture ReadReturn r = passive->read(); 1140ef1faf7SPatrick Venture EXPECT_EQ(value, r.value); 1150ef1faf7SPatrick Venture } 1160ef1faf7SPatrick Venture 117da4a5dd1SPatrick Venture TEST_F(DbusPassiveTestObj, GetScaleReturnsExpectedValue) 118da4a5dd1SPatrick Venture { 1190ef1faf7SPatrick Venture // Verify the scale is returned as expected. 1200ef1faf7SPatrick Venture EXPECT_EQ(_scale, passive->getScale()); 1210ef1faf7SPatrick Venture } 1220ef1faf7SPatrick Venture 123563a356fSPatrick Venture TEST_F(DbusPassiveTestObj, getIDReturnsExpectedValue) 124da4a5dd1SPatrick Venture { 125563a356fSPatrick Venture // Verify getID returns the expected value. 126563a356fSPatrick Venture EXPECT_EQ(id, passive->getID()); 1270ef1faf7SPatrick Venture } 1280ef1faf7SPatrick Venture 129da4a5dd1SPatrick Venture TEST_F(DbusPassiveTestObj, VerifyHandlesDbusSignal) 130da4a5dd1SPatrick Venture { 1310ef1faf7SPatrick Venture // The dbus passive sensor listens for updates and if it's the Value 1320ef1faf7SPatrick Venture // property, it needs to handle it. 1330ef1faf7SPatrick Venture 1340ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, sd_bus_message_ref(IsNull())) 1350ef1faf7SPatrick Venture .WillOnce(Return(nullptr)); 1360ef1faf7SPatrick Venture sdbusplus::message::message msg(nullptr, &sdbus_mock); 1370ef1faf7SPatrick Venture 1380ef1faf7SPatrick Venture const char* Value = "Value"; 1390ef1faf7SPatrick Venture int64_t xValue = 10000; 1400ef1faf7SPatrick Venture const char* intf = "xyz.openbmc_project.Sensor.Value"; 1410ef1faf7SPatrick Venture // string, std::map<std::string, sdbusplus::message::variant<int64_t>> 1420ef1faf7SPatrick Venture // msg.read(msgSensor, msgData); 1430ef1faf7SPatrick Venture 144da4a5dd1SPatrick Venture EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 's', NotNull())) 1450ef1faf7SPatrick Venture .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 1460ef1faf7SPatrick Venture const char** s = static_cast<const char**>(p); 1470ef1faf7SPatrick Venture // Read the first parameter, the string. 1480ef1faf7SPatrick Venture *s = intf; 1490ef1faf7SPatrick Venture return 0; 1500ef1faf7SPatrick Venture })) 1510ef1faf7SPatrick Venture .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 1520ef1faf7SPatrick Venture const char** s = static_cast<const char**>(p); 1530ef1faf7SPatrick Venture *s = Value; 1540ef1faf7SPatrick Venture // Read the string in the pair (dictionary). 1550ef1faf7SPatrick Venture return 0; 1560ef1faf7SPatrick Venture })); 1570ef1faf7SPatrick Venture 1580ef1faf7SPatrick Venture // std::map 1590ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, 1600ef1faf7SPatrick Venture sd_bus_message_enter_container(IsNull(), 'a', StrEq("{sv}"))) 1610ef1faf7SPatrick Venture .WillOnce(Return(0)); 1620ef1faf7SPatrick Venture 1630ef1faf7SPatrick Venture // while !at_end() 1640ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, sd_bus_message_at_end(IsNull(), 0)) 1650ef1faf7SPatrick Venture .WillOnce(Return(0)) 1660ef1faf7SPatrick Venture .WillOnce(Return(1)); // So it exits the loop after reading one pair. 1670ef1faf7SPatrick Venture 1680ef1faf7SPatrick Venture // std::pair 1690ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, 1700ef1faf7SPatrick Venture sd_bus_message_enter_container(IsNull(), 'e', StrEq("sv"))) 1710ef1faf7SPatrick Venture .WillOnce(Return(0)); 1720ef1faf7SPatrick Venture 1730ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, 1740ef1faf7SPatrick Venture sd_bus_message_verify_type(IsNull(), 'v', StrEq("x"))) 1750ef1faf7SPatrick Venture .WillOnce(Return(1)); 1760ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, 1770ef1faf7SPatrick Venture sd_bus_message_enter_container(IsNull(), 'v', StrEq("x"))) 1780ef1faf7SPatrick Venture .WillOnce(Return(0)); 1790ef1faf7SPatrick Venture 180da4a5dd1SPatrick Venture EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 'x', NotNull())) 1810ef1faf7SPatrick Venture .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 1820ef1faf7SPatrick Venture int64_t* s = static_cast<int64_t*>(p); 1830ef1faf7SPatrick Venture *s = xValue; 1840ef1faf7SPatrick Venture return 0; 1850ef1faf7SPatrick Venture })); 1860ef1faf7SPatrick Venture 1870ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, sd_bus_message_exit_container(IsNull())) 1880ef1faf7SPatrick Venture .WillOnce(Return(0)) /* variant. */ 1890ef1faf7SPatrick Venture .WillOnce(Return(0)) /* std::pair */ 1900ef1faf7SPatrick Venture .WillOnce(Return(0)); /* std::map */ 1910ef1faf7SPatrick Venture 1927af157b1SPatrick Venture int rv = handleSensorValue(msg, passive); 1930ef1faf7SPatrick Venture EXPECT_EQ(rv, 0); // It's always 0. 1940ef1faf7SPatrick Venture 1950ef1faf7SPatrick Venture ReadReturn r = passive->read(); 1960ef1faf7SPatrick Venture EXPECT_EQ(10, r.value); 1970ef1faf7SPatrick Venture } 1980ef1faf7SPatrick Venture 199da4a5dd1SPatrick Venture TEST_F(DbusPassiveTestObj, VerifyIgnoresOtherPropertySignal) 200da4a5dd1SPatrick Venture { 2010ef1faf7SPatrick Venture // The dbus passive sensor listens for updates and if it's the Value 2020ef1faf7SPatrick Venture // property, it needs to handle it. In this case, it won't be. 2030ef1faf7SPatrick Venture 2040ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, sd_bus_message_ref(IsNull())) 2050ef1faf7SPatrick Venture .WillOnce(Return(nullptr)); 2060ef1faf7SPatrick Venture sdbusplus::message::message msg(nullptr, &sdbus_mock); 2070ef1faf7SPatrick Venture 2080ef1faf7SPatrick Venture const char* Scale = "Scale"; 2090ef1faf7SPatrick Venture int64_t xScale = -6; 2100ef1faf7SPatrick Venture const char* intf = "xyz.openbmc_project.Sensor.Value"; 2110ef1faf7SPatrick Venture // string, std::map<std::string, sdbusplus::message::variant<int64_t>> 2120ef1faf7SPatrick Venture // msg.read(msgSensor, msgData); 2130ef1faf7SPatrick Venture 214da4a5dd1SPatrick Venture EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 's', NotNull())) 2150ef1faf7SPatrick Venture .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 2160ef1faf7SPatrick Venture const char** s = static_cast<const char**>(p); 2170ef1faf7SPatrick Venture // Read the first parameter, the string. 2180ef1faf7SPatrick Venture *s = intf; 2190ef1faf7SPatrick Venture return 0; 2200ef1faf7SPatrick Venture })) 2210ef1faf7SPatrick Venture .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 2220ef1faf7SPatrick Venture const char** s = static_cast<const char**>(p); 2230ef1faf7SPatrick Venture *s = Scale; 2240ef1faf7SPatrick Venture // Read the string in the pair (dictionary). 2250ef1faf7SPatrick Venture return 0; 2260ef1faf7SPatrick Venture })); 2270ef1faf7SPatrick Venture 2280ef1faf7SPatrick Venture // std::map 2290ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, 2300ef1faf7SPatrick Venture sd_bus_message_enter_container(IsNull(), 'a', StrEq("{sv}"))) 2310ef1faf7SPatrick Venture .WillOnce(Return(0)); 2320ef1faf7SPatrick Venture 2330ef1faf7SPatrick Venture // while !at_end() 2340ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, sd_bus_message_at_end(IsNull(), 0)) 2350ef1faf7SPatrick Venture .WillOnce(Return(0)) 2360ef1faf7SPatrick Venture .WillOnce(Return(1)); // So it exits the loop after reading one pair. 2370ef1faf7SPatrick Venture 2380ef1faf7SPatrick Venture // std::pair 2390ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, 2400ef1faf7SPatrick Venture sd_bus_message_enter_container(IsNull(), 'e', StrEq("sv"))) 2410ef1faf7SPatrick Venture .WillOnce(Return(0)); 2420ef1faf7SPatrick Venture 2430ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, 2440ef1faf7SPatrick Venture sd_bus_message_verify_type(IsNull(), 'v', StrEq("x"))) 2450ef1faf7SPatrick Venture .WillOnce(Return(1)); 2460ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, 2470ef1faf7SPatrick Venture sd_bus_message_enter_container(IsNull(), 'v', StrEq("x"))) 2480ef1faf7SPatrick Venture .WillOnce(Return(0)); 2490ef1faf7SPatrick Venture 250da4a5dd1SPatrick Venture EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 'x', NotNull())) 2510ef1faf7SPatrick Venture .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 2520ef1faf7SPatrick Venture int64_t* s = static_cast<int64_t*>(p); 2530ef1faf7SPatrick Venture *s = xScale; 2540ef1faf7SPatrick Venture return 0; 2550ef1faf7SPatrick Venture })); 2560ef1faf7SPatrick Venture 2570ef1faf7SPatrick Venture EXPECT_CALL(sdbus_mock, sd_bus_message_exit_container(IsNull())) 2580ef1faf7SPatrick Venture .WillOnce(Return(0)) /* variant. */ 2590ef1faf7SPatrick Venture .WillOnce(Return(0)) /* std::pair */ 2600ef1faf7SPatrick Venture .WillOnce(Return(0)); /* std::map */ 2610ef1faf7SPatrick Venture 2627af157b1SPatrick Venture int rv = handleSensorValue(msg, passive); 2630ef1faf7SPatrick Venture EXPECT_EQ(rv, 0); // It's always 0. 2640ef1faf7SPatrick Venture 2650ef1faf7SPatrick Venture ReadReturn r = passive->read(); 2660ef1faf7SPatrick Venture EXPECT_EQ(0.01, r.value); 2670ef1faf7SPatrick Venture } 26836b7d8ebSJames Feist TEST_F(DbusPassiveTestObj, VerifyCriticalThresholdAssert) 26936b7d8ebSJames Feist { 27036b7d8ebSJames Feist 27136b7d8ebSJames Feist // Verifies when a threshold is crossed the sensor goes into error state 27236b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, sd_bus_message_ref(IsNull())) 27336b7d8ebSJames Feist .WillOnce(Return(nullptr)); 27436b7d8ebSJames Feist sdbusplus::message::message msg(nullptr, &sdbus_mock); 27536b7d8ebSJames Feist 27636b7d8ebSJames Feist const char* criticalAlarm = "CriticalAlarmHigh"; 27736b7d8ebSJames Feist bool alarm = true; 27836b7d8ebSJames Feist const char* intf = "xyz.openbmc_project.Sensor.Threshold.Critical"; 27936b7d8ebSJames Feist 28036b7d8ebSJames Feist passive->setFailed(false); 28136b7d8ebSJames Feist 28236b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 's', NotNull())) 28336b7d8ebSJames Feist .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 28436b7d8ebSJames Feist const char** s = static_cast<const char**>(p); 28536b7d8ebSJames Feist // Read the first parameter, the string. 28636b7d8ebSJames Feist *s = intf; 28736b7d8ebSJames Feist return 0; 28836b7d8ebSJames Feist })) 28936b7d8ebSJames Feist .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 29036b7d8ebSJames Feist const char** s = static_cast<const char**>(p); 29136b7d8ebSJames Feist *s = criticalAlarm; 29236b7d8ebSJames Feist // Read the string in the pair (dictionary). 29336b7d8ebSJames Feist return 0; 29436b7d8ebSJames Feist })); 29536b7d8ebSJames Feist 29636b7d8ebSJames Feist // std::map 29736b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 29836b7d8ebSJames Feist sd_bus_message_enter_container(IsNull(), 'a', StrEq("{sv}"))) 29936b7d8ebSJames Feist .WillOnce(Return(0)); 30036b7d8ebSJames Feist 30136b7d8ebSJames Feist // while !at_end() 30236b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, sd_bus_message_at_end(IsNull(), 0)) 30336b7d8ebSJames Feist .WillOnce(Return(0)) 30436b7d8ebSJames Feist .WillOnce(Return(1)); // So it exits the loop after reading one pair. 30536b7d8ebSJames Feist 30636b7d8ebSJames Feist // std::pair 30736b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 30836b7d8ebSJames Feist sd_bus_message_enter_container(IsNull(), 'e', StrEq("sv"))) 30936b7d8ebSJames Feist .WillOnce(Return(0)); 31036b7d8ebSJames Feist 31136b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 31236b7d8ebSJames Feist sd_bus_message_verify_type(IsNull(), 'v', StrEq("x"))) 31336b7d8ebSJames Feist .WillOnce(Return(0)); 31436b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 31536b7d8ebSJames Feist sd_bus_message_verify_type(IsNull(), 'v', StrEq("d"))) 31636b7d8ebSJames Feist .WillOnce(Return(0)); 31736b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 31836b7d8ebSJames Feist sd_bus_message_verify_type(IsNull(), 'v', StrEq("b"))) 31936b7d8ebSJames Feist .WillOnce(Return(1)); 32036b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 32136b7d8ebSJames Feist sd_bus_message_enter_container(IsNull(), 'v', StrEq("b"))) 32236b7d8ebSJames Feist .WillOnce(Return(0)); 32336b7d8ebSJames Feist 32436b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 'b', NotNull())) 32536b7d8ebSJames Feist .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 32636b7d8ebSJames Feist bool* s = static_cast<bool*>(p); 32736b7d8ebSJames Feist *s = alarm; 32836b7d8ebSJames Feist return 0; 32936b7d8ebSJames Feist })); 33036b7d8ebSJames Feist 33136b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, sd_bus_message_exit_container(IsNull())) 33236b7d8ebSJames Feist .WillOnce(Return(0)) /* variant. */ 33336b7d8ebSJames Feist .WillOnce(Return(0)) /* std::pair */ 33436b7d8ebSJames Feist .WillOnce(Return(0)); /* std::map */ 33536b7d8ebSJames Feist 3367af157b1SPatrick Venture int rv = handleSensorValue(msg, passive); 33736b7d8ebSJames Feist EXPECT_EQ(rv, 0); // It's always 0. 33836b7d8ebSJames Feist bool failed = passive->getFailed(); 33936b7d8ebSJames Feist EXPECT_EQ(failed, true); 34036b7d8ebSJames Feist } 34136b7d8ebSJames Feist 34236b7d8ebSJames Feist TEST_F(DbusPassiveTestObj, VerifyCriticalThresholdDeassert) 34336b7d8ebSJames Feist { 34436b7d8ebSJames Feist 34536b7d8ebSJames Feist // Verifies when a threshold is deasserted a failed sensor goes back into 34636b7d8ebSJames Feist // the normal state 34736b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, sd_bus_message_ref(IsNull())) 34836b7d8ebSJames Feist .WillOnce(Return(nullptr)); 34936b7d8ebSJames Feist sdbusplus::message::message msg(nullptr, &sdbus_mock); 35036b7d8ebSJames Feist 35136b7d8ebSJames Feist const char* criticalAlarm = "CriticalAlarmHigh"; 35236b7d8ebSJames Feist bool alarm = false; 35336b7d8ebSJames Feist const char* intf = "xyz.openbmc_project.Sensor.Threshold.Critical"; 35436b7d8ebSJames Feist 35536b7d8ebSJames Feist passive->setFailed(true); 35636b7d8ebSJames Feist 35736b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 's', NotNull())) 35836b7d8ebSJames Feist .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 35936b7d8ebSJames Feist const char** s = static_cast<const char**>(p); 36036b7d8ebSJames Feist // Read the first parameter, the string. 36136b7d8ebSJames Feist *s = intf; 36236b7d8ebSJames Feist return 0; 36336b7d8ebSJames Feist })) 36436b7d8ebSJames Feist .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 36536b7d8ebSJames Feist const char** s = static_cast<const char**>(p); 36636b7d8ebSJames Feist *s = criticalAlarm; 36736b7d8ebSJames Feist // Read the string in the pair (dictionary). 36836b7d8ebSJames Feist return 0; 36936b7d8ebSJames Feist })); 37036b7d8ebSJames Feist 37136b7d8ebSJames Feist // std::map 37236b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 37336b7d8ebSJames Feist sd_bus_message_enter_container(IsNull(), 'a', StrEq("{sv}"))) 37436b7d8ebSJames Feist .WillOnce(Return(0)); 37536b7d8ebSJames Feist 37636b7d8ebSJames Feist // while !at_end() 37736b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, sd_bus_message_at_end(IsNull(), 0)) 37836b7d8ebSJames Feist .WillOnce(Return(0)) 37936b7d8ebSJames Feist .WillOnce(Return(1)); // So it exits the loop after reading one pair. 38036b7d8ebSJames Feist 38136b7d8ebSJames Feist // std::pair 38236b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 38336b7d8ebSJames Feist sd_bus_message_enter_container(IsNull(), 'e', StrEq("sv"))) 38436b7d8ebSJames Feist .WillOnce(Return(0)); 38536b7d8ebSJames Feist 38636b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 38736b7d8ebSJames Feist sd_bus_message_verify_type(IsNull(), 'v', StrEq("x"))) 38836b7d8ebSJames Feist .WillOnce(Return(0)); 38936b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 39036b7d8ebSJames Feist sd_bus_message_verify_type(IsNull(), 'v', StrEq("d"))) 39136b7d8ebSJames Feist .WillOnce(Return(0)); 39236b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 39336b7d8ebSJames Feist sd_bus_message_verify_type(IsNull(), 'v', StrEq("b"))) 39436b7d8ebSJames Feist .WillOnce(Return(1)); 39536b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, 39636b7d8ebSJames Feist sd_bus_message_enter_container(IsNull(), 'v', StrEq("b"))) 39736b7d8ebSJames Feist .WillOnce(Return(0)); 39836b7d8ebSJames Feist 39936b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, sd_bus_message_read_basic(IsNull(), 'b', NotNull())) 40036b7d8ebSJames Feist .WillOnce(Invoke([&](sd_bus_message* m, char type, void* p) { 40136b7d8ebSJames Feist bool* s = static_cast<bool*>(p); 40236b7d8ebSJames Feist *s = alarm; 40336b7d8ebSJames Feist return 0; 40436b7d8ebSJames Feist })); 40536b7d8ebSJames Feist 40636b7d8ebSJames Feist EXPECT_CALL(sdbus_mock, sd_bus_message_exit_container(IsNull())) 40736b7d8ebSJames Feist .WillOnce(Return(0)) /* variant. */ 40836b7d8ebSJames Feist .WillOnce(Return(0)) /* std::pair */ 40936b7d8ebSJames Feist .WillOnce(Return(0)); /* std::map */ 41036b7d8ebSJames Feist 4117af157b1SPatrick Venture int rv = handleSensorValue(msg, passive); 41236b7d8ebSJames Feist EXPECT_EQ(rv, 0); // It's always 0. 41336b7d8ebSJames Feist bool failed = passive->getFailed(); 41436b7d8ebSJames Feist EXPECT_EQ(failed, false); 41536b7d8ebSJames Feist } 416