diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/appendud.lua | 2 | ||||
-rw-r--r-- | tests/basic.lua | 62 | ||||
-rw-r--r-- | tests/cancel.lua | 2 | ||||
-rw-r--r-- | tests/deadlock.lua | 2 | ||||
-rw-r--r-- | tests/errhangtest.lua | 9 | ||||
-rw-r--r-- | tests/error.lua | 11 | ||||
-rw-r--r-- | tests/fifo.lua | 4 | ||||
-rw-r--r-- | tests/finalizer.lua | 4 | ||||
-rw-r--r-- | tests/func_is_string.lua | 13 | ||||
-rw-r--r-- | tests/irayo_closure.lua | 2 | ||||
-rw-r--r-- | tests/keeper.lua | 36 | ||||
-rw-r--r-- | tests/launchtest.lua | 4 | ||||
-rw-r--r-- | tests/linda_perf.lua | 21 | ||||
-rw-r--r-- | tests/perftest.lua | 4 | ||||
-rw-r--r-- | tests/pingpong.lua | 8 | ||||
-rw-r--r-- | tests/protect_allocator.lua | 2 | ||||
-rw-r--r-- | tests/rupval.lua | 6 | ||||
-rw-r--r-- | tests/tobeclosed.lua | 17 | ||||
-rw-r--r-- | tests/track_lanes.lua | 6 |
19 files changed, 115 insertions, 100 deletions
diff --git a/tests/appendud.lua b/tests/appendud.lua index f6f99c1..2a8c8ce 100644 --- a/tests/appendud.lua +++ b/tests/appendud.lua | |||
@@ -49,7 +49,7 @@ assert(not err) | |||
49 | -- test | 49 | -- test |
50 | -- print("t:join()") | 50 | -- print("t:join()") |
51 | a,b,c = t[1],t[2],t[3] -- Need to explicitly wait for the thread, since 'ipairs()' does not | 51 | a,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 | ||
55 | print(a,b,c) | 55 | print(a,b,c) |
diff --git a/tests/basic.lua b/tests/basic.lua index 068dc25..f393175 100644 --- a/tests/basic.lua +++ b/tests/basic.lua | |||
@@ -163,7 +163,7 @@ PRINT(" "..st) | |||
163 | assert(st == "cancelled", "st is '" .. st .. "' instead of 'cancelled'") | 163 | assert(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 |
166 | local limited = lanes_linda("limited") | 166 | local limited = lanes_linda{name = "limited"} |
167 | assert.fails(function() limited:limit("key", -1) end) | 167 | assert.fails(function() limited:limit("key", -1) end) |
168 | assert.failsnot(function() limited:limit("key", 1) end) | 168 | assert.failsnot(function() limited:limit("key", 1) end) |
169 | -- [[################################################ | 169 | -- [[################################################ |
@@ -173,42 +173,51 @@ for k, v in pairs(limited:dump()) do | |||
173 | end | 173 | end |
174 | local wait_send = function() | 174 | local 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 |
178 | end | 179 | end |
179 | 180 | ||
180 | local wait_send_lane = lanes.gen("*", { name = 'auto' }, wait_send)() | 181 | local wait_send_lane = lanes.gen("*", { name = 'auto' }, wait_send)() |
181 | repeat until wait_send_lane.status == "waiting" | 182 | repeat |
182 | print "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) | ||
186 | until wait_send_lane.status == "waiting" | ||
187 | PRINT "wait_send_lane is waiting" | ||
183 | wait_send_lane:cancel() -- hard cancel, 0 timeout | 188 | wait_send_lane:cancel() -- hard cancel, 0 timeout |
184 | repeat until wait_send_lane.status == "cancelled" | 189 | repeat until wait_send_lane.status == "cancelled" |
185 | print "wait_send_lane is cancelled" | 190 | PRINT "wait_send_lane is cancelled" |
186 | --################################################]] | 191 | --################################################]] |
187 | local wait_receive = function() | 192 | local 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 |
191 | end | 196 | end |
192 | 197 | ||
193 | local wait_receive_lane = lanes.gen("*", { name = 'auto' }, wait_receive)() | 198 | local wait_receive_lane = lanes.gen("*", { name = 'auto' }, wait_receive)() |
194 | repeat until wait_receive_lane.status == "waiting" | 199 | repeat |
195 | print "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) | ||
203 | until wait_receive_lane.status == "waiting" | ||
204 | PRINT "wait_receive_lane is waiting" | ||
196 | wait_receive_lane:cancel() -- hard cancel, 0 timeout | 205 | wait_receive_lane:cancel() -- hard cancel, 0 timeout |
197 | repeat until wait_receive_lane.status == "cancelled" | 206 | repeat until wait_receive_lane.status == "cancelled" |
198 | print "wait_receive_lane is cancelled" | 207 | PRINT "wait_receive_lane is cancelled" |
199 | --################################################]] | 208 | --################################################]] |
200 | local wait_receive_batched = function() | 209 | local 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 |
204 | end | 213 | end |
205 | 214 | ||
206 | local wait_receive_batched_lane = lanes.gen("*", { name = 'auto' }, wait_receive_batched)() | 215 | local wait_receive_batched_lane = lanes.gen("*", { name = 'auto' }, wait_receive_batched)() |
207 | repeat until wait_receive_batched_lane.status == "waiting" | 216 | repeat until wait_receive_batched_lane.status == "waiting" |
208 | print "wait_receive_batched_lane is waiting" | 217 | PRINT "wait_receive_batched_lane is waiting" |
209 | wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout | 218 | wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout |
210 | repeat until wait_receive_batched_lane.status == "cancelled" | 219 | repeat until wait_receive_batched_lane.status == "cancelled" |
211 | print "wait_receive_batched_lane is cancelled" | 220 | PRINT "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") |
247 | end | 256 | end |
248 | 257 | ||
249 | local linda = lanes_linda("communications") | 258 | local linda = lanes_linda{name = "communications"} |
250 | assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications") | 259 | assert(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) | |||
264 | assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil) | 273 | assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil) |
265 | local k, x = linda:receive("<->") | 274 | local k, x = linda:receive("<->") |
266 | assert(k == "<->" and x == "x") | 275 | assert(k == "<->" and x == "x") |
267 | local k,y,z = linda:receive(linda.batched, "<->", 2) | 276 | local k,y,z = linda:receive_batched("<->", 2) |
268 | assert(k == "<->" and y == "y" and z == "z") | 277 | assert(k == "<->" and y == "y" and z == "z") |
269 | linda:set("<->") | 278 | linda:set("<->") |
270 | local b,x,y,z,w = linda:get("<->", 4) | 279 | local b,x,y,z,w = linda:get("<->", 4) |
@@ -401,7 +410,7 @@ local tc = lanes.gen("io", { name = 'auto', gc_cb = gc_cb }, | |||
401 | end | 410 | end |
402 | ) | 411 | ) |
403 | 412 | ||
404 | local linda= lanes_linda("criss cross") | 413 | local linda= lanes_linda{name = "criss cross"} |
405 | 414 | ||
406 | local a,b= tc(linda, "A","B"), tc(linda, "B","A") -- launching two lanes, twisted comms | 415 | local 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,7 +461,7 @@ local function chunk2(linda) | |||
452 | linda:send("up", function() return ":)" end, "ok2") | 461 | linda:send("up", function() return ":)" end, "ok2") |
453 | end | 462 | end |
454 | 463 | ||
455 | local linda = lanes_linda("auto") | 464 | local linda = lanes_linda{name = "auto"} |
456 | local t2 = lanes.gen("debug,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch | 465 | local t2 = lanes.gen("debug,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch |
457 | linda:send("down", function(linda) linda:send("up", "ready!") end, | 466 | linda:send("down", function(linda) linda:send("up", "ready!") end, |
458 | "ok") | 467 | "ok") |
@@ -460,7 +469,7 @@ linda:send("down", function(linda) linda:send("up", "ready!") end, | |||
460 | -- | 469 | -- |
461 | local k,s= linda:receive(1, "up") | 470 | local k,s= linda:receive(1, "up") |
462 | if t2.status == "error" then | 471 | if t2.status == "error" then |
463 | print("t2 error: " , t2:join()) | 472 | PRINT("t2 error: " , t2:join()) |
464 | end | 473 | end |
465 | PRINT(s) | 474 | PRINT(s) |
466 | assert(s=="ready!") | 475 | assert(s=="ready!") |
@@ -498,19 +507,20 @@ local S = lanes.gen("table", { name = 'auto', gc_cb = gc_cb }, | |||
498 | return (unpack or table.unpack)(aux) | 507 | return (unpack or table.unpack)(aux) |
499 | end) | 508 | end) |
500 | 509 | ||
501 | h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values | 510 | h = 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 |
503 | SLEEP(0.5) | 512 | SLEEP(0.5) |
504 | print("joining with '" .. h:get_threadname() .. "'") | 513 | print("joining with '" .. h:get_threadname() .. "'") |
505 | local a,b,c,d= h:join() | 514 | local r,a,b,c,d= h:join() |
506 | if h.status == "error" then | 515 | if 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) |
508 | else | 517 | else |
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) | ||
514 | end | 524 | end |
515 | 525 | ||
516 | local nameof_type, nameof_name = lanes.nameof(print) | 526 | local nameof_type, nameof_name = lanes.nameof(print) |
diff --git a/tests/cancel.lua b/tests/cancel.lua index 80e6c6a..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 |
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" | |||
16 | local do_extra_stuff = true | 16 | local do_extra_stuff = true |
17 | 17 | ||
18 | if do_extra_stuff then | 18 | if 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/errhangtest.lua b/tests/errhangtest.lua index fff0dee..5b3f0c0 100644 --- a/tests/errhangtest.lua +++ b/tests/errhangtest.lua | |||
@@ -19,7 +19,6 @@ end | |||
19 | if true then | 19 | if 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 |
29 | if true then | 28 | if 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 306c51d..76ceea4 100644 --- a/tests/error.lua +++ b/tests/error.lua | |||
@@ -106,11 +106,11 @@ end | |||
106 | 106 | ||
107 | local lane_error_as_string = "'lane error as string'" | 107 | local lane_error_as_string = "'lane error as string'" |
108 | local lane_error_as_table = setmetatable({"lane error as table"}, make_table_error_mt()) | 108 | local lane_error_as_table = setmetatable({"lane error as table"}, make_table_error_mt()) |
109 | local lane_error_as_linda = lanes.linda("'lane error'") | 109 | local lane_error_as_linda = lanes.linda{name = "'lane error'"} |
110 | 110 | ||
111 | local finalizer_error_as_string = "'finalizer error as string'" | 111 | local finalizer_error_as_string = "'finalizer error as string'" |
112 | local finalizer_error_as_table = setmetatable({"finalizer error as table"}, make_table_error_mt()) | 112 | local finalizer_error_as_table = setmetatable({"finalizer error as table"}, make_table_error_mt()) |
113 | local finalizer_error_as_linda = lanes.linda("'finalizer error'") | 113 | local finalizer_error_as_linda = lanes.linda{name = "'finalizer error'"} |
114 | 114 | ||
115 | local test_settings = {} | 115 | local test_settings = {} |
116 | local configure_tests = function() | 116 | local 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" |
205 | end | 204 | end |
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 | ||
7 | local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true} | 7 | local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true} |
8 | 8 | ||
9 | local atomic_linda = lanes.linda( "atom") | 9 | local atomic_linda = lanes.linda{name = "atom"} |
10 | local atomic_inc= lanes.genatomic( atomic_linda, "FIFO_n") | 10 | local atomic_inc= lanes.genatomic( atomic_linda, "FIFO_n") |
11 | 11 | ||
12 | local fifo_linda = lanes.linda( "fifo") | 12 | local fifo_linda = lanes.linda{name = "fifo"} |
13 | 13 | ||
14 | -- Lua 5.1 support | 14 | -- Lua 5.1 support |
15 | local table_unpack = table.unpack or unpack | 15 | local table_unpack = table.unpack or unpack |
diff --git a/tests/finalizer.lua b/tests/finalizer.lua index ac5ce8b..9fa12dc 100644 --- a/tests/finalizer.lua +++ b/tests/finalizer.lua | |||
@@ -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 5de4c60..3c91603 100644 --- a/tests/func_is_string.lua +++ b/tests/func_is_string.lua | |||
@@ -21,16 +21,17 @@ end | |||
21 | 21 | ||
22 | local options = {globals = { b = 666 }} | 22 | local options = {globals = { b = 666 }} |
23 | 23 | ||
24 | local gen1 = lanes.gen("*", { name = 'auto' }, "return true, dofile('fibonacci.lua')") | 24 | local gen1 = lanes.gen("*", { name = 'auto' }, "return true, error('bob')") |
25 | local gen2 = lanes.gen(options, { name = 'auto' }, "return b") | ||
26 | 25 | ||
27 | fibLane = gen1() | 26 | fibLane = gen1() |
28 | lanes.sleep(0.1) | 27 | lanes.sleep(0.1) |
29 | print(fibLane, fibLane.status) | 28 | print(fibLane, fibLane.status) |
30 | local _status, _err = fibLane:join() | 29 | local _r, _err, _stk = fibLane:join() |
31 | print(_status, _err) | 30 | assert(_r == nil, "got " .. tostring(_r) .. " " .. tostring(_err) .. " " .. tostring(_stk)) |
32 | 31 | ||
33 | retLane1, retLane2 = gen2(), gen2() | 32 | local gen2 = lanes.gen(options, { name = 'auto' }, "return b") |
33 | local retLane1, retLane2 = gen2(), gen2() | ||
34 | 34 | ||
35 | print( retLane1[1], retLane2[1]) | 35 | print( retLane1[1], retLane2[1]) |
36 | print "TEST OK" \ No newline at end of file | 36 | assert(retLane1[1] == 666 and retLane2[1] == 666) |
37 | print "TEST OK" | ||
diff --git a/tests/irayo_closure.lua b/tests/irayo_closure.lua index 705b85e..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 |
6 | that uses closures in it as a global variable into a new lane. This | 6 | that uses closures in it as a global variable into a new lane. This |
7 | causes a segmentation fault and it appears to be related to the | 7 | causes a segmentation fault and it appears to be related to the |
8 | luaG_inter_move function near line 835-836 or so in lanes.c, but I | 8 | luaW_inter_move function near line 835-836 or so in lanes.c, but I |
9 | haven't investigated further. | 9 | haven't investigated further. |
10 | e.g. { globals = { data = 1, func = function() useclosurehere() end } }" | 10 | e.g. { globals = { data = 1, func = function() useclosurehere() end } }" |
11 | ]] | 11 | ]] |
diff --git a/tests/keeper.lua b/tests/keeper.lua index f566927..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 | ||
52 | end | 52 | end |
53 | -- should only collect the 4 successfully created lindas | 53 | -- should only collect the 4 successfully created lindas |
@@ -58,11 +58,11 @@ DONE() | |||
58 | if true then | 58 | if 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) |
68 | end | 68 | end |
@@ -74,12 +74,12 @@ DONE() | |||
74 | if true then | 74 | if 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 | ||
diff --git a/tests/launchtest.lua b/tests/launchtest.lua index 57411e1..cdd6ffc 100644 --- a/tests/launchtest.lua +++ b/tests/launchtest.lua | |||
@@ -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 bba1408..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" |
60 | end | 60 | end |
61 | 61 | ||
62 | -- ################################################################################################# | 62 | -- ################################################################################################# |
@@ -68,13 +68,13 @@ 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" |
78 | end | 78 | end |
79 | 79 | ||
80 | -- ################################################################################################# | 80 | -- ################################################################################################# |
@@ -90,7 +90,7 @@ local group_uid = 1 | |||
90 | local function ziva1( preloop, loop, batch) | 90 | local 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 |
128 | end | 129 | end |
129 | 130 | ||
@@ -165,12 +166,12 @@ end | |||
165 | 166 | ||
166 | -- sequential write/read (no parallelization involved) | 167 | -- sequential write/read (no parallelization involved) |
167 | local function ziva2( preloop, loop, batch) | 168 | local 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/perftest.lua b/tests/perftest.lua index fe43cca..35e164d 100644 --- a/tests/perftest.lua +++ b/tests/perftest.lua | |||
@@ -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 |
182 | end | 182 | end |
183 | 183 | ||
diff --git a/tests/pingpong.lua b/tests/pingpong.lua index 06c0903..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!" |
25 | end | 25 | end |
26 | 26 | ||
27 | -- pingpong("L1", '0', '1', true) | 27 | -- pingpong("L1", '0', '1', true) |
28 | local t1, err1 = lanes.gen("*", { name = 'auto' }, pingpong)("L1", 'a', 'b', true) | 28 | local t1, err1 = lanes.gen("*", { name = 'auto' }, pingpong)("L1", 'a', 'b', true) |
29 | local t2, err2 = lanes.gen("*", { name = 'auto' }, pingpong)("L2", 'b', 'a', false) | 29 | local t2, err2 = lanes.gen("*", { name = 'auto' }, pingpong)("L2", 'b', 'a', false) |
30 | 30 | ||
31 | t1:join() | 31 | local r1, ret1 = t1:join() |
32 | t2:join() | 32 | assert(r1 == true and ret1 == "ping!") |
33 | local r2, ret2 = t2:join() | ||
34 | assert(r2 == true and ret2 == "ping!") | ||
33 | print "TEST OK" | 35 | print "TEST OK" |
diff --git a/tests/protect_allocator.lua b/tests/protect_allocator.lua index e13a57c..325726a 100644 --- a/tests/protect_allocator.lua +++ b/tests/protect_allocator.lua | |||
@@ -52,7 +52,7 @@ end | |||
52 | 52 | ||
53 | -- wait for completion | 53 | -- wait for completion |
54 | print "wait for completion" | 54 | print "wait for completion" |
55 | linda:receive( linda.batched, "key", COUNT) | 55 | linda:receive_batched("key", COUNT) |
56 | print "waiting a bit more ..." | 56 | print "waiting a bit more ..." |
57 | SLEEP(1) | 57 | SLEEP(1) |
58 | print "SUCCESS" | 58 | print "SUCCESS" |
diff --git a/tests/rupval.lua b/tests/rupval.lua index ad5ad9d..c6743b3 100644 --- a/tests/rupval.lua +++ b/tests/rupval.lua | |||
@@ -26,17 +26,17 @@ end | |||
26 | local g = lanes.gen( "base", { name = 'auto' }, a) | 26 | local g = lanes.gen( "base", { name = 'auto' }, a) |
27 | 27 | ||
28 | local l = g(7) | 28 | local l = g(7) |
29 | local r = l:join() | 29 | local _, r = l:join() |
30 | assert(r == y) | 30 | assert(r == y) |
31 | print(r) | 31 | print(r) |
32 | 32 | ||
33 | local l = g(8) | 33 | local l = g(8) |
34 | local r = l:join() | 34 | local _, r = l:join() |
35 | assert(r == z) | 35 | assert(r == z) |
36 | print(r) | 36 | print(r) |
37 | 37 | ||
38 | local l = g(9) | 38 | local l = g(9) |
39 | local r = l:join() | 39 | local _, r = l:join() |
40 | assert(r == x) | 40 | assert(r == x) |
41 | print(r) | 41 | print(r) |
42 | 42 | ||
diff --git a/tests/tobeclosed.lua b/tests/tobeclosed.lua index ef09df3..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 | |||
58 | WR "================================================================================================" | 58 | WR "================================================================================================" |
59 | WR "Through Linda" | 59 | WR "Through Linda" |
60 | do | 60 | do |
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 |
@@ -99,14 +99,14 @@ end | |||
99 | WR "================================================================================================" | 99 | WR "================================================================================================" |
100 | WR "Linda closing through Lane" | 100 | WR "Linda closing through Lane" |
101 | do | 101 | do |
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("*", { name = 'auto' }, 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 d1670ae..ef2ca06 100644 --- a/tests/track_lanes.lua +++ b/tests/track_lanes.lua | |||
@@ -59,8 +59,10 @@ local threads = track( "============= START", 2) | |||
59 | -- two_seconds forever | 59 | -- two_seconds forever |
60 | assert(threads[1].status == 'waiting' and threads[2].status == 'waiting') | 60 | assert(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 |
63 | SLEEP(2.1) | 63 | repeat |
64 | SLEEP(0.1) | ||
65 | until ephemeral1.status == "done" | ||
64 | 66 | ||
65 | local threads = track( "============= two_seconds dead", 2) | 67 | local threads = track( "============= two_seconds dead", 2) |
66 | -- two_seconds forever | 68 | -- two_seconds forever |