[samples] Fixed sample with a cross platform segfault function
This commit is contained in:
parent
bbfe9aa08e
commit
cc9465e133
4 changed files with 48 additions and 11 deletions
|
@ -1,14 +1,33 @@
|
|||
#include <signal.h>
|
||||
#include <criterion/criterion.h>
|
||||
|
||||
void crash(void);
|
||||
|
||||
Test(simple, caught, .signal = SIGSEGV) {
|
||||
raise(SIGSEGV);
|
||||
crash();
|
||||
}
|
||||
|
||||
Test(simple, wrong_signal, .signal = SIGINT) {
|
||||
raise(SIGSEGV);
|
||||
crash();
|
||||
}
|
||||
|
||||
Test(simple, uncaught) {
|
||||
raise(SIGSEGV);
|
||||
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
|
||||
}
|
||||
|
|
|
@ -1,14 +1,32 @@
|
|||
#include <csignal>
|
||||
#include <criterion/criterion.h>
|
||||
|
||||
void crash(void);
|
||||
|
||||
Test(simple, caught, .signal = SIGSEGV) {
|
||||
std::raise(SIGSEGV);
|
||||
crash();
|
||||
}
|
||||
|
||||
Test(simple, wrong_signal, .signal = SIGINT) {
|
||||
std::raise(SIGSEGV);
|
||||
crash();
|
||||
}
|
||||
|
||||
Test(simple, uncaught) {
|
||||
std::raise(SIGSEGV);
|
||||
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
|
||||
std::raise(SIGSEGV);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
Simple crashes & signal testing
|
||||
|
||||
$ signal.c.bin
|
||||
[\x1b[0;34m----\x1b[0m] \x1b[0;1msignal.c\x1b[0m:\x1b[0;31m12\x1b[0m: Unexpected signal caught below this line! (esc)
|
||||
[\x1b[0;34m----\x1b[0m] \x1b[0;1msignal.c\x1b[0m:\x1b[0;31m14\x1b[0m: Unexpected signal caught below this line! (esc)
|
||||
[\x1b[0;31mFAIL\x1b[0m] simple::uncaught: CRASH! (esc)
|
||||
[\x1b[0;31mFAIL\x1b[0m] simple::wrong_signal (esc)
|
||||
[\x1b[0;34m====\x1b[0m] \x1b[0;1mSynthesis: Tested: \x1b[0;34m3\x1b[0;1m | Passing: \x1b[0;32m1\x1b[0;1m | Failing: \x1b[0;31m2\x1b[0;1m | Crashing: \x1b[0;31m1\x1b[0;1m \x1b[0m (esc)
|
||||
|
||||
$ signal.cc.bin
|
||||
[\x1b[0;34m----\x1b[0m] \x1b[0;1msignal.cc\x1b[0m:\x1b[0;31m12\x1b[0m: Unexpected signal caught below this line! (esc)
|
||||
[\x1b[0;34m----\x1b[0m] \x1b[0;1msignal.cc\x1b[0m:\x1b[0;31m14\x1b[0m: Unexpected signal caught below this line! (esc)
|
||||
[\x1b[0;31mFAIL\x1b[0m] simple::uncaught: CRASH! (esc)
|
||||
[\x1b[0;31mFAIL\x1b[0m] simple::wrong_signal (esc)
|
||||
[\x1b[0;34m====\x1b[0m] \x1b[0;1mSynthesis: Tested: \x1b[0;34m3\x1b[0;1m | Passing: \x1b[0;32m1\x1b[0;1m | Failing: \x1b[0;31m2\x1b[0;1m | Crashing: \x1b[0;31m1\x1b[0;1m \x1b[0m (esc)
|
||||
|
@ -20,7 +20,7 @@ Simple crashes & signal testing (verbose)
|
|||
[\x1b[0;34mRUN \x1b[0m] simple::caught (esc)
|
||||
[\x1b[0;32mPASS\x1b[0m] simple::caught (esc)
|
||||
[\x1b[0;34mRUN \x1b[0m] simple::uncaught (esc)
|
||||
[\x1b[0;34m----\x1b[0m] \x1b[0;1msignal.c\x1b[0m:\x1b[0;31m12\x1b[0m: Unexpected signal caught below this line! (esc)
|
||||
[\x1b[0;34m----\x1b[0m] \x1b[0;1msignal.c\x1b[0m:\x1b[0;31m14\x1b[0m: Unexpected signal caught below this line! (esc)
|
||||
[\x1b[0;31mFAIL\x1b[0m] simple::uncaught: CRASH! (esc)
|
||||
[\x1b[0;34mRUN \x1b[0m] simple::wrong_signal (esc)
|
||||
[\x1b[0;31mFAIL\x1b[0m] simple::wrong_signal (esc)
|
||||
|
@ -32,7 +32,7 @@ Simple crashes & signal testing (verbose)
|
|||
[\x1b[0;34mRUN \x1b[0m] simple::caught (esc)
|
||||
[\x1b[0;32mPASS\x1b[0m] simple::caught (esc)
|
||||
[\x1b[0;34mRUN \x1b[0m] simple::uncaught (esc)
|
||||
[\x1b[0;34m----\x1b[0m] \x1b[0;1msignal.cc\x1b[0m:\x1b[0;31m12\x1b[0m: Unexpected signal caught below this line! (esc)
|
||||
[\x1b[0;34m----\x1b[0m] \x1b[0;1msignal.cc\x1b[0m:\x1b[0;31m14\x1b[0m: Unexpected signal caught below this line! (esc)
|
||||
[\x1b[0;31mFAIL\x1b[0m] simple::uncaught: CRASH! (esc)
|
||||
[\x1b[0;34mRUN \x1b[0m] simple::wrong_signal (esc)
|
||||
[\x1b[0;31mFAIL\x1b[0m] simple::wrong_signal (esc)
|
||||
|
|
|
@ -17,7 +17,7 @@ Testing multiple samples with --tap
|
|||
|
||||
# Running 3 tests from simple
|
||||
not ok - simple::wrong_signal
|
||||
not ok - simple::uncaught unexpected signal after signal.c:12
|
||||
not ok - simple::uncaught unexpected signal after signal.c:14
|
||||
ok - simple::caught
|
||||
|
||||
$ asserts.c.bin --tap
|
||||
|
|
Loading…
Add table
Reference in a new issue