Signed-off-by: Leonid Bobrov <mazoc...@disroot.org> --- configure.ac | 7 ++++++ tests/test-compositor.c | 23 +++++++++++++++-- tests/test-runner.c | 55 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 80 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac index 941749d..1d1a25b 100644 --- a/configure.ac +++ b/configure.ac @@ -85,6 +85,13 @@ if test "x$ac_cv_header_kvm_h" != "x" && test "x$ac_cv_lib_kvm_kvm_getfiles" != AC_DEFINE(USE_LIBKVM, 1, [use libkvm on BSD]) fi +# Defines __FreeBSD__ if we're on FreeBSD, same for other *BSD +AC_CHECK_HEADERS([sys/param.h]) + +# waitid() and signal.h are needed for the test suite. +AC_CHECK_FUNCS([waitid]) +AC_CHECK_HEADERS([signal.h]) + AC_ARG_ENABLE([libraries], [AC_HELP_STRING([--disable-libraries], [Disable compilation of wayland libraries])], diff --git a/tests/test-compositor.c b/tests/test-compositor.c index 72f6351..27285ee 100644 --- a/tests/test-compositor.c +++ b/tests/test-compositor.c @@ -86,8 +86,8 @@ get_socket_name(void) static char retval[64]; gettimeofday(&tv, NULL); - snprintf(retval, sizeof retval, "wayland-test-%d-%ld%ld", - getpid(), tv.tv_sec, tv.tv_usec); + snprintf(retval, sizeof retval, "wayland-test-%d-%lld%lld", + getpid(), (long long)tv.tv_sec, (long long)tv.tv_usec); return retval; } @@ -97,10 +97,15 @@ handle_client_destroy(void *data) { struct client_info *ci = data; struct display *d; +#ifdef HAVE_WAITID siginfo_t status; +#else + int istatus; +#endif d = ci->display; +#ifdef HAVE_WAITID assert(waitid(P_PID, ci->pid, &status, WEXITED) != -1); switch (status.si_code) { @@ -118,6 +123,20 @@ handle_client_destroy(void *data) ci->exit_code = status.si_status; break; } +#else + assert(waitpid(ci->pid, &istatus, WNOHANG) != -1); + + if (WIFSIGNALED(istatus)) { + fprintf(stderr, "Client '%s' was killed by signal %d\n", + ci->name, WTERMSIG(istatus)); + ci->exit_code = WEXITSTATUS(istatus); + } else if (WIFEXITED(istatus)) { + if (WEXITSTATUS(istatus) != EXIT_SUCCESS) + fprintf(stderr, "Client '%s' exited with code %d\n", + ci->name, WEXITSTATUS(istatus)); + ci->exit_code = WEXITSTATUS(istatus); + } +#endif ++d->clients_terminated_no; if (d->clients_no == d->clients_terminated_no) { diff --git a/tests/test-runner.c b/tests/test-runner.c index 1487dc4..2936a59 100644 --- a/tests/test-runner.c +++ b/tests/test-runner.c @@ -25,6 +25,12 @@ #define _GNU_SOURCE +#include "../config.h" + +#ifdef HAVE_SYS_PARAM_H +#include <sys/param.h> +#endif + #include <unistd.h> #include <stdio.h> #include <stdlib.h> @@ -32,18 +38,30 @@ #include <sys/wait.h> #include <sys/stat.h> #include <string.h> +#include <signal.h> #include <assert.h> #include <dlfcn.h> #include <errno.h> #include <limits.h> #include <sys/ptrace.h> +#ifdef HAVE_SYS_PRCTL_H #include <sys/prctl.h> +#endif #ifndef PR_SET_PTRACER # define PR_SET_PTRACER 0x59616d61 #endif #include "test-runner.h" +extern const struct test __start_test_section, __stop_test_section; + +#ifndef __linux__ +/* XXX review ptrace() usage */ +#define PTRACE_ATTACH PT_ATTACH +#define PTRACE_CONT PT_CONTINUE +#define PTRACE_DETACH PT_DETACH +#endif + /* when set to 1, check if tests are not leaking opened files. * It is turned on by default. It can be turned off by * WAYLAND_TEST_NO_LEAK_CHECK environment variable. */ @@ -51,7 +69,7 @@ int fd_leak_check_enabled; /* when this var is set to 0, every call to test_set_timeout() is * suppressed - handy when debugging the test. Can be set by - * WAYLAND_TEST_NO_TIMEOUTS environment variable. */ + * WAYLAND_TESTS_NO_TIMEOUTS evnironment var */ static int timeouts_enabled = 1; /* set to one if the output goes to the terminal */ @@ -229,6 +247,10 @@ stderr_reset_color(void) static int is_debugger_attached(void) { +#ifdef __OpenBSD__ + /* OpenBSD doesn't allow to trace parent process */ + return 0; +#else int status; int rc; pid_t pid; @@ -239,6 +261,8 @@ is_debugger_attached(void) return 0; } + +// xxx start here pid = fork(); if (pid == -1) { perror("fork"); @@ -259,7 +283,7 @@ is_debugger_attached(void) _exit(1); if (!waitpid(-1, NULL, 0)) _exit(1); - ptrace(PTRACE_CONT, NULL, NULL); + ptrace(PTRACE_CONT, ppid, NULL, NULL); ptrace(PTRACE_DETACH, ppid, NULL, NULL); _exit(0); } else { @@ -286,6 +310,7 @@ is_debugger_attached(void) } return rc; +#endif } int main(int argc, char *argv[]) @@ -293,7 +318,11 @@ int main(int argc, char *argv[]) const struct test *t; pid_t pid; int total, pass; +#ifdef HAVE_WAITID siginfo_t info; +#else + int status; +#endif if (isatty(fileno(stderr))) is_atty = 1; @@ -336,7 +365,8 @@ int main(int argc, char *argv[]) if (pid == 0) run_test(t); /* never returns */ - if (waitid(P_PID, pid, &info, WEXITED)) { +#ifdef HAVE_WAITID + if (waitid(P_PID, 0, &info, WEXITED)) { stderr_set_color(RED); fprintf(stderr, "waitid failed: %m\n"); stderr_reset_color(); @@ -367,6 +397,25 @@ int main(int argc, char *argv[]) break; } +#else + if (waitpid(-1, &status, 0) == -1) { + fprintf(stderr, "waitpid failed: %s\n", + strerror(errno)); + abort(); + } + + fprintf(stderr, "test \"%s\":\t", t->name); + if (WIFEXITED(status)) { + fprintf(stderr, "exit status %d", WEXITSTATUS(status)); + if (WEXITSTATUS(status) == EXIT_SUCCESS) + success = 1; + } else if (WIFSIGNALED(status)) { + fprintf(stderr, "signal %d", WTERMSIG(status)); + } +#endif + + if (t->must_fail) + success = !success; if (success) { pass++; -- 2.20.1 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel