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