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