19
19
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
20
# KIND, either express or implied.
22
# $Id: runtests.pl,v 1.187 2005/05/16 07:07:00 bagder Exp $
22
# $Id: runtests.pl,v 1.197 2005/12/06 07:44:18 bagder Exp $
23
23
###########################################################################
24
24
# These should be the only variables that might be needed to get edited:
27
#use Time::HiRes qw( gettimeofday );
29
30
@INC=(@INC, $ENV{'srcdir'}, ".");
117
132
my $has_idn; # set if libcurl is built with IDN support
118
133
my $http_ipv6; # set if HTTP server has IPv6 support
119
134
my $ftp_ipv6; # set if FTP server has IPv6 support
135
my $tftp_ipv6; # set if TFTP server has IPv6 support
120
136
my $has_ipv6; # set if libcurl is built with IPv6 support
121
137
my $has_libz; # set if libcurl is built with libz support
122
138
my $has_getrlimit; # set if system has getrlimit()
171
# open and close each time to allow removal at any time
173
# uncomment the Time::HiRes usage for this
174
# my ($seconds, $microseconds) = gettimeofday;
175
# my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
176
# localtime($seconds);
179
# $t = sprintf ("%02d:%02d:%02d.%06d ", $hour, $min, $sec,
155
187
chomp($pwd = `pwd`);
157
189
# enable memory debugging if curl is compiled with it
332
print "** MEMORY FAILURE\n";
334
print `$memanalyze -l $memdump`;
364
logmsg "** MEMORY FAILURE\n";
366
logmsg `$memanalyze -l $memdump`;
339
print " Failed on alloc number $limit in test.\n",
371
logmsg " Failed on alloc number $limit in test.\n",
340
372
" invoke with -t$limit to repeat this single case.\n";
341
373
stopservers($verbose);
346
print "torture OK\n";
378
logmsg "torture OK\n";
524
557
if(!kill(0, $httppid)) {
525
558
# it is NOT alive
526
print "RUN: failed to start the HTTP server!\n";
559
logmsg "RUN: failed to start the HTTP server!\n";
527
560
stopservers($verbose);
531
564
# Server is up. Verify that we can speak to it.
532
565
if(!verifyserver("http", $ip, $port)) {
533
print "RUN: HTTP$nameext server failed verification\n";
566
logmsg "RUN: HTTP$nameext server failed verification\n";
534
567
# failed to talk to it properly. Kill the server and return failure
535
568
stopserver("$httppid $pid2");
540
print "RUN: HTTP$nameext server is now running PID $httppid\n";
573
logmsg "RUN: HTTP$nameext server is now running PID $httppid\n";
578
611
if(!kill(0, $httpspid)) {
579
612
# it is NOT alive
580
print "RUN: failed to start the HTTPS server!\n";
613
logmsg "RUN: failed to start the HTTPS server!\n";
581
614
stopservers($verbose);
585
618
# Server is up. Verify that we can speak to it.
586
619
if(!verifyserver("https", $ip, $HTTPSPORT)) {
587
print "RUN: HTTPS server failed verification\n";
620
logmsg "RUN: HTTPS server failed verification\n";
588
621
# failed to talk to it properly. Kill the server and return failure
589
622
stopserver("$httpspid $pid2");
594
print "RUN: HTTPS server is now running PID $httpspid\n";
627
logmsg "RUN: HTTPS server is now running PID $httpspid\n";
640
671
$cmd="$perl $srcdir/ftpserver.pl --pidfile $pidfile $flag --port $port";
642
675
my ($ftppid, $pid2) = startnew($cmd, $pidfile);
644
677
if(!$ftppid || !kill(0, $ftppid)) {
645
678
# it is NOT alive
646
print "RUN: failed to start the FTP$id$nameext server!\n";
679
logmsg "RUN: failed to start the FTP$id$nameext server!\n";
650
683
# Server is up. Verify that we can speak to it.
651
684
if(!verifyserver("ftp", $ip, $port)) {
652
print "RUN: FTP$id$nameext server failed verification\n";
685
logmsg "RUN: FTP$id$nameext server failed verification\n";
653
686
# failed to talk to it properly. Kill the server and return failure
654
687
stopserver("$ftppid $pid2");
659
print "RUN: FTP$id$nameext server is now running PID $ftppid\n";
692
logmsg "RUN: FTP$id$nameext server is now running PID $ftppid\n";
667
700
#######################################################################
701
# start the tftp server
704
my ($id, $verbose, $ipv6) = @_;
707
my $port = $TFTPPORT;
709
my $pidfile = $TFTPPIDFILE;
715
# if IPv6, use a different setup
716
$pidfile = $TFTP6PIDFILE;
722
my $pid = checkserver($pidfile);
728
my $flag=$debugprotocol?"-v ":"";
729
$flag .= "-s \"$srcdir\" ";
736
$cmd="./server/tftpd --pidfile $pidfile $flag $port";
740
my ($tftppid, $pid2) = startnew($cmd, $pidfile);
742
if(!$tftppid || !kill(0, $tftppid)) {
744
logmsg "RUN: failed to start the FTP$id$nameext server!\n";
748
# Server is up. Verify that we can speak to it.
749
if(!verifyserver("tftp", $ip, $port)) {
750
logmsg "RUN: TFTP$id$nameext server failed verification\n";
751
# failed to talk to it properly. Kill the server and return failure
752
stopserver("$tftppid $pid2");
757
logmsg "RUN: TFTP$id$nameext server is now running PID $tftppid\n";
762
return ($pid2, $tftppid);
766
#######################################################################
668
767
# Remove all files in the specified directory
892
1005
my $hostname=`hostname`;
893
1006
my $hosttype=`uname -a`;
895
print "********* System characteristics ******** \n",
1008
logmsg ("********* System characteristics ******** \n",
898
1011
"* Features: $feat\n",
899
1012
"* Host: $hostname",
900
"* System: $hosttype";
902
printf("* Server SSL: %s\n", $stunnel?"ON":"OFF");
903
printf("* libcurl SSL: %s\n", $ssl_version?"ON":"OFF");
904
printf("* libcurl debug: %s\n", $curl_debug?"ON":"OFF");
905
printf("* valgrind: %s\n", $valgrind?"ON":"OFF");
906
printf("* HTTP IPv6 %s\n", $http_ipv6?"ON":"OFF");
907
printf("* FTP IPv6 %s\n", $ftp_ipv6?"ON":"OFF");
909
printf("* HTTP port: %d\n", $HTTPPORT);
910
printf("* FTP port: %d\n", $FTPPORT);
911
printf("* FTP port 2: %d\n", $FTP2PORT);
1013
"* System: $hosttype");
1015
logmsg sprintf("* Server SSL: %s\n", $stunnel?"ON":"OFF");
1016
logmsg sprintf("* libcurl SSL: %s\n", $ssl_version?"ON":"OFF");
1017
logmsg sprintf("* libcurl debug: %s\n", $curl_debug?"ON":"OFF");
1018
logmsg sprintf("* valgrind: %s\n", $valgrind?"ON":"OFF");
1019
logmsg sprintf("* HTTP IPv6 %s\n", $http_ipv6?"ON":"OFF");
1020
logmsg sprintf("* FTP IPv6 %s\n", $ftp_ipv6?"ON":"OFF");
1022
logmsg sprintf("* HTTP port: %d\n", $HTTPPORT);
1023
logmsg sprintf("* FTP port: %d\n", $FTPPORT);
1024
logmsg sprintf("* FTP port 2: %d\n", $FTP2PORT);
913
#printf("* FTPS port: %d\n", $FTPSPORT);
914
printf("* HTTPS port: %d\n", $HTTPSPORT);
1026
#logmsg sprintf("* FTPS port: %d\n", $FTPSPORT);
1027
logmsg sprintf("* HTTPS port: %d\n", $HTTPSPORT);
916
1029
if($http_ipv6) {
917
printf("* HTTP IPv6 port: %d\n", $HTTP6PORT);
1030
logmsg sprintf("* HTTP IPv6 port: %d\n", $HTTP6PORT);
920
printf("* FTP IPv6 port: %d\n", $FTP6PORT);
1033
logmsg sprintf("* FTP IPv6 port: %d\n", $FTP6PORT);
1035
logmsg sprintf("* TFTP port: %d\n", $TFTPPORT);
1037
logmsg sprintf("* TFTP IPv6 port: %d\n", $TFTP6PORT);
923
1040
if($ssl_version) {
924
printf("* SSL library: %s\n",
1041
logmsg sprintf("* SSL library: %s\n",
925
1042
$has_gnutls?"GnuTLS":($has_openssl?"OpenSSL":"<unknown>"));
928
1045
$has_textaware = ($^O eq 'MSWin32') || ($^O eq 'msys');
930
print "***************************************** \n";
1047
logmsg "***************************************** \n";
933
1050
#######################################################################
1182
1301
my $filename=$fileattr{'name'};
1184
1303
if(!$filename) {
1185
print "ERROR: section client=>file has no name attribute!\n";
1304
logmsg "ERROR: section client=>file has no name attribute!\n";
1188
1307
my $fileContent = join('', @inputfile);
1189
1308
subVariables \$fileContent;
1190
# print "DEBUG: writing file " . $filename . "\n";
1309
# logmsg "DEBUG: writing file " . $filename . "\n";
1191
1310
open OUTFILE, ">$filename";
1192
1311
binmode OUTFILE; # for crapage systems, use binary
1193
1312
print OUTFILE $fileContent;
1325
1444
# verify redirected stdout
1326
1445
my @actual = loadarray($STDOUT);
1447
# get all attributes
1448
my %hash = getpartattr("verify", "stdout");
1450
# get the mode attribute
1451
my $filemode=$hash{'mode'};
1452
if(($filemode eq "text") && $has_textaware) {
1453
# text mode when running on windows: fix line endings
1454
map s/\r\n/\n/g, @actual;
1328
1457
$res = compare("stdout", \@actual, \@validstdout);
1339
1468
if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
1340
1469
# verify the received data
1341
1470
my @out = loadarray($CURLOUT);
1471
my %hash = getpartattr("reply", "data");
1472
# get the mode attribute
1473
my $filemode=$hash{'mode'};
1474
if(($filemode eq "text") && $has_textaware) {
1475
# text mode when running on windows: fix line endings
1476
map s/\r\n/\n/g, @out;
1342
1479
$res = compare("data", \@out, \@reply);
1431
1568
my $filename=$hash{'name'};
1432
1569
if(!$filename) {
1433
print "ERROR: section verify=>file has no name attribute!\n";
1570
logmsg "ERROR: section verify=>file has no name attribute!\n";
1434
1571
stopservers($verbose);
1437
my $filemode=$hash{'mode'};
1439
1574
my @generated=loadarray($filename);
1441
1576
# what parts to cut off from the file
1442
1577
my @stripfile = getpart("verify", "stripfile");
1579
my $filemode=$hash{'mode'};
1444
1580
if(($filemode eq "text") && $has_textaware) {
1445
1581
# text mode when running on windows means adding an extra
1446
1582
# strip expression
1631
if($serv =~ /^ftp(\d*)(-ipv6|)/) {
1632
my ($id, $ext) = ($1, $2);
1633
print STDERR "SERV $serv $id $ext\n";
1634
ftpkillslave($id, $ext, 1);
1495
1636
if($run{$serv}) {
1496
1637
stopserver($run{$serv}); # the pid file is in the hash table
1497
1638
$run{$serv}=0; # clear pid
1500
print STDERR "RUN: The $serv server is not running\n";
1641
logmsg "RUN: The $serv server is not running\n";
1504
1645
if($curl_debug) {
1505
1646
if(! -f $memdump) {
1506
print "\n** ALERT! memory debuggin without any output file?\n";
1647
logmsg "\n** ALERT! memory debuggin without any output file?\n";
1509
1650
my @memdata=`$memanalyze $memdump`;
1570
1711
$ok .= "-"; # valgrind not checked
1573
print "$ok " if(!$short);
1714
logmsg "$ok " if(!$short);
1575
1716
my $sofar= time()-$start;
1576
1717
my $esttotal = $sofar/$count * $total;
1577
1718
my $estleft = $esttotal - $sofar;
1578
my $left=sprintf("remaining: %dm%ds",
1719
my $left=sprintf("remaining: %02d:%02d",
1581
printf "OK ($count out of $total, %s)\n", $left;
1722
printf "OK (%-3d out of %-3d, %s)\n", $count, $total, $left;
1583
1724
# the test succeeded, remove all log files
1584
1725
if(!$keepoutfiles) {
1598
1739
my $server = $_;
1599
1740
my $pids=$run{$server};
1602
1744
foreach $pid (split(" ", $pids)) {
1603
printf("* kill pid for %-5s => %-5d\n",
1604
$server, $pid) if($verbose);
1746
# no need to kill same pid twice!
1747
logmsg sprintf("* kill pid for %s => %d\n",
1748
$server, $pid) if($verbose);
1608
1754
ftpkillslaves($verbose);
1701
1847
if($pid <= 0) {
1702
1848
return "failed starting HTTPS server (stunnel)";
1704
printf("* pid https => %-5d %-5d\n", $pid, $pid2)
1850
logmsg sprintf("* pid https => %d %d\n", $pid, $pid2)
1706
1852
$run{'https'}="$pid $pid2";
1855
elsif($what eq "tftp") {
1857
($pid, $pid2) = runtftpserver("", $verbose);
1859
return "failed starting TFTP server";
1861
printf ("* pid tftp => %d %d\n", $pid, $pid2) if($verbose);
1862
$run{'tftp'}="$pid $pid2";
1865
elsif($what eq "tftp-ipv6") {
1866
if(!$run{'tftp-ipv6'}) {
1867
($pid, $pid2) = runtftpserver("", $verbose, "IPv6");
1869
return "failed starting TFTP-IPv6 server";
1871
printf("* pid tftp-ipv6 => %d %d\n", $pid, $pid2) if($verbose);
1872
$run{'tftp-ipv6'}="$pid $pid2";
1709
1875
elsif($what eq "none") {
1710
print "* starts no server\n" if ($verbose);
1876
logmsg "* starts no server\n" if ($verbose);
1713
1879
warn "we don't support a server for $what";
1866
2032
# but we follow the same port scheme anyway)
1867
2033
$FTP2PORT = $base + 5; # FTP server 2 port
1868
2034
$FTP6PORT = $base + 6; # FTP IPv6 port
2035
$TFTPPORT = $base + 7; # TFTP (UDP) port
2036
$TFTP6PORT = $base + 8; # TFTP IPv6 (UDP) port
2038
#######################################################################
2039
# clear and create logging directory:
2043
mkdir($LOGDIR, 0777);
1870
2045
#######################################################################
1871
2046
# Output curl version and host info being tested
2001
2170
my $all = $total + $skipped;
2004
printf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
2173
logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
2007
2176
if($ok != $total) {
2008
print "TESTFAIL: These test cases failed: $failed\n";
2177
logmsg "TESTFAIL: These test cases failed: $failed\n";
2012
print "TESTFAIL: No tests were performed!\n";
2181
logmsg "TESTFAIL: No tests were performed!\n";
2016
2185
my $sofar = time()-$start;
2017
print "TESTDONE: $all tests were considered during $sofar seconds.\n";
2186
logmsg "TESTDONE: $all tests were considered during $sofar seconds.\n";
2022
print "TESTINFO: $skipped tests were skipped due to these restraints:\n";
2191
logmsg "TESTINFO: $skipped tests were skipped due to these restraints:\n";
2024
2193
for(keys %skipped) {