diff options
author | Araq <rumpf_a@web.de> | 2011-11-19 02:05:16 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-11-19 02:05:16 +0100 |
commit | 62aa8bed3b6472e8acae530f7014e7e5b0c755b5 (patch) | |
tree | 59b52d3d7f1b310cc4ae5f6f58e4d1b3b7ccb47f /tests | |
parent | a497b4d1cf529b24ac469e701cb60e8d8b5fdefc (diff) | |
download | Nim-62aa8bed3b6472e8acae530f7014e7e5b0c755b5.tar.gz |
tester: threading tests added
Diffstat (limited to 'tests')
-rw-r--r-- | tests/specials.nim | 10 | ||||
-rwxr-xr-x | tests/tester.nim | 18 | ||||
-rwxr-xr-x | tests/threads/tthreadanalysis2.nim | 2 | ||||
-rw-r--r-- | tests/threads/tthreadanalysis3.nim | 51 | ||||
-rwxr-xr-x | tests/threads/tthreadheapviolation1.nim | 8 |
5 files changed, 77 insertions, 12 deletions
diff --git a/tests/specials.nim b/tests/specials.nim index eadd0d887..a8473e34f 100644 --- a/tests/specials.nim +++ b/tests/specials.nim @@ -120,9 +120,13 @@ proc runThreadTests(r: var TResults, options: string) = #test "threadex" #test "threadring" #test "tthreadanalysis" - #test "tthreadanalysis2" #test "tthreadsort" +proc rejectThreadTests(r: var TResults, options: string) = + rejectSingleTest(r, "tests/threads/tthreadanalysis2", options) + rejectSingleTest(r, "tests/threads/tthreadanalysis3", options) + rejectSingleTest(r, "tests/threads/tthreadheapviolation1", options) + # ------------------------- register special tests here ----------------------- proc runSpecialTests(r: var TResults, options: string) = runRodFiles(r, options) @@ -131,8 +135,8 @@ proc runSpecialTests(r: var TResults, options: string) = runThreadTests(r, options & " --threads:on") proc rejectSpecialTests(r: var TResults, options: string) = - + rejectThreadTests(r, options) proc compileSpecialTests(r: var TResults, options: string) = - nil + compileRodFiles(r, options) diff --git a/tests/tester.nim b/tests/tester.nim index 7dd023cb0..9f59e7da3 100755 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -108,32 +108,35 @@ var peg"{[^(]*} '(' {\d+} ', ' \d+ ') ' ('Error'/'Warning') ':' \s* {.*}" pegOtherError = peg"'Error:' \s* {.*}" pegSuccess = peg"'Hint: operation successful'.*" - pegOfInterest = pegLineError / pegOtherError / pegSuccess + pegOfInterest = pegLineError / pegOtherError proc callCompiler(cmdTemplate, filename, options: string): TSpec = var c = parseCmdLine(cmdTemplate % [options, filename]) var p = startProcess(command=c[0], args=c[1.. -1], options={poStdErrToStdOut, poUseShell}) var outp = p.outputStream - var s = "" + var suc = "" + var err = "" while running(p) or not atEnd(outp): var x = outp.readLine().string if x =~ pegOfInterest: # `s` should contain the last error/warning message - s = x + err = x + elif x =~ pegSuccess: + suc = x close(p) result.msg = "" result.file = "" result.outp = "" result.err = true result.line = -1 - if s =~ pegLineError: + if err =~ pegLineError: result.file = extractFilename(matches[0]) result.line = parseInt(matches[1]) result.msg = matches[2] - elif s =~ pegOtherError: + elif err =~ pegOtherError: result.msg = matches[0] - elif s =~ pegSuccess: + elif suc =~ pegSuccess: result.err = false proc initResults: TResults = @@ -328,12 +331,13 @@ proc main() = of "reject": var rejectRes = initResults() reject(rejectRes, "tests/reject", p.cmdLineRest.string) + rejectSpecialTests(rejectRes, p.cmdLineRest.string) writeResults(rejectJson, rejectRes) of "compile": var compileRes = initResults() compile(compileRes, "tests/accept/compile/t*.nim", p.cmdLineRest.string) compile(compileRes, "tests/ecmas.nim", p.cmdLineRest.string) - compileRodFiles(compileRes, p.cmdLineRest.string) + compileSpecialTests(compileRes, p.cmdLineRest.string) writeResults(compileJson, compileRes) of "examples": var compileRes = readResults(compileJson) diff --git a/tests/threads/tthreadanalysis2.nim b/tests/threads/tthreadanalysis2.nim index bc071b478..07f0e61fd 100755 --- a/tests/threads/tthreadanalysis2.nim +++ b/tests/threads/tthreadanalysis2.nim @@ -40,7 +40,7 @@ proc threadFunc(interval: tuple[a, b: int]) {.thread.} = var r = buildTree(i) echoLeTree(r) # for local data root = buildTree(2) # BAD! - echoLeTree(root) # and the same for foreign data :-) + #echoLeTree(root) # and the same for foreign data :-) proc main = root = buildTree(5) diff --git a/tests/threads/tthreadanalysis3.nim b/tests/threads/tthreadanalysis3.nim new file mode 100644 index 000000000..d7a838fec --- /dev/null +++ b/tests/threads/tthreadanalysis3.nim @@ -0,0 +1,51 @@ +discard """ + file: "tthreadanalysis3.nim" + line: 35 + errormsg: "write to foreign heap" + cmd: "nimrod cc --hints:on --threads:on $# $#" +""" + +import os + +var + thr: array [0..5, TThread[tuple[a, b: int]]] + +proc doNothing() = nil + +type + PNode = ref TNode + TNode = object {.pure.} + le, ri: PNode + data: string + +var + root: PNode + +proc buildTree(depth: int): PNode = + if depth == 3: return nil + new(result) + result.le = buildTree(depth-1) + result.ri = buildTree(depth-1) + result.data = $depth + +proc echoLeTree(n: PNode) = + var it = n + while it != nil: + echo it.data + it = it.le + +proc threadFunc(interval: tuple[a, b: int]) {.thread.} = + doNothing() + for i in interval.a..interval.b: + var r = buildTree(i) + echoLeTree(r) # for local data + echoLeTree(root) # and the same for foreign data :-) + +proc main = + root = buildTree(5) + for i in 0..high(thr): + createThread(thr[i], threadFunc, (i*100, i*100+50)) + joinThreads(thr) + +main() + diff --git a/tests/threads/tthreadheapviolation1.nim b/tests/threads/tthreadheapviolation1.nim index 3cf7df7b5..cd35a44ca 100755 --- a/tests/threads/tthreadheapviolation1.nim +++ b/tests/threads/tthreadheapviolation1.nim @@ -1,6 +1,12 @@ +discard """ + line: 12 + errormsg: "write to foreign heap" + cmd: "nimrod cc --hints:on --threads:on $# $#" +""" + var global: string = "test string" - t: TThread[string] + t: TThread[void] proc horrible() {.thread.} = global = "string in thread local heap!" |