2 * Copyright 2013, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
11 #include <sys/types.h>
23 #define KILL_TIMEOUT 5
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 alarm_handler(int signum
)
90 /* Jut wake us up from waitpid */
93 static struct sigaction alarm_action
= {
94 .sa_handler
= alarm_handler
,
97 int test_harness(int (test_function
)(void), char *name
)
102 test_set_git_version(GIT_VERSION
);
104 if (sigaction(SIGALRM
, &alarm_action
, NULL
)) {
110 rc
= run_test(test_function
, name
);
112 if (rc
== MAGIC_SKIP_RETURN_VALUE
)
115 test_finish(name
, rc
);