cmCTest.cxx 130 KB

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