runtests.pl 98 KB

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