Skip to content
runtests.pl 59.7 KiB
Newer Older
  -g       run the test case with gdb
Daniel Stenberg's avatar
Daniel Stenberg committed
  -h       this help text
  -k       keep stdout and stderr files present after tests
Daniel Stenberg's avatar
Daniel Stenberg committed
  -l       list all test case names/descriptions
  -n       No valgrind
  -p       Print log file contents when a test fails
Daniel Stenberg's avatar
Daniel Stenberg committed
  -s       short output
Daniel Stenberg's avatar
Daniel Stenberg committed
  -v       verbose output
  [num]    like "5 6 9" or " 5 to 22 " to run those tests only
        $number = $1;
        if($fromnum >= 0) {
            for($fromnum .. $number) {
                push @testthis, $_;
            }
            $fromnum = -1;
        }
        else {
            push @testthis, $1;
        }
    }
    elsif($ARGV[0] =~ /^to$/i) {
        $fromnum = $number+1;
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 = system("valgrind >/dev/null 2>&1");

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

$HTTPPORT =  $base + 0; # HTTP server port
$HTTPSPORT = $base + 1; # HTTPS server port
$FTPPORT =   $base + 2; # FTP server port
$FTPSPORT =  $base + 3; # FTPS server port
$HTTP6PORT = $base + 4; # HTTP IPv6 server port (different IP protocol
                        # but we follow the same port scheme anyway)
$FTP2PORT =  $base + 5; # FTP server 2 port
$TFTPPORT =  $base + 7; # TFTP (UDP) port
$TFTP6PORT =  $base + 8; # TFTP IPv6 (UDP) port
#######################################################################
# 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);
    $TESTCASES=""; # start with no test cases

    # cut off everything but the digits
    }
    # the the numbers from low to high
    for(sort { $a <=> $b } @cmds) {
#######################################################################
# Start the command line log
#
open(CMDLOG, ">$CURLLOG") ||
    logmsg "can't log command lines to $CURLLOG\n";
#######################################################################

sub displaylogcontent {
    my ($file)=@_;
    open(SINGLE, "<$file");
    while(<SINGLE>) {
    opendir(DIR, "$LOGDIR") ||
        die "can't open dir: $!";
    my @logs = readdir(DIR);
    closedir DIR;
    my $log;
    logmsg "== Contents of files in the log/ dir after test $testnum\n";
        # the log file is not "." or ".." and contains more than zero bytes
        if(($log !~ /\.(\.|)$/) &&
           ($log ne "memdump") && # and not "memdump"
           -s "$LOGDIR/$log") {
            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
#
close(CMDLOG);

    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 $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;
        for(0 .. $lasttest) {
            my $t = $_;
            if($teststat[$_] eq $r) {
                logmsg ", " if($c);
                logmsg $_;
if($total && ($ok != $total)) {
    exit 1;
}