converting test scripts to python

svn path=/trunk/boinc/; revision=1526
This commit is contained in:
Karl Chen 2003-06-18 02:59:57 +00:00
parent a7149c4596
commit 42a26f2c06
7 changed files with 99 additions and 43 deletions

View File

@ -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

View File

@ -137,6 +137,7 @@ AC_CONFIG_FILES([RSAEuro/source/Makefile
tools/Makefile
test/Makefile
test/version.inc
test/version.py
Makefile
])

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -2,17 +2,14 @@
<?php {
// $Id$
// This tests whether upload resuming works correctly.
$use_proxy_cgi = 1;
include_once("test_uc.inc");
test_msg("upload backoff");
$project = new ProjectUC;
start_proxy('print "#$nconnections url=$url time=$time\n"; exit 1 if ($nconnections < 4); if_done_kill(); if_done_ping();');
// TODO
// start_proxy('exit 1 if ($nconnections < 4); if_done_kill(); if_done_ping();');
$project = new ProjectUC;
// $pid = $host->run_asynch("-exit_when_idle");

View File

@ -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;
}