3 use Test::More tests => 10;
5 use POSIX qw/SIGINT SIGTERM SIGKILL SIGHUP EXIT_SUCCESS EXIT_FAILURE/;
7 use IPC::MorseSignals qw/msend mrecv mreset/;
13 die 'forked too many times' if $lives < 0;
14 pipe my $rdr, my $wtr or die "pipe() failed: $!";
17 die "fork() failed: $!";
19 close $rdr or die "close() failed: $!";
21 my $s = mrecv local %SIG, cb => sub {
26 print $wtr $_[1], "\n";
30 $SIG{HUP} = sub { mreset $s };
31 $SIG{__WARN__} = sub { $block = 1; };
35 close $wtr or die "close() failed: $!";
49 my ($pid, $rdr) = spawn;
55 my @alpha = ('a' .. 'z');
56 my $msg = join '', map { $alpha[rand @alpha] } 1 .. $l;
57 my $desc_base = "$l bytes sent $n times";
58 while (($ok < $n) && (($speed /= 2) >= 1)) {
59 my $desc = "$desc_base at $speed bits/s";
65 local $SIG{ALRM} = sub { die 'timeout' };
66 local $SIG{__WARN__} = sub { die 'do not want warnings' };
67 my $a = (int(100 * (3 * $l) / $speed) || 1);
71 msend $msg => $pid, speed => $speed;
74 kill SIGHUP => $pid if $@;
76 if (!defined $r) { # Something bad happened, respawn
77 close $rdr or die "close() failed: $!";
80 redo TRY; # Retry this send
92 ok($ok >= $n, $desc_base);
93 push @res, $desc_base . (($speed) ? ' at ' . $speed . ' bits/s' : ' failed');
109 diag '=== Summary ===';
111 my ($l1, $n1) = $a =~ /(\d+)\D+(\d+)/;
112 my ($l2, $n2) = $b =~ /(\d+)\D+(\d+)/;
113 $l1 <=> $l2 || $n1 <=> $n2