1 | $|=1; |
1 | use POSIX (); |
|
|
2 | |
|
|
3 | no warnings; |
|
|
4 | |
2 | BEGIN { |
5 | BEGIN { |
3 | print "1..7\n" |
6 | # check for broken perls |
|
|
7 | if ($^O =~ /mswin32/i) { |
|
|
8 | my $ok; |
|
|
9 | local $SIG{CHLD} = sub { $ok = 1 }; |
|
|
10 | kill 'CHLD', 0; |
|
|
11 | |
|
|
12 | unless ($ok) { |
|
|
13 | print <<EOF; |
|
|
14 | 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. |
|
|
15 | EOF |
|
|
16 | exit 0; |
|
|
17 | } |
|
|
18 | } |
4 | } |
19 | } |
5 | |
20 | |
6 | use AnyEvent; |
21 | use AnyEvent; |
7 | use AnyEvent::Impl::Perl; |
22 | BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} } |
8 | |
23 | |
9 | print STDERR <<EOF; |
24 | $| = 1; print "1..50\n"; |
10 | |
25 | |
11 | If the following test hangs for a long time you either found a bug in |
26 | $AnyEvent::MAX_SIGNAL_LATENCY = 0.2; |
12 | AnyEvent or, more likely, you have a defective perl (most windows perl |
|
|
13 | distros are broken, cygwin perl works). If you do not rely on child |
|
|
14 | handlers you can force the installation of this module and the rest will |
|
|
15 | likely work. Otherwise upgrading to a working perl is recommended. |
|
|
16 | EOF |
|
|
17 | |
27 | |
|
|
28 | for my $it ("", 1, 2, 3, 4) { |
18 | print "ok 1\n"; |
29 | print "ok ${it}1\n"; |
19 | |
30 | |
20 | AnyEvent::detect; # force-load event model |
31 | AnyEvent::detect; # force-load event model |
21 | |
32 | |
22 | my $pid = fork; |
33 | my $pid = fork; |
23 | |
34 | |
24 | defined $pid or die "unable to fork"; |
35 | defined $pid or die "unable to fork"; |
25 | |
36 | |
26 | # work around Tk bug until it has been fixed. |
37 | # work around Tk bug until it has been fixed. |
27 | #my $timer = AnyEvent->timer (after => 2, cb => sub { }); |
38 | #my $timer = AnyEvent->timer (after => 2, cb => sub { }); |
28 | |
39 | |
29 | my $cv = AnyEvent->condvar; |
40 | my $cv = AnyEvent->condvar; |
30 | |
41 | |
31 | unless ($pid) { |
42 | unless ($pid) { |
32 | print "ok 2\n"; |
43 | print "ok ${it}2\n"; |
33 | exit 3; |
44 | POSIX::_exit 3; |
34 | } |
45 | } |
35 | |
46 | |
36 | my $w = AnyEvent->child (pid => $pid, cb => sub { |
47 | my $w = AnyEvent->child (pid => $pid, cb => sub { |
37 | print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n"; |
48 | print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n"; |
38 | print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n"; |
49 | print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n"; |
39 | $cv->broadcast; |
50 | $cv->broadcast; |
40 | }); |
51 | }); |
41 | |
52 | |
42 | $cv->wait; |
53 | $cv->recv; |
43 | |
54 | |
44 | my $pid2 = fork || exit 7; |
55 | my $pid2 = fork || POSIX::_exit 7; |
45 | |
56 | |
46 | my $cv2 = AnyEvent->condvar; |
57 | my $cv2 = AnyEvent->condvar; |
47 | |
58 | |
48 | my $w2 = AnyEvent->child (pid => 0, cb => sub { |
59 | # Glib is the only model that doesn't support pid == 0 |
49 | print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n"; |
60 | my $pid0 = $AnyEvent::MODEL eq "AnyEvent::Impl::Glib" ? $pid2 : 0; |
50 | print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n"; |
|
|
51 | $cv2->broadcast; |
|
|
52 | }); |
|
|
53 | |
61 | |
|
|
62 | my $w2 = AnyEvent->child (pid => $pid0, cb => sub { |
|
|
63 | print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n"; |
|
|
64 | print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n"; |
|
|
65 | $cv2->broadcast; |
|
|
66 | }); |
|
|
67 | |
54 | my $error = AnyEvent->timer (after => 5, cb => sub { |
68 | my $error = AnyEvent->timer (after => 5, cb => sub { |
55 | print <<EOF; |
69 | print <<EOF; |
56 | Bail out! No child exit detected. This is either a bug in AnyEvent or a bug in your Perl (mostly some windows distributions suffer from that): child watchers might not work properly on this platform. You can force installation of this module if you do not rely on child watchers, or you could upgrade to a working version of Perl for your platform.\n"; |
70 | Bail out! No child exit detected. This is either a bug in AnyEvent or a bug in your Perl (mostly some windows distributions suffer from that): child watchers might not work properly on this platform. You can force installation of this module if you do not rely on child watchers, or you could upgrade to a working version of Perl for your platform.\n"; |
57 | EOF |
71 | EOF |
58 | exit 0; |
72 | exit 0; |
59 | }); |
73 | }); |
60 | |
74 | |
61 | $cv2->wait; |
75 | $cv2->recv; |
62 | |
76 | |
63 | print "ok 7\n"; |
77 | print "ok ${it}7\n"; |
|
|
78 | print "ok ${it}8\n"; |
|
|
79 | print "ok ${it}9\n"; |
|
|
80 | print "ok ", $it*10+10, "\n"; |
|
|
81 | } |
64 | |
82 | |
65 | |
83 | |
66 | |
84 | |
67 | |
85 | |