selftests/powerpc: Put the test in a separate process group
authorMichael Ellerman <mpe@ellerman.id.au>
Tue, 10 Jun 2014 12:23:08 +0000 (22:23 +1000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 11 Jun 2014 07:03:49 +0000 (17:03 +1000)
Allows us to kill the test and any children it has spawned.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
tools/testing/selftests/powerpc/harness.c

index e80c42a..532ddff 100644 (file)
@@ -30,12 +30,15 @@ int run_test(int (test_function)(void), char *name)
 
        pid = fork();
        if (pid == 0) {
+               setpgid(0, 0);
                exit(test_function());
        } else if (pid == -1) {
                perror("fork");
                return 1;
        }
 
+       setpgid(pid, pid);
+
        /* Wake us up in timeout seconds */
        alarm(TIMEOUT);
        terminated = false;
@@ -50,17 +53,20 @@ wait:
 
                if (terminated) {
                        printf("!! force killing %s\n", name);
-                       kill(pid, SIGKILL);
+                       kill(-pid, SIGKILL);
                        return 1;
                } else {
                        printf("!! killing %s\n", name);
-                       kill(pid, SIGTERM);
+                       kill(-pid, SIGTERM);
                        terminated = true;
                        alarm(KILL_TIMEOUT);
                        goto wait;
                }
        }
 
+       /* Kill anything else in the process group that is still running */
+       kill(-pid, SIGTERM);
+
        if (WIFEXITED(status))
                status = WEXITSTATUS(status);
        else {