File: tests-common.c

package info (click to toggle)
xorg-server 2:1.20.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 43,244 kB
  • sloc: ansic: 372,231; xml: 17,683; sh: 5,277; objc: 3,482; makefile: 3,285; python: 514; yacc: 483; cpp: 479; lex: 281; asm: 214; awk: 52; perl: 5
file content (33 lines) | stat: -rw-r--r-- 678 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include "tests-common.h"

void
run_test_in_child(int (*func)(void), const char *funcname)
{
    int cpid;
    int csts;
    int exit_code = -1;

    printf("\n---------------------\n%s...\n", funcname);
    cpid = fork();
    if (cpid) {
        waitpid(cpid, &csts, 0);
        if (!WIFEXITED(csts))
            goto child_failed;
        exit_code = WEXITSTATUS(csts);
        if (exit_code == 0)
            printf(" Pass\n");
        else {
child_failed:
            printf(" FAIL\n");
            exit(exit_code);
        }
    } else {
        exit(func());
    }
}