[PATCH v4 09/10] tests: add OS-specific tracing to runner

Leonid Bobrov mazocomp at disroot.org
Sat Feb 9 09:16:44 UTC 2019


Signed-off-by: Leonid Bobrov <mazocomp at disroot.org>
---
 configure.ac        |  3 +++
 tests/test-runner.c | 22 +++++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 15535ff..40cbd08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,6 +101,9 @@ RT_LIBS="$LIBS"
 LIBS="$SAVE_LIBS"
 AC_SUBST(RT_LIBS)
 
+# 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])
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 7fa72eb..4791092 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -40,13 +40,26 @@
 #include <errno.h>
 #include <limits.h>
 #include <sys/ptrace.h>
+#ifdef HAVE_SYS_PRCTL_H
 #include <sys/prctl.h>
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.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__
+#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. */
@@ -232,6 +245,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;
@@ -262,13 +279,14 @@ 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 {
 		close(pipefd[0]);
 
 		/* Enable child to ptrace the parent process */
+#ifdef HAVE_SYS_PRCTL_H
 		rc = prctl(PR_SET_PTRACER, pid);
 		if (rc != 0 && errno != EINVAL) {
 			/* An error prevents us from telling if a debugger is attached.
@@ -282,6 +300,7 @@ is_debugger_attached(void)
 			/* Signal to client that parent is ready by passing '+' */
 			write(pipefd[1], "+", 1);
 		}
+#endif
 		close(pipefd[1]);
 
 		waitpid(pid, &status, 0);
@@ -289,6 +308,7 @@ is_debugger_attached(void)
 	}
 
 	return rc;
+#endif
 }
 
 int main(int argc, char *argv[])
-- 
2.20.1



More information about the wayland-devel mailing list