diff options
-rw-r--r-- | tests/cancel.lua | 34 |
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 @@ | |||
1 | local which_tests = {} | 1 | local which_tests, remaining_tests = {}, {} |
2 | for k,v in ipairs{...} do | 2 | for 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 | ||
4 | end | 6 | end |
5 | 7 | ||
8 | --#################################################################### | ||
9 | |||
6 | local lanes = require "lanes" .configure{ with_timers = false} | 10 | local lanes = require "lanes" .configure{ with_timers = false} |
7 | 11 | ||
8 | local linda = lanes.linda() | 12 | local linda = lanes.linda() |
@@ -10,7 +14,8 @@ local linda = lanes.linda() | |||
10 | linda:set( "val", 33.0) | 14 | linda:set( "val", 33.0) |
11 | 15 | ||
12 | --#################################################################### | 16 | --#################################################################### |
13 | if #which_tests and which_tests.genlock then | 17 | if 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 | ||
128 | if #which_tests and which_tests.linda then | 133 | if 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") |
143 | end | 149 | end |
144 | 150 | ||
145 | if #which_tests and which_tests.soft then | 151 | if 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") |
163 | end | 170 | end |
164 | 171 | ||
165 | if #which_tests and which_tests.hook then | 172 | if 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") |
176 | end | 184 | end |
177 | 185 | ||
178 | if #which_tests and which_tests.hard then | 186 | if 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") |
191 | end | 200 | end |
192 | 201 | ||
193 | if #which_tests and which_tests.hard_unprotected then | 202 | if 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") |
206 | end | 216 | end |
207 | 217 | ||
208 | if #which_tests and which_tests.kill then | 218 | if 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 | |||
221 | end | 232 | end |
222 | --#################################################################### | 233 | --#################################################################### |
223 | 234 | ||
224 | print "\ndone" | 235 | local unknown_test, val = next(remaining_tests) |
236 | assert(not unknown_test, tostring(unknown_test) .. " test is unknown") | ||
237 | |||
238 | print "\nTHE END" | ||
225 | 239 | ||