| 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 "common/vectorstringdatasourcestub.h" |
| 9 | #include "core/components/controls/amd/pm/handlers/ppdpmhandler.h" |
| 10 | |
| 11 | namespace Tests::AMD::PpDpmHandler { |
| 12 | |
| 13 | TEST_CASE("AMD PpDpmHandler tests", |
| 14 | "[GPU][AMD][PM][DataSourceHandler][PpDpmHandler]") |
| 15 | { |
| 16 | CommandQueueStub ctlCmds; |
| 17 | |
| 18 | std::vector<unsigned int> defaultActiveStates{0, 1}; |
| 19 | std::vector<std::string> ppDpmData{"0: 300Mhz *", "1: 2000Mhz"}; |
| 20 | |
| 21 | SECTION("Initializes states from data source on construction") |
| 22 | { |
| 23 | ::AMD::PpDpmHandler ts( |
| 24 | std::make_unique<StringDataSourceStub>( |
| 25 | "power_dpm_force_performance_level", "manual"), |
| 26 | std::make_unique<VectorStringDataSourceStub>("pp_dpm_sclk", ppDpmData)); |
| 27 | |
| 28 | auto states = ts.states(); |
| 29 | REQUIRE(states.size() == 2); |
| 30 | REQUIRE(states.front() == |
| 31 | std::make_pair(0u, units::frequency::megahertz_t(300))); |
| 32 | REQUIRE(states.back() == |
| 33 | std::make_pair(1u, units::frequency::megahertz_t(2000))); |
| 34 | |
| 35 | SECTION("Has all states active by default") |
| 36 | { |
| 37 | REQUIRE(ts.active() == defaultActiveStates); |
| 38 | } |
| 39 | |
| 40 | SECTION("Activate...") |
| 41 | { |
| 42 | SECTION("Works with known states") |
| 43 | { |
| 44 | ts.activate({1}); |
| 45 | auto &activeStates = ts.active(); |
| 46 | REQUIRE(activeStates.size() == 1); |
| 47 | REQUIRE(activeStates.front() == 1); |
| 48 | } |
| 49 | |
| 50 | SECTION("Ignores unknown states") |
| 51 | { |
| 52 | ts.activate({2, 3}); |
| 53 | REQUIRE(ts.active() == defaultActiveStates); |
| 54 | } |
| 55 | |
| 56 | SECTION("Cannot deactivate all states") |
| 57 | { |
| 58 | ts.activate({}); |
| 59 | REQUIRE(ts.active() == defaultActiveStates); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | SECTION("Saving and restoring data source state are not supported") |
| 65 | { |
| 66 | ::AMD::PpDpmHandler ts( |
| 67 | std::make_unique<StringDataSourceStub>( |
| 68 | "power_dpm_force_performance_level", "manual"), |
| 69 | std::make_unique<VectorStringDataSourceStub>("pp_dpm_sclk", ppDpmData)); |
| 70 | |
| 71 | ts.saveState(); |
| 72 | ts.restoreState(ctlCmds); |
| 73 | REQUIRE(ctlCmds.commands().empty()); |
| 74 | } |
| 75 | |
| 76 | SECTION("Generates reset control commands unconditionally...") |
| 77 | { |
| 78 | SECTION("Including performance level command when its value is not manual") |
| 79 | { |
| 80 | ::AMD::PpDpmHandler ts(std::make_unique<StringDataSourceStub>( |
| 81 | "power_dpm_force_performance_level", "auto"), |
| 82 | std::make_unique<VectorStringDataSourceStub>( |
| 83 | "pp_dpm_sclk", ppDpmData)); |
| 84 | |
| 85 | ts.reset(ctlCmds); |
| 86 | |
| 87 | auto &commands = ctlCmds.commands(); |
| 88 | REQUIRE(commands.size() == 2); |
| 89 | auto &[cmd0Path, cmd0Value] = commands.at(0); |
| 90 | REQUIRE(cmd0Path == "power_dpm_force_performance_level"); |
| 91 | REQUIRE(cmd0Value == "manual"); |
| 92 | auto &[cmd1Path, cmd1Value] = commands.at(1); |
| 93 | REQUIRE(cmd1Path == "pp_dpm_sclk"); |
| 94 | REQUIRE(cmd1Value == "0 1"); |
| 95 | } |
| 96 | |
| 97 | SECTION("Excluding performance level command when its value is not manual") |
| 98 | { |
| 99 | ::AMD::PpDpmHandler ts(std::make_unique<StringDataSourceStub>( |
| 100 | "power_dpm_force_performance_level", "manual"), |
| 101 | std::make_unique<VectorStringDataSourceStub>( |
| 102 | "pp_dpm_sclk", ppDpmData)); |
| 103 | |
| 104 | ts.reset(ctlCmds); |
| 105 | |
| 106 | auto &commands = ctlCmds.commands(); |
| 107 | REQUIRE(commands.size() == 1); |
| 108 | auto &[cmd0Path, cmd0Value] = commands.at(0); |
| 109 | REQUIRE(cmd0Path == "pp_dpm_sclk"); |
| 110 | REQUIRE(cmd0Value == "0 1"); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | SECTION("Does not generate sync control commands when is synced") |
| 115 | { |
| 116 | ::AMD::PpDpmHandler ts( |
| 117 | std::make_unique<StringDataSourceStub>( |
| 118 | "power_dpm_force_performance_level", "manual"), |
| 119 | std::make_unique<VectorStringDataSourceStub>("pp_dpm_sclk", ppDpmData)); |
| 120 | |
| 121 | // skip initial sync commands |
| 122 | ts.sync(ctlCmds); |
| 123 | ctlCmds.clear(); |
| 124 | |
| 125 | ts.sync(ctlCmds); |
| 126 | |
| 127 | REQUIRE(ctlCmds.commands().empty()); |
| 128 | } |
| 129 | |
| 130 | SECTION("Generates sync control commands when...") |
| 131 | { |
| 132 | SECTION("Performance level is not manual") |
| 133 | { |
| 134 | ::AMD::PpDpmHandler ts(std::make_unique<StringDataSourceStub>( |
| 135 | "power_dpm_force_performance_level", "auto"), |
| 136 | std::make_unique<VectorStringDataSourceStub>( |
| 137 | "pp_dpm_sclk", ppDpmData)); |
| 138 | |
| 139 | ts.sync(ctlCmds); |
| 140 | |
| 141 | auto &commands = ctlCmds.commands(); |
| 142 | REQUIRE(commands.size() == 2); |
| 143 | auto &[cmd0Path, cmd0Value] = commands.at(0); |
| 144 | REQUIRE(cmd0Path == "power_dpm_force_performance_level"); |
| 145 | REQUIRE(cmd0Value == "manual"); |
| 146 | auto &[cmd1Path, cmd1Value] = commands.at(1); |
| 147 | REQUIRE(cmd1Path == "pp_dpm_sclk"); |
| 148 | REQUIRE(cmd1Value == "0 1"); |
| 149 | } |
| 150 | |
| 151 | SECTION("Active states were changed") |
| 152 | { |
| 153 | ::AMD::PpDpmHandler ts(std::make_unique<StringDataSourceStub>( |
| 154 | "power_dpm_force_performance_level", "manual"), |
| 155 | std::make_unique<VectorStringDataSourceStub>( |
| 156 | "pp_dpm_sclk", ppDpmData)); |
| 157 | |
| 158 | ts.activate({0}); |
| 159 | ts.sync(ctlCmds); |
| 160 | |
| 161 | auto &commands = ctlCmds.commands(); |
| 162 | REQUIRE(commands.size() == 1); |
| 163 | auto &[cmd0Path, cmd0Value] = commands.at(0); |
| 164 | REQUIRE(cmd0Path == "pp_dpm_sclk"); |
| 165 | REQUIRE(cmd0Value == "0"); |
| 166 | } |
| 167 | |
| 168 | SECTION("Current index is not an active index") |
| 169 | { |
| 170 | ::AMD::PpDpmHandler ts(std::make_unique<StringDataSourceStub>( |
| 171 | "power_dpm_force_performance_level", "manual"), |
| 172 | std::make_unique<VectorStringDataSourceStub>( |
| 173 | "pp_dpm_sclk", ppDpmData)); |
| 174 | |
| 175 | ts.activate({1}); |
| 176 | ts.sync(ctlCmds); |
| 177 | ctlCmds.clear(); |
| 178 | |
| 179 | ts.sync(ctlCmds); |
| 180 | |
| 181 | auto &commands = ctlCmds.commands(); |
| 182 | REQUIRE(commands.size() == 1); |
| 183 | auto &[cmd0Path, cmd0Value] = commands.at(0); |
| 184 | REQUIRE(cmd0Path == "pp_dpm_sclk"); |
| 185 | REQUIRE(cmd0Value == "1"); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | } // namespace Tests::AMD::PpDpmHandler |