]> git.saurik.com Git - apple/objc4.git/blob - test/load-parallel.m
objc4-787.1.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.exe -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 atomic_int state;
29
30 void *thread(void *arg)
31 {
32 uintptr_t num = (uintptr_t)arg;
33 char *buf;
34
35 asprintf(&buf, "load-parallel%lu.dylib", (unsigned long)num);
36 testprintf("%s\n", buf);
37 void *dlh = dlopen(buf, RTLD_LAZY);
38 if (!dlh) {
39 fail("dlopen failed: %s", dlerror());
40 }
41 free(buf);
42
43 return NULL;
44 }
45
46 int main()
47 {
48 pthread_t t[COUNT];
49 uintptr_t i;
50
51 for (i = 0; i < COUNT; i++) {
52 pthread_create(&t[i], NULL, thread, (void *)i);
53 }
54
55 for (i = 0; i < COUNT; i++) {
56 pthread_join(t[i], NULL);
57 }
58
59 testprintf("loaded %d/%d\n", (int)state, COUNT*26);
60 testassert(state == COUNT*26);
61
62 succeed(__FILE__);
63 }