2 * Copyright 2013, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
11 #include <sys/types.h>
19 #define KILL_TIMEOUT 5
22 int run_test(int (test_function)(void), char *name)
28 /* Make sure output is flushed before forking */
34 exit(test_function());
35 } else if (pid == -1) {
42 /* Wake us up in timeout seconds */
47 rc = waitpid(pid, &status, 0);
50 printf("unknown error from waitpid\n");
55 printf("!! force killing %s\n", name);
59 printf("!! killing %s\n", name);
67 /* Kill anything else in the process group that is still running */
70 if (WIFEXITED(status))
71 status = WEXITSTATUS(status);
73 if (WIFSIGNALED(status))
74 printf("!! child died by signal %d\n", WTERMSIG(status));
76 printf("!! child died by unknown cause\n");
78 status = 1; /* Signal or other */
84 static void alarm_handler(int signum)
86 /* Jut wake us up from waitpid */
89 static struct sigaction alarm_action = {
90 .sa_handler = alarm_handler,
93 int test_harness(int (test_function)(void), char *name)
98 test_set_git_version(GIT_VERSION);
100 if (sigaction(SIGALRM, &alarm_action, NULL)) {
106 rc = run_test(test_function, name);
108 if (rc == MAGIC_SKIP_RETURN_VALUE)
111 test_finish(name, rc);