runtests.pl 195 KB

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