runtests.pl 171 KB

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