runtests.pl 103 KB

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