runtests.pl 95 KB

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