#define CACHE_TEST_TMP "./cache-test-tmp"
static void
-test_disk_cache_create(void)
+test_disk_cache_create(const char *cache_dir_name)
{
struct disk_cache *cache;
int err;
expect_true(cache_exists(cache), "disk_cache_create with XDG_CACHE_HOME "
"set");
- check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/"
- CACHE_DIR_NAME);
+ char *path;
+ asprintf(&path, "%s%s", CACHE_TEST_TMP "/xdg-cache-home/", cache_dir_name);
+ check_directories_created(path);
+ free(path);
disk_cache_destroy(cache);
expect_true(cache_exists(cache), "disk_cache_create with "
"MESA_GLSL_CACHE_DIR set");
- check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/"
- CACHE_DIR_NAME);
+ asprintf(&path, "%s%s", CACHE_TEST_TMP "/mesa-glsl-cache-dir/",
+ cache_dir_name);
+ check_directories_created(path);
+ free(path);
disk_cache_destroy(cache);
}
static void
-test_put_and_get(void)
+test_put_and_get(bool test_cache_size_limit)
{
struct disk_cache *cache;
char blob[] = "This is a blob of thirty-seven bytes";
/* Set the cache size to 1KB and add a 1KB item to force an eviction. */
disk_cache_destroy(cache);
+ if (!test_cache_size_limit)
+ return;
+
setenv("MESA_GLSL_CACHE_MAX_SIZE", "1K", 1);
cache = disk_cache_create("test", "make_check", 0);
}
#endif /* ENABLE_SHADER_CACHE */
-int
-main(void)
+static void
+test_multi_file_cache(void)
+{
+ int err;
+
+ printf("Test multi file disk cache - Start\n");
+
+ test_disk_cache_create(CACHE_DIR_NAME);
+
+ test_put_and_get(true);
+
+ test_put_key_and_get_key();
+
+ printf("Test multi file disk cache - End\n");
+
+ err = rmrf_local(CACHE_TEST_TMP);
+ expect_equal(err, 0, "Removing " CACHE_TEST_TMP " again");
+}
+
+static void
+test_single_file_cache(void)
{
-#ifdef ENABLE_SHADER_CACHE
int err;
- test_disk_cache_create();
+ printf("Test single file disk cache - Start\n");
- test_put_and_get();
+ setenv("MESA_DISK_CACHE_SINGLE_FILE", "true", 1);
+
+ test_disk_cache_create(CACHE_DIR_NAME_SF);
+
+ /* We skip testing cache size limit as the single file cache currently
+ * doesn't have any functionality to enforce cache size limits.
+ */
+ test_put_and_get(false);
test_put_key_and_get_key();
+ setenv("MESA_DISK_CACHE_SINGLE_FILE", "false", 1);
+
+ printf("Test single file disk cache - End\n");
+
err = rmrf_local(CACHE_TEST_TMP);
expect_equal(err, 0, "Removing " CACHE_TEST_TMP " again");
+}
+
+int
+main(void)
+{
+#ifdef ENABLE_SHADER_CACHE
+
+ test_multi_file_cache();
+
+ test_single_file_cache();
+
#endif /* ENABLE_SHADER_CACHE */
return error ? 1 : 0;