Skip to content

Commit

Permalink
selftests/powerpc: Put the test in a separate process group
Browse files Browse the repository at this point in the history
Allows us to kill the test and any children it has spawned.

Signed-off-by: Michael Ellerman <[email protected]>
Signed-off-by: Benjamin Herrenschmidt <[email protected]>
  • Loading branch information
mpe authored and ozbenh committed Jun 11, 2014
1 parent 0a6121c commit de506f7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/testing/selftests/powerpc/harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,17 +53,20 @@ int run_test(int (test_function)(void), char *name)

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 {
Expand Down

0 comments on commit de506f7

Please sign in to comment.