Skip to content
runtests.pl 31.7 KiB
Newer Older
Daniel Stenberg's avatar
Daniel Stenberg committed
#!/usr/bin/env perl
Daniel Stenberg's avatar
Daniel Stenberg committed
# $Id$
#
# Main curl test script, in perl to run on more platforms
#
#######################################################################
# These should be the only variables that might be needed to get edited:

require "stunnel.pm"; # stunnel functions
require "getpart.pm"; # array functions
Daniel Stenberg's avatar
Daniel Stenberg committed
my $HOSTIP="127.0.0.1";
my $HOSTPORT=8999; # bad name, but this is the HTTP server port
my $HTTPSPORT=8433; # this is the HTTPS server port
my $FTPPORT=8921;  # this is the FTP server port
my $FTPSPORT=8821;  # this is the FTPS server port
my $CURL="../src/curl"; # what curl executable to run on the tests
my $DBGCURL=$CURL; #"../src/.libs/curl";  # alternative for debugging
Daniel Stenberg's avatar
Daniel Stenberg committed
my $LOGDIR="log";
my $TESTDIR="data";
my $LIBDIR="./libtest";
my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
my $CURLLOG="$LOGDIR/curl.log"; # all command lines run
my $FTPDCMD="$LOGDIR/ftpserver.cmd"; # copy ftp server instructions here

# Normally, all test cases should be run, but at times it is handy to
# simply run a particular one:
Daniel Stenberg's avatar
Daniel Stenberg committed
my $TESTCASES="all";

# To run specific test cases, set them like:
# $TESTCASES="1 2 3 7 8";

#######################################################################
# No variables below this point should need to be modified
#

my $HTTPSPIDFILE=".https.pid";
my $FTPPIDFILE=".ftp.pid";
my $FTPSPIDFILE=".ftps.pid";
# invoke perl like this:
my $perl="perl -I$srcdir";

# this gets set if curl is compiled with debugging:
my $curl_debug=0;
# name of the file that the memory debugging creates:
my $memdump="memdump";

# the path to the script that analyzes the memory debug output file:
my $memanalyze="./memanalyze.pl";
my $checkstunnel = &checkstunnel;

my $ssl_version; # set if libcurl is built with SSL support

my $skipped=0;  # number of tests skipped; reported in main loop
my %skipped;    # skipped{reason}=counter, reasons for skip
my @teststat;   # teststat[testnum]=reason, reasons for skip
Daniel Stenberg's avatar
Daniel Stenberg committed
#######################################################################
# variables the command line options may set
#

my $short;
my $verbose;
Daniel Stenberg's avatar
Daniel Stenberg committed
my $anyway;
my $gdbthis;      # run test case with gdb debugger
my $keepoutfiles; # keep stdout and stderr files after tests
Daniel Stenberg's avatar
Daniel Stenberg committed
my $listonly;     # only list the tests

my $pwd;          # current working directory

my %run;	  # running server

# enable memory debugging if curl is compiled with it
$ENV{'CURL_MEMDEBUG'} = 1;
#######################################################################
# Return the pid of the server as found in the given pid file
    my $PIDFILE = $_[0];
    close(PFILE);
    return $PID;
}

#######################################################################
# stop the given test server
sub stopserver {
    # check for pidfile
    if ( -f $pid ) {
        my $PIDFILE = $pid;
        $pid = serverpid($PIDFILE);
        unlink $PIDFILE; # server is killed
    }
    elsif($pid <= 0) {
        return; # this is not a good pid
    }
    my $res = kill (9, $pid); # die!

    if($res && $verbose) {
        print "RUN: Test server pid $pid signalled to die\n";
    }
    elsif($verbose) {
        print "RUN: Test server pid $pid didn't exist\n";
#######################################################################
# check the given test server if it is still alive
sub checkserver {
    my ($pidfile)=@_;
    # check for pidfile
    if ( -f $pidfile ) {
        $pid=serverpid($pidfile);
        if ($pid ne "" && kill(0, $pid)) {
            return $pid;
            return -$pid; # negative means dead process
}

#######################################################################
# start the http server, or if it already runs, verify that it is our
# test server on the test-port!
#
sub runhttpserver {
    my $verbose = $_[0];
    my $RUNNING;
    $pid = checkserver ($HTTPPIDFILE);

    # verify if our/any server is running on this port
    my $cmd = "$CURL -o log/verifiedserver --silent -i $HOSTIP:$HOSTPORT/verifiedserver 2>/dev/null";
Daniel Stenberg's avatar
Daniel Stenberg committed
    print "CMD; $cmd\n" if ($verbose);
Daniel Stenberg's avatar
Daniel Stenberg committed

    print "RUN: curl command returned $res\n" if ($verbose);
Daniel Stenberg's avatar
Daniel Stenberg committed

    open(FILE, "<log/verifiedserver");
    my @file=<FILE>;
    close(FILE);
    $data=$file[0]; # first line

    if ( $data =~ /WE ROOLZ: (\d+)/ ) {
        $pid = 0+$1;
    elsif($data) {
        print "RUN: Unknown HTTP server is running on port $HOSTPORT\n";
        my $res = kill (9, $pid); # die!
        if(!$res) {
            print "RUN: Failed to kill test HTTP server, do it manually and",
    $cmd="$perl $srcdir/httpserver.pl $flag $HOSTPORT &";
    system($cmd);
    if($verbose) {
        print "CMD: $cmd\n";
    my $verified;
    for(1 .. 5) {
        # verify that our server is up and running:
        my $data=`$CURL --silent -i $HOSTIP:$HOSTPORT/verifiedserver 2>/dev/null`;
Loading
Loading full blame…