runtests.pl 152 KB

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