summary refs log tree commit diff stats
path: root/tests/parallel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parallel')
-rw-r--r--tests/parallel/t10913.nim20
-rw-r--r--tests/parallel/t7535.nim11
-rw-r--r--tests/parallel/t9691.nim9
-rw-r--r--tests/parallel/tarray_of_channels.nim1
-rw-r--r--tests/parallel/tblocking_channel.nim6
-rw-r--r--tests/parallel/tconvexhull.nim10
-rw-r--r--tests/parallel/tdeepcopy.nim61
-rw-r--r--tests/parallel/tdeepcopy2.nim7
-rw-r--r--tests/parallel/tdisjoint_slice1.nim58
-rw-r--r--tests/parallel/tdisjoint_slice2.nim40
-rw-r--r--tests/parallel/tflowvar.nim2
-rw-r--r--tests/parallel/tgc_unsafe2.nim7
-rw-r--r--tests/parallel/tguard1.nim2
-rw-r--r--tests/parallel/tinvalid_array_bounds.nim3
-rw-r--r--tests/parallel/tlet_spawn.nim11
-rw-r--r--tests/parallel/tmissing_deepcopy.nim7
-rw-r--r--tests/parallel/tnon_disjoint_slice1.nim3
-rw-r--r--tests/parallel/tparfind.nim1
-rw-r--r--tests/parallel/tpi.nim1
-rw-r--r--tests/parallel/tsendtwice.nim27
-rw-r--r--tests/parallel/tsimple_array_checks.nim12
-rw-r--r--tests/parallel/tsysspawn.nim37
-rw-r--r--tests/parallel/tuseafterdef.nim5
-rw-r--r--tests/parallel/twaitany.nim9
24 files changed, 238 insertions, 112 deletions
diff --git a/tests/parallel/t10913.nim b/tests/parallel/t10913.nim
new file mode 100644
index 000000000..191939100
--- /dev/null
+++ b/tests/parallel/t10913.nim
@@ -0,0 +1,20 @@
+discard """
+  matrix: "--mm:refc; --mm:orc"
+  errormsg: "'spawn'ed function cannot have a 'typed' or 'untyped' parameter"
+"""
+
+# bug #10913
+
+import threadpool
+
+proc useParallel*[T](unused: T) =
+  # use a generic T here to show the problem.
+  {.push experimental: "parallel".}
+  parallel:
+    for i in 0..4:
+      spawn echo "echo in parallel"
+  sync()
+  
+  {.pop.}
+
+useParallel(1)
diff --git a/tests/parallel/t7535.nim b/tests/parallel/t7535.nim
new file mode 100644
index 000000000..7817a1c9e
--- /dev/null
+++ b/tests/parallel/t7535.nim
@@ -0,0 +1,11 @@
+discard """
+  matrix: "--mm:refc; --mm:orc"
+  errormsg: "'spawn' takes a call expression; got: proc (x: uint32) = echo [x]"
+"""
+
+import threadpool
+
+# bug #7535
+proc print_parallel_nok(r: uint32) =
+  for x in 0..r:
+    spawn (proc (x: uint32) = echo x)
diff --git a/tests/parallel/t9691.nim b/tests/parallel/t9691.nim
new file mode 100644
index 000000000..254f03416
--- /dev/null
+++ b/tests/parallel/t9691.nim
@@ -0,0 +1,9 @@
+discard """
+  matrix: "--mm:refc; --mm:orc"
+  errormsg: "'spawn'ed function cannot have a 'typed' or 'untyped' parameter"
+"""
+
+# bug #9691
+
+import threadpool
+spawn echo()
diff --git a/tests/parallel/tarray_of_channels.nim b/tests/parallel/tarray_of_channels.nim
index 5139920ea..9479227aa 100644
--- a/tests/parallel/tarray_of_channels.nim
+++ b/tests/parallel/tarray_of_channels.nim
@@ -8,6 +8,7 @@ test
 test
 test
 '''
+disabled: "openbsd"
 """
 
 # bug #2257
diff --git a/tests/parallel/tblocking_channel.nim b/tests/parallel/tblocking_channel.nim
index 8b8b49454..f3ccd166a 100644
--- a/tests/parallel/tblocking_channel.nim
+++ b/tests/parallel/tblocking_channel.nim
@@ -1,6 +1,8 @@
 discard """
 output: ""
+disabled: "freebsd" # see #15725
 """
+
 import threadpool, os
 
 var chan: Channel[int]
@@ -25,11 +27,11 @@ proc emitter() =
 
 spawn emitter()
 # At this point emitter should be stuck in `send`
-sleep(100) # Sleep a bit to ensure that it is still stuck
+sleep(50) # Sleep a bit to ensure that it is still stuck
 doAssert(not msgSent)
 
 spawn receiver()
-sleep(100) # Sleep a bit to let receicer consume the messages
+sleep(50) # Sleep a bit to let receicer consume the messages
 doAssert(msgSent) # Sender should be unblocked
 
 doAssert(chan.trySend(4))
diff --git a/tests/parallel/tconvexhull.nim b/tests/parallel/tconvexhull.nim
index 184a131a2..a89aa910b 100644
--- a/tests/parallel/tconvexhull.nim
+++ b/tests/parallel/tconvexhull.nim
@@ -1,8 +1,7 @@
 discard """
+  matrix: "--mm:refc"
   output: '''
 '''
-
-ccodeCheck: "\\i ! @'deepCopy(' .*"
 """
 
 # parallel convex hull for Nim bigbreak
@@ -51,12 +50,11 @@ proc convex_hull[T](points: var seq[T], cmp: proc(x, y: T): int {.closure.}) : s
       ul[k] = spawn half[T](points, k == 0)
   result = concat(^ul[0], ^ul[1])
 
-var s = map(toSeq(0..99999), proc(x: int): Point = (float(x div 1000), float(x mod 1000)))
+var s = map(toSeq(0..9999), proc(x: int): Point = (float(x div 100), float(x mod 100)))
 # On some runs, this pool size reduction will set the "shutdown" attribute on the
 # worker thread that executes our spawned task, before we can read the flowvars.
 setMaxPoolSize 2
 
-#echo convex_hull[Point](s, cmpPoint)
-for i in 0..5:
+for i in 0..2:
   doAssert convex_hull[Point](s, cmpPoint) ==
-      @[(0.0, 0.0), (99.0, 0.0), (99.0, 999.0), (0.0, 999.0)]
+      @[(0.0, 0.0), (99.0, 0.0), (99.0, 99.0), (0.0, 99.0)]
diff --git a/tests/parallel/tdeepcopy.nim b/tests/parallel/tdeepcopy.nim
index 84e2edf3f..96ca15ca3 100644
--- a/tests/parallel/tdeepcopy.nim
+++ b/tests/parallel/tdeepcopy.nim
@@ -1,18 +1,55 @@
 discard """
-  output: '''13 abc'''
+  matrix: "--mm:refc"
+  output: '''
+13 abc
+called deepCopy for int
+called deepCopy for int
+done999 999
+'''
 """
 
-type
-  PBinaryTree = ref object
-    le, ri: PBinaryTree
-    value: int
+import threadpool
 
+block one:
+  type
+    PBinaryTree = ref object
+      le, ri: PBinaryTree
+      value: int
 
-proc main =
-  var x: PBinaryTree
-  deepCopy(x, PBinaryTree(ri: PBinaryTree(le: PBinaryTree(value: 13))))
-  var y: string
-  deepCopy y, "abc"
-  echo x.ri.le.value, " ", y
+  proc main =
+    var x: PBinaryTree
+    deepCopy(x, PBinaryTree(ri: PBinaryTree(le: PBinaryTree(value: 13))))
+    var y: string
+    deepCopy y, "abc"
+    echo x.ri.le.value, " ", y
 
-main()
+  main()
+
+
+block two:
+  type
+    Bar[T] = object
+      x: T
+
+  proc `=deepCopy`[T](b: ref Bar[T]): ref Bar[T] =
+    result.new
+    result.x = b.x
+    when T is int:
+      echo "called deepCopy for int"
+    else:
+      echo "called deepCopy for something else"
+
+  proc foo(b: ref Bar[int]): int = 999
+
+# test that the disjoint checker deals with 'a = spawn f(); g = spawn f()':
+
+  proc main =
+    var dummy: ref Bar[int]
+    new(dummy)
+    dummy.x = 44
+    #parallel:
+    let f = spawn foo(dummy)
+    let b = spawn foo(dummy)
+    echo "done", ^f, " ", ^b
+
+  main()
diff --git a/tests/parallel/tdeepcopy2.nim b/tests/parallel/tdeepcopy2.nim
index 2ad623ed1..e8305173d 100644
--- a/tests/parallel/tdeepcopy2.nim
+++ b/tests/parallel/tdeepcopy2.nim
@@ -1,7 +1,10 @@
 discard """
-  output: '''called deepCopy for int
+  matrix: "--mm:refc"
+  output: '''
 called deepCopy for int
-done999 999'''
+called deepCopy for int
+done999 999
+'''
 """
 
 import threadpool
diff --git a/tests/parallel/tdisjoint_slice1.nim b/tests/parallel/tdisjoint_slice1.nim
index c1d0e52f8..6892e7383 100644
--- a/tests/parallel/tdisjoint_slice1.nim
+++ b/tests/parallel/tdisjoint_slice1.nim
@@ -1,21 +1,51 @@
 discard """
+  matrix: "--mm:refc"
   outputsub: "EVEN 28"
 """
 
-import threadpool
+import threadpool, locks
 
-proc odd(a: int) =  echo "ODD  ", a
-proc even(a: int) = echo "EVEN ", a
+block one:
+  proc odd(a: int) =  echo "ODD  ", a
+  proc even(a: int) = echo "EVEN ", a
 
-proc main() =
-  var a: array[0..30, int]
-  for i in low(a)..high(a): a[i] = i
-  parallel:
-    var i = 0
-    while i <= 29:
-      spawn even(a[i])
-      spawn odd(a[i+1])
-      inc i, 2
-      # is correct here
+  proc main() =
+    var a: array[0..30, int]
+    for i in low(a)..high(a): a[i] = i
+    parallel:
+      var i = 0
+      while i <= 29:
+        spawn even(a[i])
+        spawn odd(a[i+1])
+        inc i, 2
+        # is correct here
 
-main()
+  main()
+
+
+block two:
+  var echoLock: Lock
+  initLock echoLock
+
+  proc f(a: openArray[int]) =
+    for x in a:
+      withLock echoLock:
+        echo x
+
+  proc f(a: int) =
+    withLock echoLock:
+      echo a
+
+  proc main() =
+    var a: array[0..9, int] = [0,1,2,3,4,5,6,7,8,9]
+    parallel:
+      spawn f(a[0..2])
+      #spawn f(a[16..30])
+      var i = 3
+      while i <= 8:
+        spawn f(a[i])
+        spawn f(a[i+1])
+        inc i, 2
+        # is correct here
+
+  main()
diff --git a/tests/parallel/tdisjoint_slice2.nim b/tests/parallel/tdisjoint_slice2.nim
deleted file mode 100644
index 25cb2362f..000000000
--- a/tests/parallel/tdisjoint_slice2.nim
+++ /dev/null
@@ -1,40 +0,0 @@
-discard """
-  output: '''0
-1
-2
-3
-4
-5
-6
-7
-8'''
-  sortoutput: true
-"""
-
-import threadpool, locks
-
-var echoLock: Lock
-initLock echoLock
-
-proc f(a: openArray[int]) =
-  for x in a:
-    withLock echoLock:
-      echo x
-
-proc f(a: int) =
-  withLock echoLock:
-    echo a
-
-proc main() =
-  var a: array[0..9, int] = [0,1,2,3,4,5,6,7,8,9]
-  parallel:
-    spawn f(a[0..2])
-    #spawn f(a[16..30])
-    var i = 3
-    while i <= 8:
-      spawn f(a[i])
-      spawn f(a[i+1])
-      inc i, 2
-      # is correct here
-
-main()
diff --git a/tests/parallel/tflowvar.nim b/tests/parallel/tflowvar.nim
index fd3aa326e..e44b29a87 100644
--- a/tests/parallel/tflowvar.nim
+++ b/tests/parallel/tflowvar.nim
@@ -1,9 +1,11 @@
 discard """
+  matrix: "--mm:refc"
   output: '''foobarfoobar
 bazbearbazbear
 
 1'''
   cmd: "nim $target --threads:on $options $file"
+  disabled: "openbsd"
 """
 
 import threadpool
diff --git a/tests/parallel/tgc_unsafe2.nim b/tests/parallel/tgc_unsafe2.nim
index 40af728fb..7d98dafcb 100644
--- a/tests/parallel/tgc_unsafe2.nim
+++ b/tests/parallel/tgc_unsafe2.nim
@@ -1,9 +1,8 @@
 discard """
   errormsg: "'consumer' is not GC-safe as it calls 'track'"
-  line: 28
-  nimout: '''tgc_unsafe2.nim(22, 6) Warning: 'trick' is not GC-safe as it accesses 'global' which is a global using GC'ed memory [GcUnsafe2]
-tgc_unsafe2.nim(26, 6) Warning: 'track' is not GC-safe as it calls 'trick' [GcUnsafe2]
-tgc_unsafe2.nim(28, 6) Error: 'consumer' is not GC-safe as it calls 'track'
+  nimout: '''tgc_unsafe2.nim(21, 6) Warning: 'trick' is not GC-safe as it accesses 'global' which is a global using GC'ed memory [GcUnsafe2]
+tgc_unsafe2.nim(25, 6) Warning: 'track' is not GC-safe as it calls 'trick' [GcUnsafe2]
+tgc_unsafe2.nim(27, 6) Error: 'consumer' is not GC-safe as it calls 'track'
 '''
 """
 
diff --git a/tests/parallel/tguard1.nim b/tests/parallel/tguard1.nim
index b1eb7e7c5..f4c92319b 100644
--- a/tests/parallel/tguard1.nim
+++ b/tests/parallel/tguard1.nim
@@ -5,7 +5,7 @@ output: "90"
 
 when false:
   template lock(a, b: ptr Lock; body: stmt) =
-    if cast[ByteAddress](a) < cast[ByteAddress](b):
+    if cast[int](a) < cast[int](b):
       pthread_mutex_lock(a)
       pthread_mutex_lock(b)
     else:
diff --git a/tests/parallel/tinvalid_array_bounds.nim b/tests/parallel/tinvalid_array_bounds.nim
index 4c6065fd6..8dc93c33f 100644
--- a/tests/parallel/tinvalid_array_bounds.nim
+++ b/tests/parallel/tinvalid_array_bounds.nim
@@ -1,5 +1,6 @@
 discard """
