Newer
Older
elsif($f eq "GnuTLS") {
if($has_gnutls) {
next;
}
}
elsif($f eq "netrc_debug") {
if($curl_debug) {
next;
}
}
elsif($f eq "large_file") {
if($large_file) {
next;
}
}
Daniel Stenberg
committed
elsif($f eq "idn") {
if($has_idn) {
next;
}
}
elsif($f eq "ipv6") {
if($has_ipv6) {
next;
}
}
elsif($f eq "libz") {
if($has_libz) {
next;
}
}
Daniel Stenberg
committed
elsif($f eq "NTLM") {
if($has_ntlm) {
next;
}
}
elsif($f eq "getrlimit") {
if($has_getrlimit) {
next;
}
}
Daniel Stenberg
committed
$why = "curl lacks $f support";
last;
}
Daniel Stenberg
committed
if(!$why) {
$why = serverfortest($testnum);
}
Daniel Stenberg
committed
if(!$why) {
Daniel Stenberg
committed
my @precheck = getpart("client", "precheck");
Daniel Stenberg
committed
$cmd = $precheck[0];
Daniel Stenberg
committed
chomp $cmd;
if($cmd) {
my @o = `$cmd 2>/dev/null`;
if($o[0]) {
$why = $o[0];
chomp $why;
}
}
}
Daniel Stenberg
committed
if($why) {
# there's a problem, count it as "skipped"
$skipped++;
$skipped{$why}++;
$teststat[$testnum]=$why; # store reason for this test case
if(!$short) {
Daniel Stenberg
committed
printf "test %03d SKIPPED: $why\n", $testnum;
}
return -1;
}
Daniel Stenberg
committed
printf("test %03d...", $testnum);
# extract the reply data
my @reply = getpart("reply", "data");
my @replycheck = getpart("reply", "datacheck");
if (@replycheck) {
# we use this file instead to check the final output against
my %hash = getpartattr("reply", "datacheck");
if($hash{'nonewline'}) {
# Yes, we must cut off the final newline from the final line
# of the datacheck
chomp($replycheck[$#replycheck]);
}
Daniel Stenberg
committed
my @curlcmd= fixarray ( getpart("client", "command") );
# this is the valid protocol blurb curl should generate
Daniel Stenberg
committed
my @protocol= fixarray ( getpart("verify", "protocol") );
# redirected stdout/stderr to these files
$STDOUT="$LOGDIR/stdout$testnum";
$STDERR="$LOGDIR/stderr$testnum";
# if this section exists, we verify that the stdout contained this:
Daniel Stenberg
committed
my @validstdout = fixarray ( getpart("verify", "stdout") );
# if this section exists, we verify upload
my @upload = getpart("verify", "upload");
# if this section exists, it might be FTP server instructions:
my @ftpservercmd = getpart("reply", "servercmd");
my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout
my @testname= getpart("client", "name");
if(!$short) {
my $name = $testname[0];
$name =~ s/\n//g;
print "[$name]\n";
}
if($listonly) {
return 0; # look successful
}
my @codepieces = getpart("client", "tool");
my $tool="";
if(@codepieces) {
$tool = $codepieces[0];
chomp $tool;
}
Daniel Stenberg
committed
# remove server output logfiles
Daniel Stenberg
committed
unlink($SERVER2IN);
if(@ftpservercmd) {
# write the instructions to file
writearray($FTPDCMD, \@ftpservercmd);
}
my (@setenv)= getpart("client", "setenv");
my @envs;
my $s;
for $s (@setenv) {
chomp $s; # cut off the newline
subVariables \$s;
if($s =~ /([^=]*)=(.*)/) {
my ($var, $content)=($1, $2);
$ENV{$var}=$content;
# remember which, so that we can clear them afterwards!
push @envs, $var;
}
}
Daniel Stenberg
committed
my @blaha;
($cmd, @blaha)= getpart("client", "command");
# make some nice replace operations
$cmd =~ s/\n//g; # no newlines please
if($curl_debug) {
unlink($memdump);
}
my @inputfile=getpart("client", "file");
if(@inputfile) {
# we need to generate a file before this test is invoked
Daniel Stenberg
committed
my %fileattr = getpartattr("client", "file");
Daniel Stenberg
committed
my $filename=$fileattr{'name'};
if(!$filename) {
print "ERROR: section client=>file has no name attribute!\n";
exit;
}
my $fileContent = join('', @inputfile);
subVariables \$fileContent;
# print "DEBUG: writing file " . $filename . "\n";
open OUTFILE, ">$filename";
binmode OUTFILE; # for crapage systems, use binary
print OUTFILE $fileContent;
my %cmdhash = getpartattr("client", "command");
if($cmdhash{'option'} !~ /no-output/) {
#We may slap on --output!
$out=" --output $CURLOUT ";
my $cmdargs;
if(!$tool) {
# run curl, add -v for debug information output
$cmdargs ="$out --include -v --trace-time $cmd";
}
else {
$cmdargs = " $cmd"; # $cmd is the command line for the test file
$CURLOUT = $STDOUT; # sends received data to stdout
}
my @stdintest = getpart("client", "stdin");
if(@stdintest) {
my $stdinfile="$LOGDIR/stdin-for-$testnum";
writearray($stdinfile, \@stdintest);
$cmdargs .= " <$stdinfile";
if(!$tool) {
$CMDLINE="$CURL";
else {
$CMDLINE="$LIBDIR/$tool";
if($valgrind) {
$CMDLINE = "valgrind ".$valgrind_tool."--leak-check=yes --num-callers=16 --logfile=log/valgrind$testnum $CMDLINE";
}
Daniel Stenberg
committed
}
print CMDLOG "$CMDLINE\n";
Daniel Stenberg
committed
unlink("core");
my $dumped_core;
my $cmdres;
my @precommand= getpart("client", "precommand");
if($precommand[0]) {
# this is pure perl to eval!
my $code = join("", @precommand);
eval $code;
if($@) {
print "perl: $code\n";
print "precommand: $@";
stopservers($verbose);
exit;
}
}
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) {
Daniel Stenberg
committed
return 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
$cmdres = system("$CMDLINE");
my $signal_num = $cmdres & 127;
Daniel Stenberg
committed
$dumped_core = $cmdres & 128;
if(!$anyway && ($signal_num || $dumped_core)) {
$cmdres = 1000;
}
else {
$cmdres /= 256;
}
Daniel Stenberg
committed
if(!$dumped_core) {
if(-r "core") {
# there's core file present now!
$dumped_core = 1;
}
}
if($dumped_core) {
print "core dumped!\n";
Daniel Stenberg
committed
print "running gdb for post-mortem analysis:\n";
open(GDBCMD, ">log/gdbcmd2");
print GDBCMD "bt\n";
close(GDBCMD);
system("gdb --directory libtest -x log/gdbcmd2 -batch $DBGCURL core ");
# unlink("log/gdbcmd2");
}
}
# remove the special FTP command file after each test!
unlink($FTPDCMD);
my $e;
for $e (@envs) {
$ENV{$e}=""; # clean up
}
my @err = getpart("verify", "errorcode");
my $errorcode = $err[0] || "0";
my $ok="";
my $res;
if (@validstdout) {
# verify redirected stdout
my @actual = loadarray($STDOUT);
$res = compare("stdout", \@actual, \@validstdout);
return 1;
}
$ok .= "s";
}
else {
$ok .= "-"; # stdout not checked
my %replyattr = getpartattr("reply", "data");
Daniel Stenberg
committed
if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
# verify the received data
my @out = loadarray($CURLOUT);
$res = compare("data", \@out, \@reply);
return 1;
}
$ok .= "d";
}
else {
$ok .= "-"; # data not checked
if(@upload) {
# verify uploaded data
my @out = loadarray("$LOGDIR/upload.$testnum");
$res = compare("upload", \@out, \@upload);
}
$ok .= "u";
}
else {
$ok .= "-"; # upload not checked
Daniel Stenberg
committed
my @out;
my $retry = 5;
# Verify the sent request. Sometimes, like in test 513 on some hosts,
# curl will return back faster than the server writes down the request
# to its file, so we might need to wait here for a while to see if the
# file gets written a bit later.
while($retry--) {
@out = loadarray($SERVERIN);
if(!$out[0]) {
# nothing there yet, wait a while and try again
sleep(1);
}
}
# what to cut off from the live protocol sent by curl
my @strip = getpart("verify", "strip");
# check if there's any attributes on the verify/protocol section
my %hash = getpartattr("verify", "protocol");
if($hash{'nonewline'}) {
# Yes, we must cut off the final newline from the final line
# of the protocol data
chomp($protstrip[$#protstrip]);
}
Daniel Stenberg
committed
# strip off all lines that match the patterns from both arrays
@out = striparray( $_, \@out);
@protstrip= striparray( $_, \@protstrip);
}
# what parts to cut off from the protocol
my @strippart = getpart("verify", "strippart");
my $strip;
for $strip (@strippart) {
chomp $strip;
for(@out) {
eval $strip;
}
}
$res = compare("protocol", \@out, \@protstrip);
if($res) {
return 1;
}
$ok .= "p";
}
else {
$ok .= "-"; # protocol not checked
}
my @outfile=getpart("verify", "file");
if(@outfile) {
# we're supposed to verify a dynamicly generated file!
my %hash = getpartattr("verify", "file");
my $filename=$hash{'name'};
if(!$filename) {
print "ERROR: section verify=>file has no name attribute!\n";
stopservers($verbose);
my $filemode=$hash{'mode'};
my @generated=loadarray($filename);
Daniel Stenberg
committed
# what parts to cut off from the file
my @stripfile = getpart("verify", "stripfile");
if(($filemode eq "text") && $has_textaware) {
# text mode when running on windows means adding an extra
# strip expression
push @stripfile, "s/\r\n/\n/";
}
Daniel Stenberg
committed
my $strip;
for $strip (@stripfile) {
chomp $strip;
for(@generated) {
eval $strip;
}
}
$res = compare("output", \@generated, \@outfile);
if($res) {
return 1;
}
$ok .= "o";
}
else {
$ok .= "-"; # output not checked
# accept multiple comma-separated error codes
my @splerr = split(/ *, */, $errorcode);
my $errok;
foreach $e (@splerr) {
if($e == $cmdres) {
# a fine error code
$errok = 1;
last;
}
}
if($errok) {
$ok .= "e";
Daniel Stenberg
committed
}
else {
if(!$short) {
printf "\ncurl returned $cmdres, %s was expected\n", $errorcode;
}
Daniel Stenberg
committed
print " exit FAILED\n";
return 1;
}
@what = getpart("client", "killserver");
for(@what) {
my $serv = $_;
chomp $serv;
if($run{$serv}) {
stopserver($run{$serv}); # the pid file is in the hash table
$run{$serv}=0; # clear pid
}
else {
print STDERR "RUN: The $serv server is not running\n";
}
}
if($curl_debug) {
if(! -f $memdump) {
print "\n** ALERT! memory debuggin without any output file?\n";
}
else {
my @memdata=`$memanalyze $memdump`;
my $leak=0;
for(@memdata) {
if($_ ne "") {
# well it could be other memory problems as well, but
# we call it leak for short here
$leak=1;
}
}
if($leak) {
print "\n** MEMORY FAILURE\n";
print @memdata;
return 1;
}
else {
$ok .= "m";
Daniel Stenberg
committed
}
else {
$ok .= "-"; # memory not checked
}
Daniel Stenberg
committed
if($valgrind) {
Daniel Stenberg
committed
# this is the valid protocol blurb curl should generate
my @disable= getpart("verify", "valgrind");
if($disable[0] !~ /disable/) {
opendir(DIR, "log") ||
return 0; # can't open log dir
my @files = readdir(DIR);
closedir DIR;
my $f;
my $l;
foreach $f (@files) {
if($f =~ /^valgrind$testnum\.pid/) {
$l = $f;
last;
Daniel Stenberg
committed
}
Daniel Stenberg
committed
}
my $src=$ENV{'srcdir'};
if(!$src) {
$src=".";
}
my @e = valgrindparse($src, $feature{'SSL'}, "log/$l");
if($e[0]) {
Daniel Stenberg
committed
print " valgrind ERROR ";
print @e;
Daniel Stenberg
committed
return 1;
}
$ok .= "v";
Daniel Stenberg
committed
}
Daniel Stenberg
committed
else {
if(!$short) {
print " valgrind SKIPPED";
}
$ok .= "-"; # skipped
Daniel Stenberg
committed
}
else {
$ok .= "-"; # valgrind not checked
print "$ok " if(!$short);
my $sofar= time()-$start;
my $esttotal = $sofar/$count * $total;
my $estleft = $esttotal - $sofar;
my $left=sprintf("remaining: %dm%ds",
$estleft/60,
$estleft%60);
printf "OK ($count out of $total, %s)\n", $left;
Daniel Stenberg
committed
# the test succeeded, remove all log files
if(!$keepoutfiles) {
cleardir($LOGDIR);
}
unlink($FTPDCMD); # remove the instructions for this test
#######################################################################
# Stop all running test servers
sub stopservers {
my ($verbose)=@_;
for(keys %run) {
Daniel Stenberg
committed
my $server = $_;
my $pids=$run{$server};
my $pid;
foreach $pid (split(" ", $pids)) {
Daniel Stenberg
committed
printf("* kill pid for %-5s => %-5d\n",
$server, $pid) if($verbose);
Daniel Stenberg
committed
stopserver($pid);
}
ftpkillslaves($verbose);
}
#######################################################################
# startservers() starts all the named servers
#
Daniel Stenberg
committed
# Returns: string with error reason or blank for success
sub startservers {
my @what = @_;
Daniel Stenberg
committed
my ($pid, $pid2);
for(@what) {
my $what = lc($_);
if($what eq "ftp") {
if(!$run{'ftp'}) {
Daniel Stenberg
committed
($pid, $pid2) = runftpserver("", $verbose);
if($pid <= 0) {
Daniel Stenberg
committed
return "failed starting FTP server";
Daniel Stenberg
committed
}
Daniel Stenberg
committed
printf ("* pid ftp => %-5d %-5d\n", $pid, $pid2) if($verbose);
$run{'ftp'}="$pid $pid2";
Daniel Stenberg
committed
elsif($what eq "ftp2") {
if(!$run{'ftp2'}) {
Daniel Stenberg
committed
($pid, $pid2) = runftpserver("2", $verbose);
Daniel Stenberg
committed
if($pid <= 0) {
return "failed starting FTP2 server";
}
Daniel Stenberg
committed
printf ("* pid ftp2 => %-5d %-5d\n", $pid, $pid2) if($verbose);
$run{'ftp2'}="$pid $pid2";
Daniel Stenberg
committed
}
}
Daniel Stenberg
committed
elsif($what eq "ftp-ipv6") {
if(!$run{'ftp-ipv6'}) {
Daniel Stenberg
committed
($pid, $pid2) = runftpserver("", $verbose, "ipv6");
Daniel Stenberg
committed
if($pid <= 0) {
return "failed starting FTP-ipv6 server";
}
Daniel Stenberg
committed
printf("* pid ftp-ipv6 => %-5d %-5d\n", $pid,
$pid2) if($verbose);
$run{'ftp-ipv6'}="$pid $pid2";
Daniel Stenberg
committed
}
}
elsif($what eq "http") {
if(!$run{'http'}) {
Daniel Stenberg
committed
($pid, $pid2) = runhttpserver($verbose);
if($pid <= 0) {
Daniel Stenberg
committed
return "failed starting HTTP server";
Daniel Stenberg
committed
printf ("* pid http => %-5d %-5d\n", $pid, $pid2) if($verbose);
$run{'http'}="$pid $pid2";
elsif($what eq "http-ipv6") {
if(!$run{'http-ipv6'}) {
Daniel Stenberg
committed
($pid, $pid2) = runhttpserver($verbose, "IPv6");
Daniel Stenberg
committed
return "failed starting IPv6 HTTP server";
Daniel Stenberg
committed
printf("* pid http-ipv6 => %-5d %-5d\n", $pid, $pid2)
if($verbose);
$run{'http-ipv6'}="$pid $pid2";
# we can't run ftps tests at all for the moment
return "test suite lacks FTPS support";
elsif($what eq "file") {
# we support it but have no server!
}
elsif($what eq "https") {
if(!$stunnel) {
# we can't run ftps tests without stunnel
return "no stunnel";
# we can't run ftps tests if libcurl is SSL-less
return "curl lacks SSL support";
}
if(!$run{'http'}) {
Daniel Stenberg
committed
($pid, $pid2) = runhttpserver($verbose);
if($pid <= 0) {
Daniel Stenberg
committed
return "failed starting HTTP server";
Daniel Stenberg
committed
}
Daniel Stenberg
committed
printf ("* pid http => %-5d %-5d\n", $pid, $pid2) if($verbose);
$run{'http'}="$pid $pid2";
Daniel Stenberg
committed
($pid, $pid2) = runhttpsserver($verbose);
if($pid <= 0) {
Daniel Stenberg
committed
return "failed starting HTTPS server (stunnel)";
}
Daniel Stenberg
committed
printf("* pid https => %-5d %-5d\n", $pid, $pid2)
if($verbose);
$run{'https'}="$pid $pid2";
Daniel Stenberg
committed
print "* starts no server\n" if ($verbose);
else {
warn "we don't support a server for $what";
return 0;
}
##############################################################################
# This function makes sure the right set of server is running for the
# specified test case. This is a useful design when we run single tests as not
# all servers need to run then!
#
Daniel Stenberg
committed
# Returns: a string, blank if everything is fine or a reason why it failed
#
sub serverfortest {
my ($testnum)=@_;
# load the test case file definition
if(loadtest("${TESTDIR}/test${testnum}")) {
if($verbose) {
# this is not a test
print "$testnum doesn't look like a test case!\n";
}
Daniel Stenberg
committed
return "no test";
}
my @what = getpart("client", "server");
if(!$what[0]) {
warn "Test case $testnum has no server(s) specified!";
Daniel Stenberg
committed
return "no server specified";
}
return &startservers(@what);
#######################################################################
# Check options to this test program
#
my $number=0;
my $fromnum=-1;
my @testthis;
do {
if ($ARGV[0] eq "-v") {
# verbose output
$verbose=1;
}
elsif ($ARGV[0] eq "-c") {
# use this path to curl instead of default
shift @ARGV;
}
elsif ($ARGV[0] eq "-d") {
# have the servers display protocol output
$debugprotocol=1;
}
elsif ($ARGV[0] eq "-g") {
# run this test with gdb
$gdbthis=1;
}
elsif($ARGV[0] eq "-s") {
# short output
$short=1;
}
elsif($ARGV[0] eq "-n") {
# no valgrind
undef $valgrind;
}
elsif($ARGV[0] =~ /^-t(.*)/) {
# torture
$torture=1;
my $xtra = $1;
if($xtra =~ s/(\d+)$//) {
$tortalloc = $1;
}
Daniel Stenberg
committed
# we undef valgrind to make this fly in comparison
undef $valgrind;
}
elsif($ARGV[0] eq "-a") {
# continue anyway, even if a test fail
$anyway=1;
}
Daniel Stenberg
committed
elsif($ARGV[0] eq "-p") {
$postmortem=1;
}
elsif($ARGV[0] eq "-l") {
# lists the test case names only
$listonly=1;
}
elsif($ARGV[0] eq "-k") {
# keep stdout and stderr files after tests
$keepoutfiles=1;
}
elsif($ARGV[0] eq "-h") {
# show help text
print <<EOHELP
-d display server debug info
-g run the test case with gdb
-k keep stdout and stderr files present after tests
Daniel Stenberg
committed
-p Print log file contents when a test fails
-t torture
[num] like "5 6 9" or " 5 to 22 " to run those tests only
elsif($ARGV[0] =~ /^(\d+)/) {
$number = $1;
if($fromnum >= 0) {
for($fromnum .. $number) {
push @testthis, $_;
}
$fromnum = -1;
}
else {
push @testthis, $1;
}
}
elsif($ARGV[0] =~ /^to$/i) {
}
} while(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 = system("valgrind >/dev/null 2>&1");
if(($code>>8) != 1) {
#print "Valgrind failure, disable it\n";
undef $valgrind;
}
}
Daniel Stenberg
committed
$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)
Daniel Stenberg
committed
$FTP2PORT = $base + 5; # FTP server 2 port
Daniel Stenberg
committed
$FTP6PORT = $base + 6; # FTP IPv6 port
Daniel Stenberg
committed
#######################################################################
# Output curl version and host info being tested
#
checksystem();
#######################################################################
# clear and create logging directory:
cleardir($LOGDIR);
mkdir($LOGDIR, 0777);
#######################################################################
# 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;
$TESTCASES=""; # start with no test cases
# cut off everything but the digits
for(@cmds) {
$_ =~ s/[a-z\/\.]*//g;
}
# the the numbers from low to high
for(sort { $a <=> $b } @cmds) {
$TESTCASES .= " $_";
}
#######################################################################
# Start the command line log
#
open(CMDLOG, ">$CURLLOG") ||
print "can't log command lines to $CURLLOG\n";
#######################################################################
Daniel Stenberg
committed
sub displaylogcontent {
my ($file)=@_;
open(SINGLE, "<$file");
while(<SINGLE>) {
print " $_";
}
close(SINGLE);
}
sub displaylogs {
my ($testnum)=@_;
Daniel Stenberg
committed
opendir(DIR, "$LOGDIR") ||
die "can't open dir: $!";
my @logs = readdir(DIR);
closedir DIR;
my $log;
print "== Contents of files in the log/ dir after test $testnum\n";
Daniel Stenberg
committed
foreach $log (sort @logs) {
# the log file is not "." or ".." and contains more than zero bytes
if(($log !~ /\.(\.|)$/) &&
($log ne "memdump") && # and not "memdump"
-s "$LOGDIR/$log") {
if($log =~ /^\.nfs/) {
next;
}
Daniel Stenberg
committed
print "== Start of file $log\n";
displaylogcontent("$LOGDIR/$log");
Daniel Stenberg
committed
print "== End of file $log\n";
}
}
}
#######################################################################
# The main test-loop
#
my $ok=0;
my $total=0;
my $lasttest;
my @at = split(" ", $TESTCASES);
$start = time();
foreach $testnum (@at) {
$lasttest = $testnum if($testnum > $lasttest);
$count++;
my $error = singletest($testnum, $count, scalar(@at));
if($error < 0) {
# not a test we can run
$total++; # number of tests we've run
if($error>0) {
Daniel Stenberg
committed
if($postmortem) {
# display all files in log/ in a nice way
displaylogs($testnum);
Daniel Stenberg
committed
}
if(!$anyway) {
# a test failed, abort
print "\n - abort tests\n";
last;
}
elsif(!$error) {
$ok++; # successful test counter
#######################################################################
# Close command log
#
close(CMDLOG);
# Tests done, stop the servers
stopservers($verbose);