X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fio%2Fopenpid.t;h=ee4702cb8fc52295ec6d0422cd4759bb9e263e1b;hb=021f53de09926928546378b3552f9240c9241dde;hp=21ec0830d4c60a65bf11032a1eb59e5353d164be;hpb=4d61ec052de5c3a91dc64c80c032c2cbec44d845;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/io/openpid.t b/t/io/openpid.t old mode 100755 new mode 100644 index 21ec083..ee4702c --- a/t/io/openpid.t +++ b/t/io/openpid.t @@ -9,18 +9,24 @@ BEGIN { chdir 't' if -d 't'; - unshift @INC, '../lib'; + @INC = '../lib'; + require './test.pl'; } +if ($^O eq 'dos') { + skip_all("no multitasking"); +} + +plan tests => 10; +watchdog(15); -use FileHandle; use Config; -autoflush STDOUT 1; +$| = 1; $SIG{PIPE} = 'IGNORE'; +$SIG{HUP} = 'IGNORE' if $^O eq 'interix'; -print "1..10\n"; - -$perl = "$^X -I../lib"; +my $perl = which_perl(); +$perl .= qq[ "-I../lib"]; # # commands run 4 perl programs. Two of these programs write a @@ -29,24 +35,21 @@ $perl = "$^X -I../lib"; # the other reader reads one line, waits a few seconds and then # exits to test the waitpid function. # -$cmd1 = qq/$perl -e "use FileHandle; autoflush STDOUT 1; / . - qq/print qq[first process\\n]; sleep 30;"/; -$cmd2 = qq/$perl -e "use FileHandle; autoflush STDOUT 1; / . - qq/print qq[second process\\n]; sleep 30;"/; +$cmd1 = qq/$perl -e "\$|=1; print qq[first process\\n]; sleep 30;"/; +$cmd2 = qq/$perl -e "\$|=1; print qq[second process\\n]; sleep 30;"/; $cmd3 = qq/$perl -e "print <>;"/; # hangs waiting for end of STDIN $cmd4 = qq/$perl -e "print scalar <>;"/; #warn "#$cmd1\n#$cmd2\n#$cmd3\n#$cmd4\n"; # start the processes -$pid1 = open(FH1, "$cmd1 |") or print "not "; -print "ok 1\n"; -$pid2 = open(FH2, "$cmd2 |") or print "not "; -print "ok 2\n"; -$pid3 = open(FH3, "| $cmd3") or print "not "; -print "ok 3\n"; -$pid4 = open(FH4, "| $cmd4") or print "not "; -print "ok 4\n"; +ok( $pid1 = open(FH1, "$cmd1 |"), 'first process started'); +ok( $pid2 = open(FH2, "$cmd2 |"), ' second' ); +{ + no warnings 'once'; + ok( $pid3 = open(FH3, "| $cmd3"), ' third' ); +} +ok( $pid4 = open(FH4, "| $cmd4"), ' fourth' ); print "# pids were $pid1, $pid2, $pid3, $pid4\n"; @@ -55,27 +58,27 @@ $killsig = 1 unless $Config{sig_name} =~ /\bHUP\b/; # get message from first process and kill it chomp($from_pid1 = scalar()); -print "# child1 returned [$from_pid1]\nnot " - unless $from_pid1 eq 'first process'; -print "ok 5\n"; +is( $from_pid1, 'first process', 'message from first process' ); + $kill_cnt = kill $killsig, $pid1; -print "not " unless $kill_cnt == 1; -print "ok 6\n"; +is( $kill_cnt, 1, 'first process killed' ) || + print "# errno == $!\n"; # get message from second process and kill second process and reader process chomp($from_pid2 = scalar()); -print "# child2 returned [$from_pid2]\nnot " - unless $from_pid2 eq 'second process'; -print "ok 7\n"; +is( $from_pid2, 'second process', 'message from second process' ); + $kill_cnt = kill $killsig, $pid2, $pid3; -print "not " unless $kill_cnt == 2; -print "ok 8\n"; +is( $kill_cnt, 2, 'killing procs 2 & 3' ) || + print "# errno == $!\n"; + # send one expected line of text to child process and then wait for it -autoflush FH4 1; -print FH4 "ok 9\n"; +select(FH4); $| = 1; select(STDOUT); + +printf FH4 "ok %d - text sent to fourth process\n", curr_test(); +next_test(); print "# waiting for process $pid4 to exit\n"; $reap_pid = waitpid $pid4, 0; -print "# reaped pid $reap_pid != $pid4\nnot " - unless $reap_pid == $pid4; -print "ok 10\n"; +is( $reap_pid, $pid4, 'fourth process reaped' ); +