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