2
0

runtests.pl 104 KB

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