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();
|
|
|
|
}
|
|
|
|
|
2016-09-05 21:32:57 +02:00
|
|
|
/* Cross platform segfault simulator ™
|
|
|
|
a.k.a. "I can't believe I have to write this for a sample" */
|
2016-01-20 14:49:15 +01:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2016-09-05 21:32:57 +02:00
|
|
|
void crash(void)
|
|
|
|
{
|
2016-01-20 14:49:15 +01:00
|
|
|
#ifdef _WIN32
|
2016-09-05 21:32:57 +02:00
|
|
|
/* This translates to a SIGSEGV */
|
2016-01-20 14:49:15 +01:00
|
|
|
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
|
|
|
}
|