| 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/stringdatasourcestub.h" |
| 8 | #include "core/components/controls/amd/pm/advanced/dynamicfreq/pmdynamicfreq.h" |
| 9 | |
| 10 | namespace Tests::AMD::PMDynamicFreq { |
| 11 | |
| 12 | class PMDynamicFreqTestAdapter : public ::AMD::PMDynamicFreq |
| 13 | { |
| 14 | public: |
| 15 | using ::AMD::PMDynamicFreq::PMDynamicFreq; |
| 16 | |
| 17 | using ::AMD::PMDynamicFreq::cleanControl; |
| 18 | using ::AMD::PMDynamicFreq::syncControl; |
| 19 | }; |
| 20 | |
| 21 | TEST_CASE("AMD PMDynamicFreq tests", |
| 22 | "[GPU][AMD][PM][PMAdvanced][PMDynamicFreq]") |
| 23 | { |
| 24 | std::string const path{"power_dpm_force_performance_level"}; |
| 25 | CommandQueueStub ctlCmds; |
| 26 | |
| 27 | SECTION("Has PMDynamicFreq ID") |
| 28 | { |
| 29 | PMDynamicFreqTestAdapter ts(std::make_unique<StringDataSourceStub>()); |
| 30 | REQUIRE(ts.ID() == ::AMD::PMDynamicFreq::ItemID); |
| 31 | } |
| 32 | |
| 33 | SECTION("Is not active by default") |
| 34 | { |
| 35 | PMDynamicFreqTestAdapter ts(std::make_unique<StringDataSourceStub>()); |
| 36 | REQUIRE_FALSE(ts.active()); |
| 37 | } |
| 38 | |
| 39 | SECTION("Does not generate pre-init control commands") |
| 40 | { |
| 41 | PMDynamicFreqTestAdapter ts(std::make_unique<StringDataSourceStub>()); |
| 42 | ts.preInit(ctlCmds); |
| 43 | |
| 44 | REQUIRE(ctlCmds.commands().empty()); |
| 45 | } |
| 46 | |
| 47 | SECTION("Does not generate post-init control commands") |
| 48 | { |
| 49 | PMDynamicFreqTestAdapter ts(std::make_unique<StringDataSourceStub>()); |
| 50 | ts.postInit(ctlCmds); |
| 51 | |
| 52 | REQUIRE(ctlCmds.commands().empty()); |
| 53 | } |
| 54 | |
| 55 | SECTION("Does not generate clean control commands") |
| 56 | { |
| 57 | PMDynamicFreqTestAdapter ts(std::make_unique<StringDataSourceStub>()); |
| 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 | PMDynamicFreqTestAdapter ts( |
| 66 | std::make_unique<StringDataSourceStub>(path, "auto")); |
| 67 | ts.syncControl(ctlCmds); |
| 68 | |
| 69 | REQUIRE(ctlCmds.commands().empty()); |
| 70 | } |
| 71 | |
| 72 | SECTION("Does generate sync control commands when is out of sync") |
| 73 | { |
| 74 | PMDynamicFreqTestAdapter ts( |
| 75 | std::make_unique<StringDataSourceStub>(path, "_other_")); |
| 76 | ts.syncControl(ctlCmds); |
| 77 | |
| 78 | REQUIRE(ctlCmds.commands().size() == 1); |
| 79 | auto &[path, value] = ctlCmds.commands().front(); |
| 80 | REQUIRE(path == path); |
| 81 | REQUIRE(value == "auto"); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | } // namespace Tests::AMD::PMDynamicFreq |