xserver/test/tests-common.c
Peter Hutterer 46b579e8d5 test: switch the unit tests to something resembling a test suite
The tests have inadvertent dependencies on each other so let's avoid
those by changing to a system that returns a null-terminated list of
test functions and our test runner iterates over those and forks off one
process per function.
2024-01-30 00:15:10 +00:00

40 lines
859 B
C

#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(const testfunc_t* (*suite)(void), const char *funcname)
{
int cpid;
int csts;
int exit_code = -1;
const testfunc_t *func = suite();
printf("\n---------------------\n%s...\n", funcname);
while (*func)
{
cpid = fork();
if (cpid) {
waitpid(cpid, &csts, 0);
if (!WIFEXITED(csts))
goto child_failed;
exit_code = WEXITSTATUS(csts);
if (exit_code != 0) {
child_failed:
printf(" FAIL\n");
exit(exit_code);
}
} else {
testfunc_t f = *func;
f();
exit(0);
}
func++;
}
printf(" Pass\n");
}