diff options
author | Araq <rumpf_a@web.de> | 2011-11-07 23:25:34 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-11-07 23:25:34 +0100 |
commit | 0b4d5e45b9a6a78f1d661d119cd76f41fecaefea (patch) | |
tree | 5848807ddc889a5eea463108db8d1d7dd15955f5 /tests | |
parent | 0ce9d4960144468c12de493487ada62e8eb04f5d (diff) | |
download | Nim-0b4d5e45b9a6a78f1d661d119cd76f41fecaefea.tar.gz |
tester checks exitcode; osproc additions; DLL fixes; taint mode fixes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/dll/client.nim | 41 | ||||
-rw-r--r-- | tests/dll/dllsimple.nim | 5 | ||||
-rw-r--r-- | tests/dll/server.nim | 27 | ||||
-rwxr-xr-x | tests/tester.nim | 69 |
4 files changed, 114 insertions, 28 deletions
diff --git a/tests/dll/client.nim b/tests/dll/client.nim new file mode 100644 index 000000000..a78cef1d4 --- /dev/null +++ b/tests/dll/client.nim @@ -0,0 +1,41 @@ +discard """ + output: "Done" + cmd: "nimrod cc --debuginfo --hints:on --define:useNimRtl $# $#" +""" + +type + TNodeKind = enum nkLit, nkSub, nkAdd, nkDiv, nkMul + TNode = object + case k: TNodeKind + of nkLit: x: int + else: a, b: ref TNode + + PNode = ref TNode + + +when defined(windows): + const dllname = "server.dll" +elif defined(macosx): + const dllname = "libserver.dylib" +else: + const dllname = "libserver.so" + +proc newLit(x: int): PNode {.importc: "newLit", dynlib: dllname.} +proc newOp(k: TNodeKind, a, b: PNode): PNode {. + importc: "newOp", dynlib: dllname.} +proc buildTree(x: int): PNode {.importc: "buildTree", dynlib: dllname.} + +proc eval(n: PNode): int = + case n.k + of nkLit: result = n.x + of nkSub: result = eval(n.a) - eval(n.b) + of nkAdd: result = eval(n.a) + eval(n.b) + of nkDiv: result = eval(n.a) div eval(n.b) + of nkMul: result = eval(n.a) * eval(n.b) + +# Test the GC: +for i in 0..100_000: + discard eval(buildTree(2)) + +echo "Done" + diff --git a/tests/dll/dllsimple.nim b/tests/dll/dllsimple.nim deleted file mode 100644 index 3f359cd52..000000000 --- a/tests/dll/dllsimple.nim +++ /dev/null @@ -1,5 +0,0 @@ -discard """ - file: tdllgen.nim -""" -proc test() {.exportc.} = - echo("Hello World!") diff --git a/tests/dll/server.nim b/tests/dll/server.nim new file mode 100644 index 000000000..a826ee2a7 --- /dev/null +++ b/tests/dll/server.nim @@ -0,0 +1,27 @@ +discard """ + cmd: "nimrod cc --debuginfo --hints:on --define:useNimRtl --app:lib $# $#" +""" + +type + TNodeKind = enum nkLit, nkSub, nkAdd, nkDiv, nkMul + TNode = object + case k: TNodeKind + of nkLit: x: int + else: a, b: ref TNode + + PNode = ref TNode + +proc newLit(x: int): PNode {.exportc: "newLit", dynlib.} = + new(result) + result.x = x + +proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} = + assert a != nil + assert b != nil + new(result) + result.k = k + result.a = a + result.b = b + +proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} = + result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x)) diff --git a/tests/tester.nim b/tests/tester.nim index 42516fe56..9398a54de 100755 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -50,8 +50,7 @@ when not defined(parseCfgBool): proc extractSpec(filename: string): string = const tripleQuote = "\"\"\"" - var x = readFile(filename) - if isNil(x): quit "cannot open file: " & filename + var x = readFile(filename).string var a = x.find(tripleQuote) var b = x.find(tripleQuote, a+3) if a >= 0 and b > a: @@ -101,9 +100,6 @@ proc parseSpec(filename: string): TSpec = # ---------------------------------------------------------------------------- -proc myExec(cmd: string): string = - result = osproc.execProcess(cmd) - var pegLineError = peg"{[^(]*} '(' {\d+} ', ' \d+ ') Error:' \s* {.*}" pegOtherError = peg"'Error:' \s* {.*}" @@ -119,7 +115,7 @@ proc callCompiler(cmdTemplate, filename, options: string): TSpec = var outp = p.outputStream var s = "" while running(p) or not outp.atEnd(outp): - var x = outp.readLine() + var x = outp.readLine().string if x =~ pegOfInterest: # `s` should contain the last error message s = x @@ -145,7 +141,7 @@ proc initResults: TResults = result.data = "" proc readResults(filename: string): TResults = - result = marshal.to[TResults](readFile(filename)) + result = marshal.to[TResults](readFile(filename).string) proc writeResults(filename: string, r: TResults) = writeFile(filename, $$r) @@ -255,12 +251,16 @@ proc runSingleTest(r: var TResults, test, options: string) = else: var exeFile = changeFileExt(test, ExeExt) if existsFile(exeFile): - var buf = myExec(exeFile) - var success = strip(buf) == strip(expected.outp) - if expected.substr: success = expected.outp in buf - if success: inc(r.passed) - r.addResult(t, expected.outp, - buf, if success: reSuccess else: reFailure) + var (buf, exitCode) = execCmdEx(exeFile) + if exitCode != 0: + r.addResult(t, expected.outp, "exitCode: " & $exitCode, reFailure) + else: + var success = strip(buf.string) == strip(expected.outp) + if expected.substr and not success: + success = expected.outp in buf.string + if success: inc(r.passed) + r.addResult(t, expected.outp, + buf.string, if success: reSuccess else: reFailure) else: r.addResult(t, expected.outp, "executable not found", reFailure) @@ -320,16 +320,35 @@ proc compileRodFiles(r: var TResults, options: string) = test "gtkex2" delNimCache() -# ----------------------------------------------------------------------------- +# --------------------- DLL generation tests ---------------------------------- -# DLL generation tests -proc testDLLGen(r: var TResults, options: string) = - compileSingleTest(r, "lib/nimrtl.nim", "--app:lib -d:createNimRtl") +proc runBasicDLLTest(r: var TResults, options: string) = + compileSingleTest r, "lib/nimrtl.nim", options & " --app:lib -d:createNimRtl" + compileSingleTest r, "tests/dll/server.nim", + options & " --app:lib -d:useNimRtl" + + when defined(Windows): + # windows looks in the dir of the exe (yay!): + var nimrtlDll = DynlibFormat % "nimrtl" + copyFile("lib" / nimrtlDll, "tests/dll" / nimrtlDll) + else: + # posix relies on crappy LD_LIBRARY_PATH (ugh!): + var libpath = getenv"LD_LIBRARY_PATH".string + if peg"\i '/nimrod' (!'/')* '/lib'" notin libpath: + echo "[Warning] insufficient LD_LIBRARY_PATH" + var serverDll = DynlibFormat % "server" + copyFile("tests/dll" / serverDll, "lib" / serverDll) + + runSingleTest r, "tests/dll/client.nim", options & " -d:useNimRtl" + +proc runDLLTests(r: var TResults, options: string) = + runBasicDLLTest(r, options) + runBasicDLLTest(r, options & " -d:release") + runBasicDLLTest(r, options & " --gc:boehm") + runBasicDLLTest(r, options & " -d:release --gc:boehm") - template test(filename: expr): stmt = - compileSingleTest(r, "tests/dll/" / filename, options) - test "dllsimple.nim" +# ----------------------------------------------------------------------------- proc compileExample(r: var TResults, pattern, options: string) = for test in os.walkFiles(pattern): compileSingleTest(r, test, options) @@ -356,7 +375,7 @@ proc main(action: string) = var options = "" for i in 2.. paramCount(): add(options, " ") - add(options, paramStr(i)) + add(options, paramStr(i).string) case action of "reject": @@ -368,7 +387,6 @@ proc main(action: string) = compile(compileRes, "tests/accept/compile/t*.nim", options) compile(compileRes, "tests/ecmas.nim", options) compileRodFiles(compileRes, options) - testDllGen(compileRes, options) writeResults(compileJson, compileRes) of "examples": var compileRes = readResults(compileJson) @@ -380,6 +398,7 @@ proc main(action: string) = var runRes = initResults() run(runRes, "tests/accept/run", options) runRodFiles(runRes, options) + runDLLTests(runRes, options) writeResults(runJson, runRes) of "merge": var rejectRes = readResults(rejectJson) @@ -387,10 +406,14 @@ proc main(action: string) = var runRes = readResults(runJson) listResults(rejectRes, compileRes, runRes) outputJSON(rejectRes, compileRes, runRes) + of "dll": + var runRes = initResults() + runDLLTests runRes, "" + writeResults(runJson, runRes) else: quit usage if paramCount() == 0: quit usage -main(paramStr(1)) +main(paramStr(1).string) |