| 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 "core/idatasource.h" |
| 7 | #include "core/info/amd/gpuinfopmoverdrive.h" |
| 8 | |
| 9 | namespace Tests::AMD::GPUInfoPMOverdrive { |
| 10 | |
| 11 | class VectorStringPathDataSourceStub |
| 12 | : public IDataSource<std::vector<std::string>, std::filesystem::path const> |
| 13 | { |
| 14 | public: |
| 15 | VectorStringPathDataSourceStub(std::string_view source = "", |
| 16 | std::vector<std::string> data = {""}, |
| 17 | bool success = true) noexcept |
| 18 | : source_(source) |
| 19 | , data_(data) |
| 20 | , success_(success) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | std::string source() const override |
| 25 | { |
| 26 | return source_; |
| 27 | } |
| 28 | |
| 29 | bool read(std::vector<std::string> &data, std::filesystem::path const &) override |
| 30 | { |
| 31 | data = data_; |
| 32 | return success_; |
| 33 | } |
| 34 | |
| 35 | std::string const source_; |
| 36 | std::vector<std::string> const data_; |
| 37 | bool success_; |
| 38 | }; |
| 39 | |
| 40 | TEST_CASE("GPUInfoPMOverdrive tests", |
| 41 | "[AMD][Info][GPUInfo][GPUInfoPMOverdrive]") |
| 42 | { |
| 43 | Vendor vendor(Vendor::AMD); |
| 44 | int const gpuIndex = 0; |
| 45 | IGPUInfo::Path path("_sys_", "_dev_"); |
| 46 | |
| 47 | SECTION("Provides voltage curve capability") |
| 48 | { |
| 49 | // clang-format off |
| 50 | std::vector<std::string> ppOdClkVoltageData{"OD_VDDC_CURVE:", |
| 51 | "0: 700Mhz 800mV",}; |
| 52 | // clang-format on |
| 53 | |
| 54 | ::AMD::GPUInfoPMOverdrive ts(std::make_unique<VectorStringPathDataSourceStub>( |
| 55 | "pp_od_clk_voltage", std::move(ppOdClkVoltageData))); |
| 56 | |
| 57 | auto output = ts.provideCapabilities(vendor, gpuIndex, path); |
| 58 | |
| 59 | REQUIRE(output.size() == 1); |
| 60 | REQUIRE(output.front() == ::AMD::GPUInfoPMOverdrive::VoltCurve); |
| 61 | } |
| 62 | |
| 63 | SECTION("Does not provide voltage curve capability when the curve points " |
| 64 | "have missing coordinates") |
| 65 | { |
| 66 | // clang-format off |
| 67 | std::vector<std::string> ppOdClkVoltageData{"OD_VDDC_CURVE:", |
| 68 | "0: 800mV"}; |
| 69 | // clang-format on |
| 70 | |
| 71 | ::AMD::GPUInfoPMOverdrive ts(std::make_unique<VectorStringPathDataSourceStub>( |
| 72 | "pp_od_clk_voltage", std::move(ppOdClkVoltageData))); |
| 73 | |
| 74 | auto output = ts.provideCapabilities(vendor, gpuIndex, path); |
| 75 | |
| 76 | REQUIRE(output.empty()); |
| 77 | } |
| 78 | |
| 79 | SECTION("Provides clock + voltage capability") |
| 80 | { |
| 81 | // clang-format off |
| 82 | std::vector<std::string> ppOdClkVoltageData{"OD_SCLK:", |
| 83 | "0: 300MHz 800mV"}; |
| 84 | // clang-format on |
| 85 | |
| 86 | ::AMD::GPUInfoPMOverdrive ts(std::make_unique<VectorStringPathDataSourceStub>( |
| 87 | "pp_od_clk_voltage", std::move(ppOdClkVoltageData))); |
| 88 | |
| 89 | auto output = ts.provideCapabilities(vendor, gpuIndex, path); |
| 90 | |
| 91 | REQUIRE(output.size() == 1); |
| 92 | REQUIRE(output.front() == ::AMD::GPUInfoPMOverdrive::ClkVolt); |
| 93 | } |
| 94 | |
| 95 | SECTION("Provides clock capability") |
| 96 | { |
| 97 | // clang-format off |
| 98 | std::vector<std::string> ppOdClkVoltageData{"OD_SCLK:", |
| 99 | "0: 300MHz"}; |
| 100 | // clang-format on |
| 101 | |
| 102 | ::AMD::GPUInfoPMOverdrive ts(std::make_unique<VectorStringPathDataSourceStub>( |
| 103 | "pp_od_clk_voltage", std::move(ppOdClkVoltageData))); |
| 104 | |
| 105 | auto output = ts.provideCapabilities(vendor, gpuIndex, path); |
| 106 | |
| 107 | REQUIRE(output.size() == 1); |
| 108 | REQUIRE(output.front() == ::AMD::GPUInfoPMOverdrive::Clk); |
| 109 | } |
| 110 | |
| 111 | SECTION("Provides clock offset capability") |
| 112 | { |
| 113 | // clang-format off |
| 114 | std::vector<std::string> ppOdClkVoltageData{"OD_SCLK_OFFSET:", |
| 115 | "-300MHz"}; |
| 116 | // clang-format on |
| 117 | |
| 118 | ::AMD::GPUInfoPMOverdrive ts(std::make_unique<VectorStringPathDataSourceStub>( |
| 119 | "pp_od_clk_voltage", std::move(ppOdClkVoltageData))); |
| 120 | |
| 121 | auto output = ts.provideCapabilities(vendor, gpuIndex, path); |
| 122 | |
| 123 | REQUIRE(output.size() == 1); |
| 124 | REQUIRE(output.front() == ::AMD::GPUInfoPMOverdrive::ClkOffset); |
| 125 | } |
| 126 | |
| 127 | SECTION("Provides voltage offset capability") |
| 128 | { |
| 129 | // clang-format off |
| 130 | std::vector<std::string> ppOdClkVoltageData{"OD_VDDGFX_OFFSET:", |
| 131 | "0mV"}; |
| 132 | // clang-format on |
| 133 | |
| 134 | ::AMD::GPUInfoPMOverdrive ts(std::make_unique<VectorStringPathDataSourceStub>( |
| 135 | "pp_od_clk_voltage", std::move(ppOdClkVoltageData))); |
| 136 | |
| 137 | auto output = ts.provideCapabilities(vendor, gpuIndex, path); |
| 138 | |
| 139 | REQUIRE(output.size() == 1); |
| 140 | REQUIRE(output.front() == ::AMD::GPUInfoPMOverdrive::VoltOffset); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | } // namespace Tests::AMD::GPUInfoPMOverdrive |