1 USING: accessors calendar concurrency.promises destructors io
2 io.backend.unix io.directories io.encodings.ascii
3 io.encodings.binary io.encodings.utf8 io.files io.launcher
4 io.streams.duplex io.timeouts kernel libc locals math namespaces
5 sequences threads tools.test unix.process unix.signals ;
6 IN: io.launcher.unix.tests
9 { } [ { "touch" "launcher-test-1" } try-process ] unit-test
11 { t } [ "launcher-test-1" file-exists? ] unit-test
14 "launcher-test-1" ?delete-file
19 "echo Hello" >>command
20 "launcher-test-1" >>stdout
25 { "cat" "launcher-test-1" }
26 ascii <process-reader> stream-contents
30 "launcher-test-1" ?delete-file
37 "launcher-test-1" >>stdout
42 { "cat" "launcher-test-1" }
43 ascii <process-reader> stream-contents
48 "launcher-test-1" binary <file-appender> [
51 "echo Hello" >>command
57 { "Hello\nHello\n" } [
58 { "cat" "launcher-test-1" }
59 ascii <process-reader> stream-contents
64 { "echo" "hi" } >>command
65 "launcher-test-2" >>stdout
67 "launcher-test-2" utf8 file-contents
74 "launcher-test-3" <appender> >>stdout
77 "launcher-test-3" utf8 file-contents
85 { { "A" "B" } } >>environment
86 ascii <process-reader> stream-lines
93 { { "A" "B" } } >>environment
94 +replace-environment+ >>environment-mode
95 ascii <process-reader> stream-lines
99 "ls" utf8 <process-stream> stream-contents >boolean
102 { "Hello world.\n" } [
103 "cat" utf8 <process-stream> [
104 "Hello world.\n" write
105 output-stream get dispose
106 input-stream get stream-contents
110 ! Test process timeouts
113 { "sleep" "10" } >>command
116 ] [ process-was-killed? ] must-fail-with
120 { "sleep" "10" } >>command
123 ] [ process-was-killed? ] must-fail-with
127 { "sleep" "10" } >>command
130 ] [ io-timeout? ] must-fail-with
132 ! Killed processes were exiting with code 0 on FreeBSD
139 "sleep 1000" run-detached
140 [ p fulfill ] [ wait-for-process s fulfill ] bi
143 p 1 seconds ?promise-timeout (kill-process)
144 s 3 seconds ?promise-timeout 0 =
148 ! Make sure that subprocesses don't inherit our signal mask
150 ! First, ensure that the Factor VM ignores SIGPIPE
151 : send-sigpipe ( pid -- )
152 "SIGPIPE" signal-names index 1 +
155 { } [ (current-process) send-sigpipe ] unit-test
158 { T{ signal f 13 } } [
159 "sleep 1000" run-detached
161 [ handle>> send-sigpipe ]
162 [ 2 seconds swap set-timeout ]
170 { "bash" "-c" "sleep 2&" } >>command
171 +low-priority+ >>priority
175 ! Check that processes launched with the group option kill their children (or not)
176 ! This test should leave two sleeps running for 30 seconds.
178 <process> { "bash" "-c" "sleep 30& sleep 30" } >>command
180 500 milliseconds >>timeout
182 ] [ process-was-killed? ] must-fail-with
184 ! This test should kill the sleep after 500ms.
186 <process> { "bash" "-c" "sleep 30& sleep 30" } >>command
188 500 milliseconds >>timeout
190 ] [ process-was-killed? ] must-fail-with
192 ! This test should kill the sleep after 500ms.
194 <process> { "bash" "-c" "sleep 30& sleep 30" } >>command
195 +new-session+ >>group
196 500 milliseconds >>timeout
198 ] [ process-was-killed? ] must-fail-with