2 // WOMultithreadedCrashTests.m
5 // Created by Wincent Colaiuta on 26 November 2006.
6 // Copyright 2006-2007 Wincent Colaiuta.
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #import "WOMultithreadedCrashTests.h"
24 @implementation WOMultithreadedCrashTests
28 [WO_TEST_SHARED_INSTANCE setExpectLowLevelExceptions:YES];
33 [WO_TEST_SHARED_INSTANCE setExpectLowLevelExceptions:YES];
37 #pragma mark Helper methods
39 - (void)secondaryThreadCrasher:(id)sender
41 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
43 // Apple's InstallExceptionHandler doesn't catch crashes on secondary threads
44 // - in the case of Carbon threads a separate handler is automatically installed for each thread
45 // - pthreads and Cocoa threads don't get extra handlers automatically installed
46 // - these are per-thread handlers because the per-process handler port is used by the crash reporter
48 // TODO: write a Mach per-process exception handler
49 return; // don't continue (would crash WOTestRunner)
51 WO_TEST_PASS; // force update of "lastKnownLocation"
52 id *object = NULL; // cause a crash, but WOTest should keep running
53 *object = @"foo"; // SIGBUS here
54 WO_TEST_FAIL; // this line never reached
55 [pool drain]; // nor this one, but pools are in a stack no problem
59 #pragma mark Test methods
61 - (void)testCrashOnSecondaryThread
63 [WO_TEST_SHARED_INSTANCE setExpectLowLevelExceptions:YES]; // will be reset to NO in preflight prior to next method
64 [NSThread detachNewThreadSelector:@selector(secondaryThreadCrasher:) toTarget:self withObject:self];