runtests.pl 104 KB

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