summaryrefslogtreecommitdiff
path: root/test/cairo-test-runner.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-08-22 17:53:59 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2009-08-26 23:51:42 +0100
commite702df59b05246a52a645792a65dc9c12d5b3feb (patch)
tree5552dca97bd8cd718be42f2141eb5b3f37ea9f9a /test/cairo-test-runner.c
parentbf4977b645270bb88225501e73848f7814cccead (diff)
[test] Attempt to automatically detect running under gdb
A common mistake is to forget to pass the foreground mode to cairo-test-suite when launching it under the debugger, resulting in the debugger not attaching to the children and missing the error you were trying to capture. Under linux, we can inspect the path to our parent's executable and if that looks like gdb, we assume it is and disable forking of traces.
Diffstat (limited to 'test/cairo-test-runner.c')
-rw-r--r--test/cairo-test-runner.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/cairo-test-runner.c b/test/cairo-test-runner.c
index f147b5b7..af2991a2 100644
--- a/test/cairo-test-runner.c
+++ b/test/cairo-test-runner.c
@@ -49,6 +49,15 @@
#include <sys/types.h>
#include <sys/wait.h>
#endif
+#if HAVE_LIBGEN_H
+#include <libgen.h>
+#endif
+
+#if HAVE_VALGRIND
+#include <valgrind.h>
+#else
+#define RUNNING_ON_VALGRIND 0
+#endif
#ifdef _MSC_VER
#include <crtdbg.h>
@@ -146,6 +155,26 @@ _list_free (cairo_test_list_t *list)
}
}
+static cairo_bool_t
+is_running_under_debugger (void)
+{
+ char buf[1024];
+
+ if (RUNNING_ON_VALGRIND)
+ return TRUE;
+
+#if HAVE_UNISTD_H && HAVE_LIBGEN_H && __linux__
+ sprintf (buf, "/proc/%d/exe", getppid ());
+ if (readlink (buf, buf, sizeof (buf)) != -1 &&
+ strncmp (basename (buf), "gdb", 3) == 0)
+ {
+ return TRUE;
+ }
+#endif
+
+ return FALSE;
+}
+
#if SHOULD_FORK
static cairo_test_status_t
_cairo_test_wait (pid_t pid)
@@ -621,6 +650,9 @@ main (int argc, char **argv)
memset (&runner, 0, sizeof (runner));
runner.num_device_offsets = 1;
+ if (is_running_under_debugger ())
+ runner.foreground = TRUE;
+
if (getenv ("CAIRO_TEST_MODE")) {
const char *env = getenv ("CAIRO_TEST_MODE");