Changeset View
Changeset View
Standalone View
Standalone View
graphics/wayland/files/patch-tests_test-runner.c
--- tests/test-runner.c.orig 2018-08-24 18:04:36 UTC | --- tests/test-runner.c.orig 2019-03-21 00:55:25 UTC | ||||
+++ tests/test-runner.c | +++ tests/test-runner.c | ||||
@@ -25,6 +25,12 @@ | @@ -25,6 +25,12 @@ | ||||
#define _GNU_SOURCE | #define _GNU_SOURCE | ||||
+#include "../config.h" | +#include "../config.h" | ||||
+ | + | ||||
+#ifdef HAVE_SYS_PARAM_H | +#ifdef HAVE_SYS_PARAM_H | ||||
+#include <sys/param.h> | +#include <sys/param.h> | ||||
+#endif | +#endif | ||||
+ | + | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
@@ -37,19 +43,36 @@ | @@ -37,13 +43,23 @@ | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <limits.h> | #include <limits.h> | ||||
#include <sys/ptrace.h> | #include <sys/ptrace.h> | ||||
+#ifdef HAVE_SYS_PRCTL_H | +#ifdef HAVE_SYS_PRCTL_H | ||||
#include <sys/prctl.h> | #include <sys/prctl.h> | ||||
+#endif | +#endif | ||||
#ifndef PR_SET_PTRACER | #ifndef PR_SET_PTRACER | ||||
# define PR_SET_PTRACER 0x59616d61 | # define PR_SET_PTRACER 0x59616d61 | ||||
#endif | #endif | ||||
+#include <signal.h> | +#include <signal.h> | ||||
#include "test-runner.h" | #include "test-runner.h" | ||||
static int num_alloc; | |||||
+ | |||||
+extern const struct test __start_test_section, __stop_test_section; | |||||
+ | |||||
+/* This is all disabled for FreeBSD because it gives "can't allocate initial | |||||
+ * thread" aborts otherwise. */ | |||||
+#ifndef __FreeBSD__ | |||||
static void* (*sys_malloc)(size_t); | |||||
static void (*sys_free)(void*); | |||||
static void* (*sys_realloc)(void*, size_t); | |||||
static void* (*sys_calloc)(size_t, size_t); | |||||
+#endif | |||||
+#ifdef __FreeBSD__ | +#ifdef __FreeBSD__ | ||||
+/* XXX review ptrace() usage */ | +/* XXX review ptrace() usage */ | ||||
+#define PTRACE_ATTACH PT_ATTACH | +#define PTRACE_ATTACH PT_ATTACH | ||||
+#define PTRACE_CONT PT_CONTINUE | +#define PTRACE_CONT PT_CONTINUE | ||||
+#define PTRACE_DETACH PT_DETACH | +#define PTRACE_DETACH PT_DETACH | ||||
+#endif | +#endif | ||||
+ | + | ||||
/* when set to 1, check if tests are not leaking memory and opened files. | /* when set to 1, check if tests are not leaking opened files. | ||||
* It is turned on by default. It can be turned off by | * It is turned on by default. It can be turned off by | ||||
* WAYLAND_TEST_NO_LEAK_CHECK environment variable. */ | * WAYLAND_TEST_NO_LEAK_CHECK environment variable. */ | ||||
@@ -57,7 +80,7 @@ int leak_check_enabled; | @@ -51,7 +67,7 @@ int fd_leak_check_enabled; | ||||
/* when this var is set to 0, every call to test_set_timeout() is | /* when this var is set to 0, every call to test_set_timeout() is | ||||
* suppressed - handy when debugging the test. Can be set by | * suppressed - handy when debugging the test. Can be set by | ||||
- * WAYLAND_TEST_NO_TIMEOUTS environment variable. */ | - * WAYLAND_TEST_NO_TIMEOUTS environment variable. */ | ||||
+ * WAYLAND_TESTS_NO_TIMEOUTS evnironment var */ | + * WAYLAND_TESTS_NO_TIMEOUTS evnironment var */ | ||||
static int timeouts_enabled = 1; | static int timeouts_enabled = 1; | ||||
/* set to one if the output goes to the terminal */ | /* set to one if the output goes to the terminal */ | ||||
@@ -65,6 +88,7 @@ static int is_atty = 0; | @@ -239,6 +255,8 @@ is_debugger_attached(void) | ||||
extern const struct test __start_test_section, __stop_test_section; | |||||
+#ifndef __FreeBSD__ | |||||
__attribute__ ((visibility("default"))) void * | |||||
malloc(size_t size) | |||||
{ | |||||
@@ -98,6 +122,7 @@ calloc(size_t nmemb, size_t size) | |||||
return sys_calloc(nmemb, size); | |||||
} | |||||
+#endif | |||||
static const struct test * | |||||
find_test(const char *name) | |||||
@@ -292,6 +317,8 @@ is_debugger_attached(void) | |||||
return 0; | return 0; | ||||
} | } | ||||
+ | + | ||||
+// xxx start here | +// xxx start here | ||||
pid = fork(); | pid = fork(); | ||||
if (pid == -1) { | if (pid == -1) { | ||||
perror("fork"); | perror("fork"); | ||||
@@ -312,13 +339,14 @@ is_debugger_attached(void) | @@ -259,13 +277,14 @@ is_debugger_attached(void) | ||||
_exit(1); | _exit(1); | ||||
if (!waitpid(-1, NULL, 0)) | if (!waitpid(-1, NULL, 0)) | ||||
_exit(1); | _exit(1); | ||||
- ptrace(PTRACE_CONT, NULL, NULL); | - ptrace(PTRACE_CONT, NULL, NULL); | ||||
+ ptrace(PTRACE_CONT, ppid, NULL, NULL); | + ptrace(PTRACE_CONT, ppid, NULL, NULL); | ||||
ptrace(PTRACE_DETACH, ppid, NULL, NULL); | ptrace(PTRACE_DETACH, ppid, NULL, NULL); | ||||
_exit(0); | _exit(0); | ||||
} else { | } else { | ||||
close(pipefd[0]); | close(pipefd[0]); | ||||
/* Enable child to ptrace the parent process */ | /* Enable child to ptrace the parent process */ | ||||
+#if defined(HAVE_PRCTL) | +#if defined(HAVE_PRCTL) | ||||
rc = prctl(PR_SET_PTRACER, pid); | rc = prctl(PR_SET_PTRACER, pid); | ||||
if (rc != 0 && errno != EINVAL) { | if (rc != 0 && errno != EINVAL) { | ||||
/* An error prevents us from telling if a debugger is attached. | /* An error prevents us from telling if a debugger is attached. | ||||
@@ -328,7 +356,9 @@ is_debugger_attached(void) | @@ -275,7 +294,9 @@ is_debugger_attached(void) | ||||
*/ | */ | ||||
perror("prctl"); | perror("prctl"); | ||||
write(pipefd[1], "-", 1); | write(pipefd[1], "-", 1); | ||||
- } else { | - } else { | ||||
+ } else | + } else | ||||
+#endif | +#endif | ||||
+ { | + { | ||||
/* Signal to client that parent is ready by passing '+' */ | /* Signal to client that parent is ready by passing '+' */ | ||||
write(pipefd[1], "+", 1); | write(pipefd[1], "+", 1); | ||||
} | } | ||||
@@ -346,17 +376,19 @@ int main(int argc, char *argv[]) | @@ -293,7 +314,11 @@ int main(int argc, char *argv[]) | ||||
const struct test *t; | const struct test *t; | ||||
pid_t pid; | pid_t pid; | ||||
int total, pass; | int total, pass; | ||||
+#ifdef HAVE_WAITID | +#ifdef HAVE_WAITID | ||||
siginfo_t info; | siginfo_t info; | ||||
+#else | +#else | ||||
+ int status; | + int status; | ||||
+#endif | +#endif | ||||
+#ifndef __FreeBSD__ | if (isatty(fileno(stderr))) | ||||
/* Load system malloc, free, and realloc */ | is_atty = 1; | ||||
sys_calloc = dlsym(RTLD_NEXT, "calloc"); | @@ -336,7 +361,8 @@ int main(int argc, char *argv[]) | ||||
sys_realloc = dlsym(RTLD_NEXT, "realloc"); | |||||
sys_malloc = dlsym(RTLD_NEXT, "malloc"); | |||||
sys_free = dlsym(RTLD_NEXT, "free"); | |||||
- if (isatty(fileno(stderr))) | |||||
- is_atty = 1; | |||||
- | |||||
if (is_debugger_attached()) { | |||||
leak_check_enabled = 0; | |||||
timeouts_enabled = 0; | |||||
@@ -364,7 +396,17 @@ int main(int argc, char *argv[]) | |||||
leak_check_enabled = !getenv("WAYLAND_TEST_NO_LEAK_CHECK"); | |||||
timeouts_enabled = !getenv("WAYLAND_TEST_NO_TIMEOUTS"); | |||||
} | |||||
+#else | |||||
+ /* Disable leak checking on FreeBSD since we can't override malloc(). */ | |||||
+ leak_check_enabled = 0; | |||||
+ /* XXX review later */ | |||||
+ timeouts_enabled = 0; | |||||
+#endif | |||||
+ if (isatty(fileno(stderr))) | |||||
+ is_atty = 1; | |||||
+ | |||||
+ | |||||
if (argc == 2 && strcmp(argv[1], "--help") == 0) | |||||
usage(argv[0], EXIT_SUCCESS); | |||||
@@ -395,7 +437,8 @@ int main(int argc, char *argv[]) | |||||
if (pid == 0) | if (pid == 0) | ||||
run_test(t); /* never returns */ | run_test(t); /* never returns */ | ||||
- if (waitid(P_PID, pid, &info, WEXITED)) { | - if (waitid(P_PID, pid, &info, WEXITED)) { | ||||
+#ifdef HAVE_WAITID | +#ifdef HAVE_WAITID | ||||
+ if (waitid(P_PID, 0, &info, WEXITED)) { | + if (waitid(P_PID, 0, &info, WEXITED)) { | ||||
stderr_set_color(RED); | stderr_set_color(RED); | ||||
fprintf(stderr, "waitid failed: %m\n"); | fprintf(stderr, "waitid failed: %m\n"); | ||||
stderr_reset_color(); | stderr_reset_color(); | ||||
@@ -426,6 +469,25 @@ int main(int argc, char *argv[]) | @@ -367,6 +393,25 @@ int main(int argc, char *argv[]) | ||||
break; | break; | ||||
} | } | ||||
+#else | +#else | ||||
+ if (waitpid(-1, &status, 0) == -1) { | + if (waitpid(-1, &status, 0) == -1) { | ||||
+ fprintf(stderr, "waitpid failed: %s\n", | + fprintf(stderr, "waitpid failed: %s\n", | ||||
+ strerror(errno)); | + strerror(errno)); | ||||
+ abort(); | + abort(); | ||||
Show All 17 Lines |