From c55f884b5c0ebc0b637138a8de446ba1fd05acdf Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Mon, 13 Apr 2015 22:36:35 -0500 Subject: integrated realtimegc stuff into testament --- tests/realtimeGC/cmain.c | 67 ++++++++++++++++++++++++++++++++++++++ tests/realtimeGC/main.c | 71 ----------------------------------------- tests/realtimeGC/main.nim | 40 ----------------------- tests/realtimeGC/make.bat | 10 ------ tests/realtimeGC/nmain.nim | 46 ++++++++++++++++++++++++++ tests/realtimeGC/shared.nim | 8 +++-- tests/realtimeGC/shared.nim.cfg | 1 - tests/testament/categories.nim | 14 ++++++++ tests/testament/tester.nim | 35 +++++++++++++++++++- 9 files changed, 166 insertions(+), 126 deletions(-) create mode 100644 tests/realtimeGC/cmain.c delete mode 100644 tests/realtimeGC/main.c delete mode 100644 tests/realtimeGC/main.nim delete mode 100755 tests/realtimeGC/make.bat create mode 100644 tests/realtimeGC/nmain.nim diff --git a/tests/realtimeGC/cmain.c b/tests/realtimeGC/cmain.c new file mode 100644 index 000000000..e9a46d7ce --- /dev/null +++ b/tests/realtimeGC/cmain.c @@ -0,0 +1,67 @@ + +#ifdef WIN +#include +#else +#include +#endif +#include +#include +#include +#include +#include + +#define RUNTIME (15*60) + + +typedef void (*pFunc)(void); + +int main(int argc, char* argv[]) +{ + int i; + void* hndl; + pFunc status; + pFunc count; + pFunc checkOccupiedMem; + +#ifdef WIN + 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"); + checkOccupiedMem = (pFunc)GetProcAddress((HMODULE) hndl, (char const*)"checkOccupiedMem"); +#else /* OSX || NIX */ + 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"); + checkOccupiedMem = (pFunc) dlsym(hndl, (char const*)"checkOccupiedMem"); +#endif + + assert(hndl); + assert(status); + assert(count); + assert(checkOccupiedMem); + + 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); + checkOccupiedMem(); + 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.c b/tests/realtimeGC/main.c deleted file mode 100644 index bbe80b23d..000000000 --- a/tests/realtimeGC/main.c +++ /dev/null @@ -1,71 +0,0 @@ - -#ifdef WIN -#include -#else -#include -#endif -#include -#include -#include -#include -#include - -#define RUNTIME (15*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)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"); - count = (pFunc) dlsym(hndl, (char const*)"count"); - occupiedMem = (pFunc) 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 deleted file mode 100644 index d2d404271..000000000 --- a/tests/realtimeGC/main.nim +++ /dev/null @@ -1,40 +0,0 @@ -discard """ - cmd: "nim $target --debuginfo $options $file" - output: "Done" -""" - -import times -import os - -const RUNTIME = 15 * 60 # 15 minutes - -when defined(windows): - const dllname = "./shared.dll" -elif defined(macosx): - const dllname = "./libshared.dylib" -else: - const dllname = "./libshared.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/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/nmain.nim b/tests/realtimeGC/nmain.nim new file mode 100644 index 000000000..c9f558dbc --- /dev/null +++ b/tests/realtimeGC/nmain.nim @@ -0,0 +1,46 @@ +discard """ + cmd: "nim $target --debuginfo $options $file" + output: "Done" +""" + +import times, os, threadpool + +const RUNTIME = 15 * 60 # 15 minutes + +when defined(windows): + const dllname = "./tests/realtimeGC/shared.dll" +elif defined(macosx): + const dllname = "./tests/realtimeGC/libshared.dylib" +else: + const dllname = "./tests/realtimeGC/libshared.so" + +proc status() {.importc: "status", dynlib: dllname.} +proc count() {.importc: "count", dynlib: dllname.} +proc checkOccupiedMem() {.importc: "checkOccupiedMem", dynlib: dllname.} + +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... ") + sleep(500) + for i in 0..10: + status() + # echo("2. sleeping... ") + sleep(500) + checkOccupiedMem() + accumTime = cast[Time]((getTime() - startTime)) + # 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 diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 4476fccf2..2d66d2f8e 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 7391b105e..86ff6a689 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) -- cgit 1.4.1-2-gfad0