diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-12 18:18:24 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-12 18:18:24 +0200 |
commit | dddc28153796f9c8eb256eddb335c8643226fd0b (patch) | |
tree | 641caa9a01933d0397a99f127cff249d3a77fdb5 /tests | |
parent | c305ff3ed1f51d86ced2bb83b10b5e0632cd98a3 (diff) | |
download | lanes-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.lua | 24 | ||||
-rw-r--r-- | tests/cancel.lua | 7 | ||||
-rw-r--r-- | tests/errhangtest.lua | 12 | ||||
-rw-r--r-- | tests/keeper.lua | 5 | ||||
-rw-r--r-- | tests/linda_perf.lua | 10 | ||||
-rw-r--r-- | tests/timer.lua | 7 | ||||
-rw-r--r-- | tests/tobeclosed.lua | 13 |
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 | ||
253 | WR "test linda:get/set..." | 253 | WR "test linda:get/set..." |
254 | linda:set("<->", "x", "y", "z") | 254 | linda:set("<->", "x", "y", "z") |
255 | local x,y,z = linda:get("<->", 1) | 255 | local b,x,y,z = linda:get("<->", 1) |
256 | assert(x == "x" and y == nil and z == nil) | 256 | assert(b == 1 and x == "x" and y == nil and z == nil) |
257 | local x,y,z = linda:get("<->", 2) | 257 | local b,x,y,z = linda:get("<->", 2) |
258 | assert(x == "x" and y == "y" and z == nil) | 258 | assert(b == 2 and x == "x" and y == "y" and z == nil) |
259 | local x,y,z = linda:get("<->", 3) | 259 | local b,x,y,z = linda:get("<->", 3) |
260 | assert(x == "x" and y == "y" and z == "z") | 260 | assert(b == 3 and x == "x" and y == "y" and z == "z") |
261 | local x,y,z,w = linda:get("<->", 4) | 261 | local b,x,y,z,w = linda:get("<->", 4) |
262 | assert(x == "x" and y == "y" and z == "z" and w == nil) | 262 | assert(b == 3 and x == "x" and y == "y" and z == "z" and w == nil) |
263 | local k, x = linda:receive("<->") | 263 | local k, x = linda:receive("<->") |
264 | assert(k == "<->" and x == "x") | 264 | assert(k == "<->" and x == "x") |
265 | local k,y,z = linda:receive(linda.batched, "<->", 2) | 265 | local k,y,z = linda:receive(linda.batched, "<->", 2) |
266 | assert(k == "<->" and y == "y" and z == "z") | 266 | assert(k == "<->" and y == "y" and z == "z") |
267 | linda:set("<->") | 267 | linda:set("<->") |
268 | local x,y,z,w = linda:get("<->", 4) | 268 | local b,x,y,z,w = linda:get("<->", 4) |
269 | assert(x == nil and y == nil and z == nil and w == nil) | 269 | assert(b == 0 and x == nil and y == nil and z == nil and w == nil) |
270 | WR "ok\n" | 270 | WR "ok\n" |
271 | 271 | ||
272 | local function PEEK(...) return linda:get("<-", ...) end | 272 | local function PEEK(...) return linda:get("<-", ...) end |
@@ -282,7 +282,7 @@ SEND(setmetatable({"should be ignored"},{__lanesconvert=lanes.null})); WR("main | |||
282 | for i=1,40 do | 282 | for 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 |
286 | end | 286 | end |
287 | SEND(nil); WR("\nmain ", "nil sent\n") | 287 | SEND(nil); WR("\nmain ", "nil sent\n") |
288 | 288 | ||
@@ -306,7 +306,7 @@ assert(null==nil) | |||
306 | local out_t = RECEIVE(); WR(type(out_t).." received\n") | 306 | local out_t = RECEIVE(); WR(type(out_t).." received\n") |
307 | assert(tables_match(out_t, {'a','b','c',d=10})) | 307 | assert(tables_match(out_t, {'a','b','c',d=10})) |
308 | 308 | ||
309 | assert(PEEK() == nil) | 309 | assert(PEEK() == 0) |
310 | SEND(4) | 310 | SEND(4) |
311 | 311 | ||
312 | local complex_table = RECEIVE(); WR(type(complex_table).." received\n") | 312 | 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 | |||
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" |
16 | end | 17 | end |
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" |
24 | end | 26 | end |
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" |
75 | end | 79 | end |
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) | |||
18 | end | 18 | end |
19 | 19 | ||
20 | -- ################################################################################################# | 20 | -- ################################################################################################# |
21 | if false then | 21 | if 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 ) | |||
94 | linda:receive( 0, T1 ) -- clear out; there could be one tick left | 94 | linda:receive( 0, T1 ) -- clear out; there could be one tick left |
95 | linda:receive( 0, T2 ) | 95 | linda:receive( 0, T2 ) |
96 | 96 | ||
97 | assert( linda:get(T1) == nil ) | 97 | local _count, _val = linda:get(T1) |
98 | assert( linda:get(T2) == nil ) | 98 | assert(_count == 0 and _val == nil) |
99 | |||
100 | local _count, _val = linda:get(T2) | ||
101 | assert(_count == 0 and _val == nil) | ||
99 | 102 | ||
100 | PRINT "...making sure no ticks are coming..." | 103 | PRINT "...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) | ||
75 | end | 76 | end |
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) | ||
120 | end | 123 | end |
121 | 124 | ||
122 | WR "================================================================================================" | 125 | WR "================================================================================================" |