James Bursa's adjustments to make the -t option work for any test case.

The -t is the "torture" test that first runs the test and counts the number
of allocations performed during it, then it runs the test repeatedly over and
over again and makes alloc number N fail to verify that we detect and return
properly from error cases everywhere.
This commit is contained in:
Daniel Stenberg 2004-05-10 09:01:45 +00:00
Родитель 228fea4628
Коммит e18d27b78a
1 изменённых файлов: 81 добавлений и 102 удалений

Просмотреть файл

@ -155,116 +155,94 @@ sub serverpid {
# Memory allocation test and failure torture testing. # Memory allocation test and failure torture testing.
# #
sub torture { sub torture {
# start all test servers (http, https, ftp, ftps) my $testcmd = shift;
&startservers(("http", "https", "ftp", "ftps")); my $gdbline = shift;
my $c;
my @test=('http://%HOSTIP:%HOSTPORT/1', # remove memdump first to be sure we get a new nice and clean one
'ftp://%HOSTIP:%FTPPORT/1', unlink($memdump);
'http://%HOSTIP:%HOSTPORT/3 -d "poo"');
# loop over the different tests commands
for(@test) {
my $cmdargs = "$_";
$c++; # First get URL from test server, ignore the output/result
system($testcmd);
if($tortnum && ($tortnum != $c)) { print " CMD: $testcmd\n" if($verbose);
next;
}
print "We want test $c\n";
my $redir=">log/torture.stdout 2>log/torture.stderr";
subVariables(\$cmdargs);
my $testcmd = "$CURL $cmdargs $redir";
# First get URL from test server, ignore the output/result
system($testcmd);
# Set up gdb-stuff if desired
if($gdbthis) {
open(GDBCMD, ">log/gdbcmd");
print GDBCMD "set args $cmdargs\n";
print GDBCMD "show args\n";
close(GDBCMD);
$testcmd = "gdb $CURL -x log/gdbcmd";
}
print "Torture test $c:\n";
print " CMD: $testcmd\n" if($verbose);
# memanalyze -v is our friend, get the number of allocations made # memanalyze -v is our friend, get the number of allocations made
my $count; my $count;
my @out = `$memanalyze -v $memdump`; my @out = `$memanalyze -v $memdump`;
for(@out) { for(@out) {
if(/^Allocations: (\d+)/) { if(/^Allocations: (\d+)/) {
$count = $1; $count = $1;
last; last;
}
} }
if(!$count) { }
# hm, no allocations in this fetch, ignore and get next
print "BEEEP, no allocs found for test $c!!!\n"; print " $count allocations to make fail\n";
for ( 1 .. $count ) {
my $limit = $_;
my $fail;
my $dumped_core;
if($tortalloc && ($tortalloc != $limit)) {
next; next;
} }
print " $count allocations to excersize\n";
for ( 1 .. $count ) { print "Fail alloc no: $limit\r" if(!$gdbthis);
my $limit = $_;
my $fail;
if($tortalloc && ($tortalloc != $limit)) {
next;
}
print "Alloc no: $limit\r" if(!$gdbthis);
# make the memory allocation function number $limit return failure # make the memory allocation function number $limit return failure
$ENV{'CURL_MEMLIMIT'} = $limit; $ENV{'CURL_MEMLIMIT'} = $limit;
# remove memdump first to be sure we get a new nice and clean one # remove memdump first to be sure we get a new nice and clean one
unlink($memdump); unlink($memdump);
print "**> Alloc number $limit is now set to fail <**\n" if($gdbthis); print "**> Alloc number $limit is now set to fail <**\n" if($gdbthis);
my $ret = system($testcmd); my $ret;
if($gdbthis) {
system($gdbline)
}
else {
$ret = system($testcmd);
}
# verify that it returns a proper error code, doesn't leak memory if(-r "core") {
# and doesn't core dump # there's core file present now!
if($ret & 255) { print " core dumped!\n";
print " system() returned $ret\n"; $dumped_core = 1;
$fail=1; $fail = 2;
} }
else {
my @memdata=`$memanalyze $memdump`; # verify that it returns a proper error code, doesn't leak memory
my $leak=0; # and doesn't core dump
for(@memdata) { if($ret & 255) {
if($_ ne "") { print " system() returned $ret\n";
# well it could be other memory problems as well, but $fail=1;
# we call it leak for short here }
$leak=1; else {
} my @memdata=`$memanalyze $memdump`;
} my $leak=0;
if($leak) { for(@memdata) {
print "** MEMORY FAILURE\n"; if($_ ne "") {
print @memdata; # well it could be other memory problems as well, but
print `$memanalyze -l $memdump`; # we call it leak for short here
$fail = 1; $leak=1;
} }
} }
if($fail) { if($leak) {
print " Failed on alloc number $limit in test $c.\n", print "** MEMORY FAILURE\n";
" invoke with -t$c,$limit to repeat this single case.\n"; print @memdata;
stopservers(); print `$memanalyze -l $memdump`;
exit 1; $fail = 1;
} }
} }
print "\n torture test $c did GOOD\n"; if($fail) {
print " Failed on alloc number $limit in test.\n",
# all is well, now test a different kind of URL " invoke with -t$limit to repeat this single case.\n";
stopservers();
exit 1;
}
} }
stopservers(); stopservers();
exit; # for now, we stop after these tests exit; # for now, we stop after these tests
} }
@ -1051,12 +1029,20 @@ sub singletest {
my $dumped_core; my $dumped_core;
my $cmdres; my $cmdres;
# run the command line we built
if($gdbthis) { if($gdbthis) {
open(GDBCMD, ">log/gdbcmd"); open(GDBCMD, ">log/gdbcmd");
print GDBCMD "set args $cmdargs\n"; print GDBCMD "set args $cmdargs\n";
print GDBCMD "show args\n"; print GDBCMD "show args\n";
close(GDBCMD); close(GDBCMD);
}
# run the command line we built
if ($torture) {
torture($CMDLINE,
"gdb --directory libtest $DBGCURL -x log/gdbcmd");
}
elsif($gdbthis) {
system("gdb --directory libtest $DBGCURL -x log/gdbcmd"); system("gdb --directory libtest $DBGCURL -x log/gdbcmd");
$cmdres=0; # makes it always continue after a debugged run $cmdres=0; # makes it always continue after a debugged run
} }
@ -1466,9 +1452,7 @@ do {
# torture # torture
$torture=1; $torture=1;
my $xtra = $1; my $xtra = $1;
if($xtra =~ s/^(\d+)//) {
$tortnum = $1;
}
if($xtra =~ s/(\d+)$//) { if($xtra =~ s/(\d+)$//) {
$tortalloc = $1; $tortalloc = $1;
} }
@ -1584,11 +1568,6 @@ open(CMDLOG, ">$CURLLOG") ||
print "can't log command lines to $CURLLOG\n"; print "can't log command lines to $CURLLOG\n";
####################################################################### #######################################################################
# Torture the memory allocation system and checks
#
if($torture) {
&torture();
}
sub displaylogcontent { sub displaylogcontent {
my ($file)=@_; my ($file)=@_;