1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2013, Michael Ellerman, IBM Corp.
11 #include <sys/types.h>
22 #define KILL_TIMEOUT 5
24 /* Setting timeout to -1 disables the alarm */
25 static uint64_t timeout
= 120;
27 int run_test(int (test_function
)(void), const char *name
)
33 /* Make sure output is flushed before forking */
39 exit(test_function());
40 } else if (pid
== -1) {
48 /* Wake us up in timeout seconds */
53 rc
= waitpid(pid
, &status
, 0);
56 printf("unknown error from waitpid\n");
61 printf("!! force killing %s\n", name
);
65 printf("!! killing %s\n", name
);
73 /* Kill anything else in the process group that is still running */
76 if (WIFEXITED(status
))
77 status
= WEXITSTATUS(status
);
79 if (WIFSIGNALED(status
))
80 printf("!! child died by signal %d\n", WTERMSIG(status
));
82 printf("!! child died by unknown cause\n");
84 status
= 1; /* Signal or other */
90 static void sig_handler(int signum
)
92 /* Just wake us up from waitpid */
95 static struct sigaction sig_action
= {
96 .sa_handler
= sig_handler
,
99 void test_harness_set_timeout(uint64_t time
)
104 int test_harness(int (test_function
)(void), const char *name
)
109 test_set_git_version(GIT_VERSION
);
111 if (sigaction(SIGINT
, &sig_action
, NULL
)) {
112 perror("sigaction (sigint)");
117 if (sigaction(SIGALRM
, &sig_action
, NULL
)) {
118 perror("sigaction (sigalrm)");
123 rc
= run_test(test_function
, name
);
125 if (rc
== MAGIC_SKIP_RETURN_VALUE
) {
127 /* so that skipped test is not marked as failed */
130 test_finish(name
, rc
);