1 USING: accessors calendar concurrency.promises continuations
2 debugger.unix destructors io io.backend.unix io.directories
3 io.encodings.ascii io.encodings.binary io.encodings.utf8
4 io.files io.launcher io.launcher.unix io.streams.duplex
5 io.timeouts kernel libc locals math namespaces sequences threads
6 tools.test unix.process ;
7 IN: io.launcher.unix.tests
11 { } [ { "touch" "launcher-test-1" } try-process ] unit-test
13 { t } [ "launcher-test-1" exists? ] unit-test
16 "launcher-test-1" ?delete-file
21 "echo Hello" >>command
22 "launcher-test-1" >>stdout
27 { "cat" "launcher-test-1" }
28 ascii <process-reader> stream-contents
32 "launcher-test-1" ?delete-file
39 "launcher-test-1" >>stdout
44 { "cat" "launcher-test-1" }
45 ascii <process-reader> stream-contents
50 "launcher-test-1" binary <file-appender> [
53 "echo Hello" >>command
59 { "Hello\nHello\n" } [
60 { "cat" "launcher-test-1" }
61 ascii <process-reader> stream-contents
66 { "echo" "hi" } >>command
67 "launcher-test-2" >>stdout
69 "launcher-test-2" utf8 file-contents
76 "launcher-test-3" <appender> >>stdout
79 "launcher-test-3" utf8 file-contents
87 { { "A" "B" } } >>environment
88 ascii <process-reader> stream-lines
95 { { "A" "B" } } >>environment
96 +replace-environment+ >>environment-mode
97 ascii <process-reader> stream-lines
101 "ls" utf8 <process-stream> stream-contents >boolean
104 { "Hello world.\n" } [
105 "cat" utf8 <process-stream> [
106 "Hello world.\n" write
107 output-stream get dispose
108 input-stream get stream-contents
112 ! Test process timeouts
115 { "sleep" "10" } >>command
118 ] [ process-was-killed? ] must-fail-with
122 { "sleep" "10" } >>command
125 ] [ process-was-killed? ] must-fail-with
129 { "sleep" "10" } >>command
132 ] [ io-timeout? ] must-fail-with
134 ! Killed processes were exiting with code 0 on FreeBSD
141 "sleep 1000" run-detached
142 [ p fulfill ] [ wait-for-process s fulfill ] bi
145 p 1 seconds ?promise-timeout (kill-process)
146 s 3 seconds ?promise-timeout 0 =
150 ! Make sure that subprocesses don't inherit our signal mask
152 ! First, ensure that the Factor VM ignores SIGPIPE
153 : send-sigpipe ( pid -- )
154 "SIGPIPE" signal-names index 1 +
157 { } [ (current-process) send-sigpipe ] unit-test
160 { T{ signal f 13 } } [
161 "sleep 1000" run-detached
163 [ handle>> send-sigpipe ]
164 [ 2 seconds swap set-timeout ]
172 { "bash" "-c" "sleep 2&" } >>command
173 +low-priority+ >>priority
177 ! Check that processes launched with the group option kill their children (or not)
178 ! This test should leave two sleeps running for 30 seconds.
180 <process> { "bash" "-c" "sleep 30& sleep 30" } >>command
182 500 milliseconds >>timeout
184 ] [ process-was-killed? ] must-fail-with
186 ! This test should kill the sleep after 500ms.
188 <process> { "bash" "-c" "sleep 30& sleep 30" } >>command
190 500 milliseconds >>timeout
192 ] [ process-was-killed? ] must-fail-with
194 ! This test should kill the sleep after 500ms.
196 <process> { "bash" "-c" "sleep 30& sleep 30" } >>command
197 +new-session+ >>group
198 500 milliseconds >>timeout
200 ] [ process-was-killed? ] must-fail-with