runtests.pl 196 KB

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