3 use Test::More tests => 4 * 3;
5 use POSIX qw/SIGINT SIGTERM SIGKILL SIGHUP 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: $!";
47 my ($pid, $rdr) = spawn;
50 my ($msg, $desc) = @_;
53 while (!$ok && (($speed /= 2) >= 1)) {
56 local $SIG{ALRM} = sub { die 'timeout' };
57 local $SIG{__WARN__} = sub { die 'do not want warnings' };
58 my $a = (int(100 * (3 * length $msg) / $speed) || 1);
62 msend $msg => $pid, speed => $speed, sign => 0;
65 kill SIGHUP => $pid if $@;
67 if (!defined $r) { # Something bad happened, respawn
68 close $rdr or die "close() failed: $!";
71 $speed *= 2; # Retry this speed
85 trysend 'hello', 'ascii';
86 trysend "\0" x 10, 'few bits';
87 trysend "\x{FF}" x 10, 'lots of bits';
88 trysend "a\0b", 'null character';