summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sydney Kerckhove <syd@cs-syd.eu>2018-12-21 12:35:32 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-02-23 21:25:41 -0500
commit2e9426df902cd2e118f162876d6991ffa5be9137 (patch)
tree674f83c0e7b256f6af5d19e173682bb8dd5a6481
parent04b7f4c1c6ea910ab378f27c5f9efd6c88f65425 (diff)
downloadhaskell-2e9426df902cd2e118f162876d6991ffa5be9137.tar.gz
hWaitForInput-accurate-socket test
-rw-r--r--libraries/base/tests/all.T1
-rw-r--r--libraries/base/tests/hWaitForInput-accurate-pipe.hs23
-rw-r--r--libraries/base/tests/hWaitForInput-accurate-pipe.stdout1
3 files changed, 25 insertions, 0 deletions
diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T
index 25e851b877..dc16246129 100644
--- a/libraries/base/tests/all.T
+++ b/libraries/base/tests/all.T
@@ -203,6 +203,7 @@ test('T8089',
test('hWaitForInput-accurate-socket', reqlib('unix'), compile_and_run, [''])
test('T8684', expect_broken(8684), compile_and_run, [''])
test('hWaitForInput-accurate-stdin', normal, compile_and_run, [''])
+test('hWaitForInput-accurate-pipe', reqlib('unix'), compile_and_run, [''])
test('T9826',normal, compile_and_run,[''])
test('T9848',
[ collect_stats('bytes allocated')
diff --git a/libraries/base/tests/hWaitForInput-accurate-pipe.hs b/libraries/base/tests/hWaitForInput-accurate-pipe.hs
new file mode 100644
index 0000000000..409c60c63c
--- /dev/null
+++ b/libraries/base/tests/hWaitForInput-accurate-pipe.hs
@@ -0,0 +1,23 @@
+import Control.Concurrent
+import Control.Monad
+import GHC.Clock
+import System.IO
+import System.Posix.IO
+import System.Timeout
+
+main :: IO ()
+main = do
+ (readPipe, _) <- createPipe
+ readPipeHandle <- fdToHandle readPipe
+ let nanoSecondsPerSecond = 1000 * 1000 * 1000
+ let milliSecondsPerSecond = 1000
+ let timeToSpend = 1
+ let timeToSpendNano = timeToSpend * nanoSecondsPerSecond
+ let timeToSpendMilli = timeToSpend * milliSecondsPerSecond
+ start <- getMonotonicTimeNSec
+ b <- hWaitForInput readPipeHandle timeToSpendMilli
+ end <- getMonotonicTimeNSec
+ let timeSpentNano = fromIntegral $ end - start
+ let delta = timeSpentNano - timeToSpendNano
+ -- We can never wait for a shorter amount of time than specified
+ putStrLn $ "delta >= 0: " ++ show (delta > 0)
diff --git a/libraries/base/tests/hWaitForInput-accurate-pipe.stdout b/libraries/base/tests/hWaitForInput-accurate-pipe.stdout
new file mode 100644
index 0000000000..f1e939c51d
--- /dev/null
+++ b/libraries/base/tests/hWaitForInput-accurate-pipe.stdout
@@ -0,0 +1 @@
+delta >= 0: True