runtests.pl 192 KB

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