Some some

This commit is contained in:
2020-04-14 11:27:28 +02:00
parent e194fdec91
commit eea53e7113
123 changed files with 14143 additions and 18 deletions

View 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
View 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, [''])

View File

@@ -0,0 +1,4 @@
import System.Posix.Process
main =
executeFile "printenv" True [] (Just [("ONE","1"),("TWO","2")])

View File

@@ -0,0 +1,2 @@
ONE=1
TWO=2

View 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

View File

@@ -0,0 +1 @@
Got: "/dev"

View 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)"

View File

@@ -0,0 +1 @@
I'm happy.

View 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

View 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")]
[]

View 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

View File

@@ -0,0 +1 @@
OK

View 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)

View 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

View 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

View File

@@ -0,0 +1,3 @@
root:0:0
root:0:0
OK

View 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 ()

View File

@@ -0,0 +1 @@
Hi, there - forked child calling