1 |
root |
1.1 |
use POSIX (); |
2 |
|
|
|
3 |
|
|
no warnings; |
4 |
|
|
|
5 |
|
|
BEGIN { |
6 |
|
|
# check for broken perls |
7 |
|
|
if ($^O =~ /mswin32/i) { |
8 |
|
|
my $ok; |
9 |
|
|
local $SIG{CHLD} = sub { $ok = 1 }; |
10 |
|
|
kill 'CHLD', 0; |
11 |
|
|
|
12 |
|
|
unless ($ok) { |
13 |
|
|
print <<EOF; |
14 |
|
|
1..0 # SKIP Your perl interpreter is badly BROKEN. Child watchers will not work, ever. Try upgrading to a newer perl or a working perl (cygwin's perl is known to work). If that is not an option, you should be able to use the remaining functionality of AnyEvent, but child watchers WILL NOT WORK. |
15 |
|
|
EOF |
16 |
|
|
exit 0; |
17 |
|
|
} |
18 |
|
|
} |
19 |
|
|
} |
20 |
|
|
|
21 |
|
|
use AnyEvent; |
22 |
|
|
|
23 |
|
|
BEGIN { $^W = 0 } |
24 |
|
|
BEGIN { $ENV{PERL_ANYEVENT_LOOP_TESTS} or ((print qq{1..0 # SKIP PERL_ANYEVENT_LOOP_TESTS not true\n}), exit 0) } |
25 |
|
|
BEGIN { eval q{use AnyEvent::Impl::UV;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::UV not loadable\n}), exit 0) } |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
$| = 1; print "1..50\n"; |
30 |
|
|
|
31 |
|
|
$AnyEvent::MAX_SIGNAL_LATENCY = 0.2; |
32 |
|
|
|
33 |
|
|
for my $it ("", 1, 2, 3, 4) { |
34 |
|
|
print "ok ${it}1\n"; |
35 |
|
|
|
36 |
|
|
AnyEvent::detect; # force-load event model |
37 |
|
|
|
38 |
|
|
my $pid = fork; |
39 |
|
|
|
40 |
|
|
defined $pid or die "unable to fork"; |
41 |
|
|
|
42 |
|
|
# work around Tk bug until it has been fixed. |
43 |
|
|
#my $timer = AnyEvent->timer (after => 2, cb => sub { }); |
44 |
|
|
|
45 |
|
|
my $cv = AnyEvent->condvar; |
46 |
|
|
|
47 |
|
|
unless ($pid) { |
48 |
|
|
print "ok ${it}2 # child $$\n"; |
49 |
|
|
|
50 |
|
|
# POE hits a race condition when the child dies too quickly |
51 |
|
|
# because it checks for child exit before installing the signal handler. |
52 |
|
|
# seen in version 1.352 - earlier versions had the same bug, but |
53 |
|
|
# polled for child exits regularly, so only caused a delay. |
54 |
|
|
sleep 1 if $AnyEvent::MODEL eq "AnyEvent::Impl::POE"; |
55 |
|
|
|
56 |
|
|
POSIX::_exit 3; |
57 |
|
|
} |
58 |
|
|
my $w = AnyEvent->child (pid => $pid, cb => sub { |
59 |
|
|
print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n"; |
60 |
|
|
print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n"; |
61 |
|
|
$cv->broadcast; |
62 |
|
|
}); |
63 |
|
|
|
64 |
|
|
$cv->recv; |
65 |
|
|
|
66 |
|
|
my $pid2 = fork || do { |
67 |
|
|
sleep 1 if $AnyEvent::MODEL eq "AnyEvent::Impl::POE"; |
68 |
|
|
POSIX::_exit 7; |
69 |
|
|
}; |
70 |
|
|
|
71 |
|
|
my $cv2 = AnyEvent->condvar; |
72 |
|
|
|
73 |
|
|
# Glib is the only model that doesn't support pid == 0 |
74 |
|
|
my $pid0 = $AnyEvent::MODEL eq "AnyEvent::Impl::Glib" ? $pid2 : 0; |
75 |
|
|
|
76 |
|
|
my $w2 = AnyEvent->child (pid => $pid0, cb => sub { |
77 |
|
|
print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n"; |
78 |
|
|
print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n"; |
79 |
|
|
$cv2->broadcast; |
80 |
|
|
}); |
81 |
|
|
|
82 |
|
|
my $error = AnyEvent->timer (after => 5, cb => sub { |
83 |
|
|
print <<EOF; |
84 |
|
|
Bail out! No child exit detected. This is either a bug in AnyEvent or a bug in your Perl (mostly some windows distributions suffer from that): child watchers might not work properly on this platform. You can force installation of this module if you do not rely on child watchers, or you could upgrade to a working version of Perl for your platform.\n"; |
85 |
|
|
EOF |
86 |
|
|
exit 0; |
87 |
|
|
}); |
88 |
|
|
|
89 |
|
|
$cv2->recv; |
90 |
|
|
|
91 |
|
|
print "ok ${it}7\n"; |
92 |
|
|
print "ok ${it}8\n"; |
93 |
|
|
print "ok ${it}9\n"; |
94 |
|
|
print "ok ", $it*10+10, "\n"; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|