mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 22:35:24 +00:00
tester checks exitcode; osproc additions; DLL fixes; taint mode fixes
This commit is contained in:
41
tests/dll/client.nim
Normal file
41
tests/dll/client.nim
Normal file
@@ -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"
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
discard """
|
||||
file: tdllgen.nim
|
||||
"""
|
||||
proc test() {.exportc.} =
|
||||
echo("Hello World!")
|
||||
27
tests/dll/server.nim
Normal file
27
tests/dll/server.nim
Normal file
@@ -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))
|
||||
@@ -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"
|
||||
|
||||
template test(filename: expr): stmt =
|
||||
compileSingleTest(r, "tests/dll/" / filename, options)
|
||||
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)
|
||||
|
||||
test "dllsimple.nim"
|
||||
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")
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user