ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/69_ev_03_child.t
(Generate patch)

Comparing AnyEvent/t/69_ev_03_child.t (file contents):
Revision 1.1 by root, Thu Oct 2 08:43:58 2008 UTC vs.
Revision 1.12 by root, Sat Oct 1 22:39:30 2011 UTC

1$|=1; 1use POSIX ();
2BEGIN { unless (eval "require EV") { print "1..0 # skip because EV isn't installed"; exit } } 2
3no warnings;
3 4
4BEGIN { 5BEGIN {
5 # check for broken perls 6 # check for broken perls
6 if ($^O =~ /mswin32/i) { 7 if ($^O =~ /mswin32/i) {
7 my $ok; 8 my $ok;
8 local $SIG{CHLD} = sub { $ok = 1 }; 9 local $SIG{CHLD} = sub { $ok = 1 };
9 kill 'CHLD', 0; 10 kill 'CHLD', 0;
10 11
11 unless ($ok) { 12 unless ($ok) {
12 print <<EOF; 13 print <<EOF;
131..0 # 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. 141..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.
14EOF 15EOF
15 exit 0; 16 exit 0;
16 } 17 }
17 } 18 }
18} 19}
19 20
20BEGIN { 21use AnyEvent;
21 print "1..7\n"
22}
23 22
24use AnyEvent; 23 BEGIN { $ENV{PERL_ANYEVENT_LOOP_TESTS} or ((print qq{1..0 # SKIP PERL_ANYEVENT_LOOP_TESTS not true\n}), exit 0) }
25use AnyEvent::Impl::EV; 24 BEGIN { eval q{use AnyEvent::Impl::EV;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::EV not loadable\n}), exit 0) }
25
26
26 27
27print "ok 1\n"; 28$| = 1; print "1..50\n";
28 29
29AnyEvent::detect; # force-load event model 30$AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
30 31
31my $pid = fork; 32for my $it ("", 1, 2, 3, 4) {
33 print "ok ${it}1\n";
32 34
33defined $pid or die "unable to fork"; 35 AnyEvent::detect; # force-load event model
34 36
35# work around Tk bug until it has been fixed. 37 my $pid = fork;
36#my $timer = AnyEvent->timer (after => 2, cb => sub { });
37 38
38my $cv = AnyEvent->condvar; 39 defined $pid or die "unable to fork";
39 40
40unless ($pid) { 41 # work around Tk bug until it has been fixed.
41 print "ok 2\n"; 42 #my $timer = AnyEvent->timer (after => 2, cb => sub { });
42 exit 3;
43}
44 43
45my $w = AnyEvent->child (pid => $pid, cb => sub { 44 my $cv = AnyEvent->condvar;
46 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n";
47 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n";
48 $cv->broadcast;
49});
50 45
51$cv->wait; 46 unless ($pid) {
47 print "ok ${it}2 # child $$\n";
48 POSIX::_exit 3;
49 }
50 my $w = AnyEvent->child (pid => $pid, cb => sub {
51 print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";
52 print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n";
53 $cv->broadcast;
54 });
52 55
53my $pid2 = fork || exit 7; 56 $cv->recv;
54 57
55my $cv2 = AnyEvent->condvar; 58 my $pid2 = fork || POSIX::_exit 7;
56 59
57my $w2 = AnyEvent->child (pid => 0, cb => sub { 60 my $cv2 = AnyEvent->condvar;
58 print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n";
59 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n";
60 $cv2->broadcast;
61});
62 61
62 # Glib is the only model that doesn't support pid == 0
63 my $pid0 = $AnyEvent::MODEL eq "AnyEvent::Impl::Glib" ? $pid2 : 0;
64
65 my $w2 = AnyEvent->child (pid => $pid0, cb => sub {
66 print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
67 print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n";
68 $cv2->broadcast;
69 });
70
63my $error = AnyEvent->timer (after => 5, cb => sub { 71 my $error = AnyEvent->timer (after => 5, cb => sub {
64 print <<EOF; 72 print <<EOF;
65Bail 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"; 73Bail 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";
66EOF 74EOF
67 exit 0; 75 exit 0;
68}); 76 });
69 77
70$cv2->wait; 78 $cv2->recv;
71 79
72print "ok 7\n"; 80 print "ok ${it}7\n";
81 print "ok ${it}8\n";
82 print "ok ${it}9\n";
83 print "ok ", $it*10+10, "\n";
84}
73 85
74 86
75 87
76 88

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines