Skip to content

Commit a820727

Browse files
committed
test_runner: add support for dying from a signal
When the test child process dies from a fatal signal, it seems to sometimes trigger `WIFSIGNALED`, but sometimes just shows up in the `WEXITSTATUS` as `128 + signal`. Thus, this handles both cases.
1 parent ee9617d commit a820727

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

misc/test_runner/include/ia2_test_runner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct fake_criterion_test {
2323
ia2_test_fn test;
2424
ia2_test_fn init;
2525
int exit_code;
26+
int signal;
2627
};
2728

2829
extern struct fake_criterion_test *fake_criterion_tests;

misc/test_runner/test_runner.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ int main() {
116116
fprintf(stderr, " (%s)", STRINGIFY(EXIT_FAILURE));
117117
} else if (exit_code > 128) {
118118
fprintf(stderr, " (SIG%s)", sigabbrev_np(exit_code - 128));
119+
} else if (test_info->signal != 0) {
120+
// Sometimes the signal doesn't show up with `WIFSIGNALED`, so we check the exit status as well.
121+
fprintf(stderr, " (SIG%s)", sigabbrev_np(test_info->signal));
122+
}
123+
if (test_info->signal != 0) {
124+
fprintf(stderr, ", signal (SIG%s)", sigabbrev_np(test_info->signal));
119125
}
120126
fprintf(stderr, "...\n");
121127

@@ -144,12 +150,14 @@ int main() {
144150
perror("waitpid");
145151
return 2;
146152
}
147-
if WIFSIGNALED (stat) {
153+
if (WIFSIGNALED(stat) && WTERMSIG(stat) != test_info->signal) {
148154
fprintf(stderr, "forked test child was terminated by signal %d\n", WTERMSIG(stat));
149155
return 1;
150156
}
151157
int exit_status = WEXITSTATUS(stat);
152-
if (exit_status != test_info->exit_code) {
158+
if (exit_status != test_info->exit_code ||
159+
// Sometimes the signal doesn't show up with `WIFSIGNALED`, so we check the exit status as well.
160+
(exit_status > 128 && exit_status - 128 == test_info->signal)) {
153161
fprintf(stderr, "forked test child exited with status %d, but %d was expected\n", exit_status, test_info->exit_code);
154162
return 1;
155163
}

tests/post_condition/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Test(post_condition, normal) {
2121
dav1d_get_picture(&c, &pic);
2222
}
2323

24-
Test(post_condition, corrupt_bounds, .exit_code = 128 + SIGABRT) {
24+
Test(post_condition, corrupt_bounds, .signal = SIGABRT) {
2525
corrupt_stride = true;
2626
dav1d_get_picture(&c, &pic);
2727
}

0 commit comments

Comments
 (0)