@@ -562,6 +562,10 @@ TEST_P(PersistentDeviceCodeCache, BasicEviction) {
562562 detail::PersistentDeviceCodeCache::putItemToDisc ({Dev}, {&Img}, {},
563563 BuildOptions, NativeProg);
564564
565+ std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath (
566+ Dev, {&Img}, {}, BuildOptions);
567+ size_t SizeOfOneEntry = (size_t )(detail::getDirectorySize (ItemDir));
568+
565569 detail::PersistentDeviceCodeCache::putItemToDisc ({Dev}, {&Img}, {},
566570 BuildOptions, NativeProg);
567571
@@ -573,35 +577,33 @@ TEST_P(PersistentDeviceCodeCache, BasicEviction) {
573577 {Dev}, {&Img}, {}, BuildOptions);
574578
575579 // Get the number of binary files in the cached item folder.
576- std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath (
577- Dev, {&Img}, {}, BuildOptions);
578580 auto BinFiles = getBinaryFileNames (ItemDir);
579-
580581 EXPECT_EQ (BinFiles.size (), static_cast <size_t >(3 ))
581582 << " Missing binary files. Eviction should not have happened." ;
582583
583- // Get Cache size and size of each entry. Set eviction threshold so that
584- // just one item is evicted.
585- size_t SizeOfOneEntry =
586- (size_t )(detail::getDirectorySize (CacheRoot, false )) + 10 ;
587-
588584 // Set SYCL_CACHE_MAX_SIZE.
589- SetDiskCacheEvictionEnv (std::to_string (SizeOfOneEntry).c_str ());
585+ SetDiskCacheEvictionEnv (std::to_string (3 * SizeOfOneEntry).c_str ());
590586
591- // Put 4th item to the cache. This should trigger eviction. Only the first
592- // item should be evicted.
587+ // Put 4th item to the cache. This should trigger eviction. Three of the
588+ // items should be evicted as we evict till the size of cache is less than
589+ // the half of cache size.
593590 detail::PersistentDeviceCodeCache::putItemToDisc ({Dev}, {&Img}, {},
594591 BuildOptions, NativeProg);
595592
596- // We should have three binary files: 0.bin, 2 .bin, 3.bin.
593+ // We should have two binary files: 0.bin, 3.bin.
597594 BinFiles = getBinaryFileNames (ItemDir);
598- EXPECT_EQ (BinFiles.size (), static_cast <size_t >(3 ))
595+ EXPECT_EQ (BinFiles.size (), static_cast <size_t >(1 ))
599596 << " Eviction failed. Wrong number of binary files in the cache." ;
600597
601- // Check that 1.bin was evicted.
602- for (const auto &File : BinFiles)
598+ // Check that 1.bin, 2.bin, and 0.bin was evicted.
599+ for (const auto &File : BinFiles) {
603600 EXPECT_NE (File, " 1.bin" )
604601 << " Eviction failed. 1.bin should have been evicted." ;
602+ EXPECT_NE (File, " 2.bin" )
603+ << " Eviction failed. 2.bin should have been evicted." ;
604+ EXPECT_NE (File, " 0.bin" )
605+ << " Eviction failed. 0.bin should have been evicted." ;
606+ }
605607
606608 ASSERT_NO_ERROR (llvm::sys::fs::remove_directories (ItemDir));
607609}
0 commit comments