diff --git a/include/criterion/criterion.h b/include/criterion/criterion.h index b8dbf1b..86b8f4d 100644 --- a/include/criterion/criterion.h +++ b/include/criterion/criterion.h @@ -34,6 +34,7 @@ struct criterion_test_extra_data { unsigned line_; void (*init)(void); void (*fini)(void); + int signal; }; struct criterion_test { diff --git a/include/criterion/stats.h b/include/criterion/stats.h index 55df8c6..7c9318b 100644 --- a/include/criterion/stats.h +++ b/include/criterion/stats.h @@ -42,6 +42,7 @@ struct criterion_test_stats { struct criterion_assert_stats *asserts; int passed; int failed; + int signal; unsigned progress; const char *file; diff --git a/samples/signal.c b/samples/signal.c new file mode 100644 index 0000000..1cda5d9 --- /dev/null +++ b/samples/signal.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +Test(simple, caught, .signal = SIGSEGV) { + int *i = NULL; + *i = 42; +} + +Test(simple, wrong_signal, .signal = SIGSEGV) { + raise(SIGINT); +} + +Test(simple, uncaught) { + int *i = NULL; + *i = 42; +} diff --git a/src/runner.c b/src/runner.c index 70163b3..473a5c1 100644 --- a/src/runner.c +++ b/src/runner.c @@ -143,8 +143,15 @@ static void run_test(struct criterion_global_stats *stats, struct criterion_test } int status; waitpid(pid, &status, 0); - if (WIFSIGNALED(status)) - report(TEST_CRASH, test_stats); + if (WIFSIGNALED(status)) { + test_stats->signal = WTERMSIG(status); + if (test->data->signal == 0) { + report(TEST_CRASH, test_stats); + } else { + report(POST_TEST, test_stats); + report(POST_FINI, test_stats); + } + } } }