@@ -44,6 +44,7 @@ constexpr uint64_t expectedEnergyCounter = 123456785u;
44
44
constexpr uint32_t mockDefaultPowerLimitVal = 300000000 ;
45
45
constexpr uint32_t mockMaxPowerLimitVal = 490000000 ;
46
46
constexpr uint32_t mockMinPowerLimitVal = 10 ;
47
+
47
48
const std::map<std::string, uint64_t > deviceKeyOffsetMapPower = {
48
49
{" PACKAGE_ENERGY" , 0x400 },
49
50
{" COMPUTE_TEMPERATURES" , 0x68 },
@@ -55,8 +56,15 @@ class PowerSysfsAccess : public SysfsAccess {};
55
56
template <>
56
57
struct Mock <PowerSysfsAccess> : public PowerSysfsAccess {
57
58
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
+
60
68
ze_result_t result = ZE_RESULT_ERROR_UNKNOWN;
61
69
if (file.compare (i915HwmonDir + " /" + " name" ) == 0 ) {
62
70
val = " i915" ;
@@ -173,9 +181,22 @@ struct Mock<PowerSysfsAccess> : public PowerSysfsAccess {
173
181
return ZE_RESULT_SUCCESS;
174
182
}
175
183
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 {
178
185
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
+
179
200
if (file.compare (i915HwmonDir + " /" + sustainedPowerLimitEnabled) == 0 ) {
180
201
val = sustainedPowerLimitEnabledVal;
181
202
} else if (file.compare (i915HwmonDir + " /" + sustainedPowerLimit) == 0 ) {
@@ -191,12 +212,25 @@ struct Mock<PowerSysfsAccess> : public PowerSysfsAccess {
191
212
} else {
192
213
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
193
214
}
194
-
195
215
return result;
196
216
}
197
217
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 {
199
219
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
+
200
234
if (file.compare (i915HwmonDir + " /" + defaultPowerLimit) == 0 ) {
201
235
val = mockDefaultPowerLimitVal;
202
236
} else if (file.compare (i915HwmonDir + " /" + maxPowerLimit) == 0 ) {
@@ -209,18 +243,16 @@ struct Mock<PowerSysfsAccess> : public PowerSysfsAccess {
209
243
return result;
210
244
}
211
245
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 {
213
247
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;
218
254
}
219
- return result;
220
- }
221
255
222
- ze_result_t setVal (const std::string file, const int val) {
223
- ze_result_t result = ZE_RESULT_SUCCESS;
224
256
if (file.compare (i915HwmonDir + " /" + sustainedPowerLimitEnabled) == 0 ) {
225
257
sustainedPowerLimitEnabledVal = static_cast <uint64_t >(val);
226
258
} else if (file.compare (i915HwmonDir + " /" + sustainedPowerLimit) == 0 ) {
@@ -234,24 +266,27 @@ struct Mock<PowerSysfsAccess> : public PowerSysfsAccess {
234
266
} else {
235
267
result = ZE_RESULT_ERROR_NOT_AVAILABLE;
236
268
}
237
-
238
269
return result;
239
270
}
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
+
241
282
if (file.compare (hwmonDir) == 0 ) {
242
283
listOfEntries = listOfMockedHwmonDirs;
243
- return ZE_RESULT_SUCCESS;
284
+ result = ZE_RESULT_SUCCESS;
244
285
}
245
- return ZE_RESULT_ERROR_NOT_AVAILABLE ;
286
+ return result ;
246
287
}
247
288
248
289
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 ));
255
290
};
256
291
257
292
class PowerPmt : public PlatformMonitoringTech {
@@ -277,7 +312,6 @@ struct Mock<PowerPmt> : public PowerPmt {
277
312
if (ZE_RESULT_SUCCESS != PlatformMonitoringTech::enumerateRootTelemIndex (pFsAccess, gpuUpstreamPortPath)) {
278
313
return ;
279
314
}
280
-
281
315
telemetryDeviceEntry = " /sys/class/intel_pmt/telem2/telem" ;
282
316
}
283
317
};
@@ -286,7 +320,8 @@ class PowerFsAccess : public FsAccess {};
286
320
287
321
template <>
288
322
struct 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 {
290
325
if (directory.compare (baseTelemSysFS) == 0 ) {
291
326
listOfTelemNodes.push_back (" telem1" );
292
327
listOfTelemNodes.push_back (" telem2" );
@@ -302,7 +337,7 @@ struct Mock<PowerFsAccess> : public PowerFsAccess {
302
337
return ZE_RESULT_ERROR_NOT_AVAILABLE;
303
338
}
304
339
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 {
306
341
if (path.compare (" /sys/class/intel_pmt/telem1" ) == 0 ) {
307
342
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" ;
308
343
} else if (path.compare (" /sys/class/intel_pmt/telem2" ) == 0 ) {
@@ -316,16 +351,13 @@ struct Mock<PowerFsAccess> : public PowerFsAccess {
316
351
} else {
317
352
return ZE_RESULT_ERROR_NOT_AVAILABLE;
318
353
}
319
-
320
354
return ZE_RESULT_SUCCESS;
321
355
}
322
356
323
357
ze_result_t getRealPathFailure (const std::string path, std::string &buf) {
324
358
return ZE_RESULT_ERROR_NOT_AVAILABLE;
325
359
}
326
360
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 ));
329
361
Mock<PowerFsAccess>() = default ;
330
362
};
331
363
@@ -357,20 +389,7 @@ class SysmanDevicePowerFixture : public SysmanDeviceFixture {
357
389
pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess ;
358
390
pSysfsAccess = std::make_unique<NiceMock<Mock<PowerSysfsAccess>>>();
359
391
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
+
374
393
uint32_t subDeviceCount = 0 ;
375
394
Device::fromHandle (device->toHandle ())->getSubDevices (&subDeviceCount, nullptr );
376
395
if (subDeviceCount == 0 ) {
@@ -434,20 +453,7 @@ class SysmanDevicePowerMultiDeviceFixture : public SysmanMultiDeviceFixture {
434
453
pSysfsAccessOld = pLinuxSysmanImp->pSysfsAccess ;
435
454
pSysfsAccess = std::make_unique<NiceMock<Mock<PowerSysfsAccess>>>();
436
455
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
+
451
457
uint32_t subDeviceCount = 0 ;
452
458
Device::fromHandle (device->toHandle ())->getSubDevices (&subDeviceCount, nullptr );
453
459
if (subDeviceCount == 0 ) {
@@ -490,4 +496,4 @@ class SysmanDevicePowerMultiDeviceFixture : public SysmanMultiDeviceFixture {
490
496
};
491
497
492
498
} // namespace ult
493
- } // namespace L0
499
+ } // namespace L0
0 commit comments