aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basic.lua23
-rw-r--r--tests/linda_perf.lua35
2 files changed, 51 insertions, 7 deletions
diff --git a/tests/basic.lua b/tests/basic.lua
index fff19ed..ecd93fc 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -249,7 +249,26 @@ assert(type(linda) == "userdata" and tostring(linda) == "Linda: communications")
249 -- ["->"] master -> slave 249 -- ["->"] master -> slave
250 -- ["<-"] slave <- master 250 -- ["<-"] slave <- master
251 251
252local function PEEK() return linda:get("<-") end 252WR "test linda:get/set..."
253linda:set("<->", "x", "y", "z")
254local x,y,z = linda:get("<->", 1)
255assert(x == "x" and y == nil and z == nil)
256local x,y,z = linda:get("<->", 2)
257assert(x == "x" and y == "y" and z == nil)
258local x,y,z = linda:get("<->", 3)
259assert(x == "x" and y == "y" and z == "z")
260local x,y,z,w = linda:get("<->", 4)
261assert(x == "x" and y == "y" and z == "z" and w == nil)
262local k, x = linda:receive("<->")
263assert(k == "<->" and x == "x")
264local k,y,z = linda:receive(linda.batched, "<->", 2)
265assert(k == "<->" and y == "y" and z == "z")
266linda:set("<->")
267local x,y,z,w = linda:get("<->", 4)
268assert(x == nil and y == nil and z == nil and w == nil)
269WR "ok\n"
270
271local function PEEK(...) return linda:get("<-", ...) end
253local function SEND(...) linda:send("->", ...) end 272local function SEND(...) linda:send("->", ...) end
254local function RECEIVE() local k,v = linda:receive(1, "<-") return v end 273local function RECEIVE() local k,v = linda:receive(1, "<-") return v end
255 274
@@ -259,7 +278,7 @@ SEND(1); WR("main ", "1 sent\n")
259SEND(2); WR("main ", "2 sent\n") 278SEND(2); WR("main ", "2 sent\n")
260SEND(3); WR("main ", "3 sent\n") 279SEND(3); WR("main ", "3 sent\n")
261SEND(setmetatable({"should be ignored"},{__lanesignore=true})); WR("main ", "__lanesignore table sent\n") 280SEND(setmetatable({"should be ignored"},{__lanesignore=true})); WR("main ", "__lanesignore table sent\n")
262for i=1,100 do 281for i=1,40 do
263 WR "." 282 WR "."
264 SLEEP(0.0001) 283 SLEEP(0.0001)
265 assert(PEEK() == nil) -- nothing coming in, yet 284 assert(PEEK() == nil) -- nothing coming in, yet
diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua
index a50e906..4d35380 100644
--- a/tests/linda_perf.lua
+++ b/tests/linda_perf.lua
@@ -62,12 +62,13 @@ local lane_gobbler_gen = lanes.gen( "*", {priority = 3}, gobbler)
62local function ziva( preloop, loop, batch) 62local function ziva( preloop, loop, batch)
63 -- prefill the linda a bit to increase fifo stress 63 -- prefill the linda a bit to increase fifo stress
64 local top = math.max( preloop, loop) 64 local top = math.max( preloop, loop)
65 local l, lane = lanes.linda() 65 local l = lanes.linda()
66 local t1 = lanes.now_secs() 66 local t1 = lanes.now_secs()
67 for i = 1, preloop do 67 for i = 1, preloop do
68 l:send( "key", i) 68 l:send( "key", i)
69 end 69 end
70 print( "stored " .. l:count( "key") .. " items in the linda before starting consumer lane") 70 print( "stored " .. l:count( "key") .. " items in the linda before starting consumer lane")
71 local lane
71 if batch > 0 then 72 if batch > 0 then
72 if l.batched then 73 if l.batched then
73 lane = lane_gobbler_gen( l, top, batch) 74 lane = lane_gobbler_gen( l, top, batch)
@@ -103,6 +104,28 @@ local function ziva( preloop, loop, batch)
103end 104end
104 105
105-- ################################################################################################# 106-- #################################################################################################
107do
108 print "############################################ tests get/set"
109 -- linda:get throughput
110 local l = lanes.linda("get/set")
111 local batch = {}
112 for i = 1,1000 do
113 table.insert(batch, i)
114 end
115 for _,size in ipairs{1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987 } do
116 l:set("<->", table_unpack(batch))
117 local count = 20000000//size
118 print("START", "get("..size..") " .. count, " times")
119 local t1 = lanes.now_secs()
120 for i = 1, 2000000/math.sqrt(size) do
121 l:get("<->", size)
122 end
123 print("DURATION = " .. lanes.now_secs() - t1 .. "\n")
124 end
125end
126
127do return end
128-- #################################################################################################
106 129
107TEST1 = TEST1 or 1000 130TEST1 = TEST1 or 1000
108PREFILL1 = PREFILL1 or 10000 131PREFILL1 = PREFILL1 or 10000
@@ -118,8 +141,9 @@ local tests1 =
118 { PREFILL1, FILL1, 8}, 141 { PREFILL1, FILL1, 8},
119 { PREFILL1, FILL1, 13}, 142 { PREFILL1, FILL1, 13},
120 { PREFILL1, FILL1, 21}, 143 { PREFILL1, FILL1, 21},
121 { PREFILL1, FILL1, 44}, 144 { PREFILL1, FILL1, 34},
122 { PREFILL1, FILL1, 65}, 145 { PREFILL1, FILL1, 55},
146 { PREFILL1, FILL1, 89},
123} 147}
124print "############################################ tests #1" 148print "############################################ tests #1"
125for i, v in ipairs( tests1) do 149for i, v in ipairs( tests1) do
@@ -194,8 +218,9 @@ local tests2 =
194 { PREFILL2, FILL2, 8}, 218 { PREFILL2, FILL2, 8},
195 { PREFILL2, FILL2, 13}, 219 { PREFILL2, FILL2, 13},
196 { PREFILL2, FILL2, 21}, 220 { PREFILL2, FILL2, 21},
197 { PREFILL2, FILL2, 44}, 221 { PREFILL2, FILL2, 34},
198 { PREFILL2, FILL2, 65}, 222 { PREFILL2, FILL2, 55},
223 { PREFILL2, FILL2, 89},
199} 224}
200 225
201print "############################################ tests #2" 226print "############################################ tests #2"