Changeset View
Changeset View
Standalone View
Standalone View
graphics/wayland/files/patch-tests_test-runner.c
--- tests/test-runner.c.orig 2020-02-11 23:46:03 UTC | --- tests/test-runner.c.orig 2020-02-11 23:46:03 UTC | ||||
+++ tests/test-runner.c | +++ tests/test-runner.c | ||||
@@ -25,6 +25,12 @@ | @@ -25,6 +25,8 @@ | ||||
#define _GNU_SOURCE | #define _GNU_SOURCE | ||||
+#include "../config.h" | +#include "../config.h" | ||||
+ | + | ||||
+#ifdef HAVE_SYS_PARAM_H | |||||
+#include <sys/param.h> | |||||
+#endif | |||||
+ | |||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
@@ -37,13 +43,23 @@ | @@ -37,13 +39,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" | ||||
+#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 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. */ | ||||
@@ -51,7 +67,7 @@ int fd_leak_check_enabled; | @@ -51,7 +63,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 */ | ||||
@@ -239,6 +255,8 @@ is_debugger_attached(void) | @@ -239,6 +251,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"); | ||||
@@ -259,13 +277,14 @@ is_debugger_attached(void) | @@ -259,13 +273,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); | ||||
imp: To make this upstreamable, do we need proper ifdef conditions here? | |||||
Done Inline ActionsUnlikely. ptrace(2) on Linux has 4 arguments as well. jbeich: Unlikely. [ptrace(2) on Linux](http://man7.org/linux/man-pages/man2/ptrace.2.html) has 4… | |||||
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. | ||||
@@ -275,7 +294,9 @@ is_debugger_attached(void) | @@ -275,7 +290,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); | ||||
} | } | ||||
@@ -293,7 +314,11 @@ int main(int argc, char *argv[]) | @@ -293,7 +310,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 | ||||
if (isatty(fileno(stderr))) | if (isatty(fileno(stderr))) | ||||
is_atty = 1; | is_atty = 1; | ||||
@@ -336,7 +361,8 @@ int main(int argc, char *argv[]) | @@ -336,7 +357,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: %s\n", | fprintf(stderr, "waitid failed: %s\n", | ||||
Done Inline ActionsYou dropped this by mistake... stderr will still be red after this error message. imp: You dropped this by mistake... stderr will still be red after this error message.
| |||||
Not Done Inline ActionsOr am I misreading the patch and this is a change in upstream... imp: Or am I misreading the patch and this is a change in upstream... | |||||
Done Inline ActionsMisreading. Only context lines have changed. This port's fixes are not colored by Phabricator. If still unsure apply the diff then look at files/patch-tests_test-runner.c. jbeich: Misreading. Only context lines have changed. This port's fixes are not colored by Phabricator. | |||||
strerror(errno)); | strerror(errno)); | ||||
@@ -368,6 +394,25 @@ int main(int argc, char *argv[]) | @@ -368,6 +390,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 |
To make this upstreamable, do we need proper ifdef conditions here?