Commit e18d27b7 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

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.
parent 228fea46
Loading
Loading
Loading
Loading
+79 −100
Original line number Diff line number Diff line
@@ -155,44 +155,15 @@ sub serverpid {
# Memory allocation test and failure torture testing.
#
sub torture {
    # start all test servers (http, https, ftp, ftps)
    &startservers(("http", "https", "ftp", "ftps"));
    my $c;
    my $testcmd = shift;
    my $gdbline = shift;

    my @test=('http://%HOSTIP:%HOSTPORT/1',
              'ftp://%HOSTIP:%FTPPORT/1',
              'http://%HOSTIP:%HOSTPORT/3 -d "poo"');
    
    # loop over the different tests commands
    for(@test) {
        my $cmdargs = "$_";

        $c++;

        if($tortnum && ($tortnum != $c)) {
            next;
        }
        print "We want test $c\n";

        my $redir=">log/torture.stdout 2>log/torture.stderr";

        subVariables(\$cmdargs);

        my $testcmd = "$CURL $cmdargs $redir";
    # remove memdump first to be sure we get a new nice and clean one
    unlink($memdump);

    # 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
@@ -204,22 +175,19 @@ sub torture {
            last;
        }
    }
        if(!$count) {
            # hm, no allocations in this fetch, ignore and get next
            print "BEEEP, no allocs found for test $c!!!\n";
            next;
        }
        print " $count allocations to excersize\n";

    print " $count allocations to make fail\n";

    for ( 1 .. $count ) {
        my $limit = $_;
        my $fail;
        my $dumped_core;
        
        if($tortalloc && ($tortalloc != $limit)) {
            next;
        }

            print "Alloc no: $limit\r" if(!$gdbthis);
        print "Fail alloc no: $limit\r" if(!$gdbthis);
            
        # make the memory allocation function number $limit return failure
        $ENV{'CURL_MEMLIMIT'} = $limit;
@@ -229,7 +197,20 @@ sub torture {
        
        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);
        }

        if(-r "core") {
            # there's core file present now!
            print " core dumped!\n";
            $dumped_core = 1;
            $fail = 2;
        }

        # verify that it returns a proper error code, doesn't leak memory
        # and doesn't core dump
@@ -255,16 +236,13 @@ sub torture {
            }
        }
        if($fail) {
                print " Failed on alloc number $limit in test $c.\n",
                " invoke with -t$c,$limit to repeat this single case.\n";
            print " Failed on alloc number $limit in test.\n",
            " invoke with -t$limit to repeat this single case.\n";
            stopservers();
            exit 1;
        }
    }
        print "\n torture test $c did GOOD\n";

        # all is well, now test a different kind of URL
    }
    stopservers();
    exit; # for now, we stop after these tests
}
@@ -1051,12 +1029,20 @@ sub singletest {

    my $dumped_core;
    my $cmdres;
    # run the command line we built


    if($gdbthis) {
        open(GDBCMD, ">log/gdbcmd");
        print GDBCMD "set args $cmdargs\n";
        print GDBCMD "show args\n";
        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");
        $cmdres=0; # makes it always continue after a debugged run
    }
@@ -1466,9 +1452,7 @@ do {
        # torture
        $torture=1;
        my $xtra = $1;
        if($xtra =~ s/^(\d+)//) {
            $tortnum = $1;
        }

        if($xtra =~ s/(\d+)$//) {
            $tortalloc = $1;
        }
@@ -1584,11 +1568,6 @@ open(CMDLOG, ">$CURLLOG") ||
    print "can't log command lines to $CURLLOG\n";

#######################################################################
# Torture the memory allocation system and checks
#
if($torture) {
    &torture();
}

sub displaylogcontent {
    my ($file)=@_;