Lines Matching full:cache
24 /* A collection of unit tests for cache.c */
150 #define CACHE_TEST_TMP "./cache-test-tmp"
155 struct disk_cache *cache; in test_disk_cache_create() local
162 cache = disk_cache_create("test", "make_check", 0); in test_disk_cache_create()
163 expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DISABLE set"); in test_disk_cache_create()
168 * variables to test creation of cache in home directory. in test_disk_cache_create()
173 cache = disk_cache_create("test", "make_check", 0); in test_disk_cache_create()
174 expect_non_null(cache, "disk_cache_create with no environment variables"); in test_disk_cache_create()
176 disk_cache_destroy(cache); in test_disk_cache_create()
179 setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1); in test_disk_cache_create()
180 cache = disk_cache_create("test", "make_check", 0); in test_disk_cache_create()
181 expect_null(cache, "disk_cache_create with XDG_CACHE_HOME set with" in test_disk_cache_create()
185 cache = disk_cache_create("test", "make_check", 0); in test_disk_cache_create()
186 expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME set"); in test_disk_cache_create()
188 check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/" in test_disk_cache_create()
191 disk_cache_destroy(cache); in test_disk_cache_create()
197 setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1); in test_disk_cache_create()
198 cache = disk_cache_create("test", "make_check", 0); in test_disk_cache_create()
199 expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set with" in test_disk_cache_create()
203 cache = disk_cache_create("test", "make_check", 0); in test_disk_cache_create()
204 expect_non_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set"); in test_disk_cache_create()
206 check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/" in test_disk_cache_create()
209 disk_cache_destroy(cache); in test_disk_cache_create()
213 does_cache_contain(struct disk_cache *cache, const cache_key key) in does_cache_contain() argument
217 result = disk_cache_get(cache, key, NULL); in does_cache_contain()
228 wait_until_file_written(struct disk_cache *cache, const cache_key key) in wait_until_file_written() argument
239 if (does_cache_contain(cache, key)) { in wait_until_file_written()
250 struct disk_cache *cache; in test_put_and_get() local
261 cache = disk_cache_create("test", "make_check", 0); in test_put_and_get()
263 disk_cache_compute_key(cache, blob, sizeof(blob), blob_key); in test_put_and_get()
266 result = disk_cache_get(cache, blob_key, &size); in test_put_and_get()
271 disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL); in test_put_and_get()
276 wait_until_file_written(cache, blob_key); in test_put_and_get()
278 result = disk_cache_get(cache, blob_key, &size); in test_put_and_get()
285 disk_cache_compute_key(cache, string, sizeof(string), string_key); in test_put_and_get()
286 disk_cache_put(cache, string_key, string, sizeof(string), NULL); in test_put_and_get()
291 wait_until_file_written(cache, string_key); in test_put_and_get()
293 result = disk_cache_get(cache, string_key, &size); in test_put_and_get()
299 /* Set the cache size to 1KB and add a 1KB item to force an eviction. */ in test_put_and_get()
300 disk_cache_destroy(cache); in test_put_and_get()
303 cache = disk_cache_create("test", "make_check", 0); in test_put_and_get()
310 * (with only three files in the cache), the probability is good in test_put_and_get()
322 * directory as the original blob first written to the cache. in test_put_and_get()
324 disk_cache_compute_key(cache, one_KB, 1024, one_KB_key); in test_put_and_get()
327 disk_cache_put(cache, one_KB_key, one_KB, 1024, NULL); in test_put_and_get()
334 wait_until_file_written(cache, one_KB_key); in test_put_and_get()
336 result = disk_cache_get(cache, one_KB_key, &size); in test_put_and_get()
343 * cache itesm were evicted. in test_put_and_get()
347 if (does_cache_contain(cache, blob_key)) in test_put_and_get()
350 if (does_cache_contain(cache, string_key)) in test_put_and_get()
353 if (does_cache_contain(cache, one_KB_key)) { in test_put_and_get()
365 disk_cache_destroy(cache); in test_put_and_get()
368 cache = disk_cache_create("test", "make_check", 0); in test_put_and_get()
370 disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL); in test_put_and_get()
371 disk_cache_put(cache, string_key, string, sizeof(string), NULL); in test_put_and_get()
376 wait_until_file_written(cache, blob_key); in test_put_and_get()
377 wait_until_file_written(cache, string_key); in test_put_and_get()
380 if (does_cache_contain(cache, blob_key)) in test_put_and_get()
383 if (does_cache_contain(cache, string_key)) in test_put_and_get()
386 if (does_cache_contain(cache, one_KB_key)) in test_put_and_get()
394 disk_cache_compute_key(cache, one_MB, 1024 * 1024, one_MB_key); in test_put_and_get()
397 disk_cache_put(cache, one_MB_key, one_MB, 1024 * 1024, NULL); in test_put_and_get()
404 wait_until_file_written(cache, one_MB_key); in test_put_and_get()
408 if (does_cache_contain(cache, blob_key)) in test_put_and_get()
411 if (does_cache_contain(cache, string_key)) in test_put_and_get()
414 if (does_cache_contain(cache, one_KB_key)) in test_put_and_get()
417 if (does_cache_contain(cache, one_MB_key)) { in test_put_and_get()
426 disk_cache_destroy(cache); in test_put_and_get()
432 struct disk_cache *cache; in test_put_key_and_get_key() local
443 cache = disk_cache_create("test", "make_check", 0); in test_put_key_and_get_key()
446 result = disk_cache_has_key(cache, key_a); in test_put_key_and_get_key()
450 disk_cache_put_key(cache, key_a); in test_put_key_and_get_key()
451 result = disk_cache_has_key(cache, key_a); in test_put_key_and_get_key()
454 disk_cache_put_key(cache, key_b); in test_put_key_and_get_key()
455 result = disk_cache_has_key(cache, key_b); in test_put_key_and_get_key()
461 disk_cache_put_key(cache, key_a_collide); in test_put_key_and_get_key()
462 result = disk_cache_has_key(cache, key_a_collide); in test_put_key_and_get_key()
463 expect_equal(result, 1, "put_key of a colliding key lands in the cache"); in test_put_key_and_get_key()
465 result = disk_cache_has_key(cache, key_a); in test_put_key_and_get_key()
466 expect_equal(result, 0, "put_key of a colliding key evicts from the cache"); in test_put_key_and_get_key()
471 disk_cache_put_key(cache, key_a); in test_put_key_and_get_key()
472 result = disk_cache_has_key(cache, key_a); in test_put_key_and_get_key()
475 result = disk_cache_has_key(cache, key_a_collide); in test_put_key_and_get_key()
478 disk_cache_destroy(cache); in test_put_key_and_get_key()