X-Git-Url: https://git.saurik.com/apple/objc4.git/blobdiff_plain/7c0e6487d7b67b6bf6c632300ee4b74e8950b051..7af964d1562d70f51a8e9aca24215ac3d83d0624:/test/gdb-lock.m diff --git a/test/gdb-lock.m b/test/gdb-lock.m new file mode 100644 index 0000000..ee426d6 --- /dev/null +++ b/test/gdb-lock.m @@ -0,0 +1,59 @@ +#import +#import + +#include "test.h" + +// gcc -arch ppc -arch i386 -arch x86_64 -x objective-c gdb-lock.m -framework Foundation +// CONFIG GC RR + +#if __cplusplus +extern "C" +#endif + BOOL gdb_objc_isRuntimeLocked(); + +@interface Foo : NSObject +@end +@implementation Foo +- (void) foo; +{ +} + +- (void) test: __attribute__((unused)) sender +{ + unsigned int x = 0; + Method foo = class_getInstanceMethod([Foo class], @selector(foo)); + IMP fooIMP = method_getImplementation(foo); + const char *fooTypes = method_getTypeEncoding(foo); + while(1) { + NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init]; + char newSELName[100]; + sprintf(newSELName, "a%u", x++); + SEL newSEL = sel_registerName(newSELName); + class_addMethod([Foo class], newSEL, fooIMP, fooTypes); + [self performSelector: newSEL]; + [p drain]; + } +} +@end + +int main() { + NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init]; + [NSThread detachNewThreadSelector: @selector(test:) toTarget: [Foo new] withObject: nil]; + unsigned int x = 0; + unsigned int lockCount = 0; + while(1) { + if (gdb_objc_isRuntimeLocked()) + lockCount++; + x++; + if (x > 1000000) + break; + } + if (lockCount < 10) { + fail("Runtime not locked very much."); + } + [p drain]; + + succeed(__FILE__); + + return 0; +} \ No newline at end of file