aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/appendud.lua4
-rw-r--r--tests/atexit.lua4
-rw-r--r--tests/basic.lua86
-rw-r--r--tests/cancel.lua12
-rw-r--r--tests/cyclic.lua6
-rw-r--r--tests/deadlock.lua2
-rw-r--r--tests/ehynes.lua2
-rw-r--r--tests/errhangtest.lua9
-rw-r--r--tests/error.lua13
-rw-r--r--tests/fibonacci.lua2
-rw-r--r--tests/fifo.lua4
-rw-r--r--tests/finalizer.lua6
-rw-r--r--tests/func_is_string.lua15
-rw-r--r--tests/hangtest.lua2
-rw-r--r--tests/irayo_closure.lua4
-rw-r--r--tests/irayo_recursive.lua2
-rw-r--r--tests/keeper.lua38
-rw-r--r--tests/lanes_as_upvalue.lua2
-rw-r--r--tests/launchtest.lua6
-rw-r--r--tests/linda_perf.lua25
-rw-r--r--tests/manual_register.lua2
-rw-r--r--tests/nameof.lua2
-rw-r--r--tests/objects.lua2
-rw-r--r--tests/parallel_os_calls.lua16
-rw-r--r--tests/perftest.lua8
-rw-r--r--tests/pingpong.lua12
-rw-r--r--tests/protect_allocator.lua4
-rw-r--r--tests/protectproxy.lua2
-rw-r--r--tests/recursive.lua2
-rw-r--r--tests/require.lua4
-rw-r--r--tests/rupval.lua8
-rw-r--r--tests/tobeclosed.lua19
-rw-r--r--tests/track_lanes.lua8
33 files changed, 174 insertions, 159 deletions
diff --git a/tests/appendud.lua b/tests/appendud.lua
index f510c8b..2a8c8ce 100644
--- a/tests/appendud.lua
+++ b/tests/appendud.lua
@@ -42,14 +42,14 @@ function appendud(tab, ud)
42 -- ('tab' is passed over lanes by value, not by reference) 42 -- ('tab' is passed over lanes by value, not by reference)
43end 43end
44 44
45local t,err= lanes.gen( "base,io", appendud )( _tab, _ud ) -- create & launch a thread 45local t,err= lanes.gen( "base,io", { name = 'auto'}, appendud )( _tab, _ud ) -- create & launch a thread
46assert(t) 46assert(t)
47assert(not err) 47assert(not err)
48 48
49-- test 49-- test
50-- print("t:join()") 50-- print("t:join()")
51a,b,c = t[1],t[2],t[3] -- Need to explicitly wait for the thread, since 'ipairs()' does not 51a,b,c = t[1],t[2],t[3] -- Need to explicitly wait for the thread, since 'ipairs()' does not
52--a,b,c = t:join() -- Need to explicitly wait for the thread, since 'ipairs()' does not 52--r,a,b,c = t:join() -- Need to explicitly wait for the thread, since 'ipairs()' does not
53 -- value the '__index' metamethod (wouldn't it be cool if it did..?) 53 -- value the '__index' metamethod (wouldn't it be cool if it did..?)
54 54
55print(a,b,c) 55print(a,b,c)
diff --git a/tests/atexit.lua b/tests/atexit.lua
index 9fc3070..ba10d3b 100644
--- a/tests/atexit.lua
+++ b/tests/atexit.lua
@@ -16,8 +16,8 @@ local g = function()
16 print "User cancellation detected!" 16 print "User cancellation detected!"
17end 17end
18 18
19local genF = lanes.gen( "", {globals = {threadName = "mylane"}}, f) 19local genF = lanes.gen( "", {name = 'auto', globals = {threadName = "mylane"}}, f)
20local genG = lanes.gen( "", g) 20local genG = lanes.gen( "", { name = 'auto'}, g)
21 21
22 22
23-- launch a good batch of free running lanes 23-- launch a good batch of free running lanes
diff --git a/tests/basic.lua b/tests/basic.lua
index 820d3c8..f393175 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -15,7 +15,7 @@ local lanes = require_lanes_result_1
15local require_assert_result_1, require_assert_result_2 = require "assert" -- assert.fails() 15local require_assert_result_1, require_assert_result_2 = require "assert" -- assert.fails()
16print("require_assert_result:", require_assert_result_1, require_assert_result_2) 16print("require_assert_result:", require_assert_result_1, require_assert_result_2)
17 17
18local lanes_gen= assert(lanes.gen) 18local lanes_gen assert(lanes.gen)
19local lanes_linda = assert(lanes.linda) 19local lanes_linda = assert(lanes.linda)
20 20
21local tostring= assert(tostring) 21local tostring= assert(tostring)
@@ -86,7 +86,7 @@ local function task(a, b, c)
86 return v, hey 86 return v, hey
87end 87end
88 88
89local task_launch= lanes_gen("", { globals={hey=true}, gc_cb = gc_cb}, task) 89local task_launch= lanes.gen("", { name = 'auto', globals={hey=true}, gc_cb = gc_cb }, task)
90 -- base stdlibs, normal priority 90 -- base stdlibs, normal priority
91 91
92-- 'task_launch' is a factory of multithreaded tasks, we can launch several: 92-- 'task_launch' is a factory of multithreaded tasks, we can launch several:
@@ -126,7 +126,7 @@ collectgarbage()
126 126
127PRINT("\n\n", "---=== Tasking (cancelling) ===---", "\n\n") 127PRINT("\n\n", "---=== Tasking (cancelling) ===---", "\n\n")
128 128
129local task_launch2= lanes_gen("", { globals={hey=true}, gc_cb = gc_cb}, task) 129local task_launch2= lanes.gen("", { name = 'auto', globals={hey=true}, gc_cb = gc_cb }, task)
130 130
131local N=999999999 131local N=999999999
132local lane9= task_launch2(1,N,1) -- huuuuuuge... 132local lane9= task_launch2(1,N,1) -- huuuuuuge...
@@ -163,7 +163,7 @@ PRINT(" "..st)
163assert(st == "cancelled", "st is '" .. st .. "' instead of 'cancelled'") 163assert(st == "cancelled", "st is '" .. st .. "' instead of 'cancelled'")
164 164
165-- cancellation of lanes waiting on a linda 165-- cancellation of lanes waiting on a linda
166local limited = lanes_linda("limited") 166local limited = lanes_linda{name = "limited"}
167assert.fails(function() limited:limit("key", -1) end) 167assert.fails(function() limited:limit("key", -1) end)
168assert.failsnot(function() limited:limit("key", 1) end) 168assert.failsnot(function() limited:limit("key", 1) end)
169-- [[################################################ 169-- [[################################################
@@ -173,42 +173,51 @@ for k, v in pairs(limited:dump()) do
173end 173end
174local wait_send = function() 174local wait_send = function()
175 local a,b 175 local a,b
176 set_finalizer(function() print("wait_send", a, b) end) 176 set_finalizer(function(err, stack_tbl) print("wait_send", a, b, " -> ", tostring(err)) end)
177 print("in wait_send")
177 a,b = limited:send("key", "bybye") -- infinite timeout, returns only when lane is cancelled 178 a,b = limited:send("key", "bybye") -- infinite timeout, returns only when lane is cancelled
178end 179end
179 180
180local wait_send_lane = lanes.gen("*", wait_send)() 181local wait_send_lane = lanes.gen("*", { name = 'auto' }, wait_send)()
181repeat until wait_send_lane.status == "waiting" 182repeat
182print "wait_send_lane is waiting" 183 io.stderr:write('!')
184 -- currently mingw64 builds can deadlock if we cancel the lane too early (before the linda blocks, at it causes the linda condvar not to be signalled)
185 lanes.sleep(0.1)
186until wait_send_lane.status == "waiting"
187PRINT "wait_send_lane is waiting"
183wait_send_lane:cancel() -- hard cancel, 0 timeout 188wait_send_lane:cancel() -- hard cancel, 0 timeout
184repeat until wait_send_lane.status == "cancelled" 189repeat until wait_send_lane.status == "cancelled"
185print "wait_send_lane is cancelled" 190PRINT "wait_send_lane is cancelled"
186--################################################]] 191--################################################]]
187local wait_receive = function() 192local wait_receive = function()
188 local k, v 193 local k, v
189 set_finalizer(function() print("wait_receive", k, v) end) 194 set_finalizer(function(err, stack_tbl) print("wait_receive", k, v, " -> ", tostring(err)) end)
190 k, v = limited:receive("dummy") -- infinite timeout, returns only when lane is cancelled 195 k, v = limited:receive("dummy") -- infinite timeout, returns only when lane is cancelled
191end 196end
192 197
193local wait_receive_lane = lanes.gen("*", wait_receive)() 198local wait_receive_lane = lanes.gen("*", { name = 'auto' }, wait_receive)()
194repeat until wait_receive_lane.status == "waiting" 199repeat
195print "wait_receive_lane is waiting" 200 io.stderr:write('!')
201 -- currently mingw64 builds can deadlock if we cancel the lane too early (before the linda blocks, at it causes the linda condvar not to be signalled)
202 lanes.sleep(0.1)
203until wait_receive_lane.status == "waiting"
204PRINT "wait_receive_lane is waiting"
196wait_receive_lane:cancel() -- hard cancel, 0 timeout 205wait_receive_lane:cancel() -- hard cancel, 0 timeout
197repeat until wait_receive_lane.status == "cancelled" 206repeat until wait_receive_lane.status == "cancelled"
198print "wait_receive_lane is cancelled" 207PRINT "wait_receive_lane is cancelled"
199--################################################]] 208--################################################]]
200local wait_receive_batched = function() 209local wait_receive_batched = function()
201 local k, v1, v2 210 local k, v1, v2
202 set_finalizer(function() print("wait_receive_batched", k, v1, v2) end) 211 set_finalizer(function() print("wait_receive_batched", k, v1, v2) end)
203 k, v1, v2 = limited:receive(limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled 212 k, v1, v2 = limited:receive_batched("dummy", 2) -- infinite timeout, returns only when lane is cancelled
204end 213end
205 214
206local wait_receive_batched_lane = lanes.gen("*", wait_receive_batched)() 215local wait_receive_batched_lane = lanes.gen("*", { name = 'auto' }, wait_receive_batched)()
207repeat until wait_receive_batched_lane.status == "waiting" 216repeat until wait_receive_batched_lane.status == "waiting"
208print "wait_receive_batched_lane is waiting" 217PRINT "wait_receive_batched_lane is waiting"
209wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout 218wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout
210repeat until wait_receive_batched_lane.status == "cancelled" 219repeat until wait_receive_batched_lane.status == "cancelled"
211print "wait_receive_batched_lane is cancelled" 220PRINT "wait_receive_batched_lane is cancelled"
212--################################################]] 221--################################################]]
213 222
214-- ################################################################################################## 223-- ##################################################################################################
@@ -246,7 +255,7 @@ local chunk= function(linda)
246 WR("chunk ", "Lane ends!\n") 255 WR("chunk ", "Lane ends!\n")
247end 256end
248 257
249local linda = lanes_linda("communications") 258local linda = lanes_linda{name = "communications"}
250assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications") 259assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications")
251 -- 260 --
252 -- ["->"] master -> slave 261 -- ["->"] master -> slave
@@ -264,7 +273,7 @@ local b,x,y,z,w = linda:get("<->", 4)
264assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil) 273assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil)
265local k, x = linda:receive("<->") 274local k, x = linda:receive("<->")
266assert(k == "<->" and x == "x") 275assert(k == "<->" and x == "x")
267local k,y,z = linda:receive(linda.batched, "<->", 2) 276local k,y,z = linda:receive_batched("<->", 2)
268assert(k == "<->" and y == "y" and z == "z") 277assert(k == "<->" and y == "y" and z == "z")
269linda:set("<->") 278linda:set("<->")
270local b,x,y,z,w = linda:get("<->", 4) 279local b,x,y,z,w = linda:get("<->", 4)
@@ -275,7 +284,7 @@ local function PEEK(...) return linda:get("<-", ...) end
275local function SEND(...) local _res, _err = linda:send("->", ...) assert(_res == true and _err == nil) end 284local function SEND(...) local _res, _err = linda:send("->", ...) assert(_res == true and _err == nil) end
276local function RECEIVE() local k,v = linda:receive(1, "<-") return v end 285local function RECEIVE() local k,v = linda:receive(1, "<-") return v end
277 286
278local comms_lane = lanes_gen("io", {gc_cb = gc_cb, name = "auto"}, chunk)(linda) -- prepare & launch 287local comms_lane = lanes.gen("io", { name = 'auto', gc_cb = gc_cb }, chunk)(linda) -- prepare & launch
279 288
280SEND(1); WR("main ", "1 sent\n") 289SEND(1); WR("main ", "1 sent\n")
281SEND(2); WR("main ", "2 sent\n") 290SEND(2); WR("main ", "2 sent\n")
@@ -355,7 +364,7 @@ local function coro_f(_x)
355 return true 364 return true
356end 365end
357 366
358assert.fails(function() lanes_gen("xxx", {gc_cb = gc_cb}, io_os_f) end) 367assert.fails(function() lanes_gen("xxx", {name = 'auto', gc_cb = gc_cb }, io_os_f) end)
359 368
360local stdlib_naming_tests = 369local stdlib_naming_tests =
361{ 370{
@@ -371,7 +380,7 @@ local stdlib_naming_tests =
371} 380}
372 381
373for _, t in ipairs(stdlib_naming_tests) do 382for _, t in ipairs(stdlib_naming_tests) do
374 local f= lanes_gen(t[1], {gc_cb = gc_cb}, t[2]) -- any delimiter will do 383 local f= lanes.gen(t[1], { name = 'auto', gc_cb = gc_cb }, t[2]) -- any delimiter will do
375 assert(f(t[1])[1]) 384 assert(f(t[1])[1])
376end 385end
377 386
@@ -386,7 +395,7 @@ PRINT("\n\n", "---=== Comms criss cross ===---", "\n\n")
386 395
387-- We make two identical lanes, which are using the same Linda channel. 396-- We make two identical lanes, which are using the same Linda channel.
388-- 397--
389local tc= lanes_gen("io", {gc_cb = gc_cb}, 398local tc = lanes.gen("io", { name = 'auto', gc_cb = gc_cb },
390 function(linda, ch_in, ch_out) 399 function(linda, ch_in, ch_out)
391 lane_threadname("criss cross " .. ch_in .. " -> " .. ch_out) 400 lane_threadname("criss cross " .. ch_in .. " -> " .. ch_out)
392 local function STAGE(str) 401 local function STAGE(str)
@@ -401,7 +410,7 @@ local tc= lanes_gen("io", {gc_cb = gc_cb},
401 end 410 end
402) 411)
403 412
404local linda= lanes_linda("criss cross") 413local linda= lanes_linda{name = "criss cross"}
405 414
406local a,b= tc(linda, "A","B"), tc(linda, "B","A") -- launching two lanes, twisted comms 415local a,b= tc(linda, "A","B"), tc(linda, "B","A") -- launching two lanes, twisted comms
407 416
@@ -437,7 +446,7 @@ local function chunk2(linda)
437 assert(config.strip_functions and info.short_src=="?" or string.match(info.short_src, "^.*basic.lua$"), "bad info.short_src") 446 assert(config.strip_functions and info.short_src=="?" or string.match(info.short_src, "^.*basic.lua$"), "bad info.short_src")
438 -- These vary so let's not be picky (they're there..) 447 -- These vary so let's not be picky (they're there..)
439 -- 448 --
440 assert(info.linedefined == 422, "bad linedefined") -- start of 'chunk2' 449 assert(info.linedefined == 431, "bad linedefined") -- start of 'chunk2'
441 assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo' 450 assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo'
442 assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2' 451 assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2'
443 local k,func= linda:receive("down") 452 local k,func= linda:receive("down")
@@ -452,15 +461,15 @@ local function chunk2(linda)
452 linda:send("up", function() return ":)" end, "ok2") 461 linda:send("up", function() return ":)" end, "ok2")
453end 462end
454 463
455local linda = lanes_linda("auto") 464local linda = lanes_linda{name = "auto"}
456local t2= lanes_gen("debug,string,io", {gc_cb = gc_cb}, chunk2)(linda) -- prepare & launch 465local t2 = lanes.gen("debug,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch
457linda:send("down", function(linda) linda:send("up", "ready!") end, 466linda:send("down", function(linda) linda:send("up", "ready!") end,
458 "ok") 467 "ok")
459-- wait to see if the tiny function gets executed 468-- wait to see if the tiny function gets executed
460-- 469--
461local k,s= linda:receive(1, "up") 470local k,s= linda:receive(1, "up")
462if t2.status == "error" then 471if t2.status == "error" then
463 print("t2 error: " , t2:join()) 472 PRINT("t2 error: " , t2:join())
464end 473end
465PRINT(s) 474PRINT(s)
466assert(s=="ready!") 475assert(s=="ready!")
@@ -486,7 +495,7 @@ PRINT("\n\n", "---=== :join test ===---", "\n\n")
486-- (unless [1..n] has been read earlier, in which case it would seemingly 495-- (unless [1..n] has been read earlier, in which case it would seemingly
487-- work). 496-- work).
488 497
489local S= lanes_gen("table", {gc_cb = gc_cb}, 498local S = lanes.gen("table", { name = 'auto', gc_cb = gc_cb },
490 function(arg) 499 function(arg)
491 lane_threadname "join test lane" 500 lane_threadname "join test lane"
492 set_finalizer(function() end) 501 set_finalizer(function() end)
@@ -498,19 +507,20 @@ local S= lanes_gen("table", {gc_cb = gc_cb},
498 return (unpack or table.unpack)(aux) 507 return (unpack or table.unpack)(aux)
499end) 508end)
500 509
501h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values 510h = S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values
502-- wait a bit so that the lane has a chance to set its debug name 511-- wait a bit so that the lane has a chance to set its debug name
503SLEEP(0.5) 512SLEEP(0.5)
504print("joining with '" .. h:get_threadname() .. "'") 513print("joining with '" .. h:get_threadname() .. "'")
505local a,b,c,d= h:join() 514local r,a,b,c,d= h:join()
506if h.status == "error" then 515if h.status == "error" then
507 print(h:get_threadname(), "error: " , a, b, c, d) 516 print(h:get_threadname(), "error: " , r, a, b, c, d)
508else 517else
509 print(h:get_threadname(), a,b,c,d) 518 print(h:get_threadname(), r,a,b,c,d)
510 assert(a==14) 519 assert(r == true)
511 assert(b==13) 520 assert(a == 14)
512 assert(c==12) 521 assert(b == 13)
513 assert(d==nil) 522 assert(c == 12)
523 assert(d == nil)
514end 524end
515 525
516local nameof_type, nameof_name = lanes.nameof(print) 526local nameof_type, nameof_name = lanes.nameof(print)
diff --git a/tests/cancel.lua b/tests/cancel.lua
index 5862c85..66957c3 100644
--- a/tests/cancel.lua
+++ b/tests/cancel.lua
@@ -148,7 +148,7 @@ local protectedBody = function(...)
148 local paramLessClosure = function() laneBody(unpack(params)) end 148 local paramLessClosure = function() laneBody(unpack(params)) end
149 local status, message = xpcall(paramLessClosure, errorHandler) 149 local status, message = xpcall(paramLessClosure, errorHandler)
150 if status == false then 150 if status == false then
151 print(" error handler rethrowing '" .. (ce == message and "cancel_error"or tostring(message)) .. "'") 151 print(" protectedBody rethrowing '" .. (ce == message and "cancel_error" or tostring(message)) .. "'")
152 -- if the error isn't rethrown, the lane's finalizer won't get it 152 -- if the error isn't rethrown, the lane's finalizer won't get it
153 error(message) 153 error(message)
154 end 154 end
@@ -160,7 +160,7 @@ end
160if not next(which_tests) or which_tests.linda then 160if not next(which_tests) or which_tests.linda then
161 remaining_tests.linda = nil 161 remaining_tests.linda = nil
162 print "\n\n####################################################################\nbegin linda cancel test\n" 162 print "\n\n####################################################################\nbegin linda cancel test\n"
163 h = generator("*", laneBody)("receive", nil) -- start an infinite wait on the linda 163 h = generator("*", { name = 'auto' }, laneBody)("receive", nil) -- start an infinite wait on the linda
164 164
165 print "wait 1s" 165 print "wait 1s"
166 SLEEP(1) 166 SLEEP(1)
@@ -181,7 +181,7 @@ end
181if not next(which_tests) or which_tests.soft then 181if not next(which_tests) or which_tests.soft then
182 remaining_tests.soft = nil 182 remaining_tests.soft = nil
183 print "\n\n####################################################################\nbegin soft cancel test\n" 183 print "\n\n####################################################################\nbegin soft cancel test\n"
184 h = generator("*", protectedBody)("receive") -- start an infinite wait on the linda 184 h = generator("*", { name = 'auto' }, protectedBody)("receive") -- start an infinite wait on the linda
185 185
186 print "wait 1s" 186 print "wait 1s"
187 SLEEP(1) 187 SLEEP(1)
@@ -205,7 +205,7 @@ end
205if not next(which_tests) or which_tests.hook then 205if not next(which_tests) or which_tests.hook then
206 remaining_tests.hook = nil 206 remaining_tests.hook = nil
207 print "\n\n####################################################################\nbegin hook cancel test\n" 207 print "\n\n####################################################################\nbegin hook cancel test\n"
208 h = generator("*", protectedBody)("get", 300000) 208 h = generator("*", { name = 'auto' }, protectedBody)("get", 300000)
209 print "wait 2s" 209 print "wait 2s"
210 SLEEP(2) 210 SLEEP(2)
211 211
@@ -222,7 +222,7 @@ end
222if not next(which_tests) or which_tests.hard then 222if not next(which_tests) or which_tests.hard then
223 remaining_tests.hard = nil 223 remaining_tests.hard = nil
224 print "\n\n####################################################################\nbegin hard cancel test\n" 224 print "\n\n####################################################################\nbegin hard cancel test\n"
225 h = lanes.gen("*", protectedBody)("receive", nil) -- infinite timeout 225 h = lanes.gen("*", { name = 'auto' }, protectedBody)("receive", nil) -- infinite timeout
226 226
227 -- wait 2s before cancelling the lane 227 -- wait 2s before cancelling the lane
228 print "wait 2s" 228 print "wait 2s"
@@ -241,7 +241,7 @@ end
241if not next(which_tests) or which_tests.hard_unprotected then 241if not next(which_tests) or which_tests.hard_unprotected then
242 remaining_tests.hard_unprotected = nil 242 remaining_tests.hard_unprotected = nil
243 print "\n\n####################################################################\nbegin hard cancel test with unprotected lane body\n" 243 print "\n\n####################################################################\nbegin hard cancel test with unprotected lane body\n"
244 h = generator("*", laneBody)("receive", nil) 244 h = generator("*", { name = 'auto' }, laneBody)("receive", nil)
245 245
246 -- wait 2s before cancelling the lane 246 -- wait 2s before cancelling the lane
247 print "wait 2s" 247 print "wait 2s"
diff --git a/tests/cyclic.lua b/tests/cyclic.lua
index ed4bdba..ca4b9f5 100644
--- a/tests/cyclic.lua
+++ b/tests/cyclic.lua
@@ -31,7 +31,7 @@ local function lane1()
31 assert( b[1]==a ) 31 assert( b[1]==a )
32 return true 32 return true
33end 33end
34local L1= lanes.gen( "io", lane1 )() 34local L1= lanes.gen( "io", { name = 'auto' }, lane1 )()
35 -- ...running 35 -- ...running
36 36
37-- Getting the tables as arguments should also keep the linkage 37-- Getting the tables as arguments should also keep the linkage
@@ -42,7 +42,7 @@ local function lane2( aa, bb )
42 assert( bb[1]==aa ) 42 assert( bb[1]==aa )
43 return true 43 return true
44end 44end
45local L2= lanes.gen( "io", lane2 )( a, b ) 45local L2= lanes.gen( "io", { name = 'auto' }, lane2 )( a, b )
46 -- ...running 46 -- ...running
47 47
48-- Really unnecessary, but let's try a directly recursive table 48-- Really unnecessary, but let's try a directly recursive table
@@ -55,7 +55,7 @@ local function lane3( cc )
55 assert( cc and cc.a==cc ) 55 assert( cc and cc.a==cc )
56 return true 56 return true
57end 57end
58local L3= lanes.gen("io", lane3)(c) 58local L3= lanes.gen("io", { name = 'auto' }, lane3)(c)
59 59
60-- Without a wait, exit from the main lane will close the process 60-- Without a wait, exit from the main lane will close the process
61-- 61--
diff --git a/tests/deadlock.lua b/tests/deadlock.lua
index d028e83..9b93e3b 100644
--- a/tests/deadlock.lua
+++ b/tests/deadlock.lua
@@ -16,7 +16,7 @@ print "let's begin"
16local do_extra_stuff = true 16local do_extra_stuff = true
17 17
18if do_extra_stuff then 18if do_extra_stuff then
19 local linda = lanes.linda "deadlock_linda" 19 local linda = lanes.linda{name = "deadlock_linda"}
20 -- just something to make send() succeed and receive() fail 20 -- just something to make send() succeed and receive() fail
21 local payload = { io.flush } 21 local payload = { io.flush }
22 22
diff --git a/tests/ehynes.lua b/tests/ehynes.lua
index cdcd5a5..e4b56a5 100644
--- a/tests/ehynes.lua
+++ b/tests/ehynes.lua
@@ -16,7 +16,7 @@ end
16local linda = lanes.linda() 16local linda = lanes.linda()
17 17
18-- a linda message receiver 18-- a linda message receiver
19local receiver_gen = lanes.gen( 'base', 'os', 'string', 'io', 19local receiver_gen = lanes.gen( 'base', 'os', 'string', 'io', { name = 'auto' },
20 function (message_name) 20 function (message_name)
21 PRINT_FMT( 'receiver for message %s entered', message_name ) 21 PRINT_FMT( 'receiver for message %s entered', message_name )
22 local n = 1 22 local n = 1
diff --git a/tests/errhangtest.lua b/tests/errhangtest.lua
index fff0dee..5b3f0c0 100644
--- a/tests/errhangtest.lua
+++ b/tests/errhangtest.lua
@@ -19,7 +19,6 @@ end
19if true then 19if true then
20 print "\n#### reserved sentinels" 20 print "\n#### reserved sentinels"
21 print(pcall(linda.set, linda, lanes.cancel_error)) 21 print(pcall(linda.set, linda, lanes.cancel_error))
22 print(pcall(linda.set, linda, linda.batched))
23 local _count, _val = linda:get("test") 22 local _count, _val = linda:get("test")
24 assert(_count == 0 and _val == nil) 23 assert(_count == 0 and _val == nil)
25 print "OK" 24 print "OK"
@@ -28,13 +27,13 @@ end
28-- get/set a few values 27-- get/set a few values
29if true then 28if true then
30 print "\n#### set 3 -> receive batched" 29 print "\n#### set 3 -> receive batched"
31 assert.fails(function() linda:receive(linda.batched, "some key", -1, 1) end) 30 assert.fails(function() linda:receive_batched("some key", -1, 1) end)
32 assert.fails(function() linda:receive(linda.batched, "some key", 2, 1) end) 31 assert.fails(function() linda:receive_batched("some key", 2, 1) end)
33 assert.failsnot(function() linda:receive(0, linda.batched, "some key", 1, 3) end) 32 assert.failsnot(function() linda:receive_batched(0, "some key", 1, 3) end)
34 local fun = function() print "function test ok" end 33 local fun = function() print "function test ok" end
35 print(pcall(linda.set, linda, 'test', true, nil, fun)) 34 print(pcall(linda.set, linda, 'test', true, nil, fun))
36 -- read back the contents 35 -- read back the contents
37 local k,b,n,f = linda:receive(linda.batched, 'test', 3) 36 local k,b,n,f = linda:receive_batched('test', 3)
38 local _count, _val = linda:get("test") 37 local _count, _val = linda:get("test")
39 assert(_count == 0 and _val == nil) 38 assert(_count == 0 and _val == nil)
40 -- check they are ok 39 -- check they are ok
diff --git a/tests/error.lua b/tests/error.lua
index 243dd57..76ceea4 100644
--- a/tests/error.lua
+++ b/tests/error.lua
@@ -87,7 +87,7 @@ end
87--################################################################################################## 87--##################################################################################################
88 88
89local start_lane = function(error_reporting_mode_, error_value_, finalizer_, finalizer_error_value_) 89local start_lane = function(error_reporting_mode_, error_value_, finalizer_, finalizer_error_value_)
90 return lanes.gen("*", {error_trace_level = error_reporting_mode_}, lane_body)(error_value_, finalizer_, finalizer_error_value_) 90 return lanes.gen("*", { name = 'auto', error_trace_level = error_reporting_mode_ }, lane_body)(error_value_, finalizer_, finalizer_error_value_)
91end 91end
92 92
93--################################################################################################## 93--##################################################################################################
@@ -106,11 +106,11 @@ end
106 106
107local lane_error_as_string = "'lane error as string'" 107local lane_error_as_string = "'lane error as string'"
108local lane_error_as_table = setmetatable({"lane error as table"}, make_table_error_mt()) 108local lane_error_as_table = setmetatable({"lane error as table"}, make_table_error_mt())
109local lane_error_as_linda = lanes.linda("'lane error'") 109local lane_error_as_linda = lanes.linda{name = "'lane error'"}
110 110
111local finalizer_error_as_string = "'finalizer error as string'" 111local finalizer_error_as_string = "'finalizer error as string'"
112local finalizer_error_as_table = setmetatable({"finalizer error as table"}, make_table_error_mt()) 112local finalizer_error_as_table = setmetatable({"finalizer error as table"}, make_table_error_mt())
113local finalizer_error_as_linda = lanes.linda("'finalizer error'") 113local finalizer_error_as_linda = lanes.linda{name = "'finalizer error'"}
114 114
115local test_settings = {} 115local test_settings = {}
116local configure_tests = function() 116local configure_tests = function()
@@ -173,8 +173,7 @@ local do_error_catching_test = function(error_reporting_mode_, error_value_, fin
173 local h = start_lane(error_reporting_mode_, error_value_, finalizer_, finalizer_error_value_) 173 local h = start_lane(error_reporting_mode_, error_value_, finalizer_, finalizer_error_value_)
174 local ret,err,stack= h:join() -- wait for the lane (no automatic error propagation) 174 local ret,err,stack= h:join() -- wait for the lane (no automatic error propagation)
175 WR("Processing results for {", error_reporting_mode_, error_value_, finalizer_, finalizer_error_value_, "}") 175 WR("Processing results for {", error_reporting_mode_, error_value_, finalizer_, finalizer_error_value_, "}")
176 if err then 176 if ret == nil then
177 assert(ret == nil)
178 assert(error_reporting_mode_ == "minimal" or type(stack)=="table") -- only true if lane was configured with error_trace_level ~= "minimal" 177 assert(error_reporting_mode_ == "minimal" or type(stack)=="table") -- only true if lane was configured with error_trace_level ~= "minimal"
179 if err == error_value_ then 178 if err == error_value_ then
180 WR("Lane regular error: ", err) 179 WR("Lane regular error: ", err)
@@ -198,8 +197,8 @@ local do_error_catching_test = function(error_reporting_mode_, error_value_, fin
198 end 197 end
199 end 198 end
200 else -- no error 199 else -- no error
201 assert(ret == "success") 200 assert(ret == true and err == "success")
202 WR("No error in lane: ", ret) 201 WR("No error in lane: ", err, ret)
203 end 202 end
204 WR "TEST OK" 203 WR "TEST OK"
205end 204end
diff --git a/tests/fibonacci.lua b/tests/fibonacci.lua
index 7885ae6..2c043c3 100644
--- a/tests/fibonacci.lua
+++ b/tests/fibonacci.lua
@@ -44,7 +44,7 @@ local function fib( n )
44 else 44 else
45 -- Splits into two; this task remains waiting for the results 45 -- Splits into two; this task remains waiting for the results
46 -- 46 --
47 local gen_f= lanes.gen( "*", fib) 47 local gen_f= lanes.gen( "*", { name = 'auto' }, fib)
48 48
49 local n1=floor(n/2) +1 49 local n1=floor(n/2) +1
50 local n2=floor(n/2) -1 + n%2 50 local n2=floor(n/2) -1 + n%2
diff --git a/tests/fifo.lua b/tests/fifo.lua
index 9efcbd9..1317a9f 100644
--- a/tests/fifo.lua
+++ b/tests/fifo.lua
@@ -6,10 +6,10 @@
6 6
7local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true} 7local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true}
8 8
9local atomic_linda = lanes.linda( "atom") 9local atomic_linda = lanes.linda{name = "atom"}
10local atomic_inc= lanes.genatomic( atomic_linda, "FIFO_n") 10local atomic_inc= lanes.genatomic( atomic_linda, "FIFO_n")
11 11
12local fifo_linda = lanes.linda( "fifo") 12local fifo_linda = lanes.linda{name = "fifo"}
13 13
14-- Lua 5.1 support 14-- Lua 5.1 support
15local table_unpack = table.unpack or unpack 15local table_unpack = table.unpack or unpack
diff --git a/tests/finalizer.lua b/tests/finalizer.lua
index 8bf89b4..9fa12dc 100644
--- a/tests/finalizer.lua
+++ b/tests/finalizer.lua
@@ -69,7 +69,7 @@ cleanup = function(err)
69end 69end
70 70
71-- we need error_trace_level above "minimal" to get a stack trace out of h:join() 71-- we need error_trace_level above "minimal" to get a stack trace out of h:join()
72local lgen = lanes.gen("*", {error_trace_level = "basic"}, lane) 72local lgen = lanes.gen("*", { name = 'auto', error_trace_level = "basic" }, lane)
73 73
74local do_test = function(error_) 74local do_test = function(error_)
75 75
@@ -77,8 +77,8 @@ local do_test = function(error_)
77 77
78 local h = lgen(error_) 78 local h = lgen(error_)
79 79
80 local _,err,stack = h:join() -- wait for the lane (no automatic error propagation) 80 local r,err,stack = h:join() -- wait for the lane (no automatic error propagation)
81 if err then 81 if not r then
82 assert(stack, "no stack trace on error, check 'error_trace_level'") 82 assert(stack, "no stack trace on error, check 'error_trace_level'")
83 io.stderr:write( "Lane error: "..tostring(err).."\n" ) 83 io.stderr:write( "Lane error: "..tostring(err).."\n" )
84 io.stderr:write( "\t", table.concat(stack,"\t\n"), "\n" ) 84 io.stderr:write( "\t", table.concat(stack,"\t\n"), "\n" )
diff --git a/tests/func_is_string.lua b/tests/func_is_string.lua
index a14c460..3c91603 100644
--- a/tests/func_is_string.lua
+++ b/tests/func_is_string.lua
@@ -7,7 +7,7 @@ if _VERSION >= "Lua 5.4" then
7 local lanes = require 'lanes' 7 local lanes = require 'lanes'
8 local r 8 local r
9 do 9 do
10 local h <close> = lanes.gen('*', lanes.sleep)(0.5) 10 local h <close> = lanes.gen('*', { name = 'auto' }, lanes.sleep)(0.5)
11 r = h 11 r = h
12 end -- h is closed here 12 end -- h is closed here
13 return r.status 13 return r.status
@@ -21,16 +21,17 @@ end
21 21
22local options = {globals = { b = 666 }} 22local options = {globals = { b = 666 }}
23 23
24local gen1 = lanes.gen("*", "return true, dofile('fibonacci.lua')") 24local gen1 = lanes.gen("*", { name = 'auto' }, "return true, error('bob')")
25local gen2 = lanes.gen(options, "return b")
26 25
27fibLane = gen1() 26fibLane = gen1()
28lanes.sleep(0.1) 27lanes.sleep(0.1)
29print(fibLane, fibLane.status) 28print(fibLane, fibLane.status)
30local _status, _err = fibLane:join() 29local _r, _err, _stk = fibLane:join()
31print(_status, _err) 30assert(_r == nil, "got " .. tostring(_r) .. " " .. tostring(_err) .. " " .. tostring(_stk))
32 31
33retLane1, retLane2 = gen2(), gen2() 32local gen2 = lanes.gen(options, { name = 'auto' }, "return b")
33local retLane1, retLane2 = gen2(), gen2()
34 34
35print( retLane1[1], retLane2[1]) 35print( retLane1[1], retLane2[1])
36print "TEST OK" \ No newline at end of file 36assert(retLane1[1] == 666 and retLane2[1] == 666)
37print "TEST OK"
diff --git a/tests/hangtest.lua b/tests/hangtest.lua
index 0e44451..e48ff60 100644
--- a/tests/hangtest.lua
+++ b/tests/hangtest.lua
@@ -7,7 +7,7 @@ local lanes = require "lanes"
7local function ret(b) 7local function ret(b)
8 return b 8 return b
9end 9end
10local lgen = lanes.gen("*", {}, ret) 10local lgen = lanes.gen("*", { name = 'auto' }, ret)
11 11
12for i=1,10000 do 12for i=1,10000 do
13 local ln = lgen(i) 13 local ln = lgen(i)
diff --git a/tests/irayo_closure.lua b/tests/irayo_closure.lua
index 45189ec..40c586d 100644
--- a/tests/irayo_closure.lua
+++ b/tests/irayo_closure.lua
@@ -5,7 +5,7 @@
5"Another issue I've noticed is trying to pass a table with a function 5"Another issue I've noticed is trying to pass a table with a function
6that uses closures in it as a global variable into a new lane. This 6that uses closures in it as a global variable into a new lane. This
7causes a segmentation fault and it appears to be related to the 7causes a segmentation fault and it appears to be related to the
8luaG_inter_move function near line 835-836 or so in lanes.c, but I 8luaW_inter_move function near line 835-836 or so in lanes.c, but I
9haven't investigated further. 9haven't investigated further.
10e.g. { globals = { data = 1, func = function() useclosurehere() end } }" 10e.g. { globals = { data = 1, func = function() useclosurehere() end } }"
11]] 11]]
@@ -33,5 +33,5 @@ local function useclosurehere()
33 print "using the closure" 33 print "using the closure"
34end 34end
35 35
36local lane= lanes.gen( "", { globals = { data=1, func=useclosurehere } }, testrun )() 36local lane= lanes.gen( "", { name = 'auto', globals = { data=1, func=useclosurehere } }, testrun )()
37print(lane[1]) 37print(lane[1])
diff --git a/tests/irayo_recursive.lua b/tests/irayo_recursive.lua
index 0187a15..99522f7 100644
--- a/tests/irayo_recursive.lua
+++ b/tests/irayo_recursive.lua
@@ -11,7 +11,7 @@ local function recurse()
11 11
12 --local lanes = require "lanes" 12 --local lanes = require "lanes"
13 13
14 local lane = lanes.gen( "base,string,lanes_core", { globals = { ["i"]= i + 1 } }, recurse ) () 14 local lane = lanes.gen( "base,string,lanes_core", { name = 'auto', globals = { ["i"]= i + 1 } }, recurse ) ()
15 return lane[1] 15 return lane[1]
16end 16end
17 17
diff --git a/tests/keeper.lua b/tests/keeper.lua
index 0e93de2..4742732 100644
--- a/tests/keeper.lua
+++ b/tests/keeper.lua
@@ -40,14 +40,14 @@ if true then
40 end 40 end
41 41
42 -- should succeed 42 -- should succeed
43 assert.failsnot(function() createLinda("zero", 0) end) 43 assert.failsnot(function() createLinda{name = "zero", group = 0} end)
44 assert.failsnot(function() createLinda("one", 1) end) 44 assert.failsnot(function() createLinda{name = "one", group = 1} end)
45 assert.failsnot(function() createLinda("two", 2) end) 45 assert.failsnot(function() createLinda{name = "two", group = 2} end)
46 assert.failsnot(function() createLinda("three", 3) end) 46 assert.failsnot(function() createLinda{name = "three", group = 3} end)
47 -- should fail (and not create the lindas) 47 -- should fail (and not create the lindas)
48 assert.fails(function() createLinda("minus 1", -1) end) 48 assert.fails(function() createLinda{name = "minus 1", group = -1} end)
49 assert.fails(function() createLinda("none") end) 49 assert.fails(function() createLinda{name = "none"} end)
50 assert.fails(function() createLinda("four", 4) end) 50 assert.fails(function() createLinda{name = "four", group = 4} end)
51 51
52end 52end
53-- should only collect the 4 successfully created lindas 53-- should only collect the 4 successfully created lindas
@@ -58,11 +58,11 @@ DONE()
58if true then 58if true then
59 PRINT "=========================================================================================" 59 PRINT "========================================================================================="
60 PRINT "Linda names test:" 60 PRINT "Linda names test:"
61 local unnamedLinda1 = lanes.linda(1) 61 local unnamedLinda1 = lanes.linda{group = 1}
62 local unnamedLinda2 = lanes.linda("", 2) 62 local unnamedLinda2 = lanes.linda{name = "", group = 2}
63 local veeeerrrryyyylooongNamedLinda3 = lanes.linda( "veeeerrrryyyylooongNamedLinda", 3) 63 local veeeerrrryyyylooongNamedLinda3 = lanes.linda{ name = "veeeerrrryyyylooongNamedLinda", group = 3}
64 assert(tostring(veeeerrrryyyylooongNamedLinda3) == "Linda: veeeerrrryyyylooongNamedLinda") 64 assert(tostring(veeeerrrryyyylooongNamedLinda3) == "Linda: veeeerrrryyyylooongNamedLinda")
65 local shortNamedLinda0 = lanes.linda( "short", 0) 65 local shortNamedLinda0 = lanes.linda{name = "short", group = 0}
66 assert(tostring(shortNamedLinda0) == "Linda: short") 66 assert(tostring(shortNamedLinda0) == "Linda: short")
67 PRINT(shortNamedLinda0, unnamedLinda1, unnamedLinda2, veeeerrrryyyylooongNamedLinda3) 67 PRINT(shortNamedLinda0, unnamedLinda1, unnamedLinda2, veeeerrrryyyylooongNamedLinda3)
68end 68end
@@ -74,12 +74,12 @@ DONE()
74if true then 74if true then
75 PRINT "=========================================================================================" 75 PRINT "========================================================================================="
76 PRINT "Linda GC test:" 76 PRINT "Linda GC test:"
77 local a = lanes.linda("A", 1) 77 local a = lanes.linda{name = "A", group = 1}
78 local b = lanes.linda("B", 2) 78 local b = lanes.linda{name = "B", group = 2}
79 local c = lanes.linda("C", 3) 79 local c = lanes.linda{name = "C", group = 3}
80 80
81 -- store lindas in each other and in themselves 81 -- store lindas in each other and in themselves
82 a:set("here", lanes.linda("temporary linda", 0)) 82 a:set("here", lanes.linda{name = "temporary linda", group = 0})
83 b:set("here", a, b, c) 83 b:set("here", a, b, c)
84 c:set("here", a, b, c) 84 c:set("here", a, b, c)
85 85
@@ -120,13 +120,13 @@ if true then
120 end 120 end
121 121
122 -- 122 --
123 local lindaA= lanes.linda( "A", 1) 123 local lindaA= lanes.linda{name = "A", group = 1}
124 local A= keeper( lindaA ) 124 local A= keeper( lindaA )
125 125
126 local lindaB= lanes.linda( "B", 2) 126 local lindaB= lanes.linda{name = "B", group = 2}
127 local B= keeper( lindaB ) 127 local B= keeper( lindaB )
128 128
129 local lindaC= lanes.linda( "C", 3) 129 local lindaC= lanes.linda{name = "C", group = 3}
130 local C= keeper( lindaC ) 130 local C= keeper( lindaC )
131 PRINT("Created", lindaA, lindaB, lindaC) 131 PRINT("Created", lindaA, lindaB, lindaC)
132 132
@@ -160,7 +160,7 @@ if true then
160 end 160 end
161 161
162 PRINT("lane started") 162 PRINT("lane started")
163 local h= lanes.gen( "io", lane )() 163 local h= lanes.gen( "io", { name = 'auto' }, lane )()
164 PRINT("lane joined:", h:join()) 164 PRINT("lane joined:", h:join())
165 165
166 PRINT("A.some = " .. A.some ) 166 PRINT("A.some = " .. A.some )
diff --git a/tests/lanes_as_upvalue.lua b/tests/lanes_as_upvalue.lua
index e7fcd3a..beef22e 100644
--- a/tests/lanes_as_upvalue.lua
+++ b/tests/lanes_as_upvalue.lua
@@ -4,7 +4,7 @@ local function foo()
4 local lanes = lanes -- lanes as upvalue 4 local lanes = lanes -- lanes as upvalue
5end 5end
6 6
7local g = lanes.gen( "*", {error_trace_level = "extended"}, foo) 7local g = lanes.gen( "*", { name = 'auto', error_trace_level = "extended"}, foo)
8 8
9-- this should raise an error as lanes.timer_lane is a Lane (a non-deep full userdata) 9-- this should raise an error as lanes.timer_lane is a Lane (a non-deep full userdata)
10local res, err = pcall( g) 10local res, err = pcall( g)
diff --git a/tests/launchtest.lua b/tests/launchtest.lua
index 16db242..cdd6ffc 100644
--- a/tests/launchtest.lua
+++ b/tests/launchtest.lua
@@ -47,7 +47,7 @@ end
47 47
48local lanes = require "lanes" 48local lanes = require "lanes"
49 49
50local g= lanes.gen( LIBS, function(i) 50local g= lanes.gen( LIBS, { name = 'auto' }, function(i)
51 --io.stderr:write( i.."\t" ) 51 --io.stderr:write( i.."\t" )
52 return i 52 return i
53 end ) 53 end )
@@ -69,8 +69,8 @@ else
69 io.stderr:write( N.." lanes launched.\n" ) 69 io.stderr:write( N.." lanes launched.\n" )
70 70
71 for i=1,N do 71 for i=1,N do
72 local rc= t[i]:join() 72 local r,rc = t[i]:join()
73 assert( rc==i ) 73 assert( r == true and rc == i )
74 end 74 end
75 75
76 io.stderr:write( N.." lanes finished.\n" ) 76 io.stderr:write( N.." lanes finished.\n" )
diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua
index 96f26f4..e68d552 100644
--- a/tests/linda_perf.lua
+++ b/tests/linda_perf.lua
@@ -22,7 +22,7 @@ if true then
22 do 22 do
23 print "############################################ tests get/set" 23 print "############################################ tests get/set"
24 -- linda:get throughput 24 -- linda:get throughput
25 local l = lanes.linda("get/set", 1) 25 local l = lanes.linda{name = "get/set", group = 1}
26 local batch = {} 26 local batch = {}
27 for i = 1,1000 do 27 for i = 1,1000 do
28 table.insert(batch, i) 28 table.insert(batch, i)
@@ -56,7 +56,7 @@ local eater = function( l, loop)
56 -- print "loop is over" 56 -- print "loop is over"
57 key, val = l:receive( "done") 57 key, val = l:receive( "done")
58 print("eater: done ("..val..")") 58 print("eater: done ("..val..")")
59 return true 59 return "ate everything"
60end 60end
61 61
62-- ################################################################################################# 62-- #################################################################################################
@@ -68,19 +68,19 @@ local gobbler = function( l, loop, batch)
68 l:receive( "go") 68 l:receive( "go")
69 -- eat data in batches 69 -- eat data in batches
70 for i = 1, loop/batch do 70 for i = 1, loop/batch do
71 l:receive( l.batched, "key", batch) 71 l:receive_batched("key", batch)
72 -- print("gobbler:", batch) 72 -- print("gobbler:", batch)
73 end 73 end
74 print "loop is over" 74 print "loop is over"
75 key, val = l:receive( "done") 75 key, val = l:receive( "done")
76 print("gobbler: done ("..val..")") 76 print("gobbler: done ("..val..")")
77 return true 77 return "gobbled everything"
78end 78end
79 79
80-- ################################################################################################# 80-- #################################################################################################
81 81
82local lane_eater_gen = lanes.gen( "*", {priority = 3}, eater) 82local lane_eater_gen = lanes.gen( "*", { name = 'auto', priority = 3 }, eater)
83local lane_gobbler_gen = lanes.gen( "*", {priority = 3}, gobbler) 83local lane_gobbler_gen = lanes.gen( "*", { name = 'auto', priority = 3 }, gobbler)
84 84
85-- ################################################################################################# 85-- #################################################################################################
86 86
@@ -90,7 +90,7 @@ local group_uid = 1
90local function ziva1( preloop, loop, batch) 90local function ziva1( preloop, loop, batch)
91 -- prefill the linda a bit to increase fifo stress 91 -- prefill the linda a bit to increase fifo stress
92 local top = math.max( preloop, loop) 92 local top = math.max( preloop, loop)
93 local l = lanes.linda("ziva1("..preloop..":"..loop..":"..batch..")", group_uid) 93 local l = lanes.linda{name = "ziva1("..preloop..":"..loop..":"..batch..")", group = group_uid}
94 group_uid = (group_uid % config.nb_user_keepers) + 1 94 group_uid = (group_uid % config.nb_user_keepers) + 1
95 local t1 = lanes.now_secs() 95 local t1 = lanes.now_secs()
96 for i = 1, preloop do 96 for i = 1, preloop do
@@ -123,7 +123,8 @@ local function ziva1( preloop, loop, batch)
123 end 123 end
124 end 124 end
125 l:send( "done" ,"are you happy?") 125 l:send( "done" ,"are you happy?")
126 lane:join() 126 local r, ret = lane:join()
127 assert(r == true and type(ret) == "string", "got " .. tostring(r) .. " " .. tostring(ret))
127 return lanes.now_secs() - t1 128 return lanes.now_secs() - t1
128end 129end
129 130
@@ -165,12 +166,12 @@ end
165 166
166-- sequential write/read (no parallelization involved) 167-- sequential write/read (no parallelization involved)
167local function ziva2( preloop, loop, batch) 168local function ziva2( preloop, loop, batch)
168 local l = lanes.linda("ziva2("..preloop..":"..loop..":"..tostring(batch)..")", group_uid) 169 local l = lanes.linda{name = "ziva2("..preloop..":"..loop..":"..tostring(batch)..")", group = group_uid}
169 group_uid = (group_uid % config.nb_user_keepers) + 1 170 group_uid = (group_uid % config.nb_user_keepers) + 1
170 -- prefill the linda a bit to increase fifo stress 171 -- prefill the linda a bit to increase fifo stress
171 local top, step = math.max( preloop, loop), (l.batched and batch) and batch or 1 172 local top, step = math.max( preloop, loop), batch or 1
172 local batch_send, batch_read 173 local batch_send, batch_read
173 if l.batched and batch then 174 if batch then
174 local batch_values = {} 175 local batch_values = {}
175 for i = 1, batch do 176 for i = 1, batch do
176 table.insert( batch_values, i) 177 table.insert( batch_values, i)
@@ -180,7 +181,7 @@ local function ziva2( preloop, loop, batch)
180 l:send( "key", table_unpack( batch_values)) 181 l:send( "key", table_unpack( batch_values))
181 end 182 end
182 batch_read = function() 183 batch_read = function()
183 l:receive( l.batched, "key", batch) 184 l:receive_batched("key", batch)
184 end 185 end
185 else -- not batched 186 else -- not batched
186 batch_send = function() 187 batch_send = function()
diff --git a/tests/manual_register.lua b/tests/manual_register.lua
index 52cc4ed..36a41ad 100644
--- a/tests/manual_register.lua
+++ b/tests/manual_register.lua
@@ -25,7 +25,7 @@ local f = function()
25end 25end
26 26
27 27
28local g = lanes.gen( "*", f) 28local g = lanes.gen( "*", { name = 'auto' }, f)
29 29
30-- generate a lane, this will transfer f, which pulls GlobalFunc. 30-- generate a lane, this will transfer f, which pulls GlobalFunc.
31local h = g() 31local h = g()
diff --git a/tests/nameof.lua b/tests/nameof.lua
index 1abcf3d..fb7332a 100644
--- a/tests/nameof.lua
+++ b/tests/nameof.lua
@@ -18,7 +18,7 @@ local body = function()
18end 18end
19 19
20-- start the lane without any library 20-- start the lane without any library
21local h = lanes.gen(nil, body)() 21local h = lanes.gen(nil, { name = 'auto' }, body)()
22SLEEP(0.1) 22SLEEP(0.1)
23print("Name of lane: ", lanes.nameof(h), "("..h.status..")") 23print("Name of lane: ", lanes.nameof(h), "("..h.status..")")
24assert(h.status == "running") 24assert(h.status == "running")
diff --git a/tests/objects.lua b/tests/objects.lua
index ed460af..22a4df1 100644
--- a/tests/objects.lua
+++ b/tests/objects.lua
@@ -8,7 +8,7 @@ local lanes = require "lanes"
8 8
9local linda= lanes.linda() 9local linda= lanes.linda()
10 10
11local start_lane= lanes.gen("io", 11local start_lane= lanes.gen("io", { name = 'auto' },
12 function(obj1 ) 12 function(obj1 )
13 13
14 assert(obj1.v ) 14 assert(obj1.v )
diff --git a/tests/parallel_os_calls.lua b/tests/parallel_os_calls.lua
index 8030d4c..55159e8 100644
--- a/tests/parallel_os_calls.lua
+++ b/tests/parallel_os_calls.lua
@@ -1,15 +1,15 @@
1local lanes = require "lanes" 1local lanes = require "lanes"
2print( os.date()) 2print( os.date())
3local linda = lanes.linda() 3local linda = lanes.linda()
4local l1 = lanes.gen("os,base", function() print "start sleeping" linda:receive(3, "null") print("finished_sleeping " .. os.date()) return true end)() 4local l1 = lanes.gen("os,base", { name = 'auto' }, function() print "start sleeping" linda:receive(3, "null") print("finished_sleeping " .. os.date()) return true end)()
5lanes.gen("os,base", function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)() 5lanes.gen("os,base", { name = 'auto' }, function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)()
6lanes.gen("os,base", function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)() 6lanes.gen("os,base", { name = 'auto' }, function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)()
7lanes.gen("os,base", function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)() 7lanes.gen("os,base", { name = 'auto' }, function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)()
8-- wait, else all lanes will get hard-cancelled at stat shutdown 8-- wait, else all lanes will get hard-cancelled at stat shutdown
9l1:join() 9l1:join()
10--[[ 10--[[
11lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() 11lanes.gen("os,base", { name = 'auto' }, function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)()
12lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() 12lanes.gen("os,base", { name = 'auto' }, function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)()
13lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() 13lanes.gen("os,base", { name = 'auto' }, function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)()
14lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() 14lanes.gen("os,base", { name = 'auto' }, function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)()
15]] 15]]
diff --git a/tests/perftest.lua b/tests/perftest.lua
index 35f522c..35e164d 100644
--- a/tests/perftest.lua
+++ b/tests/perftest.lua
@@ -137,10 +137,10 @@ end
137-- Keep preparation code outside of the performance test 137-- Keep preparation code outside of the performance test
138-- 138--
139local f_even= lanes.gen( "base,coroutine,math,table,io", -- "*" = all 139local f_even= lanes.gen( "base,coroutine,math,table,io", -- "*" = all
140 { priority= PRIO_EVEN }, sieve_lane ) 140 { name = 'auto', priority= PRIO_EVEN }, sieve_lane )
141 141
142local f_odd= lanes.gen( "base,coroutine,math,table,io", -- "*" = all 142local f_odd= lanes.gen( "base,coroutine,math,table,io", -- "*" = all
143 { priority= PRIO_ODD }, sieve_lane ) 143 { name = 'auto', priority= PRIO_ODD }, sieve_lane )
144 144
145io.stderr:write( "*** Counting primes 1.."..M.." "..N.." times ***\n\n" ) 145io.stderr:write( "*** Counting primes 1.."..M.." "..N.." times ***\n\n" )
146 146
@@ -175,9 +175,9 @@ else
175 -- Make sure all lanes finished 175 -- Make sure all lanes finished
176 -- 176 --
177 for i=1,N do 177 for i=1,N do
178 local tmp= t[i]:join() 178 local r, tmp = t[i]:join()
179 -- this assert will trigger if you change M to values below 1000 in order to solve C stack overflow 179 -- this assert will trigger if you change M to values below 1000 in order to solve C stack overflow
180 assert( type(tmp)=="table" and tmp[1]==2 and tmp[168]==997 ) 180 assert( r == true and type(tmp) == "table" and tmp[1] == 2 and tmp[168] == 997 )
181 end 181 end
182end 182end
183 183
diff --git a/tests/pingpong.lua b/tests/pingpong.lua
index 3498f49..1ed5b9a 100644
--- a/tests/pingpong.lua
+++ b/tests/pingpong.lua
@@ -21,13 +21,15 @@ local pingpong = function(name, qr, qs, start)
21 q:send(qs, val) 21 q:send(qs, val)
22 count = count + 1 22 count = count + 1
23 end 23 end
24 return true 24 return "ping!"
25end 25end
26 26
27-- pingpong("L1", '0', '1', true) 27-- pingpong("L1", '0', '1', true)
28local t1, err1 = lanes.gen("*", pingpong)("L1", 'a', 'b', true) 28local t1, err1 = lanes.gen("*", { name = 'auto' }, pingpong)("L1", 'a', 'b', true)
29local t2, err2 = lanes.gen("*", pingpong)("L2", 'b', 'a', false) 29local t2, err2 = lanes.gen("*", { name = 'auto' }, pingpong)("L2", 'b', 'a', false)
30 30
31t1:join() 31local r1, ret1 = t1:join()
32t2:join() 32assert(r1 == true and ret1 == "ping!")
33local r2, ret2 = t2:join()
34assert(r2 == true and ret2 == "ping!")
33print "TEST OK" 35print "TEST OK"
diff --git a/tests/protect_allocator.lua b/tests/protect_allocator.lua
index 994cb39..325726a 100644
--- a/tests/protect_allocator.lua
+++ b/tests/protect_allocator.lua
@@ -36,7 +36,7 @@ end
36 36
37-- start threads 37-- start threads
38local COUNT = 4 38local COUNT = 4
39local gen = lanes.gen( "*", body) 39local gen = lanes.gen( "*", { name = 'auto' }, body)
40for i = 1, COUNT do 40for i = 1, COUNT do
41 gen( i) 41 gen( i)
42end 42end
@@ -52,7 +52,7 @@ end
52 52
53-- wait for completion 53-- wait for completion
54print "wait for completion" 54print "wait for completion"
55linda:receive( linda.batched, "key", COUNT) 55linda:receive_batched("key", COUNT)
56print "waiting a bit more ..." 56print "waiting a bit more ..."
57SLEEP(1) 57SLEEP(1)
58print "SUCCESS" 58print "SUCCESS"
diff --git a/tests/protectproxy.lua b/tests/protectproxy.lua
index ed1bd4f..84887ec 100644
--- a/tests/protectproxy.lua
+++ b/tests/protectproxy.lua
@@ -5,7 +5,7 @@ local body = function( param)
5 return 1 5 return 1
6end 6end
7 7
8local gen = lanes.gen( "*", body) 8local gen = lanes.gen( "*", { name = 'auto' }, body)
9 9
10local mylane = gen( "hello") 10local mylane = gen( "hello")
11 11
diff --git a/tests/recursive.lua b/tests/recursive.lua
index 716fe60..e294104 100644
--- a/tests/recursive.lua
+++ b/tests/recursive.lua
@@ -12,7 +12,7 @@ local function func( depth )
12 end 12 end
13 13
14 local lanes = require "lanes" 14 local lanes = require "lanes"
15 local lane = lanes.gen("*", func)( depth-1 ) 15 local lane = lanes.gen("*", { name = 'auto' }, func)( depth-1 )
16 return lane[1] 16 return lane[1]
17end 17end
18 18
diff --git a/tests/require.lua b/tests/require.lua
index b194af1..f017ddf 100644
--- a/tests/require.lua
+++ b/tests/require.lua
@@ -19,14 +19,14 @@ local function a_lane()
19 local lanes = require "lanes" 19 local lanes = require "lanes"
20 assert( lanes and lanes.gen ) 20 assert( lanes and lanes.gen )
21 21
22 local h= lanes.gen( function() return 42 end ) () 22 local h= lanes.gen( { name = 'auto' }, function() return 42 end ) ()
23 local v= h[1] 23 local v= h[1]
24 24
25 return v==42 25 return v==42
26end 26end
27 27
28-- string and table for Lanes itself, package to be able to require in the lane, math for the actual work 28-- string and table for Lanes itself, package to be able to require in the lane, math for the actual work
29local gen= lanes.gen( "math,package,string,table", {package={}},a_lane ) 29local gen= lanes.gen( "math,package,string,table", { name = 'auto', package={} },a_lane )
30 30
31local h= gen() 31local h= gen()
32local ret= h[1] 32local ret= h[1]
diff --git a/tests/rupval.lua b/tests/rupval.lua
index 122e0ac..c6743b3 100644
--- a/tests/rupval.lua
+++ b/tests/rupval.lua
@@ -23,20 +23,20 @@ c = function( n)
23 return n <= 0 and z or a( n-1) 23 return n <= 0 and z or a( n-1)
24end 24end
25 25
26local g = lanes.gen( "base", a) 26local g = lanes.gen( "base", { name = 'auto' }, a)
27 27
28local l = g(7) 28local l = g(7)
29local r = l:join() 29local _, r = l:join()
30assert(r == y) 30assert(r == y)
31print(r) 31print(r)
32 32
33local l = g(8) 33local l = g(8)
34local r = l:join() 34local _, r = l:join()
35assert(r == z) 35assert(r == z)
36print(r) 36print(r)
37 37
38local l = g(9) 38local l = g(9)
39local r = l:join() 39local _, r = l:join()
40assert(r == x) 40assert(r == x)
41print(r) 41print(r)
42 42
diff --git a/tests/tobeclosed.lua b/tests/tobeclosed.lua
index 7a5e3ae..fd157e2 100644
--- a/tests/tobeclosed.lua
+++ b/tests/tobeclosed.lua
@@ -36,7 +36,7 @@ do
36 WR("f closing ", linda_) 36 WR("f closing ", linda_)
37 closed_by_f = true 37 closed_by_f = true
38 end 38 end
39 local lf <close> = lanes.linda("closed by f", close_handler_f) 39 local lf <close> = lanes.linda{name = "closed by f", close_handler = close_handler_f}
40 40
41 local close_handler_t = setmetatable({}, 41 local close_handler_t = setmetatable({},
42 { 42 {
@@ -46,7 +46,7 @@ do
46 end 46 end
47 } 47 }
48 ) 48 )
49 local lt <close> = lanes.linda("closed by t", close_handler_t) 49 local lt <close> = lanes.linda{name = "closed by t", close_handler = close_handler_t}
50 end 50 end
51 assert(closed_by_f == true) 51 assert(closed_by_f == true)
52 assert(closed_by_t == true) 52 assert(closed_by_t == true)
@@ -58,13 +58,13 @@ end
58WR "================================================================================================" 58WR "================================================================================================"
59WR "Through Linda" 59WR "Through Linda"
60do 60do
61 local l = lanes.linda("channel") 61 local l = lanes.linda{name = "channel"}
62 62
63 local close_handler_f = function(linda_, err_) 63 local close_handler_f = function(linda_, err_)
64 WR("f closing ", linda_) 64 WR("f closing ", linda_)
65 linda_:set("closed", true) 65 linda_:set("closed", true)
66 end 66 end
67 local l_in = lanes.linda("voyager", close_handler_f) 67 local l_in = lanes.linda{name = "voyager", close_handler = close_handler_f}
68 l:set("trip", l_in) 68 l:set("trip", l_in)
69 69
70 do 70 do
@@ -86,7 +86,7 @@ do
86 return "success" 86 return "success"
87 end 87 end
88 88
89 local h = lanes.gen("*", lane_body)() 89 local h = lanes.gen("*", { name = 'auto' }, lane_body)()
90 do 90 do
91 local tobeclosed <close> = h 91 local tobeclosed <close> = h
92 end 92 end
@@ -99,14 +99,14 @@ end
99WR "================================================================================================" 99WR "================================================================================================"
100WR "Linda closing through Lane" 100WR "Linda closing through Lane"
101do 101do
102 local l = lanes.linda("channel") 102 local l = lanes.linda{name = "channel"}
103 local lane_body = function(l_arg_) 103 local lane_body = function(l_arg_)
104 WR "In lane body" 104 WR "In lane body"
105 -- linda obtained through a linda 105 -- linda obtained through a linda
106 local _count, l_out <close> = l:get("trip") 106 local _count, l_out <close> = l:get("trip")
107 -- linda from arguments 107 -- linda from arguments
108 local l_arg <close> = l_arg_ 108 local l_arg <close> = l_arg_
109 return true 109 return "done"
110 end 110 end
111 111
112 local close_handler_f = function(linda_, err_) 112 local close_handler_f = function(linda_, err_)
@@ -114,11 +114,12 @@ do
114 local _count, _closed = linda_:get("closed") 114 local _count, _closed = linda_:get("closed")
115 linda_:set("closed", (_closed or 0) + 1) 115 linda_:set("closed", (_closed or 0) + 1)
116 end 116 end
117 local l_in = lanes.linda("voyager", close_handler_f) 117 local l_in = lanes.linda{name = "voyager", close_handler = close_handler_f}
118 l:set("trip", l_in) 118 l:set("trip", l_in)
119 119
120 do 120 do
121 lanes.gen("*", lane_body)(l_in):join() 121 local r, ret = lanes.gen("*", { name = 'auto' }, lane_body)(l_in):join()
122 assert(r == true and ret == "done")
122 end 123 end
123 local _count, _closed = l_in:get("closed") 124 local _count, _closed = l_in:get("closed")
124 assert(_count == 1 and _closed == 2) 125 assert(_count == 1 and _closed == 2)
diff --git a/tests/track_lanes.lua b/tests/track_lanes.lua
index 803fae5..ef2ca06 100644
--- a/tests/track_lanes.lua
+++ b/tests/track_lanes.lua
@@ -43,7 +43,7 @@ end
43-- sleeper( "main", 1) 43-- sleeper( "main", 1)
44 44
45-- the generator 45-- the generator
46local g = lanes.gen( "*", sleeper) 46local g = lanes.gen( "*", { name = 'auto' }, sleeper)
47 47
48-- start a forever-waiting lane (nil timeout) 48-- start a forever-waiting lane (nil timeout)
49local forever = g( "forever", 'indefinitely') 49local forever = g( "forever", 'indefinitely')
@@ -59,8 +59,10 @@ local threads = track( "============= START", 2)
59-- two_seconds forever 59-- two_seconds forever
60assert(threads[1].status == 'waiting' and threads[2].status == 'waiting') 60assert(threads[1].status == 'waiting' and threads[2].status == 'waiting')
61 61
62-- wait until ephemeral1 has completed 62-- wait until ephemeral1 has completed, should take about 2 seconds
63SLEEP(2.1) 63repeat
64 SLEEP(0.1)
65until ephemeral1.status == "done"
64 66
65local threads = track( "============= two_seconds dead", 2) 67local threads = track( "============= two_seconds dead", 2)
66-- two_seconds forever 68-- two_seconds forever