diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/collections/ttables.nim | 16 | ||||
-rw-r--r-- | tests/collections/ttablesref.nim | 18 | ||||
-rw-r--r-- | tests/manyloc/standalone/panicoverride.nim | 6 | ||||
-rw-r--r-- | tests/metatype/ttypedesc3.nim | 19 | ||||
-rw-r--r-- | tests/readme.txt | 5 | ||||
-rw-r--r-- | tests/realtimeGC/cmain.c | 67 | ||||
-rw-r--r-- | tests/realtimeGC/main.nim.cfg | 6 | ||||
-rw-r--r-- | tests/realtimeGC/nmain.nim | 46 | ||||
-rw-r--r-- | tests/realtimeGC/readme.txt | 21 | ||||
-rw-r--r-- | tests/realtimeGC/shared.nim | 63 | ||||
-rw-r--r-- | tests/realtimeGC/shared.nim.cfg | 5 | ||||
-rw-r--r-- | tests/testament/categories.nim | 14 | ||||
-rw-r--r-- | tests/testament/tester.nim | 35 |
13 files changed, 301 insertions, 20 deletions
diff --git a/tests/collections/ttables.nim b/tests/collections/ttables.nim index 3a923610e..a10606843 100644 --- a/tests/collections/ttables.nim +++ b/tests/collections/ttables.nim @@ -22,15 +22,15 @@ const "---00": 346677844, "0": 34404, "1": 344004, - "10": 34484, + "10": 34484, "11": 34474, "12": 789, "19": 34464, - "2": 344774, "20": 34454, + "2": 344774, "20": 34454, "3": 342244, "30": 34141244, "34": 123456, "4": 3412344, "40": 344114, - "5": 341232144, "50": 344490, + "5": 341232144, "50": 344490, "6": 34214544, "60": 344491, "7": 3434544, "70": 344492, "8": 344544, "80": 344497, @@ -46,7 +46,7 @@ block tableTest1: for x in 0..1: for y in 0..1: assert t[(x,y)] == $x & $y - assert($t == + assert($t == "{(x: 0, y: 1): 01, (x: 0, y: 0): 00, (x: 1, y: 0): 10, (x: 1, y: 1): 11}") block tableTest2: @@ -55,14 +55,16 @@ block tableTest2: t["111"] = 1.000043 t["123"] = 1.23 t.del("111") - + t["012"] = 67.9 t["123"] = 1.5 # test overwriting - + assert t["123"] == 1.5 assert t["111"] == 0.0 # deleted assert(not hasKey(t, "111")) - + assert "123" in t + assert("111" notin t) + for key, val in items(data): t[key] = val.toFloat for key, val in items(data): assert t[key] == val.toFloat diff --git a/tests/collections/ttablesref.nim b/tests/collections/ttablesref.nim index 16b0d831e..0b641ebc7 100644 --- a/tests/collections/ttablesref.nim +++ b/tests/collections/ttablesref.nim @@ -22,15 +22,15 @@ const "---00": 346677844, "0": 34404, "1": 344004, - "10": 34484, + "10": 34484, "11": 34474, "12": 789, "19": 34464, - "2": 344774, "20": 34454, + "2": 344774, "20": 34454, "3": 342244, "30": 34141244, "34": 123456, "4": 3412344, "40": 344114, - "5": 341232144, "50": 344490, + "5": 341232144, "50": 344490, "6": 34214544, "60": 344491, "7": 3434544, "70": 344492, "8": 344544, "80": 344497, @@ -46,7 +46,7 @@ block tableTest1: for x in 0..1: for y in 0..1: assert t[(x,y)] == $x & $y - assert($t == + assert($t == "{(x: 0, y: 1): 01, (x: 0, y: 0): 00, (x: 1, y: 0): 10, (x: 1, y: 1): 11}") block tableTest2: @@ -55,17 +55,19 @@ block tableTest2: t["111"] = 1.000043 t["123"] = 1.23 t.del("111") - + t["012"] = 67.9 t["123"] = 1.5 # test overwriting - + assert t["123"] == 1.5 assert t["111"] == 0.0 # deleted + assert "123" in t assert(not hasKey(t, "111")) - + assert "111" notin t + for key, val in items(data): t[key] = val.toFloat for key, val in items(data): assert t[key] == val.toFloat - + block orderedTableTest1: var t = newOrderedTable[string, int](2) diff --git a/tests/manyloc/standalone/panicoverride.nim b/tests/manyloc/standalone/panicoverride.nim index efd2b21f9..d9b3f4388 100644 --- a/tests/manyloc/standalone/panicoverride.nim +++ b/tests/manyloc/standalone/panicoverride.nim @@ -7,13 +7,13 @@ proc exit(code: int) {.importc, header: "<stdlib.h>", cdecl.} proc rawoutput(s: string) = printf("%s\n", s) -proc panic(s: string) = +proc panic(s: string) {.noreturn.} = rawoutput(s) exit(1) # Alternatively we also could implement these 2 here: # -# template sysFatal(exceptn: typeDesc, message: string) -# template sysFatal(exceptn: typeDesc, message, arg: string) +# proc sysFatal(exceptn: typeDesc, message: string) {.noReturn.} +# proc sysFatal(exceptn: typeDesc, message, arg: string) {.noReturn.} {.pop.} diff --git a/tests/metatype/ttypedesc3.nim b/tests/metatype/ttypedesc3.nim new file mode 100644 index 000000000..3d40b25b2 --- /dev/null +++ b/tests/metatype/ttypedesc3.nim @@ -0,0 +1,19 @@ +import typetraits + +type + Base = object of RootObj + Child = object of Base + +proc pr(T: typedesc[Base]) = echo "proc " & T.name +method me(T: typedesc[Base]) = echo "method " & T.name +iterator it(T: typedesc[Base]) = yield "yield " & T.name + +Base.pr +Child.pr + +Base.me +when false: + Child.me #<- bug #2710 + +for s in Base.it: echo s +for s in Child.it: echo s #<- bug #2662 diff --git a/tests/readme.txt b/tests/readme.txt index 0d33a81c7..2cfc79f9a 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. 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 <windows.h> +#else +#include <dlfcn.h> +#endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <time.h> + +#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.nim.cfg b/tests/realtimeGC/main.nim.cfg new file mode 100644 index 000000000..fed4fa471 --- /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/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/readme.txt b/tests/realtimeGC/readme.txt new file mode 100644 index 000000000..035a00001 --- /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 000000000..2d1dd6c3c --- /dev/null +++ b/tests/realtimeGC/shared.nim @@ -0,0 +1,63 @@ +discard """ + cmd: "nim $target --debuginfo --hints:on --app:lib $options $file" +""" + +import strutils + +# Global state, accessing with threads, no locks. Don't do this at +# home. +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 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 new file mode 100644 index 000000000..e153b26fa --- /dev/null +++ b/tests/realtimeGC/shared.nim.cfg @@ -0,0 +1,5 @@ +--app:lib +--threads:on + +-d:release +-d:useRealtimeGC diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 07a2421a6..4de1edeee 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 b3e65959a..0308ce940 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -89,6 +89,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[5.. ^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 @@ -257,8 +276,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) |