-  errormsg: "can prove: i + 1 > 30"
+  matrix: "--mm:refc"
+  errormsg: "cannot prove (i)..(i) disjoint from (i + 1)..(i + 1)"
   line: 21
 """
 
diff --git a/tests/parallel/tlet_spawn.nim b/tests/parallel/tlet_spawn.nim
index 62341d8f0..853ffc443 100644
--- a/tests/parallel/tlet_spawn.nim
+++ b/tests/parallel/tlet_spawn.nim
@@ -4,7 +4,7 @@ done999 999
 '''
 """
 
-import threadpool
+import std/[threadpool, os]
 
 proc foo(): int = 999
 
@@ -17,3 +17,12 @@ proc main =
   echo "done", f, " ", b
 
 main()
+
+# bug #13781
+proc thread(): string =
+  os.sleep(1000)
+  return "ok"
+
+var fv = spawn thread()
+sync()
+doAssert ^fv == "ok"
diff --git a/tests/parallel/tmissing_deepcopy.nim b/tests/parallel/tmissing_deepcopy.nim
index 94e027b60..ea77936ad 100644
--- a/tests/parallel/tmissing_deepcopy.nim
+++ b/tests/parallel/tmissing_deepcopy.nim
@@ -1,4 +1,5 @@
 discard """
+  matrix: "--mm:refc"
   ccodeCheck: "@'genericDeepCopy(' .*"
   action: compile
 """
