Josh Lehan | de74542 | 2020-11-07 02:14:09 -0800 | [diff] [blame] | 1 | #include "pid/ec/logging.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 2 | #include "pid/ec/pid.hpp" |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 3 | #include "pid/zone.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 4 | #include "sensors/manager.hpp" |
| 5 | #include "test/controller_mock.hpp" |
| 6 | #include "test/helpers.hpp" |
| 7 | #include "test/sensor_mock.hpp" |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 8 | |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 9 | #include <sdbusplus/test/sdbus_mock.hpp> |
| 10 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 11 | #include <chrono> |
| 12 | #include <cstring> |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 15 | #include <gmock/gmock.h> |
| 16 | #include <gtest/gtest.h> |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 17 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 18 | namespace pid_control |
| 19 | { |
| 20 | namespace |
| 21 | { |
| 22 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 23 | using ::testing::_; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 24 | using ::testing::IsNull; |
| 25 | using ::testing::Return; |
| 26 | using ::testing::StrEq; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 27 | |
| 28 | static std::string modeInterface = "xyz.openbmc_project.Control.Mode"; |
Harvey Wu | cc0232a | 2023-02-09 14:58:55 +0800 | [diff] [blame^] | 29 | static std::string debugZoneInterface = "xyz.openbmc_project.Debug.Pid.Zone"; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 30 | static std::string enableInterface = "xyz.openbmc_project.Object.Enable"; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 31 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 32 | namespace |
| 33 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 34 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 35 | TEST(PidZoneConstructorTest, BoringConstructorTest) |
| 36 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 37 | // Build a PID Zone. |
| 38 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 39 | sdbusplus::SdBusMock sdbus_mock_passive, sdbus_mock_host, sdbus_mock_mode, |
| 40 | sdbus_mock_enable; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 41 | auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive); |
| 42 | auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host); |
| 43 | auto bus_mock_mode = sdbusplus::get_mocked_new(&sdbus_mock_mode); |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 44 | auto bus_mock_enable = sdbusplus::get_mocked_new(&sdbus_mock_enable); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 45 | |
| 46 | EXPECT_CALL(sdbus_mock_host, |
| 47 | sd_bus_add_object_manager( |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 48 | IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 49 | .WillOnce(Return(0)); |
| 50 | |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 51 | SensorManager m(bus_mock_passive, bus_mock_host); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 52 | |
| 53 | bool defer = true; |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 54 | const char* objPath = "/path/"; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 55 | int64_t zone = 1; |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 56 | double minThermalOutput = 1000.0; |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 57 | double failSafePercent = 0; |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 58 | conf::CycleTime cycleTime; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 59 | |
James Feist | 0709e2f | 2020-07-08 10:59:45 -0700 | [diff] [blame] | 60 | double d; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 61 | std::vector<std::string> properties; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 62 | SetupDbusObject(&sdbus_mock_mode, defer, objPath, modeInterface, properties, |
James Feist | 0709e2f | 2020-07-08 10:59:45 -0700 | [diff] [blame] | 63 | &d); |
Harvey Wu | cc0232a | 2023-02-09 14:58:55 +0800 | [diff] [blame^] | 64 | SetupDbusObject(&sdbus_mock_mode, defer, objPath, debugZoneInterface, |
| 65 | properties, &d); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 66 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 67 | std::string sensorname = "temp1"; |
| 68 | std::string pidsensorpath = "/xyz/openbmc_project/settings/fanctrl/zone1/" + |
| 69 | sensorname; |
| 70 | |
| 71 | double de; |
| 72 | std::vector<std::string> propertiesenable; |
| 73 | SetupDbusObject(&sdbus_mock_enable, defer, pidsensorpath.c_str(), |
| 74 | enableInterface, propertiesenable, &de); |
| 75 | |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 76 | DbusPidZone p(zone, minThermalOutput, failSafePercent, cycleTime, m, |
| 77 | bus_mock_mode, objPath, defer); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 78 | // Success. |
| 79 | } |
| 80 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 81 | } // namespace |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 82 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 83 | class PidZoneTest : public ::testing::Test |
| 84 | { |
| 85 | protected: |
| 86 | PidZoneTest() : |
| 87 | property_index(), properties(), sdbus_mock_passive(), sdbus_mock_host(), |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 88 | sdbus_mock_mode(), sdbus_mock_enable() |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 89 | { |
| 90 | EXPECT_CALL(sdbus_mock_host, |
| 91 | sd_bus_add_object_manager( |
| 92 | IsNull(), _, StrEq("/xyz/openbmc_project/extsensors"))) |
| 93 | .WillOnce(Return(0)); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 94 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 95 | auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive); |
| 96 | auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host); |
| 97 | auto bus_mock_mode = sdbusplus::get_mocked_new(&sdbus_mock_mode); |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 98 | auto bus_mock_enable = sdbusplus::get_mocked_new(&sdbus_mock_enable); |
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 | // Compiler weirdly not happy about just instantiating mgr(...); |
James Feist | 1fe0895 | 2019-05-07 09:17:16 -0700 | [diff] [blame] | 101 | SensorManager m(bus_mock_passive, bus_mock_host); |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 102 | mgr = std::move(m); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 103 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 104 | SetupDbusObject(&sdbus_mock_mode, defer, objPath, modeInterface, |
| 105 | properties, &property_index); |
Harvey Wu | cc0232a | 2023-02-09 14:58:55 +0800 | [diff] [blame^] | 106 | SetupDbusObject(&sdbus_mock_mode, defer, objPath, debugZoneInterface, |
| 107 | properties, &property_index); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 108 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 109 | SetupDbusObject(&sdbus_mock_enable, defer, pidsensorpath.c_str(), |
| 110 | enableInterface, propertiesenable, |
| 111 | &propertyenable_index); |
| 112 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 113 | zone = std::make_unique<DbusPidZone>(zoneId, minThermalOutput, |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 114 | failSafePercent, cycleTime, mgr, |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 115 | bus_mock_mode, objPath, defer); |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 116 | } |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 117 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 118 | // unused |
James Feist | 0709e2f | 2020-07-08 10:59:45 -0700 | [diff] [blame] | 119 | double property_index; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 120 | std::vector<std::string> properties; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 121 | double propertyenable_index; |
| 122 | std::vector<std::string> propertiesenable; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 123 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 124 | sdbusplus::SdBusMock sdbus_mock_passive; |
| 125 | sdbusplus::SdBusMock sdbus_mock_host; |
| 126 | sdbusplus::SdBusMock sdbus_mock_mode; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 127 | sdbusplus::SdBusMock sdbus_mock_enable; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 128 | int64_t zoneId = 1; |
James Feist | 3484bed | 2019-02-25 13:28:18 -0800 | [diff] [blame] | 129 | double minThermalOutput = 1000.0; |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 130 | double failSafePercent = 0; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 131 | bool defer = true; |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 132 | const char* objPath = "/path/"; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 133 | SensorManager mgr; |
Bonnie Lo | 0e8fc39 | 2022-10-05 10:20:55 +0800 | [diff] [blame] | 134 | conf::CycleTime cycleTime; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 135 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 136 | std::string sensorname = "temp1"; |
| 137 | std::string pidsensorpath = "/xyz/openbmc_project/settings/fanctrl/zone1/" + |
| 138 | sensorname; |
| 139 | |
Patrick Venture | 597ebd6 | 2020-08-11 08:48:19 -0700 | [diff] [blame] | 140 | std::unique_ptr<DbusPidZone> zone; |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 143 | TEST_F(PidZoneTest, GetZoneId_ReturnsExpected) |
| 144 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 145 | // Verifies the zoneId returned is what we expect. |
| 146 | |
Patrick Venture | 0bbeaf8 | 2018-10-30 18:50:31 -0700 | [diff] [blame] | 147 | EXPECT_EQ(zoneId, zone->getZoneID()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 150 | TEST_F(PidZoneTest, GetAndSetManualModeTest_BehavesAsExpected) |
| 151 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 152 | // Verifies that the zone starts in manual mode. Verifies that one can set |
| 153 | // the mode. |
| 154 | EXPECT_FALSE(zone->getManualMode()); |
| 155 | |
| 156 | zone->setManualMode(true); |
| 157 | EXPECT_TRUE(zone->getManualMode()); |
| 158 | } |
| 159 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 160 | TEST_F(PidZoneTest, AddPidControlProcessGetAndSetEnableTest_BehavesAsExpected) |
| 161 | { |
| 162 | // Verifies that the zone starts in enable mode. Verifies that one can set |
| 163 | // enable the mode. |
| 164 | auto bus_mock_enable = sdbusplus::get_mocked_new(&sdbus_mock_enable); |
| 165 | |
| 166 | EXPECT_CALL(sdbus_mock_mode, sd_bus_emit_properties_changed_strv( |
| 167 | IsNull(), StrEq(pidsensorpath.c_str()), |
| 168 | StrEq(enableInterface), NotNull())) |
| 169 | .Times(::testing::AnyNumber()) |
| 170 | .WillOnce(Invoke( |
| 171 | [&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path, |
| 172 | [[maybe_unused]] const char* interface, const char** names) { |
| 173 | EXPECT_STREQ("Enable", names[0]); |
| 174 | return 0; |
| 175 | })); |
| 176 | |
| 177 | zone->addPidControlProcess(sensorname, bus_mock_enable, |
| 178 | pidsensorpath.c_str(), defer); |
| 179 | EXPECT_TRUE(zone->isPidProcessEnabled(sensorname)); |
| 180 | } |
| 181 | |
Josh Lehan | a4146eb | 2020-10-01 11:49:09 -0700 | [diff] [blame] | 182 | TEST_F(PidZoneTest, SetManualMode_RedundantWritesEnabledOnceAfterManualMode) |
| 183 | { |
| 184 | // Tests adding a fan PID controller to the zone, and verifies it's |
| 185 | // touched during processing. |
| 186 | |
| 187 | std::unique_ptr<PIDController> tpid = |
| 188 | std::make_unique<ControllerMock>("fan1", zone.get()); |
| 189 | ControllerMock* tmock = reinterpret_cast<ControllerMock*>(tpid.get()); |
| 190 | |
| 191 | // Access the internal pid configuration to clear it out (unrelated to the |
| 192 | // test). |
| 193 | ec::pid_info_t* info = tpid->getPIDInfo(); |
| 194 | std::memset(info, 0x00, sizeof(ec::pid_info_t)); |
| 195 | |
| 196 | zone->addFanPID(std::move(tpid)); |
| 197 | |
| 198 | EXPECT_CALL(*tmock, setptProc()).WillOnce(Return(10.0)); |
| 199 | EXPECT_CALL(*tmock, inputProc()).WillOnce(Return(11.0)); |
| 200 | EXPECT_CALL(*tmock, outputProc(_)); |
| 201 | |
| 202 | // while zone is in auto mode redundant writes should be disabled |
| 203 | EXPECT_FALSE(zone->getRedundantWrite()); |
| 204 | |
| 205 | // but switching from manual to auto enables a single redundant write |
| 206 | zone->setManualMode(true); |
| 207 | zone->setManualMode(false); |
| 208 | EXPECT_TRUE(zone->getRedundantWrite()); |
| 209 | |
| 210 | // after one iteration of a pid loop redundant write should be cleared |
| 211 | zone->processFans(); |
| 212 | EXPECT_FALSE(zone->getRedundantWrite()); |
| 213 | } |
| 214 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 215 | TEST_F(PidZoneTest, RpmSetPoints_AddMaxClear_BehaveAsExpected) |
| 216 | { |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 217 | // Tests addSetPoint, clearSetPoints, determineMaxSetPointRequest |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 218 | // and getMinThermalSetPoint. |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 219 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 220 | // Need to add pid control process for the zone that can enable |
| 221 | // the process and add the set point. |
| 222 | auto bus_mock_enable = sdbusplus::get_mocked_new(&sdbus_mock_enable); |
| 223 | |
| 224 | EXPECT_CALL(sdbus_mock_mode, sd_bus_emit_properties_changed_strv( |
| 225 | IsNull(), StrEq(pidsensorpath.c_str()), |
| 226 | StrEq(enableInterface), NotNull())) |
| 227 | .Times(::testing::AnyNumber()) |
| 228 | .WillOnce(Invoke( |
| 229 | [&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path, |
| 230 | [[maybe_unused]] const char* interface, const char** names) { |
| 231 | EXPECT_STREQ("Enable", names[0]); |
| 232 | return 0; |
| 233 | })); |
| 234 | |
| 235 | zone->addPidControlProcess(sensorname, bus_mock_enable, |
| 236 | pidsensorpath.c_str(), defer); |
| 237 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 238 | // At least one value must be above the minimum thermal setpoint used in |
| 239 | // the constructor otherwise it'll choose that value |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 240 | std::vector<double> values = {100, 200, 300, 400, 500, 5000}; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 241 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 242 | for (auto v : values) |
| 243 | { |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 244 | zone->addSetPoint(v, sensorname); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | // This will pull the maximum RPM setpoint request. |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 248 | zone->determineMaxSetPointRequest(); |
| 249 | EXPECT_EQ(5000, zone->getMaxSetPointRequest()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 250 | |
| 251 | // Clear the values, so it'll choose the minimum thermal setpoint. |
Patrick Venture | 9bbf333 | 2019-07-16 10:50:37 -0700 | [diff] [blame] | 252 | zone->clearSetPoints(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 253 | |
| 254 | // 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] | 255 | zone->determineMaxSetPointRequest(); |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 256 | EXPECT_EQ(zone->getMinThermalSetPoint(), zone->getMaxSetPointRequest()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 259 | TEST_F(PidZoneTest, RpmSetPoints_AddBelowMinimum_BehavesAsExpected) |
| 260 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 261 | // Tests adding several RPM setpoints, however, they're all lower than the |
Patrick Venture | 7280e27 | 2019-02-11 10:45:32 -0800 | [diff] [blame] | 262 | // configured minimal thermal setpoint RPM value. |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 263 | |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 264 | // Need to add pid control process for the zone that can enable |
| 265 | // the process and add the set point. |
| 266 | auto bus_mock_enable = sdbusplus::get_mocked_new(&sdbus_mock_enable); |
| 267 | |
| 268 | EXPECT_CALL(sdbus_mock_mode, sd_bus_emit_properties_changed_strv( |
| 269 | IsNull(), StrEq(pidsensorpath.c_str()), |
| 270 | StrEq(enableInterface), NotNull())) |
| 271 | .Times(::testing::AnyNumber()) |
| 272 | .WillOnce(Invoke( |
| 273 | [&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path, |
| 274 | [[maybe_unused]] const char* interface, const char** names) { |
| 275 | EXPECT_STREQ("Enable", names[0]); |
| 276 | return 0; |
| 277 | })); |
| 278 | |
| 279 | zone->addPidControlProcess(sensorname, bus_mock_enable, |
| 280 | pidsensorpath.c_str(), defer); |
| 281 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 282 | std::vector<double> values = {100, 200, 300, 400, 500}; |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 283 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 284 | for (auto v : values) |
| 285 | { |
ykchiu | 7c6d35d | 2023-05-10 17:01:46 +0800 | [diff] [blame] | 286 | zone->addSetPoint(v, sensorname); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // This will pull the maximum RPM setpoint request. |
Patrick Venture | f7a2dd5 | 2019-07-16 14:31:13 -0700 | [diff] [blame] | 290 | zone->determineMaxSetPointRequest(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 291 | |
| 292 | // Verifies the value returned in the minimal thermal rpm set point. |
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 293 | EXPECT_EQ(zone->getMinThermalSetPoint(), zone->getMaxSetPointRequest()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 296 | TEST_F(PidZoneTest, GetFailSafePercent_ReturnsExpected) |
| 297 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 298 | // Verify the value used to create the object is stored. |
ykchiu | 9fe3a3c | 2023-05-11 13:43:54 +0800 | [diff] [blame] | 299 | // when the final failsafe percent is zero , it indicate |
| 300 | // no failsafe percent is configured  , set it to 100% as |
| 301 | // the default setting. |
| 302 | |
| 303 | std::vector<double> values = {0, 0, 0}; |
| 304 | int64_t defaultPercent = 100; |
| 305 | |
| 306 | zone->addPidFailSafePercent("temp1", values[0]); |
| 307 | zone->addPidFailSafePercent("temp2", values[1]); |
| 308 | zone->addPidFailSafePercent("temp3", values[2]); |
| 309 | |
| 310 | zone->initPidFailSafePercent(); |
| 311 | |
| 312 | EXPECT_EQ(defaultPercent, zone->getFailSafePercent()); |
| 313 | } |
| 314 | |
| 315 | TEST_F(PidZoneTest, GetFailSafePercent_VerifyReturnsExpected) |
| 316 | { |
| 317 | // Tests adding PID controller with FailSafePercent to the zone, |
| 318 | // and verifies it's returned as expected. |
| 319 | |
| 320 | std::vector<double> values = {60, 80, 70}; |
| 321 | double max_value = 0; |
| 322 | |
| 323 | for (const auto& value : values) |
| 324 | { |
| 325 | max_value = std::max(max_value, value); |
| 326 | } |
| 327 | |
| 328 | zone->addPidFailSafePercent("temp1", values[0]); |
| 329 | zone->addPidFailSafePercent("temp2", values[1]); |
| 330 | zone->addPidFailSafePercent("temp3", values[2]); |
| 331 | |
| 332 | zone->initPidFailSafePercent(); |
| 333 | |
| 334 | EXPECT_EQ(max_value, zone->getFailSafePercent()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 337 | TEST_F(PidZoneTest, ThermalInputs_FailsafeToValid_ReadsSensors) |
| 338 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 339 | // This test will add a couple thermal inputs, and verify that the zone |
| 340 | // initializes into failsafe mode, and will read each sensor. |
| 341 | |
| 342 | std::string name1 = "temp1"; |
| 343 | int64_t timeout = 1; |
| 344 | |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 345 | std::unique_ptr<Sensor> sensor1 = std::make_unique<SensorMock>(name1, |
| 346 | timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 347 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 348 | |
| 349 | std::string name2 = "temp2"; |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 350 | std::unique_ptr<Sensor> sensor2 = std::make_unique<SensorMock>(name2, |
| 351 | timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 352 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 353 | |
| 354 | std::string type = "unchecked"; |
| 355 | mgr.addSensor(type, name1, std::move(sensor1)); |
| 356 | EXPECT_EQ(mgr.getSensor(name1), sensor_ptr1); |
| 357 | mgr.addSensor(type, name2, std::move(sensor2)); |
| 358 | EXPECT_EQ(mgr.getSensor(name2), sensor_ptr2); |
| 359 | |
| 360 | // Now that the sensors exist, add them to the zone. |
| 361 | zone->addThermalInput(name1); |
| 362 | zone->addThermalInput(name2); |
| 363 | |
| 364 | // Initialize Zone |
| 365 | zone->initializeCache(); |
| 366 | |
| 367 | // Verify now in failsafe mode. |
| 368 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 369 | |
| 370 | ReadReturn r1; |
| 371 | r1.value = 10.0; |
| 372 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 373 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 374 | |
| 375 | ReadReturn r2; |
| 376 | r2.value = 11.0; |
| 377 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 378 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 379 | |
| 380 | // Read the sensors, this will put the values into the cache. |
| 381 | zone->updateSensors(); |
| 382 | |
| 383 | // We should no longer be in failsafe mode. |
| 384 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 385 | |
| 386 | EXPECT_EQ(r1.value, zone->getCachedValue(name1)); |
| 387 | EXPECT_EQ(r2.value, zone->getCachedValue(name2)); |
| 388 | } |
| 389 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 390 | TEST_F(PidZoneTest, FanInputTest_VerifiesFanValuesCached) |
| 391 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 392 | // This will add a couple fan inputs, and verify the values are cached. |
| 393 | |
| 394 | std::string name1 = "fan1"; |
| 395 | int64_t timeout = 2; |
| 396 | |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 397 | std::unique_ptr<Sensor> sensor1 = std::make_unique<SensorMock>(name1, |
| 398 | timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 399 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 400 | |
| 401 | std::string name2 = "fan2"; |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 402 | std::unique_ptr<Sensor> sensor2 = std::make_unique<SensorMock>(name2, |
| 403 | timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 404 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 405 | |
| 406 | std::string type = "unchecked"; |
| 407 | mgr.addSensor(type, name1, std::move(sensor1)); |
| 408 | EXPECT_EQ(mgr.getSensor(name1), sensor_ptr1); |
| 409 | mgr.addSensor(type, name2, std::move(sensor2)); |
| 410 | EXPECT_EQ(mgr.getSensor(name2), sensor_ptr2); |
| 411 | |
| 412 | // Now that the sensors exist, add them to the zone. |
| 413 | zone->addFanInput(name1); |
| 414 | zone->addFanInput(name2); |
| 415 | |
| 416 | // Initialize Zone |
| 417 | zone->initializeCache(); |
| 418 | |
| 419 | ReadReturn r1; |
| 420 | r1.value = 10.0; |
| 421 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 422 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 423 | |
| 424 | ReadReturn r2; |
| 425 | r2.value = 11.0; |
| 426 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 427 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 428 | |
| 429 | // Method under test will read through each fan sensor for the zone and |
| 430 | // cache the values. |
| 431 | zone->updateFanTelemetry(); |
| 432 | |
| 433 | EXPECT_EQ(r1.value, zone->getCachedValue(name1)); |
| 434 | EXPECT_EQ(r2.value, zone->getCachedValue(name2)); |
| 435 | } |
| 436 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 437 | TEST_F(PidZoneTest, ThermalInput_ValueTimeoutEntersFailSafeMode) |
| 438 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 439 | // On the second updateSensors call, the updated timestamp will be beyond |
| 440 | // the timeout limit. |
| 441 | |
| 442 | int64_t timeout = 1; |
| 443 | |
| 444 | std::string name1 = "temp1"; |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 445 | std::unique_ptr<Sensor> sensor1 = std::make_unique<SensorMock>(name1, |
| 446 | timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 447 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 448 | |
| 449 | std::string name2 = "temp2"; |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 450 | std::unique_ptr<Sensor> sensor2 = std::make_unique<SensorMock>(name2, |
| 451 | timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 452 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 453 | |
| 454 | std::string type = "unchecked"; |
| 455 | mgr.addSensor(type, name1, std::move(sensor1)); |
| 456 | EXPECT_EQ(mgr.getSensor(name1), sensor_ptr1); |
| 457 | mgr.addSensor(type, name2, std::move(sensor2)); |
| 458 | EXPECT_EQ(mgr.getSensor(name2), sensor_ptr2); |
| 459 | |
| 460 | zone->addThermalInput(name1); |
| 461 | zone->addThermalInput(name2); |
| 462 | |
| 463 | // Initialize Zone |
| 464 | zone->initializeCache(); |
| 465 | |
| 466 | // Verify now in failsafe mode. |
| 467 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 468 | |
| 469 | ReadReturn r1; |
| 470 | r1.value = 10.0; |
| 471 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 472 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 473 | |
| 474 | ReadReturn r2; |
| 475 | r2.value = 11.0; |
| 476 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 477 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 478 | |
| 479 | zone->updateSensors(); |
| 480 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 481 | |
| 482 | // Ok, so we're not in failsafe mode, so let's set updated to the past. |
| 483 | // sensor1 will have an updated field older than its timeout value, but |
| 484 | // sensor2 will be fine. :D |
| 485 | r1.updated -= std::chrono::seconds(3); |
| 486 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 487 | |
| 488 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 489 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 490 | |
| 491 | // Method under test will read each sensor. One sensor's value is older |
| 492 | // than the timeout for that sensor and this triggers failsafe mode. |
| 493 | zone->updateSensors(); |
| 494 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 495 | } |
| 496 | |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 497 | TEST_F(PidZoneTest, FanInputTest_FailsafeToValid_ReadsSensors) |
| 498 | { |
| 499 | // This will add a couple fan inputs, and verify the values are cached. |
| 500 | |
| 501 | std::string name1 = "fan1"; |
| 502 | int64_t timeout = 2; |
| 503 | |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 504 | std::unique_ptr<Sensor> sensor1 = std::make_unique<SensorMock>(name1, |
| 505 | timeout); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 506 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
| 507 | |
| 508 | std::string name2 = "fan2"; |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 509 | std::unique_ptr<Sensor> sensor2 = std::make_unique<SensorMock>(name2, |
| 510 | timeout); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 511 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
| 512 | |
| 513 | std::string type = "unchecked"; |
| 514 | mgr.addSensor(type, name1, std::move(sensor1)); |
| 515 | EXPECT_EQ(mgr.getSensor(name1), sensor_ptr1); |
| 516 | mgr.addSensor(type, name2, std::move(sensor2)); |
| 517 | EXPECT_EQ(mgr.getSensor(name2), sensor_ptr2); |
| 518 | |
| 519 | // Now that the sensors exist, add them to the zone. |
| 520 | zone->addFanInput(name1); |
| 521 | zone->addFanInput(name2); |
| 522 | |
| 523 | // Initialize Zone |
| 524 | zone->initializeCache(); |
| 525 | |
| 526 | // Verify now in failsafe mode. |
| 527 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 528 | |
| 529 | ReadReturn r1; |
| 530 | r1.value = 10.0; |
| 531 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 532 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 533 | |
| 534 | ReadReturn r2; |
| 535 | r2.value = 11.0; |
| 536 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 537 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 538 | |
| 539 | // Method under test will read through each fan sensor for the zone and |
| 540 | // cache the values. |
| 541 | zone->updateFanTelemetry(); |
| 542 | |
| 543 | // We should no longer be in failsafe mode. |
| 544 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 545 | |
| 546 | EXPECT_EQ(r1.value, zone->getCachedValue(name1)); |
| 547 | EXPECT_EQ(r2.value, zone->getCachedValue(name2)); |
| 548 | } |
| 549 | |
| 550 | TEST_F(PidZoneTest, FanInputTest_ValueTimeoutEntersFailSafeMode) |
| 551 | { |
| 552 | // This will add a couple fan inputs, and verify the values are cached. |
| 553 | |
| 554 | std::string name1 = "fan1"; |
| 555 | int64_t timeout = 2; |
| 556 | |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 557 | std::unique_ptr<Sensor> sensor1 = std::make_unique<SensorMock>(name1, |
| 558 | timeout); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 559 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
| 560 | |
| 561 | std::string name2 = "fan2"; |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 562 | std::unique_ptr<Sensor> sensor2 = std::make_unique<SensorMock>(name2, |
| 563 | timeout); |
Will Liang | ded0ab5 | 2019-05-15 17:10:06 +0800 | [diff] [blame] | 564 | SensorMock* sensor_ptr2 = reinterpret_cast<SensorMock*>(sensor2.get()); |
| 565 | |
| 566 | std::string type = "unchecked"; |
| 567 | mgr.addSensor(type, name1, std::move(sensor1)); |
| 568 | EXPECT_EQ(mgr.getSensor(name1), sensor_ptr1); |
| 569 | mgr.addSensor(type, name2, std::move(sensor2)); |
| 570 | EXPECT_EQ(mgr.getSensor(name2), sensor_ptr2); |
| 571 | |
| 572 | // Now that the sensors exist, add them to the zone. |
| 573 | zone->addFanInput(name1); |
| 574 | zone->addFanInput(name2); |
| 575 | |
| 576 | // Initialize Zone |
| 577 | zone->initializeCache(); |
| 578 | |
| 579 | // Verify now in failsafe mode. |
| 580 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 581 | |
| 582 | ReadReturn r1; |
| 583 | r1.value = 10.0; |
| 584 | r1.updated = std::chrono::high_resolution_clock::now(); |
| 585 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 586 | |
| 587 | ReadReturn r2; |
| 588 | r2.value = 11.0; |
| 589 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 590 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 591 | |
| 592 | // Method under test will read through each fan sensor for the zone and |
| 593 | // cache the values. |
| 594 | zone->updateFanTelemetry(); |
| 595 | |
| 596 | // We should no longer be in failsafe mode. |
| 597 | EXPECT_FALSE(zone->getFailSafeMode()); |
| 598 | |
| 599 | r1.updated -= std::chrono::seconds(3); |
| 600 | r2.updated = std::chrono::high_resolution_clock::now(); |
| 601 | |
| 602 | EXPECT_CALL(*sensor_ptr1, read()).WillOnce(Return(r1)); |
| 603 | EXPECT_CALL(*sensor_ptr2, read()).WillOnce(Return(r2)); |
| 604 | |
| 605 | zone->updateFanTelemetry(); |
| 606 | EXPECT_TRUE(zone->getFailSafeMode()); |
| 607 | } |
| 608 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 609 | TEST_F(PidZoneTest, GetSensorTest_ReturnsExpected) |
| 610 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 611 | // One can grab a sensor from the manager through the zone. |
| 612 | |
| 613 | int64_t timeout = 1; |
| 614 | |
| 615 | std::string name1 = "temp1"; |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 616 | std::unique_ptr<Sensor> sensor1 = std::make_unique<SensorMock>(name1, |
| 617 | timeout); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 618 | SensorMock* sensor_ptr1 = reinterpret_cast<SensorMock*>(sensor1.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 619 | |
| 620 | std::string type = "unchecked"; |
| 621 | mgr.addSensor(type, name1, std::move(sensor1)); |
| 622 | EXPECT_EQ(mgr.getSensor(name1), sensor_ptr1); |
| 623 | |
| 624 | zone->addThermalInput(name1); |
| 625 | |
| 626 | // Verify method under test returns the pointer we expect. |
| 627 | EXPECT_EQ(mgr.getSensor(name1), zone->getSensor(name1)); |
| 628 | } |
| 629 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 630 | TEST_F(PidZoneTest, AddThermalPIDTest_VerifiesThermalPIDsProcessed) |
| 631 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 632 | // Tests adding a thermal PID controller to the zone, and verifies it's |
| 633 | // touched during processing. |
| 634 | |
| 635 | std::unique_ptr<PIDController> tpid = |
| 636 | std::make_unique<ControllerMock>("thermal1", zone.get()); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 637 | ControllerMock* tmock = reinterpret_cast<ControllerMock*>(tpid.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 638 | |
| 639 | // Access the internal pid configuration to clear it out (unrelated to the |
| 640 | // test). |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 641 | ec::pid_info_t* info = tpid->getPIDInfo(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 642 | std::memset(info, 0x00, sizeof(ec::pid_info_t)); |
| 643 | |
| 644 | zone->addThermalPID(std::move(tpid)); |
| 645 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 646 | EXPECT_CALL(*tmock, setptProc()).WillOnce(Return(10.0)); |
| 647 | EXPECT_CALL(*tmock, inputProc()).WillOnce(Return(11.0)); |
| 648 | EXPECT_CALL(*tmock, outputProc(_)); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 649 | |
| 650 | // Method under test will, for each thermal PID, call setpt, input, and |
| 651 | // output. |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 652 | zone->processThermals(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 655 | TEST_F(PidZoneTest, AddFanPIDTest_VerifiesFanPIDsProcessed) |
| 656 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 657 | // Tests adding a fan PID controller to the zone, and verifies it's |
| 658 | // touched during processing. |
| 659 | |
| 660 | std::unique_ptr<PIDController> tpid = |
| 661 | std::make_unique<ControllerMock>("fan1", zone.get()); |
Patrick Venture | e2ec0f6 | 2018-09-04 12:30:27 -0700 | [diff] [blame] | 662 | ControllerMock* tmock = reinterpret_cast<ControllerMock*>(tpid.get()); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 663 | |
| 664 | // Access the internal pid configuration to clear it out (unrelated to the |
| 665 | // test). |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 666 | ec::pid_info_t* info = tpid->getPIDInfo(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 667 | std::memset(info, 0x00, sizeof(ec::pid_info_t)); |
| 668 | |
| 669 | zone->addFanPID(std::move(tpid)); |
| 670 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 671 | EXPECT_CALL(*tmock, setptProc()).WillOnce(Return(10.0)); |
| 672 | EXPECT_CALL(*tmock, inputProc()).WillOnce(Return(11.0)); |
| 673 | EXPECT_CALL(*tmock, outputProc(_)); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 674 | |
| 675 | // 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] | 676 | zone->processFans(); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 679 | TEST_F(PidZoneTest, ManualModeDbusTest_VerifySetManualBehavesAsExpected) |
| 680 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 681 | // The manual(bool) method is inherited from the dbus mode interface. |
| 682 | |
| 683 | // Verifies that someone doesn't remove the internal call to the dbus |
| 684 | // object from which we're inheriting. |
| 685 | EXPECT_CALL(sdbus_mock_mode, |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 686 | sd_bus_emit_properties_changed_strv( |
| 687 | IsNull(), StrEq(objPath), StrEq(modeInterface), NotNull())) |
Harvey.Wu | a1ae4fa | 2022-10-28 17:38:35 +0800 | [diff] [blame] | 688 | .WillOnce(Invoke( |
| 689 | [&]([[maybe_unused]] sd_bus* bus, [[maybe_unused]] const char* path, |
| 690 | [[maybe_unused]] const char* interface, const char** names) { |
Patrick Williams | 8c05112 | 2023-05-10 07:50:59 -0500 | [diff] [blame] | 691 | EXPECT_STREQ("Manual", names[0]); |
| 692 | return 0; |
| 693 | })); |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 694 | |
| 695 | // Method under test will set the manual mode to true and broadcast this |
| 696 | // change on dbus. |
| 697 | zone->manual(true); |
| 698 | EXPECT_TRUE(zone->getManualMode()); |
| 699 | } |
| 700 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 701 | TEST_F(PidZoneTest, FailsafeDbusTest_VerifiesReturnsExpected) |
| 702 | { |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 703 | // This property is implemented by us as read-only, such that trying to |
| 704 | // write to it will have no effect. |
| 705 | EXPECT_EQ(zone->failSafe(), zone->getFailSafeMode()); |
| 706 | } |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 707 | |
| 708 | } // namespace |
| 709 | } // namespace pid_control |