]> git.saurik.com Git - apple/objc4.git/blob - test/load-noobjc.m
objc4-787.1.tar.gz
[apple/objc4.git] / test / load-noobjc.m
1 /*
2 dyld3 calls the load callback with its own internal lock held, which causes
3 this test to deadlock. Disable the test in dyld3 mode. If
4 rdar://problem/53769512 is fixed then remove this.
5 TEST_CONFIG DYLD=2
6 TEST_BUILD
7 $C{COMPILE} $DIR/load-noobjc.m -o load-noobjc.exe
8 $C{COMPILE} $DIR/load-noobjc2.m -o libload-noobjc2.dylib -bundle -bundle_loader load-noobjc.exe
9 $C{COMPILE} $DIR/load-noobjc3.m -o libload-noobjc3.dylib -bundle -bundle_loader load-noobjc.exe
10 END
11 */
12
13 #include "test.h"
14 #include <dlfcn.h>
15
16 int state = 0;
17 semaphore_t go;
18
19 void *thread(void *arg __unused)
20 {
21 dlopen("libload-noobjc2.dylib", RTLD_LAZY);
22 fail("dlopen should not have returned");
23 }
24
25 int main()
26 {
27 semaphore_create(mach_task_self(), &go, SYNC_POLICY_FIFO, 0);
28
29 pthread_t th;
30 pthread_create(&th, nil, &thread, nil);
31
32 // Wait for thread to stop in libload-noobjc2's +load method.
33 semaphore_wait(go);
34
35 // run nooobjc3's constructor function.
36 // There's no objc code here so it shouldn't require the +load lock.
37 void *dlh = dlopen("libload-noobjc3.dylib", RTLD_LAZY);
38 testassert(dlh);
39 testassert(state == 1);
40
41 succeed(__FILE__);
42 }