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);
120 static char auxv[4096];
122 void *get_auxv_entry(int type)
129 fd = open("/proc/self/auxv", O_RDONLY);
137 num = read(fd, auxv, sizeof(auxv));
143 if (num > sizeof(auxv)) {
144 printf("Overflowed auxv buffer\n");
148 p = (ElfW(auxv_t) *)auxv;
150 while (p->a_type != AT_NULL) {
151 if (p->a_type == type) {
152 result = (void *)p->a_un.a_val;