| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include <catch2/catch_all.hpp> |
| 5 | |
| 6 | #include "common/commandqueuestub.h" |
| 7 | #include "common/uintdatasourcestub.h" |
| 8 | #include "core/components/controls/amd/fan/auto/fanauto.h" |
| 9 | |
| 10 | namespace Tests::AMD::FanAuto { |
| 11 | |
| 12 | class FanAutoTestAdapter : public ::AMD::FanAuto |
| 13 | { |
| 14 | public: |
| 15 | using ::AMD::FanAuto::FanAuto; |
| 16 | |
| 17 | using ::AMD::FanAuto::cleanControl; |
| 18 | using ::AMD::FanAuto::syncControl; |
| 19 | }; |
| 20 | |
| 21 | TEST_CASE("AMD FanAuto tests", "[GPU][AMD][Fan][FanAuto]") |
| 22 | { |
| 23 | CommandQueueStub ctlCmds; |
| 24 | |
| 25 | SECTION("Has FanAuto ID") |
| 26 | { |
| 27 | FanAutoTestAdapter ts(std::make_unique<UIntDataSourceStub>()); |
| 28 | |
| 29 | REQUIRE(ts.ID() == ::AMD::FanAuto::ItemID); |
| 30 | } |
| 31 | |
| 32 | SECTION("Is active by default") |
| 33 | { |
| 34 | FanAutoTestAdapter ts(std::make_unique<UIntDataSourceStub>()); |
| 35 | |
| 36 | REQUIRE(ts.active()); |
| 37 | } |
| 38 | |
| 39 | SECTION("Does not generate pre-init control commands") |
| 40 | { |
| 41 | FanAutoTestAdapter ts(std::make_unique<UIntDataSourceStub>()); |
| 42 | ts.preInit(ctlCmds); |
| 43 | |
| 44 | REQUIRE(ctlCmds.commands().empty()); |
| 45 | } |
| 46 | |
| 47 | SECTION("Does not generate post-init control commands") |
| 48 | { |
| 49 | FanAutoTestAdapter ts(std::make_unique<UIntDataSourceStub>()); |
| 50 | ts.postInit(ctlCmds); |
| 51 | |
| 52 | REQUIRE(ctlCmds.commands().empty()); |
| 53 | } |
| 54 | |
| 55 | SECTION("Does not generate clean control commands") |
| 56 | { |
| 57 | FanAutoTestAdapter ts(std::make_unique<UIntDataSourceStub>()); |
| 58 | ts.cleanControl(ctlCmds); |
| 59 | |
| 60 | REQUIRE(ctlCmds.commands().empty()); |
| 61 | } |
| 62 | |
| 63 | SECTION("Does not generate sync control commands when is synced") |
| 64 | { |
| 65 | FanAutoTestAdapter ts(std::make_unique<UIntDataSourceStub>("path", 2)); |
| 66 | ts.syncControl(ctlCmds); |
| 67 | |
| 68 | REQUIRE(ctlCmds.commands().empty()); |
| 69 | } |
| 70 | |
| 71 | SECTION("Does generate sync control commands when is out of sync") |
| 72 | { |
| 73 | FanAutoTestAdapter ts(std::make_unique<UIntDataSourceStub>("path", 123)); |
| 74 | ts.syncControl(ctlCmds); |
| 75 | |
| 76 | REQUIRE(ctlCmds.commands().size() == 1); |
| 77 | auto &[path, value] = ctlCmds.commands().front(); |
| 78 | REQUIRE(path == "path"); |
| 79 | REQUIRE(value == "2"); // 2 == automatic |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | } // namespace Tests::AMD::FanAuto |