1 |
BEGIN { |
2 |
# check for broken perls |
3 |
if ($^O =~ /mswin32/i) { |
4 |
my $ok; |
5 |
local $SIG{CHLD} = sub { $ok = 1 }; |
6 |
kill 'CHLD', 0; |
7 |
|
8 |
unless ($ok) { |
9 |
print <<EOF; |
10 |
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. |
11 |
EOF |
12 |
exit 0; |
13 |
} |
14 |
} |
15 |
} |
16 |
|
17 |
$^W = 0; # 5.8.6 bugs |
18 |
|
19 |
use AnyEvent; |
20 |
use AnyEvent::Util; |
21 |
BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} } |
22 |
|
23 |
$| = 1; print "1..15\n"; |
24 |
|
25 |
print "ok 1\n"; |
26 |
|
27 |
my ($a, $b) = AnyEvent::Util::portable_socketpair; |
28 |
|
29 |
# I/O write |
30 |
{ |
31 |
my $cv = AE::cv; |
32 |
my $wt = AE::timer 1, 0, $cv; |
33 |
my $s = 0; |
34 |
|
35 |
$cv->begin; my $wa = AE::io $a, 1, sub { $cv->end; $s |= 1 }; |
36 |
$cv->begin; my $wb = AE::io $a, 1, sub { $cv->end; $s |= 2 }; |
37 |
|
38 |
$cv->recv; |
39 |
|
40 |
print $s == 3 ? "" : "not ", "ok 2 # $s\n"; |
41 |
} |
42 |
|
43 |
# I/O read |
44 |
{ |
45 |
my $cv = AE::cv; |
46 |
my $wt = AE::timer 0.01, 0, $cv; |
47 |
my $s = 0; |
48 |
|
49 |
my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 }; |
50 |
my $wb = AE::io $a, 0, sub { $cv->end; $s |= 2 }; |
51 |
|
52 |
$cv->recv; |
53 |
|
54 |
print $s == 0 ? "" : "not ", "ok 3 # $s\n"; |
55 |
|
56 |
syswrite $b, "x"; |
57 |
|
58 |
$cv = AE::cv; |
59 |
$wt = AE::timer 1, 0, $cv; |
60 |
|
61 |
$s = 0; |
62 |
$cv->begin; |
63 |
$cv->begin; |
64 |
$cv->recv; |
65 |
|
66 |
print $s == 3 ? "" : "not ", "ok 4 # $s\n"; |
67 |
|
68 |
sysread $a, my $dummy, 1; |
69 |
|
70 |
$cv = AE::cv; |
71 |
$wt = AE::timer 0.01, 0, $cv; |
72 |
|
73 |
$s = 0; |
74 |
$cv->recv; |
75 |
|
76 |
print $s == 0 ? "" : "not ", "ok 5 # $s\n"; |
77 |
} |
78 |
|
79 |
# signal |
80 |
{ |
81 |
my $cv = AE::cv; |
82 |
my $wt = AE::timer 0.01, 0, $cv; |
83 |
my $s = 0; |
84 |
|
85 |
$cv->begin; my $wa = AE::signal INT => sub { $cv->end; $s |= 1 }; |
86 |
$cv->begin; my $wb = AE::signal INT => sub { $cv->end; $s |= 2 }; |
87 |
|
88 |
$cv->recv; |
89 |
|
90 |
print $s == 0 ? "" : "not ", "ok 6 # $s\n"; |
91 |
|
92 |
kill INT => $$; |
93 |
|
94 |
$cv = AE::cv; |
95 |
$wt = AE::timer 0.01, 0, $cv; |
96 |
|
97 |
$s = 0; |
98 |
$cv->recv; |
99 |
|
100 |
print $s == 3 ? "" : "not ", "ok 7 # $s\n"; |
101 |
|
102 |
$cv = AE::cv; |
103 |
$wt = AE::timer 0.01, 0, $cv; |
104 |
|
105 |
$s = 0; |
106 |
$cv->recv; |
107 |
|
108 |
print $s == 0 ? "" : "not ", "ok 8 # $s\n"; |
109 |
} |
110 |
|
111 |
$AnyEvent::MAX_SIGNAL_LATENCY = 0.2; |
112 |
|
113 |
# child |
114 |
{ |
115 |
my $cv = AE::cv; |
116 |
my $wt = AE::timer 0.01, 0, $cv; |
117 |
my $s = 0; |
118 |
|
119 |
my $pid = fork; |
120 |
|
121 |
unless ($pid) { |
122 |
sleep 2; |
123 |
exit 1; |
124 |
} |
125 |
|
126 |
my ($apid, $bpid, $astatus, $bstatus); |
127 |
|
128 |
$cv->begin; my $wa = AE::child $pid, sub { ($apid, $astatus) = @_; $cv->end; $s |= 1 }; |
129 |
$cv->begin; my $wb = AE::child $pid, sub { ($bpid, $bstatus) = @_; $cv->end; $s |= 2 }; |
130 |
|
131 |
$cv->recv; |
132 |
|
133 |
print $s == 0 ? "" : "not ", "ok 9 # $s\n"; |
134 |
|
135 |
kill 9, $pid; |
136 |
|
137 |
$cv = AE::cv; |
138 |
$wt = AE::timer 0.2, 0, $cv; # cygwin needs ages for this |
139 |
|
140 |
$s = 0; |
141 |
$cv->recv; |
142 |
|
143 |
print $s == 3 ? "" : "not ", "ok 10 # $s\n"; |
144 |
print $apid == $pid && $bpid == $pid ? "" : "not ", "ok 11 # $apid == $bpid == $pid\n"; |
145 |
print $astatus == 9 && $bstatus == 9 ? "" : "not ", "ok 12 # $astatus == $bstatus == 9\n"; |
146 |
|
147 |
$cv = AE::cv; |
148 |
$wt = AE::timer 0.01, 0, $cv; |
149 |
|
150 |
$s = 0; |
151 |
$cv->recv; |
152 |
|
153 |
print $s == 0 ? "" : "not ", "ok 13 # $s\n"; |
154 |
} |
155 |
|
156 |
# timers (don't laugh, some event loops are more broken...) |
157 |
{ |
158 |
my $cv = AE::cv; |
159 |
my $wt = AE::timer 1, 0, $cv; |
160 |
my $s = 0; |
161 |
|
162 |
$cv->begin; my $wa = AE::timer 0 , 0, sub { $cv->end; $s |= 1 }; |
163 |
$cv->begin; my $wb = AE::timer 0 , 0, sub { $cv->end; $s |= 2 }; |
164 |
$cv->begin; my $wc = AE::timer 0.01, 0, sub { $cv->end; $s |= 4 }; |
165 |
|
166 |
$cv->recv; |
167 |
|
168 |
print $s == 7 ? "" : "not ", "ok 14 # $s\n"; |
169 |
} |
170 |
|
171 |
print "ok 15\n"; |
172 |
|
173 |
exit 0; |
174 |
|