#!./perl
BEGIN {
chdir
't'
if
-d
't'
;
@INC
=
'../lib'
;
require
"./test.pl"
;
}
BEGIN {
unless
($^O =~ /^MSWin/) {
skip_all(
'windows specific test'
);
}
}
skip_all(
"requires compilation with the fork emulation"
)
unless
$Config
{
'd_pseudofork'
};
++$|;
print
"1..4\n"
;
my
(
$sig
) =
grep
/^NUM/,
split
' '
,
$Config
{sig_name};
$sig
||=
"CONT"
;
SKIP:
{
my
$pid
=
fork
;
unless
(
defined
$pid
) {
print
<<EOS;
not ok 1 # fork failed: $!
ok 2 # SKIP
ok 3 # SKIP
ok 4 # SKIP
EOS
last
SKIP;
}
if
(
$pid
) {
print
"ok 1 # pseudo-forked\n"
;
sleep
2;
kill
$sig
,
$pid
;
waitpid
(
$pid
, 0);
}
else
{
my
$signalled
;
$SIG
{
$sig
} =
sub
{
$! = 1;
$^E = 1000;
print
"ok 2 # $sig signal handler called\n"
;
++
$signalled
;
};
$! = 0;
$^E = 0;
my
$count
= 0;
while
(!
$signalled
&& ++
$count
< 10) {
sleep
1;
}
print
"# signaled after $count loops\n"
;
print
$! != 0 ?
"not "
:
""
,
"ok 3 # \$! preserved\n"
;
print
$^E != 0 ?
"not "
:
""
,
"ok 4 # \$^E preserved\n"
or
print
STDERR
"# \$^E = "
, 0+$^E,
"\n"
;
exit
;
}
}