2015-02-06 01:53:58 +01:00
|
|
|
#include <signal.h>
|
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
2016-01-20 14:49:15 +01:00
|
|
|
void crash(void);
|
|
|
|
|
2015-02-06 01:53:58 +01:00
|
|
|
Test(simple, caught, .signal = SIGSEGV) {
|
2016-01-20 14:49:15 +01:00
|
|
|
crash();
|
2015-02-06 01:53:58 +01:00
|
|
|
}
|
|
|
|
|
2015-08-04 15:18:39 +02:00
|
|
|
Test(simple, wrong_signal, .signal = SIGINT) {
|
2016-01-20 14:49:15 +01:00
|
|
|
crash();
|
2015-02-06 01:53:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Test(simple, uncaught) {
|
2016-01-20 14:49:15 +01:00
|
|
|
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
|
2016-01-17 00:19:31 +01:00
|
|
|
raise(SIGSEGV);
|
2016-01-20 14:49:15 +01:00
|
|
|
#endif
|
2015-02-06 01:53:58 +01:00
|
|
|
}
|