ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/63_eventlib_03_child.t
Revision: 1.8
Committed: Sun Dec 5 11:41:46 2010 UTC (13 years, 6 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-5_29
Changes since 1.7: +2 -2 lines
Log Message:
5.29

File Contents

# User Rev Content
1 root 1.4 use POSIX ();
2    
3 root 1.5 no warnings;
4    
5 root 1.1 BEGIN {
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 root 1.7 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 root 1.1 EOF
16     exit 0;
17     }
18     }
19     }
20    
21 root 1.7 use AnyEvent;
22     BEGIN { eval q{use AnyEvent::Impl::EventLib;1} or ((print qq{1..0 # SKIP AnyEvent::Impl::EventLib not loadable}), exit 0) }
23    
24 root 1.5 $| = 1; print "1..50\n";
25 root 1.1
26 root 1.6 $AnyEvent::MAX_SIGNAL_LATENCY = 0.2;
27    
28 root 1.5 for my $it ("", 1, 2, 3, 4) {
29     print "ok ${it}1\n";
30 root 1.1
31 root 1.5 AnyEvent::detect; # force-load event model
32 root 1.1
33 root 1.5 my $pid = fork;
34 root 1.1
35 root 1.5 defined $pid or die "unable to fork";
36 root 1.1
37     # work around Tk bug until it has been fixed.
38     #my $timer = AnyEvent->timer (after => 2, cb => sub { });
39    
40 root 1.5 my $cv = AnyEvent->condvar;
41 root 1.1
42 root 1.5 unless ($pid) {
43     print "ok ${it}2\n";
44     POSIX::_exit 3;
45     }
46 root 1.1
47 root 1.5 my $w = AnyEvent->child (pid => $pid, cb => sub {
48     print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n";
49     print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n";
50     $cv->broadcast;
51     });
52    
53     $cv->wait;
54    
55     my $pid2 = fork || POSIX::_exit 7;
56    
57     my $cv2 = AnyEvent->condvar;
58    
59     my $w2 = AnyEvent->child (pid => 0, cb => sub {
60     print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n";
61     print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n";
62     $cv2->broadcast;
63     });
64 root 1.1
65 root 1.5 my $error = AnyEvent->timer (after => 5, cb => sub {
66     print <<EOF;
67 root 1.8 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";
68 root 1.1 EOF
69 root 1.8 exit 1;
70 root 1.5 });
71 root 1.1
72 root 1.5 $cv2->wait;
73 root 1.1
74 root 1.5 print "ok ${it}7\n";
75     print "ok ${it}8\n";
76     print "ok ${it}9\n";
77     print "ok ", $it*10+10, "\n";
78     }
79 root 1.1
80    
81    
82