xserver/test/tests-common.c
Enrico Weigelt, metux IT consult dc778e4356 Revert "test: fail when a child terminates abnormally"
This reverts commit b799d88a78.

Breaks CI. We'll have to do some more things, until we can
actually merge that.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2026-10-05 14:15:20 +02:00

67 lines
1.5 KiB
C

#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.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();
char *xlibre_testenv = getenv("XLIBRE_TEST");
if (xlibre_testenv != NULL) {
bool run_this_test = false;
char *tok_r;
char *tok;
xlibre_testenv = strdup(xlibre_testenv);
tok = strtok_r(xlibre_testenv, ",", &tok_r);
while (tok != NULL) {
if (strcmp(tok, funcname) == 0) {
run_this_test = true;
break;
}
tok = strtok_r(NULL, ",", &tok_r);
}
free(xlibre_testenv);
if (!run_this_test) {
return; /* not selected via XLIBRE_TEST, skip it */
}
}
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");
}