| 
									
										
										
										
											2019-09-28 00:13:51 -04:00
										 |  |  | USING: accessors calendar concurrency.promises destructors io | 
					
						
							|  |  |  | io.backend.unix io.directories io.encodings.ascii | 
					
						
							|  |  |  | io.encodings.binary io.encodings.utf8 io.files io.launcher | 
					
						
							|  |  |  | io.streams.duplex io.timeouts kernel libc locals math namespaces | 
					
						
							|  |  |  | sequences threads tools.test unix.process unix.signals ;
 | 
					
						
							| 
									
										
										
										
											2008-12-14 21:03:00 -05:00
										 |  |  | IN: io.launcher.unix.tests | 
					
						
							| 
									
										
										
										
											2012-09-22 13:30:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 00:08:03 -04:00
										 |  |  | [ | 
					
						
							| 
									
										
										
										
											2016-04-04 13:32:42 -04:00
										 |  |  |     { } [ { "touch" "launcher-test-1" } try-process ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { t } [ "launcher-test-1" exists? ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { } [ | 
					
						
							| 
									
										
										
										
											2016-07-10 23:28:46 -04:00
										 |  |  |         "launcher-test-1" ?delete-file | 
					
						
							| 
									
										
										
										
											2016-04-04 13:32:42 -04:00
										 |  |  |     ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { } [ | 
					
						
							|  |  |  |         <process> | 
					
						
							|  |  |  |             "echo Hello" >>command | 
					
						
							|  |  |  |             "launcher-test-1" >>stdout | 
					
						
							|  |  |  |         try-process | 
					
						
							|  |  |  |     ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { "Hello\n" } [ | 
					
						
							|  |  |  |         { "cat" "launcher-test-1" } | 
					
						
							|  |  |  |         ascii <process-reader> stream-contents
 | 
					
						
							|  |  |  |     ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { } [ | 
					
						
							| 
									
										
										
										
											2016-07-10 23:28:46 -04:00
										 |  |  |         "launcher-test-1" ?delete-file | 
					
						
							| 
									
										
										
										
											2016-04-04 13:32:42 -04:00
										 |  |  |     ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { } [ | 
					
						
							|  |  |  |         <process> | 
					
						
							|  |  |  |             "cat" >>command | 
					
						
							|  |  |  |             +closed+ >>stdin | 
					
						
							|  |  |  |             "launcher-test-1" >>stdout | 
					
						
							|  |  |  |         try-process | 
					
						
							|  |  |  |     ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { "" } [ | 
					
						
							|  |  |  |         { "cat" "launcher-test-1" } | 
					
						
							|  |  |  |         ascii <process-reader> stream-contents
 | 
					
						
							|  |  |  |     ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { } [ | 
					
						
							|  |  |  |         2 [ | 
					
						
							|  |  |  |             "launcher-test-1" binary <file-appender> [ | 
					
						
							| 
									
										
										
										
											2016-04-01 00:08:03 -04:00
										 |  |  |                 <process> | 
					
						
							| 
									
										
										
										
											2016-04-04 13:32:42 -04:00
										 |  |  |                     swap >>stdout | 
					
						
							|  |  |  |                     "echo Hello" >>command | 
					
						
							| 
									
										
										
										
											2016-04-01 00:08:03 -04:00
										 |  |  |                 try-process | 
					
						
							| 
									
										
										
										
											2016-04-04 13:32:42 -04:00
										 |  |  |             ] with-disposal | 
					
						
							|  |  |  |         ] times
 | 
					
						
							|  |  |  |     ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { "Hello\nHello\n" } [ | 
					
						
							|  |  |  |         { "cat" "launcher-test-1" } | 
					
						
							|  |  |  |         ascii <process-reader> stream-contents
 | 
					
						
							|  |  |  |     ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { "hi\n" } [ | 
					
						
							|  |  |  |         <process> | 
					
						
							|  |  |  |             { "echo" "hi" } >>command | 
					
						
							|  |  |  |             "launcher-test-2" >>stdout | 
					
						
							|  |  |  |         try-process | 
					
						
							|  |  |  |         "launcher-test-2" utf8 file-contents | 
					
						
							|  |  |  |     ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     { "hi\nhi\n" } [ | 
					
						
							|  |  |  |         2 [ | 
					
						
							|  |  |  |             <process> | 
					
						
							|  |  |  |                 "echo hi" >>command | 
					
						
							|  |  |  |                 "launcher-test-3" <appender> >>stdout | 
					
						
							|  |  |  |             try-process | 
					
						
							|  |  |  |         ] times
 | 
					
						
							|  |  |  |         "launcher-test-3" utf8 file-contents | 
					
						
							|  |  |  |     ] unit-test | 
					
						
							| 
									
										
										
										
											2016-04-01 00:08:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-04 13:32:42 -04:00
										 |  |  | ] with-test-directory | 
					
						
							| 
									
										
										
										
											2008-03-06 21:44:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { t } [ | 
					
						
							| 
									
										
										
										
											2008-03-06 21:44:52 -05:00
										 |  |  |     <process> | 
					
						
							|  |  |  |         "env" >>command | 
					
						
							|  |  |  |         { { "A" "B" } } >>environment | 
					
						
							| 
									
										
										
										
											2009-05-01 17:38:04 -04:00
										 |  |  |     ascii <process-reader> stream-lines
 | 
					
						
							| 
									
										
										
										
											2008-03-06 21:44:52 -05:00
										 |  |  |     "A=B" swap member?
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { { "A=B" } } [ | 
					
						
							| 
									
										
										
										
											2008-03-06 21:44:52 -05:00
										 |  |  |     <process> | 
					
						
							|  |  |  |         "env" >>command | 
					
						
							|  |  |  |         { { "A" "B" } } >>environment | 
					
						
							|  |  |  |         +replace-environment+ >>environment-mode | 
					
						
							| 
									
										
										
										
											2009-05-01 17:38:04 -04:00
										 |  |  |     ascii <process-reader> stream-lines
 | 
					
						
							| 
									
										
										
										
											2008-03-06 21:44:52 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-03-26 23:39:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 00:08:03 -04:00
										 |  |  | { t } [ | 
					
						
							|  |  |  |     "ls" utf8 <process-stream> stream-contents >boolean
 | 
					
						
							| 
									
										
										
										
											2008-05-05 20:12:22 -04:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-05-14 04:55:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { "Hello world.\n" } [ | 
					
						
							| 
									
										
										
										
											2008-07-24 22:47:09 -04:00
										 |  |  |     "cat" utf8 <process-stream> [ | 
					
						
							|  |  |  |         "Hello world.\n" write
 | 
					
						
							|  |  |  |         output-stream get dispose | 
					
						
							| 
									
										
										
										
											2009-05-01 17:38:04 -04:00
										 |  |  |         input-stream get stream-contents
 | 
					
						
							| 
									
										
										
										
											2008-07-24 22:47:09 -04:00
										 |  |  |     ] with-stream | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2008-12-10 18:30:07 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-29 00:52:24 -04:00
										 |  |  | ! Test process timeouts | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     <process> | 
					
						
							|  |  |  |         { "sleep" "10" } >>command | 
					
						
							|  |  |  |         1 seconds >>timeout | 
					
						
							|  |  |  |     run-process | 
					
						
							|  |  |  | ] [ process-was-killed? ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     <process> | 
					
						
							|  |  |  |         { "sleep" "10" } >>command | 
					
						
							|  |  |  |         1 seconds >>timeout | 
					
						
							|  |  |  |     try-process | 
					
						
							|  |  |  | ] [ process-was-killed? ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     <process> | 
					
						
							|  |  |  |         { "sleep" "10" } >>command | 
					
						
							|  |  |  |         1 seconds >>timeout | 
					
						
							|  |  |  |     try-output-process | 
					
						
							|  |  |  | ] [ io-timeout? ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-10 18:30:07 -05:00
										 |  |  | ! Killed processes were exiting with code 0 on FreeBSD | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { f } [ | 
					
						
							| 
									
										
										
										
											2015-07-02 13:34:01 -04:00
										 |  |  |     [let | 
					
						
							| 
									
										
										
										
											2009-10-27 22:50:31 -04:00
										 |  |  |         <promise> :> p | 
					
						
							|  |  |  |         <promise> :> s | 
					
						
							| 
									
										
										
										
											2009-11-22 14:49:10 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-27 22:50:31 -04:00
										 |  |  |         [ | 
					
						
							|  |  |  |             "sleep 1000" run-detached | 
					
						
							|  |  |  |             [ p fulfill ] [ wait-for-process s fulfill ] bi
 | 
					
						
							|  |  |  |         ] in-thread | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-30 13:04:09 -05:00
										 |  |  |         p 1 seconds ?promise-timeout (kill-process) | 
					
						
							| 
									
										
										
										
											2010-05-02 20:06:45 -04:00
										 |  |  |         s 3 seconds ?promise-timeout 0 =
 | 
					
						
							| 
									
										
										
										
											2015-07-02 16:37:42 -04:00
										 |  |  |     ] | 
					
						
							| 
									
										
										
										
											2008-12-10 18:30:07 -05:00
										 |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2010-09-03 01:11:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Make sure that subprocesses don't inherit our signal mask | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! First, ensure that the Factor VM ignores SIGPIPE | 
					
						
							|  |  |  | : send-sigpipe ( pid -- )
 | 
					
						
							|  |  |  |     "SIGPIPE" signal-names index 1 +
 | 
					
						
							|  |  |  |     kill io-error ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { } [ (current-process) send-sigpipe ] unit-test | 
					
						
							| 
									
										
										
										
											2010-09-03 01:11:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Spawn a process | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { T{ signal f 13 } } [ | 
					
						
							| 
									
										
										
										
											2010-09-03 01:11:45 -04:00
										 |  |  |     "sleep 1000" run-detached | 
					
						
							| 
									
										
										
										
											2010-09-04 15:00:23 -04:00
										 |  |  |     1 seconds sleep | 
					
						
							| 
									
										
										
										
											2010-09-03 01:11:45 -04:00
										 |  |  |     [ handle>> send-sigpipe ] | 
					
						
							|  |  |  |     [ 2 seconds swap set-timeout ] | 
					
						
							|  |  |  |     [ wait-for-process ] | 
					
						
							|  |  |  |     tri
 | 
					
						
							|  |  |  | ] unit-test | 
					
						
							| 
									
										
										
										
											2011-10-29 05:47:10 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Test priority | 
					
						
							| 
									
										
										
										
											2015-07-03 12:39:59 -04:00
										 |  |  | { 0 } [ | 
					
						
							| 
									
										
										
										
											2011-10-29 05:47:10 -04:00
										 |  |  |     <process> | 
					
						
							|  |  |  |         { "bash" "-c" "sleep 2&" } >>command | 
					
						
							|  |  |  |         +low-priority+ >>priority | 
					
						
							|  |  |  |     run-process status>> | 
					
						
							|  |  |  | ] unit-test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! Check that processes launched with the group option kill their children (or not) | 
					
						
							|  |  |  | ! This test should leave two sleeps running for 30 seconds. | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     <process> { "bash" "-c" "sleep 30& sleep 30" } >>command | 
					
						
							|  |  |  |         +same-group+ >>group | 
					
						
							|  |  |  |         500 milliseconds >>timeout | 
					
						
							|  |  |  |     run-process | 
					
						
							|  |  |  | ] [ process-was-killed? ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! This test should kill the sleep after 500ms. | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     <process> { "bash" "-c" "sleep 30& sleep 30" } >>command | 
					
						
							|  |  |  |         +new-group+ >>group | 
					
						
							|  |  |  |         500 milliseconds >>timeout | 
					
						
							|  |  |  |     run-process | 
					
						
							|  |  |  | ] [ process-was-killed? ] must-fail-with | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! This test should kill the sleep after 500ms. | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |     <process> { "bash" "-c" "sleep 30& sleep 30" } >>command | 
					
						
							|  |  |  |         +new-session+ >>group | 
					
						
							|  |  |  |         500 milliseconds >>timeout | 
					
						
							|  |  |  |     run-process | 
					
						
							|  |  |  | ] [ process-was-killed? ] must-fail-with |