|
1 | 1 | /*
|
2 |
| - * Copyright (C) 2020-2023 Intel Corporation |
| 2 | + * Copyright (C) 2020-2024 Intel Corporation |
3 | 3 | *
|
4 | 4 | * SPDX-License-Identifier: MIT
|
5 | 5 | *
|
@@ -257,6 +257,35 @@ TEST(FdCacheTest, GivenValidFdCacheWhenCallingGetFdOnSameFileThenVerifyCacheIsUp
|
257 | 257 | EXPECT_EQ(pFdCache->fdMap.end(), pFdCache->fdMap.find("mockfile9.txt"));
|
258 | 258 | }
|
259 | 259 |
|
| 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 | + |
260 | 289 | TEST(FdCacheTest, GivenValidFdCacheWhenClearingCacheThenVerifyProperFdsAreClosedAndCacheIsUpdatedProperly) {
|
261 | 290 |
|
262 | 291 | class MockFdCache : public FdCache {
|
|
0 commit comments