aboutsummaryrefslogtreecommitdiff
path: root/tests/basic.lua
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-03-14 14:53:09 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2025-03-14 14:53:09 +0100
commit512f4c0b46ea5cc359e673b7379cd81925863121 (patch)
tree1e72167d8d63f44109719db9643d4c0445b17d57 /tests/basic.lua
parent0aa030db022c57947afbae3b97038a403973e3cd (diff)
downloadlanes-master.tar.gz
lanes-master.tar.bz2
lanes-master.zip
Give a name to all lanes in the testsHEADmaster
Diffstat (limited to 'tests/basic.lua')
-rw-r--r--tests/basic.lua24
1 files changed, 12 insertions, 12 deletions
diff --git a/tests/basic.lua b/tests/basic.lua
index 820d3c8..068dc25 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...
@@ -177,7 +177,7 @@ local wait_send = function()
177 a,b = limited:send("key", "bybye") -- infinite timeout, returns only when lane is cancelled 177 a,b = limited:send("key", "bybye") -- infinite timeout, returns only when lane is cancelled
178end 178end
179 179
180local wait_send_lane = lanes.gen("*", wait_send)() 180local wait_send_lane = lanes.gen("*", { name = 'auto' }, wait_send)()
181repeat until wait_send_lane.status == "waiting" 181repeat until wait_send_lane.status == "waiting"
182print "wait_send_lane is waiting" 182print "wait_send_lane is waiting"
183wait_send_lane:cancel() -- hard cancel, 0 timeout 183wait_send_lane:cancel() -- hard cancel, 0 timeout
@@ -190,7 +190,7 @@ local wait_receive = function()
190 k, v = limited:receive("dummy") -- infinite timeout, returns only when lane is cancelled 190 k, v = limited:receive("dummy") -- infinite timeout, returns only when lane is cancelled
191end 191end
192 192
193local wait_receive_lane = lanes.gen("*", wait_receive)() 193local wait_receive_lane = lanes.gen("*", { name = 'auto' }, wait_receive)()
194repeat until wait_receive_lane.status == "waiting" 194repeat until wait_receive_lane.status == "waiting"
195print "wait_receive_lane is waiting" 195print "wait_receive_lane is waiting"
196wait_receive_lane:cancel() -- hard cancel, 0 timeout 196wait_receive_lane:cancel() -- hard cancel, 0 timeout
@@ -203,7 +203,7 @@ local wait_receive_batched = function()
203 k, v1, v2 = limited:receive(limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled 203 k, v1, v2 = limited:receive(limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled
204end 204end
205 205
206local wait_receive_batched_lane = lanes.gen("*", wait_receive_batched)() 206local wait_receive_batched_lane = lanes.gen("*", { name = 'auto' }, wait_receive_batched)()
207repeat until wait_receive_batched_lane.status == "waiting" 207repeat until wait_receive_batched_lane.status == "waiting"
208print "wait_receive_batched_lane is waiting" 208print "wait_receive_batched_lane is waiting"
209wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout 209wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout
@@ -275,7 +275,7 @@ local function PEEK(...) return linda:get("<-", ...) end
275local function SEND(...) local _res, _err = linda:send("->", ...) assert(_res == true and _err == nil) end 275local 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 276local function RECEIVE() local k,v = linda:receive(1, "<-") return v end
277 277
278local comms_lane = lanes_gen("io", {gc_cb = gc_cb, name = "auto"}, chunk)(linda) -- prepare & launch 278local comms_lane = lanes.gen("io", { name = 'auto', gc_cb = gc_cb }, chunk)(linda) -- prepare & launch
279 279
280SEND(1); WR("main ", "1 sent\n") 280SEND(1); WR("main ", "1 sent\n")
281SEND(2); WR("main ", "2 sent\n") 281SEND(2); WR("main ", "2 sent\n")
@@ -355,7 +355,7 @@ local function coro_f(_x)
355 return true 355 return true
356end 356end
357 357
358assert.fails(function() lanes_gen("xxx", {gc_cb = gc_cb}, io_os_f) end) 358assert.fails(function() lanes_gen("xxx", {name = 'auto', gc_cb = gc_cb }, io_os_f) end)
359 359
360local stdlib_naming_tests = 360local stdlib_naming_tests =
361{ 361{
@@ -371,7 +371,7 @@ local stdlib_naming_tests =
371} 371}
372 372
373for _, t in ipairs(stdlib_naming_tests) do 373for _, t in ipairs(stdlib_naming_tests) do
374 local f= lanes_gen(t[1], {gc_cb = gc_cb}, t[2]) -- any delimiter will do 374 local f= lanes.gen(t[1], { name = 'auto', gc_cb = gc_cb }, t[2]) -- any delimiter will do
375 assert(f(t[1])[1]) 375 assert(f(t[1])[1])
376end 376end
377 377
@@ -386,7 +386,7 @@ PRINT("\n\n", "---=== Comms criss cross ===---", "\n\n")
386 386
387-- We make two identical lanes, which are using the same Linda channel. 387-- We make two identical lanes, which are using the same Linda channel.
388-- 388--
389local tc= lanes_gen("io", {gc_cb = gc_cb}, 389local tc = lanes.gen("io", { name = 'auto', gc_cb = gc_cb },
390 function(linda, ch_in, ch_out) 390 function(linda, ch_in, ch_out)
391 lane_threadname("criss cross " .. ch_in .. " -> " .. ch_out) 391 lane_threadname("criss cross " .. ch_in .. " -> " .. ch_out)
392 local function STAGE(str) 392 local function STAGE(str)
@@ -453,7 +453,7 @@ local function chunk2(linda)
453end 453end
454 454
455local linda = lanes_linda("auto") 455local linda = lanes_linda("auto")
456local t2= lanes_gen("debug,string,io", {gc_cb = gc_cb}, chunk2)(linda) -- prepare & launch 456local 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, 457linda:send("down", function(linda) linda:send("up", "ready!") end,
458 "ok") 458 "ok")
459-- wait to see if the tiny function gets executed 459-- wait to see if the tiny function gets executed
@@ -486,7 +486,7 @@ PRINT("\n\n", "---=== :join test ===---", "\n\n")
486-- (unless [1..n] has been read earlier, in which case it would seemingly 486-- (unless [1..n] has been read earlier, in which case it would seemingly
487-- work). 487-- work).
488 488
489local S= lanes_gen("table", {gc_cb = gc_cb}, 489local S = lanes.gen("table", { name = 'auto', gc_cb = gc_cb },
490 function(arg) 490 function(arg)
491 lane_threadname "join test lane" 491 lane_threadname "join test lane"
492 set_finalizer(function() end) 492 set_finalizer(function() end)