cmCTest.cxx 144 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTest.h"
  14. #include "cmake.h"
  15. #include "cmMakefile.h"
  16. #include "cmLocalGenerator.h"
  17. #include "cmGlobalGenerator.h"
  18. #include <cmsys/Directory.hxx>
  19. #include "cmGlob.h"
  20. #include "cmDynamicLoader.h"
  21. #include "cmCTestScriptHandler.h"
  22. #include "cmCTestSubmit.h"
  23. #include "curl/curl.h"
  24. #include <cmsys/RegularExpression.hxx>
  25. #include <cmsys/Process.h>
  26. #include <cmsys/Base64.h>
  27. #include <stdlib.h>
  28. #include <time.h>
  29. #include <math.h>
  30. #include <float.h>
  31. #include <memory> // auto_ptr
  32. #define SAFEDIV(x,y) (((y)!=0)?((x)/(y)):(0))
  33. #define DEBUGOUT std::cout << __LINE__ << " "; std::cout
  34. #define DEBUGERR std::cerr << __LINE__ << " "; std::cerr
  35. static struct tm* GetNightlyTime(std::string str, bool verbose, bool tomorrowtag)
  36. {
  37. struct tm* lctime;
  38. time_t tctime = time(0);
  39. if ( verbose )
  40. {
  41. std::cout << "Determine Nightly Start Time" << std::endl;
  42. std::cout << " Specified time: " << str.c_str() << std::endl;
  43. }
  44. //Convert the nightly start time to seconds. Since we are
  45. //providing only a time and a timezone, the current date of
  46. //the local machine is assumed. Consequently, nightlySeconds
  47. //is the time at which the nightly dashboard was opened or
  48. //will be opened on the date of the current client machine.
  49. //As such, this time may be in the past or in the future.
  50. time_t ntime = curl_getdate(str.c_str(), &tctime);
  51. if ( verbose )
  52. {
  53. std::cout << " Get curl time: " << ntime << std::endl;
  54. }
  55. tctime = time(0);
  56. if ( verbose )
  57. {
  58. std::cout << " Get the current time: " << tctime << std::endl;
  59. }
  60. const int dayLength = 24 * 60 * 60;
  61. //std::cout << "Seconds: " << tctime << std::endl;
  62. if ( ntime > tctime )
  63. {
  64. // If nightlySeconds is in the past, this is the current
  65. // open dashboard, then return nightlySeconds. If
  66. // nightlySeconds is in the future, this is the next
  67. // dashboard to be opened, so subtract 24 hours to get the
  68. // time of the current open dashboard
  69. ntime -= dayLength;
  70. //std::cout << "Pick yesterday" << std::endl;
  71. if ( verbose )
  72. {
  73. std::cout << " Future time, subtract day: " << ntime << std::endl;
  74. }
  75. }
  76. if ( (tctime - ntime) > dayLength )
  77. {
  78. ntime += dayLength;
  79. if ( verbose )
  80. {
  81. std::cout << " Past time, subtract day: " << ntime << std::endl;
  82. }
  83. }
  84. //std::cout << "nightlySeconds: " << ntime << std::endl;
  85. if ( verbose )
  86. {
  87. std::cout << " Current time: " << tctime
  88. << " Nightly time: " << ntime << std::endl;
  89. }
  90. if ( tomorrowtag )
  91. {
  92. std::cout << "Use future tag, Add a day" << std::endl;
  93. ntime += dayLength;
  94. }
  95. lctime = gmtime(&ntime);
  96. return lctime;
  97. }
  98. static std::string CleanString(const std::string& str)
  99. {
  100. std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
  101. std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
  102. if ( spos == str.npos )
  103. {
  104. return std::string();
  105. }
  106. if ( epos != str.npos )
  107. {
  108. epos = epos - spos + 1;
  109. }
  110. return str.substr(spos, epos);
  111. }
  112. std::string cmCTest::CurrentTime()
  113. {
  114. time_t currenttime = time(0);
  115. struct tm* t = localtime(&currenttime);
  116. //return ::CleanString(ctime(&currenttime));
  117. char current_time[1024];
  118. if ( m_ShortDateFormat )
  119. {
  120. strftime(current_time, 1000, "%b %d %H:%M %Z", t);
  121. }
  122. else
  123. {
  124. strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
  125. }
  126. //std::cout << "Current_Time: " << current_time << std::endl;
  127. return this->MakeXMLSafe(::CleanString(current_time));
  128. }
  129. static const char* cmCTestErrorMatches[] = {
  130. "^[Bb]us [Ee]rror",
  131. "^[Ss]egmentation [Vv]iolation",
  132. "^[Ss]egmentation [Ff]ault",
  133. "([^ :]+):([0-9]+): ([^ \\t])",
  134. "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
  135. "^Error ([0-9]+):",
  136. "^Fatal",
  137. "^Error: ",
  138. "^Error ",
  139. "[0-9] ERROR: ",
  140. "^\"[^\"]+\", line [0-9]+: [^Ww]",
  141. "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
  142. "^ld([^:])*:([ \\t])*ERROR([^:])*:",
  143. "^ild:([ \\t])*\\(undefined symbol\\)",
  144. "([^ :]+) : (error|fatal error|catastrophic error)",
  145. "([^:]+): (Error:|error|undefined reference|multiply defined)",
  146. "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
  147. "^fatal error C[0-9]+:",
  148. ": syntax error ",
  149. "^collect2: ld returned 1 exit status",
  150. "Unsatisfied symbols:",
  151. "^Unresolved:",
  152. "Undefined symbols:",
  153. "^Undefined[ \\t]+first referenced",
  154. "^CMake Error:",
  155. ":[ \\t]cannot find",
  156. ":[ \\t]can't find",
  157. ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
  158. ": Invalid loader fixup for symbol",
  159. ": internal link edit command failed",
  160. ": Unrecognized option \\`.*\\'",
  161. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^W]\\)",
  162. "ld: 0706-006 Cannot find or open library file: -l ",
  163. "ild: \\(argument error\\) can't find library argument ::",
  164. "^could not be found and will not be loaded.",
  165. "s:616 string too big",
  166. "make: Fatal error: ",
  167. "ld: 0711-993 Error occurred while writing to the output file:",
  168. "make: \\*\\*\\*.*Error",
  169. 0
  170. };
  171. static const char* cmCTestErrorExceptions[] = {
  172. "instantiated from ",
  173. "candidates are:",
  174. ": warning",
  175. "makefile:",
  176. "Makefile:",
  177. ":[ \\t]+Where:",
  178. "([^ :]+):([0-9]+): Warning",
  179. 0
  180. };
  181. static const char* cmCTestWarningMatches[] = {
  182. "([^ :]+):([0-9]+): warning:",
  183. "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
  184. "^ld([^:])*:([ \\t])*WARNING([^:])*:",
  185. "([^:]+): warning ([0-9]+):",
  186. "^\"[^\"]+\", line [0-9]+: [Ww]arning",
  187. "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
  188. "^Warning ([0-9]+):",
  189. "^Warning ",
  190. "WARNING: ",
  191. "([^ :]+) : warning",
  192. "([^:]+): warning",
  193. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\(W\\)",
  194. "^cxx: Warning:",
  195. ".*file: .* has no symbols",
  196. "([^ :]+):([0-9]+): Warning",
  197. 0
  198. };
  199. static const char* cmCTestWarningExceptions[] = {
  200. "/usr/openwin/include/X11/Xlib\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  201. "/usr/openwin/include/X11/Xutil\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  202. "/usr/openwin/include/X11/XResource\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  203. "WARNING 84 :",
  204. "WARNING 47 :",
  205. "makefile:",
  206. "Makefile:",
  207. "warning: Clock skew detected. Your build may be incomplete.",
  208. "/usr/openwin/include/GL/[^:]+:",
  209. "bind_at_load",
  210. "XrmQGetResource",
  211. "IceFlush",
  212. "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
  213. "ld32: WARNING 85: definition of dataKey in",
  214. "cc: warning 422: Unknown option \"\\+b",
  215. "_with_warning_C",
  216. 0
  217. };
  218. static const char* cmCTestMemCheckResultStrings[] = {
  219. "ABR",
  220. "ABW",
  221. "ABWL",
  222. "COR",
  223. "EXU",
  224. "FFM",
  225. "FIM",
  226. "FMM",
  227. "FMR",
  228. "FMW",
  229. "FUM",
  230. "IPR",
  231. "IPW",
  232. "MAF",
  233. "MLK",
  234. "MPK",
  235. "NPR",
  236. "ODS",
  237. "PAR",
  238. "PLK",
  239. "UMC",
  240. "UMR",
  241. 0
  242. };
  243. static const char* cmCTestMemCheckResultLongStrings[] = {
  244. "Threading Problem",
  245. "ABW",
  246. "ABWL",
  247. "COR",
  248. "EXU",
  249. "FFM",
  250. "FIM",
  251. "Mismatched deallocation",
  252. "FMR",
  253. "FMW",
  254. "FUM",
  255. "IPR",
  256. "IPW",
  257. "MAF",
  258. "Memory Leak",
  259. "Potential Memory Leak",
  260. "NPR",
  261. "ODS",
  262. "Invalid syscall param",
  263. "PLK",
  264. "Uninitialized Memory Conditional",
  265. "Uninitialized Memory Read",
  266. 0
  267. };
  268. std::string cmCTest::MakeXMLSafe(const std::string& str)
  269. {
  270. cmOStringStream ost;
  271. // By uncommenting the lcnt code, it will put newline every 120 characters
  272. //int lcnt = 0;
  273. for (std::string::size_type pos = 0; pos < str.size(); pos ++ )
  274. {
  275. unsigned char ch = str[pos];
  276. if ( (ch > 126 || ch < 32) && ch != 9 && ch != 10 && ch != 13 )
  277. {
  278. char buffer[33];
  279. sprintf(buffer, "&lt;%d&gt;", (int)ch);
  280. //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
  281. ost << buffer;
  282. //lcnt += 4;
  283. }
  284. else
  285. {
  286. switch ( ch )
  287. {
  288. case '&': ost << "&amp;"; break;
  289. case '<': ost << "&lt;"; break;
  290. case '>': ost << "&gt;"; break;
  291. case '\n': ost << "\n";
  292. //lcnt = 0;
  293. break;
  294. default: ost << ch;
  295. }
  296. //lcnt ++;
  297. }
  298. //if ( lcnt > 120 )
  299. // {
  300. // ost << "\n";
  301. // lcnt = 0;
  302. // }
  303. }
  304. return ost.str();
  305. }
  306. std::string cmCTest::MakeURLSafe(const std::string& str)
  307. {
  308. cmOStringStream ost;
  309. char buffer[10];
  310. for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
  311. {
  312. unsigned char ch = str[pos];
  313. if ( ( ch > 126 || ch < 32 ||
  314. ch == '&' ||
  315. ch == '%' ||
  316. ch == '+' ||
  317. ch == '=' ||
  318. ch == '@'
  319. ) && ch != 9 )
  320. {
  321. sprintf(buffer, "%02x;", (unsigned int)ch);
  322. ost << buffer;
  323. }
  324. else
  325. {
  326. ost << ch;
  327. }
  328. }
  329. return ost.str();
  330. }
  331. bool TryExecutable(const char *dir, const char *file,
  332. std::string *fullPath, const char *subdir)
  333. {
  334. // try current directory
  335. std::string tryPath;
  336. if (dir && strcmp(dir,""))
  337. {
  338. tryPath = dir;
  339. tryPath += "/";
  340. }
  341. if (subdir && strcmp(subdir,""))
  342. {
  343. tryPath += subdir;
  344. tryPath += "/";
  345. }
  346. tryPath += file;
  347. if(cmSystemTools::FileExists(tryPath.c_str()))
  348. {
  349. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  350. return true;
  351. }
  352. tryPath += cmSystemTools::GetExecutableExtension();
  353. if(cmSystemTools::FileExists(tryPath.c_str()))
  354. {
  355. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  356. return true;
  357. }
  358. return false;
  359. }
  360. cmCTest::cmCTest()
  361. {
  362. m_ForceNewCTestProcess = false;
  363. m_TomorrowTag = false;
  364. m_BuildNoCMake = false;
  365. m_BuildNoClean = false;
  366. m_BuildTwoConfig = false;
  367. m_UseIncludeRegExp = false;
  368. m_UseExcludeRegExp = false;
  369. m_UseExcludeRegExpFirst = false;
  370. m_Verbose = false;
  371. m_DartMode = false;
  372. m_ShowOnly = false;
  373. m_RunConfigurationScript = false;
  374. m_TestModel = cmCTest::EXPERIMENTAL;
  375. m_InteractiveDebugMode = true;
  376. m_TimeOut = 0;
  377. m_CompatibilityMode = 0;
  378. int cc;
  379. for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
  380. {
  381. m_Tests[cc] = 0;
  382. }
  383. m_ShortDateFormat = true;
  384. m_MaximumPassedTestResultSize = 100 * 1024;
  385. m_MaximumFailedTestResultSize = 200 * 1024;
  386. this->ScriptHandler = new cmCTestScriptHandler;
  387. }
  388. cmCTest::~cmCTest()
  389. {
  390. delete this->ScriptHandler;
  391. }
  392. int cmCTest::Initialize()
  393. {
  394. if(!m_InteractiveDebugMode)
  395. {
  396. this->BlockTestErrorDiagnostics();
  397. }
  398. m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
  399. cmSystemTools::ConvertToUnixSlashes(m_ToplevelPath);
  400. if ( !this->ReadCustomConfigurationFileTree(m_ToplevelPath.c_str()) )
  401. {
  402. return 0;
  403. }
  404. this->UpdateCTestConfiguration();
  405. if ( m_DartMode )
  406. {
  407. std::string testingDir = m_ToplevelPath + "/Testing";
  408. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  409. {
  410. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  411. {
  412. std::cerr << "File " << testingDir << " is in the place of the testing directory"
  413. << std::endl;
  414. return 0;
  415. }
  416. }
  417. else
  418. {
  419. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  420. {
  421. std::cerr << "Cannot create directory " << testingDir
  422. << std::endl;
  423. return 0;
  424. }
  425. }
  426. std::string tagfile = testingDir + "/TAG";
  427. std::ifstream tfin(tagfile.c_str());
  428. std::string tag;
  429. time_t tctime = time(0);
  430. if ( m_TomorrowTag )
  431. {
  432. tctime += ( 24 * 60 * 60 );
  433. }
  434. struct tm *lctime = gmtime(&tctime);
  435. if ( tfin && cmSystemTools::GetLineFromStream(tfin, tag) )
  436. {
  437. int year = 0;
  438. int mon = 0;
  439. int day = 0;
  440. int hour = 0;
  441. int min = 0;
  442. sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
  443. &year, &mon, &day, &hour, &min);
  444. if ( year != lctime->tm_year + 1900 ||
  445. mon != lctime->tm_mon+1 ||
  446. day != lctime->tm_mday )
  447. {
  448. tag = "";
  449. }
  450. std::string tagmode;
  451. if ( cmSystemTools::GetLineFromStream(tfin, tagmode) )
  452. {
  453. if ( tagmode.size() > 4 && !( m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST] ))
  454. {
  455. m_TestModel = cmCTest::GetTestModelFromString(tagmode.c_str());
  456. }
  457. }
  458. tfin.close();
  459. }
  460. if ( tag.size() == 0 || m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST])
  461. {
  462. //std::cout << "TestModel: " << this->GetTestModelString() << std::endl;
  463. //std::cout << "TestModel: " << m_TestModel << std::endl;
  464. if ( m_TestModel == cmCTest::NIGHTLY )
  465. {
  466. lctime = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"],
  467. m_Verbose,
  468. m_TomorrowTag);
  469. }
  470. char datestring[100];
  471. sprintf(datestring, "%04d%02d%02d-%02d%02d",
  472. lctime->tm_year + 1900,
  473. lctime->tm_mon+1,
  474. lctime->tm_mday,
  475. lctime->tm_hour,
  476. lctime->tm_min);
  477. tag = datestring;
  478. std::ofstream ofs(tagfile.c_str());
  479. if ( ofs )
  480. {
  481. ofs << tag << std::endl;
  482. ofs << this->GetTestModelString() << std::endl;
  483. }
  484. ofs.close();
  485. std::cout << "Create new tag: " << tag << " - "
  486. << this->GetTestModelString() << std::endl;
  487. }
  488. m_CurrentTag = tag;
  489. }
  490. return 1;
  491. }
  492. void cmCTest::UpdateCTestConfiguration()
  493. {
  494. // parse the dart test file
  495. std::ifstream fin("DartConfiguration.tcl");
  496. if(!fin)
  497. {
  498. return;
  499. }
  500. char buffer[1024];
  501. while ( fin )
  502. {
  503. buffer[0] = 0;
  504. fin.getline(buffer, 1023);
  505. buffer[1023] = 0;
  506. std::string line = ::CleanString(buffer);
  507. if(line.size() == 0)
  508. {
  509. continue;
  510. }
  511. while ( fin && (line[line.size()-1] == '\\') )
  512. {
  513. line = line.substr(0, line.size()-1);
  514. buffer[0] = 0;
  515. fin.getline(buffer, 1023);
  516. buffer[1023] = 0;
  517. line += ::CleanString(buffer);
  518. }
  519. if ( line[0] == '#' )
  520. {
  521. continue;
  522. }
  523. std::string::size_type cpos = line.find_first_of(":");
  524. if ( cpos == line.npos )
  525. {
  526. continue;
  527. }
  528. std::string key = line.substr(0, cpos);
  529. std::string value = ::CleanString(line.substr(cpos+1, line.npos));
  530. m_DartConfiguration[key] = value;
  531. }
  532. fin.close();
  533. if ( m_DartMode )
  534. {
  535. m_TimeOut = atoi(m_DartConfiguration["TimeOut"].c_str());
  536. }
  537. }
  538. void cmCTest::BlockTestErrorDiagnostics()
  539. {
  540. cmSystemTools::PutEnv("DART_TEST_FROM_DART=1");
  541. cmSystemTools::PutEnv("DASHBOARD_TEST_FROM_CTEST=1");
  542. #if defined(_WIN32)
  543. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  544. #endif
  545. }
  546. void cmCTest::SetTestModel(int mode)
  547. {
  548. m_InteractiveDebugMode = false;
  549. m_TestModel = mode;
  550. }
  551. bool cmCTest::SetTest(const char* ttype, bool report)
  552. {
  553. if ( cmSystemTools::LowerCase(ttype) == "all" )
  554. {
  555. m_Tests[cmCTest::ALL_TEST] = 1;
  556. }
  557. else if ( cmSystemTools::LowerCase(ttype) == "start" )
  558. {
  559. m_Tests[cmCTest::START_TEST] = 1;
  560. }
  561. else if ( cmSystemTools::LowerCase(ttype) == "update" )
  562. {
  563. m_Tests[cmCTest::UPDATE_TEST] = 1;
  564. }
  565. else if ( cmSystemTools::LowerCase(ttype) == "configure" )
  566. {
  567. m_Tests[cmCTest::CONFIGURE_TEST] = 1;
  568. }
  569. else if ( cmSystemTools::LowerCase(ttype) == "build" )
  570. {
  571. m_Tests[cmCTest::BUILD_TEST] = 1;
  572. }
  573. else if ( cmSystemTools::LowerCase(ttype) == "test" )
  574. {
  575. m_Tests[cmCTest::TEST_TEST] = 1;
  576. }
  577. else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
  578. {
  579. m_Tests[cmCTest::COVERAGE_TEST] = 1;
  580. }
  581. else if ( cmSystemTools::LowerCase(ttype) == "memcheck" )
  582. {
  583. m_Tests[cmCTest::MEMCHECK_TEST] = 1;
  584. }
  585. else if ( cmSystemTools::LowerCase(ttype) == "notes" )
  586. {
  587. m_Tests[cmCTest::NOTES_TEST] = 1;
  588. }
  589. else if ( cmSystemTools::LowerCase(ttype) == "submit" )
  590. {
  591. m_Tests[cmCTest::SUBMIT_TEST] = 1;
  592. }
  593. else
  594. {
  595. if ( report )
  596. {
  597. std::cerr << "Don't know about test \"" << ttype << "\" yet..." << std::endl;
  598. }
  599. return false;
  600. }
  601. return true;
  602. }
  603. void cmCTest::Finalize()
  604. {
  605. }
  606. std::string cmCTest::FindTheExecutable(const char *exe)
  607. {
  608. std::string fullPath = "";
  609. std::string dir;
  610. std::string file;
  611. cmSystemTools::SplitProgramPath(exe, dir, file);
  612. if(m_ConfigType != "" &&
  613. ::TryExecutable(dir.c_str(), file.c_str(), &fullPath,
  614. m_ConfigType.c_str()))
  615. {
  616. return fullPath;
  617. }
  618. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
  619. {
  620. return fullPath;
  621. }
  622. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
  623. {
  624. return fullPath;
  625. }
  626. if ( m_ConfigType == "" )
  627. {
  628. // No config type, so try to guess it
  629. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
  630. {
  631. return fullPath;
  632. }
  633. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
  634. {
  635. return fullPath;
  636. }
  637. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
  638. {
  639. return fullPath;
  640. }
  641. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
  642. {
  643. return fullPath;
  644. }
  645. }
  646. // if everything else failed, check the users path
  647. if (dir != "")
  648. {
  649. std::string path = cmSystemTools::FindProgram(file.c_str());
  650. if (path != "")
  651. {
  652. return path;
  653. }
  654. }
  655. if ( m_ConfigType != "" )
  656. {
  657. dir += "/";
  658. dir += m_ConfigType;
  659. dir += "/";
  660. dir += file;
  661. cmSystemTools::Error("config type specified on the command line, but test executable not found.",
  662. dir.c_str());
  663. return "";
  664. }
  665. return fullPath;
  666. }
  667. int cmCTest::UpdateDirectory()
  668. {
  669. int count = 0;
  670. std::string::size_type cc, kk;
  671. std::string cvsCommand = m_DartConfiguration["CVSCommand"];
  672. if ( cvsCommand.size() == 0 )
  673. {
  674. std::cerr << "Cannot find CVSCommand key in the DartConfiguration.tcl" << std::endl;
  675. return -1;
  676. }
  677. std::string cvsOptions = m_DartConfiguration["CVSUpdateOptions"];
  678. if ( cvsOptions.size() == 0 )
  679. {
  680. std::cerr << "Cannot find CVSUpdateOptions key in the DartConfiguration.tcl" << std::endl;
  681. return -1;
  682. }
  683. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  684. if ( sourceDirectory.size() == 0 )
  685. {
  686. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  687. return -1;
  688. }
  689. std::string extra_update_opts;
  690. if ( m_TestModel == cmCTest::NIGHTLY )
  691. {
  692. struct tm* t = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"],
  693. m_Verbose,
  694. m_TomorrowTag);
  695. char current_time[1024];
  696. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d UTC",
  697. t->tm_year + 1900,
  698. t->tm_mon + 1,
  699. t->tm_mday,
  700. t->tm_hour,
  701. t->tm_min,
  702. t->tm_sec);
  703. std::string today_update_date = current_time;
  704. extra_update_opts += "-D \"" + today_update_date +"\"";
  705. //std::cout << "Update: " << extra_update_opts << std::endl;
  706. }
  707. std::string command = cvsCommand + " -z3 update " + cvsOptions +
  708. " " + extra_update_opts;
  709. std::ofstream os;
  710. if ( !this->OpenOutputFile(m_CurrentTag, "Update.xml", os) )
  711. {
  712. std::cerr << "Cannot open log file" << std::endl;
  713. }
  714. std::string start_time = this->CurrentTime();
  715. double elapsed_time_start = cmSystemTools::GetTime();
  716. std::string goutput;
  717. int retVal = 0;
  718. bool res = true;
  719. std::ofstream ofs;
  720. if ( !m_ShowOnly )
  721. {
  722. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  723. &retVal, sourceDirectory.c_str(),
  724. m_Verbose, 0 /*m_TimeOut*/);
  725. if ( this->OpenOutputFile("Temporary", "LastUpdate.log", ofs) )
  726. {
  727. ofs << goutput << std::endl;;
  728. }
  729. }
  730. else
  731. {
  732. std::cout << "Update with command: " << command << std::endl;
  733. }
  734. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  735. << "<Update mode=\"Client\" Generator=\"ctest-" << CMake_VERSION_FULL << "\">\n"
  736. << "\t<Site>" << m_DartConfiguration["Site"] << "</Site>\n"
  737. << "\t<BuildName>" << m_DartConfiguration["BuildName"]
  738. << "</BuildName>\n"
  739. << "\t<BuildStamp>" << m_CurrentTag << "-"
  740. << this->GetTestModelString() << "</BuildStamp>" << std::endl;
  741. os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  742. << "\t<UpdateCommand>" << this->MakeXMLSafe(command)
  743. << "</UpdateCommand>\n"
  744. << "\t<UpdateReturnStatus>";
  745. int failed = 0;
  746. if ( !res || retVal )
  747. {
  748. os << "Update error: ";
  749. os << this->MakeXMLSafe(goutput);
  750. std::cerr << "Update with command: " << command << " failed" << std::endl;
  751. failed = 1;
  752. }
  753. os << "</UpdateReturnStatus>" << std::endl;
  754. if ( !failed )
  755. {
  756. std::vector<cmStdString> lines;
  757. cmSystemTools::Split(goutput.c_str(), lines);
  758. std::cout << "Updated; gathering version information" << std::endl;
  759. cmsys::RegularExpression date_author("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  760. cmsys::RegularExpression revision("^revision +([^ ]*) *$");
  761. cmsys::RegularExpression end_of_file("^=============================================================================$");
  762. cmsys::RegularExpression end_of_comment("^----------------------------$");
  763. std::string current_path = "<no-path>";
  764. bool first_file = true;
  765. cmCTest::AuthorsToUpdatesMap authors_files_map;
  766. int num_updated = 0;
  767. int num_modified = 0;
  768. int num_conflicting = 0;
  769. for ( cc= 0 ; cc < lines.size(); cc ++ )
  770. {
  771. const char* line = lines[cc].c_str();
  772. char mod = line[0];
  773. if ( line[1] == ' ' && mod != '?' )
  774. {
  775. if ( mod != 'M' && mod != 'C' )
  776. {
  777. count ++;
  778. }
  779. const char* file = line + 2;
  780. //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl;
  781. std::string logcommand = cvsCommand + " -z3 log -N " + file;
  782. //std::cout << "Do log: " << logcommand << std::endl;
  783. std::string output;
  784. res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output,
  785. &retVal, sourceDirectory.c_str(),
  786. m_Verbose, 0 /*m_TimeOut*/);
  787. if ( ofs )
  788. {
  789. ofs << output << std::endl;
  790. }
  791. if ( res && retVal == 0)
  792. {
  793. //std::cout << output << std::endl;
  794. std::vector<cmStdString> ulines;
  795. cmSystemTools::Split(output.c_str(), ulines);
  796. std::string::size_type sline = 0;
  797. std::string srevision1 = "Unknown";
  798. std::string sdate1 = "Unknown";
  799. std::string sauthor1 = "Unknown";
  800. std::string semail1 = "Unknown";
  801. std::string comment1 = "";
  802. std::string srevision2 = "Unknown";
  803. std::string sdate2 = "Unknown";
  804. std::string sauthor2 = "Unknown";
  805. std::string comment2 = "";
  806. std::string semail2 = "Unknown";
  807. bool have_first = false;
  808. bool have_second = false;
  809. for ( kk = 0; kk < ulines.size(); kk ++ )
  810. {
  811. const char* clp = ulines[kk].c_str();
  812. if ( !have_second && !sline && revision.find(clp) )
  813. {
  814. if ( !have_first )
  815. {
  816. srevision1 = revision.match(1);
  817. }
  818. else
  819. {
  820. srevision2 = revision.match(1);
  821. }
  822. }
  823. else if ( !have_second && !sline && date_author.find(clp) )
  824. {
  825. sline = kk + 1;
  826. if ( !have_first )
  827. {
  828. sdate1 = date_author.match(1);
  829. sauthor1 = date_author.match(2);
  830. }
  831. else
  832. {
  833. sdate2 = date_author.match(1);
  834. sauthor2 = date_author.match(2);
  835. }
  836. }
  837. else if ( sline && end_of_comment.find(clp) || end_of_file.find(clp))
  838. {
  839. if ( !have_first )
  840. {
  841. have_first = true;
  842. }
  843. else if ( !have_second )
  844. {
  845. have_second = true;
  846. }
  847. sline = 0;
  848. }
  849. else if ( sline )
  850. {
  851. if ( !have_first )
  852. {
  853. comment1 += clp;
  854. comment1 += "\n";
  855. }
  856. else
  857. {
  858. comment2 += clp;
  859. comment2 += "\n";
  860. }
  861. }
  862. }
  863. if ( mod == 'M' )
  864. {
  865. comment1 = "Locally modified file\n";
  866. }
  867. if ( mod == 'C' )
  868. {
  869. comment1 = "Conflict while updating\n";
  870. }
  871. std::string path = cmSystemTools::GetFilenamePath(file);
  872. std::string fname = cmSystemTools::GetFilenameName(file);
  873. if ( path != current_path )
  874. {
  875. if ( !first_file )
  876. {
  877. os << "\t</Directory>" << std::endl;
  878. }
  879. else
  880. {
  881. first_file = false;
  882. }
  883. os << "\t<Directory>\n"
  884. << "\t\t<Name>" << path << "</Name>" << std::endl;
  885. }
  886. if ( mod == 'C' )
  887. {
  888. num_conflicting ++;
  889. os << "\t<Conflicting>" << std::endl;
  890. }
  891. else if ( mod == 'M' )
  892. {
  893. num_modified ++;
  894. os << "\t<Modified>" << std::endl;
  895. }
  896. else
  897. {
  898. num_updated ++;
  899. os << "\t<Updated>" << std::endl;
  900. }
  901. if ( srevision2 == "Unknown" )
  902. {
  903. srevision2 = srevision1;
  904. }
  905. os << "\t\t<File Directory=\"" << path << "\">" << fname
  906. << "</File>\n"
  907. << "\t\t<Directory>" << path << "</Directory>\n"
  908. << "\t\t<FullName>" << file << "</FullName>\n"
  909. << "\t\t<CheckinDate>" << sdate1 << "</CheckinDate>\n"
  910. << "\t\t<Author>" << sauthor1 << "</Author>\n"
  911. << "\t\t<Email>" << semail1 << "</Email>\n"
  912. << "\t\t<Log>" << this->MakeXMLSafe(comment1) << "</Log>\n"
  913. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  914. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  915. << std::endl;
  916. if ( srevision2 != srevision1 )
  917. {
  918. os
  919. << "\t\t<Revisions>\n"
  920. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  921. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  922. << "\t\t\t<Author>" << sauthor1<< "</Author>\n"
  923. << "\t\t\t<Date>" << sdate1 << "</Date>\n"
  924. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment1) << "</Comment>\n"
  925. << "\t\t\t<Email>" << semail1 << "</Email>\n"
  926. << "\t\t</Revisions>\n"
  927. << "\t\t<Revisions>\n"
  928. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  929. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  930. << "\t\t\t<Author>" << sauthor2<< "</Author>\n"
  931. << "\t\t\t<Date>" << sdate2 << "</Date>\n"
  932. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment2) << "</Comment>\n"
  933. << "\t\t\t<Email>" << semail2 << "</Email>\n"
  934. << "\t\t</Revisions>" << std::endl;
  935. }
  936. if ( mod == 'C' )
  937. {
  938. os << "\t</Conflicting>" << std::endl;
  939. }
  940. else if ( mod == 'M' )
  941. {
  942. os << "\t</Modified>" << std::endl;
  943. }
  944. else
  945. {
  946. os << "\t</Updated>" << std::endl;
  947. }
  948. cmCTest::UpdateFiles *u = &authors_files_map[sauthor1];
  949. cmCTest::StringPair p;
  950. p.first = path;
  951. p.second = fname;
  952. u->push_back(p);
  953. current_path = path;
  954. }
  955. }
  956. }
  957. if ( num_updated )
  958. {
  959. std::cout << "Found " << num_updated << " updated files" << std::endl;
  960. }
  961. if ( num_modified )
  962. {
  963. std::cout << "Found " << num_modified << " locally modified files"
  964. << std::endl;
  965. }
  966. if ( num_conflicting )
  967. {
  968. std::cout << "Found " << num_conflicting << " conflicting files"
  969. << std::endl;
  970. }
  971. if ( !first_file )
  972. {
  973. os << "\t</Directory>" << std::endl;
  974. }
  975. cmCTest::AuthorsToUpdatesMap::iterator it;
  976. for ( it = authors_files_map.begin();
  977. it != authors_files_map.end();
  978. it ++ )
  979. {
  980. os << "\t<Author>\n"
  981. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  982. cmCTest::UpdateFiles *u = &(it->second);
  983. for ( cc = 0; cc < u->size(); cc ++ )
  984. {
  985. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  986. << (*u)[cc].second << "</File>" << std::endl;
  987. }
  988. os << "\t</Author>" << std::endl;
  989. }
  990. }
  991. //std::cout << "End" << std::endl;
  992. std::string end_time = this->CurrentTime();
  993. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  994. << "<ElapsedMinutes>" <<
  995. static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  996. << "</ElapsedMinutes>"
  997. << "</Update>" << std::endl;
  998. if ( ofs )
  999. {
  1000. ofs.close();
  1001. }
  1002. if (! res || retVal )
  1003. {
  1004. std::cerr << "Error(s) when updating the project" << std::endl;
  1005. std::cerr << "Output: " << goutput << std::endl;
  1006. return -1;
  1007. }
  1008. return count;
  1009. }
  1010. int cmCTest::ConfigureDirectory()
  1011. {
  1012. std::cout << "Configure project" << std::endl;
  1013. std::string cCommand = m_DartConfiguration["ConfigureCommand"];
  1014. if ( cCommand.size() == 0 )
  1015. {
  1016. std::cerr << "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  1017. << std::endl;
  1018. return 1;
  1019. }
  1020. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  1021. if ( buildDirectory.size() == 0 )
  1022. {
  1023. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  1024. return 1;
  1025. }
  1026. double elapsed_time_start = cmSystemTools::GetTime();
  1027. std::string output;
  1028. int retVal = 0;
  1029. int res = 0;
  1030. if ( !m_ShowOnly )
  1031. {
  1032. std::ofstream os;
  1033. if ( !this->OpenOutputFile(m_CurrentTag, "Configure.xml", os) )
  1034. {
  1035. std::cerr << "Cannot open configure file" << std::endl;
  1036. return 1;
  1037. }
  1038. std::string start_time = this->CurrentTime();
  1039. std::ofstream ofs;
  1040. this->OpenOutputFile("Temporary", "LastConfigure.log", ofs);
  1041. res = this->RunMakeCommand(cCommand.c_str(), &output,
  1042. &retVal, buildDirectory.c_str(),
  1043. m_Verbose, 0, ofs);
  1044. if ( ofs )
  1045. {
  1046. ofs.close();
  1047. }
  1048. if ( os )
  1049. {
  1050. this->StartXML(os);
  1051. os << "<Configure>\n"
  1052. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  1053. if ( res == cmsysProcess_State_Exited && retVal )
  1054. {
  1055. os << retVal;
  1056. }
  1057. os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>" << std::endl;
  1058. //std::cout << "End" << std::endl;
  1059. os << "<Log>" << this->MakeXMLSafe(output) << "</Log>" << std::endl;
  1060. std::string end_time = this->CurrentTime();
  1061. os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
  1062. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  1063. << "<ElapsedMinutes>"
  1064. << static_cast<int>(
  1065. (cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  1066. << "</ElapsedMinutes>"
  1067. << "</Configure>" << std::endl;
  1068. this->EndXML(os);
  1069. }
  1070. }
  1071. else
  1072. {
  1073. std::cout << "Configure with command: " << cCommand << std::endl;
  1074. }
  1075. if (! res || retVal )
  1076. {
  1077. std::cerr << "Error(s) when updating the project" << std::endl;
  1078. return 1;
  1079. }
  1080. return 0;
  1081. }
  1082. int cmCTest::BuildDirectory()
  1083. {
  1084. std::cout << "Build project" << std::endl;
  1085. std::string makeCommand = m_DartConfiguration["MakeCommand"];
  1086. if ( makeCommand.size() == 0 )
  1087. {
  1088. std::cerr << "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl;
  1089. return 1;
  1090. }
  1091. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  1092. if ( buildDirectory.size() == 0 )
  1093. {
  1094. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  1095. return 1;
  1096. }
  1097. std::ofstream ofs;
  1098. double elapsed_time_start = cmSystemTools::GetTime();
  1099. if ( !this->OpenOutputFile("Temporary", "LastBuild.log", ofs) )
  1100. {
  1101. std::cerr << "Cannot create LastBuild.log file" << std::endl;
  1102. }
  1103. m_StartBuild = this->CurrentTime();
  1104. std::string output;
  1105. int retVal = 0;
  1106. int res = cmsysProcess_State_Exited;
  1107. if ( !m_ShowOnly )
  1108. {
  1109. res = this->RunMakeCommand(makeCommand.c_str(), &output,
  1110. &retVal, buildDirectory.c_str(),
  1111. m_Verbose, 0, ofs);
  1112. }
  1113. else
  1114. {
  1115. std::cout << "Build with command: " << makeCommand << std::endl;
  1116. }
  1117. m_EndBuild = this->CurrentTime();
  1118. double elapsed_build_time = cmSystemTools::GetTime() - elapsed_time_start;
  1119. if (res != cmsysProcess_State_Exited || retVal )
  1120. {
  1121. std::cerr << "Error(s) when building project" << std::endl;
  1122. }
  1123. if ( ofs )
  1124. {
  1125. ofs.close();
  1126. }
  1127. tm_VectorOfStrings::size_type cc;
  1128. if ( m_DartConfiguration["SourceDirectory"].size() > 20 ||
  1129. m_DartConfiguration["BuildDirectory"].size() > 20 )
  1130. {
  1131. std::string srcdir = m_DartConfiguration["SourceDirectory"] + "/";
  1132. std::string bindir = m_DartConfiguration["BuildDirectory"] + "/";
  1133. std::string srcdirrep;
  1134. std::string bindirrep;
  1135. for ( cc = srcdir.size()-2; cc > 0; cc -- )
  1136. {
  1137. if ( srcdir[cc] == '/' )
  1138. {
  1139. srcdirrep = srcdir.c_str() + cc;
  1140. srcdirrep = "/..." + srcdirrep;
  1141. srcdir = srcdir.substr(0, cc+1);
  1142. break;
  1143. }
  1144. }
  1145. for ( cc = bindir.size()-2; cc > 0; cc -- )
  1146. {
  1147. if ( bindir[cc] == '/' )
  1148. {
  1149. bindirrep = bindir.c_str() + cc;
  1150. bindirrep = "/..." + bindirrep;
  1151. bindir = bindir.substr(0, cc+1);
  1152. break;
  1153. }
  1154. }
  1155. cmSystemTools::ReplaceString(output, srcdir.c_str(), "/.../"); //srcdirrep.c_str());
  1156. cmSystemTools::ReplaceString(output, bindir.c_str(), "/.../"); //bindirrep.c_str());
  1157. }
  1158. // Parsing of output for errors and warnings.
  1159. std::vector<cmStdString> lines;
  1160. cmSystemTools::Split(output.c_str(), lines);
  1161. // Lines are marked:
  1162. // 0 - nothing
  1163. // 1 - error
  1164. // > 1 - warning
  1165. std::vector<int> markedLines(lines.size(), 0);
  1166. // Errors
  1167. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  1168. {
  1169. m_CustomErrorMatches.push_back(cmCTestErrorMatches[cc]);
  1170. }
  1171. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  1172. {
  1173. m_CustomErrorExceptions.push_back(cmCTestErrorExceptions[cc]);
  1174. }
  1175. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  1176. {
  1177. m_CustomWarningMatches.push_back(cmCTestWarningMatches[cc]);
  1178. }
  1179. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  1180. {
  1181. m_CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]);
  1182. }
  1183. for ( cc = 0; cc < m_CustomErrorMatches.size(); cc ++ )
  1184. {
  1185. cmsys::RegularExpression re(m_CustomErrorMatches[cc].c_str());
  1186. cmCTest::tm_VectorOfStrings::size_type kk;
  1187. for ( kk = 0; kk < lines.size(); kk ++ )
  1188. {
  1189. if ( re.find(lines[kk]) )
  1190. {
  1191. markedLines[kk] = 1;
  1192. }
  1193. }
  1194. }
  1195. // Warnings
  1196. for ( cc = 0; cc < m_CustomWarningMatches.size(); cc ++ )
  1197. {
  1198. cmsys::RegularExpression re(m_CustomWarningMatches[cc].c_str());
  1199. cmCTest::tm_VectorOfStrings::size_type kk;
  1200. for ( kk = 0; kk < lines.size(); kk ++ )
  1201. {
  1202. if ( re.find(lines[kk]) )
  1203. {
  1204. markedLines[kk] += 2;
  1205. }
  1206. }
  1207. }
  1208. // Errors exceptions
  1209. for ( cc = 0; cc < m_CustomErrorExceptions.size(); cc ++ )
  1210. {
  1211. cmsys::RegularExpression re(m_CustomErrorExceptions[cc].c_str());
  1212. std::vector<int>::size_type kk;
  1213. for ( kk =0; kk < markedLines.size(); kk ++ )
  1214. {
  1215. if ( markedLines[kk] == 1 )
  1216. {
  1217. if ( re.find(lines[kk]) )
  1218. {
  1219. markedLines[kk] = 0;
  1220. }
  1221. }
  1222. }
  1223. }
  1224. // Warning exceptions
  1225. for ( cc = 0; cc < m_CustomWarningExceptions.size(); cc ++ )
  1226. {
  1227. cmsys::RegularExpression re(m_CustomWarningExceptions[cc].c_str());
  1228. std::vector<int>::size_type kk;
  1229. for ( kk =0; kk < markedLines.size(); kk ++ )
  1230. {
  1231. if ( markedLines[kk] > 1 )
  1232. {
  1233. if ( re.find(lines[kk]) )
  1234. {
  1235. markedLines[kk] = 0;
  1236. }
  1237. }
  1238. }
  1239. }
  1240. std::vector<cmCTestBuildErrorWarning> errorsWarnings;
  1241. int errors = 0;
  1242. int warnings = 0;
  1243. std::vector<int>::size_type kk;
  1244. cmCTestBuildErrorWarning errorwarning;
  1245. for ( kk =0; kk < markedLines.size(); kk ++ )
  1246. {
  1247. errorwarning.m_LineNumber = -1;
  1248. bool found = false;
  1249. if ( markedLines[kk] == 1 )
  1250. {
  1251. //std::cout << "Error: " << lines[kk] << std::endl;
  1252. errorwarning.m_Error = true;
  1253. found = true;
  1254. }
  1255. else if ( markedLines[kk] > 1 )
  1256. {
  1257. //std::cout << "Warning: " << lines[kk] << std::endl;
  1258. errorwarning.m_Error = false;
  1259. found = true;
  1260. }
  1261. if ( found )
  1262. {
  1263. errorwarning.m_LogLine = static_cast<int>(kk+1);
  1264. errorwarning.m_Text = lines[kk];
  1265. errorwarning.m_PreContext = "";
  1266. errorwarning.m_PostContext = "";
  1267. std::vector<int>::size_type jj;
  1268. std::vector<int>::size_type ll = 0;
  1269. if ( kk > 6 )
  1270. {
  1271. ll = kk - 6;
  1272. }
  1273. for ( jj = kk-1;
  1274. jj > 0 && jj > ll && markedLines[jj] != markedLines[kk];
  1275. jj -- );
  1276. while ( markedLines[jj] == markedLines[kk] && jj < kk )
  1277. {
  1278. jj ++;
  1279. }
  1280. for (; jj < kk; jj ++ )
  1281. {
  1282. errorwarning.m_PreContext += lines[jj] + "\n";
  1283. }
  1284. for ( jj = kk+1;
  1285. jj < lines.size() && jj < kk + 7 && markedLines[jj] != markedLines[kk];
  1286. jj ++ )
  1287. {
  1288. errorwarning.m_PostContext += lines[jj] + "\n";
  1289. }
  1290. errorsWarnings.push_back(errorwarning);
  1291. if ( errorwarning.m_Error )
  1292. {
  1293. errors ++;
  1294. }
  1295. else
  1296. {
  1297. warnings ++;
  1298. }
  1299. }
  1300. }
  1301. std::cout << " " << errors << " Compiler errors" << std::endl;
  1302. std::cout << " " << warnings << " Compiler warnings" << std::endl;
  1303. if( !this->OpenOutputFile(m_CurrentTag, "Build.xml", ofs) )
  1304. {
  1305. std::cerr << "Cannot create build XML file" << std::endl;
  1306. return 1;
  1307. }
  1308. this->GenerateDartBuildOutput(ofs, errorsWarnings, elapsed_build_time);
  1309. return 0;
  1310. }
  1311. int cmCTest::CoverageDirectory()
  1312. {
  1313. std::cout << "Performing coverage" << std::endl;
  1314. double elapsed_time_start = cmSystemTools::GetTime();
  1315. cmCTest::tm_VectorOfStrings files;
  1316. cmCTest::tm_VectorOfStrings cfiles;
  1317. cmCTest::tm_VectorOfStrings cdirs;
  1318. bool done = false;
  1319. std::string::size_type cc;
  1320. std::string glob;
  1321. std::map<std::string, std::string> allsourcefiles;
  1322. std::map<std::string, std::string> allbinaryfiles;
  1323. std::string start_time = this->CurrentTime();
  1324. // Find all source files.
  1325. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  1326. if ( sourceDirectory.size() == 0 )
  1327. {
  1328. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  1329. return 1;
  1330. }
  1331. std::string coverageCommand = m_DartConfiguration["CoverageCommand"];
  1332. if ( coverageCommand.size() == 0 )
  1333. {
  1334. std::cerr << "Coverage command not defined in DartConfiguration.tcl" << std::endl;
  1335. return 1;
  1336. }
  1337. cdirs.push_back(sourceDirectory);
  1338. while ( !done )
  1339. {
  1340. if ( cdirs.size() <= 0 )
  1341. {
  1342. break;
  1343. }
  1344. glob = cdirs[cdirs.size()-1] + "/*";
  1345. //std::cout << "Glob: " << glob << std::endl;
  1346. cdirs.pop_back();
  1347. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1348. {
  1349. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1350. {
  1351. allsourcefiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1352. }
  1353. }
  1354. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1355. {
  1356. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1357. {
  1358. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1359. {
  1360. cdirs.push_back(cfiles[cc]);
  1361. }
  1362. }
  1363. }
  1364. }
  1365. // find all binary files
  1366. cdirs.push_back(cmSystemTools::GetCurrentWorkingDirectory());
  1367. while ( !done )
  1368. {
  1369. if ( cdirs.size() <= 0 )
  1370. {
  1371. break;
  1372. }
  1373. glob = cdirs[cdirs.size()-1] + "/*";
  1374. //std::cout << "Glob: " << glob << std::endl;
  1375. cdirs.pop_back();
  1376. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1377. {
  1378. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1379. {
  1380. allbinaryfiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1381. }
  1382. }
  1383. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1384. {
  1385. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1386. {
  1387. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1388. {
  1389. cdirs.push_back(cfiles[cc]);
  1390. }
  1391. }
  1392. }
  1393. }
  1394. std::map<std::string, std::string>::iterator sit;
  1395. for ( sit = allbinaryfiles.begin(); sit != allbinaryfiles.end(); sit ++ )
  1396. {
  1397. const std::string& fname = sit->second;
  1398. //std::cout << "File: " << fname << std::endl;
  1399. if ( strcmp(fname.substr(fname.size()-3, 3).c_str(), ".da") == 0 )
  1400. {
  1401. files.push_back(fname);
  1402. }
  1403. }
  1404. if ( files.size() == 0 )
  1405. {
  1406. std::cerr << "Cannot find any coverage information files (.da)" << std::endl;
  1407. return 1;
  1408. }
  1409. std::ofstream log;
  1410. if (!this->OpenOutputFile("Temporary", "Coverage.log", log))
  1411. {
  1412. std::cerr << "Cannot open log file" << std::endl;
  1413. return 1;
  1414. }
  1415. log.close();
  1416. if (!this->OpenOutputFile(m_CurrentTag, "Coverage.xml", log))
  1417. {
  1418. std::cerr << "Cannot open log file" << std::endl;
  1419. return 1;
  1420. }
  1421. std::string opath = m_ToplevelPath + "/Testing/Temporary/Coverage";
  1422. cmSystemTools::MakeDirectory(opath.c_str());
  1423. cfiles.clear();
  1424. cmCTest::tm_VectorOfStrings ncfiles;
  1425. cmCTest::tm_VectorOfStrings missing_files;
  1426. for ( cc = 0; cc < files.size(); cc ++ )
  1427. {
  1428. std::string currPath = cmSystemTools::GetFilenamePath(files[cc]);
  1429. std::string command = coverageCommand + " -o \"" + currPath + "\" -l \"" + files[cc] + "\"";
  1430. std::string output;
  1431. int retVal = 0;
  1432. if ( m_Verbose )
  1433. {
  1434. std::cerr << "Run gcov on " << files[cc] << " in directory: " << currPath.c_str() << std::endl;
  1435. }
  1436. //std::cout << " --- Run [" << command << "]" << std::endl;
  1437. bool res = true;
  1438. if ( !m_ShowOnly )
  1439. {
  1440. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  1441. &retVal, currPath.c_str(),
  1442. m_Verbose, 0 /*m_TimeOut*/);
  1443. }
  1444. if ( res && retVal == 0 )
  1445. {
  1446. //std::cout << " - done" << std::endl;
  1447. glob = currPath + "/*";
  1448. if ( !cmSystemTools::SimpleGlob(glob, ncfiles, 1) )
  1449. {
  1450. std::cerr << "Cannot found any coverage files" << std::endl;
  1451. return 1;
  1452. }
  1453. cfiles.insert(cfiles.end(), ncfiles.begin(), ncfiles.end());
  1454. std::vector<cmStdString> gcovlines;
  1455. cmSystemTools::Split(output.c_str(), gcovlines);
  1456. std::vector<cmStdString>::iterator git;
  1457. const char* message = "Could not open source file";
  1458. for ( git = gcovlines.begin(); git != gcovlines.end(); ++git )
  1459. {
  1460. if ( strncmp(git->c_str(), message, strlen(message) ) == 0 )
  1461. {
  1462. std::cerr << "Problem: " << git->c_str() << std::endl;
  1463. missing_files.push_back(git->c_str() + strlen(message));
  1464. }
  1465. }
  1466. }
  1467. else
  1468. {
  1469. std::cerr << "Run gcov on " << files[cc] << std::flush;
  1470. std::cerr << " [" << command << "]" << std::endl;
  1471. std::cerr << " - fail" << std::endl;
  1472. }
  1473. }
  1474. files.clear();
  1475. std::map<std::string, cmCTest::tm_VectorOfStrings > sourcefiles;
  1476. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1477. {
  1478. std::string& fname = cfiles[cc];
  1479. // std::cout << "File: " << fname << std::endl;
  1480. if ( strcmp(fname.substr(fname.size()-5, 5).c_str(), ".gcov") == 0 )
  1481. {
  1482. files.push_back(fname);
  1483. std::string::size_type pos = fname.find(".da.");
  1484. std::string::size_type pos2 = fname.find(".da##");
  1485. if(pos2 != fname.npos)
  1486. {
  1487. pos = pos2+1;
  1488. }
  1489. if ( pos != fname.npos )
  1490. {
  1491. pos += 4;
  1492. std::string::size_type epos = fname.size() - pos - strlen(".gcov");
  1493. std::string nf = fname.substr(pos, epos);
  1494. //std::cout << "Substring: " << nf << std::endl;
  1495. if ( allsourcefiles.find(nf) != allsourcefiles.end() ||
  1496. allbinaryfiles.find(nf) != allbinaryfiles.end() )
  1497. {
  1498. cmCTest::tm_VectorOfStrings &cvec = sourcefiles[nf];
  1499. cvec.push_back(fname);
  1500. }
  1501. }
  1502. }
  1503. }
  1504. // for ( cc = 0; cc < files.size(); cc ++ )
  1505. // {
  1506. // std::cout << "File: " << files[cc] << std::endl;
  1507. // }
  1508. if ( missing_files.size() > 0 )
  1509. {
  1510. std::cout << "---------------------------------------------------------------" << std::endl;
  1511. std::cout << "The following files were missing:" << std::endl;
  1512. for ( cc = 0; cc < missing_files.size(); cc ++ )
  1513. {
  1514. std::cout << "File: " << missing_files[cc] << std::endl;
  1515. }
  1516. std::cout << "---------------------------------------------------------------" << std::endl;
  1517. }
  1518. std::map<std::string, cmCTest::tm_VectorOfStrings >::iterator it;
  1519. cmCTest::tm_CoverageMap coverageresults;
  1520. this->StartXML(log);
  1521. log << "<Coverage>\n"
  1522. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  1523. int total_tested = 0;
  1524. int total_untested = 0;
  1525. for ( it = sourcefiles.begin(); it != sourcefiles.end(); it ++ )
  1526. {
  1527. //std::cerr << "Source file: " << it->first << std::endl;
  1528. cmCTest::tm_VectorOfStrings &gfiles = it->second;
  1529. for ( cc = 0; cc < gfiles.size(); cc ++ )
  1530. {
  1531. int do_coverage = 1;
  1532. std::string coverage_dir = cmSystemTools::GetFilenamePath(gfiles[cc].c_str());
  1533. std::string builDir = m_DartConfiguration["BuildDirectory"];
  1534. do
  1535. {
  1536. std::string coverage_file = coverage_dir + "/.NoDartCoverage";
  1537. if ( cmSystemTools::FileExists(coverage_file.c_str()) )
  1538. {
  1539. do_coverage = 0;
  1540. break;
  1541. }
  1542. // is there a parent directory we can check
  1543. std::string::size_type pos = coverage_dir.rfind('/');
  1544. // if we could not find the directory return 0
  1545. if(pos == std::string::npos)
  1546. {
  1547. break;
  1548. }
  1549. coverage_dir = coverage_dir.substr(0, pos);
  1550. }
  1551. while (coverage_dir.size() >= builDir.size());
  1552. if ( !do_coverage )
  1553. {
  1554. continue;
  1555. }
  1556. //std::cout << "\t" << gfiles[cc] << std::endl;
  1557. std::ifstream ifile(gfiles[cc].c_str());
  1558. if ( !ifile )
  1559. {
  1560. std::cerr << "Cannot open file: " << gfiles[cc].c_str() << std::endl;
  1561. }
  1562. ifile.seekg (0, std::ios::end);
  1563. int length = ifile.tellg();
  1564. ifile.seekg (0, std::ios::beg);
  1565. char *buffer = new char [ length + 1 ];
  1566. ifile.read(buffer, length);
  1567. buffer [length] = 0;
  1568. //std::cout << "Read: " << buffer << std::endl;
  1569. std::vector<cmStdString> lines;
  1570. cmSystemTools::Split(buffer, lines);
  1571. delete [] buffer;
  1572. cmCTest::cmCTestCoverage& cov = coverageresults[it->first];
  1573. std::vector<int>& covlines = cov.m_Lines;
  1574. if ( cov.m_FullPath == "" )
  1575. {
  1576. covlines.insert(covlines.begin(), lines.size(), -1);
  1577. if ( allsourcefiles.find(it->first) != allsourcefiles.end() )
  1578. {
  1579. cov.m_FullPath = allsourcefiles[it->first];
  1580. }
  1581. else if ( allbinaryfiles.find(it->first) != allbinaryfiles.end() )
  1582. {
  1583. cov.m_FullPath = allbinaryfiles[it->first];
  1584. }
  1585. cov.m_AbsolutePath = cov.m_FullPath;
  1586. std::string src_dir = m_DartConfiguration["SourceDirectory"];
  1587. if ( src_dir[src_dir.size()-1] != '/' )
  1588. {
  1589. src_dir = src_dir + "/";
  1590. }
  1591. std::string::size_type spos = cov.m_FullPath.find(src_dir);
  1592. if ( spos == 0 )
  1593. {
  1594. cov.m_FullPath = std::string("./") + cov.m_FullPath.substr(src_dir.size());
  1595. }
  1596. else
  1597. {
  1598. //std::cerr << "Compare -- " << cov.m_FullPath << std::endl;
  1599. //std::cerr << " -- " << src_dir << std::endl;
  1600. cov.m_Show = false;
  1601. continue;
  1602. }
  1603. cov.m_Show = true;
  1604. }
  1605. std::string::size_type kk;
  1606. // std::cerr << "number of lines " << lines.size() << "\n";
  1607. for ( kk = 0; kk < lines.size(); kk ++ )
  1608. {
  1609. std::string& line = lines[kk];
  1610. //std::cerr << line << "\n";
  1611. std::string sub1 = line.substr(0, strlen(" #####"));
  1612. std::string sub2 = line.substr(0, strlen(" ######"));
  1613. int count = atoi(sub2.c_str());
  1614. if ( sub1.compare(" #####") == 0 ||
  1615. sub2.compare(" ######") == 0 )
  1616. {
  1617. if ( covlines[kk] == -1 )
  1618. {
  1619. covlines[kk] = 0;
  1620. }
  1621. cov.m_UnTested ++;
  1622. //std::cout << "Untested - ";
  1623. }
  1624. else if ( count > 0 )
  1625. {
  1626. if ( covlines[kk] == -1 )
  1627. {
  1628. covlines[kk] = 0;
  1629. }
  1630. cov.m_Tested ++;
  1631. covlines[kk] ++;
  1632. //std::cout << "Tested[" << count << "] - ";
  1633. }
  1634. //std::cout << line << std::endl;
  1635. }
  1636. }
  1637. }
  1638. //std::cerr << "Finalizing" << std::endl;
  1639. cmCTest::tm_CoverageMap::iterator cit;
  1640. int ccount = 0;
  1641. std::ofstream cfileoutput;
  1642. int cfileoutputcount = 0;
  1643. char cfileoutputname[100];
  1644. std::string local_start_time = this->CurrentTime();
  1645. std::string local_end_time;
  1646. for ( cit = coverageresults.begin(); cit != coverageresults.end(); cit ++ )
  1647. {
  1648. cmCTest::cmCTestCoverage &cov = cit->second;
  1649. if ( !cov.m_Show )
  1650. {
  1651. continue;
  1652. }
  1653. // Check if we should ignore the directory, if we find a NoDartCoverage
  1654. // file in it or any of its parents
  1655. int do_coverage = 1;
  1656. std::string coverage_dir = cmSystemTools::GetFilenamePath(cov.m_AbsolutePath.c_str());
  1657. do
  1658. {
  1659. std::string coverage_file = coverage_dir + "/.NoDartCoverage";
  1660. if ( cmSystemTools::FileExists(coverage_file.c_str()) )
  1661. {
  1662. do_coverage = 0;
  1663. break;
  1664. }
  1665. // is there a parent directory we can check
  1666. std::string::size_type pos = coverage_dir.rfind('/');
  1667. // if we could not find the directory return 0
  1668. if(pos == std::string::npos)
  1669. {
  1670. break;
  1671. }
  1672. coverage_dir = coverage_dir.substr(0, pos);
  1673. }
  1674. while (coverage_dir.size() >= sourceDirectory.size());
  1675. if (!do_coverage)
  1676. {
  1677. if ( m_Verbose )
  1678. {
  1679. std::cout << "Ignore file: " << cov.m_FullPath.c_str() << std::endl;
  1680. }
  1681. continue;
  1682. }
  1683. if ( ccount == 100 )
  1684. {
  1685. local_end_time = this->CurrentTime();
  1686. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1687. << "</CoverageLog>" << std::endl;
  1688. this->EndXML(cfileoutput);
  1689. cfileoutput.close();
  1690. std::cout << "Close file: " << cfileoutputname << std::endl;
  1691. ccount = 0;
  1692. }
  1693. if ( ccount == 0 )
  1694. {
  1695. sprintf(cfileoutputname, "CoverageLog-%d.xml", cfileoutputcount++);
  1696. std::cout << "Open file: " << cfileoutputname << std::endl;
  1697. if (!this->OpenOutputFile(m_CurrentTag, cfileoutputname, cfileoutput))
  1698. {
  1699. std::cerr << "Cannot open log file: " << cfileoutputname << std::endl;
  1700. return 1;
  1701. }
  1702. local_start_time = this->CurrentTime();
  1703. this->StartXML(cfileoutput);
  1704. cfileoutput << "<CoverageLog>\n"
  1705. << "\t<StartDateTime>" << local_start_time << "</StartDateTime>" << std::endl;
  1706. }
  1707. //std::cerr << "Final process of Source file: " << cit->first << std::endl;
  1708. cov.m_UnTested = 0;
  1709. cov.m_Tested = 0;
  1710. for ( cc = 0; cc < cov.m_Lines.size(); cc ++ )
  1711. {
  1712. if ( cov.m_Lines[cc] == 0 )
  1713. {
  1714. cov.m_UnTested ++;
  1715. }
  1716. else if ( cov.m_Lines[cc] > 0 )
  1717. {
  1718. cov.m_Tested ++;
  1719. }
  1720. }
  1721. std::ifstream ifile(cov.m_AbsolutePath.c_str());
  1722. if ( !ifile )
  1723. {
  1724. std::cerr << "Cannot open file: " << cov.m_FullPath.c_str() << std::endl;
  1725. }
  1726. ifile.seekg (0, std::ios::end);
  1727. int length = ifile.tellg();
  1728. ifile.seekg (0, std::ios::beg);
  1729. char *buffer = new char [ length + 1 ];
  1730. ifile.read(buffer, length);
  1731. buffer [length] = 0;
  1732. //std::cout << "Read: " << buffer << std::endl;
  1733. std::vector<cmStdString> lines;
  1734. cmSystemTools::Split(buffer, lines);
  1735. delete [] buffer;
  1736. cfileoutput << "\t<File Name=\"" << cit->first << "\" FullPath=\""
  1737. << cov.m_FullPath << "\">\n"
  1738. << "\t\t<Report>" << std::endl;
  1739. for ( cc = 0; cc < lines.size(); cc ++ )
  1740. {
  1741. cfileoutput << "\t\t<Line Number=\""
  1742. << static_cast<int>(cc) << "\" Count=\""
  1743. << cov.m_Lines[cc] << "\">"
  1744. << cmCTest::MakeXMLSafe(lines[cc]) << "</Line>" << std::endl;
  1745. }
  1746. cfileoutput << "\t\t</Report>\n"
  1747. << "\t</File>" << std::endl;
  1748. total_tested += cov.m_Tested;
  1749. total_untested += cov.m_UnTested;
  1750. float cper = 0;
  1751. float cmet = 0;
  1752. if ( total_tested + total_untested > 0 && (cov.m_Tested + cov.m_UnTested) > 0)
  1753. {
  1754. cper = (100 * SAFEDIV(static_cast<float>(cov.m_Tested),
  1755. static_cast<float>(cov.m_Tested + cov.m_UnTested)));
  1756. cmet = ( SAFEDIV(static_cast<float>(cov.m_Tested + 10),
  1757. static_cast<float>(cov.m_Tested + cov.m_UnTested + 10)));
  1758. }
  1759. log << "\t<File Name=\"" << cit->first << "\" FullPath=\"" << cov.m_FullPath
  1760. << "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n"
  1761. << "\t\t<LOCTested>" << cov.m_Tested << "</LOCTested>\n"
  1762. << "\t\t<LOCUnTested>" << cov.m_UnTested << "</LOCUnTested>\n"
  1763. << "\t\t<PercentCoverage>";
  1764. log.setf(std::ios::fixed, std::ios::floatfield);
  1765. log.precision(2);
  1766. log << (cper) << "</PercentCoverage>\n"
  1767. << "\t\t<CoverageMetric>";
  1768. log.setf(std::ios::fixed, std::ios::floatfield);
  1769. log.precision(2);
  1770. log << (cmet) << "</CoverageMetric>\n"
  1771. << "\t</File>" << std::endl;
  1772. ccount ++;
  1773. }
  1774. if ( ccount > 0 )
  1775. {
  1776. local_end_time = this->CurrentTime();
  1777. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1778. << "</CoverageLog>" << std::endl;
  1779. this->EndXML(cfileoutput);
  1780. cfileoutput.close();
  1781. }
  1782. int total_lines = total_tested + total_untested;
  1783. float percent_coverage = 100 * SAFEDIV(static_cast<float>(total_tested),
  1784. static_cast<float>(total_lines));
  1785. if ( total_lines == 0 )
  1786. {
  1787. percent_coverage = 0;
  1788. }
  1789. std::string end_time = this->CurrentTime();
  1790. log << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
  1791. << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
  1792. << "\t<LOC>" << total_lines << "</LOC>\n"
  1793. << "\t<PercentCoverage>";
  1794. log.setf(std::ios::fixed, std::ios::floatfield);
  1795. log.precision(2);
  1796. log << (percent_coverage)<< "</PercentCoverage>\n"
  1797. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n";
  1798. log << "<ElapsedMinutes>" <<
  1799. static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start)/6)/10.0
  1800. << "</ElapsedMinutes>"
  1801. << "</Coverage>" << std::endl;
  1802. this->EndXML(log);
  1803. std::cout << "\tCovered LOC: " << total_tested << std::endl
  1804. << "\tNot covered LOC: " << total_untested << std::endl
  1805. << "\tTotal LOC: " << total_lines << std::endl
  1806. << "\tPercentage Coverage: ";
  1807. std::cout.setf(std::ios::fixed, std::ios::floatfield);
  1808. std::cout.precision(2);
  1809. std::cout << (percent_coverage) << "%" << std::endl;
  1810. return 1;
  1811. }
  1812. bool cmCTest::OpenOutputFile(const std::string& path,
  1813. const std::string& name, std::ofstream& stream)
  1814. {
  1815. std::string testingDir = m_ToplevelPath + "/Testing";
  1816. if ( path.size() > 0 )
  1817. {
  1818. testingDir += "/" + path;
  1819. }
  1820. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  1821. {
  1822. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  1823. {
  1824. std::cerr << "File " << testingDir
  1825. << " is in the place of the testing directory"
  1826. << std::endl;
  1827. return false;
  1828. }
  1829. }
  1830. else
  1831. {
  1832. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  1833. {
  1834. std::cerr << "Cannot create directory " << testingDir
  1835. << std::endl;
  1836. return false;
  1837. }
  1838. }
  1839. std::string filename = testingDir + "/" + name;
  1840. stream.open(filename.c_str());
  1841. if( !stream )
  1842. {
  1843. std::cerr << "Problem opening file: " << filename << std::endl;
  1844. return false;
  1845. }
  1846. return true;
  1847. }
  1848. void cmCTest::GenerateDartBuildOutput(std::ostream& os,
  1849. std::vector<cmCTestBuildErrorWarning> ew,
  1850. double elapsed_build_time)
  1851. {
  1852. this->StartXML(os);
  1853. os << "<Build>\n"
  1854. << "\t<StartDateTime>" << m_StartBuild << "</StartDateTime>\n"
  1855. << "<BuildCommand>"
  1856. << this->MakeXMLSafe(m_DartConfiguration["MakeCommand"])
  1857. << "</BuildCommand>" << std::endl;
  1858. std::vector<cmCTestBuildErrorWarning>::iterator it;
  1859. for ( it = ew.begin(); it != ew.end(); it++ )
  1860. {
  1861. cmCTestBuildErrorWarning *cm = &(*it);
  1862. os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n"
  1863. << "\t\t<BuildLogLine>" << cm->m_LogLine << "</BuildLogLine>\n"
  1864. << "\t\t<Text>" << this->MakeXMLSafe(cm->m_Text)
  1865. << "\n</Text>" << std::endl;
  1866. if ( cm->m_SourceFile.size() > 0 )
  1867. {
  1868. os << "\t\t<SourceFile>" << cm->m_SourceFile << "</SourceFile>"
  1869. << std::endl;
  1870. }
  1871. if ( cm->m_SourceFileTail.size() > 0 )
  1872. {
  1873. os << "\t\t<SourceFileTail>" << cm->m_SourceFileTail
  1874. << "</SourceFileTail>" << std::endl;
  1875. }
  1876. if ( cm->m_LineNumber >= 0 )
  1877. {
  1878. os << "\t\t<SourceLineNumber>" << cm->m_LineNumber
  1879. << "</SourceLineNumber>" << std::endl;
  1880. }
  1881. os << "\t\t<PreContext>" << this->MakeXMLSafe(cm->m_PreContext)
  1882. << "</PreContext>\n"
  1883. << "\t\t<PostContext>" << this->MakeXMLSafe(cm->m_PostContext)
  1884. << "</PostContext>\n"
  1885. << "\t\t<RepeatCount>0</RepeatCount>\n"
  1886. << "</" << (cm->m_Error ? "Error" : "Warning") << ">\n\n"
  1887. << std::endl;
  1888. }
  1889. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  1890. << "\t<EndDateTime>" << m_EndBuild << "</EndDateTime>\n"
  1891. << "<ElapsedMinutes>" << static_cast<int>(elapsed_build_time/6)/10.0
  1892. << "</ElapsedMinutes>"
  1893. << "</Build>" << std::endl;
  1894. this->EndXML(os);
  1895. }
  1896. void cmCTest::GetListOfTests(tm_ListOfTests* testlist, bool memcheck)
  1897. {
  1898. // does the DartTestfile.txt exist ?
  1899. if(!cmSystemTools::FileExists("DartTestfile.txt"))
  1900. {
  1901. return;
  1902. }
  1903. // parse the file
  1904. std::ifstream fin("DartTestfile.txt");
  1905. if(!fin)
  1906. {
  1907. return;
  1908. }
  1909. cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
  1910. cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
  1911. cmListFileCache cache;
  1912. cmListFile* listFile = cache.GetFileCache("DartTestfile.txt", false);
  1913. for(std::vector<cmListFileFunction>::const_iterator f =
  1914. listFile->m_Functions.begin(); f != listFile->m_Functions.end(); ++f)
  1915. {
  1916. const cmListFileFunction& lff = *f;
  1917. const std::string& name = lff.m_Name;
  1918. const tm_VectorOfListFileArgs& args = lff.m_Arguments;
  1919. if (name == "SUBDIRS")
  1920. {
  1921. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1922. for(tm_VectorOfListFileArgs::const_iterator j = args.begin();
  1923. j != args.end(); ++j)
  1924. {
  1925. std::string nwd = cwd + "/";
  1926. nwd += j->Value;
  1927. if (cmSystemTools::FileIsDirectory(nwd.c_str()))
  1928. {
  1929. cmSystemTools::ChangeDirectory(nwd.c_str());
  1930. this->GetListOfTests(testlist, memcheck);
  1931. }
  1932. }
  1933. // return to the original directory
  1934. cmSystemTools::ChangeDirectory(cwd.c_str());
  1935. }
  1936. if (name == "ADD_TEST")
  1937. {
  1938. const std::string& testname = args[0].Value;
  1939. if (this->m_UseExcludeRegExp &&
  1940. this->m_UseExcludeRegExpFirst &&
  1941. ereg.find(testname.c_str()))
  1942. {
  1943. continue;
  1944. }
  1945. if ( memcheck )
  1946. {
  1947. tm_VectorOfStrings::iterator it;
  1948. bool found = false;
  1949. for ( it = m_CustomMemCheckIgnore.begin();
  1950. it != m_CustomMemCheckIgnore.end(); ++ it )
  1951. {
  1952. if ( *it == testname )
  1953. {
  1954. found = true;
  1955. break;
  1956. }
  1957. }
  1958. if ( found )
  1959. {
  1960. if ( m_Verbose )
  1961. {
  1962. std::cout << "Ignore memcheck: " << *it << std::endl;
  1963. }
  1964. continue;
  1965. }
  1966. }
  1967. else
  1968. {
  1969. tm_VectorOfStrings::iterator it;
  1970. bool found = false;
  1971. for ( it = m_CustomTestsIgnore.begin();
  1972. it != m_CustomTestsIgnore.end(); ++ it )
  1973. {
  1974. if ( *it == testname )
  1975. {
  1976. found = true;
  1977. break;
  1978. }
  1979. }
  1980. if ( found )
  1981. {
  1982. if ( m_Verbose )
  1983. {
  1984. std::cout << "Ignore test: " << *it << std::endl;
  1985. }
  1986. continue;
  1987. }
  1988. }
  1989. if (this->m_UseIncludeRegExp && !ireg.find(testname.c_str()))
  1990. {
  1991. continue;
  1992. }
  1993. if (this->m_UseExcludeRegExp &&
  1994. !this->m_UseExcludeRegExpFirst &&
  1995. ereg.find(testname.c_str()))
  1996. {
  1997. continue;
  1998. }
  1999. cmCTestTestProperties test;
  2000. test.m_Name = testname;
  2001. test.m_Args = args;
  2002. test.m_Directory = cmSystemTools::GetCurrentWorkingDirectory();
  2003. testlist->push_back(test);
  2004. }
  2005. }
  2006. }
  2007. void cmCTest::ProcessDirectory(cmCTest::tm_VectorOfStrings &passed,
  2008. cmCTest::tm_VectorOfStrings &failed,
  2009. bool memcheck)
  2010. {
  2011. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  2012. cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  2013. tm_ListOfTests testlist;
  2014. this->GetListOfTests(&testlist, memcheck);
  2015. tm_ListOfTests::size_type tmsize = testlist.size();
  2016. std::ofstream ofs;
  2017. std::ofstream *olog = 0;
  2018. if ( !m_ShowOnly && tmsize > 0 &&
  2019. this->OpenOutputFile("Temporary",
  2020. (memcheck?"LastMemCheck.log":"LastTest.log"), ofs) )
  2021. {
  2022. olog = &ofs;
  2023. }
  2024. m_StartTest = this->CurrentTime();
  2025. double elapsed_time_start = cmSystemTools::GetTime();
  2026. if ( olog )
  2027. {
  2028. *olog << "Start testing: " << m_StartTest << std::endl
  2029. << "----------------------------------------------------------"
  2030. << std::endl;
  2031. }
  2032. // expand the test list
  2033. this->ExpandTestsToRunInformation((int)tmsize);
  2034. int cnt = 0;
  2035. tm_ListOfTests::iterator it;
  2036. std::string last_directory = "";
  2037. for ( it = testlist.begin(); it != testlist.end(); it ++ )
  2038. {
  2039. cnt ++;
  2040. const std::string& testname = it->m_Name;
  2041. tm_VectorOfListFileArgs& args = it->m_Args;
  2042. cmCTestTestResult cres;
  2043. cres.m_Status = cmCTest::NOT_RUN;
  2044. cres.m_TestCount = cnt;
  2045. if (!(last_directory == it->m_Directory))
  2046. {
  2047. if ( m_Verbose )
  2048. {
  2049. std::cerr << "Changing directory into "
  2050. << it->m_Directory.c_str() << "\n";
  2051. }
  2052. last_directory = it->m_Directory;
  2053. cmSystemTools::ChangeDirectory(it->m_Directory.c_str());
  2054. }
  2055. cres.m_Name = testname;
  2056. if(m_TestsToRun.size() &&
  2057. std::find(m_TestsToRun.begin(), m_TestsToRun.end(), cnt) == m_TestsToRun.end())
  2058. {
  2059. continue;
  2060. }
  2061. if ( m_ShowOnly )
  2062. {
  2063. std::cerr.width(3);
  2064. std::cerr << cnt << "/";
  2065. std::cerr.width(3);
  2066. std::cerr << tmsize << " Testing ";
  2067. std::string outname = testname;
  2068. outname.resize(30, ' ');
  2069. std::cerr << outname.c_str() << "\n";
  2070. }
  2071. else
  2072. {
  2073. std::cerr.width(3);
  2074. std::cerr << cnt << "/";
  2075. std::cerr.width(3);
  2076. std::cerr << tmsize << " Testing ";
  2077. std::string outname = testname;
  2078. outname.resize(30, ' ');
  2079. std::cerr << outname.c_str();
  2080. std::cerr.flush();
  2081. }
  2082. //std::cerr << "Testing " << args[0] << " ... ";
  2083. // find the test executable
  2084. std::string actualCommand = this->FindTheExecutable(args[1].Value.c_str());
  2085. std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
  2086. std::string memcheckcommand = "";
  2087. // continue if we did not find the executable
  2088. if (testCommand == "")
  2089. {
  2090. std::cerr << "Unable to find executable: " <<
  2091. args[1].Value.c_str() << "\n";
  2092. if ( !m_ShowOnly )
  2093. {
  2094. m_TestResults.push_back( cres );
  2095. failed.push_back(testname);
  2096. continue;
  2097. }
  2098. }
  2099. // add the arguments
  2100. tm_VectorOfListFileArgs::const_iterator j = args.begin();
  2101. ++j;
  2102. ++j;
  2103. std::vector<const char*> arguments;
  2104. if ( memcheck )
  2105. {
  2106. cmCTest::tm_VectorOfStrings::size_type pp;
  2107. arguments.push_back(m_MemoryTester.c_str());
  2108. memcheckcommand = m_MemoryTester;
  2109. for ( pp = 0; pp < m_MemoryTesterOptionsParsed.size(); pp ++ )
  2110. {
  2111. arguments.push_back(m_MemoryTesterOptionsParsed[pp].c_str());
  2112. memcheckcommand += " ";
  2113. memcheckcommand += cmSystemTools::EscapeSpaces(m_MemoryTesterOptionsParsed[pp].c_str());
  2114. }
  2115. }
  2116. arguments.push_back(actualCommand.c_str());
  2117. for(;j != args.end(); ++j)
  2118. {
  2119. testCommand += " ";
  2120. testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
  2121. arguments.push_back(j->Value.c_str());
  2122. }
  2123. arguments.push_back(0);
  2124. /**
  2125. * Run an executable command and put the stdout in output.
  2126. */
  2127. std::string output;
  2128. int retVal = 0;
  2129. if ( m_Verbose )
  2130. {
  2131. std::cout << std::endl << (memcheck?"MemCheck":"Test") << " command: " << testCommand << std::endl;
  2132. if ( memcheck )
  2133. {
  2134. std::cout << "Memory check command: " << memcheckcommand << std::endl;
  2135. }
  2136. }
  2137. if ( olog )
  2138. {
  2139. *olog << cnt << "/" << tmsize
  2140. << " Test: " << testname.c_str() << std::endl;
  2141. *olog << "Command: ";
  2142. tm_VectorOfStrings::size_type ll;
  2143. for ( ll = 0; ll < arguments.size()-1; ll ++ )
  2144. {
  2145. *olog << "\"" << arguments[ll] << "\" ";
  2146. }
  2147. *olog
  2148. << std::endl
  2149. << "Directory: " << it->m_Directory << std::endl
  2150. << "\"" << testname.c_str() << "\" start time: "
  2151. << this->CurrentTime() << std::endl
  2152. << "Output:" << std::endl
  2153. << "----------------------------------------------------------"
  2154. << std::endl;
  2155. }
  2156. int res = 0;
  2157. double clock_start, clock_finish;
  2158. clock_start = cmSystemTools::GetTime();
  2159. if ( !m_ShowOnly )
  2160. {
  2161. res = this->RunTest(arguments, &output, &retVal, olog);
  2162. }
  2163. clock_finish = cmSystemTools::GetTime();
  2164. if ( olog )
  2165. {
  2166. double ttime = clock_finish - clock_start;
  2167. int hours = static_cast<int>(ttime / (60 * 60));
  2168. int minutes = static_cast<int>(ttime / 60) % 60;
  2169. int seconds = static_cast<int>(ttime) % 60;
  2170. char buffer[100];
  2171. sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
  2172. *olog
  2173. << "----------------------------------------------------------"
  2174. << std::endl
  2175. << "\"" << testname.c_str() << "\" end time: "
  2176. << this->CurrentTime() << std::endl
  2177. << "\"" << testname.c_str() << "\" time elapsed: "
  2178. << buffer << std::endl
  2179. << "----------------------------------------------------------"
  2180. << std::endl << std::endl;
  2181. }
  2182. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  2183. cres.m_FullCommandLine = testCommand;
  2184. if ( !m_ShowOnly )
  2185. {
  2186. if (res == cmsysProcess_State_Exited && retVal == 0)
  2187. {
  2188. std::cerr << " Passed\n";
  2189. passed.push_back(testname);
  2190. cres.m_Status = cmCTest::COMPLETED;
  2191. }
  2192. else
  2193. {
  2194. cres.m_Status = cmCTest::FAILED;
  2195. if ( res == cmsysProcess_State_Expired )
  2196. {
  2197. std::cerr << "***Timeout\n";
  2198. cres.m_Status = cmCTest::TIMEOUT;
  2199. }
  2200. else if ( res == cmsysProcess_State_Exception )
  2201. {
  2202. std::cerr << "***Exception: ";
  2203. switch ( retVal )
  2204. {
  2205. case cmsysProcess_Exception_Fault:
  2206. std::cerr << "SegFault";
  2207. cres.m_Status = cmCTest::SEGFAULT;
  2208. break;
  2209. case cmsysProcess_Exception_Illegal:
  2210. std::cerr << "Illegal";
  2211. cres.m_Status = cmCTest::ILLEGAL;
  2212. break;
  2213. case cmsysProcess_Exception_Interrupt:
  2214. std::cerr << "Interrupt";
  2215. cres.m_Status = cmCTest::INTERRUPT;
  2216. break;
  2217. case cmsysProcess_Exception_Numerical:
  2218. std::cerr << "Numerical";
  2219. cres.m_Status = cmCTest::NUMERICAL;
  2220. break;
  2221. default:
  2222. std::cerr << "Other";
  2223. cres.m_Status = cmCTest::OTHER_FAULT;
  2224. }
  2225. std::cerr << "\n";
  2226. }
  2227. else if ( res == cmsysProcess_State_Error )
  2228. {
  2229. std::cerr << "***Bad command " << res << "\n";
  2230. cres.m_Status = cmCTest::BAD_COMMAND;
  2231. }
  2232. else
  2233. {
  2234. std::cerr << "***Failed\n";
  2235. }
  2236. failed.push_back(testname);
  2237. }
  2238. if (output != "")
  2239. {
  2240. if (dartStuff.find(output.c_str()))
  2241. {
  2242. std::string dartString = dartStuff.match(1);
  2243. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  2244. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  2245. }
  2246. }
  2247. }
  2248. cres.m_Output = output;
  2249. cres.m_ReturnValue = retVal;
  2250. std::string nwd = it->m_Directory;
  2251. if ( nwd.size() > m_ToplevelPath.size() )
  2252. {
  2253. nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
  2254. }
  2255. cmSystemTools::ReplaceString(nwd, "\\", "/");
  2256. cres.m_Path = nwd;
  2257. cres.m_CompletionStatus = "Completed";
  2258. m_TestResults.push_back( cres );
  2259. }
  2260. m_EndTest = this->CurrentTime();
  2261. m_ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
  2262. if ( olog )
  2263. {
  2264. *olog << "End testing: " << m_EndTest << std::endl;
  2265. }
  2266. cmSystemTools::ChangeDirectory(current_dir.c_str());
  2267. }
  2268. bool cmCTest::InitializeMemoryChecking()
  2269. {
  2270. // Setup the command
  2271. if ( cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckCommand"].c_str()) )
  2272. {
  2273. m_MemoryTester
  2274. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["MemoryCheckCommand"].c_str());
  2275. }
  2276. else if ( cmSystemTools::FileExists(m_DartConfiguration["PurifyCommand"].c_str()) )
  2277. {
  2278. m_MemoryTester
  2279. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["PurifyCommand"].c_str());
  2280. }
  2281. else if ( cmSystemTools::FileExists(m_DartConfiguration["ValgrindCommand"].c_str()) )
  2282. {
  2283. m_MemoryTester
  2284. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["ValgrindCommand"].c_str());
  2285. }
  2286. else
  2287. {
  2288. std::cerr << "Memory checker (MemoryCheckCommand) not set, or cannot find the specified program."
  2289. << std::endl;
  2290. return false;
  2291. }
  2292. if ( m_MemoryTester[0] == '\"' && m_MemoryTester[m_MemoryTester.size()-1] == '\"' )
  2293. {
  2294. m_MemoryTester = m_MemoryTester.substr(1, m_MemoryTester.size()-2);
  2295. }
  2296. // Setup the options
  2297. if ( m_DartConfiguration["MemoryCheckCommandOptions"].size() )
  2298. {
  2299. m_MemoryTesterOptions = m_DartConfiguration["MemoryCheckCommandOptions"];
  2300. }
  2301. else if ( m_DartConfiguration["ValgrindCommandOptions"].size() )
  2302. {
  2303. m_MemoryTesterOptions = m_DartConfiguration["ValgrindCommandOptions"];
  2304. }
  2305. m_MemoryTesterOutputFile = m_ToplevelPath + "/Testing/Temporary/MemoryChecker.log";
  2306. m_MemoryTesterOutputFile = cmSystemTools::EscapeSpaces(m_MemoryTesterOutputFile.c_str());
  2307. if ( m_MemoryTester.find("valgrind") != std::string::npos )
  2308. {
  2309. m_MemoryTesterStyle = cmCTest::VALGRIND;
  2310. if ( !m_MemoryTesterOptions.size() )
  2311. {
  2312. m_MemoryTesterOptions = "-q --skin=memcheck --leak-check=yes --show-reachable=yes --workaround-gcc296-bugs=yes --num-callers=100";
  2313. }
  2314. if ( m_DartConfiguration["MemoryCheckSuppressionFile"].size() )
  2315. {
  2316. if ( !cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) )
  2317. {
  2318. std::cerr << "Cannot find memory checker suppression file: "
  2319. << m_DartConfiguration["MemoryCheckSuppressionFile"].c_str() << std::endl;
  2320. return false;
  2321. }
  2322. m_MemoryTesterOptions += " --suppressions=" + cmSystemTools::EscapeSpaces(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) + "";
  2323. }
  2324. }
  2325. else if ( m_MemoryTester.find("purify") != std::string::npos )
  2326. {
  2327. m_MemoryTesterStyle = cmCTest::PURIFY;
  2328. #ifdef _WIN32
  2329. m_MemoryTesterOptions += " /SAVETEXTDATA=" + m_MemoryTesterOutputFile;
  2330. #else
  2331. m_MemoryTesterOptions += " -log-file=" + m_MemoryTesterOutputFile;
  2332. #endif
  2333. }
  2334. else if ( m_MemoryTester.find("boundschecker") != std::string::npos )
  2335. {
  2336. m_MemoryTesterStyle = cmCTest::BOUNDS_CHECKER;
  2337. std::cerr << "Bounds checker not yet implemented" << std::endl;
  2338. return false;
  2339. }
  2340. else
  2341. {
  2342. std::cerr << "Do not understand memory checker: " << m_MemoryTester.c_str() << std::endl;
  2343. return false;
  2344. }
  2345. m_MemoryTesterOptionsParsed = cmSystemTools::ParseArguments(m_MemoryTesterOptions.c_str());
  2346. cmCTest::tm_VectorOfStrings::size_type cc;
  2347. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  2348. {
  2349. m_MemoryTesterGlobalResults[cc] = 0;
  2350. }
  2351. return true;
  2352. }
  2353. int cmCTest::TestDirectory(bool memcheck)
  2354. {
  2355. m_TestResults.clear();
  2356. std::cout << (memcheck ? "Memory check" : "Test") << " project" << std::endl;
  2357. if ( memcheck )
  2358. {
  2359. if ( !this->InitializeMemoryChecking() )
  2360. {
  2361. return 1;
  2362. }
  2363. }
  2364. if ( memcheck )
  2365. {
  2366. if ( !this->ExecuteCommands(m_CustomPreMemCheck) )
  2367. {
  2368. std::cerr << "Problem executing pre-memcheck command(s)." << std::endl;
  2369. return 1;
  2370. }
  2371. }
  2372. else
  2373. {
  2374. if ( !this->ExecuteCommands(m_CustomPreTest) )
  2375. {
  2376. std::cerr << "Problem executing pre-test command(s)." << std::endl;
  2377. return 1;
  2378. }
  2379. }
  2380. cmCTest::tm_VectorOfStrings passed;
  2381. cmCTest::tm_VectorOfStrings failed;
  2382. int total;
  2383. this->ProcessDirectory(passed, failed, memcheck);
  2384. total = int(passed.size()) + int(failed.size());
  2385. if (total == 0)
  2386. {
  2387. if ( !m_ShowOnly )
  2388. {
  2389. std::cerr << "No tests were found!!!\n";
  2390. }
  2391. }
  2392. else
  2393. {
  2394. if (m_Verbose && passed.size() &&
  2395. (m_UseIncludeRegExp || m_UseExcludeRegExp))
  2396. {
  2397. std::cerr << "\nThe following tests passed:\n";
  2398. for(cmCTest::tm_VectorOfStrings::iterator j = passed.begin();
  2399. j != passed.end(); ++j)
  2400. {
  2401. std::cerr << "\t" << *j << "\n";
  2402. }
  2403. }
  2404. float percent = float(passed.size()) * 100.0f / total;
  2405. if ( failed.size() > 0 && percent > 99)
  2406. {
  2407. percent = 99;
  2408. }
  2409. fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  2410. percent, int(failed.size()), total);
  2411. if (failed.size())
  2412. {
  2413. std::ofstream ofs;
  2414. std::cerr << "\nThe following tests FAILED:\n";
  2415. this->OpenOutputFile("Temporary", "LastTestsFailed.log", ofs);
  2416. std::vector<cmCTest::cmCTestTestResult>::iterator ftit;
  2417. for(ftit = m_TestResults.begin();
  2418. ftit != m_TestResults.end(); ++ftit)
  2419. {
  2420. if ( ftit->m_Status != cmCTest::COMPLETED )
  2421. {
  2422. ofs << ftit->m_TestCount << ":" << ftit->m_Name << std::endl;
  2423. fprintf(stderr, "\t%3d - %s (%s)\n", ftit->m_TestCount, ftit->m_Name.c_str(),
  2424. this->GetTestStatus(ftit->m_Status));
  2425. }
  2426. }
  2427. }
  2428. }
  2429. if ( m_DartMode )
  2430. {
  2431. std::ofstream xmlfile;
  2432. if( !this->OpenOutputFile(m_CurrentTag,
  2433. (memcheck ? (m_CompatibilityMode?"Purify.xml":"DynamicAnalysis.xml") : "Test.xml"), xmlfile) )
  2434. {
  2435. std::cerr << "Cannot create " << (memcheck ? "memory check" : "testing")
  2436. << " XML file" << std::endl;
  2437. return 1;
  2438. }
  2439. if ( memcheck )
  2440. {
  2441. this->GenerateDartMemCheckOutput(xmlfile);
  2442. }
  2443. else
  2444. {
  2445. this->GenerateDartTestOutput(xmlfile);
  2446. }
  2447. }
  2448. if ( memcheck )
  2449. {
  2450. if ( !this->ExecuteCommands(m_CustomPostMemCheck) )
  2451. {
  2452. std::cerr << "Problem executing post-memcheck command(s)." << std::endl;
  2453. return 1;
  2454. }
  2455. }
  2456. else
  2457. {
  2458. if ( !this->ExecuteCommands(m_CustomPostTest) )
  2459. {
  2460. std::cerr << "Problem executing post-test command(s)." << std::endl;
  2461. return 1;
  2462. }
  2463. }
  2464. return int(failed.size());
  2465. }
  2466. int cmCTest::SubmitResults()
  2467. {
  2468. std::ofstream ofs;
  2469. this->OpenOutputFile("Temporary", "LastSubmit.log", ofs);
  2470. cmCTest::tm_VectorOfStrings files;
  2471. std::string prefix = this->GetSubmitResultsPrefix();
  2472. // TODO:
  2473. // Check if test is enabled
  2474. if ( this->CTestFileExists("Update.xml") )
  2475. {
  2476. files.push_back("Update.xml");
  2477. }
  2478. if ( this->CTestFileExists("Configure.xml") )
  2479. {
  2480. files.push_back("Configure.xml");
  2481. }
  2482. if ( this->CTestFileExists("Build.xml") )
  2483. {
  2484. files.push_back("Build.xml");
  2485. }
  2486. if ( this->CTestFileExists("Test.xml") )
  2487. {
  2488. files.push_back("Test.xml");
  2489. }
  2490. if ( this->CTestFileExists("Coverage.xml") )
  2491. {
  2492. files.push_back("Coverage.xml");
  2493. cmCTest::tm_VectorOfStrings gfiles;
  2494. std::string gpath = m_ToplevelPath + "/Testing/" + m_CurrentTag;
  2495. std::string::size_type glen = gpath.size() + 1;
  2496. gpath = gpath + "/CoverageLog*";
  2497. //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
  2498. if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
  2499. {
  2500. size_t cc;
  2501. for ( cc = 0; cc < gfiles.size(); cc ++ )
  2502. {
  2503. gfiles[cc] = gfiles[cc].substr(glen);
  2504. //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
  2505. files.push_back(gfiles[cc]);
  2506. }
  2507. }
  2508. else
  2509. {
  2510. std::cerr << "Problem globbing" << std::endl;
  2511. }
  2512. }
  2513. if ( this->CTestFileExists("DynamicAnalysis.xml") )
  2514. {
  2515. files.push_back("DynamicAnalysis.xml");
  2516. }
  2517. if ( this->CTestFileExists("Purify.xml") )
  2518. {
  2519. files.push_back("Purify.xml");
  2520. }
  2521. if ( this->CTestFileExists("Notes.xml") )
  2522. {
  2523. files.push_back("Notes.xml");
  2524. }
  2525. if ( ofs )
  2526. {
  2527. ofs << "Upload files:" << std::endl;
  2528. int cnt = 0;
  2529. cmCTest::tm_VectorOfStrings::iterator it;
  2530. for ( it = files.begin(); it != files.end(); ++ it )
  2531. {
  2532. ofs << cnt << "\t" << it->c_str() << std::endl;
  2533. cnt ++;
  2534. }
  2535. }
  2536. std::cout << "Submit files (using " << m_DartConfiguration["DropMethod"] << ")"
  2537. << std::endl;
  2538. cmCTestSubmit submit;
  2539. submit.SetVerbose(m_Verbose);
  2540. submit.SetLogFile(&ofs);
  2541. if ( m_DartConfiguration["DropMethod"] == "" ||
  2542. m_DartConfiguration["DropMethod"] == "ftp" )
  2543. {
  2544. ofs << "Using drop method: FTP" << std::endl;
  2545. std::cout << " Using FTP submit method" << std::endl;
  2546. std::string url = "ftp://";
  2547. url += cmCTest::MakeURLSafe(m_DartConfiguration["DropSiteUser"]) + ":" +
  2548. cmCTest::MakeURLSafe(m_DartConfiguration["DropSitePassword"]) + "@" +
  2549. m_DartConfiguration["DropSite"] +
  2550. cmCTest::MakeURLSafe(m_DartConfiguration["DropLocation"]);
  2551. if ( !submit.SubmitUsingFTP(m_ToplevelPath+"/Testing/"+m_CurrentTag,
  2552. files, prefix, url) )
  2553. {
  2554. std::cerr << " Problems when submitting via FTP" << std::endl;
  2555. ofs << " Problems when submitting via FTP" << std::endl;
  2556. return 0;
  2557. }
  2558. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  2559. {
  2560. std::cerr << " Problems when triggering via HTTP" << std::endl;
  2561. ofs << " Problems when triggering via HTTP" << std::endl;
  2562. return 0;
  2563. }
  2564. std::cout << " Submission successfull" << std::endl;
  2565. ofs << " Submission succesfull" << std::endl;
  2566. return 1;
  2567. }
  2568. else if ( m_DartConfiguration["DropMethod"] == "http" )
  2569. {
  2570. ofs << "Using drop method: HTTP" << std::endl;
  2571. std::cout << " Using HTTP submit method" << std::endl;
  2572. std::string url = "http://";
  2573. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  2574. {
  2575. url += m_DartConfiguration["DropSiteUser"];
  2576. if ( m_DartConfiguration["DropSitePassword"].size() > 0 )
  2577. {
  2578. url += ":" + m_DartConfiguration["DropSitePassword"];
  2579. }
  2580. url += "@";
  2581. }
  2582. url += m_DartConfiguration["DropSite"] + m_DartConfiguration["DropLocation"];
  2583. if ( !submit.SubmitUsingHTTP(m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  2584. {
  2585. std::cerr << " Problems when submitting via HTTP" << std::endl;
  2586. ofs << " Problems when submitting via HTTP" << std::endl;
  2587. return 0;
  2588. }
  2589. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  2590. {
  2591. std::cerr << " Problems when triggering via HTTP" << std::endl;
  2592. ofs << " Problems when triggering via HTTP" << std::endl;
  2593. return 0;
  2594. }
  2595. std::cout << " Submission successfull" << std::endl;
  2596. ofs << " Submission succesfull" << std::endl;
  2597. return 1;
  2598. }
  2599. else
  2600. {
  2601. std::string url;
  2602. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  2603. {
  2604. url += m_DartConfiguration["DropSiteUser"] + "@";
  2605. }
  2606. url += m_DartConfiguration["DropSite"] + ":" + m_DartConfiguration["DropLocation"];
  2607. if ( !submit.SubmitUsingSCP(m_DartConfiguration["ScpCommand"],
  2608. m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  2609. {
  2610. std::cerr << " Problems when submitting via SCP" << std::endl;
  2611. ofs << " Problems when submitting via SCP" << std::endl;
  2612. return 0;
  2613. }
  2614. std::cout << " Submission successfull" << std::endl;
  2615. ofs << " Submission succesfull" << std::endl;
  2616. }
  2617. return 0;
  2618. }
  2619. bool cmCTest::CTestFileExists(const std::string& filename)
  2620. {
  2621. std::string testingDir = m_ToplevelPath + "/Testing/" + m_CurrentTag + "/" +
  2622. filename;
  2623. return cmSystemTools::FileExists(testingDir.c_str());
  2624. }
  2625. std::string cmCTest::GetSubmitResultsPrefix()
  2626. {
  2627. std::string name = m_DartConfiguration["Site"] +
  2628. "___" + m_DartConfiguration["BuildName"] +
  2629. "___" + m_CurrentTag + "-" +
  2630. this->GetTestModelString() + "___XML___";
  2631. return name;
  2632. }
  2633. void cmCTest::GenerateDartMemCheckOutput(std::ostream& os)
  2634. {
  2635. if ( !m_DartMode )
  2636. {
  2637. return;
  2638. }
  2639. this->StartXML(os);
  2640. if ( m_CompatibilityMode )
  2641. {
  2642. os << "<Purify>" << std::endl;
  2643. }
  2644. else
  2645. {
  2646. os << "<DynamicAnalysis Checker=\"";
  2647. switch ( m_MemoryTesterStyle )
  2648. {
  2649. case cmCTest::VALGRIND:
  2650. os << "Valgrind";
  2651. break;
  2652. case cmCTest::PURIFY:
  2653. os << "Purify";
  2654. break;
  2655. case cmCTest::BOUNDS_CHECKER:
  2656. os << "BoundsChecker";
  2657. break;
  2658. default:
  2659. os << "Unknown";
  2660. }
  2661. os << "\">" << std::endl;
  2662. }
  2663. os << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  2664. << "\t<TestList>\n";
  2665. tm_TestResultsVector::size_type cc;
  2666. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2667. {
  2668. cmCTestTestResult *result = &m_TestResults[cc];
  2669. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  2670. << "/" << this->MakeXMLSafe(result->m_Name)
  2671. << "</Test>" << std::endl;
  2672. }
  2673. os << "\t</TestList>\n";
  2674. std::cout << "-- Processing memory checking output: ";
  2675. unsigned int total = m_TestResults.size();
  2676. unsigned int step = total / 10;
  2677. unsigned int current = 0;
  2678. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2679. {
  2680. cmCTestTestResult *result = &m_TestResults[cc];
  2681. std::string memcheckstr;
  2682. int memcheckresults[cmCTest::NO_MEMORY_FAULT];
  2683. int kk;
  2684. bool res = this->ProcessMemCheckOutput(result->m_Output, memcheckstr, memcheckresults);
  2685. if ( res && result->m_Status == cmCTest::COMPLETED )
  2686. {
  2687. continue;
  2688. }
  2689. os << "\t<Test Status=\"";
  2690. if ( result->m_Status == cmCTest::COMPLETED )
  2691. {
  2692. os << "passed";
  2693. }
  2694. else if ( result->m_Status == cmCTest::NOT_RUN )
  2695. {
  2696. os << "notrun";
  2697. }
  2698. else
  2699. {
  2700. os << "failed";
  2701. }
  2702. os << "\">\n"
  2703. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  2704. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  2705. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  2706. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  2707. << "\t\t<FullCommandLine>"
  2708. << this->MakeXMLSafe(result->m_FullCommandLine)
  2709. << "</FullCommandLine>\n"
  2710. << "\t\t<Results>" << std::endl;
  2711. if ( m_CompatibilityMode )
  2712. {
  2713. for ( kk = 0; cmCTestMemCheckResultStrings[kk]; kk ++ )
  2714. {
  2715. os << "\t\t\t<" << cmCTestMemCheckResultStrings[kk] << ">"
  2716. << memcheckresults[kk]
  2717. << "</" << cmCTestMemCheckResultStrings[kk] << ">" << std::endl;
  2718. m_MemoryTesterGlobalResults[kk] += memcheckresults[kk];
  2719. }
  2720. }
  2721. else
  2722. {
  2723. for ( kk = 0; cmCTestMemCheckResultLongStrings[kk]; kk ++ )
  2724. {
  2725. if ( memcheckresults[kk] )
  2726. {
  2727. os << "\t\t\t<Defect type=\"" << cmCTestMemCheckResultLongStrings[kk] << "\">"
  2728. << memcheckresults[kk]
  2729. << "</Defect>" << std::endl;
  2730. }
  2731. m_MemoryTesterGlobalResults[kk] += memcheckresults[kk];
  2732. }
  2733. }
  2734. os
  2735. << "\t\t</Results>\n"
  2736. << "\t<Log>\n" << memcheckstr << std::endl
  2737. << "\t</Log>\n"
  2738. << "\t</Test>" << std::endl;
  2739. if ( current < cc )
  2740. {
  2741. std::cout << "#";
  2742. std::cout.flush();
  2743. current += step;
  2744. }
  2745. }
  2746. std::cout << std::endl;
  2747. std::cerr << "Memory checking results:" << std::endl;
  2748. os << "\t<DefectList>" << std::endl;
  2749. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  2750. {
  2751. if ( m_MemoryTesterGlobalResults[cc] )
  2752. {
  2753. std::cerr.width(35);
  2754. std::cerr << cmCTestMemCheckResultLongStrings[cc] << " - "
  2755. << m_MemoryTesterGlobalResults[cc] << std::endl;
  2756. if ( !m_CompatibilityMode )
  2757. {
  2758. os << "\t\t<Defect Type=\"" << cmCTestMemCheckResultLongStrings[cc] << "\"/>" << std::endl;
  2759. }
  2760. }
  2761. }
  2762. os << "\t</DefectList>" << std::endl;
  2763. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>" << std::endl;
  2764. os << "<ElapsedMinutes>"
  2765. << static_cast<int>(m_ElapsedTestingTime/6)/10.0
  2766. << "</ElapsedMinutes>\n";
  2767. if ( m_CompatibilityMode )
  2768. {
  2769. os << "</Purify>" << std::endl;
  2770. }
  2771. else
  2772. {
  2773. os << "</DynamicAnalysis>" << std::endl;
  2774. }
  2775. this->EndXML(os);
  2776. }
  2777. void cmCTest::GenerateDartTestOutput(std::ostream& os)
  2778. {
  2779. if ( !m_DartMode )
  2780. {
  2781. return;
  2782. }
  2783. this->StartXML(os);
  2784. os << "<Testing>\n"
  2785. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  2786. << "\t<TestList>\n";
  2787. tm_TestResultsVector::size_type cc;
  2788. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2789. {
  2790. cmCTestTestResult *result = &m_TestResults[cc];
  2791. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  2792. << "/" << this->MakeXMLSafe(result->m_Name)
  2793. << "</Test>" << std::endl;
  2794. }
  2795. os << "\t</TestList>\n";
  2796. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2797. {
  2798. cmCTestTestResult *result = &m_TestResults[cc];
  2799. os << "\t<Test Status=\"";
  2800. if ( result->m_Status == cmCTest::COMPLETED )
  2801. {
  2802. os << "passed";
  2803. }
  2804. else if ( result->m_Status == cmCTest::NOT_RUN )
  2805. {
  2806. os << "notrun";
  2807. }
  2808. else
  2809. {
  2810. os << "failed";
  2811. }
  2812. os << "\">\n"
  2813. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  2814. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  2815. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  2816. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  2817. << "\t\t<FullCommandLine>"
  2818. << this->MakeXMLSafe(result->m_FullCommandLine)
  2819. << "</FullCommandLine>\n"
  2820. << "\t\t<Results>" << std::endl;
  2821. if ( result->m_Status != cmCTest::NOT_RUN )
  2822. {
  2823. if ( result->m_Status != cmCTest::COMPLETED || result->m_ReturnValue )
  2824. {
  2825. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  2826. << this->GetTestStatus(result->m_Status) << "</Value></NamedMeasurement>\n"
  2827. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  2828. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  2829. }
  2830. os << result->m_RegressionImages;
  2831. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  2832. << "name=\"Execution Time\"><Value>"
  2833. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n";
  2834. os
  2835. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  2836. << "name=\"Completion Status\"><Value>"
  2837. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n";
  2838. }
  2839. os
  2840. << "\t\t\t<Measurement>\n"
  2841. << "\t\t\t\t<Value>";
  2842. size_t truncate = result->m_Output.size();
  2843. if ( result->m_Status == cmCTest::COMPLETED )
  2844. {
  2845. if ( result->m_Output.size() > m_MaximumPassedTestResultSize )
  2846. {
  2847. truncate = m_MaximumPassedTestResultSize;
  2848. }
  2849. }
  2850. else
  2851. {
  2852. if ( result->m_Output.size() > m_MaximumFailedTestResultSize )
  2853. {
  2854. truncate = m_MaximumFailedTestResultSize;
  2855. }
  2856. }
  2857. os << this->MakeXMLSafe(result->m_Output.substr(0, truncate));
  2858. if ( truncate < result->m_Output.size() )
  2859. {
  2860. os << "...\n\nThe output was stirpped because it excedes maximum allowed size: "
  2861. << truncate << std::endl;
  2862. }
  2863. os
  2864. << "</Value>\n"
  2865. << "\t\t\t</Measurement>\n"
  2866. << "\t\t</Results>\n"
  2867. << "\t</Test>" << std::endl;
  2868. }
  2869. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  2870. << "<ElapsedMinutes>"
  2871. << static_cast<int>(m_ElapsedTestingTime/6)/10.0
  2872. << "</ElapsedMinutes>"
  2873. << "</Testing>" << std::endl;
  2874. this->EndXML(os);
  2875. }
  2876. int cmCTest::ProcessTests()
  2877. {
  2878. int res = 0;
  2879. bool notest = true;
  2880. int cc;
  2881. int update_count = 0;
  2882. for ( cc = 0; cc < LAST_TEST; cc ++ )
  2883. {
  2884. if ( m_Tests[cc] )
  2885. {
  2886. notest = false;
  2887. break;
  2888. }
  2889. }
  2890. if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
  2891. {
  2892. update_count = this->UpdateDirectory();
  2893. if ( update_count < 0 )
  2894. {
  2895. res |= cmCTest::UPDATE_ERRORS;
  2896. }
  2897. }
  2898. if ( m_TestModel == cmCTest::CONTINUOUS && !update_count )
  2899. {
  2900. return 0;
  2901. }
  2902. if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
  2903. {
  2904. if (this->ConfigureDirectory())
  2905. {
  2906. res |= cmCTest::CONFIGURE_ERRORS;
  2907. }
  2908. }
  2909. if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
  2910. {
  2911. this->UpdateCTestConfiguration();
  2912. if (this->BuildDirectory())
  2913. {
  2914. res |= cmCTest::BUILD_ERRORS;
  2915. }
  2916. }
  2917. if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
  2918. {
  2919. this->UpdateCTestConfiguration();
  2920. if (this->TestDirectory(false))
  2921. {
  2922. res |= cmCTest::TEST_ERRORS;
  2923. }
  2924. }
  2925. if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
  2926. {
  2927. this->UpdateCTestConfiguration();
  2928. this->CoverageDirectory();
  2929. }
  2930. if ( m_Tests[MEMCHECK_TEST] || m_Tests[ALL_TEST] )
  2931. {
  2932. this->UpdateCTestConfiguration();
  2933. if (this->TestDirectory(true))
  2934. {
  2935. res |= cmCTest::MEMORY_ERRORS;
  2936. }
  2937. }
  2938. if ( !notest )
  2939. {
  2940. std::string notes_dir = m_ToplevelPath + "/Testing/Notes";
  2941. if ( cmSystemTools::FileIsDirectory(notes_dir.c_str()) )
  2942. {
  2943. cmsys::Directory d;
  2944. d.Load(notes_dir.c_str());
  2945. unsigned long kk;
  2946. for ( kk = 0; kk < d.GetNumberOfFiles(); kk ++ )
  2947. {
  2948. const char* file = d.GetFile(kk);
  2949. std::string fullname = notes_dir + "/" + file;
  2950. if ( cmSystemTools::FileExists(fullname.c_str()) &&
  2951. !cmSystemTools::FileIsDirectory(fullname.c_str()) )
  2952. {
  2953. if ( m_NotesFiles.size() > 0 )
  2954. {
  2955. m_NotesFiles += ";";
  2956. }
  2957. m_NotesFiles += fullname;
  2958. m_Tests[NOTES_TEST] = 1;
  2959. }
  2960. }
  2961. }
  2962. }
  2963. if ( m_Tests[NOTES_TEST] || m_Tests[ALL_TEST] )
  2964. {
  2965. this->UpdateCTestConfiguration();
  2966. if ( m_NotesFiles.size() )
  2967. {
  2968. this->GenerateNotesFile(m_NotesFiles.c_str());
  2969. }
  2970. }
  2971. if ( m_Tests[SUBMIT_TEST] || m_Tests[ALL_TEST] )
  2972. {
  2973. this->UpdateCTestConfiguration();
  2974. this->SubmitResults();
  2975. }
  2976. return res;
  2977. }
  2978. std::string cmCTest::GetTestModelString()
  2979. {
  2980. switch ( m_TestModel )
  2981. {
  2982. case cmCTest::NIGHTLY:
  2983. return "Nightly";
  2984. case cmCTest::CONTINUOUS:
  2985. return "Continuous";
  2986. }
  2987. return "Experimental";
  2988. }
  2989. int cmCTest::GetTestModelFromString(const char* str)
  2990. {
  2991. if ( !str )
  2992. {
  2993. return cmCTest::EXPERIMENTAL;
  2994. }
  2995. std::string rstr = cmSystemTools::LowerCase(str);
  2996. if ( strncmp(rstr.c_str(), "cont", 4) == 0 )
  2997. {
  2998. return cmCTest::CONTINUOUS;
  2999. }
  3000. if ( strncmp(rstr.c_str(), "nigh", 4) == 0 )
  3001. {
  3002. return cmCTest::NIGHTLY;
  3003. }
  3004. return cmCTest::EXPERIMENTAL;
  3005. }
  3006. #define SPACE_REGEX "[ \t\r\n]"
  3007. std::string cmCTest::GenerateRegressionImages(const std::string& xml)
  3008. {
  3009. cmsys::RegularExpression twoattributes(
  3010. "<DartMeasurement"
  3011. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3012. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3013. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  3014. cmsys::RegularExpression threeattributes(
  3015. "<DartMeasurement"
  3016. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3017. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3018. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3019. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  3020. cmsys::RegularExpression fourattributes(
  3021. "<DartMeasurement"
  3022. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3023. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3024. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3025. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3026. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  3027. cmsys::RegularExpression measurementfile(
  3028. "<DartMeasurementFile"
  3029. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3030. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  3031. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  3032. cmOStringStream ostr;
  3033. bool done = false;
  3034. std::string cxml = xml;
  3035. while ( ! done )
  3036. {
  3037. if ( twoattributes.find(cxml) )
  3038. {
  3039. ostr
  3040. << "\t\t\t<NamedMeasurement"
  3041. << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
  3042. << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
  3043. << "><Value>" << twoattributes.match(5)
  3044. << "</Value></NamedMeasurement>"
  3045. << std::endl;
  3046. cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
  3047. }
  3048. else if ( threeattributes.find(cxml) )
  3049. {
  3050. ostr
  3051. << "\t\t\t<NamedMeasurement"
  3052. << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
  3053. << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
  3054. << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
  3055. << "><Value>" << threeattributes.match(7)
  3056. << "</Value></NamedMeasurement>"
  3057. << std::endl;
  3058. cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
  3059. }
  3060. else if ( fourattributes.find(cxml) )
  3061. {
  3062. ostr
  3063. << "\t\t\t<NamedMeasurement"
  3064. << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
  3065. << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
  3066. << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
  3067. << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
  3068. << "><Value>" << fourattributes.match(9)
  3069. << "</Value></NamedMeasurement>"
  3070. << std::endl;
  3071. cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
  3072. }
  3073. else if ( measurementfile.find(cxml) )
  3074. {
  3075. const std::string& filename = ::CleanString(measurementfile.match(5));
  3076. if ( cmSystemTools::FileExists(filename.c_str()) )
  3077. {
  3078. long len = cmSystemTools::FileLength(filename.c_str());
  3079. if ( len == 0 )
  3080. {
  3081. std::string k1 = measurementfile.match(1);
  3082. std::string v1 = measurementfile.match(2);
  3083. std::string k2 = measurementfile.match(3);
  3084. std::string v2 = measurementfile.match(4);
  3085. if ( cmSystemTools::LowerCase(k1) == "type" )
  3086. {
  3087. v1 = "text/string";
  3088. }
  3089. if ( cmSystemTools::LowerCase(k2) == "type" )
  3090. {
  3091. v2 = "text/string";
  3092. }
  3093. ostr
  3094. << "\t\t\t<NamedMeasurement"
  3095. << " " << k1 << "=\"" << v1 << "\""
  3096. << " " << k2 << "=\"" << v2 << "\""
  3097. << " encoding=\"none\""
  3098. << "><Value>Image " << filename.c_str()
  3099. << " is empty</Value></NamedMeasurement>";
  3100. }
  3101. else
  3102. {
  3103. std::ifstream ifs(filename.c_str(), std::ios::in
  3104. #ifdef _WIN32
  3105. | std::ios::binary
  3106. #endif
  3107. );
  3108. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  3109. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  3110. unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 5) ];
  3111. unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  3112. unsigned long cc;
  3113. ostr
  3114. << "\t\t\t<NamedMeasurement"
  3115. << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
  3116. << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
  3117. << " encoding=\"base64\""
  3118. << ">" << std::endl << "\t\t\t\t<Value>";
  3119. for ( cc = 0; cc < rlen; cc ++ )
  3120. {
  3121. ostr << encoded_buffer[cc];
  3122. if ( cc % 60 == 0 && cc )
  3123. {
  3124. ostr << std::endl;
  3125. }
  3126. }
  3127. ostr
  3128. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  3129. << std::endl;
  3130. delete [] file_buffer;
  3131. delete [] encoded_buffer;
  3132. }
  3133. }
  3134. else
  3135. {
  3136. int idx = 4;
  3137. if ( measurementfile.match(1) == "name" )
  3138. {
  3139. idx = 2;
  3140. }
  3141. ostr
  3142. << "\t\t\t<NamedMeasurement"
  3143. << " name=\"" << measurementfile.match(idx) << "\""
  3144. << " text=\"text/string\""
  3145. << "><Value>File " << filename.c_str() << " not found</Value></NamedMeasurement>"
  3146. << std::endl;
  3147. std::cout << "File \"" << filename.c_str() << "\" not found." << std::endl;
  3148. }
  3149. cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
  3150. }
  3151. else
  3152. {
  3153. done = true;
  3154. }
  3155. }
  3156. return ostr.str();
  3157. }
  3158. int cmCTest::RunMakeCommand(const char* command, std::string* output,
  3159. int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs)
  3160. {
  3161. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  3162. if(args.size() < 1)
  3163. {
  3164. return false;
  3165. }
  3166. std::vector<const char*> argv;
  3167. for(std::vector<cmStdString>::const_iterator a = args.begin();
  3168. a != args.end(); ++a)
  3169. {
  3170. argv.push_back(a->c_str());
  3171. }
  3172. argv.push_back(0);
  3173. if ( output )
  3174. {
  3175. *output = "";
  3176. }
  3177. cmsysProcess* cp = cmsysProcess_New();
  3178. cmsysProcess_SetCommand(cp, &*argv.begin());
  3179. cmsysProcess_SetWorkingDirectory(cp, dir);
  3180. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  3181. cmsysProcess_SetTimeout(cp, timeout);
  3182. cmsysProcess_Execute(cp);
  3183. std::string::size_type tick = 0;
  3184. std::string::size_type tick_len = 1024;
  3185. std::string::size_type tick_line_len = 50;
  3186. char* data;
  3187. int length;
  3188. if ( !verbose )
  3189. {
  3190. std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl;
  3191. std::cout << " " << std::flush;
  3192. }
  3193. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  3194. {
  3195. if ( output )
  3196. {
  3197. for(int cc =0; cc < length; ++cc)
  3198. {
  3199. if(data[cc] == 0)
  3200. {
  3201. data[cc] = '\n';
  3202. }
  3203. }
  3204. output->append(data, length);
  3205. if ( !verbose )
  3206. {
  3207. while ( output->size() > (tick * tick_len) )
  3208. {
  3209. tick ++;
  3210. std::cout << "." << std::flush;
  3211. if ( tick % tick_line_len == 0 && tick > 0 )
  3212. {
  3213. std::cout << " Size: ";
  3214. std::cout << int((output->size() / 1024.0) + 1) << "K" << std::endl;
  3215. std::cout << " " << std::flush;
  3216. }
  3217. }
  3218. }
  3219. }
  3220. if(verbose)
  3221. {
  3222. std::cout.write(data, length);
  3223. std::cout.flush();
  3224. }
  3225. if ( ofs )
  3226. {
  3227. ofs.write(data, length);
  3228. ofs.flush();
  3229. }
  3230. }
  3231. std::cout << " Size of output: ";
  3232. std::cout << int(output->size() / 1024.0) << "K" << std::endl;
  3233. cmsysProcess_WaitForExit(cp, 0);
  3234. int result = cmsysProcess_GetState(cp);
  3235. if(result == cmsysProcess_State_Exited)
  3236. {
  3237. *retVal = cmsysProcess_GetExitValue(cp);
  3238. }
  3239. else if(result == cmsysProcess_State_Exception)
  3240. {
  3241. *retVal = cmsysProcess_GetExitException(cp);
  3242. std::cout << "There was an exception: " << *retVal << std::endl;
  3243. }
  3244. else if(result == cmsysProcess_State_Expired)
  3245. {
  3246. std::cout << "There was a timeout" << std::endl;
  3247. }
  3248. else if(result == cmsysProcess_State_Error)
  3249. {
  3250. *output += "\n*** ERROR executing: ";
  3251. *output += cmsysProcess_GetErrorString(cp);
  3252. }
  3253. cmsysProcess_Delete(cp);
  3254. return result;
  3255. }
  3256. int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *retVal,
  3257. std::ostream* log)
  3258. {
  3259. if(cmSystemTools::SameFile(argv[0], m_CTestSelf.c_str()) && !m_ForceNewCTestProcess)
  3260. {
  3261. cmCTest inst;
  3262. inst.m_ConfigType = m_ConfigType;
  3263. inst.m_TimeOut = m_TimeOut;
  3264. std::vector<std::string> args;
  3265. for(unsigned int i =0; i < argv.size(); ++i)
  3266. {
  3267. if(argv[i])
  3268. {
  3269. args.push_back(argv[i]);
  3270. }
  3271. }
  3272. if ( *log )
  3273. {
  3274. *log << "* Run internal CTest" << std::endl;
  3275. }
  3276. std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
  3277. *retVal = inst.Run(args, output);
  3278. if ( *log )
  3279. {
  3280. *log << output->c_str();
  3281. }
  3282. cmSystemTools::ChangeDirectory(oldpath.c_str());
  3283. if(m_Verbose)
  3284. {
  3285. std::cout << "Internal cmCTest object used to run test.\n";
  3286. std::cout << *output << "\n";
  3287. }
  3288. return cmsysProcess_State_Exited;
  3289. }
  3290. std::vector<char> tempOutput;
  3291. if ( output )
  3292. {
  3293. *output = "";
  3294. }
  3295. cmsysProcess* cp = cmsysProcess_New();
  3296. cmsysProcess_SetCommand(cp, &*argv.begin());
  3297. // std::cout << "Command is: " << argv[0] << std::endl;
  3298. if(cmSystemTools::GetRunCommandHideConsole())
  3299. {
  3300. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  3301. }
  3302. cmsysProcess_SetTimeout(cp, m_TimeOut);
  3303. cmsysProcess_Execute(cp);
  3304. char* data;
  3305. int length;
  3306. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  3307. {
  3308. if ( output )
  3309. {
  3310. tempOutput.insert(tempOutput.end(), data, data+length);
  3311. }
  3312. if ( m_Verbose )
  3313. {
  3314. std::cout.write(data, length);
  3315. std::cout.flush();
  3316. }
  3317. if ( log )
  3318. {
  3319. log->write(data, length);
  3320. log->flush();
  3321. }
  3322. }
  3323. cmsysProcess_WaitForExit(cp, 0);
  3324. if(output)
  3325. {
  3326. output->append(&*tempOutput.begin(), tempOutput.size());
  3327. }
  3328. if ( m_Verbose )
  3329. {
  3330. std::cout << "-- Process completed" << std::endl;
  3331. }
  3332. int result = cmsysProcess_GetState(cp);
  3333. if(result == cmsysProcess_State_Exited)
  3334. {
  3335. *retVal = cmsysProcess_GetExitValue(cp);
  3336. }
  3337. else if(result == cmsysProcess_State_Exception)
  3338. {
  3339. *retVal = cmsysProcess_GetExitException(cp);
  3340. std::string outerr = "\n*** Exception executing: ";
  3341. outerr += cmsysProcess_GetExceptionString(cp);
  3342. *output += outerr;
  3343. if ( m_Verbose )
  3344. {
  3345. std::cout << outerr.c_str() << "\n";
  3346. std::cout.flush();
  3347. }
  3348. }
  3349. else if(result == cmsysProcess_State_Error)
  3350. {
  3351. std::string outerr = "\n*** ERROR executing: ";
  3352. outerr += cmsysProcess_GetErrorString(cp);
  3353. *output += outerr;
  3354. if ( m_Verbose )
  3355. {
  3356. std::cout << outerr.c_str() << "\n";
  3357. std::cout.flush();
  3358. }
  3359. }
  3360. cmsysProcess_Delete(cp);
  3361. return result;
  3362. }
  3363. const char* cmCTest::GetTestStatus(int status)
  3364. {
  3365. static const char statuses[][100] = {
  3366. "Not Run",
  3367. "Timeout",
  3368. "SEGFAULT",
  3369. "ILLEGAL",
  3370. "INTERRUPT",
  3371. "NUMERICAL",
  3372. "OTHER_FAULT",
  3373. "Failed",
  3374. "BAD_COMMAND",
  3375. "Completed"
  3376. };
  3377. if ( status < cmCTest::NOT_RUN || status > cmCTest::COMPLETED )
  3378. {
  3379. return "No Status";
  3380. }
  3381. return statuses[status];
  3382. }
  3383. void cmCTest::StartXML(std::ostream& ostr)
  3384. {
  3385. ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  3386. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  3387. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  3388. << this->GetTestModelString() << "\" Name=\""
  3389. << m_DartConfiguration["Site"] << "\" Generator=\"ctest-" << CMake_VERSION_FULL
  3390. << "\">" << std::endl;
  3391. }
  3392. void cmCTest::EndXML(std::ostream& ostr)
  3393. {
  3394. ostr << "</Site>" << std::endl;
  3395. }
  3396. bool cmCTest::ProcessMemCheckPurifyOutput(const std::string&, std::string& log,
  3397. int* results)
  3398. {
  3399. if ( !cmSystemTools::FileExists(m_MemoryTesterOutputFile.c_str()) )
  3400. {
  3401. log = "Cannot find Purify output file: " + m_MemoryTesterOutputFile;
  3402. std::cerr << log.c_str() << std::endl;
  3403. return false;
  3404. }
  3405. std::ifstream ifs(m_MemoryTesterOutputFile.c_str());
  3406. if ( !ifs )
  3407. {
  3408. log = "Cannot read Purify output file: " + m_MemoryTesterOutputFile;
  3409. std::cerr << log.c_str() << std::endl;
  3410. return false;
  3411. }
  3412. cmOStringStream ostr;
  3413. log = "";
  3414. cmsys::RegularExpression pfW("^\\[[WEI]\\] ([A-Z][A-Z][A-Z][A-Z]*): ");
  3415. int defects = 0;
  3416. std::string line;
  3417. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  3418. {
  3419. int failure = cmCTest::NO_MEMORY_FAULT;
  3420. if ( pfW.find(line) )
  3421. {
  3422. int cc;
  3423. for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
  3424. {
  3425. if ( pfW.match(1) == cmCTestMemCheckResultStrings[cc] )
  3426. {
  3427. failure = cc;
  3428. break;
  3429. }
  3430. }
  3431. if ( cc == cmCTest::NO_MEMORY_FAULT )
  3432. {
  3433. std::cerr<< "Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  3434. ostr << "*** Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  3435. }
  3436. }
  3437. if ( failure != NO_MEMORY_FAULT )
  3438. {
  3439. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  3440. results[failure] ++;
  3441. defects ++;
  3442. }
  3443. ostr << cmCTest::MakeXMLSafe(line) << std::endl;
  3444. }
  3445. log = ostr.str();
  3446. if ( defects )
  3447. {
  3448. return false;
  3449. }
  3450. return true;
  3451. }
  3452. bool cmCTest::ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
  3453. int* results)
  3454. {
  3455. std::vector<cmStdString> lines;
  3456. cmSystemTools::Split(str.c_str(), lines);
  3457. std::string::size_type cc;
  3458. cmOStringStream ostr;
  3459. log = "";
  3460. int defects = 0;
  3461. cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
  3462. cmsys::RegularExpression vgFIM(
  3463. "== .*Invalid free\\(\\) / delete / delete\\[\\]");
  3464. cmsys::RegularExpression vgFMM(
  3465. "== .*Mismatched free\\(\\) / delete / delete \\[\\]");
  3466. cmsys::RegularExpression vgMLK(
  3467. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are definitely lost"
  3468. " in loss record [0-9][0-9]* of [0-9]");
  3469. cmsys::RegularExpression vgPAR(
  3470. "== .*Syscall param .* contains unaddressable byte\\(s\\)");
  3471. cmsys::RegularExpression vgMPK1(
  3472. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are possibly lost in"
  3473. " loss record [0-9][0-9]* of [0-9]");
  3474. cmsys::RegularExpression vgMPK2(
  3475. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are still reachable"
  3476. " in loss record [0-9][0-9]* of [0-9]");
  3477. cmsys::RegularExpression vgUMC(
  3478. "== .*Conditional jump or move depends on uninitialised value\\(s\\)");
  3479. cmsys::RegularExpression vgUMR1("== .*Use of uninitialised value of size [0-9][0-9]*");
  3480. cmsys::RegularExpression vgUMR2("== .*Invalid read of size [0-9][0-9]*");
  3481. cmsys::RegularExpression vgUMR3("== .*Jump to the invalid address ");
  3482. cmsys::RegularExpression vgUMR4(
  3483. "== .*Syscall param .* contains uninitialised or unaddressable byte\\(s\\)");
  3484. cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9]");
  3485. cmsys::RegularExpression vgABR("== .*pthread_mutex_unlock: mutex is locked by a different thread");
  3486. //double sttime = cmSystemTools::GetTime();
  3487. //std::cout << "Start test: " << lines.size() << std::endl;
  3488. for ( cc = 0; cc < lines.size(); cc ++ )
  3489. {
  3490. if ( valgrindLine.find(lines[cc]) )
  3491. {
  3492. int failure = cmCTest::NO_MEMORY_FAULT;
  3493. if ( vgFIM.find(lines[cc]) ) { failure = cmCTest::FIM; }
  3494. else if ( vgFMM.find(lines[cc]) ) { failure = cmCTest::FMM; }
  3495. else if ( vgMLK.find(lines[cc]) ) { failure = cmCTest::MLK; }
  3496. else if ( vgPAR.find(lines[cc]) ) { failure = cmCTest::PAR; }
  3497. else if ( vgMPK1.find(lines[cc]) ){ failure = cmCTest::MPK; }
  3498. else if ( vgMPK2.find(lines[cc]) ){ failure = cmCTest::MPK; }
  3499. else if ( vgUMC.find(lines[cc]) ) { failure = cmCTest::UMC; }
  3500. else if ( vgUMR1.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3501. else if ( vgUMR2.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3502. else if ( vgUMR3.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3503. else if ( vgUMR4.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3504. else if ( vgIPW.find(lines[cc]) ) { failure = cmCTest::IPW; }
  3505. else if ( vgABR.find(lines[cc]) ) { failure = cmCTest::ABR; }
  3506. if ( failure != cmCTest::NO_MEMORY_FAULT )
  3507. {
  3508. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  3509. results[failure] ++;
  3510. defects ++;
  3511. }
  3512. ostr << cmCTest::MakeXMLSafe(lines[cc]) << std::endl;
  3513. }
  3514. }
  3515. //std::cout << "End test (elapsed: " << (cmSystemTools::GetTime() - sttime) << std::endl;
  3516. log = ostr.str();
  3517. if ( defects )
  3518. {
  3519. return false;
  3520. }
  3521. return true;
  3522. }
  3523. bool cmCTest::ProcessMemCheckOutput(const std::string& str, std::string& log, int* results)
  3524. {
  3525. std::string::size_type cc;
  3526. for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
  3527. {
  3528. results[cc] = 0;
  3529. }
  3530. if ( m_MemoryTesterStyle == cmCTest::VALGRIND )
  3531. {
  3532. return this->ProcessMemCheckValgrindOutput(str, log, results);
  3533. }
  3534. else if ( m_MemoryTesterStyle == cmCTest::PURIFY )
  3535. {
  3536. return this->ProcessMemCheckPurifyOutput(str, log, results);
  3537. }
  3538. else if ( m_MemoryTesterStyle == cmCTest::BOUNDS_CHECKER )
  3539. {
  3540. log.append("\nMemory checking style used was: ");
  3541. log.append("Bounds Checker");
  3542. }
  3543. else
  3544. {
  3545. log.append("\nMemory checking style used was: ");
  3546. log.append("None that I know");
  3547. log = str;
  3548. }
  3549. return true;
  3550. }
  3551. int cmCTest::GenerateDartNotesOutput(std::ostream& os, const cmCTest::tm_VectorOfStrings& files)
  3552. {
  3553. cmCTest::tm_VectorOfStrings::const_iterator it;
  3554. for ( it = files.begin(); it != files.end(); it ++ )
  3555. {
  3556. if ( !cmSystemTools::FileExists(it->c_str()) )
  3557. {
  3558. std::cerr << "Error creating notes. File " << it->c_str() << " does not exists" << std::endl;
  3559. return 0;
  3560. }
  3561. }
  3562. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  3563. << "<?xml-stylesheet type=\"text/xsl\" href=\"Dart/Source/Server/XSL/Build.xsl <file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
  3564. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"] << "\" BuildStamp=\""
  3565. << m_CurrentTag << "-" << this->GetTestModelString() << "\" Name=\""
  3566. << m_DartConfiguration["Site"] << "\" Generator=\"ctest-" << CMake_VERSION_FULL
  3567. << "\">\n"
  3568. << "<Notes>" << std::endl;
  3569. for ( it = files.begin(); it != files.end(); it ++ )
  3570. {
  3571. std::cout << "\tAdd file: " << it->c_str() << std::endl;
  3572. std::string note_time = this->CurrentTime();
  3573. os << "<Note Name=\"" << this->MakeXMLSafe(it->c_str()) << "\">\n"
  3574. << "<DateTime>" << note_time << "</DateTime>\n"
  3575. << "<Text>" << std::endl;
  3576. std::ifstream ifs(it->c_str());
  3577. if ( ifs )
  3578. {
  3579. std::string line;
  3580. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  3581. {
  3582. os << this->MakeXMLSafe(line) << std::endl;
  3583. }
  3584. ifs.close();
  3585. }
  3586. else
  3587. {
  3588. os << "Problem reading file: " << it->c_str() << std::endl;
  3589. std::cerr << "Problem reading file: " << it->c_str() << " while creating notes" << std::endl;
  3590. }
  3591. os << "</Text>\n"
  3592. << "</Note>" << std::endl;
  3593. }
  3594. os << "</Notes>\n"
  3595. << "</Site>" << std::endl;
  3596. return 1;
  3597. }
  3598. int cmCTest::GenerateNotesFile(const char* cfiles)
  3599. {
  3600. if ( !cfiles )
  3601. {
  3602. return 1;
  3603. }
  3604. std::vector<cmStdString> files;
  3605. std::cout << "Create notes file" << std::endl;
  3606. files = cmSystemTools::SplitString(cfiles, ';');
  3607. if ( files.size() == 0 )
  3608. {
  3609. return 1;
  3610. }
  3611. std::ofstream ofs;
  3612. if ( !this->OpenOutputFile(m_CurrentTag, "Notes.xml", ofs) )
  3613. {
  3614. std::cerr << "Cannot open notes file" << std::endl;
  3615. return 1;
  3616. }
  3617. this->GenerateDartNotesOutput(ofs, files);
  3618. return 0;
  3619. }
  3620. int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
  3621. {
  3622. this->FindRunningCMake(args[0].c_str());
  3623. const char* ctestExec = "ctest";
  3624. bool cmakeAndTest = false;
  3625. bool performSomeTest = true;
  3626. for(unsigned int i=1; i < args.size(); ++i)
  3627. {
  3628. std::string arg = args[i];
  3629. if(arg.find("-C",0) == 0 && i < args.size() - 1)
  3630. {
  3631. i++;
  3632. this->m_ConfigType = args[i];
  3633. cmSystemTools::ReplaceString(this->m_ConfigType, ".\\", "");
  3634. }
  3635. if( arg.find("-V",0) == 0 || arg.find("--verbose",0) == 0 )
  3636. {
  3637. this->m_Verbose = true;
  3638. this->ScriptHandler->SetVerbose(this->m_Verbose);
  3639. }
  3640. if( arg.find("-N",0) == 0 || arg.find("--show-only",0) == 0 )
  3641. {
  3642. this->m_ShowOnly = true;
  3643. }
  3644. if( arg.find("-S",0) == 0 && i < args.size() - 1 )
  3645. {
  3646. this->m_RunConfigurationScript = true;
  3647. i++;
  3648. this->ScriptHandler->AddConfigurationScript(args[i].c_str());
  3649. }
  3650. if( arg.find("--tomorrow-tag",0) == 0 )
  3651. {
  3652. m_TomorrowTag = true;
  3653. }
  3654. if( arg.find("--force-new-ctest-process",0) == 0 )
  3655. {
  3656. m_ForceNewCTestProcess = true;
  3657. }
  3658. if( arg.find("--interactive-debug-mode",0) == 0 && i < args.size() - 1 )
  3659. {
  3660. i++;
  3661. m_InteractiveDebugMode = cmSystemTools::IsOn(args[i].c_str());
  3662. }
  3663. if( arg.find("--compatibility-mode",0) == 0 )
  3664. {
  3665. m_CompatibilityMode = true;
  3666. }
  3667. if( arg.find("-D",0) == 0 && i < args.size() - 1 )
  3668. {
  3669. this->m_DartMode = true;
  3670. i++;
  3671. std::string targ = args[i];
  3672. if ( targ == "Experimental" )
  3673. {
  3674. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3675. this->SetTest("Start");
  3676. this->SetTest("Configure");
  3677. this->SetTest("Build");
  3678. this->SetTest("Test");
  3679. this->SetTest("Coverage");
  3680. this->SetTest("Submit");
  3681. }
  3682. else if ( targ == "ExperimentalStart" )
  3683. {
  3684. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3685. this->SetTest("Start");
  3686. }
  3687. else if ( targ == "ExperimentalUpdate" )
  3688. {
  3689. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3690. this->SetTest("Update");
  3691. }
  3692. else if ( targ == "ExperimentalConfigure" )
  3693. {
  3694. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3695. this->SetTest("Configure");
  3696. }
  3697. else if ( targ == "ExperimentalBuild" )
  3698. {
  3699. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3700. this->SetTest("Build");
  3701. }
  3702. else if ( targ == "ExperimentalTest" )
  3703. {
  3704. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3705. this->SetTest("Test");
  3706. }
  3707. else if ( targ == "ExperimentalMemCheck"
  3708. || targ == "ExperimentalPurify" )
  3709. {
  3710. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3711. this->SetTest("MemCheck");
  3712. }
  3713. else if ( targ == "ExperimentalCoverage" )
  3714. {
  3715. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3716. this->SetTest("Coverage");
  3717. }
  3718. else if ( targ == "ExperimentalSubmit" )
  3719. {
  3720. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3721. this->SetTest("Submit");
  3722. }
  3723. else if ( targ == "Continuous" )
  3724. {
  3725. this->SetTestModel(cmCTest::CONTINUOUS);
  3726. this->SetTest("Start");
  3727. this->SetTest("Update");
  3728. this->SetTest("Configure");
  3729. this->SetTest("Build");
  3730. this->SetTest("Test");
  3731. this->SetTest("Coverage");
  3732. this->SetTest("Submit");
  3733. }
  3734. else if ( targ == "ContinuousStart" )
  3735. {
  3736. this->SetTestModel(cmCTest::CONTINUOUS);
  3737. this->SetTest("Start");
  3738. }
  3739. else if ( targ == "ContinuousUpdate" )
  3740. {
  3741. this->SetTestModel(cmCTest::CONTINUOUS);
  3742. this->SetTest("Update");
  3743. }
  3744. else if ( targ == "ContinuousConfigure" )
  3745. {
  3746. this->SetTestModel(cmCTest::CONTINUOUS);
  3747. this->SetTest("Configure");
  3748. }
  3749. else if ( targ == "ContinuousBuild" )
  3750. {
  3751. this->SetTestModel(cmCTest::CONTINUOUS);
  3752. this->SetTest("Build");
  3753. }
  3754. else if ( targ == "ContinuousTest" )
  3755. {
  3756. this->SetTestModel(cmCTest::CONTINUOUS);
  3757. this->SetTest("Test");
  3758. }
  3759. else if ( targ == "ContinuousMemCheck"
  3760. || targ == "ContinuousPurify" )
  3761. {
  3762. this->SetTestModel(cmCTest::CONTINUOUS);
  3763. this->SetTest("MemCheck");
  3764. }
  3765. else if ( targ == "ContinuousCoverage" )
  3766. {
  3767. this->SetTestModel(cmCTest::CONTINUOUS);
  3768. this->SetTest("Coverage");
  3769. }
  3770. else if ( targ == "ContinuousSubmit" )
  3771. {
  3772. this->SetTestModel(cmCTest::CONTINUOUS);
  3773. this->SetTest("Submit");
  3774. }
  3775. else if ( targ == "Nightly" )
  3776. {
  3777. this->SetTestModel(cmCTest::NIGHTLY);
  3778. this->SetTest("Start");
  3779. this->SetTest("Update");
  3780. this->SetTest("Configure");
  3781. this->SetTest("Build");
  3782. this->SetTest("Test");
  3783. this->SetTest("Coverage");
  3784. this->SetTest("Submit");
  3785. }
  3786. else if ( targ == "NightlyStart" )
  3787. {
  3788. this->SetTestModel(cmCTest::NIGHTLY);
  3789. this->SetTest("Start");
  3790. }
  3791. else if ( targ == "NightlyUpdate" )
  3792. {
  3793. this->SetTestModel(cmCTest::NIGHTLY);
  3794. this->SetTest("Update");
  3795. }
  3796. else if ( targ == "NightlyConfigure" )
  3797. {
  3798. this->SetTestModel(cmCTest::NIGHTLY);
  3799. this->SetTest("Configure");
  3800. }
  3801. else if ( targ == "NightlyBuild" )
  3802. {
  3803. this->SetTestModel(cmCTest::NIGHTLY);
  3804. this->SetTest("Build");
  3805. }
  3806. else if ( targ == "NightlyTest" )
  3807. {
  3808. this->SetTestModel(cmCTest::NIGHTLY);
  3809. this->SetTest("Test");
  3810. }
  3811. else if ( targ == "NightlyMemCheck"
  3812. || targ == "NightlyPurify" )
  3813. {
  3814. this->SetTestModel(cmCTest::NIGHTLY);
  3815. this->SetTest("MemCheck");
  3816. }
  3817. else if ( targ == "NightlyCoverage" )
  3818. {
  3819. this->SetTestModel(cmCTest::NIGHTLY);
  3820. this->SetTest("Coverage");
  3821. }
  3822. else if ( targ == "NightlySubmit" )
  3823. {
  3824. this->SetTestModel(cmCTest::NIGHTLY);
  3825. this->SetTest("Submit");
  3826. }
  3827. else if ( targ == "MemoryCheck" )
  3828. {
  3829. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3830. this->SetTest("Start");
  3831. this->SetTest("Configure");
  3832. this->SetTest("Build");
  3833. this->SetTest("MemCheck");
  3834. this->SetTest("Coverage");
  3835. this->SetTest("Submit");
  3836. }
  3837. else if ( targ == "NightlyMemoryCheck" )
  3838. {
  3839. this->SetTestModel(cmCTest::NIGHTLY);
  3840. this->SetTest("Start");
  3841. this->SetTest("Update");
  3842. this->SetTest("Configure");
  3843. this->SetTest("Build");
  3844. this->SetTest("MemCheck");
  3845. this->SetTest("Coverage");
  3846. this->SetTest("Submit");
  3847. }
  3848. else
  3849. {
  3850. performSomeTest = false;
  3851. std::cerr << "CTest -D called with incorrect option: " << targ << std::endl;
  3852. std::cerr << "Available options are:" << std::endl
  3853. << " " << ctestExec << " -D Continuous" << std::endl
  3854. << " " << ctestExec << " -D Continuous(Start|Update|Configure|Build)" << std::endl
  3855. << " " << ctestExec << " -D Continuous(Test|Coverage|MemCheck|Submit)" << std::endl
  3856. << " " << ctestExec << " -D Experimental" << std::endl
  3857. << " " << ctestExec << " -D Experimental(Start|Update|Configure|Build)" << std::endl
  3858. << " " << ctestExec << " -D Experimental(Test|Coverage|MemCheck|Submit)" << std::endl
  3859. << " " << ctestExec << " -D Nightly" << std::endl
  3860. << " " << ctestExec << " -D Nightly(Start|Update|Configure|Build)" << std::endl
  3861. << " " << ctestExec << " -D Nightly(Test|Coverage|MemCheck|Submit)" << std::endl
  3862. << " " << ctestExec << " -D NightlyMemoryCheck" << std::endl;
  3863. ;
  3864. }
  3865. }
  3866. if( ( arg.find("-T",0) == 0 ) &&
  3867. (i < args.size() -1) )
  3868. {
  3869. this->m_DartMode = true;
  3870. i++;
  3871. if ( !this->SetTest(args[i].c_str(), false) )
  3872. {
  3873. performSomeTest = false;
  3874. std::cerr << "CTest -T called with incorrect option: " << args[i].c_str() << std::endl;
  3875. std::cerr << "Available options are:" << std::endl
  3876. << " " << ctestExec << " -T all" << std::endl
  3877. << " " << ctestExec << " -T start" << std::endl
  3878. << " " << ctestExec << " -T update" << std::endl
  3879. << " " << ctestExec << " -T configure" << std::endl
  3880. << " " << ctestExec << " -T build" << std::endl
  3881. << " " << ctestExec << " -T test" << std::endl
  3882. << " " << ctestExec << " -T coverage" << std::endl
  3883. << " " << ctestExec << " -T memcheck" << std::endl
  3884. << " " << ctestExec << " -T notes" << std::endl
  3885. << " " << ctestExec << " -T submit" << std::endl;
  3886. }
  3887. }
  3888. if( ( arg.find("-M",0) == 0 || arg.find("--test-model",0) == 0 ) &&
  3889. (i < args.size() -1) )
  3890. {
  3891. i++;
  3892. std::string const& str = args[i];
  3893. if ( cmSystemTools::LowerCase(str) == "nightly" )
  3894. {
  3895. this->SetTestModel(cmCTest::NIGHTLY);
  3896. }
  3897. else if ( cmSystemTools::LowerCase(str) == "continuous" )
  3898. {
  3899. this->SetTestModel(cmCTest::CONTINUOUS);
  3900. }
  3901. else if ( cmSystemTools::LowerCase(str) == "experimental" )
  3902. {
  3903. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3904. }
  3905. else
  3906. {
  3907. performSomeTest = false;
  3908. std::cerr << "CTest -M called with incorrect option: " << str.c_str() << std::endl;
  3909. std::cerr << "Available options are:" << std::endl
  3910. << " " << ctestExec << " -M Continuous" << std::endl
  3911. << " " << ctestExec << " -M Experimental" << std::endl
  3912. << " " << ctestExec << " -M Nightly" << std::endl;
  3913. }
  3914. }
  3915. if(arg.find("-I",0) == 0 && i < args.size() - 1)
  3916. {
  3917. i++;
  3918. this->SetTestsToRunInformation(args[i].c_str());
  3919. }
  3920. if(arg.find("-R",0) == 0 && i < args.size() - 1)
  3921. {
  3922. this->m_UseIncludeRegExp = true;
  3923. i++;
  3924. this->m_IncludeRegExp = args[i];
  3925. }
  3926. if(arg.find("-E",0) == 0 && i < args.size() - 1)
  3927. {
  3928. this->m_UseExcludeRegExp = true;
  3929. i++;
  3930. this->m_ExcludeRegExp = args[i];
  3931. this->m_UseExcludeRegExpFirst = this->m_UseIncludeRegExp ? false : true;
  3932. }
  3933. if(arg.find("-A",0) == 0 && i < args.size() - 1)
  3934. {
  3935. this->m_DartMode = true;
  3936. this->SetTest("Notes");
  3937. i++;
  3938. this->SetNotesFiles(args[i].c_str());
  3939. }
  3940. // --build-and-test options
  3941. if(arg.find("--build-and-test",0) == 0 && i < args.size() - 1)
  3942. {
  3943. cmakeAndTest = true;
  3944. if(i+2 < args.size())
  3945. {
  3946. i++;
  3947. m_SourceDir = args[i];
  3948. i++;
  3949. m_BinaryDir = args[i];
  3950. // dir must exist before CollapseFullPath is called
  3951. cmSystemTools::MakeDirectory(m_BinaryDir.c_str());
  3952. m_BinaryDir = cmSystemTools::CollapseFullPath(m_BinaryDir.c_str());
  3953. m_SourceDir = cmSystemTools::CollapseFullPath(m_SourceDir.c_str());
  3954. }
  3955. else
  3956. {
  3957. std::cerr << "--build-and-test must have source and binary dir\n";
  3958. }
  3959. }
  3960. if(arg.find("--build-target",0) == 0 && i < args.size() - 1)
  3961. {
  3962. i++;
  3963. m_BuildTarget = args[i];
  3964. }
  3965. if(arg.find("--build-nocmake",0) == 0)
  3966. {
  3967. m_BuildNoCMake = true;
  3968. }
  3969. if(arg.find("--build-run-dir",0) == 0 && i < args.size() - 1)
  3970. {
  3971. i++;
  3972. m_BuildRunDir = args[i];
  3973. }
  3974. if(arg.find("--build-two-config",0) == 0)
  3975. {
  3976. m_BuildTwoConfig = true;
  3977. }
  3978. if(arg.find("--build-exe-dir",0) == 0 && i < args.size() - 1)
  3979. {
  3980. i++;
  3981. m_ExecutableDirectory = args[i];
  3982. }
  3983. if(arg.find("--build-generator",0) == 0 && i < args.size() - 1)
  3984. {
  3985. i++;
  3986. m_BuildGenerator = args[i];
  3987. }
  3988. if(arg.find("--build-project",0) == 0 && i < args.size() - 1)
  3989. {
  3990. i++;
  3991. m_BuildProject = args[i];
  3992. }
  3993. if(arg.find("--build-makeprogram",0) == 0 && i < args.size() - 1)
  3994. {
  3995. i++;
  3996. m_BuildMakeProgram = args[i];
  3997. }
  3998. if(arg.find("--build-noclean",0) == 0)
  3999. {
  4000. m_BuildNoClean = true;
  4001. }
  4002. if(arg.find("--build-options",0) == 0 && i < args.size() - 1)
  4003. {
  4004. ++i;
  4005. bool done = false;
  4006. while(i < args.size() && !done)
  4007. {
  4008. m_BuildOptions.push_back(args[i]);
  4009. if(i+1 < args.size()
  4010. && (args[i+1] == "--build-target" || args[i+1] == "--test-command"))
  4011. {
  4012. done = true;
  4013. }
  4014. else
  4015. {
  4016. ++i;
  4017. }
  4018. }
  4019. }
  4020. if(arg.find("--test-command",0) == 0 && i < args.size() - 1)
  4021. {
  4022. ++i;
  4023. m_TestCommand = args[i];
  4024. while(i+1 < args.size())
  4025. {
  4026. ++i;
  4027. m_TestCommandArgs.push_back(args[i]);
  4028. }
  4029. }
  4030. }
  4031. if(cmakeAndTest)
  4032. {
  4033. cmSystemTools::ResetErrorOccuredFlag();
  4034. cmListFileCache::GetInstance()->ClearCache();
  4035. int retv = this->RunCMakeAndTest(output);
  4036. cmSystemTools::ResetErrorOccuredFlag();
  4037. cmListFileCache::GetInstance()->ClearCache();
  4038. #ifdef CMAKE_BUILD_WITH_CMAKE
  4039. cmDynamicLoader::FlushCache();
  4040. #endif
  4041. return retv;
  4042. }
  4043. if(performSomeTest )
  4044. {
  4045. int res;
  4046. // call process directory
  4047. if (this->m_RunConfigurationScript)
  4048. {
  4049. res = this->ScriptHandler->RunConfigurationScript();
  4050. }
  4051. else
  4052. {
  4053. if ( !this->Initialize() )
  4054. {
  4055. res = 12;
  4056. }
  4057. else
  4058. {
  4059. res = this->ProcessTests();
  4060. }
  4061. this->Finalize();
  4062. }
  4063. return res;
  4064. }
  4065. return 1;
  4066. }
  4067. void cmCTest::FindRunningCMake(const char* arg0)
  4068. {
  4069. // Find our own executable.
  4070. std::vector<cmStdString> failures;
  4071. m_CTestSelf = arg0;
  4072. cmSystemTools::ConvertToUnixSlashes(m_CTestSelf);
  4073. failures.push_back(m_CTestSelf);
  4074. m_CTestSelf = cmSystemTools::FindProgram(m_CTestSelf.c_str());
  4075. if(!cmSystemTools::FileExists(m_CTestSelf.c_str()))
  4076. {
  4077. failures.push_back(m_CTestSelf);
  4078. m_CTestSelf = "/usr/local/bin/ctest";
  4079. }
  4080. if(!cmSystemTools::FileExists(m_CTestSelf.c_str()))
  4081. {
  4082. failures.push_back(m_CTestSelf);
  4083. cmOStringStream msg;
  4084. msg << "CTEST can not find the command line program cmake.\n";
  4085. msg << " argv[0] = \"" << arg0 << "\"\n";
  4086. msg << " Attempted paths:\n";
  4087. std::vector<cmStdString>::iterator i;
  4088. for(i=failures.begin(); i != failures.end(); ++i)
  4089. {
  4090. msg << " \"" << i->c_str() << "\"\n";
  4091. }
  4092. cmSystemTools::Error(msg.str().c_str());
  4093. }
  4094. std::string dir;
  4095. std::string file;
  4096. if(cmSystemTools::SplitProgramPath(m_CTestSelf.c_str(),
  4097. dir,
  4098. file,
  4099. true))
  4100. {
  4101. m_CMakeSelf = dir += "/cmake";
  4102. m_CMakeSelf += cmSystemTools::GetExecutableExtension();
  4103. if(!cmSystemTools::FileExists(m_CMakeSelf.c_str()))
  4104. {
  4105. cmOStringStream msg;
  4106. failures.push_back(m_CMakeSelf);
  4107. msg << "CTEST can not find the command line program cmake.\n";
  4108. msg << " argv[0] = \"" << arg0 << "\"\n";
  4109. msg << " Attempted path:\n";
  4110. msg << " \"" << m_CMakeSelf.c_str() << "\"\n";
  4111. cmSystemTools::Error(msg.str().c_str());
  4112. }
  4113. }
  4114. }
  4115. void CMakeMessageCallback(const char* m, const char*, bool&, void* s)
  4116. {
  4117. std::string* out = (std::string*)s;
  4118. *out += m;
  4119. *out += "\n";
  4120. }
  4121. void CMakeStdoutCallback(const char* m, int len, void* s)
  4122. {
  4123. std::string* out = (std::string*)s;
  4124. out->append(m, len);
  4125. }
  4126. int cmCTest::RunCMakeAndTest(std::string* outstring)
  4127. {
  4128. unsigned int k;
  4129. std::string cmakeOutString;
  4130. cmSystemTools::SetErrorCallback(CMakeMessageCallback, &cmakeOutString);
  4131. cmSystemTools::SetStdoutCallback(CMakeStdoutCallback, &cmakeOutString);
  4132. cmOStringStream out;
  4133. cmake cm;
  4134. double timeout = m_TimeOut;
  4135. // default to the build type of ctest itself
  4136. if(m_ConfigType.size() == 0)
  4137. {
  4138. #ifdef CMAKE_INTDIR
  4139. m_ConfigType = CMAKE_INTDIR;
  4140. #endif
  4141. }
  4142. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  4143. out << "Internal cmake changing into directory: " << m_BinaryDir << "\n";
  4144. if (!cmSystemTools::FileIsDirectory(m_BinaryDir.c_str()))
  4145. {
  4146. cmSystemTools::MakeDirectory(m_BinaryDir.c_str());
  4147. }
  4148. cmSystemTools::ChangeDirectory(m_BinaryDir.c_str());
  4149. if(!m_BuildNoCMake)
  4150. {
  4151. std::vector<std::string> args;
  4152. args.push_back(m_CMakeSelf);
  4153. args.push_back(m_SourceDir);
  4154. if(m_BuildGenerator.size())
  4155. {
  4156. std::string generator = "-G";
  4157. generator += m_BuildGenerator;
  4158. args.push_back(generator);
  4159. }
  4160. if ( m_ConfigType.size() > 0 )
  4161. {
  4162. std::string btype = "-DBUILD_TYPE:STRING=" + m_ConfigType;
  4163. args.push_back(btype);
  4164. }
  4165. for(k=0; k < m_BuildOptions.size(); ++k)
  4166. {
  4167. args.push_back(m_BuildOptions[k]);
  4168. }
  4169. if (cm.Run(args) != 0)
  4170. {
  4171. out << "Error: cmake execution failed\n";
  4172. out << cmakeOutString << "\n";
  4173. // return to the original directory
  4174. cmSystemTools::ChangeDirectory(cwd.c_str());
  4175. if(outstring)
  4176. {
  4177. *outstring = out.str();
  4178. }
  4179. else
  4180. {
  4181. std::cerr << out.str() << "\n";
  4182. }
  4183. return 1;
  4184. }
  4185. if(m_BuildTwoConfig)
  4186. {
  4187. if (cm.Run(args) != 0)
  4188. {
  4189. out << "Error: cmake execution failed\n";
  4190. out << cmakeOutString << "\n";
  4191. // return to the original directory
  4192. cmSystemTools::ChangeDirectory(cwd.c_str());
  4193. if(outstring)
  4194. {
  4195. *outstring = out.str();
  4196. }
  4197. else
  4198. {
  4199. std::cerr << out.str() << "\n";
  4200. }
  4201. return 1;
  4202. }
  4203. }
  4204. }
  4205. cmSystemTools::SetErrorCallback(0, 0);
  4206. out << cmakeOutString << "\n";
  4207. if(m_BuildMakeProgram.size() == 0)
  4208. {
  4209. out << "Error: cmake does not have a valid MAKEPROGRAM\n";
  4210. out << "Did you specify a --build-makeprogram and a --build-generator?\n";
  4211. if(outstring)
  4212. {
  4213. *outstring = out.str();
  4214. }
  4215. else
  4216. {
  4217. std::cerr << out.str() << "\n";
  4218. }
  4219. return 1;
  4220. }
  4221. int retVal = 0;
  4222. std::string makeCommand = cmSystemTools::ConvertToOutputPath(m_BuildMakeProgram.c_str());
  4223. std::string lowerCaseCommand = cmSystemTools::LowerCase(makeCommand);
  4224. // if msdev is the make program then do the following
  4225. // MSDEV 6.0
  4226. if(lowerCaseCommand.find("msdev") != std::string::npos)
  4227. {
  4228. // if there are spaces in the makeCommand, assume a full path
  4229. // and convert it to a path with no spaces in it as the
  4230. // RunSingleCommand does not like spaces
  4231. #if defined(_WIN32) && !defined(__CYGWIN__)
  4232. if(makeCommand.find(' ') != std::string::npos)
  4233. {
  4234. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  4235. }
  4236. #endif
  4237. makeCommand += " ";
  4238. makeCommand += m_BuildProject;
  4239. makeCommand += ".dsw /MAKE \"ALL_BUILD - ";
  4240. makeCommand += m_ConfigType;
  4241. if(m_BuildNoClean)
  4242. {
  4243. makeCommand += "\" /BUILD";
  4244. }
  4245. else
  4246. {
  4247. makeCommand += "\" /REBUILD";
  4248. }
  4249. }
  4250. // MSDEV 7.0 .NET
  4251. else if (lowerCaseCommand.find("devenv") != std::string::npos)
  4252. {
  4253. #if defined(_WIN32) && !defined(__CYGWIN__)
  4254. if(makeCommand.find(' ') != std::string::npos)
  4255. {
  4256. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  4257. }
  4258. #endif
  4259. makeCommand += " ";
  4260. makeCommand += m_BuildProject;
  4261. makeCommand += ".sln ";
  4262. if(m_BuildNoClean)
  4263. {
  4264. makeCommand += "/build ";
  4265. }
  4266. else
  4267. {
  4268. makeCommand += "/rebuild ";
  4269. }
  4270. makeCommand += m_ConfigType + " /project ALL_BUILD";
  4271. }
  4272. else if (lowerCaseCommand.find("make") != std::string::npos)
  4273. {
  4274. // assume a make sytle program
  4275. // clean first
  4276. if(!m_BuildNoClean)
  4277. {
  4278. std::string cleanCommand = makeCommand;
  4279. cleanCommand += " clean";
  4280. out << "Running make clean command: " << cleanCommand.c_str() << " ...\n";
  4281. retVal = 0;
  4282. std::string output;
  4283. if (!cmSystemTools::RunSingleCommand(cleanCommand.c_str(), &output, &retVal, 0,
  4284. false, timeout) ||
  4285. retVal)
  4286. {
  4287. out << "Error: " << cleanCommand.c_str() << " execution failed\n";
  4288. out << output.c_str() << "\n";
  4289. // return to the original directory
  4290. cmSystemTools::ChangeDirectory(cwd.c_str());
  4291. out << "Return value: " << retVal << std::endl;
  4292. if(outstring)
  4293. {
  4294. *outstring = out.str();
  4295. }
  4296. else
  4297. {
  4298. std::cerr << out.str() << "\n";
  4299. }
  4300. return 1;
  4301. }
  4302. out << output;
  4303. }
  4304. if(m_BuildTarget.size())
  4305. {
  4306. makeCommand += " ";
  4307. makeCommand += m_BuildTarget;
  4308. }
  4309. }
  4310. // command line make program
  4311. out << "Running make command: " << makeCommand.c_str() << "\n";
  4312. retVal = 0;
  4313. std::string output;
  4314. if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), &output, &retVal, 0, false, timeout))
  4315. {
  4316. out << "Error: " << makeCommand.c_str() << " execution failed\n";
  4317. out << output.c_str() << "\n";
  4318. // return to the original directory
  4319. cmSystemTools::ChangeDirectory(cwd.c_str());
  4320. out << "Return value: " << retVal << std::endl;
  4321. if(outstring)
  4322. {
  4323. *outstring = out.str();
  4324. }
  4325. else
  4326. {
  4327. std::cerr << out.str() << "\n";
  4328. }
  4329. return 1;
  4330. }
  4331. if ( retVal )
  4332. {
  4333. if(outstring)
  4334. {
  4335. *outstring = out.str();
  4336. *outstring += "Building of project failed\n";
  4337. *outstring += output;
  4338. *outstring += "\n";
  4339. }
  4340. else
  4341. {
  4342. std::cerr << "Building of project failed\n";
  4343. std::cerr << out.str() << output << "\n";
  4344. }
  4345. // return to the original directory
  4346. cmSystemTools::ChangeDirectory(cwd.c_str());
  4347. return 1;
  4348. }
  4349. out << output;
  4350. if(m_TestCommand.size() == 0)
  4351. {
  4352. if(outstring)
  4353. {
  4354. *outstring = out.str();
  4355. }
  4356. else
  4357. {
  4358. std::cout << out.str() << "\n";
  4359. }
  4360. return retVal;
  4361. }
  4362. // now run the compiled test if we can find it
  4363. std::vector<std::string> attempted;
  4364. std::vector<std::string> failed;
  4365. std::string tempPath;
  4366. std::string filepath =
  4367. cmSystemTools::GetFilenamePath(m_TestCommand);
  4368. std::string filename =
  4369. cmSystemTools::GetFilenameName(m_TestCommand);
  4370. // if full path specified then search that first
  4371. if (filepath.size())
  4372. {
  4373. tempPath = filepath;
  4374. tempPath += "/";
  4375. tempPath += filename;
  4376. attempted.push_back(tempPath);
  4377. if(m_ConfigType.size())
  4378. {
  4379. tempPath = filepath;
  4380. tempPath += "/";
  4381. tempPath += m_ConfigType;
  4382. tempPath += "/";
  4383. tempPath += filename;
  4384. attempted.push_back(tempPath);
  4385. }
  4386. }
  4387. // otherwise search local dirs
  4388. else
  4389. {
  4390. attempted.push_back(filename);
  4391. if(m_ConfigType.size())
  4392. {
  4393. tempPath = m_ConfigType;
  4394. tempPath += "/";
  4395. tempPath += filename;
  4396. attempted.push_back(tempPath);
  4397. }
  4398. }
  4399. // if m_ExecutableDirectory is set try that as well
  4400. if (m_ExecutableDirectory.size())
  4401. {
  4402. tempPath = m_ExecutableDirectory;
  4403. tempPath += "/";
  4404. tempPath += m_TestCommand;
  4405. attempted.push_back(tempPath);
  4406. if(m_ConfigType.size())
  4407. {
  4408. tempPath = m_ExecutableDirectory;
  4409. tempPath += "/";
  4410. tempPath += m_ConfigType;
  4411. tempPath += "/";
  4412. tempPath += filename;
  4413. attempted.push_back(tempPath);
  4414. }
  4415. }
  4416. // store the final location in fullPath
  4417. std::string fullPath;
  4418. // now look in the paths we specified above
  4419. for(unsigned int ai=0;
  4420. ai < attempted.size() && fullPath.size() == 0; ++ai)
  4421. {
  4422. // first check without exe extension
  4423. if(cmSystemTools::FileExists(attempted[ai].c_str())
  4424. && !cmSystemTools::FileIsDirectory(attempted[ai].c_str()))
  4425. {
  4426. fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str());
  4427. }
  4428. // then try with the exe extension
  4429. else
  4430. {
  4431. failed.push_back(attempted[ai].c_str());
  4432. tempPath = attempted[ai];
  4433. tempPath += cmSystemTools::GetExecutableExtension();
  4434. if(cmSystemTools::FileExists(tempPath.c_str())
  4435. && !cmSystemTools::FileIsDirectory(tempPath.c_str()))
  4436. {
  4437. fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str());
  4438. }
  4439. else
  4440. {
  4441. failed.push_back(tempPath.c_str());
  4442. }
  4443. }
  4444. }
  4445. if(!cmSystemTools::FileExists(fullPath.c_str()))
  4446. {
  4447. out << "Could not find path to executable, perhaps it was not built: " <<
  4448. m_TestCommand << "\n";
  4449. out << "tried to find it in these places:\n";
  4450. out << fullPath.c_str() << "\n";
  4451. for(unsigned int i=0; i < failed.size(); ++i)
  4452. {
  4453. out << failed[i] << "\n";
  4454. }
  4455. if(outstring)
  4456. {
  4457. *outstring = out.str();
  4458. }
  4459. else
  4460. {
  4461. std::cerr << out.str();
  4462. }
  4463. // return to the original directory
  4464. cmSystemTools::ChangeDirectory(cwd.c_str());
  4465. return 1;
  4466. }
  4467. std::vector<const char*> testCommand;
  4468. testCommand.push_back(fullPath.c_str());
  4469. for(k=0; k < m_TestCommandArgs.size(); ++k)
  4470. {
  4471. testCommand.push_back(m_TestCommandArgs[k].c_str());
  4472. }
  4473. testCommand.push_back(0);
  4474. std::string outs;
  4475. int retval = 0;
  4476. // run the test from the m_BuildRunDir if set
  4477. if(m_BuildRunDir.size())
  4478. {
  4479. out << "Run test in directory: " << m_BuildRunDir << "\n";
  4480. cmSystemTools::ChangeDirectory(m_BuildRunDir.c_str());
  4481. }
  4482. out << "Running test executable: " << fullPath << " ";
  4483. for(k=0; k < m_TestCommandArgs.size(); ++k)
  4484. {
  4485. out << m_TestCommandArgs[k] << " ";
  4486. }
  4487. out << "\n";
  4488. m_TimeOut = timeout;
  4489. int runTestRes = this->RunTest(testCommand, &outs, &retval, 0);
  4490. if(runTestRes != cmsysProcess_State_Exited || retval != 0)
  4491. {
  4492. out << "Failed to run test command: " << testCommand[0] << "\n";
  4493. retval = 1;
  4494. }
  4495. out << outs << "\n";
  4496. if(outstring)
  4497. {
  4498. *outstring = out.str();
  4499. }
  4500. else
  4501. {
  4502. std::cout << out.str() << "\n";
  4503. }
  4504. return retval;
  4505. }
  4506. void cmCTest::SetNotesFiles(const char* notes)
  4507. {
  4508. if ( !notes )
  4509. {
  4510. return;
  4511. }
  4512. m_NotesFiles = notes;
  4513. }
  4514. int cmCTest::ReadCustomConfigurationFileTree(const char* dir)
  4515. {
  4516. tm_VectorOfStrings dirs;
  4517. tm_VectorOfStrings ndirs;
  4518. dirs.push_back(dir);
  4519. cmake cm;
  4520. cmGlobalGenerator gg;
  4521. gg.SetCMakeInstance(&cm);
  4522. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  4523. lg->SetGlobalGenerator(&gg);
  4524. cmMakefile *mf = lg->GetMakefile();
  4525. while ( dirs.size() > 0 )
  4526. {
  4527. tm_VectorOfStrings::iterator cdir = dirs.end()-1;
  4528. std::string rexpr = *cdir + "/*";
  4529. std::string fname = *cdir + "/CTestCustom.ctest";
  4530. if ( cmSystemTools::FileExists(fname.c_str()) &&
  4531. (!lg->GetMakefile()->ReadListFile(0, fname.c_str()) ||
  4532. cmSystemTools::GetErrorOccuredFlag() ) )
  4533. {
  4534. std::cerr << "Problem reading custom configuration" << std::endl;
  4535. }
  4536. dirs.erase(dirs.end()-1, dirs.end());
  4537. cmSystemTools::SimpleGlob(rexpr, ndirs, -1);
  4538. dirs.insert(dirs.end(), ndirs.begin(), ndirs.end());
  4539. }
  4540. this->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_MATCH", m_CustomErrorMatches);
  4541. this->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_EXCEPTION", m_CustomErrorExceptions);
  4542. this->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_MATCH", m_CustomWarningMatches);
  4543. this->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_EXCEPTION", m_CustomWarningExceptions);
  4544. this->PopulateCustomVector(mf, "CTEST_CUSTOM_TESTS_IGNORE", m_CustomTestsIgnore);
  4545. this->PopulateCustomVector(mf, "CTEST_CUSTOM_MEMCHECK_IGNORE", m_CustomMemCheckIgnore);
  4546. this->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST", m_CustomPreTest);
  4547. this->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST", m_CustomPostTest);
  4548. this->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_MEMCHECK", m_CustomPreMemCheck);
  4549. this->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_MEMCHECK", m_CustomPostMemCheck);
  4550. const char* maxstr = mf->GetDefinition("CTEST_CUSTOM_PASSED_TEST_STRING_MAXLEN");
  4551. if ( maxstr )
  4552. {
  4553. long val = atoi(maxstr);
  4554. if ( val > 0 )
  4555. {
  4556. m_MaximumPassedTestResultSize = val;
  4557. }
  4558. }
  4559. maxstr = mf->GetDefinition("CTEST_CUSTOM_FAILED_TEST_STRING_MAXLEN");
  4560. if ( maxstr )
  4561. {
  4562. long val = atoi(maxstr);
  4563. if ( val > 0 )
  4564. {
  4565. m_MaximumFailedTestResultSize = val;
  4566. }
  4567. }
  4568. return 1;
  4569. }
  4570. void cmCTest::PopulateCustomVector(cmMakefile* mf, const char* def, tm_VectorOfStrings& vec)
  4571. {
  4572. if ( !def)
  4573. {
  4574. return;
  4575. }
  4576. const char* dval = mf->GetDefinition(def);
  4577. if ( !dval )
  4578. {
  4579. return;
  4580. }
  4581. std::vector<std::string> slist;
  4582. cmSystemTools::ExpandListArgument(dval, slist);
  4583. std::vector<std::string>::iterator it;
  4584. for ( it = slist.begin(); it != slist.end(); ++it )
  4585. {
  4586. vec.push_back(it->c_str());
  4587. }
  4588. }
  4589. int cmCTest::ExecuteCommands(tm_VectorOfStrings& vec)
  4590. {
  4591. tm_VectorOfStrings::iterator it;
  4592. for ( it = vec.begin(); it != vec.end(); ++it )
  4593. {
  4594. int retVal = 0;
  4595. if ( m_Verbose )
  4596. {
  4597. std::cout << "Run command: " << *it << std::endl;
  4598. }
  4599. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true /*m_Verbose*/) ||
  4600. retVal != 0 )
  4601. {
  4602. std::cerr << "Problem running command: " << *it << std::endl;
  4603. return 0;
  4604. }
  4605. }
  4606. return 1;
  4607. }
  4608. // get the next number in a string with numbers separated by ,
  4609. // pos is the start of the search and pos2 is the end of the search
  4610. // pos becomes pos2 after a call to GetNextNumber.
  4611. // -1 is returned at the end of the list.
  4612. inline int GetNextNumber(std::string const& in,
  4613. int& val,
  4614. std::string::size_type& pos,
  4615. std::string::size_type& pos2)
  4616. {
  4617. pos2 = in.find(',', pos);
  4618. if(pos2 != in.npos)
  4619. {
  4620. if(pos2-pos == 0)
  4621. {
  4622. val = -1;
  4623. }
  4624. else
  4625. {
  4626. val = atoi(in.substr(pos, pos2-pos).c_str());
  4627. }
  4628. pos = pos2+1;
  4629. return 1;
  4630. }
  4631. else
  4632. {
  4633. if(in.size()-pos == 0)
  4634. {
  4635. val = -1;
  4636. }
  4637. else
  4638. {
  4639. val = atoi(in.substr(pos, in.size()-pos).c_str());
  4640. }
  4641. return 0;
  4642. }
  4643. }
  4644. // get the next number in a string with numbers separated by ,
  4645. // pos is the start of the search and pos2 is the end of the search
  4646. // pos becomes pos2 after a call to GetNextNumber.
  4647. // -1 is returned at the end of the list.
  4648. inline int GetNextRealNumber(std::string const& in,
  4649. double& val,
  4650. std::string::size_type& pos,
  4651. std::string::size_type& pos2)
  4652. {
  4653. pos2 = in.find(',', pos);
  4654. if(pos2 != in.npos)
  4655. {
  4656. if(pos2-pos == 0)
  4657. {
  4658. val = -1;
  4659. }
  4660. else
  4661. {
  4662. val = atof(in.substr(pos, pos2-pos).c_str());
  4663. }
  4664. pos = pos2+1;
  4665. return 1;
  4666. }
  4667. else
  4668. {
  4669. if(in.size()-pos == 0)
  4670. {
  4671. val = -1;
  4672. }
  4673. else
  4674. {
  4675. val = atof(in.substr(pos, in.size()-pos).c_str());
  4676. }
  4677. return 0;
  4678. }
  4679. }
  4680. void cmCTest::SetTestsToRunInformation(const char* in)
  4681. {
  4682. this->TestsToRunString = in;
  4683. // if the argument is a file, then read it and use the contents as the string
  4684. if(cmSystemTools::FileExists(in))
  4685. {
  4686. std::ifstream fin(in);
  4687. unsigned long filelen = cmSystemTools::FileLength(in);
  4688. char* buff = new char[filelen+1];
  4689. fin.getline(buff, filelen);
  4690. buff[fin.gcount()] = 0;
  4691. this->TestsToRunString = buff;
  4692. }
  4693. }
  4694. void cmCTest::ExpandTestsToRunInformation(int numTests)
  4695. {
  4696. if (this->TestsToRunString.empty())
  4697. {
  4698. return;
  4699. }
  4700. int start;
  4701. int end = -1;
  4702. double stride = -1;
  4703. std::string::size_type pos = 0;
  4704. std::string::size_type pos2;
  4705. // read start
  4706. if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
  4707. {
  4708. // read end
  4709. if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
  4710. {
  4711. // read stride
  4712. if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
  4713. {
  4714. int val =0;
  4715. // now read specific numbers
  4716. while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
  4717. {
  4718. m_TestsToRun.push_back(val);
  4719. }
  4720. m_TestsToRun.push_back(val);
  4721. }
  4722. }
  4723. }
  4724. // if start is not specified then we assume we start at 1
  4725. if(start == -1)
  4726. {
  4727. start = 1;
  4728. }
  4729. // if end isnot specified then we assume we end with the last test
  4730. if(end == -1)
  4731. {
  4732. end = numTests;
  4733. }
  4734. // if the stride wasn't specified then it defaults to 1
  4735. if(stride == -1)
  4736. {
  4737. stride = 1;
  4738. }
  4739. // if we have a range then add it
  4740. if(end != -1 && start != -1 && stride > 0)
  4741. {
  4742. int i = 0;
  4743. while (i*stride + start <= end)
  4744. {
  4745. m_TestsToRun.push_back(static_cast<int>(i*stride+start));
  4746. ++i;
  4747. }
  4748. }
  4749. // sort the array
  4750. std::sort(m_TestsToRun.begin(), m_TestsToRun.end(), std::less<int>());
  4751. // remove duplicates
  4752. std::vector<int>::iterator new_end =
  4753. std::unique(m_TestsToRun.begin(), m_TestsToRun.end());
  4754. m_TestsToRun.erase(new_end, m_TestsToRun.end());
  4755. std::cout << "Running tests: ";
  4756. for(unsigned int i =0; i < m_TestsToRun.size(); ++i)
  4757. {
  4758. std::cout << m_TestsToRun[i] << " ";
  4759. }
  4760. std::cout << "\n";
  4761. }