runtests.pl 183 KB

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