diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-30 17:57:21 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-30 17:57:21 +0200 |
commit | 731556711e453a501f1d1d06a6013b8fbd53414e (patch) | |
tree | 4c5c28cd83de320fcf4c9b4c749f2e6e8d5bef48 /tests | |
parent | a156aaeb07fada043b308409dcffcae1726eec0b (diff) | |
download | lanes-731556711e453a501f1d1d06a6013b8fbd53414e.tar.gz lanes-731556711e453a501f1d1d06a6013b8fbd53414e.tar.bz2 lanes-731556711e453a501f1d1d06a6013b8fbd53414e.zip |
Keeper management modernisation and improvements
* use a std::variant to manage the distinction between one or more keeper states. Use std::unique_ptr<Keeper[]> to manage the multiple keeper case.
* setting "nb_keepers" renamed "nb_user_keepers", to indicate these are in addition to internal keeper #0 used for timers.
* stricter lanes.linda() argument checking. group is imposed if more than one keeper is used.
* more tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fibonacci.lua | 32 | ||||
-rw-r--r-- | tests/irayo_recursive.lua | 2 | ||||
-rw-r--r-- | tests/keeper.lua | 14 | ||||
-rw-r--r-- | tests/nameof.lua | 2 | ||||
-rw-r--r-- | tests/nb_keepers.lua | 20 | ||||
-rw-r--r-- | tests/parallel_os_calls.lua | 2 |
6 files changed, 46 insertions, 26 deletions
diff --git a/tests/fibonacci.lua b/tests/fibonacci.lua index 6dba1dd..0ff2f37 100644 --- a/tests/fibonacci.lua +++ b/tests/fibonacci.lua | |||
@@ -12,7 +12,7 @@ | |||
12 | 12 | ||
13 | -- Need to say it's 'local' so it can be an upvalue | 13 | -- Need to say it's 'local' so it can be an upvalue |
14 | -- | 14 | -- |
15 | local lanes = require "lanes".configure{ nb_keepers =1, with_timers = false} | 15 | local lanes = require "lanes".configure() |
16 | 16 | ||
17 | local function WR(str) | 17 | local function WR(str) |
18 | io.stderr:write( str.."\n" ) | 18 | io.stderr:write( str.."\n" ) |
@@ -27,7 +27,7 @@ local KNOWN= { [0]=0, 1,1,2,3,5,8,13,21,34,55,89,144 } | |||
27 | set_debug_threadname = function ( ...) | 27 | set_debug_threadname = function ( ...) |
28 | end | 28 | end |
29 | 29 | ||
30 | -- | 30 | -- |
31 | -- uint= fib( n_uint ) | 31 | -- uint= fib( n_uint ) |
32 | -- | 32 | -- |
33 | local function fib( n ) | 33 | local function fib( n ) |
@@ -72,20 +72,20 @@ end | |||
72 | -- | 72 | -- |
73 | local right= | 73 | local right= |
74 | { | 74 | { |
75 | 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, | 75 | 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, |
76 | 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, | 76 | 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, |
77 | 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, | 77 | 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, |
78 | 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, | 78 | 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, |
79 | 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, | 79 | 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, |
80 | 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, | 80 | 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, |
81 | 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, | 81 | 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, |
82 | 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, | 82 | 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, |
83 | 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676220, 23416728348467684, | 83 | 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676220, 23416728348467684, |
84 | 37889062373143900, 61305790721611580, 99194853094755490, 160500643816367070, 259695496911122560, | 84 | 37889062373143900, 61305790721611580, 99194853094755490, 160500643816367070, 259695496911122560, |
85 | 420196140727489660, 679891637638612200, 1100087778366101900, 1779979416004714000, | 85 | 420196140727489660, 679891637638612200, 1100087778366101900, 1779979416004714000, |
86 | 2880067194370816000, 4660046610375530000, 7540113804746346000, 12200160415121877000, | 86 | 2880067194370816000, 4660046610375530000, 7540113804746346000, 12200160415121877000, |
87 | 19740274219868226000, 31940434634990105000, 51680708854858334000, 83621143489848440000, | 87 | 19740274219868226000, 31940434634990105000, 51680708854858334000, 83621143489848440000, |
88 | 135301852344706780000, 218922995834555200000 | 88 | 135301852344706780000, 218922995834555200000 |
89 | } | 89 | } |
90 | assert( #right==99 ) | 90 | assert( #right==99 ) |
91 | 91 | ||
diff --git a/tests/irayo_recursive.lua b/tests/irayo_recursive.lua index 2f8b8a8..fe722a3 100644 --- a/tests/irayo_recursive.lua +++ b/tests/irayo_recursive.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | local lanes = require "lanes".configure{ nb_keepers = 1, with_timers = false} | 1 | local lanes = require "lanes".configure() |
2 | -- | 2 | -- |
3 | -- Bugs filed by irayo Jul-2008 | 3 | -- Bugs filed by irayo Jul-2008 |
4 | -- | 4 | -- |
diff --git a/tests/keeper.lua b/tests/keeper.lua index e758b54..d08dd98 100644 --- a/tests/keeper.lua +++ b/tests/keeper.lua | |||
@@ -3,20 +3,20 @@ | |||
3 | -- | 3 | -- |
4 | -- Test program for Lua Lanes | 4 | -- Test program for Lua Lanes |
5 | -- | 5 | -- |
6 | -- TODO: there is a random crash when nb_keepers > 1. Will have to investigate | 6 | -- TODO: there is a random crash when nb_user_keepers > 1. Will have to investigate if it rears its ugly head again |
7 | local lanes = require "lanes".configure{ with_timers = false, nb_keepers = 1, keepers_gc_threshold = 500} | 7 | local lanes = require "lanes".configure{ nb_user_keepers = 3, keepers_gc_threshold = 500 } |
8 | 8 | ||
9 | do | 9 | do |
10 | print "Linda names test:" | 10 | print "Linda names test:" |
11 | local unnamedLinda = lanes.linda() | 11 | local unnamedLinda = lanes.linda(1) |
12 | local unnamedLinda2 = lanes.linda("") | 12 | local unnamedLinda2 = lanes.linda("", 2) |
13 | local veeeerrrryyyylooongNamedLinda= lanes.linda( "veeeerrrryyyylooongNamedLinda", 1) | 13 | local veeeerrrryyyylooongNamedLinda= lanes.linda( "veeeerrrryyyylooongNamedLinda", 3) |
14 | print(unnamedLinda, unnamedLinda2, veeeerrrryyyylooongNamedLinda) | 14 | print(unnamedLinda, unnamedLinda2, veeeerrrryyyylooongNamedLinda) |
15 | print "GC deadlock test start" | 15 | print "GC deadlock test start" |
16 | -- store a linda in another linda (-> in a keeper) | 16 | -- store a linda in another linda (-> in a keeper) |
17 | unnamedLinda:set("here", lanes.linda("temporary linda")) | 17 | unnamedLinda:set("here", lanes.linda("temporary linda", 0)) |
18 | -- repeatedly add and remove stuff in the linda so that a GC happens during the keeper operation | 18 | -- repeatedly add and remove stuff in the linda so that a GC happens during the keeper operation |
19 | for i = 1, 1000 do | 19 | for i = 1, 100 do |
20 | for j = 1, 1000 do -- send 1000 tables | 20 | for j = 1, 1000 do -- send 1000 tables |
21 | -- print("send #" .. j) | 21 | -- print("send #" .. j) |
22 | unnamedLinda:send("here", {"a", "table", "with", "some", "stuff"}) | 22 | unnamedLinda:send("here", {"a", "table", "with", "some", "stuff"}) |
diff --git a/tests/nameof.lua b/tests/nameof.lua index 5c4f1b1..58df3e2 100644 --- a/tests/nameof.lua +++ b/tests/nameof.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | local lanes = require "lanes".configure{on_state_create = function() end} | 1 | local lanes = require "lanes".configure{nb_user_keepers = 100, on_state_create = function() end} |
2 | 2 | ||
3 | print("Name of table: ", lanes.nameof({})) | 3 | print("Name of table: ", lanes.nameof({})) |
4 | print("Name of string.sub: ", lanes.nameof(string.sub)) | 4 | print("Name of string.sub: ", lanes.nameof(string.sub)) |
diff --git a/tests/nb_keepers.lua b/tests/nb_keepers.lua new file mode 100644 index 0000000..575138c --- /dev/null +++ b/tests/nb_keepers.lua | |||
@@ -0,0 +1,20 @@ | |||
1 | -- 2 keepers in addition to the one reserved for the timer linda | ||
2 | local require_lanes_result_1, require_lanes_result_2 = require "lanes".configure{nb_user_keepers = 2} | ||
3 | print("require_lanes_result:", require_lanes_result_1, require_lanes_result_2) | ||
4 | local lanes = require_lanes_result_1 | ||
5 | |||
6 | local require_assert_result_1, require_assert_result_2 = require "assert" -- assert.fails() | ||
7 | print("require_assert_result:", require_assert_result_1, require_assert_result_2) | ||
8 | |||
9 | local createLinda = function(...) | ||
10 | return lanes.linda(...) | ||
11 | end | ||
12 | |||
13 | -- should succeed | ||
14 | assert.failsnot(function() createLinda("one", 1) end) | ||
15 | assert.failsnot(function() createLinda("two", 2) end) | ||
16 | -- should fail | ||
17 | assert.fails(function() createLinda("none") end) | ||
18 | assert.fails(function() createLinda("zero", 0) end) | ||
19 | assert.fails(function() createLinda("three", 3) end) | ||
20 | print "TEST OK" | ||
diff --git a/tests/parallel_os_calls.lua b/tests/parallel_os_calls.lua index 7119272..596053c 100644 --- a/tests/parallel_os_calls.lua +++ b/tests/parallel_os_calls.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | local lanes = require "lanes".configure{with_timers = false, nb_keepers = 1} | 1 | local lanes = require "lanes".configure() |
2 | print( os.date()) | 2 | print( os.date()) |
3 | local linda = lanes.linda() | 3 | local linda = lanes.linda() |
4 | local l1 = lanes.gen("os,base", function() print "start sleeping" linda:receive(10, "null") print("finished_sleeping " .. os.date()) end)() | 4 | local l1 = lanes.gen("os,base", function() print "start sleeping" linda:receive(10, "null") print("finished_sleeping " .. os.date()) end)() |