diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic.lua | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/tests/basic.lua b/tests/basic.lua index 5b0d8a7..16919a3 100644 --- a/tests/basic.lua +++ b/tests/basic.lua | |||
@@ -25,6 +25,11 @@ local function PRINT(...) | |||
25 | end | 25 | end |
26 | end | 26 | end |
27 | 27 | ||
28 | local gc_cb = function( name_, status_) | ||
29 | PRINT( " ---> lane '" .. name_ .. "' collected with status " .. status_) | ||
30 | end | ||
31 | --gc_cb = nil | ||
32 | |||
28 | 33 | ||
29 | ---=== Local helpers ===--- | 34 | ---=== Local helpers ===--- |
30 | 35 | ||
@@ -71,7 +76,7 @@ local function task( a, b, c ) | |||
71 | return v, hey | 76 | return v, hey |
72 | end | 77 | end |
73 | 78 | ||
74 | local task_launch= lanes_gen( "", { globals={hey=true} }, task ) | 79 | local task_launch= lanes_gen( "", { globals={hey=true}, gc_cb = gc_cb}, task ) |
75 | -- base stdlibs, normal priority | 80 | -- base stdlibs, normal priority |
76 | 81 | ||
77 | -- 'task_launch' is a factory of multithreaded tasks, we can launch several: | 82 | -- 'task_launch' is a factory of multithreaded tasks, we can launch several: |
@@ -100,6 +105,8 @@ assert( v2_hey == true ) | |||
100 | 105 | ||
101 | assert( lane1.status == "done" ) | 106 | assert( lane1.status == "done" ) |
102 | assert( lane1.status == "done" ) | 107 | assert( lane1.status == "done" ) |
108 | lane1, lane2 = nil | ||
109 | collectgarbage() | ||
103 | 110 | ||
104 | --############################################################## | 111 | --############################################################## |
105 | --############################################################## | 112 | --############################################################## |
@@ -107,7 +114,7 @@ assert( lane1.status == "done" ) | |||
107 | 114 | ||
108 | PRINT( "\n\n", "---=== Tasking (cancelling) ===---", "\n\n") | 115 | PRINT( "\n\n", "---=== Tasking (cancelling) ===---", "\n\n") |
109 | 116 | ||
110 | local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true} }, task ) | 117 | local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true}, gc_cb = gc_cb}, task ) |
111 | 118 | ||
112 | local N=999999999 | 119 | local N=999999999 |
113 | local lane9= task_launch2(1,N,1) -- huuuuuuge... | 120 | local lane9= task_launch2(1,N,1) -- huuuuuuge... |
@@ -196,7 +203,7 @@ PRINT( "\n\n", "---=== Communications ===---", "\n\n") | |||
196 | local function WR(...) io.stderr:write(...) end | 203 | local function WR(...) io.stderr:write(...) end |
197 | 204 | ||
198 | local chunk= function( linda ) | 205 | local chunk= function( linda ) |
199 | 206 | set_debug_threadname "chunk" | |
200 | local function receive() return linda:receive( "->" ) end | 207 | local function receive() return linda:receive( "->" ) end |
201 | local function send(...) linda:send( "<-", ... ) end | 208 | local function send(...) linda:send( "<-", ... ) end |
202 | 209 | ||
@@ -226,7 +233,7 @@ local function PEEK() return linda:get("<-") end | |||
226 | local function SEND(...) linda:send( "->", ... ) end | 233 | local function SEND(...) linda:send( "->", ... ) end |
227 | local function RECEIVE() local k,v = linda:receive( 1, "<-" ) return v end | 234 | local function RECEIVE() local k,v = linda:receive( 1, "<-" ) return v end |
228 | 235 | ||
229 | local t= lanes_gen("io",chunk)(linda) -- prepare & launch | 236 | local t= lanes_gen("io", {gc_cb = gc_cb}, chunk)(linda) -- prepare & launch |
230 | 237 | ||
231 | SEND(1); WR( "1 sent\n" ) | 238 | SEND(1); WR( "1 sent\n" ) |
232 | SEND(2); WR( "2 sent\n" ) | 239 | SEND(2); WR( "2 sent\n" ) |
@@ -256,6 +263,8 @@ assert( tables_match( a, {'a','b','c',d=10} ) ) | |||
256 | assert( PEEK() == nil ) | 263 | assert( PEEK() == nil ) |
257 | SEND(4) | 264 | SEND(4) |
258 | 265 | ||
266 | t = nil | ||
267 | collectgarbage() | ||
259 | -- wait | 268 | -- wait |
260 | linda: receive( 1, "wait") | 269 | linda: receive( 1, "wait") |
261 | 270 | ||
@@ -266,6 +275,7 @@ linda: receive( 1, "wait") | |||
266 | PRINT( "\n\n", "---=== Stdlib naming ===---", "\n\n") | 275 | PRINT( "\n\n", "---=== Stdlib naming ===---", "\n\n") |
267 | 276 | ||
268 | local function dump_g( _x) | 277 | local function dump_g( _x) |
278 | set_debug_threadname "dump_g" | ||
269 | assert(print) | 279 | assert(print) |
270 | print( "### dumping _G for '" .. _x .. "'") | 280 | print( "### dumping _G for '" .. _x .. "'") |
271 | for k, v in pairs( _G) do | 281 | for k, v in pairs( _G) do |
@@ -275,6 +285,7 @@ local function dump_g( _x) | |||
275 | end | 285 | end |
276 | 286 | ||
277 | local function io_os_f( _x) | 287 | local function io_os_f( _x) |
288 | set_debug_threadname "io_os_f" | ||
278 | assert(print) | 289 | assert(print) |
279 | print( "### checking io and os libs existence for '" .. _x .. "'") | 290 | print( "### checking io and os libs existence for '" .. _x .. "'") |
280 | assert(io) | 291 | assert(io) |
@@ -283,13 +294,14 @@ local function io_os_f( _x) | |||
283 | end | 294 | end |
284 | 295 | ||
285 | local function coro_f( _x) | 296 | local function coro_f( _x) |
297 | set_debug_threadname "coro_f" | ||
286 | assert(print) | 298 | assert(print) |
287 | print( "### checking coroutine lib existence for '" .. _x .. "'") | 299 | print( "### checking coroutine lib existence for '" .. _x .. "'") |
288 | assert(coroutine) | 300 | assert(coroutine) |
289 | return true | 301 | return true |
290 | end | 302 | end |
291 | 303 | ||
292 | assert.fails( function() lanes_gen( "xxx", io_os_f ) end ) | 304 | assert.fails( function() lanes_gen( "xxx", {gc_cb = gc_cb}, io_os_f ) end ) |
293 | 305 | ||
294 | local stdlib_naming_tests = | 306 | local stdlib_naming_tests = |
295 | { | 307 | { |
@@ -305,10 +317,12 @@ local stdlib_naming_tests = | |||
305 | } | 317 | } |
306 | 318 | ||
307 | for _, t in ipairs( stdlib_naming_tests) do | 319 | for _, t in ipairs( stdlib_naming_tests) do |
308 | local f= lanes_gen( t[1], t[2]) -- any delimiter will do | 320 | local f= lanes_gen( t[1], {gc_cb = gc_cb}, t[2]) -- any delimiter will do |
309 | assert( f(t[1])[1] ) | 321 | assert( f(t[1])[1] ) |
310 | end | 322 | end |
311 | 323 | ||
324 | collectgarbage() | ||
325 | |||
312 | --############################################################## | 326 | --############################################################## |
313 | --############################################################## | 327 | --############################################################## |
314 | --############################################################## | 328 | --############################################################## |
@@ -317,9 +331,9 @@ PRINT( "\n\n", "---=== Comms criss cross ===---", "\n\n") | |||
317 | 331 | ||
318 | -- We make two identical lanes, which are using the same Linda channel. | 332 | -- We make two identical lanes, which are using the same Linda channel. |
319 | -- | 333 | -- |
320 | local tc= lanes_gen( "io", | 334 | local tc= lanes_gen( "io", {gc_cb = gc_cb}, |
321 | function( linda, ch_in, ch_out ) | 335 | function( linda, ch_in, ch_out ) |
322 | 336 | set_debug_threadname( "criss cross " .. ch_in .. " -> " .. ch_out) | |
323 | local function STAGE(str) | 337 | local function STAGE(str) |
324 | io.stderr:write( ch_in..": "..str.."\n" ) | 338 | io.stderr:write( ch_in..": "..str.."\n" ) |
325 | linda:send( nil, ch_out, str ) | 339 | linda:send( nil, ch_out, str ) |
@@ -338,6 +352,8 @@ local a,b= tc(linda, "A","B"), tc(linda, "B","A") -- launching two lanes, twis | |||
338 | 352 | ||
339 | local _= a[1],b[1] -- waits until they are both ready | 353 | local _= a[1],b[1] -- waits until they are both ready |
340 | 354 | ||
355 | a, b = nil | ||
356 | collectgarbage() | ||
341 | 357 | ||
342 | --############################################################## | 358 | --############################################################## |
343 | --############################################################## | 359 | --############################################################## |
@@ -378,7 +394,7 @@ local function chunk2( linda ) | |||
378 | end | 394 | end |
379 | 395 | ||
380 | local linda= lanes.linda() | 396 | local linda= lanes.linda() |
381 | local t2= lanes_gen( "debug,string,io", chunk2 )(linda) -- prepare & launch | 397 | local t2= lanes_gen( "debug,string,io", {gc_cb = gc_cb}, chunk2 )(linda) -- prepare & launch |
382 | linda:send( "down", function(linda) linda:send( "up", "ready!" ) end, | 398 | linda:send( "down", function(linda) linda:send( "up", "ready!" ) end, |
383 | "ok" ) | 399 | "ok" ) |
384 | -- wait to see if the tiny function gets executed | 400 | -- wait to see if the tiny function gets executed |
@@ -411,7 +427,7 @@ PRINT( "\n\n", "---=== :join test ===---", "\n\n") | |||
411 | -- (unless [1..n] has been read earlier, in which case it would seemingly | 427 | -- (unless [1..n] has been read earlier, in which case it would seemingly |
412 | -- work). | 428 | -- work). |
413 | 429 | ||
414 | local S= lanes_gen( "table", | 430 | local S= lanes_gen( "table", {gc_cb = gc_cb}, |
415 | function(arg) | 431 | function(arg) |
416 | set_debug_threadname "join test lane" | 432 | set_debug_threadname "join test lane" |
417 | set_finalizer( function() end) | 433 | set_finalizer( function() end) |