Debian Codegraph @

tests/src/test_pmoverdrive.cpp

raw symbols SCIP
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/controlmock.h"
8 #include "common/stringdatasourcestub.h"
9 #include "common/vectorstringdatasourcestub.h"
10 #include "core/components/controls/amd/pm/advanced/overdrive/pmoverdrive.h"
11
12 namespace Tests::AMD::PMOverdrive {
13
14 class PMOverdriveTestAdapter : public ::AMD::PMOverdrive
15 {
16 public:
17 using ::AMD::PMOverdrive::PMOverdrive;
18
19 using ::AMD::PMOverdrive::cleanControl;
20 using ::AMD::PMOverdrive::perfLevelPreInitValue;
21 using ::AMD::PMOverdrive::syncControl;
22 };
23
24 TEST_CASE("AMD PMOverdrive tests", "[GPU][AMD][PM][PMOverdrive]")
25 {
26 std::vector<std::unique_ptr<IControl>> controlMocks;
27
28 SECTION("Has PMOverdrive ID")
29 {
30 ::AMD::PMOverdrive ts(std::make_unique<StringDataSourceStub>(),
31 std::make_unique<VectorStringDataSourceStub>(),
32 std::move(controlMocks));
33 REQUIRE(ts.ID() == ::AMD::PMOverdrive::ItemID);
34 }
35
36 SECTION("Is not active by default")
37 {
38 ::AMD::PMOverdrive ts(std::make_unique<StringDataSourceStub>(),
39 std::make_unique<VectorStringDataSourceStub>(),
40 std::move(controlMocks));
41 REQUIRE_FALSE(ts.active());
42 }
43
44 SECTION("Pre-init its controls, generating pre-init overdrive commands...")
45 {
46 std::vector<std::string> ppOdClkVoltageData{"..."};
47
48 controlMocks.emplace_back(std::make_unique<ControlMock>());
49 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
50 REQUIRE_CALL(*controlMock, preInit(trompeloeil::_));
51
52 SECTION("Including performance level command when its value is not manual")
53 {
54 PMOverdriveTestAdapter ts(
55 std::make_unique<StringDataSourceStub>(
56 "power_dpm_force_performance_level", "auto"),
57 std::make_unique<VectorStringDataSourceStub>("pp_od_clk_voltage",
58 ppOdClkVoltageData),
59 std::move(controlMocks));
60
61 CommandQueueStub ctlCmds;
62 ts.preInit(ctlCmds);
63
64 auto perfLevelEntry = ts.perfLevelPreInitValue();
65 REQUIRE(perfLevelEntry == "auto");
66
67 auto &commands = ctlCmds.commands();
68 REQUIRE(commands.size() == 3);
69
70 auto &[cmd0Path, cmd0Value] = commands.at(0);
71 REQUIRE(cmd0Path == "power_dpm_force_performance_level");
72 REQUIRE(cmd0Value == "manual");
73
74 auto &[cmd1Path, cmd1Value] = commands.at(1);
75 REQUIRE(cmd1Path == "pp_od_clk_voltage");
76 REQUIRE(cmd1Value == "r");
77
78 auto &[cmd2Path, cmd2Value] = commands.at(2);
79 REQUIRE(cmd2Path == "pp_od_clk_voltage");
80 REQUIRE(cmd2Value == "c");
81 }
82
83 SECTION("Excluding performance level command when its value is manual")
84 {
85 PMOverdriveTestAdapter ts(
86 std::make_unique<StringDataSourceStub>(
87 "power_dpm_force_performance_level", "manual"),
88 std::make_unique<VectorStringDataSourceStub>("pp_od_clk_voltage",
89 ppOdClkVoltageData),
90 std::move(controlMocks));
91
92 CommandQueueStub ctlCmds;
93 ts.preInit(ctlCmds);
94
95 auto perfLevelEntry = ts.perfLevelPreInitValue();
96 REQUIRE(perfLevelEntry == "manual");
97
98 auto &commands = ctlCmds.commands();
99 REQUIRE(commands.size() == 2);
100
101 auto &[cmd0Path, cmd0Value] = commands.at(0);
102 REQUIRE(cmd0Path == "pp_od_clk_voltage");
103 REQUIRE(cmd0Value == "r");
104
105 auto &[cmd1Path, cmd1Value] = commands.at(1);
106 REQUIRE(cmd1Path == "pp_od_clk_voltage");
107 REQUIRE(cmd1Value == "c");
108 }
109 }
110
111 SECTION("Post-init its controls and generate post-init overdrive commands")
112 {
113 std::vector<std::string> ppOdClkVoltageData{"..."};
114
115 controlMocks.emplace_back(std::make_unique<ControlMock>());
116 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
117 ALLOW_CALL(*controlMock, preInit(trompeloeil::_));
118 REQUIRE_CALL(*controlMock, postInit(trompeloeil::_));
119
120 PMOverdriveTestAdapter ts(std::make_unique<StringDataSourceStub>(
121 "power_dpm_force_performance_level", "auto"),
122 std::make_unique<VectorStringDataSourceStub>(
123 "pp_od_clk_voltage", ppOdClkVoltageData),
124 std::move(controlMocks));
125
126 CommandQueueStub ctlCmds;
127 ts.preInit(ctlCmds);
128 ctlCmds.clear();
129 ts.postInit(ctlCmds);
130
131 auto &commands = ctlCmds.commands();
132 REQUIRE(commands.size() == 2);
133
134 auto &[cmd0Path, cmd0Value] = commands.at(0);
135 REQUIRE(cmd0Path == "pp_od_clk_voltage");
136 REQUIRE(cmd0Value == "c");
137
138 auto &[cmd1Path, cmd1Value] = commands.at(1);
139 REQUIRE(cmd1Path == "power_dpm_force_performance_level");
140 REQUIRE(cmd1Value == "auto");
141 }
142
143 SECTION("Generate overdrive clean controls commands...")
144 {
145 std::vector<std::string> ppOdClkVoltageData{"..."};
146
147 controlMocks.emplace_back(std::make_unique<ControlMock>());
148 ControlMock *controlMock = static_cast<ControlMock *>(controlMocks[0].get());
149 REQUIRE_CALL(*controlMock, clean(trompeloeil::_));
150
151 SECTION("Including performance level command when its value is not manual")
152 {
153 PMOverdriveTestAdapter ts(
154 std::make_unique<StringDataSourceStub>(
155 "power_dpm_force_performance_level", "auto"),
156 std::make_unique<VectorStringDataSourceStub>("pp_od_clk_voltage",
157 ppOdClkVoltageData),
158 std::move(controlMocks));
159
160 CommandQueueStub ctlCmds;
161 ts.cleanControl(ctlCmds);
162
163 auto &commands = ctlCmds.commands();
164 REQUIRE(commands.size() == 3);
165
166 auto &[cmd0Path, cmd0Value] = commands.at(0);
167 REQUIRE(cmd0Path == "power_dpm_force_performance_level");
168 REQUIRE(cmd0Value == "manual");
169
170 auto &[cmd1Path, cmd1Value] = commands.at(1);
171 REQUIRE(cmd1Path == "pp_od_clk_voltage");
172 REQUIRE(cmd1Value == "r");
173
174 auto &[cmd2Path, cmd2Value] = commands.at(2);
175 REQUIRE(cmd2Path == "pp_od_clk_voltage");
176 REQUIRE(cmd2Value == "c");
177 }
178
179 SECTION("Excluding performance level command when its value is manual")
180 {
181 PMOverdriveTestAdapter ts(
182 std::make_unique<StringDataSourceStub>(
183 "power_dpm_force_performance_level", "manual"),
184 std::make_unique<VectorStringDataSourceStub>("pp_od_clk_voltage",
185 ppOdClkVoltageData),
186 std::move(controlMocks));
187
188 CommandQueueStub ctlCmds;
189 ts.cleanControl(ctlCmds);
190
191 auto &commands = ctlCmds.commands();
192 REQUIRE(commands.size() == 2);
193
194 auto &[cmd0Path, cmd0Value] = commands.at(0);
195 REQUIRE(cmd0Path == "pp_od_clk_voltage");
196 REQUIRE(cmd0Value == "r");
197
198 auto &[cmd1Path, cmd1Value] = commands.at(1);
199 REQUIRE(cmd1Path == "pp_od_clk_voltage");
200 REQUIRE(cmd1Value == "c");
201 }
202 }
203
204 SECTION("Sync its controls, generating sync control commands when is out of "
205 "sync...")
206 {
207 std::vector<std::string> ppOdClkVoltageData{"..."};
208
209 SECTION("Including performance level command when its value is not manual")
210 {
211 controlMocks.emplace_back(std::make_unique<ControlMock>());
212 ControlMock *controlMock =
213 static_cast<ControlMock *>(controlMocks[0].get());
214 REQUIRE_CALL(*controlMock, sync(trompeloeil::_));
215
216 PMOverdriveTestAdapter ts(
217 std::make_unique<StringDataSourceStub>(
218 "power_dpm_force_performance_level", "auto"),
219 std::make_unique<VectorStringDataSourceStub>("pp_od_clk_voltage",
220 ppOdClkVoltageData),
221 std::move(controlMocks));
222
223 CommandQueueStub ctlCmds;
224 ts.syncControl(ctlCmds);
225
226 auto &commands = ctlCmds.commands();
227 REQUIRE(commands.size() == 1);
228
229 auto &[cmd0Path, cmd0Value] = commands.at(0);
230 REQUIRE(cmd0Path == "power_dpm_force_performance_level");
231 REQUIRE(cmd0Value == "manual");
232 }
233
234 SECTION("Excluding performance level command when its value is manual")
235 {
236 controlMocks.emplace_back(std::make_unique<ControlMock>());
237 ControlMock *controlMock =
238 static_cast<ControlMock *>(controlMocks[0].get());
239 REQUIRE_CALL(*controlMock, sync(trompeloeil::_));
240
241 PMOverdriveTestAdapter ts(
242 std::make_unique<StringDataSourceStub>(
243 "power_dpm_force_performance_level", "manual"),
244 std::make_unique<VectorStringDataSourceStub>("pp_od_clk_voltage",
245 ppOdClkVoltageData),
246 std::move(controlMocks));
247
248 CommandQueueStub ctlCmds;
249 ts.syncControl(ctlCmds);
250
251 REQUIRE(ctlCmds.commands().empty());
252 }
253 }
254 }
255
256 } // namespace Tests::AMD::PMOverdrive