Criterion/samples/signal.c

34 lines
576 B
C
Raw Permalink Normal View History

2015-02-06 01:53:58 +01:00
#include <signal.h>
#include <criterion/criterion.h>
void crash(void);
2015-02-06 01:53:58 +01:00
Test(simple, caught, .signal = SIGSEGV) {
crash();
2015-02-06 01:53:58 +01:00
}
2015-08-04 15:18:39 +02:00
Test(simple, wrong_signal, .signal = SIGINT) {
crash();
2015-02-06 01:53:58 +01:00
}
Test(simple, uncaught) {
crash();
}
/* Cross platform segfault simulator ™
a.k.a. "I can't believe I have to write this for a sample" */
#ifdef _WIN32
# include <windows.h>
#endif
void crash(void)
{
#ifdef _WIN32
/* This translates to a SIGSEGV */
RaiseException(EXCEPTION_ACCESS_VIOLATION, EXCEPTION_NONCONTINUABLE, 0, NULL);
#else
raise(SIGSEGV);
#endif
2015-02-06 01:53:58 +01:00
}