| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2024 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/cpu/handlers/epphandler.h" |
| 9 | |
| 10 | namespace Tests::CPU::EPPHandler { |
| 11 | |
| 12 | TEST_CASE("AMD PpDpmHandler tests", "[CPU][DataSourceHandler][EPPHandler]") |
| 13 | { |
| 14 | CommandQueueStub ctlCmds; |
| 15 | |
| 16 | std::string defaultHint{"default"}; |
| 17 | |
| 18 | auto availableEPPHintsDataSource = std::make_unique<StringDataSourceStub>( |
| 19 | "energy_performance_available_preferences", "default power"); |
| 20 | std::vector<std::unique_ptr<IDataSource<std::string>>> eppHintDataSource{}; |
| 21 | eppHintDataSource.emplace_back(std::make_unique<StringDataSourceStub>( |
| 22 | "energy_performance_preference", "default")); |
| 23 | |
| 24 | ::EPPHandler ts(std::move(availableEPPHintsDataSource), |
| 25 | std::move(eppHintDataSource)); |
| 26 | ts.init(); |
| 27 | |
| 28 | SECTION("Initialize the available EPP hints from its data source") |
| 29 | { |
| 30 | std::vector<std::string> eppHints = {"default", "power"}; |
| 31 | REQUIRE_THAT(ts.hints(), Catch::Matchers::Equals(eppHints)); |
| 32 | } |
| 33 | |
| 34 | SECTION("Has 'default' as the active hint by default when available") |
| 35 | { |
| 36 | REQUIRE(ts.hint() == defaultHint); |
| 37 | } |
| 38 | |
| 39 | SECTION("Setting a hint...") |
| 40 | { |
| 41 | SECTION("Works with known hints") |
| 42 | { |
| 43 | ts.hint("power"); |
| 44 | REQUIRE(ts.hint() == "power"); |
| 45 | } |
| 46 | |
| 47 | SECTION("Ignores unknown hints") |
| 48 | { |
| 49 | ts.hint("unknown"); |
| 50 | REQUIRE(ts.hint() == defaultHint); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | SECTION("Does not save and restore CPU data source state") |
| 55 | { |
| 56 | ts.saveState(); |
| 57 | ts.restoreState(ctlCmds); |
| 58 | REQUIRE(ctlCmds.commands().empty()); |
| 59 | } |
| 60 | |
| 61 | SECTION("Does not generate reset control commands") |
| 62 | { |
| 63 | ts.reset(ctlCmds); |
| 64 | REQUIRE(ctlCmds.commands().empty()); |
| 65 | } |
| 66 | |
| 67 | SECTION("Does not generate sync control commands when is synced") |
| 68 | { |
| 69 | ts.sync(ctlCmds); |
| 70 | REQUIRE(ctlCmds.commands().empty()); |
| 71 | } |
| 72 | |
| 73 | SECTION("Generates sync control commands when CPU hint is out of sync") |
| 74 | { |
| 75 | ts.hint("power"); |
| 76 | ts.sync(ctlCmds); |
| 77 | |
| 78 | auto &commands = ctlCmds.commands(); |
| 79 | REQUIRE(commands.size() == 1); |
| 80 | auto &[cmdPath, cmdValue] = commands.at(0); |
| 81 | REQUIRE(cmdPath == "energy_performance_preference"); |
| 82 | REQUIRE(cmdValue == "power"); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | } // namespace Tests::CPU::EPPHandler |