2
0

runtests.pl 189 KB

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