runtests.pl 169 KB

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