cmCTest.cxx 119 KB

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