summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-11-19 02:05:16 +0100
committerAraq <rumpf_a@web.de>2011-11-19 02:05:16 +0100
commit62aa8bed3b6472e8acae530f7014e7e5b0c755b5 (patch)
tree59b52d3d7f1b310cc4ae5f6f58e4d1b3b7ccb47f
parenta497b4d1cf529b24ac469e701cb60e8d8b5fdefc (diff)
downloadNim-62aa8bed3b6472e8acae530f7014e7e5b0c755b5.tar.gz
tester: threading tests added
-rwxr-xr-xcompiler/semtempl.nim3
-rwxr-xr-xcompiler/types.nim8
-rwxr-xr-xlib/pure/collections/tables.nim22
-rw-r--r--tests/specials.nim10
-rwxr-xr-xtests/tester.nim18
-rwxr-xr-xtests/threads/tthreadanalysis2.nim2
-rw-r--r--tests/threads/tthreadanalysis3.nim51
-rwxr-xr-xtests/threads/tthreadheapviolation1.nim8
-rwxr-xr-xtodo.txt3
9 files changed, 96 insertions, 29 deletions
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index 80d6036c6..ee540c5d2 100755
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -92,7 +92,8 @@ proc symChoice(c: PContext, n: PNode, s: PSym): PNode =
     # appropriately
     result = newNodeIT(nkSymChoice, n.info, newTypeS(tyNone, c))
     a = initOverloadIter(o, c, n)
-    while a != nil: 
+    while a != nil:
+      incl(a.flags, sfUsed)
       addSon(result, newSymNode(a))
       a = nextOverloadIter(o, c, n)
 
diff --git a/compiler/types.nim b/compiler/types.nim
index 2a96f14af..31c94236a 100755
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -857,11 +857,11 @@ proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool =
   of tyOpenArray, tyVarargs: 
     result = (kind == skParam) and typeAllowedAux(marker, t.sons[0], skVar)
   of tySequence: 
-    result = typeAllowedAux(marker, t.sons[0], skVar) or
-        t.sons[0].kind == tyEmpty
+    result = t.sons[0].kind == tyEmpty or 
+        typeAllowedAux(marker, t.sons[0], skVar)
   of tyArray:
-    result = typeAllowedAux(marker, t.sons[1], skVar) or
-        t.sons[1].kind == tyEmpty
+    result = t.sons[1].kind == tyEmpty or
+        typeAllowedAux(marker, t.sons[1], skVar)
   of tyPtr, tyRef:
     result = typeAllowedAux(marker, t.sons[0], skVar)
   of tyArrayConstr, tyTuple, tySet, tyConst, tyMutable, tyIter, tyProxy: 
diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim
index 31b98a0cc..ccbfd9a40 100755
--- a/lib/pure/collections/tables.nim
+++ b/lib/pure/collections/tables.nim
@@ -127,16 +127,18 @@ template PutImpl() =
   else:
     AddImpl()
 
-template HasKeyOrPutImpl() =
-  var index = RawGet(t, key)
-  if index >= 0:
-    t.data[index].val = val
-    result = true
-  else:
-    if mustRehash(len(t.data), t.counter): Enlarge(t)
-    RawInsert(t, t.data, key, val)
-    inc(t.counter)
-    result = false
+when false:
+  # not yet used:
+  template HasKeyOrPutImpl() =
+    var index = RawGet(t, key)
+    if index >= 0:
+      t.data[index].val = val
+      result = true
+    else:
+      if mustRehash(len(t.data), t.counter): Enlarge(t)
+      RawInsert(t, t.data, key, val)
+      inc(t.counter)
+      result = false
 
 proc `[]=`*[A, B](t: var TTable[A, B], key: A, val: B) =
   ## puts a (key, value)-pair into `t`.
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!"
diff --git a/todo.txt b/todo.txt
index a85a0c5c3..f0620de1a 100755
--- a/todo.txt
+++ b/todo.txt
@@ -2,8 +2,7 @@ Version 0.8.14
 ==============
 
 - optimize unused constants away (affected by HLO)
-- fix actors.nim: fix thread local storage emulation; 
-  add thread tests to test suite
+- fix thread tests
 
 version 0.9.0
 =============