runtests.pl 159 KB

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