Lines Matching full:cache
24 /* A collection of unit tests for cache.c */
103 does_cache_contain(struct disk_cache *cache, const cache_key key) in does_cache_contain() argument
107 result = disk_cache_get(cache, key, NULL); in does_cache_contain()
118 cache_exists(struct disk_cache *cache) in cache_exists() argument
123 if (!cache) in cache_exists()
126 disk_cache_compute_key(cache, data, sizeof(data), key); in cache_exists()
127 disk_cache_put(cache, key, data, sizeof(data), NULL); in cache_exists()
128 disk_cache_wait_for_idle(cache); in cache_exists()
129 void *result = disk_cache_get(cache, key, NULL); in cache_exists()
130 disk_cache_remove(cache, key); in cache_exists()
177 #define CACHE_TEST_TMP "./cache-test-tmp"
183 struct disk_cache *cache; in test_disk_cache_create() local
187 * MESA_SHADER_CACHE_DISABLE set to true, that disk_cache_create returns NO-OP cache. in test_disk_cache_create()
190 cache = disk_cache_create("test", driver_id, 0); in test_disk_cache_create()
191 … EXPECT_EQ(cache->type, DISK_CACHE_NONE) << "disk_cache_create with MESA_SHADER_CACHE_DISABLE set"; in test_disk_cache_create()
192 disk_cache_destroy(cache); in test_disk_cache_create()
198 * MESA_SHADER_CACHE_DISABLE set to nothing, disk_cache_create returns NO-OP cache. in test_disk_cache_create()
201 cache = disk_cache_create("test", driver_id, 0); in test_disk_cache_create()
202 EXPECT_EQ(cache->type, DISK_CACHE_NONE) in test_disk_cache_create()
205 disk_cache_destroy(cache); in test_disk_cache_create()
207 /* For remaining tests, ensure that the cache is enabled. */ in test_disk_cache_create()
212 * variables to test creation of cache in home directory. in test_disk_cache_create()
217 cache = disk_cache_create("test", driver_id, 0); in test_disk_cache_create()
218 EXPECT_NE(cache, nullptr) << "disk_cache_create with no environment variables"; in test_disk_cache_create()
220 disk_cache_destroy(cache); in test_disk_cache_create()
223 /* Android doesn't try writing to disk (just calls the cache callbacks), so in test_disk_cache_create()
230 setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1); in test_disk_cache_create()
231 cache = disk_cache_create("test", driver_id, 0); in test_disk_cache_create()
232 EXPECT_TRUE(cache_exists(cache)) in test_disk_cache_create()
236 mem_ctx, "%s%s", CACHE_TEST_TMP "/xdg-cache-home/", cache_dir_name); in test_disk_cache_create()
239 disk_cache_destroy(cache); in test_disk_cache_create()
245 setenv("MESA_SHADER_CACHE_DIR", CACHE_TEST_TMP "/mesa-shader-cache-dir", 1); in test_disk_cache_create()
246 cache = disk_cache_create("test", driver_id, 0); in test_disk_cache_create()
247 EXPECT_TRUE(cache_exists(cache)) in test_disk_cache_create()
250 disk_cache_destroy(cache); in test_disk_cache_create()
260 cache = disk_cache_create("test", driver_id, 0); in test_disk_cache_create()
261 …EXPECT_TRUE(cache_exists(cache)) << "disk_cache_create with MESA_SHADER_CACHE_DIR set with existin… in test_disk_cache_create()
264 mem_ctx, "%s%s", CACHE_TEST_TMP "/mesa-shader-cache-dir/", cache_dir_name); in test_disk_cache_create()
267 disk_cache_destroy(cache); in test_disk_cache_create()
273 struct disk_cache *cache; in test_put_and_get() local
288 cache = disk_cache_create("test", driver_id, 0); in test_put_and_get()
290 disk_cache_compute_key(cache, blob, sizeof(blob), blob_key); in test_put_and_get()
293 result = (char *) disk_cache_get(cache, blob_key, &size); in test_put_and_get()
298 disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL); in test_put_and_get()
301 disk_cache_wait_for_idle(cache); in test_put_and_get()
303 result = (char *) disk_cache_get(cache, blob_key, &size); in test_put_and_get()
310 disk_cache_compute_key(cache, string, sizeof(string), string_key); in test_put_and_get()
311 disk_cache_put(cache, string_key, string, sizeof(string), NULL); in test_put_and_get()
314 disk_cache_wait_for_idle(cache); in test_put_and_get()
316 result = (char *) disk_cache_get(cache, string_key, &size); in test_put_and_get()
322 /* Set the cache size to 1KB and add a 1KB item to force an eviction. */ in test_put_and_get()
323 disk_cache_destroy(cache); in test_put_and_get()
329 cache = disk_cache_create("test", driver_id, 0); in test_put_and_get()
336 * (with only three files in the cache), the probability is good in test_put_and_get()
348 * directory as the original blob first written to the cache. in test_put_and_get()
350 disk_cache_compute_key(cache, one_KB, 1024, one_KB_key); in test_put_and_get()
353 disk_cache_put(cache, one_KB_key, one_KB, 1024, NULL); in test_put_and_get()
358 disk_cache_wait_for_idle(cache); in test_put_and_get()
360 result = (char *) disk_cache_get(cache, one_KB_key, &size); in test_put_and_get()
367 * cache itesm were evicted. in test_put_and_get()
371 if (does_cache_contain(cache, blob_key)) in test_put_and_get()
374 if (does_cache_contain(cache, string_key)) in test_put_and_get()
377 if (does_cache_contain(cache, one_KB_key)) { in test_put_and_get()
389 disk_cache_destroy(cache); in test_put_and_get()
392 cache = disk_cache_create("test", driver_id, 0); in test_put_and_get()
394 disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL); in test_put_and_get()
395 disk_cache_put(cache, string_key, string, sizeof(string), NULL); in test_put_and_get()
398 disk_cache_wait_for_idle(cache); in test_put_and_get()
401 if (does_cache_contain(cache, blob_key)) in test_put_and_get()
404 if (does_cache_contain(cache, string_key)) in test_put_and_get()
407 if (does_cache_contain(cache, one_KB_key)) in test_put_and_get()
415 disk_cache_compute_key(cache, one_MB, 1024 * 1024, one_MB_key); in test_put_and_get()
418 disk_cache_put(cache, one_MB_key, one_MB, 1024 * 1024, NULL); in test_put_and_get()
423 disk_cache_wait_for_idle(cache); in test_put_and_get()
427 if (does_cache_contain(cache, blob_key)) in test_put_and_get()
430 if (does_cache_contain(cache, string_key)) in test_put_and_get()
433 if (does_cache_contain(cache, one_KB_key)) in test_put_and_get()
436 if (does_cache_contain(cache, one_MB_key)) { in test_put_and_get()
445 disk_cache_destroy(cache); in test_put_and_get()
451 struct disk_cache *cache; in test_put_key_and_get_key() local
466 cache = disk_cache_create("test", driver_id, 0); in test_put_key_and_get_key()
469 result = disk_cache_has_key(cache, key_a); in test_put_key_and_get_key()
473 disk_cache_put_key(cache, key_a); in test_put_key_and_get_key()
474 result = disk_cache_has_key(cache, key_a); in test_put_key_and_get_key()
477 disk_cache_put_key(cache, key_b); in test_put_key_and_get_key()
478 result = disk_cache_has_key(cache, key_b); in test_put_key_and_get_key()
484 disk_cache_put_key(cache, key_a_collide); in test_put_key_and_get_key()
485 result = disk_cache_has_key(cache, key_a_collide); in test_put_key_and_get_key()
486 EXPECT_EQ(result, 1) << "put_key of a colliding key lands in the cache"; in test_put_key_and_get_key()
488 result = disk_cache_has_key(cache, key_a); in test_put_key_and_get_key()
489 EXPECT_EQ(result, 0) << "put_key of a colliding key evicts from the cache"; in test_put_key_and_get_key()
494 disk_cache_put_key(cache, key_a); in test_put_key_and_get_key()
495 result = disk_cache_has_key(cache, key_a); in test_put_key_and_get_key()
498 result = disk_cache_has_key(cache, key_a_collide); in test_put_key_and_get_key()
501 disk_cache_destroy(cache); in test_put_key_and_get_key()
504 /* To make sure we are not just using the inmemory cache index for the single
505 * file cache we test adding and retriving cache items between two different
506 * cache instances.
571 struct disk_cache *cache[2]; in test_put_and_get_between_instances_with_eviction() local
584 cache[0] = disk_cache_create("test_between_instances_with_eviction", driver_id, 0); in test_put_and_get_between_instances_with_eviction()
585 cache[1] = disk_cache_create("test_between_instances_with_eviction", driver_id, 0); in test_put_and_get_between_instances_with_eviction()
591 disk_cache_put(cache[0], two_KB_key, two_KB, sizeof(two_KB), NULL); in test_put_and_get_between_instances_with_eviction()
592 disk_cache_wait_for_idle(cache[0]); in test_put_and_get_between_instances_with_eviction()
597 size_big -= cache[0]->driver_keys_blob_size; in test_put_and_get_between_instances_with_eviction()
604 disk_cache_compute_key(cache[0], big, size_big, big_key[i]); in test_put_and_get_between_instances_with_eviction()
605 disk_cache_put(cache[0], big_key[i], big, size_big, NULL); in test_put_and_get_between_instances_with_eviction()
606 disk_cache_wait_for_idle(cache[0]); in test_put_and_get_between_instances_with_eviction()
608 result = (char *) disk_cache_get(cache[0], big_key[i], &size); in test_put_and_get_between_instances_with_eviction()
619 size_small -= cache[1]->driver_keys_blob_size; in test_put_and_get_between_instances_with_eviction()
626 disk_cache_compute_key(cache[1], small, size_small, small_key[i]); in test_put_and_get_between_instances_with_eviction()
627 disk_cache_put(cache[1], small_key[i], small, size_small, NULL); in test_put_and_get_between_instances_with_eviction()
628 disk_cache_wait_for_idle(cache[1]); in test_put_and_get_between_instances_with_eviction()
631 * At first we added two 1000KB entries to cache[0]. Now, when first in test_put_and_get_between_instances_with_eviction()
635 * All four 256KB entries stay in the cache. in test_put_and_get_between_instances_with_eviction()
637 for (k = 0; k < ARRAY_SIZE(cache); k++) { in test_put_and_get_between_instances_with_eviction()
639 result = (char *) disk_cache_get(cache[k], big_key[0], &size); in test_put_and_get_between_instances_with_eviction()
644 result = (char *) disk_cache_get(cache[k], big_key[1], &size); in test_put_and_get_between_instances_with_eviction()
649 result = (char *) disk_cache_get(cache[k], small_key[n], &size); in test_put_and_get_between_instances_with_eviction()
654 result = (char *) disk_cache_get(cache[k], small_key[n], &size); in test_put_and_get_between_instances_with_eviction()
669 disk_cache_compute_key(cache[0], small, size_small, small_key2); in test_put_and_get_between_instances_with_eviction()
670 disk_cache_put(cache[0], small_key2, small, size_small, NULL); in test_put_and_get_between_instances_with_eviction()
671 disk_cache_wait_for_idle(cache[0]); in test_put_and_get_between_instances_with_eviction()
675 for (k = 0; k < ARRAY_SIZE(cache); k++) { in test_put_and_get_between_instances_with_eviction()
676 result = (char *) disk_cache_get(cache[k], small_key2, &size); in test_put_and_get_between_instances_with_eviction()
682 for (i = 0, k = 0; k < ARRAY_SIZE(cache); k++) { in test_put_and_get_between_instances_with_eviction()
684 result = (char *) disk_cache_get(cache[k], small_key[n], &size); in test_put_and_get_between_instances_with_eviction()
693 disk_cache_destroy(cache[0]); in test_put_and_get_between_instances_with_eviction()
694 disk_cache_destroy(cache[1]); in test_put_and_get_between_instances_with_eviction()
702 struct disk_cache *cache; in test_put_big_sized_entry_to_empty_cache() local
711 cache = disk_cache_create("test", driver_id, 0); in test_put_big_sized_entry_to_empty_cache()
713 disk_cache_compute_key(cache, blob, sizeof(blob), blob_key); in test_put_big_sized_entry_to_empty_cache()
715 disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL); in test_put_big_sized_entry_to_empty_cache()
716 disk_cache_wait_for_idle(cache); in test_put_big_sized_entry_to_empty_cache()
718 result = (char *) disk_cache_get(cache, blob_key, &size); in test_put_big_sized_entry_to_empty_cache()
719 EXPECT_NE(result, nullptr) << "disk_cache_get(cache) with existing item (pointer)"; in test_put_big_sized_entry_to_empty_cache()
720 EXPECT_EQ(size, sizeof(blob)) << "disk_cache_get of(cache) existing item (size)"; in test_put_big_sized_entry_to_empty_cache()
724 disk_cache_destroy(cache); in test_put_big_sized_entry_to_empty_cache()
728 class Cache : public ::testing::Test { class
732 Cache() { in Cache() function in Cache
735 ~Cache() { in ~Cache()
740 TEST_F(Cache, MultiFile) in TEST_F() argument
775 TEST_F(Cache, SingleFile) in TEST_F() argument
794 /* We skip testing cache size limit as the single file cache currently in TEST_F()
795 * doesn't have any functionality to enforce cache size limits. in TEST_F()
815 TEST_F(Cache, Database) in TEST_F() argument
826 /* We skip testing cache size limit as the single file cache compresses in TEST_F()
827 * data much better than the multi-file cache, which results in the in TEST_F()
828 * failing tests of the cache eviction function. We we will test the in TEST_F()
855 TEST_F(Cache, Combined) in TEST_F() argument
880 /* Enable Fossilize read-write cache. */ in TEST_F()
885 /* Create Fossilize writable cache. */ in TEST_F()
897 /* Put blob entry to the cache. */ in TEST_F()
918 /* Disable Fossilize read-write cache. */ in TEST_F()
921 /* Set up Fossilize read-only cache. */ in TEST_F()
925 /* Create FOZ cache that fetches the RO cache. Note that this produces in TEST_F()
926 * empty RW cache files. */ in TEST_F()
939 /* Remove empty FOZ RW cache files created above. We only need RO cache. */ in TEST_F()
946 /* Create MESA-DB cache with enabled retrieval from the read-only in TEST_F()
947 * cache. */ in TEST_F()
951 /* Dummy entry must not present in any of the caches. Foz cache in TEST_F()
952 * reloads index if cache entry is missing. This is a sanity-check in TEST_F()
954 * FOZ RW cache. */ in TEST_F()
960 * read-only cache. */ in TEST_F()
971 /* Put blob2 entry to the cache. */ in TEST_F()
976 * read-write cache. */ in TEST_F()
984 /* Disable read-only cache. */ in TEST_F()
987 /* Create MESA-DB cache with disabled retrieval from the in TEST_F()
988 * read-only cache. */ in TEST_F()
992 * MESA-DB cache. */ in TEST_F()
1000 /* Create MESA-DB cache with disabled retrieval from the read-only in TEST_F()
1001 * cache. */ in TEST_F()
1004 /* Blob entry must not present in the cache because we disable the in TEST_F()
1005 * read-only cache. */ in TEST_F()
1012 /* Create default multi-file cache. */ in TEST_F()
1015 /* Enable read-only cache. */ in TEST_F()
1018 /* Create multi-file cache with enabled retrieval from the in TEST_F()
1019 * read-only cache. */ in TEST_F()
1024 * read-only cache. */ in TEST_F()
1035 /* Put blob2 entry to the cache. */ in TEST_F()
1040 * read-write cache. */ in TEST_F()
1048 /* Disable read-only cache. */ in TEST_F()
1052 /* Create multi-file cache with disabled retrieval from the in TEST_F()
1053 * read-only cache. */ in TEST_F()
1056 /* Blob entry must not present in the cache because we disabled the in TEST_F()
1057 * read-only cache. */ in TEST_F()
1063 * read-write cache. */ in TEST_F()
1078 TEST_F(Cache, List) in TEST_F() argument
1105 /* Create Fossilize writable cache. */ in TEST_F()
1117 /* Put blob entry to the cache. */ in TEST_F()
1148 /* Create Fossilize writable cache. */ in TEST_F()
1166 /* Create Fossilize writable cache. */ in TEST_F()
1199 /* Create Fossilize writable cache. */ in TEST_F()
1254 struct disk_cache *cache = disk_cache_create("test", driver_id, 0); in test_multipart_eviction() local
1259 entry_file_size -= cache->driver_keys_blob_size; in test_multipart_eviction()
1263 * 1. Allocate 3KB cache in 3 parts, each part is 1KB in test_multipart_eviction()
1264 * 2. Fill up cache with six 512K entries in test_multipart_eviction()
1266 * of the first two cache entries in test_multipart_eviction()
1272 /* Fill up cache with six 512K entries. */ in test_multipart_eviction()
1276 disk_cache_compute_key(cache, blobs[i], entry_file_size, keys[i]); in test_multipart_eviction()
1277 disk_cache_put(cache, keys[i], blobs[i], entry_file_size, NULL); in test_multipart_eviction()
1278 disk_cache_wait_for_idle(cache); in test_multipart_eviction()
1280 result = (char *) disk_cache_get(cache, keys[i], &size); in test_multipart_eviction()
1285 /* Ensure that cache entries will have distinct last_access_time in test_multipart_eviction()
1294 result = (char *) disk_cache_get(cache, keys[i], &size); in test_multipart_eviction()
1302 disk_cache_compute_key(cache, blobs[6], entry_file_size, keys[6]); in test_multipart_eviction()
1303 disk_cache_put(cache, keys[6], blobs[6], entry_file_size, NULL); in test_multipart_eviction()
1304 disk_cache_wait_for_idle(cache); in test_multipart_eviction()
1308 result = (char *) disk_cache_get(cache, keys[i], &size); in test_multipart_eviction()
1318 disk_cache_destroy(cache); in test_multipart_eviction()
1321 TEST_F(Cache, DatabaseMultipartEviction) in TEST_F() argument
1344 struct disk_cache *cache; in test_put_and_get_disabled() local
1350 cache = disk_cache_create("test", driver_id, 0); in test_put_and_get_disabled()
1352 disk_cache_compute_key(cache, blob, sizeof(blob), blob_key); in test_put_and_get_disabled()
1355 result = (char *) disk_cache_get(cache, blob_key, &size); in test_put_and_get_disabled()
1360 disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL); in test_put_and_get_disabled()
1363 disk_cache_wait_for_idle(cache); in test_put_and_get_disabled()
1365 result = (char *) disk_cache_get(cache, blob_key, &size); in test_put_and_get_disabled()
1369 disk_cache_destroy(cache); in test_put_and_get_disabled()
1372 TEST_F(Cache, Disabled) in TEST_F() argument
1401 TEST_F(Cache, DoNotDeleteNewCache) in TEST_F() argument
1432 TEST_F(Cache, DoNotDeleteCacheWithNewMarker) in TEST_F() argument
1470 TEST_F(Cache, DeleteOldCache) in TEST_F() argument