From 891c0bf89b89e3995d2dbc1f6f72b43312b14a44 Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Fri, 9 Mar 2012 11:44:41 +0000 Subject: Copy tests from GHC testsuite (#1161) --- tests/libposix/Makefile | 7 +++++++ tests/libposix/all.T | 15 ++++++++++++++ tests/libposix/posix002.hs | 4 ++++ tests/libposix/posix002.stdout | 2 ++ tests/libposix/posix003.hs | 17 ++++++++++++++++ tests/libposix/posix003.stdout | 1 + tests/libposix/posix004.hs | 44 ++++++++++++++++++++++++++++++++++++++++++ tests/libposix/posix004.stdout | 1 + tests/libposix/posix005.hs | 21 ++++++++++++++++++++ tests/libposix/posix005.stdout | 7 +++++++ tests/libposix/posix006.hs | 18 +++++++++++++++++ tests/libposix/posix006.stdout | 1 + tests/libposix/posix009.hs | 15 ++++++++++++++ tests/libposix/posix009.stdout | 6 ++++++ tests/libposix/posix010.hs | 16 +++++++++++++++ tests/libposix/posix010.stdout | 3 +++ tests/libposix/posix014.hs | 13 +++++++++++++ tests/libposix/posix014.stdout | 1 + 18 files changed, 192 insertions(+) create mode 100644 tests/libposix/Makefile create mode 100644 tests/libposix/all.T create mode 100644 tests/libposix/posix002.hs create mode 100644 tests/libposix/posix002.stdout create mode 100644 tests/libposix/posix003.hs create mode 100644 tests/libposix/posix003.stdout create mode 100644 tests/libposix/posix004.hs create mode 100644 tests/libposix/posix004.stdout create mode 100644 tests/libposix/posix005.hs create mode 100644 tests/libposix/posix005.stdout create mode 100644 tests/libposix/posix006.hs create mode 100644 tests/libposix/posix006.stdout create mode 100644 tests/libposix/posix009.hs create mode 100644 tests/libposix/posix009.stdout create mode 100644 tests/libposix/posix010.hs create mode 100644 tests/libposix/posix010.stdout create mode 100644 tests/libposix/posix014.hs create mode 100644 tests/libposix/posix014.stdout (limited to 'tests') diff --git a/tests/libposix/Makefile b/tests/libposix/Makefile new file mode 100644 index 0000000..4ca7751 --- /dev/null +++ b/tests/libposix/Makefile @@ -0,0 +1,7 @@ +# This Makefile runs the tests using GHC's testsuite framework. It +# assumes the package is part of a GHC build tree with the testsuite +# installed in ../../../testsuite. + +TOP=../../../../testsuite +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk diff --git a/tests/libposix/all.T b/tests/libposix/all.T new file mode 100644 index 0000000..a266040 --- /dev/null +++ b/tests/libposix/all.T @@ -0,0 +1,15 @@ +test('posix002', [ reqlib('unix'), omit_ways(prof_ways) ], + compile_and_run, ['']) + +# Skip on mingw32: assumes existence of 'pwd' and /tmp +test('posix003', if_os('mingw32', skip), compile_and_run, ['']) + +test('posix004', [ reqlib('unix') ], compile_and_run, ['']) + +test('posix005', [reqlib('unix'), expect_broken(5648)], compile_and_run, ['']) + +test('posix006', reqlib('unix'), compile_and_run, ['']) +test('posix009', [ omit_ways(threaded_ways), reqlib('unix') ], compile_and_run, ['']) +test('posix010', reqlib('unix'), compile_and_run, ['']) + +test('posix014', [ reqlib('unix') ], compile_and_run, ['']) diff --git a/tests/libposix/posix002.hs b/tests/libposix/posix002.hs new file mode 100644 index 0000000..c5909ab --- /dev/null +++ b/tests/libposix/posix002.hs @@ -0,0 +1,4 @@ +import System.Posix.Process + +main = + executeFile "printenv" True [] (Just [("ONE","1"),("TWO","2")]) diff --git a/tests/libposix/posix002.stdout b/tests/libposix/posix002.stdout new file mode 100644 index 0000000..5e17a60 --- /dev/null +++ b/tests/libposix/posix002.stdout @@ -0,0 +1,2 @@ +ONE=1 +TWO=2 diff --git a/tests/libposix/posix003.hs b/tests/libposix/posix003.hs new file mode 100644 index 0000000..b28f9f7 --- /dev/null +++ b/tests/libposix/posix003.hs @@ -0,0 +1,17 @@ + +import Control.Monad +import Data.Char +import System.Exit +import System.IO +import System.Process + +main = do hw <- openFile "po003.out" WriteMode + ph <- runProcess "pwd" [] (Just "/dev") Nothing Nothing (Just hw) Nothing + ec <- waitForProcess ph + hClose hw + unless (ec == ExitSuccess) $ error "pwd failed" + hr <- openFile "po003.out" ReadMode + output <- hGetContents hr + putStrLn ("Got: " ++ show (filter (not . isSpace) output)) + hClose hr + diff --git a/tests/libposix/posix003.stdout b/tests/libposix/posix003.stdout new file mode 100644 index 0000000..5206ef3 --- /dev/null +++ b/tests/libposix/posix003.stdout @@ -0,0 +1 @@ +Got: "/dev" diff --git a/tests/libposix/posix004.hs b/tests/libposix/posix004.hs new file mode 100644 index 0000000..20e2af2 --- /dev/null +++ b/tests/libposix/posix004.hs @@ -0,0 +1,44 @@ + +import System.Exit (ExitCode(..), exitWith) +import System.Posix.Process +import System.Posix.Signals + +main = do test1 + test2 + test3 + test4 + putStrLn "I'm happy." + +test1 = do + forkProcess $ raiseSignal floatingPointException + Just (pid, tc) <- getAnyProcessStatus True False + case tc of + Terminated sig | sig == floatingPointException -> return () + _ -> error "unexpected termination cause" + +test2 = do + forkProcess $ exitImmediately (ExitFailure 42) + Just (pid, tc) <- getAnyProcessStatus True False + case tc of + Exited (ExitFailure 42) -> return () + _ -> error "unexpected termination cause (2)" + +test3 = do + forkProcess $ exitImmediately ExitSuccess + Just (pid, tc) <- getAnyProcessStatus True False + case tc of + Exited ExitSuccess -> return () + _ -> error "unexpected termination cause (3)" + +test4 = do + forkProcess $ raiseSignal softwareStop + Just (pid, tc) <- getAnyProcessStatus True True + case tc of + Stopped sig | sig == softwareStop -> do + signalProcess killProcess pid + Just (pid, tc) <- getAnyProcessStatus True True + case tc of + Terminated sig | sig == killProcess -> return () + _ -> error "unexpected termination cause (5)" + _ -> error "unexpected termination cause (4)" + diff --git a/tests/libposix/posix004.stdout b/tests/libposix/posix004.stdout new file mode 100644 index 0000000..8ed7ee5 --- /dev/null +++ b/tests/libposix/posix004.stdout @@ -0,0 +1 @@ +I'm happy. diff --git a/tests/libposix/posix005.hs b/tests/libposix/posix005.hs new file mode 100644 index 0000000..9ca569c --- /dev/null +++ b/tests/libposix/posix005.hs @@ -0,0 +1,21 @@ + +import System.IO +import System.Posix.Env + +main = do + hSetBuffering stdout NoBuffering + term <- getEnvVar "TERM" + putStrLn term + setEnvironment [("one","1"),("two","2")] + getEnvironment >>= print + setEnv "foo" "bar" True + getEnvironment >>= print + setEnv "foo" "baz" True + getEnvironment >>= print + setEnv "fu" "bar" True + getEnvironment >>= print + unsetEnv "foo" + getEnvironment >>= print + setEnvironment [] + getEnvironment >>= print + diff --git a/tests/libposix/posix005.stdout b/tests/libposix/posix005.stdout new file mode 100644 index 0000000..9896f43 --- /dev/null +++ b/tests/libposix/posix005.stdout @@ -0,0 +1,7 @@ +emacs +[("one","1"),("two","2")] +[("one","1"),("two","2"),("foo","bar")] +[("one","1"),("two","2"),("foo","baz")] +[("one","1"),("two","2"),("foo","baz"),("fu","bar")] +[("one","1"),("two","2"),("fu","bar")] +[] diff --git a/tests/libposix/posix006.hs b/tests/libposix/posix006.hs new file mode 100644 index 0000000..697e4e6 --- /dev/null +++ b/tests/libposix/posix006.hs @@ -0,0 +1,18 @@ + +import System.Posix.Time +import System.Posix.Unistd +import System.Posix.Signals + +main = do start <- epochTime + blockSignals reservedSignals -- see #4504 + sleep 1 + finish <- epochTime + let slept = finish - start + if slept >= 1 && slept <= 2 + then putStrLn "OK" + else do putStr "Started: " + print start + putStr "Finished: " + print finish + putStr "Slept: " + print slept diff --git a/tests/libposix/posix006.stdout b/tests/libposix/posix006.stdout new file mode 100644 index 0000000..d86bac9 --- /dev/null +++ b/tests/libposix/posix006.stdout @@ -0,0 +1 @@ +OK diff --git a/tests/libposix/posix009.hs b/tests/libposix/posix009.hs new file mode 100644 index 0000000..067d3a9 --- /dev/null +++ b/tests/libposix/posix009.hs @@ -0,0 +1,15 @@ +import System.Posix.Signals +import System.Posix.Unistd + +main = do + putStrLn "Blocking real time alarms." + blockSignals (addSignal realTimeAlarm reservedSignals) + putStrLn "Scheduling an alarm in 2 seconds..." + scheduleAlarm 2 + putStrLn "Sleeping 5 seconds." + sleep 5 + putStrLn "Woken up" + ints <- getPendingSignals + putStrLn "Checking pending interrupts for RealTimeAlarm" + print (inSignalSet realTimeAlarm ints) + diff --git a/tests/libposix/posix009.stdout b/tests/libposix/posix009.stdout new file mode 100644 index 0000000..d294675 --- /dev/null +++ b/tests/libposix/posix009.stdout @@ -0,0 +1,6 @@ +Blocking real time alarms. +Scheduling an alarm in 2 seconds... +Sleeping 5 seconds. +Woken up +Checking pending interrupts for RealTimeAlarm +True diff --git a/tests/libposix/posix010.hs b/tests/libposix/posix010.hs new file mode 100644 index 0000000..420d210 --- /dev/null +++ b/tests/libposix/posix010.hs @@ -0,0 +1,16 @@ +import System.Posix + +main = do + root <- getUserEntryForName "root" + putStrLn (ue2String root) + root' <- getUserEntryForID (userID root) + putStrLn (ue2String root') + if homeDirectory root == homeDirectory root' && + userShell root == userShell root' + then putStrLn "OK" + else putStrLn "Mismatch" + +ue2String ue = concat [name, ":", show uid, ":", show gid] + where name = userName ue + uid = userID ue + gid = userGroupID ue diff --git a/tests/libposix/posix010.stdout b/tests/libposix/posix010.stdout new file mode 100644 index 0000000..77a5024 --- /dev/null +++ b/tests/libposix/posix010.stdout @@ -0,0 +1,3 @@ +root:0:0 +root:0:0 +OK diff --git a/tests/libposix/posix014.hs b/tests/libposix/posix014.hs new file mode 100644 index 0000000..9d844b2 --- /dev/null +++ b/tests/libposix/posix014.hs @@ -0,0 +1,13 @@ +-- !! Basic pipe usage +module Main (main) where + +import System.Posix + +main = do + (rd, wd) <- createPipe + pid <- forkProcess $ do (str, _) <- fdRead rd 32 + putStrLn str + fdWrite wd "Hi, there - forked child calling" + getProcessStatus True False pid + return () + diff --git a/tests/libposix/posix014.stdout b/tests/libposix/posix014.stdout new file mode 100644 index 0000000..cab0a57 --- /dev/null +++ b/tests/libposix/posix014.stdout @@ -0,0 +1 @@ +Hi, there - forked child calling -- cgit v1.2.3