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 */
33 exit(test_function());
34 } else if (pid
== -1) {
39 /* Wake us up in timeout seconds */
44 rc
= waitpid(pid
, &status
, 0);
47 printf("unknown error from waitpid\n");
52 printf("!! force killing %s\n", name
);
56 printf("!! killing %s\n", name
);
64 if (WIFEXITED(status
))
65 status
= WEXITSTATUS(status
);
67 if (WIFSIGNALED(status
))
68 printf("!! child died by signal %d\n", WTERMSIG(status
));
70 printf("!! child died by unknown cause\n");
72 status
= 1; /* Signal or other */
78 static void alarm_handler(int signum
)
80 /* Jut wake us up from waitpid */
83 static struct sigaction alarm_action
= {
84 .sa_handler
= alarm_handler
,
87 int test_harness(int (test_function
)(void), char *name
)
92 test_set_git_version(GIT_VERSION
);
94 if (sigaction(SIGALRM
, &alarm_action
, NULL
)) {
100 rc
= run_test(test_function
, name
);
102 test_finish(name
, rc
);