xserver/test/tests-common.c
Lukáš Lipinský 84ea9e8ccb test: fail when a child terminates abnormally
When a later test child is killed by a signal, exit_code may still contain
zero from the preceding child. Return EXIT_FAILURE explicitly so Meson cannot
report a false success.

Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2293>
Signed-off-by: Lukáš Lipinský <18076-Mr-Tao@users.noreply.gitlab.freedesktop.org>
2026-10-19 14:14:08 +02:00

40 lines
862 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_FAILURE);
}
} else {
testfunc_t f = *func;
f();
exit(0);
}
func++;
}
printf(" Pass\n");
}