Debian Codegraph @

tests/src/test_amdpmfreqod.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 #include <catch2/trompeloeil.hpp>
6
7 #include "common/commandqueuestub.h"
8 #include "common/uintdatasourcestub.h"
9 #include "core/components/controls/amd/pm/advanced/overclock/freqod/pmfreqod.h"
10
11 extern template struct trompeloeil::reporter<trompeloeil::specialized>;
12
13 namespace Tests::AMD::PMFreqOd {
14
15 class PMFreqOdTestAdapter : public ::AMD::PMFreqOd
16 {
17 public:
18 using ::AMD::PMFreqOd::PMFreqOd;
19
20 using PMFreqOd::baseMclk;
21 using PMFreqOd::baseSclk;
22 using PMFreqOd::cleanControl;
23 using PMFreqOd::exportControl;
24 using PMFreqOd::importControl;
25 using PMFreqOd::mclkOd;
26 using PMFreqOd::sclkOd;
27 using PMFreqOd::syncControl;
28 };
29
30 class PMFreqOdImporterStub : public ::AMD::PMFreqOd::Importer
31 {
32 public:
33 PMFreqOdImporterStub(unsigned int sclkOd, unsigned int mclkOd)
34 : sclkOd_(sclkOd)
35 , mclkOd_(mclkOd)
36 {
37 }
38
39 std::optional<std::reference_wrapper<Importable::Importer>>
40 provideImporter(Item const &) override
41 {
42 return {};
43 }
44
45 bool provideActive() const override
46 {
47 return false;
48 }
49
50 unsigned int providePMFreqOdSclkOd() const override
51 {
52 return sclkOd_;
53 }
54
55 unsigned int providePMFreqOdMclkOd() const override
56 {
57 return mclkOd_;
58 }
59
60 private:
61 unsigned int sclkOd_;
62 unsigned int mclkOd_;
63 };
64
65 class PMFreqOdExporterMock : public ::AMD::PMFreqOd::Exporter
66 {
67 public:
68 MAKE_MOCK1(takePMFreqOdSclkOd, void(unsigned int), override);
69 MAKE_MOCK1(takePMFreqOdMclkOd, void(unsigned int), override);
70 MAKE_MOCK1(takePMFreqOdBaseSclk, void(units::frequency::megahertz_t), override);
71 MAKE_MOCK1(takePMFreqOdBaseMclk, void(units::frequency::megahertz_t), override);
72 MAKE_MOCK1(takeActive, void(bool), override);
73 MAKE_MOCK1(
74 provideExporter,
75 std::optional<std::reference_wrapper<Exportable::Exporter>>(Item const &),
76 override);
77 };
78
79 TEST_CASE("AMD PMFreqOd tests",
80 "[GPU][AMD][PM][PMAdvanced][PMOverclock][PMFreqOd]")
81 {
82 CommandQueueStub ctlCmds;
83 std::vector<std::pair<unsigned int, units::frequency::megahertz_t>> const states{
84 std::make_pair(0u, units::frequency::megahertz_t(300)),
85 std::make_pair(1u, units::frequency::megahertz_t(2000))};
86
87 SECTION("Has PMFreqOd ID")
88 {
89 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
90 std::make_unique<UIntDataSourceStub>(), states,
91 states);
92 REQUIRE(ts.ID() == ::AMD::PMFreqOd::ItemID);
93 }
94
95 SECTION("Is active by default")
96 {
97 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
98 std::make_unique<UIntDataSourceStub>(), states,
99 states);
100 REQUIRE(ts.active());
101 }
102
103 SECTION("Has 0 as sclk & mclk od values by default")
104 {
105 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
106 std::make_unique<UIntDataSourceStub>(), states,
107 states);
108 REQUIRE(ts.sclkOd() == 0);
109 REQUIRE(ts.mclkOd() == 0);
110 }
111
112 SECTION("Initializes base sclk from sclk states on construction")
113 {
114 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
115 std::make_unique<UIntDataSourceStub>(), states,
116 states);
117 ts.init();
118 REQUIRE(ts.baseSclk() == units::frequency::megahertz_t(2000));
119 }
120
121 SECTION("Initializes base mclk from mclk states on construction")
122 {
123 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
124 std::make_unique<UIntDataSourceStub>(), states,
125 states);
126 ts.init();
127 REQUIRE(ts.baseMclk() == units::frequency::megahertz_t(2000));
128 }
129
130 SECTION("Clamps sclkOd in [0, 20] range")
131 {
132 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
133 std::make_unique<UIntDataSourceStub>(), states,
134 states);
135 ts.sclkOd(21);
136 REQUIRE(ts.sclkOd() == 20);
137 }
138
139 SECTION("Clamps mclkOd in [0, 20] range")
140 {
141 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
142 std::make_unique<UIntDataSourceStub>(), states,
143 states);
144 ts.mclkOd(21);
145 REQUIRE(ts.mclkOd() == 20);
146 }
147
148 SECTION("Does not generate pre-init control commands")
149 {
150 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
151 std::make_unique<UIntDataSourceStub>(), states,
152 states);
153 ts.preInit(ctlCmds);
154 REQUIRE(ctlCmds.commands().empty());
155 }
156
157 SECTION("Does not generate post-init control commands")
158 {
159 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
160 std::make_unique<UIntDataSourceStub>(), states,
161 states);
162 ts.postInit(ctlCmds);
163 REQUIRE(ctlCmds.commands().empty());
164 }
165
166 SECTION("Import its state")
167 {
168 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
169 std::make_unique<UIntDataSourceStub>(), states,
170 states);
171 ts.init();
172 PMFreqOdImporterStub i(2, 3);
173 ts.importControl(i);
174
175 REQUIRE(ts.sclkOd() == 2);
176 REQUIRE(ts.mclkOd() == 3);
177 }
178
179 SECTION("Export its state and available states")
180 {
181 PMFreqOdTestAdapter ts(std::make_unique<UIntDataSourceStub>(),
182 std::make_unique<UIntDataSourceStub>(), states,
183 states);
184 ts.init();
185
186 trompeloeil::sequence seq;
187 PMFreqOdExporterMock e;
188 REQUIRE_CALL(e, takePMFreqOdBaseSclk(
189 trompeloeil::eq(units::frequency::megahertz_t(2000))))
190 .IN_SEQUENCE(seq);
191 REQUIRE_CALL(e, takePMFreqOdBaseMclk(
192 trompeloeil::eq(units::frequency::megahertz_t(2000))))
193 .IN_SEQUENCE(seq);
194 REQUIRE_CALL(e, takePMFreqOdSclkOd(trompeloeil::eq(0u))).IN_SEQUENCE(seq);
195 REQUIRE_CALL(e, takePMFreqOdMclkOd(trompeloeil::eq(0u))).IN_SEQUENCE(seq);
196
197 ts.exportControl(e);
198 }
199
200 SECTION("Generate clean control commands unconditionally")
201 {
202 PMFreqOdTestAdapter ts(
203 std::make_unique<UIntDataSourceStub>("pp_sclk_od", 0),
204 std::make_unique<UIntDataSourceStub>("pp_mclk_od", 0), states, states);
205 ts.init();
206 ts.cleanControl(ctlCmds);
207
208 auto &commands = ctlCmds.commands();
209 REQUIRE(commands.size() == 2);
210
211 auto &[cmd0Path, cmd0Value] = commands.front();
212 REQUIRE(cmd0Path == "pp_sclk_od");
213 REQUIRE(cmd0Value == "0");
214
215 auto &[cmd1Path, cmd1Value] = commands.back();
216 REQUIRE(cmd1Path == "pp_mclk_od");
217 REQUIRE(cmd1Value == "0");
218 }
219
220 SECTION("Does not generate sync control commands when is synced")
221 {
222 PMFreqOdTestAdapter ts(
223 std::make_unique<UIntDataSourceStub>("pp_sclk_od", 1),
224 std::make_unique<UIntDataSourceStub>("pp_mclk_od", 2), states, states);
225 ts.init();
226 ts.sclkOd(1);
227 ts.mclkOd(2);
228 ts.syncControl(ctlCmds);
229
230 REQUIRE(ctlCmds.commands().empty());
231 }
232
233 SECTION("Does generate sync control commands when...")
234 {
235 SECTION("pp_sclk_od is out of sync")
236 {
237 PMFreqOdTestAdapter ts(
238 std::make_unique<UIntDataSourceStub>("pp_sclk_od", 0),
239 std::make_unique<UIntDataSourceStub>("pp_mclk_od", 0), states, states);
240 ts.init();
241 ts.sclkOd(1);
242 ts.mclkOd(0);
243 ts.syncControl(ctlCmds);
244
245 REQUIRE(ctlCmds.commands().size() == 1);
246 auto &[cmdPath, cmdValue] = ctlCmds.commands().front();
247 REQUIRE(cmdPath == "pp_sclk_od");
248 REQUIRE(cmdValue == "1");
249 }
250
251 SECTION("pp_mclk_od is out of sync")
252 {
253 PMFreqOdTestAdapter ts(
254 std::make_unique<UIntDataSourceStub>("pp_sclk_od", 0),
255 std::make_unique<UIntDataSourceStub>("pp_mclk_od", 0), states, states);
256 ts.init();
257 ts.sclkOd(0);
258 ts.mclkOd(1);
259 ts.syncControl(ctlCmds);
260
261 REQUIRE(ctlCmds.commands().size() == 1);
262 auto &[cmdPath, cmdValue] = ctlCmds.commands().front();
263 REQUIRE(cmdPath == "pp_mclk_od");
264 REQUIRE(cmdValue == "1");
265 }
266 }
267 }
268
269 } // namespace Tests::AMD::PMFreqOd