Next patch will allow disk_cache instance to be created without path set for it, remove some test cases that assume disk_cache creation to fail with invalid path.
To test if different paths work, insert put/get cycle before directory check so that path gets properly created. Signed-off-by: Tapani Pälli <tapani.pa...@intel.com> --- src/compiler/glsl/tests/cache_test.c | 51 ++++++++++++++---------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c index dd11fd5944..4a2f43a4c3 100644 --- a/src/compiler/glsl/tests/cache_test.c +++ b/src/compiler/glsl/tests/cache_test.c @@ -182,21 +182,25 @@ wait_until_file_written(struct disk_cache *cache, const cache_key key) } } +static void * +verify_cache_existence(struct disk_cache *cache) +{ + uint8_t dummy_key[20]; + char *data = "some test data"; + + disk_cache_put(cache, dummy_key, data, sizeof(data), NULL); + wait_until_file_written(cache, dummy_key); + return disk_cache_get(cache, dummy_key, NULL); +} + #define CACHE_TEST_TMP "./cache-test-tmp" static void test_disk_cache_create(void) { struct disk_cache *cache; - int err; - - /* Before doing anything else, ensure that with - * MESA_GLSL_CACHE_DISABLE set to true, that disk_cache_create returns NULL. - */ - setenv("MESA_GLSL_CACHE_DISABLE", "true", 1); - cache = disk_cache_create("test", "make_check", 0); - expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DISABLE set"); + /* Make sure disk cache is enabled. */ unsetenv("MESA_GLSL_CACHE_DISABLE"); /* For the first real disk_cache_create() clear these environment @@ -206,41 +210,26 @@ test_disk_cache_create(void) unsetenv("XDG_CACHE_HOME"); cache = disk_cache_create("test", "make_check", 0); - expect_non_null(cache, "disk_cache_create with no environment variables"); - + expect_non_null(verify_cache_existence(cache), + "cache works with no environment variables"); disk_cache_destroy(cache); - /* Test with XDG_CACHE_HOME set */ - setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1); - cache = disk_cache_create("test", "make_check", 0); - expect_null(cache, "disk_cache_create with XDG_CACHE_HOME set with" - "a non-existing parent directory"); - mkdir(CACHE_TEST_TMP, 0755); - cache = disk_cache_create("test", "make_check", 0); - expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME set"); + setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1); + cache = disk_cache_create("test", "make_check", 0); + expect_non_null(verify_cache_existence(cache), + "cache works with XDG_CACHE_HOME set"); check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/" CACHE_DIR_NAME); - disk_cache_destroy(cache); - /* Test with MESA_GLSL_CACHE_DIR set */ - err = rmrf_local(CACHE_TEST_TMP); - expect_equal(err, 0, "Removing " CACHE_TEST_TMP); - setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1); cache = disk_cache_create("test", "make_check", 0); - expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set with" - "a non-existing parent directory"); - - mkdir(CACHE_TEST_TMP, 0755); - cache = disk_cache_create("test", "make_check", 0); - expect_non_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set"); - + expect_non_null(verify_cache_existence(cache), + "cache works with MESA_GLSL_CACHE_DIR set"); check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/" CACHE_DIR_NAME); - disk_cache_destroy(cache); } -- 2.13.6 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev