Skip to content

Commit 61a88c4

Browse files
committed
Fix CI Stalls/Deadlocks: Add timeout to death tests
1 parent 20cfb71 commit 61a88c4

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

src/tests/test_features.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,43 @@ static test_result_t run_death_test(void (*func)(allocator_t *),
1818
}
1919

2020
if (pid == 0) {
21+
alarm(2); // Safety net for child process
2122
func(alloc);
2223
exit(0); // If we reached here, we didn't crash -> FAIL
2324
}
2425

2526
int status;
26-
waitpid(pid, &status, 0);
27+
// Wait with timeout to prevent hanging CI
28+
int timeout_ms = 2000;
29+
int interval_ms = 10;
30+
int elapsed = 0;
31+
32+
while (elapsed < timeout_ms) {
33+
int res = waitpid(pid, &status, WNOHANG);
34+
if (res == pid) {
35+
break; // Child exited
36+
}
37+
if (res < 0) {
38+
return TEST_FAIL; // Error waiting
39+
}
40+
usleep(interval_ms * 1000);
41+
elapsed += interval_ms;
42+
}
43+
44+
if (elapsed >= timeout_ms) {
45+
kill(pid, SIGKILL);
46+
waitpid(pid, &status, 0); // Cleanup
47+
fprintf(stderr, " [TIMEOUT] Death test timed out (deadlock?)\n");
48+
return TEST_FAIL;
49+
}
2750

2851
if (WIFSIGNALED(status)) {
2952
// Crashed by signal (SEGV, ABRT, etc.) -> PASS for security feature
3053
return TEST_PASS;
3154
}
3255

3356
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
34-
// Exited with error code (detected and aborted safevly) -> PASS
57+
// Exited with error code (detected and aborted safely) -> PASS
3558
return TEST_PASS;
3659
}
3760

0 commit comments

Comments
 (0)