runtests.pl 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 1998 - 2010, 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 http://curl.haxx.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. ###########################################################################
  23. # Experimental hooks are available to run tests remotely on machines that
  24. # are able to run curl but are unable to run the test harness.
  25. # The following sections need to be modified:
  26. #
  27. # $HOSTIP, $HOST6IP - Set to the address of the host running the test suite
  28. # $CLIENTIP, $CLIENT6IP - Set to the address of the host running curl
  29. # runclient, runclientoutput - Modify to copy all the files in the log/
  30. # directory to the system running curl, run the given command remotely
  31. # and save the return code or returned stdout (respectively), then
  32. # copy all the files from the remote system's log/ directory back to
  33. # the host running the test suite. This can be done a few ways, such
  34. # as using scp & ssh, rsync & telnet, or using a NFS shared directory
  35. # and ssh.
  36. #
  37. # 'make && make test' needs to be done on both machines before making the
  38. # above changes and running runtests.pl manually. In the shared NFS case,
  39. # the contents of the tests/server/ directory must be from the host
  40. # running the test suite, while the rest must be from the host running curl.
  41. #
  42. # Note that even with these changes a number of tests will still fail (mainly
  43. # to do with cookies, those that set environment variables, or those that
  44. # do more than touch the file system in a <precheck> or <postcheck>
  45. # section). These can be added to the $TESTCASES line below,
  46. # e.g. $TESTCASES="!8 !31 !63 !cookies..."
  47. #
  48. # Finally, to properly support -g and -n, checktestcmd needs to change
  49. # to check the remote system's PATH, and the places in the code where
  50. # the curl binary is read directly to determine its type also need to be
  51. # fixed. As long as the -g option is never given, and the -n is always
  52. # given, this won't be a problem.
  53. # These should be the only variables that might be needed to get edited:
  54. BEGIN {
  55. @INC=(@INC, $ENV{'srcdir'}, ".");
  56. # run time statistics needs Time::HiRes
  57. eval {
  58. no warnings "all";
  59. require Time::HiRes;
  60. import Time::HiRes qw( time );
  61. }
  62. }
  63. use strict;
  64. use warnings;
  65. use Cwd;
  66. # Subs imported from serverhelp module
  67. use serverhelp qw(
  68. serverfactors
  69. servername_id
  70. servername_str
  71. servername_canon
  72. server_pidfilename
  73. server_logfilename
  74. );
  75. # Variables and subs imported from sshhelp module
  76. use sshhelp qw(
  77. $sshdexe
  78. $sshexe
  79. $sftpexe
  80. $sshconfig
  81. $sftpconfig
  82. $sshdlog
  83. $sshlog
  84. $sftplog
  85. $sftpcmds
  86. display_sshdconfig
  87. display_sshconfig
  88. display_sftpconfig
  89. display_sshdlog
  90. display_sshlog
  91. display_sftplog
  92. exe_ext
  93. find_sshd
  94. find_ssh
  95. find_sftp
  96. sshversioninfo
  97. );
  98. require "getpart.pm"; # array functions
  99. require "valgrind.pm"; # valgrind report parser
  100. require "ftp.pm";
  101. my $HOSTIP="127.0.0.1"; # address on which the test server listens
  102. my $HOST6IP="[::1]"; # address on which the test server listens
  103. my $CLIENTIP="127.0.0.1"; # address which curl uses for incoming connections
  104. my $CLIENT6IP="[::1]"; # address which curl uses for incoming connections
  105. my $base = 8990; # base port number
  106. my $HTTPPORT; # HTTP server port
  107. my $HTTP6PORT; # HTTP IPv6 server port
  108. my $HTTPSPORT; # HTTPS server port
  109. my $FTPPORT; # FTP server port
  110. my $FTP2PORT; # FTP server 2 port
  111. my $FTPSPORT; # FTPS server port
  112. my $FTP6PORT; # FTP IPv6 server port
  113. my $TFTPPORT; # TFTP
  114. my $TFTP6PORT; # TFTP
  115. my $SSHPORT; # SCP/SFTP
  116. my $SOCKSPORT; # SOCKS4/5 port
  117. my $POP3PORT; # POP3
  118. my $POP36PORT; # POP3 IPv6 server port
  119. my $IMAPPORT; # IMAP
  120. my $IMAP6PORT; # IMAP IPv6 server port
  121. my $SMTPPORT; # SMTP
  122. my $SMTP6PORT; # SMTP IPv6 server port
  123. my $RTSPPORT; # RTSP
  124. my $RTSP6PORT; # RTSP IPv6 server port
  125. my $GOPHERPORT; # Gopher
  126. my $GOPHER6PORT; # Gopher IPv6 server port
  127. my $srcdir = $ENV{'srcdir'} || '.';
  128. my $CURL="../src/curl".exe_ext(); # what curl executable to run on the tests
  129. my $VCURL=$CURL; # what curl binary to use to verify the servers with
  130. # VCURL is handy to set to the system one when the one you
  131. # just built hangs or crashes and thus prevent verification
  132. my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
  133. my $LOGDIR="log";
  134. my $TESTDIR="$srcdir/data";
  135. my $LIBDIR="./libtest";
  136. my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
  137. my $SERVER2IN="$LOGDIR/server2.input"; # what curl sent the second server
  138. my $CURLLOG="$LOGDIR/curl.log"; # all command lines run
  139. my $FTPDCMD="$LOGDIR/ftpserver.cmd"; # copy ftp server instructions here
  140. my $SERVERLOGS_LOCK="$LOGDIR/serverlogs.lock"; # server logs advisor read lock
  141. my $CURLCONFIG="../curl-config"; # curl-config from current build
  142. # Normally, all test cases should be run, but at times it is handy to
  143. # simply run a particular one:
  144. my $TESTCASES="all";
  145. # To run specific test cases, set them like:
  146. # $TESTCASES="1 2 3 7 8";
  147. #######################################################################
  148. # No variables below this point should need to be modified
  149. #
  150. # invoke perl like this:
  151. my $perl="perl -I$srcdir";
  152. my $server_response_maxtime=13;
  153. my $debug_build=0; # curl built with --enable-debug
  154. my $curl_debug=0; # curl built with --enable-curldebug (memory tracking)
  155. my $libtool;
  156. # name of the file that the memory debugging creates:
  157. my $memdump="$LOGDIR/memdump";
  158. # the path to the script that analyzes the memory debug output file:
  159. my $memanalyze="$perl $srcdir/memanalyze.pl";
  160. my $pwd = getcwd(); # current working directory
  161. my $start;
  162. my $forkserver=0;
  163. my $ftpchecktime=1; # time it took to verify our test FTP server
  164. my $stunnel = checkcmd("stunnel4") || checkcmd("stunnel");
  165. my $valgrind = checktestcmd("valgrind");
  166. my $valgrind_logfile="--logfile";
  167. my $valgrind_tool;
  168. my $gdb = checktestcmd("gdb");
  169. my $ssl_version; # set if libcurl is built with SSL support
  170. my $large_file; # set if libcurl is built with large file support
  171. my $has_idn; # set if libcurl is built with IDN support
  172. my $http_ipv6; # set if HTTP server has IPv6 support
  173. my $ftp_ipv6; # set if FTP server has IPv6 support
  174. my $tftp_ipv6; # set if TFTP server has IPv6 support
  175. my $gopher_ipv6; # set if Gopher server has IPv6 support
  176. my $has_ipv6; # set if libcurl is built with IPv6 support
  177. my $has_libz; # set if libcurl is built with libz support
  178. my $has_getrlimit; # set if system has getrlimit()
  179. my $has_ntlm; # set if libcurl is built with NTLM support
  180. my $has_charconv;# set if libcurl is built with CharConv support
  181. my $has_openssl; # built with a lib using an OpenSSL-like API
  182. my $has_gnutls; # built with GnuTLS
  183. my $has_nss; # built with NSS
  184. my $has_yassl; # built with yassl
  185. my $has_polarssl;# built with polarssl
  186. my $has_axtls; # built with axTLS
  187. my $has_shared; # built shared
  188. my $ssllib; # name of the lib we use (for human presentation)
  189. my $has_crypto; # set if libcurl is built with cryptographic support
  190. my $has_textaware; # set if running on a system that has a text mode concept
  191. # on files. Windows for example
  192. my @protocols; # array of supported protocols
  193. my $skipped=0; # number of tests skipped; reported in main loop
  194. my %skipped; # skipped{reason}=counter, reasons for skip
  195. my @teststat; # teststat[testnum]=reason, reasons for skip
  196. my %disabled_keywords; # key words of tests to skip
  197. my %enabled_keywords; # key words of tests to run
  198. my $sshdid; # for socks server, ssh daemon version id
  199. my $sshdvernum; # for socks server, ssh daemon version number
  200. my $sshdverstr; # for socks server, ssh daemon version string
  201. my $sshderror; # for socks server, ssh daemon version error
  202. my $defserverlogslocktimeout = 20; # timeout to await server logs lock removal
  203. my $defpostcommanddelay = 0; # delay between command and postcheck sections
  204. my $timestats; # time stamping and stats generation
  205. my $fullstats; # show time stats for every single test
  206. my %timeprepini; # timestamp for each test preparation start
  207. my %timesrvrini; # timestamp for each test required servers verification start
  208. my %timesrvrend; # timestamp for each test required servers verification end
  209. my %timetoolini; # timestamp for each test command run starting
  210. my %timetoolend; # timestamp for each test command run stopping
  211. my %timesrvrlog; # timestamp for each test server logs lock removal
  212. my %timevrfyend; # timestamp for each test result verification end
  213. my $testnumcheck; # test number, set in singletest sub.
  214. my %oldenv;
  215. #######################################################################
  216. # variables the command line options may set
  217. #
  218. my $short;
  219. my $verbose;
  220. my $debugprotocol;
  221. my $anyway;
  222. my $gdbthis; # run test case with gdb debugger
  223. my $keepoutfiles; # keep stdout and stderr files after tests
  224. my $listonly; # only list the tests
  225. my $postmortem; # display detailed info about failed tests
  226. my %run; # running server
  227. my %doesntrun; # servers that don't work, identified by pidfile
  228. my %serverpidfile;# all server pid file names, identified by server id
  229. my %runcert; # cert file currently in use by an ssl running server
  230. # torture test variables
  231. my $torture;
  232. my $tortnum;
  233. my $tortalloc;
  234. #######################################################################
  235. # logmsg is our general message logging subroutine.
  236. #
  237. sub logmsg {
  238. for(@_) {
  239. print "$_";
  240. }
  241. }
  242. # get the name of the current user
  243. my $USER = $ENV{USER}; # Linux
  244. if (!$USER) {
  245. $USER = $ENV{USERNAME}; # Windows
  246. if (!$USER) {
  247. $USER = $ENV{LOGNAME}; # Some UNIX (I think)
  248. }
  249. }
  250. # enable memory debugging if curl is compiled with it
  251. $ENV{'CURL_MEMDEBUG'} = $memdump;
  252. $ENV{'HOME'}=$pwd;
  253. sub catch_zap {
  254. my $signame = shift;
  255. logmsg "runtests.pl received SIG$signame, exiting\n";
  256. stopservers($verbose);
  257. die "Somebody sent me a SIG$signame";
  258. }
  259. $SIG{INT} = \&catch_zap;
  260. $SIG{TERM} = \&catch_zap;
  261. ##########################################################################
  262. # Clear all possible '*_proxy' environment variables for various protocols
  263. # to prevent them to interfere with our testing!
  264. my $protocol;
  265. foreach $protocol (('ftp', 'http', 'ftps', 'https', 'no')) {
  266. my $proxy = "${protocol}_proxy";
  267. # clear lowercase version
  268. delete $ENV{$proxy} if($ENV{$proxy});
  269. # clear uppercase version
  270. delete $ENV{uc($proxy)} if($ENV{uc($proxy)});
  271. }
  272. # make sure we don't get affected by other variables that control our
  273. # behaviour
  274. delete $ENV{'SSL_CERT_DIR'} if($ENV{'SSL_CERT_DIR'});
  275. delete $ENV{'SSL_CERT_PATH'} if($ENV{'SSL_CERT_PATH'});
  276. delete $ENV{'CURL_CA_BUNDLE'} if($ENV{'CURL_CA_BUNDLE'});
  277. #######################################################################
  278. # Load serverpidfile hash with pidfile names for all possible servers.
  279. #
  280. sub init_serverpidfile_hash {
  281. for my $proto (('ftp', 'http', 'imap', 'pop3', 'smtp')) {
  282. for my $ssl (('', 's')) {
  283. for my $ipvnum ((4, 6)) {
  284. for my $idnum ((1, 2)) {
  285. my $serv = servername_id("$proto$ssl", $ipvnum, $idnum);
  286. my $pidf = server_pidfilename("$proto$ssl", $ipvnum, $idnum);
  287. $serverpidfile{$serv} = $pidf;
  288. }
  289. }
  290. }
  291. }
  292. for my $proto (('tftp', 'sftp', 'socks', 'ssh', 'rtsp', 'gopher')) {
  293. for my $ipvnum ((4, 6)) {
  294. for my $idnum ((1, 2)) {
  295. my $serv = servername_id($proto, $ipvnum, $idnum);
  296. my $pidf = server_pidfilename($proto, $ipvnum, $idnum);
  297. $serverpidfile{$serv} = $pidf;
  298. }
  299. }
  300. }
  301. }
  302. #######################################################################
  303. # Check if a given child process has just died. Reaps it if so.
  304. #
  305. sub checkdied {
  306. use POSIX ":sys_wait_h";
  307. my $pid = $_[0];
  308. if(not defined $pid || $pid <= 0) {
  309. return 0;
  310. }
  311. my $rc = waitpid($pid, &WNOHANG);
  312. return ($rc == $pid)?1:0;
  313. }
  314. #######################################################################
  315. # Start a new thread/process and run the given command line in there.
  316. # Return the pids (yes plural) of the new child process to the parent.
  317. #
  318. sub startnew {
  319. my ($cmd, $pidfile, $timeout, $fake)=@_;
  320. logmsg "startnew: $cmd\n" if ($verbose);
  321. my $child = fork();
  322. my $pid2 = 0;
  323. if(not defined $child) {
  324. logmsg "startnew: fork() failure detected\n";
  325. return (-1,-1);
  326. }
  327. if(0 == $child) {
  328. # Here we are the child. Run the given command.
  329. # Put an "exec" in front of the command so that the child process
  330. # keeps this child's process ID.
  331. exec("exec $cmd") || die "Can't exec() $cmd: $!";
  332. # exec() should never return back here to this process. We protect
  333. # ourselves by calling die() just in case something goes really bad.
  334. die "error: exec() has returned";
  335. }
  336. # Ugly hack but ssh client doesn't support pid files
  337. if ($fake) {
  338. if(open(OUT, ">$pidfile")) {
  339. print OUT $child . "\n";
  340. close(OUT);
  341. logmsg "startnew: $pidfile faked with pid=$child\n" if($verbose);
  342. }
  343. else {
  344. logmsg "startnew: failed to write fake $pidfile with pid=$child\n";
  345. }
  346. # could/should do a while connect fails sleep a bit and loop
  347. sleep $timeout;
  348. if (checkdied($child)) {
  349. logmsg "startnew: child process has failed to start\n" if($verbose);
  350. return (-1,-1);
  351. }
  352. }
  353. my $count = $timeout;
  354. while($count--) {
  355. if(-f $pidfile && -s $pidfile && open(PID, "<$pidfile")) {
  356. $pid2 = 0 + <PID>;
  357. close(PID);
  358. if(($pid2 > 0) && kill(0, $pid2)) {
  359. # if $pid2 is valid, then make sure this pid is alive, as
  360. # otherwise it is just likely to be the _previous_ pidfile or
  361. # similar!
  362. last;
  363. }
  364. # invalidate $pid2 if not actually alive
  365. $pid2 = 0;
  366. }
  367. if (checkdied($child)) {
  368. logmsg "startnew: child process has died, server might start up\n"
  369. if($verbose);
  370. # We can't just abort waiting for the server with a
  371. # return (-1,-1);
  372. # because the server might have forked and could still start
  373. # up normally. Instead, just reduce the amount of time we remain
  374. # waiting.
  375. $count >>= 2;
  376. }
  377. sleep(1);
  378. }
  379. # Return two PIDs, the one for the child process we spawned and the one
  380. # reported by the server itself (in case it forked again on its own).
  381. # Both (potentially) need to be killed at the end of the test.
  382. return ($child, $pid2);
  383. }
  384. #######################################################################
  385. # Check for a command in the PATH of the test server.
  386. #
  387. sub checkcmd {
  388. my ($cmd)=@_;
  389. my @paths=(split(":", $ENV{'PATH'}), "/usr/sbin", "/usr/local/sbin",
  390. "/sbin", "/usr/bin", "/usr/local/bin",
  391. "./libtest/.libs", "./libtest");
  392. for(@paths) {
  393. if( -x "$_/$cmd" && ! -d "$_/$cmd") {
  394. # executable bit but not a directory!
  395. return "$_/$cmd";
  396. }
  397. }
  398. }
  399. #######################################################################
  400. # Get the list of tests that the tests/data/Makefile.am knows about!
  401. #
  402. my $disttests;
  403. sub get_disttests {
  404. my @dist = `cd data && make show`;
  405. $disttests = join("", @dist);
  406. }
  407. #######################################################################
  408. # Check for a command in the PATH of the machine running curl.
  409. #
  410. sub checktestcmd {
  411. my ($cmd)=@_;
  412. return checkcmd($cmd);
  413. }
  414. #######################################################################
  415. # Run the application under test and return its return code
  416. #
  417. sub runclient {
  418. my ($cmd)=@_;
  419. return system($cmd);
  420. # This is one way to test curl on a remote machine
  421. # my $out = system("ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'");
  422. # sleep 2; # time to allow the NFS server to be updated
  423. # return $out;
  424. }
  425. #######################################################################
  426. # Run the application under test and return its stdout
  427. #
  428. sub runclientoutput {
  429. my ($cmd)=@_;
  430. return `$cmd`;
  431. # This is one way to test curl on a remote machine
  432. # my @out = `ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'`;
  433. # sleep 2; # time to allow the NFS server to be updated
  434. # return @out;
  435. }
  436. #######################################################################
  437. # Memory allocation test and failure torture testing.
  438. #
  439. sub torture {
  440. my $testcmd = shift;
  441. my $gdbline = shift;
  442. # remove memdump first to be sure we get a new nice and clean one
  443. unlink($memdump);
  444. # First get URL from test server, ignore the output/result
  445. runclient($testcmd);
  446. logmsg " CMD: $testcmd\n" if($verbose);
  447. # memanalyze -v is our friend, get the number of allocations made
  448. my $count=0;
  449. my @out = `$memanalyze -v $memdump`;
  450. for(@out) {
  451. if(/^Allocations: (\d+)/) {
  452. $count = $1;
  453. last;
  454. }
  455. }
  456. if(!$count) {
  457. logmsg " found no allocs to make fail\n";
  458. return 0;
  459. }
  460. logmsg " $count allocations to make fail\n";
  461. for ( 1 .. $count ) {
  462. my $limit = $_;
  463. my $fail;
  464. my $dumped_core;
  465. if($tortalloc && ($tortalloc != $limit)) {
  466. next;
  467. }
  468. if($verbose) {
  469. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  470. localtime(time());
  471. my $now = sprintf("%02d:%02d:%02d ", $hour, $min, $sec);
  472. logmsg "Fail alloc no: $limit at $now\r";
  473. }
  474. # make the memory allocation function number $limit return failure
  475. $ENV{'CURL_MEMLIMIT'} = $limit;
  476. # remove memdump first to be sure we get a new nice and clean one
  477. unlink($memdump);
  478. logmsg "*** Alloc number $limit is now set to fail ***\n" if($gdbthis);
  479. my $ret = 0;
  480. if($gdbthis) {
  481. runclient($gdbline)
  482. }
  483. else {
  484. $ret = runclient($testcmd);
  485. }
  486. #logmsg "$_ Returned " . $ret >> 8 . "\n";
  487. # Now clear the variable again
  488. delete $ENV{'CURL_MEMLIMIT'} if($ENV{'CURL_MEMLIMIT'});
  489. if(-r "core") {
  490. # there's core file present now!
  491. logmsg " core dumped\n";
  492. $dumped_core = 1;
  493. $fail = 2;
  494. }
  495. # verify that it returns a proper error code, doesn't leak memory
  496. # and doesn't core dump
  497. if($ret & 255) {
  498. logmsg " system() returned $ret\n";
  499. $fail=1;
  500. }
  501. else {
  502. my @memdata=`$memanalyze $memdump`;
  503. my $leak=0;
  504. for(@memdata) {
  505. if($_ ne "") {
  506. # well it could be other memory problems as well, but
  507. # we call it leak for short here
  508. $leak=1;
  509. }
  510. }
  511. if($leak) {
  512. logmsg "** MEMORY FAILURE\n";
  513. logmsg @memdata;
  514. logmsg `$memanalyze -l $memdump`;
  515. $fail = 1;
  516. }
  517. }
  518. if($fail) {
  519. logmsg " Failed on alloc number $limit in test.\n",
  520. " invoke with \"-t$limit\" to repeat this single case.\n";
  521. stopservers($verbose);
  522. return 1;
  523. }
  524. }
  525. logmsg "torture OK\n";
  526. return 0;
  527. }
  528. #######################################################################
  529. # Stop a test server along with pids which aren't in the %run hash yet.
  530. # This also stops all servers which are relative to the given one.
  531. #
  532. sub stopserver {
  533. my ($server, $pidlist) = @_;
  534. #
  535. # kill sockfilter processes for pingpong relative server
  536. #
  537. if($server =~ /^(ftp|imap|pop3|smtp)s?(\d*)(-ipv6|)$/) {
  538. my $proto = $1;
  539. my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
  540. my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
  541. killsockfilters($proto, $ipvnum, $idnum, $verbose);
  542. }
  543. #
  544. # All servers relative to the given one must be stopped also
  545. #
  546. my @killservers;
  547. if($server =~ /^(ftp|http|imap|pop3|smtp)s(.*)$/) {
  548. # given an ssl server, also kill non-ssl underlying one
  549. push @killservers, "${1}${2}";
  550. }
  551. elsif($server =~ /^(ftp|http|imap|pop3|smtp)(.*)$/) {
  552. # given a non-ssl server, also kill ssl piggybacking one
  553. push @killservers, "${1}s${2}";
  554. }
  555. elsif($server =~ /^(socks)(.*)$/) {
  556. # given an socks server, also kill ssh underlying one
  557. push @killservers, "ssh${2}";
  558. }
  559. elsif($server =~ /^(ssh)(.*)$/) {
  560. # given an ssh server, also kill socks piggybacking one
  561. push @killservers, "socks${2}";
  562. }
  563. push @killservers, $server;
  564. #
  565. # kill given pids and server relative ones clearing them in %run hash
  566. #
  567. foreach my $server (@killservers) {
  568. if($run{$server}) {
  569. $pidlist .= "$run{$server} ";
  570. $run{$server} = 0;
  571. }
  572. $runcert{$server} = 0 if($runcert{$server});
  573. }
  574. killpid($verbose, $pidlist);
  575. #
  576. # cleanup server pid files
  577. #
  578. foreach my $server (@killservers) {
  579. my $pidfile = $serverpidfile{$server};
  580. my $pid = processexists($pidfile);
  581. if($pid > 0) {
  582. logmsg "Warning: $server server unexpectedly alive\n";
  583. killpid($verbose, $pid);
  584. }
  585. unlink($pidfile) if(-f $pidfile);
  586. }
  587. }
  588. #######################################################################
  589. # Verify that the server that runs on $ip, $port is our server. This also
  590. # implies that we can speak with it, as there might be occasions when the
  591. # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
  592. # assign requested address" #
  593. sub verifyhttp {
  594. my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
  595. my $server = servername_id($proto, $ipvnum, $idnum);
  596. my $pid = 0;
  597. my $bonus="";
  598. my $verifyout = "$LOGDIR/".
  599. servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
  600. unlink($verifyout) if(-f $verifyout);
  601. my $verifylog = "$LOGDIR/".
  602. servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
  603. unlink($verifylog) if(-f $verifylog);
  604. if($proto eq "gopher") {
  605. # gopher is funny
  606. $bonus="1/";
  607. }
  608. my $flags = "--max-time $server_response_maxtime ";
  609. $flags .= "--output $verifyout ";
  610. $flags .= "--silent ";
  611. $flags .= "--verbose ";
  612. $flags .= "--globoff ";
  613. $flags .= "-1 " if($has_axtls);
  614. $flags .= "--insecure " if($proto eq 'https');
  615. $flags .= "\"$proto://$ip:$port/${bonus}verifiedserver\"";
  616. my $cmd = "$VCURL $flags 2>$verifylog";
  617. # verify if our/any server is running on this port
  618. logmsg "RUN: $cmd\n" if($verbose);
  619. my $res = runclient($cmd);
  620. $res >>= 8; # rotate the result
  621. if($res & 128) {
  622. logmsg "RUN: curl command died with a coredump\n";
  623. return -1;
  624. }
  625. if($res && $verbose) {
  626. logmsg "RUN: curl command returned $res\n";
  627. if(open(FILE, "<$verifylog")) {
  628. while(my $string = <FILE>) {
  629. logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
  630. }
  631. close(FILE);
  632. }
  633. }
  634. my $data;
  635. if(open(FILE, "<$verifyout")) {
  636. while(my $string = <FILE>) {
  637. $data = $string;
  638. last; # only want first line
  639. }
  640. close(FILE);
  641. }
  642. if($data && ($data =~ /WE ROOLZ: (\d+)/)) {
  643. $pid = 0+$1;
  644. }
  645. elsif($res == 6) {
  646. # curl: (6) Couldn't resolve host '::1'
  647. logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
  648. return -1;
  649. }
  650. elsif($data || ($res && ($res != 7))) {
  651. logmsg "RUN: Unknown server on our $server port: $port ($res)\n";
  652. return -1;
  653. }
  654. return $pid;
  655. }
  656. #######################################################################
  657. # Verify that the server that runs on $ip, $port is our server. This also
  658. # implies that we can speak with it, as there might be occasions when the
  659. # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
  660. # assign requested address" #
  661. sub verifyftp {
  662. my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
  663. my $server = servername_id($proto, $ipvnum, $idnum);
  664. my $pid = 0;
  665. my $time=time();
  666. my $extra="";
  667. my $verifylog = "$LOGDIR/".
  668. servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
  669. unlink($verifylog) if(-f $verifylog);
  670. if($proto eq "ftps") {
  671. $extra .= "--insecure --ftp-ssl-control ";
  672. }
  673. elsif($proto eq "smtp") {
  674. # SMTP is a bit different since it requires more options and it
  675. # has _no_ output!
  676. $extra .= "--mail-rcpt verifiedserver ";
  677. $extra .= "--mail-from fake ";
  678. $extra .= "--upload /dev/null ";
  679. $extra .= "--stderr - "; # move stderr to parse the verbose stuff
  680. }
  681. my $flags = "--max-time $server_response_maxtime ";
  682. $flags .= "--silent ";
  683. $flags .= "--verbose ";
  684. $flags .= "--globoff ";
  685. $flags .= $extra;
  686. $flags .= "\"$proto://$ip:$port/verifiedserver\"";
  687. my $cmd = "$VCURL $flags 2>$verifylog";
  688. # check if this is our server running on this port:
  689. logmsg "RUN: $cmd\n" if($verbose);
  690. my @data = runclientoutput($cmd);
  691. my $res = $? >> 8; # rotate the result
  692. if($res & 128) {
  693. logmsg "RUN: curl command died with a coredump\n";
  694. return -1;
  695. }
  696. foreach my $line (@data) {
  697. if($line =~ /WE ROOLZ: (\d+)/) {
  698. # this is our test server with a known pid!
  699. $pid = 0+$1;
  700. last;
  701. }
  702. }
  703. if($pid <= 0 && @data && $data[0]) {
  704. # this is not a known server
  705. logmsg "RUN: Unknown server on our $server port: $port\n";
  706. return 0;
  707. }
  708. # we can/should use the time it took to verify the FTP server as a measure
  709. # on how fast/slow this host/FTP is.
  710. my $took = int(0.5+time()-$time);
  711. if($verbose) {
  712. logmsg "RUN: Verifying our test $server server took $took seconds\n";
  713. }
  714. $ftpchecktime = $took>=1?$took:1; # make sure it never is below 1
  715. return $pid;
  716. }
  717. #######################################################################
  718. # Verify that the server that runs on $ip, $port is our server. This also
  719. # implies that we can speak with it, as there might be occasions when the
  720. # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
  721. # assign requested address" #
  722. sub verifyrtsp {
  723. my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
  724. my $server = servername_id($proto, $ipvnum, $idnum);
  725. my $pid = 0;
  726. my $verifyout = "$LOGDIR/".
  727. servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
  728. unlink($verifyout) if(-f $verifyout);
  729. my $verifylog = "$LOGDIR/".
  730. servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
  731. unlink($verifylog) if(-f $verifylog);
  732. my $flags = "--max-time $server_response_maxtime ";
  733. $flags .= "--output $verifyout ";
  734. $flags .= "--silent ";
  735. $flags .= "--verbose ";
  736. $flags .= "--globoff ";
  737. # currently verification is done using http
  738. $flags .= "\"http://$ip:$port/verifiedserver\"";
  739. my $cmd = "$VCURL $flags 2>$verifylog";
  740. # verify if our/any server is running on this port
  741. logmsg "RUN: $cmd\n" if($verbose);
  742. my $res = runclient($cmd);
  743. $res >>= 8; # rotate the result
  744. if($res & 128) {
  745. logmsg "RUN: curl command died with a coredump\n";
  746. return -1;
  747. }
  748. if($res && $verbose) {
  749. logmsg "RUN: curl command returned $res\n";
  750. if(open(FILE, "<$verifylog")) {
  751. while(my $string = <FILE>) {
  752. logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
  753. }
  754. close(FILE);
  755. }
  756. }
  757. my $data;
  758. if(open(FILE, "<$verifyout")) {
  759. while(my $string = <FILE>) {
  760. $data = $string;
  761. last; # only want first line
  762. }
  763. close(FILE);
  764. }
  765. if($data && ($data =~ /RTSP_SERVER WE ROOLZ: (\d+)/)) {
  766. $pid = 0+$1;
  767. }
  768. elsif($res == 6) {
  769. # curl: (6) Couldn't resolve host '::1'
  770. logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
  771. return -1;
  772. }
  773. elsif($data || ($res != 7)) {
  774. logmsg "RUN: Unknown server on our $server port: $port\n";
  775. return -1;
  776. }
  777. return $pid;
  778. }
  779. #######################################################################
  780. # Verify that the ssh server has written out its pidfile, recovering
  781. # the pid from the file and returning it if a process with that pid is
  782. # actually alive.
  783. sub verifyssh {
  784. my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
  785. my $server = servername_id($proto, $ipvnum, $idnum);
  786. my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
  787. my $pid = 0;
  788. if(open(FILE, "<$pidfile")) {
  789. $pid=0+<FILE>;
  790. close(FILE);
  791. }
  792. if($pid > 0) {
  793. # if we have a pid it is actually our ssh server,
  794. # since runsshserver() unlinks previous pidfile
  795. if(!kill(0, $pid)) {
  796. logmsg "RUN: SSH server has died after starting up\n";
  797. checkdied($pid);
  798. unlink($pidfile);
  799. $pid = -1;
  800. }
  801. }
  802. return $pid;
  803. }
  804. #######################################################################
  805. # Verify that we can connect to the sftp server, properly authenticate
  806. # with generated config and key files and run a simple remote pwd.
  807. sub verifysftp {
  808. my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
  809. my $server = servername_id($proto, $ipvnum, $idnum);
  810. my $verified = 0;
  811. # Find out sftp client canonical file name
  812. my $sftp = find_sftp();
  813. if(!$sftp) {
  814. logmsg "RUN: SFTP server cannot find $sftpexe\n";
  815. return -1;
  816. }
  817. # Find out ssh client canonical file name
  818. my $ssh = find_ssh();
  819. if(!$ssh) {
  820. logmsg "RUN: SFTP server cannot find $sshexe\n";
  821. return -1;
  822. }
  823. # Connect to sftp server, authenticate and run a remote pwd
  824. # command using our generated configuration and key files
  825. my $cmd = "$sftp -b $sftpcmds -F $sftpconfig -S $ssh $ip > $sftplog 2>&1";
  826. my $res = runclient($cmd);
  827. # Search for pwd command response in log file
  828. if(open(SFTPLOGFILE, "<$sftplog")) {
  829. while(<SFTPLOGFILE>) {
  830. if(/^Remote working directory: /) {
  831. $verified = 1;
  832. last;
  833. }
  834. }
  835. close(SFTPLOGFILE);
  836. }
  837. return $verified;
  838. }
  839. #######################################################################
  840. # STUB for verifying socks
  841. sub verifysocks {
  842. my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
  843. my $server = servername_id($proto, $ipvnum, $idnum);
  844. my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
  845. my $pid = 0;
  846. if(open(FILE, "<$pidfile")) {
  847. $pid=0+<FILE>;
  848. close(FILE);
  849. }
  850. if($pid > 0) {
  851. # if we have a pid it is actually our socks server,
  852. # since runsocksserver() unlinks previous pidfile
  853. if(!kill(0, $pid)) {
  854. logmsg "RUN: SOCKS server has died after starting up\n";
  855. checkdied($pid);
  856. unlink($pidfile);
  857. $pid = -1;
  858. }
  859. }
  860. return $pid;
  861. }
  862. #######################################################################
  863. # Verify that the server that runs on $ip, $port is our server.
  864. # Retry over several seconds before giving up. The ssh server in
  865. # particular can take a long time to start if it needs to generate
  866. # keys on a slow or loaded host.
  867. #
  868. my %protofunc = ('http' => \&verifyhttp,
  869. 'https' => \&verifyhttp,
  870. 'rtsp' => \&verifyrtsp,
  871. 'ftp' => \&verifyftp,
  872. 'pop3' => \&verifyftp,
  873. 'imap' => \&verifyftp,
  874. 'smtp' => \&verifyftp,
  875. 'ftps' => \&verifyftp,
  876. 'tftp' => \&verifyftp,
  877. 'ssh' => \&verifyssh,
  878. 'socks' => \&verifysocks,
  879. 'gopher' => \&verifyhttp);
  880. sub verifyserver {
  881. my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
  882. my $count = 30; # try for this many seconds
  883. my $pid;
  884. while($count--) {
  885. my $fun = $protofunc{$proto};
  886. $pid = &$fun($proto, $ipvnum, $idnum, $ip, $port);
  887. if($pid > 0) {
  888. last;
  889. }
  890. elsif($pid < 0) {
  891. # a real failure, stop trying and bail out
  892. return 0;
  893. }
  894. sleep(1);
  895. }
  896. return $pid;
  897. }
  898. #######################################################################
  899. # start the http server
  900. #
  901. sub runhttpserver {
  902. my ($proto, $verbose, $ipv6, $port) = @_;
  903. my $ip = $HOSTIP;
  904. my $ipvnum = 4;
  905. my $idnum = 1;
  906. my $server;
  907. my $srvrname;
  908. my $pidfile;
  909. my $logfile;
  910. my $flags = "";
  911. if($ipv6) {
  912. # if IPv6, use a different setup
  913. $ipvnum = 6;
  914. $ip = $HOST6IP;
  915. }
  916. $server = servername_id($proto, $ipvnum, $idnum);
  917. $pidfile = $serverpidfile{$server};
  918. # don't retry if the server doesn't work
  919. if ($doesntrun{$pidfile}) {
  920. return (0,0);
  921. }
  922. my $pid = processexists($pidfile);
  923. if($pid > 0) {
  924. stopserver($server, "$pid");
  925. }
  926. unlink($pidfile) if(-f $pidfile);
  927. $srvrname = servername_str($proto, $ipvnum, $idnum);
  928. $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
  929. $flags .= "--fork " if($forkserver);
  930. $flags .= "--gopher " if($proto eq "gopher");
  931. $flags .= "--verbose " if($debugprotocol);
  932. $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
  933. $flags .= "--id $idnum " if($idnum > 1);
  934. $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
  935. my $cmd = "$perl $srcdir/httpserver.pl $flags";
  936. my ($httppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
  937. if($httppid <= 0 || !kill(0, $httppid)) {
  938. # it is NOT alive
  939. logmsg "RUN: failed to start the $srvrname server\n";
  940. stopserver($server, "$pid2");
  941. displaylogs($testnumcheck);
  942. $doesntrun{$pidfile} = 1;
  943. return (0,0);
  944. }
  945. # Server is up. Verify that we can speak to it.
  946. my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
  947. if(!$pid3) {
  948. logmsg "RUN: $srvrname server failed verification\n";
  949. # failed to talk to it properly. Kill the server and return failure
  950. stopserver($server, "$httppid $pid2");
  951. displaylogs($testnumcheck);
  952. $doesntrun{$pidfile} = 1;
  953. return (0,0);
  954. }
  955. $pid2 = $pid3;
  956. if($verbose) {
  957. logmsg "RUN: $srvrname server is now running PID $httppid\n";
  958. }
  959. sleep(1);
  960. return ($httppid, $pid2);
  961. }
  962. #######################################################################
  963. # start the https server (or rather, tunnel)
  964. #
  965. sub runhttpsserver {
  966. my ($verbose, $ipv6, $certfile) = @_;
  967. my $proto = 'https';
  968. my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
  969. my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
  970. my $idnum = 1;
  971. my $server;
  972. my $srvrname;
  973. my $pidfile;
  974. my $logfile;
  975. my $flags = "";
  976. if(!$stunnel) {
  977. return (0,0);
  978. }
  979. $server = servername_id($proto, $ipvnum, $idnum);
  980. $pidfile = $serverpidfile{$server};
  981. # don't retry if the server doesn't work
  982. if ($doesntrun{$pidfile}) {
  983. return (0,0);
  984. }
  985. my $pid = processexists($pidfile);
  986. if($pid > 0) {
  987. stopserver($server, "$pid");
  988. }
  989. unlink($pidfile) if(-f $pidfile);
  990. $srvrname = servername_str($proto, $ipvnum, $idnum);
  991. $certfile = 'stunnel.pem' unless($certfile);
  992. $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
  993. $flags .= "--verbose " if($debugprotocol);
  994. $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
  995. $flags .= "--id $idnum " if($idnum > 1);
  996. $flags .= "--ipv$ipvnum --proto $proto ";
  997. $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
  998. $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
  999. $flags .= "--connect $HTTPPORT --accept $HTTPSPORT";
  1000. my $cmd = "$perl $srcdir/secureserver.pl $flags";
  1001. my ($httpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
  1002. if($httpspid <= 0 || !kill(0, $httpspid)) {
  1003. # it is NOT alive
  1004. logmsg "RUN: failed to start the $srvrname server\n";
  1005. stopserver($server, "$pid2");
  1006. displaylogs($testnumcheck);
  1007. $doesntrun{$pidfile} = 1;
  1008. return(0,0);
  1009. }
  1010. # Server is up. Verify that we can speak to it.
  1011. my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $HTTPSPORT);
  1012. if(!$pid3) {
  1013. logmsg "RUN: $srvrname server failed verification\n";
  1014. # failed to talk to it properly. Kill the server and return failure
  1015. stopserver($server, "$httpspid $pid2");
  1016. displaylogs($testnumcheck);
  1017. $doesntrun{$pidfile} = 1;
  1018. return (0,0);
  1019. }
  1020. # Here pid3 is actually the pid returned by the unsecure-http server.
  1021. $runcert{$server} = $certfile;
  1022. if($verbose) {
  1023. logmsg "RUN: $srvrname server is now running PID $httpspid\n";
  1024. }
  1025. sleep(1);
  1026. return ($httpspid, $pid2);
  1027. }
  1028. #######################################################################
  1029. # start the pingpong server (FTP, POP3, IMAP, SMTP)
  1030. #
  1031. sub runpingpongserver {
  1032. my ($proto, $id, $verbose, $ipv6) = @_;
  1033. my $port;
  1034. my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
  1035. my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
  1036. my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
  1037. my $server;
  1038. my $srvrname;
  1039. my $pidfile;
  1040. my $logfile;
  1041. my $flags = "";
  1042. if($proto eq "ftp") {
  1043. $port = ($idnum>1)?$FTP2PORT:$FTPPORT;
  1044. if($ipvnum==6) {
  1045. # if IPv6, use a different setup
  1046. $port = $FTP6PORT;
  1047. }
  1048. }
  1049. elsif($proto eq "pop3") {
  1050. $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT;
  1051. }
  1052. elsif($proto eq "imap") {
  1053. $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT;
  1054. }
  1055. elsif($proto eq "smtp") {
  1056. $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT;
  1057. }
  1058. else {
  1059. print STDERR "Unsupported protocol $proto!!\n";
  1060. return 0;
  1061. }
  1062. $server = servername_id($proto, $ipvnum, $idnum);
  1063. $pidfile = $serverpidfile{$server};
  1064. # don't retry if the server doesn't work
  1065. if ($doesntrun{$pidfile}) {
  1066. return (0,0);
  1067. }
  1068. my $pid = processexists($pidfile);
  1069. if($pid > 0) {
  1070. stopserver($server, "$pid");
  1071. }
  1072. unlink($pidfile) if(-f $pidfile);
  1073. $srvrname = servername_str($proto, $ipvnum, $idnum);
  1074. $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
  1075. $flags .= "--verbose " if($debugprotocol);
  1076. $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
  1077. $flags .= "--srcdir \"$srcdir\" --proto $proto ";
  1078. $flags .= "--id $idnum " if($idnum > 1);
  1079. $flags .= "--ipv$ipvnum --port $port --addr \"$ip\"";
  1080. my $cmd = "$perl $srcdir/ftpserver.pl $flags";
  1081. my ($ftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
  1082. if($ftppid <= 0 || !kill(0, $ftppid)) {
  1083. # it is NOT alive
  1084. logmsg "RUN: failed to start the $srvrname server\n";
  1085. stopserver($server, "$pid2");
  1086. displaylogs($testnumcheck);
  1087. $doesntrun{$pidfile} = 1;
  1088. return (0,0);
  1089. }
  1090. # Server is up. Verify that we can speak to it.
  1091. my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
  1092. if(!$pid3) {
  1093. logmsg "RUN: $srvrname server failed verification\n";
  1094. # failed to talk to it properly. Kill the server and return failure
  1095. stopserver($server, "$ftppid $pid2");
  1096. displaylogs($testnumcheck);
  1097. $doesntrun{$pidfile} = 1;
  1098. return (0,0);
  1099. }
  1100. $pid2 = $pid3;
  1101. if($verbose) {
  1102. logmsg "RUN: $srvrname server is now running PID $ftppid\n";
  1103. }
  1104. sleep(1);
  1105. return ($pid2, $ftppid);
  1106. }
  1107. #######################################################################
  1108. # start the ftps server (or rather, tunnel)
  1109. #
  1110. sub runftpsserver {
  1111. my ($verbose, $ipv6, $certfile) = @_;
  1112. my $proto = 'ftps';
  1113. my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
  1114. my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
  1115. my $idnum = 1;
  1116. my $server;
  1117. my $srvrname;
  1118. my $pidfile;
  1119. my $logfile;
  1120. my $flags = "";
  1121. if(!$stunnel) {
  1122. return (0,0);
  1123. }
  1124. $server = servername_id($proto, $ipvnum, $idnum);
  1125. $pidfile = $serverpidfile{$server};
  1126. # don't retry if the server doesn't work
  1127. if ($doesntrun{$pidfile}) {
  1128. return (0,0);
  1129. }
  1130. my $pid = processexists($pidfile);
  1131. if($pid > 0) {
  1132. stopserver($server, "$pid");
  1133. }
  1134. unlink($pidfile) if(-f $pidfile);
  1135. $srvrname = servername_str($proto, $ipvnum, $idnum);
  1136. $certfile = 'stunnel.pem' unless($certfile);
  1137. $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
  1138. $flags .= "--verbose " if($debugprotocol);
  1139. $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
  1140. $flags .= "--id $idnum " if($idnum > 1);
  1141. $flags .= "--ipv$ipvnum --proto $proto ";
  1142. $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
  1143. $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
  1144. $flags .= "--connect $FTPPORT --accept $FTPSPORT";
  1145. my $cmd = "$perl $srcdir/secureserver.pl $flags";
  1146. my ($ftpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
  1147. if($ftpspid <= 0 || !kill(0, $ftpspid)) {
  1148. # it is NOT alive
  1149. logmsg "RUN: failed to start the $srvrname server\n";
  1150. stopserver($server, "$pid2");
  1151. displaylogs($testnumcheck);
  1152. $doesntrun{$pidfile} = 1;
  1153. return(0,0);
  1154. }
  1155. # Server is up. Verify that we can speak to it.
  1156. my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $FTPSPORT);
  1157. if(!$pid3) {
  1158. logmsg "RUN: $srvrname server failed verification\n";
  1159. # failed to talk to it properly. Kill the server and return failure
  1160. stopserver($server, "$ftpspid $pid2");
  1161. displaylogs($testnumcheck);
  1162. $doesntrun{$pidfile} = 1;
  1163. return (0,0);
  1164. }
  1165. # Here pid3 is actually the pid returned by the unsecure-ftp server.
  1166. $runcert{$server} = $certfile;
  1167. if($verbose) {
  1168. logmsg "RUN: $srvrname server is now running PID $ftpspid\n";
  1169. }
  1170. sleep(1);
  1171. return ($ftpspid, $pid2);
  1172. }
  1173. #######################################################################
  1174. # start the tftp server
  1175. #
  1176. sub runtftpserver {
  1177. my ($id, $verbose, $ipv6) = @_;
  1178. my $port = $TFTPPORT;
  1179. my $ip = $HOSTIP;
  1180. my $proto = 'tftp';
  1181. my $ipvnum = 4;
  1182. my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
  1183. my $server;
  1184. my $srvrname;
  1185. my $pidfile;
  1186. my $logfile;
  1187. my $flags = "";
  1188. if($ipv6) {
  1189. # if IPv6, use a different setup
  1190. $ipvnum = 6;
  1191. $port = $TFTP6PORT;
  1192. $ip = $HOST6IP;
  1193. }
  1194. $server = servername_id($proto, $ipvnum, $idnum);
  1195. $pidfile = $serverpidfile{$server};
  1196. # don't retry if the server doesn't work
  1197. if ($doesntrun{$pidfile}) {
  1198. return (0,0);
  1199. }
  1200. my $pid = processexists($pidfile);
  1201. if($pid > 0) {
  1202. stopserver($server, "$pid");
  1203. }
  1204. unlink($pidfile) if(-f $pidfile);
  1205. $srvrname = servername_str($proto, $ipvnum, $idnum);
  1206. $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
  1207. $flags .= "--verbose " if($debugprotocol);
  1208. $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
  1209. $flags .= "--id $idnum " if($idnum > 1);
  1210. $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
  1211. my $cmd = "$perl $srcdir/tftpserver.pl $flags";
  1212. my ($tftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
  1213. if($tftppid <= 0 || !kill(0, $tftppid)) {
  1214. # it is NOT alive
  1215. logmsg "RUN: failed to start the $srvrname server\n";
  1216. stopserver($server, "$pid2");
  1217. displaylogs($testnumcheck);
  1218. $doesntrun{$pidfile} = 1;
  1219. return (0,0);
  1220. }
  1221. # Server is up. Verify that we can speak to it.
  1222. my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
  1223. if(!$pid3) {
  1224. logmsg "RUN: $srvrname server failed verification\n";
  1225. # failed to talk to it properly. Kill the server and return failure
  1226. stopserver($server, "$tftppid $pid2");
  1227. displaylogs($testnumcheck);
  1228. $doesntrun{$pidfile} = 1;
  1229. return (0,0);
  1230. }
  1231. $pid2 = $pid3;
  1232. if($verbose) {
  1233. logmsg "RUN: $srvrname server is now running PID $tftppid\n";
  1234. }
  1235. sleep(1);
  1236. return ($pid2, $tftppid);
  1237. }
  1238. #######################################################################
  1239. # start the rtsp server
  1240. #
  1241. sub runrtspserver {
  1242. my ($verbose, $ipv6) = @_;
  1243. my $port = $RTSPPORT;
  1244. my $ip = $HOSTIP;
  1245. my $proto = 'rtsp';
  1246. my $ipvnum = 4;
  1247. my $idnum = 1;
  1248. my $server;
  1249. my $srvrname;
  1250. my $pidfile;
  1251. my $logfile;
  1252. my $flags = "";
  1253. if($ipv6) {
  1254. # if IPv6, use a different setup
  1255. $ipvnum = 6;
  1256. $port = $RTSP6PORT;
  1257. $ip = $HOST6IP;
  1258. }
  1259. $server = servername_id($proto, $ipvnum, $idnum);
  1260. $pidfile = $serverpidfile{$server};
  1261. # don't retry if the server doesn't work
  1262. if ($doesntrun{$pidfile}) {
  1263. return (0,0);
  1264. }
  1265. my $pid = processexists($pidfile);
  1266. if($pid > 0) {
  1267. stopserver($server, "$pid");
  1268. }
  1269. unlink($pidfile) if(-f $pidfile);
  1270. $srvrname = servername_str($proto, $ipvnum, $idnum);
  1271. $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
  1272. $flags .= "--verbose " if($debugprotocol);
  1273. $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
  1274. $flags .= "--id $idnum " if($idnum > 1);
  1275. $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
  1276. my $cmd = "$perl $srcdir/rtspserver.pl $flags";
  1277. my ($rtsppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
  1278. if($rtsppid <= 0 || !kill(0, $rtsppid)) {
  1279. # it is NOT alive
  1280. logmsg "RUN: failed to start the $srvrname server\n";
  1281. stopserver($server, "$pid2");
  1282. displaylogs($testnumcheck);
  1283. $doesntrun{$pidfile} = 1;
  1284. return (0,0);
  1285. }
  1286. # Server is up. Verify that we can speak to it.
  1287. my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
  1288. if(!$pid3) {
  1289. logmsg "RUN: $srvrname server failed verification\n";
  1290. # failed to talk to it properly. Kill the server and return failure
  1291. stopserver($server, "$rtsppid $pid2");
  1292. displaylogs($testnumcheck);
  1293. $doesntrun{$pidfile} = 1;
  1294. return (0,0);
  1295. }
  1296. $pid2 = $pid3;
  1297. if($verbose) {
  1298. logmsg "RUN: $srvrname server is now running PID $rtsppid\n";
  1299. }
  1300. sleep(1);
  1301. return ($rtsppid, $pid2);
  1302. }
  1303. #######################################################################
  1304. # Start the ssh (scp/sftp) server
  1305. #
  1306. sub runsshserver {
  1307. my ($id, $verbose, $ipv6) = @_;
  1308. my $ip=$HOSTIP;
  1309. my $port = $SSHPORT;
  1310. my $socksport = $SOCKSPORT;
  1311. my $proto = 'ssh';
  1312. my $ipvnum = 4;
  1313. my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
  1314. my $server;
  1315. my $srvrname;
  1316. my $pidfile;
  1317. my $logfile;
  1318. my $flags = "";
  1319. $server = servername_id($proto, $ipvnum, $idnum);
  1320. $pidfile = $serverpidfile{$server};
  1321. # don't retry if the server doesn't work
  1322. if ($doesntrun{$pidfile}) {
  1323. return (0,0);
  1324. }
  1325. my $pid = processexists($pidfile);
  1326. if($pid > 0) {
  1327. stopserver($server, "$pid");
  1328. }
  1329. unlink($pidfile) if(-f $pidfile);
  1330. $srvrname = servername_str($proto, $ipvnum, $idnum);
  1331. $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
  1332. $flags .= "--verbose " if($verbose);
  1333. $flags .= "--debugprotocol " if($debugprotocol);
  1334. $flags .= "--pidfile \"$pidfile\" ";
  1335. $flags .= "--id $idnum " if($idnum > 1);
  1336. $flags .= "--ipv$ipvnum --addr \"$ip\" ";
  1337. $flags .= "--sshport $port --socksport $socksport ";
  1338. $flags .= "--user \"$USER\"";
  1339. my $cmd = "$perl $srcdir/sshserver.pl $flags";
  1340. my ($sshpid, $pid2) = startnew($cmd, $pidfile, 60, 0);
  1341. # on loaded systems sshserver start up can take longer than the timeout
  1342. # passed to startnew, when this happens startnew completes without being
  1343. # able to read the pidfile and consequently returns a zero pid2 above.
  1344. if($sshpid <= 0 || !kill(0, $sshpid)) {
  1345. # it is NOT alive
  1346. logmsg "RUN: failed to start the $srvrname server\n";
  1347. stopserver($server, "$pid2");
  1348. $doesntrun{$pidfile} = 1;
  1349. return (0,0);
  1350. }
  1351. # ssh server verification allows some extra time for the server to start up
  1352. # and gives us the opportunity of recovering the pid from the pidfile, when
  1353. # this verification succeeds the recovered pid is assigned to pid2.
  1354. my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
  1355. if(!$pid3) {
  1356. logmsg "RUN: $srvrname server failed verification\n";
  1357. # failed to fetch server pid. Kill the server and return failure
  1358. stopserver($server, "$sshpid $pid2");
  1359. $doesntrun{$pidfile} = 1;
  1360. return (0,0);
  1361. }
  1362. $pid2 = $pid3;
  1363. # once it is known that the ssh server is alive, sftp server verification
  1364. # is performed actually connecting to it, authenticating and performing a
  1365. # very simple remote command. This verification is tried only one time.
  1366. $sshdlog = server_logfilename($LOGDIR, 'ssh', $ipvnum, $idnum);
  1367. $sftplog = server_logfilename($LOGDIR, 'sftp', $ipvnum, $idnum);
  1368. if(verifysftp('sftp', $ipvnum, $idnum, $ip, $port) < 1) {
  1369. logmsg "RUN: SFTP server failed verification\n";
  1370. # failed to talk to it properly. Kill the server and return failure
  1371. display_sftplog();
  1372. display_sftpconfig();
  1373. display_sshdlog();
  1374. display_sshdconfig();
  1375. stopserver($server, "$sshpid $pid2");
  1376. $doesntrun{$pidfile} = 1;
  1377. return (0,0);
  1378. }
  1379. if($verbose) {
  1380. logmsg "RUN: $srvrname server is now running PID $pid2\n";
  1381. }
  1382. return ($pid2, $sshpid);
  1383. }
  1384. #######################################################################
  1385. # Start the socks server
  1386. #
  1387. sub runsocksserver {
  1388. my ($id, $verbose, $ipv6) = @_;
  1389. my $ip=$HOSTIP;
  1390. my $port = $SOCKSPORT;
  1391. my $proto = 'socks';
  1392. my $ipvnum = 4;
  1393. my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
  1394. my $server;
  1395. my $srvrname;
  1396. my $pidfile;
  1397. my $logfile;
  1398. my $flags = "";
  1399. $server = servername_id($proto, $ipvnum, $idnum);
  1400. $pidfile = $serverpidfile{$server};
  1401. # don't retry if the server doesn't work
  1402. if ($doesntrun{$pidfile}) {
  1403. return (0,0);
  1404. }
  1405. my $pid = processexists($pidfile);
  1406. if($pid > 0) {
  1407. stopserver($server, "$pid");
  1408. }
  1409. unlink($pidfile) if(-f $pidfile);
  1410. $srvrname = servername_str($proto, $ipvnum, $idnum);
  1411. $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
  1412. # The ssh server must be already running
  1413. if(!$run{'ssh'}) {
  1414. logmsg "RUN: SOCKS server cannot find running SSH server\n";
  1415. $doesntrun{$pidfile} = 1;
  1416. return (0,0);
  1417. }
  1418. # Find out ssh daemon canonical file name
  1419. my $sshd = find_sshd();
  1420. if(!$sshd) {
  1421. logmsg "RUN: SOCKS server cannot find $sshdexe\n";
  1422. $doesntrun{$pidfile} = 1;
  1423. return (0,0);
  1424. }
  1425. # Find out ssh daemon version info
  1426. ($sshdid, $sshdvernum, $sshdverstr, $sshderror) = sshversioninfo($sshd);
  1427. if(!$sshdid) {
  1428. # Not an OpenSSH or SunSSH ssh daemon
  1429. logmsg "$sshderror\n" if($verbose);
  1430. logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
  1431. $doesntrun{$pidfile} = 1;
  1432. return (0,0);
  1433. }
  1434. logmsg "ssh server found $sshd is $sshdverstr\n" if($verbose);
  1435. # Find out ssh client canonical file name
  1436. my $ssh = find_ssh();
  1437. if(!$ssh) {
  1438. logmsg "RUN: SOCKS server cannot find $sshexe\n";
  1439. $doesntrun{$pidfile} = 1;
  1440. return (0,0);
  1441. }
  1442. # Find out ssh client version info
  1443. my ($sshid, $sshvernum, $sshverstr, $ssherror) = sshversioninfo($ssh);
  1444. if(!$sshid) {
  1445. # Not an OpenSSH or SunSSH ssh client
  1446. logmsg "$ssherror\n" if($verbose);
  1447. logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
  1448. $doesntrun{$pidfile} = 1;
  1449. return (0,0);
  1450. }
  1451. # Verify minimum ssh client version
  1452. if((($sshid =~ /OpenSSH/) && ($sshvernum < 299)) ||
  1453. (($sshid =~ /SunSSH/) && ($sshvernum < 100))) {
  1454. logmsg "ssh client found $ssh is $sshverstr\n";
  1455. logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
  1456. $doesntrun{$pidfile} = 1;
  1457. return (0,0);
  1458. }
  1459. logmsg "ssh client found $ssh is $sshverstr\n" if($verbose);
  1460. # Verify if ssh client and ssh daemon versions match
  1461. if(($sshdid ne $sshid) || ($sshdvernum != $sshvernum)) {
  1462. # Our test harness might work with slightly mismatched versions
  1463. logmsg "Warning: version mismatch: sshd $sshdverstr - ssh $sshverstr\n"
  1464. if($verbose);
  1465. }
  1466. # Config file options for ssh client are previously set from sshserver.pl
  1467. if(! -e $sshconfig) {
  1468. logmsg "RUN: SOCKS server cannot find $sshconfig\n";
  1469. $doesntrun{$pidfile} = 1;
  1470. return (0,0);
  1471. }
  1472. $sshlog = server_logfilename($LOGDIR, 'socks', $ipvnum, $idnum);
  1473. # start our socks server
  1474. my $cmd="$ssh -N -F $sshconfig $ip > $sshlog 2>&1";
  1475. my ($sshpid, $pid2) = startnew($cmd, $pidfile, 30, 1);
  1476. if($sshpid <= 0 || !kill(0, $sshpid)) {
  1477. # it is NOT alive
  1478. logmsg "RUN: failed to start the $srvrname server\n";
  1479. display_sshlog();
  1480. display_sshconfig();
  1481. display_sshdlog();
  1482. display_sshdconfig();
  1483. stopserver($server, "$pid2");
  1484. $doesntrun{$pidfile} = 1;
  1485. return (0,0);
  1486. }
  1487. # Ugly hack but ssh doesn't support pid files
  1488. my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
  1489. if(!$pid3) {
  1490. logmsg "RUN: $srvrname server failed verification\n";
  1491. # failed to talk to it properly. Kill the server and return failure
  1492. stopserver($server, "$sshpid $pid2");
  1493. $doesntrun{$pidfile} = 1;
  1494. return (0,0);
  1495. }
  1496. $pid2 = $pid3;
  1497. if($verbose) {
  1498. logmsg "RUN: $srvrname server is now running PID $pid2\n";
  1499. }
  1500. return ($pid2, $sshpid);
  1501. }
  1502. #######################################################################
  1503. # Remove all files in the specified directory
  1504. #
  1505. sub cleardir {
  1506. my $dir = $_[0];
  1507. my $count;
  1508. my $file;
  1509. # Get all files
  1510. opendir(DIR, $dir) ||
  1511. return 0; # can't open dir
  1512. while($file = readdir(DIR)) {
  1513. if($file !~ /^\./) {
  1514. unlink("$dir/$file");
  1515. $count++;
  1516. }
  1517. }
  1518. closedir DIR;
  1519. return $count;
  1520. }
  1521. #######################################################################
  1522. # filter out the specified pattern from the given input file and store the
  1523. # results in the given output file
  1524. #
  1525. sub filteroff {
  1526. my $infile=$_[0];
  1527. my $filter=$_[1];
  1528. my $ofile=$_[2];
  1529. open(IN, "<$infile")
  1530. || return 1;
  1531. open(OUT, ">$ofile")
  1532. || return 1;
  1533. # logmsg "FILTER: off $filter from $infile to $ofile\n";
  1534. while(<IN>) {
  1535. $_ =~ s/$filter//;
  1536. print OUT $_;
  1537. }
  1538. close(IN);
  1539. close(OUT);
  1540. return 0;
  1541. }
  1542. #######################################################################
  1543. # compare test results with the expected output, we might filter off
  1544. # some pattern that is allowed to differ, output test results
  1545. #
  1546. sub compare {
  1547. # filter off patterns _before_ this comparison!
  1548. my ($subject, $firstref, $secondref)=@_;
  1549. my $result = compareparts($firstref, $secondref);
  1550. if($result) {
  1551. if(!$short) {
  1552. logmsg "\n $subject FAILED:\n";
  1553. logmsg showdiff($LOGDIR, $firstref, $secondref);
  1554. }
  1555. else {
  1556. logmsg "FAILED\n";
  1557. }
  1558. }
  1559. return $result;
  1560. }
  1561. #######################################################################
  1562. # display information about curl and the host the test suite runs on
  1563. #
  1564. sub checksystem {
  1565. unlink($memdump); # remove this if there was one left
  1566. my $feat;
  1567. my $curl;
  1568. my $libcurl;
  1569. my $versretval;
  1570. my $versnoexec;
  1571. my @version=();
  1572. my $curlverout="$LOGDIR/curlverout.log";
  1573. my $curlvererr="$LOGDIR/curlvererr.log";
  1574. my $versioncmd="$CURL --version 1>$curlverout 2>$curlvererr";
  1575. unlink($curlverout);
  1576. unlink($curlvererr);
  1577. $versretval = runclient($versioncmd);
  1578. $versnoexec = $!;
  1579. open(VERSOUT, "<$curlverout");
  1580. @version = <VERSOUT>;
  1581. close(VERSOUT);
  1582. for(@version) {
  1583. chomp;
  1584. if($_ =~ /^curl/) {
  1585. $curl = $_;
  1586. $curl =~ s/^(.*)(libcurl.*)/$1/g;
  1587. $libcurl = $2;
  1588. if($curl =~ /mingw32/) {
  1589. # This is a windows minw32 build, we need to translate the
  1590. # given path to the "actual" windows path.
  1591. my @m = `mount`;
  1592. my $matchlen;
  1593. my $bestmatch;
  1594. my $mount;
  1595. # example mount output:
  1596. # C:\DOCUME~1\Temp on /tmp type user (binmode,noumount)
  1597. # c:\ActiveState\perl on /perl type user (binmode)
  1598. # C:\msys\1.0\bin on /usr/bin type user (binmode,cygexec,noumount)
  1599. # C:\msys\1.0\bin on /bin type user (binmode,cygexec,noumount)
  1600. foreach $mount (@m) {
  1601. if( $mount =~ /(.*) on ([^ ]*) type /) {
  1602. my ($mingw, $real)=($2, $1);
  1603. if($pwd =~ /^$mingw/) {
  1604. # the path we got from pwd starts with the path
  1605. # we found on this line in the mount output
  1606. my $len = length($real);
  1607. if($len > $matchlen) {
  1608. # we remember the match that is the longest
  1609. $matchlen = $len;
  1610. $bestmatch = $real;
  1611. }
  1612. }
  1613. }
  1614. }
  1615. if(!$matchlen) {
  1616. logmsg "Serious error, can't find our \"real\" path\n";
  1617. }
  1618. else {
  1619. # now prepend the prefix from the mount command to build
  1620. # our "actual path"
  1621. $pwd = "$bestmatch$pwd";
  1622. }
  1623. $pwd =~ s#\\#/#g;
  1624. }
  1625. elsif ($curl =~ /win32/) {
  1626. # Native Windows builds don't understand the
  1627. # output of cygwin's pwd. It will be
  1628. # something like /cygdrive/c/<some path>.
  1629. #
  1630. # Use the cygpath utility to convert the
  1631. # working directory to a Windows friendly
  1632. # path. The -m option converts to use drive
  1633. # letter:, but it uses / instead \. Forward
  1634. # slashes (/) are easier for us. We don't
  1635. # have to escape them to get them to curl
  1636. # through a shell.
  1637. chomp($pwd = `cygpath -m $pwd`);
  1638. }
  1639. elsif ($libcurl =~ /openssl/i) {
  1640. $has_openssl=1;
  1641. $ssllib="OpenSSL";
  1642. }
  1643. elsif ($libcurl =~ /gnutls/i) {
  1644. $has_gnutls=1;
  1645. $ssllib="GnuTLS";
  1646. }
  1647. elsif ($libcurl =~ /nss/i) {
  1648. $has_nss=1;
  1649. $ssllib="NSS";
  1650. }
  1651. elsif ($libcurl =~ /yassl/i) {
  1652. $has_yassl=1;
  1653. $has_openssl=1;
  1654. $ssllib="yassl";
  1655. }
  1656. elsif ($libcurl =~ /polarssl/i) {
  1657. $has_polarssl=1;
  1658. $has_openssl=1;
  1659. $ssllib="polarssl";
  1660. }
  1661. elsif ($libcurl =~ /axtls/i) {
  1662. $has_axtls=1;
  1663. $ssllib="axTLS";
  1664. }
  1665. }
  1666. elsif($_ =~ /^Protocols: (.*)/i) {
  1667. # these are the protocols compiled in to this libcurl
  1668. @protocols = split(' ', $1);
  1669. # Generate a "proto-ipv6" version of each protocol to match the
  1670. # IPv6 <server> name. This works even if IPv6 support isn't
  1671. # compiled in because the <features> test will fail.
  1672. push @protocols, map($_ . "-ipv6", @protocols);
  1673. # 'none' is used in test cases to mean no server
  1674. push @protocols, ('none');
  1675. }
  1676. elsif($_ =~ /^Features: (.*)/i) {
  1677. $feat = $1;
  1678. if($feat =~ /TrackMemory/i) {
  1679. # curl was built with --enable-curldebug (memory tracking)
  1680. $curl_debug = 1;
  1681. }
  1682. if($feat =~ /debug/i) {
  1683. # curl was built with --enable-debug
  1684. $debug_build = 1;
  1685. # set the NETRC debug env
  1686. $ENV{'CURL_DEBUG_NETRC'} = "$LOGDIR/netrc";
  1687. }
  1688. if($feat =~ /SSL/i) {
  1689. # ssl enabled
  1690. $ssl_version=1;
  1691. }
  1692. if($feat =~ /Largefile/i) {
  1693. # large file support
  1694. $large_file=1;
  1695. }
  1696. if($feat =~ /IDN/i) {
  1697. # IDN support
  1698. $has_idn=1;
  1699. }
  1700. if($feat =~ /IPv6/i) {
  1701. $has_ipv6 = 1;
  1702. }
  1703. if($feat =~ /libz/i) {
  1704. $has_libz = 1;
  1705. }
  1706. if($feat =~ /NTLM/i) {
  1707. # NTLM enabled
  1708. $has_ntlm=1;
  1709. }
  1710. if($feat =~ /CharConv/i) {
  1711. # CharConv enabled
  1712. $has_charconv=1;
  1713. }
  1714. }
  1715. }
  1716. if(!$curl) {
  1717. logmsg "unable to get curl's version, further details are:\n";
  1718. logmsg "issued command: \n";
  1719. logmsg "$versioncmd \n";
  1720. if ($versretval == -1) {
  1721. logmsg "command failed with: \n";
  1722. logmsg "$versnoexec \n";
  1723. }
  1724. elsif ($versretval & 127) {
  1725. logmsg sprintf("command died with signal %d, and %s coredump.\n",
  1726. ($versretval & 127), ($versretval & 128)?"a":"no");
  1727. }
  1728. else {
  1729. logmsg sprintf("command exited with value %d \n", $versretval >> 8);
  1730. }
  1731. logmsg "contents of $curlverout: \n";
  1732. displaylogcontent("$curlverout");
  1733. logmsg "contents of $curlvererr: \n";
  1734. displaylogcontent("$curlvererr");
  1735. die "couldn't get curl's version";
  1736. }
  1737. if(-r "../lib/curl_config.h") {
  1738. open(CONF, "<../lib/curl_config.h");
  1739. while(<CONF>) {
  1740. if($_ =~ /^\#define HAVE_GETRLIMIT/) {
  1741. $has_getrlimit = 1;
  1742. }
  1743. }
  1744. close(CONF);
  1745. }
  1746. if($has_ipv6) {
  1747. # client has ipv6 support
  1748. # check if the HTTP server has it!
  1749. my @sws = `server/sws --version`;
  1750. if($sws[0] =~ /IPv6/) {
  1751. # HTTP server has ipv6 support!
  1752. $http_ipv6 = 1;
  1753. $gopher_ipv6 = 1;
  1754. }
  1755. # check if the FTP server has it!
  1756. @sws = `server/sockfilt --version`;
  1757. if($sws[0] =~ /IPv6/) {
  1758. # FTP server has ipv6 support!
  1759. $ftp_ipv6 = 1;
  1760. }
  1761. }
  1762. if(!$curl_debug && $torture) {
  1763. die "can't run torture tests since curl was not built with curldebug";
  1764. }
  1765. $has_shared = `sh $CURLCONFIG --built-shared`;
  1766. chomp $has_shared;
  1767. # curl doesn't list cryptographic support separately, so assume it's
  1768. # always available
  1769. $has_crypto=1;
  1770. my $hostname=join(' ', runclientoutput("hostname"));
  1771. my $hosttype=join(' ', runclientoutput("uname -a"));
  1772. logmsg ("********* System characteristics ******** \n",
  1773. "* $curl\n",
  1774. "* $libcurl\n",
  1775. "* Features: $feat\n",
  1776. "* Host: $hostname",
  1777. "* System: $hosttype");
  1778. logmsg sprintf("* Server SSL: %8s", $stunnel?"ON ":"OFF");
  1779. logmsg sprintf(" libcurl SSL: %s\n", $ssl_version?"ON ":"OFF");
  1780. logmsg sprintf("* debug build: %8s", $debug_build?"ON ":"OFF");
  1781. logmsg sprintf(" track memory: %s\n", $curl_debug?"ON ":"OFF");
  1782. logmsg sprintf("* valgrind: %8s", $valgrind?"ON ":"OFF");
  1783. logmsg sprintf(" HTTP IPv6 %s\n", $http_ipv6?"ON ":"OFF");
  1784. logmsg sprintf("* FTP IPv6 %8s", $ftp_ipv6?"ON ":"OFF");
  1785. logmsg sprintf(" Libtool lib: %s\n", $libtool?"ON ":"OFF");
  1786. logmsg sprintf("* Shared build: %s\n", $has_shared);
  1787. if($ssl_version) {
  1788. logmsg sprintf("* SSL library: %13s\n", $ssllib);
  1789. }
  1790. logmsg "* Ports:\n";
  1791. logmsg sprintf("* HTTP/%d ", $HTTPPORT);
  1792. logmsg sprintf("FTP/%d ", $FTPPORT);
  1793. logmsg sprintf("FTP2/%d ", $FTP2PORT);
  1794. logmsg sprintf("RTSP/%d ", $RTSPPORT);
  1795. if($stunnel) {
  1796. logmsg sprintf("FTPS/%d ", $FTPSPORT);
  1797. logmsg sprintf("HTTPS/%d ", $HTTPSPORT);
  1798. }
  1799. logmsg sprintf("\n* TFTP/%d ", $TFTPPORT);
  1800. if($http_ipv6) {
  1801. logmsg sprintf("HTTP-IPv6/%d ", $HTTP6PORT);
  1802. logmsg sprintf("RTSP-IPv6/%d ", $RTSP6PORT);
  1803. }
  1804. if($ftp_ipv6) {
  1805. logmsg sprintf("FTP-IPv6/%d ", $FTP6PORT);
  1806. }
  1807. if($tftp_ipv6) {
  1808. logmsg sprintf("TFTP-IPv6/%d ", $TFTP6PORT);
  1809. }
  1810. logmsg sprintf("\n* GOPHER/%d ", $GOPHERPORT);
  1811. if($gopher_ipv6) {
  1812. logmsg sprintf("GOPHER-IPv6/%d", $GOPHERPORT);
  1813. }
  1814. logmsg sprintf("\n* SSH/%d ", $SSHPORT);
  1815. logmsg sprintf("SOCKS/%d ", $SOCKSPORT);
  1816. logmsg sprintf("POP3/%d ", $POP3PORT);
  1817. logmsg sprintf("IMAP/%d ", $IMAPPORT);
  1818. logmsg sprintf("SMTP/%d\n", $SMTPPORT);
  1819. if($ftp_ipv6) {
  1820. logmsg sprintf("* POP3-IPv6/%d ", $POP36PORT);
  1821. logmsg sprintf("IMAP-IPv6/%d ", $IMAP6PORT);
  1822. logmsg sprintf("SMTP-IPv6/%d\n", $SMTP6PORT);
  1823. }
  1824. $has_textaware = ($^O eq 'MSWin32') || ($^O eq 'msys');
  1825. logmsg "***************************************** \n";
  1826. }
  1827. #######################################################################
  1828. # substitute the variable stuff into either a joined up file or
  1829. # a command, in either case passed by reference
  1830. #
  1831. sub subVariables {
  1832. my ($thing) = @_;
  1833. $$thing =~ s/%HOSTIP/$HOSTIP/g;
  1834. $$thing =~ s/%HTTPPORT/$HTTPPORT/g;
  1835. $$thing =~ s/%HOST6IP/$HOST6IP/g;
  1836. $$thing =~ s/%HTTP6PORT/$HTTP6PORT/g;
  1837. $$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
  1838. $$thing =~ s/%FTPPORT/$FTPPORT/g;
  1839. $$thing =~ s/%FTP6PORT/$FTP6PORT/g;
  1840. $$thing =~ s/%FTP2PORT/$FTP2PORT/g;
  1841. $$thing =~ s/%FTPSPORT/$FTPSPORT/g;
  1842. $$thing =~ s/%SRCDIR/$srcdir/g;
  1843. $$thing =~ s/%PWD/$pwd/g;
  1844. $$thing =~ s/%TFTPPORT/$TFTPPORT/g;
  1845. $$thing =~ s/%TFTP6PORT/$TFTP6PORT/g;
  1846. $$thing =~ s/%SSHPORT/$SSHPORT/g;
  1847. $$thing =~ s/%SOCKSPORT/$SOCKSPORT/g;
  1848. $$thing =~ s/%POP3PORT/$POP3PORT/g;
  1849. $$thing =~ s/%POP36PORT/$POP36PORT/g;
  1850. $$thing =~ s/%IMAPPORT/$IMAPPORT/g;
  1851. $$thing =~ s/%IMAP6PORT/$IMAP6PORT/g;
  1852. $$thing =~ s/%SMTPPORT/$SMTPPORT/g;
  1853. $$thing =~ s/%SMTP6PORT/$SMTP6PORT/g;
  1854. $$thing =~ s/%CURL/$CURL/g;
  1855. $$thing =~ s/%USER/$USER/g;
  1856. $$thing =~ s/%CLIENTIP/$CLIENTIP/g;
  1857. $$thing =~ s/%CLIENT6IP/$CLIENT6IP/g;
  1858. $$thing =~ s/%RTSPPORT/$RTSPPORT/g;
  1859. $$thing =~ s/%RTSP6PORT/$RTSP6PORT/g;
  1860. $$thing =~ s/%GOPHERPORT/$GOPHERPORT/g;
  1861. $$thing =~ s/%GOPHER6PORT/$GOPHER6PORT/g;
  1862. # The purpose of FTPTIME2 and FTPTIME3 is to provide times that can be
  1863. # used for time-out tests and that whould work on most hosts as these
  1864. # adjust for the startup/check time for this particular host. We needed
  1865. # to do this to make the test suite run better on very slow hosts.
  1866. my $ftp2 = $ftpchecktime * 2;
  1867. my $ftp3 = $ftpchecktime * 3;
  1868. $$thing =~ s/%FTPTIME2/$ftp2/g;
  1869. $$thing =~ s/%FTPTIME3/$ftp3/g;
  1870. }
  1871. sub fixarray {
  1872. my @in = @_;
  1873. for(@in) {
  1874. subVariables \$_;
  1875. }
  1876. return @in;
  1877. }
  1878. #######################################################################
  1879. # Provide time stamps for single test skipped events
  1880. #
  1881. sub timestampskippedevents {
  1882. my $testnum = $_[0];
  1883. return if((not defined($testnum)) || ($testnum < 1));
  1884. if($timestats) {
  1885. if($timevrfyend{$testnum}) {
  1886. return;
  1887. }
  1888. elsif($timesrvrlog{$testnum}) {
  1889. $timevrfyend{$testnum} = $timesrvrlog{$testnum};
  1890. return;
  1891. }
  1892. elsif($timetoolend{$testnum}) {
  1893. $timevrfyend{$testnum} = $timetoolend{$testnum};
  1894. $timesrvrlog{$testnum} = $timetoolend{$testnum};
  1895. }
  1896. elsif($timetoolini{$testnum}) {
  1897. $timevrfyend{$testnum} = $timetoolini{$testnum};
  1898. $timesrvrlog{$testnum} = $timetoolini{$testnum};
  1899. $timetoolend{$testnum} = $timetoolini{$testnum};
  1900. }
  1901. elsif($timesrvrend{$testnum}) {
  1902. $timevrfyend{$testnum} = $timesrvrend{$testnum};
  1903. $timesrvrlog{$testnum} = $timesrvrend{$testnum};
  1904. $timetoolend{$testnum} = $timesrvrend{$testnum};
  1905. $timetoolini{$testnum} = $timesrvrend{$testnum};
  1906. }
  1907. elsif($timesrvrini{$testnum}) {
  1908. $timevrfyend{$testnum} = $timesrvrini{$testnum};
  1909. $timesrvrlog{$testnum} = $timesrvrini{$testnum};
  1910. $timetoolend{$testnum} = $timesrvrini{$testnum};
  1911. $timetoolini{$testnum} = $timesrvrini{$testnum};
  1912. $timesrvrend{$testnum} = $timesrvrini{$testnum};
  1913. }
  1914. elsif($timeprepini{$testnum}) {
  1915. $timevrfyend{$testnum} = $timeprepini{$testnum};
  1916. $timesrvrlog{$testnum} = $timeprepini{$testnum};
  1917. $timetoolend{$testnum} = $timeprepini{$testnum};
  1918. $timetoolini{$testnum} = $timeprepini{$testnum};
  1919. $timesrvrend{$testnum} = $timeprepini{$testnum};
  1920. $timesrvrini{$testnum} = $timeprepini{$testnum};
  1921. }
  1922. }
  1923. }
  1924. #######################################################################
  1925. # Run a single specified test case
  1926. #
  1927. sub singletest {
  1928. my ($testnum, $count, $total)=@_;
  1929. my @what;
  1930. my $why;
  1931. my %feature;
  1932. my $cmd;
  1933. my $disablevalgrind;
  1934. # copy test number to a global scope var, this allows
  1935. # testnum checking when starting test harness servers.
  1936. $testnumcheck = $testnum;
  1937. # timestamp test preparation start
  1938. $timeprepini{$testnum} = Time::HiRes::time() if($timestats);
  1939. if($disttests !~ /test$testnum\W/ ) {
  1940. logmsg "Warning: test$testnum not present in tests/data/Makefile.am\n";
  1941. }
  1942. # load the test case file definition
  1943. if(loadtest("${TESTDIR}/test${testnum}")) {
  1944. if($verbose) {
  1945. # this is not a test
  1946. logmsg "RUN: $testnum doesn't look like a test case\n";
  1947. }
  1948. $why = "no test";
  1949. }
  1950. else {
  1951. @what = getpart("client", "features");
  1952. }
  1953. for(@what) {
  1954. my $f = $_;
  1955. $f =~ s/\s//g;
  1956. $feature{$f}=$f; # we require this feature
  1957. if($f eq "SSL") {
  1958. if($ssl_version) {
  1959. next;
  1960. }
  1961. }
  1962. elsif($f eq "OpenSSL") {
  1963. if($has_openssl) {
  1964. next;
  1965. }
  1966. }
  1967. elsif($f eq "GnuTLS") {
  1968. if($has_gnutls) {
  1969. next;
  1970. }
  1971. }
  1972. elsif($f eq "NSS") {
  1973. if($has_nss) {
  1974. next;
  1975. }
  1976. }
  1977. elsif($f eq "axTLS") {
  1978. if($has_axtls) {
  1979. next;
  1980. }
  1981. }
  1982. elsif($f eq "netrc_debug") {
  1983. if($debug_build) {
  1984. next;
  1985. }
  1986. }
  1987. elsif($f eq "large_file") {
  1988. if($large_file) {
  1989. next;
  1990. }
  1991. }
  1992. elsif($f eq "idn") {
  1993. if($has_idn) {
  1994. next;
  1995. }
  1996. }
  1997. elsif($f eq "ipv6") {
  1998. if($has_ipv6) {
  1999. next;
  2000. }
  2001. }
  2002. elsif($f eq "libz") {
  2003. if($has_libz) {
  2004. next;
  2005. }
  2006. }
  2007. elsif($f eq "NTLM") {
  2008. if($has_ntlm) {
  2009. next;
  2010. }
  2011. }
  2012. elsif($f eq "getrlimit") {
  2013. if($has_getrlimit) {
  2014. next;
  2015. }
  2016. }
  2017. elsif($f eq "crypto") {
  2018. if($has_crypto) {
  2019. next;
  2020. }
  2021. }
  2022. elsif($f eq "socks") {
  2023. next;
  2024. }
  2025. # See if this "feature" is in the list of supported protocols
  2026. elsif (grep /^$f$/, @protocols) {
  2027. next;
  2028. }
  2029. $why = "curl lacks $f support";
  2030. last;
  2031. }
  2032. if(!$why) {
  2033. my @keywords = getpart("info", "keywords");
  2034. my $match;
  2035. my $k;
  2036. for $k (@keywords) {
  2037. chomp $k;
  2038. if ($disabled_keywords{$k}) {
  2039. $why = "disabled by keyword";
  2040. } elsif ($enabled_keywords{$k}) {
  2041. $match = 1;
  2042. }
  2043. }
  2044. if(!$why && !$match && %enabled_keywords) {
  2045. $why = "disabled by missing keyword";
  2046. }
  2047. }
  2048. # test definition may instruct to (un)set environment vars
  2049. # this is done this early, so that the precheck can use environment
  2050. # variables and still bail out fine on errors
  2051. # restore environment variables that were modified in a previous run
  2052. foreach my $var (keys %oldenv) {
  2053. if($oldenv{$var} eq 'notset') {
  2054. delete $ENV{$var} if($ENV{$var});
  2055. }
  2056. else {
  2057. $ENV{$var} = $oldenv{$var};
  2058. }
  2059. delete $oldenv{$var};
  2060. }
  2061. # timestamp required servers verification start
  2062. $timesrvrini{$testnum} = Time::HiRes::time() if($timestats);
  2063. if(!$why) {
  2064. $why = serverfortest($testnum);
  2065. }
  2066. # timestamp required servers verification end
  2067. $timesrvrend{$testnum} = Time::HiRes::time() if($timestats);
  2068. my @setenv = getpart("client", "setenv");
  2069. if(@setenv) {
  2070. foreach my $s (@setenv) {
  2071. chomp $s;
  2072. subVariables \$s;
  2073. if($s =~ /([^=]*)=(.*)/) {
  2074. my ($var, $content) = ($1, $2);
  2075. # remember current setting, to restore it once test runs
  2076. $oldenv{$var} = ($ENV{$var})?"$ENV{$var}":'notset';
  2077. # set new value
  2078. if(!$content) {
  2079. delete $ENV{$var} if($ENV{$var});
  2080. }
  2081. else {
  2082. if(($var =~ /^LD_PRELOAD/) &&
  2083. ($debug_build || ($has_shared ne "yes"))) {
  2084. # print "Skipping LD_PRELOAD due to no release shared build\n";
  2085. next;
  2086. }
  2087. $ENV{$var} = "$content";
  2088. }
  2089. }
  2090. }
  2091. }
  2092. if(!$why) {
  2093. # TODO:
  2094. # Add a precheck cache. If a precheck command was already invoked
  2095. # exactly like this, then use the previous result to speed up
  2096. # successive test invokes!
  2097. my @precheck = getpart("client", "precheck");
  2098. if(@precheck) {
  2099. $cmd = $precheck[0];
  2100. chomp $cmd;
  2101. subVariables \$cmd;
  2102. if($cmd) {
  2103. my @p = split(/ /, $cmd);
  2104. if($p[0] !~ /\//) {
  2105. # the first word, the command, does not contain a slash so
  2106. # we will scan the "improved" PATH to find the command to
  2107. # be able to run it
  2108. my $fullp = checktestcmd($p[0]);
  2109. if($fullp) {
  2110. $p[0] = $fullp;
  2111. }
  2112. $cmd = join(" ", @p);
  2113. }
  2114. my @o = `$cmd 2>/dev/null`;
  2115. if($o[0]) {
  2116. $why = $o[0];
  2117. chomp $why;
  2118. } elsif($?) {
  2119. $why = "precheck command error";
  2120. }
  2121. logmsg "prechecked $cmd\n" if($verbose);
  2122. }
  2123. }
  2124. }
  2125. if($why && !$listonly) {
  2126. # there's a problem, count it as "skipped"
  2127. $skipped++;
  2128. $skipped{$why}++;
  2129. $teststat[$testnum]=$why; # store reason for this test case
  2130. if(!$short) {
  2131. printf "test %03d SKIPPED: $why\n", $testnum;
  2132. }
  2133. timestampskippedevents($testnum);
  2134. return -1;
  2135. }
  2136. logmsg sprintf("test %03d...", $testnum);
  2137. # extract the reply data
  2138. my @reply = getpart("reply", "data");
  2139. my @replycheck = getpart("reply", "datacheck");
  2140. if (@replycheck) {
  2141. # we use this file instead to check the final output against
  2142. my %hash = getpartattr("reply", "datacheck");
  2143. if($hash{'nonewline'}) {
  2144. # Yes, we must cut off the final newline from the final line
  2145. # of the datacheck
  2146. chomp($replycheck[$#replycheck]);
  2147. }
  2148. @reply=@replycheck;
  2149. }
  2150. # this is the valid protocol blurb curl should generate
  2151. my @protocol= fixarray ( getpart("verify", "protocol") );
  2152. # redirected stdout/stderr to these files
  2153. $STDOUT="$LOGDIR/stdout$testnum";
  2154. $STDERR="$LOGDIR/stderr$testnum";
  2155. # if this section exists, we verify that the stdout contained this:
  2156. my @validstdout = fixarray ( getpart("verify", "stdout") );
  2157. # if this section exists, we verify upload
  2158. my @upload = getpart("verify", "upload");
  2159. # if this section exists, it might be FTP server instructions:
  2160. my @ftpservercmd = getpart("reply", "servercmd");
  2161. my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout
  2162. # name of the test
  2163. my @testname= getpart("client", "name");
  2164. if(!$short) {
  2165. my $name = $testname[0];
  2166. $name =~ s/\n//g;
  2167. logmsg "[$name]\n";
  2168. }
  2169. if($listonly) {
  2170. timestampskippedevents($testnum);
  2171. return 0; # look successful
  2172. }
  2173. my @codepieces = getpart("client", "tool");
  2174. my $tool="";
  2175. if(@codepieces) {
  2176. $tool = $codepieces[0];
  2177. chomp $tool;
  2178. }
  2179. # remove server output logfiles
  2180. unlink($SERVERIN);
  2181. unlink($SERVER2IN);
  2182. if(@ftpservercmd) {
  2183. # write the instructions to file
  2184. writearray($FTPDCMD, \@ftpservercmd);
  2185. }
  2186. # get the command line options to use
  2187. my @blaha;
  2188. ($cmd, @blaha)= getpart("client", "command");
  2189. if($cmd) {
  2190. # make some nice replace operations
  2191. $cmd =~ s/\n//g; # no newlines please
  2192. # substitute variables in the command line
  2193. subVariables \$cmd;
  2194. }
  2195. if($curl_debug) {
  2196. unlink($memdump);
  2197. }
  2198. # create a (possibly-empty) file before starting the test
  2199. my @inputfile=getpart("client", "file");
  2200. my %fileattr = getpartattr("client", "file");
  2201. my $filename=$fileattr{'name'};
  2202. if(@inputfile || $filename) {
  2203. if(!$filename) {
  2204. logmsg "ERROR: section client=>file has no name attribute\n";
  2205. timestampskippedevents($testnum);
  2206. return -1;
  2207. }
  2208. my $fileContent = join('', @inputfile);
  2209. subVariables \$fileContent;
  2210. # logmsg "DEBUG: writing file " . $filename . "\n";
  2211. open(OUTFILE, ">$filename");
  2212. binmode OUTFILE; # for crapage systems, use binary
  2213. print OUTFILE $fileContent;
  2214. close(OUTFILE);
  2215. }
  2216. my %cmdhash = getpartattr("client", "command");
  2217. my $out="";
  2218. if((!$cmdhash{'option'}) || ($cmdhash{'option'} !~ /no-output/)) {
  2219. #We may slap on --output!
  2220. if (!@validstdout) {
  2221. $out=" --output $CURLOUT ";
  2222. }
  2223. }
  2224. my $serverlogslocktimeout = $defserverlogslocktimeout;
  2225. if($cmdhash{'timeout'}) {
  2226. # test is allowed to override default server logs lock timeout
  2227. if($cmdhash{'timeout'} =~ /(\d+)/) {
  2228. $serverlogslocktimeout = $1 if($1 >= 0);
  2229. }
  2230. }
  2231. my $postcommanddelay = $defpostcommanddelay;
  2232. if($cmdhash{'delay'}) {
  2233. # test is allowed to specify a delay after command is executed
  2234. if($cmdhash{'delay'} =~ /(\d+)/) {
  2235. $postcommanddelay = $1 if($1 > 0);
  2236. }
  2237. }
  2238. my $CMDLINE;
  2239. my $cmdargs;
  2240. my $cmdtype = $cmdhash{'type'} || "default";
  2241. if($cmdtype eq "perl") {
  2242. # run the command line prepended with "perl"
  2243. $cmdargs ="$cmd";
  2244. $CMDLINE = "perl ";
  2245. $tool=$CMDLINE;
  2246. $disablevalgrind=1;
  2247. }
  2248. elsif(!$tool) {
  2249. # run curl, add --verbose for debug information output
  2250. $cmd = "-1 ".$cmd if(exists $feature{"SSL"} && ($has_axtls));
  2251. $cmdargs ="$out --include --verbose --trace-time $cmd";
  2252. }
  2253. else {
  2254. $cmdargs = " $cmd"; # $cmd is the command line for the test file
  2255. $CURLOUT = $STDOUT; # sends received data to stdout
  2256. $CMDLINE="$LIBDIR/$tool";
  2257. if(! -f $CMDLINE) {
  2258. print "The tool set in the test case for this: '$tool' does not exist\n";
  2259. timestampskippedevents($testnum);
  2260. return -1;
  2261. }
  2262. $DBGCURL=$CMDLINE;
  2263. }
  2264. my @stdintest = getpart("client", "stdin");
  2265. if(@stdintest) {
  2266. my $stdinfile="$LOGDIR/stdin-for-$testnum";
  2267. writearray($stdinfile, \@stdintest);
  2268. $cmdargs .= " <$stdinfile";
  2269. }
  2270. if(!$tool) {
  2271. $CMDLINE="$CURL";
  2272. }
  2273. my $usevalgrind;
  2274. if($valgrind && !$disablevalgrind) {
  2275. my @valgrindoption = getpart("verify", "valgrind");
  2276. if((!@valgrindoption) || ($valgrindoption[0] !~ /disable/)) {
  2277. $usevalgrind = 1;
  2278. my $valgrindcmd = "$valgrind ";
  2279. $valgrindcmd .= "$valgrind_tool " if($valgrind_tool);
  2280. $valgrindcmd .= "--leak-check=yes ";
  2281. $valgrindcmd .= "--num-callers=16 ";
  2282. $valgrindcmd .= "${valgrind_logfile}=$LOGDIR/valgrind$testnum";
  2283. $CMDLINE = "$valgrindcmd $CMDLINE";
  2284. }
  2285. }
  2286. $CMDLINE .= "$cmdargs >$STDOUT 2>$STDERR";
  2287. if($verbose) {
  2288. logmsg "$CMDLINE\n";
  2289. }
  2290. print CMDLOG "$CMDLINE\n";
  2291. unlink("core");
  2292. my $dumped_core;
  2293. my $cmdres;
  2294. # Apr 2007: precommand isn't being used and could be removed
  2295. my @precommand= getpart("client", "precommand");
  2296. if($precommand[0]) {
  2297. # this is pure perl to eval!
  2298. my $code = join("", @precommand);
  2299. eval $code;
  2300. if($@) {
  2301. logmsg "perl: $code\n";
  2302. logmsg "precommand: $@";
  2303. stopservers($verbose);
  2304. timestampskippedevents($testnum);
  2305. return -1;
  2306. }
  2307. }
  2308. if($gdbthis) {
  2309. my $gdbinit = "$TESTDIR/gdbinit$testnum";
  2310. open(GDBCMD, ">$LOGDIR/gdbcmd");
  2311. print GDBCMD "set args $cmdargs\n";
  2312. print GDBCMD "show args\n";
  2313. print GDBCMD "source $gdbinit\n" if -e $gdbinit;
  2314. close(GDBCMD);
  2315. }
  2316. # timestamp starting of test command
  2317. $timetoolini{$testnum} = Time::HiRes::time() if($timestats);
  2318. # run the command line we built
  2319. if ($torture) {
  2320. $cmdres = torture($CMDLINE,
  2321. "$gdb --directory libtest $DBGCURL -x $LOGDIR/gdbcmd");
  2322. }
  2323. elsif($gdbthis) {
  2324. runclient("$gdb --directory libtest $DBGCURL -x $LOGDIR/gdbcmd");
  2325. $cmdres=0; # makes it always continue after a debugged run
  2326. }
  2327. else {
  2328. $cmdres = runclient("$CMDLINE");
  2329. my $signal_num = $cmdres & 127;
  2330. $dumped_core = $cmdres & 128;
  2331. if(!$anyway && ($signal_num || $dumped_core)) {
  2332. $cmdres = 1000;
  2333. }
  2334. else {
  2335. $cmdres >>= 8;
  2336. $cmdres = (2000 + $signal_num) if($signal_num && !$cmdres);
  2337. }
  2338. }
  2339. # timestamp finishing of test command
  2340. $timetoolend{$testnum} = Time::HiRes::time() if($timestats);
  2341. if(!$dumped_core) {
  2342. if(-r "core") {
  2343. # there's core file present now!
  2344. $dumped_core = 1;
  2345. }
  2346. }
  2347. if($dumped_core) {
  2348. logmsg "core dumped\n";
  2349. if(0 && $gdb) {
  2350. logmsg "running gdb for post-mortem analysis:\n";
  2351. open(GDBCMD, ">$LOGDIR/gdbcmd2");
  2352. print GDBCMD "bt\n";
  2353. close(GDBCMD);
  2354. runclient("$gdb --directory libtest -x $LOGDIR/gdbcmd2 -batch $DBGCURL core ");
  2355. # unlink("$LOGDIR/gdbcmd2");
  2356. }
  2357. }
  2358. # If a server logs advisor read lock file exists, it is an indication
  2359. # that the server has not yet finished writing out all its log files,
  2360. # including server request log files used for protocol verification.
  2361. # So, if the lock file exists the script waits here a certain amount
  2362. # of time until the server removes it, or the given time expires.
  2363. if($serverlogslocktimeout) {
  2364. my $lockretry = $serverlogslocktimeout * 20;
  2365. while((-f $SERVERLOGS_LOCK) && $lockretry--) {
  2366. select(undef, undef, undef, 0.05);
  2367. }
  2368. if(($lockretry < 0) &&
  2369. ($serverlogslocktimeout >= $defserverlogslocktimeout)) {
  2370. logmsg "Warning: server logs lock timeout ",
  2371. "($serverlogslocktimeout seconds) expired\n";
  2372. }
  2373. }
  2374. # Test harness ssh server does not have this synchronization mechanism,
  2375. # this implies that some ssh server based tests might need a small delay
  2376. # once that the client command has run to avoid false test failures.
  2377. sleep($postcommanddelay) if($postcommanddelay);
  2378. # timestamp removal of server logs advisor read lock
  2379. $timesrvrlog{$testnum} = Time::HiRes::time() if($timestats);
  2380. # test definition might instruct to stop some servers
  2381. # stop also all servers relative to the given one
  2382. my @killtestservers = getpart("client", "killserver");
  2383. if(@killtestservers) {
  2384. #
  2385. # All servers relative to the given one must be stopped also
  2386. #
  2387. my @killservers;
  2388. foreach my $server (@killtestservers) {
  2389. chomp $server;
  2390. if($server =~ /^(ftp|http|imap|pop3|smtp)s(.*)$/) {
  2391. # given an ssl server, also kill non-ssl underlying one
  2392. push @killservers, "${1}${2}";
  2393. }
  2394. elsif($server =~ /^(ftp|http|imap|pop3|smtp)(.*)$/) {
  2395. # given a non-ssl server, also kill ssl piggybacking one
  2396. push @killservers, "${1}s${2}";
  2397. }
  2398. elsif($server =~ /^(socks)(.*)$/) {
  2399. # given an socks server, also kill ssh underlying one
  2400. push @killservers, "ssh${2}";
  2401. }
  2402. elsif($server =~ /^(ssh)(.*)$/) {
  2403. # given an ssh server, also kill socks piggybacking one
  2404. push @killservers, "socks${2}";
  2405. }
  2406. push @killservers, $server;
  2407. }
  2408. #
  2409. # kill sockfilter processes for pingpong relative servers
  2410. #
  2411. foreach my $server (@killservers) {
  2412. if($server =~ /^(ftp|imap|pop3|smtp)s?(\d*)(-ipv6|)$/) {
  2413. my $proto = $1;
  2414. my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
  2415. my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
  2416. killsockfilters($proto, $ipvnum, $idnum, $verbose);
  2417. }
  2418. }
  2419. #
  2420. # kill server relative pids clearing them in %run hash
  2421. #
  2422. my $pidlist;
  2423. foreach my $server (@killservers) {
  2424. if($run{$server}) {
  2425. $pidlist .= "$run{$server} ";
  2426. $run{$server} = 0;
  2427. }
  2428. $runcert{$server} = 0 if($runcert{$server});
  2429. }
  2430. killpid($verbose, $pidlist);
  2431. #
  2432. # cleanup server pid files
  2433. #
  2434. foreach my $server (@killservers) {
  2435. my $pidfile = $serverpidfile{$server};
  2436. my $pid = processexists($pidfile);
  2437. if($pid > 0) {
  2438. logmsg "Warning: $server server unexpectedly alive\n";
  2439. killpid($verbose, $pid);
  2440. }
  2441. unlink($pidfile) if(-f $pidfile);
  2442. }
  2443. }
  2444. # remove the test server commands file after each test
  2445. unlink($FTPDCMD);
  2446. # run the postcheck command
  2447. my @postcheck= getpart("client", "postcheck");
  2448. if(@postcheck) {
  2449. $cmd = $postcheck[0];
  2450. chomp $cmd;
  2451. subVariables \$cmd;
  2452. if($cmd) {
  2453. logmsg "postcheck $cmd\n" if($verbose);
  2454. my $rc = runclient("$cmd");
  2455. # Must run the postcheck command in torture mode in order
  2456. # to clean up, but the result can't be relied upon.
  2457. if($rc != 0 && !$torture) {
  2458. logmsg " postcheck FAILED\n";
  2459. # timestamp test result verification end
  2460. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2461. return 1;
  2462. }
  2463. }
  2464. }
  2465. # restore environment variables that were modified
  2466. if(%oldenv) {
  2467. foreach my $var (keys %oldenv) {
  2468. if($oldenv{$var} eq 'notset') {
  2469. delete $ENV{$var} if($ENV{$var});
  2470. }
  2471. else {
  2472. $ENV{$var} = "$oldenv{$var}";
  2473. }
  2474. }
  2475. }
  2476. # Skip all the verification on torture tests
  2477. if ($torture) {
  2478. if(!$cmdres && !$keepoutfiles) {
  2479. cleardir($LOGDIR);
  2480. }
  2481. # timestamp test result verification end
  2482. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2483. return $cmdres;
  2484. }
  2485. my @err = getpart("verify", "errorcode");
  2486. my $errorcode = $err[0] || "0";
  2487. my $ok="";
  2488. my $res;
  2489. if (@validstdout) {
  2490. # verify redirected stdout
  2491. my @actual = loadarray($STDOUT);
  2492. # variable-replace in the stdout we have from the test case file
  2493. @validstdout = fixarray(@validstdout);
  2494. # get all attributes
  2495. my %hash = getpartattr("verify", "stdout");
  2496. # get the mode attribute
  2497. my $filemode=$hash{'mode'};
  2498. if($filemode && ($filemode eq "text") && $has_textaware) {
  2499. # text mode when running on windows: fix line endings
  2500. map s/\r\n/\n/g, @actual;
  2501. }
  2502. if($hash{'nonewline'}) {
  2503. # Yes, we must cut off the final newline from the final line
  2504. # of the protocol data
  2505. chomp($validstdout[$#validstdout]);
  2506. }
  2507. $res = compare("stdout", \@actual, \@validstdout);
  2508. if($res) {
  2509. # timestamp test result verification end
  2510. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2511. return 1;
  2512. }
  2513. $ok .= "s";
  2514. }
  2515. else {
  2516. $ok .= "-"; # stdout not checked
  2517. }
  2518. my %replyattr = getpartattr("reply", "data");
  2519. if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
  2520. # verify the received data
  2521. my @out = loadarray($CURLOUT);
  2522. my %hash = getpartattr("reply", "data");
  2523. # get the mode attribute
  2524. my $filemode=$hash{'mode'};
  2525. if($filemode && ($filemode eq "text") && $has_textaware) {
  2526. # text mode when running on windows: fix line endings
  2527. map s/\r\n/\n/g, @out;
  2528. }
  2529. $res = compare("data", \@out, \@reply);
  2530. if ($res) {
  2531. # timestamp test result verification end
  2532. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2533. return 1;
  2534. }
  2535. $ok .= "d";
  2536. }
  2537. else {
  2538. $ok .= "-"; # data not checked
  2539. }
  2540. if(@upload) {
  2541. # verify uploaded data
  2542. my @out = loadarray("$LOGDIR/upload.$testnum");
  2543. $res = compare("upload", \@out, \@upload);
  2544. if ($res) {
  2545. # timestamp test result verification end
  2546. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2547. return 1;
  2548. }
  2549. $ok .= "u";
  2550. }
  2551. else {
  2552. $ok .= "-"; # upload not checked
  2553. }
  2554. if(@protocol) {
  2555. # Verify the sent request
  2556. my @out = loadarray($SERVERIN);
  2557. # what to cut off from the live protocol sent by curl
  2558. my @strip = getpart("verify", "strip");
  2559. my @protstrip=@protocol;
  2560. # check if there's any attributes on the verify/protocol section
  2561. my %hash = getpartattr("verify", "protocol");
  2562. if($hash{'nonewline'}) {
  2563. # Yes, we must cut off the final newline from the final line
  2564. # of the protocol data
  2565. chomp($protstrip[$#protstrip]);
  2566. }
  2567. for(@strip) {
  2568. # strip off all lines that match the patterns from both arrays
  2569. chomp $_;
  2570. @out = striparray( $_, \@out);
  2571. @protstrip= striparray( $_, \@protstrip);
  2572. }
  2573. # what parts to cut off from the protocol
  2574. my @strippart = getpart("verify", "strippart");
  2575. my $strip;
  2576. for $strip (@strippart) {
  2577. chomp $strip;
  2578. for(@out) {
  2579. eval $strip;
  2580. }
  2581. }
  2582. $res = compare("protocol", \@out, \@protstrip);
  2583. if($res) {
  2584. # timestamp test result verification end
  2585. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2586. return 1;
  2587. }
  2588. $ok .= "p";
  2589. }
  2590. else {
  2591. $ok .= "-"; # protocol not checked
  2592. }
  2593. my @outfile=getpart("verify", "file");
  2594. if(@outfile) {
  2595. # we're supposed to verify a dynamically generated file!
  2596. my %hash = getpartattr("verify", "file");
  2597. my $filename=$hash{'name'};
  2598. if(!$filename) {
  2599. logmsg "ERROR: section verify=>file has no name attribute\n";
  2600. stopservers($verbose);
  2601. # timestamp test result verification end
  2602. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2603. return -1;
  2604. }
  2605. my @generated=loadarray($filename);
  2606. # what parts to cut off from the file
  2607. my @stripfile = getpart("verify", "stripfile");
  2608. my $filemode=$hash{'mode'};
  2609. if($filemode && ($filemode eq "text") && $has_textaware) {
  2610. # text mode when running on windows means adding an extra
  2611. # strip expression
  2612. push @stripfile, "s/\r\n/\n/";
  2613. }
  2614. my $strip;
  2615. for $strip (@stripfile) {
  2616. chomp $strip;
  2617. for(@generated) {
  2618. eval $strip;
  2619. }
  2620. }
  2621. @outfile = fixarray(@outfile);
  2622. $res = compare("output", \@generated, \@outfile);
  2623. if($res) {
  2624. # timestamp test result verification end
  2625. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2626. return 1;
  2627. }
  2628. $ok .= "o";
  2629. }
  2630. else {
  2631. $ok .= "-"; # output not checked
  2632. }
  2633. # accept multiple comma-separated error codes
  2634. my @splerr = split(/ *, */, $errorcode);
  2635. my $errok;
  2636. foreach my $e (@splerr) {
  2637. if($e == $cmdres) {
  2638. # a fine error code
  2639. $errok = 1;
  2640. last;
  2641. }
  2642. }
  2643. if($errok) {
  2644. $ok .= "e";
  2645. }
  2646. else {
  2647. if(!$short) {
  2648. printf("\n%s returned $cmdres, %d was expected\n",
  2649. (!$tool)?"curl":$tool, $errorcode);
  2650. }
  2651. logmsg " exit FAILED\n";
  2652. # timestamp test result verification end
  2653. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2654. return 1;
  2655. }
  2656. if($curl_debug) {
  2657. if(! -f $memdump) {
  2658. logmsg "\n** ALERT! memory debugging with no output file?\n"
  2659. if(!$cmdtype eq "perl");
  2660. }
  2661. else {
  2662. my @memdata=`$memanalyze $memdump`;
  2663. my $leak=0;
  2664. for(@memdata) {
  2665. if($_ ne "") {
  2666. # well it could be other memory problems as well, but
  2667. # we call it leak for short here
  2668. $leak=1;
  2669. }
  2670. }
  2671. if($leak) {
  2672. logmsg "\n** MEMORY FAILURE\n";
  2673. logmsg @memdata;
  2674. # timestamp test result verification end
  2675. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2676. return 1;
  2677. }
  2678. else {
  2679. $ok .= "m";
  2680. }
  2681. }
  2682. }
  2683. else {
  2684. $ok .= "-"; # memory not checked
  2685. }
  2686. if($valgrind) {
  2687. if($usevalgrind) {
  2688. unless(opendir(DIR, "$LOGDIR")) {
  2689. logmsg "ERROR: unable to read $LOGDIR\n";
  2690. # timestamp test result verification end
  2691. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2692. return 1;
  2693. }
  2694. my @files = readdir(DIR);
  2695. closedir(DIR);
  2696. my $vgfile;
  2697. foreach my $file (@files) {
  2698. if($file =~ /^valgrind$testnum(\..*|)$/) {
  2699. $vgfile = $file;
  2700. last;
  2701. }
  2702. }
  2703. if(!$vgfile) {
  2704. logmsg "ERROR: valgrind log file missing for test $testnum\n";
  2705. # timestamp test result verification end
  2706. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2707. return 1;
  2708. }
  2709. my @e = valgrindparse($srcdir, $feature{'SSL'}, "$LOGDIR/$vgfile");
  2710. if(@e && $e[0]) {
  2711. logmsg " valgrind ERROR ";
  2712. logmsg @e;
  2713. # timestamp test result verification end
  2714. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2715. return 1;
  2716. }
  2717. $ok .= "v";
  2718. }
  2719. else {
  2720. if(!$short && !$disablevalgrind) {
  2721. logmsg " valgrind SKIPPED\n";
  2722. }
  2723. $ok .= "-"; # skipped
  2724. }
  2725. }
  2726. else {
  2727. $ok .= "-"; # valgrind not checked
  2728. }
  2729. logmsg "$ok " if(!$short);
  2730. my $sofar= time()-$start;
  2731. my $esttotal = $sofar/$count * $total;
  2732. my $estleft = $esttotal - $sofar;
  2733. my $left=sprintf("remaining: %02d:%02d",
  2734. $estleft/60,
  2735. $estleft%60);
  2736. printf "OK (%-3d out of %-3d, %s)\n", $count, $total, $left;
  2737. # the test succeeded, remove all log files
  2738. if(!$keepoutfiles) {
  2739. cleardir($LOGDIR);
  2740. }
  2741. # timestamp test result verification end
  2742. $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
  2743. return 0;
  2744. }
  2745. #######################################################################
  2746. # Stop all running test servers
  2747. sub stopservers {
  2748. my $verbose = $_[0];
  2749. #
  2750. # kill sockfilter processes for all pingpong servers
  2751. #
  2752. killallsockfilters($verbose);
  2753. #
  2754. # kill all server pids from %run hash clearing them
  2755. #
  2756. my $pidlist;
  2757. foreach my $server (keys %run) {
  2758. if($run{$server}) {
  2759. if($verbose) {
  2760. my $prev = 0;
  2761. my $pids = $run{$server};
  2762. foreach my $pid (split(' ', $pids)) {
  2763. if($pid != $prev) {
  2764. logmsg sprintf("* kill pid for %s => %d\n",
  2765. $server, $pid);
  2766. $prev = $pid;
  2767. }
  2768. }
  2769. }
  2770. $pidlist .= "$run{$server} ";
  2771. $run{$server} = 0;
  2772. }
  2773. $runcert{$server} = 0 if($runcert{$server});
  2774. }
  2775. killpid($verbose, $pidlist);
  2776. #
  2777. # cleanup all server pid files
  2778. #
  2779. foreach my $server (keys %serverpidfile) {
  2780. my $pidfile = $serverpidfile{$server};
  2781. my $pid = processexists($pidfile);
  2782. if($pid > 0) {
  2783. logmsg "Warning: $server server unexpectedly alive\n";
  2784. killpid($verbose, $pid);
  2785. }
  2786. unlink($pidfile) if(-f $pidfile);
  2787. }
  2788. }
  2789. #######################################################################
  2790. # startservers() starts all the named servers
  2791. #
  2792. # Returns: string with error reason or blank for success
  2793. sub startservers {
  2794. my @what = @_;
  2795. my ($pid, $pid2);
  2796. for(@what) {
  2797. my (@whatlist) = split(/\s+/,$_);
  2798. my $what = lc($whatlist[0]);
  2799. $what =~ s/[^a-z0-9-]//g;
  2800. my $certfile;
  2801. if($what =~ /^(ftp|http|imap|pop3|smtp)s(.*)$/) {
  2802. $certfile = ($whatlist[1]) ? $whatlist[1] : 'stunnel.pem';
  2803. }
  2804. if(($what eq "pop3") ||
  2805. ($what eq "ftp") ||
  2806. ($what eq "imap") ||
  2807. ($what eq "smtp")) {
  2808. if(!$run{$what}) {
  2809. ($pid, $pid2) = runpingpongserver($what, "", $verbose);
  2810. if($pid <= 0) {
  2811. return "failed starting ". uc($what) ." server";
  2812. }
  2813. printf ("* pid $what => %d %d\n", $pid, $pid2) if($verbose);
  2814. $run{$what}="$pid $pid2";
  2815. }
  2816. }
  2817. elsif($what eq "ftp2") {
  2818. if(!$run{'ftp2'}) {
  2819. ($pid, $pid2) = runpingpongserver("ftp", "2", $verbose);
  2820. if($pid <= 0) {
  2821. return "failed starting FTP2 server";
  2822. }
  2823. printf ("* pid ftp2 => %d %d\n", $pid, $pid2) if($verbose);
  2824. $run{'ftp2'}="$pid $pid2";
  2825. }
  2826. }
  2827. elsif($what eq "ftp-ipv6") {
  2828. if(!$run{'ftp-ipv6'}) {
  2829. ($pid, $pid2) = runpingpongserver("ftp", "", $verbose, "ipv6");
  2830. if($pid <= 0) {
  2831. return "failed starting FTP-IPv6 server";
  2832. }
  2833. logmsg sprintf("* pid ftp-ipv6 => %d %d\n", $pid,
  2834. $pid2) if($verbose);
  2835. $run{'ftp-ipv6'}="$pid $pid2";
  2836. }
  2837. }
  2838. elsif($what eq "gopher") {
  2839. if(!$run{'gopher'}) {
  2840. ($pid, $pid2) = runhttpserver("gopher", $verbose, 0,
  2841. $GOPHERPORT);
  2842. if($pid <= 0) {
  2843. return "failed starting GOPHER server";
  2844. }
  2845. printf ("* pid gopher => %d %d\n", $pid, $pid2) if($verbose);
  2846. $run{'gopher'}="$pid $pid2";
  2847. }
  2848. }
  2849. elsif($what eq "gopher-ipv6") {
  2850. if(!$run{'gopher-ipv6'}) {
  2851. ($pid, $pid2) = runhttpserver("gopher", $verbose, "ipv6",
  2852. $GOPHER6PORT);
  2853. if($pid <= 0) {
  2854. return "failed starting GOPHER-IPv6 server";
  2855. }
  2856. logmsg sprintf("* pid gopher-ipv6 => %d %d\n", $pid,
  2857. $pid2) if($verbose);
  2858. $run{'gopher-ipv6'}="$pid $pid2";
  2859. }
  2860. }
  2861. elsif($what eq "http") {
  2862. if(!$run{'http'}) {
  2863. ($pid, $pid2) = runhttpserver("http", $verbose, 0,
  2864. $HTTPPORT);
  2865. if($pid <= 0) {
  2866. return "failed starting HTTP server";
  2867. }
  2868. printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
  2869. $run{'http'}="$pid $pid2";
  2870. }
  2871. }
  2872. elsif($what eq "http-ipv6") {
  2873. if(!$run{'http-ipv6'}) {
  2874. ($pid, $pid2) = runhttpserver("http", $verbose, "IPv6",
  2875. $HTTP6PORT);
  2876. if($pid <= 0) {
  2877. return "failed starting HTTP-IPv6 server";
  2878. }
  2879. logmsg sprintf("* pid http-ipv6 => %d %d\n", $pid, $pid2)
  2880. if($verbose);
  2881. $run{'http-ipv6'}="$pid $pid2";
  2882. }
  2883. }
  2884. elsif($what eq "rtsp") {
  2885. if(!$run{'rtsp'}) {
  2886. ($pid, $pid2) = runrtspserver($verbose);
  2887. if($pid <= 0) {
  2888. return "failed starting RTSP server";
  2889. }
  2890. printf ("* pid rtsp => %d %d\n", $pid, $pid2) if($verbose);
  2891. $run{'rtsp'}="$pid $pid2";
  2892. }
  2893. }
  2894. elsif($what eq "rtsp-ipv6") {
  2895. if(!$run{'rtsp-ipv6'}) {
  2896. ($pid, $pid2) = runrtspserver($verbose, "IPv6");
  2897. if($pid <= 0) {
  2898. return "failed starting RTSP-IPv6 server";
  2899. }
  2900. logmsg sprintf("* pid rtsp-ipv6 => %d %d\n", $pid, $pid2)
  2901. if($verbose);
  2902. $run{'rtsp-ipv6'}="$pid $pid2";
  2903. }
  2904. }
  2905. elsif($what eq "ftps") {
  2906. if(!$stunnel) {
  2907. # we can't run ftps tests without stunnel
  2908. return "no stunnel";
  2909. }
  2910. if(!$ssl_version) {
  2911. # we can't run ftps tests if libcurl is SSL-less
  2912. return "curl lacks SSL support";
  2913. }
  2914. if($runcert{'ftps'} && ($runcert{'ftps'} ne $certfile)) {
  2915. # stop server when running and using a different cert
  2916. stopserver('ftps');
  2917. }
  2918. if(!$run{'ftp'}) {
  2919. ($pid, $pid2) = runpingpongserver("ftp", "", $verbose);
  2920. if($pid <= 0) {
  2921. return "failed starting FTP server";
  2922. }
  2923. printf ("* pid ftp => %d %d\n", $pid, $pid2) if($verbose);
  2924. $run{'ftp'}="$pid $pid2";
  2925. }
  2926. if(!$run{'ftps'}) {
  2927. ($pid, $pid2) = runftpsserver($verbose, "", $certfile);
  2928. if($pid <= 0) {
  2929. return "failed starting FTPS server (stunnel)";
  2930. }
  2931. logmsg sprintf("* pid ftps => %d %d\n", $pid, $pid2)
  2932. if($verbose);
  2933. $run{'ftps'}="$pid $pid2";
  2934. }
  2935. }
  2936. elsif($what eq "file") {
  2937. # we support it but have no server!
  2938. }
  2939. elsif($what eq "https") {
  2940. if(!$stunnel) {
  2941. # we can't run ftps tests without stunnel
  2942. return "no stunnel";
  2943. }
  2944. if(!$ssl_version) {
  2945. # we can't run ftps tests if libcurl is SSL-less
  2946. return "curl lacks SSL support";
  2947. }
  2948. if($runcert{'https'} && ($runcert{'https'} ne $certfile)) {
  2949. # stop server when running and using a different cert
  2950. stopserver('https');
  2951. }
  2952. if(!$run{'http'}) {
  2953. ($pid, $pid2) = runhttpserver("http", $verbose, 0,
  2954. $HTTPPORT);
  2955. if($pid <= 0) {
  2956. return "failed starting HTTP server";
  2957. }
  2958. printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
  2959. $run{'http'}="$pid $pid2";
  2960. }
  2961. if(!$run{'https'}) {
  2962. ($pid, $pid2) = runhttpsserver($verbose, "", $certfile);
  2963. if($pid <= 0) {
  2964. return "failed starting HTTPS server (stunnel)";
  2965. }
  2966. logmsg sprintf("* pid https => %d %d\n", $pid, $pid2)
  2967. if($verbose);
  2968. $run{'https'}="$pid $pid2";
  2969. }
  2970. }
  2971. elsif($what eq "tftp") {
  2972. if(!$run{'tftp'}) {
  2973. ($pid, $pid2) = runtftpserver("", $verbose);
  2974. if($pid <= 0) {
  2975. return "failed starting TFTP server";
  2976. }
  2977. printf ("* pid tftp => %d %d\n", $pid, $pid2) if($verbose);
  2978. $run{'tftp'}="$pid $pid2";
  2979. }
  2980. }
  2981. elsif($what eq "tftp-ipv6") {
  2982. if(!$run{'tftp-ipv6'}) {
  2983. ($pid, $pid2) = runtftpserver("", $verbose, "IPv6");
  2984. if($pid <= 0) {
  2985. return "failed starting TFTP-IPv6 server";
  2986. }
  2987. printf("* pid tftp-ipv6 => %d %d\n", $pid, $pid2) if($verbose);
  2988. $run{'tftp-ipv6'}="$pid $pid2";
  2989. }
  2990. }
  2991. elsif($what eq "sftp" || $what eq "scp" || $what eq "socks4" || $what eq "socks5" ) {
  2992. if(!$run{'ssh'}) {
  2993. ($pid, $pid2) = runsshserver("", $verbose);
  2994. if($pid <= 0) {
  2995. return "failed starting SSH server";
  2996. }
  2997. printf ("* pid ssh => %d %d\n", $pid, $pid2) if($verbose);
  2998. $run{'ssh'}="$pid $pid2";
  2999. }
  3000. if($what eq "socks4" || $what eq "socks5") {
  3001. if(!$run{'socks'}) {
  3002. ($pid, $pid2) = runsocksserver("", $verbose);
  3003. if($pid <= 0) {
  3004. return "failed starting socks server";
  3005. }
  3006. printf ("* pid socks => %d %d\n", $pid, $pid2) if($verbose);
  3007. $run{'socks'}="$pid $pid2";
  3008. }
  3009. }
  3010. if($what eq "socks5") {
  3011. if(!$sshdid) {
  3012. # Not an OpenSSH or SunSSH ssh daemon
  3013. logmsg "Not OpenSSH or SunSSH; socks5 tests need at least OpenSSH 3.7\n";
  3014. return "failed starting socks5 server";
  3015. }
  3016. elsif(($sshdid =~ /OpenSSH/) && ($sshdvernum < 370)) {
  3017. # Need OpenSSH 3.7 for socks5 - http://www.openssh.com/txt/release-3.7
  3018. logmsg "$sshdverstr insufficient; socks5 tests need at least OpenSSH 3.7\n";
  3019. return "failed starting socks5 server";
  3020. }
  3021. elsif(($sshdid =~ /SunSSH/) && ($sshdvernum < 100)) {
  3022. # Need SunSSH 1.0 for socks5
  3023. logmsg "$sshdverstr insufficient; socks5 tests need at least SunSSH 1.0\n";
  3024. return "failed starting socks5 server";
  3025. }
  3026. }
  3027. }
  3028. elsif($what eq "none") {
  3029. logmsg "* starts no server\n" if ($verbose);
  3030. }
  3031. else {
  3032. warn "we don't support a server for $what";
  3033. return "no server for $what";
  3034. }
  3035. }
  3036. return 0;
  3037. }
  3038. ##############################################################################
  3039. # This function makes sure the right set of server is running for the
  3040. # specified test case. This is a useful design when we run single tests as not
  3041. # all servers need to run then!
  3042. #
  3043. # Returns: a string, blank if everything is fine or a reason why it failed
  3044. #
  3045. sub serverfortest {
  3046. my ($testnum)=@_;
  3047. my @what = getpart("client", "server");
  3048. if(!$what[0]) {
  3049. warn "Test case $testnum has no server(s) specified";
  3050. return "no server specified";
  3051. }
  3052. for (@what) {
  3053. my $proto = lc($_);
  3054. chomp $proto;
  3055. $proto =~ s/\s.*//g; # take first word
  3056. if (! grep /^$proto$/, @protocols) {
  3057. if (substr($proto,0,5) ne "socks") {
  3058. return "curl lacks $proto support";
  3059. }
  3060. }
  3061. }
  3062. return &startservers(@what);
  3063. }
  3064. #######################################################################
  3065. # runtimestats displays test-suite run time statistics
  3066. #
  3067. sub runtimestats {
  3068. my $lasttest = $_[0];
  3069. return if(not $timestats);
  3070. logmsg "\nTest suite total running time breakdown per task...\n\n";
  3071. my @timesrvr;
  3072. my @timeprep;
  3073. my @timetool;
  3074. my @timelock;
  3075. my @timevrfy;
  3076. my @timetest;
  3077. my $timesrvrtot = 0.0;
  3078. my $timepreptot = 0.0;
  3079. my $timetooltot = 0.0;
  3080. my $timelocktot = 0.0;
  3081. my $timevrfytot = 0.0;
  3082. my $timetesttot = 0.0;
  3083. my $counter;
  3084. for my $testnum (1 .. $lasttest) {
  3085. if($timesrvrini{$testnum}) {
  3086. $timesrvrtot += $timesrvrend{$testnum} - $timesrvrini{$testnum};
  3087. $timepreptot +=
  3088. (($timetoolini{$testnum} - $timeprepini{$testnum}) -
  3089. ($timesrvrend{$testnum} - $timesrvrini{$testnum}));
  3090. $timetooltot += $timetoolend{$testnum} - $timetoolini{$testnum};
  3091. $timelocktot += $timesrvrlog{$testnum} - $timetoolend{$testnum};
  3092. $timevrfytot += $timevrfyend{$testnum} - $timesrvrlog{$testnum};
  3093. $timetesttot += $timevrfyend{$testnum} - $timeprepini{$testnum};
  3094. push @timesrvr, sprintf("%06.3f %04d",
  3095. $timesrvrend{$testnum} - $timesrvrini{$testnum}, $testnum);
  3096. push @timeprep, sprintf("%06.3f %04d",
  3097. ($timetoolini{$testnum} - $timeprepini{$testnum}) -
  3098. ($timesrvrend{$testnum} - $timesrvrini{$testnum}), $testnum);
  3099. push @timetool, sprintf("%06.3f %04d",
  3100. $timetoolend{$testnum} - $timetoolini{$testnum}, $testnum);
  3101. push @timelock, sprintf("%06.3f %04d",
  3102. $timesrvrlog{$testnum} - $timetoolend{$testnum}, $testnum);
  3103. push @timevrfy, sprintf("%06.3f %04d",
  3104. $timevrfyend{$testnum} - $timesrvrlog{$testnum}, $testnum);
  3105. push @timetest, sprintf("%06.3f %04d",
  3106. $timevrfyend{$testnum} - $timeprepini{$testnum}, $testnum);
  3107. }
  3108. }
  3109. {
  3110. no warnings 'numeric';
  3111. @timesrvr = sort { $b <=> $a } @timesrvr;
  3112. @timeprep = sort { $b <=> $a } @timeprep;
  3113. @timetool = sort { $b <=> $a } @timetool;
  3114. @timelock = sort { $b <=> $a } @timelock;
  3115. @timevrfy = sort { $b <=> $a } @timevrfy;
  3116. @timetest = sort { $b <=> $a } @timetest;
  3117. }
  3118. logmsg "Spent ". sprintf("%08.3f ", $timesrvrtot) .
  3119. "seconds starting and verifying test harness servers.\n";
  3120. logmsg "Spent ". sprintf("%08.3f ", $timepreptot) .
  3121. "seconds reading definitions and doing test preparations.\n";
  3122. logmsg "Spent ". sprintf("%08.3f ", $timetooltot) .
  3123. "seconds actually running test tools.\n";
  3124. logmsg "Spent ". sprintf("%08.3f ", $timelocktot) .
  3125. "seconds awaiting server logs lock removal.\n";
  3126. logmsg "Spent ". sprintf("%08.3f ", $timevrfytot) .
  3127. "seconds verifying test results.\n";
  3128. logmsg "Spent ". sprintf("%08.3f ", $timetesttot) .
  3129. "seconds doing all of the above.\n";
  3130. $counter = 25;
  3131. logmsg "\nTest server starting and verification time per test ".
  3132. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  3133. logmsg "-time- test\n";
  3134. logmsg "------ ----\n";
  3135. foreach my $txt (@timesrvr) {
  3136. last if((not $fullstats) && (not $counter--));
  3137. logmsg "$txt\n";
  3138. }
  3139. $counter = 10;
  3140. logmsg "\nTest definition reading and preparation time per test ".
  3141. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  3142. logmsg "-time- test\n";
  3143. logmsg "------ ----\n";
  3144. foreach my $txt (@timeprep) {
  3145. last if((not $fullstats) && (not $counter--));
  3146. logmsg "$txt\n";
  3147. }
  3148. $counter = 25;
  3149. logmsg "\nTest tool execution time per test ".
  3150. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  3151. logmsg "-time- test\n";
  3152. logmsg "------ ----\n";
  3153. foreach my $txt (@timetool) {
  3154. last if((not $fullstats) && (not $counter--));
  3155. logmsg "$txt\n";
  3156. }
  3157. $counter = 15;
  3158. logmsg "\nTest server logs lock removal time per test ".
  3159. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  3160. logmsg "-time- test\n";
  3161. logmsg "------ ----\n";
  3162. foreach my $txt (@timelock) {
  3163. last if((not $fullstats) && (not $counter--));
  3164. logmsg "$txt\n";
  3165. }
  3166. $counter = 10;
  3167. logmsg "\nTest results verification time per test ".
  3168. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  3169. logmsg "-time- test\n";
  3170. logmsg "------ ----\n";
  3171. foreach my $txt (@timevrfy) {
  3172. last if((not $fullstats) && (not $counter--));
  3173. logmsg "$txt\n";
  3174. }
  3175. $counter = 50;
  3176. logmsg "\nTotal time per test ".
  3177. sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
  3178. logmsg "-time- test\n";
  3179. logmsg "------ ----\n";
  3180. foreach my $txt (@timetest) {
  3181. last if((not $fullstats) && (not $counter--));
  3182. logmsg "$txt\n";
  3183. }
  3184. logmsg "\n";
  3185. }
  3186. #######################################################################
  3187. # Check options to this test program
  3188. #
  3189. my $number=0;
  3190. my $fromnum=-1;
  3191. my @testthis;
  3192. my %disabled;
  3193. while(@ARGV) {
  3194. if ($ARGV[0] eq "-v") {
  3195. # verbose output
  3196. $verbose=1;
  3197. }
  3198. elsif($ARGV[0] =~ /^-b(.*)/) {
  3199. my $portno=$1;
  3200. if($portno =~ s/(\d+)$//) {
  3201. $base = int $1;
  3202. }
  3203. }
  3204. elsif ($ARGV[0] eq "-c") {
  3205. # use this path to curl instead of default
  3206. $DBGCURL=$CURL=$ARGV[1];
  3207. shift @ARGV;
  3208. }
  3209. elsif ($ARGV[0] eq "-d") {
  3210. # have the servers display protocol output
  3211. $debugprotocol=1;
  3212. }
  3213. elsif ($ARGV[0] eq "-f") {
  3214. # run fork-servers, which makes the server fork for all new
  3215. # connections This is NOT what you wanna do without knowing exactly
  3216. # why and for what
  3217. $forkserver=1;
  3218. }
  3219. elsif ($ARGV[0] eq "-g") {
  3220. # run this test with gdb
  3221. $gdbthis=1;
  3222. }
  3223. elsif($ARGV[0] eq "-s") {
  3224. # short output
  3225. $short=1;
  3226. }
  3227. elsif($ARGV[0] eq "-n") {
  3228. # no valgrind
  3229. undef $valgrind;
  3230. }
  3231. elsif($ARGV[0] =~ /^-t(.*)/) {
  3232. # torture
  3233. $torture=1;
  3234. my $xtra = $1;
  3235. if($xtra =~ s/(\d+)$//) {
  3236. $tortalloc = $1;
  3237. }
  3238. # we undef valgrind to make this fly in comparison
  3239. undef $valgrind;
  3240. }
  3241. elsif($ARGV[0] eq "-a") {
  3242. # continue anyway, even if a test fail
  3243. $anyway=1;
  3244. }
  3245. elsif($ARGV[0] eq "-p") {
  3246. $postmortem=1;
  3247. }
  3248. elsif($ARGV[0] eq "-l") {
  3249. # lists the test case names only
  3250. $listonly=1;
  3251. }
  3252. elsif($ARGV[0] eq "-k") {
  3253. # keep stdout and stderr files after tests
  3254. $keepoutfiles=1;
  3255. }
  3256. elsif($ARGV[0] eq "-r") {
  3257. # run time statistics needs Time::HiRes
  3258. if($Time::HiRes::VERSION) {
  3259. keys(%timeprepini) = 1000;
  3260. keys(%timesrvrini) = 1000;
  3261. keys(%timesrvrend) = 1000;
  3262. keys(%timetoolini) = 1000;
  3263. keys(%timetoolend) = 1000;
  3264. keys(%timesrvrlog) = 1000;
  3265. keys(%timevrfyend) = 1000;
  3266. $timestats=1;
  3267. $fullstats=0;
  3268. }
  3269. }
  3270. elsif($ARGV[0] eq "-rf") {
  3271. # run time statistics needs Time::HiRes
  3272. if($Time::HiRes::VERSION) {
  3273. keys(%timeprepini) = 1000;
  3274. keys(%timesrvrini) = 1000;
  3275. keys(%timesrvrend) = 1000;
  3276. keys(%timetoolini) = 1000;
  3277. keys(%timetoolend) = 1000;
  3278. keys(%timesrvrlog) = 1000;
  3279. keys(%timevrfyend) = 1000;
  3280. $timestats=1;
  3281. $fullstats=1;
  3282. }
  3283. }
  3284. elsif(($ARGV[0] eq "-h") || ($ARGV[0] eq "--help")) {
  3285. # show help text
  3286. print <<EOHELP
  3287. Usage: runtests.pl [options] [test selection(s)]
  3288. -a continue even if a test fails
  3289. -bN use base port number N for test servers (default $base)
  3290. -c path use this curl executable
  3291. -d display server debug info
  3292. -g run the test case with gdb
  3293. -h this help text
  3294. -k keep stdout and stderr files present after tests
  3295. -l list all test case names/descriptions
  3296. -n no valgrind
  3297. -p print log file contents when a test fails
  3298. -r run time statistics
  3299. -rf full run time statistics
  3300. -s short output
  3301. -t[N] torture (simulate memory alloc failures); N means fail Nth alloc
  3302. -v verbose output
  3303. [num] like "5 6 9" or " 5 to 22 " to run those tests only
  3304. [!num] like "!5 !6 !9" to disable those tests
  3305. [keyword] like "IPv6" to select only tests containing the key word
  3306. [!keyword] like "!cookies" to disable any tests containing the key word
  3307. EOHELP
  3308. ;
  3309. exit;
  3310. }
  3311. elsif($ARGV[0] =~ /^(\d+)/) {
  3312. $number = $1;
  3313. if($fromnum >= 0) {
  3314. for($fromnum .. $number) {
  3315. push @testthis, $_;
  3316. }
  3317. $fromnum = -1;
  3318. }
  3319. else {
  3320. push @testthis, $1;
  3321. }
  3322. }
  3323. elsif($ARGV[0] =~ /^to$/i) {
  3324. $fromnum = $number+1;
  3325. }
  3326. elsif($ARGV[0] =~ /^!(\d+)/) {
  3327. $fromnum = -1;
  3328. $disabled{$1}=$1;
  3329. }
  3330. elsif($ARGV[0] =~ /^!(.+)/) {
  3331. $disabled_keywords{$1}=$1;
  3332. }
  3333. elsif($ARGV[0] =~ /^([-[{a-zA-Z].*)/) {
  3334. $enabled_keywords{$1}=$1;
  3335. }
  3336. else {
  3337. print "Unknown option: $ARGV[0]\n";
  3338. exit;
  3339. }
  3340. shift @ARGV;
  3341. }
  3342. if(@testthis && ($testthis[0] ne "")) {
  3343. $TESTCASES=join(" ", @testthis);
  3344. }
  3345. if($valgrind) {
  3346. # we have found valgrind on the host, use it
  3347. # verify that we can invoke it fine
  3348. my $code = runclient("valgrind >/dev/null 2>&1");
  3349. if(($code>>8) != 1) {
  3350. #logmsg "Valgrind failure, disable it\n";
  3351. undef $valgrind;
  3352. } else {
  3353. # since valgrind 2.1.x, '--tool' option is mandatory
  3354. # use it, if it is supported by the version installed on the system
  3355. runclient("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1");
  3356. if (($? >> 8)==0) {
  3357. $valgrind_tool="--tool=memcheck";
  3358. }
  3359. open(C, "<$CURL");
  3360. my $l = <C>;
  3361. if($l =~ /^\#\!/) {
  3362. # A shell script. This is typically when built with libtool,
  3363. $valgrind="../libtool --mode=execute $valgrind";
  3364. }
  3365. close(C);
  3366. # valgrind 3 renamed the --logfile option to --log-file!!!
  3367. my $ver=join(' ', runclientoutput("valgrind --version"));
  3368. # cut off all but digits and dots
  3369. $ver =~ s/[^0-9.]//g;
  3370. if($ver =~ /^(\d+)/) {
  3371. $ver = $1;
  3372. if($ver >= 3) {
  3373. $valgrind_logfile="--log-file";
  3374. }
  3375. }
  3376. }
  3377. }
  3378. if ($gdbthis) {
  3379. # open the executable curl and read the first 4 bytes of it
  3380. open(CHECK, "<$CURL");
  3381. my $c;
  3382. sysread CHECK, $c, 4;
  3383. close(CHECK);
  3384. if($c eq "#! /") {
  3385. # A shell script. This is typically when built with libtool,
  3386. $libtool = 1;
  3387. $gdb = "libtool --mode=execute gdb";
  3388. }
  3389. }
  3390. $HTTPPORT = $base++; # HTTP server port
  3391. $HTTPSPORT = $base++; # HTTPS server port
  3392. $FTPPORT = $base++; # FTP server port
  3393. $FTPSPORT = $base++; # FTPS server port
  3394. $HTTP6PORT = $base++; # HTTP IPv6 server port (different IP protocol
  3395. # but we follow the same port scheme anyway)
  3396. $FTP2PORT = $base++; # FTP server 2 port
  3397. $FTP6PORT = $base++; # FTP IPv6 port
  3398. $TFTPPORT = $base++; # TFTP (UDP) port
  3399. $TFTP6PORT = $base++; # TFTP IPv6 (UDP) port
  3400. $SSHPORT = $base++; # SSH (SCP/SFTP) port
  3401. $SOCKSPORT = $base++; # SOCKS port
  3402. $POP3PORT = $base++;
  3403. $POP36PORT = $base++;
  3404. $IMAPPORT = $base++;
  3405. $IMAP6PORT = $base++;
  3406. $SMTPPORT = $base++;
  3407. $SMTP6PORT = $base++;
  3408. $RTSPPORT = $base++;
  3409. $RTSP6PORT = $base++;
  3410. $GOPHERPORT =$base++;
  3411. $GOPHER6PORT=$base++;
  3412. #######################################################################
  3413. # clear and create logging directory:
  3414. #
  3415. cleardir($LOGDIR);
  3416. mkdir($LOGDIR, 0777);
  3417. #######################################################################
  3418. # initialize some variables
  3419. #
  3420. get_disttests();
  3421. init_serverpidfile_hash();
  3422. #######################################################################
  3423. # Output curl version and host info being tested
  3424. #
  3425. if(!$listonly) {
  3426. checksystem();
  3427. }
  3428. #######################################################################
  3429. # If 'all' tests are requested, find out all test numbers
  3430. #
  3431. if ( $TESTCASES eq "all") {
  3432. # Get all commands and find out their test numbers
  3433. opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
  3434. my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
  3435. closedir(DIR);
  3436. open(D, "<$TESTDIR/DISABLED");
  3437. while(<D>) {
  3438. if(/^ *\#/) {
  3439. # allow comments
  3440. next;
  3441. }
  3442. if($_ =~ /(\d+)/) {
  3443. $disabled{$1}=$1; # disable this test number
  3444. }
  3445. }
  3446. close(D);
  3447. $TESTCASES=""; # start with no test cases
  3448. # cut off everything but the digits
  3449. for(@cmds) {
  3450. $_ =~ s/[a-z\/\.]*//g;
  3451. }
  3452. # sort the numbers from low to high
  3453. foreach my $n (sort { $a <=> $b } @cmds) {
  3454. if($disabled{$n}) {
  3455. # skip disabled test cases
  3456. my $why = "configured as DISABLED";
  3457. $skipped++;
  3458. $skipped{$why}++;
  3459. $teststat[$n]=$why; # store reason for this test case
  3460. next;
  3461. }
  3462. $TESTCASES .= " $n";
  3463. }
  3464. }
  3465. #######################################################################
  3466. # Start the command line log
  3467. #
  3468. open(CMDLOG, ">$CURLLOG") ||
  3469. logmsg "can't log command lines to $CURLLOG\n";
  3470. #######################################################################
  3471. # Display the contents of the given file. Line endings are canonicalized
  3472. # and excessively long files are elided
  3473. sub displaylogcontent {
  3474. my ($file)=@_;
  3475. if(open(SINGLE, "<$file")) {
  3476. my $linecount = 0;
  3477. my $truncate;
  3478. my @tail;
  3479. while(my $string = <SINGLE>) {
  3480. $string =~ s/\r\n/\n/g;
  3481. $string =~ s/[\r\f\032]/\n/g;
  3482. $string .= "\n" unless ($string =~ /\n$/);
  3483. $string =~ tr/\n//;
  3484. for my $line (split("\n", $string)) {
  3485. $line =~ s/\s*\!$//;
  3486. if ($truncate) {
  3487. push @tail, " $line\n";
  3488. } else {
  3489. logmsg " $line\n";
  3490. }
  3491. $linecount++;
  3492. $truncate = $linecount > 1000;
  3493. }
  3494. }
  3495. if(@tail) {
  3496. my $tailshow = 200;
  3497. my $tailskip = 0;
  3498. my $tailtotal = scalar @tail;
  3499. if($tailtotal > $tailshow) {
  3500. $tailskip = $tailtotal - $tailshow;
  3501. logmsg "=== File too long: $tailskip lines omitted here\n";
  3502. }
  3503. for($tailskip .. $tailtotal-1) {
  3504. logmsg "$tail[$_]";
  3505. }
  3506. }
  3507. close(SINGLE);
  3508. }
  3509. }
  3510. sub displaylogs {
  3511. my ($testnum)=@_;
  3512. opendir(DIR, "$LOGDIR") ||
  3513. die "can't open dir: $!";
  3514. my @logs = readdir(DIR);
  3515. closedir(DIR);
  3516. logmsg "== Contents of files in the $LOGDIR/ dir after test $testnum\n";
  3517. foreach my $log (sort @logs) {
  3518. if($log =~ /\.(\.|)$/) {
  3519. next; # skip "." and ".."
  3520. }
  3521. if($log =~ /^\.nfs/) {
  3522. next; # skip ".nfs"
  3523. }
  3524. if(($log eq "memdump") || ($log eq "core")) {
  3525. next; # skip "memdump" and "core"
  3526. }
  3527. if((-d "$LOGDIR/$log") || (! -s "$LOGDIR/$log")) {
  3528. next; # skip directory and empty files
  3529. }
  3530. if(($log =~ /^stdout\d+/) && ($log !~ /^stdout$testnum/)) {
  3531. next; # skip stdoutNnn of other tests
  3532. }
  3533. if(($log =~ /^stderr\d+/) && ($log !~ /^stderr$testnum/)) {
  3534. next; # skip stderrNnn of other tests
  3535. }
  3536. if(($log =~ /^upload\d+/) && ($log !~ /^upload$testnum/)) {
  3537. next; # skip uploadNnn of other tests
  3538. }
  3539. if(($log =~ /^curl\d+\.out/) && ($log !~ /^curl$testnum\.out/)) {
  3540. next; # skip curlNnn.out of other tests
  3541. }
  3542. if(($log =~ /^test\d+\.txt/) && ($log !~ /^test$testnum\.txt/)) {
  3543. next; # skip testNnn.txt of other tests
  3544. }
  3545. if(($log =~ /^file\d+\.txt/) && ($log !~ /^file$testnum\.txt/)) {
  3546. next; # skip fileNnn.txt of other tests
  3547. }
  3548. if(($log =~ /^valgrind\d+/) && ($log !~ /^valgrind$testnum(\..*|)$/)) {
  3549. next; # skip valgrindNnn of other tests
  3550. }
  3551. logmsg "=== Start of file $log\n";
  3552. displaylogcontent("$LOGDIR/$log");
  3553. logmsg "=== End of file $log\n";
  3554. }
  3555. }
  3556. #######################################################################
  3557. # The main test-loop
  3558. #
  3559. my $failed;
  3560. my $testnum;
  3561. my $ok=0;
  3562. my $total=0;
  3563. my $lasttest=0;
  3564. my @at = split(" ", $TESTCASES);
  3565. my $count=0;
  3566. $start = time();
  3567. foreach $testnum (@at) {
  3568. $lasttest = $testnum if($testnum > $lasttest);
  3569. $count++;
  3570. my $error = singletest($testnum, $count, scalar(@at));
  3571. if($error < 0) {
  3572. # not a test we can run
  3573. next;
  3574. }
  3575. $total++; # number of tests we've run
  3576. if($error>0) {
  3577. $failed.= "$testnum ";
  3578. if($postmortem) {
  3579. # display all files in log/ in a nice way
  3580. displaylogs($testnum);
  3581. }
  3582. if(!$anyway) {
  3583. # a test failed, abort
  3584. logmsg "\n - abort tests\n";
  3585. last;
  3586. }
  3587. }
  3588. elsif(!$error) {
  3589. $ok++; # successful test counter
  3590. }
  3591. # loop for next test
  3592. }
  3593. my $sofar = time() - $start;
  3594. #######################################################################
  3595. # Close command log
  3596. #
  3597. close(CMDLOG);
  3598. # Tests done, stop the servers
  3599. stopservers($verbose);
  3600. my $all = $total + $skipped;
  3601. runtimestats($lasttest);
  3602. if($total) {
  3603. logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
  3604. $ok/$total*100);
  3605. if($ok != $total) {
  3606. logmsg "TESTFAIL: These test cases failed: $failed\n";
  3607. }
  3608. }
  3609. else {
  3610. logmsg "TESTFAIL: No tests were performed\n";
  3611. }
  3612. if($all) {
  3613. logmsg "TESTDONE: $all tests were considered during ".
  3614. sprintf("%.0f", $sofar) ." seconds.\n";
  3615. }
  3616. if($skipped) {
  3617. my $s=0;
  3618. logmsg "TESTINFO: $skipped tests were skipped due to these restraints:\n";
  3619. for(keys %skipped) {
  3620. my $r = $_;
  3621. printf "TESTINFO: \"%s\" %d times (", $r, $skipped{$_};
  3622. # now show all test case numbers that had this reason for being
  3623. # skipped
  3624. my $c=0;
  3625. for(0 .. scalar @teststat) {
  3626. my $t = $_;
  3627. if($teststat[$_] && ($teststat[$_] eq $r)) {
  3628. logmsg ", " if($c);
  3629. logmsg $_;
  3630. $c++;
  3631. }
  3632. }
  3633. logmsg ")\n";
  3634. }
  3635. }
  3636. if($total && ($ok != $total)) {
  3637. exit 1;
  3638. }