cmCTest.cxx 121 KB

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