runtests.pl 203 KB

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