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