diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2016-08-01 14:09:02 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2016-08-02 11:32:03 +1000 |
commit | 6cde53fc1d8aae22f780eeee23199a41ab1521f3 (patch) | |
tree | 3824cff21b5f714dbefef1e4ad97d0681d63b841 | |
parent | 681f967c8fb67d4af8de49a4298965ba61878384 (diff) |
test: if we're in a debugger, use single-fork mode only
Don't fork by default if we're in gdb.
Note that is_debugger_attached() is now inside #ifndef LITEST_NO_MAIN, gdb for
the litest selftest will now require a manual CK_FORK=no.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | doc/test-suite.dox | 3 | ||||
-rw-r--r-- | test/litest.c | 71 |
2 files changed, 38 insertions, 36 deletions
diff --git a/doc/test-suite.dox b/doc/test-suite.dox index 67d1805..e6fbe62 100644 --- a/doc/test-suite.dox +++ b/doc/test-suite.dox @@ -11,7 +11,8 @@ The test suite has a make-like job control enabled by the `-j` or `--jobs` flag and will fork off as many parallel processes as given by this flag. The default if unspecified is 8. When debugging a specific test case failure it is recommended to employ test filtures (see @ref test-filtering) and disable -parallel tests. +parallel tests. The test suite automatically disables parallel make when run +in gdb. @section test-config X.Org config to avoid interference diff --git a/test/litest.c b/test/litest.c index 902543d..c344f2f 100644 --- a/test/litest.c +++ b/test/litest.c @@ -751,35 +751,6 @@ _litest_add_ranged_for_device(const char *name, litest_abort_msg("Invalid test device type"); } -static int -is_debugger_attached(void) -{ - int status; - int rc; - int pid = fork(); - - if (pid == -1) - return 0; - - if (pid == 0) { - int ppid = getppid(); - if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) == 0) { - waitpid(ppid, NULL, 0); - ptrace(PTRACE_CONT, NULL, NULL); - ptrace(PTRACE_DETACH, ppid, NULL, NULL); - rc = 0; - } else { - rc = 1; - } - _exit(rc); - } else { - waitpid(pid, &status, 0); - rc = WEXITSTATUS(status); - } - - return rc; -} - static void litest_log_handler(struct libinput *libinput, enum libinput_log_priority pri, @@ -988,12 +959,6 @@ litest_run(int argc, char **argv) return 1; } - if (in_debugger == -1) { - in_debugger = is_debugger_attached(); - if (in_debugger) - setenv("CK_FORK", "no", 0); - } - if (getenv("LITEST_VERBOSE")) verbose = 1; @@ -3105,6 +3070,9 @@ litest_parse_argv(int argc, char **argv) JOBS_CUSTOM } want_jobs = JOBS_DEFAULT; + if (in_debugger) + want_jobs = JOBS_SINGLE; + while(1) { int c; int option_index = 0; @@ -3151,6 +3119,35 @@ litest_parse_argv(int argc, char **argv) } #ifndef LITEST_NO_MAIN +static int +is_debugger_attached(void) +{ + int status; + int rc; + int pid = fork(); + + if (pid == -1) + return 0; + + if (pid == 0) { + int ppid = getppid(); + if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) == 0) { + waitpid(ppid, NULL, 0); + ptrace(PTRACE_CONT, NULL, NULL); + ptrace(PTRACE_DETACH, ppid, NULL, NULL); + rc = 0; + } else { + rc = 1; + } + _exit(rc); + } else { + waitpid(pid, &status, 0); + rc = WEXITSTATUS(status); + } + + return rc; +} + static void litest_list_tests(struct list *tests) { @@ -3175,6 +3172,10 @@ main(int argc, char **argv) setenv("CK_DEFAULT_TIMEOUT", "30", 0); setenv("LIBINPUT_RUNNING_TEST_SUITE", "1", 1); + in_debugger = is_debugger_attached(); + if (in_debugger) + setenv("CK_FORK", "no", 0); + mode = litest_parse_argv(argc, argv); if (mode == LITEST_MODE_ERROR) return EXIT_FAILURE; |