runtests.pl 182 KB

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