ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/67_tk_03_child.t
Revision: 1.3
Committed: Fri Jul 17 22:05:12 2009 UTC (14 years, 10 months ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.2: +2 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 BEGIN {
2 # check for broken perls
3 if ($^O =~ /mswin32/i) {
4 my $ok;
5 local $SIG{CHLD} = sub { $ok = 1 };
6 kill 'CHLD', 0;
7
8 unless ($ok) {
9 print <<EOF;
10 1..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.
11 EOF
12 exit 0;
13 }
14 }
15 }
16
17 BEGIN {
18 $|=1;
19 print "1..7\n"
20 }
21
22 use POSIX ();
23
24 use AnyEvent;
25 use AnyEvent::Impl::Tk;
26
27 $AnyEvent::MAX_SIGNAL_LATENCY = 1;
28
29 print "ok 1\n";
30
31 AnyEvent::detect; # force-load event model
32
33 my $pid = fork;
34
35 defined $pid or die "unable to fork";
36
37 # work around Tk bug until it has been fixed.
38 #my $timer = AnyEvent->timer (after => 2, cb => sub { });
39
40 my $cv = AnyEvent->condvar;
41
42 unless ($pid) {
43 print "ok 2\n";
44 POSIX::_exit 3;
45 }
46
47 my $w = AnyEvent->child (pid => $pid, cb => sub {
48 print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n";
49 print 3 == ($_[1] >> 8) ? "" : "not ", "ok 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 5 # $pid2 == $_[0]\n";
61 print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n";
62 $cv2->broadcast;
63 });
64
65 my $error = AnyEvent->timer (after => 15, cb => sub {
66 print <<EOF;
67 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";
68 EOF
69 exit 0;
70 });
71
72 my $inter = AnyEvent->timer (after => 14, cb => sub {
73 print "not ok 5 # inter\n";
74 print "not ok 6 # inter\n";
75 $cv2->send;
76 });
77
78 $cv2->wait;
79
80 print "ok 7\n";
81
82
83
84