runtests.pl 189 KB

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