test: if we're in a debugger, use single-fork mode only
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 1 Aug 2016 04:09:02 +0000 (14:09 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 2 Aug 2016 01:32:03 +0000 (11:32 +1000)
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>
doc/test-suite.dox
test/litest.c

index 67d1805..e6fbe62 100644 (file)
@@ -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
 
index 902543d..c344f2f 100644 (file)
@@ -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;