aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basic.lua36
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
26end 26end
27 27
28local gc_cb = function( name_, status_)
29 PRINT( " ---> lane '" .. name_ .. "' collected with status " .. status_)
30end
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
72end 77end
73 78
74local task_launch= lanes_gen( "", { globals={hey=true} }, task ) 79local 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
101assert( lane1.status == "done" ) 106assert( lane1.status == "done" )
102assert( lane1.status == "done" ) 107assert( lane1.status == "done" )
108lane1, lane2 = nil
109collectgarbage()
103 110
104--############################################################## 111--##############################################################
105--############################################################## 112--##############################################################
@@ -107,7 +114,7 @@ assert( lane1.status == "done" )
107 114
108PRINT( "\n\n", "---=== Tasking (cancelling) ===---", "\n\n") 115PRINT( "\n\n", "---=== Tasking (cancelling) ===---", "\n\n")
109 116
110local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true} }, task ) 117local task_launch2= lanes_gen( "", { cancelstep=100, globals={hey=true}, gc_cb = gc_cb}, task )
111 118
112local N=999999999 119local N=999999999
113local lane9= task_launch2(1,N,1) -- huuuuuuge... 120local lane9= task_launch2(1,N,1) -- huuuuuuge...
@@ -196,7 +203,7 @@ PRINT( "\n\n", "---=== Communications ===---", "\n\n")
196local function WR(...) io.stderr:write(...) end 203local function WR(...) io.stderr:write(...) end
197 204
198local chunk= function( linda ) 205local 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
226local function SEND(...) linda:send( "->", ... ) end 233local function SEND(...) linda:send( "->", ... ) end
227local function RECEIVE() local k,v = linda:receive( 1, "<-" ) return v end 234local function RECEIVE() local k,v = linda:receive( 1, "<-" ) return v end
228 235
229local t= lanes_gen("io",chunk)(linda) -- prepare & launch 236local t= lanes_gen("io", {gc_cb = gc_cb}, chunk)(linda) -- prepare & launch
230 237
231SEND(1); WR( "1 sent\n" ) 238SEND(1); WR( "1 sent\n" )
232SEND(2); WR( "2 sent\n" ) 239SEND(2); WR( "2 sent\n" )
@@ -256,6 +263,8 @@ assert( tables_match( a, {'a','b','c',d=10} ) )
256assert( PEEK() == nil ) 263assert( PEEK() == nil )
257SEND(4) 264SEND(4)
258 265
266t = nil
267collectgarbage()
259-- wait 268-- wait
260linda: receive( 1, "wait") 269linda: receive( 1, "wait")
261 270
@@ -266,6 +275,7 @@ linda: receive( 1, "wait")
266PRINT( "\n\n", "---=== Stdlib naming ===---", "\n\n") 275PRINT( "\n\n", "---=== Stdlib naming ===---", "\n\n")
267 276
268local function dump_g( _x) 277local 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)
275end 285end
276 286
277local function io_os_f( _x) 287local 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)
283end 294end
284 295
285local function coro_f( _x) 296local 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
290end 302end
291 303
292assert.fails( function() lanes_gen( "xxx", io_os_f ) end ) 304assert.fails( function() lanes_gen( "xxx", {gc_cb = gc_cb}, io_os_f ) end )
293 305
294local stdlib_naming_tests = 306local stdlib_naming_tests =
295{ 307{
@@ -305,10 +317,12 @@ local stdlib_naming_tests =
305} 317}
306 318
307for _, t in ipairs( stdlib_naming_tests) do 319for _, 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] )
310end 322end
311 323
324collectgarbage()
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--
320local tc= lanes_gen( "io", 334local 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
339local _= a[1],b[1] -- waits until they are both ready 353local _= a[1],b[1] -- waits until they are both ready
340 354
355a, b = nil
356collectgarbage()
341 357
342--############################################################## 358--##############################################################
343--############################################################## 359--##############################################################
@@ -378,7 +394,7 @@ local function chunk2( linda )
378end 394end
379 395
380local linda= lanes.linda() 396local linda= lanes.linda()
381local t2= lanes_gen( "debug,string,io", chunk2 )(linda) -- prepare & launch 397local t2= lanes_gen( "debug,string,io", {gc_cb = gc_cb}, chunk2 )(linda) -- prepare & launch
382linda:send( "down", function(linda) linda:send( "up", "ready!" ) end, 398linda: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
414local S= lanes_gen( "table", 430local 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)