| 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/fixed/pmfixedlegacy.h" |
| 9 | |
| 10 | namespace Tests::AMD::PMFixedLegacy { |
| 11 | |
| 12 | class PMFixedLegacyTestAdapter : public ::AMD::PMFixedLegacy |
| 13 | { |
| 14 | public: |
| 15 | using ::AMD::PMFixedLegacy::PMFixedLegacy; |
| 16 | |
| 17 | using ::AMD::PMFixedLegacy::cleanControl; |
| 18 | using ::AMD::PMFixedLegacy::mode; |
| 19 | using ::AMD::PMFixedLegacy::modes; |
| 20 | using ::AMD::PMFixedLegacy::syncControl; |
| 21 | }; |
| 22 | |
| 23 | TEST_CASE("AMD PMFixedLegacy tests", "[GPU][AMD][PM][PMFixed][Legacy]") |
| 24 | { |
| 25 | std::string const powerMethodPath{"power_method"}; |
| 26 | std::string const powerProfilePath{"power_profile"}; |
| 27 | CommandQueueStub ctlCmds; |
| 28 | |
| 29 | SECTION("Has 'low' mode selected by default") |
| 30 | { |
| 31 | PMFixedLegacyTestAdapter ts(std::make_unique<StringDataSourceStub>(), |
| 32 | std::make_unique<StringDataSourceStub>()); |
| 33 | |
| 34 | REQUIRE(ts.mode() == "low"); |
| 35 | } |
| 36 | |
| 37 | SECTION("Has [low, mid, high] modes") |
| 38 | { |
| 39 | std::vector<std::string> const powerProfiles{"low", "mid", "high"}; |
| 40 | PMFixedLegacyTestAdapter ts(std::make_unique<StringDataSourceStub>(), |
| 41 | std::make_unique<StringDataSourceStub>()); |
| 42 | |
| 43 | REQUIRE(ts.modes() == powerProfiles); |
| 44 | } |
| 45 | |
| 46 | SECTION("Does generate clean control commands") |
| 47 | { |
| 48 | PMFixedLegacyTestAdapter ts( |
| 49 | std::make_unique<StringDataSourceStub>(powerMethodPath, "profile"), |
| 50 | std::make_unique<StringDataSourceStub>(powerProfilePath, "low")); |
| 51 | ts.cleanControl(ctlCmds); |
| 52 | |
| 53 | REQUIRE(ctlCmds.commands().size() == 2); |
| 54 | |
| 55 | auto &[cmd0Path, cmd0Value] = ctlCmds.commands().front(); |
| 56 | REQUIRE(cmd0Path == powerMethodPath); |
| 57 | REQUIRE(cmd0Value == "profile"); |
| 58 | |
| 59 | auto &[cmd1Path, cmd1Value] = ctlCmds.commands().back(); |
| 60 | REQUIRE(cmd1Path == powerProfilePath); |
| 61 | REQUIRE(cmd1Value == "auto"); |
| 62 | } |
| 63 | |
| 64 | SECTION("Does not generate sync control commands when is synced") |
| 65 | { |
| 66 | PMFixedLegacyTestAdapter ts( |
| 67 | std::make_unique<StringDataSourceStub>(powerMethodPath, "profile"), |
| 68 | std::make_unique<StringDataSourceStub>(powerProfilePath, "low")); |
| 69 | ts.syncControl(ctlCmds); |
| 70 | |
| 71 | REQUIRE(ctlCmds.commands().empty()); |
| 72 | } |
| 73 | |
| 74 | SECTION("Does generate sync control commands when...") |
| 75 | { |
| 76 | SECTION("power_method is out of sync") |
| 77 | { |
| 78 | PMFixedLegacyTestAdapter ts( |
| 79 | std::make_unique<StringDataSourceStub>(powerMethodPath, "_other_"), |
| 80 | std::make_unique<StringDataSourceStub>(powerProfilePath, "low")); |
| 81 | ts.syncControl(ctlCmds); |
| 82 | |
| 83 | REQUIRE(ctlCmds.commands().size() == 2); |
| 84 | |
| 85 | auto &[cmd0Path, cmd0Value] = ctlCmds.commands().front(); |
| 86 | REQUIRE(cmd0Path == powerMethodPath); |
| 87 | REQUIRE(cmd0Value == "profile"); |
| 88 | |
| 89 | auto &[cmd1Path, cmd1Value] = ctlCmds.commands().back(); |
| 90 | REQUIRE(cmd1Path == powerProfilePath); |
| 91 | REQUIRE(cmd1Value == "low"); |
| 92 | } |
| 93 | |
| 94 | SECTION("power_profile is out of sync") |
| 95 | { |
| 96 | PMFixedLegacyTestAdapter ts( |
| 97 | std::make_unique<StringDataSourceStub>(powerMethodPath, "profile"), |
| 98 | std::make_unique<StringDataSourceStub>(powerProfilePath, "_other_")); |
| 99 | ts.syncControl(ctlCmds); |
| 100 | |
| 101 | REQUIRE(ctlCmds.commands().size() == 1); |
| 102 | |
| 103 | auto &[cmdPath, cmdValue] = ctlCmds.commands().front(); |
| 104 | REQUIRE(cmdPath == powerProfilePath); |
| 105 | REQUIRE(cmdValue == "low"); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | SECTION("power_method and power_profile are out of sync") |
| 110 | { |
| 111 | PMFixedLegacyTestAdapter ts( |
| 112 | std::make_unique<StringDataSourceStub>(powerMethodPath, "_other_"), |
| 113 | std::make_unique<StringDataSourceStub>(powerProfilePath, "_other_")); |
| 114 | ts.syncControl(ctlCmds); |
| 115 | |
| 116 | REQUIRE(ctlCmds.commands().size() == 2); |
| 117 | |
| 118 | auto &[cmd0Path, cmd0Value] = ctlCmds.commands().front(); |
| 119 | REQUIRE(cmd0Path == powerMethodPath); |
| 120 | REQUIRE(cmd0Value == "profile"); |
| 121 | |
| 122 | auto &[cmd1Path, cmd1Value] = ctlCmds.commands().back(); |
| 123 | REQUIRE(cmd1Path == powerProfilePath); |
| 124 | REQUIRE(cmd1Value == "low"); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | } // namespace Tests::AMD::PMFixedLegacy |