From dddc28153796f9c8eb256eddb335c8643226fd0b Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 12 Jun 2024 18:18:24 +0200 Subject: linda :get(), :set(), :limit() return value changes --- tests/basic.lua | 24 ++++++++++++------------ tests/cancel.lua | 7 ++++--- tests/errhangtest.lua | 12 ++++++++---- tests/keeper.lua | 5 +++-- tests/linda_perf.lua | 10 +++++----- tests/timer.lua | 7 +++++-- tests/tobeclosed.lua | 13 ++++++++----- 7 files changed, 45 insertions(+), 33 deletions(-) (limited to 'tests') 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") WR "test linda:get/set..." linda:set("<->", "x", "y", "z") -local x,y,z = linda:get("<->", 1) -assert(x == "x" and y == nil and z == nil) -local x,y,z = linda:get("<->", 2) -assert(x == "x" and y == "y" and z == nil) -local x,y,z = linda:get("<->", 3) -assert(x == "x" and y == "y" and z == "z") -local x,y,z,w = linda:get("<->", 4) -assert(x == "x" and y == "y" and z == "z" and w == nil) +local b,x,y,z = linda:get("<->", 1) +assert(b == 1 and x == "x" and y == nil and z == nil) +local b,x,y,z = linda:get("<->", 2) +assert(b == 2 and x == "x" and y == "y" and z == nil) +local b,x,y,z = linda:get("<->", 3) +assert(b == 3 and x == "x" and y == "y" and z == "z") +local b,x,y,z,w = linda:get("<->", 4) +assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil) local k, x = linda:receive("<->") assert(k == "<->" and x == "x") local k,y,z = linda:receive(linda.batched, "<->", 2) assert(k == "<->" and y == "y" and z == "z") linda:set("<->") -local x,y,z,w = linda:get("<->", 4) -assert(x == nil and y == nil and z == nil and w == nil) +local b,x,y,z,w = linda:get("<->", 4) +assert(b == 0 and x == nil and y == nil and z == nil and w == nil) WR "ok\n" local function PEEK(...) return linda:get("<-", ...) end @@ -282,7 +282,7 @@ SEND(setmetatable({"should be ignored"},{__lanesconvert=lanes.null})); WR("main for i=1,40 do WR "." SLEEP(0.0001) - assert(PEEK() == nil) -- nothing coming in, yet + assert(PEEK() == 0) -- nothing coming in, yet end SEND(nil); WR("\nmain ", "nil sent\n") @@ -306,7 +306,7 @@ assert(null==nil) local out_t = RECEIVE(); WR(type(out_t).." received\n") assert(tables_match(out_t, {'a','b','c',d=10})) -assert(PEEK() == nil) +assert(PEEK() == 0) SEND(4) local 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 -- check that cancelled lindas give cancel_error as they should linda:cancel() - assert( linda:get( "empty") == lanes.cancel_error) + local _status, _err = linda:get( "empty") + assert(_status == nil and _err == lanes.cancel_error) assert( lanes.genlock( linda, "any", 1) == lanes.cancel_error) assert( lanes.genatomic( linda, "any") == lanes.cancel_error) @@ -102,14 +103,14 @@ local laneBody = function( mode_, payload_) io.stdout:write( " lane busy waiting ... ") for i = 1, payload_ do -- force a non-jitable call - local a = linda:get( "val") + local _, a = linda:get( "val") a = a * 2 end print( "again?") elseif mode_ == "busy" then -- busy wait mode in pure Lua code io.stdout:write( " lane busy waiting ... ") - local a = linda:get( "val") + local _, a = linda:get( "val") for i = 1, payload_ do a = a * 2 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 print "#### coro set" local coro = coroutine.create(function() end) print(pcall(linda.set, linda, 'test', coro)) - assert(linda:get("test") == nil) + local _count, _val = linda:get("test") + assert(_count == 0 and _val == nil) print "OK" end @@ -19,7 +20,8 @@ if true then print "\n#### reserved sentinels" print(pcall(linda.set, linda, lanes.cancel_error)) print(pcall(linda.set, linda, linda.batched)) - assert(linda:get("test") == nil) + local _count, _val = linda:get("test") + assert(_count == 0 and _val == nil) print "OK" end @@ -33,7 +35,8 @@ if true then print(pcall(linda.set, linda, 'test', true, nil, fun)) -- read back the contents local k,b,n,f = linda:receive(linda.batched, 'test', 3) - assert(linda:get("test") == nil) + local _count, _val = linda:get("test") + assert(_count == 0 and _val == nil) -- check they are ok print(k, b, n) f() @@ -70,7 +73,8 @@ if true then print "\n#### coro send" local coro = coroutine.create(function() end) print(pcall(linda.send, linda, 'test', coro)) - assert(linda:get("test") == nil) + local _count, _val = linda:get("test") + assert(_count == 0 and _val == nil) print "OK" end 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 local function keeper(linda) local mt= { - __index= function( _, key ) - return linda:get( key ) + __index= function(_, key) + local _count, _val = linda:get(key) + return _val end, __newindex= function( _, key, val ) 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) end -- ################################################################################################# -if false then +if true then do print "############################################ tests get/set" -- linda:get throughput - local l = lanes.linda("get/set") + local l = lanes.linda("get/set", 1) local batch = {} for i = 1,1000 do table.insert(batch, i) end for _,size in ipairs{1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 } do l:set("<->", table_unpack(batch)) - local count = math.floor(20000000/size) + local count = math.floor(20000/math.sqrt(size)) print("START", "get("..size..") " .. count, " times") local t1 = lanes.now_secs() - for i = 1, 2000000/math.sqrt(size) do - l:get("<->", size) + for i = 1, count do + assert (l:get("<->", size) == size) end print("DURATION = " .. lanes.now_secs() - t1 .. "\n") 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 ) linda:receive( 0, T1 ) -- clear out; there could be one tick left linda:receive( 0, T2 ) -assert( linda:get(T1) == nil ) -assert( linda:get(T2) == nil ) +local _count, _val = linda:get(T1) +assert(_count == 0 and _val == nil) + +local _count, _val = linda:get(T2) +assert(_count == 0 and _val == nil) PRINT "...making sure no ticks are coming..." 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 do - local l_out = l:get("trip") + local _, l_out = l:get("trip") end - assert(l_in:get("closed") == true) + local _count, _closed = l_in:get("closed") + assert(_count == 1 and _closed == true) end -- ################################################################################################# @@ -100,7 +101,7 @@ do local lane_body = function(l_arg_) WR "In lane body" -- linda obtained through a linda - local l_out = l:get("trip") + local _count, l_out = l:get("trip") -- linda from arguments local l_arg = l_arg_ return true @@ -108,7 +109,8 @@ do local close_handler_f = function(linda_, err_) WR("f closing ", linda_) - linda_:set("closed", (linda_:get("closed") or 0) + 1) + local _count, _closed = linda_:get("closed") + linda_:set("closed", (_closed or 0) + 1) end local l_in = lanes.linda("voyager", close_handler_f) l:set("trip", l_in) @@ -116,7 +118,8 @@ do do lanes.gen("*", lane_body)(l_in):join() end - assert(l_in:get("closed") == 2) + local _count, _closed = l_in:get("closed") + assert(_count == 1 and _closed == 2) end WR "================================================================================================" -- cgit v1.2.3-55-g6feb