load-parallel.m 2.0 KB

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