runtests.pl 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213
  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 $nghttpx_version=join(' ', `"$ENV{'NGHTTPX'}" -v 2>/dev/null`);
  285. $nghttpx_h3 = $nghttpx_version =~ /nghttp3\//;
  286. chomp $nghttpx_h3;
  287. }
  288. #######################################################################
  289. # Get the list of tests that the tests/data/Makefile.am knows about!
  290. #
  291. my $disttests = "";
  292. sub get_disttests {
  293. # If a non-default $TESTDIR is being used there may not be any
  294. # Makefile.am in which case there's nothing to do.
  295. open(my $dh, "<", "$TESTDIR/Makefile.am") or return;
  296. while(<$dh>) {
  297. chomp $_;
  298. if(($_ =~ /^#/) ||($_ !~ /test/)) {
  299. next;
  300. }
  301. $disttests .= $_;
  302. }
  303. close($dh);
  304. }
  305. #######################################################################
  306. # Remove all files in the specified directory
  307. #
  308. sub cleardir {
  309. my $dir = $_[0];
  310. my $done = 1; # success
  311. my $file;
  312. # Get all files
  313. opendir(my $dh, $dir) ||
  314. return 0; # can't open dir
  315. while($file = readdir($dh)) {
  316. # Don't clear the $PIDDIR or $LOCKDIR since those need to live beyond
  317. # one test
  318. if(($file !~ /^(\.|\.\.)\z/) &&
  319. "$file" ne $PIDDIR && "$file" ne $LOCKDIR) {
  320. if(-d "$dir/$file") {
  321. if(!cleardir("$dir/$file")) {
  322. $done = 0;
  323. }
  324. if(!rmdir("$dir/$file")) {
  325. $done = 0;
  326. }
  327. }
  328. else {
  329. # Ignore stunnel since we cannot do anything about its locks
  330. if(!unlink("$dir/$file") && "$file" !~ /_stunnel\.log$/) {
  331. $done = 0;
  332. }
  333. }
  334. }
  335. }
  336. closedir $dh;
  337. return $done;
  338. }
  339. #######################################################################
  340. # Given two array references, this function will store them in two temporary
  341. # files, run 'diff' on them, store the result and return the diff output!
  342. sub showdiff {
  343. my ($logdir, $firstref, $secondref)=@_;
  344. my $file1="$logdir/check-generated";
  345. my $file2="$logdir/check-expected";
  346. open(my $temp, ">", "$file1") || die "Failure writing diff file";
  347. for(@$firstref) {
  348. my $l = $_;
  349. $l =~ s/\r/[CR]/g;
  350. $l =~ s/\n/[LF]/g;
  351. $l =~ s/([^\x20-\x7f])/sprintf "%%%02x", ord $1/eg;
  352. print $temp $l;
  353. print $temp "\n";
  354. }
  355. close($temp) || die "Failure writing diff file";
  356. open($temp, ">", "$file2") || die "Failure writing diff file";
  357. for(@$secondref) {
  358. my $l = $_;
  359. $l =~ s/\r/[CR]/g;
  360. $l =~ s/\n/[LF]/g;
  361. $l =~ s/([^\x20-\x7f])/sprintf "%%%02x", ord $1/eg;
  362. print $temp $l;
  363. print $temp "\n";
  364. }
  365. close($temp) || die "Failure writing diff file";
  366. my @out = `diff -u $file2 $file1 2>/dev/null`;
  367. if(!$out[0]) {
  368. @out = `diff -c $file2 $file1 2>/dev/null`;
  369. }
  370. return @out;
  371. }
  372. #######################################################################
  373. # compare test results with the expected output, we might filter off
  374. # some pattern that is allowed to differ, output test results
  375. #
  376. sub compare {
  377. my ($runnerid, $testnum, $testname, $subject, $firstref, $secondref)=@_;
  378. my $result = compareparts($firstref, $secondref);
  379. if($result) {
  380. # timestamp test result verification end
  381. $timevrfyend{$testnum} = Time::HiRes::time();
  382. if(!$short) {
  383. logmsg "\n $testnum: $subject FAILED:\n";
  384. my $logdir = getrunnerlogdir($runnerid);
  385. logmsg showdiff($logdir, $firstref, $secondref);
  386. }
  387. elsif(!$automakestyle) {
  388. logmsg "FAILED\n";
  389. }
  390. else {
  391. # automakestyle
  392. logmsg "FAIL: $testnum - $testname - $subject\n";
  393. }
  394. }
  395. return $result;
  396. }
  397. #######################################################################
  398. # Numeric-sort words in a string
  399. sub numsortwords {
  400. my ($string)=@_;
  401. return join(' ', sort { $a <=> $b } split(' ', $string));
  402. }
  403. #######################################################################
  404. # Parse and store the protocols in curl's Protocols: line
  405. sub parseprotocols {
  406. my ($line)=@_;
  407. @protocols = split(' ', lc($line));
  408. # Generate a "proto-ipv6" version of each protocol to match the
  409. # IPv6 <server> name and a "proto-unix" to match the variant which
  410. # uses Unix domain sockets. This works even if support isn't
  411. # compiled in because the <features> test will fail.
  412. push @protocols, map(("$_-ipv6", "$_-unix"), @protocols);
  413. # 'http-proxy' is used in test cases to do CONNECT through
  414. push @protocols, 'http-proxy';
  415. # 'none' is used in test cases to mean no server
  416. push @protocols, 'none';
  417. }
  418. #######################################################################
  419. # Check & display information about curl and the host the test suite runs on.
  420. # Information to do with servers is displayed in displayserverfeatures, after
  421. # the server initialization is performed.
  422. sub checksystemfeatures {
  423. my $proto;
  424. my $feat;
  425. my $curl;
  426. my $libcurl;
  427. my $versretval;
  428. my $versnoexec;
  429. my @version=();
  430. my @disabled;
  431. my $dis = "";
  432. my $curlverout="$LOGDIR/curlverout.log";
  433. my $curlvererr="$LOGDIR/curlvererr.log";
  434. my $versioncmd=shell_quote($CURL) . " --version 1>$curlverout 2>$curlvererr";
  435. unlink($curlverout);
  436. unlink($curlvererr);
  437. $versretval = runclient($versioncmd);
  438. $versnoexec = $!;
  439. my $current_time = int(time());
  440. $ENV{'SOURCE_DATE_EPOCH'} = $current_time;
  441. $DATE = strftime "%Y-%m-%d", gmtime($current_time);
  442. open(my $versout, "<", "$curlverout");
  443. @version = <$versout>;
  444. close($versout);
  445. open(my $disabledh, "-|", "server/disabled".exe_ext('TOOL'));
  446. @disabled = <$disabledh>;
  447. close($disabledh);
  448. if($disabled[0]) {
  449. s/[\r\n]//g for @disabled;
  450. $dis = join(", ", @disabled);
  451. }
  452. $resolver="stock";
  453. for(@version) {
  454. chomp;
  455. if($_ =~ /^curl ([^ ]*)/) {
  456. $curl = $_;
  457. $CURLVERSION = $1;
  458. $CURLVERNUM = $CURLVERSION;
  459. $CURLVERNUM =~ s/^([0-9.]+)(.*)/$1/; # leading dots and numbers
  460. $curl =~ s/^(.*)(libcurl.*)/$1/g || die "Failure determining curl binary version";
  461. $libcurl = $2;
  462. if($curl =~ /linux|bsd|solaris/) {
  463. # system support LD_PRELOAD; may be disabled later
  464. $feature{"ld_preload"} = 1;
  465. }
  466. if($curl =~ /win32|Windows|mingw(32|64)/) {
  467. # This is a Windows MinGW build or native build, we need to use
  468. # Windows-style path.
  469. $pwd = sys_native_current_path();
  470. $feature{"win32"} = 1;
  471. # set if built with MinGW (as opposed to MinGW-w64)
  472. $feature{"MinGW"} = 1 if ($curl =~ /-pc-mingw32/);
  473. }
  474. if ($libcurl =~ /\s(winssl|schannel)\b/i) {
  475. $feature{"Schannel"} = 1;
  476. $feature{"SSLpinning"} = 1;
  477. }
  478. elsif ($libcurl =~ /\sopenssl\b/i) {
  479. $feature{"OpenSSL"} = 1;
  480. $feature{"SSLpinning"} = 1;
  481. }
  482. elsif ($libcurl =~ /\sgnutls\b/i) {
  483. $feature{"GnuTLS"} = 1;
  484. $feature{"SSLpinning"} = 1;
  485. }
  486. elsif ($libcurl =~ /\srustls-ffi\b/i) {
  487. $feature{"rustls"} = 1;
  488. }
  489. elsif ($libcurl =~ /\swolfssl\b/i) {
  490. $feature{"wolfssl"} = 1;
  491. $feature{"SSLpinning"} = 1;
  492. }
  493. elsif ($libcurl =~ /\sbearssl\b/i) {
  494. $feature{"bearssl"} = 1;
  495. }
  496. elsif ($libcurl =~ /\ssecuretransport\b/i) {
  497. $feature{"sectransp"} = 1;
  498. $feature{"SSLpinning"} = 1;
  499. }
  500. elsif ($libcurl =~ /\sBoringSSL\b/i) {
  501. # OpenSSL compatible API
  502. $feature{"OpenSSL"} = 1;
  503. $feature{"SSLpinning"} = 1;
  504. }
  505. elsif ($libcurl =~ /\slibressl\b/i) {
  506. # OpenSSL compatible API
  507. $feature{"OpenSSL"} = 1;
  508. $feature{"SSLpinning"} = 1;
  509. }
  510. elsif ($libcurl =~ /\squictls\b/i) {
  511. # OpenSSL compatible API
  512. $feature{"OpenSSL"} = 1;
  513. $feature{"SSLpinning"} = 1;
  514. }
  515. elsif ($libcurl =~ /\smbedTLS\b/i) {
  516. $feature{"mbedtls"} = 1;
  517. $feature{"SSLpinning"} = 1;
  518. }
  519. if ($libcurl =~ /ares/i) {
  520. $feature{"c-ares"} = 1;
  521. $resolver="c-ares";
  522. }
  523. if ($libcurl =~ /Hyper/i) {
  524. $feature{"hyper"} = 1;
  525. }
  526. if ($libcurl =~ /nghttp2/i) {
  527. # nghttp2 supports h2c, hyper does not
  528. $feature{"h2c"} = 1;
  529. }
  530. if ($libcurl =~ /AppleIDN/) {
  531. $feature{"AppleIDN"} = 1;
  532. }
  533. if ($libcurl =~ /WinIDN/) {
  534. $feature{"WinIDN"} = 1;
  535. }
  536. if ($libcurl =~ /libidn2/) {
  537. $feature{"libidn2"} = 1;
  538. }
  539. if ($libcurl =~ /libssh2/i) {
  540. $feature{"libssh2"} = 1;
  541. }
  542. if ($libcurl =~ /libssh\/([0-9.]*)\//i) {
  543. $feature{"libssh"} = 1;
  544. if($1 =~ /(\d+)\.(\d+).(\d+)/) {
  545. my $v = $1 * 100 + $2 * 10 + $3;
  546. if($v < 94) {
  547. # before 0.9.4
  548. $feature{"oldlibssh"} = 1;
  549. }
  550. }
  551. }
  552. if ($libcurl =~ /wolfssh/i) {
  553. $feature{"wolfssh"} = 1;
  554. }
  555. }
  556. elsif($_ =~ /^Protocols: (.*)/i) {
  557. $proto = $1;
  558. # these are the protocols compiled in to this libcurl
  559. parseprotocols($proto);
  560. }
  561. elsif($_ =~ /^Features: (.*)/i) {
  562. $feat = $1;
  563. # built with memory tracking support (--enable-curldebug); may be disabled later
  564. $feature{"TrackMemory"} = $feat =~ /TrackMemory/i;
  565. # curl was built with --enable-debug
  566. $feature{"Debug"} = $feat =~ /Debug/i;
  567. # ssl enabled
  568. $feature{"SSL"} = $feat =~ /SSL/i;
  569. # multiple ssl backends available.
  570. $feature{"MultiSSL"} = $feat =~ /MultiSSL/i;
  571. # large file support
  572. $feature{"Largefile"} = $feat =~ /Largefile/i;
  573. # IDN support
  574. $feature{"IDN"} = $feat =~ /IDN/i;
  575. # IPv6 support
  576. $feature{"IPv6"} = $feat =~ /IPv6/i;
  577. # Unix sockets support
  578. $feature{"UnixSockets"} = $feat =~ /UnixSockets/i;
  579. # libz compression
  580. $feature{"libz"} = $feat =~ /libz/i;
  581. # Brotli compression
  582. $feature{"brotli"} = $feat =~ /brotli/i;
  583. # Zstd compression
  584. $feature{"zstd"} = $feat =~ /zstd/i;
  585. # NTLM enabled
  586. $feature{"NTLM"} = $feat =~ /NTLM/i;
  587. # NTLM delegation to winbind daemon ntlm_auth helper enabled
  588. $feature{"NTLM_WB"} = $feat =~ /NTLM_WB/i;
  589. # SSPI enabled
  590. $feature{"SSPI"} = $feat =~ /SSPI/i;
  591. # GSS-API enabled
  592. $feature{"GSS-API"} = $feat =~ /GSS-API/i;
  593. # Kerberos enabled
  594. $feature{"Kerberos"} = $feat =~ /Kerberos/i;
  595. # SPNEGO enabled
  596. $feature{"SPNEGO"} = $feat =~ /SPNEGO/i;
  597. # TLS-SRP enabled
  598. $feature{"TLS-SRP"} = $feat =~ /TLS-SRP/i;
  599. # PSL enabled
  600. $feature{"PSL"} = $feat =~ /PSL/i;
  601. # alt-svc enabled
  602. $feature{"alt-svc"} = $feat =~ /alt-svc/i;
  603. # HSTS support
  604. $feature{"HSTS"} = $feat =~ /HSTS/i;
  605. if($feat =~ /AsynchDNS/i) {
  606. if(!$feature{"c-ares"}) {
  607. # this means threaded resolver
  608. $feature{"threaded-resolver"} = 1;
  609. $resolver="threaded";
  610. }
  611. }
  612. # http2 enabled
  613. $feature{"http/2"} = $feat =~ /HTTP2/;
  614. if($feature{"http/2"}) {
  615. push @protocols, 'http/2';
  616. }
  617. # http3 enabled
  618. $feature{"http/3"} = $feat =~ /HTTP3/;
  619. if($feature{"http/3"}) {
  620. push @protocols, 'http/3';
  621. }
  622. # https proxy support
  623. $feature{"HTTPS-proxy"} = $feat =~ /HTTPS-proxy/;
  624. if($feature{"HTTPS-proxy"}) {
  625. # 'https-proxy' is used as "server" so consider it a protocol
  626. push @protocols, 'https-proxy';
  627. }
  628. # Unicode support
  629. $feature{"Unicode"} = $feat =~ /Unicode/i;
  630. # Thread-safe init
  631. $feature{"threadsafe"} = $feat =~ /threadsafe/i;
  632. }
  633. #
  634. # Test harness currently uses a non-stunnel server in order to
  635. # run HTTP TLS-SRP tests required when curl is built with https
  636. # protocol support and TLS-SRP feature enabled. For convenience
  637. # 'httptls' may be included in the test harness protocols array
  638. # to differentiate this from classic stunnel based 'https' test
  639. # harness server.
  640. #
  641. if($feature{"TLS-SRP"}) {
  642. my $add_httptls;
  643. for(@protocols) {
  644. if($_ =~ /^https(-ipv6|)$/) {
  645. $add_httptls=1;
  646. last;
  647. }
  648. }
  649. if($add_httptls && (! grep /^httptls$/, @protocols)) {
  650. push @protocols, 'httptls';
  651. push @protocols, 'httptls-ipv6';
  652. }
  653. }
  654. }
  655. if(!$curl) {
  656. logmsg "unable to get curl's version, further details are:\n";
  657. logmsg "issued command: \n";
  658. logmsg "$versioncmd \n";
  659. if ($versretval == -1) {
  660. logmsg "command failed with: \n";
  661. logmsg "$versnoexec \n";
  662. }
  663. elsif ($versretval & 127) {
  664. logmsg sprintf("command died with signal %d, and %s coredump.\n",
  665. ($versretval & 127), ($versretval & 128)?"a":"no");
  666. }
  667. else {
  668. logmsg sprintf("command exited with value %d \n", $versretval >> 8);
  669. }
  670. logmsg "contents of $curlverout: \n";
  671. displaylogcontent("$curlverout");
  672. logmsg "contents of $curlvererr: \n";
  673. displaylogcontent("$curlvererr");
  674. die "couldn't get curl's version";
  675. }
  676. if(-r "../lib/curl_config.h") {
  677. open(my $conf, "<", "../lib/curl_config.h");
  678. while(<$conf>) {
  679. if($_ =~ /^\#define HAVE_GETRLIMIT/) {
  680. # set if system has getrlimit()
  681. $feature{"getrlimit"} = 1;
  682. }
  683. }
  684. close($conf);
  685. }
  686. # allow this feature only if debug mode is disabled
  687. $feature{"ld_preload"} = $feature{"ld_preload"} && !$feature{"Debug"};
  688. if($feature{"IPv6"}) {
  689. # client has IPv6 support
  690. # check if the HTTP server has it!
  691. my $cmd = "server/sws".exe_ext('SRV')." --version";
  692. my @sws = `$cmd`;
  693. if($sws[0] =~ /IPv6/) {
  694. # HTTP server has IPv6 support!
  695. $http_ipv6 = 1;
  696. }
  697. # check if the FTP server has it!
  698. $cmd = "server/sockfilt".exe_ext('SRV')." --version";
  699. @sws = `$cmd`;
  700. if($sws[0] =~ /IPv6/) {
  701. # FTP server has IPv6 support!
  702. $ftp_ipv6 = 1;
  703. }
  704. }
  705. if($feature{"UnixSockets"}) {
  706. # client has Unix sockets support, check whether the HTTP server has it
  707. my $cmd = "server/sws".exe_ext('SRV')." --version";
  708. my @sws = `$cmd`;
  709. $http_unix = 1 if($sws[0] =~ /unix/);
  710. }
  711. open(my $manh, "-|", shell_quote($CURL) . " -M 2>&1");
  712. while(my $s = <$manh>) {
  713. if($s =~ /built-in manual was disabled at build-time/) {
  714. $feature{"manual"} = 0;
  715. last;
  716. }
  717. $feature{"manual"} = 1;
  718. last;
  719. }
  720. close($manh);
  721. $feature{"unittest"} = $feature{"Debug"};
  722. $feature{"nghttpx"} = !!$ENV{'NGHTTPX'};
  723. $feature{"nghttpx-h3"} = !!$nghttpx_h3;
  724. #
  725. # strings that must exactly match the names used in server/disabled.c
  726. #
  727. $feature{"cookies"} = 1;
  728. # Use this as a proxy for any cryptographic authentication
  729. $feature{"crypto"} = $feature{"NTLM"} || $feature{"Kerberos"} || $feature{"SPNEGO"};
  730. $feature{"DoH"} = 1;
  731. $feature{"HTTP-auth"} = 1;
  732. $feature{"Mime"} = 1;
  733. $feature{"form-api"} = 1;
  734. $feature{"netrc"} = 1;
  735. $feature{"parsedate"} = 1;
  736. $feature{"proxy"} = 1;
  737. $feature{"shuffle-dns"} = 1;
  738. $feature{"typecheck"} = 1;
  739. $feature{"verbose-strings"} = 1;
  740. $feature{"wakeup"} = 1;
  741. $feature{"headers-api"} = 1;
  742. $feature{"xattr"} = 1;
  743. $feature{"large-time"} = 1;
  744. $feature{"sha512-256"} = 1;
  745. $feature{"local-http"} = servers::localhttp();
  746. $feature{"codeset-utf8"} = lc(langinfo(CODESET())) eq "utf-8";
  747. # make each protocol an enabled "feature"
  748. for my $p (@protocols) {
  749. $feature{$p} = 1;
  750. }
  751. # 'socks' was once here but is now removed
  752. $has_shared = `sh $CURLCONFIG --built-shared`;
  753. chomp $has_shared;
  754. $has_shared = $has_shared eq "yes";
  755. if(!$feature{"TrackMemory"} && $torture) {
  756. die "can't run torture tests since curl was built without ".
  757. "TrackMemory feature (--enable-curldebug)";
  758. }
  759. my $hostname=join(' ', runclientoutput("hostname"));
  760. chomp $hostname;
  761. my $hosttype=join(' ', runclientoutput("uname -a"));
  762. chomp $hosttype;
  763. my $hostos=$^O;
  764. # display summary information about curl and the test host
  765. logmsg ("********* System characteristics ******** \n",
  766. "* $curl\n",
  767. "* $libcurl\n",
  768. "* Protocols: $proto\n",
  769. "* Features: $feat\n",
  770. "* Disabled: $dis\n",
  771. "* Host: $hostname\n",
  772. "* System: $hosttype\n",
  773. "* OS: $hostos\n",
  774. "* Perl: $^V ($^X)\n",
  775. "* Args: $args\n");
  776. if($jobs) {
  777. # Only show if not the default for now
  778. logmsg "* Jobs: $jobs\n";
  779. }
  780. if($feature{"TrackMemory"} && $feature{"threaded-resolver"}) {
  781. logmsg("*\n",
  782. "*** DISABLES memory tracking when using threaded resolver\n",
  783. "*\n");
  784. }
  785. logmsg sprintf("* Env: %s%s%s%s", $valgrind?"Valgrind ":"",
  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") {
  2024. # run the tests cases event based if possible
  2025. $run_event_based=1;
  2026. }
  2027. elsif($ARGV[0] eq "-f") {
  2028. # force - run the test case even if listed in DISABLED
  2029. $run_disabled=1;
  2030. }
  2031. elsif($ARGV[0] eq "-E") {
  2032. # load additional reasons to skip tests
  2033. shift @ARGV;
  2034. my $exclude_file = $ARGV[0];
  2035. open(my $fd, "<", $exclude_file) or die "Couldn't open '$exclude_file': $!";
  2036. while(my $line = <$fd>) {
  2037. next if ($line =~ /^#/);
  2038. chomp $line;
  2039. my ($type, $patterns, $skip_reason) = split(/\s*:\s*/, $line, 3);
  2040. die "Unsupported type: $type\n" if($type !~ /^keyword|test|tool$/);
  2041. foreach my $pattern (split(/,/, $patterns)) {
  2042. if($type eq "test") {
  2043. # Strip leading zeros in the test number
  2044. $pattern = int($pattern);
  2045. }
  2046. $custom_skip_reasons{$type}{$pattern} = $skip_reason;
  2047. }
  2048. }
  2049. close($fd);
  2050. }
  2051. elsif ($ARGV[0] eq "-g") {
  2052. # run this test with gdb
  2053. $gdbthis=1;
  2054. }
  2055. elsif ($ARGV[0] eq "-gl") {
  2056. # run this test with lldb
  2057. $gdbthis=2;
  2058. }
  2059. elsif ($ARGV[0] eq "-gw") {
  2060. # run this test with windowed gdb
  2061. $gdbthis=1;
  2062. $gdbxwin=1;
  2063. }
  2064. elsif($ARGV[0] eq "-s") {
  2065. # short output
  2066. $short=1;
  2067. }
  2068. elsif($ARGV[0] eq "-am") {
  2069. # automake-style output
  2070. $short=1;
  2071. $automakestyle=1;
  2072. }
  2073. elsif($ARGV[0] eq "-n") {
  2074. # no valgrind
  2075. undef $valgrind;
  2076. }
  2077. elsif($ARGV[0] eq "--no-debuginfod") {
  2078. # disable the valgrind debuginfod functionality
  2079. $no_debuginfod = 1;
  2080. }
  2081. elsif ($ARGV[0] eq "-R") {
  2082. # execute in scrambled order
  2083. $scrambleorder=1;
  2084. }
  2085. elsif($ARGV[0] =~ /^-t(.*)/) {
  2086. # torture
  2087. $torture=1;
  2088. my $xtra = $1;
  2089. if($xtra =~ s/(\d+)$//) {
  2090. $tortalloc = $1;
  2091. }
  2092. }
  2093. elsif($ARGV[0] =~ /--shallow=(\d+)/) {
  2094. # Fail no more than this amount per tests when running
  2095. # torture.
  2096. my ($num)=($1);
  2097. $shallow=$num;
  2098. }
  2099. elsif($ARGV[0] =~ /--repeat=(\d+)/) {
  2100. # Repeat-run the given tests this many times
  2101. $repeat = $1;
  2102. }
  2103. elsif($ARGV[0] =~ /--seed=(\d+)/) {
  2104. # Set a fixed random seed (used for -R and --shallow)
  2105. $randseed = $1;
  2106. }
  2107. elsif($ARGV[0] eq "-a") {
  2108. # continue anyway, even if a test fail
  2109. $anyway=1;
  2110. }
  2111. elsif($ARGV[0] eq "-o") {
  2112. shift @ARGV;
  2113. if ($ARGV[0] =~ /^(\w+)=([\w.:\/\[\]-]+)$/) {
  2114. my ($variable, $value) = ($1, $2);
  2115. eval "\$$variable='$value'" or die "Failed to set \$$variable to $value: $@";
  2116. } else {
  2117. die "Failed to parse '-o $ARGV[0]'. May contain unexpected characters.\n";
  2118. }
  2119. }
  2120. elsif($ARGV[0] eq "-p") {
  2121. $postmortem=1;
  2122. }
  2123. elsif($ARGV[0] eq "-P") {
  2124. shift @ARGV;
  2125. $proxy_address=$ARGV[0];
  2126. }
  2127. elsif($ARGV[0] eq "-L") {
  2128. # require additional library file
  2129. shift @ARGV;
  2130. require $ARGV[0];
  2131. }
  2132. elsif($ARGV[0] eq "-l") {
  2133. # lists the test case names only
  2134. $listonly=1;
  2135. }
  2136. elsif($ARGV[0] =~ /^-j(.*)/) {
  2137. # parallel jobs
  2138. $jobs=1;
  2139. my $xtra = $1;
  2140. if($xtra =~ s/(\d+)$//) {
  2141. $jobs = $1;
  2142. }
  2143. }
  2144. elsif($ARGV[0] eq "-k") {
  2145. # keep stdout and stderr files after tests
  2146. $keepoutfiles=1;
  2147. }
  2148. elsif($ARGV[0] eq "-r") {
  2149. # run time statistics needs Time::HiRes
  2150. if($Time::HiRes::VERSION) {
  2151. # presize hashes appropriately to hold an entire test run
  2152. keys(%timeprepini) = 2000;
  2153. keys(%timesrvrini) = 2000;
  2154. keys(%timesrvrend) = 2000;
  2155. keys(%timetoolini) = 2000;
  2156. keys(%timetoolend) = 2000;
  2157. keys(%timesrvrlog) = 2000;
  2158. keys(%timevrfyend) = 2000;
  2159. $timestats=1;
  2160. $fullstats=0;
  2161. }
  2162. }
  2163. elsif($ARGV[0] eq "-rf") {
  2164. # run time statistics needs Time::HiRes
  2165. if($Time::HiRes::VERSION) {
  2166. # presize hashes appropriately to hold an entire test run
  2167. keys(%timeprepini) = 2000;
  2168. keys(%timesrvrini) = 2000;
  2169. keys(%timesrvrend) = 2000;
  2170. keys(%timetoolini) = 2000;
  2171. keys(%timetoolend) = 2000;
  2172. keys(%timesrvrlog) = 2000;
  2173. keys(%timevrfyend) = 2000;
  2174. $timestats=1;
  2175. $fullstats=1;
  2176. }
  2177. }
  2178. elsif($ARGV[0] eq "-rm") {
  2179. # force removal of files by killing locking processes
  2180. $clearlocks=1;
  2181. }
  2182. elsif($ARGV[0] eq "-u") {
  2183. # error instead of warning on server unexpectedly alive
  2184. $err_unexpected=1;
  2185. }
  2186. elsif(($ARGV[0] eq "-h") || ($ARGV[0] eq "--help")) {
  2187. # show help text
  2188. print <<"EOHELP"
  2189. Usage: runtests.pl [options] [test selection(s)]
  2190. -a continue even if a test fails
  2191. -ac path use this curl only to talk to APIs (currently only CI test APIs)
  2192. -am automake style output PASS/FAIL: [number] [name]
  2193. -bundle use test bundles
  2194. -c path use this curl executable
  2195. -d display server debug info
  2196. -e event-based execution
  2197. -E file load the specified file to exclude certain tests
  2198. -f forcibly run even if disabled
  2199. -g run the test case with gdb
  2200. -gw run the test case with gdb as a windowed application
  2201. -h this help text
  2202. -j[N] spawn this number of processes to run tests (default 0)
  2203. -k keep stdout and stderr files present after tests
  2204. -L path require an additional perl library file to replace certain functions
  2205. -l list all test case names/descriptions
  2206. -n no valgrind
  2207. --no-debuginfod disable the valgrind debuginfod functionality
  2208. -o variable=value set internal variable to the specified value
  2209. -P proxy use the specified proxy
  2210. -p print log file contents when a test fails
  2211. -R scrambled order (uses the random seed, see --seed)
  2212. -r run time statistics
  2213. -rf full run time statistics
  2214. -rm force removal of files by killing locking processes (Windows only)
  2215. --repeat=[num] run the given tests this many times
  2216. -s short output
  2217. --seed=[num] set the random seed to a fixed number
  2218. --shallow=[num] randomly makes the torture tests "thinner"
  2219. -t[N] torture (simulate function failures); N means fail Nth function
  2220. -u error instead of warning on server unexpectedly alive
  2221. -v verbose output
  2222. -vc path use this curl only to verify the existing servers
  2223. [num] like "5 6 9" or " 5 to 22 " to run those tests only
  2224. [!num] like "!5 !6 !9" to disable those tests
  2225. [~num] like "~5 ~6 ~9" to ignore the result of those tests
  2226. [keyword] like "IPv6" to select only tests containing the key word
  2227. [!keyword] like "!cookies" to disable any tests containing the key word
  2228. [~keyword] like "~cookies" to ignore results of tests containing key word
  2229. EOHELP
  2230. ;
  2231. exit;
  2232. }
  2233. elsif($ARGV[0] =~ /^(\d+)/) {
  2234. $number = $1;
  2235. if($fromnum >= 0) {
  2236. for my $n ($fromnum .. $number) {
  2237. push @testthis, $n;
  2238. }
  2239. $fromnum = -1;
  2240. }
  2241. else {
  2242. push @testthis, $1;
  2243. }
  2244. }
  2245. elsif($ARGV[0] =~ /^to$/i) {
  2246. $fromnum = $number+1;
  2247. }
  2248. elsif($ARGV[0] =~ /^!(\d+)/) {
  2249. $fromnum = -1;
  2250. $disabled{$1}=$1;
  2251. }
  2252. elsif($ARGV[0] =~ /^~(\d+)/) {
  2253. $fromnum = -1;
  2254. $ignored{$1}=$1;
  2255. }
  2256. elsif($ARGV[0] =~ /^!(.+)/) {
  2257. $disabled_keywords{lc($1)}=$1;
  2258. }
  2259. elsif($ARGV[0] =~ /^~(.+)/) {
  2260. $ignored_keywords{lc($1)}=$1;
  2261. }
  2262. elsif($ARGV[0] =~ /^([-[{a-zA-Z].*)/) {
  2263. $enabled_keywords{lc($1)}=$1;
  2264. }
  2265. else {
  2266. print "Unknown option: $ARGV[0]\n";
  2267. exit;
  2268. }
  2269. shift @ARGV;
  2270. }
  2271. delete $ENV{'DEBUGINFOD_URLS'} if($ENV{'DEBUGINFOD_URLS'} && $no_debuginfod);
  2272. if(!$randseed) {
  2273. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  2274. localtime(time);
  2275. # seed of the month. December 2019 becomes 201912
  2276. $randseed = ($year+1900)*100 + $mon+1;
  2277. print "Using curl: $CURL\n";
  2278. open(my $curlvh, "-|", shell_quote($CURL) . " --version 2>/dev/null") ||
  2279. die "could not get curl version!";
  2280. my @c = <$curlvh>;
  2281. close($curlvh) || die "could not get curl version!";
  2282. # use the first line of output and get the md5 out of it
  2283. my $str = md5($c[0]);
  2284. $randseed += unpack('S', $str); # unsigned 16 bit value
  2285. }
  2286. srand $randseed;
  2287. if(@testthis && ($testthis[0] ne "")) {
  2288. $TESTCASES=join(" ", @testthis);
  2289. }
  2290. if($valgrind) {
  2291. # we have found valgrind on the host, use it
  2292. # verify that we can invoke it fine
  2293. my $code = runclient("valgrind >/dev/null 2>&1");
  2294. if(($code>>8) != 1) {
  2295. #logmsg "Valgrind failure, disable it\n";
  2296. undef $valgrind;
  2297. } else {
  2298. # since valgrind 2.1.x, '--tool' option is mandatory
  2299. # use it, if it is supported by the version installed on the system
  2300. # (this happened in 2003, so we could probably don't need to care about
  2301. # that old version any longer and just delete this check)
  2302. runclient("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1");
  2303. if (($? >> 8)) {
  2304. $valgrind_tool="";
  2305. }
  2306. open(my $curlh, "<", "$CURL");
  2307. my $l = <$curlh>;
  2308. if($l =~ /^\#\!/) {
  2309. # A shell script. This is typically when built with libtool,
  2310. $valgrind="../libtool --mode=execute $valgrind";
  2311. }
  2312. close($curlh);
  2313. # valgrind 3 renamed the --logfile option to --log-file!!!
  2314. # (this happened in 2005, so we could probably don't need to care about
  2315. # that old version any longer and just delete this check)
  2316. my $ver=join(' ', runclientoutput("valgrind --version"));
  2317. # cut off all but digits and dots
  2318. $ver =~ s/[^0-9.]//g;
  2319. if($ver =~ /^(\d+)/) {
  2320. $ver = $1;
  2321. if($ver < 3) {
  2322. $valgrind_logfile="--logfile";
  2323. }
  2324. }
  2325. }
  2326. }
  2327. if ($gdbthis) {
  2328. # open the executable curl and read the first 4 bytes of it
  2329. open(my $check, "<", "$CURL");
  2330. my $c;
  2331. sysread $check, $c, 4;
  2332. close($check);
  2333. if($c eq "#! /") {
  2334. # A shell script. This is typically when built with libtool,
  2335. $libtool = 1;
  2336. $gdb = "../libtool --mode=execute gdb";
  2337. }
  2338. }
  2339. #######################################################################
  2340. # clear and create logging directory:
  2341. #
  2342. # TODO: figure how to get around this. This dir is needed for checksystemfeatures()
  2343. # Maybe create & use & delete a temporary directory in that function
  2344. cleardir($LOGDIR);
  2345. mkdir($LOGDIR, 0777);
  2346. mkdir("$LOGDIR/$LOCKDIR", 0777);
  2347. #######################################################################
  2348. # initialize some variables
  2349. #
  2350. get_disttests();
  2351. if(!$jobs) {
  2352. # Disable buffered logging with only one test job
  2353. setlogfunc(\&logmsg);
  2354. }
  2355. #######################################################################
  2356. # Output curl version and host info being tested
  2357. #
  2358. if(!$listonly) {
  2359. checksystemfeatures();
  2360. }
  2361. #######################################################################
  2362. # Output information about the curl build
  2363. #
  2364. if(!$listonly) {
  2365. if(open(my $fd, "<", "../buildinfo.txt")) {
  2366. while(my $line = <$fd>) {
  2367. chomp $line;
  2368. if($line && $line !~ /^#/) {
  2369. logmsg("* $line\n");
  2370. }
  2371. }
  2372. close($fd);
  2373. }
  2374. }
  2375. #######################################################################
  2376. # initialize configuration needed to set up servers
  2377. # TODO: rearrange things so this can be called only in runner_init()
  2378. #
  2379. initserverconfig();
  2380. if(!$listonly) {
  2381. # these can only be displayed after initserverconfig() has been called
  2382. displayserverfeatures();
  2383. # globally disabled tests
  2384. disabledtests("$TESTDIR/DISABLED");
  2385. }
  2386. #######################################################################
  2387. # Fetch all disabled tests, if there are any
  2388. #
  2389. sub disabledtests {
  2390. my ($file) = @_;
  2391. my @input;
  2392. if(open(my $disabledh, "<", "$file")) {
  2393. while(<$disabledh>) {
  2394. if(/^ *\#/) {
  2395. # allow comments
  2396. next;
  2397. }
  2398. push @input, $_;
  2399. }
  2400. close($disabledh);
  2401. # preprocess the input to make conditionally disabled tests depending
  2402. # on variables
  2403. my @pp = prepro(0, @input);
  2404. for my $t (@pp) {
  2405. if($t =~ /(\d+)/) {
  2406. my ($n) = $1;
  2407. $disabled{$n}=$n; # disable this test number
  2408. if(! -f "$srcdir/data/test$n") {
  2409. print STDERR "WARNING! Non-existing test $n in $file!\n";
  2410. # fail hard to make user notice
  2411. exit 1;
  2412. }
  2413. logmsg "DISABLED: test $n\n" if ($verbose);
  2414. }
  2415. else {
  2416. print STDERR "$file: rubbish content: $t\n";
  2417. exit 2;
  2418. }
  2419. }
  2420. }
  2421. else {
  2422. print STDERR "Cannot open $file, exiting\n";
  2423. exit 3;
  2424. }
  2425. }
  2426. #######################################################################
  2427. # If 'all' tests are requested, find out all test numbers
  2428. #
  2429. if ( $TESTCASES eq "all") {
  2430. # Get all commands and find out their test numbers
  2431. opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
  2432. my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
  2433. closedir(DIR);
  2434. $TESTCASES=""; # start with no test cases
  2435. # cut off everything but the digits
  2436. for(@cmds) {
  2437. $_ =~ s/[a-z\/\.]*//g;
  2438. }
  2439. # sort the numbers from low to high
  2440. foreach my $n (sort { $a <=> $b } @cmds) {
  2441. if($disabled{$n}) {
  2442. # skip disabled test cases
  2443. my $why = "configured as DISABLED";
  2444. $skipped{$why}++;
  2445. $teststat[$n]=$why; # store reason for this test case
  2446. next;
  2447. }
  2448. $TESTCASES .= " $n";
  2449. }
  2450. }
  2451. else {
  2452. my $verified="";
  2453. for(split(" ", $TESTCASES)) {
  2454. if (-e "$TESTDIR/test$_") {
  2455. $verified.="$_ ";
  2456. }
  2457. }
  2458. if($verified eq "") {
  2459. print "No existing test cases were specified\n";
  2460. exit;
  2461. }
  2462. $TESTCASES = $verified;
  2463. }
  2464. if($repeat) {
  2465. my $s;
  2466. for(1 .. $repeat) {
  2467. $s .= $TESTCASES;
  2468. }
  2469. $TESTCASES = $s;
  2470. }
  2471. if($scrambleorder) {
  2472. # scramble the order of the test cases
  2473. my @rand;
  2474. while($TESTCASES) {
  2475. my @all = split(/ +/, $TESTCASES);
  2476. if(!$all[0]) {
  2477. # if the first is blank, shift away it
  2478. shift @all;
  2479. }
  2480. my $r = rand @all;
  2481. push @rand, $all[$r];
  2482. $all[$r]="";
  2483. $TESTCASES = join(" ", @all);
  2484. }
  2485. $TESTCASES = join(" ", @rand);
  2486. }
  2487. # Display the contents of the given file. Line endings are canonicalized
  2488. # and excessively long files are elided
  2489. sub displaylogcontent {
  2490. my ($file)=@_;
  2491. if(open(my $single, "<", "$file")) {
  2492. my $linecount = 0;
  2493. my $truncate;
  2494. my @tail;
  2495. while(my $string = <$single>) {
  2496. $string =~ s/\r\n/\n/g;
  2497. $string =~ s/[\r\f\032]/\n/g;
  2498. $string .= "\n" unless ($string =~ /\n$/);
  2499. $string =~ tr/\n//;
  2500. for my $line (split(m/\n/, $string)) {
  2501. $line =~ s/\s*\!$//;
  2502. if ($truncate) {
  2503. push @tail, " $line\n";
  2504. } else {
  2505. logmsg " $line\n";
  2506. }
  2507. $linecount++;
  2508. $truncate = $linecount > 1200;
  2509. }
  2510. }
  2511. close($single);
  2512. if(@tail) {
  2513. my $tailshow = 200;
  2514. my $tailskip = 0;
  2515. my $tailtotal = scalar @tail;
  2516. if($tailtotal > $tailshow) {
  2517. $tailskip = $tailtotal - $tailshow;
  2518. logmsg "=== File too long: $tailskip lines omitted here\n";
  2519. }
  2520. for($tailskip .. $tailtotal-1) {
  2521. logmsg "$tail[$_]";
  2522. }
  2523. }
  2524. }
  2525. }
  2526. sub displaylogs {
  2527. my ($runnerid, $testnum)=@_;
  2528. my $logdir = getrunnerlogdir($runnerid);
  2529. opendir(DIR, "$logdir") ||
  2530. die "can't open dir: $!";
  2531. my @logs = readdir(DIR);
  2532. closedir(DIR);
  2533. logmsg "== Contents of files in the $logdir/ dir after test $testnum\n";
  2534. foreach my $log (sort @logs) {
  2535. if($log =~ /\.(\.|)$/) {
  2536. next; # skip "." and ".."
  2537. }
  2538. if($log =~ /^\.nfs/) {
  2539. next; # skip ".nfs"
  2540. }
  2541. if(($log eq "memdump") || ($log eq "core")) {
  2542. next; # skip "memdump" and "core"
  2543. }
  2544. if((-d "$logdir/$log") || (! -s "$logdir/$log")) {
  2545. next; # skip directory and empty files
  2546. }
  2547. if(($log =~ /^stdout\d+/) && ($log !~ /^stdout$testnum/)) {
  2548. next; # skip stdoutNnn of other tests
  2549. }
  2550. if(($log =~ /^stderr\d+/) && ($log !~ /^stderr$testnum/)) {
  2551. next; # skip stderrNnn of other tests
  2552. }
  2553. if(($log =~ /^upload\d+/) && ($log !~ /^upload$testnum/)) {
  2554. next; # skip uploadNnn of other tests
  2555. }
  2556. if(($log =~ /^curl\d+\.out/) && ($log !~ /^curl$testnum\.out/)) {
  2557. next; # skip curlNnn.out of other tests
  2558. }
  2559. if(($log =~ /^test\d+\.txt/) && ($log !~ /^test$testnum\.txt/)) {
  2560. next; # skip testNnn.txt of other tests
  2561. }
  2562. if(($log =~ /^file\d+\.txt/) && ($log !~ /^file$testnum\.txt/)) {
  2563. next; # skip fileNnn.txt of other tests
  2564. }
  2565. if(($log =~ /^netrc\d+/) && ($log !~ /^netrc$testnum/)) {
  2566. next; # skip netrcNnn of other tests
  2567. }
  2568. if(($log =~ /^trace\d+/) && ($log !~ /^trace$testnum/)) {
  2569. next; # skip traceNnn of other tests
  2570. }
  2571. if(($log =~ /^valgrind\d+/) && ($log !~ /^valgrind$testnum(?:\..*)?$/)) {
  2572. next; # skip valgrindNnn of other tests
  2573. }
  2574. if(($log =~ /^test$testnum$/)) {
  2575. next; # skip test$testnum since it can be very big
  2576. }
  2577. logmsg "=== Start of file $log\n";
  2578. displaylogcontent("$logdir/$log");
  2579. logmsg "=== End of file $log\n";
  2580. }
  2581. }
  2582. #######################################################################
  2583. # Scan tests to find suitable candidates
  2584. #
  2585. my $failed;
  2586. my $failedign;
  2587. my $ok=0;
  2588. my $ign=0;
  2589. my $total=0;
  2590. my $lasttest=0;
  2591. my @at = split(" ", $TESTCASES);
  2592. my $count=0;
  2593. my $endwaitcnt=0;
  2594. $start = time();
  2595. # scan all tests to find ones we should try to run
  2596. my @runtests;
  2597. foreach my $testnum (@at) {
  2598. $lasttest = $testnum if($testnum > $lasttest);
  2599. my ($why, $errorreturncode) = singletest_shouldrun($testnum);
  2600. if($why || $listonly) {
  2601. # Display test name now--test will be completely skipped later
  2602. my $error = singletest_count($testnum, $why);
  2603. next;
  2604. }
  2605. $ignoretestcodes{$testnum} = $errorreturncode;
  2606. push(@runtests, $testnum);
  2607. }
  2608. my $totaltests = scalar(@runtests);
  2609. if($listonly) {
  2610. exit(0);
  2611. }
  2612. #######################################################################
  2613. # Setup CI Test Run
  2614. citest_starttestrun();
  2615. #######################################################################
  2616. # Start test runners
  2617. #
  2618. my $numrunners = $jobs < scalar(@runtests) ? $jobs : scalar(@runtests);
  2619. createrunners($numrunners);
  2620. #######################################################################
  2621. # The main test-loop
  2622. #
  2623. # Every iteration through the loop consists of these steps:
  2624. # - if the global abort flag is set, exit the loop; we are done
  2625. # - if a runner is idle, start a new test on it
  2626. # - if all runners are idle, exit the loop; we are done
  2627. # - if a runner has a response for us, process the response
  2628. # run through each candidate test and execute it
  2629. my $runner_wait_cnt = 0;
  2630. while () {
  2631. # check the abort flag
  2632. if($globalabort) {
  2633. logmsg singletest_dumplogs();
  2634. logmsg "Aborting tests\n";
  2635. logmsg "Waiting for " . scalar((keys %runnersrunning)) . " outstanding test(s) to finish...\n";
  2636. # Wait for the last requests to complete and throw them away so
  2637. # that IPC calls & responses stay in sync
  2638. # TODO: send a signal to the runners to interrupt a long test
  2639. foreach my $rid (keys %runnersrunning) {
  2640. runnerar($rid);
  2641. delete $runnersrunning{$rid};
  2642. logmsg ".";
  2643. $| = 1;
  2644. }
  2645. logmsg "\n";
  2646. last;
  2647. }
  2648. # Start a new test if possible
  2649. if(scalar(@runnersidle) && scalar(@runtests)) {
  2650. # A runner is ready to run a test, and tests are still available to run
  2651. # so start a new test.
  2652. $count++;
  2653. my $testnum = shift(@runtests);
  2654. # pick a runner for this new test
  2655. my $runnerid = pickrunner($testnum);
  2656. $countforrunner{$runnerid} = $count;
  2657. # Start the test
  2658. my ($error, $again) = singletest($runnerid, $testnum, $countforrunner{$runnerid}, $totaltests);
  2659. if($again) {
  2660. # this runner is busy running a test
  2661. $runnersrunning{$runnerid} = $testnum;
  2662. } else {
  2663. runnerready($runnerid);
  2664. if($error >= 0) {
  2665. # We make this simplifying assumption to avoid having to handle
  2666. # $error properly here, but we must handle the case of runner
  2667. # death without abending here.
  2668. die "Internal error: test must not complete on first call";
  2669. }
  2670. }
  2671. }
  2672. # See if we've completed all the tests
  2673. if(!scalar(%runnersrunning)) {
  2674. # No runners are running; we must be done
  2675. scalar(@runtests) && die 'Internal error: still have tests to run';
  2676. last;
  2677. }
  2678. # See if a test runner needs attention
  2679. # If we could be running more tests, don't wait so we can schedule a new
  2680. # one immediately. If all runners are busy, wait a fraction of a second
  2681. # for one to finish so we can still loop around to check the abort flag.
  2682. my $runnerwait = scalar(@runnersidle) && scalar(@runtests) ? 0 : 1.0;
  2683. my (@ridsready, $riderror) = runnerar_ready($runnerwait);
  2684. if(@ridsready) {
  2685. for my $ridready (@ridsready) {
  2686. if($ridready && ! defined $runnersrunning{$ridready}) {
  2687. # On Linux, a closed pipe still shows up as ready instead of error.
  2688. # Detect this here by seeing if we are expecting it to be ready and
  2689. # treat it as an error if not.
  2690. logmsg "ERROR: Runner $ridready is unexpectedly ready; is probably actually dead\n";
  2691. $riderror = $ridready;
  2692. undef $ridready;
  2693. }
  2694. if($ridready) {
  2695. # This runner is ready to be serviced
  2696. my $testnum = $runnersrunning{$ridready};
  2697. defined $testnum || die "Internal error: test for runner $ridready unknown";
  2698. delete $runnersrunning{$ridready};
  2699. my ($error, $again) = singletest($ridready, $testnum, $countforrunner{$ridready}, $totaltests);
  2700. if($again) {
  2701. # this runner is busy running a test
  2702. $runnersrunning{$ridready} = $testnum;
  2703. } else {
  2704. # Test is complete
  2705. $runner_wait_cnt = 0;
  2706. runnerready($ridready);
  2707. if($error < 0) {
  2708. # not a test we can run
  2709. next;
  2710. }
  2711. $total++; # number of tests we've run
  2712. if($error>0) {
  2713. if($error==2) {
  2714. # ignored test failures
  2715. $failedign .= "$testnum ";
  2716. }
  2717. else {
  2718. $failed.= "$testnum ";
  2719. }
  2720. if($postmortem) {
  2721. # display all files in $LOGDIR/ in a nice way
  2722. displaylogs($ridready, $testnum);
  2723. }
  2724. if($error==2) {
  2725. $ign++; # ignored test result counter
  2726. }
  2727. elsif(!$anyway) {
  2728. # a test failed, abort
  2729. logmsg "\n - abort tests\n";
  2730. undef @runtests; # empty out the remaining tests
  2731. }
  2732. }
  2733. elsif(!$error) {
  2734. $ok++; # successful test counter
  2735. }
  2736. }
  2737. }
  2738. }
  2739. }
  2740. if(!@ridsready && $runnerwait && !$torture && scalar(%runnersrunning)) {
  2741. $runner_wait_cnt++;
  2742. if($runner_wait_cnt >= 5) {
  2743. my $msg = "waiting for " . scalar(%runnersrunning) . " results:";
  2744. my $sep = " ";
  2745. foreach my $rid (keys %runnersrunning) {
  2746. $msg .= $sep . $runnersrunning{$rid} . "[$rid]";
  2747. $sep = ", "
  2748. }
  2749. logmsg "$msg\n";
  2750. }
  2751. if($runner_wait_cnt >= 10) {
  2752. $runner_wait_cnt = 0;
  2753. foreach my $rid (keys %runnersrunning) {
  2754. my $testnum = $runnersrunning{$rid};
  2755. logmsg "current state of test $testnum in [$rid]:\n";
  2756. displaylogs($rid, $testnum);
  2757. }
  2758. }
  2759. }
  2760. if($riderror) {
  2761. logmsg "ERROR: runner $riderror is dead! aborting test run\n";
  2762. delete $runnersrunning{$riderror} if(defined $runnersrunning{$riderror});
  2763. $globalabort = 1;
  2764. }
  2765. if(!scalar(@runtests) && ++$endwaitcnt == (240 + $jobs)) {
  2766. # Once all tests have been scheduled on a runner at the end of a test
  2767. # run, we just wait for their results to come in. If we're still
  2768. # waiting after a couple of minutes ($endwaitcnt multiplied by
  2769. # $runnerwait, plus $jobs because that number won't time out), display
  2770. # the same test runner status as we give with a SIGUSR1. This will
  2771. # likely point to a single test that has hung.
  2772. logmsg "Hmmm, the tests are taking a while to finish. Here is the status:\n";
  2773. catch_usr1();
  2774. }
  2775. }
  2776. my $sofar = time() - $start;
  2777. #######################################################################
  2778. # Finish CI Test Run
  2779. citest_finishtestrun();
  2780. # Tests done, stop the servers
  2781. foreach my $runnerid (values %runnerids) {
  2782. runnerac_stopservers($runnerid);
  2783. }
  2784. # Wait for servers to stop
  2785. my $unexpected;
  2786. foreach my $runnerid (values %runnerids) {
  2787. my ($rid, $unexpect, $logs) = runnerar($runnerid);
  2788. $unexpected ||= $unexpect;
  2789. logmsg $logs;
  2790. }
  2791. # Kill the runners
  2792. # There is a race condition here since we don't know exactly when the runners
  2793. # have each finished shutting themselves down, but we're about to exit so it
  2794. # doesn't make much difference.
  2795. foreach my $runnerid (values %runnerids) {
  2796. runnerac_shutdown($runnerid);
  2797. sleep 0; # give runner a context switch so it can shut itself down
  2798. }
  2799. my $numskipped = %skipped ? sum values %skipped : 0;
  2800. my $all = $total + $numskipped;
  2801. runtimestats($lasttest);
  2802. if($all) {
  2803. logmsg "TESTDONE: $all tests were considered during ".
  2804. sprintf("%.0f", $sofar) ." seconds.\n";
  2805. }
  2806. if(%skipped && !$short) {
  2807. my $s=0;
  2808. # Temporary hash to print the restraints sorted by the number
  2809. # of their occurrences
  2810. my %restraints;
  2811. logmsg "TESTINFO: $numskipped tests were skipped due to these restraints:\n";
  2812. for(keys %skipped) {
  2813. my $r = $_;
  2814. my $skip_count = $skipped{$r};
  2815. my $log_line = sprintf("TESTINFO: \"%s\" %d time%s (", $r, $skip_count,
  2816. ($skip_count == 1) ? "" : "s");
  2817. # now gather all test case numbers that had this reason for being
  2818. # skipped
  2819. my $c=0;
  2820. my $max = 9;
  2821. for(0 .. scalar @teststat) {
  2822. my $t = $_;
  2823. if($teststat[$t] && ($teststat[$t] eq $r)) {
  2824. if($c < $max) {
  2825. $log_line .= ", " if($c);
  2826. $log_line .= $t;
  2827. }
  2828. $c++;
  2829. }
  2830. }
  2831. if($c > $max) {
  2832. $log_line .= " and ".($c-$max)." more";
  2833. }
  2834. $log_line .= ")\n";
  2835. $restraints{$log_line} = $skip_count;
  2836. }
  2837. foreach my $log_line (sort {$restraints{$b} <=> $restraints{$a}} keys %restraints) {
  2838. logmsg $log_line;
  2839. }
  2840. }
  2841. sub testnumdetails {
  2842. my ($desc, $numlist) = @_;
  2843. foreach my $testnum (split(' ', $numlist)) {
  2844. if(!loadtest("${TESTDIR}/test${testnum}")) {
  2845. my @info_keywords = getpart("info", "keywords");
  2846. my $testname = (getpart("client", "name"))[0];
  2847. chomp $testname;
  2848. logmsg "$desc $testnum: '$testname'";
  2849. my $first = 1;
  2850. for my $k (@info_keywords) {
  2851. chomp $k;
  2852. my $sep = ($first == 1) ? " " : ", ";
  2853. logmsg "$sep$k";
  2854. $first = 0;
  2855. }
  2856. logmsg "\n";
  2857. }
  2858. }
  2859. }
  2860. if($total) {
  2861. if($passedign) {
  2862. my $sorted = numsortwords($passedign);
  2863. logmsg "::group::Passed Ignored Test details\n";
  2864. testnumdetails("PASSED-IGNORED", $sorted);
  2865. logmsg "IGNORED: passed tests: $sorted\n";
  2866. logmsg "::endgroup::\n";
  2867. }
  2868. if($failedign) {
  2869. my $sorted = numsortwords($failedign);
  2870. testnumdetails("FAIL-IGNORED", $sorted);
  2871. logmsg "IGNORED: failed tests: $sorted\n";
  2872. }
  2873. logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
  2874. $ok/$total*100);
  2875. if($failed && ($ok != $total)) {
  2876. my $failedsorted = numsortwords($failed);
  2877. logmsg "\n";
  2878. testnumdetails("FAIL", $failedsorted);
  2879. logmsg "\nTESTFAIL: These test cases failed: $failedsorted\n\n";
  2880. }
  2881. }
  2882. else {
  2883. logmsg "\nTESTFAIL: No tests were performed\n\n";
  2884. if(scalar(keys %enabled_keywords)) {
  2885. logmsg "TESTFAIL: Nothing matched these keywords: ";
  2886. for(keys %enabled_keywords) {
  2887. logmsg "$_ ";
  2888. }
  2889. logmsg "\n";
  2890. }
  2891. }
  2892. if(($total && (($ok+$ign) != $total)) || !$total || $unexpected) {
  2893. exit 1;
  2894. }