Added signal & crash handling
This commit is contained in:
parent
6356d35a05
commit
6cca71103a
4 changed files with 29 additions and 2 deletions
|
@ -34,6 +34,7 @@ struct criterion_test_extra_data {
|
|||
unsigned line_;
|
||||
void (*init)(void);
|
||||
void (*fini)(void);
|
||||
int signal;
|
||||
};
|
||||
|
||||
struct criterion_test {
|
||||
|
|
|
@ -42,6 +42,7 @@ struct criterion_test_stats {
|
|||
struct criterion_assert_stats *asserts;
|
||||
int passed;
|
||||
int failed;
|
||||
int signal;
|
||||
unsigned progress;
|
||||
const char *file;
|
||||
|
||||
|
|
18
samples/signal.c
Normal file
18
samples/signal.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <criterion/criterion.h>
|
||||
|
||||
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;
|
||||
}
|
11
src/runner.c
11
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue