cmCTest.cxx 143 KB

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