@@ -26,10 +27,10 @@ proc greet(p:Person) =
     " friend:", p.friend.name, "(", cast[int](addr p.friend.name),") }"
 
 proc setup =
-  for i in 0 ..< 20:
+  for i in 0 ..< 10:
     people.add newPerson("Person" & $(i + 1))
-  for i in 0 ..< 20:
-    people[i].friend = people[19-i]
+  for i in 0 ..< 10:
+    people[i].friend = people[9-i]
 
 proc update =
   parallel:
diff --git a/tests/parallel/tnon_disjoint_slice1.nim b/tests/parallel/tnon_disjoint_slice1.nim
index 72d008bbd..51762187d 100644
--- a/tests/parallel/tnon_disjoint_slice1.nim
+++ b/tests/parallel/tnon_disjoint_slice1.nim
@@ -1,6 +1,7 @@
 discard """
+  matrix: "--mm:refc"
   errormsg: "cannot prove (i)..(i) disjoint from (i + 1)..(i + 1)"
-  line: 20
+  line: 21
 """
 
 import threadpool
diff --git a/tests/parallel/tparfind.nim b/tests/parallel/tparfind.nim
index 4b3610c67..cf1bc9336 100644
--- a/tests/parallel/tparfind.nim
+++ b/tests/parallel/tparfind.nim
@@ -1,4 +1,5 @@
 discard """
+  matrix: "--mm:refc"
   output: "500"
 """
 
