Lines Matching defs:cache
24 /* A collection of unit tests for cache.c */
96 does_cache_contain(struct disk_cache *cache, const cache_key key)
100 result = disk_cache_get(cache, key, NULL);
111 cache_exists(struct disk_cache *cache)
116 if (!cache)
119 disk_cache_compute_key(cache, data, sizeof(data), key);
120 disk_cache_put(cache, key, data, sizeof(data), NULL);
121 disk_cache_wait_for_idle(cache);
122 void *result = disk_cache_get(cache, key, NULL);
128 #define CACHE_TEST_TMP "./cache-test-tmp"
133 struct disk_cache *cache;
140 cache = disk_cache_create("test", "make_check", 0);
141 EXPECT_EQ(cache, nullptr) << "disk_cache_create with MESA_SHADER_CACHE_DISABLE set";
150 cache = disk_cache_create("test", "make_check", 0);
151 EXPECT_EQ(cache, nullptr)
155 /* For remaining tests, ensure that the cache is enabled. */
160 * variables to test creation of cache in home directory.
165 cache = disk_cache_create("test", "make_check", 0);
166 EXPECT_NE(cache, nullptr) << "disk_cache_create with no environment variables";
168 disk_cache_destroy(cache);
171 /* Android doesn't try writing to disk (just calls the cache callbacks), so
178 setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1);
179 cache = disk_cache_create("test", "make_check", 0);
180 EXPECT_FALSE(cache_exists(cache))
188 disk_cache_destroy(cache);
190 cache = disk_cache_create("test", "make_check", 0);
191 EXPECT_TRUE(cache_exists(cache))
195 mem_ctx, "%s%s", CACHE_TEST_TMP "/xdg-cache-home/", cache_dir_name);
198 disk_cache_destroy(cache);
204 setenv("MESA_SHADER_CACHE_DIR", CACHE_TEST_TMP "/mesa-shader-cache-dir", 1);
205 cache = disk_cache_create("test", "make_check", 0);
206 EXPECT_FALSE(cache_exists(cache))
214 disk_cache_destroy(cache);
216 cache = disk_cache_create("test", "make_check", 0);
217 EXPECT_TRUE(cache_exists(cache)) << "disk_cache_create with MESA_SHADER_CACHE_DIR set";
220 mem_ctx, "%s%s", CACHE_TEST_TMP "/mesa-shader-cache-dir/", cache_dir_name);
223 disk_cache_destroy(cache);
229 struct disk_cache *cache;
244 cache = disk_cache_create("test", "make_check", 0);
246 disk_cache_compute_key(cache, blob, sizeof(blob), blob_key);
249 result = (char *) disk_cache_get(cache, blob_key, &size);
254 disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL);
257 disk_cache_wait_for_idle(cache);
259 result = (char *) disk_cache_get(cache, blob_key, &size);
266 disk_cache_compute_key(cache, string, sizeof(string), string_key);
267 disk_cache_put(cache, string_key, string, sizeof(string), NULL);
270 disk_cache_wait_for_idle(cache);
272 result = (char *) disk_cache_get(cache, string_key, &size);
278 /* Set the cache size to 1KB and add a 1KB item to force an eviction. */
279 disk_cache_destroy(cache);
285 cache = disk_cache_create("test", "make_check", 0);
292 * (with only three files in the cache), the probability is good
304 * directory as the original blob first written to the cache.
306 disk_cache_compute_key(cache, one_KB, 1024, one_KB_key);
309 disk_cache_put(cache, one_KB_key, one_KB, 1024, NULL);
314 disk_cache_wait_for_idle(cache);
316 result = (char *) disk_cache_get(cache, one_KB_key, &size);
323 * cache itesm were evicted.
327 if (does_cache_contain(cache, blob_key))
330 if (does_cache_contain(cache, string_key))
333 if (does_cache_contain(cache, one_KB_key)) {
345 disk_cache_destroy(cache);
348 cache = disk_cache_create("test", "make_check", 0);
350 disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL);
351 disk_cache_put(cache, string_key, string, sizeof(string), NULL);
354 disk_cache_wait_for_idle(cache);
357 if (does_cache_contain(cache, blob_key))
360 if (does_cache_contain(cache, string_key))
363 if (does_cache_contain(cache, one_KB_key))
371 disk_cache_compute_key(cache, one_MB, 1024 * 1024, one_MB_key);
374 disk_cache_put(cache, one_MB_key, one_MB, 1024 * 1024, NULL);
379 disk_cache_wait_for_idle(cache);
383 if (does_cache_contain(cache, blob_key))
386 if (does_cache_contain(cache, string_key))
389 if (does_cache_contain(cache, one_KB_key))
392 if (does_cache_contain(cache, one_MB_key)) {
401 disk_cache_destroy(cache);
407 struct disk_cache *cache;
422 cache = disk_cache_create("test", "make_check", 0);
425 result = disk_cache_has_key(cache, key_a);
429 disk_cache_put_key(cache, key_a);
430 result = disk_cache_has_key(cache, key_a);
433 disk_cache_put_key(cache, key_b);
434 result = disk_cache_has_key(cache, key_b);
440 disk_cache_put_key(cache, key_a_collide);
441 result = disk_cache_has_key(cache, key_a_collide);
442 EXPECT_EQ(result, 1) << "put_key of a colliding key lands in the cache";
444 result = disk_cache_has_key(cache, key_a);
445 EXPECT_EQ(result, 0) << "put_key of a colliding key evicts from the cache";
450 disk_cache_put_key(cache, key_a);
451 result = disk_cache_has_key(cache, key_a);
454 result = disk_cache_has_key(cache, key_a_collide);
457 disk_cache_destroy(cache);
460 /* To make sure we are not just using the inmemory cache index for the single
461 * file cache we test adding and retriving cache items between two different
462 * cache instances.
561 /* We skip testing cache size limit as the single file cache currently
562 * doesn't have any functionality to enforce cache size limits.