| 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 "core/components/controls/amd/pm/fixed/pmfixed.h" |
| 9 | |
| 10 | extern template struct trompeloeil::reporter<trompeloeil::specialized>; |
| 11 | |
| 12 | namespace Tests::AMD::PMFixed { |
| 13 | |
| 14 | class PMFixedTestAdapter : public ::AMD::PMFixed |
| 15 | { |
| 16 | public: |
| 17 | using ::AMD::PMFixed::PMFixed; |
| 18 | |
| 19 | using ::AMD::PMFixed::exportControl; |
| 20 | using ::AMD::PMFixed::importControl; |
| 21 | using ::AMD::PMFixed::mode; |
| 22 | |
| 23 | MAKE_MOCK1(cleanControl, void(ICommandQueue &), override); |
| 24 | MAKE_MOCK1(syncControl, void(ICommandQueue &), override); |
| 25 | MAKE_CONST_MOCK0(modes, std::vector<std::string> const &(), override); |
| 26 | }; |
| 27 | |
| 28 | class PMFixedImporterStub : public ::AMD::PMFixed::Importer |
| 29 | { |
| 30 | public: |
| 31 | PMFixedImporterStub(std::string mode) |
| 32 | : mode_(std::move(mode)) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | std::optional<std::reference_wrapper<Importable::Importer>> |
| 37 | provideImporter(Item const &) override |
| 38 | { |
| 39 | return {}; |
| 40 | } |
| 41 | |
| 42 | bool provideActive() const override |
| 43 | { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | std::string const &providePMFixedMode() const override |
| 48 | { |
| 49 | return mode_; |
| 50 | } |
| 51 | |
| 52 | private: |
| 53 | std::string mode_; |
| 54 | }; |
| 55 | |
| 56 | class PMFixedExporterMock : public ::AMD::PMFixed::Exporter |
| 57 | { |
| 58 | public: |
| 59 | MAKE_MOCK1(takePMFixedMode, void(std::string const &), override); |
| 60 | MAKE_MOCK1(takePMFixedModes, void(std::vector<std::string> const &), override); |
| 61 | MAKE_MOCK1(takeActive, void(bool), override); |
| 62 | MAKE_MOCK1( |
| 63 | provideExporter, |
| 64 | std::optional<std::reference_wrapper<Exportable::Exporter>>(Item const &), |
| 65 | override); |
| 66 | }; |
| 67 | |
| 68 | TEST_CASE("AMD PMFixed tests", "[GPU][AMD][PM][PMFixed]") |
| 69 | { |
| 70 | std::vector<std::string> const modes{"_mode_0_", "_mode_1_"}; |
| 71 | PMFixedTestAdapter ts("_mode_0_"); |
| 72 | ALLOW_CALL(ts, modes()).LR_RETURN(modes); |
| 73 | |
| 74 | SECTION("Has PMFixed ID") |
| 75 | { |
| 76 | REQUIRE(ts.ID() == ::AMD::PMFixed::ItemID); |
| 77 | } |
| 78 | |
| 79 | SECTION("Is not active by default") |
| 80 | { |
| 81 | REQUIRE_FALSE(ts.active()); |
| 82 | } |
| 83 | |
| 84 | SECTION("mode only sets known modes") |
| 85 | { |
| 86 | REQUIRE_CALL(ts, modes()).LR_RETURN(modes); |
| 87 | |
| 88 | ts.mode("_mode_1_"); |
| 89 | REQUIRE(ts.mode() == "_mode_1_"); |
| 90 | |
| 91 | ts.mode("unkown"); |
| 92 | REQUIRE(ts.mode() == "_mode_1_"); |
| 93 | } |
| 94 | |
| 95 | SECTION("Does not generate pre-init control commands") |
| 96 | { |
| 97 | CommandQueueStub cmds; |
| 98 | ts.preInit(cmds); |
| 99 | REQUIRE(cmds.commands().empty()); |
| 100 | } |
| 101 | |
| 102 | SECTION("Does not generate post-init control commands") |
| 103 | { |
| 104 | CommandQueueStub cmds; |
| 105 | ts.postInit(cmds); |
| 106 | REQUIRE(cmds.commands().empty()); |
| 107 | } |
| 108 | |
| 109 | SECTION("Imports its mode") |
| 110 | { |
| 111 | PMFixedImporterStub i("_mode_1_"); |
| 112 | ts.importControl(i); |
| 113 | |
| 114 | REQUIRE(ts.mode() == "_mode_1_"); |
| 115 | } |
| 116 | |
| 117 | SECTION("Export its mode and available modes") |
| 118 | { |
| 119 | trompeloeil::sequence seq; |
| 120 | PMFixedExporterMock e; |
| 121 | REQUIRE_CALL(e, takePMFixedModes(trompeloeil::_)).IN_SEQUENCE(seq); |
| 122 | REQUIRE_CALL(e, takePMFixedMode(trompeloeil::eq("_mode_0_"))).IN_SEQUENCE(seq); |
| 123 | |
| 124 | ts.exportControl(e); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | } // namespace Tests::AMD::PMFixed |