Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 1 | #include "conf.hpp" |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 2 | #include "failsafeloggers/builder.hpp" |
Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 3 | #include "interfaces.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 4 | #include "pid/ec/pid.hpp" |
Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 5 | #include "pid/pidcontroller.hpp" |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 6 | #include "pid/zone.hpp" |
Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 7 | #include "pid/zone_interface.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 8 | #include "sensors/manager.hpp" |
Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 9 | #include "sensors/sensor.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 10 | #include "test/controller_mock.hpp" |
| 11 | #include "test/helpers.hpp" |
| 12 | #include "test/sensor_mock.hpp" |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 13 | |
Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 14 | #include <systemd/sd-bus.h> |
| 15 | |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 16 | #include <sdbusplus/test/sdbus_mock.hpp> |
| 17 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 18 | #include <chrono> |
Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 19 | #include <cstdint> |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 20 | #include <cstring> |
Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 21 | #include <map> |
| 22 | #include <memory> |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 23 | #include <optional> |
Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 24 | #include <string> |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 25 | #include <unordered_map> |
Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame^] | 26 | #include <utility> |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 27 | #include <vector> |
| 28 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 29 | #include <gmock/gmock.h> |
| 30 | #include <gtest/gtest.h> |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 31 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 32 | namespace pid_control |
| 33 | { |
| 34 | namespace |
| 35 | { |
| 36 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 37 | using ::testing::_; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 38 | using ::testing::IsNull; |
| 39 | using ::testing::Return; |
| 40 | using ::testing::StrEq; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 41 | |
| 42 | static std::string modeInterface = "xyz.openbmc_project.Control.Mode"; |
Harvey Wu | cc0232a | 2023-02-09 14:58:55 +0800 | [diff] [blame] | 43 | static std::string debugZoneInterface = "xyz.openbmc_project.Debug.Pid.Zone"; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 44 | static std::string enableInterface = "xyz.openbmc_project.Object.Enable"; |
Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 45 | static std::string debugThermalPowerInterface = |
| 46 | "xyz.openbmc_project.Debug.Pid.ThermalPower"; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 47 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 48 | namespace |
| 49 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 50 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 51 | TEST(PidZoneConstructorTest, BoringConstructorTest) |
| 52 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 53 | // Build a PID Zone. |
| 54 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 55 | sdbusplus::SdBusMock sdbus_mock_passive, sdbus_mock_host, sdbus_mock_mode, |
| 56 | sdbus_mock_enable; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 57 | auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive); |
| 58 | auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host); |
| 59 | auto bus_mock_mode = sdbusplus::get_mocked_new(&sdbus_mock_mode); |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 60 | auto bus_mock_enable = sdbusplus::get_mocked_new(&sdbus_mock_enable); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 61 | |
| 62 | EXPECT_CALL(sdbus_mock_host, |
| 63 | sd_bus_add_object_manager( |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 64 | IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 65 | .WillOnce(Return(0)); |
| 66 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 67 | SensorManager m(bus_mock_passive, bus_mock_host); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 68 | |
| 69 | bool defer = true; |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 70 | bool accSetPoint = false; |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 71 | const char* objPath = "/path/"; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 72 | int64_t zone = 1; |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 73 | double minThermalOutput = 1000.0; |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 74 | double failSafePercent = 100; |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 75 | conf::CycleTime cycleTime; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 76 | |
James Feist | 0709e2f | 2020-07-08 10:59:45 -0700 | [diff] [blame] | 77 | double d; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 78 | std::vector<std::string> properties; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 79 | SetupDbusObject(&sdbus_mock_mode, defer, objPath, modeInterface, properties, |
James Feist | 0709e2f | 2020-07-08 10:59:45 -0700 | [diff] [blame] | 80 | &d); |
Harvey Wu | cc0232a | 2023-02-09 14:58:55 +0800 | [diff] [blame] | 81 | SetupDbusObject(&sdbus_mock_mode, defer, objPath, debugZoneInterface, |
| 82 | properties, &d); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 83 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 84 | std::string sensorname = "temp1"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 85 | std::string pidsensorpath = |
| 86 | "/xyz/openbmc_project/settings/fanctrl/zone1/" + sensorname; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 87 | |
| 88 | double de; |
| 89 | std::vector<std::string> propertiesenable; |
| 90 | SetupDbusObject(&sdbus_mock_enable, defer, pidsensorpath.c_str(), |
| 91 | enableInterface, propertiesenable, &de); |
| 92 | |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 93 | DbusPidZone p(zone, minThermalOutput, failSafePercent, cycleTime, m, |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 94 | bus_mock_mode, objPath, defer, accSetPoint); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 95 | // Success. |
| 96 | } |
| 97 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 98 | } // namespace |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 99 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 100 | class PidZoneTest : public ::testing::Test |
| 101 | { |
| 102 | protected: |
| 103 | PidZoneTest() : |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 104 | properties(), sdbus_mock_passive(), sdbus_mock_host(), |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 105 | sdbus_mock_mode(), sdbus_mock_enable() |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 106 | { |
| 107 | EXPECT_CALL(sdbus_mock_host, |
| 108 | sd_bus_add_object_manager( |
| 109 | IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) |
| 110 | .WillOnce(Return(0)); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 111 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 112 | auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive); |
| 113 | auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host); |
| 114 | auto bus_mock_mode = sdbusplus::get_mocked_new(&sdbus_mock_mode); |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 115 | auto bus_mock_enable = sdbusplus::get_mocked_new(&sdbus_mock_enable); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 116 | |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 117 | mgr = SensorManager(bus_mock_passive, bus_mock_host); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 118 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 119 | SetupDbusObject(&sdbus_mock_mode, defer, objPath, modeInterface, |
| 120 | properties, &property_index); |
Harvey Wu | cc0232a | 2023-02-09 14:58:55 +0800 | [diff] [blame] | 121 | SetupDbusObject(&sdbus_mock_mode, defer, objPath, debugZoneInterface, |
| 122 | properties, &property_index); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 123 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 124 | SetupDbusObject(&sdbus_mock_enable, defer, pidsensorpath.c_str(), |
| 125 | enableInterface, propertiesenable, |
| 126 | &propertyenable_index); |
| 127 | |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 128 | zone = std::make_unique<DbusPidZone>( |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 129 | zoneId, minThermalOutput, failSafePercent, cycleTime, *mgr, |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 130 | bus_mock_mode, objPath, defer, accSetPoint); |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 131 | } |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 132 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 133 | // unused |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 134 | double property_index{}; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 135 | std::vector<std::string> properties; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 136 | double propertyenable_index; |
| 137 | std::vector<std::string> propertiesenable; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 138 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 139 | sdbusplus::SdBusMock sdbus_mock_passive; |
| 140 | sdbusplus::SdBusMock sdbus_mock_host; |
| 141 | sdbusplus::SdBusMock sdbus_mock_mode; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 142 | sdbusplus::SdBusMock sdbus_mock_enable; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 143 | int64_t zoneId = 1; |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 144 | double minThermalOutput = 1000.0; |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 145 | double failSafePercent = 100; |
Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 146 | double setpoint = 50.0; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 147 | bool defer = true; |
Delphine CC Chiu | 9788963 | 2023-11-06 11:32:46 +0800 | [diff] [blame] | 148 | bool accSetPoint = false; |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 149 | const char* objPath = "/path/"; |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 150 | std::optional<SensorManager> mgr; |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 151 | conf::CycleTime cycleTime; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 152 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 153 | std::string sensorname = "temp1"; |
Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 154 | std::string sensorType = "temp"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 155 | std::string pidsensorpath = |
| 156 | "/xyz/openbmc_project/settings/fanctrl/zone1/" + sensorname; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 157 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 158 | std::unique_ptr<DbusPidZone> zone; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 161 | TEST_F(PidZoneTest, GetZoneId_ReturnsExpected) |
| 162 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 163 | // Verifies the zoneId returned is what we expect. |
| 164 | |
Patrick Venture | 0bbeaf8 | 2018-10-30 18:50:31 -0700 | [diff] [blame] | 165 | EXPECT_EQ(zoneId, zone->getZoneID()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 168 | TEST_F(PidZoneTest, GetAndSetManualModeTest_BehavesAsExpected) |
| 169 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 170 | // Verifies that the zone starts in manual mode. Verifies that one can set |
| 171 | // the mode. |
| 172 | EXPECT_FALSE(zone->getManualMode()); |
| 173 | |
| 174 | zone->setManualMode(true); |
| 175 | EXPECT_TRUE(zone->getManualMode()); |
| 176 | } |
| 177 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 178 | TEST_F(PidZoneTest, AddPidControlProcessGetAndSetEnableTest_BehavesAsExpected) |
| 179 | { |
| 180 | // Verifies that the zone starts in enable mode. Verifies that one can set |
| 181 | // enable the mode. |
| 182 | auto bus_mock_enable = sdbusplus::get_mocked_new(&sdbus_mock_enable); |
| 183 | |
| 184 | EXPECT_CALL(sdbus_mock_mode, sd_bus_emit_properties_changed_strv( |
| 185 | IsNull(), StrEq(pidsensorpath.c_str()), |
| 186 | StrEq(enableInterface), NotNull())) |
| 187 | .Times(::testing::AnyNumber()) |
| 188 | .WillOnce(Invoke( |
| 189 | [&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path, |
| 190 | [[maybe_unused]] const char* interface, const char** names) { |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 191 | EXPECT_STREQ("Enable", names[0]); |
| 192 | return 0; |
| 193 | })); |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 194 | |
Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 195 | zone->addPidControlProcess(sensorname, sensorType, setpoint, |
| 196 | bus_mock_enable, pidsensorpath.c_str(), defer); |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 197 | EXPECT_TRUE(zone->isPidProcessEnabled(sensorname)); |
| 198 | } |
| 199 | |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 200 | TEST_F(PidZoneTest, SetManualMode_RedundantWritesEnabledOnceAfterManualMode) |
| 201 | { |
| 202 | // Tests adding a fan PID controller to the zone, and verifies it's |
| 203 | // touched during processing. |
| 204 | |
| 205 | std::unique_ptr<PIDController> tpid = |
| 206 | std::make_unique<ControllerMock>("fan1", zone.get()); |
| 207 | ControllerMock* tmock = reinterpret_cast<ControllerMock*>(tpid.get()); |
| 208 | |
| 209 | // Access the internal pid configuration to clear it out (unrelated to the |
| 210 | // test). |
Harvey Wu | 1b3b730 | 2024-10-04 16:49:46 +0800 | [diff] [blame] | 211 | [[maybe_unused]] ec::pid_info_t* info = tpid->getPIDInfo(); |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 212 | |
| 213 | zone->addFanPID(std::move(tpid)); |
| 214 | |
| 215 | EXPECT_CALL(*tmock, setptProc()).WillOnce(Return(10.0)); |
| 216 | EXPECT_CALL(*tmock, inputProc()).WillOnce(Return(11.0)); |
| 217 | EXPECT_CALL(*tmock, outputProc(_)); |
| 218 | |
| 219 | // while zone is in auto mode redundant writes should be disabled |
| 220 | EXPECT_FALSE(zone->getRedundantWrite()); |
| 221 | |
| 222 | // but switching from manual to auto enables a single redundant write |
| 223 | zone->setManualMode(true); |
| 224 | zone->setManualMode(false); |
| 225 | EXPECT_TRUE(zone->getRedundantWrite()); |
| 226 | |
| 227 | // after one iteration of a pid loop redundant write should be cleared |
| 228 | zone->processFans(); |
| 229 | EXPECT_FALSE(zone->getRedundantWrite()); |
| 230 | } |
| 231 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 232 | TEST_F(PidZoneTest, RpmSetPoints_AddMaxClear_BehaveAsExpected) |
| 233 | { |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 234 | // Tests addSetPoint, clearSetPoints, determineMaxSetPointRequest |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 235 | // and getMinThermalSetPoint. |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 236 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 237 | // Need to add pid control process for the zone that can enable |
| 238 | // the process and add the set point. |
| 239 | auto bus_mock_enable = sdbusplus::get_mocked_new(&sdbus_mock_enable); |
| 240 | |
| 241 | EXPECT_CALL(sdbus_mock_mode, sd_bus_emit_properties_changed_strv( |
| 242 | IsNull(), StrEq(pidsensorpath.c_str()), |
| 243 | StrEq(enableInterface), NotNull())) |
| 244 | .Times(::testing::AnyNumber()) |
| 245 | .WillOnce(Invoke( |
| 246 | [&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path, |
| 247 | [[maybe_unused]] const char* interface, const char** names) { |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 248 | EXPECT_STREQ("Enable", names[0]); |
| 249 | return 0; |
| 250 | })); |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 251 | |
Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 252 | zone->addPidControlProcess(sensorname, sensorType, setpoint, |
| 253 | bus_mock_enable, pidsensorpath.c_str(), defer); |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 254 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 255 | // At least one value must be above the minimum thermal setpoint used in |
| 256 | // the constructor otherwise it'll choose that value |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 257 | std::vector<double> values = {100, 200, 300, 400, 500, 5000}; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 258 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 259 | for (auto v : values) |
| 260 | { |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 261 | zone->addSetPoint(v, sensorname); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | // This will pull the maximum RPM setpoint request. |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 265 | zone->determineMaxSetPointRequest(); |
| 266 | EXPECT_EQ(5000, zone->getMaxSetPointRequest()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 267 | |
| 268 | // Clear the values, so it'll choose the minimum thermal setpoint. |
Patrick Venture | 9bbf333 | 2019-07-16 10:50:37 -0700 | [diff] [blame] | 269 | zone->clearSetPoints(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 270 | |
| 271 | // This will go through the RPM set point values and grab the maximum. |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 272 | zone->determineMaxSetPointRequest(); |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 273 | EXPECT_EQ(zone->getMinThermalSetPoint(), zone->getMaxSetPointRequest()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 276 | TEST_F(PidZoneTest, RpmSetPoints_AddBelowMinimum_BehavesAsExpected) |
| 277 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 278 | // Tests adding several RPM setpoints, however, they're all lower than the |
Patrick Venture | 7280e27 | 2019-02-11 10:45:32 -0800 | [diff] [blame] | 279 | // configured minimal thermal setpoint RPM value. |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 280 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 281 | // Need to add pid control process for the zone that can enable |
| 282 | // the process and add the set point. |
| 283 | auto bus_mock_enable = sdbusplus::get_mocked_new(&sdbus_mock_enable); |
| 284 | |
| 285 | EXPECT_CALL(sdbus_mock_mode, sd_bus_emit_properties_changed_strv( |
| 286 | IsNull(), StrEq(pidsensorpath.c_str()), |
| 287 | StrEq(enableInterface), NotNull())) |
| 288 | .Times(::testing::AnyNumber()) |
| 289 | .WillOnce(Invoke( |
| 290 | [&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path, |
| 291 | [[maybe_unused]] const char* interface, const char** names) { |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 292 | EXPECT_STREQ("Enable", names[0]); |
| 293 | return 0; |
| 294 | })); |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 295 | |
Harvey Wu | 3718006 | 2023-10-02 09:42:50 +0800 | [diff] [blame] | 296 | zone->addPidControlProcess(sensorname, sensorType, setpoint, |
| 297 | bus_mock_enable, pidsensorpath.c_str(), defer); |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 298 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 299 | std::vector<double> values = {100, 200, 300, 400, 500}; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 300 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 301 | for (auto v : values) |
| 302 | { |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 303 | zone->addSetPoint(v, sensorname); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | // This will pull the maximum RPM setpoint request. |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 307 | zone->determineMaxSetPointRequest(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 308 | |
| 309 | // Verifies the value returned in the minimal thermal rpm set point. |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 310 | EXPECT_EQ(zone->getMinThermalSetPoint(), zone->getMaxSetPointRequest()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 313 | TEST_F(PidZoneTest, GetFailSafePercent_SingleFailedReturnsExpected) |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 314 | { |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 315 | // Tests when only one sensor failed and the sensor's failsafe duty is zero, |
| 316 | // and verify that the sensor name is empty and failsafe duty is PID zone's |
| 317 | // failsafe duty. |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 318 | |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 319 | std::vector<std::string> input1 = {"temp1"}; |
| 320 | std::vector<std::string> input2 = {"temp2"}; |
| 321 | std::vector<std::string> input3 = {"temp3"}; |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 322 | std::vector<double> values = {0, 0, 0}; |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 323 | |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 324 | zone->addPidFailSafePercent(input1, values[0]); |
| 325 | zone->addPidFailSafePercent(input2, values[1]); |
| 326 | zone->addPidFailSafePercent(input3, values[2]); |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 327 | |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 328 | zone->markSensorMissing("temp1", "Sensor threshold asserted"); |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 329 | |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 330 | EXPECT_EQ(failSafePercent, zone->getFailSafePercent()); |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 331 | |
| 332 | std::map<std::string, std::pair<std::string, double>> failSensorList = |
| 333 | zone->getFailSafeSensors(); |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 334 | EXPECT_EQ(1U, failSensorList.size()); |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 335 | EXPECT_EQ("Sensor threshold asserted", failSensorList["temp1"].first); |
| 336 | EXPECT_EQ(failSafePercent, failSensorList["temp1"].second); |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 337 | } |
| 338 | |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 339 | TEST_F(PidZoneTest, GetFailSafePercent_MultiFailedReturnsExpected) |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 340 | { |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 341 | // Tests when multi sensor failed, and verify the final failsafe's sensor |
| 342 | // name and duty as expected. |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 343 | |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 344 | std::vector<std::string> input1 = {"temp1"}; |
| 345 | std::vector<std::string> input2 = {"temp2"}; |
| 346 | std::vector<std::string> input3 = {"temp3"}; |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 347 | std::vector<double> values = {60, 80, 70}; |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 348 | |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 349 | zone->addPidFailSafePercent(input1, values[0]); |
| 350 | zone->addPidFailSafePercent(input2, values[1]); |
| 351 | zone->addPidFailSafePercent(input3, values[2]); |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 352 | |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 353 | zone->markSensorMissing("temp1", "Sensor threshold asserted"); |
| 354 | zone->markSensorMissing("temp2", "Sensor reading bad"); |
| 355 | zone->markSensorMissing("temp3", "Sensor unavailable"); |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 356 | |
Harvey Wu | 92f9f3c | 2023-11-07 09:23:35 +0800 | [diff] [blame] | 357 | EXPECT_EQ(80, zone->getFailSafePercent()); |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 358 | |
| 359 | std::map<std::string, std::pair<std::string, double>> failSensorList = |
| 360 | zone->getFailSafeSensors(); |
Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 361 | EXPECT_EQ(3U, failSensorList.size()); |
Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 362 | EXPECT_EQ("Sensor threshold asserted", failSensorList["temp1"].first); |
| 363 | EXPECT_EQ(60, failSensorList["temp1"].second); |
| 364 | EXPECT_EQ("Sensor reading bad", failSensorList["temp2"].first); |
| 365 | EXPECT_EQ(80, failSensorList["temp2"].second); |
| 366 | EXPECT_EQ("Sensor unavailable", failSensorList["temp3"].first); |
| 367 | EXPECT_EQ(70, failSensorList["temp3"].second); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 370 | TEST_F(PidZoneTest, ThermalInputs_FailsafeToValid_ReadsSensors) |
| 371 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 372 | // This test will add a couple thermal inputs, and verify that the zone |
| 373 | // initializes into failsafe mode, and will read each sensor. |
| 374 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 375 | // Disable failsafe logger for the unit test. |
| 376 | std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map; |
| 377 | buildFailsafeLoggers(empty_zone_map, 0); |
| 378 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 379 | std::string name1 = "temp1"; |
| 380 | int64_t timeout = 1; |
| 381 | |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 382 | std::unique_ptr<Sensor> sensor1 = |
| 383 | std::make_unique<SensorMock>(name1, timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 384 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 385 | |
| 386 | std::string name2 = "temp2"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 387 | std::unique_ptr<Sensor> sensor2 = |
| 388 | std::make_unique<SensorMock>(name2, timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 389 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 390 | |
| 391 | std::string type = "unchecked"; |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 392 | mgr->addSensor(type, name1, std::move(sensor1)); |
| 393 | EXPECT_EQ(mgr->getSensor(name1), sensor_ptr1); |
| 394 | mgr->addSensor(type, name2, std::move(sensor2)); |
| 395 | EXPECT_EQ(mgr->getSensor(name2), sensor_ptr2); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 396 | |
| 397 | // Now that the sensors exist, add them to the zone. |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 398 | zone->addThermalInput(name1, false); |
| 399 | zone->addThermalInput(name2, false); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 400 | |
| 401 | // Initialize Zone |
| 402 | zone->initializeCache(); |
| 403 | |
| 404 | // Verify now in failsafe mode. |
| 405 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 406 | |
| 407 | ReadReturn r1; |
| 408 | r1.value = 10.0; |
| 409 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 410 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 411 | |
| 412 | ReadReturn r2; |
| 413 | r2.value = 11.0; |
| 414 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 415 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 416 | |
| 417 | // Read the sensors, this will put the values into the cache. |
| 418 | zone->updateSensors(); |
| 419 | |
| 420 | // We should no longer be in failsafe mode. |
| 421 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 422 | |
| 423 | EXPECT_EQ(r1.value, zone->getCachedValue(name1)); |
| 424 | EXPECT_EQ(r2.value, zone->getCachedValue(name2)); |
| 425 | } |
| 426 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 427 | TEST_F(PidZoneTest, FanInputTest_VerifiesFanValuesCached) |
| 428 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 429 | // This will add a couple fan inputs, and verify the values are cached. |
| 430 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 431 | // Disable failsafe logger for the unit test. |
| 432 | std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map; |
| 433 | buildFailsafeLoggers(empty_zone_map, 0); |
| 434 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 435 | std::string name1 = "fan1"; |
| 436 | int64_t timeout = 2; |
| 437 | |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 438 | std::unique_ptr<Sensor> sensor1 = |
| 439 | std::make_unique<SensorMock>(name1, timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 440 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 441 | |
| 442 | std::string name2 = "fan2"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 443 | std::unique_ptr<Sensor> sensor2 = |
| 444 | std::make_unique<SensorMock>(name2, timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 445 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 446 | |
| 447 | std::string type = "unchecked"; |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 448 | mgr->addSensor(type, name1, std::move(sensor1)); |
| 449 | EXPECT_EQ(mgr->getSensor(name1), sensor_ptr1); |
| 450 | mgr->addSensor(type, name2, std::move(sensor2)); |
| 451 | EXPECT_EQ(mgr->getSensor(name2), sensor_ptr2); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 452 | |
| 453 | // Now that the sensors exist, add them to the zone. |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 454 | zone->addFanInput(name1, false); |
| 455 | zone->addFanInput(name2, false); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 456 | |
| 457 | // Initialize Zone |
| 458 | zone->initializeCache(); |
| 459 | |
| 460 | ReadReturn r1; |
| 461 | r1.value = 10.0; |
| 462 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 463 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 464 | |
| 465 | ReadReturn r2; |
| 466 | r2.value = 11.0; |
| 467 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 468 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 469 | |
| 470 | // Method under test will read through each fan sensor for the zone and |
| 471 | // cache the values. |
| 472 | zone->updateFanTelemetry(); |
| 473 | |
| 474 | EXPECT_EQ(r1.value, zone->getCachedValue(name1)); |
| 475 | EXPECT_EQ(r2.value, zone->getCachedValue(name2)); |
| 476 | } |
| 477 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 478 | TEST_F(PidZoneTest, ThermalInput_ValueTimeoutEntersFailSafeMode) |
| 479 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 480 | // On the second updateSensors call, the updated timestamp will be beyond |
| 481 | // the timeout limit. |
| 482 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 483 | // Disable failsafe logger for the unit test. |
| 484 | std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map; |
| 485 | buildFailsafeLoggers(empty_zone_map, 0); |
| 486 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 487 | int64_t timeout = 1; |
| 488 | |
| 489 | std::string name1 = "temp1"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 490 | std::unique_ptr<Sensor> sensor1 = |
| 491 | std::make_unique<SensorMock>(name1, timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 492 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 493 | |
| 494 | std::string name2 = "temp2"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 495 | std::unique_ptr<Sensor> sensor2 = |
| 496 | std::make_unique<SensorMock>(name2, timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 497 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 498 | |
| 499 | std::string type = "unchecked"; |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 500 | mgr->addSensor(type, name1, std::move(sensor1)); |
| 501 | EXPECT_EQ(mgr->getSensor(name1), sensor_ptr1); |
| 502 | mgr->addSensor(type, name2, std::move(sensor2)); |
| 503 | EXPECT_EQ(mgr->getSensor(name2), sensor_ptr2); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 504 | |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 505 | zone->addThermalInput(name1, false); |
| 506 | zone->addThermalInput(name2, false); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 507 | |
| 508 | // Initialize Zone |
| 509 | zone->initializeCache(); |
| 510 | |
| 511 | // Verify now in failsafe mode. |
| 512 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 513 | |
| 514 | ReadReturn r1; |
| 515 | r1.value = 10.0; |
| 516 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 517 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 518 | |
| 519 | ReadReturn r2; |
| 520 | r2.value = 11.0; |
| 521 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 522 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 523 | |
| 524 | zone->updateSensors(); |
| 525 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 526 | |
| 527 | // Ok, so we're not in failsafe mode, so let's set updated to the past. |
| 528 | // sensor1 will have an updated field older than its timeout value, but |
| 529 | // sensor2 will be fine. :D |
| 530 | r1.updated -= std::chrono::seconds(3); |
| 531 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 532 | |
| 533 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 534 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 535 | |
| 536 | // Method under test will read each sensor. One sensor's value is older |
| 537 | // than the timeout for that sensor and this triggers failsafe mode. |
| 538 | zone->updateSensors(); |
| 539 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 540 | } |
| 541 | |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 542 | TEST_F(PidZoneTest, ThermalInput_MissingIsAcceptableNoFailSafe) |
| 543 | { |
| 544 | // This is similar to the above test, but because missingIsAcceptable |
| 545 | // is set for sensor1, the zone should not enter failsafe mode when |
| 546 | // only sensor1 goes missing. |
| 547 | // However, sensor2 going missing should still trigger failsafe mode. |
| 548 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 549 | // Disable failsafe logger for the unit test. |
| 550 | std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map; |
| 551 | buildFailsafeLoggers(empty_zone_map, 0); |
| 552 | |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 553 | int64_t timeout = 1; |
| 554 | |
| 555 | std::string name1 = "temp1"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 556 | std::unique_ptr<Sensor> sensor1 = |
| 557 | std::make_unique<SensorMock>(name1, timeout); |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 558 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
| 559 | |
| 560 | std::string name2 = "temp2"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 561 | std::unique_ptr<Sensor> sensor2 = |
| 562 | std::make_unique<SensorMock>(name2, timeout); |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 563 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
| 564 | |
| 565 | std::string type = "unchecked"; |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 566 | mgr->addSensor(type, name1, std::move(sensor1)); |
| 567 | EXPECT_EQ(mgr->getSensor(name1), sensor_ptr1); |
| 568 | mgr->addSensor(type, name2, std::move(sensor2)); |
| 569 | EXPECT_EQ(mgr->getSensor(name2), sensor_ptr2); |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 570 | |
| 571 | // Only sensor1 has MissingIsAcceptable enabled for it |
| 572 | zone->addThermalInput(name1, true); |
| 573 | zone->addThermalInput(name2, false); |
| 574 | |
| 575 | // Initialize Zone |
| 576 | zone->initializeCache(); |
| 577 | |
| 578 | // As sensors are not initialized, zone should be in failsafe mode |
| 579 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 580 | |
| 581 | // r1 not populated here, intentionally, to simulate a sensor that |
| 582 | // is not available yet, perhaps takes a long time to start up. |
| 583 | ReadReturn r1; |
| 584 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 585 | |
| 586 | ReadReturn r2; |
| 587 | r2.value = 11.0; |
| 588 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 589 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 590 | |
| 591 | zone->updateSensors(); |
| 592 | |
| 593 | // Only sensor2 has been initialized here. Failsafe should be false, |
| 594 | // because sensor1 MissingIsAcceptable so it is OK for it to go missing. |
| 595 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 596 | |
| 597 | r1.value = 10.0; |
| 598 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 599 | |
| 600 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 601 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 602 | zone->updateSensors(); |
| 603 | |
| 604 | // Both sensors are now properly initialized |
| 605 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 606 | |
| 607 | // Ok, so we're not in failsafe mode, so let's set updated to the past. |
| 608 | // sensor1 will have an updated field older than its timeout value, but |
| 609 | // sensor2 will be fine. :D |
| 610 | r1.updated -= std::chrono::seconds(3); |
| 611 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 612 | |
| 613 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 614 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 615 | zone->updateSensors(); |
| 616 | |
| 617 | // MissingIsAcceptable is true for sensor1, so the zone should not be |
| 618 | // thrown into failsafe mode. |
| 619 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 620 | |
| 621 | // Do the same thing, but for the opposite sensors: r1 is good, |
| 622 | // but r2 is set to some time in the past. |
| 623 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 624 | r2.updated -= std::chrono::seconds(3); |
| 625 | |
| 626 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 627 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 628 | zone->updateSensors(); |
| 629 | |
| 630 | // Now, the zone should be in failsafe mode, because sensor2 does not |
| 631 | // have MissingIsAcceptable set true, it is still subject to failsafe. |
| 632 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 633 | |
| 634 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 635 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 636 | |
| 637 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 638 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 639 | zone->updateSensors(); |
| 640 | |
| 641 | // The failsafe mode should cease, as both sensors are good again. |
| 642 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 643 | } |
| 644 | |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 645 | TEST_F(PidZoneTest, FanInputTest_FailsafeToValid_ReadsSensors) |
| 646 | { |
| 647 | // This will add a couple fan inputs, and verify the values are cached. |
| 648 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 649 | // Disable failsafe logger for the unit test. |
| 650 | std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map; |
| 651 | buildFailsafeLoggers(empty_zone_map, 0); |
| 652 | |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 653 | std::string name1 = "fan1"; |
| 654 | int64_t timeout = 2; |
| 655 | |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 656 | std::unique_ptr<Sensor> sensor1 = |
| 657 | std::make_unique<SensorMock>(name1, timeout); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 658 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
| 659 | |
| 660 | std::string name2 = "fan2"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 661 | std::unique_ptr<Sensor> sensor2 = |
| 662 | std::make_unique<SensorMock>(name2, timeout); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 663 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
| 664 | |
| 665 | std::string type = "unchecked"; |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 666 | mgr->addSensor(type, name1, std::move(sensor1)); |
| 667 | EXPECT_EQ(mgr->getSensor(name1), sensor_ptr1); |
| 668 | mgr->addSensor(type, name2, std::move(sensor2)); |
| 669 | EXPECT_EQ(mgr->getSensor(name2), sensor_ptr2); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 670 | |
| 671 | // Now that the sensors exist, add them to the zone. |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 672 | zone->addFanInput(name1, false); |
| 673 | zone->addFanInput(name2, false); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 674 | |
| 675 | // Initialize Zone |
| 676 | zone->initializeCache(); |
| 677 | |
| 678 | // Verify now in failsafe mode. |
| 679 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 680 | |
| 681 | ReadReturn r1; |
| 682 | r1.value = 10.0; |
| 683 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 684 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 685 | |
| 686 | ReadReturn r2; |
| 687 | r2.value = 11.0; |
| 688 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 689 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 690 | |
| 691 | // Method under test will read through each fan sensor for the zone and |
| 692 | // cache the values. |
| 693 | zone->updateFanTelemetry(); |
| 694 | |
| 695 | // We should no longer be in failsafe mode. |
| 696 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 697 | |
| 698 | EXPECT_EQ(r1.value, zone->getCachedValue(name1)); |
| 699 | EXPECT_EQ(r2.value, zone->getCachedValue(name2)); |
| 700 | } |
| 701 | |
| 702 | TEST_F(PidZoneTest, FanInputTest_ValueTimeoutEntersFailSafeMode) |
| 703 | { |
| 704 | // This will add a couple fan inputs, and verify the values are cached. |
| 705 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 706 | // Disable failsafe logger for the unit test. |
| 707 | std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map; |
| 708 | buildFailsafeLoggers(empty_zone_map, 0); |
| 709 | |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 710 | std::string name1 = "fan1"; |
| 711 | int64_t timeout = 2; |
| 712 | |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 713 | std::unique_ptr<Sensor> sensor1 = |
| 714 | std::make_unique<SensorMock>(name1, timeout); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 715 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
| 716 | |
| 717 | std::string name2 = "fan2"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 718 | std::unique_ptr<Sensor> sensor2 = |
| 719 | std::make_unique<SensorMock>(name2, timeout); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 720 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
| 721 | |
| 722 | std::string type = "unchecked"; |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 723 | mgr->addSensor(type, name1, std::move(sensor1)); |
| 724 | EXPECT_EQ(mgr->getSensor(name1), sensor_ptr1); |
| 725 | mgr->addSensor(type, name2, std::move(sensor2)); |
| 726 | EXPECT_EQ(mgr->getSensor(name2), sensor_ptr2); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 727 | |
| 728 | // Now that the sensors exist, add them to the zone. |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 729 | zone->addFanInput(name1, false); |
| 730 | zone->addFanInput(name2, false); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 731 | |
| 732 | // Initialize Zone |
| 733 | zone->initializeCache(); |
| 734 | |
| 735 | // Verify now in failsafe mode. |
| 736 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 737 | |
| 738 | ReadReturn r1; |
| 739 | r1.value = 10.0; |
| 740 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 741 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 742 | |
| 743 | ReadReturn r2; |
| 744 | r2.value = 11.0; |
| 745 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 746 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 747 | |
| 748 | // Method under test will read through each fan sensor for the zone and |
| 749 | // cache the values. |
| 750 | zone->updateFanTelemetry(); |
| 751 | |
| 752 | // We should no longer be in failsafe mode. |
| 753 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 754 | |
| 755 | r1.updated -= std::chrono::seconds(3); |
| 756 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 757 | |
| 758 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 759 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 760 | |
| 761 | zone->updateFanTelemetry(); |
| 762 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 763 | } |
| 764 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 765 | TEST_F(PidZoneTest, GetSensorTest_ReturnsExpected) |
| 766 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 767 | // One can grab a sensor from the manager through the zone. |
| 768 | |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 769 | // Disable failsafe logger for the unit test. |
| 770 | std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map; |
| 771 | buildFailsafeLoggers(empty_zone_map, 0); |
| 772 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 773 | int64_t timeout = 1; |
| 774 | |
| 775 | std::string name1 = "temp1"; |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 776 | std::unique_ptr<Sensor> sensor1 = |
| 777 | std::make_unique<SensorMock>(name1, timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 778 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 779 | |
| 780 | std::string type = "unchecked"; |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 781 | mgr->addSensor(type, name1, std::move(sensor1)); |
| 782 | EXPECT_EQ(mgr->getSensor(name1), sensor_ptr1); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 783 | |
Josh Lehan | 3f0f7bc | 2023-02-13 01:45:29 -0800 | [diff] [blame] | 784 | zone->addThermalInput(name1, false); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 785 | |
| 786 | // Verify method under test returns the pointer we expect. |
Patrick Williams | e3c6077 | 2025-04-07 17:53:42 -0400 | [diff] [blame] | 787 | EXPECT_EQ(mgr->getSensor(name1), zone->getSensor(name1)); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 790 | TEST_F(PidZoneTest, AddThermalPIDTest_VerifiesThermalPIDsProcessed) |
| 791 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 792 | // Tests adding a thermal PID controller to the zone, and verifies it's |
| 793 | // touched during processing. |
| 794 | |
| 795 | std::unique_ptr<PIDController> tpid = |
| 796 | std::make_unique<ControllerMock>("thermal1", zone.get()); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 797 | ControllerMock* tmock = reinterpret_cast<ControllerMock*>(tpid.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 798 | |
| 799 | // Access the internal pid configuration to clear it out (unrelated to the |
| 800 | // test). |
Harvey Wu | 1b3b730 | 2024-10-04 16:49:46 +0800 | [diff] [blame] | 801 | [[maybe_unused]] ec::pid_info_t* info = tpid->getPIDInfo(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 802 | |
| 803 | zone->addThermalPID(std::move(tpid)); |
| 804 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 805 | EXPECT_CALL(*tmock, setptProc()).WillOnce(Return(10.0)); |
| 806 | EXPECT_CALL(*tmock, inputProc()).WillOnce(Return(11.0)); |
| 807 | EXPECT_CALL(*tmock, outputProc(_)); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 808 | |
| 809 | // Method under test will, for each thermal PID, call setpt, input, and |
| 810 | // output. |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 811 | zone->processThermals(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 814 | TEST_F(PidZoneTest, AddFanPIDTest_VerifiesFanPIDsProcessed) |
| 815 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 816 | // Tests adding a fan PID controller to the zone, and verifies it's |
| 817 | // touched during processing. |
| 818 | |
| 819 | std::unique_ptr<PIDController> tpid = |
| 820 | std::make_unique<ControllerMock>("fan1", zone.get()); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 821 | ControllerMock* tmock = reinterpret_cast<ControllerMock*>(tpid.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 822 | |
| 823 | // Access the internal pid configuration to clear it out (unrelated to the |
| 824 | // test). |
Harvey Wu | 1b3b730 | 2024-10-04 16:49:46 +0800 | [diff] [blame] | 825 | [[maybe_unused]] ec::pid_info_t* info = tpid->getPIDInfo(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 826 | |
| 827 | zone->addFanPID(std::move(tpid)); |
| 828 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 829 | EXPECT_CALL(*tmock, setptProc()).WillOnce(Return(10.0)); |
| 830 | EXPECT_CALL(*tmock, inputProc()).WillOnce(Return(11.0)); |
| 831 | EXPECT_CALL(*tmock, outputProc(_)); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 832 | |
| 833 | // Method under test will, for each fan PID, call setpt, input, and output. |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 834 | zone->processFans(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 837 | TEST_F(PidZoneTest, ManualModeDbusTest_VerifySetManualBehavesAsExpected) |
| 838 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 839 | // The manual(bool) method is inherited from the dbus mode interface. |
| 840 | |
| 841 | // Verifies that someone doesn't remove the internal call to the dbus |
| 842 | // object from which we're inheriting. |
| 843 | EXPECT_CALL(sdbus_mock_mode, |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 844 | sd_bus_emit_properties_changed_strv( |
| 845 | IsNull(), StrEq(objPath), StrEq(modeInterface), NotNull())) |
Harvey.Wu | a1ae4fa | 2022-10-28 17:38:35 +0800 | [diff] [blame] | 846 | .WillOnce(Invoke( |
| 847 | [&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path, |
| 848 | [[maybe_unused]] const char* interface, const char** names) { |
Patrick Williams | bd63bca | 2024-08-16 15:21:10 -0400 | [diff] [blame] | 849 | EXPECT_STREQ("Manual", names[0]); |
| 850 | return 0; |
| 851 | })); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 852 | |
| 853 | // Method under test will set the manual mode to true and broadcast this |
| 854 | // change on dbus. |
| 855 | zone->manual(true); |
| 856 | EXPECT_TRUE(zone->getManualMode()); |
| 857 | } |
| 858 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 859 | TEST_F(PidZoneTest, FailsafeDbusTest_VerifiesReturnsExpected) |
| 860 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 861 | // This property is implemented by us as read-only, such that trying to |
| 862 | // write to it will have no effect. |
James Zheng | 6df8bb5 | 2024-11-27 23:38:47 +0000 | [diff] [blame] | 863 | |
| 864 | // Disable failsafe logger for the unit test. |
| 865 | std::unordered_map<int64_t, std::shared_ptr<ZoneInterface>> empty_zone_map; |
| 866 | buildFailsafeLoggers(empty_zone_map, 0); |
| 867 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 868 | EXPECT_EQ(zone->failSafe(), zone->getFailSafeMode()); |
| 869 | } |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 870 | |
| 871 | } // namespace |
| 872 | } // namespace pid_control |