Skip to content
runtests.pl 103 KiB
Newer Older
  [!keyword] like "!cookies" to disable any tests containing the key word
        $number = $1;
        if($fromnum >= 0) {
            for($fromnum .. $number) {
                push @testthis, $_;
            }
            $fromnum = -1;
        }
        else {
            push @testthis, $1;
        }
    }
    elsif($ARGV[0] =~ /^to$/i) {
        $fromnum = $number+1;
    elsif($ARGV[0] =~ /^!(\d+)/) {
        $fromnum = -1;
        $disabled{$1}=$1;
    }
    elsif($ARGV[0] =~ /^!(.+)/) {
        $disabled_keywords{$1}=$1;
    }
    elsif($ARGV[0] =~ /^([-[{a-zA-Z].*)/) {
        $enabled_keywords{$1}=$1;
    }
    else {
    	print "Unknown option: $ARGV[0]\n";
    	exit;
    }
    shift @ARGV;
} 
if($testthis[0] ne "") {
    $TESTCASES=join(" ", @testthis);
}

if($valgrind) {
    # we have found valgrind on the host, use it

    # verify that we can invoke it fine
    my $code = runclient("valgrind >/dev/null 2>&1");

    if(($code>>8) != 1) {
        #logmsg "Valgrind failure, disable it\n";
        undef $valgrind;
    } else {

	# since valgrind 2.1.x, '--tool' option is mandatory
	# use it, if it is supported by the version installed on the system
	runclient("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1");
	if (($? >> 8)==0) {
	    $valgrind_tool="--tool=memcheck ";
	}
	open(C, "<$CURL");
	my $l = <C>;
	if($l =~ /^\#\!/) {
	    # A shell script. This is typically when built with libtool,
	    $valgrind="../libtool --mode=execute $valgrind";
	}
	close(C);

	# valgrind 3 renamed the --logfile option to --log-file!!!
	my $ver=join(' ', runclientoutput("valgrind --version"));
	# cut off all but digits and dots
	$ver =~ s/[^0-9.]//g;

	if($ver >= 3) {
	    $valgrind_logfile="--log-file";
	}
if ($gdbthis) {
    # open the executable curl and read the first 4 bytes of it
    open(CHECK, "<$CURL");
    my $c;
    sysread CHECK, $c, 4;
    close(CHECK);
    if($c eq "#! /") {
	# A shell script. This is typically when built with libtool,
	$libtool = 1;
	$gdb = "libtool --mode=execute gdb";
    }
$HTTPPORT =  $base++; # HTTP server port
$HTTPSPORT = $base++; # HTTPS server port
$FTPPORT =   $base++; # FTP server port
$FTPSPORT =  $base++; # FTPS server port
$HTTP6PORT = $base++; # HTTP IPv6 server port (different IP protocol
                        # but we follow the same port scheme anyway)
$FTP2PORT =  $base++; # FTP server 2 port
$FTP6PORT =  $base++; # FTP IPv6 port
$TFTPPORT =  $base++; # TFTP (UDP) port
$TFTP6PORT = $base++; # TFTP IPv6 (UDP) port
$SSHPORT =   $base++; # SSH (SCP/SFTP) port
$SOCKSPORT = $base++; # SOCKS port
$POP3PORT =  $base++;
$IMAPPORT =  $base++;
$SMTPPORT =  $base++;
#######################################################################
# clear and create logging directory:
#

cleardir($LOGDIR);
mkdir($LOGDIR, 0777);

#######################################################################
# Output curl version and host info being tested
#

if(!$listonly) {

#######################################################################
# If 'all' tests are requested, find out all test numbers
#

if ( $TESTCASES eq "all") {
    # Get all commands and find out their test numbers
    opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
    my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
    closedir(DIR);
    open(D, "<$TESTDIR/DISABLED");
        if(/^ *\#/) {
            # allow comments
            next;
        }
        if($_ =~ /(\d+)/) {
            $disabled{$1}=$1; # disable this test number
    $TESTCASES=""; # start with no test cases

    # cut off everything but the digits
    # sort the numbers from low to high
    foreach my $n (sort { $a <=> $b } @cmds) {
            $skipped++;
            $skipped{$why}++;
            $teststat[$n]=$why; # store reason for this test case
        $TESTCASES .= " $n";
#######################################################################
# Start the command line log
#
open(CMDLOG, ">$CURLLOG") ||
    logmsg "can't log command lines to $CURLLOG\n";
#######################################################################
# Display the contents of the given file.  Line endings are canonicalized
# and excessively long files are elided
    if(open(SINGLE, "<$file")) {
        while(my $string = <SINGLE>) {
            $string =~ s/\r\n/\n/g;
            $string =~ s/[\r\f\032]/\n/g;
            $string .= "\n" unless ($string =~ /\n$/);
            $string =~ tr/\n//;
	    for my $line (split("\n", $string)) {
		$line =~ s/\s*\!$//;
		if ($truncate) {
		    push @tail, " $line\n";
		} else {
		    logmsg " $line\n";
		}
		$linecount++;
		$truncate = $linecount > 1000;
	    }
        }
        if (@tail) {
            logmsg "=== File too long: lines here were removed\n";
            # This won't work properly if time stamps are enabled in logmsg
            logmsg join('',@tail[$#tail-200..$#tail]);
    opendir(DIR, "$LOGDIR") ||
    my @logs = readdir(DIR);
    closedir(DIR);
    logmsg "== Contents of files in the $LOGDIR/ dir after test $testnum\n";
    foreach my $log (sort @logs) {
        if($log =~ /\.(\.|)$/) {
            next; # skip "." and ".."
        }
        if($log =~ /^\.nfs/) {
            next; # skip ".nfs"
        }
        if(($log eq "memdump") || ($log eq "core")) {
            next; # skip "memdump" and  "core"
        }
        if((-d "$LOGDIR/$log") || (! -s "$LOGDIR/$log")) {
            next; # skip directory and empty files
        }
        if(($log =~ /^stdout\d+/) && ($log !~ /^stdout$testnum/)) {
            next; # skip stdoutNnn of other tests
        }
        if(($log =~ /^stderr\d+/) && ($log !~ /^stderr$testnum/)) {
            next; # skip stderrNnn of other tests
        }
        if(($log =~ /^upload\d+/) && ($log !~ /^upload$testnum/)) {
            next; # skip uploadNnn of other tests
        }
        if(($log =~ /^curl\d+\.out/) && ($log !~ /^curl$testnum\.out/)) {
            next; # skip curlNnn.out of other tests
        }
        if(($log =~ /^test\d+\.txt/) && ($log !~ /^test$testnum\.txt/)) {
            next; # skip testNnn.txt of other tests
        if(($log =~ /^file\d+\.txt/) && ($log !~ /^file$testnum\.txt/)) {
            next; # skip fileNnn.txt of other tests
        }
        if(($log =~ /^valgrind\d+/) && ($log !~ /^valgrind$testnum/)) {
            next; # skip valgrindNnn of other tests
        }
        logmsg "=== Start of file $log\n";
        displaylogcontent("$LOGDIR/$log");
        logmsg "=== End of file $log\n";
#######################################################################
# The main test-loop
#

Daniel Stenberg's avatar
Daniel Stenberg committed
my $testnum;
    $lasttest = $testnum if($testnum > $lasttest);
    my $error = singletest($testnum, $count, scalar(@at));
        $failed.= "$testnum ";
        if($postmortem) {
            # display all files in log/ in a nice way
        if(!$anyway) {
            # a test failed, abort
            logmsg "\n - abort tests\n";
#######################################################################
# Close command log
#
stopservers($verbose);
    logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
                   $ok/$total*100);
        logmsg "TESTFAIL: These test cases failed: $failed\n";
    logmsg "TESTFAIL: No tests were performed\n";
    logmsg "TESTDONE: $all tests were considered during ".
        sprintf("%.0f", $sofar) ." seconds.\n";
if($skipped) {
    logmsg "TESTINFO: $skipped tests were skipped due to these restraints:\n";
        printf "TESTINFO: \"%s\" %d times (", $r, $skipped{$_};

        # now show all test case numbers that had this reason for being
        # skipped
        my $c=0;
                logmsg ", " if($c);
                logmsg $_;
if($timestats) {
Yang Tse's avatar
 
Yang Tse committed
    logmsg "\nTest suite total running time breakdown per task...\n\n";
    my @timetool;
    my @timelock;
Yang Tse's avatar
 
Yang Tse committed
    my @timevrfy;
    my $timesrvrtot = 0.0;
    my $timepreptot = 0.0;
    my $timetooltot = 0.0;
    my $timelocktot = 0.0;
Yang Tse's avatar
 
Yang Tse committed
    my $timevrfytot = 0.0;
    my $timetesttot = 0.0;
Yang Tse's avatar
 
Yang Tse committed
    my $counter;

    for my $testnum (1 .. $lasttest) {
        if($timesrvrini{$testnum}) {
            $timesrvrtot += $timesrvrend{$testnum} - $timesrvrini{$testnum};
            $timepreptot +=
                (($timetoolini{$testnum} - $timeprepini{$testnum}) -
                 ($timesrvrend{$testnum} - $timesrvrini{$testnum}));
            $timetooltot += $timetoolend{$testnum} - $timetoolini{$testnum};
            $timelocktot += $timesrvrlog{$testnum} - $timetoolend{$testnum};
Yang Tse's avatar
 
Yang Tse committed
            $timevrfytot += $timevrfyend{$testnum} - $timesrvrlog{$testnum};
            $timetesttot += $timevrfyend{$testnum} - $timeprepini{$testnum};
            push @timesrvr, sprintf("%06.3f  %04d",
                $timesrvrend{$testnum} - $timesrvrini{$testnum}, $testnum);
            push @timeprep, sprintf("%06.3f  %04d",
                ($timetoolini{$testnum} - $timeprepini{$testnum}) -
                ($timesrvrend{$testnum} - $timesrvrini{$testnum}), $testnum);
            push @timetool, sprintf("%06.3f  %04d",
                $timetoolend{$testnum} - $timetoolini{$testnum}, $testnum);
            push @timelock, sprintf("%06.3f  %04d",
                $timesrvrlog{$testnum} - $timetoolend{$testnum}, $testnum);
Yang Tse's avatar
 
Yang Tse committed
            push @timevrfy, sprintf("%06.3f  %04d",
                $timevrfyend{$testnum} - $timesrvrlog{$testnum}, $testnum);
            push @timetest, sprintf("%06.3f  %04d",
Yang Tse's avatar
 
Yang Tse committed
                $timevrfyend{$testnum} - $timeprepini{$testnum}, $testnum);
    @timesrvr = sort { $b <=> $a } @timesrvr;
    @timeprep = sort { $b <=> $a } @timeprep;
    @timetool = sort { $b <=> $a } @timetool;
    @timelock = sort { $b <=> $a } @timelock;
Yang Tse's avatar
 
Yang Tse committed
    @timevrfy = sort { $b <=> $a } @timevrfy;
    @timetest = sort { $b <=> $a } @timetest;

Yang Tse's avatar
 
Yang Tse committed
    logmsg "Spent ". sprintf("%08.3f ", $timesrvrtot) .
           "seconds starting and verifying test harness servers.\n";
    logmsg "Spent ". sprintf("%08.3f ", $timepreptot) .
           "seconds reading definitions and doing test preparations.\n";
    logmsg "Spent ". sprintf("%08.3f ", $timetooltot) .
           "seconds actually running test tools.\n";
    logmsg "Spent ". sprintf("%08.3f ", $timelocktot) .
           "seconds awaiting server logs lock removal.\n";
    logmsg "Spent ". sprintf("%08.3f ", $timevrfytot) .
           "seconds verifying test results.\n";
    logmsg "Spent ". sprintf("%08.3f ", $timetesttot) .
           "seconds doing all of the above.\n";

    $counter = 25;
    logmsg "\nTest server starting and verification time per test ".
        sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
    logmsg "-time-  test\n";
    logmsg "------  ----\n";
    foreach my $txt (@timesrvr) {
Yang Tse's avatar
 
Yang Tse committed
        last if((not $fullstats) && (not $counter--));
Yang Tse's avatar
 
Yang Tse committed
    $counter = 25;
    logmsg "\nTest definition reading and preparation time per test ".
        sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
    logmsg "-time-  test\n";
    logmsg "------  ----\n";
    foreach my $txt (@timeprep) {
Yang Tse's avatar
 
Yang Tse committed
        last if((not $fullstats) && (not $counter--));
Yang Tse's avatar
 
Yang Tse committed
    $counter = 25;
    logmsg "\nTest tool execution time per test ".
        sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
    logmsg "-time-  test\n";
    logmsg "------  ----\n";
    foreach my $txt (@timetool) {
Yang Tse's avatar
 
Yang Tse committed
        last if((not $fullstats) && (not $counter--));
Yang Tse's avatar
 
Yang Tse committed
    $counter = 25;
    logmsg "\nTest server logs lock removal time per test ".
        sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
    logmsg "-time-  test\n";
    logmsg "------  ----\n";
    foreach my $txt (@timelock) {
Yang Tse's avatar
 
Yang Tse committed
        last if((not $fullstats) && (not $counter--));
Yang Tse's avatar
 
Yang Tse committed
    $counter = 25;
    logmsg "\nTest results verification time per test ".
        sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
    logmsg "-time-  test\n";
    logmsg "------  ----\n";
    foreach my $txt (@timevrfy) {
        last if((not $fullstats) && (not $counter--));
        logmsg "$txt\n";
    }

    $counter = 50;
    logmsg "\nAggregated time per test ".
        sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
    logmsg "-time-  test\n";
    logmsg "------  ----\n";
    foreach my $txt (@timetest) {
Yang Tse's avatar
 
Yang Tse committed
        last if((not $fullstats) && (not $counter--));
Yang Tse's avatar
 
Yang Tse committed

    logmsg "\n";
if($total && ($ok != $total)) {
    exit 1;
}