diff --git a/tests/parallel/tpi.nim b/tests/parallel/tpi.nim
index 1abed6f23..cd965d585 100644
--- a/tests/parallel/tpi.nim
+++ b/tests/parallel/tpi.nim
@@ -1,4 +1,5 @@
 discard """
+  matrix: "--mm:refc"
   output: '''3.141792613595791
 3.141792613595791'''
 """
diff --git a/tests/parallel/tsendtwice.nim b/tests/parallel/tsendtwice.nim
index 0b3ce15a5..9f4a2e06e 100644
--- a/tests/parallel/tsendtwice.nim
+++ b/tests/parallel/tsendtwice.nim
@@ -1,25 +1,17 @@
 discard """
-  output: '''ob2 @[]
-ob @[]
-ob3 @[]
-3
-ob2 @[]
-ob @[]
-ob3 @[]
-'''
-  cmd: "nim c -r --threads:on $file"
+  matrix: "--mm:refc"
 """
 
 # bug #4776
 
-import tables
+import tables, algorithm
 
 type
   Base* = ref object of RootObj
     someSeq: seq[int]
-    baseData: array[400000, byte]
+    baseData: array[40000, byte]
   Derived* = ref object of Base
-    data: array[400000, byte]
+    data: array[40000, byte]
 
 type
   ThreadPool = ref object
