| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include <catch2/catch_all.hpp> |
| 5 | #include <catch2/trompeloeil.hpp> |
| 6 | |
| 7 | #include "common/commandqueuestub.h" |
| 8 | #include "common/vectorstringdatasourcestub.h" |
| 9 | #include "core/components/controls/amd/fan/overdrive/curve/odfancurve.h" |
| 10 | |
| 11 | extern template struct trompeloeil::reporter<trompeloeil::specialized>; |
| 12 | |
| 13 | namespace Tests::AMD::OdFanCurve { |
| 14 | |
| 15 | class OdFanCurveTestAdapter : public ::AMD::OdFanCurve |
| 16 | { |
| 17 | public: |
| 18 | // clang-format off |
| 19 | using ::AMD::OdFanCurve::OdFanCurve; |
| 20 | |
| 21 | using ::AMD::OdFanCurve::exportControl; |
| 22 | using ::AMD::OdFanCurve::importControl; |
| 23 | using ::AMD::OdFanCurve::cleanControl; |
| 24 | using ::AMD::OdFanCurve::syncControl; |
| 25 | |
| 26 | using ::AMD::OdFanCurve::defaultCurve; |
| 27 | using ::AMD::OdFanCurve::fanCurve; |
| 28 | using ::AMD::OdFanCurve::controlPoints; |
| 29 | using ::AMD::OdFanCurve::tempRange; |
| 30 | using ::AMD::OdFanCurve::speedRange; |
| 31 | using ::AMD::OdFanCurve::isZeroCurve; |
| 32 | using ::AMD::OdFanCurve::setPointCoordinatesFrom; |
| 33 | using ::AMD::OdFanCurve::controlPointCmd; |
| 34 | using ::AMD::OdFanCurve::toCurvePoints; |
| 35 | using ::AMD::OdFanCurve::stop; |
| 36 | using ::AMD::OdFanCurve::stopTemp; |
| 37 | using ::AMD::OdFanCurve::stopTempRange; |
| 38 | // clang-format on |
| 39 | }; |
| 40 | |
| 41 | class FanCurveImporterStub : public ::AMD::OdFanCurve::Importer |
| 42 | { |
| 43 | public: |
| 44 | FanCurveImporterStub(std::vector<::AMD::OdFanCurve::CurvePoint> const &curve, |
| 45 | bool stop, units::temperature::celsius_t stopTemp) |
| 46 | : curve_(curve) |
| 47 | , stop_(stop) |
| 48 | , stopTemp_(stopTemp) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | std::optional<std::reference_wrapper<Importable::Importer>> |
| 53 | provideImporter(Item const &) override |
| 54 | { |
| 55 | return *this; |
| 56 | } |
| 57 | |
| 58 | bool provideActive() const override |
| 59 | { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | std::vector<::AMD::OdFanCurve::CurvePoint> const &provideFanCurve() const override |
| 64 | { |
| 65 | return curve_; |
| 66 | } |
| 67 | |
| 68 | bool provideFanStop() const override |
| 69 | { |
| 70 | return stop_; |
| 71 | } |
| 72 | |
| 73 | units::temperature::celsius_t provideFanStopTemp() const override |
| 74 | { |
| 75 | return stopTemp_; |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | std::vector<::AMD::OdFanCurve::CurvePoint> const curve_; |
| 80 | bool stop_; |
| 81 | units::temperature::celsius_t stopTemp_; |
| 82 | }; |
| 83 | |
| 84 | class FanCurveExporterMock : public ::AMD::OdFanCurve::Exporter |
| 85 | { |
| 86 | public: |
| 87 | MAKE_MOCK1(takeFanCurve, |
| 88 | void(std::vector<::AMD::OdFanCurve::CurvePoint> const &), override); |
| 89 | MAKE_MOCK2(takeFanCurveRange, |
| 90 | void(::AMD::OdFanCurve::TempRange, ::AMD::OdFanCurve::SpeedRange), |
| 91 | override); |
| 92 | MAKE_MOCK1(takeFanStop, void(bool), override); |
| 93 | MAKE_MOCK1(takeFanStopTemp, void(units::temperature::celsius_t), override); |
| 94 | MAKE_MOCK1(takeFanStopTempRange, void(::AMD::OdFanCurve::TempRange), override); |
| 95 | MAKE_MOCK1(takeActive, void(bool), override); |
| 96 | MAKE_MOCK1( |
| 97 | provideExporter, |
| 98 | std::optional<std::reference_wrapper<Exportable::Exporter>>(Item const &), |
| 99 | override); |
| 100 | }; |
| 101 | |
| 102 | TEST_CASE("AMD OdFanCurve tests", "[GPU][AMD][Fan][Overdrive][OdFanCurve]") |
| 103 | { |
| 104 | CommandQueueStub ctlCmds; |
| 105 | // clang-format off |
| 106 | std::vector<std::string> regularInput{ |
| 107 | "OD_FAN_CURVE:", |
| 108 | "0: 10C 10%", |
| 109 | "1: 45C 20%", |
| 110 | "2: 50C 50%", |
| 111 | "3: 75C 70%", |
| 112 | "4: 100C 100%", |
| 113 | "OD_RANGE:", |
| 114 | "FAN_CURVE(hotspot temp): 10C 100C", |
| 115 | "FAN_CURVE(fan speed): 10% 100%" |
| 116 | }; |
| 117 | std::vector<std::string> zeroCurveInput{ |
| 118 | "OD_FAN_CURVE:", |
| 119 | "0: 0C 0%", |
| 120 | "1: 0C 0%", |
| 121 | "2: 0C 0%", |
| 122 | "3: 0C 0%", |
| 123 | "4: 0C 0%", |
| 124 | "OD_RANGE:", |
| 125 | "FAN_CURVE(hotspot temp): 10C 100C", |
| 126 | "FAN_CURVE(fan speed): 10% 100%" |
| 127 | }; |
| 128 | std::vector<std::string> stopInput{ |
| 129 | "FAN_ZERO_RPM_ENABLE:", |
| 130 | "1", |
| 131 | "OD_RANGE:", |
| 132 | "ZERO_RPM_ENABLE: 0 1" |
| 133 | }; |
| 134 | std::vector<std::string> stopTempInput{ |
| 135 | "FAN_ZERO_RPM_STOP_TEMPERATURE:", |
| 136 | "20", |
| 137 | "OD_RANGE:", |
| 138 | "ZERO_RPM_STOP_TEMPERATURE: 10 100" |
| 139 | }; |
| 140 | // clang-format on |
| 141 | auto curveTempRange = std::make_pair(units::temperature::celsius_t(10), |
| 142 | units::temperature::celsius_t(100)); |
| 143 | auto curveSpeedRange = std::make_pair(units::concentration::percent_t(10), |
| 144 | units::concentration::percent_t(100)); |
| 145 | |
| 146 | auto stopDataSource = std::make_optional<::AMD::OdFanCurve::StopDataSource>( |
| 147 | {std::make_unique<VectorStringDataSourceStub>("fan_zero_rpm_enable", |
| 148 | stopInput), |
| 149 | std::make_optional<::AMD::OdFanCurve::StopTemperatureDataSource>( |
| 150 | {std::make_unique<VectorStringDataSourceStub>( |
| 151 | "fan_zero_rpm_stop_temperature", stopTempInput), |
| 152 | std::make_pair(units::temperature::celsius_t(10), |
| 153 | units::temperature::celsius_t(100))})}); |
| 154 | |
| 155 | SECTION("toCurvePoints") |
| 156 | { |
| 157 | // clang-format off |
| 158 | std::vector<std::tuple<unsigned int, units::temperature::celsius_t, |
| 159 | units::concentration::percent_t>> |
| 160 | controlCurve { |
| 161 | {0, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 162 | {1, units::temperature::celsius_t(1), units::concentration::percent_t(1)}, |
| 163 | {2, units::temperature::celsius_t(2), units::concentration::percent_t(2)}, |
| 164 | {3, units::temperature::celsius_t(3), units::concentration::percent_t(3)}, |
| 165 | {4, units::temperature::celsius_t(4), units::concentration::percent_t(4)} |
| 166 | }; |
| 167 | |
| 168 | std::vector<std::pair<units::temperature::celsius_t, |
| 169 | units::concentration::percent_t>> |
| 170 | curvePoints { |
| 171 | {units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 172 | {units::temperature::celsius_t(1), units::concentration::percent_t(1)}, |
| 173 | {units::temperature::celsius_t(2), units::concentration::percent_t(2)}, |
| 174 | {units::temperature::celsius_t(3), units::concentration::percent_t(3)}, |
| 175 | {units::temperature::celsius_t(4), units::concentration::percent_t(4)} |
| 176 | }; |
| 177 | // clang-format on |
| 178 | |
| 179 | OdFanCurveTestAdapter ts({std::make_unique<VectorStringDataSourceStub>(), |
| 180 | std::move(curveTempRange), |
| 181 | std::move(curveSpeedRange)}); |
| 182 | auto output = ts.toCurvePoints(controlCurve); |
| 183 | REQUIRE_THAT(output, Catch::Matchers::Equals(curvePoints)); |
| 184 | } |
| 185 | |
| 186 | SECTION("setPointCoordinatesFrom") |
| 187 | { |
| 188 | // clang-format off |
| 189 | std::vector<std::tuple<unsigned int, units::temperature::celsius_t, |
| 190 | units::concentration::percent_t>> |
| 191 | curve { |
| 192 | {0, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 193 | {1, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 194 | {2, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 195 | {3, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 196 | {4, units::temperature::celsius_t(0), units::concentration::percent_t(0)} |
| 197 | }; |
| 198 | std::vector<std::pair<units::temperature::celsius_t, |
| 199 | units::concentration::percent_t>> |
| 200 | values { |
| 201 | {units::temperature::celsius_t(-10), units::concentration::percent_t(-10)}, |
| 202 | {units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 203 | {units::temperature::celsius_t(1), units::concentration::percent_t(1)}, |
| 204 | {units::temperature::celsius_t(20), units::concentration::percent_t(20)}, |
| 205 | {units::temperature::celsius_t(300), units::concentration::percent_t(300)} |
| 206 | }; |
| 207 | std::vector<std::tuple<unsigned int, units::temperature::celsius_t, |
| 208 | units::concentration::percent_t>> |
| 209 | targetCurve { |
| 210 | {0, units::temperature::celsius_t(-10), units::concentration::percent_t(-10)}, |
| 211 | {1, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 212 | {2, units::temperature::celsius_t(1), units::concentration::percent_t(1)}, |
| 213 | {3, units::temperature::celsius_t(20), units::concentration::percent_t(20)}, |
| 214 | {4, units::temperature::celsius_t(300), units::concentration::percent_t(300)} |
| 215 | }; |
| 216 | // clang-format on |
| 217 | |
| 218 | OdFanCurveTestAdapter ts({std::make_unique<VectorStringDataSourceStub>(), |
| 219 | std::move(curveTempRange), |
| 220 | std::move(curveSpeedRange)}); |
| 221 | ts.setPointCoordinatesFrom(curve, values); |
| 222 | REQUIRE_THAT(curve, Catch::Matchers::Equals(targetCurve)); |
| 223 | } |
| 224 | |
| 225 | SECTION("isZeroCurve") |
| 226 | { |
| 227 | // clang-format off |
| 228 | std::vector<std::tuple<unsigned int, units::temperature::celsius_t, |
| 229 | units::concentration::percent_t>> |
| 230 | zeroCurve { |
| 231 | {0, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 232 | {1, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 233 | {2, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 234 | {3, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 235 | {4, units::temperature::celsius_t(0), units::concentration::percent_t(0)} |
| 236 | }; |
| 237 | std::vector<std::tuple<unsigned int, units::temperature::celsius_t, |
| 238 | units::concentration::percent_t>> |
| 239 | nonZeroCurve { |
| 240 | {0, units::temperature::celsius_t(0), units::concentration::percent_t(0)}, |
| 241 | {1, units::temperature::celsius_t(1), units::concentration::percent_t(1)}, |
| 242 | {2, units::temperature::celsius_t(2), units::concentration::percent_t(2)}, |
| 243 | {3, units::temperature::celsius_t(3), units::concentration::percent_t(3)}, |
| 244 | {4, units::temperature::celsius_t(4), units::concentration::percent_t(4)} |
| 245 | }; |
| 246 | // clang-format on |
| 247 | |
| 248 | OdFanCurveTestAdapter ts({std::make_unique<VectorStringDataSourceStub>(), |
| 249 | std::move(curveTempRange), |
| 250 | std::move(curveSpeedRange)}); |
| 251 | REQUIRE(ts.isZeroCurve(zeroCurve)); |
| 252 | REQUIRE_FALSE(ts.isZeroCurve(nonZeroCurve)); |
| 253 | } |
| 254 | |
| 255 | SECTION("controlPointCmd") |
| 256 | { |
| 257 | auto point = std::make_tuple(0, units::temperature::celsius_t(-100), |
| 258 | units::concentration::percent_t(100)); |
| 259 | |
| 260 | OdFanCurveTestAdapter ts({std::make_unique<VectorStringDataSourceStub>(), |
| 261 | std::move(curveTempRange), |
| 262 | std::move(curveSpeedRange)}); |
| 263 | auto output = ts.controlPointCmd(point); |
| 264 | REQUIRE(output == "0 -100 100"); |
| 265 | } |
| 266 | |
| 267 | SECTION("Has OdFanCurve ID") |
| 268 | { |
| 269 | OdFanCurveTestAdapter ts({std::make_unique<VectorStringDataSourceStub>(), |
| 270 | std::move(curveTempRange), |
| 271 | std::move(curveSpeedRange)}); |
| 272 | |
| 273 | REQUIRE(ts.ID() == ::AMD::OdFanCurve::ItemID); |
| 274 | } |
| 275 | |
| 276 | SECTION("Is not active by default") |
| 277 | { |
| 278 | OdFanCurveTestAdapter ts({std::make_unique<VectorStringDataSourceStub>(), |
| 279 | std::move(curveTempRange), |
| 280 | std::move(curveSpeedRange)}); |
| 281 | |
| 282 | REQUIRE_FALSE(ts.active()); |
| 283 | } |
| 284 | |
| 285 | SECTION("Generate pre-init control commands...") |
| 286 | { |
| 287 | SECTION("for curve control only") |
| 288 | { |
| 289 | OdFanCurveTestAdapter ts( |
| 290 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 291 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 292 | ts.preInit(ctlCmds); |
| 293 | |
| 294 | auto const &cmds = ctlCmds.commands(); |
| 295 | REQUIRE(cmds.size() == 2); |
| 296 | REQUIRE(cmds[0].first == "fan_curve"); |
| 297 | REQUIRE(cmds[0].second == "r"); |
| 298 | REQUIRE(cmds[1].first == "fan_curve"); |
| 299 | REQUIRE(cmds[1].second == "c"); |
| 300 | } |
| 301 | |
| 302 | SECTION("with stop and stop temp controls") |
| 303 | { |
| 304 | OdFanCurveTestAdapter ts({std::make_unique<VectorStringDataSourceStub>( |
| 305 | "fan_curve", std::move(regularInput)), |
| 306 | std::move(curveTempRange), |
| 307 | std::move(curveSpeedRange)}, |
| 308 | std::move(stopDataSource)); |
| 309 | ts.preInit(ctlCmds); |
| 310 | |
| 311 | auto const &cmds = ctlCmds.commands(); |
| 312 | REQUIRE(cmds.size() == 6); |
| 313 | REQUIRE(cmds[0].first == "fan_curve"); |
| 314 | REQUIRE(cmds[0].second == "r"); |
| 315 | REQUIRE(cmds[1].first == "fan_curve"); |
| 316 | REQUIRE(cmds[1].second == "c"); |
| 317 | REQUIRE(cmds[2].first == "fan_zero_rpm_enable"); |
| 318 | REQUIRE(cmds[2].second == "r"); |
| 319 | REQUIRE(cmds[3].first == "fan_zero_rpm_enable"); |
| 320 | REQUIRE(cmds[3].second == "c"); |
| 321 | REQUIRE(cmds[4].first == "fan_zero_rpm_stop_temperature"); |
| 322 | REQUIRE(cmds[4].second == "r"); |
| 323 | REQUIRE(cmds[5].first == "fan_zero_rpm_stop_temperature"); |
| 324 | REQUIRE(cmds[5].second == "c"); |
| 325 | } |
| 326 | |
| 327 | SECTION("with only stop control") |
| 328 | { |
| 329 | auto dataSource = std::make_optional<::AMD::OdFanCurve::StopDataSource>( |
| 330 | {std::make_unique<VectorStringDataSourceStub>("fan_zero_rpm_enable", |
| 331 | stopInput), |
| 332 | std::nullopt}); |
| 333 | |
| 334 | OdFanCurveTestAdapter ts({std::make_unique<VectorStringDataSourceStub>( |
| 335 | "fan_curve", std::move(regularInput)), |
| 336 | std::move(curveTempRange), |
| 337 | std::move(curveSpeedRange)}, |
| 338 | std::move(dataSource)); |
| 339 | ts.preInit(ctlCmds); |
| 340 | |
| 341 | auto const &cmds = ctlCmds.commands(); |
| 342 | REQUIRE(cmds.size() == 4); |
| 343 | REQUIRE(cmds[0].first == "fan_curve"); |
| 344 | REQUIRE(cmds[0].second == "r"); |
| 345 | REQUIRE(cmds[1].first == "fan_curve"); |
| 346 | REQUIRE(cmds[1].second == "c"); |
| 347 | REQUIRE(cmds[2].first == "fan_zero_rpm_enable"); |
| 348 | REQUIRE(cmds[2].second == "r"); |
| 349 | REQUIRE(cmds[3].first == "fan_zero_rpm_enable"); |
| 350 | REQUIRE(cmds[3].second == "c"); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | SECTION("Does not generate post-init control commands with a pre-init zero " |
| 355 | "point curve without stop controls") |
| 356 | { |
| 357 | OdFanCurveTestAdapter ts( |
| 358 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", zeroCurveInput), |
| 359 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 360 | ts.preInit(ctlCmds); |
| 361 | ts.init(); |
| 362 | ctlCmds.clear(); |
| 363 | |
| 364 | ts.postInit(ctlCmds); |
| 365 | |
| 366 | REQUIRE(ctlCmds.commands().empty()); |
| 367 | } |
| 368 | |
| 369 | SECTION("Generate post-init control commands...") |
| 370 | { |
| 371 | SECTION("for curve control only with a pre-init non-zero points " |
| 372 | "curve restoring the pre-init curve state") |
| 373 | { |
| 374 | OdFanCurveTestAdapter ts( |
| 375 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 376 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 377 | ts.preInit(ctlCmds); |
| 378 | ts.init(); |
| 379 | ctlCmds.clear(); |
| 380 | |
| 381 | ts.postInit(ctlCmds); |
| 382 | |
| 383 | auto const &cmds = ctlCmds.commands(); |
| 384 | REQUIRE(cmds.size() == 6); |
| 385 | REQUIRE(cmds[0].first == "fan_curve"); |
| 386 | REQUIRE(cmds[0].second == "0 10 10"); |
| 387 | REQUIRE(cmds[1].first == "fan_curve"); |
| 388 | REQUIRE(cmds[1].second == "1 45 20"); |
| 389 | REQUIRE(cmds[2].first == "fan_curve"); |
| 390 | REQUIRE(cmds[2].second == "2 50 50"); |
| 391 | REQUIRE(cmds[3].first == "fan_curve"); |
| 392 | REQUIRE(cmds[3].second == "3 75 70"); |
| 393 | REQUIRE(cmds[4].first == "fan_curve"); |
| 394 | REQUIRE(cmds[4].second == "4 100 100"); |
| 395 | REQUIRE(cmds[5].second == "c"); |
| 396 | } |
| 397 | |
| 398 | SECTION("with stop and stop temp controls, restoring their pre-init state") |
| 399 | { |
| 400 | OdFanCurveTestAdapter ts( |
| 401 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", |
| 402 | zeroCurveInput), |
| 403 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 404 | std::move(stopDataSource)); |
| 405 | ts.preInit(ctlCmds); |
| 406 | ts.init(); |
| 407 | ctlCmds.clear(); |
| 408 | |
| 409 | ts.postInit(ctlCmds); |
| 410 | auto const &cmds = ctlCmds.commands(); |
| 411 | REQUIRE(cmds.size() == 4); |
| 412 | REQUIRE(cmds[0].first == "fan_zero_rpm_enable"); |
| 413 | REQUIRE(cmds[0].second == "1"); |
| 414 | REQUIRE(cmds[1].first == "fan_zero_rpm_enable"); |
| 415 | REQUIRE(cmds[1].second == "c"); |
| 416 | REQUIRE(cmds[2].first == "fan_zero_rpm_stop_temperature"); |
| 417 | REQUIRE(cmds[2].second == "20"); |
| 418 | REQUIRE(cmds[3].first == "fan_zero_rpm_stop_temperature"); |
| 419 | REQUIRE(cmds[3].second == "c"); |
| 420 | } |
| 421 | |
| 422 | SECTION("with only stop control, restoring its pre-init state") |
| 423 | { |
| 424 | auto dataSource = std::make_optional<::AMD::OdFanCurve::StopDataSource>( |
| 425 | {std::make_unique<VectorStringDataSourceStub>("fan_zero_rpm_enable", |
| 426 | stopInput), |
| 427 | std::nullopt}); |
| 428 | |
| 429 | OdFanCurveTestAdapter ts( |
| 430 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", |
| 431 | zeroCurveInput), |
| 432 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 433 | std::move(dataSource)); |
| 434 | ts.preInit(ctlCmds); |
| 435 | ts.init(); |
| 436 | ctlCmds.clear(); |
| 437 | |
| 438 | ts.postInit(ctlCmds); |
| 439 | auto const &cmds = ctlCmds.commands(); |
| 440 | REQUIRE(cmds.size() == 2); |
| 441 | REQUIRE(cmds[0].first == "fan_zero_rpm_enable"); |
| 442 | REQUIRE(cmds[0].second == "1"); |
| 443 | REQUIRE(cmds[1].first == "fan_zero_rpm_enable"); |
| 444 | REQUIRE(cmds[1].second == "c"); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | SECTION("Initializes...") |
| 449 | { |
| 450 | SECTION("Control curve with the custom default curve when the GPU has " |
| 451 | "default zero point curve") |
| 452 | { |
| 453 | OdFanCurveTestAdapter ts({std::make_unique<VectorStringDataSourceStub>( |
| 454 | "fan_curve", zeroCurveInput), |
| 455 | std::move(curveTempRange), |
| 456 | std::move(curveSpeedRange)}); |
| 457 | ts.init(); |
| 458 | |
| 459 | auto defaultCurvePoints = ts.defaultCurve(); |
| 460 | auto controlPoints = ts.controlPoints(); |
| 461 | REQUIRE(controlPoints.size() == 5); |
| 462 | auto const &[_i0, t0, s0] = controlPoints[0]; |
| 463 | REQUIRE(t0 == defaultCurvePoints[0].first); |
| 464 | REQUIRE(s0 == defaultCurvePoints[0].second); |
| 465 | auto const &[_i1, t1, s1] = controlPoints[1]; |
| 466 | REQUIRE(t1 == defaultCurvePoints[1].first); |
| 467 | REQUIRE(s1 == defaultCurvePoints[1].second); |
| 468 | auto const &[_i2, t2, s2] = controlPoints[2]; |
| 469 | REQUIRE(t2 == defaultCurvePoints[2].first); |
| 470 | REQUIRE(s2 == defaultCurvePoints[2].second); |
| 471 | auto const &[_i3, t3, s3] = controlPoints[3]; |
| 472 | REQUIRE(t3 == defaultCurvePoints[3].first); |
| 473 | REQUIRE(s3 == defaultCurvePoints[3].second); |
| 474 | auto const &[_i4, t4, s4] = controlPoints[4]; |
| 475 | REQUIRE(t4 == defaultCurvePoints[4].first); |
| 476 | REQUIRE(s4 == defaultCurvePoints[4].second); |
| 477 | } |
| 478 | |
| 479 | SECTION("Control curve with the device default curve when the GPU has " |
| 480 | "default non-zero point curve") |
| 481 | { |
| 482 | OdFanCurveTestAdapter ts( |
| 483 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 484 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 485 | ts.init(); |
| 486 | |
| 487 | auto controlPoints = ts.controlPoints(); |
| 488 | REQUIRE(controlPoints.size() == 5); |
| 489 | auto const &[_i0, t0, s0] = controlPoints[0]; |
| 490 | REQUIRE(t0 == units::temperature::celsius_t(10)); |
| 491 | REQUIRE(s0 == units::concentration::percent_t(10)); |
| 492 | auto const &[_i1, t1, s1] = controlPoints[1]; |
| 493 | REQUIRE(t1 == units::temperature::celsius_t(45)); |
| 494 | REQUIRE(s1 == units::concentration::percent_t(20)); |
| 495 | auto const &[_i2, t2, s2] = controlPoints[2]; |
| 496 | REQUIRE(t2 == units::temperature::celsius_t(50)); |
| 497 | REQUIRE(s2 == units::concentration::percent_t(50)); |
| 498 | auto const &[_i3, t3, s3] = controlPoints[3]; |
| 499 | REQUIRE(t3 == units::temperature::celsius_t(75)); |
| 500 | REQUIRE(s3 == units::concentration::percent_t(70)); |
| 501 | auto const &[_i4, t4, s4] = controlPoints[4]; |
| 502 | REQUIRE(t4 == units::temperature::celsius_t(100)); |
| 503 | REQUIRE(s4 == units::concentration::percent_t(100)); |
| 504 | } |
| 505 | |
| 506 | SECTION("Control curve with normalized curve point coordinates") |
| 507 | { |
| 508 | // clang-format off |
| 509 | std::vector<std::string> input{ |
| 510 | "OD_FAN_CURVE:", |
| 511 | "0: 0C 0%", // out of range |
| 512 | "1: 45C 20%", |
| 513 | "2: 50C 50%", |
| 514 | "3: 75C 70%", |
| 515 | "4: 200C 200%", // out of range |
| 516 | "OD_RANGE:", |
| 517 | "FAN_CURVE(hotspot temp): 10C 100C", |
| 518 | "FAN_CURVE(fan speed): 10% 100%" |
| 519 | }; |
| 520 | // clang-format on |
| 521 | OdFanCurveTestAdapter ts( |
| 522 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", input), |
| 523 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 524 | ts.init(); |
| 525 | |
| 526 | auto const &tempRange = ts.tempRange(); |
| 527 | auto const &speedRange = ts.speedRange(); |
| 528 | auto const &points = ts.controlPoints(); |
| 529 | |
| 530 | REQUIRE_FALSE( |
| 531 | std::any_of(points.cbegin(), points.cend(), [&](auto const &point) { |
| 532 | return std::get<1>(point) < tempRange.first || |
| 533 | std::get<1>(point) > tempRange.second || |
| 534 | std::get<2>(point) < speedRange.first || |
| 535 | std::get<2>(point) > speedRange.second; |
| 536 | })); |
| 537 | } |
| 538 | |
| 539 | SECTION("Stop state") |
| 540 | { |
| 541 | OdFanCurveTestAdapter ts( |
| 542 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 543 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 544 | std::move(stopDataSource)); |
| 545 | ts.init(); |
| 546 | |
| 547 | REQUIRE(ts.stop()); |
| 548 | } |
| 549 | |
| 550 | SECTION("Stop temperature state when available") |
| 551 | { |
| 552 | OdFanCurveTestAdapter ts( |
| 553 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 554 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 555 | std::move(stopDataSource)); |
| 556 | ts.init(); |
| 557 | |
| 558 | REQUIRE(ts.stopTemp() == units::temperature::celsius_t(20)); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | SECTION("Imports curve state...") |
| 563 | { |
| 564 | SECTION("for curve control only") |
| 565 | { |
| 566 | // clang-format off |
| 567 | std::vector<std::pair<units::temperature::celsius_t, units::concentration::percent_t>> |
| 568 | curve { |
| 569 | {units::temperature::celsius_t(10), units::concentration::percent_t(15)}, |
| 570 | {units::temperature::celsius_t(20), units::concentration::percent_t(25)}, |
| 571 | {units::temperature::celsius_t(30), units::concentration::percent_t(35)}, |
| 572 | {units::temperature::celsius_t(40), units::concentration::percent_t(45)}, |
| 573 | {units::temperature::celsius_t(50), units::concentration::percent_t(55)}, |
| 574 | }; |
| 575 | // clang-format on |
| 576 | |
| 577 | FanCurveImporterStub i(curve, false, units::temperature::celsius_t(40)); |
| 578 | OdFanCurveTestAdapter ts( |
| 579 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 580 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 581 | ts.init(); |
| 582 | |
| 583 | ts.importControl(i); |
| 584 | |
| 585 | auto controlPoints = ts.controlPoints(); |
| 586 | REQUIRE(controlPoints.size() == 5); |
| 587 | auto const &[_i0, t0, s0] = controlPoints[0]; |
| 588 | REQUIRE(t0 == units::temperature::celsius_t(10)); |
| 589 | REQUIRE(s0 == units::concentration::percent_t(15)); |
| 590 | auto const &[_i1, t1, s1] = controlPoints[1]; |
| 591 | REQUIRE(t1 == units::temperature::celsius_t(20)); |
| 592 | REQUIRE(s1 == units::concentration::percent_t(25)); |
| 593 | auto const &[_i2, t2, s2] = controlPoints[2]; |
| 594 | REQUIRE(t2 == units::temperature::celsius_t(30)); |
| 595 | REQUIRE(s2 == units::concentration::percent_t(35)); |
| 596 | auto const &[_i3, t3, s3] = controlPoints[3]; |
| 597 | REQUIRE(t3 == units::temperature::celsius_t(40)); |
| 598 | REQUIRE(s3 == units::concentration::percent_t(45)); |
| 599 | auto const &[_i4, t4, s4] = controlPoints[4]; |
| 600 | REQUIRE(t4 == units::temperature::celsius_t(50)); |
| 601 | REQUIRE(s4 == units::concentration::percent_t(55)); |
| 602 | } |
| 603 | |
| 604 | SECTION("and stop state with stop and stop temp controls") |
| 605 | { |
| 606 | // clang-format off |
| 607 | std::vector<std::pair<units::temperature::celsius_t, units::concentration::percent_t>> |
| 608 | curve { |
| 609 | {units::temperature::celsius_t(10), units::concentration::percent_t(15)}, |
| 610 | {units::temperature::celsius_t(20), units::concentration::percent_t(25)}, |
| 611 | {units::temperature::celsius_t(30), units::concentration::percent_t(35)}, |
| 612 | {units::temperature::celsius_t(40), units::concentration::percent_t(45)}, |
| 613 | {units::temperature::celsius_t(50), units::concentration::percent_t(55)}, |
| 614 | }; |
| 615 | // clang-format on |
| 616 | |
| 617 | FanCurveImporterStub i(curve, false, units::temperature::celsius_t(40)); |
| 618 | OdFanCurveTestAdapter ts( |
| 619 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 620 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 621 | std::move(stopDataSource)); |
| 622 | ts.init(); |
| 623 | |
| 624 | ts.importControl(i); |
| 625 | |
| 626 | auto controlPoints = ts.controlPoints(); |
| 627 | REQUIRE(controlPoints.size() == 5); |
| 628 | auto const &[_i0, t0, s0] = controlPoints[0]; |
| 629 | REQUIRE(t0 == units::temperature::celsius_t(10)); |
| 630 | REQUIRE(s0 == units::concentration::percent_t(15)); |
| 631 | auto const &[_i1, t1, s1] = controlPoints[1]; |
| 632 | REQUIRE(t1 == units::temperature::celsius_t(20)); |
| 633 | REQUIRE(s1 == units::concentration::percent_t(25)); |
| 634 | auto const &[_i2, t2, s2] = controlPoints[2]; |
| 635 | REQUIRE(t2 == units::temperature::celsius_t(30)); |
| 636 | REQUIRE(s2 == units::concentration::percent_t(35)); |
| 637 | auto const &[_i3, t3, s3] = controlPoints[3]; |
| 638 | REQUIRE(t3 == units::temperature::celsius_t(40)); |
| 639 | REQUIRE(s3 == units::concentration::percent_t(45)); |
| 640 | auto const &[_i4, t4, s4] = controlPoints[4]; |
| 641 | REQUIRE(t4 == units::temperature::celsius_t(50)); |
| 642 | REQUIRE(s4 == units::concentration::percent_t(55)); |
| 643 | |
| 644 | REQUIRE_FALSE(ts.stop()); |
| 645 | REQUIRE(ts.stopTemp() == units::temperature::celsius_t(40)); |
| 646 | } |
| 647 | |
| 648 | SECTION("and stop state with only stop control") |
| 649 | { |
| 650 | // clang-format off |
| 651 | std::vector<std::pair<units::temperature::celsius_t, units::concentration::percent_t>> |
| 652 | curve { |
| 653 | {units::temperature::celsius_t(10), units::concentration::percent_t(15)}, |
| 654 | {units::temperature::celsius_t(20), units::concentration::percent_t(25)}, |
| 655 | {units::temperature::celsius_t(30), units::concentration::percent_t(35)}, |
| 656 | {units::temperature::celsius_t(40), units::concentration::percent_t(45)}, |
| 657 | {units::temperature::celsius_t(50), units::concentration::percent_t(55)}, |
| 658 | }; |
| 659 | // clang-format on |
| 660 | |
| 661 | auto dataSource = std::make_optional<::AMD::OdFanCurve::StopDataSource>( |
| 662 | {std::make_unique<VectorStringDataSourceStub>("fan_zero_rpm_enable", |
| 663 | stopInput), |
| 664 | std::nullopt}); |
| 665 | |
| 666 | FanCurveImporterStub i(curve, false, units::temperature::celsius_t(40)); |
| 667 | OdFanCurveTestAdapter ts( |
| 668 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 669 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 670 | std::move(dataSource)); |
| 671 | ts.init(); |
| 672 | |
| 673 | ts.importControl(i); |
| 674 | |
| 675 | auto controlPoints = ts.controlPoints(); |
| 676 | REQUIRE(controlPoints.size() == 5); |
| 677 | auto const &[_i0, t0, s0] = controlPoints[0]; |
| 678 | REQUIRE(t0 == units::temperature::celsius_t(10)); |
| 679 | REQUIRE(s0 == units::concentration::percent_t(15)); |
| 680 | auto const &[_i1, t1, s1] = controlPoints[1]; |
| 681 | REQUIRE(t1 == units::temperature::celsius_t(20)); |
| 682 | REQUIRE(s1 == units::concentration::percent_t(25)); |
| 683 | auto const &[_i2, t2, s2] = controlPoints[2]; |
| 684 | REQUIRE(t2 == units::temperature::celsius_t(30)); |
| 685 | REQUIRE(s2 == units::concentration::percent_t(35)); |
| 686 | auto const &[_i3, t3, s3] = controlPoints[3]; |
| 687 | REQUIRE(t3 == units::temperature::celsius_t(40)); |
| 688 | REQUIRE(s3 == units::concentration::percent_t(45)); |
| 689 | auto const &[_i4, t4, s4] = controlPoints[4]; |
| 690 | REQUIRE(t4 == units::temperature::celsius_t(50)); |
| 691 | REQUIRE(s4 == units::concentration::percent_t(55)); |
| 692 | |
| 693 | REQUIRE_FALSE(ts.stop()); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | SECTION("Export curve state...") |
| 698 | { |
| 699 | SECTION("for curve control only") |
| 700 | { |
| 701 | // clang-format off |
| 702 | std::vector<std::pair<units::temperature::celsius_t, units::concentration::percent_t>> |
| 703 | curve { |
| 704 | {units::temperature::celsius_t(10), units::concentration::percent_t(10)}, |
| 705 | {units::temperature::celsius_t(45), units::concentration::percent_t(20)}, |
| 706 | {units::temperature::celsius_t(50), units::concentration::percent_t(50)}, |
| 707 | {units::temperature::celsius_t(75), units::concentration::percent_t(70)}, |
| 708 | {units::temperature::celsius_t(100), units::concentration::percent_t(100)}, |
| 709 | }; |
| 710 | // clang-format on |
| 711 | |
| 712 | OdFanCurveTestAdapter ts( |
| 713 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 714 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 715 | ts.init(); |
| 716 | |
| 717 | trompeloeil::sequence seq; |
| 718 | FanCurveExporterMock e; |
| 719 | REQUIRE_CALL(e, takeFanCurveRange(trompeloeil::_, trompeloeil::_)) |
| 720 | .WITH(_1 == std::make_pair(units::temperature::celsius_t(10), |
| 721 | units::temperature::celsius_t(100))) |
| 722 | .WITH(_2 == std::make_pair(units::concentration::percent_t(10), |
| 723 | units::concentration::percent_t(100))) |
| 724 | .IN_SEQUENCE(seq); |
| 725 | REQUIRE_CALL(e, takeFanCurve(trompeloeil::_)) |
| 726 | .LR_WITH(_1 == curve) |
| 727 | .IN_SEQUENCE(seq); |
| 728 | |
| 729 | ts.exportControl(e); |
| 730 | } |
| 731 | |
| 732 | SECTION("and stop state with stop and stop temp controls") |
| 733 | { |
| 734 | // clang-format off |
| 735 | std::vector<std::pair<units::temperature::celsius_t, units::concentration::percent_t>> |
| 736 | curve { |
| 737 | {units::temperature::celsius_t(10), units::concentration::percent_t(10)}, |
| 738 | {units::temperature::celsius_t(45), units::concentration::percent_t(20)}, |
| 739 | {units::temperature::celsius_t(50), units::concentration::percent_t(50)}, |
| 740 | {units::temperature::celsius_t(75), units::concentration::percent_t(70)}, |
| 741 | {units::temperature::celsius_t(100), units::concentration::percent_t(100)}, |
| 742 | }; |
| 743 | // clang-format on |
| 744 | |
| 745 | OdFanCurveTestAdapter ts( |
| 746 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 747 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 748 | std::move(stopDataSource)); |
| 749 | ts.init(); |
| 750 | |
| 751 | trompeloeil::sequence seq; |
| 752 | FanCurveExporterMock e; |
| 753 | REQUIRE_CALL(e, takeFanCurveRange(trompeloeil::_, trompeloeil::_)) |
| 754 | .WITH(_1 == std::make_pair(units::temperature::celsius_t(10), |
| 755 | units::temperature::celsius_t(100))) |
| 756 | .WITH(_2 == std::make_pair(units::concentration::percent_t(10), |
| 757 | units::concentration::percent_t(100))) |
| 758 | .IN_SEQUENCE(seq); |
| 759 | REQUIRE_CALL(e, takeFanCurve(trompeloeil::_)) |
| 760 | .LR_WITH(_1 == curve) |
| 761 | .IN_SEQUENCE(seq); |
| 762 | REQUIRE_CALL(e, takeFanStop(trompeloeil::_)) |
| 763 | .LR_WITH(_1 == true) |
| 764 | .IN_SEQUENCE(seq); |
| 765 | REQUIRE_CALL(e, takeFanStopTempRange(trompeloeil::_)) |
| 766 | .WITH(_1 == std::make_pair(units::temperature::celsius_t(10), |
| 767 | units::temperature::celsius_t(100))) |
| 768 | .IN_SEQUENCE(seq); |
| 769 | REQUIRE_CALL(e, takeFanStopTemp(trompeloeil::_)) |
| 770 | .LR_WITH(_1 == units::temperature::celsius_t(20)) |
| 771 | .IN_SEQUENCE(seq); |
| 772 | |
| 773 | ts.exportControl(e); |
| 774 | } |
| 775 | |
| 776 | SECTION("and stop state with only stop control") |
| 777 | { |
| 778 | // clang-format off |
| 779 | std::vector<std::pair<units::temperature::celsius_t, units::concentration::percent_t>> |
| 780 | curve { |
| 781 | {units::temperature::celsius_t(10), units::concentration::percent_t(10)}, |
| 782 | {units::temperature::celsius_t(45), units::concentration::percent_t(20)}, |
| 783 | {units::temperature::celsius_t(50), units::concentration::percent_t(50)}, |
| 784 | {units::temperature::celsius_t(75), units::concentration::percent_t(70)}, |
| 785 | {units::temperature::celsius_t(100), units::concentration::percent_t(100)}, |
| 786 | }; |
| 787 | // clang-format on |
| 788 | |
| 789 | auto dataSource = std::make_optional<::AMD::OdFanCurve::StopDataSource>( |
| 790 | {std::make_unique<VectorStringDataSourceStub>("fan_zero_rpm_enable", |
| 791 | stopInput), |
| 792 | std::nullopt}); |
| 793 | |
| 794 | OdFanCurveTestAdapter ts( |
| 795 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 796 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 797 | std::move(dataSource)); |
| 798 | ts.init(); |
| 799 | |
| 800 | trompeloeil::sequence seq; |
| 801 | FanCurveExporterMock e; |
| 802 | REQUIRE_CALL(e, takeFanCurveRange(trompeloeil::_, trompeloeil::_)) |
| 803 | .WITH(_1 == std::make_pair(units::temperature::celsius_t(10), |
| 804 | units::temperature::celsius_t(100))) |
| 805 | .WITH(_2 == std::make_pair(units::concentration::percent_t(10), |
| 806 | units::concentration::percent_t(100))) |
| 807 | .IN_SEQUENCE(seq); |
| 808 | REQUIRE_CALL(e, takeFanCurve(trompeloeil::_)) |
| 809 | .LR_WITH(_1 == curve) |
| 810 | .IN_SEQUENCE(seq); |
| 811 | REQUIRE_CALL(e, takeFanStop(trompeloeil::_)) |
| 812 | .LR_WITH(_1 == true) |
| 813 | .IN_SEQUENCE(seq); |
| 814 | FORBID_CALL(e, takeFanStopTempRange(trompeloeil::_)); |
| 815 | FORBID_CALL(e, takeFanStopTemp(trompeloeil::_)); |
| 816 | |
| 817 | ts.exportControl(e); |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | SECTION("Generate clean control commands...") |
| 822 | { |
| 823 | SECTION("for curve control only") |
| 824 | { |
| 825 | OdFanCurveTestAdapter ts( |
| 826 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 827 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 828 | ts.cleanControl(ctlCmds); |
| 829 | |
| 830 | auto const &cmds = ctlCmds.commands(); |
| 831 | REQUIRE(cmds.size() == 2); |
| 832 | REQUIRE(cmds[0].first == "fan_curve"); |
| 833 | REQUIRE(cmds[0].second == "r"); |
| 834 | REQUIRE(cmds[1].first == "fan_curve"); |
| 835 | REQUIRE(cmds[1].second == "c"); |
| 836 | } |
| 837 | |
| 838 | SECTION("with fan stop and stop temp controls") |
| 839 | { |
| 840 | OdFanCurveTestAdapter ts( |
| 841 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 842 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 843 | std::move(stopDataSource)); |
| 844 | ts.cleanControl(ctlCmds); |
| 845 | |
| 846 | auto const &cmds = ctlCmds.commands(); |
| 847 | REQUIRE(cmds.size() == 6); |
| 848 | REQUIRE(cmds[0].first == "fan_curve"); |
| 849 | REQUIRE(cmds[0].second == "r"); |
| 850 | REQUIRE(cmds[1].first == "fan_curve"); |
| 851 | REQUIRE(cmds[1].second == "c"); |
| 852 | REQUIRE(cmds[2].first == "fan_zero_rpm_enable"); |
| 853 | REQUIRE(cmds[2].second == "r"); |
| 854 | REQUIRE(cmds[3].first == "fan_zero_rpm_enable"); |
| 855 | REQUIRE(cmds[3].second == "c"); |
| 856 | REQUIRE(cmds[4].first == "fan_zero_rpm_stop_temperature"); |
| 857 | REQUIRE(cmds[4].second == "r"); |
| 858 | REQUIRE(cmds[5].first == "fan_zero_rpm_stop_temperature"); |
| 859 | REQUIRE(cmds[5].second == "c"); |
| 860 | } |
| 861 | |
| 862 | SECTION("with only fan stop control") |
| 863 | { |
| 864 | auto dataSource = std::make_optional<::AMD::OdFanCurve::StopDataSource>( |
| 865 | {std::make_unique<VectorStringDataSourceStub>("fan_zero_rpm_enable", |
| 866 | stopInput), |
| 867 | std::nullopt}); |
| 868 | |
| 869 | OdFanCurveTestAdapter ts( |
| 870 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 871 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 872 | std::move(dataSource)); |
| 873 | ts.cleanControl(ctlCmds); |
| 874 | |
| 875 | auto const &cmds = ctlCmds.commands(); |
| 876 | REQUIRE(cmds.size() == 4); |
| 877 | REQUIRE(cmds[0].first == "fan_curve"); |
| 878 | REQUIRE(cmds[0].second == "r"); |
| 879 | REQUIRE(cmds[1].first == "fan_curve"); |
| 880 | REQUIRE(cmds[1].second == "c"); |
| 881 | REQUIRE(cmds[2].first == "fan_zero_rpm_enable"); |
| 882 | REQUIRE(cmds[2].second == "r"); |
| 883 | REQUIRE(cmds[3].first == "fan_zero_rpm_enable"); |
| 884 | REQUIRE(cmds[3].second == "c"); |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | SECTION("Does not generate sync control commands when...") |
| 889 | { |
| 890 | SECTION("is synced") |
| 891 | { |
| 892 | OdFanCurveTestAdapter ts( |
| 893 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 894 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 895 | std::move(stopDataSource)); |
| 896 | ts.init(); |
| 897 | ts.syncControl(ctlCmds); |
| 898 | ctlCmds.clear(); |
| 899 | |
| 900 | ts.syncControl(ctlCmds); |
| 901 | |
| 902 | REQUIRE(ctlCmds.commands().empty()); |
| 903 | } |
| 904 | |
| 905 | SECTION("is synced for curve control only") |
| 906 | { |
| 907 | OdFanCurveTestAdapter ts( |
| 908 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 909 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 910 | ts.init(); |
| 911 | ts.syncControl(ctlCmds); |
| 912 | ctlCmds.clear(); |
| 913 | |
| 914 | ts.syncControl(ctlCmds); |
| 915 | |
| 916 | REQUIRE(ctlCmds.commands().empty()); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | SECTION("Does generate sync control commands when...") |
| 921 | { |
| 922 | SECTION("curve is in sync but the operation mode must be set to manual") |
| 923 | { |
| 924 | OdFanCurveTestAdapter ts( |
| 925 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 926 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 927 | ts.init(); |
| 928 | |
| 929 | ts.syncControl(ctlCmds); |
| 930 | |
| 931 | auto const &cmds = ctlCmds.commands(); |
| 932 | REQUIRE(cmds.size() == 2); |
| 933 | REQUIRE(cmds[0].first == "fan_curve"); |
| 934 | REQUIRE(cmds[0].second == "r"); |
| 935 | REQUIRE(cmds[1].first == "fan_curve"); |
| 936 | REQUIRE(cmds[1].second == "c"); |
| 937 | } |
| 938 | |
| 939 | SECTION("curve is out of sync") |
| 940 | { |
| 941 | // clang-format off |
| 942 | std::vector<std::pair<units::temperature::celsius_t, |
| 943 | units::concentration::percent_t>> |
| 944 | curve { |
| 945 | {units::temperature::celsius_t(15), units::concentration::percent_t(15)}, |
| 946 | {units::temperature::celsius_t(20), units::concentration::percent_t(20)}, |
| 947 | {units::temperature::celsius_t(30), units::concentration::percent_t(30)}, |
| 948 | {units::temperature::celsius_t(40), units::concentration::percent_t(40)}, |
| 949 | {units::temperature::celsius_t(50), units::concentration::percent_t(50)} |
| 950 | }; |
| 951 | // clang-format on |
| 952 | |
| 953 | OdFanCurveTestAdapter ts( |
| 954 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 955 | std::move(curveTempRange), std::move(curveSpeedRange)}); |
| 956 | ts.init(); |
| 957 | ts.syncControl(ctlCmds); |
| 958 | ctlCmds.clear(); |
| 959 | |
| 960 | ts.fanCurve(curve); |
| 961 | ts.syncControl(ctlCmds); |
| 962 | |
| 963 | auto const &cmds = ctlCmds.commands(); |
| 964 | REQUIRE(cmds.size() == 6); |
| 965 | REQUIRE(cmds[0].first == "fan_curve"); |
| 966 | REQUIRE(cmds[0].second == "0 15 15"); |
| 967 | REQUIRE(cmds[1].first == "fan_curve"); |
| 968 | REQUIRE(cmds[1].second == "1 20 20"); |
| 969 | REQUIRE(cmds[2].first == "fan_curve"); |
| 970 | REQUIRE(cmds[2].second == "2 30 30"); |
| 971 | REQUIRE(cmds[3].first == "fan_curve"); |
| 972 | REQUIRE(cmds[3].second == "3 40 40"); |
| 973 | REQUIRE(cmds[4].first == "fan_curve"); |
| 974 | REQUIRE(cmds[4].second == "4 50 50"); |
| 975 | REQUIRE(cmds[5].second == "c"); |
| 976 | } |
| 977 | |
| 978 | SECTION("stop control is out of sync") |
| 979 | { |
| 980 | OdFanCurveTestAdapter ts( |
| 981 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 982 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 983 | std::move(stopDataSource)); |
| 984 | ts.init(); |
| 985 | ts.syncControl(ctlCmds); |
| 986 | ctlCmds.clear(); |
| 987 | |
| 988 | ts.stop(false); |
| 989 | ts.syncControl(ctlCmds); |
| 990 | |
| 991 | auto const &cmds = ctlCmds.commands(); |
| 992 | REQUIRE(cmds.size() == 2); |
| 993 | REQUIRE(cmds[0].first == "fan_zero_rpm_enable"); |
| 994 | REQUIRE(cmds[0].second == "0"); |
| 995 | REQUIRE(cmds[1].first == "fan_zero_rpm_enable"); |
| 996 | REQUIRE(cmds[1].second == "c"); |
| 997 | } |
| 998 | |
| 999 | SECTION("stop temperature control is out of sync") |
| 1000 | { |
| 1001 | OdFanCurveTestAdapter ts( |
| 1002 | {std::make_unique<VectorStringDataSourceStub>("fan_curve", regularInput), |
| 1003 | std::move(curveTempRange), std::move(curveSpeedRange)}, |
| 1004 | std::move(stopDataSource)); |
| 1005 | ts.init(); |
| 1006 | ts.syncControl(ctlCmds); |
| 1007 | ctlCmds.clear(); |
| 1008 | |
| 1009 | ts.stopTemp(units::temperature::celsius_t(40)); |
| 1010 | ts.syncControl(ctlCmds); |
| 1011 | |
| 1012 | auto const &cmds = ctlCmds.commands(); |
| 1013 | REQUIRE(cmds.size() == 2); |
| 1014 | REQUIRE(cmds[0].first == "fan_zero_rpm_stop_temperature"); |
| 1015 | REQUIRE(cmds[0].second == "40"); |
| 1016 | REQUIRE(cmds[1].first == "fan_zero_rpm_stop_temperature"); |
| 1017 | REQUIRE(cmds[1].second == "c"); |
| 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | } // namespace Tests::AMD::OdFanCurve |