2 * Copyright 2013, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
11 #include <sys/types.h>
22 #define KILL_TIMEOUT 5
24 static uint64_t timeout = 120;
26 int run_test(int (test_function)(void), char *name)
32 /* Make sure output is flushed before forking */
38 exit(test_function());
39 } else if (pid == -1) {
46 /* Wake us up in timeout seconds */
51 rc = waitpid(pid, &status, 0);
54 printf("unknown error from waitpid\n");
59 printf("!! force killing %s\n", name);
63 printf("!! killing %s\n", name);
71 /* Kill anything else in the process group that is still running */
74 if (WIFEXITED(status))
75 status = WEXITSTATUS(status);
77 if (WIFSIGNALED(status))
78 printf("!! child died by signal %d\n", WTERMSIG(status));
80 printf("!! child died by unknown cause\n");
82 status = 1; /* Signal or other */
88 static void sig_handler(int signum)
90 /* Just wake us up from waitpid */
93 static struct sigaction sig_action = {
94 .sa_handler = sig_handler,
97 void test_harness_set_timeout(uint64_t time)
102 int test_harness(int (test_function)(void), char *name)
107 test_set_git_version(GIT_VERSION);
109 if (sigaction(SIGINT, &sig_action, NULL)) {
110 perror("sigaction (sigint)");
115 if (sigaction(SIGALRM, &sig_action, NULL)) {
116 perror("sigaction (sigalrm)");
121 rc = run_test(test_function, name);
123 if (rc == MAGIC_SKIP_RETURN_VALUE) {
125 /* so that skipped test is not marked as failed */
128 test_finish(name, rc);