diff options
| author | Marek Chalupa <mchqwerty@gmail.com> | 2014-09-24 14:07:59 +0200 |
|---|---|---|
| committer | Pekka Paalanen <pekka.paalanen@collabora.co.uk> | 2014-11-10 14:00:56 +0200 |
| commit | ba6b79c577e4792f35beb471a8d429475aacf3ad (patch) | |
| tree | d0a4f115dcb36ac63d8fab88de891200fd2e930c | |
| parent | queue-test: Add another assertion (diff) | |
| download | wayland-ba6b79c577e4792f35beb471a8d429475aacf3ad.tar wayland-ba6b79c577e4792f35beb471a8d429475aacf3ad.tar.gz wayland-ba6b79c577e4792f35beb471a8d429475aacf3ad.tar.bz2 wayland-ba6b79c577e4792f35beb471a8d429475aacf3ad.tar.lz wayland-ba6b79c577e4792f35beb471a8d429475aacf3ad.tar.xz wayland-ba6b79c577e4792f35beb471a8d429475aacf3ad.tar.zst wayland-ba6b79c577e4792f35beb471a8d429475aacf3ad.zip | |
tests: use our own XDG_RUNTIME_DIR for tests
Use $XDG_RUNTIME_DIR/wayland-tests for tests. This way we won't be
messing XDG_RUNTIME_DIR and it also fixes a bug, when socket-test
failed when another compositor was running.
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
| -rw-r--r-- | tests/test-runner.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test-runner.c b/tests/test-runner.c index 8f3d5d3..af80d2b 100644 --- a/tests/test-runner.c +++ b/tests/test-runner.c @@ -27,10 +27,13 @@ #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> +#include <sys/stat.h> #include <string.h> #include <assert.h> #include <dlfcn.h> #include <errno.h> +#include <limits.h> + #include "test-runner.h" static int num_alloc; @@ -133,6 +136,45 @@ run_test(const struct test *t) exit(EXIT_SUCCESS); } +#ifndef PATH_MAX +#define PATH_MAX 256 +#endif + +static void +set_xdg_runtime_dir(void) +{ + char xdg_runtime_dir[PATH_MAX]; + const char *xrd_env; + + xrd_env = getenv("XDG_RUNTIME_DIR"); + /* if XDG_RUNTIME_DIR is not set in environ, fallback to /tmp */ + assert((snprintf(xdg_runtime_dir, PATH_MAX, "%s/wayland-tests", + xrd_env ? xrd_env : "/tmp") < PATH_MAX) + && "test error: XDG_RUNTIME_DIR too long"); + + if (mkdir(xdg_runtime_dir, 0700) == -1) + if (errno != EEXIST) { + perror("Creating XDG_RUNTIME_DIR"); + abort(); + } + + if (setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1) == -1) { + perror("Setting XDG_RUNTIME_DIR"); + abort(); + } +} + +static void +rmdir_xdg_runtime_dir(void) +{ + const char *xrd_env = getenv("XDG_RUNTIME_DIR"); + assert(xrd_env && "No XDG_RUNTIME_DIR set"); + + /* rmdir may fail if some test didn't do clean up */ + if (rmdir(xrd_env) == -1) + perror("Cleaning XDG_RUNTIME_DIR"); +} + int main(int argc, char *argv[]) { const struct test *t; @@ -158,9 +200,16 @@ int main(int argc, char *argv[]) usage(argv[0], EXIT_FAILURE); } + set_xdg_runtime_dir(); + /* run_test calls exit() */ + assert(atexit(rmdir_xdg_runtime_dir) == 0); + run_test(t); } + /* set our own XDG_RUNTIME_DIR */ + set_xdg_runtime_dir(); + pass = 0; for (t = &__start_test_section; t < &__stop_test_section; t++) { int success = 0; @@ -203,5 +252,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "%d tests, %d pass, %d fail\n", total, pass, total - pass); + /* cleaning */ + rmdir_xdg_runtime_dir(); + return pass == total ? EXIT_SUCCESS : EXIT_FAILURE; } |
