disk_cache: Fix memory leaks in the unit test.
Needed for meson test with asan enabled. Reviewed-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7936>
This commit is contained in:
@@ -51,6 +51,15 @@ expect_true(bool result, const char *test)
|
|||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void
|
||||||
|
expect_false(bool result, const char *test)
|
||||||
|
{
|
||||||
|
if (result) {
|
||||||
|
fprintf(stderr, "Error: Test '%s' failed: Expected=false"
|
||||||
|
", Actual=true\n", test);
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
expect_equal(uint64_t actual, uint64_t expected, const char *test)
|
expect_equal(uint64_t actual, uint64_t expected, const char *test)
|
||||||
@@ -162,7 +171,7 @@ does_cache_contain(struct disk_cache *cache, const cache_key key)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static bool
|
||||||
cache_exists(struct disk_cache *cache)
|
cache_exists(struct disk_cache *cache)
|
||||||
{
|
{
|
||||||
uint8_t dummy_key[20];
|
uint8_t dummy_key[20];
|
||||||
@@ -173,7 +182,10 @@ cache_exists(struct disk_cache *cache)
|
|||||||
|
|
||||||
disk_cache_put(cache, dummy_key, data, sizeof(data), NULL);
|
disk_cache_put(cache, dummy_key, data, sizeof(data), NULL);
|
||||||
disk_cache_wait_for_idle(cache);
|
disk_cache_wait_for_idle(cache);
|
||||||
return disk_cache_get(cache, dummy_key, NULL);
|
void *result = disk_cache_get(cache, dummy_key, NULL);
|
||||||
|
|
||||||
|
free(result);
|
||||||
|
return result != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CACHE_TEST_TMP "./cache-test-tmp"
|
#define CACHE_TEST_TMP "./cache-test-tmp"
|
||||||
@@ -227,7 +239,7 @@ test_disk_cache_create(void)
|
|||||||
/* Test with XDG_CACHE_HOME set */
|
/* Test with XDG_CACHE_HOME set */
|
||||||
setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1);
|
setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1);
|
||||||
cache = disk_cache_create("test", "make_check", 0);
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
expect_null(cache_exists(cache), "disk_cache_create with XDG_CACHE_HOME set "
|
expect_false(cache_exists(cache), "disk_cache_create with XDG_CACHE_HOME set "
|
||||||
"with a non-existing parent directory");
|
"with a non-existing parent directory");
|
||||||
|
|
||||||
err = mkdir(CACHE_TEST_TMP, 0755);
|
err = mkdir(CACHE_TEST_TMP, 0755);
|
||||||
@@ -236,9 +248,10 @@ test_disk_cache_create(void)
|
|||||||
error = true;
|
error = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
disk_cache_destroy(cache);
|
||||||
|
|
||||||
cache = disk_cache_create("test", "make_check", 0);
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
expect_non_null(cache_exists(cache), "disk_cache_create with XDG_CACHE_HOME "
|
expect_true(cache_exists(cache), "disk_cache_create with XDG_CACHE_HOME "
|
||||||
"set");
|
"set");
|
||||||
|
|
||||||
check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/"
|
check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/"
|
||||||
@@ -252,7 +265,7 @@ test_disk_cache_create(void)
|
|||||||
|
|
||||||
setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1);
|
setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1);
|
||||||
cache = disk_cache_create("test", "make_check", 0);
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
expect_null(cache_exists(cache), "disk_cache_create with MESA_GLSL_CACHE_DIR"
|
expect_false(cache_exists(cache), "disk_cache_create with MESA_GLSL_CACHE_DIR"
|
||||||
" set with a non-existing parent directory");
|
" set with a non-existing parent directory");
|
||||||
|
|
||||||
err = mkdir(CACHE_TEST_TMP, 0755);
|
err = mkdir(CACHE_TEST_TMP, 0755);
|
||||||
@@ -261,9 +274,10 @@ test_disk_cache_create(void)
|
|||||||
error = true;
|
error = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
disk_cache_destroy(cache);
|
||||||
|
|
||||||
cache = disk_cache_create("test", "make_check", 0);
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
expect_non_null(cache_exists(cache), "disk_cache_create with "
|
expect_true(cache_exists(cache), "disk_cache_create with "
|
||||||
"MESA_GLSL_CACHE_DIR set");
|
"MESA_GLSL_CACHE_DIR set");
|
||||||
|
|
||||||
check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/"
|
check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/"
|
||||||
|
Reference in New Issue
Block a user