runtests.pl 159 KB

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