aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/cancel.lua34
1 files changed, 24 insertions, 10 deletions
diff --git a/tests/cancel.lua b/tests/cancel.lua
index 001483a..c5bb761 100644
--- a/tests/cancel.lua
+++ b/tests/cancel.lua
@@ -1,8 +1,12 @@
1local which_tests = {} 1local which_tests, remaining_tests = {}, {}
2for k,v in ipairs{...} do 2for k,v in ipairs{...} do
3 print("got arg:", type(v), tostring(v))
3 which_tests[v] = true 4 which_tests[v] = true
5 remaining_tests[v] = true
4end 6end
5 7
8--####################################################################
9
6local lanes = require "lanes" .configure{ with_timers = false} 10local lanes = require "lanes" .configure{ with_timers = false}
7 11
8local linda = lanes.linda() 12local linda = lanes.linda()
@@ -10,7 +14,8 @@ local linda = lanes.linda()
10linda:set( "val", 33.0) 14linda:set( "val", 33.0)
11 15
12--#################################################################### 16--####################################################################
13if #which_tests and which_tests.genlock then 17if not next(which_tests) or which_tests.genlock then
18 remaining_tests.genlock = nil
14 print "\n\n####################################################################\nbegin genlock & genatomic cancel test\n" 19 print "\n\n####################################################################\nbegin genlock & genatomic cancel test\n"
15 20
16 -- get a lock and a atomic operator 21 -- get a lock and a atomic operator
@@ -125,7 +130,8 @@ end
125--#################################################################### 130--####################################################################
126--#################################################################### 131--####################################################################
127 132
128if #which_tests and which_tests.linda then 133if not next(which_tests) or which_tests.linda then
134 remaining_tests.linda = nil
129 print "\n\n####################################################################\nbegin linda cancel test\n" 135 print "\n\n####################################################################\nbegin linda cancel test\n"
130 h = lanes.gen( "*", laneBody)( "receive", nil) -- start an infinite wait on the linda 136 h = lanes.gen( "*", laneBody)( "receive", nil) -- start an infinite wait on the linda
131 137
@@ -142,7 +148,8 @@ if #which_tests and which_tests.linda then
142 linda:cancel( "none") 148 linda:cancel( "none")
143end 149end
144 150
145if #which_tests and which_tests.soft then 151if not next(which_tests) or which_tests.soft then
152 remaining_tests.soft = nil
146 print "\n\n####################################################################\nbegin soft cancel test\n" 153 print "\n\n####################################################################\nbegin soft cancel test\n"
147 h = lanes.gen( "*", protectedBody)( "receive") -- start an infinite wait on the linda 154 h = lanes.gen( "*", protectedBody)( "receive") -- start an infinite wait on the linda
148 155
@@ -162,20 +169,22 @@ if #which_tests and which_tests.soft then
162 waitCancellation( h, "done") 169 waitCancellation( h, "done")
163end 170end
164 171
165if #which_tests and which_tests.hook then 172if not next(which_tests) or which_tests.hook then
173 remaining_tests.hook = nil
166 print "\n\n####################################################################\nbegin hook cancel test\n" 174 print "\n\n####################################################################\nbegin hook cancel test\n"
167 h = lanes.gen( "*", protectedBody)( "get", 300000) 175 h = lanes.gen( "*", protectedBody)( "get", 300000)
168 print "wait 2s" 176 print "wait 2s"
169 linda:receive( 2, "yeah") 177 linda:receive( 2, "yeah")
170 178
171 -- count hook cancel after some instruction instructions 179 -- count hook cancel after some instruction instructions
172 h:cancel( "count", 300, 5.0) 180 h:cancel( "line", 300, 5.0)
173 181
174 -- wait until cancellation is effective. the lane will interrupt its loop and print the exit message 182 -- wait until cancellation is effective. the lane will interrupt its loop and print the exit message
175 waitCancellation( h, "cancelled") 183 waitCancellation( h, "cancelled")
176end 184end
177 185
178if #which_tests and which_tests.hard then 186if not next(which_tests) or which_tests.hard then
187 remaining_tests.hard = nil
179 print "\n\n####################################################################\nbegin hard cancel test\n" 188 print "\n\n####################################################################\nbegin hard cancel test\n"
180 h = lanes.gen( "*", protectedBody)( "receive", nil) -- infinite timeout 189 h = lanes.gen( "*", protectedBody)( "receive", nil) -- infinite timeout
181 190
@@ -190,7 +199,8 @@ if #which_tests and which_tests.hard then
190 waitCancellation( h, "cancelled") 199 waitCancellation( h, "cancelled")
191end 200end
192 201
193if #which_tests and which_tests.hard_unprotected then 202if not next(which_tests) or which_tests.hard_unprotected then
203 remaining_tests.hard_unprotected = nil
194 print "\n\n####################################################################\nbegin hard cancel test with unprotected lane body\n" 204 print "\n\n####################################################################\nbegin hard cancel test with unprotected lane body\n"
195 h = lanes.gen( "*", laneBody)( "receive", nil) 205 h = lanes.gen( "*", laneBody)( "receive", nil)
196 206
@@ -205,7 +215,8 @@ if #which_tests and which_tests.hard_unprotected then
205 waitCancellation( h, "cancelled") 215 waitCancellation( h, "cancelled")
206end 216end
207 217
208if #which_tests and which_tests.kill then 218if not next(which_tests) or which_tests.kill then
219 remaining_tests.kill = nil
209 print "\n\n####################################################################\nbegin kill cancel test\n" 220 print "\n\n####################################################################\nbegin kill cancel test\n"
210 h = lanes.gen( "*", laneBody)( "busy", 50000000) -- start a pure Lua busy loop lane 221 h = lanes.gen( "*", laneBody)( "busy", 50000000) -- start a pure Lua busy loop lane
211 222
@@ -221,5 +232,8 @@ if #which_tests and which_tests.kill then
221end 232end
222--#################################################################### 233--####################################################################
223 234
224print "\ndone" 235local unknown_test, val = next(remaining_tests)
236assert(not unknown_test, tostring(unknown_test) .. " test is unknown")
237
238print "\nTHE END"
225 239