| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/tests/src/test_gpu.cpp`/ |
| 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"cxx . . $ `<file>/tests/src/common/commandqueuestub.h`/ |
| 8 | #include "common/controlmock.h"cxx . . $ `<file>/tests/src/common/controlmock.h`/ |
| 9 | #include "common/sensormock.h"cxx . . $ `<file>/tests/src/common/sensormock.h`/ |
| 10 | #include "core/components/gpu.h"cxx . . $ `<file>/src/core/components/gpu.h`/ |
| 11 | #include "core/info/igpuinfo.h"cxx . . $ `<file>/src/core/info/igpuinfo.h`/ |
| 12 | |
| 13 | extern template struct trompeloeil::reportercxx . . $ trompeloeil/reporter#<trompeloeilcxx . . $ trompeloeil/::specializedcxx . . $ trompeloeil/specialized#>; |
| 14 | |
| 15 | namespace Testscxx . . $ Tests/::GPUcxx . . $ Tests/GPU/ { |
| 16 | |
| 17 | class GPUInfoStubcxx . . $ Tests/GPU/GPUInfoStub# : public IGPUInfocxx . . $ IGPUInfo# |
| 18 | { |
| 19 | public: |
| 20 | Vendorcxx . . $ Vendor# vendorcxx . . $ Tests/GPU/GPUInfoStub#vendor(f3352d101b4b8e0).() const override |
| 21 | { |
| 22 | return Vendorcxx . . $ Vendor#::AMDcxx . . $ Vendor#AMD.; |
| 23 | } |
| 24 | |
| 25 | int indexcxx . . $ Tests/GPU/GPUInfoStub#index(455f465bc33b4cdf).() const override |
| 26 | { |
| 27 | return 123; |
| 28 | } |
| 29 | |
| 30 | IGPUInfocxx . . $ IGPUInfo#::Pathcxx . . $ IGPUInfo#Path# const &pathcxx . . $ Tests/GPU/GPUInfoStub#path(f79b37054f6b84d7).() const override |
| 31 | { |
| 32 | return path_cxx . . $ Tests/GPU/GPUInfoStub#path_.; |
| 33 | } |
| 34 | |
| 35 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> keyscxx . . $ Tests/GPU/GPUInfoStub#keys(491c255a7e496038).() const override |
| 36 | { |
| 37 | return stdcxx . . $ std/vector#vector(9619226211e5a241).::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#>{"info_k1"}; |
| 38 | } |
| 39 | |
| 40 | stdcxx . . $ std/::stringcxx . . $ std/string# infocxx . . $ Tests/GPU/GPUInfoStub#info(3654cd48a63d288).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view#) const override |
| 41 | { |
| 42 | return "info_1"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 43 | } |
| 44 | |
| 45 | bool hasCapabilitycxx . . $ Tests/GPU/GPUInfoStub#hasCapability(aa6d140991badc75).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view#) const override |
| 46 | { |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | void initializecxx . . $ Tests/GPU/GPUInfoStub#initialize(c158fff4aa1693ae).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IGPUInfocxx . . $ IGPUInfo#::IProvidercxx . . $ IGPUInfo#IProvider#>> const &, |
| 51 | IHWIDTranslatorcxx . . $ IHWIDTranslator# const &) override |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | IGPUInfocxx . . $ IGPUInfo#::Pathcxx . . $ IGPUInfo#Path# path_cxx . . $ Tests/GPU/GPUInfoStub#path_.{cxx . . $ IGPUInfo#Path#Path(df8cb93b336b884d)."_sys_"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "_dev_"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).}; |
| 57 | }; |
| 58 | |
| 59 | class GPUImporterStubcxx . . $ Tests/GPU/GPUImporterStub# : public IGPUcxx . . $ IGPU#::Importercxx . . $ ISysComponent#Importer# |
| 60 | { |
| 61 | public: |
| 62 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Importablecxx . . $ Importable#::Importercxx . . $ Importable#Importer#>> |
| 63 | provideImportercxx . . $ Tests/GPU/GPUImporterStub#provideImporter(c13a3bcac0db4745).(Itemcxx . . $ Item# const &) override |
| 64 | { |
| 65 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).this; |
| 66 | } |
| 67 | |
| 68 | bool provideActivecxx . . $ Tests/GPU/GPUImporterStub#provideActive(50ce9a9e25b4a850).() const override |
| 69 | { |
| 70 | return false; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | class GPUExporterMockcxx . . $ Tests/GPU/GPUExporterMock# : public IGPUcxx . . $ IGPU#::Exportercxx . . $ IGPU#Exporter# |
| 75 | { |
| 76 | public: |
| 77 | MAKE_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4223:9`!(takeActive, void(bool), override); |
| 78 | MAKE_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4223:9`!(takeInfo, void(IGPUInfo const &), override); |
| 79 | MAKE_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4223:9`!(takeSensor, void(ISensor const &), override); |
| 80 | MAKE_MOCK1cxx . . $ `<external>/1068432606165018960/mock.hpp:4223:9`!( |
| 81 | provideExporter, |
| 82 | std::optional<std::reference_wrapper<Exportable::Exporter>>(Item const &), |
| 83 | override); |
| 84 | }; |
| 85 | |
| 86 | TEST_CASEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:144:11`!("GPU tests", "[GPU]") |
| 87 | { |
| 88 | CommandQueueStubcxx . . $ CommandQueueStub# ctlCmds; |
| 89 | |
| 90 | auto info = stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<GPUInfoStubcxx . . $ Tests/GPU/GPUInfoStub#>(); |
| 91 | auto &infoStub = *cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).info; |
| 92 | |
| 93 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IControlcxx . . $ IControl#>> controlscxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 94 | controls.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ControlMockcxx . . $ ControlMock#>()); |
| 95 | auto &controlMock = static_cast<ControlMockcxx . . $ ControlMock# &>(*cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).controls[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]); |
| 96 | |
| 97 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<ISensorcxx . . $ ISensor#>> sensorscxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 98 | sensors.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<SensorMockcxx . . $ SensorMock#>()); |
| 99 | auto &sensorMock = static_cast<SensorMockcxx . . $ SensorMock# &>(*cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).sensors[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]); |
| 100 | |
| 101 | ::GPUcxx . . $ GPU# tscxx . . $ GPU#GPU(3288d85259378b97).(stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::movecxx . . $ std/move(e35c19a1ba7baa26).(info), stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(controls), stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sensors)); |
| 102 | |
| 103 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Has IGPU ID") |
| 104 | { |
| 105 | REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(ts.ID() == IGPU::ItemID); |
| 106 | } |
| 107 | |
| 108 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Is active by default") |
| 109 | { |
| 110 | REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(ts.active()); |
| 111 | |
| 112 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Can be deactivated") |
| 113 | { |
| 114 | ts.activatecxx . . $ GPU#activate(b45ddcbc8423892c).(false); |
| 115 | |
| 116 | REQUIRE_FALSEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:128:11`!(ts.active()); |
| 117 | |
| 118 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Can be activated") |
| 119 | { |
| 120 | ts.activatecxx . . $ GPU#activate(b45ddcbc8423892c).(true); |
| 121 | |
| 122 | REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(ts.active()); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Has a unique key in a system component scope") |
| 128 | { |
| 129 | // 'GPU' + gpu index combination seems to be good enough to differentiate |
| 130 | // between system components. |
| 131 | REQUIRE_THATcxx . . $ `<external>/3333208929440565380/catch_matchers.hpp:222:11`!(ts.key(), Catch::Matchers::ContainsSubstring("GPU") && |
| 132 | Catch::Matchers::ContainsSubstring("123")); |
| 133 | } |
| 134 | |
| 135 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Its GPU information can be retrieved") |
| 136 | { |
| 137 | REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(&ts.info() == &infoStub); |
| 138 | } |
| 139 | |
| 140 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("GPU description and information can be retrieved") |
| 141 | { |
| 142 | auto [gpuDesc, infos] = ts.componentInfocxx . . $ GPU#componentInfo(e6b143d762ee67dc).(); |
| 143 | REQUIRE_THATcxx . . $ `<external>/3333208929440565380/catch_matchers.hpp:222:11`!(gpuDesc, Catch::Matchers::ContainsSubstring("GPU") && |
| 144 | Catch::Matchers::ContainsSubstring("123")); |
| 145 | REQUIRE_FALSEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:128:11`!(infos.empty()); |
| 146 | auto &[infoKey, info] = infos[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]; |
| 147 | REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(infoKey == "info_k1"); |
| 148 | REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(info == "info_1"); |
| 149 | } |
| 150 | |
| 151 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Update its sensors") |
| 152 | { |
| 153 | stdcxx . . $ std/::stringcxx . . $ std/string# const sensoridcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("sensorid"); |
| 154 | ALLOW_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4337:9`!(sensorMock, ID()).LR_RETURNcxx . . $ `<external>/1068432606165018960/mock.hpp:4349:9`!(sensorid); |
| 155 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(sensorMock, update()); |
| 156 | |
| 157 | stdcxx . . $ std/::unordered_mapcxx . . $ std/unordered_map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::unordered_setcxx . . $ std/unordered_set#<stdcxx . . $ std/::stringcxx . . $ std/string#>> ignoredcxx . . $ std/unordered_map#unordered_map(49f6e7a06ebc5aa8).; |
| 158 | ts.updateSensorscxx . . $ GPU#updateSensors(b9a76d75a3ae6a25).(ignored); |
| 159 | } |
| 160 | |
| 161 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Does not update ignored sensors") |
| 162 | { |
| 163 | stdcxx . . $ std/::stringcxx . . $ std/string# const sensoridcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("sensorid"); |
| 164 | stdcxx . . $ std/::unordered_mapcxx . . $ std/unordered_map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::unordered_setcxx . . $ std/unordered_set#<stdcxx . . $ std/::stringcxx . . $ std/string#>> ignoredcxx . . $ std/unordered_map#unordered_map(49f6e7a06ebc5aa8).; |
| 165 | ignored[cxx . . $ std/unordered_map#`operator[]`(4f10b6009f0ee734).ts.keycxx . . $ GPU#key(f4fff0029955a25f).()] =cxx . . $ std/unordered_set#`operator=`(f9fceeb5a0eae059). {cxx . . $ std/initializer_list#initializer_list(ced63f7c635d850d).}; |
| 166 | ignored[cxx . . $ std/unordered_map#`operator[]`(4f10b6009f0ee734).ts.keycxx . . $ GPU#key(f4fff0029955a25f).()].emplacecxx . . $ std/unordered_set#emplace(422e73f5886d780d).(sensorid); |
| 167 | |
| 168 | ALLOW_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4337:9`!(sensorMock, ID()).LR_RETURNcxx . . $ `<external>/1068432606165018960/mock.hpp:4349:9`!(sensorid); |
| 169 | FORBID_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4339:9`!(sensorMock, update()); |
| 170 | ts.updateSensorscxx . . $ GPU#updateSensors(b9a76d75a3ae6a25).(ignored); |
| 171 | } |
| 172 | |
| 173 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Pre-init its controls") |
| 174 | { |
| 175 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(controlMock, preInit(trompeloeil::_)); |
| 176 | ts.preInitcxx . . $ GPU#preInit(151e9138769f295e).(ctlCmds); |
| 177 | } |
| 178 | |
| 179 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Post-init its controls") |
| 180 | { |
| 181 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(controlMock, postInit(trompeloeil::_)); |
| 182 | ts.postInitcxx . . $ GPU#postInit(151e9138769f295e).(ctlCmds); |
| 183 | } |
| 184 | |
| 185 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Init controls") |
| 186 | { |
| 187 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(controlMock, init()); |
| 188 | ts.initcxx . . $ GPU#init(49f6e7a06ebc5aa8).(); |
| 189 | } |
| 190 | |
| 191 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Only clear and sync controls when is active") |
| 192 | { |
| 193 | ALLOW_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4337:9`!(sensorMock, update()); |
| 194 | |
| 195 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(controlMock, clean(trompeloeil::_)); |
| 196 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(controlMock, sync(trompeloeil::_)); |
| 197 | ts.activatecxx . . $ GPU#activate(b45ddcbc8423892c).(true); |
| 198 | ts.synccxx . . $ GPU#sync(151e9138769f295e).(ctlCmds); |
| 199 | |
| 200 | FORBID_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4339:9`!(controlMock, clean(trompeloeil::_)); |
| 201 | FORBID_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4339:9`!(controlMock, sync(trompeloeil::_)); |
| 202 | ts.activatecxx . . $ GPU#activate(b45ddcbc8423892c).(false); |
| 203 | ts.synccxx . . $ GPU#sync(151e9138769f295e).(ctlCmds); |
| 204 | } |
| 205 | |
| 206 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Imports its state and controls") |
| 207 | { |
| 208 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(controlMock, importWith(trompeloeil::_)); |
| 209 | |
| 210 | ts.activatecxx . . $ GPU#activate(b45ddcbc8423892c).(true); |
| 211 | GPUImporterStubcxx . . $ Tests/GPU/GPUImporterStub# i; |
| 212 | ts.importWithcxx . . $ GPU#importWith(94eddebf9440278).(i); |
| 213 | |
| 214 | REQUIRE_FALSEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:128:11`!(ts.active()); |
| 215 | } |
| 216 | |
| 217 | SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Exports its state, sensors and controls") |
| 218 | { |
| 219 | GPUExporterMockcxx . . $ Tests/GPU/GPUExporterMock# e; |
| 220 | ALLOW_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4337:9`!(e, provideExporter(trompeloeil::_)).LR_RETURNcxx . . $ `<external>/1068432606165018960/mock.hpp:4349:9`!(e); |
| 221 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(e, takeActive(true)); |
| 222 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(e, takeInfo(trompeloeil::_)).LR_WITHcxx . . $ `<external>/1068432606165018960/mock.hpp:4345:9`!(&_1 == &infoStub); |
| 223 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(e, takeSensor(trompeloeil::_)).LR_WITHcxx . . $ `<external>/1068432606165018960/mock.hpp:4345:9`!(&_1 == &sensorMock); |
| 224 | |
| 225 | REQUIRE_CALLcxx . . $ `<external>/1068432606165018960/mock.hpp:4335:9`!(controlMock, exportWith(trompeloeil::_)); |
| 226 | |
| 227 | ts.activatecxx . . $ GPU#activate(b45ddcbc8423892c).(true); |
| 228 | ts.exportWithcxx . . $ GPU#exportWith(5b5c94ff60635419).(e); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | } // namespace Tests::GPU |