From: bluhm Date: Thu, 25 Aug 2016 22:56:13 +0000 (+0000) Subject: Make relayd test slow-consumer more reliable. Set SO_SNDTIMEO X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d43d768f8e0bf3c825ce547deda5c0a95c5bce72;p=openbsd Make relayd test slow-consumer more reliable. Set SO_SNDTIMEO sockopt correctly with Perl pack on i386. Make it possible to grep in each others client and server logfile. Client does not simply sleep but waits for short write at server. --- diff --git a/regress/usr.sbin/relayd/Proc.pm b/regress/usr.sbin/relayd/Proc.pm index f7cecbc6ddc..affe554b581 100644 --- a/regress/usr.sbin/relayd/Proc.pm +++ b/regress/usr.sbin/relayd/Proc.pm @@ -1,6 +1,6 @@ -# $OpenBSD: Proc.pm,v 1.11 2016/05/03 19:13:04 bluhm Exp $ +# $OpenBSD: Proc.pm,v 1.12 2016/08/25 22:56:13 bluhm Exp $ -# Copyright (c) 2010-2014 Alexander Bluhm +# Copyright (c) 2010-2016 Alexander Bluhm # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -70,6 +70,7 @@ sub new { or die "$class log file $self->{logfile} create failed: $!"; $fh->autoflush; $self->{log} = $fh; + $self->{ppid} = $$; return bless $self, $class; } @@ -128,6 +129,9 @@ sub wait { my $self = shift; my $flags = shift; + # if we a not the parent process, assume the child is still running + return 0 unless $self->{ppid} == $$; + my $pid = $self->{pid} or croak ref($self), " no child pid"; my $kid = waitpid($pid, $flags); diff --git a/regress/usr.sbin/relayd/Server.pm b/regress/usr.sbin/relayd/Server.pm index 6c403dbc36b..22d2855a284 100644 --- a/regress/usr.sbin/relayd/Server.pm +++ b/regress/usr.sbin/relayd/Server.pm @@ -1,4 +1,4 @@ -# $OpenBSD: Server.pm,v 1.9 2015/07/18 22:11:34 benno Exp $ +# $OpenBSD: Server.pm,v 1.10 2016/08/25 22:56:13 bluhm Exp $ # Copyright (c) 2010-2015 Alexander Bluhm # @@ -20,6 +20,7 @@ use warnings; package Server; use parent 'Proc'; use Carp; +use Config; use Socket; use Socket6; use IO::Socket; @@ -57,14 +58,16 @@ sub new { pack('i', $self->{rcvbuf})) or die ref($self), " set rcvbuf SO_RCVBUF failed: $!"; } + my $packstr = $Config{longsize} == 8 ? 'ql!' : + $Config{byteorder} == 1234 ? 'lxxxxl!' : 'xxxxll!'; if ($self->{sndtimeo}) { setsockopt($ls, SOL_SOCKET, SO_SNDTIMEO, - pack('l!l!', $self->{sndtimeo}, 0)) + pack($packstr, $self->{sndtimeo}, 0)) or die ref($self), " set SO_SNDTIMEO failed failed: $!"; } if ($self->{rcvtimeo}) { setsockopt($ls, SOL_SOCKET, SO_RCVTIMEO, - pack('l!l!', $self->{rcvtimeo}, 0)) + pack($packstr, $self->{rcvtimeo}, 0)) or die ref($self), " set SO_RCVTIMEO failed failed: $!"; } my $log = $self->{log}; diff --git a/regress/usr.sbin/relayd/args-http-slow-consumer.pl b/regress/usr.sbin/relayd/args-http-slow-consumer.pl index bb6ac1b18c1..83a57de3221 100644 --- a/regress/usr.sbin/relayd/args-http-slow-consumer.pl +++ b/regress/usr.sbin/relayd/args-http-slow-consumer.pl @@ -3,6 +3,10 @@ use strict; use warnings; +use Errno ':POSIX'; + +my @errors = (EWOULDBLOCK); +my $errors = "(". join("|", map { $! = $_ } @errors). ")"; my $size = 2**21; @@ -11,14 +15,16 @@ our %args = ( fast => 1, max => 100, func => sub { - http_request(@_, $size, "1.0", ""); - http_response(@_, $size); + my $self = shift; + http_request($self , $size, "1.0", ""); + http_response($self , $size); print STDERR "going to sleep\n"; - sleep 8; - read_char(@_, $size); + ${$self->{server}}->loggrep(qr/short write \($errors\)/, 8) + or die "no short write in server.log"; + read_char($self, $size); return; }, - rcvbuf => 2**8, + rcvbuf => 2**12, nocheck => 1, }, relayd => { @@ -31,7 +37,7 @@ our %args = ( server => { fast => 1, func => \&http_server, - sndbuf => 2**8, + sndbuf => 2**12, sndtimeo => 2, loggrep => 'short write', diff --git a/regress/usr.sbin/relayd/relayd.pl b/regress/usr.sbin/relayd/relayd.pl index 904a8e4d98c..07c34dab0f4 100644 --- a/regress/usr.sbin/relayd/relayd.pl +++ b/regress/usr.sbin/relayd/relayd.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $OpenBSD: relayd.pl,v 1.14 2016/05/03 19:13:04 bluhm Exp $ +# $OpenBSD: relayd.pl,v 1.15 2016/08/25 22:56:13 bluhm Exp $ # Copyright (c) 2010-2014 Alexander Bluhm # @@ -51,6 +51,7 @@ $s = Server->new( redo => $redo, %{$args{server}}, testfile => $testfile, + client => \$c, ) unless $args{server}{noserver}; $r = Relayd->new( forward => $ARGV[0], @@ -71,6 +72,7 @@ $c = Client->new( connectport => $rport, %{$args{client}}, testfile => $testfile, + server => \$s, ) unless $args{client}{noclient}; $s->run unless $args{server}{noserver}; diff --git a/regress/usr.sbin/relayd/remote.pl b/regress/usr.sbin/relayd/remote.pl index 12fe6db86e6..c8f29ca39cb 100644 --- a/regress/usr.sbin/relayd/remote.pl +++ b/regress/usr.sbin/relayd/remote.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $OpenBSD: remote.pl,v 1.8 2016/05/03 19:13:04 bluhm Exp $ +# $OpenBSD: remote.pl,v 1.9 2016/08/25 22:56:13 bluhm Exp $ # Copyright (c) 2010-2014 Alexander Bluhm # @@ -107,6 +107,7 @@ $s = Server->new( listenaddr => ($mode eq "auto" ? $ARGV[1] : undef), listenport => ($mode eq "manual" ? $ARGV[0] : undef), testfile => $testfile, + client => \$c, ) unless $args{server}{noserver}; if ($mode eq "auto") { $r = Remote->new( @@ -129,6 +130,7 @@ $c = Client->new( connectaddr => ($mode eq "manual" ? $ARGV[1] : $r->{listenaddr}), connectport => ($mode eq "manual" ? $ARGV[2] : $r->{listenport}), testfile => $testfile, + server => \$s, ) unless $args{client}{noclient}; $s->run unless $args{server}{noserver};