]> git.saurik.com Git - apple/objc4.git/blob - test/gdb-lock.m
322e45d827da20a91c2db08f5854bc77730069a3
[apple/objc4.git] / test / gdb-lock.m
1 // TEST_CFLAGS -framework Foundation
2
3 #import <Foundation/Foundation.h>
4 #import <objc/runtime.h>
5 #import <objc/objc-gdb.h>
6
7 #include "test.h"
8
9 @interface Foo : NSObject
10 @end
11 @implementation Foo
12 - (void) foo
13 {
14 }
15
16 - (void) test: __attribute__((unused)) sender
17 {
18 unsigned int x = 0;
19 Method foo = class_getInstanceMethod([Foo class], @selector(foo));
20 IMP fooIMP = method_getImplementation(foo);
21 const char *fooTypes = method_getTypeEncoding(foo);
22 while(1) {
23 NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
24 char newSELName[100];
25 sprintf(newSELName, "a%u", x++);
26 SEL newSEL = sel_registerName(newSELName);
27 class_addMethod([Foo class], newSEL, fooIMP, fooTypes);
28 [self performSelector: newSEL];
29 [p drain];
30 }
31 }
32 @end
33
34 int main() {
35 NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
36 [NSThread detachNewThreadSelector: @selector(test:) toTarget: [Foo new] withObject: nil];
37 unsigned int x = 0;
38 unsigned int lockCount = 0;
39 while(1) {
40 if (gdb_objc_isRuntimeLocked())
41 lockCount++;
42 x++;
43 if (x > 1000000)
44 break;
45 }
46 if (lockCount < 10) {
47 fail("Runtime not locked very much.");
48 }
49 [p drain];
50
51 succeed(__FILE__);
52
53 return 0;
54 }