From: Vincent Pit Date: Sun, 29 Jun 2008 16:35:31 +0000 (+0200) Subject: Importing IPC-MorseSignals-0.03.tar.gz X-Git-Tag: v0.03^0 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=133946d2bfe0a5d47755a8f182a76e2f57b72e20;p=perl%2Fmodules%2FIPC-MorseSignals.git Importing IPC-MorseSignals-0.03.tar.gz --- diff --git a/Changes b/Changes index 1432373..b0b881a 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for IPC-MorseSignals +0.03 2007-08-16 16:20 UTC + + Chg : Better t/10-base.t... Or at least, I hope so. + 0.02 2007-08-16 15:55 UTC + Add : samples/bench.pl, a transfer speed benchmark script. + Add : New tests : t/02-sigusr.t, t/11-speed.t diff --git a/META.yml b/META.yml index 8a0c77b..b7d2982 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: IPC-MorseSignals -version: 0.02 +version: 0.03 abstract: Communicate between processes with Morse signals. license: perl generated_by: ExtUtils::MakeMaker version 6.36 diff --git a/README b/README index 0e5fb78..32ad19f 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ NAME IPC::MorseSignals - Communicate between processes with Morse signals. VERSION - Version 0.02 + Version 0.03 SYNOPSIS use IPC::MorseSignals qw/msend mrecv/; diff --git a/lib/IPC/MorseSignals.pm b/lib/IPC/MorseSignals.pm index 214073b..498cd07 100644 --- a/lib/IPC/MorseSignals.pm +++ b/lib/IPC/MorseSignals.pm @@ -12,11 +12,11 @@ IPC::MorseSignals - Communicate between processes with Morse signals. =head1 VERSION -Version 0.02 +Version 0.03 =cut -our $VERSION = '0.02'; +our $VERSION = '0.03'; =head1 SYNOPSIS diff --git a/samples/bench.pl b/samples/bench.pl index 852c09f..45b485b 100755 --- a/samples/bench.pl +++ b/samples/bench.pl @@ -41,7 +41,7 @@ TRY: } close $wtr or die "$desc: close() failed : $!"; eval { - local $SIG{ALRM} = sub { die 'alarm' }; + local $SIG{ALRM} = sub { die 'timeout' }; my $a = (int(100 * (3 * $l) / $speed) || 1); $a = 10 if $a > 10; alarm $a; diff --git a/t/02-sigusr.t b/t/02-sigusr.t index 0adb3c6..8a048e9 100644 --- a/t/02-sigusr.t +++ b/t/02-sigusr.t @@ -31,5 +31,6 @@ sub trysig { ok($ret == EXIT_SUCCESS, $s); } +sleep 1; trysig SIGUSR1, 'USR1'; trysig SIGUSR2, 'USR2'; diff --git a/t/10-base.t b/t/10-base.t index 153cffe..bc55f14 100644 --- a/t/10-base.t +++ b/t/10-base.t @@ -6,43 +6,51 @@ use POSIX qw/SIGINT SIGTERM SIGKILL EXIT_SUCCESS/; use IPC::MorseSignals qw/msend mrecv/; -my $speed = 128; - sub trysend { my ($msg, $desc) = @_; - pipe my $rdr, my $wtr or die "$desc: pipe() failed : $!"; - my $pid = fork; - if (!defined $pid) { - die "$desc: fork() failed : $!"; - } elsif ($pid == 0) { - close $rdr; - local @SIG{qw/USR1 USR2/} = mrecv sub { - print $wtr $_[0], "\n"; - close $wtr; - exit EXIT_SUCCESS; + my $speed = 2 ** 16; + my $ok = 0; +SPEED: + while (($speed > 1) && !$ok) { + $speed /= 2; + pipe my $rdr, my $wtr or die "$desc: pipe() failed : $!"; + my $pid = fork; + if (!defined $pid) { + die "$desc: fork() failed : $!"; + } elsif ($pid == 0) { + close $rdr; + local @SIG{qw/USR1 USR2/} = mrecv sub { + print $wtr $_[0], "\n"; + close $wtr; + exit EXIT_SUCCESS; + }; + 1 while 1; + } + close $wtr or die "$desc: close() failed : $!"; + eval { + local $SIG{ALRM} = sub { die 'timeout' }; + my $a = (int(100 * (3 * length $msg) / $speed) || 1); + $a = 10 if $a > 10; + alarm $a; + msend $msg => $pid, $speed; + waitpid $pid, 0; }; - 1 while 1; - } - close $wtr or die "$desc: close() failed : $!"; - eval { - local $SIG{ALRM} = sub { die 'timeout' }; - my $a = (int(100 * (3 * length $msg) / $speed) || 1); - $a = 10 if $a > 10; - alarm $a; - msend $msg => $pid, $speed; - waitpid $pid, 0; - }; - alarm 0; - if ($@) { - kill SIGINT, $pid; - kill SIGTERM, $pid; - kill SIGKILL, $pid; - die "$desc: died ($@)"; + alarm 0; + if ($@) { + kill SIGINT, $pid; + kill SIGTERM, $pid; + kill SIGKILL, $pid; + close $rdr or die "$desc: close() failed : $!"; + next SPEED; + } + my $recv = do { local $/; <$rdr> }; + close $rdr or die "$desc: close() failed : $!"; + next SPEED unless $recv; + chomp $recv; + next SPEED unless $msg eq $recv; + $ok = 1; } - my $recv = do { local $/; <$rdr> }; - close $rdr; - chomp $recv; - ok($msg eq $recv, $desc); + ok($speed >= 1, $desc); } for (1 .. 5) { diff --git a/t/11-speed.t b/t/11-speed.t index 2593fd4..373bda2 100644 --- a/t/11-speed.t +++ b/t/11-speed.t @@ -14,7 +14,7 @@ sub tryspeed { my $ok = 0; my $msg = join '', map { chr int rand 256 } 1 .. $l; my $desc; - while (($speed >= 1) && ($ok < $n)) { + while (($speed > 1) && ($ok < $n)) { $desc = "$n sends of $l bytes at $speed bits/s"; $speed /= 2; $ok = 0; @@ -36,7 +36,7 @@ TRY: } close $wtr or die "$desc: close() failed : $!"; eval { - local $SIG{ALRM} = sub { die 'alarm' }; + local $SIG{ALRM} = sub { die 'timeout' }; my $a = (int(100 * (3 * $l) / $speed) || 1); $a = 10 if $a > 10; alarm $a;