runtests.pl 197 KB

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