xref: /OK3568_Linux_fs/external/xserver/test/tests-common.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #include <sys/types.h>
2 #include <sys/wait.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 
7 #include "tests-common.h"
8 
9 void
run_test_in_child(int (* func)(void),const char * funcname)10 run_test_in_child(int (*func)(void), const char *funcname)
11 {
12     int cpid;
13     int csts;
14     int exit_code = -1;
15 
16     printf("\n---------------------\n%s...\n", funcname);
17     cpid = fork();
18     if (cpid) {
19         waitpid(cpid, &csts, 0);
20         if (!WIFEXITED(csts))
21             goto child_failed;
22         exit_code = WEXITSTATUS(csts);
23         if (exit_code == 0)
24             printf(" Pass\n");
25         else {
26 child_failed:
27             printf(" FAIL\n");
28             exit(exit_code);
29         }
30     } else {
31         exit(func());
32     }
33 }
34