runtests.pl 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 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 https://curl.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. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. # For documentation, run `man ./runtests.1` and see README.md.
  26. # Experimental hooks are available to run tests remotely on machines that
  27. # are able to run curl but are unable to run the test harness.
  28. # The following sections need to be modified:
  29. #
  30. # $HOSTIP, $HOST6IP - Set to the address of the host running the test suite
  31. # $CLIENTIP, $CLIENT6IP - Set to the address of the host running curl
  32. # runclient, runclientoutput - Modify to copy all the files in the log/
  33. # directory to the system running curl, run the given command remotely
  34. # and save the return code or returned stdout (respectively), then
  35. # copy all the files from the remote system's log/ directory back to
  36. # the host running the test suite. This can be done a few ways, such
  37. # as using scp & ssh, rsync & telnet, or using a NFS shared directory
  38. # and ssh.
  39. #
  40. # 'make && make test' needs to be done on both machines before making the
  41. # above changes and running runtests.pl manually. In the shared NFS case,
  42. # the contents of the tests/server/ directory must be from the host
  43. # running the test suite, while the rest must be from the host running curl.
  44. #
  45. # Note that even with these changes a number of tests will still fail (mainly
  46. # to do with cookies, those that set environment variables, or those that
  47. # do more than touch the file system in a <precheck> or <postcheck>
  48. # section). These can be added to the $TESTCASES line below,
  49. # e.g. $TESTCASES="!8 !31 !63 !cookies..."
  50. #
  51. # Finally, to properly support -g and -n, checktestcmd needs to change
  52. # to check the remote system's PATH, and the places in the code where
  53. # the curl binary is read directly to determine its type also need to be
  54. # fixed. As long as the -g option is never given, and the -n is always
  55. # given, this won't be a problem.
  56. use strict;
  57. # Promote all warnings to fatal
  58. use warnings FATAL => 'all';
  59. use 5.006;
  60. use POSIX qw(strftime);
  61. # These should be the only variables that might be needed to get edited:
  62. BEGIN {
  63. # Define srcdir to the location of the tests source directory. This is
  64. # usually set by the Makefile, but for out-of-tree builds with direct
  65. # invocation of runtests.pl, it may not be set.
  66. if(!defined $ENV{'srcdir'}) {
  67. use File::Basename;
  68. $ENV{'srcdir'} = dirname(__FILE__);
  69. }
  70. push(@INC, $ENV{'srcdir'});
  71. # run time statistics needs Time::HiRes
  72. eval {
  73. no warnings "all";
  74. require Time::HiRes;
  75. import Time::HiRes qw( time );
  76. }
  77. }
  78. use Digest::MD5 qw(md5);
  79. use List::Util 'sum';
  80. use pathhelp qw(
  81. exe_ext
  82. sys_native_current_path
  83. );
  84. use processhelp qw(
  85. portable_sleep
  86. );
  87. use appveyor;
  88. use azure;
  89. use getpart; # array functions
  90. use servers;
  91. use valgrind; # valgrind report parser
  92. use globalconfig;
  93. use runner;
  94. use testutil;
  95. my %custom_skip_reasons;
  96. my $ACURL=$VCURL; # what curl binary to use to talk to APIs (relevant for CI)
  97. # ACURL is handy to set to the system one for reliability
  98. my $CURLCONFIG="../curl-config"; # curl-config from current build
  99. # Normally, all test cases should be run, but at times it is handy to
  100. # simply run a particular one:
  101. my $TESTCASES="all";
  102. # To run specific test cases, set them like:
  103. # $TESTCASES="1 2 3 7 8";
  104. #######################################################################
  105. # No variables below this point should need to be modified
  106. #
  107. my $libtool;
  108. my $repeat = 0;
  109. my $start; # time at which testing started
  110. my $uname_release = `uname -r`;
  111. my $is_wsl = $uname_release =~ /Microsoft$/;
  112. my $http_ipv6; # set if HTTP server has IPv6 support
  113. my $http_unix; # set if HTTP server has Unix sockets support
  114. my $ftp_ipv6; # set if FTP server has IPv6 support
  115. my $resolver; # name of the resolver backend (for human presentation)
  116. my $has_textaware; # set if running on a system that has a text mode concept
  117. # on files. Windows for example
  118. my %skipped; # skipped{reason}=counter, reasons for skip
  119. my @teststat; # teststat[testnum]=reason, reasons for skip
  120. my %disabled_keywords; # key words of tests to skip
  121. my %ignored_keywords; # key words of tests to ignore results
  122. my %enabled_keywords; # key words of tests to run
  123. my %disabled; # disabled test cases
  124. my %ignored; # ignored results of test cases
  125. my %ignoretestcodes; # if test results are to be ignored
  126. my $timestats; # time stamping and stats generation
  127. my $fullstats; # show time stats for every single test
  128. my %timeprepini; # timestamp for each test preparation start
  129. my %timesrvrini; # timestamp for each test required servers verification start
  130. my %timesrvrend; # timestamp for each test required servers verification end
  131. my %timetoolini; # timestamp for each test command run starting
  132. my %timetoolend; # timestamp for each test command run stopping
  133. my %timesrvrlog; # timestamp for each test server logs lock removal
  134. my %timevrfyend; # timestamp for each test result verification end
  135. my $globalabort; # flag signalling program abort
  136. # values for $singletest_state
  137. use constant {
  138. ST_INIT => 0,
  139. ST_CLEARLOCKS => 1,
  140. ST_INITED => 2,
  141. ST_PREPROCESS => 3,
  142. ST_RUN => 4,
  143. };
  144. my %singletest_state; # current state of singletest() by runner ID
  145. my %singletest_logs; # log messages while in singletest array ref by runner
  146. my $singletest_bufferedrunner; # runner ID which is buffering logs
  147. my %runnerids; # runner IDs by number
  148. my @runnersidle; # runner IDs idle and ready to execute a test
  149. my %countforrunner; # test count by runner ID
  150. my %runnersrunning; # tests currently running by runner ID
  151. #######################################################################
  152. # variables that command line options may set
  153. #
  154. my $short;
  155. my $no_debuginfod;
  156. my $keepoutfiles; # keep stdout and stderr files after tests
  157. my $clearlocks; # force removal of files by killing locking processes
  158. my $postmortem; # display detailed info about failed tests
  159. my $run_disabled; # run the specific tests even if listed in DISABLED
  160. my $scrambleorder;
  161. my $jobs = 0;
  162. # Azure Pipelines specific variables
  163. my $AZURE_RUN_ID = 0;
  164. my $AZURE_RESULT_ID = 0;
  165. #######################################################################
  166. # logmsg is our general message logging subroutine.
  167. #
  168. sub logmsg {
  169. if($singletest_bufferedrunner) {
  170. # Logs are currently being buffered
  171. return singletest_logmsg(@_);
  172. }
  173. for(@_) {
  174. my $line = $_;
  175. if(!$line) {
  176. next;
  177. }
  178. if ($is_wsl) {
  179. # use \r\n for WSL shell
  180. $line =~ s/\r?\n$/\r\n/g;
  181. }
  182. print "$line";
  183. }
  184. }
  185. #######################################################################
  186. # enable logmsg buffering for the given runner ID
  187. #
  188. sub logmsg_bufferfortest {
  189. my ($runnerid)=@_;
  190. if($jobs) {
  191. # Only enable buffering in multiprocess mode
  192. $singletest_bufferedrunner = $runnerid;
  193. }
  194. }
  195. #######################################################################
  196. # Store a log message in a buffer for this test
  197. # The messages can then be displayed all at once at the end of the test
  198. # which prevents messages from different tests from being interleaved.
  199. sub singletest_logmsg {
  200. if(!exists $singletest_logs{$singletest_bufferedrunner}) {
  201. # initialize to a reference to an empty anonymous array
  202. $singletest_logs{$singletest_bufferedrunner} = [];
  203. }
  204. my $logsref = $singletest_logs{$singletest_bufferedrunner};
  205. push @$logsref, @_;
  206. }
  207. #######################################################################
  208. # Stop buffering log messages, but don't touch them
  209. sub singletest_unbufferlogs {
  210. undef $singletest_bufferedrunner;
  211. }
  212. #######################################################################
  213. # Clear the buffered log messages & stop buffering after returning them
  214. sub singletest_dumplogs {
  215. if(!defined $singletest_bufferedrunner) {
  216. # probably not multiprocess mode and logs weren't buffered
  217. return undef;
  218. }
  219. my $logsref = $singletest_logs{$singletest_bufferedrunner};
  220. my $msg = join("", @$logsref);
  221. delete $singletest_logs{$singletest_bufferedrunner};
  222. singletest_unbufferlogs();
  223. return $msg;
  224. }
  225. sub catch_zap {
  226. my $signame = shift;
  227. print "runtests.pl received SIG$signame, exiting\r\n";
  228. $globalabort = 1;
  229. }
  230. $SIG{INT} = \&catch_zap;
  231. $SIG{TERM} = \&catch_zap;
  232. sub catch_usr1 {
  233. print "runtests.pl internal state:\r\n";
  234. print scalar(%runnersrunning) . " busy test runner(s) of " . scalar(keys %runnerids) . "\r\n";
  235. foreach my $rid (sort(keys(%runnersrunning))) {
  236. my $runnernum = "unknown";
  237. foreach my $rnum (keys %runnerids) {
  238. if($runnerids{$rnum} == $rid) {
  239. $runnernum = $rnum;
  240. last;
  241. }
  242. }
  243. print "Runner $runnernum (id $rid) running test $runnersrunning{$rid} in state $singletest_state{$rid}\r\n";
  244. }
  245. }
  246. eval {
  247. # some msys2 perl versions don't define SIGUSR1
  248. $SIG{USR1} = \&catch_usr1;
  249. };
  250. $SIG{PIPE} = 'IGNORE'; # these errors are captured in the read/write calls
  251. ##########################################################################
  252. # Clear all possible '*_proxy' environment variables for various protocols
  253. # to prevent them to interfere with our testing!
  254. foreach my $protocol (('ftp', 'http', 'ftps', 'https', 'no', 'all')) {
  255. my $proxy = "${protocol}_proxy";
  256. # clear lowercase version
  257. delete $ENV{$proxy} if($ENV{$proxy});
  258. # clear uppercase version
  259. delete $ENV{uc($proxy)} if($ENV{uc($proxy)});
  260. }
  261. # make sure we don't get affected by other variables that control our
  262. # behavior
  263. delete $ENV{'SSL_CERT_DIR'} if($ENV{'SSL_CERT_DIR'});
  264. delete $ENV{'SSL_CERT_PATH'} if($ENV{'SSL_CERT_PATH'});
  265. delete $ENV{'CURL_CA_BUNDLE'} if($ENV{'CURL_CA_BUNDLE'});
  266. # provide defaults from our config file for ENV vars not explicitly
  267. # set by the caller
  268. if (open(my $fd, "<", "config")) {
  269. while(my $line = <$fd>) {
  270. next if ($line =~ /^#/);
  271. chomp $line;
  272. my ($name, $val) = split(/\s*:\s*/, $line, 2);
  273. $ENV{$name} = $val if(!$ENV{$name});
  274. }
  275. close($fd);
  276. }
  277. # Check if we have nghttpx available and if it talks http/3
  278. my $nghttpx_h3 = 0;
  279. if (!$ENV{"NGHTTPX"}) {
  280. $ENV{"NGHTTPX"} = checktestcmd("nghttpx");
  281. }
  282. if ($ENV{"NGHTTPX"}) {
  283. my $nghttpx_version=join(' ', `"$ENV{'NGHTTPX'}" -v 2>/dev/null`);
  284. $nghttpx_h3 = $nghttpx_version =~ /nghttp3\//;
  285. chomp $nghttpx_h3;
  286. }
  287. #######################################################################
  288. # Get the list of tests that the tests/data/Makefile.am knows about!
  289. #
  290. my $disttests = "";
  291. sub get_disttests {
  292. # If a non-default $TESTDIR is being used there may not be any
  293. # Makefile.inc in which case there's nothing to do.
  294. open(my $dh, "<", "$TESTDIR/Makefile.inc") or return;
  295. while(<$dh>) {
  296. chomp $_;
  297. if(($_ =~ /^#/) ||($_ !~ /test/)) {
  298. next;
  299. }
  300. $disttests .= $_;
  301. }
  302. close($dh);
  303. }
  304. #######################################################################
  305. # Remove all files in the specified directory
  306. #
  307. sub cleardir {
  308. my $dir = $_[0];
  309. my $done = 1; # success
  310. my $file;
  311. # Get all files
  312. opendir(my $dh, $dir) ||
  313. return 0; # can't open dir
  314. while($file = readdir($dh)) {
  315. # Don't clear the $PIDDIR or $LOCKDIR since those need to live beyond
  316. # one test
  317. if(($file !~ /^(\.|\.\.)\z/) &&
  318. "$file" ne $PIDDIR && "$file" ne $LOCKDIR) {
  319. if(-d "$dir/$file") {
  320. if(!cleardir("$dir/$file")) {
  321. $done = 0;
  322. }
  323. if(!rmdir("$dir/$file")) {
  324. $done = 0;
  325. }
  326. }
  327. else {
  328. # Ignore stunnel since we cannot do anything about its locks
  329. if(!unlink("$dir/$file") && "$file" !~ /_stunnel\.log$/) {
  330. $done = 0;
  331. }
  332. }
  333. }
  334. }
  335. closedir $dh;
  336. return $done;
  337. }
  338. #######################################################################
  339. # Given two array references, this function will store them in two temporary
  340. # files, run 'diff' on them, store the result and return the diff output!
  341. sub showdiff {
  342. my ($logdir, $firstref, $secondref)=@_;
  343. my $file1="$logdir/check-generated";
  344. my $file2="$logdir/check-expected";
  345. open(my $temp, ">", "$file1") || die "Failure writing diff file";
  346. for(@$firstref) {
  347. my $l = $_;
  348. $l =~ s/\r/[CR]/g;
  349. $l =~ s/\n/[LF]/g;
  350. $l =~ s/([^\x20-\x7f])/sprintf "%%%02x", ord $1/eg;
  351. print $temp $l;
  352. print $temp "\n";
  353. }
  354. close($temp) || die "Failure writing diff file";
  355. open($temp, ">", "$file2") || die "Failure writing diff file";
  356. for(@$secondref) {
  357. my $l = $_;
  358. $l =~ s/\r/[CR]/g;
  359. $l =~ s/\n/[LF]/g;
  360. $l =~ s/([^\x20-\x7f])/sprintf "%%%02x", ord $1/eg;
  361. print $temp $l;
  362. print $temp "\n";
  363. }
  364. close($temp) || die "Failure writing diff file";
  365. my @out = `diff -u $file2 $file1 2>/dev/null`;
  366. if(!$out[0]) {
  367. @out = `diff -c $file2 $file1 2>/dev/null`;
  368. }
  369. return @out;
  370. }
  371. #######################################################################
  372. # compare test results with the expected output, we might filter off
  373. # some pattern that is allowed to differ, output test results
  374. #
  375. sub compare {
  376. my ($runnerid, $testnum, $testname, $subject, $firstref, $secondref)=@_;
  377. my $result = compareparts($firstref, $secondref);
  378. if($result) {
  379. # timestamp test result verification end
  380. $timevrfyend{$testnum} = Time::HiRes::time();
  381. if(!$short) {
  382. logmsg "\n $testnum: $subject FAILED:\n";
  383. my $logdir = getrunnerlogdir($runnerid);
  384. logmsg showdiff($logdir, $firstref, $secondref);
  385. }
  386. elsif(!$automakestyle) {
  387. logmsg "FAILED\n";
  388. }
  389. else {
  390. # automakestyle
  391. logmsg "FAIL: $testnum - $testname - $subject\n";
  392. }
  393. }
  394. return $result;
  395. }
  396. #######################################################################
  397. # Numeric-sort words in a string
  398. sub numsortwords {
  399. my ($string)=@_;
  400. return join(' ', sort { $a <=> $b } split(' ', $string));
  401. }
  402. #######################################################################
  403. # Parse and store the protocols in curl's Protocols: line
  404. sub parseprotocols {
  405. my ($line)=@_;
  406. @protocols = split(' ', lc($line));
  407. # Generate a "proto-ipv6" version of each protocol to match the
  408. # IPv6 <server> name and a "proto-unix" to match the variant which
  409. # uses Unix domain sockets. This works even if support isn't
  410. # compiled in because the <features> test will fail.
  411. push @protocols, map(("$_-ipv6", "$_-unix"), @protocols);
  412. # 'http-proxy' is used in test cases to do CONNECT through
  413. push @protocols, 'http-proxy';
  414. # 'none' is used in test cases to mean no server
  415. push @protocols, 'none';
  416. }
  417. #######################################################################
  418. # Check & display information about curl and the host the test suite runs on.
  419. # Information to do with servers is displayed in displayserverfeatures, after
  420. # the server initialization is performed.
  421. sub checksystemfeatures {
  422. my $feat;
  423. my $curl;
  424. my $libcurl;
  425. my $versretval;
  426. my $versnoexec;
  427. my @version=();
  428. my @disabled;
  429. my $dis = "";
  430. my $curlverout="$LOGDIR/curlverout.log";
  431. my $curlvererr="$LOGDIR/curlvererr.log";
  432. my $versioncmd=shell_quote($CURL) . " --version 1>$curlverout 2>$curlvererr";
  433. unlink($curlverout);
  434. unlink($curlvererr);
  435. $versretval = runclient($versioncmd);
  436. $versnoexec = $!;
  437. my $current_time = int(time());
  438. $ENV{'SOURCE_DATE_EPOCH'} = $current_time;
  439. $DATE = strftime "%Y-%m-%d", gmtime($current_time);
  440. open(my $versout, "<", "$curlverout");
  441. @version = <$versout>;
  442. close($versout);
  443. open(my $disabledh, "-|", "server/disabled".exe_ext('TOOL'));
  444. @disabled = <$disabledh>;
  445. close($disabledh);
  446. if($disabled[0]) {
  447. s/[\r\n]//g for @disabled;
  448. $dis = join(", ", @disabled);
  449. }
  450. $resolver="stock";
  451. for(@version) {
  452. chomp;
  453. if($_ =~ /^curl ([^ ]*)/) {
  454. $curl = $_;
  455. $CURLVERSION = $1;
  456. $CURLVERNUM = $CURLVERSION;
  457. $CURLVERNUM =~ s/^([0-9.]+)(.*)/$1/; # leading dots and numbers
  458. $curl =~ s/^(.*)(libcurl.*)/$1/g || die "Failure determining curl binary version";
  459. $libcurl = $2;
  460. if($curl =~ /linux|bsd|solaris/) {
  461. # system support LD_PRELOAD; may be disabled later
  462. $feature{"ld_preload"} = 1;
  463. }
  464. if($curl =~ /win32|Windows|mingw(32|64)/) {
  465. # This is a Windows MinGW build or native build, we need to use
  466. # Win32-style path.
  467. $pwd = sys_native_current_path();
  468. $has_textaware = 1;
  469. $feature{"win32"} = 1;
  470. # set if built with MinGW (as opposed to MinGW-w64)
  471. $feature{"MinGW"} = 1 if ($curl =~ /-pc-mingw32/);
  472. }
  473. if ($libcurl =~ /\s(winssl|schannel)\b/i) {
  474. $feature{"Schannel"} = 1;
  475. $feature{"SSLpinning"} = 1;
  476. }
  477. elsif ($libcurl =~ /\sopenssl\b/i) {
  478. $feature{"OpenSSL"} = 1;
  479. $feature{"SSLpinning"} = 1;
  480. }
  481. elsif ($libcurl =~ /\sgnutls\b/i) {
  482. $feature{"GnuTLS"} = 1;
  483. $feature{"SSLpinning"} = 1;
  484. }
  485. elsif ($libcurl =~ /\srustls-ffi\b/i) {
  486. $feature{"rustls"} = 1;
  487. }
  488. elsif ($libcurl =~ /\swolfssl\b/i) {
  489. $feature{"wolfssl"} = 1;
  490. $feature{"SSLpinning"} = 1;
  491. }
  492. elsif ($libcurl =~ /\sbearssl\b/i) {
  493. $feature{"bearssl"} = 1;
  494. }
  495. elsif ($libcurl =~ /\ssecuretransport\b/i) {
  496. $feature{"sectransp"} = 1;
  497. $feature{"SSLpinning"} = 1;
  498. }
  499. elsif ($libcurl =~ /\sBoringSSL\b/i) {
  500. # OpenSSL compatible API
  501. $feature{"OpenSSL"} = 1;
  502. $feature{"SSLpinning"} = 1;
  503. }
  504. elsif ($libcurl =~ /\slibressl\b/i) {
  505. # OpenSSL compatible API
  506. $feature{"OpenSSL"} = 1;
  507. $feature{"SSLpinning"} = 1;
  508. }
  509. elsif ($libcurl =~ /\smbedTLS\b/i) {
  510. $feature{"mbedtls"} = 1;
  511. $feature{"SSLpinning"} = 1;
  512. }
  513. if ($libcurl =~ /ares/i) {
  514. $feature{"c-ares"} = 1;
  515. $resolver="c-ares";
  516. }
  517. if ($libcurl =~ /Hyper/i) {
  518. $feature{"hyper"} = 1;
  519. }
  520. if ($libcurl =~ /nghttp2/i) {
  521. # nghttp2 supports h2c, hyper does not
  522. $feature{"h2c"} = 1;
  523. }
  524. if ($libcurl =~ /libssh2/i) {
  525. $feature{"libssh2"} = 1;
  526. }
  527. if ($libcurl =~ /libssh\/([0-9.]*)\//i) {
  528. $feature{"libssh"} = 1;
  529. if($1 =~ /(\d+)\.(\d+).(\d+)/) {
  530. my $v = $1 * 100 + $2 * 10 + $3;
  531. if($v < 94) {
  532. # before 0.9.4
  533. $feature{"oldlibssh"} = 1;
  534. }
  535. }
  536. }
  537. if ($libcurl =~ /wolfssh/i) {
  538. $feature{"wolfssh"} = 1;
  539. }
  540. }
  541. elsif($_ =~ /^Protocols: (.*)/i) {
  542. # these are the protocols compiled in to this libcurl
  543. parseprotocols($1);
  544. }
  545. elsif($_ =~ /^Features: (.*)/i) {
  546. $feat = $1;
  547. # built with memory tracking support (--enable-curldebug); may be disabled later
  548. $feature{"TrackMemory"} = $feat =~ /TrackMemory/i;
  549. # curl was built with --enable-debug
  550. $feature{"Debug"} = $feat =~ /Debug/i;
  551. # ssl enabled
  552. $feature{"SSL"} = $feat =~ /SSL/i;
  553. # multiple ssl backends available.
  554. $feature{"MultiSSL"} = $feat =~ /MultiSSL/i;
  555. # large file support
  556. $feature{"Largefile"} = $feat =~ /Largefile/i;
  557. # IDN support
  558. $feature{"IDN"} = $feat =~ /IDN/i;
  559. # IPv6 support
  560. $feature{"IPv6"} = $feat =~ /IPv6/i;
  561. # Unix sockets support
  562. $feature{"UnixSockets"} = $feat =~ /UnixSockets/i;
  563. # libz compression
  564. $feature{"libz"} = $feat =~ /libz/i;
  565. # Brotli compression
  566. $feature{"brotli"} = $feat =~ /brotli/i;
  567. # Zstd compression
  568. $feature{"zstd"} = $feat =~ /zstd/i;
  569. # NTLM enabled
  570. $feature{"NTLM"} = $feat =~ /NTLM/i;
  571. # NTLM delegation to winbind daemon ntlm_auth helper enabled
  572. $feature{"NTLM_WB"} = $feat =~ /NTLM_WB/i;
  573. # SSPI enabled
  574. $feature{"SSPI"} = $feat =~ /SSPI/i;
  575. # GSS-API enabled
  576. $feature{"GSS-API"} = $feat =~ /GSS-API/i;
  577. # Kerberos enabled
  578. $feature{"Kerberos"} = $feat =~ /Kerberos/i;
  579. # SPNEGO enabled
  580. $feature{"SPNEGO"} = $feat =~ /SPNEGO/i;
  581. # TLS-SRP enabled
  582. $feature{"TLS-SRP"} = $feat =~ /TLS-SRP/i;
  583. # PSL enabled
  584. $feature{"PSL"} = $feat =~ /PSL/i;
  585. # alt-svc enabled
  586. $feature{"alt-svc"} = $feat =~ /alt-svc/i;
  587. # HSTS support
  588. $feature{"HSTS"} = $feat =~ /HSTS/i;
  589. if($feat =~ /AsynchDNS/i) {
  590. if(!$feature{"c-ares"}) {
  591. # this means threaded resolver
  592. $feature{"threaded-resolver"} = 1;
  593. $resolver="threaded";
  594. }
  595. }
  596. # http2 enabled
  597. $feature{"http/2"} = $feat =~ /HTTP2/;
  598. if($feature{"http/2"}) {
  599. push @protocols, 'http/2';
  600. }
  601. # http3 enabled
  602. $feature{"http/3"} = $feat =~ /HTTP3/;
  603. if($feature{"http/3"}) {
  604. push @protocols, 'http/3';
  605. }
  606. # https proxy support
  607. $feature{"HTTPS-proxy"} = $feat =~ /HTTPS-proxy/;
  608. if($feature{"HTTPS-proxy"}) {
  609. # 'https-proxy' is used as "server" so consider it a protocol
  610. push @protocols, 'https-proxy';
  611. }
  612. # UNICODE support
  613. $feature{"Unicode"} = $feat =~ /Unicode/i;
  614. # Thread-safe init
  615. $feature{"threadsafe"} = $feat =~ /threadsafe/i;
  616. }
  617. #
  618. # Test harness currently uses a non-stunnel server in order to
  619. # run HTTP TLS-SRP tests required when curl is built with https
  620. # protocol support and TLS-SRP feature enabled. For convenience
  621. # 'httptls' may be included in the test harness protocols array
  622. # to differentiate this from classic stunnel based 'https' test
  623. # harness server.
  624. #
  625. if($feature{"TLS-SRP"}) {
  626. my $add_httptls;
  627. for(@protocols) {
  628. if($_ =~ /^https(-ipv6|)$/) {
  629. $add_httptls=1;
  630. last;
  631. }
  632. }
  633. if($add_httptls && (! grep /^httptls$/, @protocols)) {
  634. push @protocols, 'httptls';
  635. push @protocols, 'httptls-ipv6';
  636. }
  637. }
  638. }
  639. if(!$curl) {
  640. logmsg "unable to get curl's version, further details are:\n";
  641. logmsg "issued command: \n";
  642. logmsg "$versioncmd \n";
  643. if ($versretval == -1) {
  644. logmsg "command failed with: \n";
  645. logmsg "$versnoexec \n";
  646. }
  647. elsif ($versretval & 127) {
  648. logmsg sprintf("command died with signal %d, and %s coredump.\n",
  649. ($versretval & 127), ($versretval & 128)?"a":"no");
  650. }
  651. else {
  652. logmsg sprintf("command exited with value %d \n", $versretval >> 8);
  653. }
  654. logmsg "contents of $curlverout: \n";
  655. displaylogcontent("$curlverout");
  656. logmsg "contents of $curlvererr: \n";
  657. displaylogcontent("$curlvererr");
  658. die "couldn't get curl's version";
  659. }
  660. if(-r "../lib/curl_config.h") {
  661. open(my $conf, "<", "../lib/curl_config.h");
  662. while(<$conf>) {
  663. if($_ =~ /^\#define HAVE_GETRLIMIT/) {
  664. # set if system has getrlimit()
  665. $feature{"getrlimit"} = 1;
  666. }
  667. }
  668. close($conf);
  669. }
  670. # allow this feature only if debug mode is disabled
  671. $feature{"ld_preload"} = $feature{"ld_preload"} && !$feature{"Debug"};
  672. if($feature{"IPv6"}) {
  673. # client has IPv6 support
  674. # check if the HTTP server has it!
  675. my $cmd = "server/sws".exe_ext('SRV')." --version";
  676. my @sws = `$cmd`;
  677. if($sws[0] =~ /IPv6/) {
  678. # HTTP server has IPv6 support!
  679. $http_ipv6 = 1;
  680. }
  681. # check if the FTP server has it!
  682. $cmd = "server/sockfilt".exe_ext('SRV')." --version";
  683. @sws = `$cmd`;
  684. if($sws[0] =~ /IPv6/) {
  685. # FTP server has IPv6 support!
  686. $ftp_ipv6 = 1;
  687. }
  688. }
  689. if($feature{"UnixSockets"}) {
  690. # client has Unix sockets support, check whether the HTTP server has it
  691. my $cmd = "server/sws".exe_ext('SRV')." --version";
  692. my @sws = `$cmd`;
  693. $http_unix = 1 if($sws[0] =~ /unix/);
  694. }
  695. open(my $manh, "-|", shell_quote($CURL) . " -M 2>&1");
  696. while(my $s = <$manh>) {
  697. if($s =~ /built-in manual was disabled at build-time/) {
  698. $feature{"manual"} = 0;
  699. last;
  700. }
  701. $feature{"manual"} = 1;
  702. last;
  703. }
  704. close($manh);
  705. $feature{"unittest"} = $feature{"Debug"};
  706. $feature{"nghttpx"} = !!$ENV{'NGHTTPX'};
  707. $feature{"nghttpx-h3"} = !!$nghttpx_h3;
  708. #
  709. # strings that must exactly match the names used in server/disabled.c
  710. #
  711. $feature{"cookies"} = 1;
  712. # Use this as a proxy for any cryptographic authentication
  713. $feature{"crypto"} = $feature{"NTLM"} || $feature{"Kerberos"} || $feature{"SPNEGO"};
  714. $feature{"DoH"} = 1;
  715. $feature{"HTTP-auth"} = 1;
  716. $feature{"Mime"} = 1;
  717. $feature{"form-api"} = 1;
  718. $feature{"netrc"} = 1;
  719. $feature{"parsedate"} = 1;
  720. $feature{"proxy"} = 1;
  721. $feature{"shuffle-dns"} = 1;
  722. $feature{"typecheck"} = 1;
  723. $feature{"verbose-strings"} = 1;
  724. $feature{"wakeup"} = 1;
  725. $feature{"headers-api"} = 1;
  726. $feature{"xattr"} = 1;
  727. $feature{"large-time"} = 1;
  728. $feature{"sha512-256"} = 1;
  729. # make each protocol an enabled "feature"
  730. for my $p (@protocols) {
  731. $feature{$p} = 1;
  732. }
  733. # 'socks' was once here but is now removed
  734. $has_shared = `sh $CURLCONFIG --built-shared`;
  735. chomp $has_shared;
  736. $has_shared = $has_shared eq "yes";
  737. if(!$feature{"TrackMemory"} && $torture) {
  738. die "can't run torture tests since curl was built without ".
  739. "TrackMemory feature (--enable-curldebug)";
  740. }
  741. my $hostname=join(' ', runclientoutput("hostname"));
  742. my $hosttype=join(' ', runclientoutput("uname -a"));
  743. my $hostos=$^O;
  744. # display summary information about curl and the test host
  745. logmsg ("********* System characteristics ******** \n",
  746. "* $curl\n",
  747. "* $libcurl\n",
  748. "* Features: $feat\n",
  749. "* Disabled: $dis\n",
  750. "* Host: $hostname",
  751. "* System: $hosttype",
  752. "* OS: $hostos\n");
  753. if($jobs) {
  754. # Only show if not the default for now
  755. logmsg "* Jobs: $jobs\n";
  756. }
  757. if($feature{"TrackMemory"} && $feature{"threaded-resolver"}) {
  758. logmsg("*\n",
  759. "*** DISABLES memory tracking when using threaded resolver\n",
  760. "*\n");
  761. }
  762. logmsg sprintf("* Env: %s%s%s", $valgrind?"Valgrind ":"",
  763. $run_event_based?"event-based ":"",
  764. $nghttpx_h3);
  765. logmsg sprintf("%s\n", $libtool?"Libtool ":"");
  766. logmsg ("* Seed: $randseed\n");
  767. # Disable memory tracking when using threaded resolver
  768. $feature{"TrackMemory"} = $feature{"TrackMemory"} && !$feature{"threaded-resolver"};
  769. # toggle off the features that were disabled in the build
  770. for my $d(@disabled) {
  771. $feature{$d} = 0;
  772. }
  773. }
  774. #######################################################################
  775. # display information about server features
  776. #
  777. sub displayserverfeatures {
  778. logmsg sprintf("* Servers: %s", $stunnel?"SSL ":"");
  779. logmsg sprintf("%s", $http_ipv6?"HTTP-IPv6 ":"");
  780. logmsg sprintf("%s", $http_unix?"HTTP-unix ":"");
  781. logmsg sprintf("%s\n", $ftp_ipv6?"FTP-IPv6 ":"");
  782. logmsg "***************************************** \n";
  783. }
  784. #######################################################################
  785. # Provide time stamps for single test skipped events
  786. #
  787. sub timestampskippedevents {
  788. my $testnum = $_[0];
  789. return if((not defined($testnum)) || ($testnum < 1));
  790. if($timestats) {
  791. if($timevrfyend{$testnum}) {
  792. return;
  793. }
  794. elsif($timesrvrlog{$testnum}) {
  795. $timevrfyend{$testnum} = $timesrvrlog{$testnum};
  796. return;
  797. }
  798. elsif($timetoolend{$testnum}) {
  799. $timevrfyend{$testnum} = $timetoolend{$testnum};
  800. $timesrvrlog{$testnum} = $timetoolend{$testnum};
  801. }
  802. elsif($timetoolini{$testnum}) {
  803. $timevrfyend{$testnum} = $timetoolini{$testnum};
  804. $timesrvrlog{$testnum} = $timetoolini{$testnum};
  805. $timetoolend{$testnum} = $timetoolini{$testnum};
  806. }
  807. elsif($timesrvrend{$testnum}) {
  808. $timevrfyend{$testnum} = $timesrvrend{$testnum};
  809. $timesrvrlog{$testnum} = $timesrvrend{$testnum};
  810. $timetoolend{$testnum} = $timesrvrend{$testnum};
  811. $timetoolini{$testnum} = $timesrvrend{$testnum};
  812. }
  813. elsif($timesrvrini{$testnum}) {
  814. $timevrfyend{$testnum} = $timesrvrini{$testnum};
  815. $timesrvrlog{$testnum} = $timesrvrini{$testnum};
  816. $timetoolend{$testnum} = $timesrvrini{$testnum};
  817. $timetoolini{$testnum} = $timesrvrini{$testnum};
  818. $timesrvrend{$testnum} = $timesrvrini{$testnum};
  819. }
  820. elsif($timeprepini{$testnum}) {
  821. $timevrfyend{$testnum} = $timeprepini{$testnum};
  822. $timesrvrlog{$testnum} = $timeprepini{$testnum};
  823. $timetoolend{$testnum} = $timeprepini{$testnum};
  824. $timetoolini{$testnum} = $timeprepini{$testnum};
  825. $timesrvrend{$testnum} = $timeprepini{$testnum};
  826. $timesrvrini{$testnum} = $timeprepini{$testnum};
  827. }
  828. }
  829. }
  830. # Setup CI Test Run
  831. sub citest_starttestrun {
  832. if(azure_check_environment()) {
  833. $AZURE_RUN_ID = azure_create_test_run($ACURL);
  834. logmsg "Azure Run ID: $AZURE_RUN_ID\n" if ($verbose);
  835. }
  836. # Appveyor doesn't require anything here
  837. }
  838. # Register the test case with the CI runner
  839. sub citest_starttest {
  840. my $testnum = $_[0];
  841. # get the name of the test early
  842. my $testname= (getpart("client", "name"))[0];
  843. chomp $testname;
  844. # create test result in CI services
  845. if(azure_check_environment() && $AZURE_RUN_ID) {
  846. $AZURE_RESULT_ID = azure_create_test_result($ACURL, $AZURE_RUN_ID, $testnum, $testname);
  847. }
  848. elsif(appveyor_check_environment()) {
  849. appveyor_create_test_result($ACURL, $testnum, $testname);
  850. }
  851. }
  852. # Submit the test case result with the CI runner
  853. sub citest_finishtest {
  854. my ($testnum, $error) = @_;
  855. # update test result in CI services
  856. if(azure_check_environment() && $AZURE_RUN_ID && $AZURE_RESULT_ID) {
  857. $AZURE_RESULT_ID = azure_update_test_result($ACURL, $AZURE_RUN_ID, $AZURE_RESULT_ID, $testnum, $error,
  858. $timeprepini{$testnum}, $timevrfyend{$testnum});
  859. }
  860. elsif(appveyor_check_environment()) {
  861. appveyor_update_test_result($ACURL, $testnum, $error, $timeprepini{$testnum}, $timevrfyend{$testnum});
  862. }
  863. }
  864. # Complete CI test run
  865. sub citest_finishtestrun {
  866. if(azure_check_environment() && $AZURE_RUN_ID) {
  867. $AZURE_RUN_ID = azure_update_test_run($ACURL, $AZURE_RUN_ID);
  868. }
  869. # Appveyor doesn't require anything here
  870. }
  871. # add one set of test timings from the runner to global set
  872. sub updatetesttimings {
  873. my ($testnum, %testtimings)=@_;
  874. if(defined $testtimings{"timeprepini"}) {
  875. $timeprepini{$testnum} = $testtimings{"timeprepini"};
  876. }
  877. if(defined $testtimings{"timesrvrini"}) {
  878. $timesrvrini{$testnum} = $testtimings{"timesrvrini"};
  879. }
  880. if(defined $testtimings{"timesrvrend"}) {
  881. $timesrvrend{$testnum} = $testtimings{"timesrvrend"};
  882. }
  883. if(defined $testtimings{"timetoolini"}) {
  884. $timetoolini{$testnum} = $testtimings{"timetoolini"};
  885. }
  886. if(defined $testtimings{"timetoolend"}) {
  887. $timetoolend{$testnum} = $testtimings{"timetoolend"};
  888. }
  889. if(defined $testtimings{"timesrvrlog"}) {
  890. $timesrvrlog{$testnum} = $testtimings{"timesrvrlog"};
  891. }
  892. }
  893. #######################################################################
  894. # Return the log directory for the given test runner
  895. sub getrunnernumlogdir {
  896. my $runnernum = $_[0];
  897. return $jobs > 1 ? "$LOGDIR/$runnernum" : $LOGDIR;
  898. }
  899. #######################################################################
  900. # Return the log directory for the given test runner ID
  901. sub getrunnerlogdir {
  902. my $runnerid = $_[0];
  903. if($jobs <= 1) {
  904. return $LOGDIR;
  905. }
  906. # TODO: speed up this O(n) operation
  907. for my $runnernum (keys %runnerids) {
  908. if($runnerid eq $runnerids{$runnernum}) {
  909. return "$LOGDIR/$runnernum";
  910. }
  911. }
  912. die "Internal error: runner ID $runnerid not found";
  913. }
  914. #######################################################################
  915. # Verify that this test case should be run
  916. sub singletest_shouldrun {
  917. my $testnum = $_[0];
  918. my $why; # why the test won't be run
  919. my $errorreturncode = 1; # 1 means normal error, 2 means ignored error
  920. my @what; # what features are needed
  921. if($disttests !~ /test$testnum(\W|\z)/ ) {
  922. logmsg "Warning: test$testnum not present in tests/data/Makefile.inc\n";
  923. }
  924. if($disabled{$testnum}) {
  925. if(!$run_disabled) {
  926. $why = "listed in DISABLED";
  927. }
  928. else {
  929. logmsg "Warning: test$testnum is explicitly disabled\n";
  930. }
  931. }
  932. if($ignored{$testnum}) {
  933. logmsg "Warning: test$testnum result is ignored\n";
  934. $errorreturncode = 2;
  935. }
  936. if(loadtest("${TESTDIR}/test${testnum}")) {
  937. if($verbose) {
  938. # this is not a test
  939. logmsg "RUN: $testnum doesn't look like a test case\n";
  940. }
  941. $why = "no test";
  942. }
  943. else {
  944. @what = getpart("client", "features");
  945. }
  946. # We require a feature to be present
  947. for(@what) {
  948. my $f = $_;
  949. $f =~ s/\s//g;
  950. if($f =~ /^([^!].*)$/) {
  951. if($feature{$1}) {
  952. next;
  953. }
  954. $why = "curl lacks $1 support";
  955. last;
  956. }
  957. }
  958. # We require a feature to not be present
  959. if(!$why) {
  960. for(@what) {
  961. my $f = $_;
  962. $f =~ s/\s//g;
  963. if($f =~ /^!(.*)$/) {
  964. if(!$feature{$1}) {
  965. next;
  966. }
  967. }
  968. else {
  969. next;
  970. }
  971. $why = "curl has $1 support";
  972. last;
  973. }
  974. }
  975. my @info_keywords;
  976. if(!$why) {
  977. @info_keywords = getpart("info", "keywords");
  978. if(!$info_keywords[0]) {
  979. $why = "missing the <keywords> section!";
  980. }
  981. my $match;
  982. for my $k (@info_keywords) {
  983. chomp $k;
  984. if ($disabled_keywords{lc($k)}) {
  985. $why = "disabled by keyword";
  986. }
  987. elsif ($enabled_keywords{lc($k)}) {
  988. $match = 1;
  989. }
  990. if ($ignored_keywords{lc($k)}) {
  991. logmsg "Warning: test$testnum result is ignored due to $k\n";
  992. $errorreturncode = 2;
  993. }
  994. }
  995. if(!$why && !$match && %enabled_keywords) {
  996. $why = "disabled by missing keyword";
  997. }
  998. }
  999. if (!$why && defined $custom_skip_reasons{test}{$testnum}) {
  1000. $why = $custom_skip_reasons{test}{$testnum};
  1001. }
  1002. if (!$why && defined $custom_skip_reasons{tool}) {
  1003. foreach my $tool (getpart("client", "tool")) {
  1004. foreach my $tool_skip_pattern (keys %{$custom_skip_reasons{tool}}) {
  1005. if ($tool =~ /$tool_skip_pattern/i) {
  1006. $why = $custom_skip_reasons{tool}{$tool_skip_pattern};
  1007. }
  1008. }
  1009. }
  1010. }
  1011. if (!$why && defined $custom_skip_reasons{keyword}) {
  1012. foreach my $keyword (@info_keywords) {
  1013. foreach my $keyword_skip_pattern (keys %{$custom_skip_reasons{keyword}}) {
  1014. if ($keyword =~ /$keyword_skip_pattern/i) {
  1015. $why = $custom_skip_reasons{keyword}{$keyword_skip_pattern};
  1016. }
  1017. }
  1018. }
  1019. }
  1020. return ($why, $errorreturncode);
  1021. }
  1022. #######################################################################
  1023. # Print the test name and count tests
  1024. sub singletest_count {
  1025. my ($testnum, $why) = @_;
  1026. if($why && !$listonly) {
  1027. # there's a problem, count it as "skipped"
  1028. $skipped{$why}++;
  1029. $teststat[$testnum]=$why; # store reason for this test case
  1030. if(!$short) {
  1031. if($skipped{$why} <= 3) {
  1032. # show only the first three skips for each reason
  1033. logmsg sprintf("test %04d SKIPPED: $why\n", $testnum);
  1034. }
  1035. }
  1036. timestampskippedevents($testnum);
  1037. return -1;
  1038. }
  1039. # At this point we've committed to run this test
  1040. logmsg sprintf("test %04d...", $testnum) if(!$automakestyle);
  1041. # name of the test
  1042. my $testname= (getpart("client", "name"))[0];
  1043. chomp $testname;
  1044. logmsg "[$testname]\n" if(!$short);
  1045. if($listonly) {
  1046. timestampskippedevents($testnum);
  1047. }
  1048. return 0;
  1049. }
  1050. #######################################################################
  1051. # Verify test succeeded
  1052. sub singletest_check {
  1053. my ($runnerid, $testnum, $cmdres, $CURLOUT, $tool, $usedvalgrind)=@_;
  1054. # Skip all the verification on torture tests
  1055. if ($torture) {
  1056. # timestamp test result verification end
  1057. $timevrfyend{$testnum} = Time::HiRes::time();
  1058. return -2;
  1059. }
  1060. my $logdir = getrunnerlogdir($runnerid);
  1061. my @err = getpart("verify", "errorcode");
  1062. my $errorcode = $err[0] || "0";
  1063. my $ok="";
  1064. my $res;
  1065. chomp $errorcode;
  1066. my $testname= (getpart("client", "name"))[0];
  1067. chomp $testname;
  1068. # what parts to cut off from stdout/stderr
  1069. my @stripfile = getpart("verify", "stripfile");
  1070. my @validstdout = getpart("verify", "stdout");
  1071. # get all attributes
  1072. my %hash = getpartattr("verify", "stdout");
  1073. my $loadfile = $hash{'loadfile'};
  1074. if ($loadfile) {
  1075. open(my $tmp, "<", "$loadfile") || die "Cannot open file $loadfile: $!";
  1076. @validstdout = <$tmp>;
  1077. close($tmp);
  1078. # Enforce LF newlines on load
  1079. s/\r\n/\n/g for @validstdout;
  1080. }
  1081. if (@validstdout) {
  1082. # verify redirected stdout
  1083. my @actual = loadarray(stdoutfilename($logdir, $testnum));
  1084. foreach my $strip (@stripfile) {
  1085. chomp $strip;
  1086. my @newgen;
  1087. for(@actual) {
  1088. eval $strip;
  1089. if($_) {
  1090. push @newgen, $_;
  1091. }
  1092. }
  1093. # this is to get rid of array entries that vanished (zero
  1094. # length) because of replacements
  1095. @actual = @newgen;
  1096. }
  1097. # get the mode attribute
  1098. my $filemode=$hash{'mode'};
  1099. if($filemode && ($filemode eq "text") && $has_textaware) {
  1100. # text mode when running on windows: fix line endings
  1101. s/\r\n/\n/g for @validstdout;
  1102. s/\n/\r\n/g for @validstdout;
  1103. s/\r\n/\n/g for @actual;
  1104. s/\n/\r\n/g for @actual;
  1105. }
  1106. if($hash{'nonewline'}) {
  1107. # Yes, we must cut off the final newline from the final line
  1108. # of the protocol data
  1109. chomp($validstdout[-1]);
  1110. }
  1111. if($hash{'crlf'} ||
  1112. ($feature{"hyper"} && ($keywords{"HTTP"}
  1113. || $keywords{"HTTPS"}))) {
  1114. subnewlines(0, \$_) for @validstdout;
  1115. }
  1116. $res = compare($runnerid, $testnum, $testname, "stdout", \@actual, \@validstdout);
  1117. if($res) {
  1118. return -1;
  1119. }
  1120. $ok .= "s";
  1121. }
  1122. else {
  1123. $ok .= "-"; # stdout not checked
  1124. }
  1125. my @validstderr = getpart("verify", "stderr");
  1126. if (@validstderr) {
  1127. # verify redirected stderr
  1128. my @actual = loadarray(stderrfilename($logdir, $testnum));
  1129. foreach my $strip (@stripfile) {
  1130. chomp $strip;
  1131. my @newgen;
  1132. for(@actual) {
  1133. eval $strip;
  1134. if($_) {
  1135. push @newgen, $_;
  1136. }
  1137. }
  1138. # this is to get rid of array entries that vanished (zero
  1139. # length) because of replacements
  1140. @actual = @newgen;
  1141. }
  1142. # get all attributes
  1143. my %hash = getpartattr("verify", "stderr");
  1144. # get the mode attribute
  1145. my $filemode=$hash{'mode'};
  1146. if($filemode && ($filemode eq "text") && $feature{"hyper"}) {
  1147. # text mode check in hyper-mode. Sometimes necessary if the stderr
  1148. # data *looks* like HTTP and thus has gotten CRLF newlines
  1149. # mistakenly
  1150. s/\r\n/\n/g for @validstderr;
  1151. }
  1152. if($filemode && ($filemode eq "text") && $has_textaware) {
  1153. # text mode when running on windows: fix line endings
  1154. s/\r\n/\n/g for @validstderr;
  1155. s/\n/\r\n/g for @validstderr;
  1156. }
  1157. if($hash{'nonewline'}) {
  1158. # Yes, we must cut off the final newline from the final line
  1159. # of the protocol data
  1160. chomp($validstderr[-1]);
  1161. }
  1162. if($hash{'crlf'}) {
  1163. subnewlines(0, \$_) for @validstderr;
  1164. }
  1165. $res = compare($runnerid, $testnum, $testname, "stderr", \@actual, \@validstderr);
  1166. if($res) {
  1167. return -1;
  1168. }
  1169. $ok .= "r";
  1170. }
  1171. else {
  1172. $ok .= "-"; # stderr not checked
  1173. }
  1174. # what to cut off from the live protocol sent by curl
  1175. my @strip = getpart("verify", "strip");
  1176. # what parts to cut off from the protocol & upload
  1177. my @strippart = getpart("verify", "strippart");
  1178. # this is the valid protocol blurb curl should generate
  1179. my @protocol= getpart("verify", "protocol");
  1180. if(@protocol) {
  1181. # Verify the sent request
  1182. my @out = loadarray("$logdir/$SERVERIN");
  1183. # check if there's any attributes on the verify/protocol section
  1184. my %hash = getpartattr("verify", "protocol");
  1185. if($hash{'nonewline'}) {
  1186. # Yes, we must cut off the final newline from the final line
  1187. # of the protocol data
  1188. chomp($protocol[-1]);
  1189. }
  1190. for(@strip) {
  1191. # strip off all lines that match the patterns from both arrays
  1192. chomp $_;
  1193. @out = striparray( $_, \@out);
  1194. @protocol= striparray( $_, \@protocol);
  1195. }
  1196. for my $strip (@strippart) {
  1197. chomp $strip;
  1198. for(@out) {
  1199. eval $strip;
  1200. }
  1201. }
  1202. if($hash{'crlf'}) {
  1203. subnewlines(1, \$_) for @protocol;
  1204. }
  1205. if((!$out[0] || ($out[0] eq "")) && $protocol[0]) {
  1206. logmsg "\n $testnum: protocol FAILED!\n".
  1207. " There was no content at all in the file $logdir/$SERVERIN.\n".
  1208. " Server glitch? Total curl failure? Returned: $cmdres\n";
  1209. # timestamp test result verification end
  1210. $timevrfyend{$testnum} = Time::HiRes::time();
  1211. return -1;
  1212. }
  1213. $res = compare($runnerid, $testnum, $testname, "protocol", \@out, \@protocol);
  1214. if($res) {
  1215. return -1;
  1216. }
  1217. $ok .= "p";
  1218. }
  1219. else {
  1220. $ok .= "-"; # protocol not checked
  1221. }
  1222. my %replyattr = getpartattr("reply", "data");
  1223. my @reply;
  1224. if (partexists("reply", "datacheck")) {
  1225. for my $partsuffix (('', '1', '2', '3', '4')) {
  1226. my @replycheckpart = getpart("reply", "datacheck".$partsuffix);
  1227. if(@replycheckpart) {
  1228. my %replycheckpartattr = getpartattr("reply", "datacheck".$partsuffix);
  1229. # get the mode attribute
  1230. my $filemode=$replycheckpartattr{'mode'};
  1231. if($filemode && ($filemode eq "text") && $has_textaware) {
  1232. # text mode when running on windows: fix line endings
  1233. s/\r\n/\n/g for @replycheckpart;
  1234. s/\n/\r\n/g for @replycheckpart;
  1235. }
  1236. if($replycheckpartattr{'nonewline'}) {
  1237. # Yes, we must cut off the final newline from the final line
  1238. # of the datacheck
  1239. chomp($replycheckpart[-1]);
  1240. }
  1241. if($replycheckpartattr{'crlf'} ||
  1242. ($feature{"hyper"} && ($keywords{"HTTP"}
  1243. || $keywords{"HTTPS"}))) {
  1244. subnewlines(0, \$_) for @replycheckpart;
  1245. }
  1246. push(@reply, @replycheckpart);
  1247. }
  1248. }
  1249. }
  1250. else {
  1251. # check against the data section
  1252. @reply = getpart("reply", "data");
  1253. if(@reply) {
  1254. if($replyattr{'nonewline'}) {
  1255. # cut off the final newline from the final line of the data
  1256. chomp($reply[-1]);
  1257. }
  1258. }
  1259. # get the mode attribute
  1260. my $filemode=$replyattr{'mode'};
  1261. if($filemode && ($filemode eq "text") && $has_textaware) {
  1262. # text mode when running on windows: fix line endings
  1263. s/\r\n/\n/g for @reply;
  1264. s/\n/\r\n/g for @reply;
  1265. }
  1266. if($replyattr{'crlf'} ||
  1267. ($feature{"hyper"} && ($keywords{"HTTP"}
  1268. || $keywords{"HTTPS"}))) {
  1269. subnewlines(0, \$_) for @reply;
  1270. }
  1271. }
  1272. if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
  1273. # verify the received data
  1274. my @out = loadarray($CURLOUT);
  1275. $res = compare($runnerid, $testnum, $testname, "data", \@out, \@reply);
  1276. if ($res) {
  1277. return -1;
  1278. }
  1279. $ok .= "d";
  1280. }
  1281. else {
  1282. $ok .= "-"; # data not checked
  1283. }
  1284. # if this section exists, we verify upload
  1285. my @upload = getpart("verify", "upload");
  1286. if(@upload) {
  1287. my %hash = getpartattr("verify", "upload");
  1288. if($hash{'nonewline'}) {
  1289. # cut off the final newline from the final line of the upload data
  1290. chomp($upload[-1]);
  1291. }
  1292. for my $line (@upload) {
  1293. subbase64(\$line);
  1294. }
  1295. # verify uploaded data
  1296. my @out = loadarray("$logdir/upload.$testnum");
  1297. for my $strip (@strippart) {
  1298. chomp $strip;
  1299. for(@out) {
  1300. eval $strip;
  1301. }
  1302. }
  1303. $res = compare($runnerid, $testnum, $testname, "upload", \@out, \@upload);
  1304. if ($res) {
  1305. return -1;
  1306. }
  1307. $ok .= "u";
  1308. }
  1309. else {
  1310. $ok .= "-"; # upload not checked
  1311. }
  1312. # this is the valid protocol blurb curl should generate to a proxy
  1313. my @proxyprot = getpart("verify", "proxy");
  1314. if(@proxyprot) {
  1315. # Verify the sent proxy request
  1316. # check if there's any attributes on the verify/protocol section
  1317. my %hash = getpartattr("verify", "proxy");
  1318. if($hash{'nonewline'}) {
  1319. # Yes, we must cut off the final newline from the final line
  1320. # of the protocol data
  1321. chomp($proxyprot[-1]);
  1322. }
  1323. my @out = loadarray("$logdir/$PROXYIN");
  1324. for(@strip) {
  1325. # strip off all lines that match the patterns from both arrays
  1326. chomp $_;
  1327. @out = striparray( $_, \@out);
  1328. @proxyprot= striparray( $_, \@proxyprot);
  1329. }
  1330. for my $strip (@strippart) {
  1331. chomp $strip;
  1332. for(@out) {
  1333. eval $strip;
  1334. }
  1335. }
  1336. if($hash{'crlf'} ||
  1337. ($feature{"hyper"} && ($keywords{"HTTP"} || $keywords{"HTTPS"}))) {
  1338. subnewlines(0, \$_) for @proxyprot;
  1339. }
  1340. $res = compare($runnerid, $testnum, $testname, "proxy", \@out, \@proxyprot);
  1341. if($res) {
  1342. return -1;
  1343. }
  1344. $ok .= "P";
  1345. }
  1346. else {
  1347. $ok .= "-"; # proxy not checked
  1348. }
  1349. my $outputok;
  1350. for my $partsuffix (('', '1', '2', '3', '4')) {
  1351. my @outfile=getpart("verify", "file".$partsuffix);
  1352. if(@outfile || partexists("verify", "file".$partsuffix) ) {
  1353. # we're supposed to verify a dynamically generated file!
  1354. my %hash = getpartattr("verify", "file".$partsuffix);
  1355. my $filename=$hash{'name'};
  1356. if(!$filename) {
  1357. logmsg " $testnum: IGNORED: section verify=>file$partsuffix ".
  1358. "has no name attribute\n";
  1359. if (runnerac_stopservers($runnerid)) {
  1360. logmsg "ERROR: runner $runnerid seems to have died\n";
  1361. } else {
  1362. # TODO: this is a blocking call that will stall the controller,
  1363. if($verbose) {
  1364. logmsg "WARNING: blocking call in async function\n";
  1365. }
  1366. # but this error condition should never happen except during
  1367. # development.
  1368. my ($rid, $unexpected, $logs) = runnerar($runnerid);
  1369. if(!$rid) {
  1370. logmsg "ERROR: runner $runnerid seems to have died\n";
  1371. } else {
  1372. logmsg $logs;
  1373. }
  1374. }
  1375. # timestamp test result verification end
  1376. $timevrfyend{$testnum} = Time::HiRes::time();
  1377. return -1;
  1378. }
  1379. my @generated=loadarray($filename);
  1380. # what parts to cut off from the file
  1381. my @stripfilepar = getpart("verify", "stripfile".$partsuffix);
  1382. my $filemode=$hash{'mode'};
  1383. if($filemode && ($filemode eq "text") && $has_textaware) {
  1384. # text mode when running on windows: fix line endings
  1385. s/\r\n/\n/g for @outfile;
  1386. s/\n/\r\n/g for @outfile;
  1387. }
  1388. if($hash{'crlf'} ||
  1389. ($feature{"hyper"} && ($keywords{"HTTP"}
  1390. || $keywords{"HTTPS"}))) {
  1391. subnewlines(0, \$_) for @outfile;
  1392. }
  1393. for my $strip (@stripfilepar) {
  1394. chomp $strip;
  1395. my @newgen;
  1396. for(@generated) {
  1397. eval $strip;
  1398. if($_) {
  1399. push @newgen, $_;
  1400. }
  1401. }
  1402. # this is to get rid of array entries that vanished (zero
  1403. # length) because of replacements
  1404. @generated = @newgen;
  1405. }
  1406. if($hash{'nonewline'}) {
  1407. # cut off the final newline from the final line of the
  1408. # output data
  1409. chomp($outfile[-1]);
  1410. }
  1411. $res = compare($runnerid, $testnum, $testname, "output ($filename)",
  1412. \@generated, \@outfile);
  1413. if($res) {
  1414. return -1;
  1415. }
  1416. $outputok = 1; # output checked
  1417. }
  1418. }
  1419. $ok .= ($outputok) ? "o" : "-"; # output checked or not
  1420. # verify SOCKS proxy details
  1421. my @socksprot = getpart("verify", "socks");
  1422. if(@socksprot) {
  1423. # Verify the sent SOCKS proxy details
  1424. my @out = loadarray("$logdir/$SOCKSIN");
  1425. $res = compare($runnerid, $testnum, $testname, "socks", \@out, \@socksprot);
  1426. if($res) {
  1427. return -1;
  1428. }
  1429. }
  1430. # accept multiple comma-separated error codes
  1431. my @splerr = split(/ *, */, $errorcode);
  1432. my $errok;
  1433. foreach my $e (@splerr) {
  1434. if($e == $cmdres) {
  1435. # a fine error code
  1436. $errok = 1;
  1437. last;
  1438. }
  1439. }
  1440. if($errok) {
  1441. $ok .= "e";
  1442. }
  1443. else {
  1444. if(!$short) {
  1445. logmsg sprintf("\n%s returned $cmdres, when expecting %s\n",
  1446. (!$tool)?"curl":$tool, $errorcode);
  1447. }
  1448. logmsg " $testnum: exit FAILED\n";
  1449. # timestamp test result verification end
  1450. $timevrfyend{$testnum} = Time::HiRes::time();
  1451. return -1;
  1452. }
  1453. if($feature{"TrackMemory"}) {
  1454. if(! -f "$logdir/$MEMDUMP") {
  1455. my %cmdhash = getpartattr("client", "command");
  1456. my $cmdtype = $cmdhash{'type'} || "default";
  1457. logmsg "\n** ALERT! memory tracking with no output file?\n"
  1458. if(!$cmdtype eq "perl");
  1459. $ok .= "-"; # problem with memory checking
  1460. }
  1461. else {
  1462. my @memdata=`$memanalyze "$logdir/$MEMDUMP"`;
  1463. my $leak=0;
  1464. for(@memdata) {
  1465. if($_ ne "") {
  1466. # well it could be other memory problems as well, but
  1467. # we call it leak for short here
  1468. $leak=1;
  1469. }
  1470. }
  1471. if($leak) {
  1472. logmsg "\n** MEMORY FAILURE\n";
  1473. logmsg @memdata;
  1474. # timestamp test result verification end
  1475. $timevrfyend{$testnum} = Time::HiRes::time();
  1476. return -1;
  1477. }
  1478. else {
  1479. $ok .= "m";
  1480. }
  1481. }
  1482. }
  1483. else {
  1484. $ok .= "-"; # memory not checked
  1485. }
  1486. if($valgrind) {
  1487. if($usedvalgrind) {
  1488. if(!opendir(DIR, "$logdir")) {
  1489. logmsg "ERROR: unable to read $logdir\n";
  1490. # timestamp test result verification end
  1491. $timevrfyend{$testnum} = Time::HiRes::time();
  1492. return -1;
  1493. }
  1494. my @files = readdir(DIR);
  1495. closedir(DIR);
  1496. my $vgfile;
  1497. foreach my $file (@files) {
  1498. if($file =~ /^valgrind$testnum(\..*|)$/) {
  1499. $vgfile = $file;
  1500. last;
  1501. }
  1502. }
  1503. if(!$vgfile) {
  1504. logmsg "ERROR: valgrind log file missing for test $testnum\n";
  1505. # timestamp test result verification end
  1506. $timevrfyend{$testnum} = Time::HiRes::time();
  1507. return -1;
  1508. }
  1509. my @e = valgrindparse("$logdir/$vgfile");
  1510. if(@e && $e[0]) {
  1511. if($automakestyle) {
  1512. logmsg "FAIL: $testnum - $testname - valgrind\n";
  1513. }
  1514. else {
  1515. logmsg " valgrind ERROR ";
  1516. logmsg @e;
  1517. }
  1518. # timestamp test result verification end
  1519. $timevrfyend{$testnum} = Time::HiRes::time();
  1520. return -1;
  1521. }
  1522. $ok .= "v";
  1523. }
  1524. else {
  1525. if($verbose) {
  1526. logmsg " valgrind SKIPPED\n";
  1527. }
  1528. $ok .= "-"; # skipped
  1529. }
  1530. }
  1531. else {
  1532. $ok .= "-"; # valgrind not checked
  1533. }
  1534. # add 'E' for event-based
  1535. $ok .= $run_event_based ? "E" : "-";
  1536. logmsg "$ok " if(!$short);
  1537. # timestamp test result verification end
  1538. $timevrfyend{$testnum} = Time::HiRes::time();
  1539. return 0;
  1540. }
  1541. #######################################################################
  1542. # Report a successful test
  1543. sub singletest_success {
  1544. my ($testnum, $count, $total, $errorreturncode)=@_;
  1545. my $sofar= time()-$start;
  1546. my $esttotal = $sofar/$count * $total;
  1547. my $estleft = $esttotal - $sofar;
  1548. my $timeleft=sprintf("remaining: %02d:%02d",
  1549. $estleft/60,
  1550. $estleft%60);
  1551. my $took = $timevrfyend{$testnum} - $timeprepini{$testnum};
  1552. my $duration = sprintf("duration: %02d:%02d",
  1553. $sofar/60, $sofar%60);
  1554. if(!$automakestyle) {
  1555. logmsg sprintf("OK (%-3d out of %-3d, %s, took %.3fs, %s)\n",
  1556. $count, $total, $timeleft, $took, $duration);
  1557. }
  1558. else {
  1559. my $testname= (getpart("client", "name"))[0];
  1560. chomp $testname;
  1561. logmsg "PASS: $testnum - $testname\n";
  1562. }
  1563. if($errorreturncode==2) {
  1564. logmsg "Warning: test$testnum result is ignored, but passed!\n";
  1565. }
  1566. }
  1567. #######################################################################
  1568. # Run a single specified test case
  1569. # This is structured as a state machine which changes state after an
  1570. # asynchronous call is made that awaits a response. The function returns with
  1571. # an error code and a flag that indicates if the state machine has completed,
  1572. # which means (if not) the function must be called again once the response has
  1573. # arrived.
  1574. #
  1575. sub singletest {
  1576. my ($runnerid, $testnum, $count, $total)=@_;
  1577. # start buffering logmsg; stop it on return
  1578. logmsg_bufferfortest($runnerid);
  1579. if(!exists $singletest_state{$runnerid}) {
  1580. # First time in singletest() for this test
  1581. $singletest_state{$runnerid} = ST_INIT;
  1582. }
  1583. if($singletest_state{$runnerid} == ST_INIT) {
  1584. my $logdir = getrunnerlogdir($runnerid);
  1585. # first, remove all lingering log & lock files
  1586. if((!cleardir($logdir) || !cleardir("$logdir/$LOCKDIR"))
  1587. && $clearlocks) {
  1588. # On Windows, lock files can't be deleted when the process still
  1589. # has them open, so kill those processes first
  1590. if(runnerac_clearlocks($runnerid, "$logdir/$LOCKDIR")) {
  1591. logmsg "ERROR: runner $runnerid seems to have died\n";
  1592. $singletest_state{$runnerid} = ST_INIT;
  1593. return (-1, 0);
  1594. }
  1595. $singletest_state{$runnerid} = ST_CLEARLOCKS;
  1596. } else {
  1597. $singletest_state{$runnerid} = ST_INITED;
  1598. # Recursively call the state machine again because there is no
  1599. # event expected that would otherwise trigger a new call.
  1600. return singletest(@_);
  1601. }
  1602. } elsif($singletest_state{$runnerid} == ST_CLEARLOCKS) {
  1603. my ($rid, $logs) = runnerar($runnerid);
  1604. if(!$rid) {
  1605. logmsg "ERROR: runner $runnerid seems to have died\n";
  1606. $singletest_state{$runnerid} = ST_INIT;
  1607. return (-1, 0);
  1608. }
  1609. logmsg $logs;
  1610. my $logdir = getrunnerlogdir($runnerid);
  1611. cleardir($logdir);
  1612. $singletest_state{$runnerid} = ST_INITED;
  1613. # Recursively call the state machine again because there is no
  1614. # event expected that would otherwise trigger a new call.
  1615. return singletest(@_);
  1616. } elsif($singletest_state{$runnerid} == ST_INITED) {
  1617. ###################################################################
  1618. # Restore environment variables that were modified in a previous run.
  1619. # Test definition may instruct to (un)set environment vars.
  1620. # This is done this early so that leftover variables don't affect
  1621. # starting servers or CI registration.
  1622. # restore_test_env(1);
  1623. ###################################################################
  1624. # Load test file so CI registration can get the right data before the
  1625. # runner is called
  1626. loadtest("${TESTDIR}/test${testnum}");
  1627. ###################################################################
  1628. # Register the test case with the CI environment
  1629. citest_starttest($testnum);
  1630. if(runnerac_test_preprocess($runnerid, $testnum)) {
  1631. logmsg "ERROR: runner $runnerid seems to have died\n";
  1632. $singletest_state{$runnerid} = ST_INIT;
  1633. return (-1, 0);
  1634. }
  1635. $singletest_state{$runnerid} = ST_PREPROCESS;
  1636. } elsif($singletest_state{$runnerid} == ST_PREPROCESS) {
  1637. my ($rid, $why, $error, $logs, $testtimings) = runnerar($runnerid);
  1638. if(!$rid) {
  1639. logmsg "ERROR: runner $runnerid seems to have died\n";
  1640. $singletest_state{$runnerid} = ST_INIT;
  1641. return (-1, 0);
  1642. }
  1643. logmsg $logs;
  1644. updatetesttimings($testnum, %$testtimings);
  1645. if($error == -2) {
  1646. if($postmortem) {
  1647. # Error indicates an actual problem starting the server, so
  1648. # display the server logs
  1649. displaylogs($rid, $testnum);
  1650. }
  1651. }
  1652. #######################################################################
  1653. # Load test file for this test number
  1654. my $logdir = getrunnerlogdir($runnerid);
  1655. loadtest("${logdir}/test${testnum}");
  1656. #######################################################################
  1657. # Print the test name and count tests
  1658. $error = singletest_count($testnum, $why);
  1659. if($error) {
  1660. # Submit the test case result with the CI environment
  1661. citest_finishtest($testnum, $error);
  1662. $singletest_state{$runnerid} = ST_INIT;
  1663. logmsg singletest_dumplogs();
  1664. return ($error, 0);
  1665. }
  1666. #######################################################################
  1667. # Execute this test number
  1668. my $cmdres;
  1669. my $CURLOUT;
  1670. my $tool;
  1671. my $usedvalgrind;
  1672. if(runnerac_test_run($runnerid, $testnum)) {
  1673. logmsg "ERROR: runner $runnerid seems to have died\n";
  1674. $singletest_state{$runnerid} = ST_INIT;
  1675. return (-1, 0);
  1676. }
  1677. $singletest_state{$runnerid} = ST_RUN;
  1678. } elsif($singletest_state{$runnerid} == ST_RUN) {
  1679. my ($rid, $error, $logs, $testtimings, $cmdres, $CURLOUT, $tool, $usedvalgrind) = runnerar($runnerid);
  1680. if(!$rid) {
  1681. logmsg "ERROR: runner $runnerid seems to have died\n";
  1682. $singletest_state{$runnerid} = ST_INIT;
  1683. return (-1, 0);
  1684. }
  1685. logmsg $logs;
  1686. updatetesttimings($testnum, %$testtimings);
  1687. if($error == -1) {
  1688. # no further verification will occur
  1689. $timevrfyend{$testnum} = Time::HiRes::time();
  1690. my $err = ignoreresultcode($testnum);
  1691. # Submit the test case result with the CI environment
  1692. citest_finishtest($testnum, $err);
  1693. $singletest_state{$runnerid} = ST_INIT;
  1694. logmsg singletest_dumplogs();
  1695. # return a test failure, either to be reported or to be ignored
  1696. return ($err, 0);
  1697. }
  1698. elsif($error == -2) {
  1699. # fill in the missing timings on error
  1700. timestampskippedevents($testnum);
  1701. # Submit the test case result with the CI environment
  1702. citest_finishtest($testnum, $error);
  1703. $singletest_state{$runnerid} = ST_INIT;
  1704. logmsg singletest_dumplogs();
  1705. return ($error, 0);
  1706. }
  1707. elsif($error > 0) {
  1708. # no further verification will occur
  1709. $timevrfyend{$testnum} = Time::HiRes::time();
  1710. # Submit the test case result with the CI environment
  1711. citest_finishtest($testnum, $error);
  1712. $singletest_state{$runnerid} = ST_INIT;
  1713. logmsg singletest_dumplogs();
  1714. return ($error, 0);
  1715. }
  1716. #######################################################################
  1717. # Verify that the test succeeded
  1718. #
  1719. # Load test file for this test number
  1720. my $logdir = getrunnerlogdir($runnerid);
  1721. loadtest("${logdir}/test${testnum}");
  1722. readtestkeywords();
  1723. $error = singletest_check($runnerid, $testnum, $cmdres, $CURLOUT, $tool, $usedvalgrind);
  1724. if($error == -1) {
  1725. my $err = ignoreresultcode($testnum);
  1726. # Submit the test case result with the CI environment
  1727. citest_finishtest($testnum, $err);
  1728. $singletest_state{$runnerid} = ST_INIT;
  1729. logmsg singletest_dumplogs();
  1730. # return a test failure, either to be reported or to be ignored
  1731. return ($err, 0);
  1732. }
  1733. elsif($error == -2) {
  1734. # torture test; there is no verification, so the run result holds the
  1735. # test success code
  1736. # Submit the test case result with the CI environment
  1737. citest_finishtest($testnum, $cmdres);
  1738. $singletest_state{$runnerid} = ST_INIT;
  1739. logmsg singletest_dumplogs();
  1740. return ($cmdres, 0);
  1741. }
  1742. #######################################################################
  1743. # Report a successful test
  1744. singletest_success($testnum, $count, $total, ignoreresultcode($testnum));
  1745. # Submit the test case result with the CI environment
  1746. citest_finishtest($testnum, 0);
  1747. $singletest_state{$runnerid} = ST_INIT;
  1748. logmsg singletest_dumplogs();
  1749. return (0, 0); # state machine is finished
  1750. }
  1751. singletest_unbufferlogs();
  1752. return (0, 1); # state machine must be called again on event
  1753. }
  1754. #######################################################################
  1755. # runtimestats displays test-suite run time statistics
  1756. #
  1757. sub runtimestats {
  1758. my $lasttest = $_[0];
  1759. return if(not $timestats);
  1760. logmsg "::group::Run Time Stats\n";
  1761. logmsg "\nTest suite total running time breakdown per task...\n\n";
  1762. my @timesrvr;
  1763. my @timeprep;
  1764. my @timetool;
  1765. my @timelock;
  1766. my @timevrfy;
  1767. my @timetest;
  1768. my $timesrvrtot = 0.0;
  1769. my $timepreptot = 0.0;
  1770. my $timetooltot = 0.0;
  1771. my $timelocktot = 0.0;
  1772. my $timevrfytot = 0.0;
  1773. my $timetesttot = 0.0;
  1774. my $counter;
  1775. for my $testnum (1 .. $lasttest) {
  1776. if($timesrvrini{$testnum}) {
  1777. $timesrvrtot += $timesrvrend{$testnum} - $timesrvrini{$testnum};
  1778. $timepreptot +=
  1779. (($timetoolini{$testnum} - $timeprepini{$testnum}) -
  1780. ($timesrvrend{$testnum} - $timesrvrini{$testnum}));
  1781. $timetooltot += $timetoolend{$testnum} - $timetoolini{$testnum};
  1782. $timelocktot += $timesrvrlog{$testnum} - $timetoolend{$testnum};
  1783. $timevrfytot += $timevrfyend{$testnum} - $timesrvrlog{$testnum};
  1784. $timetesttot += $timevrfyend{$testnum} - $timeprepini{$testnum};
  1785. push @timesrvr, sprintf("%06.3f %04d",
  1786. $timesrvrend{$testnum} - $timesrvrini{$testnum}, $testnum);
  1787. push @timeprep, sprintf("%06.3f %04d",
  1788. ($timetoolini{$testnum} - $timeprepini{$testnum}) -
  1789. ($timesrvrend{$testnum} - $timesrvrini{$testnum}), $testnum);
  1790. push @timetool, sprintf("%06.3f %04d",
  1791. $timetoolend{$testnum} - $timetoolini{$testnum}, $testnum);
  1792. push @timelock, sprintf("%06.3f %04d",
  1793. $timesrvrlog{$testnum} - $timetoolend{$testnum}, $testnum);
  1794. push @timevrfy, sprintf("%06.3f %04d",
  1795. $timevrfyend{$testnum} - $timesrvrlog{$testnum}, $testnum);
  1796. push @timetest, sprintf("%06.3f %04d",
  1797. $timevrfyend{$testnum} - $timeprepini{$testnum}, $testnum);
  1798. }
  1799. }
  1800. {
  1801. no warnings 'numeric';
  1802. @timesrvr = sort { $b <=> $a } @timesrvr;
  1803. @timeprep = sort { $b <=> $a } @timeprep;
  1804. @timetool = sort { $b <=> $a } @timetool;
  1805. @timelock = sort { $b <=> $a } @timelock;
  1806. @timevrfy = sort { $b <=> $a } @timevrfy;
  1807. @timetest = sort { $b <=> $a } @timetest;
  1808. }
  1809. logmsg "Spent ". sprintf("%08.3f ", $timesrvrtot) .
  1810. "seconds starting and verifying test harness servers.\n";
  1811. logmsg "Spent ". sprintf("%08.3f ", $timepreptot) .
  1812. "seconds reading definitions and doing test preparations.\n";
  1813. logmsg "Spent ". sprintf("%08.3f ", $timetooltot) .
  1814. "seconds actually running test tools.\n";
  1815. logmsg "Spent ". sprintf("%08.3f ", $timelocktot) .
  1816. "seconds awaiting server logs lock removal.\n";
  1817. logmsg "Spent ". sprintf("%08.3f ", $timevrfytot) .
  1818. "seconds verifying test results.\n";
  1819. logmsg "Spent ". sprintf("%08.3f ", $timetesttot) .
  1820. "seconds doing all of the above.\n";
  1821. $counter = 25;
  1822. logmsg "\nTest server starting and verification time per test ".
  1823. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  1824. logmsg "-time- test\n";
  1825. logmsg "------ ----\n";
  1826. foreach my $txt (@timesrvr) {
  1827. last if((not $fullstats) && (not $counter--));
  1828. logmsg "$txt\n";
  1829. }
  1830. $counter = 10;
  1831. logmsg "\nTest definition reading and preparation time per test ".
  1832. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  1833. logmsg "-time- test\n";
  1834. logmsg "------ ----\n";
  1835. foreach my $txt (@timeprep) {
  1836. last if((not $fullstats) && (not $counter--));
  1837. logmsg "$txt\n";
  1838. }
  1839. $counter = 25;
  1840. logmsg "\nTest tool execution time per test ".
  1841. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  1842. logmsg "-time- test\n";
  1843. logmsg "------ ----\n";
  1844. foreach my $txt (@timetool) {
  1845. last if((not $fullstats) && (not $counter--));
  1846. logmsg "$txt\n";
  1847. }
  1848. $counter = 15;
  1849. logmsg "\nTest server logs lock removal time per test ".
  1850. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  1851. logmsg "-time- test\n";
  1852. logmsg "------ ----\n";
  1853. foreach my $txt (@timelock) {
  1854. last if((not $fullstats) && (not $counter--));
  1855. logmsg "$txt\n";
  1856. }
  1857. $counter = 10;
  1858. logmsg "\nTest results verification time per test ".
  1859. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  1860. logmsg "-time- test\n";
  1861. logmsg "------ ----\n";
  1862. foreach my $txt (@timevrfy) {
  1863. last if((not $fullstats) && (not $counter--));
  1864. logmsg "$txt\n";
  1865. }
  1866. $counter = 50;
  1867. logmsg "\nTotal time per test ".
  1868. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  1869. logmsg "-time- test\n";
  1870. logmsg "------ ----\n";
  1871. foreach my $txt (@timetest) {
  1872. last if((not $fullstats) && (not $counter--));
  1873. logmsg "$txt\n";
  1874. }
  1875. logmsg "\n";
  1876. logmsg "::endgroup::\n";
  1877. }
  1878. #######################################################################
  1879. # returns code indicating why a test was skipped
  1880. # 0=unknown test, 1=use test result, 2=ignore test result
  1881. #
  1882. sub ignoreresultcode {
  1883. my ($testnum)=@_;
  1884. if(defined $ignoretestcodes{$testnum}) {
  1885. return $ignoretestcodes{$testnum};
  1886. }
  1887. return 0;
  1888. }
  1889. #######################################################################
  1890. # Put the given runner ID onto the queue of runners ready for a new task
  1891. #
  1892. sub runnerready {
  1893. my ($runnerid)=@_;
  1894. push @runnersidle, $runnerid;
  1895. }
  1896. #######################################################################
  1897. # Create test runners
  1898. #
  1899. sub createrunners {
  1900. my ($numrunners)=@_;
  1901. if(! $numrunners) {
  1902. $numrunners++;
  1903. }
  1904. # create $numrunners runners with minimum 1
  1905. for my $runnernum (1..$numrunners) {
  1906. my $dir = getrunnernumlogdir($runnernum);
  1907. cleardir($dir);
  1908. mkdir($dir, 0777);
  1909. $runnerids{$runnernum} = runner_init($dir, $jobs);
  1910. runnerready($runnerids{$runnernum});
  1911. }
  1912. }
  1913. #######################################################################
  1914. # Pick a test runner for the given test
  1915. #
  1916. sub pickrunner {
  1917. my ($testnum)=@_;
  1918. scalar(@runnersidle) || die "No runners available";
  1919. return pop @runnersidle;
  1920. }
  1921. #######################################################################
  1922. # Check options to this test program
  1923. #
  1924. # Special case for CMake: replace '$TFLAGS' by the contents of the
  1925. # environment variable (if any).
  1926. if(@ARGV && $ARGV[-1] eq '$TFLAGS') {
  1927. pop @ARGV;
  1928. push(@ARGV, split(' ', $ENV{'TFLAGS'})) if defined($ENV{'TFLAGS'});
  1929. }
  1930. $valgrind = checktestcmd("valgrind");
  1931. my $number=0;
  1932. my $fromnum=-1;
  1933. my @testthis;
  1934. while(@ARGV) {
  1935. if ($ARGV[0] eq "-v") {
  1936. # verbose output
  1937. $verbose=1;
  1938. }
  1939. elsif ($ARGV[0] eq "-c") {
  1940. # use this path to curl instead of default
  1941. $DBGCURL=$CURL=$ARGV[1];
  1942. shift @ARGV;
  1943. }
  1944. elsif ($ARGV[0] eq "-vc") {
  1945. # use this path to a curl used to verify servers
  1946. # Particularly useful when you introduce a crashing bug somewhere in
  1947. # the development version as then it won't be able to run any tests
  1948. # since it can't verify the servers!
  1949. $VCURL=shell_quote($ARGV[1]);
  1950. shift @ARGV;
  1951. }
  1952. elsif ($ARGV[0] eq "-ac") {
  1953. # use this curl only to talk to APIs (currently only CI test APIs)
  1954. $ACURL=shell_quote($ARGV[1]);
  1955. shift @ARGV;
  1956. }
  1957. elsif ($ARGV[0] eq "-d") {
  1958. # have the servers display protocol output
  1959. $debugprotocol=1;
  1960. }
  1961. elsif($ARGV[0] eq "-e") {
  1962. # run the tests cases event based if possible
  1963. $run_event_based=1;
  1964. }
  1965. elsif($ARGV[0] eq "-f") {
  1966. # force - run the test case even if listed in DISABLED
  1967. $run_disabled=1;
  1968. }
  1969. elsif($ARGV[0] eq "-E") {
  1970. # load additional reasons to skip tests
  1971. shift @ARGV;
  1972. my $exclude_file = $ARGV[0];
  1973. open(my $fd, "<", $exclude_file) or die "Couldn't open '$exclude_file': $!";
  1974. while(my $line = <$fd>) {
  1975. next if ($line =~ /^#/);
  1976. chomp $line;
  1977. my ($type, $patterns, $skip_reason) = split(/\s*:\s*/, $line, 3);
  1978. die "Unsupported type: $type\n" if($type !~ /^keyword|test|tool$/);
  1979. foreach my $pattern (split(/,/, $patterns)) {
  1980. if($type eq "test") {
  1981. # Strip leading zeros in the test number
  1982. $pattern = int($pattern);
  1983. }
  1984. $custom_skip_reasons{$type}{$pattern} = $skip_reason;
  1985. }
  1986. }
  1987. close($fd);
  1988. }
  1989. elsif ($ARGV[0] eq "-g") {
  1990. # run this test with gdb
  1991. $gdbthis=1;
  1992. }
  1993. elsif ($ARGV[0] eq "-gl") {
  1994. # run this test with lldb
  1995. $gdbthis=2;
  1996. }
  1997. elsif ($ARGV[0] eq "-gw") {
  1998. # run this test with windowed gdb
  1999. $gdbthis=1;
  2000. $gdbxwin=1;
  2001. }
  2002. elsif($ARGV[0] eq "-s") {
  2003. # short output
  2004. $short=1;
  2005. }
  2006. elsif($ARGV[0] eq "-am") {
  2007. # automake-style output
  2008. $short=1;
  2009. $automakestyle=1;
  2010. }
  2011. elsif($ARGV[0] eq "-n") {
  2012. # no valgrind
  2013. undef $valgrind;
  2014. }
  2015. elsif($ARGV[0] eq "--no-debuginfod") {
  2016. # disable the valgrind debuginfod functionality
  2017. $no_debuginfod = 1;
  2018. }
  2019. elsif ($ARGV[0] eq "-R") {
  2020. # execute in scrambled order
  2021. $scrambleorder=1;
  2022. }
  2023. elsif($ARGV[0] =~ /^-t(.*)/) {
  2024. # torture
  2025. $torture=1;
  2026. my $xtra = $1;
  2027. if($xtra =~ s/(\d+)$//) {
  2028. $tortalloc = $1;
  2029. }
  2030. }
  2031. elsif($ARGV[0] =~ /--shallow=(\d+)/) {
  2032. # Fail no more than this amount per tests when running
  2033. # torture.
  2034. my ($num)=($1);
  2035. $shallow=$num;
  2036. }
  2037. elsif($ARGV[0] =~ /--repeat=(\d+)/) {
  2038. # Repeat-run the given tests this many times
  2039. $repeat = $1;
  2040. }
  2041. elsif($ARGV[0] =~ /--seed=(\d+)/) {
  2042. # Set a fixed random seed (used for -R and --shallow)
  2043. $randseed = $1;
  2044. }
  2045. elsif($ARGV[0] eq "-a") {
  2046. # continue anyway, even if a test fail
  2047. $anyway=1;
  2048. }
  2049. elsif($ARGV[0] eq "-o") {
  2050. shift @ARGV;
  2051. if ($ARGV[0] =~ /^(\w+)=([\w.:\/\[\]-]+)$/) {
  2052. my ($variable, $value) = ($1, $2);
  2053. eval "\$$variable='$value'" or die "Failed to set \$$variable to $value: $@";
  2054. } else {
  2055. die "Failed to parse '-o $ARGV[0]'. May contain unexpected characters.\n";
  2056. }
  2057. }
  2058. elsif($ARGV[0] eq "-p") {
  2059. $postmortem=1;
  2060. }
  2061. elsif($ARGV[0] eq "-P") {
  2062. shift @ARGV;
  2063. $proxy_address=$ARGV[0];
  2064. }
  2065. elsif($ARGV[0] eq "-L") {
  2066. # require additional library file
  2067. shift @ARGV;
  2068. require $ARGV[0];
  2069. }
  2070. elsif($ARGV[0] eq "-l") {
  2071. # lists the test case names only
  2072. $listonly=1;
  2073. }
  2074. elsif($ARGV[0] =~ /^-j(.*)/) {
  2075. # parallel jobs
  2076. $jobs=1;
  2077. my $xtra = $1;
  2078. if($xtra =~ s/(\d+)$//) {
  2079. $jobs = $1;
  2080. }
  2081. }
  2082. elsif($ARGV[0] eq "-k") {
  2083. # keep stdout and stderr files after tests
  2084. $keepoutfiles=1;
  2085. }
  2086. elsif($ARGV[0] eq "-r") {
  2087. # run time statistics needs Time::HiRes
  2088. if($Time::HiRes::VERSION) {
  2089. # presize hashes appropriately to hold an entire test run
  2090. keys(%timeprepini) = 2000;
  2091. keys(%timesrvrini) = 2000;
  2092. keys(%timesrvrend) = 2000;
  2093. keys(%timetoolini) = 2000;
  2094. keys(%timetoolend) = 2000;
  2095. keys(%timesrvrlog) = 2000;
  2096. keys(%timevrfyend) = 2000;
  2097. $timestats=1;
  2098. $fullstats=0;
  2099. }
  2100. }
  2101. elsif($ARGV[0] eq "-rf") {
  2102. # run time statistics needs Time::HiRes
  2103. if($Time::HiRes::VERSION) {
  2104. # presize hashes appropriately to hold an entire test run
  2105. keys(%timeprepini) = 2000;
  2106. keys(%timesrvrini) = 2000;
  2107. keys(%timesrvrend) = 2000;
  2108. keys(%timetoolini) = 2000;
  2109. keys(%timetoolend) = 2000;
  2110. keys(%timesrvrlog) = 2000;
  2111. keys(%timevrfyend) = 2000;
  2112. $timestats=1;
  2113. $fullstats=1;
  2114. }
  2115. }
  2116. elsif($ARGV[0] eq "-rm") {
  2117. # force removal of files by killing locking processes
  2118. $clearlocks=1;
  2119. }
  2120. elsif($ARGV[0] eq "-u") {
  2121. # error instead of warning on server unexpectedly alive
  2122. $err_unexpected=1;
  2123. }
  2124. elsif(($ARGV[0] eq "-h") || ($ARGV[0] eq "--help")) {
  2125. # show help text
  2126. print <<"EOHELP"
  2127. Usage: runtests.pl [options] [test selection(s)]
  2128. -a continue even if a test fails
  2129. -ac path use this curl only to talk to APIs (currently only CI test APIs)
  2130. -am automake style output PASS/FAIL: [number] [name]
  2131. -c path use this curl executable
  2132. -d display server debug info
  2133. -e event-based execution
  2134. -E file load the specified file to exclude certain tests
  2135. -f forcibly run even if disabled
  2136. -g run the test case with gdb
  2137. -gw run the test case with gdb as a windowed application
  2138. -h this help text
  2139. -j[N] spawn this number of processes to run tests (default 0)
  2140. -k keep stdout and stderr files present after tests
  2141. -L path require an additional perl library file to replace certain functions
  2142. -l list all test case names/descriptions
  2143. -n no valgrind
  2144. --no-debuginfod disable the valgrind debuginfod functionality
  2145. -o variable=value set internal variable to the specified value
  2146. -P proxy use the specified proxy
  2147. -p print log file contents when a test fails
  2148. -R scrambled order (uses the random seed, see --seed)
  2149. -r run time statistics
  2150. -rf full run time statistics
  2151. -rm force removal of files by killing locking processes (Windows only)
  2152. --repeat=[num] run the given tests this many times
  2153. -s short output
  2154. --seed=[num] set the random seed to a fixed number
  2155. --shallow=[num] randomly makes the torture tests "thinner"
  2156. -t[N] torture (simulate function failures); N means fail Nth function
  2157. -u error instead of warning on server unexpectedly alive
  2158. -v verbose output
  2159. -vc path use this curl only to verify the existing servers
  2160. [num] like "5 6 9" or " 5 to 22 " to run those tests only
  2161. [!num] like "!5 !6 !9" to disable those tests
  2162. [~num] like "~5 ~6 ~9" to ignore the result of those tests
  2163. [keyword] like "IPv6" to select only tests containing the key word
  2164. [!keyword] like "!cookies" to disable any tests containing the key word
  2165. [~keyword] like "~cookies" to ignore results of tests containing key word
  2166. EOHELP
  2167. ;
  2168. exit;
  2169. }
  2170. elsif($ARGV[0] =~ /^(\d+)/) {
  2171. $number = $1;
  2172. if($fromnum >= 0) {
  2173. for my $n ($fromnum .. $number) {
  2174. push @testthis, $n;
  2175. }
  2176. $fromnum = -1;
  2177. }
  2178. else {
  2179. push @testthis, $1;
  2180. }
  2181. }
  2182. elsif($ARGV[0] =~ /^to$/i) {
  2183. $fromnum = $number+1;
  2184. }
  2185. elsif($ARGV[0] =~ /^!(\d+)/) {
  2186. $fromnum = -1;
  2187. $disabled{$1}=$1;
  2188. }
  2189. elsif($ARGV[0] =~ /^~(\d+)/) {
  2190. $fromnum = -1;
  2191. $ignored{$1}=$1;
  2192. }
  2193. elsif($ARGV[0] =~ /^!(.+)/) {
  2194. $disabled_keywords{lc($1)}=$1;
  2195. }
  2196. elsif($ARGV[0] =~ /^~(.+)/) {
  2197. $ignored_keywords{lc($1)}=$1;
  2198. }
  2199. elsif($ARGV[0] =~ /^([-[{a-zA-Z].*)/) {
  2200. $enabled_keywords{lc($1)}=$1;
  2201. }
  2202. else {
  2203. print "Unknown option: $ARGV[0]\n";
  2204. exit;
  2205. }
  2206. shift @ARGV;
  2207. }
  2208. delete $ENV{'DEBUGINFOD_URLS'} if($ENV{'DEBUGINFOD_URLS'} && $no_debuginfod);
  2209. if(!$randseed) {
  2210. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  2211. localtime(time);
  2212. # seed of the month. December 2019 becomes 201912
  2213. $randseed = ($year+1900)*100 + $mon+1;
  2214. print "Using curl: $CURL\n";
  2215. open(my $curlvh, "-|", shell_quote($CURL) . " --version 2>/dev/null") ||
  2216. die "could not get curl version!";
  2217. my @c = <$curlvh>;
  2218. close($curlvh) || die "could not get curl version!";
  2219. # use the first line of output and get the md5 out of it
  2220. my $str = md5($c[0]);
  2221. $randseed += unpack('S', $str); # unsigned 16 bit value
  2222. }
  2223. srand $randseed;
  2224. if(@testthis && ($testthis[0] ne "")) {
  2225. $TESTCASES=join(" ", @testthis);
  2226. }
  2227. if($valgrind) {
  2228. # we have found valgrind on the host, use it
  2229. # verify that we can invoke it fine
  2230. my $code = runclient("valgrind >/dev/null 2>&1");
  2231. if(($code>>8) != 1) {
  2232. #logmsg "Valgrind failure, disable it\n";
  2233. undef $valgrind;
  2234. } else {
  2235. # since valgrind 2.1.x, '--tool' option is mandatory
  2236. # use it, if it is supported by the version installed on the system
  2237. # (this happened in 2003, so we could probably don't need to care about
  2238. # that old version any longer and just delete this check)
  2239. runclient("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1");
  2240. if (($? >> 8)) {
  2241. $valgrind_tool="";
  2242. }
  2243. open(my $curlh, "<", "$CURL");
  2244. my $l = <$curlh>;
  2245. if($l =~ /^\#\!/) {
  2246. # A shell script. This is typically when built with libtool,
  2247. $valgrind="../libtool --mode=execute $valgrind";
  2248. }
  2249. close($curlh);
  2250. # valgrind 3 renamed the --logfile option to --log-file!!!
  2251. # (this happened in 2005, so we could probably don't need to care about
  2252. # that old version any longer and just delete this check)
  2253. my $ver=join(' ', runclientoutput("valgrind --version"));
  2254. # cut off all but digits and dots
  2255. $ver =~ s/[^0-9.]//g;
  2256. if($ver =~ /^(\d+)/) {
  2257. $ver = $1;
  2258. if($ver < 3) {
  2259. $valgrind_logfile="--logfile";
  2260. }
  2261. }
  2262. }
  2263. }
  2264. if ($gdbthis) {
  2265. # open the executable curl and read the first 4 bytes of it
  2266. open(my $check, "<", "$CURL");
  2267. my $c;
  2268. sysread $check, $c, 4;
  2269. close($check);
  2270. if($c eq "#! /") {
  2271. # A shell script. This is typically when built with libtool,
  2272. $libtool = 1;
  2273. $gdb = "../libtool --mode=execute gdb";
  2274. }
  2275. }
  2276. #######################################################################
  2277. # clear and create logging directory:
  2278. #
  2279. # TODO: figure how to get around this. This dir is needed for checksystemfeatures()
  2280. # Maybe create & use & delete a temporary directory in that function
  2281. cleardir($LOGDIR);
  2282. mkdir($LOGDIR, 0777);
  2283. mkdir("$LOGDIR/$LOCKDIR", 0777);
  2284. #######################################################################
  2285. # initialize some variables
  2286. #
  2287. get_disttests();
  2288. if(!$jobs) {
  2289. # Disable buffered logging with only one test job
  2290. setlogfunc(\&logmsg);
  2291. }
  2292. #######################################################################
  2293. # Output curl version and host info being tested
  2294. #
  2295. if(!$listonly) {
  2296. checksystemfeatures();
  2297. }
  2298. #######################################################################
  2299. # initialize configuration needed to set up servers
  2300. # TODO: rearrange things so this can be called only in runner_init()
  2301. #
  2302. initserverconfig();
  2303. if(!$listonly) {
  2304. # these can only be displayed after initserverconfig() has been called
  2305. displayserverfeatures();
  2306. # globally disabled tests
  2307. disabledtests("$TESTDIR/DISABLED");
  2308. }
  2309. #######################################################################
  2310. # Fetch all disabled tests, if there are any
  2311. #
  2312. sub disabledtests {
  2313. my ($file) = @_;
  2314. my @input;
  2315. if(open(my $disabledh, "<", "$file")) {
  2316. while(<$disabledh>) {
  2317. if(/^ *\#/) {
  2318. # allow comments
  2319. next;
  2320. }
  2321. push @input, $_;
  2322. }
  2323. close($disabledh);
  2324. # preprocess the input to make conditionally disabled tests depending
  2325. # on variables
  2326. my @pp = prepro(0, @input);
  2327. for my $t (@pp) {
  2328. if($t =~ /(\d+)/) {
  2329. my ($n) = $1;
  2330. $disabled{$n}=$n; # disable this test number
  2331. if(! -f "$srcdir/data/test$n") {
  2332. print STDERR "WARNING! Non-existing test $n in $file!\n";
  2333. # fail hard to make user notice
  2334. exit 1;
  2335. }
  2336. logmsg "DISABLED: test $n\n" if ($verbose);
  2337. }
  2338. else {
  2339. print STDERR "$file: rubbish content: $t\n";
  2340. exit 2;
  2341. }
  2342. }
  2343. }
  2344. }
  2345. #######################################################################
  2346. # If 'all' tests are requested, find out all test numbers
  2347. #
  2348. if ( $TESTCASES eq "all") {
  2349. # Get all commands and find out their test numbers
  2350. opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
  2351. my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
  2352. closedir(DIR);
  2353. $TESTCASES=""; # start with no test cases
  2354. # cut off everything but the digits
  2355. for(@cmds) {
  2356. $_ =~ s/[a-z\/\.]*//g;
  2357. }
  2358. # sort the numbers from low to high
  2359. foreach my $n (sort { $a <=> $b } @cmds) {
  2360. if($disabled{$n}) {
  2361. # skip disabled test cases
  2362. my $why = "configured as DISABLED";
  2363. $skipped{$why}++;
  2364. $teststat[$n]=$why; # store reason for this test case
  2365. next;
  2366. }
  2367. $TESTCASES .= " $n";
  2368. }
  2369. }
  2370. else {
  2371. my $verified="";
  2372. for(split(" ", $TESTCASES)) {
  2373. if (-e "$TESTDIR/test$_") {
  2374. $verified.="$_ ";
  2375. }
  2376. }
  2377. if($verified eq "") {
  2378. print "No existing test cases were specified\n";
  2379. exit;
  2380. }
  2381. $TESTCASES = $verified;
  2382. }
  2383. if($repeat) {
  2384. my $s;
  2385. for(1 .. $repeat) {
  2386. $s .= $TESTCASES;
  2387. }
  2388. $TESTCASES = $s;
  2389. }
  2390. if($scrambleorder) {
  2391. # scramble the order of the test cases
  2392. my @rand;
  2393. while($TESTCASES) {
  2394. my @all = split(/ +/, $TESTCASES);
  2395. if(!$all[0]) {
  2396. # if the first is blank, shift away it
  2397. shift @all;
  2398. }
  2399. my $r = rand @all;
  2400. push @rand, $all[$r];
  2401. $all[$r]="";
  2402. $TESTCASES = join(" ", @all);
  2403. }
  2404. $TESTCASES = join(" ", @rand);
  2405. }
  2406. # Display the contents of the given file. Line endings are canonicalized
  2407. # and excessively long files are elided
  2408. sub displaylogcontent {
  2409. my ($file)=@_;
  2410. if(open(my $single, "<", "$file")) {
  2411. my $linecount = 0;
  2412. my $truncate;
  2413. my @tail;
  2414. while(my $string = <$single>) {
  2415. $string =~ s/\r\n/\n/g;
  2416. $string =~ s/[\r\f\032]/\n/g;
  2417. $string .= "\n" unless ($string =~ /\n$/);
  2418. $string =~ tr/\n//;
  2419. for my $line (split(m/\n/, $string)) {
  2420. $line =~ s/\s*\!$//;
  2421. if ($truncate) {
  2422. push @tail, " $line\n";
  2423. } else {
  2424. logmsg " $line\n";
  2425. }
  2426. $linecount++;
  2427. $truncate = $linecount > 1200;
  2428. }
  2429. }
  2430. close($single);
  2431. if(@tail) {
  2432. my $tailshow = 200;
  2433. my $tailskip = 0;
  2434. my $tailtotal = scalar @tail;
  2435. if($tailtotal > $tailshow) {
  2436. $tailskip = $tailtotal - $tailshow;
  2437. logmsg "=== File too long: $tailskip lines omitted here\n";
  2438. }
  2439. for($tailskip .. $tailtotal-1) {
  2440. logmsg "$tail[$_]";
  2441. }
  2442. }
  2443. }
  2444. }
  2445. sub displaylogs {
  2446. my ($runnerid, $testnum)=@_;
  2447. my $logdir = getrunnerlogdir($runnerid);
  2448. opendir(DIR, "$logdir") ||
  2449. die "can't open dir: $!";
  2450. my @logs = readdir(DIR);
  2451. closedir(DIR);
  2452. logmsg "== Contents of files in the $logdir/ dir after test $testnum\n";
  2453. foreach my $log (sort @logs) {
  2454. if($log =~ /\.(\.|)$/) {
  2455. next; # skip "." and ".."
  2456. }
  2457. if($log =~ /^\.nfs/) {
  2458. next; # skip ".nfs"
  2459. }
  2460. if(($log eq "memdump") || ($log eq "core")) {
  2461. next; # skip "memdump" and "core"
  2462. }
  2463. if((-d "$logdir/$log") || (! -s "$logdir/$log")) {
  2464. next; # skip directory and empty files
  2465. }
  2466. if(($log =~ /^stdout\d+/) && ($log !~ /^stdout$testnum/)) {
  2467. next; # skip stdoutNnn of other tests
  2468. }
  2469. if(($log =~ /^stderr\d+/) && ($log !~ /^stderr$testnum/)) {
  2470. next; # skip stderrNnn of other tests
  2471. }
  2472. if(($log =~ /^upload\d+/) && ($log !~ /^upload$testnum/)) {
  2473. next; # skip uploadNnn of other tests
  2474. }
  2475. if(($log =~ /^curl\d+\.out/) && ($log !~ /^curl$testnum\.out/)) {
  2476. next; # skip curlNnn.out of other tests
  2477. }
  2478. if(($log =~ /^test\d+\.txt/) && ($log !~ /^test$testnum\.txt/)) {
  2479. next; # skip testNnn.txt of other tests
  2480. }
  2481. if(($log =~ /^file\d+\.txt/) && ($log !~ /^file$testnum\.txt/)) {
  2482. next; # skip fileNnn.txt of other tests
  2483. }
  2484. if(($log =~ /^netrc\d+/) && ($log !~ /^netrc$testnum/)) {
  2485. next; # skip netrcNnn of other tests
  2486. }
  2487. if(($log =~ /^trace\d+/) && ($log !~ /^trace$testnum/)) {
  2488. next; # skip traceNnn of other tests
  2489. }
  2490. if(($log =~ /^valgrind\d+/) && ($log !~ /^valgrind$testnum(?:\..*)?$/)) {
  2491. next; # skip valgrindNnn of other tests
  2492. }
  2493. if(($log =~ /^test$testnum$/)) {
  2494. next; # skip test$testnum since it can be very big
  2495. }
  2496. logmsg "=== Start of file $log\n";
  2497. displaylogcontent("$logdir/$log");
  2498. logmsg "=== End of file $log\n";
  2499. }
  2500. }
  2501. #######################################################################
  2502. # Scan tests to find suitable candidates
  2503. #
  2504. my $failed;
  2505. my $failedign;
  2506. my $ok=0;
  2507. my $ign=0;
  2508. my $total=0;
  2509. my $lasttest=0;
  2510. my @at = split(" ", $TESTCASES);
  2511. my $count=0;
  2512. my $endwaitcnt=0;
  2513. $start = time();
  2514. # scan all tests to find ones we should try to run
  2515. my @runtests;
  2516. foreach my $testnum (@at) {
  2517. $lasttest = $testnum if($testnum > $lasttest);
  2518. my ($why, $errorreturncode) = singletest_shouldrun($testnum);
  2519. if($why || $listonly) {
  2520. # Display test name now--test will be completely skipped later
  2521. my $error = singletest_count($testnum, $why);
  2522. next;
  2523. }
  2524. $ignoretestcodes{$testnum} = $errorreturncode;
  2525. push(@runtests, $testnum);
  2526. }
  2527. my $totaltests = scalar(@runtests);
  2528. if($listonly) {
  2529. exit(0);
  2530. }
  2531. #######################################################################
  2532. # Setup CI Test Run
  2533. citest_starttestrun();
  2534. #######################################################################
  2535. # Start test runners
  2536. #
  2537. my $numrunners = $jobs < scalar(@runtests) ? $jobs : scalar(@runtests);
  2538. createrunners($numrunners);
  2539. #######################################################################
  2540. # The main test-loop
  2541. #
  2542. # Every iteration through the loop consists of these steps:
  2543. # - if the global abort flag is set, exit the loop; we are done
  2544. # - if a runner is idle, start a new test on it
  2545. # - if all runners are idle, exit the loop; we are done
  2546. # - if a runner has a response for us, process the response
  2547. # run through each candidate test and execute it
  2548. while () {
  2549. # check the abort flag
  2550. if($globalabort) {
  2551. logmsg singletest_dumplogs();
  2552. logmsg "Aborting tests\n";
  2553. logmsg "Waiting for " . scalar((keys %runnersrunning)) . " outstanding test(s) to finish...\n";
  2554. # Wait for the last requests to complete and throw them away so
  2555. # that IPC calls & responses stay in sync
  2556. # TODO: send a signal to the runners to interrupt a long test
  2557. foreach my $rid (keys %runnersrunning) {
  2558. runnerar($rid);
  2559. delete $runnersrunning{$rid};
  2560. logmsg ".";
  2561. $| = 1;
  2562. }
  2563. logmsg "\n";
  2564. last;
  2565. }
  2566. # Start a new test if possible
  2567. if(scalar(@runnersidle) && scalar(@runtests)) {
  2568. # A runner is ready to run a test, and tests are still available to run
  2569. # so start a new test.
  2570. $count++;
  2571. my $testnum = shift(@runtests);
  2572. # pick a runner for this new test
  2573. my $runnerid = pickrunner($testnum);
  2574. $countforrunner{$runnerid} = $count;
  2575. # Start the test
  2576. my ($error, $again) = singletest($runnerid, $testnum, $countforrunner{$runnerid}, $totaltests);
  2577. if($again) {
  2578. # this runner is busy running a test
  2579. $runnersrunning{$runnerid} = $testnum;
  2580. } else {
  2581. runnerready($runnerid);
  2582. if($error >= 0) {
  2583. # We make this simplifying assumption to avoid having to handle
  2584. # $error properly here, but we must handle the case of runner
  2585. # death without abending here.
  2586. die "Internal error: test must not complete on first call";
  2587. }
  2588. }
  2589. }
  2590. # See if we've completed all the tests
  2591. if(!scalar(%runnersrunning)) {
  2592. # No runners are running; we must be done
  2593. scalar(@runtests) && die 'Internal error: still have tests to run';
  2594. last;
  2595. }
  2596. # See if a test runner needs attention
  2597. # If we could be running more tests, don't wait so we can schedule a new
  2598. # one immediately. If all runners are busy, wait a fraction of a second
  2599. # for one to finish so we can still loop around to check the abort flag.
  2600. my $runnerwait = scalar(@runnersidle) && scalar(@runtests) ? 0 : 0.5;
  2601. my ($ridready, $riderror) = runnerar_ready($runnerwait);
  2602. if($ridready && ! defined $runnersrunning{$ridready}) {
  2603. # On Linux, a closed pipe still shows up as ready instead of error.
  2604. # Detect this here by seeing if we are expecting it to be ready and
  2605. # treat it as an error if not.
  2606. logmsg "ERROR: Runner $ridready is unexpectedly ready; is probably actually dead\n";
  2607. $riderror = $ridready;
  2608. undef $ridready;
  2609. }
  2610. if($ridready) {
  2611. # This runner is ready to be serviced
  2612. my $testnum = $runnersrunning{$ridready};
  2613. defined $testnum || die "Internal error: test for runner $ridready unknown";
  2614. delete $runnersrunning{$ridready};
  2615. my ($error, $again) = singletest($ridready, $testnum, $countforrunner{$ridready}, $totaltests);
  2616. if($again) {
  2617. # this runner is busy running a test
  2618. $runnersrunning{$ridready} = $testnum;
  2619. } else {
  2620. # Test is complete
  2621. runnerready($ridready);
  2622. if($error < 0) {
  2623. # not a test we can run
  2624. next;
  2625. }
  2626. $total++; # number of tests we've run
  2627. if($error>0) {
  2628. if($error==2) {
  2629. # ignored test failures
  2630. $failedign .= "$testnum ";
  2631. }
  2632. else {
  2633. $failed.= "$testnum ";
  2634. }
  2635. if($postmortem) {
  2636. # display all files in $LOGDIR/ in a nice way
  2637. displaylogs($ridready, $testnum);
  2638. }
  2639. if($error==2) {
  2640. $ign++; # ignored test result counter
  2641. }
  2642. elsif(!$anyway) {
  2643. # a test failed, abort
  2644. logmsg "\n - abort tests\n";
  2645. undef @runtests; # empty out the remaining tests
  2646. }
  2647. }
  2648. elsif(!$error) {
  2649. $ok++; # successful test counter
  2650. }
  2651. }
  2652. }
  2653. if($riderror) {
  2654. logmsg "ERROR: runner $riderror is dead! aborting test run\n";
  2655. delete $runnersrunning{$riderror} if(defined $runnersrunning{$riderror});
  2656. $globalabort = 1;
  2657. }
  2658. if(!scalar(@runtests) && ++$endwaitcnt == (240 + $jobs)) {
  2659. # Once all tests have been scheduled on a runner at the end of a test
  2660. # run, we just wait for their results to come in. If we're still
  2661. # waiting after a couple of minutes ($endwaitcnt multiplied by
  2662. # $runnerwait, plus $jobs because that number won't time out), display
  2663. # the same test runner status as we give with a SIGUSR1. This will
  2664. # likely point to a single test that has hung.
  2665. logmsg "Hmmm, the tests are taking a while to finish. Here is the status:\n";
  2666. catch_usr1();
  2667. }
  2668. }
  2669. my $sofar = time() - $start;
  2670. #######################################################################
  2671. # Finish CI Test Run
  2672. citest_finishtestrun();
  2673. # Tests done, stop the servers
  2674. foreach my $runnerid (values %runnerids) {
  2675. runnerac_stopservers($runnerid);
  2676. }
  2677. # Wait for servers to stop
  2678. my $unexpected;
  2679. foreach my $runnerid (values %runnerids) {
  2680. my ($rid, $unexpect, $logs) = runnerar($runnerid);
  2681. $unexpected ||= $unexpect;
  2682. logmsg $logs;
  2683. }
  2684. # Kill the runners
  2685. # There is a race condition here since we don't know exactly when the runners
  2686. # have each finished shutting themselves down, but we're about to exit so it
  2687. # doesn't make much difference.
  2688. foreach my $runnerid (values %runnerids) {
  2689. runnerac_shutdown($runnerid);
  2690. sleep 0; # give runner a context switch so it can shut itself down
  2691. }
  2692. my $numskipped = %skipped ? sum values %skipped : 0;
  2693. my $all = $total + $numskipped;
  2694. runtimestats($lasttest);
  2695. if($all) {
  2696. logmsg "TESTDONE: $all tests were considered during ".
  2697. sprintf("%.0f", $sofar) ." seconds.\n";
  2698. }
  2699. if(%skipped && !$short) {
  2700. my $s=0;
  2701. # Temporary hash to print the restraints sorted by the number
  2702. # of their occurrences
  2703. my %restraints;
  2704. logmsg "TESTINFO: $numskipped tests were skipped due to these restraints:\n";
  2705. for(keys %skipped) {
  2706. my $r = $_;
  2707. my $skip_count = $skipped{$r};
  2708. my $log_line = sprintf("TESTINFO: \"%s\" %d time%s (", $r, $skip_count,
  2709. ($skip_count == 1) ? "" : "s");
  2710. # now gather all test case numbers that had this reason for being
  2711. # skipped
  2712. my $c=0;
  2713. my $max = 9;
  2714. for(0 .. scalar @teststat) {
  2715. my $t = $_;
  2716. if($teststat[$t] && ($teststat[$t] eq $r)) {
  2717. if($c < $max) {
  2718. $log_line .= ", " if($c);
  2719. $log_line .= $t;
  2720. }
  2721. $c++;
  2722. }
  2723. }
  2724. if($c > $max) {
  2725. $log_line .= " and ".($c-$max)." more";
  2726. }
  2727. $log_line .= ")\n";
  2728. $restraints{$log_line} = $skip_count;
  2729. }
  2730. foreach my $log_line (sort {$restraints{$b} <=> $restraints{$a}} keys %restraints) {
  2731. logmsg $log_line;
  2732. }
  2733. }
  2734. sub testnumdetails {
  2735. my ($desc, $numlist) = @_;
  2736. foreach my $testnum (split(' ', $numlist)) {
  2737. if(!loadtest("${TESTDIR}/test${testnum}")) {
  2738. my @info_keywords = getpart("info", "keywords");
  2739. my $testname = (getpart("client", "name"))[0];
  2740. chomp $testname;
  2741. logmsg "$desc $testnum: '$testname'";
  2742. my $first = 1;
  2743. for my $k (@info_keywords) {
  2744. chomp $k;
  2745. my $sep = ($first == 1) ? " " : ", ";
  2746. logmsg "$sep$k";
  2747. $first = 0;
  2748. }
  2749. logmsg "\n";
  2750. }
  2751. }
  2752. }
  2753. if($total) {
  2754. if($failedign) {
  2755. my $failedignsorted = numsortwords($failedign);
  2756. testnumdetails("FAIL-IGNORED", $failedignsorted);
  2757. logmsg "IGNORED: failed tests: $failedignsorted\n";
  2758. }
  2759. logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
  2760. $ok/$total*100);
  2761. if($failed && ($ok != $total)) {
  2762. my $failedsorted = numsortwords($failed);
  2763. logmsg "\n";
  2764. testnumdetails("FAIL", $failedsorted);
  2765. logmsg "\nTESTFAIL: These test cases failed: $failedsorted\n\n";
  2766. }
  2767. }
  2768. else {
  2769. logmsg "\nTESTFAIL: No tests were performed\n\n";
  2770. if(scalar(keys %enabled_keywords)) {
  2771. logmsg "TESTFAIL: Nothing matched these keywords: ";
  2772. for(keys %enabled_keywords) {
  2773. logmsg "$_ ";
  2774. }
  2775. logmsg "\n";
  2776. }
  2777. }
  2778. if(($total && (($ok+$ign) != $total)) || !$total || $unexpected) {
  2779. exit 1;
  2780. }