From 0e469b567b806336daade7fd5c581f9c8ebf009b Mon Sep 17 00:00:00 2001 From: sof Date: Sun, 27 Jul 1997 01:01:34 +0000 Subject: [PATCH] [project @ 1997-07-27 00:59:57 by sof] --- ghc/tests/io/should_run/io001.hs | 1 + ghc/tests/io/should_run/io001.stdout | 1 + ghc/tests/io/should_run/io002.hs | 13 ++++++++ ghc/tests/io/should_run/io002.stdout | 1 + ghc/tests/io/should_run/io003.hs | 9 ++++++ ghc/tests/io/should_run/io003.stdout | 1 + ghc/tests/io/should_run/io004.hs | 3 ++ ghc/tests/io/should_run/io005.hs | 11 +++++++ ghc/tests/io/should_run/io005.stdout | 11 +++++++ ghc/tests/io/should_run/io006.hs | 6 ++++ ghc/tests/io/should_run/io006.stdout | 1 + ghc/tests/io/should_run/io007.hs | 11 +++++++ ghc/tests/io/should_run/io007.stdout | 6 ++++ ghc/tests/io/should_run/io008.hs | 24 ++++++++++++++ ghc/tests/io/should_run/io008.stdout | 4 +++ ghc/tests/io/should_run/io009.hs | 6 ++++ ghc/tests/io/should_run/io009.stdout | 1 + ghc/tests/io/should_run/io010.hs | 20 ++++++++++++ ghc/tests/io/should_run/io010.stdout | 1 + ghc/tests/io/should_run/io011.hs | 18 +++++++++++ ghc/tests/io/should_run/io011.stdout | 1 + ghc/tests/io/should_run/io012.hs | 17 ++++++++++ ghc/tests/io/should_run/io013.hs | 18 +++++++++++ ghc/tests/io/should_run/io013.stdout | 3 ++ ghc/tests/io/should_run/io014.hs | 22 +++++++++++++ ghc/tests/io/should_run/io014.stdout | 7 ++++ ghc/tests/io/should_run/io015.hs | 10 ++++++ ghc/tests/io/should_run/io015.stdout | 10 ++++++ ghc/tests/io/should_run/io016.hs | 21 ++++++++++++ ghc/tests/io/should_run/io017.hs | 19 +++++++++++ ghc/tests/io/should_run/io017.stdout | 1 + ghc/tests/io/should_run/io018.hs | 28 ++++++++++++++++ ghc/tests/io/should_run/io019.hs | 22 +++++++++++++ ghc/tests/io/should_run/io020.hs | 13 ++++++++ ghc/tests/io/should_run/io021.hs | 6 ++++ ghc/tests/io/should_run/net001.hs | 55 +++++++++++++++++++++++++++++++ ghc/tests/io/should_run/net002.hs | 42 ++++++++++++++++++++++++ ghc/tests/io/should_run/net003.hs | 43 +++++++++++++++++++++++++ ghc/tests/io/should_run/net004.hs | 33 +++++++++++++++++++ ghc/tests/io/should_run/net005.hs | 37 +++++++++++++++++++++ ghc/tests/io/should_run/net006.hs | 27 ++++++++++++++++ ghc/tests/io/should_run/net007.hs | 44 +++++++++++++++++++++++++ ghc/tests/io/should_run/net008.hs | 21 ++++++++++++ ghc/tests/io/should_run/net009.hs | 28 ++++++++++++++++ ghc/tests/io/should_run/po001.hs | 23 +++++++++++++ ghc/tests/io/should_run/po002.hs | 4 +++ ghc/tests/io/should_run/po002.stdout | 2 ++ ghc/tests/io/should_run/po003.hs | 6 ++++ ghc/tests/io/should_run/po004.hs | 58 +++++++++++++++++++++++++++++++++ ghc/tests/io/should_run/po004.stdout | 1 + ghc/tests/io/should_run/po005.hs | 30 +++++++++++++++++ ghc/tests/io/should_run/po006.hs | 14 ++++++++ ghc/tests/io/should_run/po007.hs | 31 ++++++++++++++++++ ghc/tests/io/should_run/po008.hs | 12 +++++++ ghc/tests/io/should_run/po009.hs | 14 ++++++++ ghc/tests/io/should_run/po010.hs | 24 ++++++++++++++ ghc/tests/io/should_run/po010.stdout | 4 +++ ghc/tests/io/should_run/po011.hs | 22 +++++++++++++ ghc/tests/io/should_run/po011.stdout | 4 +++ ghc/tests/io/should_run/po012.hs | 59 ++++++++++++++++++++++++++++++++++ ghc/tests/io/stable001/Main.lhs | 50 ++++++++++++++++++++++++++++ ghc/tests/io/stable001/Makefile | 5 +++ ghc/tests/io/stable001/registers.h | 2 ++ 63 files changed, 1042 insertions(+) create mode 100644 ghc/tests/io/should_run/io001.hs create mode 100644 ghc/tests/io/should_run/io001.stdout create mode 100644 ghc/tests/io/should_run/io002.hs create mode 100644 ghc/tests/io/should_run/io002.stdout create mode 100644 ghc/tests/io/should_run/io003.hs create mode 100644 ghc/tests/io/should_run/io003.stdout create mode 100644 ghc/tests/io/should_run/io004.hs create mode 100644 ghc/tests/io/should_run/io004.stdout create mode 100644 ghc/tests/io/should_run/io005.hs create mode 100644 ghc/tests/io/should_run/io005.stdout create mode 100644 ghc/tests/io/should_run/io006.hs create mode 100644 ghc/tests/io/should_run/io006.stdout create mode 100644 ghc/tests/io/should_run/io007.hs create mode 100644 ghc/tests/io/should_run/io007.stdout create mode 100644 ghc/tests/io/should_run/io008.hs create mode 100644 ghc/tests/io/should_run/io008.stdout create mode 100644 ghc/tests/io/should_run/io009.hs create mode 100644 ghc/tests/io/should_run/io009.stdout create mode 100644 ghc/tests/io/should_run/io010.hs create mode 100644 ghc/tests/io/should_run/io010.stdout create mode 100644 ghc/tests/io/should_run/io011.hs create mode 100644 ghc/tests/io/should_run/io011.stdout create mode 100644 ghc/tests/io/should_run/io012.hs create mode 100644 ghc/tests/io/should_run/io013.hs create mode 100644 ghc/tests/io/should_run/io013.stdout create mode 100644 ghc/tests/io/should_run/io014.hs create mode 100644 ghc/tests/io/should_run/io014.stdout create mode 100644 ghc/tests/io/should_run/io015.hs create mode 100644 ghc/tests/io/should_run/io015.stdout create mode 100644 ghc/tests/io/should_run/io016.hs create mode 100644 ghc/tests/io/should_run/io016.stdout create mode 100644 ghc/tests/io/should_run/io017.hs create mode 100644 ghc/tests/io/should_run/io017.stdout create mode 100644 ghc/tests/io/should_run/io018.hs create mode 100644 ghc/tests/io/should_run/io018.stdout create mode 100644 ghc/tests/io/should_run/io019.hs create mode 100644 ghc/tests/io/should_run/io019.stdout create mode 100644 ghc/tests/io/should_run/io020.hs create mode 100644 ghc/tests/io/should_run/io020.stdout create mode 100644 ghc/tests/io/should_run/io021.hs create mode 100644 ghc/tests/io/should_run/io021.stdout create mode 100644 ghc/tests/io/should_run/net001.hs create mode 100644 ghc/tests/io/should_run/net001.stdout create mode 100644 ghc/tests/io/should_run/net002.hs create mode 100644 ghc/tests/io/should_run/net002.stdout create mode 100644 ghc/tests/io/should_run/net003.hs create mode 100644 ghc/tests/io/should_run/net003.stdout create mode 100644 ghc/tests/io/should_run/net004.hs create mode 100644 ghc/tests/io/should_run/net004.stdout create mode 100644 ghc/tests/io/should_run/net005.hs create mode 100644 ghc/tests/io/should_run/net005.stdout create mode 100644 ghc/tests/io/should_run/net006.hs create mode 100644 ghc/tests/io/should_run/net006.stdout create mode 100644 ghc/tests/io/should_run/net007.hs create mode 100644 ghc/tests/io/should_run/net007.stdout create mode 100644 ghc/tests/io/should_run/net008.hs create mode 100644 ghc/tests/io/should_run/net008.stdout create mode 100644 ghc/tests/io/should_run/net009.hs create mode 100644 ghc/tests/io/should_run/net009.stdout create mode 100644 ghc/tests/io/should_run/po001.hs create mode 100644 ghc/tests/io/should_run/po001.stdout create mode 100644 ghc/tests/io/should_run/po002.hs create mode 100644 ghc/tests/io/should_run/po002.stdout create mode 100644 ghc/tests/io/should_run/po003.hs create mode 100644 ghc/tests/io/should_run/po003.stdout create mode 100644 ghc/tests/io/should_run/po004.hs create mode 100644 ghc/tests/io/should_run/po004.stdout create mode 100644 ghc/tests/io/should_run/po005.hs create mode 100644 ghc/tests/io/should_run/po005.stdout create mode 100644 ghc/tests/io/should_run/po006.hs create mode 100644 ghc/tests/io/should_run/po006.stdout create mode 100644 ghc/tests/io/should_run/po007.hs create mode 100644 ghc/tests/io/should_run/po007.stdout create mode 100644 ghc/tests/io/should_run/po008.hs create mode 100644 ghc/tests/io/should_run/po008.stdout create mode 100644 ghc/tests/io/should_run/po009.hs create mode 100644 ghc/tests/io/should_run/po009.stdout create mode 100644 ghc/tests/io/should_run/po010.hs create mode 100644 ghc/tests/io/should_run/po010.stdout create mode 100644 ghc/tests/io/should_run/po011.hs create mode 100644 ghc/tests/io/should_run/po011.stdout create mode 100644 ghc/tests/io/should_run/po012.hs create mode 100644 ghc/tests/io/should_run/po012.stdout create mode 100644 ghc/tests/io/stable001/Main.lhs create mode 100644 ghc/tests/io/stable001/Makefile create mode 100644 ghc/tests/io/stable001/registers.h diff --git a/ghc/tests/io/should_run/io001.hs b/ghc/tests/io/should_run/io001.hs new file mode 100644 index 0000000..6620e3c --- /dev/null +++ b/ghc/tests/io/should_run/io001.hs @@ -0,0 +1 @@ +main = putStr "Hello, world\n" diff --git a/ghc/tests/io/should_run/io001.stdout b/ghc/tests/io/should_run/io001.stdout new file mode 100644 index 0000000..a5c1966 --- /dev/null +++ b/ghc/tests/io/should_run/io001.stdout @@ -0,0 +1 @@ +Hello, world diff --git a/ghc/tests/io/should_run/io002.hs b/ghc/tests/io/should_run/io002.hs new file mode 100644 index 0000000..620b44d --- /dev/null +++ b/ghc/tests/io/should_run/io002.hs @@ -0,0 +1,13 @@ +import System (getEnv) + +main = + getEnv "TERM" >>= \ term -> + putStr term >> + putChar '\n' >> + getEnv "One fish, two fish, red fish, blue fish" >>= \ fish -> + putStr fish >> + putChar '\n' + + + + diff --git a/ghc/tests/io/should_run/io002.stdout b/ghc/tests/io/should_run/io002.stdout new file mode 100644 index 0000000..e4be0f5 --- /dev/null +++ b/ghc/tests/io/should_run/io002.stdout @@ -0,0 +1 @@ +emacs diff --git a/ghc/tests/io/should_run/io003.hs b/ghc/tests/io/should_run/io003.hs new file mode 100644 index 0000000..93fff71 --- /dev/null +++ b/ghc/tests/io/should_run/io003.hs @@ -0,0 +1,9 @@ +import System (getProgName, getArgs) + +main = + getProgName >>= \ argv0 -> + putStr argv0 >> + getArgs >>= \ argv -> + sequence (map (\ x -> putChar ' ' >> putStr x) argv) >> + putChar '\n' + diff --git a/ghc/tests/io/should_run/io003.stdout b/ghc/tests/io/should_run/io003.stdout new file mode 100644 index 0000000..10f7f2b --- /dev/null +++ b/ghc/tests/io/should_run/io003.stdout @@ -0,0 +1 @@ +io003 with some arguments diff --git a/ghc/tests/io/should_run/io004.hs b/ghc/tests/io/should_run/io004.hs new file mode 100644 index 0000000..69d2221 --- /dev/null +++ b/ghc/tests/io/should_run/io004.hs @@ -0,0 +1,3 @@ +import System (exitWith, ExitCode(..)) + +main = exitWith (ExitFailure 42) diff --git a/ghc/tests/io/should_run/io004.stdout b/ghc/tests/io/should_run/io004.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/io005.hs b/ghc/tests/io/should_run/io005.hs new file mode 100644 index 0000000..3a41560 --- /dev/null +++ b/ghc/tests/io/should_run/io005.hs @@ -0,0 +1,11 @@ +import System (system, ExitCode(..), exitWith) + +main = + system "cat dog 1>/dev/null 2>&1" >>= \ ec -> + case ec of + ExitSuccess -> putStr "What?!?\n" >> fail (userError "dog succeeded") + ExitFailure _ -> + system "cat Main.hs 2>/dev/null" >>= \ ec -> + case ec of + ExitSuccess -> exitWith ExitSuccess + ExitFailure _ -> putStr "What?!?\n" >> fail (userError "cat failed") diff --git a/ghc/tests/io/should_run/io005.stdout b/ghc/tests/io/should_run/io005.stdout new file mode 100644 index 0000000..3a41560 --- /dev/null +++ b/ghc/tests/io/should_run/io005.stdout @@ -0,0 +1,11 @@ +import System (system, ExitCode(..), exitWith) + +main = + system "cat dog 1>/dev/null 2>&1" >>= \ ec -> + case ec of + ExitSuccess -> putStr "What?!?\n" >> fail (userError "dog succeeded") + ExitFailure _ -> + system "cat Main.hs 2>/dev/null" >>= \ ec -> + case ec of + ExitSuccess -> exitWith ExitSuccess + ExitFailure _ -> putStr "What?!?\n" >> fail (userError "cat failed") diff --git a/ghc/tests/io/should_run/io006.hs b/ghc/tests/io/should_run/io006.hs new file mode 100644 index 0000000..6eb862c --- /dev/null +++ b/ghc/tests/io/should_run/io006.hs @@ -0,0 +1,6 @@ +import IO -- 1.3 + +main = + hClose stderr >> + hPutStr stderr "junk" `catch` \ err -> if isIllegalOperation err then putStr "Okay\n" else error "Not okay\n" + diff --git a/ghc/tests/io/should_run/io006.stdout b/ghc/tests/io/should_run/io006.stdout new file mode 100644 index 0000000..1ddd42b --- /dev/null +++ b/ghc/tests/io/should_run/io006.stdout @@ -0,0 +1 @@ +Okay diff --git a/ghc/tests/io/should_run/io007.hs b/ghc/tests/io/should_run/io007.hs new file mode 100644 index 0000000..467382f --- /dev/null +++ b/ghc/tests/io/should_run/io007.hs @@ -0,0 +1,11 @@ +import IO -- 1.3 + +main = + openFile "io007.in" ReadMode >>= \ hIn -> + hPutStr hIn "test" `catch` + \ err -> + if isIllegalOperation err then + hGetContents hIn >>= \ stuff -> + hPutStr stdout stuff + else + error "Oh dear\n" diff --git a/ghc/tests/io/should_run/io007.stdout b/ghc/tests/io/should_run/io007.stdout new file mode 100644 index 0000000..d6c94d8 --- /dev/null +++ b/ghc/tests/io/should_run/io007.stdout @@ -0,0 +1,6 @@ +main = + openFile "io007.in" ReadMode >>= \ hIn -> + hPutStr hIn "test" `handle` + \ (IllegalOperation _) -> + hGetContents hIn >>= \ stuff -> + hPutStr stdout stuff diff --git a/ghc/tests/io/should_run/io008.hs b/ghc/tests/io/should_run/io008.hs new file mode 100644 index 0000000..b275a5a --- /dev/null +++ b/ghc/tests/io/should_run/io008.hs @@ -0,0 +1,24 @@ +module Main(main) where + +import IO -- 1.3 +--import IOBase -- tryIO 1.3 +--import GHCio + +import Directory (removeFile) + +main = + openFile "io008.in" ReadMode >>= \ hIn -> + openFile "io008.out" ReadWriteMode >>= \ hOut -> + removeFile "io008.out" >> + hGetPosn hIn >>= \ bof -> + copy hIn hOut >> + hSetPosn bof >> + copy hIn hOut >> + hSeek hOut AbsoluteSeek 0 >> + hGetContents hOut >>= \ stuff -> + putStr stuff + +copy :: Handle -> Handle -> IO () +copy hIn hOut = + try (hGetChar hIn) >>= + either (\ err -> if isEOFError err then return () else error "copy") ( \ x -> hPutChar hOut x >> copy hIn hOut) diff --git a/ghc/tests/io/should_run/io008.stdout b/ghc/tests/io/should_run/io008.stdout new file mode 100644 index 0000000..7ac3cc5 --- /dev/null +++ b/ghc/tests/io/should_run/io008.stdout @@ -0,0 +1,4 @@ +123456789*123456789*123456789*123456789*123456789*123456789*123456789*12 + 1 2 3 4 5 6 7 +123456789*123456789*123456789*123456789*123456789*123456789*123456789*12 + 1 2 3 4 5 6 7 diff --git a/ghc/tests/io/should_run/io009.hs b/ghc/tests/io/should_run/io009.hs new file mode 100644 index 0000000..5f95ce0 --- /dev/null +++ b/ghc/tests/io/should_run/io009.hs @@ -0,0 +1,6 @@ +import Directory (getDirectoryContents) +import QSort (sort) + +main = + getDirectoryContents "." >>= \ names -> + print (sort names) diff --git a/ghc/tests/io/should_run/io009.stdout b/ghc/tests/io/should_run/io009.stdout new file mode 100644 index 0000000..2b57378 --- /dev/null +++ b/ghc/tests/io/should_run/io009.stdout @@ -0,0 +1 @@ +[".", "..", ".depend", "CVS", "Main.hi", "Main.hs", "Main.o", "Makefile", "io009", "io009.stdout"] diff --git a/ghc/tests/io/should_run/io010.hs b/ghc/tests/io/should_run/io010.hs new file mode 100644 index 0000000..7fa0327 --- /dev/null +++ b/ghc/tests/io/should_run/io010.hs @@ -0,0 +1,20 @@ +import Directory (getCurrentDirectory, setCurrentDirectory, + createDirectory, removeDirectory, getDirectoryContents) + +main = + getCurrentDirectory >>= \ oldpwd -> + createDirectory "foo" >> + setCurrentDirectory "foo" >> + getDirectoryContents "." >>= \ [n1, n2] -> + if dot n1 && dot n2 then + setCurrentDirectory oldpwd >> + removeDirectory "foo" >> + putStr "Okay\n" + else + fail (userError "Oops") + + +dot :: String -> Bool +dot "." = True +dot ".." = True +dot _ = False diff --git a/ghc/tests/io/should_run/io010.stdout b/ghc/tests/io/should_run/io010.stdout new file mode 100644 index 0000000..1ddd42b --- /dev/null +++ b/ghc/tests/io/should_run/io010.stdout @@ -0,0 +1 @@ +Okay diff --git a/ghc/tests/io/should_run/io011.hs b/ghc/tests/io/should_run/io011.hs new file mode 100644 index 0000000..8d8d745 --- /dev/null +++ b/ghc/tests/io/should_run/io011.hs @@ -0,0 +1,18 @@ +import IO -- 1.3 + +import Directory +import GlaExts (trace) + +main = + createDirectory "foo" >> + openFile "foo/bar" WriteMode >>= \ h -> + hPutStr h "Okay\n" >> + hClose h >> + renameFile "foo/bar" "foo/baz" >> + renameDirectory "foo" "bar" >> + openFile "bar/baz" ReadMode >>= \ h -> + hGetContents h >>= \ stuff -> + putStr stuff >> + hClose h >> + removeFile "bar/baz" >> + removeDirectory "bar" diff --git a/ghc/tests/io/should_run/io011.stdout b/ghc/tests/io/should_run/io011.stdout new file mode 100644 index 0000000..1ddd42b --- /dev/null +++ b/ghc/tests/io/should_run/io011.stdout @@ -0,0 +1 @@ +Okay diff --git a/ghc/tests/io/should_run/io012.hs b/ghc/tests/io/should_run/io012.hs new file mode 100644 index 0000000..c5a16b7 --- /dev/null +++ b/ghc/tests/io/should_run/io012.hs @@ -0,0 +1,17 @@ +import IO -- 1.3 + +import CPUTime + +main = + openFile "/dev/null" WriteMode >>= \ h -> + hPrint h (nfib 30) >> + getCPUTime >>= \ t -> + print t + +nfib :: Integer -> Integer +nfib n + | n <= 1 = 1 + | otherwise = (n1 + n2 + 1) + where + n1 = nfib (n-1) + n2 = nfib (n-2) diff --git a/ghc/tests/io/should_run/io013.hs b/ghc/tests/io/should_run/io013.hs new file mode 100644 index 0000000..e4249d8 --- /dev/null +++ b/ghc/tests/io/should_run/io013.hs @@ -0,0 +1,18 @@ +import IO -- 1.3 + +main = + openFile "io013.in" ReadMode >>= \ h -> + hFileSize h >>= \ sz -> + print sz >> + hSeek h SeekFromEnd (-3) >> + hGetChar h >>= \ x -> + putStr (x:"\n") >> + hSeek h RelativeSeek (-2) >> + hGetChar h >>= \ w -> + putStr (w:"\n") >> + hIsSeekable h >>= \ True -> + hClose h >> + openFile "/dev/null" ReadMode >>= \ h -> + hIsSeekable h >>= \ False -> + hClose h + diff --git a/ghc/tests/io/should_run/io013.stdout b/ghc/tests/io/should_run/io013.stdout new file mode 100644 index 0000000..cffb0fd --- /dev/null +++ b/ghc/tests/io/should_run/io013.stdout @@ -0,0 +1,3 @@ +26 +x +w diff --git a/ghc/tests/io/should_run/io014.hs b/ghc/tests/io/should_run/io014.hs new file mode 100644 index 0000000..fecf4a5 --- /dev/null +++ b/ghc/tests/io/should_run/io014.hs @@ -0,0 +1,22 @@ +import IO -- 1.3 + +main = + accumulate (map hIsOpen [stdin, stdout, stderr]) >>= \ opens -> + print opens >> + accumulate (map hIsClosed [stdin, stdout, stderr]) >>= \ closeds -> + print closeds >> + accumulate (map hIsReadable [stdin, stdout, stderr]) >>= \ readables -> + print readables >> + accumulate (map hIsWritable [stdin, stdout, stderr]) >>= \ writables -> + print writables >> + accumulate (map hIsBlockBuffered [stdin, stdout, stderr]) >>= \ buffereds -> + print buffereds >> + accumulate (map hIsLineBuffered [stdin, stdout, stderr]) >>= \ buffereds -> + print buffereds >> + accumulate (map hIsNotBuffered [stdin, stdout, stderr]) >>= \ buffereds -> + print buffereds + where + -- these didn't make it into 1.3 + hIsBlockBuffered h = hGetBuffering h >>= \ b -> return $ case b of { BlockBuffering _ -> True; _ -> False } + hIsLineBuffered h = hGetBuffering h >>= \ b -> return $ case b of { LineBuffering -> True; _ -> False } + hIsNotBuffered h = hGetBuffering h >>= \ b -> return $ case b of { NoBuffering -> True; _ -> False } diff --git a/ghc/tests/io/should_run/io014.stdout b/ghc/tests/io/should_run/io014.stdout new file mode 100644 index 0000000..209be0b --- /dev/null +++ b/ghc/tests/io/should_run/io014.stdout @@ -0,0 +1,7 @@ +[True, True, True] +[False, False, False] +[True, False, False] +[False, True, True] +[True, True, False] +[False, False, False] +[False, False, True] diff --git a/ghc/tests/io/should_run/io015.hs b/ghc/tests/io/should_run/io015.hs new file mode 100644 index 0000000..37f0cc1 --- /dev/null +++ b/ghc/tests/io/should_run/io015.hs @@ -0,0 +1,10 @@ +import IO -- 1.3 + +main = + isEOF >>= \ eof -> + if eof then + return () + else + getChar >>= \ c -> + putChar c >> + main diff --git a/ghc/tests/io/should_run/io015.stdout b/ghc/tests/io/should_run/io015.stdout new file mode 100644 index 0000000..37f0cc1 --- /dev/null +++ b/ghc/tests/io/should_run/io015.stdout @@ -0,0 +1,10 @@ +import IO -- 1.3 + +main = + isEOF >>= \ eof -> + if eof then + return () + else + getChar >>= \ c -> + putChar c >> + main diff --git a/ghc/tests/io/should_run/io016.hs b/ghc/tests/io/should_run/io016.hs new file mode 100644 index 0000000..1ce01b2 --- /dev/null +++ b/ghc/tests/io/should_run/io016.hs @@ -0,0 +1,21 @@ +import IO -- 1.3 + +import System (getArgs) +import Char (toUpper) + +main = getArgs >>= \ [f1,f2] -> + openFile f1 ReadMode >>= \ h1 -> + openFile f2 WriteMode >>= \ h2 -> + copyFile h1 h2 >> + hClose h1 >> + hClose h2 + +copyFile h1 h2 = + hIsEOF h1 >>= \ eof -> + if eof then + return () + else + hGetChar h1 >>= \ c -> + hPutChar h2 (toUpper c) >> + copyFile h1 h2 + diff --git a/ghc/tests/io/should_run/io016.stdout b/ghc/tests/io/should_run/io016.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/io017.hs b/ghc/tests/io/should_run/io017.hs new file mode 100644 index 0000000..2be7254 --- /dev/null +++ b/ghc/tests/io/should_run/io017.hs @@ -0,0 +1,19 @@ +import IO -- 1.3 + +main = + hSetBuffering stdout NoBuffering >> + putStr "Enter an integer: " >> + readLine >>= \ x1 -> + putStr "Enter another integer: " >> + readLine >>= \ x2 -> + putStr ("Their sum is " ++ show (read x1+ read x2) ++ "\n") + + where readLine = isEOF >>= \ eof -> + if eof then return [] + else getChar >>= \ c -> + if c `elem` ['\n','\r'] then + return [] + else + readLine >>= \ cs -> + return (c:cs) + diff --git a/ghc/tests/io/should_run/io017.stdout b/ghc/tests/io/should_run/io017.stdout new file mode 100644 index 0000000..47d4185 --- /dev/null +++ b/ghc/tests/io/should_run/io017.stdout @@ -0,0 +1 @@ +Enter an integer: Enter another integer: Their sum is 35 diff --git a/ghc/tests/io/should_run/io018.hs b/ghc/tests/io/should_run/io018.hs new file mode 100644 index 0000000..c34334e --- /dev/null +++ b/ghc/tests/io/should_run/io018.hs @@ -0,0 +1,28 @@ +-- Sigbjorn and I don't understand what this test is meant to do +-- It simply hangs on stdin! + +import IO -- 1.3 + +import System(getArgs) + +main = getArgs >>= \ [user,host] -> + let username = (user ++ "@" ++ host) in + openFile username ReadWriteMode >>= \ cd -> + hSetBuffering stdin NoBuffering >> + hSetBuffering stdout NoBuffering >> + hSetBuffering cd NoBuffering >> + hPutStr cd speakString >> + speak cd + +speakString = "Someone wants to speak with you\n" + +speak cd = + (hReady cd >>= \ ready -> + if ready then (hGetChar cd >>= putChar) + else return () >> + + hReady stdin >>= \ ready -> + if ready then (getChar >>= hPutChar cd) + else return ()) >> + + speak cd diff --git a/ghc/tests/io/should_run/io018.stdout b/ghc/tests/io/should_run/io018.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/io019.hs b/ghc/tests/io/should_run/io019.hs new file mode 100644 index 0000000..bd50838 --- /dev/null +++ b/ghc/tests/io/should_run/io019.hs @@ -0,0 +1,22 @@ +import Time + +main = + getClockTime >>= \ time -> + print time >> + + let (CalendarTime year month mday hour min sec psec + wday yday timezone gmtoff isdst) = toUTCTime time + in + putStr (wdays !! wday) >> + putStr (' ' : months !! month) >> + putStr (' ' : shows2 mday (' ' : shows2 hour (':' : shows2 min (':' : shows2 sec + (' ' : timezone ++ ' ' : shows year "\n"))))) + + where + wdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] + months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] + shows2 x = showString (pad2 x) + pad2 x = case show x of + c@[_] -> '0' : c + cs -> cs diff --git a/ghc/tests/io/should_run/io019.stdout b/ghc/tests/io/should_run/io019.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/io020.hs b/ghc/tests/io/should_run/io020.hs new file mode 100644 index 0000000..1f349eb --- /dev/null +++ b/ghc/tests/io/should_run/io020.hs @@ -0,0 +1,13 @@ +import Time + +main = + getClockTime >>= \ time -> + let (CalendarTime year month mday hour min sec psec + wday yday timezone gmtoff isdst) = toUTCTime time + time' = toClockTime (CalendarTime (year - 1) month mday hour min sec psec + wday yday timezone gmtoff isdst) + in + print time >> + putChar '\n' >> + print time' >> + putChar '\n' diff --git a/ghc/tests/io/should_run/io020.stdout b/ghc/tests/io/should_run/io020.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/io021.hs b/ghc/tests/io/should_run/io021.hs new file mode 100644 index 0000000..c45a40b --- /dev/null +++ b/ghc/tests/io/should_run/io021.hs @@ -0,0 +1,6 @@ +import IO -- 1.3 + +main = + hSetBuffering stdin NoBuffering >> + hSetBuffering stdout NoBuffering >> + interact id diff --git a/ghc/tests/io/should_run/io021.stdout b/ghc/tests/io/should_run/io021.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/net001.hs b/ghc/tests/io/should_run/net001.hs new file mode 100644 index 0000000..121e51d --- /dev/null +++ b/ghc/tests/io/should_run/net001.hs @@ -0,0 +1,55 @@ +{- server + +The purpose of this test driver is to test TCP Stream sockets. +All values have been hard coded since the BSD library is not used to +query the databases for the values. In therory this code is thus not +portable but net007/Main.hs provides a portable version using the BSD +module. + +This creates a stream socket bound to port 5000 and waits for incoming +messages it then reads all available data before closing the +connection to that peer. + +No form of error checking is provided other than that already provided +by module SocketPrim. + + +TESTS: + socket + bindSocket + listen + accept + readSocket + sClose + +-} + + +module Main where + +import SocketPrim + + +main = + socket AF_INET Stream 6 >>= \ s -> + bindSocket s (SockAddrInet 5000 iNADDR_ANY) >> + listen s 5 >> + + let + loop = + accept s >>= \ (s',peerAddr) -> + putStr "*** Start of Transfer ***\n" >> + let + read_all = + readSocket s' 4 >>= \ (str, nbytes) -> + if nbytes /= 0 then + putStr str >> + read_all + else + putStr "\n*** End of Transfer ***\n" >> + sClose s' + in + read_all + in + loop + diff --git a/ghc/tests/io/should_run/net001.stdout b/ghc/tests/io/should_run/net001.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/net002.hs b/ghc/tests/io/should_run/net002.hs new file mode 100644 index 0000000..7ae6cdc --- /dev/null +++ b/ghc/tests/io/should_run/net002.hs @@ -0,0 +1,42 @@ +{- client + +Client side to net001/Main.hs. + +Note that the machine IP numbers have been hard coded into this +program so it is unlikely that you will be able to run this test if +you are not at dcs.gla.ac.uk :-( + +The reason for this is to aviod using the BSD module at this stage of +testing. + + +TESTS: + socket + connect + writeSocket + shutdown + inet_addr +-} + + +module Main where + +import SocketPrim + + +starbuck = "130.209.240.81" -- SunOS 4.1.3 1 sun4c +marcus = "130.209.247.2" -- SunOS 4.1.3 6 sun4m +avon = "130.209.247.4" -- OSF1 V2.0 240 alpha +karkar = "130.209.247.3" -- OSF1 V2.0 240 alpha + +message = "Hello World" + + +main = + socket AF_INET Stream 6 >>= \ s -> + connect s (SockAddrInet 5000 (inet_addr avon)) >> + + writeSocket s message >> + shutdown s 2 >> + sClose s + diff --git a/ghc/tests/io/should_run/net002.stdout b/ghc/tests/io/should_run/net002.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/net003.hs b/ghc/tests/io/should_run/net003.hs new file mode 100644 index 0000000..85c00e4 --- /dev/null +++ b/ghc/tests/io/should_run/net003.hs @@ -0,0 +1,43 @@ +{- server + +As for net001 but gets the system to allocate the next free port +number. It also prints out the IP number of the peer. + +TESTS: + getSocketName + inet_ntoa + +-} + +module Main where + +import SocketPrim + + +main = + socket AF_INET Stream 6 >>= \ s -> + bindSocket s (SockAddrInet aNY_PORT iNADDR_ANY) >> + getSocketName s >>= \ (SockAddrInet port _) -> + putStr ("Allocated Port Number: " ++ show port ++ "\n") >> + listen s 5 >> + + + let + loop = + accept s >>= \ (s',(SockAddrInet _ haddr)) -> + putStr ("*** Start of Transfer from: " ++ + (inet_ntoa haddr) ++ "***\n") >> + let + read_all = + readSocket s' 4 >>= \ (str, nbytes) -> + if nbytes /= 0 then + putStr str >> + read_all + else + putStr "\n*** End of Transfer ***\n" >> + sClose s' + in + read_all + in + loop + diff --git a/ghc/tests/io/should_run/net003.stdout b/ghc/tests/io/should_run/net003.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/net004.hs b/ghc/tests/io/should_run/net004.hs new file mode 100644 index 0000000..3891156 --- /dev/null +++ b/ghc/tests/io/should_run/net004.hs @@ -0,0 +1,33 @@ +{- client + +As for net002 but reads port number and message as arguments. +It also prints out the IP number of the peer machine. + + + +TESTS: + getPeerName +-} + + +module Main(main) where + +import SocketPrim +import System + + +starbuck = "130.209.240.81" +marcus = "130.209.247.2" + + +main = + getArgs >>= \ [port, message] -> + socket AF_INET Stream 6 >>= \ s -> + connect s (SockAddrInet (read port) (inet_addr starbuck)) >> + + getPeerName s >>= \ (SockAddrInet p haddr) -> + putStr ("Connected to : " ++ (inet_ntoa haddr) ++ "\n") >> + writeSocket s message >> + shutdown s 2 >> + sClose s + diff --git a/ghc/tests/io/should_run/net004.stdout b/ghc/tests/io/should_run/net004.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/net005.hs b/ghc/tests/io/should_run/net005.hs new file mode 100644 index 0000000..ec504aa --- /dev/null +++ b/ghc/tests/io/should_run/net005.hs @@ -0,0 +1,37 @@ +{- server + +Server as net001 but for Unix Domain Datagram sockets. + +TESTS: + socket + bindSocket + readSocket + +-} + + +module Main where + +import SocketPrim + + +main = + socket AF_UNIX Datagram 0 >>= \ s -> + bindSocket s (SockAddrUnix "sock") >> + + let + loop = + putStr "*** Start of Transfer ***\n" >> + let + read_all = + readSocket s 1024 >>= \ (str, nbytes) -> + if nbytes /= 0 then + putStr str >> + read_all + else + putStr "\n*** End of Transfer ***\n" + in + read_all + in + loop + diff --git a/ghc/tests/io/should_run/net005.stdout b/ghc/tests/io/should_run/net005.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/net006.hs b/ghc/tests/io/should_run/net006.hs new file mode 100644 index 0000000..e2ad13a --- /dev/null +++ b/ghc/tests/io/should_run/net006.hs @@ -0,0 +1,27 @@ +{- client + +Client side of net005 + +TESTS: + socket + connect + writeSocket + shutdown + sClose +-} + + +module Main where + +import SocketPrim + +message = "Hello World" + + +main = + socket AF_UNIX Datagram 0 >>= \ s -> + connect s (SockAddrUnix "sock") >> + + writeSocket s message >> + shutdown s ShutdownBoth >> + sClose s diff --git a/ghc/tests/io/should_run/net006.stdout b/ghc/tests/io/should_run/net006.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/net007.hs b/ghc/tests/io/should_run/net007.hs new file mode 100644 index 0000000..fbc9ff0 --- /dev/null +++ b/ghc/tests/io/should_run/net007.hs @@ -0,0 +1,44 @@ +{- server + +As net003 but uses the BSD module for portability. Also prints the +common name of the host rather than its IP number. + +TESTS: + getProtocolNumber + getSocketName + getHostByAddr + +-} + +module Main where + +import BSD +import SocketPrim + +main = + getProtocolNumber "tcp" >>= \ proto -> + socket AF_INET Stream proto >>= \ s -> + bindSocket s (SockAddrInet aNY_PORT iNADDR_ANY) >> + getSocketName s >>= \ (SockAddrInet port _) -> + putStr ("Allocated Port Number: " ++ show port ++ "\n") >> + listen s 5 >> + + + let + loop = + accept s >>= \ (s',(SockAddrInet _ haddr)) -> + getHostByAddr AF_INET haddr >>= \ (HostEntry hname _ _ _) -> + putStr ("*** Start of Transfer from: " ++ hname ++ "***\n") >> + let + read_all = + readSocket s' 4 >>= \ (str, nbytes) -> + if nbytes /= 0 then + putStr str >> + read_all + else + putStr "\n*** End of Transfer ***\n" >> + sClose s' + in + read_all + in + loop diff --git a/ghc/tests/io/should_run/net007.stdout b/ghc/tests/io/should_run/net007.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/net008.hs b/ghc/tests/io/should_run/net008.hs new file mode 100644 index 0000000..2cf1774 --- /dev/null +++ b/ghc/tests/io/should_run/net008.hs @@ -0,0 +1,21 @@ +module Main where + +import SocketPrim +import BSD +import System + +main = + getArgs >>= \ [host, port, message] -> + getProtocolNumber "tcp" >>= \ proto -> + socket AF_INET Stream proto >>= \ s -> + getHostByName host >>= \ (HostEntry _ _ _ haddrs) -> + connect s (SockAddrInet (read port) + (head haddrs)) >> + + getPeerName s >>= \ (SockAddrInet _ haddr) -> + getHostByAddr AF_INET haddr >>= \ (HostEntry hname _ _ _) -> + putStr ("Connected to : " ++ hname ++ "\n") >> + writeSocket s message >> + shutdown s ShutdownBoth >> + sClose s + diff --git a/ghc/tests/io/should_run/net008.stdout b/ghc/tests/io/should_run/net008.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/net009.hs b/ghc/tests/io/should_run/net009.hs new file mode 100644 index 0000000..c34334e --- /dev/null +++ b/ghc/tests/io/should_run/net009.hs @@ -0,0 +1,28 @@ +-- Sigbjorn and I don't understand what this test is meant to do +-- It simply hangs on stdin! + +import IO -- 1.3 + +import System(getArgs) + +main = getArgs >>= \ [user,host] -> + let username = (user ++ "@" ++ host) in + openFile username ReadWriteMode >>= \ cd -> + hSetBuffering stdin NoBuffering >> + hSetBuffering stdout NoBuffering >> + hSetBuffering cd NoBuffering >> + hPutStr cd speakString >> + speak cd + +speakString = "Someone wants to speak with you\n" + +speak cd = + (hReady cd >>= \ ready -> + if ready then (hGetChar cd >>= putChar) + else return () >> + + hReady stdin >>= \ ready -> + if ready then (getChar >>= hPutChar cd) + else return ()) >> + + speak cd diff --git a/ghc/tests/io/should_run/net009.stdout b/ghc/tests/io/should_run/net009.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/po001.hs b/ghc/tests/io/should_run/po001.hs new file mode 100644 index 0000000..31c32ba --- /dev/null +++ b/ghc/tests/io/should_run/po001.hs @@ -0,0 +1,23 @@ +import Posix + +main = + getParentProcessID >>= \ ppid -> + getProcessID >>= \ pid -> + putStr "Parent Process ID: " >> + print ppid >> + putStr "\nProcess ID: " >> + print pid >> + putStr "\nforking ps uxww" >> + print ppid >> + putChar '\n' >> + forkProcess >>= \ child -> + case child of + Nothing -> executeFile "ps" True ["uxww" ++ show ppid] Nothing + Just x -> doParent x pid + +doParent cpid pid = + getProcessStatus True False cpid >> + putStr "\nChild finished. Now exec'ing ps uxww" >> + print pid >> + putChar '\n' >> + executeFile "ps" True ["uxww" ++ show pid] Nothing diff --git a/ghc/tests/io/should_run/po001.stdout b/ghc/tests/io/should_run/po001.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/po002.hs b/ghc/tests/io/should_run/po002.hs new file mode 100644 index 0000000..8d01e8b --- /dev/null +++ b/ghc/tests/io/should_run/po002.hs @@ -0,0 +1,4 @@ +import Posix + +main = + executeFile "printenv" True [] (Just [("ONE","1"),("TWO","2")]) diff --git a/ghc/tests/io/should_run/po002.stdout b/ghc/tests/io/should_run/po002.stdout new file mode 100644 index 0000000..5e17a60 --- /dev/null +++ b/ghc/tests/io/should_run/po002.stdout @@ -0,0 +1,2 @@ +ONE=1 +TWO=2 diff --git a/ghc/tests/io/should_run/po003.hs b/ghc/tests/io/should_run/po003.hs new file mode 100644 index 0000000..dbea5e1 --- /dev/null +++ b/ghc/tests/io/should_run/po003.hs @@ -0,0 +1,6 @@ +import IO +import Posix + +main = + openFile "po003.out" WriteMode >>= \ h -> + runProcess "pwd" [] Nothing (Just "/usr/tmp") Nothing (Just h) Nothing diff --git a/ghc/tests/io/should_run/po003.stdout b/ghc/tests/io/should_run/po003.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/po004.hs b/ghc/tests/io/should_run/po004.hs new file mode 100644 index 0000000..2423f3f --- /dev/null +++ b/ghc/tests/io/should_run/po004.hs @@ -0,0 +1,58 @@ +import Posix +import System(ExitCode(..), exitWith) + +main = + forkProcess >>= \ maybe_pid -> + case maybe_pid of + Nothing -> raiseSignal floatingPointException + _ -> doParent + +doParent = + getAnyProcessStatus True False >>= \ (Just (pid, tc)) -> + case tc of + Terminated sig | sig == floatingPointException -> forkChild2 + _ -> fail (userError "unexpected termination cause") + +forkChild2 = + forkProcess >>= \ maybe_pid -> + case maybe_pid of + Nothing -> exitImmediately (ExitFailure 42) + _ -> doParent2 + +doParent2 = + getAnyProcessStatus True False >>= \ (Just (pid, tc)) -> + case tc of + Exited (ExitFailure 42) -> forkChild3 + _ -> fail (userError "unexpected termination cause (2)") + +forkChild3 = + forkProcess >>= \ maybe_pid -> + case maybe_pid of + Nothing -> exitImmediately (ExitSuccess) + _ -> doParent3 + +doParent3 = + getAnyProcessStatus True False >>= \ (Just (pid, tc)) -> + case tc of + Exited ExitSuccess -> forkChild4 + _ -> fail (userError "unexpected termination cause (3)") + +forkChild4 = + forkProcess >>= \ maybe_pid -> + case maybe_pid of + Nothing -> raiseSignal softwareStop + _ -> doParent4 + +doParent4 = + getAnyProcessStatus True True >>= \ (Just (pid, tc)) -> + case tc of + Stopped sig | sig == softwareStop -> enoughAlready pid + _ -> fail (userError "unexpected termination cause (4)") + +enoughAlready pid = + signalProcess killProcess pid >> + getAnyProcessStatus True True >>= \ (Just (pid, tc)) -> + case tc of + Terminated sig | sig == killProcess -> putStr "I'm happy.\n" + _ -> fail (userError "unexpected termination cause (5)") + diff --git a/ghc/tests/io/should_run/po004.stdout b/ghc/tests/io/should_run/po004.stdout new file mode 100644 index 0000000..8ed7ee5 --- /dev/null +++ b/ghc/tests/io/should_run/po004.stdout @@ -0,0 +1 @@ +I'm happy. diff --git a/ghc/tests/io/should_run/po005.hs b/ghc/tests/io/should_run/po005.hs new file mode 100644 index 0000000..81dce3a --- /dev/null +++ b/ghc/tests/io/should_run/po005.hs @@ -0,0 +1,30 @@ +import Posix + +main = + getEnvVar "TERM" >>= \ term -> + putStr term >> + putChar '\n' >> + setEnvironment [("one","1"),("two","2")] >> + getEnvironment >>= \ env -> + print env >> + putChar '\n' >> + setEnvVar "foo" "bar" >> + getEnvironment >>= \ env -> + print env >> + putChar '\n' >> + setEnvVar "foo" "baz" >> + getEnvironment >>= \ env -> + print env >> + putChar '\n' >> + setEnvVar "fu" "bar" >> + getEnvironment >>= \ env -> + print env >> + putChar '\n' >> + removeEnvVar "foo" >> + getEnvironment >>= \ env -> + print env >> + putChar '\n' >> + setEnvironment [] >> + getEnvironment >>= \ env -> + print env >> + putChar '\n' diff --git a/ghc/tests/io/should_run/po005.stdout b/ghc/tests/io/should_run/po005.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/po006.hs b/ghc/tests/io/should_run/po006.hs new file mode 100644 index 0000000..eb6451d --- /dev/null +++ b/ghc/tests/io/should_run/po006.hs @@ -0,0 +1,14 @@ +import Posix + +main = + epochTime >>= \ start -> + sleep 5 >> + let timeleft = 0 in + epochTime >>= \ finish -> + putStr "Started: " >> + print start >> + putStr "\nSlept: " >> + print (5 - timeleft) >> + putStr "\nFinished: " >> + print finish >> + putChar '\n' diff --git a/ghc/tests/io/should_run/po006.stdout b/ghc/tests/io/should_run/po006.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/po007.hs b/ghc/tests/io/should_run/po007.hs new file mode 100644 index 0000000..3a37dc7 --- /dev/null +++ b/ghc/tests/io/should_run/po007.hs @@ -0,0 +1,31 @@ +import Posix + +main = + installHandler keyboardSignal (Catch doCtrlC) Nothing >> + getTerminalAttributes stdInput >>= \ ta -> + case (controlChar ta Interrupt) of + Nothing -> fixMe ta + Just x -> continue x + +fixMe ta = + putStr "Oops...no interrupt character?\nI can fix that...\n" >> + setTerminalAttributes stdInput (withCC ta (Interrupt, '\ETX')) Immediately >> + getTerminalAttributes stdInput >>= \ ta -> + case (controlChar ta Interrupt) of + Nothing -> putStr "...Then again, maybe I can't\n" + Just x -> continue x + +continue x = + putStr "Press '" >> + putStr (ccStr x) >> + putStr "'.\n" >> + awaitSignal Nothing >> + putStr "How did I get here?\n" + +doCtrlC = + putStr "Caught an interrupt.\n" + +ccStr '\DEL' = "^?" +ccStr x + | x >= ' ' = [x] + | otherwise = ['^', (toEnum (fromEnum x + fromEnum '@'))] diff --git a/ghc/tests/io/should_run/po007.stdout b/ghc/tests/io/should_run/po007.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/po008.hs b/ghc/tests/io/should_run/po008.hs new file mode 100644 index 0000000..249e58e --- /dev/null +++ b/ghc/tests/io/should_run/po008.hs @@ -0,0 +1,12 @@ +import Posix + +main = + installHandler realTimeAlarm (Catch alarmclock) Nothing >> + putStr "Scheduling an alarm in 5 seconds...\n" >> + scheduleAlarm 5 >> + putStr "Sleeping one minute.\n" >> + sleep 60 >> + putStr "How did I get here?\n" + +alarmclock = + putStr "The alarm went off.\n" diff --git a/ghc/tests/io/should_run/po008.stdout b/ghc/tests/io/should_run/po008.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/po009.hs b/ghc/tests/io/should_run/po009.hs new file mode 100644 index 0000000..a1f284f --- /dev/null +++ b/ghc/tests/io/should_run/po009.hs @@ -0,0 +1,14 @@ +import Posix + +main = + putStr "Blocking real time alarms.\n" >> + blockSignals (addSignal realTimeAlarm emptySignalSet) >> + putStr "Scheduling an alarm in 2 seconds...\n" >> + scheduleAlarm 2 >> + putStr "Sleeping 5 seconds.\n" >> + sleep 5 >> + getPendingSignals >>= \ ints -> + putStr "Checking pending interrupts for RealTimeAlarm\n" >> + print (inSignalSet realTimeAlarm ints) >> + putChar '\n' + diff --git a/ghc/tests/io/should_run/po009.stdout b/ghc/tests/io/should_run/po009.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/should_run/po010.hs b/ghc/tests/io/should_run/po010.hs new file mode 100644 index 0000000..86ef3e1 --- /dev/null +++ b/ghc/tests/io/should_run/po010.hs @@ -0,0 +1,24 @@ +import Posix + +main = + getUserEntryForName "mattson" >>= \ mattson -> + getUserEntryForName "partain" >>= \ partain -> + putStr (ue2String mattson) >> + putChar '\n' >> + putStr (ue2String partain) >> + putChar '\n' >> + getUserEntryForID (userID mattson) >>= \ muid -> + getUserEntryForID (userID partain) >>= \ puid -> + putStr (ue2String muid) >> + putChar '\n' >> + putStr (ue2String puid) >> + putChar '\n' + +ue2String ue = + name ++ (':' : (show uid) ++ (':' : (show gid) ++ (':' : home ++ (':' : shell)))) + where + name = userName ue + uid = userID ue + gid = userGroupID ue + home = homeDirectory ue + shell = userShell ue diff --git a/ghc/tests/io/should_run/po010.stdout b/ghc/tests/io/should_run/po010.stdout new file mode 100644 index 0000000..ec1d729 --- /dev/null +++ b/ghc/tests/io/should_run/po010.stdout @@ -0,0 +1,4 @@ +mattson:104:401:/users/fp/mattson:/bin/csh +partain:184:401:/users/fp/partain:/usr/local/bin/tcsh +mattson:104:401:/users/fp/mattson:/bin/csh +partain:184:401:/users/fp/partain:/usr/local/bin/tcsh diff --git a/ghc/tests/io/should_run/po011.hs b/ghc/tests/io/should_run/po011.hs new file mode 100644 index 0000000..f8baf1c --- /dev/null +++ b/ghc/tests/io/should_run/po011.hs @@ -0,0 +1,22 @@ +import Posix + +main = + getGroupEntryForName "grasp" >>= \ grasp -> + getGroupEntryForName "staff" >>= \ staff -> + putStr (ge2String grasp) >> + putChar '\n' >> + putStr (ge2String staff) >> + putChar '\n' >> + getGroupEntryForID (groupID grasp) >>= \ guid -> + getGroupEntryForID (groupID staff) >>= \ suid -> + putStr (ge2String guid) >> + putChar '\n' >> + putStr (ge2String suid) >> + putChar '\n' + +ge2String ge = + name ++ (':' : (show gid) ++ (':' : members)) + where + name = groupName ge + gid = groupID ge + members = foldr (\x y -> x ++ (',' : y)) "" (groupMembers ge) diff --git a/ghc/tests/io/should_run/po011.stdout b/ghc/tests/io/should_run/po011.stdout new file mode 100644 index 0000000..11b5df4 --- /dev/null +++ b/ghc/tests/io/should_run/po011.stdout @@ -0,0 +1,4 @@ +grasp:401:andre,andy,ap,areid,cvh,dm,dnt,gnik,grasp,hwloidl,jan,johan,jonathan,jtod,kh,laszlo,mattson,partain,sansom,satnam,sewardj,sharpkm,simonm,simonpj,sof,trinder,wadler, +staff:9:aileen,alexa,ali,alison,andy,anne,ansftp,aran,arthur,audit,bill,botech,bw,carol,carron,cathy,conftp,cs2head,cvh,dam,darryn,daw,dcg,debbie,del,deptlib,dkm,dlg,dm,dnt,ellen,f131mgr,fabio,fairouz,faxback,fido,finance,fiona,footsie,george,gilbert,gilles,gsm,handbook,harrismi,helen,hme,hmg,huw,iain,id,igr,iii,imis-doc,imm,inei,infoman,ingres,inventdb,irfest,isabel,jacksonn,jacqui,james,janice,jej,jim,jl,jmm,johnson,jon,jstack,jtod,jwp,keith,kempj,kh,kieran,kimb,kirsten,kmssys,laurent,lewis,lisa,lizbeth,logiej,love,lyons,maclib,macneisd,margaret,mark,mary,mattson,meurig,mjj,mmi,monica,mossin,mpa,muffy,nk,norman,partain,pd,pdg,pete,pp,ps,quintin,rab,ray,rdm,reh,replib,rff,rffingres,rich,rios,rjw,rn,ron,ruffin,rwi,sanderso,sandy,sansom,satnam,sheila,sid,simonm,simonpj,slurry,softlib,stephen,steve,stevem,stuart,support,susan,tania,tech,teresa,tfm,tommyk,tracy,trinder,types,typesftp,wadler,wf,xadmin, +grasp:401:andre,andy,ap,areid,cvh,dm,dnt,gnik,grasp,hwloidl,jan,johan,jonathan,jtod,kh,laszlo,mattson,partain,sansom,satnam,sewardj,sharpkm,simonm,simonpj,sof,trinder,wadler, +staff:9:aileen,alexa,ali,alison,andy,anne,ansftp,aran,arthur,audit,bill,botech,bw,carol,carron,cathy,conftp,cs2head,cvh,dam,darryn,daw,dcg,debbie,del,deptlib,dkm,dlg,dm,dnt,ellen,f131mgr,fabio,fairouz,faxback,fido,finance,fiona,footsie,george,gilbert,gilles,gsm,handbook,harrismi,helen,hme,hmg,huw,iain,id,igr,iii,imis-doc,imm,inei,infoman,ingres,inventdb,irfest,isabel,jacksonn,jacqui,james,janice,jej,jim,jl,jmm,johnson,jon,jstack,jtod,jwp,keith,kempj,kh,kieran,kimb,kirsten,kmssys,laurent,lewis,lisa,lizbeth,logiej,love,lyons,maclib,macneisd,margaret,mark,mary,mattson,meurig,mjj,mmi,monica,mossin,mpa,muffy,nk,norman,partain,pd,pdg,pete,pp,ps,quintin,rab,ray,rdm,reh,replib,rff,rffingres,rich,rios,rjw,rn,ron,ruffin,rwi,sanderso,sandy,sansom,satnam,sheila,sid,simonm,simonpj,slurry,softlib,stephen,steve,stevem,stuart,support,susan,tania,tech,teresa,tfm,tommyk,tracy,trinder,types,typesftp,wadler,wf,xadmin, diff --git a/ghc/tests/io/should_run/po012.hs b/ghc/tests/io/should_run/po012.hs new file mode 100644 index 0000000..87f002a --- /dev/null +++ b/ghc/tests/io/should_run/po012.hs @@ -0,0 +1,59 @@ +import Posix +import IO -- 1.3 + +main = + createFile "po012.out" stdFileMode >>= \ fd -> + installHandler processStatusChanged (Catch (reap1 fd)) Nothing >> + ls >> + awaitSignal Nothing + +ls = + runProcess "ls" ["-l"] Nothing Nothing Nothing Nothing Nothing + +reap1 fd = + hPutStrLn stderr "Reaper1" >> + getAnyProcessStatus True False >> + installHandler processStatusChanged (Catch (reap2 fd)) Nothing >> + fdWrite fd (take 666 (repeat 'x')) >> + ls >> + awaitSignal Nothing + +reap2 fd = + hPutStrLn stderr "Reaper2" >> + getAnyProcessStatus True False >> + installHandler processStatusChanged (Catch (reap3 fd)) Nothing >> + setFileMode "po012.out" + (foldr1 unionFileModes [ownerReadMode,ownerWriteMode,groupReadMode,otherReadMode]) >> + ls >> + awaitSignal Nothing + +reap3 fd = + hPutStrLn stderr "Reaper3" >> + getAnyProcessStatus True False >> + installHandler processStatusChanged (Catch (reap4 fd)) Nothing >> + setFileTimes "po012.out" 0 0 >> + ls >> + awaitSignal Nothing + +reap4 fd = + hPutStrLn stderr "Reaper4" >> + getAnyProcessStatus True False >> + installHandler processStatusChanged (Catch (reap5 fd)) Nothing >> + --removeLink "po012.out" >> + ls >> + awaitSignal Nothing + +reap5 fd = + hPutStrLn stderr "Reaper5" >> + getAnyProcessStatus True False >> + fdSeek fd SeekFromEnd 0 >>= \ bytes -> + if bytes == 666 then + fdSeek fd AbsoluteSeek 0 >> + hPutStrLn stderr "Reaper5" >> + fdRead fd 666 >>= \ (str, _) -> + if str == (take 666 (repeat 'x')) then + putStr "Okay\n" + else + putStr "Read failed\n" + else + putStr "Seek returned wrong size\n" diff --git a/ghc/tests/io/should_run/po012.stdout b/ghc/tests/io/should_run/po012.stdout new file mode 100644 index 0000000..e69de29 diff --git a/ghc/tests/io/stable001/Main.lhs b/ghc/tests/io/stable001/Main.lhs new file mode 100644 index 0000000..6950a54 --- /dev/null +++ b/ghc/tests/io/stable001/Main.lhs @@ -0,0 +1,50 @@ +\begin{code} +module Main(main) where + +--import PreludeGlaST +--old:import GHCio(stThen) +--old:import PreludeGlaMisc + +main = makeStablePtr test >>= \ stablePtr -> + ((_casm_GC_ ``SaveAllStgRegs(); test1(%0); RestoreAllStgRegs();'' stablePtr) + :: PrimIO ()) + >>= \ _ -> + return () + +test :: IO Int +test = + let f x = sum [1..x] + f :: Int -> Int + in + _ccall_ printf + "The stable pointer has just been used to print this number %d\n" (f 100) + >>= \ _ -> + return 5 +\end{code} + +This is a rather exciting experiment in using the new call +@makeStablePtr#@ and @performIO@. It doesn't do much but it took an +incredible effort to get it to do it. + +\begin{code}[C-code] +#define NULL_REG_MAP +#include "stgdefs.h" + +int +test1( stableIOPtr ) + StgStablePtr stableIOPtr; +{ + int i; + int result; + + printf("Using stable pointer %x\n", stableIOPtr); + + for( i = 0; i != 10; i = i + 1 ) { + printf( "Calling stable pointer for %dth time\n", i ); + performIO( stableIOPtr ); + printf( "Returned after stable pointer\n" ); + } + + return 1; +} +\end{code} diff --git a/ghc/tests/io/stable001/Makefile b/ghc/tests/io/stable001/Makefile new file mode 100644 index 0000000..f3b9242 --- /dev/null +++ b/ghc/tests/io/stable001/Makefile @@ -0,0 +1,5 @@ +TOP = ../.. +include $(TOP)/mk/boilerplate.mk +SRC_HC_OPTS += -fglasgow-exts +include $(TOP)/mk/target.mk + diff --git a/ghc/tests/io/stable001/registers.h b/ghc/tests/io/stable001/registers.h new file mode 100644 index 0000000..84e92d7 --- /dev/null +++ b/ghc/tests/io/stable001/registers.h @@ -0,0 +1,2 @@ +#define UpdateStgRegs _SaveStgRegs() +#define ReloadStgRegs _RestoreStgRegs() -- 1.7.10.4