@@ -219,6 +219,39 @@ TEST_F(SysmanDeviceFixture, GivenSysfsAccessClassAndIntegerWhenCallingReadOnMult
219
219
delete tempSysfsAccess;
220
220
}
221
221
222
+ TEST_F (SysmanDeviceFixture, GivenValidMockMutexFsAccessWhenCallingReadThenMutexLockCounterMatchesNumberOfReadCalls) {
223
+ VariableBackup<decltype (NEO::SysCalls::sysCallsOpen)> mockOpen (&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
224
+ return 1 ;
225
+ });
226
+
227
+ VariableBackup<decltype (NEO::SysCalls::sysCallsPread)> mockPread (&NEO::SysCalls::sysCallsPread, [](int fd, void *buf, size_t count, off_t offset) -> ssize_t {
228
+ std::string value = " 123" ;
229
+ memcpy (buf, value.data (), value.size ());
230
+ return value.size ();
231
+ });
232
+
233
+ class MockMutexFsAccess : public L0 ::Sysman::FsAccessInterface {
234
+ public:
235
+ uint32_t mutexLockCounter = 0 ;
236
+ std::unique_lock<std::mutex> obtainMutex () override {
237
+ mutexLockCounter++;
238
+ std::unique_lock<std::mutex> mutexLock = L0::Sysman::FsAccessInterface::obtainMutex ();
239
+ EXPECT_TRUE (mutexLock.owns_lock ());
240
+ return mutexLock;
241
+ }
242
+ };
243
+ MockMutexFsAccess *tempFsAccess = new MockMutexFsAccess ();
244
+ std::string fileName = {};
245
+ uint32_t iVal32;
246
+ uint32_t testReadCount = 10 ;
247
+ for (uint32_t i = 0 ; i < testReadCount; i++) {
248
+ fileName = " mockfile" + std::to_string (i) + " .txt" ;
249
+ EXPECT_EQ (ZE_RESULT_SUCCESS, tempFsAccess->read (fileName, iVal32));
250
+ }
251
+ EXPECT_EQ (tempFsAccess->mutexLockCounter , testReadCount);
252
+ delete tempFsAccess;
253
+ }
254
+
222
255
TEST (FdCacheTest, GivenValidFdCacheWhenCallingGetFdOnSameFileThenVerifyCacheIsUpdatedProperly) {
223
256
224
257
class MockFdCache : public FdCache {
@@ -257,35 +290,6 @@ TEST(FdCacheTest, GivenValidFdCacheWhenCallingGetFdOnSameFileThenVerifyCacheIsUp
257
290
EXPECT_EQ (pFdCache->fdMap .end (), pFdCache->fdMap .find (" mockfile9.txt" ));
258
291
}
259
292
260
- TEST (FdCacheTest, GivenValidFdCacheWhenCallingGetFdOnMultipleFilesManyTimesThenVerifyCacheIsUpdatedCorrectly) {
261
-
262
- class MockFdCache : public FdCacheInterface {
263
- public:
264
- using FdCacheInterface::fdMap;
265
- };
266
-
267
- VariableBackup<decltype (NEO::SysCalls::sysCallsOpen)> mockOpen (&NEO::SysCalls::sysCallsOpen, [](const char *pathname, int flags) -> int {
268
- return 1 ;
269
- });
270
-
271
- std::unique_ptr<MockFdCache> pFdCache = std::make_unique<MockFdCache>();
272
- std::string fileName = {};
273
- for (auto i = 0 ; i < L0::Sysman::FdCacheInterface::maxSize; i++) {
274
- fileName = " mockfile" + std::to_string (i) + " .txt" ;
275
- int j = i + 1 ;
276
- while (j--) {
277
- EXPECT_LE (0 , pFdCache->getFd (fileName));
278
- }
279
- }
280
-
281
- // replace a least referred file and add new file
282
- fileName = " mockfile100.txt" ;
283
- EXPECT_LE (0 , pFdCache->getFd (fileName));
284
-
285
- // Verify cache doesn't have an element that is accessed less number of times.
286
- EXPECT_EQ (pFdCache->fdMap .end (), pFdCache->fdMap .find (" mockfile0.txt" ));
287
- }
288
-
289
293
TEST (FdCacheTest, GivenValidFdCacheWhenClearingCacheThenVerifyProperFdsAreClosedAndCacheIsUpdatedProperly) {
290
294
291
295
class MockFdCache : public FdCache {
0 commit comments