runtests.pl 147 KB

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