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