diff options
author | Joe Crayne <joe@jerkface.net> | 2020-01-23 22:03:32 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-24 03:01:27 -0500 |
commit | fead89918f61272998e968397ad51de097d197ea (patch) | |
tree | 5289ad9c332d5ec6e0146c67666445b308390a5b | |
parent | 140381ff489213ce890e660ae37a18ae7587c4fb (diff) |
Thread instrumentation test.
-rw-r--r-- | lifted-concurrent/lifted-concurrent.cabal | 5 | ||||
-rw-r--r-- | lifted-concurrent/test/TestThreads.hs | 21 |
2 files changed, 26 insertions, 0 deletions
diff --git a/lifted-concurrent/lifted-concurrent.cabal b/lifted-concurrent/lifted-concurrent.cabal index 8fe4b6a9..26e9df68 100644 --- a/lifted-concurrent/lifted-concurrent.cabal +++ b/lifted-concurrent/lifted-concurrent.cabal | |||
@@ -35,3 +35,8 @@ library | |||
35 | hs-source-dirs: src | 35 | hs-source-dirs: src |
36 | default-language: Haskell2010 | 36 | default-language: Haskell2010 |
37 | cpp-options: -DTHREAD_DEBUG | 37 | cpp-options: -DTHREAD_DEBUG |
38 | |||
39 | executable testhr | ||
40 | build-depends: base,lifted-concurrent | ||
41 | main-is: TestThreads.hs | ||
42 | hs-source-dirs: test | ||
diff --git a/lifted-concurrent/test/TestThreads.hs b/lifted-concurrent/test/TestThreads.hs new file mode 100644 index 00000000..8360badb --- /dev/null +++ b/lifted-concurrent/test/TestThreads.hs | |||
@@ -0,0 +1,21 @@ | |||
1 | import Control.Monad | ||
2 | import Control.Exception (throwIO) | ||
3 | |||
4 | import Control.Concurrent.ThreadUtil | ||
5 | import DebugUtil | ||
6 | |||
7 | main = do | ||
8 | mvars <- sequence $ replicate 200 $ newEmptyMVar | ||
9 | threads <- forM mvars $ forkIO . join . takeMVar | ||
10 | let (normalquits,mvars1) = splitAt 20 mvars | ||
11 | mapM_ (`putMVar` return ()) normalquits | ||
12 | let (exceptionquits,mvars2) = splitAt 20 mvars1 | ||
13 | mapM_ (`putMVar` throwIO (userError "oops")) exceptionquits | ||
14 | let (throwtoexceptions,threads1) = splitAt 20 $ drop 40 threads | ||
15 | mapM_ (`throwTo` userError "throwTo-oops") throwtoexceptions | ||
16 | let (killed,threads2) = splitAt 20 threads1 | ||
17 | mapM_ killThread killed | ||
18 | threadDelay 1000000 | ||
19 | report <- threadReport True | ||
20 | sequence_ $ zipWith (\n s -> putStrLn $ unwords [show n,s]) [1..] $ lines report | ||
21 | return () | ||