runtests.pl 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at http://curl.haxx.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. # $Id: runtests.pl,v 1.111 2004/03/01 16:24:54 bagder Exp $
  23. ###########################################################################
  24. # These should be the only variables that might be needed to get edited:
  25. use strict;
  26. #use warnings;
  27. @INC=(@INC, $ENV{'srcdir'}, ".");
  28. require "getpart.pm"; # array functions
  29. my $srcdir = $ENV{'srcdir'} || '.';
  30. my $HOSTIP="127.0.0.1";
  31. my $HOSTPORT=8999; # bad name, but this is the HTTP server port
  32. my $HTTPSPORT=8433; # this is the HTTPS server port
  33. my $FTPPORT=8921; # this is the FTP server port
  34. my $FTPSPORT=8821; # this is the FTPS server port
  35. my $CURL="../src/curl"; # what curl executable to run on the tests
  36. my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
  37. my $LOGDIR="log";
  38. my $TESTDIR="$srcdir/data";
  39. my $LIBDIR="./libtest";
  40. my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
  41. my $CURLLOG="$LOGDIR/curl.log"; # all command lines run
  42. my $FTPDCMD="$LOGDIR/ftpserver.cmd"; # copy ftp server instructions here
  43. # Normally, all test cases should be run, but at times it is handy to
  44. # simply run a particular one:
  45. my $TESTCASES="all";
  46. # To run specific test cases, set them like:
  47. # $TESTCASES="1 2 3 7 8";
  48. #######################################################################
  49. # No variables below this point should need to be modified
  50. #
  51. my $HTTPPIDFILE=".http.pid";
  52. my $HTTPSPIDFILE=".https.pid";
  53. my $FTPPIDFILE=".ftp.pid";
  54. my $FTPSPIDFILE=".ftps.pid";
  55. # invoke perl like this:
  56. my $perl="perl -I$srcdir";
  57. # this gets set if curl is compiled with debugging:
  58. my $curl_debug=0;
  59. # name of the file that the memory debugging creates:
  60. my $memdump="memdump";
  61. # the path to the script that analyzes the memory debug output file:
  62. my $memanalyze="./memanalyze.pl";
  63. my $stunnel = checkcmd("stunnel");
  64. my $valgrind = checkcmd("valgrind");
  65. my $ssl_version; # set if libcurl is built with SSL support
  66. my $large_file; # set if libcurl is built with large file support
  67. my $skipped=0; # number of tests skipped; reported in main loop
  68. my %skipped; # skipped{reason}=counter, reasons for skip
  69. my @teststat; # teststat[testnum]=reason, reasons for skip
  70. #######################################################################
  71. # variables the command line options may set
  72. #
  73. my $short;
  74. my $verbose;
  75. my $debugprotocol;
  76. my $anyway;
  77. my $gdbthis; # run test case with gdb debugger
  78. my $keepoutfiles; # keep stdout and stderr files after tests
  79. my $listonly; # only list the tests
  80. my $pwd; # current working directory
  81. my %run; # running server
  82. # torture test variables
  83. my $torture;
  84. my $tortnum;
  85. my $tortalloc;
  86. chomp($pwd = `pwd`);
  87. # enable memory debugging if curl is compiled with it
  88. $ENV{'CURL_MEMDEBUG'} = 1;
  89. $ENV{'HOME'}=$pwd;
  90. ##########################################################################
  91. # Clear all possible '*_proxy' environment variables for various protocols
  92. # to prevent them to interfere with our testing!
  93. my $protocol;
  94. foreach $protocol (('ftp', 'http', 'ftps', 'https', 'gopher', 'no')) {
  95. my $proxy = "${protocol}_proxy";
  96. # clear lowercase version
  97. $ENV{$proxy}=undef;
  98. # clear uppercase version
  99. $ENV{uc($proxy)}=undef;
  100. }
  101. #######################################################################
  102. # Check for a command in the PATH.
  103. #
  104. sub checkcmd {
  105. my ($cmd)=@_;
  106. my @paths=("/usr/sbin", "/usr/local/sbin", "/sbin", "/usr/bin",
  107. "/usr/local/bin", split(":", $ENV{'PATH'}));
  108. for(@paths) {
  109. if( -x "$_/$cmd") {
  110. return "$_/$cmd";
  111. }
  112. }
  113. }
  114. #######################################################################
  115. # Return the pid of the server as found in the given pid file
  116. #
  117. sub serverpid {
  118. my $PIDFILE = $_[0];
  119. open(PFILE, "<$PIDFILE");
  120. my $PID=0+<PFILE>;
  121. close(PFILE);
  122. return $PID;
  123. }
  124. #######################################################################
  125. # Memory allocation test and failure torture testing.
  126. #
  127. sub torture {
  128. # start all test servers (http, https, ftp, ftps)
  129. &startservers(("http", "https", "ftp", "ftps"));
  130. my $c;
  131. my @test=('http://%HOSTIP:%HOSTPORT/1',
  132. 'ftp://%HOSTIP:%FTPPORT/');
  133. # loop over the different tests commands
  134. for(@test) {
  135. my $cmdargs = "$_";
  136. $c++;
  137. if($tortnum && ($tortnum != $c)) {
  138. next;
  139. }
  140. print "We want test $c\n";
  141. my $redir=">log/torture.stdout 2>log/torture.stderr";
  142. subVariables(\$cmdargs);
  143. my $testcmd = "$CURL $cmdargs $redir";
  144. # First get URL from test server, ignore the output/result
  145. system($testcmd);
  146. # Set up gdb-stuff if desired
  147. if($gdbthis) {
  148. open(GDBCMD, ">log/gdbcmd");
  149. print GDBCMD "set args $cmdargs\n";
  150. print GDBCMD "show args\n";
  151. close(GDBCMD);
  152. $testcmd = "gdb $CURL -x log/gdbcmd";
  153. }
  154. print "Torture test $c:\n";
  155. print " CMD: $testcmd\n" if($verbose);
  156. # memanalyze -v is our friend, get the number of allocations made
  157. my $count;
  158. my @out = `$memanalyze -v $memdump`;
  159. for(@out) {
  160. if(/^Allocations: (\d+)/) {
  161. $count = $1;
  162. last;
  163. }
  164. }
  165. if(!$count) {
  166. # hm, no allocations in this fetch, ignore and get next
  167. print "BEEEP, no allocs found for test $c!!!\n";
  168. next;
  169. }
  170. print " $count allocations to excersize\n";
  171. for ( 1 .. $count ) {
  172. my $limit = $_;
  173. my $fail;
  174. if($tortalloc && ($tortalloc != $limit)) {
  175. next;
  176. }
  177. print "Alloc no: $limit\r" if(!$gdbthis);
  178. # make the memory allocation function number $limit return failure
  179. $ENV{'CURL_MEMLIMIT'} = $limit;
  180. # remove memdump first to be sure we get a new nice and clean one
  181. unlink($memdump);
  182. print "**> Alloc number $limit is now set to fail <**\n" if($gdbthis);
  183. my $ret = system($testcmd);
  184. # verify that it returns a proper error code, doesn't leak memory
  185. # and doesn't core dump
  186. if($ret & 255) {
  187. print " system() returned $ret\n";
  188. $fail=1;
  189. }
  190. else {
  191. my @memdata=`$memanalyze $memdump`;
  192. my $leak=0;
  193. for(@memdata) {
  194. if($_ ne "") {
  195. # well it could be other memory problems as well, but
  196. # we call it leak for short here
  197. $leak=1;
  198. }
  199. }
  200. if($leak) {
  201. print "** MEMORY FAILURE\n";
  202. print @memdata;
  203. print `$memanalyze -l $memdump`;
  204. $fail = 1;
  205. }
  206. }
  207. if($fail) {
  208. print " Failed on alloc number $limit in test $c.\n",
  209. " invoke with -t$c,$limit to repeat this single case.\n";
  210. stopservers();
  211. exit 1;
  212. }
  213. }
  214. print "\n torture test $c did GOOD\n";
  215. # all is well, now test a different kind of URL
  216. }
  217. stopservers();
  218. exit; # for now, we stop after these tests
  219. }
  220. #######################################################################
  221. # stop the given test server
  222. #
  223. sub stopserver {
  224. my $pid = $_[0];
  225. # check for pidfile
  226. if ( -f $pid ) {
  227. my $PIDFILE = $pid;
  228. $pid = serverpid($PIDFILE);
  229. unlink $PIDFILE; # server is killed
  230. }
  231. elsif($pid <= 0) {
  232. return; # this is not a good pid
  233. }
  234. my $res = kill (9, $pid); # die!
  235. if($res && $verbose) {
  236. print "RUN: Test server pid $pid signalled to die\n";
  237. }
  238. elsif($verbose) {
  239. print "RUN: Test server pid $pid didn't exist\n";
  240. }
  241. }
  242. #######################################################################
  243. # check the given test server if it is still alive
  244. #
  245. sub checkserver {
  246. my ($pidfile)=@_;
  247. my $pid=0;
  248. # check for pidfile
  249. if ( -f $pidfile ) {
  250. $pid=serverpid($pidfile);
  251. if ($pid ne "" && kill(0, $pid)) {
  252. return $pid;
  253. }
  254. else {
  255. return -$pid; # negative means dead process
  256. }
  257. }
  258. return 0;
  259. }
  260. #######################################################################
  261. # start the http server, or if it already runs, verify that it is our
  262. # test server on the test-port!
  263. #
  264. sub runhttpserver {
  265. my $verbose = $_[0];
  266. my $RUNNING;
  267. my $pid;
  268. $pid = checkserver ($HTTPPIDFILE);
  269. # verify if our/any server is running on this port
  270. my $cmd = "$CURL -o log/verifiedserver --silent -i $HOSTIP:$HOSTPORT/verifiedserver 2>/dev/null";
  271. print "CMD; $cmd\n" if ($verbose);
  272. my $res = system($cmd);
  273. $res >>= 8; # rotate the result
  274. my $data;
  275. print "RUN: curl command returned $res\n" if ($verbose);
  276. open(FILE, "<log/verifiedserver");
  277. my @file=<FILE>;
  278. close(FILE);
  279. $data=$file[0]; # first line
  280. if ( $data =~ /WE ROOLZ: (\d+)/ ) {
  281. $pid = 0+$1;
  282. }
  283. elsif($data || ($res != 7)) {
  284. print "RUN: Unknown HTTP server is running on port $HOSTPORT\n";
  285. return -2;
  286. }
  287. if($pid > 0) {
  288. my $res = kill (9, $pid); # die!
  289. if(!$res) {
  290. print "RUN: Failed to kill test HTTP server, do it manually and",
  291. " restart the tests.\n";
  292. exit;
  293. }
  294. sleep(1);
  295. }
  296. my $flag=$debugprotocol?"-v ":"";
  297. my $dir=$ENV{'srcdir'};
  298. if($dir) {
  299. $flag .= "-d \"$dir\" ";
  300. }
  301. $cmd="$perl $srcdir/httpserver.pl $flag $HOSTPORT &";
  302. system($cmd);
  303. if($verbose) {
  304. print "CMD: $cmd\n";
  305. }
  306. my $verified;
  307. for(1 .. 10) {
  308. # verify that our server is up and running:
  309. my $data=`$CURL --silent -i $HOSTIP:$HOSTPORT/verifiedserver 2>/dev/null`;
  310. if ( $data =~ /WE ROOLZ: (\d+)/ ) {
  311. $pid = 0+$1;
  312. $verified = 1;
  313. last;
  314. }
  315. else {
  316. if($verbose) {
  317. print STDERR "RUN: Retrying HTTP server existence in 3 sec\n";
  318. }
  319. sleep(3);
  320. next;
  321. }
  322. }
  323. if(!$verified) {
  324. print STDERR "RUN: failed to start our HTTP server\n";
  325. return -1;
  326. }
  327. if($verbose) {
  328. print "RUN: HTTP server is now verified to be our server\n";
  329. }
  330. return $pid;
  331. }
  332. #######################################################################
  333. # start the https server (or rather, tunnel) if needed
  334. #
  335. sub runhttpsserver {
  336. my $verbose = $_[0];
  337. my $STATUS;
  338. my $RUNNING;
  339. if(!$stunnel) {
  340. return 0;
  341. }
  342. my $pid=checkserver($HTTPSPIDFILE );
  343. if($pid > 0) {
  344. # kill previous stunnel!
  345. if($verbose) {
  346. print "RUN: kills off running stunnel at $pid\n";
  347. }
  348. stopserver($HTTPSPIDFILE);
  349. }
  350. my $flag=$debugprotocol?"-v ":"";
  351. my $cmd="$perl $srcdir/httpsserver.pl $flag -s \"$stunnel\" -d $srcdir -r $HOSTPORT $HTTPSPORT &";
  352. system($cmd);
  353. if($verbose) {
  354. print "CMD: $cmd\n";
  355. }
  356. sleep(1);
  357. for(1 .. 10) {
  358. $pid=checkserver($HTTPSPIDFILE);
  359. if($pid <= 0) {
  360. if($verbose) {
  361. print STDERR "RUN: waiting 3 sec for HTTPS server\n";
  362. }
  363. sleep(3);
  364. }
  365. else {
  366. last;
  367. }
  368. }
  369. return $pid;
  370. }
  371. #######################################################################
  372. # start the ftp server if needed
  373. #
  374. sub runftpserver {
  375. my $verbose = $_[0];
  376. my $STATUS;
  377. my $RUNNING;
  378. # check for pidfile
  379. my $pid = checkserver ($FTPPIDFILE );
  380. if ($pid <= 0) {
  381. print "RUN: Check port $FTPPORT for our own FTP server\n"
  382. if ($verbose);
  383. my $time=time();
  384. # check if this is our server running on this port:
  385. my $data=`$CURL -m4 --silent -i ftp://$HOSTIP:$FTPPORT/verifiedserver 2>/dev/null`;
  386. # if this took more than 2 secs, we assume it "hung" on a weird server
  387. my $took = time()-$time;
  388. if ( $data =~ /WE ROOLZ: (\d+)/ ) {
  389. # this is our test server with a known pid!
  390. $pid = 0+$1;
  391. }
  392. else {
  393. if($data || ($took > 2)) {
  394. # this is not a known server
  395. print "RUN: Unknown server on our favourite port: $FTPPORT\n";
  396. return -1;
  397. }
  398. }
  399. }
  400. if($pid > 0) {
  401. print "RUN: Killing a previous server using pid $pid\n" if($verbose);
  402. my $res = kill (9, $pid); # die!
  403. if(!$res) {
  404. print "RUN: Failed to kill our FTP test server, do it manually and",
  405. " restart the tests.\n";
  406. return -1;
  407. }
  408. sleep(1);
  409. }
  410. # now (re-)start our server:
  411. my $flag=$debugprotocol?"-v ":"";
  412. $flag .= "-s \"$srcdir\"";
  413. my $cmd="$perl $srcdir/ftpserver.pl $flag $FTPPORT &";
  414. if($verbose) {
  415. print "CMD: $cmd\n";
  416. }
  417. system($cmd);
  418. my $verified;
  419. for(1 .. 10) {
  420. # verify that our server is up and running:
  421. my $data=`$CURL --silent -i ftp://$HOSTIP:$FTPPORT/verifiedserver 2>/dev/null`;
  422. if ( $data =~ /WE ROOLZ: (\d+)/ ) {
  423. $pid = 0+$1;
  424. $verified = 1;
  425. last;
  426. }
  427. else {
  428. if($verbose) {
  429. print STDERR "RUN: Retrying FTP server existence in 3 sec\n";
  430. }
  431. sleep(3);
  432. next;
  433. }
  434. }
  435. if(!$verified) {
  436. warn "RUN: failed to start our FTP server\n";
  437. return -2;
  438. }
  439. if($verbose) {
  440. print "RUN: FTP server is now verified to be our server\n";
  441. }
  442. return $pid;
  443. }
  444. #######################################################################
  445. # start the ftps server (or rather, tunnel) if needed
  446. #
  447. sub runftpsserver {
  448. my $verbose = $_[0];
  449. my $STATUS;
  450. my $RUNNING;
  451. if(!$stunnel) {
  452. return 0;
  453. }
  454. my $pid=checkserver($FTPSPIDFILE );
  455. if($pid > 0) {
  456. # kill previous stunnel!
  457. if($verbose) {
  458. print "kills off running stunnel at $pid\n";
  459. }
  460. stopserver($FTPSPIDFILE);
  461. }
  462. my $flag=$debugprotocol?"-v ":"";
  463. my $cmd="$perl $srcdir/ftpsserver.pl $flag -s \"$stunnel\" -d $srcdir -r $FTPPORT $FTPSPORT &";
  464. system($cmd);
  465. if($verbose) {
  466. print "CMD: $cmd\n";
  467. }
  468. sleep(1);
  469. for(1 .. 10) {
  470. $pid=checkserver($FTPSPIDFILE );
  471. if($pid <= 0) {
  472. if($verbose) {
  473. print STDERR "RUN: waiting 3 sec for FTPS server\n";
  474. }
  475. sleep(3);
  476. }
  477. else {
  478. last;
  479. }
  480. }
  481. return $pid;
  482. }
  483. #######################################################################
  484. # Remove all files in the specified directory
  485. #
  486. sub cleardir {
  487. my $dir = $_[0];
  488. my $count;
  489. my $file;
  490. # Get all files
  491. opendir(DIR, $dir) ||
  492. return 0; # can't open dir
  493. while($file = readdir(DIR)) {
  494. if($file !~ /^\./) {
  495. unlink("$dir/$file");
  496. $count++;
  497. }
  498. }
  499. closedir DIR;
  500. return $count;
  501. }
  502. #######################################################################
  503. # filter out the specified pattern from the given input file and store the
  504. # results in the given output file
  505. #
  506. sub filteroff {
  507. my $infile=$_[0];
  508. my $filter=$_[1];
  509. my $ofile=$_[2];
  510. open(IN, "<$infile")
  511. || return 1;
  512. open(OUT, ">$ofile")
  513. || return 1;
  514. # print "FILTER: off $filter from $infile to $ofile\n";
  515. while(<IN>) {
  516. $_ =~ s/$filter//;
  517. print OUT $_;
  518. }
  519. close(IN);
  520. close(OUT);
  521. return 0;
  522. }
  523. #######################################################################
  524. # compare test results with the expected output, we might filter off
  525. # some pattern that is allowed to differ, output test results
  526. #
  527. sub compare {
  528. # filter off patterns _before_ this comparison!
  529. my ($subject, $firstref, $secondref)=@_;
  530. my $result = compareparts($firstref, $secondref);
  531. if($result) {
  532. if(!$short) {
  533. print "\n $subject FAILED:\n";
  534. print showdiff($firstref, $secondref);
  535. }
  536. else {
  537. print "FAILED\n";
  538. }
  539. }
  540. return $result;
  541. }
  542. #######################################################################
  543. # display information about curl and the host the test suite runs on
  544. #
  545. sub checkcurl {
  546. unlink($memdump); # remove this if there was one left
  547. my $curl;
  548. my $libcurl;
  549. my @version=`$CURL -V 2>/dev/null`;
  550. for(@version) {
  551. chomp;
  552. if($_ =~ /^curl/) {
  553. $curl = $_;
  554. $curl =~ s/^(.*)(libcurl.*)/$1/g;
  555. $libcurl = $2;
  556. if ($curl =~ /win32/)
  557. {
  558. # Native Windows builds don't understand the
  559. # output of cygwin's pwd. It will be
  560. # something like /cygdrive/c/<some path>.
  561. #
  562. # Use the cygpath utility to convert the
  563. # working directory to a Windows friendly
  564. # path. The -m option converts to use drive
  565. # letter:, but it uses / instead \. Forward
  566. # slashes (/) are easier for us. We don't
  567. # have to escape them to get them to curl
  568. # through a shell.
  569. chomp($pwd = `cygpath -m $pwd`);
  570. }
  571. }
  572. elsif($_ =~ /^Protocols: (.*)/i) {
  573. # these are the supported protocols, we don't use this knowledge
  574. # at this point
  575. }
  576. elsif($_ =~ /^Features: (.*)/i) {
  577. my $feat = $1;
  578. if($feat =~ /debug/i) {
  579. # debug is a listed "feature", use that knowledge
  580. $curl_debug = 1;
  581. # set the NETRC debug env
  582. $ENV{'CURL_DEBUG_NETRC'} = 'log/netrc';
  583. }
  584. if($feat =~ /SSL/i) {
  585. # ssl enabled
  586. $ssl_version=1;
  587. }
  588. if($feat =~ /Largefile/i) {
  589. # large file support
  590. $large_file=1;
  591. }
  592. }
  593. }
  594. if(!$curl) {
  595. die "couldn't run curl!"
  596. }
  597. my $hostname=`hostname`;
  598. my $hosttype=`uname -a`;
  599. print "********* System characteristics ******** \n",
  600. "* $curl\n",
  601. "* $libcurl\n",
  602. "* Host: $hostname",
  603. "* System: $hosttype";
  604. printf("* Server SSL: %s\n", $stunnel?"ON":"OFF");
  605. printf("* libcurl SSL: %s\n", $ssl_version?"ON":"OFF");
  606. printf("* libcurl debug: %s\n", $curl_debug?"ON":"OFF");
  607. printf("* valgrind: %s\n", $valgrind?"ON":"OFF");
  608. print "***************************************** \n";
  609. }
  610. #######################################################################
  611. # substitute the variable stuff into either a joined up file or
  612. # a command, in either case passed by reference
  613. #
  614. sub subVariables {
  615. my ($thing) = @_;
  616. $$thing =~ s/%HOSTIP/$HOSTIP/g;
  617. $$thing =~ s/%HOSTPORT/$HOSTPORT/g;
  618. $$thing =~ s/%HTTPPORT/$HOSTPORT/g;
  619. $$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
  620. $$thing =~ s/%FTPPORT/$FTPPORT/g;
  621. $$thing =~ s/%FTPSPORT/$FTPSPORT/g;
  622. $$thing =~ s/%SRCDIR/$srcdir/g;
  623. $$thing =~ s/%PWD/$pwd/g;
  624. }
  625. #######################################################################
  626. # Run a single specified test case
  627. #
  628. sub singletest {
  629. my $testnum=$_[0];
  630. my @what;
  631. my $why;
  632. my $serverproblem;
  633. # load the test case file definition
  634. if(loadtest("${TESTDIR}/test${testnum}")) {
  635. if($verbose) {
  636. # this is not a test
  637. print "RUN: $testnum doesn't look like a test case!\n";
  638. }
  639. $serverproblem = 100;
  640. }
  641. else {
  642. @what = getpart("client", "features");
  643. }
  644. printf("test %03d...", $testnum);
  645. for(@what) {
  646. my $f = $_;
  647. $f =~ s/\s//g;
  648. if($f eq "SSL") {
  649. if($ssl_version) {
  650. next;
  651. }
  652. }
  653. elsif($f eq "netrc_debug") {
  654. if($curl_debug) {
  655. next;
  656. }
  657. }
  658. elsif($f eq "large_file") {
  659. if($large_file) {
  660. next;
  661. }
  662. }
  663. $why = "curl lacks $f support";
  664. $serverproblem = 15; # set it here
  665. last;
  666. }
  667. if(!$serverproblem) {
  668. $serverproblem = serverfortest($testnum);
  669. }
  670. if($serverproblem) {
  671. # there's a problem with the server, don't run
  672. # this particular server, but count it as "skipped"
  673. if($serverproblem == 2) {
  674. $why = "server problems";
  675. }
  676. elsif($serverproblem == 100) {
  677. $why = "no test";
  678. }
  679. elsif($serverproblem == 99) {
  680. $why = "bad test";
  681. }
  682. elsif($serverproblem == 15) {
  683. # set above, a lacking prereq
  684. }
  685. elsif($serverproblem == 1) {
  686. $why = "no HTTPS server";
  687. }
  688. elsif($serverproblem == 3) {
  689. $why = "no FTPS server";
  690. }
  691. else {
  692. $why = "unfulfilled requirements";
  693. }
  694. $skipped++;
  695. $skipped{$why}++;
  696. $teststat[$testnum]=$why; # store reason for this test case
  697. print "SKIPPED\n";
  698. if(!$short) {
  699. print "* Test $testnum: $why\n";
  700. }
  701. return -1;
  702. }
  703. # extract the reply data
  704. my @reply = getpart("reply", "data");
  705. my @replycheck = getpart("reply", "datacheck");
  706. if (@replycheck) {
  707. # we use this file instead to check the final output against
  708. my %hash = getpartattr("reply", "datacheck");
  709. if($hash{'nonewline'}) {
  710. # Yes, we must cut off the final newline from the final line
  711. # of the datacheck
  712. chomp($replycheck[$#replycheck]);
  713. }
  714. @reply=@replycheck;
  715. }
  716. # curl command to run
  717. my @curlcmd= getpart("client", "command");
  718. # this is the valid protocol blurb curl should generate
  719. my @protocol= getpart("verify", "protocol");
  720. # redirected stdout/stderr to these files
  721. $STDOUT="$LOGDIR/stdout$testnum";
  722. $STDERR="$LOGDIR/stderr$testnum";
  723. # if this section exists, we verify that the stdout contained this:
  724. my @validstdout = getpart("verify", "stdout");
  725. # if this section exists, we verify upload
  726. my @upload = getpart("verify", "upload");
  727. # if this section exists, it is FTP server instructions:
  728. my @ftpservercmd = getpart("server", "instruction");
  729. my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout
  730. # name of the test
  731. my @testname= getpart("client", "name");
  732. if(!$short) {
  733. my $name = $testname[0];
  734. $name =~ s/\n//g;
  735. print "[$name]\n";
  736. }
  737. if($listonly) {
  738. return 0; # look successful
  739. }
  740. my @codepieces = getpart("client", "tool");
  741. my $tool="";
  742. if(@codepieces) {
  743. $tool = $codepieces[0];
  744. chomp $tool;
  745. }
  746. # remove previous server output logfile
  747. unlink($SERVERIN);
  748. if(@ftpservercmd) {
  749. # write the instructions to file
  750. writearray($FTPDCMD, \@ftpservercmd);
  751. }
  752. my (@setenv)= getpart("client", "setenv");
  753. my @envs;
  754. my $s;
  755. for $s (@setenv) {
  756. chomp $s; # cut off the newline
  757. subVariables \$s;
  758. if($s =~ /([^=]*)=(.*)/) {
  759. my ($var, $content)=($1, $2);
  760. $ENV{$var}=$content;
  761. # remember which, so that we can clear them afterwards!
  762. push @envs, $var;
  763. }
  764. }
  765. # get the command line options to use
  766. my ($cmd, @blaha)= getpart("client", "command");
  767. # make some nice replace operations
  768. $cmd =~ s/\n//g; # no newlines please
  769. # substitute variables in the command line
  770. subVariables \$cmd;
  771. if($curl_debug) {
  772. unlink($memdump);
  773. }
  774. my @inputfile=getpart("client", "file");
  775. if(@inputfile) {
  776. # we need to generate a file before this test is invoked
  777. my %hash = getpartattr("client", "file");
  778. my $filename=$hash{'name'};
  779. if(!$filename) {
  780. print "ERROR: section client=>file has no name attribute!\n";
  781. exit;
  782. }
  783. my $fileContent = join('', @inputfile);
  784. subVariables \$fileContent;
  785. # print "DEBUG: writing file " . $filename . "\n";
  786. open OUTFILE, ">$filename";
  787. binmode OUTFILE; # for crapage systems, use binary
  788. print OUTFILE $fileContent;
  789. close OUTFILE;
  790. }
  791. my %cmdhash = getpartattr("client", "command");
  792. my $out="";
  793. if($cmdhash{'option'} !~ /no-output/) {
  794. #We may slap on --output!
  795. if (!@validstdout) {
  796. $out=" --output $CURLOUT ";
  797. }
  798. }
  799. my $cmdargs;
  800. if(!$tool) {
  801. # run curl, add -v for debug information output
  802. $cmdargs ="$out --include -v $cmd";
  803. }
  804. else {
  805. $cmdargs = " $cmd"; # $cmd is the command line for the test file
  806. $CURLOUT = $STDOUT; # sends received data to stdout
  807. }
  808. my @stdintest = getpart("client", "stdin");
  809. if(@stdintest) {
  810. my $stdinfile="$LOGDIR/stdin-for-$testnum";
  811. writearray($stdinfile, \@stdintest);
  812. $cmdargs .= " <$stdinfile";
  813. }
  814. if($valgrind) {
  815. $cmdargs .= " 3>log/valgrind$testnum";
  816. }
  817. my $CMDLINE;
  818. if(!$tool) {
  819. $CMDLINE="$CURL";
  820. }
  821. else {
  822. $CMDLINE="$LIBDIR/$tool";
  823. $DBGCURL=$CMDLINE;
  824. }
  825. $CMDLINE .= "$cmdargs >>$STDOUT 2>>$STDERR";
  826. if($verbose) {
  827. print "$CMDLINE\n";
  828. }
  829. print CMDLOG "$CMDLINE\n";
  830. my $cmdres;
  831. # run the command line we built
  832. if($gdbthis) {
  833. open(GDBCMD, ">log/gdbcmd");
  834. print GDBCMD "set args $cmdargs\n";
  835. print GDBCMD "show args\n";
  836. close(GDBCMD);
  837. system("gdb --directory libtest $DBGCURL -x log/gdbcmd");
  838. $cmdres=0; # makes it always continue after a debugged run
  839. }
  840. else {
  841. $cmdres = system("$CMDLINE");
  842. my $signal_num = $cmdres & 127;
  843. my $dumped_core = $cmdres & 128;
  844. if(!$anyway && ($signal_num || $dumped_core)) {
  845. $cmdres = 1000;
  846. }
  847. else {
  848. $cmdres /= 256;
  849. }
  850. }
  851. # remove the special FTP command file after each test!
  852. unlink($FTPDCMD);
  853. my $e;
  854. for $e (@envs) {
  855. $ENV{$e}=""; # clean up
  856. }
  857. my @err = getpart("verify", "errorcode");
  858. my $errorcode = $err[0];
  859. my $res;
  860. if (@validstdout) {
  861. # verify redirected stdout
  862. my @actual = loadarray($STDOUT);
  863. $res = compare("stdout", \@actual, \@validstdout);
  864. if($res) {
  865. return 1;
  866. }
  867. if(!$short) {
  868. print " stdout OK";
  869. }
  870. }
  871. my %replyattr = getpartattr("reply", "data");
  872. if(!$replyattr{'nocheck'} && @reply) {
  873. # verify the received data
  874. my @out = loadarray($CURLOUT);
  875. $res = compare("data", \@out, \@reply);
  876. if ($res) {
  877. return 1;
  878. }
  879. if(!$short) {
  880. print " data OK";
  881. }
  882. }
  883. if(@upload) {
  884. # verify uploaded data
  885. my @out = loadarray("$LOGDIR/upload.$testnum");
  886. $res = compare("upload", \@out, \@upload);
  887. if ($res) {
  888. return 1;
  889. }
  890. if(!$short) {
  891. print " upload OK";
  892. }
  893. }
  894. if(@protocol) {
  895. # verify the sent request
  896. my @out = loadarray($SERVERIN);
  897. # what to cut off from the live protocol sent by curl
  898. my @strip = getpart("verify", "strip");
  899. my @protstrip=@protocol;
  900. # check if there's any attributes on the verify/protocol section
  901. my %hash = getpartattr("verify", "protocol");
  902. if($hash{'nonewline'}) {
  903. # Yes, we must cut off the final newline from the final line
  904. # of the protocol data
  905. chomp($protstrip[$#protstrip]);
  906. }
  907. for(@strip) {
  908. # strip all patterns from both arrays
  909. @out = striparray( $_, \@out);
  910. @protstrip= striparray( $_, \@protstrip);
  911. }
  912. $res = compare("protocol", \@out, \@protstrip);
  913. if($res) {
  914. return 1;
  915. }
  916. if(!$short) {
  917. print " protocol OK";
  918. }
  919. }
  920. my @outfile=getpart("verify", "file");
  921. if(@outfile) {
  922. # we're supposed to verify a dynamicly generated file!
  923. my %hash = getpartattr("verify", "file");
  924. my $filename=$hash{'name'};
  925. if(!$filename) {
  926. print "ERROR: section verify=>file has no name attribute!\n";
  927. exit;
  928. }
  929. my @generated=loadarray($filename);
  930. $res = compare("output", \@generated, \@outfile);
  931. if($res) {
  932. return 1;
  933. }
  934. if(!$short) {
  935. print " output OK";
  936. }
  937. }
  938. if($errorcode || $cmdres) {
  939. if($errorcode == $cmdres) {
  940. $errorcode =~ s/\n//;
  941. if($verbose) {
  942. print " received errorcode $errorcode OK";
  943. }
  944. elsif(!$short) {
  945. print " error OK";
  946. }
  947. }
  948. else {
  949. if(!$short) {
  950. print "curl returned $cmdres, ".(0+$errorcode)." was expected\n";
  951. }
  952. print " error FAILED\n";
  953. return 1;
  954. }
  955. }
  956. if(!$keepoutfiles) {
  957. # remove the stdout and stderr files
  958. unlink($STDOUT);
  959. unlink($STDERR);
  960. unlink($CURLOUT); # remove the downloaded results
  961. unlink("$LOGDIR/upload.$testnum"); # remove upload leftovers
  962. }
  963. unlink($FTPDCMD); # remove the instructions for this test
  964. @what = getpart("client", "killserver");
  965. for(@what) {
  966. my $serv = $_;
  967. chomp $serv;
  968. if($run{$serv}) {
  969. stopserver($run{$serv}); # the pid file is in the hash table
  970. $run{$serv}=0; # clear pid
  971. }
  972. else {
  973. print STDERR "RUN: The $serv server is not running\n";
  974. }
  975. }
  976. if($curl_debug) {
  977. if(! -f $memdump) {
  978. print "\n** ALERT! memory debuggin without any output file?\n";
  979. }
  980. else {
  981. my @memdata=`$memanalyze $memdump`;
  982. my $leak=0;
  983. for(@memdata) {
  984. if($_ ne "") {
  985. # well it could be other memory problems as well, but
  986. # we call it leak for short here
  987. $leak=1;
  988. }
  989. }
  990. if($leak) {
  991. print "\n** MEMORY FAILURE\n";
  992. print @memdata;
  993. return 1;
  994. }
  995. else {
  996. if(!$short) {
  997. print " memory OK";
  998. }
  999. }
  1000. }
  1001. }
  1002. if($short) {
  1003. print "OK";
  1004. }
  1005. print "\n";
  1006. return 0;
  1007. }
  1008. #######################################################################
  1009. # Stop all running test servers
  1010. sub stopservers {
  1011. print "Shutting down test suite servers:\n" if ($verbose);
  1012. for(keys %run) {
  1013. printf ("* kill pid for %-5s => %-5d\n", $_, $run{$_}) if($verbose);
  1014. stopserver($run{$_}); # the pid file is in the hash table
  1015. }
  1016. }
  1017. #######################################################################
  1018. # startservers() starts all the named servers
  1019. #
  1020. sub startservers {
  1021. my @what = @_;
  1022. my $pid;
  1023. for(@what) {
  1024. my $what = lc($_);
  1025. $what =~ s/[^a-z]//g;
  1026. if($what eq "ftp") {
  1027. if(!$run{'ftp'}) {
  1028. $pid = runftpserver($verbose);
  1029. if($pid <= 0) {
  1030. return 2; # error starting it
  1031. }
  1032. printf ("* pid ftp => %-5d\n", $pid) if($verbose);
  1033. $run{'ftp'}=$pid;
  1034. }
  1035. }
  1036. elsif($what eq "http") {
  1037. if(!$run{'http'}) {
  1038. $pid = runhttpserver($verbose);
  1039. if($pid <= 0) {
  1040. return 2; # error starting
  1041. }
  1042. printf ("* pid http => %-5d\n", $pid) if($verbose);
  1043. $run{'http'}=$pid;
  1044. }
  1045. }
  1046. elsif($what eq "ftps") {
  1047. if(!$stunnel || !$ssl_version) {
  1048. # we can't run ftps tests without stunnel
  1049. # or if libcurl is SSL-less
  1050. return 3;
  1051. }
  1052. if(!$run{'ftp'}) {
  1053. $pid = runftpserver($verbose);
  1054. if($pid <= 0) {
  1055. return 2; # error starting it
  1056. }
  1057. $run{'ftp'}=$pid;
  1058. }
  1059. if(!$run{'ftps'}) {
  1060. return 2;
  1061. $pid = runftpsserver($verbose);
  1062. if($pid <= 0) {
  1063. return 2;
  1064. }
  1065. printf ("* pid ftps => %-5d\n", $pid) if($verbose);
  1066. $run{'ftps'}=$pid;
  1067. }
  1068. }
  1069. elsif($what eq "file") {
  1070. # we support it but have no server!
  1071. }
  1072. elsif($what eq "https") {
  1073. if(!$stunnel || !$ssl_version) {
  1074. # we can't run https tests without stunnel
  1075. # or if libcurl is SSL-less
  1076. return 1;
  1077. }
  1078. if(!$run{'http'}) {
  1079. $pid = runhttpserver($verbose);
  1080. if($pid <= 0) {
  1081. return 2; # problems starting server
  1082. }
  1083. $run{'http'}=$pid;
  1084. }
  1085. if(!$run{'https'}) {
  1086. $pid = runhttpsserver($verbose);
  1087. if($pid <= 0) {
  1088. return 2;
  1089. }
  1090. printf ("* pid https => %-5d\n", $pid) if($verbose);
  1091. $run{'https'}=$pid;
  1092. }
  1093. }
  1094. elsif($what eq "none") {
  1095. }
  1096. else {
  1097. warn "we don't support a server for $what";
  1098. }
  1099. }
  1100. return 0;
  1101. }
  1102. ##############################################################################
  1103. # This function makes sure the right set of server is running for the
  1104. # specified test case. This is a useful design when we run single tests as not
  1105. # all servers need to run then!
  1106. #
  1107. # Returns:
  1108. # 100 if this is not a test case
  1109. # 99 if this test case has no servers specified
  1110. # 3 if this test is skipped due to no FTPS server
  1111. # 2 if one of the required servers couldn't be started
  1112. # 1 if this test is skipped due to no HTTPS server
  1113. sub serverfortest {
  1114. my ($testnum)=@_;
  1115. # load the test case file definition
  1116. if(loadtest("${TESTDIR}/test${testnum}")) {
  1117. if($verbose) {
  1118. # this is not a test
  1119. print "$testnum doesn't look like a test case!\n";
  1120. }
  1121. return 100;
  1122. }
  1123. my @what = getpart("client", "server");
  1124. if(!$what[0]) {
  1125. warn "Test case $testnum has no server(s) specified!";
  1126. return 99;
  1127. }
  1128. return &startservers(@what);
  1129. }
  1130. #######################################################################
  1131. # Check options to this test program
  1132. #
  1133. my $number=0;
  1134. my $fromnum=-1;
  1135. my @testthis;
  1136. do {
  1137. if ($ARGV[0] eq "-v") {
  1138. # verbose output
  1139. $verbose=1;
  1140. }
  1141. elsif ($ARGV[0] eq "-c") {
  1142. # use this path to curl instead of default
  1143. $CURL=$ARGV[1];
  1144. shift @ARGV;
  1145. }
  1146. elsif ($ARGV[0] eq "-d") {
  1147. # have the servers display protocol output
  1148. $debugprotocol=1;
  1149. }
  1150. elsif ($ARGV[0] eq "-g") {
  1151. # run this test with gdb
  1152. $gdbthis=1;
  1153. }
  1154. elsif($ARGV[0] eq "-s") {
  1155. # short output
  1156. $short=1;
  1157. }
  1158. elsif($ARGV[0] eq "-n") {
  1159. # no valgrind
  1160. undef $valgrind;
  1161. }
  1162. elsif($ARGV[0] =~ /^-t(.*)/) {
  1163. # torture
  1164. $torture=1;
  1165. my $xtra = $1;
  1166. if($xtra =~ s/^(\d+)//) {
  1167. $tortnum = $1;
  1168. }
  1169. if($xtra =~ s/(\d+)$//) {
  1170. $tortalloc = $1;
  1171. }
  1172. }
  1173. elsif($ARGV[0] eq "-a") {
  1174. # continue anyway, even if a test fail
  1175. $anyway=1;
  1176. }
  1177. elsif($ARGV[0] eq "-l") {
  1178. # lists the test case names only
  1179. $listonly=1;
  1180. }
  1181. elsif($ARGV[0] eq "-k") {
  1182. # keep stdout and stderr files after tests
  1183. $keepoutfiles=1;
  1184. }
  1185. elsif($ARGV[0] eq "-h") {
  1186. # show help text
  1187. print <<EOHELP
  1188. Usage: runtests.pl [options]
  1189. -a continue even if a test fails
  1190. -d display server debug info
  1191. -g run the test case with gdb
  1192. -h this help text
  1193. -k keep stdout and stderr files present after tests
  1194. -l list all test case names/descriptions
  1195. -n No valgrind
  1196. -s short output
  1197. -t torture
  1198. -v verbose output
  1199. [num] like "5 6 9" or " 5 to 22 " to run those tests only
  1200. EOHELP
  1201. ;
  1202. exit;
  1203. }
  1204. elsif($ARGV[0] =~ /^(\d+)/) {
  1205. $number = $1;
  1206. if($fromnum >= 0) {
  1207. for($fromnum .. $number) {
  1208. push @testthis, $_;
  1209. }
  1210. $fromnum = -1;
  1211. }
  1212. else {
  1213. push @testthis, $1;
  1214. }
  1215. }
  1216. elsif($ARGV[0] =~ /^to$/i) {
  1217. $fromnum = $number+1;
  1218. }
  1219. } while(shift @ARGV);
  1220. if($testthis[0] ne "") {
  1221. $TESTCASES=join(" ", @testthis);
  1222. }
  1223. if($valgrind) {
  1224. # we have found valgrind on the host, use it
  1225. # verify that we can invoke it fine
  1226. my $code = system("valgrind >/dev/null 2>&1");
  1227. if(($code>>8) != 1) {
  1228. #print "Valgrind failure, disable it\n";
  1229. undef $valgrind;
  1230. }
  1231. else {
  1232. $CURL="valgrind --leak-check=yes --logfile-fd=3 -q $CURL";
  1233. }
  1234. }
  1235. #######################################################################
  1236. # Output curl version and host info being tested
  1237. #
  1238. if(!$listonly) {
  1239. checkcurl();
  1240. }
  1241. #######################################################################
  1242. # clear and create logging directory:
  1243. #
  1244. cleardir($LOGDIR);
  1245. mkdir($LOGDIR, 0777);
  1246. #######################################################################
  1247. # If 'all' tests are requested, find out all test numbers
  1248. #
  1249. if ( $TESTCASES eq "all") {
  1250. # Get all commands and find out their test numbers
  1251. opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
  1252. my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
  1253. closedir DIR;
  1254. $TESTCASES=""; # start with no test cases
  1255. # cut off everything but the digits
  1256. for(@cmds) {
  1257. $_ =~ s/[a-z\/\.]*//g;
  1258. }
  1259. # the the numbers from low to high
  1260. for(sort { $a <=> $b } @cmds) {
  1261. $TESTCASES .= " $_";
  1262. }
  1263. }
  1264. #######################################################################
  1265. # Start the command line log
  1266. #
  1267. open(CMDLOG, ">$CURLLOG") ||
  1268. print "can't log command lines to $CURLLOG\n";
  1269. #######################################################################
  1270. # Torture the memory allocation system and checks
  1271. #
  1272. if($torture) {
  1273. &torture();
  1274. }
  1275. #######################################################################
  1276. # The main test-loop
  1277. #
  1278. my $failed;
  1279. my $testnum;
  1280. my $ok=0;
  1281. my $total=0;
  1282. my $lasttest;
  1283. foreach $testnum (split(" ", $TESTCASES)) {
  1284. $lasttest = $testnum if($testnum > $lasttest);
  1285. my $error = singletest($testnum);
  1286. if($error < 0) {
  1287. # not a test we can run
  1288. next;
  1289. }
  1290. $total++; # number of tests we've run
  1291. if($error>0) {
  1292. $failed.= "$testnum ";
  1293. if(!$anyway) {
  1294. # a test failed, abort
  1295. print "\n - abort tests\n";
  1296. last;
  1297. }
  1298. }
  1299. elsif(!$error) {
  1300. $ok++; # successful test counter
  1301. }
  1302. # loop for next test
  1303. }
  1304. #######################################################################
  1305. # Close command log
  1306. #
  1307. close(CMDLOG);
  1308. # Tests done, stop the servers
  1309. stopservers();
  1310. my $all = $total + $skipped;
  1311. if($total) {
  1312. printf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
  1313. $ok/$total*100);
  1314. if($ok != $total) {
  1315. print "TESTFAIL: These test cases failed: $failed\n";
  1316. }
  1317. }
  1318. else {
  1319. print "TESTFAIL: No tests were performed!\n";
  1320. }
  1321. if($all) {
  1322. print "TESTDONE: $all tests were considered.\n";
  1323. }
  1324. if($skipped) {
  1325. my $s=0;
  1326. print "TESTINFO: $skipped tests were skipped due to these restraints:\n";
  1327. for(keys %skipped) {
  1328. my $r = $_;
  1329. printf "TESTINFO: \"%s\" %d times (", $r, $skipped{$_};
  1330. # now show all test case numbers that had this reason for being
  1331. # skipped
  1332. my $c=0;
  1333. for(0 .. $lasttest) {
  1334. my $t = $_;
  1335. if($teststat[$_] eq $r) {
  1336. print ", " if($c);
  1337. print $_;
  1338. $c++;
  1339. }
  1340. }
  1341. print ")\n";
  1342. }
  1343. }
  1344. if($total && ($ok != $total)) {
  1345. exit 1;
  1346. }