OSDN Git Service

util/disk_cache: create timestamp and gpu_id dirs when MESA_GLSL_CACHE_DIR is used
authorTimothy Arceri <tarceri@itsqueeze.com>
Tue, 21 Feb 2017 05:34:49 +0000 (16:34 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Tue, 21 Feb 2017 21:40:14 +0000 (08:40 +1100)
The make check test is also updated to make sure these dirs are created.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/compiler/glsl/tests/cache_test.c
src/util/disk_cache.c

index ba56441..c4e6e36 100644 (file)
@@ -31,6 +31,8 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <inttypes.h>
+#include <limits.h>
+#include <unistd.h>
 
 #include "util/mesa-sha1.h"
 #include "util/disk_cache.h"
@@ -40,6 +42,16 @@ bool error = false;
 #ifdef ENABLE_SHADER_CACHE
 
 static void
+expect_true(bool result, const char *test)
+{
+   if (!result) {
+      fprintf(stderr, "Error: Test '%s' failed: Expected=true"
+              ", Actual=false\n", test);
+      error = true;
+   }
+}
+
+static void
 expect_equal(uint64_t actual, uint64_t expected, const char *test)
 {
    if (actual != expected) {
@@ -114,6 +126,26 @@ rmrf_local(const char *path)
    return nftw(path, remove_entry, 64, FTW_DEPTH | FTW_PHYS | FTW_MOUNT);
 }
 
+static void
+check_timestamp_and_gpu_id_directories_created(const char *cache_dir)
+{
+   bool sub_dirs_created = false;
+
+   char buf[PATH_MAX];
+   if (getcwd(buf, PATH_MAX)) {
+      char *full_path = NULL;
+      if (asprintf(&full_path, "%s%s", buf, ++cache_dir) != -1 ) {
+         struct stat sb;
+         if (stat(full_path, &sb) != -1 && S_ISDIR(sb.st_mode))
+            sub_dirs_created = true;
+
+         free(full_path);
+      }
+   }
+
+   expect_true(sub_dirs_created, "create timestamp and gpu ip sub dirs");
+}
+
 #define CACHE_TEST_TMP "./cache-test-tmp"
 
 static void
@@ -152,6 +184,10 @@ test_disk_cache_create(void)
    cache = disk_cache_create("test", "make_check");
    expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME set");
 
+   check_timestamp_and_gpu_id_directories_created(CACHE_TEST_TMP
+                                                  "/xdg-cache-home"
+                                                  "/mesa/make_check/test");
+
    disk_cache_destroy(cache);
 
    /* Test with MESA_GLSL_CACHE_DIR set */
@@ -167,6 +203,10 @@ test_disk_cache_create(void)
    cache = disk_cache_create("test", "make_check");
    expect_non_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set");
 
+   check_timestamp_and_gpu_id_directories_created(CACHE_TEST_TMP
+                                                  "/mesa-glsl-cache-dir"
+                                                  "/mesa/make_check/test");
+
    disk_cache_destroy(cache);
 }
 
index 6618a24..2f138da 100644 (file)
@@ -225,8 +225,14 @@ disk_cache_create(const char *gpu_name, const char *timestamp)
     *   <pwd.pw_dir>/.cache/mesa
     */
    path = getenv("MESA_GLSL_CACHE_DIR");
-   if (path && mkdir_if_needed(path) == -1) {
-      goto fail;
+   if (path) {
+      if (mkdir_if_needed(path) == -1)
+         goto fail;
+
+      path = create_mesa_cache_dir(local, path, timestamp,
+                                   gpu_name);
+      if (path == NULL)
+         goto fail;
    }
 
    if (path == NULL) {