mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
StdlibUnittest: add a prototype of a Swift-based driver for trapping tests
This technique is about 10x faster than using lit as the driver. Swift SVN r20668
This commit is contained in:
34
stdlib/unittest/InterceptTraps.cpp
Normal file
34
stdlib/unittest/InterceptTraps.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void CrashCatcher(int Sig) {
|
||||
const char *Msg;
|
||||
switch (Sig) {
|
||||
case SIGILL: Msg = "CRASHED: SIGILL\n"; break;
|
||||
case SIGTRAP: Msg = "CRASHED: SIGTRAP\n"; break;
|
||||
case SIGABRT: Msg = "CRASHED: SIGABRT\n"; break;
|
||||
case SIGFPE: Msg = "CRASHED: SIGFPE\n"; break;
|
||||
case SIGBUS: Msg = "CRASHED: SIGBUS\n"; break;
|
||||
case SIGSEGV: Msg = "CRASHED: SIGSEGV\n"; break;
|
||||
case SIGSYS: Msg = "CRASHED: SIGSYS\n"; break;
|
||||
default: Msg = "CRASHED: SIG????\n"; break;
|
||||
}
|
||||
write(STDERR_FILENO, Msg, strlen(Msg));
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
extern "C" void swift_stdlib_installTrapInterceptor() {
|
||||
// Disable buffering on stdout so that everything is printed before crashing.
|
||||
setbuf(stdout, 0);
|
||||
|
||||
signal(SIGILL, CrashCatcher);
|
||||
signal(SIGTRAP, CrashCatcher);
|
||||
signal(SIGABRT, CrashCatcher);
|
||||
signal(SIGFPE, CrashCatcher);
|
||||
signal(SIGBUS, CrashCatcher);
|
||||
signal(SIGSEGV, CrashCatcher);
|
||||
signal(SIGSYS, CrashCatcher);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user