1 USING: accessors arrays bootstrap.image calendar
2 concurrency.promises continuations debugger.unix destructors io
3 io.backend.unix io.directories io.encodings.ascii
4 io.encodings.binary io.encodings.utf8 io.files io.files.temp
5 io.launcher io.launcher.unix io.pathnames io.streams.duplex
6 io.timeouts kernel libc locals math namespaces sequences
7 threads tools.test unix unix.process ;
8 IN: io.launcher.unix.tests
10 : arch-temp-file ( str -- str' )
11 "-" my-arch 3append temp-file ;
14 [ "launcher-test-1" arch-temp-file delete-file ] ignore-errors
19 "launcher-test-1" arch-temp-file
24 { t } [ "launcher-test-1" arch-temp-file exists? ] unit-test
27 [ "launcher-test-1" arch-temp-file delete-file ] ignore-errors
32 "echo Hello" >>command
33 "launcher-test-1" arch-temp-file >>stdout
39 "launcher-test-1" arch-temp-file
41 ascii <process-reader> stream-contents
45 [ "launcher-test-1" arch-temp-file delete-file ] ignore-errors
52 "launcher-test-1" arch-temp-file >>stdout
58 "launcher-test-1" arch-temp-file
60 ascii <process-reader> stream-contents
65 "launcher-test-1" arch-temp-file binary <file-appender> [
68 "echo Hello" >>command
74 { "Hello\nHello\n" } [
76 "launcher-test-1" arch-temp-file
78 ascii <process-reader> stream-contents
84 { { "A" "B" } } >>environment
85 ascii <process-reader> stream-lines
92 { { "A" "B" } } >>environment
93 +replace-environment+ >>environment-mode
94 ascii <process-reader> stream-lines
99 [ "aloha" delete-file ] ignore-errors
101 { "echo" "hi" } >>command
105 temp-directory "aloha" append-path
109 [ "append-test" arch-temp-file delete-file ] ignore-errors
115 "append-test" arch-temp-file <appender> >>stdout
118 "append-test" arch-temp-file utf8 file-contents
121 { t } [ "ls" utf8 <process-stream> stream-contents >boolean ] unit-test
123 { "Hello world.\n" } [
124 "cat" utf8 <process-stream> [
125 "Hello world.\n" write
126 output-stream get dispose
127 input-stream get stream-contents
131 ! Test process timeouts
134 { "sleep" "10" } >>command
137 ] [ process-was-killed? ] must-fail-with
141 { "sleep" "10" } >>command
144 ] [ process-was-killed? ] must-fail-with
148 { "sleep" "10" } >>command
151 ] [ io-timeout? ] must-fail-with
153 ! Killed processes were exiting with code 0 on FreeBSD
160 "sleep 1000" run-detached
161 [ p fulfill ] [ wait-for-process s fulfill ] bi
164 p 1 seconds ?promise-timeout (kill-process)
165 s 3 seconds ?promise-timeout 0 =
169 ! Make sure that subprocesses don't inherit our signal mask
171 ! First, ensure that the Factor VM ignores SIGPIPE
172 : send-sigpipe ( pid -- )
173 "SIGPIPE" signal-names index 1 +
176 { } [ (current-process) send-sigpipe ] unit-test
179 { T{ signal f 13 } } [
180 "sleep 1000" run-detached
182 [ handle>> send-sigpipe ]
183 [ 2 seconds swap set-timeout ]
191 { "bash" "-c" "sleep 2&" } >>command
192 +low-priority+ >>priority
196 ! Check that processes launched with the group option kill their children (or not)
197 ! This test should leave two sleeps running for 30 seconds.
199 <process> { "bash" "-c" "sleep 30& sleep 30" } >>command
201 500 milliseconds >>timeout
203 ] [ process-was-killed? ] must-fail-with
205 ! This test should kill the sleep after 500ms.
207 <process> { "bash" "-c" "sleep 30& sleep 30" } >>command
209 500 milliseconds >>timeout
211 ] [ process-was-killed? ] must-fail-with
213 ! This test should kill the sleep after 500ms.
215 <process> { "bash" "-c" "sleep 30& sleep 30" } >>command
216 +new-session+ >>group
217 500 milliseconds >>timeout
219 ] [ process-was-killed? ] must-fail-with