aboutsummaryrefslogtreecommitdiff
path: root/unit_tests
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2025-07-24 16:51:49 +0200
committerBenoit Germain <bnt.germain@gmail.com>2025-07-24 16:51:49 +0200
commitd8acb18ce8bf6e89a042d166f61b2934e8722cf0 (patch)
tree69f5046056f4aa38b868b057055da8144e029846 /unit_tests
parenteb997664a5a0a7890efa050982854a1447aec70f (diff)
downloadlanes-d8acb18ce8bf6e89a042d166f61b2934e8722cf0.tar.gz
lanes-d8acb18ce8bf6e89a042d166f61b2934e8722cf0.tar.bz2
lanes-d8acb18ce8bf6e89a042d166f61b2934e8722cf0.zip
Rework function bytecode dumping to be Lua5.5-ready
* prepare the luaL_Buffer in the destination state instead of the source state to prevent stack issues when everything happens in the same state
Diffstat (limited to 'unit_tests')
-rw-r--r--unit_tests/UnitTests.vcxproj.filters3
-rw-r--r--unit_tests/linda_tests.cpp1
-rw-r--r--unit_tests/scripts/lane/tasking_send_receive_code.lua18
-rw-r--r--unit_tests/scripts/linda/send_receive_func_and_string.lua13
4 files changed, 25 insertions, 10 deletions
diff --git a/unit_tests/UnitTests.vcxproj.filters b/unit_tests/UnitTests.vcxproj.filters
index a1db461..33d484a 100644
--- a/unit_tests/UnitTests.vcxproj.filters
+++ b/unit_tests/UnitTests.vcxproj.filters
@@ -146,5 +146,8 @@
146 <None Include="scripts\coro\cancelling_suspended.lua"> 146 <None Include="scripts\coro\cancelling_suspended.lua">
147 <Filter>Scripts\coro</Filter> 147 <Filter>Scripts\coro</Filter>
148 </None> 148 </None>
149 <None Include="scripts\linda\send_receive_func_and_string.lua">
150 <Filter>Scripts\linda</Filter>
151 </None>
149 </ItemGroup> 152 </ItemGroup>
150</Project> \ No newline at end of file 153</Project> \ No newline at end of file
diff --git a/unit_tests/linda_tests.cpp b/unit_tests/linda_tests.cpp
index a36723a..8d3cd50 100644
--- a/unit_tests/linda_tests.cpp
+++ b/unit_tests/linda_tests.cpp
@@ -390,6 +390,7 @@ TEST_CASE("scripted_tests." #DIR "." #FILE) \
390 390
391MAKE_TEST_CASE(linda, multiple_keepers) 391MAKE_TEST_CASE(linda, multiple_keepers)
392MAKE_TEST_CASE(linda, send_receive) 392MAKE_TEST_CASE(linda, send_receive)
393MAKE_TEST_CASE(linda, send_receive_func_and_string)
393MAKE_TEST_CASE(linda, send_registered_userdata) 394MAKE_TEST_CASE(linda, send_registered_userdata)
394MAKE_TEST_CASE(linda, wake_period) 395MAKE_TEST_CASE(linda, wake_period)
395 396
diff --git a/unit_tests/scripts/lane/tasking_send_receive_code.lua b/unit_tests/scripts/lane/tasking_send_receive_code.lua
index cb3663f..fdc2602 100644
--- a/unit_tests/scripts/lane/tasking_send_receive_code.lua
+++ b/unit_tests/scripts/lane/tasking_send_receive_code.lua
@@ -53,28 +53,26 @@ local function chunk2(linda)
53 assert(info.linedefined == 32, "bad linedefined") -- start of 'chunk2' 53 assert(info.linedefined == 32, "bad linedefined") -- start of 'chunk2'
54 assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo' 54 assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo'
55 assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2' 55 assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2'
56 local k,func= linda:receive("down") 56 assert(linda:count("down") == 2, "bad linda contents") -- function, "ok"
57 assert(type(func)=="function", "not a function") 57 local k,func,str= linda:receive_batched("down", 2)
58 assert(k=="down") 58 assert(k=="down")
59 assert(type(func)=="function", "not a function")
60 assert(str=="ok", "bad receive result: " .. tostring(k) .. " -> ".. tostring(str))
61 assert(linda:count("down") == 0, "bad linda contents") -- nothing
59 62
60 func(linda) 63 func(linda)
61
62 local k,str= linda:receive("down")
63 assert(str=="ok", "bad receive result")
64
65 linda:send("up", function() return ":)" end, "ok2") 64 linda:send("up", function() return ":)" end, "ok2")
66end 65end
67 66
68local linda = lanes_linda{name = "auto"} 67local linda = lanes_linda{name = "auto"}
69local t2= lanes_gen("debug,package,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch 68local t2= lanes_gen("debug,package,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch
70linda:send("down", function(linda) linda:send("up", "ready!") end, 69linda:send("down", function(linda) linda:send("up", "ready!") end, "ok")
71 "ok")
72-- wait to see if the tiny function gets executed 70-- wait to see if the tiny function gets executed
73-- 71--
74local k,s= linda:receive(1, "up") 72local k,s= linda:receive(1, "up")
75if t2.status == "error" then 73if t2.status == "error" then
76 PRINT("t2 error: " , t2:join()) 74 local n,err,s = t2:join()
77 assert(false) 75 assert(false, "t2 error: " .. err)
78end 76end
79PRINT(s) 77PRINT(s)
80assert(s=="ready!", s .. " is not 'ready!'") 78assert(s=="ready!", s .. " is not 'ready!'")
diff --git a/unit_tests/scripts/linda/send_receive_func_and_string.lua b/unit_tests/scripts/linda/send_receive_func_and_string.lua
new file mode 100644
index 0000000..188cfcd
--- /dev/null
+++ b/unit_tests/scripts/linda/send_receive_func_and_string.lua
@@ -0,0 +1,13 @@
1local lanes = require "lanes"
2
3-- a newly created linda doesn't contain anything
4local l = lanes.linda()
5
6-- send a function and a string, make sure that's what we read back
7l:send("k", function() end, "str")
8local c = l:count("k")
9assert(c == 2, "got " .. c)
10local k, v1, v2 = l:receive_batched("k", 2)
11local tv1, tv2 = type(v1), type(v2)
12assert(k == "k" and tv1 == "function" and tv2 == "string", "got " .. tv1 .. " " .. tv2)
13assert(l:count("k") == 0)