]> git.saurik.com Git - apple/objc4.git/blob - test/load-parallel.m
objc4-680.tar.gz
[apple/objc4.git] / test / load-parallel.m
1 /*
2 TEST_BUILD
3 $C{COMPILE} $DIR/load-parallel00.m -o load-parallel00.dylib -dynamiclib
4 $C{COMPILE} $DIR/load-parallel.m -x none load-parallel00.dylib -o load-parallel.out -DCOUNT=10
5
6 $C{COMPILE} $DIR/load-parallel0.m -x none load-parallel00.dylib -o load-parallel0.dylib -dynamiclib -DN=0
7 $C{COMPILE} $DIR/load-parallel0.m -x none load-parallel00.dylib -o load-parallel1.dylib -dynamiclib -DN=1
8 $C{COMPILE} $DIR/load-parallel0.m -x none load-parallel00.dylib -o load-parallel2.dylib -dynamiclib -DN=2
9 $C{COMPILE} $DIR/load-parallel0.m -x none load-parallel00.dylib -o load-parallel3.dylib -dynamiclib -DN=3
10 $C{COMPILE} $DIR/load-parallel0.m -x none load-parallel00.dylib -o load-parallel4.dylib -dynamiclib -DN=4
11 $C{COMPILE} $DIR/load-parallel0.m -x none load-parallel00.dylib -o load-parallel5.dylib -dynamiclib -DN=5
12 $C{COMPILE} $DIR/load-parallel0.m -x none load-parallel00.dylib -o load-parallel6.dylib -dynamiclib -DN=6
13 $C{COMPILE} $DIR/load-parallel0.m -x none load-parallel00.dylib -o load-parallel7.dylib -dynamiclib -DN=7
14 $C{COMPILE} $DIR/load-parallel0.m -x none load-parallel00.dylib -o load-parallel8.dylib -dynamiclib -DN=8
15 $C{COMPILE} $DIR/load-parallel0.m -x none load-parallel00.dylib -o load-parallel9.dylib -dynamiclib -DN=9
16 END
17 */
18
19 #include "test.h"
20
21 #include <dlfcn.h>
22 #include <pthread.h>
23
24 #ifndef COUNT
25 #error -DCOUNT=c missing
26 #endif
27
28 extern int state;
29
30 void *thread(void *arg)
31 {
32 uintptr_t num = (uintptr_t)arg;
33 char *buf;
34
35 objc_registerThreadWithCollector();
36
37 asprintf(&buf, "load-parallel%lu.dylib", (unsigned long)num);
38 testprintf("%s\n", buf);
39 void *dlh = dlopen(buf, RTLD_LAZY);
40 if (!dlh) {
41 fail("dlopen failed: %s", dlerror());
42 }
43 free(buf);
44
45 return NULL;
46 }
47
48 int main()
49 {
50 pthread_t t[COUNT];
51 uintptr_t i;
52
53 for (i = 0; i < COUNT; i++) {
54 pthread_create(&t[i], NULL, thread, (void *)i);
55 }
56
57 for (i = 0; i < COUNT; i++) {
58 pthread_join(t[i], NULL);
59 }
60
61 testprintf("loaded %d/%d\n", state, COUNT*26);
62 testassert(state == COUNT*26);
63
64 succeed(__FILE__);
65 }