2
0

runtests.pl 104 KB

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