runtests.pl 101 KB

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