runtests.pl 181 KB

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