diff --git a/checkin_notes b/checkin_notes index 781ca29dcc..cc20b96fc3 100755 --- a/checkin_notes +++ b/checkin_notes @@ -4778,3 +4778,18 @@ Karl 2003/06/17 tools/ backend_lib.C create_work.C + +Karl 2003/06/17 + Converting test scripts to Python + + configure.ac + test/ + Makefile.am + boinc.py + boinc_db.py + db_def_to_py + test.inc + test_upload_backoff.php + test_uc.py + testproxy + version.py.in diff --git a/configure.ac b/configure.ac index dac753ddae..f8547373d9 100644 --- a/configure.ac +++ b/configure.ac @@ -137,6 +137,7 @@ AC_CONFIG_FILES([RSAEuro/source/Makefile tools/Makefile test/Makefile test/version.inc + test/version.py Makefile ]) diff --git a/test/Makefile.am b/test/Makefile.am index b3a741548f..78fa985bb8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -13,7 +13,11 @@ TESTS = test_sanity.php \ EXTRA_DIST = \ *.xml *.php *wu *result *output \ - *input *.inc *.in + *input *.inc *.py *.in \ + db_def_to_php db_def_to_py boinc_db.inc: ../db/boinc_db.h ./db_def_to_php < ../db/boinc_db.h > boinc_db.inc + +boinc_db.py: ../db/boinc_db.h + ./db_def_to_py < ../db/boinc_db.h > boinc_db.py diff --git a/test/Makefile.in b/test/Makefile.in index 7b75a83d9a..30eb3095a7 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -180,16 +180,16 @@ TESTS = test_sanity.php \ # test_sticky.php EXTRA_DIST = \ *.xml *.php *wu *result *output \ - *input *.inc *.in + *input *.inc *.py *.in subdir = test ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = version.inc +CONFIG_CLEAN_FILES = version.inc version.py DIST_SOURCES = DIST_COMMON = $(top_srcdir)/Makefile.incl Makefile.am Makefile.in \ - version.inc.in + version.inc.in version.py.in all: all-am .SUFFIXES: @@ -200,6 +200,8 @@ Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.s cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) version.inc: $(top_builddir)/config.status version.inc.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +version.py: $(top_builddir)/config.status version.py.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ uninstall-info-am: tags: TAGS TAGS: @@ -404,6 +406,9 @@ $(LIBRSA): boinc_db.inc: ../db/boinc_db.h ./db_def_to_php < ../db/boinc_db.h > boinc_db.inc + +boinc_db.py: ../db/boinc_db.h + ./db_def_to_py < ../db/boinc_db.h > boinc_db.py # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/test/test.inc b/test/test.inc index 54906683ff..3841be5fc6 100644 --- a/test/test.inc +++ b/test/test.inc @@ -1087,7 +1087,8 @@ class Work { function start_proxy($code) { - verbose_XPassThru("./testproxy 8080 localhost:80 '$code' 2>/dev/null &"); + verbose_echo(1, "Starting proxy server"); + verbose_XPassThru("./testproxy 8080 localhost:80 '$code' 2>testproxy.log &"); } function test_msg($msg) diff --git a/test/test_upload_backoff.php b/test/test_upload_backoff.php index 2d491628ed..d34ecb5b9e 100644 --- a/test/test_upload_backoff.php +++ b/test/test_upload_backoff.php @@ -2,17 +2,14 @@ run_asynch("-exit_when_idle"); diff --git a/test/testproxy b/test/testproxy index 8d6f48cec3..76b7fdb26b 100755 --- a/test/testproxy +++ b/test/testproxy @@ -47,16 +47,17 @@ CODE is evaluated every 128 bytes transferred from server to client. \$time : seconds since server started \$chars, \$nchars : characters & length about to send to client. \$bytes_transferred : characters already sent to client + \$start : beginning of connection \$done, \$success : finished transfer; successful transfer + \$n, \$m : unused variables initialized to 0 For more, view the code. Functions: - kill_server, if_done_kill, if_done_ping + close_connection, kill_server, if_done_kill, if_done_ping, logmsg - You can also call any functions like exit, sleep, \$target\->close, - \$target\->print. You should return 1 to indicate success (otherwise - testproxy will warn). + You can also call standard perl functions such as print, sleep, exit. You + should return 1 to indicate success (otherwise testproxy will warn). Examples: # fail connections for first 3 connections @@ -85,7 +86,8 @@ my $N = "\015\012"; sub proxy; sub spawn; -sub logmsg { print STDERR "$0 $$: @_ at ", scalar localtime, "\n" } +use POSIX qw/strftime/; +sub logmsg { print STDERR "$0 $$ ", strftime("%Y/%m/%d %H:%M:%S", localtime), ": @_\n" } my $server = IO::Socket::INET->new(Listen => 5, LocalAddr => inet_ntoa(INADDR_ANY), @@ -105,32 +107,32 @@ use POSIX ":sys_wait_h"; sub REAPER { my $child; while (($waitedpid = waitpid(-1,WNOHANG)) > 0) { - # logmsg "reaped $waitedpid" . ($? ? " with exit $?" : ''); + logmsg "reaped $waitedpid" . ($? ? " with exit $?" : ''); } $SIG{CHLD} = \&REAPER; # loathe sysV } $SIG{CHLD} = \&REAPER; +my $time_started = time(); my $nconnections = 0; - -my $client; +my $cclient; for ( $waitedpid = 0; - ($client = $server->accept()) || $waitedpid; + ($cclient = $server->accept()) || $waitedpid; $waitedpid = 0) { - next if $waitedpid and not $client; - die unless $client; - my $paddr = $client->peername(); + next if $waitedpid and not $cclient; + die unless $cclient; + my $paddr = $cclient->peername(); my($port,$iaddr) = sockaddr_in($paddr); my $name = gethostbyaddr($iaddr,AF_INET); - logmsg "connection from $name", "[", inet_ntoa($iaddr), "]:$port"; + logmsg "connection from $name:$port"; # [", inet_ntoa($iaddr), "]" ++$nconnections; - spawn \&proxy, $client; + spawn \&proxy, $cclient; } sub spawn { @@ -145,7 +147,7 @@ sub spawn { logmsg "cannot fork: $!"; return; } elsif ($pid) { - # logmsg "begat $pid"; + logmsg "begat $pid"; return; # I'm the parent } # else I'm the child -- go spawn @@ -158,8 +160,12 @@ sub kill_server() kill "INT", $server_pid; } +my $start = 0; my $done = 0; my $success = 0; +my $url = undef; +my $n = 0; +my $m = 0; sub if_done_ping() { @@ -182,38 +188,65 @@ sub if_done_kill() 1; } -sub proxy { - my $client = shift or die; +sub eval_test_code() +{ + my $time = time() - $time_started; + eval $testcode || warn "test code failed"; +} - my $target = IO::Socket::INET->new(PeerAddr => $target_server) +my ($client, $target); + +sub close_connection() { + # $client->close(), $target->close() doesn't always work for some reason + # (maybe to do with forked processes) + $client->shutdown(2); + $target->shutdown(2); + 1; +} + +sub proxy { + $client = shift or die; + + $target = IO::Socket::INET->new(PeerAddr => $target_server) or die "$0: couldn't connect to $target_server: $!"; $client->autoflush(1); $target->autoflush(1); + my $bytes_transferred = 0; + my $chars; + my $nchars; + + { + $chars = undef; $nchars = 0; + $done = 0; + $success = 0; + $start = 1; + eval_test_code(); + $start = 0; + } + # transfer lines from client -> server until we get an empty line while (my $line = $client->getline()) { + if ($. == 1 && $line =~ /^(GET|PUT|POST) ([^\s]+)/) { + $url = $2; + logmsg "url = $url"; + } $target->print($line); $line =~ s/[\015\012]+$//; last unless $line; } + # indicate we have stopped reading data from client and stopped writing + # data to server (not sure if this helps) + $client->shutdown(0); + $target->shutdown(1); + # transfer from server->client - my $bytes_transferred = 0; - # while (my $line = $target->getline()) { - # $bytes_transferred += length($line); - # print "[$bytes_transferred] $line"; - # $client->print($line); - # } - - $done = 0; - $success = 0; - my $chars; - my $nchars; while ($nchars = $target->read($chars, 128)) { - eval $testcode || warn; + eval_test_code(); $bytes_transferred += $nchars; $client->write($chars, $nchars); } @@ -222,9 +255,9 @@ sub proxy { $chars = undef; $nchars = 0; $done = 1; $success = $client->connected() && 1; - eval $testcode || warn; + eval_test_code(); } - $target->close(); - $client->close(); + close_connection(); + return 0; }