[Mesa-dev] [PATCH] util/disk_cache: fix make check
Timothy Arceri
tarceri at itsqueeze.com
Mon Mar 6 02:25:59 UTC 2017
Fixes make check after 11f0efec2e615f5233d which caused disk cache
to create an additional directory.
---
src/compiler/glsl/tests/cache_test.c | 19 ++++++++++++-------
src/util/disk_cache.c | 17 -----------------
src/util/disk_cache.h | 18 ++++++++++++++++++
3 files changed, 30 insertions(+), 24 deletions(-)
diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c
index de92e5a..7a1ff0a 100644
--- a/src/compiler/glsl/tests/cache_test.c
+++ b/src/compiler/glsl/tests/cache_test.c
@@ -120,21 +120,21 @@ remove_entry(const char *path,
static int
rmrf_local(const char *path)
{
if (path == NULL || *path == '\0' || *path != '.')
return -1;
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)
+check_timestamp_and_gpu_id_directories_created(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;
@@ -173,46 +173,51 @@ test_disk_cache_create(void)
expect_non_null(cache, "disk_cache_create 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");
expect_null(cache, "disk_cache_create with XDG_CACHE_HOME set with"
"a non-existing parent directory");
+ /* Create string with expected directory hierarchy */
+ char expected_dir_h[255];
+ sprintf(expected_dir_h, "%s%s%s", CACHE_TEST_TMP "/xdg-cache-home/mesa/",
+ get_arch_bitness_str(), "/make_check/test");
+
mkdir(CACHE_TEST_TMP, 0755);
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");
+ check_timestamp_and_gpu_id_directories_created(expected_dir_h);
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");
expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set with"
"a non-existing parent directory");
+ sprintf(expected_dir_h, "%s%s%s", CACHE_TEST_TMP
+ "/mesa-glsl-cache-dir/mesa/", get_arch_bitness_str(),
+ "/make_check/test");
+
mkdir(CACHE_TEST_TMP, 0755);
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");
+ check_timestamp_and_gpu_id_directories_created(expected_dir_h);
disk_cache_destroy(cache);
}
static bool
does_cache_contain(struct disk_cache *cache, cache_key key)
{
void *result;
result = disk_cache_get(cache, key, NULL);
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 9a7c5c9..31a9336 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -67,37 +67,20 @@ struct disk_cache {
/* Pointer to total size of all objects in cache (within index_mmap) */
uint64_t *size;
/* Pointer to stored keys, (within index_mmap). */
uint8_t *stored_keys;
/* Maximum size of all cached objects (in bytes). */
uint64_t max_size;
};
-static const char *
-get_arch_bitness_str(void)
-{
- if (sizeof(void *) == 4)
-#ifdef __ILP32__
- return "ilp-32";
-#else
- return "32";
-#endif
- if (sizeof(void *) == 8)
- return "64";
-
- /* paranoia check which will be dropped by the optimiser */
- assert(!"unknown_arch");
- return "unknown_arch";
-}
-
/* Create a directory named 'path' if it does not already exist.
*
* Returns: 0 if path already exists as a directory or if created.
* -1 in all other cases.
*/
static int
mkdir_if_needed(const char *path)
{
struct stat sb;
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index 63ab9b3..3659b6d 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -20,35 +20,53 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef DISK_CACHE_H
#define DISK_CACHE_H
#ifdef ENABLE_SHADER_CACHE
#include <dlfcn.h>
#endif
+#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/stat.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Size of cache keys in bytes. */
#define CACHE_KEY_SIZE 20
typedef uint8_t cache_key[CACHE_KEY_SIZE];
struct disk_cache;
+static inline const char *
+get_arch_bitness_str(void)
+{
+ if (sizeof(void *) == 4)
+#ifdef __ILP32__
+ return "ilp-32";
+#else
+ return "32";
+#endif
+ if (sizeof(void *) == 8)
+ return "64";
+
+ /* paranoia check which will be dropped by the optimiser */
+ assert(!"unknown_arch");
+ return "unknown_arch";
+}
+
static inline bool
disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
{
#ifdef ENABLE_SHADER_CACHE
Dl_info info;
struct stat st;
if (!dladdr(ptr, &info) || !info.dli_fname) {
return false;
}
if (stat(info.dli_fname, &st)) {
--
2.9.3
More information about the mesa-dev
mailing list