Some some
This commit is contained in:
7
unix/tests/libposix/Makefile
Normal file
7
unix/tests/libposix/Makefile
Normal file
@@ -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
|
||||
16
unix/tests/libposix/all.T
Normal file
16
unix/tests/libposix/all.T
Normal file
@@ -0,0 +1,16 @@
|
||||
test('posix002', [ reqlib('unix'), omit_ways(prof_ways), fragile_for(16550, ['threaded2']) ],
|
||||
compile_and_run, [''])
|
||||
|
||||
# Skip on mingw32: assumes existence of 'pwd' and /tmp
|
||||
test('posix003', [when(opsys('mingw32'), skip), extra_clean(['po003.out'])],
|
||||
compile_and_run, [''])
|
||||
|
||||
test('posix004', [ reqlib('unix') ], compile_and_run, [''])
|
||||
|
||||
test('posix005', [reqlib('unix') ], 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, [''])
|
||||
4
unix/tests/libposix/posix002.hs
Normal file
4
unix/tests/libposix/posix002.hs
Normal file
@@ -0,0 +1,4 @@
|
||||
import System.Posix.Process
|
||||
|
||||
main =
|
||||
executeFile "printenv" True [] (Just [("ONE","1"),("TWO","2")])
|
||||
2
unix/tests/libposix/posix002.stdout
Normal file
2
unix/tests/libposix/posix002.stdout
Normal file
@@ -0,0 +1,2 @@
|
||||
ONE=1
|
||||
TWO=2
|
||||
17
unix/tests/libposix/posix003.hs
Normal file
17
unix/tests/libposix/posix003.hs
Normal file
@@ -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
|
||||
|
||||
1
unix/tests/libposix/posix003.stdout
Normal file
1
unix/tests/libposix/posix003.stdout
Normal file
@@ -0,0 +1 @@
|
||||
Got: "/dev"
|
||||
48
unix/tests/libposix/posix004.hs
Normal file
48
unix/tests/libposix/posix004.hs
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
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
|
||||
-- Force SIGFPE exceptions to not be ignored. Under some
|
||||
-- circumstances this test will be run with SIGFPE
|
||||
-- ignored, see #7399
|
||||
installHandler sigFPE Default Nothing
|
||||
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)"
|
||||
|
||||
1
unix/tests/libposix/posix004.stdout
Normal file
1
unix/tests/libposix/posix004.stdout
Normal file
@@ -0,0 +1 @@
|
||||
I'm happy.
|
||||
24
unix/tests/libposix/posix005.hs
Normal file
24
unix/tests/libposix/posix005.hs
Normal file
@@ -0,0 +1,24 @@
|
||||
import Data.List (sort)
|
||||
import System.IO
|
||||
import System.Posix.Env
|
||||
|
||||
printEnv :: IO ()
|
||||
printEnv = getEnvironment >>= print . sort
|
||||
|
||||
main = do
|
||||
hSetBuffering stdout NoBuffering
|
||||
term <- getEnv "TERM"
|
||||
maybe (return ()) putStrLn term
|
||||
setEnvironment [("one","1"),("two","2")]
|
||||
printEnv
|
||||
setEnv "foo" "bar" True
|
||||
printEnv
|
||||
setEnv "foo" "baz" True
|
||||
printEnv
|
||||
setEnv "fu" "bar" True
|
||||
printEnv
|
||||
unsetEnv "foo"
|
||||
printEnv
|
||||
clearEnv
|
||||
printEnv
|
||||
|
||||
7
unix/tests/libposix/posix005.stdout
Normal file
7
unix/tests/libposix/posix005.stdout
Normal file
@@ -0,0 +1,7 @@
|
||||
vt100
|
||||
[("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"),("one","1"),("two","2")]
|
||||
[]
|
||||
18
unix/tests/libposix/posix006.hs
Normal file
18
unix/tests/libposix/posix006.hs
Normal file
@@ -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
|
||||
1
unix/tests/libposix/posix006.stdout
Normal file
1
unix/tests/libposix/posix006.stdout
Normal file
@@ -0,0 +1 @@
|
||||
OK
|
||||
15
unix/tests/libposix/posix009.hs
Normal file
15
unix/tests/libposix/posix009.hs
Normal file
@@ -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)
|
||||
|
||||
6
unix/tests/libposix/posix009.stdout
Normal file
6
unix/tests/libposix/posix009.stdout
Normal file
@@ -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
|
||||
16
unix/tests/libposix/posix010.hs
Normal file
16
unix/tests/libposix/posix010.hs
Normal file
@@ -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
|
||||
3
unix/tests/libposix/posix010.stdout
Normal file
3
unix/tests/libposix/posix010.stdout
Normal file
@@ -0,0 +1,3 @@
|
||||
root:0:0
|
||||
root:0:0
|
||||
OK
|
||||
13
unix/tests/libposix/posix014.hs
Normal file
13
unix/tests/libposix/posix014.hs
Normal file
@@ -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 ()
|
||||
|
||||
1
unix/tests/libposix/posix014.stdout
Normal file
1
unix/tests/libposix/posix014.stdout
Normal file
@@ -0,0 +1 @@
|
||||
Hi, there - forked child calling
|
||||
Reference in New Issue
Block a user