diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2011-07-04 05:43:03 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2011-07-04 05:43:03 +0000 |
commit | 8cf37cfbd19193cf80d60e7772669aa6e62cf728 (patch) | |
tree | 6804e5818917b5e93a892ef407d217901d89db9b /regress/sys/kern/splice | |
parent | f57b852a44563605cd60c0185254420b8d416162 (diff) |
Add new socket splicing tests for the idle timeout feature. Note
that you need p5-BSD-Socket-Splice version 0.03 to run the regression
tests.
Diffstat (limited to 'regress/sys/kern/splice')
-rw-r--r-- | regress/sys/kern/splice/args-idle.pl | 17 | ||||
-rwxr-xr-x | regress/sys/kern/splice/echo.pl | 11 | ||||
-rwxr-xr-x | regress/sys/kern/splice/error-idle-EINVAL.pl | 36 | ||||
-rwxr-xr-x | regress/sys/kern/splice/error-max-EINVAL.pl | 9 | ||||
-rw-r--r-- | regress/sys/kern/splice/funcs.pl | 41 | ||||
-rwxr-xr-x | regress/sys/kern/splice/relay.pl | 11 | ||||
-rwxr-xr-x | regress/sys/kern/splice/remote.pl | 11 |
7 files changed, 112 insertions, 24 deletions
diff --git a/regress/sys/kern/splice/args-idle.pl b/regress/sys/kern/splice/args-idle.pl new file mode 100644 index 00000000000..7045249ce85 --- /dev/null +++ b/regress/sys/kern/splice/args-idle.pl @@ -0,0 +1,17 @@ +# test idle timeout + +use strict; +use warnings; + +our %args = ( + client => { + func => sub { sleep 1; write_char(@_); sleep 3; }, + }, + relay => { + idle => 2, + }, + len => 251, + md5 => "bc3a3f39af35fe5b1687903da2b00c7f", +); + +1; diff --git a/regress/sys/kern/splice/echo.pl b/regress/sys/kern/splice/echo.pl index 30d011558b2..9d147703175 100755 --- a/regress/sys/kern/splice/echo.pl +++ b/regress/sys/kern/splice/echo.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $OpenBSD: echo.pl,v 1.2 2011/03/13 03:15:41 bluhm Exp $ +# $OpenBSD: echo.pl,v 1.3 2011/07/04 05:43:02 bluhm Exp $ # Copyright (c) 2010 Alexander Bluhm <bluhm@openbsd.org> # @@ -82,6 +82,11 @@ $s->{pid} = -1; # XXX hack exit if $args{nocheck}; +$r->loggrep(qr/^Timeout$/) or die "no relay timeout" + if $args{relay}{idle}; +$r->loggrep(qr/^Max$/) or die "no relay max" + if $args{relay}{max} && $args{len}; + my $clen = $c->loggrep(qr/^LEN: /) // die "no client len" unless $args{client}{nocheck}; my $rlen = $r->loggrep(qr/^LEN: /) // die "no relay len" @@ -110,8 +115,8 @@ my $smd5 = $s->loggrep(qr/^MD5: /) unless $args{server}{nocheck}; !defined($args{md5}) || !$smd5 || $smd5 eq "MD5: $args{md5}\n" or die "server: $smd5", "md5 $args{md5} expected"; -$args{relay}{errorin} = 0 unless $args{relay}{nocheck}; -$args{relay}{errorout} = 0 unless $args{relay}{nocheck}; +$args{relay}{errorin} //= 0 unless $args{relay}{nocheck}; +$args{relay}{errorout} //= 0 unless $args{relay}{nocheck}; $args{relay}{errorin} //= $args{relay}{error}; if (defined($args{relay}{errorin})) { my $ein = $r->loggrep(qr/^ERROR IN: /); diff --git a/regress/sys/kern/splice/error-idle-EINVAL.pl b/regress/sys/kern/splice/error-idle-EINVAL.pl new file mode 100755 index 00000000000..42f5c1a818a --- /dev/null +++ b/regress/sys/kern/splice/error-idle-EINVAL.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl +# test EINVAL for splicing with negative idle timeout + +use Errno; +use IO::Socket; +use BSD::Socket::Splice "SO_SPLICE"; +use Config; + +my $sl = IO::Socket::INET->new( + Proto => "tcp", + Listen => 5, + LocalAddr => "127.0.0.1", +) or die "socket listen failed: $!"; + +my $s = IO::Socket::INET->new( + Proto => "tcp", + PeerAddr => $sl->sockhost(), + PeerPort => $sl->sockport(), +) or die "socket failed: $!"; + +my $ss = IO::Socket::INET->new( + Proto => "tcp", + PeerAddr => $sl->sockhost(), + PeerPort => $sl->sockport(), +) or die "socket splice failed: $!"; + +my $packed; +if ($Config{longsize} == 8) { + $packed = pack('iiiiiiii', $ss->fileno(),0,0,0,-1,-1,-1,-1); +} else { + $packed = pack('iiiii', $ss->fileno(),0,0,-1,-1); +} +$s->setsockopt(SOL_SOCKET, SO_SPLICE, $packed) + and die "splice to unconnected socket succeeded"; +$!{EINVAL} + or die "error not EINVAL: $!" diff --git a/regress/sys/kern/splice/error-max-EINVAL.pl b/regress/sys/kern/splice/error-max-EINVAL.pl index 7d62dc4374c..34cdbd0265f 100755 --- a/regress/sys/kern/splice/error-max-EINVAL.pl +++ b/regress/sys/kern/splice/error-max-EINVAL.pl @@ -4,6 +4,7 @@ use Errno; use IO::Socket; use BSD::Socket::Splice "SO_SPLICE"; +use Config; my $sl = IO::Socket::INET->new( Proto => "tcp", @@ -23,7 +24,13 @@ my $ss = IO::Socket::INET->new( PeerPort => $sl->sockport(), ) or die "socket splice failed: $!"; -$s->setsockopt(SOL_SOCKET, SO_SPLICE, pack('iiii', $ss->fileno(),-1,-1,-1)) +my $packed; +if ($Config{longsize} == 8) { + $packed = pack('iiiiiiii', $ss->fileno(),0,-1,-1,0,0,0,0); +} else { + $packed = pack('iiiii', $ss->fileno(),-1,-1,0,0); +} +$s->setsockopt(SOL_SOCKET, SO_SPLICE, $packed) and die "splice to unconnected socket succeeded"; $!{EINVAL} or die "error not EINVAL: $!" diff --git a/regress/sys/kern/splice/funcs.pl b/regress/sys/kern/splice/funcs.pl index 570ec605558..d0342fd8f6f 100644 --- a/regress/sys/kern/splice/funcs.pl +++ b/regress/sys/kern/splice/funcs.pl @@ -1,4 +1,4 @@ -# $OpenBSD: funcs.pl,v 1.5 2011/04/22 02:06:00 bluhm Exp $ +# $OpenBSD: funcs.pl,v 1.6 2011/07/04 05:43:02 bluhm Exp $ # Copyright (c) 2010,2011 Alexander Bluhm <bluhm@openbsd.org> # @@ -53,6 +53,7 @@ sub write_char { or die ref($self), " print failed: $!"; print STDERR ".\n"; } + IO::Handle::flush(\*STDOUT); print STDERR "LEN: ", $len, "\n"; print STDERR "MD5: ", $ctx->hexdigest, "\n"; @@ -99,6 +100,7 @@ sub write_oob { or die ref($self), " send failed: $!"; print STDERR ".\n"; } + IO::Handle::flush(\*STDOUT); print STDERR "LEN: ", $len, "\n"; print STDERR "MD5: ", $ctx->hexdigest, "\n"; @@ -110,7 +112,8 @@ sub write_oob { sub relay_copy { my $self = shift; - my $max = shift // $self->{max}; + my $max = $self->{max}; + my $idle = $self->{idle}; my $size = $self->{size} || 8093; my $len = 0; @@ -118,8 +121,13 @@ sub relay_copy { my $rin = my $win = my $ein = ''; vec($rin, fileno(STDIN), 1) = 1; vec($ein, fileno(STDIN), 1) = 1 unless $self->{oobinline}; - select($rin, undef, $ein, undef) + defined(my $n = select($rin, undef, $ein, $idle)) or die ref($self), " select failed: $!"; + if ($idle && $n == 0) { + print STDERR "\n"; + print STDERR "Timeout\n"; + last; + } my $buf; my $atmark = sockatmark(\*STDIN) or die ref($self), " sockatmark failed: $!"; @@ -182,14 +190,16 @@ sub relay_copy { sub relay_splice { my $self = shift; - my $max = shift // $self->{max}; + my $max = $self->{max}; + my $idle = $self->{idle}; my $len = 0; my $splicelen; my $shortsplice = 0; + my $error; do { my $splicemax = $max ? $max - $len : 0; - setsplice(\*STDIN, \*STDOUT, $splicemax) + setsplice(\*STDIN, \*STDOUT, $splicemax, $idle) or die ref($self), " splice stdin to stdout failed: $!"; if ($self->{readblocking}) { @@ -212,9 +222,9 @@ sub relay_splice { or die ref($self), " select failed: $!"; } - defined(my $error = geterror(\*STDIN)) + defined($error = geterror(\*STDIN)) or die ref($self), " get error from stdin failed: $!"; - $! = $error + ($! = $error) && ! $!{ETIMEDOUT} and die ref($self), " splice failed: $!"; defined($splicelen = getsplice(\*STDIN)) @@ -226,13 +236,16 @@ sub relay_splice { $len += $splicelen; } while ($max && $max > $len && !$shortsplice++); + if ($idle && $error == Errno::ETIMEDOUT) { + print STDERR "Timeout\n"; + } if ($max && $max == $len) { print STDERR "Max\n"; } elsif ($max && $max < $len) { die ref($self), " max $max less than len $len"; } elsif ($max && $max > $len && $splicelen) { die ref($self), " max $max greater than len $len"; - } else { + } elsif (!$error) { defined(my $read = sysread(STDIN, my $buf, 2**16)) or die ref($self), " sysread stdin failed: $!"; $read > 0 @@ -291,16 +304,16 @@ sub errignore { sub shutin { my $self = shift; - shutdown(\*STDIN, SHUT_RD) - or die ref($self), " shutdown read failed: $!"; + shutdown(\*STDIN, SHUT_RD) + or die ref($self), " shutdown read failed: $!"; } sub shutout { my $self = shift; IO::Handle::flush(\*STDOUT) - or die ref($self), " flush stdout failed: $!"; - shutdown(\*STDOUT, SHUT_WR) - or die ref($self), " shutdown write failed: $!"; + or die ref($self), " flush stdout failed: $!"; + shutdown(\*STDOUT, SHUT_WR) + or die ref($self), " shutdown write failed: $!"; } ######################################################################## @@ -309,7 +322,7 @@ sub shutout { sub read_char { my $self = shift; - my $max = shift // $self->{max}; + my $max = $self->{max}; my $ctx = Digest::MD5->new(); my $len = 0; diff --git a/regress/sys/kern/splice/relay.pl b/regress/sys/kern/splice/relay.pl index 72c12ede581..f22a314629d 100755 --- a/regress/sys/kern/splice/relay.pl +++ b/regress/sys/kern/splice/relay.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $OpenBSD: relay.pl,v 1.2 2011/03/13 03:15:41 bluhm Exp $ +# $OpenBSD: relay.pl,v 1.3 2011/07/04 05:43:02 bluhm Exp $ # Copyright (c) 2010 Alexander Bluhm <bluhm@openbsd.org> # @@ -76,6 +76,11 @@ $s->down; exit if $args{nocheck}; +$r->loggrep(qr/^Timeout$/) or die "no relay timeout" + if $args{relay}{idle}; +$r->loggrep(qr/^Max$/) or die "no relay max" + if $args{relay}{max} && $args{len}; + my $clen = $c->loggrep(qr/^LEN: /) // die "no client len" unless $args{client}{nocheck}; my $rlen = $r->loggrep(qr/^LEN: /) // die "no relay len" @@ -104,8 +109,8 @@ my $smd5 = $s->loggrep(qr/^MD5: /) unless $args{server}{nocheck}; !defined($args{md5}) || !$smd5 || $smd5 eq "MD5: $args{md5}\n" or die "server: $smd5", "md5 $args{md5} expected"; -$args{relay}{errorin} = 0 unless $args{relay}{nocheck}; -$args{relay}{errorout} = 0 unless $args{relay}{nocheck}; +$args{relay}{errorin} //= 0 unless $args{relay}{nocheck}; +$args{relay}{errorout} //= 0 unless $args{relay}{nocheck}; my %name2proc = (client => $c, relay => $r, server => $s); foreach my $name (qw(client relay server)) { $args{$name}{errorin} //= $args{$name}{error}; diff --git a/regress/sys/kern/splice/remote.pl b/regress/sys/kern/splice/remote.pl index 775621779c4..05fd6c362db 100755 --- a/regress/sys/kern/splice/remote.pl +++ b/regress/sys/kern/splice/remote.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $OpenBSD: remote.pl,v 1.2 2011/03/13 03:15:41 bluhm Exp $ +# $OpenBSD: remote.pl,v 1.3 2011/07/04 05:43:02 bluhm Exp $ # Copyright (c) 2010 Alexander Bluhm <bluhm@openbsd.org> # @@ -128,6 +128,11 @@ $s->down; exit if $args{nocheck}; +$r->loggrep(qr/^Timeout$/) or die "no relay timeout" + if $args{relay}{idle}; +$r->loggrep(qr/^Max$/) or die "no relay max" + if $args{relay}{max} && $args{len}; + my $clen = $c->loggrep(qr/^LEN: /) // die "no client len" unless $args{client}{nocheck}; my $slen = $s->loggrep(qr/^LEN: /) // die "no server len" @@ -148,8 +153,8 @@ my $smd5 = $s->loggrep(qr/^MD5: /) unless $args{server}{nocheck}; !defined($args{md5}) || !$smd5 || $smd5 eq "MD5: $args{md5}\n" or die "server: $smd5", "md5 $args{md5} expected"; -$args{relay}{errorin} = 0 unless $args{relay}{nocheck}; -$args{relay}{errorout} = 0 unless $args{relay}{nocheck}; +$args{relay}{errorin} //= 0 unless $args{relay}{nocheck}; +$args{relay}{errorout} //= 0 unless $args{relay}{nocheck}; my %name2proc = (client => $c, relay => $r, server => $s); foreach my $name (qw(client relay server)) { $args{$name}{errorin} //= $args{$name}{error}; |