@@ -35,20 +27,21 @@ globalTable.add("ob", d)
 globalTable.add("ob2", d)
 globalTable.add("ob3", d)
 
+proc `<`(x, y: seq[int]): bool = x.len < y.len
+proc kvs(t: TableRef[string, Base]): seq[(string, seq[int])] =
+  for k, v in t.pairs: result.add (k, v.someSeq)
+  result.sort
+
 proc testThread(channel: ptr TableChannel) {.thread.} =
   globalTable = channel[].recv()
-  for k, v in pairs globaltable:
-    echo k, " ", v.someSeq
   var myObj: Base
   deepCopy(myObj, globalTable["ob"])
   myObj.someSeq = newSeq[int](100)
   let table = channel[].recv() # same table
-  echo table.len
-  for k, v in mpairs table:
-    echo k, " ", v.someSeq
   assert(table.contains("ob")) # fails!
   assert(table.contains("ob2")) # fails!
   assert(table.contains("ob3")) # fails!
+  assert table.kvs == globalTable.kvs # Last to see above spot checks first
 
 var channel: TableChannel
 
diff --git a/tests/parallel/tsimple_array_checks.nim b/tests/parallel/tsimple_array_checks.nim
index 650b809e0..ab292f935 100644
--- a/tests/parallel/tsimple_array_checks.nim
+++ b/tests/parallel/tsimple_array_checks.nim
@@ -61,3 +61,15 @@ maino() # Doesn't work outside a proc
 
 when true:
   main()
