From e940e7d37b2ffcc24595e99868c40e46c57f74b9 Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Tue, 6 Jan 2015 12:42:36 -0600 Subject: [PATCH 1/9] Test the realtime GC, via long running process in a shared object, without linking nimrtl.dll/so. --- tests/realtimeGC/main.c | 71 +++++++++++++++++++++++++++++++++ tests/realtimeGC/main.nim | 40 +++++++++++++++++++ tests/realtimeGC/main.nim.cfg | 6 +++ tests/realtimeGC/make.bat | 10 +++++ tests/realtimeGC/readme.txt | 21 ++++++++++ tests/realtimeGC/shared.nim | 60 ++++++++++++++++++++++++++++ tests/realtimeGC/shared.nim.cfg | 6 +++ 7 files changed, 214 insertions(+) create mode 100644 tests/realtimeGC/main.c create mode 100644 tests/realtimeGC/main.nim create mode 100644 tests/realtimeGC/main.nim.cfg create mode 100755 tests/realtimeGC/make.bat create mode 100644 tests/realtimeGC/readme.txt create mode 100644 tests/realtimeGC/shared.nim create mode 100644 tests/realtimeGC/shared.nim.cfg diff --git a/tests/realtimeGC/main.c b/tests/realtimeGC/main.c new file mode 100644 index 0000000000..0a0ea95b26 --- /dev/null +++ b/tests/realtimeGC/main.c @@ -0,0 +1,71 @@ + +#ifdef WIN +#include +#else +#include +#endif +#include +#include +#include +#include +#include + +#define RUNTIME (35*60) + + +typedef void (*pFunc)(void); + +int main(int argc, char* argv[]) +{ + int i; + void* hndl; + pFunc status; + pFunc count; + pFunc occupiedMem; + +#ifdef WIN + hndl = (void*) LoadLibrary((char const*)"./shared.dll"); + status = (pFunc)GetProcessAddress((HMODULE) hndl, (char const*)"status"); + count = (pFunc)GetProcessAddress((HMODULE) hndl, (char const*)"count"); + occupiedMem = (pFunc)GetProcessAddress((HMODULE) hndl, (char const*)"occupiedMem"); +#else /* OSX || NIX */ + hndl = (void*) dlopen((char const*)"./libshared.so", RTLD_LAZY); + status = (void*) dlsym(hndl, (char const*)"status"); + count = (void*) dlsym(hndl, (char const*)"count"); + occupiedMem = (void*) dlsym(hndl, (char const*)"occupiedMem"); +#endif + + assert(hndl); + assert(status); + assert(count); + assert(occupiedMem); + + time_t startTime = time((time_t*)0); + time_t runTime = (time_t)(RUNTIME); + time_t accumTime = 0; + while (accumTime < runTime) { + for (i = 0; i < 10; i++) + count(); + printf("1. sleeping...\n"); + sleep(1); + for (i = 0; i < 10; i++) + status(); + printf("2. sleeping...\n"); + sleep(1); + occupiedMem(); + accumTime = time((time_t*)0) - startTime; + printf("--- Minutes left to run: %d\n", (int)(runTime-accumTime)/60); + } + printf("Cleaning up the shared object pointer...\n"); +#ifdef WIN + FreeLibrary((HMODULE)hndl); +#else /* OSX || NIX */ + dlclose(hndl); +#endif + printf("Done\n"); + return 0; +} + + + + diff --git a/tests/realtimeGC/main.nim b/tests/realtimeGC/main.nim new file mode 100644 index 0000000000..21e90d545f --- /dev/null +++ b/tests/realtimeGC/main.nim @@ -0,0 +1,40 @@ +discard """ + cmd: " nim c main.nim" + final output: "Done!" +""" + +import times +import os + +const RUNTIME = 35 * 60 # 35 minutes + +when defined(windows): + const dllname = "./server.dll" +elif defined(macosx): + const dllname = "./libserver.dylib" +else: + const dllname = "./libserver.so" + +proc status() {.importc: "status", dynlib: dllname.} +proc count() {.importc: "count", dynlib: dllname.} +proc occupiedMem() {.importc: "occupiedMem", dynlib: dllname.} + +proc main() = + let startTime = getTime() + let runTime = cast[Time](RUNTIME) # + var accumTime: Time + while accumTime < runTime: + for i in 0..10: + count() + echo("1. sleeping... ") + sleep(500) + for i in 0..10: + status() + echo("2. sleeping... ") + sleep(500) + occupiedMem() + accumTime = cast[Time]((getTime() - startTime)) + echo("--- Minutes left to run: ", int(int(runTime-accumTime)/60)) + echo("Done") + +main() diff --git a/tests/realtimeGC/main.nim.cfg b/tests/realtimeGC/main.nim.cfg new file mode 100644 index 0000000000..fed4fa4718 --- /dev/null +++ b/tests/realtimeGC/main.nim.cfg @@ -0,0 +1,6 @@ + +--app:console +--threads:on + +-d:release +-d:useRealtimeGC diff --git a/tests/realtimeGC/make.bat b/tests/realtimeGC/make.bat new file mode 100755 index 0000000000..1825952708 --- /dev/null +++ b/tests/realtimeGC/make.bat @@ -0,0 +1,10 @@ + +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/readme.txt b/tests/realtimeGC/readme.txt new file mode 100644 index 0000000000..035a00001a --- /dev/null +++ b/tests/realtimeGC/readme.txt @@ -0,0 +1,21 @@ +Test the realtime GC without linking nimrtl.dll/so. + +Note, this is a long running test, default is 35 minutes. To change the +the run time see RUNTIME in main.nim and main.c. + +You can build shared.nim, main.nim, and main.c by running make (nix systems) +or maike.bat (Windows systems). They both assume GCC and that it's in your +path. Output: shared.(dll/so), camin(.exe), nmain(.exe). + +To run the test: execute either nmain or cmain in a shell window. + +To build buy hand: + + - build the shared object (shared.nim): + + $ nim c shared.nim + + - build the client executables: + + $ nim c -o:nmain main.nim + $ gcc -o cmain main.c -ldl diff --git a/tests/realtimeGC/shared.nim b/tests/realtimeGC/shared.nim new file mode 100644 index 0000000000..5da1f1fc2c --- /dev/null +++ b/tests/realtimeGC/shared.nim @@ -0,0 +1,60 @@ +discard """ + cmd: " nim c shared.nim" +""" + +import strutils + +var gCounter: uint64 +var gTxStatus: bool +var gRxStatus: bool +var gConnectStatus: bool +var gPttStatus: bool +var gComm1Status: bool +var gComm2Status: bool + +proc getTxStatus(): string = + result = if gTxStatus: "On" else: "Off" + gTxStatus = not gTxStatus + +proc getRxStatus(): string = + result = if gRxStatus: "On" else: "Off" + gRxStatus = not gRxStatus + +proc getConnectStatus(): string = + result = if gConnectStatus: "Yes" else: "No" + gConnectStatus = not gConnectStatus + +proc getPttStatus(): string = + result = if gPttStatus: "PTT: On" else: "PTT: Off" + gPttStatus = not gPttStatus + +proc getComm1Status(): string = + result = if gComm1Status: "On" else: "Off" + gComm1Status = not gComm1Status + +proc getComm2Status(): string = + result = if gComm2Status: "On" else: "Off" + gComm2Status = not gComm2Status + +proc status() {.exportc: "status", dynlib.} = + var tx_status = getTxStatus() + var rx_status = getRxStatus() + var connected = getConnectStatus() + var ptt_status = getPttStatus() + var str1: string = "[PilotEdge] Connected: $1 TX: $2 RX: $3" % [connected, tx_status, rx_status] + var a = getComm1Status() + var b = getComm2Status() + var str2: string = "$1 COM1: $2 COM2: $3" % [ptt_status, a, b] + echo(str1) + echo(str2) + +proc count() {.exportc: "count", dynlib.} = + var temp: uint64 + for i in 0..100_000: + temp += 1 + gCounter += 1 + echo("gCounter: ", gCounter) + +proc occupiedMem() {.exportc: "occupiedMem", dynlib.} = + echo("Occupied Memmory: ", getOccupiedMem()) + diff --git a/tests/realtimeGC/shared.nim.cfg b/tests/realtimeGC/shared.nim.cfg new file mode 100644 index 0000000000..5d498029da --- /dev/null +++ b/tests/realtimeGC/shared.nim.cfg @@ -0,0 +1,6 @@ + +--app:lib +--threads:on + +-d:release +-d:useRealtimeGC From 9be15cd3b3f769f834771b48e190a8062bd2d176 Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Tue, 6 Jan 2015 13:02:31 -0600 Subject: [PATCH 2/9] fixed import object name --- tests/realtimeGC/main.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/realtimeGC/main.nim b/tests/realtimeGC/main.nim index 21e90d545f..98cebdd30d 100644 --- a/tests/realtimeGC/main.nim +++ b/tests/realtimeGC/main.nim @@ -9,11 +9,11 @@ import os const RUNTIME = 35 * 60 # 35 minutes when defined(windows): - const dllname = "./server.dll" + const dllname = "./shared.dll" elif defined(macosx): - const dllname = "./libserver.dylib" + const dllname = "./libshared.dylib" else: - const dllname = "./libserver.so" + const dllname = "./libshared.so" proc status() {.importc: "status", dynlib: dllname.} proc count() {.importc: "count", dynlib: dllname.} From 4e2192fd1cc1f8281a6992e6252df8ce763a9b7c Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Tue, 6 Jan 2015 13:42:02 -0600 Subject: [PATCH 3/9] properly typecast the function pointers --- tests/realtimeGC/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/realtimeGC/main.c b/tests/realtimeGC/main.c index 0a0ea95b26..8bf7aed19d 100644 --- a/tests/realtimeGC/main.c +++ b/tests/realtimeGC/main.c @@ -30,9 +30,9 @@ int main(int argc, char* argv[]) occupiedMem = (pFunc)GetProcessAddress((HMODULE) hndl, (char const*)"occupiedMem"); #else /* OSX || NIX */ hndl = (void*) dlopen((char const*)"./libshared.so", RTLD_LAZY); - status = (void*) dlsym(hndl, (char const*)"status"); - count = (void*) dlsym(hndl, (char const*)"count"); - occupiedMem = (void*) dlsym(hndl, (char const*)"occupiedMem"); + status = (pFunc) dlsym(hndl, (char const*)"status"); + count = (pFunc) dlsym(hndl, (char const*)"count"); + occupiedMem = (pFunc) dlsym(hndl, (char const*)"occupiedMem"); #endif assert(hndl); From 159bbce6d5cf2605f3fbade8807be185a0870657 Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Tue, 6 Jan 2015 14:56:50 -0600 Subject: [PATCH 4/9] add proper cdm strings and comment out all echos --- tests/realtimeGC/main.nim | 10 +++++----- tests/realtimeGC/shared.nim | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/realtimeGC/main.nim b/tests/realtimeGC/main.nim index 98cebdd30d..5496cd9990 100644 --- a/tests/realtimeGC/main.nim +++ b/tests/realtimeGC/main.nim @@ -1,6 +1,6 @@ discard """ - cmd: " nim c main.nim" - final output: "Done!" + cmd: "nim $target --debuginfo $options $file" + output: "Done" """ import times @@ -26,15 +26,15 @@ proc main() = 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() 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)) echo("Done") main() diff --git a/tests/realtimeGC/shared.nim b/tests/realtimeGC/shared.nim index 5da1f1fc2c..df11b4ef92 100644 --- a/tests/realtimeGC/shared.nim +++ b/tests/realtimeGC/shared.nim @@ -1,5 +1,5 @@ discard """ - cmd: " nim c shared.nim" + cmd: "nim $target --debuginfo --hints:on --app:lib $options $file" """ import strutils @@ -45,16 +45,16 @@ proc status() {.exportc: "status", dynlib.} = var a = getComm1Status() var b = getComm2Status() var str2: string = "$1 COM1: $2 COM2: $3" % [ptt_status, a, b] - echo(str1) - echo(str2) + #echo(str1) + #echo(str2) proc count() {.exportc: "count", dynlib.} = var temp: uint64 for i in 0..100_000: temp += 1 gCounter += 1 - echo("gCounter: ", gCounter) + #echo("gCounter: ", gCounter) proc occupiedMem() {.exportc: "occupiedMem", dynlib.} = - echo("Occupied Memmory: ", getOccupiedMem()) + #echo("Occupied Memmory: ", getOccupiedMem()) From 5f3d7e8940779cc2f03374d3e29650c6e7dc3d34 Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Tue, 6 Jan 2015 15:05:51 -0600 Subject: [PATCH 5/9] add test note to the readme --- tests/readme.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/readme.txt b/tests/readme.txt index 0d33a81c70..2cfc79f9ad 100644 --- a/tests/readme.txt +++ b/tests/readme.txt @@ -3,8 +3,11 @@ Each test must have a filename of the form: ``t*.nim`` Each test can contain a spec in a ``discard """"""`` block. -The folder ``rodfiles`` contains special tests that test incremental +The folder ``rodfiles`` contains special tests that test incremental compilation via symbol files. The folder ``dll`` contains simple DLL tests. +The folder ``realtimeGC`` contains a test for validating that the realtime GC +can run properly without linking against the nimrtl.dll/so. It includes a C +client and platform specific build files for manual compilation. From e9f9f6f369f54f13eb94a126695989cdc35787a0 Mon Sep 17 00:00:00 2001 From: Joseph Poirier Date: Thu, 8 Jan 2015 13:40:06 -0600 Subject: [PATCH 6/9] proper windows get process function name, fix batch file, add echoes back --- tests/realtimeGC/main.c | 6 +++--- tests/realtimeGC/make.bat | 2 +- tests/realtimeGC/shared.nim | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/realtimeGC/main.c b/tests/realtimeGC/main.c index 8bf7aed19d..a7ac19dda0 100644 --- a/tests/realtimeGC/main.c +++ b/tests/realtimeGC/main.c @@ -25,9 +25,9 @@ int main(int argc, char* argv[]) #ifdef WIN hndl = (void*) LoadLibrary((char const*)"./shared.dll"); - status = (pFunc)GetProcessAddress((HMODULE) hndl, (char const*)"status"); - count = (pFunc)GetProcessAddress((HMODULE) hndl, (char const*)"count"); - occupiedMem = (pFunc)GetProcessAddress((HMODULE) hndl, (char const*)"occupiedMem"); + status = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"status"); + count = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"count"); + occupiedMem = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"occupiedMem"); #else /* OSX || NIX */ hndl = (void*) dlopen((char const*)"./libshared.so", RTLD_LAZY); status = (pFunc) dlsym(hndl, (char const*)"status"); diff --git a/tests/realtimeGC/make.bat b/tests/realtimeGC/make.bat index 1825952708..cce8292bf2 100755 --- a/tests/realtimeGC/make.bat +++ b/tests/realtimeGC/make.bat @@ -7,4 +7,4 @@ set INC= nim c shared.nim nim c -o:nmain main.nim -%CXX% %INC) %DEFS% %CFLAGS% -o cmain main.c %LNFLAGS% %LIBS% +%CXX% %INC% %DEFS% %CFLAGS% -o cmain main.c %LNFLAGS% %LIBS% diff --git a/tests/realtimeGC/shared.nim b/tests/realtimeGC/shared.nim index df11b4ef92..345051bb5c 100644 --- a/tests/realtimeGC/shared.nim +++ b/tests/realtimeGC/shared.nim @@ -57,4 +57,5 @@ proc count() {.exportc: "count", dynlib.} = proc occupiedMem() {.exportc: "occupiedMem", dynlib.} = #echo("Occupied Memmory: ", getOccupiedMem()) + discard From c1d0b2403b3f1c9ca487c362658aefb954ee7d96 Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Sat, 4 Apr 2015 16:31:50 -0500 Subject: [PATCH 7/9] 15 minutes, bit better messages --- tests/realtimeGC/main.c | 6 +++--- tests/realtimeGC/main.nim | 2 +- tests/realtimeGC/shared.nim | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/realtimeGC/main.c b/tests/realtimeGC/main.c index a7ac19dda0..bbe80b23d0 100644 --- a/tests/realtimeGC/main.c +++ b/tests/realtimeGC/main.c @@ -10,7 +10,7 @@ #include #include -#define RUNTIME (35*60) +#define RUNTIME (15*60) typedef void (*pFunc)(void); @@ -46,11 +46,11 @@ int main(int argc, char* argv[]) while (accumTime < runTime) { for (i = 0; i < 10; i++) count(); - printf("1. sleeping...\n"); + /* printf("1. sleeping...\n"); */ sleep(1); for (i = 0; i < 10; i++) status(); - printf("2. sleeping...\n"); + /* printf("2. sleeping...\n"); */ sleep(1); occupiedMem(); accumTime = time((time_t*)0) - startTime; diff --git a/tests/realtimeGC/main.nim b/tests/realtimeGC/main.nim index 5496cd9990..d2d404271b 100644 --- a/tests/realtimeGC/main.nim +++ b/tests/realtimeGC/main.nim @@ -6,7 +6,7 @@ discard """ import times import os -const RUNTIME = 35 * 60 # 35 minutes +const RUNTIME = 15 * 60 # 15 minutes when defined(windows): const dllname = "./shared.dll" diff --git a/tests/realtimeGC/shared.nim b/tests/realtimeGC/shared.nim index 345051bb5c..c8a70e1ee9 100644 --- a/tests/realtimeGC/shared.nim +++ b/tests/realtimeGC/shared.nim @@ -45,17 +45,17 @@ proc status() {.exportc: "status", dynlib.} = var a = getComm1Status() var b = getComm2Status() var str2: string = "$1 COM1: $2 COM2: $3" % [ptt_status, a, b] - #echo(str1) - #echo(str2) + # echo(str1) + # echo(str2) proc count() {.exportc: "count", dynlib.} = var temp: uint64 for i in 0..100_000: temp += 1 gCounter += 1 - #echo("gCounter: ", gCounter) + # echo("gCounter: ", gCounter) proc occupiedMem() {.exportc: "occupiedMem", dynlib.} = - #echo("Occupied Memmory: ", getOccupiedMem()) + echo("Occupied Memmory: ", getOccupiedMem()) discard From c55f884b5c0ebc0b637138a8de446ba1fd05acdf Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Mon, 13 Apr 2015 22:36:35 -0500 Subject: [PATCH 8/9] integrated realtimegc stuff into testament --- tests/realtimeGC/{main.c => cmain.c} | 20 ++++++-------- tests/realtimeGC/make.bat | 10 ------- tests/realtimeGC/{main.nim => nmain.nim} | 28 +++++++++++-------- tests/realtimeGC/shared.nim | 8 ++++-- tests/realtimeGC/shared.nim.cfg | 1 - tests/testament/categories.nim | 14 ++++++++++ tests/testament/tester.nim | 35 +++++++++++++++++++++++- 7 files changed, 78 insertions(+), 38 deletions(-) rename tests/realtimeGC/{main.c => cmain.c} (71%) delete mode 100755 tests/realtimeGC/make.bat rename tests/realtimeGC/{main.nim => nmain.nim} (53%) diff --git a/tests/realtimeGC/main.c b/tests/realtimeGC/cmain.c similarity index 71% rename from tests/realtimeGC/main.c rename to tests/realtimeGC/cmain.c index bbe80b23d0..e9a46d7ce1 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 cce8292bf2..0000000000 --- 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 similarity index 53% rename from tests/realtimeGC/main.nim rename to tests/realtimeGC/nmain.nim index d2d404271b..c9f558dbc0 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 c8a70e1ee9..2d1dd6c3cd 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 5d498029da..e153b26fa4 100644 --- a/tests/realtimeGC/shared.nim.cfg +++ b/tests/realtimeGC/shared.nim.cfg @@ -1,4 +1,3 @@ - --app:lib --threads:on diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 4476fccf25..2d66d2f8eb 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -138,6 +138,18 @@ proc gcTests(r: var TResults, cat: Category, options: string) = test "stackrefleak" test "cyclecollector" +proc longGCTests(r: var TResults, cat: Category, options: string) = + when defined(windows): + let cOptions = "gcc -ldl -DWIN" + else: + let cOptions = "gcc -ldl" + + var c = initResults() + # According to ioTests, this should compile the file + testNoSpec c, makeTest("tests/realtimeGC/shared", options, cat, actionCompile) + # testC r, makeTest("tests/realtimeGC/cmain", cOptions, cat, actionRun) + testSpec r, makeTest("tests/realtimeGC/nmain", options & "--threads: on", cat, actionRun) + # ------------------------- threading tests ----------------------------------- proc threadTests(r: var TResults, cat: Category, options: string) = @@ -340,6 +352,8 @@ proc processCategory(r: var TResults, cat: Category, options: string) = dllTests(r, cat, options) of "gc": gcTests(r, cat, options) + of "longgc": + longGCTests(r, cat, options) of "debugger": debuggerTests(r, cat, options) of "manyloc": diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index 7391b105e4..86ff6a6895 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -87,6 +87,25 @@ proc callCompiler(cmdTemplate, filename, options: string, elif suc =~ pegSuccess: result.err = reSuccess +proc callCCompiler(cmdTemplate, filename, options: string, + target: TTarget): TSpec = + let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target], + "options", options, "file", filename.quoteShell]) + var p = startProcess(command="gcc", args=c[4.. ^1], + options={poStdErrToStdOut, poUsePath}) + let outp = p.outputStream + var x = newStringOfCap(120) + result.nimout = "" + result.msg = "" + result.file = "" + result.outp = "" + result.line = -1 + while outp.readLine(x.TaintedString) or running(p): + result.nimout.add(x & "\n") + close(p) + if p.peekExitCode == 0: + result.err = reSuccess + proc initResults: TResults = result.total = 0 result.passed = 0 @@ -247,8 +266,22 @@ proc testNoSpec(r: var TResults, test: TTest) = r.addResult(test, "", given.msg, given.err) if given.err == reSuccess: inc(r.passed) +proc testC(r: var TResults, test: TTest) = + # runs C code. Doesn't support any specs, just goes by exit code. + let tname = test.name.addFileExt(".c") + inc(r.total) + styledEcho "Processing ", fgCyan, extractFilename(tname) + var given = callCCompiler(cmdTemplate, test.name & ".c", test.options, test.target) + if given.err != reSuccess: + r.addResult(test, "", given.msg, given.err) + elif test.action == actionRun: + let exeFile = changeFileExt(test.name, ExeExt) + var (buf, exitCode) = execCmdEx(exeFile, options = {poStdErrToStdOut, poUseShell}) + if exitCode != 0: given.err = reExitCodesDiffer + if given.err == reSuccess: inc(r.passed) + proc makeTest(test, options: string, cat: Category, action = actionCompile, - target = targetC): TTest = + target = targetC, env: string = ""): TTest = # start with 'actionCompile', will be overwritten in the spec: result = TTest(cat: cat, name: test, options: options, target: target, action: action) From 2bc1db7a30a52378c0fcf16611bc0faba6ddc390 Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Wed, 13 May 2015 13:13:30 -0500 Subject: [PATCH 9/9] run the C test too --- tests/testament/categories.nim | 2 +- tests/testament/tester.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 336cf211e6..4de1edeee1 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -147,7 +147,7 @@ proc longGCTests(r: var TResults, cat: Category, options: string) = var c = initResults() # According to ioTests, this should compile the file testNoSpec c, makeTest("tests/realtimeGC/shared", options, cat, actionCompile) - # testC r, makeTest("tests/realtimeGC/cmain", cOptions, cat, actionRun) + testC r, makeTest("tests/realtimeGC/cmain", cOptions, cat, actionRun) testSpec r, makeTest("tests/realtimeGC/nmain", options & "--threads: on", cat, actionRun) # ------------------------- threading tests ----------------------------------- diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index 93cb3cc7a8..0308ce9403 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -93,7 +93,7 @@ proc callCCompiler(cmdTemplate, filename, options: string, target: TTarget): TSpec = let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target], "options", options, "file", filename.quoteShell]) - var p = startProcess(command="gcc", args=c[4.. ^1], + var p = startProcess(command="gcc", args=c[5.. ^1], options={poStdErrToStdOut, poUsePath}) let outp = p.outputStream var x = newStringOfCap(120)