summaryrefslogtreecommitdiff
path: root/lib/mesa/src/compiler/glsl/tests/cache_test.c
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2019-01-29 11:52:33 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2019-01-29 11:52:33 +0000
commit37bbf6a1792773f11c15a4da1588a7520ee2fb4e (patch)
tree64944d4aa665a1e479cfc004e446593062254550 /lib/mesa/src/compiler/glsl/tests/cache_test.c
parent6b139c2063623e9310025247cd966490b9aa57ea (diff)
Merge Mesa 18.3.2
Diffstat (limited to 'lib/mesa/src/compiler/glsl/tests/cache_test.c')
-rw-r--r--lib/mesa/src/compiler/glsl/tests/cache_test.c98
1 files changed, 57 insertions, 41 deletions
diff --git a/lib/mesa/src/compiler/glsl/tests/cache_test.c b/lib/mesa/src/compiler/glsl/tests/cache_test.c
index 75319f116..9d7bde283 100644
--- a/lib/mesa/src/compiler/glsl/tests/cache_test.c
+++ b/lib/mesa/src/compiler/glsl/tests/cache_test.c
@@ -147,6 +147,55 @@ check_directories_created(const char *cache_dir)
expect_true(sub_dirs_created, "create sub dirs");
}
+static bool
+does_cache_contain(struct disk_cache *cache, const cache_key key)
+{
+ void *result;
+
+ result = disk_cache_get(cache, key, NULL);
+
+ if (result) {
+ free(result);
+ return true;
+ }
+
+ return false;
+}
+
+static void
+wait_until_file_written(struct disk_cache *cache, const cache_key key)
+{
+ struct timespec req;
+ struct timespec rem;
+
+ /* Set 100ms delay */
+ req.tv_sec = 0;
+ req.tv_nsec = 100000000;
+
+ unsigned retries = 0;
+ while (retries++ < 20) {
+ if (does_cache_contain(cache, key)) {
+ break;
+ }
+
+ nanosleep(&req, &rem);
+ }
+}
+
+static void *
+cache_exists(struct disk_cache *cache)
+{
+ uint8_t dummy_key[20];
+ char data[] = "some test data";
+
+ if (!cache)
+ return NULL;
+
+ 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
@@ -178,12 +227,13 @@ test_disk_cache_create(void)
/* 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");
+ expect_null(cache_exists(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");
+ expect_non_null(cache_exists(cache), "disk_cache_create with XDG_CACHE_HOME "
+ "set");
check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/"
CACHE_DIR_NAME);
@@ -196,12 +246,13 @@ test_disk_cache_create(void)
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");
+ expect_null(cache_exists(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(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);
@@ -209,41 +260,6 @@ test_disk_cache_create(void)
disk_cache_destroy(cache);
}
-static bool
-does_cache_contain(struct disk_cache *cache, const cache_key key)
-{
- void *result;
-
- result = disk_cache_get(cache, key, NULL);
-
- if (result) {
- free(result);
- return true;
- }
-
- return false;
-}
-
-static void
-wait_until_file_written(struct disk_cache *cache, const cache_key key)
-{
- struct timespec req;
- struct timespec rem;
-
- /* Set 100ms delay */
- req.tv_sec = 0;
- req.tv_nsec = 100000000;
-
- unsigned retries = 0;
- while (retries++ < 20) {
- if (does_cache_contain(cache, key)) {
- break;
- }
-
- nanosleep(&req, &rem);
- }
-}
-
static void
test_put_and_get(void)
{