summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2020-01-23 22:03:32 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-24 03:01:27 -0500
commitfead89918f61272998e968397ad51de097d197ea (patch)
tree5289ad9c332d5ec6e0146c67666445b308390a5b
parent140381ff489213ce890e660ae37a18ae7587c4fb (diff)
Thread instrumentation test.
-rw-r--r--lifted-concurrent/lifted-concurrent.cabal5
-rw-r--r--lifted-concurrent/test/TestThreads.hs21
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
39executable 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 @@
1import Control.Monad
2import Control.Exception (throwIO)
3
4import Control.Concurrent.ThreadUtil
5import DebugUtil
6
7main = 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 ()