Skip to content

Fix process tests on OpenBSD #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/all.T
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# some platforms use spawnp instead of exec in some cases, resulting
# in spurious error output changes.
normalise_exec = normalise_fun(lambda s: s.replace('spawnp', 'exec'))
normalise_exec = normalise_fun(lambda s: s.replace('posix_spawnp', 'exec'))

test('process001', extra_clean(['process001.out']), compile_and_run, [''])
test('process002', [fragile_for(16547, concurrent_ways), extra_clean(['process002.out'])], compile_and_run, [''])
Expand Down
10 changes: 8 additions & 2 deletions tests/process009.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ import Control.Monad
import System.Exit
import System.Process
import Data.Maybe
import Data.List (intercalate)

-- Test that we get the right exit code for processes that terminate
-- with a signal (#7229)

main = do
(_,_,_,p) <- createProcess (shell "kill -HUP $$")
let script = intercalate " "
[ "exec python3 2>/dev/null"
, "-c"
, "'import os; os.kill(os.getpid(), 1)'"
]
(_,_,_,p) <- createProcess (shell script)
waitForProcess p >>= print
getProcessExitCode p >>= print

(_,_,_,p) <- createProcess (shell "kill -HUP $$")
(_,_,_,p) <- createProcess (shell script)
forever $ do
r <- getProcessExitCode p
if (isJust r) then do print r; exitWith ExitSuccess else return ()
Expand Down
16 changes: 10 additions & 6 deletions tests/process011.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ main = do

-- shell kills itself with SIGINT,
-- delegation off, exit code (death by signal) reported as normal
do let script = intercalate "; "
[ "kill -INT $$"
, "exit 42" ]
do let script = intercalate " "
[ "exec python3 2>/dev/null"
, "-c"
, "'import os; os.kill(os.getpid(), 2)'"
]
(_,_,_,p) <- createProcess (shell script) { delegate_ctlc = False }
waitForProcess p >>= print

putStrLn "===================== test 2"

-- shell kills itself with SIGINT,
-- delegation on, so expect to throw UserInterrupt
do let script = intercalate "; "
[ "kill -INT $$"
, "exit 42" ]
do let script = intercalate " "
[ "exec python3 2>/dev/null"
, "-c"
, "'import os; os.kill(os.getpid(), 2)'"
]
(_,_,_,p) <- createProcess (shell script) { delegate_ctlc = True }
(waitForProcess p >>= print)
`catchUserInterrupt` \e -> putStrLn $ "caught: " ++ show e
Expand Down