aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-06-12 18:18:24 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-06-12 18:18:24 +0200
commitdddc28153796f9c8eb256eddb335c8643226fd0b (patch)
tree641caa9a01933d0397a99f127cff249d3a77fdb5 /tests
parentc305ff3ed1f51d86ced2bb83b10b5e0632cd98a3 (diff)
downloadlanes-dddc28153796f9c8eb256eddb335c8643226fd0b.tar.gz
lanes-dddc28153796f9c8eb256eddb335c8643226fd0b.tar.bz2
lanes-dddc28153796f9c8eb256eddb335c8643226fd0b.zip
linda :get(), :set(), :limit() return value changes
Diffstat (limited to 'tests')
-rw-r--r--tests/basic.lua24
-rw-r--r--tests/cancel.lua7
-rw-r--r--tests/errhangtest.lua12
-rw-r--r--tests/keeper.lua5
-rw-r--r--tests/linda_perf.lua10
-rw-r--r--tests/timer.lua7
-rw-r--r--tests/tobeclosed.lua13
7 files changed, 45 insertions, 33 deletions
diff --git a/tests/basic.lua b/tests/basic.lua
index bdad44c..ae8ebd9 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -252,21 +252,21 @@ assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications")
252 252
253WR "test linda:get/set..." 253WR "test linda:get/set..."
254linda:set("<->", "x", "y", "z") 254linda:set("<->", "x", "y", "z")
255local x,y,z = linda:get("<->", 1) 255local b,x,y,z = linda:get("<->", 1)
256assert(x == "x" and y == nil and z == nil) 256assert(b == 1 and x == "x" and y == nil and z == nil)
257local x,y,z = linda:get("<->", 2) 257local b,x,y,z = linda:get("<->", 2)
258assert(x == "x" and y == "y" and z == nil) 258assert(b == 2 and x == "x" and y == "y" and z == nil)
259local x,y,z = linda:get("<->", 3) 259local b,x,y,z = linda:get("<->", 3)
260assert(x == "x" and y == "y" and z == "z") 260assert(b == 3 and x == "x" and y == "y" and z == "z")
261local x,y,z,w = linda:get("<->", 4) 261local b,x,y,z,w = linda:get("<->", 4)
262assert(x == "x" and y == "y" and z == "z" and w == nil) 262assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil)
263local k, x = linda:receive("<->") 263local k, x = linda:receive("<->")
264assert(k == "<->" and x == "x") 264assert(k == "<->" and x == "x")
265local k,y,z = linda:receive(linda.batched, "<->", 2) 265local k,y,z = linda:receive(linda.batched, "<->", 2)
266assert(k == "<->" and y == "y" and z == "z") 266assert(k == "<->" and y == "y" and z == "z")
267linda:set("<->") 267linda:set("<->")
268local x,y,z,w = linda:get("<->", 4) 268local b,x,y,z,w = linda:get("<->", 4)
269assert(x == nil and y == nil and z == nil and w == nil) 269assert(b == 0 and x == nil and y == nil and z == nil and w == nil)
270WR "ok\n" 270WR "ok\n"
271 271
272local function PEEK(...) return linda:get("<-", ...) end 272local function PEEK(...) return linda:get("<-", ...) end
@@ -282,7 +282,7 @@ SEND(setmetatable({"should be ignored"},{__lanesconvert=lanes.null})); WR("main
282for i=1,40 do 282for i=1,40 do
283 WR "." 283 WR "."
284 SLEEP(0.0001) 284 SLEEP(0.0001)
285 assert(PEEK() == nil) -- nothing coming in, yet 285 assert(PEEK() == 0) -- nothing coming in, yet
286end 286end
287SEND(nil); WR("\nmain ", "nil sent\n") 287SEND(nil); WR("\nmain ", "nil sent\n")
288 288
@@ -306,7 +306,7 @@ assert(null==nil)
306local out_t = RECEIVE(); WR(type(out_t).." received\n") 306local out_t = RECEIVE(); WR(type(out_t).." received\n")
307assert(tables_match(out_t, {'a','b','c',d=10})) 307assert(tables_match(out_t, {'a','b','c',d=10}))
308 308
309assert(PEEK() == nil) 309assert(PEEK() == 0)
310SEND(4) 310SEND(4)
311 311
312local complex_table = RECEIVE(); WR(type(complex_table).." received\n") 312local complex_table = RECEIVE(); WR(type(complex_table).." received\n")
diff --git a/tests/cancel.lua b/tests/cancel.lua
index 42ae839..d6c293d 100644
--- a/tests/cancel.lua
+++ b/tests/cancel.lua
@@ -38,7 +38,8 @@ if not next(which_tests) or which_tests.genlock then
38 38
39 -- check that cancelled lindas give cancel_error as they should 39 -- check that cancelled lindas give cancel_error as they should
40 linda:cancel() 40 linda:cancel()
41 assert( linda:get( "empty") == lanes.cancel_error) 41 local _status, _err = linda:get( "empty")
42 assert(_status == nil and _err == lanes.cancel_error)
42 assert( lanes.genlock( linda, "any", 1) == lanes.cancel_error) 43 assert( lanes.genlock( linda, "any", 1) == lanes.cancel_error)
43 assert( lanes.genatomic( linda, "any") == lanes.cancel_error) 44 assert( lanes.genatomic( linda, "any") == lanes.cancel_error)
44 45
@@ -102,14 +103,14 @@ local laneBody = function( mode_, payload_)
102 io.stdout:write( " lane busy waiting ... ") 103 io.stdout:write( " lane busy waiting ... ")
103 for i = 1, payload_ do 104 for i = 1, payload_ do
104 -- force a non-jitable call 105 -- force a non-jitable call
105 local a = linda:get( "val") 106 local _, a = linda:get( "val")
106 a = a * 2 107 a = a * 2
107 end 108 end
108 print( "again?") 109 print( "again?")
109 elseif mode_ == "busy" then 110 elseif mode_ == "busy" then
110 -- busy wait mode in pure Lua code 111 -- busy wait mode in pure Lua code
111 io.stdout:write( " lane busy waiting ... ") 112 io.stdout:write( " lane busy waiting ... ")
112 local a = linda:get( "val") 113 local _, a = linda:get( "val")
113 for i = 1, payload_ do 114 for i = 1, payload_ do
114 a = a * 2 115 a = a * 2
115 a = math.sin( a) * math.sin( a) + math.cos( a) * math.cos( a) -- aka 1 116 a = math.sin( a) * math.sin( a) + math.cos( a) * math.cos( a) -- aka 1
diff --git a/tests/errhangtest.lua b/tests/errhangtest.lua
index d0ffcc4..fff0dee 100644
--- a/tests/errhangtest.lua
+++ b/tests/errhangtest.lua
@@ -11,7 +11,8 @@ if true then
11 print "#### coro set" 11 print "#### coro set"
12 local coro = coroutine.create(function() end) 12 local coro = coroutine.create(function() end)
13 print(pcall(linda.set, linda, 'test', coro)) 13 print(pcall(linda.set, linda, 'test', coro))
14 assert(linda:get("test") == nil) 14 local _count, _val = linda:get("test")
15 assert(_count == 0 and _val == nil)
15 print "OK" 16 print "OK"
16end 17end
17 18
@@ -19,7 +20,8 @@ if true then
19 print "\n#### reserved sentinels" 20 print "\n#### reserved sentinels"
20 print(pcall(linda.set, linda, lanes.cancel_error)) 21 print(pcall(linda.set, linda, lanes.cancel_error))
21 print(pcall(linda.set, linda, linda.batched)) 22 print(pcall(linda.set, linda, linda.batched))
22 assert(linda:get("test") == nil) 23 local _count, _val = linda:get("test")
24 assert(_count == 0 and _val == nil)
23 print "OK" 25 print "OK"
24end 26end
25 27
@@ -33,7 +35,8 @@ if true then
33 print(pcall(linda.set, linda, 'test', true, nil, fun)) 35 print(pcall(linda.set, linda, 'test', true, nil, fun))
34 -- read back the contents 36 -- read back the contents
35 local k,b,n,f = linda:receive(linda.batched, 'test', 3) 37 local k,b,n,f = linda:receive(linda.batched, 'test', 3)
36 assert(linda:get("test") == nil) 38 local _count, _val = linda:get("test")
39 assert(_count == 0 and _val == nil)
37 -- check they are ok 40 -- check they are ok
38 print(k, b, n) 41 print(k, b, n)
39 f() 42 f()
@@ -70,7 +73,8 @@ if true then
70 print "\n#### coro send" 73 print "\n#### coro send"
71 local coro = coroutine.create(function() end) 74 local coro = coroutine.create(function() end)
72 print(pcall(linda.send, linda, 'test', coro)) 75 print(pcall(linda.send, linda, 'test', coro))
73 assert(linda:get("test") == nil) 76 local _count, _val = linda:get("test")
77 assert(_count == 0 and _val == nil)
74 print "OK" 78 print "OK"
75end 79end
76 80
diff --git a/tests/keeper.lua b/tests/keeper.lua
index 2f731f0..0e93de2 100644
--- a/tests/keeper.lua
+++ b/tests/keeper.lua
@@ -108,8 +108,9 @@ if true then
108 108
109 local function keeper(linda) 109 local function keeper(linda)
110 local mt= { 110 local mt= {
111 __index= function( _, key ) 111 __index= function(_, key)
112 return linda:get( key ) 112 local _count, _val = linda:get(key)
113 return _val
113 end, 114 end,
114 __newindex= function( _, key, val ) 115 __newindex= function( _, key, val )
115 linda:set( key, val ) 116 linda:set( key, val )
diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua
index 4b0c005..96f26f4 100644
--- a/tests/linda_perf.lua
+++ b/tests/linda_perf.lua
@@ -18,22 +18,22 @@ local finalizer = function(err, stk)
18end 18end
19 19
20-- ################################################################################################# 20-- #################################################################################################
21if false then 21if true then
22 do 22 do
23 print "############################################ tests get/set" 23 print "############################################ tests get/set"
24 -- linda:get throughput 24 -- linda:get throughput
25 local l = lanes.linda("get/set") 25 local l = lanes.linda("get/set", 1)
26 local batch = {} 26 local batch = {}
27 for i = 1,1000 do 27 for i = 1,1000 do
28 table.insert(batch, i) 28 table.insert(batch, i)
29 end 29 end
30 for _,size in ipairs{1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 } do 30 for _,size in ipairs{1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 } do
31 l:set("<->", table_unpack(batch)) 31 l:set("<->", table_unpack(batch))
32 local count = math.floor(20000000/size) 32 local count = math.floor(20000/math.sqrt(size))
33 print("START", "get("..size..") " .. count, " times") 33 print("START", "get("..size..") " .. count, " times")
34 local t1 = lanes.now_secs() 34 local t1 = lanes.now_secs()
35 for i = 1, 2000000/math.sqrt(size) do 35 for i = 1, count do
36 l:get("<->", size) 36 assert (l:get("<->", size) == size)
37 end 37 end
38 print("DURATION = " .. lanes.now_secs() - t1 .. "\n") 38 print("DURATION = " .. lanes.now_secs() - t1 .. "\n")
39 end 39 end
diff --git a/tests/timer.lua b/tests/timer.lua
index 4da1a50..ac8b385 100644
--- a/tests/timer.lua
+++ b/tests/timer.lua
@@ -94,8 +94,11 @@ lanes.timer( linda, T2, 0 )
94linda:receive( 0, T1 ) -- clear out; there could be one tick left 94linda:receive( 0, T1 ) -- clear out; there could be one tick left
95linda:receive( 0, T2 ) 95linda:receive( 0, T2 )
96 96
97assert( linda:get(T1) == nil ) 97local _count, _val = linda:get(T1)
98assert( linda:get(T2) == nil ) 98assert(_count == 0 and _val == nil)
99
100local _count, _val = linda:get(T2)
101assert(_count == 0 and _val == nil)
99 102
100PRINT "...making sure no ticks are coming..." 103PRINT "...making sure no ticks are coming..."
101 104
diff --git a/tests/tobeclosed.lua b/tests/tobeclosed.lua
index 6e3de4c..5ac8ab7 100644
--- a/tests/tobeclosed.lua
+++ b/tests/tobeclosed.lua
@@ -69,9 +69,10 @@ do
69 69
70 do 70 do
71 71
72 local l_out <close> = l:get("trip") 72 local _, l_out <close> = l:get("trip")
73 end 73 end
74 assert(l_in:get("closed") == true) 74 local _count, _closed = l_in:get("closed")
75 assert(_count == 1 and _closed == true)
75end 76end
76 77
77-- ################################################################################################# 78-- #################################################################################################
@@ -100,7 +101,7 @@ do
100 local lane_body = function(l_arg_) 101 local lane_body = function(l_arg_)
101 WR "In lane body" 102 WR "In lane body"
102 -- linda obtained through a linda 103 -- linda obtained through a linda
103 local l_out <close> = l:get("trip") 104 local _count, l_out <close> = l:get("trip")
104 -- linda from arguments 105 -- linda from arguments
105 local l_arg <close> = l_arg_ 106 local l_arg <close> = l_arg_
106 return true 107 return true
@@ -108,7 +109,8 @@ do
108 109
109 local close_handler_f = function(linda_, err_) 110 local close_handler_f = function(linda_, err_)
110 WR("f closing ", linda_) 111 WR("f closing ", linda_)
111 linda_:set("closed", (linda_:get("closed") or 0) + 1) 112 local _count, _closed = linda_:get("closed")
113 linda_:set("closed", (_closed or 0) + 1)
112 end 114 end
113 local l_in = lanes.linda("voyager", close_handler_f) 115 local l_in = lanes.linda("voyager", close_handler_f)
114 l:set("trip", l_in) 116 l:set("trip", l_in)
@@ -116,7 +118,8 @@ do
116 do 118 do
117 lanes.gen("*", lane_body)(l_in):join() 119 lanes.gen("*", lane_body)(l_in):join()
118 end 120 end
119 assert(l_in:get("closed") == 2) 121 local _count, _closed = l_in:get("closed")
122 assert(_count == 1 and _closed == 2)
120end 123end
121 124
122WR "================================================================================================" 125WR "================================================================================================"