add tests for deadlocks in readChan & writeChan
authorSimon Marlow <marlowsd@gmail.com>
Mon, 11 Jun 2012 08:51:36 +0000 (09:51 +0100)
committerSimon Marlow <marlowsd@gmail.com>
Mon, 11 Jun 2012 11:21:19 +0000 (12:21 +0100)
tests/Concurrent/Chan002.hs [new file with mode: 0644]
tests/Concurrent/Chan002.stdout [new file with mode: 0644]
tests/Concurrent/Chan003.hs [new file with mode: 0644]
tests/Concurrent/Chan003.stdout [new file with mode: 0644]
tests/Concurrent/all.T

diff --git a/tests/Concurrent/Chan002.hs b/tests/Concurrent/Chan002.hs
new file mode 100644 (file)
index 0000000..812298e
--- /dev/null
@@ -0,0 +1,19 @@
+import Control.Concurrent
+import Control.Exception
+import Control.Monad
+import System.IO
+import System.Environment
+
+-- test for deadlocks
+main = do
+  hSetBuffering stdout NoBuffering
+  [n] <- getArgs
+  replicateM_ (read n) $ do
+         chan <- newChan
+         wid <- forkIO $ forever $ writeChan chan (5::Int)
+         rid <- forkIO $ forever $ void $ readChan chan
+         threadDelay 1000
+         throwTo rid ThreadKilled
+         putStr "."
+         readChan chan
+         throwTo wid ThreadKilled
diff --git a/tests/Concurrent/Chan002.stdout b/tests/Concurrent/Chan002.stdout
new file mode 100644 (file)
index 0000000..ab79b98
--- /dev/null
@@ -0,0 +1 @@
+....................................................................................................
\ No newline at end of file
diff --git a/tests/Concurrent/Chan003.hs b/tests/Concurrent/Chan003.hs
new file mode 100644 (file)
index 0000000..bfadaa8
--- /dev/null
@@ -0,0 +1,17 @@
+import Control.Concurrent
+import Control.Exception
+import Control.Monad
+import System.IO
+import System.Environment
+
+-- test for deadlocks
+main = do
+  hSetBuffering stdout NoBuffering
+  [n] <- getArgs
+  replicateM_ (read n) $ do
+         chan <- newChan
+         wid <- forkIO $ forever $ writeChan chan (5::Int)
+         threadDelay 3000
+         throwTo wid ThreadKilled
+         putStr "."
+         writeChan chan (3::Int)
diff --git a/tests/Concurrent/Chan003.stdout b/tests/Concurrent/Chan003.stdout
new file mode 100644 (file)
index 0000000..e003cf1
--- /dev/null
@@ -0,0 +1 @@
+........................................................................................................................................................................................................
\ No newline at end of file
index 004c6a1..35a7547 100644 (file)
@@ -4,6 +4,10 @@ test('SampleVar001', reqlib('QuickCheck'), compile_and_run, ['-package QuickChec
 test('4876', reqlib('random'), compile_and_run, ['']) # another SampleVar test
 
 test('Chan001',      reqlib('QuickCheck'), compile_and_run, ['-package QuickCheck'])
+
+test('Chan002',      extra_run_opts('100'), compile_and_run, [''])
+test('Chan003',      extra_run_opts('200'), compile_and_run, [''])
+
 test('MVar001',      reqlib('QuickCheck'), compile_and_run, ['-package QuickCheck'])
 test('QSemN001',     reqlib('QuickCheck'), compile_and_run, ['-package QuickCheck'])
 test('QSem001',      reqlib('QuickCheck'), compile_and_run, ['-package QuickCheck'])