cmain.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* xxx consider removing, this seems redundant with tmain.nim */
  2. #ifdef WIN
  3. #include <windows.h>
  4. #else
  5. #include <dlfcn.h>
  6. #include <unistd.h> /* for sleep(3) */
  7. #endif
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <assert.h>
  12. #include <time.h>
  13. #define RUNTIME (15*60)
  14. typedef void (*pFunc)(void);
  15. int main(int argc, char* argv[])
  16. {
  17. int i;
  18. void* hndl;
  19. pFunc status;
  20. pFunc count;
  21. pFunc checkOccupiedMem;
  22. #ifdef WIN
  23. hndl = (void*) LoadLibrary((char const*)"./tests/realtimeGC/shared.dll");
  24. status = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"status");
  25. count = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"count");
  26. checkOccupiedMem = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"checkOccupiedMem");
  27. #else /* OSX || NIX xxx: OSX assumes dylib*/
  28. hndl = (void*) dlopen((char const*)"./tests/realtimeGC/libshared.so", RTLD_LAZY);
  29. status = (pFunc) dlsym(hndl, (char const*)"status");
  30. count = (pFunc) dlsym(hndl, (char const*)"count");
  31. checkOccupiedMem = (pFunc) dlsym(hndl, (char const*)"checkOccupiedMem");
  32. #endif
  33. assert(hndl);
  34. assert(status);
  35. assert(count);
  36. assert(checkOccupiedMem);
  37. time_t startTime = time((time_t*)0);
  38. time_t runTime = (time_t)(RUNTIME);
  39. time_t accumTime = 0;
  40. while (accumTime < runTime) {
  41. for (i = 0; i < 10; i++)
  42. count();
  43. /* printf("1. sleeping...\n"); */
  44. sleep(1);
  45. for (i = 0; i < 10; i++)
  46. status();
  47. /* printf("2. sleeping...\n"); */
  48. sleep(1);
  49. checkOccupiedMem();
  50. accumTime = time((time_t*)0) - startTime;
  51. /* printf("--- Minutes left to run: %d\n", (int)(runTime-accumTime)/60); */
  52. }
  53. printf("Cleaning up the shared object pointer...\n");
  54. #ifdef WIN
  55. FreeLibrary((HMODULE)hndl);
  56. #else /* OSX || NIX */
  57. dlclose(hndl);
  58. #endif
  59. printf("Done\n");
  60. return 0;
  61. }