diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-03-14 14:53:09 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-03-14 14:53:09 +0100 |
commit | 512f4c0b46ea5cc359e673b7379cd81925863121 (patch) | |
tree | 1e72167d8d63f44109719db9643d4c0445b17d57 /tests/basic.lua | |
parent | 0aa030db022c57947afbae3b97038a403973e3cd (diff) | |
download | lanes-master.tar.gz lanes-master.tar.bz2 lanes-master.zip |
Diffstat (limited to 'tests/basic.lua')
-rw-r--r-- | tests/basic.lua | 24 |
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 | |||
15 | local require_assert_result_1, require_assert_result_2 = require "assert" -- assert.fails() | 15 | local require_assert_result_1, require_assert_result_2 = require "assert" -- assert.fails() |
16 | print("require_assert_result:", require_assert_result_1, require_assert_result_2) | 16 | print("require_assert_result:", require_assert_result_1, require_assert_result_2) |
17 | 17 | ||
18 | local lanes_gen= assert(lanes.gen) | 18 | local lanes_gen assert(lanes.gen) |
19 | local lanes_linda = assert(lanes.linda) | 19 | local lanes_linda = assert(lanes.linda) |
20 | 20 | ||
21 | local tostring= assert(tostring) | 21 | local tostring= assert(tostring) |
@@ -86,7 +86,7 @@ local function task(a, b, c) | |||
86 | return v, hey | 86 | return v, hey |
87 | end | 87 | end |
88 | 88 | ||
89 | local task_launch= lanes_gen("", { globals={hey=true}, gc_cb = gc_cb}, task) | 89 | local 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 | ||
127 | PRINT("\n\n", "---=== Tasking (cancelling) ===---", "\n\n") | 127 | PRINT("\n\n", "---=== Tasking (cancelling) ===---", "\n\n") |
128 | 128 | ||
129 | local task_launch2= lanes_gen("", { globals={hey=true}, gc_cb = gc_cb}, task) | 129 | local task_launch2= lanes.gen("", { name = 'auto', globals={hey=true}, gc_cb = gc_cb }, task) |
130 | 130 | ||
131 | local N=999999999 | 131 | local N=999999999 |
132 | local lane9= task_launch2(1,N,1) -- huuuuuuge... | 132 | local 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 |
178 | end | 178 | end |
179 | 179 | ||
180 | local wait_send_lane = lanes.gen("*", wait_send)() | 180 | local wait_send_lane = lanes.gen("*", { name = 'auto' }, wait_send)() |
181 | repeat until wait_send_lane.status == "waiting" | 181 | repeat until wait_send_lane.status == "waiting" |
182 | print "wait_send_lane is waiting" | 182 | print "wait_send_lane is waiting" |
183 | wait_send_lane:cancel() -- hard cancel, 0 timeout | 183 | wait_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 |
191 | end | 191 | end |
192 | 192 | ||
193 | local wait_receive_lane = lanes.gen("*", wait_receive)() | 193 | local wait_receive_lane = lanes.gen("*", { name = 'auto' }, wait_receive)() |
194 | repeat until wait_receive_lane.status == "waiting" | 194 | repeat until wait_receive_lane.status == "waiting" |
195 | print "wait_receive_lane is waiting" | 195 | print "wait_receive_lane is waiting" |
196 | wait_receive_lane:cancel() -- hard cancel, 0 timeout | 196 | wait_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 |
204 | end | 204 | end |
205 | 205 | ||
206 | local wait_receive_batched_lane = lanes.gen("*", wait_receive_batched)() | 206 | local wait_receive_batched_lane = lanes.gen("*", { name = 'auto' }, wait_receive_batched)() |
207 | repeat until wait_receive_batched_lane.status == "waiting" | 207 | repeat until wait_receive_batched_lane.status == "waiting" |
208 | print "wait_receive_batched_lane is waiting" | 208 | print "wait_receive_batched_lane is waiting" |
209 | wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout | 209 | wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout |
@@ -275,7 +275,7 @@ local function PEEK(...) return linda:get("<-", ...) end | |||
275 | local function SEND(...) local _res, _err = linda:send("->", ...) assert(_res == true and _err == nil) end | 275 | local function SEND(...) local _res, _err = linda:send("->", ...) assert(_res == true and _err == nil) end |
276 | local function RECEIVE() local k,v = linda:receive(1, "<-") return v end | 276 | local function RECEIVE() local k,v = linda:receive(1, "<-") return v end |
277 | 277 | ||
278 | local comms_lane = lanes_gen("io", {gc_cb = gc_cb, name = "auto"}, chunk)(linda) -- prepare & launch | 278 | local comms_lane = lanes.gen("io", { name = 'auto', gc_cb = gc_cb }, chunk)(linda) -- prepare & launch |
279 | 279 | ||
280 | SEND(1); WR("main ", "1 sent\n") | 280 | SEND(1); WR("main ", "1 sent\n") |
281 | SEND(2); WR("main ", "2 sent\n") | 281 | SEND(2); WR("main ", "2 sent\n") |
@@ -355,7 +355,7 @@ local function coro_f(_x) | |||
355 | return true | 355 | return true |
356 | end | 356 | end |
357 | 357 | ||
358 | assert.fails(function() lanes_gen("xxx", {gc_cb = gc_cb}, io_os_f) end) | 358 | assert.fails(function() lanes_gen("xxx", {name = 'auto', gc_cb = gc_cb }, io_os_f) end) |
359 | 359 | ||
360 | local stdlib_naming_tests = | 360 | local stdlib_naming_tests = |
361 | { | 361 | { |
@@ -371,7 +371,7 @@ local stdlib_naming_tests = | |||
371 | } | 371 | } |
372 | 372 | ||
373 | for _, t in ipairs(stdlib_naming_tests) do | 373 | for _, 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]) |
376 | end | 376 | end |
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 | -- |
389 | local tc= lanes_gen("io", {gc_cb = gc_cb}, | 389 | local 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) | |||
453 | end | 453 | end |
454 | 454 | ||
455 | local linda = lanes_linda("auto") | 455 | local linda = lanes_linda("auto") |
456 | local t2= lanes_gen("debug,string,io", {gc_cb = gc_cb}, chunk2)(linda) -- prepare & launch | 456 | 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, | 457 | linda: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 | ||
489 | local S= lanes_gen("table", {gc_cb = gc_cb}, | 489 | local 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) |