11b5d61b8Smrg#include <sys/types.h> 21b5d61b8Smrg#include <sys/wait.h> 31b5d61b8Smrg#include <stdlib.h> 41b5d61b8Smrg#include <stdio.h> 51b5d61b8Smrg#include <unistd.h> 61b5d61b8Smrg 71b5d61b8Smrg#include "tests-common.h" 81b5d61b8Smrg 91b5d61b8Smrgvoid 101b5d61b8Smrgrun_test_in_child(int (*func)(void), const char *funcname) 111b5d61b8Smrg{ 121b5d61b8Smrg int cpid; 131b5d61b8Smrg int csts; 141b5d61b8Smrg int exit_code = -1; 151b5d61b8Smrg 161b5d61b8Smrg printf("\n---------------------\n%s...\n", funcname); 171b5d61b8Smrg cpid = fork(); 181b5d61b8Smrg if (cpid) { 191b5d61b8Smrg waitpid(cpid, &csts, 0); 201b5d61b8Smrg if (!WIFEXITED(csts)) 211b5d61b8Smrg goto child_failed; 221b5d61b8Smrg exit_code = WEXITSTATUS(csts); 231b5d61b8Smrg if (exit_code == 0) 241b5d61b8Smrg printf(" Pass\n"); 251b5d61b8Smrg else { 261b5d61b8Smrgchild_failed: 271b5d61b8Smrg printf(" FAIL\n"); 281b5d61b8Smrg exit(exit_code); 291b5d61b8Smrg } 301b5d61b8Smrg } else { 311b5d61b8Smrg exit(func()); 321b5d61b8Smrg } 331b5d61b8Smrg} 34