+
+block two:
+  proc f(a: openArray[int]) =
+    discard
+
+  proc main() =
+    var a: array[0..9, int] = [0,1,2,3,4,5,6,7,8,9]
+    parallel:
+      spawn f(a[0..2])
+
+
+  main()
\ No newline at end of file
diff --git a/tests/parallel/tsysspawn.nim b/tests/parallel/tsysspawn.nim
index 7244a5ee6..b7ecd1264 100644
--- a/tests/parallel/tsysspawn.nim
+++ b/tests/parallel/tsysspawn.nim
@@ -1,7 +1,11 @@
 discard """
   output: '''4
-8'''
-  cmd: "nim $target --threads:on $options $file"
+8
+(a: 1)
+2
+2
+'''
+  matrix: "--mm:refc"
 """
 
 import threadpool
@@ -29,3 +33,32 @@ sync()
 
 echo x
 echo y
+
+
+#--------------------------------------------------------
+# issue #14014
+
+import threadpool
+
+type A = object
+    a: int
+
+proc f(t: typedesc): t =
+  t(a:1)
+
+let r = spawn f(A)
+echo ^r
+
+proc f2(x: static[int]): int =
+  x
+
+let r2 = spawn f2(2)
+echo ^r2
+
+type statint = static[int]
+
+proc f3(x: statint): int =
+  x
+
+let r3 = spawn f3(2)
+echo ^r3
diff --git a/tests/parallel/tuseafterdef.nim b/tests/parallel/tuseafterdef.nim
index 833c72a0a..64f835a1b 100644
--- a/tests/parallel/tuseafterdef.nim
+++ b/tests/parallel/tuseafterdef.nim
@@ -1,6 +1,9 @@
 discard """
+  matrix: "--mm:refc"
+  disabled: true
   errormsg: "(k)..(k) not disjoint from (k)..(k)"
-  line: 23
+  line: 24
+  action: compile
 """
 
 # bug #1597
diff --git a/tests/parallel/twaitany.nim b/tests/parallel/twaitany.nim
index 2be3d432f..d57c5f40f 100644
--- a/tests/parallel/twaitany.nim
+++ b/tests/parallel/twaitany.nim
@@ -1,9 +1,10 @@
 discard """
+  matrix: "--mm:refc"
   output: '''true'''
 """
 
 # bug #7638
-import threadpool, os, strformat
+import threadpool, os
 
 proc timer(d: int): int =
   #echo fmt"sleeping {d}"
@@ -11,7 +12,7 @@ proc timer(d: int): int =
   #echo fmt"done {d}"
   return d
 
-var durations = [1000, 1500, 2000, 2500, 3000]
+var durations = [1000, 1500, 2000]
 var tasks: seq[FlowVarBase] = @[]
 var results: seq[int] = @[]
 
@@ -25,11 +26,9 @@ while index != -1:
   #echo repr results
   index = blockUntilAny(tasks)
 
-doAssert results.len == 5
+doAssert results.len == 3
 doAssert 1000 in results
 doAssert 1500 in results
 doAssert 2000 in results
-doAssert 2500 in results
-doAssert 3000 in results
 sync()
 echo "true"