@@ -146,26 +146,45 @@ tests =
146
146
, testProperty " lazy" prop_mfix_lazy
147
147
, testProperty " recdata" prop_mfix_recdata
148
148
]
149
- -- NOTE: Most of the tests below only work because the io-sim scheduler works the way it does.
149
+ -- NOTE: Most of the tests below only work because the io-sim
150
+ -- scheduler works the way it does.
150
151
, testGroup " ThreadStatus"
151
- [ testProperty " thread status finished (IOSim)" $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_finished
152
- , testProperty " thread status finished (IO)" $ withMaxSuccess 1 $ ioProperty prop_thread_status_finished
153
- , testProperty " thread status running (IOSim)" $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_running
154
- , testProperty " thread status running (IO)" $ withMaxSuccess 1 $ ioProperty prop_thread_status_running
155
- , testProperty " thread status blocked (IOSim)" $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_blocked
156
- , testProperty " thread status blocked (IO)" $ withMaxSuccess 1 $ ioProperty prop_thread_status_blocked
157
- , testProperty " thread status blocked delay (IOSim)" $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_blocked_delay
158
- , testProperty " thread status blocked delay (IO)" $ withMaxSuccess 1 $ ioProperty prop_thread_status_blocked_delay
159
- , testProperty " thread status died (IOSim)" $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_died
160
- , testProperty " thread status died (IO)" $ withMaxSuccess 1 $ ioProperty prop_thread_status_died
161
- , testProperty " thread status died_own (IOSim)" $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_died_own
162
- , testProperty " thread status died_own (IO)" $ withMaxSuccess 1 $ ioProperty prop_thread_status_died_own
163
- , testProperty " thread status yield (IOSim)" $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_yield
164
- , testProperty " thread status yield (IO)" $ withMaxSuccess 1 $ ioProperty prop_thread_status_yield
165
- , testProperty " thread status mask (IOSim)" $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_mask
166
- , testProperty " thread status mask (IO)" $ withMaxSuccess 1 $ ioProperty prop_thread_status_mask
167
- , testProperty " thread status mask blocked (IOSim)" $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_mask_blocked
168
- , testProperty " thread status mask blocked (IO)" $ withMaxSuccess 1 $ ioProperty prop_thread_status_mask_blocked
152
+ [ testProperty " thread status finished (IOSim)"
153
+ $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_finished
154
+ , testProperty " thread status finished (IO)"
155
+ $ withMaxSuccess 1 $ ioProperty prop_thread_status_finished
156
+ , testProperty " thread status running (IOSim)"
157
+ $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_running
158
+ , testProperty " thread status running (IO)"
159
+ $ withMaxSuccess 1 $ ioProperty prop_thread_status_running
160
+ , testProperty " thread status blocked (IOSim)"
161
+ $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_blocked
162
+ , testProperty " thread status blocked (IO)"
163
+ $ withMaxSuccess 1 $ ioProperty prop_thread_status_blocked
164
+ , testProperty " thread status blocked delay (IOSim)"
165
+ $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_blocked_delay
166
+ , testProperty " thread status blocked delay (IO)"
167
+ $ withMaxSuccess 1 $ ioProperty prop_thread_status_blocked_delay
168
+ , testProperty " thread status died (IOSim)"
169
+ $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_died
170
+ , testProperty " thread status died (IO)"
171
+ $ withMaxSuccess 1 $ ioProperty prop_thread_status_died
172
+ , testProperty " thread status died_own (IOSim)"
173
+ $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_died_own
174
+ , testProperty " thread status died_own (IO)"
175
+ $ withMaxSuccess 1 $ ioProperty prop_thread_status_died_own
176
+ , testProperty " thread status yield (IOSim)"
177
+ $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_yield
178
+ , testProperty " thread status yield (IO)"
179
+ $ withMaxSuccess 1 $ ioProperty prop_thread_status_yield
180
+ , testProperty " thread status mask (IOSim)"
181
+ $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_mask
182
+ , testProperty " thread status mask (IO)"
183
+ $ withMaxSuccess 1 $ ioProperty prop_thread_status_mask
184
+ , testProperty " thread status mask blocked (IOSim)"
185
+ $ withMaxSuccess 1 $ runSimOrThrow prop_thread_status_mask_blocked
186
+ , testProperty " thread status mask blocked (IO)"
187
+ $ withMaxSuccess 1 $ ioProperty prop_thread_status_mask_blocked
169
188
]
170
189
]
171
190
@@ -188,65 +207,117 @@ prop_two_threads_expect_ :: (MonadFork m, MonadThread m)
188
207
=> m ()
189
208
-> (ThreadStatus -> Property )
190
209
-> m Property
191
- prop_two_threads_expect_ target prop = prop_two_threads_expect target (const $ yield) prop
210
+ prop_two_threads_expect_ target prop =
211
+ prop_two_threads_expect target
212
+ (const $ yield)
213
+ prop
192
214
193
- prop_thread_status_finished :: (MonadFork m , MonadDelay m , MonadThread m ) => m Property
215
+ prop_thread_status_finished :: (MonadFork m , MonadDelay m , MonadThread m )
216
+ => m Property
194
217
prop_thread_status_finished =
195
218
prop_two_threads_expect_ (pure () )
196
219
(ThreadFinished === )
197
220
198
- prop_thread_status_running :: (MonadFork m , MonadDelay m , MonadThread m ) => m Property
221
+ prop_thread_status_running :: (MonadFork m , MonadDelay m , MonadThread m )
222
+ => m Property
199
223
prop_thread_status_running =
200
224
prop_two_threads_expect_ (forever yield)
201
225
(ThreadRunning === )
202
226
203
- prop_thread_status_blocked :: (MonadFork m , MonadDelay m , MonadThread m , MonadSTM m ) => m Property
227
+ prop_thread_status_blocked :: ( MonadFork m
228
+ , MonadDelay m
229
+ , MonadThread m
230
+ , MonadSTM m
231
+ )
232
+ => m Property
204
233
prop_thread_status_blocked = do
205
234
var <- newEmptyTMVarIO
206
- prop_two_threads_expect_ (atomically $ takeTMVar var)
207
- $ \ status -> case status of
208
- ThreadBlocked _ -> property True
209
- _ -> counterexample (show status ++ " /= ThreadBlocked _" ) False
210
-
211
- prop_thread_status_blocked_delay :: (MonadFork m , MonadDelay m , MonadThread m ) => m Property
235
+ prop_two_threads_expect_
236
+ (atomically $ takeTMVar var)
237
+ $ \ status -> case status of
238
+ ThreadBlocked _ -> property True
239
+ _ ->
240
+ counterexample (show status ++ " /= ThreadBlocked _" )
241
+ False
242
+
243
+ prop_thread_status_blocked_delay :: (MonadFork m , MonadDelay m , MonadThread m )
244
+ => m Property
212
245
prop_thread_status_blocked_delay =
213
- prop_two_threads_expect_ (threadDelay 1 )
214
- $ \ status -> case status of
215
- ThreadBlocked _ -> property True
216
- _ -> counterexample (show status ++ " /= ThreadBlocked _" ) False
217
-
218
- prop_thread_status_died :: (MonadFork m , MonadThrow m , MonadDelay m , MonadThread m ) => m Property
246
+ prop_two_threads_expect_
247
+ (threadDelay 1 )
248
+ $ \ status -> case status of
249
+ ThreadBlocked _ -> property True
250
+ _ ->
251
+ counterexample (show status ++ " /= ThreadBlocked _" )
252
+ False
253
+
254
+ prop_thread_status_died :: ( MonadFork m
255
+ , MonadThrow m
256
+ , MonadDelay m
257
+ , MonadThread m
258
+ )
259
+ => m Property
219
260
prop_thread_status_died =
220
261
prop_two_threads_expect (forever yield)
221
262
(\ tid -> do throwTo tid DivideByZero ; yield)
222
263
(ThreadDied === )
223
264
224
- prop_thread_status_died_own :: (MonadFork m , MonadThrow m , MonadDelay m , MonadThread m ) => m Property
265
+ prop_thread_status_died_own :: ( MonadFork m
266
+ , MonadThrow m
267
+ , MonadDelay m
268
+ , MonadThread m
269
+ )
270
+ => m Property
225
271
prop_thread_status_died_own = do
226
272
prop_two_threads_expect_ (throwIO DivideByZero )
227
273
(ThreadFinished === )
228
274
229
- prop_thread_status_yield :: (MonadFork m , MonadThrow m , MonadDelay m , MonadThread m , MonadSTM m ) => m Property
275
+ prop_thread_status_yield :: ( MonadFork m
276
+ , MonadThrow m
277
+ , MonadDelay m
278
+ , MonadThread m
279
+ , MonadSTM m
280
+ )
281
+ => m Property
230
282
prop_thread_status_yield = do
231
283
var <- newEmptyTMVarIO
232
- prop_two_threads_expect (do atomically (putTMVar var () ); forever yield)
233
- (const $ atomically (takeTMVar var))
234
- (ThreadRunning === )
235
-
236
- prop_thread_status_mask :: (MonadFork m , MonadThrow m , MonadDelay m , MonadThread m , MonadSTM m , MonadMask m ) => m Property
284
+ prop_two_threads_expect
285
+ (do atomically (putTMVar var () ); forever yield)
286
+ (const $ atomically (takeTMVar var))
287
+ (ThreadRunning === )
288
+
289
+ prop_thread_status_mask :: ( MonadFork m
290
+ , MonadThrow m
291
+ , MonadDelay m
292
+ , MonadThread m
293
+ , MonadSTM m
294
+ , MonadMask m
295
+ )
296
+ => m Property
237
297
prop_thread_status_mask = do
238
298
var <- newEmptyTMVarIO
239
- prop_two_threads_expect (mask_ (do atomically (putTMVar var () ); yield) >> forever yield)
240
- (\ tid -> do atomically (takeTMVar var); throwTo tid DivideByZero ; yield)
241
- (ThreadFinished === )
242
-
243
- prop_thread_status_mask_blocked :: (MonadFork m , MonadThrow m , MonadThread m , MonadMask m ) => m Property
299
+ prop_two_threads_expect
300
+ (mask_ (do atomically (putTMVar var () ); yield) >> forever yield)
301
+ (\ tid -> do atomically (takeTMVar var)
302
+ throwTo tid DivideByZero
303
+ yield)
304
+ (ThreadFinished === )
305
+
306
+ prop_thread_status_mask_blocked :: ( MonadFork m
307
+ , MonadThrow m
308
+ , MonadThread m
309
+ , MonadMask m
310
+ )
311
+ => m Property
244
312
prop_thread_status_mask_blocked = do
245
313
helper <- forkIO $ mask_ (forever yield)
246
- prop_two_threads_expect_ (throwTo helper DivideByZero )
247
- $ \ status -> case status of
248
- ThreadBlocked _ -> property True
249
- _ -> counterexample (show status ++ " /= ThreadBlocked _" ) False
314
+ prop_two_threads_expect_
315
+ (throwTo helper DivideByZero )
316
+ $ \ status -> case status of
317
+ ThreadBlocked _ -> property True
318
+ _ ->
319
+ counterexample (show status ++ " /= ThreadBlocked _" )
320
+ False
250
321
251
322
--
252
323
-- Read/Write graph
@@ -367,12 +438,13 @@ test_timers xs =
367
438
countUnique [] = 0
368
439
countUnique (a: as) =
369
440
let as' = filter (== a) as
370
- in 1 + countUnique as'
441
+ in 1 + countUnique as'
371
442
372
443
lbl :: Eq a => [a ] -> String
373
444
lbl as =
374
- let p = (if null as then 0 else (100 * countUnique as) `div` length as) `mod` 10 * 10
375
- in show p ++ " % unique"
445
+ let p = (if null as then 0 else (100 * countUnique as) `div` length as)
446
+ `mod` 10 * 10
447
+ in show p ++ " % unique"
376
448
377
449
experiment :: Probe m (DiffTime , Int ) -> m ()
378
450
experiment p = do
@@ -399,7 +471,7 @@ test_timers xs =
399
471
sortFn :: DiffTime -> DiffTime -> Ordering
400
472
sortFn a b | a >= 0 && b >= 0 = a `compare` b
401
473
| a < 0 && b < 0 = EQ
402
- | otherwise = a `compare` b
474
+ | otherwise = a `compare` b
403
475
404
476
prop_timers_ST :: TestMicro -> Property
405
477
prop_timers_ST (TestMicro xs) =
@@ -450,12 +522,12 @@ prop_fork_order_IO = ioProperty . test_fork_order
450
522
451
523
452
524
test_threadId_order :: forall m .
453
- ( MonadFork m
454
- , MonadSTM m
455
- , MonadTimer m
456
- )
457
- => Positive Int
458
- -> m Property
525
+ ( MonadFork m
526
+ , MonadSTM m
527
+ , MonadTimer m
528
+ )
529
+ => Positive Int
530
+ -> m Property
459
531
test_threadId_order = \ (Positive n) -> do
460
532
isValid n <$> (forM [1 .. n] (const experiment))
461
533
where
@@ -490,7 +562,7 @@ test_wakeup_order :: ( MonadFork m
490
562
, MonadSTM m
491
563
, MonadTimer m
492
564
)
493
- => m Property
565
+ => m Property
494
566
test_wakeup_order = do
495
567
v <- newTVarIO False
496
568
wakupOrder <-
@@ -1154,7 +1226,12 @@ prop_stm_referenceM (SomeTerm _tyrep t) = do
1154
1226
-- | Check that 'timeout' does not deadlock when executed with asynchronous
1155
1227
-- exceptions uninterruptibly masked.
1156
1228
--
1157
- prop_timeout_no_deadlockM :: forall m . ( MonadFork m , MonadSTM m , MonadTimer m , MonadMask m )
1229
+ prop_timeout_no_deadlockM :: forall m .
1230
+ ( MonadFork m
1231
+ , MonadSTM m
1232
+ , MonadTimer m
1233
+ , MonadMask m
1234
+ )
1158
1235
=> m Bool
1159
1236
prop_timeout_no_deadlockM = do
1160
1237
v <- registerDelay' 0.01
0 commit comments