@@ -44,6 +44,7 @@ constexpr uint64_t expectedEnergyCounter = 123456785u;
4444constexpr uint32_t mockDefaultPowerLimitVal = 300000000 ;
4545constexpr uint32_t mockMaxPowerLimitVal = 490000000 ;
4646constexpr uint32_t mockMinPowerLimitVal = 10 ;
47+
4748const std::map<std::string, uint64_t > deviceKeyOffsetMapPower = {
4849 {" PACKAGE_ENERGY" , 0x400 },
4950 {" COMPUTE_TEMPERATURES" , 0x68 },
@@ -55,8 +56,15 @@ class PowerSysfsAccess : public SysfsAccess {};
5556template <>
5657struct Mock <PowerSysfsAccess> : public PowerSysfsAccess {
5758
58- ze_result_t getValStringHelper (const std::string file, std::string &val);
59- ze_result_t getValString (const std::string file, std::string &val) {
59+ std::vector<ze_result_t > mockReadReturnStatus{};
60+ std::vector<ze_result_t > mockWriteReturnStatus{};
61+ std::vector<ze_result_t > mockScanDirEntriesReturnStatus{};
62+ std::vector<uint64_t > mockReadUnsignedLongValue{};
63+ std::vector<uint32_t > mockReadUnsignedIntValue{};
64+ bool isRepeated = false ;
65+
66+ ze_result_t read (const std::string file, std::string &val) override {
67+
6068 ze_result_t result = ZE_RESULT_ERROR_UNKNOWN;
6169 if (file.compare (i915HwmonDir + " /" + " name" ) == 0 ) {
6270 val = " i915" ;
@@ -173,9 +181,22 @@ struct Mock<PowerSysfsAccess> : public PowerSysfsAccess {
173181 return ZE_RESULT_SUCCESS;
174182 }
175183
176- ze_result_t getValUnsignedLongHelper (const std::string file, uint64_t &val);
177- ze_result_t getValUnsignedLong (const std::string file, uint64_t &val) {
184+ ze_result_t read (const std::string file, uint64_t &val) override {
178185 ze_result_t result = ZE_RESULT_SUCCESS;
186+ if (!mockReadReturnStatus.empty ()) {
187+ result = mockReadReturnStatus.front ();
188+ if (!mockReadUnsignedLongValue.empty ()) {
189+ val = mockReadUnsignedLongValue.front ();
190+ }
191+ if (isRepeated != true ) {
192+ if (mockReadUnsignedLongValue.size () != 0 ) {
193+ mockReadUnsignedLongValue.erase (mockReadUnsignedLongValue.begin ());
194+ }
195+ mockReadReturnStatus.erase (mockReadReturnStatus.begin ());
196+ }
197+ return result;
198+ }
199+
179200 if (file.compare (i915HwmonDir + " /" + sustainedPowerLimitEnabled) == 0 ) {
180201 val = sustainedPowerLimitEnabledVal;
181202 } else if (file.compare (i915HwmonDir + " /" + sustainedPowerLimit) == 0 ) {
@@ -191,12 +212,25 @@ struct Mock<PowerSysfsAccess> : public PowerSysfsAccess {
191212 } else {
192213 result = ZE_RESULT_ERROR_NOT_AVAILABLE;
193214 }
194-
195215 return result;
196216 }
197217
198- ze_result_t getValUnsignedInt (const std::string file, uint32_t &val) {
218+ ze_result_t read (const std::string file, uint32_t &val) override {
199219 ze_result_t result = ZE_RESULT_SUCCESS;
220+ if (!mockReadReturnStatus.empty ()) {
221+ result = mockReadReturnStatus.front ();
222+ if (!mockReadUnsignedIntValue.empty ()) {
223+ val = mockReadUnsignedIntValue.front ();
224+ }
225+ if (isRepeated != true ) {
226+ if (mockReadUnsignedIntValue.size () != 0 ) {
227+ mockReadUnsignedIntValue.erase (mockReadUnsignedIntValue.begin ());
228+ }
229+ mockReadReturnStatus.erase (mockReadReturnStatus.begin ());
230+ }
231+ return result;
232+ }
233+
200234 if (file.compare (i915HwmonDir + " /" + defaultPowerLimit) == 0 ) {
201235 val = mockDefaultPowerLimitVal;
202236 } else if (file.compare (i915HwmonDir + " /" + maxPowerLimit) == 0 ) {
@@ -209,18 +243,16 @@ struct Mock<PowerSysfsAccess> : public PowerSysfsAccess {
209243 return result;
210244 }
211245
212- ze_result_t getValUnsignedIntMax (const std::string file, uint32_t & val) {
246+ ze_result_t write (const std::string file, const int val) override {
213247 ze_result_t result = ZE_RESULT_SUCCESS;
214- if (file.compare (i915HwmonDir + " /" + maxPowerLimit) == 0 ) {
215- val = std::numeric_limits<uint32_t >::max ();
216- } else {
217- result = ZE_RESULT_ERROR_NOT_AVAILABLE;
248+ if (!mockWriteReturnStatus.empty ()) {
249+ ze_result_t result = mockWriteReturnStatus.front ();
250+ if (isRepeated != true ) {
251+ mockWriteReturnStatus.erase (mockWriteReturnStatus.begin ());
252+ }
253+ return result;
218254 }
219- return result;
220- }
221255
222- ze_result_t setVal (const std::string file, const int val) {
223- ze_result_t result = ZE_RESULT_SUCCESS;
224256 if (file.compare (i915HwmonDir + " /" + sustainedPowerLimitEnabled) == 0 ) {
225257 sustainedPowerLimitEnabledVal = static_cast <uint64_t >(val);
226258 } else if (file.compare (i915HwmonDir + " /" + sustainedPowerLimit) == 0 ) {
@@ -234,24 +266,27 @@ struct Mock<PowerSysfsAccess> : public PowerSysfsAccess {
234266 } else {
235267 result = ZE_RESULT_ERROR_NOT_AVAILABLE;
236268 }
237-
238269 return result;
239270 }
240- ze_result_t getscanDirEntries (const std::string file, std::vector<std::string> &listOfEntries) {
271+
272+ ze_result_t scanDirEntries (const std::string file, std::vector<std::string> &listOfEntries) override {
273+ ze_result_t result = ZE_RESULT_ERROR_NOT_AVAILABLE;
274+ if (!mockScanDirEntriesReturnStatus.empty ()) {
275+ ze_result_t result = mockScanDirEntriesReturnStatus.front ();
276+ if (isRepeated != true ) {
277+ mockScanDirEntriesReturnStatus.erase (mockScanDirEntriesReturnStatus.begin ());
278+ }
279+ return result;
280+ }
281+
241282 if (file.compare (hwmonDir) == 0 ) {
242283 listOfEntries = listOfMockedHwmonDirs;
243- return ZE_RESULT_SUCCESS;
284+ result = ZE_RESULT_SUCCESS;
244285 }
245- return ZE_RESULT_ERROR_NOT_AVAILABLE ;
286+ return result ;
246287 }
247288
248289 Mock<PowerSysfsAccess>() = default ;
249-
250- MOCK_METHOD (ze_result_t , read, (const std::string file, uint64_t &val), (override ));
251- MOCK_METHOD (ze_result_t , read, (const std::string file, std::string &val), (override ));
252- MOCK_METHOD (ze_result_t , read, (const std::string file, uint32_t &val), (override ));
253- MOCK_METHOD (ze_result_t , write, (const std::string file, const int val), (override ));
254- MOCK_METHOD (ze_result_t , scanDirEntries, (const std::string file, std::vector<std::string> &listOfEntries), (override ));
255290};
256291
257292class PowerPmt : public PlatformMonitoringTech {
@@ -277,7 +312,6 @@ struct Mock<PowerPmt> : public PowerPmt {
277312 if (ZE_RESULT_SUCCESS != PlatformMonitoringTech::enumerateRootTelemIndex (pFsAccess, gpuUpstreamPortPath)) {
278313 return ;
279314 }
280-
281315 telemetryDeviceEntry = " /sys/class/intel_pmt/telem2/telem" ;
282316 }
283317};
@@ -286,7 +320,8 @@ class PowerFsAccess : public FsAccess {};
286320
287321template <>
288322struct Mock <PowerFsAccess> : public PowerFsAccess {
289- ze_result_t listDirectorySuccess (const std::string directory, std::vector<std::string> &listOfTelemNodes) {
323+
324+ ze_result_t listDirectory (const std::string directory, std::vector<std::string> &listOfTelemNodes) override {
290325 if (directory.compare (baseTelemSysFS) == 0 ) {
291326 listOfTelemNodes.push_back (" telem1" );
292327 listOfTelemNodes.push_back (" telem2" );
@@ -302,7 +337,7 @@ struct Mock<PowerFsAccess> : public PowerFsAccess {
302337 return ZE_RESULT_ERROR_NOT_AVAILABLE;
303338 }
304339
305- ze_result_t getRealPathSuccess (const std::string path, std::string &buf) {
340+ ze_result_t getRealPath (const std::string path, std::string &buf) override {
306341 if (path.compare (" /sys/class/intel_pmt/telem1" ) == 0 ) {
307342 buf = " /sys/devices/pci0000:89/0000:89:02.0/0000:86:00.0/0000:8b:02.0/0000:8e:00.1/pmt_telemetry.1.auto/intel_pmt/telem1" ;
308343 } else if (path.compare (" /sys/class/intel_pmt/telem2" ) == 0 ) {
@@ -316,16 +351,13 @@ struct Mock<PowerFsAccess> : public PowerFsAccess {
316351 } else {
317352 return ZE_RESULT_ERROR_NOT_AVAILABLE;
318353 }
319-
320354 return ZE_RESULT_SUCCESS;
321355 }
322356
323357 ze_result_t getRealPathFailure (const std::string path, std::string &buf) {
324358 return ZE_RESULT_ERROR_NOT_AVAILABLE;
325359 }
326360
327- MOCK_METHOD (ze_result_t , listDirectory, (const std::string path, std::vector<std::string> &list), (override ));
328- MOCK_METHOD (ze_result_t , getRealPath, (const std::string path, std::string &buf), (override ));
329361 Mock<PowerFsAccess>() = default ;
330362};
331363
@@ -357,20 +389,7 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture {
357389 pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess ;
358390 pSysfsAccess = std::make_unique<NiceMock<Mock<PowerSysfsAccess>>>();
359391 pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get ();
360- ON_CALL (*pFsAccess.get (), listDirectory (_, _))
361- .WillByDefault (::testing::Invoke (pFsAccess.get (), &Mock<PowerFsAccess>::listDirectorySuccess));
362- ON_CALL (*pFsAccess.get (), getRealPath (_, _))
363- .WillByDefault (::testing::Invoke (pFsAccess.get (), &Mock<PowerFsAccess>::getRealPathSuccess));
364- ON_CALL (*pSysfsAccess.get (), read (_, Matcher<std::string &>(_)))
365- .WillByDefault (::testing::Invoke (pSysfsAccess.get (), &Mock<PowerSysfsAccess>::getValString));
366- ON_CALL (*pSysfsAccess.get (), read (_, Matcher<uint64_t &>(_)))
367- .WillByDefault (::testing::Invoke (pSysfsAccess.get (), &Mock<PowerSysfsAccess>::getValUnsignedLong));
368- ON_CALL (*pSysfsAccess.get (), read (_, Matcher<uint32_t &>(_)))
369- .WillByDefault (::testing::Invoke (pSysfsAccess.get (), &Mock<PowerSysfsAccess>::getValUnsignedInt));
370- ON_CALL (*pSysfsAccess.get (), write (_, _))
371- .WillByDefault (::testing::Invoke (pSysfsAccess.get (), &Mock<PowerSysfsAccess>::setVal));
372- ON_CALL (*pSysfsAccess.get (), scanDirEntries (_, _))
373- .WillByDefault (::testing::Invoke (pSysfsAccess.get (), &Mock<PowerSysfsAccess>::getscanDirEntries));
392+
374393 uint32_t subDeviceCount = 0 ;
375394 Device::fromHandle (device->toHandle ())->getSubDevices (&subDeviceCount, nullptr );
376395 if (subDeviceCount == 0 ) {
@@ -434,20 +453,7 @@ class SysmanDevicePowerMultiDeviceFixture : public SysmanMultiDeviceFixture {
434453 pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess ;
435454 pSysfsAccess = std::make_unique<NiceMock<Mock<PowerSysfsAccess>>>();
436455 pLinuxSysmanImp->pSysfsAccess = pSysfsAccess.get ();
437- ON_CALL (*pFsAccess.get (), listDirectory (_, _))
438- .WillByDefault (::testing::Invoke (pFsAccess.get (), &Mock<PowerFsAccess>::listDirectorySuccess));
439- ON_CALL (*pFsAccess.get (), getRealPath (_, _))
440- .WillByDefault (::testing::Invoke (pFsAccess.get (), &Mock<PowerFsAccess>::getRealPathSuccess));
441- ON_CALL (*pSysfsAccess.get (), read (_, Matcher<std::string &>(_)))
442- .WillByDefault (::testing::Invoke (pSysfsAccess.get (), &Mock<PowerSysfsAccess>::getValString));
443- ON_CALL (*pSysfsAccess.get (), read (_, Matcher<uint64_t &>(_)))
444- .WillByDefault (::testing::Invoke (pSysfsAccess.get (), &Mock<PowerSysfsAccess>::getValUnsignedLong));
445- ON_CALL (*pSysfsAccess.get (), read (_, Matcher<uint32_t &>(_)))
446- .WillByDefault (::testing::Invoke (pSysfsAccess.get (), &Mock<PowerSysfsAccess>::getValUnsignedInt));
447- ON_CALL (*pSysfsAccess.get (), write (_, _))
448- .WillByDefault (::testing::Invoke (pSysfsAccess.get (), &Mock<PowerSysfsAccess>::setVal));
449- ON_CALL (*pSysfsAccess.get (), scanDirEntries (_, _))
450- .WillByDefault (::testing::Invoke (pSysfsAccess.get (), &Mock<PowerSysfsAccess>::getscanDirEntries));
456+
451457 uint32_t subDeviceCount = 0 ;
452458 Device::fromHandle (device->toHandle ())->getSubDevices (&subDeviceCount, nullptr );
453459 if (subDeviceCount == 0 ) {
@@ -490,4 +496,4 @@ class SysmanDevicePowerMultiDeviceFixture : public SysmanMultiDeviceFixture {
490496};
491497
492498} // namespace ult
493- } // namespace L0
499+ } // namespace L0
0 commit comments