runtests.pl 197 KB

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