4 require_relative 'envutil'
6 class TestProcess < Test::Unit::TestCase
17 def write_file(filename, content)
18 File.open(filename, "w") {|f|
25 d = Pathname.new(d).realpath.to_s
32 def run_in_child(str) # should be called in a temporary directory
33 write_file("test-script", str)
34 Process.wait spawn(RUBY, "test-script")
38 def test_rlimit_availability
40 Process.getrlimit(nil)
41 rescue NotImplementedError
42 assert_raise(NotImplementedError) { Process.setrlimit }
44 assert_raise(ArgumentError) { Process.setrlimit }
49 Process.getrlimit(nil)
50 rescue NotImplementedError
56 def test_rlimit_nofile
57 return unless rlimit_exist?
59 write_file 's', <<-"End"
60 cur_nofile, max_nofile = Process.getrlimit(Process::RLIMIT_NOFILE)
63 Process.setrlimit(Process::RLIMIT_NOFILE, 0, max_nofile)
74 Process.setrlimit(Process::RLIMIT_NOFILE, cur_nofile, max_nofile)
79 assert_equal(0, $?.to_i, "#{$?}")
84 return unless rlimit_exist?
98 if Process.const_defined? "RLIMIT_#{name}"
99 assert_nothing_raised { Process.getrlimit(name) }
101 assert_raise(ArgumentError) { Process.getrlimit(name) }
104 assert_raise(ArgumentError) { Process.getrlimit(:FOO) }
105 assert_raise(ArgumentError) { Process.getrlimit("FOO") }
108 def test_rlimit_value
109 return unless rlimit_exist?
110 assert_raise(ArgumentError) { Process.setrlimit(:CORE, :FOO) }
111 assert_raise(Errno::EPERM) { Process.setrlimit(:NOFILE, :INFINITY) }
112 assert_raise(Errno::EPERM) { Process.setrlimit(:NOFILE, "INFINITY") }
115 TRUECOMMAND = [RUBY, '-e', '']
117 def test_execopts_opts
118 assert_nothing_raised {
119 Process.wait Process.spawn(*TRUECOMMAND, {})
121 assert_raise(ArgumentError) {
122 Process.wait Process.spawn(*TRUECOMMAND, :foo => 100)
124 assert_raise(ArgumentError) {
125 Process.wait Process.spawn(*TRUECOMMAND, Process => 100)
129 def test_execopts_pgroup
130 assert_nothing_raised { system(*TRUECOMMAND, :pgroup=>false) }
132 io = IO.popen([RUBY, "-e", "print Process.getpgrp"])
133 assert_equal(Process.getpgrp.to_s, io.read)
136 io = IO.popen([RUBY, "-e", "print Process.getpgrp", :pgroup=>true])
137 assert_equal(io.pid.to_s, io.read)
140 assert_raise(ArgumentError) { system(*TRUECOMMAND, :pgroup=>-1) }
141 assert_raise(Errno::EPERM) { Process.wait spawn(*TRUECOMMAND, :pgroup=>2) }
143 io1 = IO.popen([RUBY, "-e", "print Process.getpgrp", :pgroup=>true])
144 io2 = IO.popen([RUBY, "-e", "print Process.getpgrp", :pgroup=>io1.pid])
145 assert_equal(io1.pid.to_s, io1.read)
146 assert_equal(io1.pid.to_s, io2.read)
153 def test_execopts_rlimit
154 return unless rlimit_exist?
155 assert_raise(ArgumentError) { system(*TRUECOMMAND, :rlimit_foo=>0) }
156 assert_raise(ArgumentError) { system(*TRUECOMMAND, :rlimit_NOFILE=>0) }
157 assert_raise(ArgumentError) { system(*TRUECOMMAND, :rlimit_nofile=>[]) }
158 assert_raise(ArgumentError) { system(*TRUECOMMAND, :rlimit_nofile=>[1,2,3]) }
160 max = Process.getrlimit(:CORE).last
163 IO.popen([RUBY, "-e",
164 "p Process.getrlimit(:CORE)", :rlimit_core=>n]) {|io|
165 assert_equal("[#{n}, #{n}]\n", io.read)
169 IO.popen([RUBY, "-e",
170 "p Process.getrlimit(:CORE)", :rlimit_core=>n]) {|io|
171 assert_equal("[#{n}, #{n}]\n", io.read)
175 IO.popen([RUBY, "-e",
176 "p Process.getrlimit(:CORE)", :rlimit_core=>[n]]) {|io|
177 assert_equal("[#{n}, #{n}]", io.read.chomp)
181 IO.popen([RUBY, "-e",
182 "p Process.getrlimit(:CORE)", :rlimit_core=>[m,n]]) {|io|
183 assert_equal("[#{m}, #{n}]", io.read.chomp)
187 IO.popen([RUBY, "-e",
188 "p Process.getrlimit(:CORE)", :rlimit_core=>[m,n]]) {|io|
189 assert_equal("[#{m}, #{n}]", io.read.chomp)
193 IO.popen([RUBY, "-e",
194 "p Process.getrlimit(:CORE), Process.getrlimit(:CPU)",
195 :rlimit_core=>n, :rlimit_cpu=>3600]) {|io|
196 assert_equal("[#{n}, #{n}]\n[3600, 3600]", io.read.chomp)
200 ENVCOMMAND = [RUBY, '-e', 'ENV.each {|k,v| puts "#{k}=#{v}" }']
202 def test_execopts_env
203 assert_raise(ArgumentError) {
204 system({"F=O"=>"BAR"}, *TRUECOMMAND)
208 ENV.each {|k,v| h[k] = nil unless k.upcase == "PATH" }
209 IO.popen([h, RUBY, '-e', 'puts ENV.keys.map{|e|e.upcase}']) {|io|
210 assert_equal("PATH\n", io.read)
213 IO.popen([{"FOO"=>"BAR"}, *ENVCOMMAND]) {|io|
214 assert_match(/^FOO=BAR$/, io.read)
218 system({"fofo"=>"haha"}, *ENVCOMMAND, STDOUT=>"out")
219 assert_match(/^fofo=haha$/, File.read("out").chomp)
223 def test_execopts_unsetenv_others
224 IO.popen([*ENVCOMMAND, :unsetenv_others=>true]) {|io|
225 assert_equal("", io.read)
227 IO.popen([{"A"=>"B"}, *ENVCOMMAND, :unsetenv_others=>true]) {|io|
228 assert_equal("A=B\n", io.read)
232 PWD = [RUBY, '-e', 'puts Dir.pwd']
234 def test_execopts_chdir
236 IO.popen([*PWD, :chdir => d]) {|io|
237 assert_equal(d, io.read.chomp)
239 assert_raise(Errno::ENOENT) {
240 Process.wait Process.spawn(*PWD, :chdir => "d/notexist")
245 UMASK = [RUBY, '-e', 'printf "%04o\n", File.umask']
247 def test_execopts_umask
248 IO.popen([*UMASK, :umask => 0]) {|io|
249 assert_equal("0000", io.read.chomp)
251 IO.popen([*UMASK, :umask => 0777]) {|io|
252 assert_equal("0777", io.read.chomp)
261 r.close unless r.closed?
262 w.close unless w.closed?
275 r.close unless r.closed?
276 w.close unless w.closed?
281 ECHO = lambda {|arg| [RUBY, '-e', "puts #{arg.dump}; STDOUT.flush"] }
282 SORT = [RUBY, '-e', "puts ARGF.readlines.sort"]
283 CAT = [RUBY, '-e', "IO.copy_stream STDIN, STDOUT"]
285 def test_execopts_redirect
287 Process.wait Process.spawn(*ECHO["a"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
288 assert_equal("a", File.read("out").chomp)
289 Process.wait Process.spawn(*ECHO["0"], STDOUT=>["out", File::WRONLY|File::CREAT|File::APPEND, 0644])
290 assert_equal("a\n0\n", File.read("out"))
291 Process.wait Process.spawn(*SORT, STDIN=>["out", File::RDONLY, 0644],
292 STDOUT=>["out2", File::WRONLY|File::CREAT|File::TRUNC, 0644])
293 assert_equal("0\na\n", File.read("out2"))
294 Process.wait Process.spawn(*ECHO["b"], [STDOUT, STDERR]=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
295 assert_equal("b", File.read("out").chomp)
296 # problem occur with valgrind
297 #Process.wait Process.spawn(*ECHO["a"], STDOUT=>:close, STDERR=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
299 #assert(!File.read("out").empty?) # error message such as "-e:1:in `flush': Bad file descriptor (Errno::EBADF)"
300 Process.wait Process.spawn(*ECHO["c"], STDERR=>STDOUT, STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
301 assert_equal("c", File.read("out").chomp)
302 File.open("out", "w") {|f|
303 Process.wait Process.spawn(*ECHO["d"], f=>STDOUT, STDOUT=>f)
304 assert_equal("d", File.read("out").chomp)
306 Process.wait Process.spawn(*ECHO["e"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644],
307 3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT)
308 assert_equal("e", File.read("out").chomp)
309 File.open("out", "w") {|f|
310 h = {STDOUT=>f, f=>STDOUT}
311 3.upto(30) {|i| h[i] = STDOUT if f.fileno != i }
312 Process.wait Process.spawn(*ECHO["f"], h)
313 assert_equal("f", File.read("out").chomp)
315 assert_raise(ArgumentError) {
316 Process.wait Process.spawn(*ECHO["f"], 1=>Process)
318 assert_raise(ArgumentError) {
319 Process.wait Process.spawn(*ECHO["f"], [Process]=>1)
321 assert_raise(ArgumentError) {
322 Process.wait Process.spawn(*ECHO["f"], [1, STDOUT]=>2)
324 assert_raise(ArgumentError) {
325 Process.wait Process.spawn(*ECHO["f"], -1=>2)
327 Process.wait Process.spawn(*ECHO["hhh\nggg\n"], STDOUT=>"out")
328 assert_equal("hhh\nggg\n", File.read("out"))
329 Process.wait Process.spawn(*SORT, STDIN=>"out", STDOUT=>"out2")
330 assert_equal("ggg\nhhh\n", File.read("out2"))
332 assert_raise(Errno::ENOENT) {
333 Process.wait Process.spawn("non-existing-command", (3..60).to_a=>["err", File::WRONLY|File::CREAT])
335 assert_equal("", File.read("err"))
337 system(*ECHO["bb\naa\n"], STDOUT=>["out", "w"])
338 assert_equal("bb\naa\n", File.read("out"))
339 system(*SORT, STDIN=>["out"], STDOUT=>"out2")
340 assert_equal("aa\nbb\n", File.read("out2"))
344 pid = spawn(*SORT, STDIN=>r1, STDOUT=>w2, w1=>:close, r2=>:close)
351 assert_equal("a\nb\nc\n", r2.read)
356 with_pipes(5) {|pipes|
359 ios.length.times {|i| h[ios[i]] = ios[(i-1)%ios.length] }
361 rios = pipes.map {|r, w| r }
362 wios = pipes.map {|r, w| w }
363 child_wfds = wios.map {|w| h2[w].fileno }
364 pid = spawn(RUBY, "-e",
365 "[#{child_wfds.join(',')}].each {|fd| IO.new(fd).puts fd }", h)
367 assert_equal("#{h2[w].fileno}\n", r.gets)
372 with_pipes(5) {|pipes|
375 ios.length.times {|i| h[ios[i]] = ios[(i+1)%ios.length] }
377 rios = pipes.map {|r, w| r }
378 wios = pipes.map {|r, w| w }
379 child_wfds = wios.map {|w| h2[w].fileno }
380 pid = spawn(RUBY, "-e",
381 "[#{child_wfds.join(',')}].each {|fd| IO.new(fd).puts fd }", h)
383 assert_equal("#{h2[w].fileno}\n", r.gets)
389 with_pipes(5) {|pipes|
391 closed_fd = io.fileno
393 assert_raise(Errno::EBADF) { Process.wait spawn(*TRUECOMMAND, closed_fd=>closed_fd) }
396 w.close_on_exec = true
397 pid = spawn(RUBY, "-e", "IO.new(#{w.fileno}).print 'a'", w=>w)
399 assert_equal("a", r.read)
403 system(*ECHO["funya"], :out=>"out")
404 assert_equal("funya\n", File.read("out"))
405 system(RUBY, '-e', 'STDOUT.reopen(STDERR); puts "henya"', :err=>"out")
406 assert_equal("henya\n", File.read("out"))
407 IO.popen([*CAT, :in=>"out"]) {|io|
408 assert_equal("henya\n", io.read)
413 def test_execopts_exec
415 write_file("s", 'exec "echo aaa", STDOUT=>"foo"')
416 pid = spawn RUBY, 's'
418 assert_equal("aaa\n", File.read("foo"))
422 def test_execopts_popen
424 IO.popen("#{RUBY} -e 'puts :foo'") {|io| assert_equal("foo\n", io.read) }
425 assert_raise(Errno::ENOENT) { IO.popen(["echo bar"]) {} } # assuming "echo bar" command not exist.
426 IO.popen(ECHO["baz"]) {|io| assert_equal("baz\n", io.read) }
427 assert_raise(ArgumentError) {
428 IO.popen([*ECHO["qux"], STDOUT=>STDOUT]) {|io| }
430 IO.popen([*ECHO["hoge"], STDERR=>STDOUT]) {|io|
431 assert_equal("hoge\n", io.read)
433 assert_raise(ArgumentError) {
434 IO.popen([*ECHO["fuga"], STDOUT=>"out"]) {|io| }
437 IO.popen([RUBY, '-e', 'IO.new(3).puts("a"); puts "b"', 3=>w]) {|io|
438 assert_equal("b\n", io.read)
441 assert_equal("a\n", r.read)
443 IO.popen([RUBY, '-e', "IO.new(9).puts(:b)",
444 9=>["out2", File::WRONLY|File::CREAT|File::TRUNC]]) {|io|
445 assert_equal("", io.read)
447 assert_equal("b\n", File.read("out2"))
452 return if /freebsd/ =~ RUBY_PLATFORM # this test freeze in FreeBSD
457 assert_equal("fooo\n", io.read)
460 rescue NotImplementedError
463 def test_fd_inheritance
465 system(RUBY, '-e', 'IO.new(ARGV[0].to_i).puts(:ba)', w.fileno.to_s)
467 assert_equal("ba\n", r.read)
470 Process.wait spawn(RUBY, '-e',
471 'IO.new(ARGV[0].to_i).puts("bi") rescue nil',
474 assert_equal("", r.read)
478 write_file("s", <<-"End")
479 exec(#{RUBY.dump}, '-e',
480 'IO.new(ARGV[0].to_i).puts("bu") rescue nil',
481 #{w.fileno.to_s.dump})
483 Process.wait spawn(RUBY, "s", :close_others=>false)
485 assert_equal("bu\n", r.read)
489 io = IO.popen([RUBY, "-e", "STDERR.reopen(STDOUT); IO.new(#{w.fileno}).puts('me')"])
492 assert_equal("", r.read)
493 assert_not_equal("", errmsg)
497 errmsg = `#{RUBY} -e "STDERR.reopen(STDOUT); IO.new(#{w.fileno}).puts(123)"`
499 assert_equal("", r.read)
500 assert_not_equal("", errmsg)
504 def test_execopts_close_others
507 system(RUBY, '-e', 'STDERR.reopen("err", "w"); IO.new(ARGV[0].to_i).puts("ma")', w.fileno.to_s, :close_others=>true)
509 assert_equal("", r.read)
510 assert_not_equal("", File.read("err"))
514 Process.wait spawn(RUBY, '-e', 'STDERR.reopen("err", "w"); IO.new(ARGV[0].to_i).puts("mi")', w.fileno.to_s, :close_others=>true)
516 assert_equal("", r.read)
517 assert_not_equal("", File.read("err"))
521 Process.wait spawn(RUBY, '-e', 'IO.new(ARGV[0].to_i).puts("bi")', w.fileno.to_s, :close_others=>false)
523 assert_equal("bi\n", r.read)
526 write_file("s", <<-"End")
527 exec(#{RUBY.dump}, '-e',
528 'STDERR.reopen("err", "w"); IO.new(ARGV[0].to_i).puts("mu")',
529 #{w.fileno.to_s.dump},
532 Process.wait spawn(RUBY, "s", :close_others=>false)
534 assert_equal("", r.read)
535 assert_not_equal("", File.read("err"))
539 io = IO.popen([RUBY, "-e", "STDERR.reopen(STDOUT); IO.new(#{w.fileno}).puts('me')", :close_others=>true])
542 assert_equal("", r.read)
543 assert_not_equal("", errmsg)
547 io = IO.popen([RUBY, "-e", "STDERR.reopen(STDOUT); IO.new(#{w.fileno}).puts('mo')", :close_others=>false])
550 assert_equal("mo\n", r.read)
551 assert_equal("", errmsg)
555 io = IO.popen([RUBY, "-e", "STDERR.reopen(STDOUT); IO.new(#{w.fileno}).puts('mo')", :close_others=>nil])
558 assert_equal("mo\n", r.read)
559 assert_equal("", errmsg)
566 def test_execopts_redirect_self
570 r.close_on_exec = true
571 IO.popen([RUBY, "-e", "print IO.new(#{r.fileno}).read", r.fileno=>r.fileno, :close_others=>false]) {|io|
572 assert_equal("haha\n", io.read)
577 def test_execopts_duplex_io
578 IO.popen("#{RUBY} -e ''", "r+") {|duplex|
579 assert_raise(ArgumentError) { system("#{RUBY} -e ''", duplex=>STDOUT) }
580 assert_raise(ArgumentError) { system("#{RUBY} -e ''", STDOUT=>duplex) }
584 def test_execopts_modification
586 Process.wait spawn(*TRUECOMMAND, h)
590 system(*TRUECOMMAND, h)
594 io = IO.popen([*TRUECOMMAND, h])
599 def test_system_noshell
600 str = "echo non existing command name which contains spaces"
601 assert_nil(system([str, str]))
604 def test_spawn_noshell
605 str = "echo non existing command name which contains spaces"
606 assert_raise(Errno::ENOENT) { spawn([str, str]) }
609 def test_popen_noshell
610 str = "echo non existing command name which contains spaces"
611 assert_raise(Errno::ENOENT) { IO.popen([str, str]) }
614 def test_exec_noshell
617 write_file("s", <<-"End")
618 str = "echo non existing command name which contains spaces"
619 w = IO.new(#{w.fileno})
625 w.write "Errno::ENOENT success"
628 system(RUBY, "s", :close_others=>false)
630 assert_equal("Errno::ENOENT success", r.read)
635 def test_system_wordsplit
637 write_file("script", <<-'End')
638 File.open("result", "w") {|t| t << "haha pid=#{$$} ppid=#{Process.ppid}" }
641 str = "#{RUBY} script"
644 assert_equal(false, ret)
645 assert(status.exited?)
646 assert_equal(5, status.exitstatus)
647 assert_equal("haha pid=#{status.pid} ppid=#{$$}", File.read("result"))
651 def test_spawn_wordsplit
653 write_file("script", <<-'End')
654 File.open("result", "w") {|t| t << "hihi pid=#{$$} ppid=#{Process.ppid}" }
657 str = "#{RUBY} script"
661 assert_equal(pid, status.pid)
662 assert(status.exited?)
663 assert_equal(6, status.exitstatus)
664 assert_equal("hihi pid=#{status.pid} ppid=#{$$}", File.read("result"))
668 def test_popen_wordsplit
670 write_file("script", <<-'End')
671 print "fufu pid=#{$$} ppid=#{Process.ppid}"
674 str = "#{RUBY} script"
680 assert_equal(pid, status.pid)
681 assert(status.exited?)
682 assert_equal(7, status.exitstatus)
683 assert_equal("fufu pid=#{status.pid} ppid=#{$$}", result)
687 def test_exec_wordsplit
689 write_file("script", <<-'End')
690 File.open("result", "w") {|t|
691 if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
692 t << "hehe ppid=#{Process.ppid}"
694 t << "hehe pid=#{$$} ppid=#{Process.ppid}"
699 write_file("s", <<-"End")
701 exec "\#{ruby} script"
703 pid = spawn(RUBY, "s")
706 assert_equal(pid, status.pid)
707 assert(status.exited?)
708 assert_equal(6, status.exitstatus)
709 if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
710 expected = "hehe ppid=#{status.pid}"
712 expected = "hehe pid=#{status.pid} ppid=#{$$}"
714 assert_equal(expected, File.read("result"))
718 def test_system_shell
720 write_file("script1", <<-'End')
721 File.open("result1", "w") {|t| t << "taka pid=#{$$} ppid=#{Process.ppid}" }
724 write_file("script2", <<-'End')
725 File.open("result2", "w") {|t| t << "taki pid=#{$$} ppid=#{Process.ppid}" }
728 ret = system("#{RUBY} script1 || #{RUBY} script2")
730 assert_equal(false, ret)
731 assert(status.exited?)
732 result1 = File.read("result1")
733 result2 = File.read("result2")
734 assert_match(/\Ataka pid=\d+ ppid=\d+\z/, result1)
735 assert_match(/\Ataki pid=\d+ ppid=\d+\z/, result2)
736 assert_not_equal(result1[/\d+/].to_i, status.pid)
742 write_file("script1", <<-'End')
743 File.open("result1", "w") {|t| t << "taku pid=#{$$} ppid=#{Process.ppid}" }
746 write_file("script2", <<-'End')
747 File.open("result2", "w") {|t| t << "take pid=#{$$} ppid=#{Process.ppid}" }
750 pid = spawn("#{RUBY} script1 || #{RUBY} script2")
753 assert(status.exited?)
754 assert(!status.success?)
755 result1 = File.read("result1")
756 result2 = File.read("result2")
757 assert_match(/\Ataku pid=\d+ ppid=\d+\z/, result1)
758 assert_match(/\Atake pid=\d+ ppid=\d+\z/, result2)
759 assert_not_equal(result1[/\d+/].to_i, status.pid)
765 write_file("script1", <<-'End')
766 puts "tako pid=#{$$} ppid=#{Process.ppid}"
769 write_file("script2", <<-'End')
770 puts "tika pid=#{$$} ppid=#{Process.ppid}"
773 io = IO.popen("#{RUBY} script1 || #{RUBY} script2")
777 assert(status.exited?)
778 assert(!status.success?)
779 assert_match(/\Atako pid=\d+ ppid=\d+\ntika pid=\d+ ppid=\d+\n\z/, result)
780 assert_not_equal(result[/\d+/].to_i, status.pid)
786 write_file("script1", <<-'End')
787 File.open("result1", "w") {|t| t << "tiki pid=#{$$} ppid=#{Process.ppid}" }
790 write_file("script2", <<-'End')
791 File.open("result2", "w") {|t| t << "tiku pid=#{$$} ppid=#{Process.ppid}" }
794 write_file("s", <<-"End")
796 exec("\#{ruby} script1 || \#{ruby} script2")
798 pid = spawn RUBY, "s"
801 assert(status.exited?)
802 assert(!status.success?)
803 result1 = File.read("result1")
804 result2 = File.read("result2")
805 assert_match(/\Atiki pid=\d+ ppid=\d+\z/, result1)
806 assert_match(/\Atiku pid=\d+ ppid=\d+\z/, result2)
807 assert_not_equal(result1[/\d+/].to_i, status.pid)
813 assert_equal(false, system([RUBY, "asdfg"], "-e", "exit false"))
814 assert_equal(true, system([RUBY, "zxcvb"], "-e", "exit true"))
816 Process.wait spawn([RUBY, "poiu"], "-e", "exit 4")
817 assert_equal(4, $?.exitstatus)
819 assert_equal("1", IO.popen([[RUBY, "qwerty"], "-e", "print 1"]).read)
822 write_file("s", <<-"End")
823 exec([#{RUBY.dump}, "lkjh"], "-e", "exit 5")
825 pid = spawn RUBY, "s"
827 assert_equal(5, $?.exitstatus)
831 def with_stdin(filename)
836 STDIN.reopen(filename)
849 open("t", "w") {|f| f.print "exit true" }
850 open("f", "w") {|f| f.print "exit false" }
852 with_stdin("t") { assert_equal(true, system([RUBY, "qaz"])) }
853 with_stdin("f") { assert_equal(false, system([RUBY, "wsx"])) }
855 with_stdin("t") { Process.wait spawn([RUBY, "edc"]) }
857 with_stdin("f") { Process.wait spawn([RUBY, "rfv"]) }
860 with_stdin("t") { IO.popen([[RUBY, "tgb"]]) {|io| assert_equal("", io.read) } }
862 with_stdin("f") { IO.popen([[RUBY, "yhn"]]) {|io| assert_equal("", io.read) } }
865 status = run_in_child "STDIN.reopen('t'); exec([#{RUBY.dump}, 'ujm'])"
866 assert(status.success?)
867 status = run_in_child "STDIN.reopen('f'); exec([#{RUBY.dump}, 'ik,'])"
868 assert(!status.success?)
874 s = run_in_child("exit 1")
875 assert_equal("#<Process::Status: pid #{ s.pid } exit #{ s.exitstatus }>", s.inspect)
878 assert_equal(s, s.to_i)
880 assert_equal(s.to_i & 0x55555555, s & 0x55555555)
881 assert_equal(s.to_i >> 1, s >> 1)
882 assert_equal(false, s.stopped?)
883 assert_equal(nil, s.stopsig)
888 return unless Process.respond_to?(:kill)
889 return unless Signal.list.include?("QUIT")
892 write_file("foo", "sleep 30")
893 pid = spawn(RUBY, "foo")
894 Thread.new { sleep 1; Process.kill(:SIGQUIT, pid) }
898 [["#<Process::Status: pid #{ s.pid } SIGQUIT (signal #{ s.termsig })>",
899 "#<Process::Status: pid #{ s.pid } SIGQUIT (signal #{ s.termsig }) (core dumped)>"],
902 assert_equal(false, s.exited?)
903 assert_equal(nil, s.success?)
907 def test_wait_without_arg
909 write_file("foo", "sleep 0.1")
910 pid = spawn(RUBY, "foo")
911 assert_equal(pid, Process.wait)
917 write_file("foo", "sleep 0.1")
918 pid = spawn(RUBY, "foo")
919 assert_equal([pid, 0], Process.wait2)
925 write_file("foo", "sleep 0.1")
926 ps = (0...3).map { spawn(RUBY, "foo") }.sort
927 ss = Process.waitall.sort
928 ps.zip(ss) do |p1, (p2, s)|
930 assert_equal(p1, s.pid)
937 s = run_in_child("abort")
938 assert_not_equal(0, s.exitstatus)
943 assert_raise(ArgumentError) { sleep(1, 1) }
947 assert_kind_of(Integer, Process.getpgid(Process.ppid))
948 rescue NotImplementedError
952 assert_kind_of(Integer, Process.getpriority(Process::PRIO_PROCESS, $$))
953 rescue NameError, NotImplementedError
957 if defined? Process::PRIO_USER
958 assert_nothing_raised do
959 pr = Process.getpriority(Process::PRIO_PROCESS, $$)
960 Process.setpriority(Process::PRIO_PROCESS, $$, pr)
966 assert_kind_of(Integer, Process.uid)
971 assert_instance_of(Array, gs)
972 gs.each {|g| assert_kind_of(Integer, g) }
973 rescue NotImplementedError
977 assert_kind_of(Integer, Process.maxgroups)
981 assert_kind_of(Integer, Process.egid)
984 def test_uid_re_exchangeable_p
985 r = Process::UID.re_exchangeable?
986 assert(true == r || false == r)
989 def test_gid_re_exchangeable_p
990 r = Process::GID.re_exchangeable?
991 assert(true == r || false == r)
994 def test_uid_sid_available?
995 r = Process::UID.sid_available?
996 assert(true == r || false == r)
999 def test_gid_sid_available?
1000 r = Process::GID.sid_available?
1001 assert(true == r || false == r)