summary refs log tree commit diff stats
path: root/tests/realtimeGC
diff options
context:
space:
mode:
authorSimon Hafner <hafnersimon@gmail.com>2015-04-13 22:36:35 -0500
committerSimon Hafner <hafnersimon@gmail.com>2015-04-13 22:36:35 -0500
commitc55f884b5c0ebc0b637138a8de446ba1fd05acdf (patch)
tree0fe74403843327ac380d3fb8a2775b5b74b93371 /tests/realtimeGC
parentc1d0b2403b3f1c9ca487c362658aefb954ee7d96 (diff)
downloadNim-c55f884b5c0ebc0b637138a8de446ba1fd05acdf.tar.gz
integrated realtimegc stuff into testament
Diffstat (limited to 'tests/realtimeGC')
-rw-r--r--tests/realtimeGC/cmain.c (renamed from tests/realtimeGC/main.c)20
-rwxr-xr-xtests/realtimeGC/make.bat10
-rw-r--r--tests/realtimeGC/nmain.nim (renamed from tests/realtimeGC/main.nim)28
-rw-r--r--tests/realtimeGC/shared.nim8
-rw-r--r--tests/realtimeGC/shared.nim.cfg1
5 files changed, 30 insertions, 37 deletions
diff --git a/tests/realtimeGC/main.c b/tests/realtimeGC/cmain.c
index bbe80b23d..e9a46d7ce 100644
--- a/tests/realtimeGC/main.c
+++ b/tests/realtimeGC/cmain.c
@@ -21,24 +21,24 @@ int main(int argc, char* argv[])
     void* hndl;
     pFunc status;
     pFunc count;
-    pFunc occupiedMem;
+    pFunc checkOccupiedMem;
 
 #ifdef WIN
-    hndl = (void*) LoadLibrary((char const*)"./shared.dll");
+    hndl = (void*) LoadLibrary((char const*)"./tests/realtimeGC/shared.dll");
     status = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"status");
     count = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"count");
-    occupiedMem = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"occupiedMem");
+    checkOccupiedMem = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"checkOccupiedMem");
 #else /* OSX || NIX */
-    hndl = (void*) dlopen((char const*)"./libshared.so", RTLD_LAZY);
+    hndl = (void*) dlopen((char const*)"./tests/realtimeGC/libshared.so", RTLD_LAZY);
     status = (pFunc) dlsym(hndl, (char const*)"status");
     count = (pFunc) dlsym(hndl, (char const*)"count");
-    occupiedMem = (pFunc) dlsym(hndl, (char const*)"occupiedMem");
+    checkOccupiedMem = (pFunc) dlsym(hndl, (char const*)"checkOccupiedMem");
 #endif
 
     assert(hndl);
     assert(status);
     assert(count);
-    assert(occupiedMem);
+    assert(checkOccupiedMem);
 
     time_t startTime = time((time_t*)0);
     time_t runTime = (time_t)(RUNTIME);
@@ -52,9 +52,9 @@ int main(int argc, char* argv[])
             status();
         /* printf("2. sleeping...\n"); */
         sleep(1);
-        occupiedMem();
+        checkOccupiedMem();
         accumTime = time((time_t*)0) - startTime;
-        printf("--- Minutes left to run: %d\n", (int)(runTime-accumTime)/60);
+        /* printf("--- Minutes left to run: %d\n", (int)(runTime-accumTime)/60); */
     }
     printf("Cleaning up the shared object pointer...\n");
 #ifdef WIN
@@ -65,7 +65,3 @@ int main(int argc, char* argv[])
     printf("Done\n");
     return 0;
 }
-
-
-
-
diff --git a/tests/realtimeGC/make.bat b/tests/realtimeGC/make.bat
deleted file mode 100755
index cce8292bf..000000000
--- a/tests/realtimeGC/make.bat
+++ /dev/null
@@ -1,10 +0,0 @@
-

-set CXX=gcc

-set LIBS=-ldl

-set LNFLAGS=

-set CFLAGS=-DWIN

-set INC=

-

-nim c shared.nim

-nim c -o:nmain main.nim

-%CXX% %INC% %DEFS% %CFLAGS% -o cmain main.c %LNFLAGS% %LIBS%

diff --git a/tests/realtimeGC/main.nim b/tests/realtimeGC/nmain.nim
index d2d404271..c9f558dbc 100644
--- a/tests/realtimeGC/main.nim
+++ b/tests/realtimeGC/nmain.nim
@@ -3,38 +3,44 @@ discard """
   output: "Done"
 """
 
-import times
-import os
+import times, os, threadpool
 
 const RUNTIME = 15 * 60 # 15 minutes
 
 when defined(windows):
-  const dllname = "./shared.dll"
+  const dllname = "./tests/realtimeGC/shared.dll"
 elif defined(macosx):
-  const dllname = "./libshared.dylib"
+  const dllname = "./tests/realtimeGC/libshared.dylib"
 else:
-  const dllname = "./libshared.so"
+  const dllname = "./tests/realtimeGC/libshared.so"
 
 proc status() {.importc: "status", dynlib: dllname.}
 proc count() {.importc: "count", dynlib: dllname.}
-proc occupiedMem() {.importc: "occupiedMem", dynlib: dllname.}
+proc checkOccupiedMem() {.importc: "checkOccupiedMem", dynlib: dllname.}
 
-proc main() =
+proc process() =
   let startTime = getTime()
   let runTime = cast[Time](RUNTIME) #
   var accumTime: Time
   while accumTime < runTime:
     for i in 0..10:
       count()
-    #echo("1. sleeping... ")
+    # echo("1. sleeping... ")
     sleep(500)
     for i in 0..10:
       status()
-    #echo("2. sleeping... ")
+    # echo("2. sleeping... ")
     sleep(500)
-    occupiedMem()
+    checkOccupiedMem()
     accumTime = cast[Time]((getTime() - startTime))
-    #echo("--- Minutes left to run: ", int(int(runTime-accumTime)/60))
+    # echo("--- Minutes left to run: ", int(int(runTime-accumTime)/60))
+
+proc main() =
+  process()
+  # parallel:
+  #   for i in 0..0:
+  #     spawn process()
+  # sync()
   echo("Done")
 
 main()
diff --git a/tests/realtimeGC/shared.nim b/tests/realtimeGC/shared.nim
index c8a70e1ee..2d1dd6c3c 100644
--- a/tests/realtimeGC/shared.nim
+++ b/tests/realtimeGC/shared.nim
@@ -4,6 +4,8 @@ discard """
 
 import strutils
 
+# Global state, accessing with threads, no locks. Don't do this at
+# home.
 var gCounter: uint64
 var gTxStatus: bool
 var gRxStatus: bool
@@ -55,7 +57,7 @@ proc count() {.exportc: "count", dynlib.} =
   gCounter += 1
   # echo("gCounter: ", gCounter)
 
-proc occupiedMem() {.exportc: "occupiedMem", dynlib.} =
-  echo("Occupied Memmory: ", getOccupiedMem())
+proc checkOccupiedMem() {.exportc: "checkOccupiedMem", dynlib.} =
+  if getOccupiedMem() > 10_000_000:
+    quit 1
   discard
-
diff --git a/tests/realtimeGC/shared.nim.cfg b/tests/realtimeGC/shared.nim.cfg
index 5d498029d..e153b26fa 100644
--- a/tests/realtimeGC/shared.nim.cfg
+++ b/tests/realtimeGC/shared.nim.cfg
@@ -1,4 +1,3 @@
-
 --app:lib
 --threads:on