aboutsummaryrefslogtreecommitdiff
path: root/UnitTesting
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-11-16 21:34:57 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-11-16 21:34:57 +0000
commitcd70708c55a7eb471acca8993b5494c347a03ac1 (patch)
tree693aebe576668e8f42bec2a95045cd89976d94a1 /UnitTesting
parent67b6ec2aee256a859af2bebbde86632b7555e544 (diff)
[Author: thomasvl]
Put in a signal handler to restore the profile in a crash. R=dmaclach DELTA=25 (25 added, 0 deleted, 0 changed)
Diffstat (limited to 'UnitTesting')
-rw-r--r--UnitTesting/GTMUnitTestingUtilities.m25
1 files changed, 25 insertions, 0 deletions
diff --git a/UnitTesting/GTMUnitTestingUtilities.m b/UnitTesting/GTMUnitTestingUtilities.m
index e72a921..2d78f23 100644
--- a/UnitTesting/GTMUnitTestingUtilities.m
+++ b/UnitTesting/GTMUnitTestingUtilities.m
@@ -18,6 +18,8 @@
#import "GTMUnitTestingUtilities.h"
#import <AppKit/AppKit.h>
+#include <signal.h>
+#include <unistd.h>
#import "GTMDefines.h"
#import "GTMGarbageCollection.h"
@@ -30,6 +32,8 @@ static BOOL GTMAreCMProfilesEqual(CMProfileRef a, CMProfileRef b);
static void GTMSetColorProfileToGenericRGB();
// Restores the users profile.
static void GTMRestoreColorProfile(void);
+// Signal handler to try and restore users profile.
+static void GTMHandleCrashSignal(int signalNumber);
static CGKeyCode GTMKeyCodeForCharCode(CGCharCode charCode);
@@ -219,6 +223,14 @@ void GTMRestoreColorProfile(void) {
}
}
+void GTMHandleCrashSignal(int signalNumber) {
+ // Going down in flames, might as well try to restore the color profile
+ // anyways.
+ GTMRestoreColorProfile();
+ // Go ahead and exit with the signal value relayed just incase.
+ _exit(signalNumber + 128);
+}
+
void GTMSetColorProfileToGenericRGB(void) {
NSColorSpace *genericSpace = [NSColorSpace genericRGBColorSpace];
CMProfileRef genericProfile = (CMProfileRef)[genericSpace colorSyncProfile];
@@ -260,6 +272,19 @@ void GTMSetColorProfileToGenericRGB(void) {
} else {
gGTMCurrentColorProfile = previousProfile;
atexit(GTMRestoreColorProfile);
+ // WebKit DRT and Chrome TestShell both use this trick. If the test is
+ // already crashing, might as well try restoring the color profile, and if
+ // it fails, it is no worse than crashing without having tried.
+ signal(SIGILL, GTMHandleCrashSignal);
+ signal(SIGTRAP, GTMHandleCrashSignal);
+ signal(SIGEMT, GTMHandleCrashSignal);
+ signal(SIGFPE, GTMHandleCrashSignal);
+ signal(SIGBUS, GTMHandleCrashSignal);
+ signal(SIGSEGV, GTMHandleCrashSignal);
+ signal(SIGSYS, GTMHandleCrashSignal);
+ signal(SIGPIPE, GTMHandleCrashSignal);
+ signal(SIGXCPU, GTMHandleCrashSignal);
+ signal(SIGXFSZ, GTMHandleCrashSignal);
}
CFRelease(previousProfileName);
CFRelease(genericProfileName);