1#!./perl 2 3my $perl; 4 5BEGIN { 6 unless(grep /blib/, @INC) { 7 $perl = './perl'; 8 chdir 't' if -d 't'; 9 @INC = '../lib'; 10 } 11 else { 12 $perl = $^X; 13 } 14} 15 16use Config; 17 18BEGIN { 19 if(-d "lib" && -f "TEST") { 20 my $reason; 21 if (! $Config{'d_fork'}) { 22 $reason = 'no fork'; 23 } 24 elsif ($Config{'extensions'} !~ /\bIO\b/) { 25 $reason = 'IO extension unavailable'; 26 } 27 if ($reason) { 28 print "1..0 # Skip: $reason\n"; 29 exit 0; 30 } 31 } 32} 33 34use IO::Pipe; 35 36 37$| = 1; 38print "1..10\n"; 39 40$pipe = new IO::Pipe->reader($perl, '-e', 'print "not ok 1\n"'); 41while (<$pipe>) { 42 s/^not //; 43 print; 44} 45$pipe->close or print "# \$!=$!\nnot "; 46print "ok 2\n"; 47 48$cmd = 'BEGIN{$SIG{ALRM} = sub {print "not ok 4\n"; exit}; alarm 10} s/not //'; 49$pipe = new IO::Pipe->writer($perl, '-pe', $cmd); 50print $pipe "not ok 3\n" ; 51$pipe->close or print "# \$!=$!\nnot "; 52print "ok 4\n"; 53 54# Check if can fork with dynamic extensions (bug in CRT): 55if ($^O eq 'os2' and 56 system "$^X -I../lib -MOpcode -e 'defined fork or die' > /dev/null 2>&1") { 57 print "ok $_ # skipped: broken fork\n" for 5..10; 58 exit 0; 59} 60 61$pipe = new IO::Pipe; 62 63$pid = fork(); 64 65if($pid) 66 { 67 $pipe->writer; 68 print $pipe "Xk 5\n"; 69 print $pipe "oY 6\n"; 70 $pipe->close; 71 wait; 72 } 73elsif(defined $pid) 74 { 75 $pipe->reader; 76 $stdin = bless \*STDIN, "IO::Handle"; 77 $stdin->fdopen($pipe,"r"); 78 exec 'tr', 'YX', 'ko'; 79 } 80else 81 { 82 die "# error = $!"; 83 } 84 85$pipe = new IO::Pipe; 86$pid = fork(); 87 88if($pid) 89 { 90 $pipe->reader; 91 while(<$pipe>) { 92 s/^not //; 93 print; 94 } 95 $pipe->close; 96 wait; 97 } 98elsif(defined $pid) 99 { 100 $pipe->writer; 101 102 $stdout = bless \*STDOUT, "IO::Handle"; 103 $stdout->fdopen($pipe,"w"); 104 print STDOUT "not ok 7\n"; 105 exec 'echo', 'not ok 8'; 106 } 107else 108 { 109 die; 110 } 111 112$pipe = new IO::Pipe; 113$pipe->writer; 114 115$SIG{'PIPE'} = 'broken_pipe'; 116 117sub broken_pipe { 118 print "ok 9\n"; 119} 120 121print $pipe "not ok 9\n"; 122$pipe->close; 123 124sleep 1; 125 126print "ok 10\n"; 127 128