cmCTest.cxx 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232
  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. int lcnt = 0;
  195. for (std::string::size_type pos = 0; pos < str.size(); pos ++ )
  196. {
  197. unsigned char ch = str[pos];
  198. if ( (ch > 126 || ch < 32) && ch != 9 && ch != 10 && ch != 13 )
  199. {
  200. sprintf(buffer, "&gt;%d&lt;", (int)ch);
  201. //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
  202. ost << buffer;
  203. lcnt += 4;
  204. }
  205. else
  206. {
  207. switch ( ch )
  208. {
  209. case '&': ost << "&amp;"; break;
  210. case '<': ost << "&lt;"; break;
  211. case '>': ost << "&gt;"; break;
  212. case '\n': ost << "\n"; lcnt = 0; break;
  213. default: ost << ch;
  214. }
  215. lcnt ++;
  216. }
  217. //if ( lcnt > 120 )
  218. // {
  219. // ost << "\n";
  220. // lcnt = 0;
  221. // }
  222. }
  223. return ost.str();
  224. }
  225. std::string cmCTest::MakeURLSafe(const std::string& str)
  226. {
  227. cmOStringStream ost;
  228. char buffer[10];
  229. for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
  230. {
  231. unsigned char ch = str[pos];
  232. if ( ( ch > 126 || ch < 32 ||
  233. ch == '&' ||
  234. ch == '%' ||
  235. ch == '+' ||
  236. ch == '=' ||
  237. ch == '@'
  238. ) && ch != 9 )
  239. {
  240. sprintf(buffer, "%02x;", (unsigned int)ch);
  241. ost << buffer;
  242. }
  243. else
  244. {
  245. ost << ch;
  246. }
  247. }
  248. return ost.str();
  249. }
  250. bool TryExecutable(const char *dir, const char *file,
  251. std::string *fullPath, const char *subdir)
  252. {
  253. // try current directory
  254. std::string tryPath;
  255. if (dir && strcmp(dir,""))
  256. {
  257. tryPath = dir;
  258. tryPath += "/";
  259. }
  260. if (subdir && strcmp(subdir,""))
  261. {
  262. tryPath += subdir;
  263. tryPath += "/";
  264. }
  265. tryPath += file;
  266. if(cmSystemTools::FileExists(tryPath.c_str()))
  267. {
  268. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  269. return true;
  270. }
  271. tryPath += cmSystemTools::GetExecutableExtension();
  272. if(cmSystemTools::FileExists(tryPath.c_str()))
  273. {
  274. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  275. return true;
  276. }
  277. return false;
  278. }
  279. cmCTest::cmCTest()
  280. {
  281. m_UseIncludeRegExp = false;
  282. m_UseExcludeRegExp = false;
  283. m_UseExcludeRegExpFirst = false;
  284. m_Verbose = false;
  285. m_DartMode = false;
  286. m_ShowOnly = false;
  287. m_RunConfigurationScript = false;
  288. m_TestModel = cmCTest::EXPERIMENTAL;
  289. m_TimeOut = 0;
  290. m_CompatibilityMode = 1;
  291. int cc;
  292. for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
  293. {
  294. m_Tests[cc] = 0;
  295. }
  296. }
  297. void cmCTest::Initialize()
  298. {
  299. m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
  300. cmSystemTools::ConvertToUnixSlashes(m_ToplevelPath);
  301. // parse the dart test file
  302. std::ifstream fin("DartConfiguration.tcl");
  303. if(!fin)
  304. {
  305. return;
  306. }
  307. char buffer[1024];
  308. while ( fin )
  309. {
  310. buffer[0] = 0;
  311. fin.getline(buffer, 1023);
  312. buffer[1023] = 0;
  313. std::string line = ::CleanString(buffer);
  314. if(line.size() == 0)
  315. {
  316. continue;
  317. }
  318. while ( fin && (line[line.size()-1] == '\\') )
  319. {
  320. line = line.substr(0, line.size()-1);
  321. buffer[0] = 0;
  322. fin.getline(buffer, 1023);
  323. buffer[1023] = 0;
  324. line += ::CleanString(buffer);
  325. }
  326. if ( line[0] == '#' )
  327. {
  328. continue;
  329. }
  330. std::string::size_type cpos = line.find_first_of(":");
  331. if ( cpos == line.npos )
  332. {
  333. continue;
  334. }
  335. std::string key = line.substr(0, cpos);
  336. std::string value = ::CleanString(line.substr(cpos+1, line.npos));
  337. m_DartConfiguration[key] = value;
  338. }
  339. fin.close();
  340. if ( m_DartMode )
  341. {
  342. m_TimeOut = atoi(m_DartConfiguration["TimeOut"].c_str());
  343. std::string testingDir = m_ToplevelPath + "/Testing";
  344. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  345. {
  346. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  347. {
  348. std::cerr << "File " << testingDir << " is in the place of the testing directory"
  349. << std::endl;
  350. return;
  351. }
  352. }
  353. else
  354. {
  355. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  356. {
  357. std::cerr << "Cannot create directory " << testingDir
  358. << std::endl;
  359. return;
  360. }
  361. }
  362. std::string tagfile = testingDir + "/TAG";
  363. std::ifstream tfin(tagfile.c_str());
  364. std::string tag;
  365. time_t tctime = time(0);
  366. struct tm *lctime = gmtime(&tctime);
  367. if ( tfin )
  368. {
  369. tfin >> tag;
  370. tfin.close();
  371. int year = 0;
  372. int mon = 0;
  373. int day = 0;
  374. int hour = 0;
  375. int min = 0;
  376. sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
  377. &year, &mon, &day, &hour, &min);
  378. if ( year != lctime->tm_year + 1900 ||
  379. mon != lctime->tm_mon+1 ||
  380. day != lctime->tm_mday )
  381. {
  382. tag = "";
  383. }
  384. }
  385. if ( tag.size() == 0 || m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST])
  386. {
  387. //std::cout << "TestModel: " << this->GetTestModelString() << std::endl;
  388. //std::cout << "TestModel: " << m_TestModel << std::endl;
  389. if ( m_TestModel == cmCTest::NIGHTLY )
  390. {
  391. lctime = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"]);
  392. }
  393. char datestring[100];
  394. sprintf(datestring, "%04d%02d%02d-%02d%02d",
  395. lctime->tm_year + 1900,
  396. lctime->tm_mon+1,
  397. lctime->tm_mday,
  398. lctime->tm_hour,
  399. lctime->tm_min);
  400. tag = datestring;
  401. std::ofstream ofs(tagfile.c_str());
  402. if ( ofs )
  403. {
  404. ofs << tag << std::endl;
  405. }
  406. ofs.close();
  407. std::cout << "Create new tag: " << tag << std::endl;
  408. }
  409. m_CurrentTag = tag;
  410. }
  411. }
  412. bool cmCTest::SetTest(const char* ttype)
  413. {
  414. if ( cmSystemTools::LowerCase(ttype) == "all" )
  415. {
  416. m_Tests[cmCTest::ALL_TEST] = 1;
  417. }
  418. else if ( cmSystemTools::LowerCase(ttype) == "start" )
  419. {
  420. m_Tests[cmCTest::START_TEST] = 1;
  421. }
  422. else if ( cmSystemTools::LowerCase(ttype) == "update" )
  423. {
  424. m_Tests[cmCTest::UPDATE_TEST] = 1;
  425. }
  426. else if ( cmSystemTools::LowerCase(ttype) == "configure" )
  427. {
  428. m_Tests[cmCTest::CONFIGURE_TEST] = 1;
  429. }
  430. else if ( cmSystemTools::LowerCase(ttype) == "build" )
  431. {
  432. m_Tests[cmCTest::BUILD_TEST] = 1;
  433. }
  434. else if ( cmSystemTools::LowerCase(ttype) == "test" )
  435. {
  436. m_Tests[cmCTest::TEST_TEST] = 1;
  437. }
  438. else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
  439. {
  440. m_Tests[cmCTest::COVERAGE_TEST] = 1;
  441. }
  442. else if ( cmSystemTools::LowerCase(ttype) == "memcheck" )
  443. {
  444. m_Tests[cmCTest::MEMCHECK_TEST] = 1;
  445. }
  446. else if ( cmSystemTools::LowerCase(ttype) == "submit" )
  447. {
  448. m_Tests[cmCTest::SUBMIT_TEST] = 1;
  449. }
  450. else
  451. {
  452. std::cerr << "Don't know about test \"" << ttype << "\" yet..." << std::endl;
  453. return false;
  454. }
  455. return true;
  456. }
  457. void cmCTest::Finalize()
  458. {
  459. }
  460. std::string cmCTest::FindTheExecutable(const char *exe)
  461. {
  462. std::string fullPath = "";
  463. std::string dir;
  464. std::string file;
  465. cmSystemTools::SplitProgramPath(exe, dir, file);
  466. if(m_ConfigType != "" &&
  467. ::TryExecutable(dir.c_str(), file.c_str(), &fullPath,
  468. m_ConfigType.c_str()))
  469. {
  470. return fullPath;
  471. }
  472. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
  473. {
  474. return fullPath;
  475. }
  476. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
  477. {
  478. return fullPath;
  479. }
  480. if ( m_ConfigType == "" )
  481. {
  482. // No config type, so try to guess it
  483. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
  484. {
  485. return fullPath;
  486. }
  487. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
  488. {
  489. return fullPath;
  490. }
  491. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
  492. {
  493. return fullPath;
  494. }
  495. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
  496. {
  497. return fullPath;
  498. }
  499. }
  500. // if everything else failed, check the users path
  501. if (dir != "")
  502. {
  503. std::string path = cmSystemTools::FindProgram(file.c_str());
  504. if (path != "")
  505. {
  506. return path;
  507. }
  508. }
  509. if ( m_ConfigType != "" )
  510. {
  511. dir += "/";
  512. dir += m_ConfigType;
  513. dir += "/";
  514. dir += file;
  515. cmSystemTools::Error("config type specified on the command line, but test executable not found.",
  516. dir.c_str());
  517. return "";
  518. }
  519. return fullPath;
  520. }
  521. int cmCTest::UpdateDirectory()
  522. {
  523. int count = 0;
  524. std::string::size_type cc, kk;
  525. std::string cvsCommand = m_DartConfiguration["CVSCommand"];
  526. if ( cvsCommand.size() == 0 )
  527. {
  528. std::cerr << "Cannot find CVSCommand key in the DartConfiguration.tcl" << std::endl;
  529. return -1;
  530. }
  531. std::string cvsOptions = m_DartConfiguration["CVSUpdateOptions"];
  532. if ( cvsOptions.size() == 0 )
  533. {
  534. std::cerr << "Cannot find CVSUpdateOptions key in the DartConfiguration.tcl" << std::endl;
  535. return -1;
  536. }
  537. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  538. if ( sourceDirectory.size() == 0 )
  539. {
  540. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  541. return -1;
  542. }
  543. std::string extra_update_opts;
  544. if ( m_TestModel == cmCTest::NIGHTLY )
  545. {
  546. struct tm* t = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"]);
  547. char current_time[1024];
  548. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d UTC",
  549. t->tm_year + 1900,
  550. t->tm_mon + 1,
  551. t->tm_mday,
  552. t->tm_hour,
  553. t->tm_min,
  554. t->tm_sec);
  555. std::string today_update_date = current_time;
  556. extra_update_opts += "-D \"" + today_update_date +"\"";
  557. //std::cout << "Update: " << extra_update_opts << std::endl;
  558. }
  559. std::string command = cvsCommand + " -z3 update " + cvsOptions +
  560. " " + extra_update_opts;
  561. std::ofstream os;
  562. if ( !this->OpenOutputFile(m_CurrentTag, "Update.xml", os) )
  563. {
  564. std::cerr << "Cannot open log file" << std::endl;
  565. }
  566. std::string start_time = ::CurrentTime();
  567. std::string goutput;
  568. int retVal = 0;
  569. bool res = true;
  570. std::ofstream ofs;
  571. if ( !m_ShowOnly )
  572. {
  573. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  574. &retVal, sourceDirectory.c_str(),
  575. m_Verbose, 0 /*m_TimeOut*/);
  576. if ( this->OpenOutputFile("Temporary", "LastUpdate.log", ofs) )
  577. {
  578. ofs << goutput << std::endl;;
  579. }
  580. }
  581. else
  582. {
  583. std::cout << "Update with command: " << command << std::endl;
  584. }
  585. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  586. << "<Update mode=\"Client\">\n"
  587. << "\t<Site>" <<m_DartConfiguration["Site"] << "</Site>\n"
  588. << "\t<BuildName>" << m_DartConfiguration["BuildName"]
  589. << "</BuildName>\n"
  590. << "\t<BuildStamp>" << m_CurrentTag << "-"
  591. << this->GetTestModelString() << "</BuildStamp>" << std::endl;
  592. os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  593. << "\t<UpdateCommand>" << command << "</UpdateCommand>\n"
  594. << "\t<UpdateReturnStatus>";
  595. if ( retVal )
  596. {
  597. os << goutput;
  598. }
  599. os << "</UpdateReturnStatus>" << std::endl;
  600. std::vector<cmStdString> lines;
  601. cmSystemTools::Split(goutput.c_str(), lines);
  602. std::cout << "Updated; gathering version information" << std::endl;
  603. cmsys::RegularExpression date_author("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  604. cmsys::RegularExpression revision("^revision +([^ ]*) *$");
  605. cmsys::RegularExpression end_of_file("^=============================================================================$");
  606. cmsys::RegularExpression end_of_comment("^----------------------------$");
  607. std::string current_path = "";
  608. bool first_file = true;
  609. cmCTest::AuthorsToUpdatesMap authors_files_map;
  610. int num_updated = 0;
  611. int num_modified = 0;
  612. int num_conflicting = 0;
  613. for ( cc= 0 ; cc < lines.size(); cc ++ )
  614. {
  615. const char* line = lines[cc].c_str();
  616. char mod = line[0];
  617. if ( line[1] == ' ' && mod != '?' )
  618. {
  619. count ++;
  620. const char* file = line + 2;
  621. //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl;
  622. std::string logcommand = cvsCommand + " -z3 log -N " + file;
  623. //std::cout << "Do log: " << logcommand << std::endl;
  624. std::string output;
  625. res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output,
  626. &retVal, sourceDirectory.c_str(),
  627. m_Verbose, 0 /*m_TimeOut*/);
  628. if ( ofs )
  629. {
  630. ofs << output << std::endl;
  631. }
  632. if ( res && retVal == 0)
  633. {
  634. //std::cout << output << std::endl;
  635. std::vector<cmStdString> ulines;
  636. cmSystemTools::Split(output.c_str(), ulines);
  637. std::string::size_type sline = 0;
  638. std::string srevision1 = "Unknown";
  639. std::string sdate1 = "Unknown";
  640. std::string sauthor1 = "Unknown";
  641. std::string semail1 = "Unknown";
  642. std::string comment1 = "";
  643. std::string srevision2 = "Unknown";
  644. std::string sdate2 = "Unknown";
  645. std::string sauthor2 = "Unknown";
  646. std::string comment2 = "";
  647. std::string semail2 = "Unknown";
  648. bool have_first = false;
  649. bool have_second = false;
  650. for ( kk = 0; kk < ulines.size(); kk ++ )
  651. {
  652. const char* clp = ulines[kk].c_str();
  653. if ( !have_second && !sline && revision.find(clp) )
  654. {
  655. if ( !have_first )
  656. {
  657. srevision1 = revision.match(1);
  658. }
  659. else
  660. {
  661. srevision2 = revision.match(1);
  662. }
  663. }
  664. else if ( !have_second && !sline && date_author.find(clp) )
  665. {
  666. sline = kk + 1;
  667. if ( !have_first )
  668. {
  669. sdate1 = date_author.match(1);
  670. sauthor1 = date_author.match(2);
  671. }
  672. else
  673. {
  674. sdate2 = date_author.match(1);
  675. sauthor2 = date_author.match(2);
  676. }
  677. }
  678. else if ( sline && end_of_comment.find(clp) || end_of_file.find(clp))
  679. {
  680. if ( !have_first )
  681. {
  682. have_first = true;
  683. }
  684. else if ( !have_second )
  685. {
  686. have_second = true;
  687. }
  688. sline = 0;
  689. }
  690. else if ( sline )
  691. {
  692. if ( !have_first )
  693. {
  694. comment1 += clp;
  695. comment1 += "\n";
  696. }
  697. else
  698. {
  699. comment2 += clp;
  700. comment2 += "\n";
  701. }
  702. }
  703. }
  704. if ( mod == 'M' )
  705. {
  706. comment1 = "Locally modified file\n";
  707. }
  708. if ( mod == 'C' )
  709. {
  710. comment1 = "Conflict while updating\n";
  711. }
  712. std::string path = cmSystemTools::GetFilenamePath(file);
  713. std::string fname = cmSystemTools::GetFilenameName(file);
  714. if ( path != current_path )
  715. {
  716. if ( !first_file )
  717. {
  718. os << "\t</Directory>" << std::endl;
  719. }
  720. else
  721. {
  722. first_file = false;
  723. }
  724. os << "\t<Directory>\n"
  725. << "\t\t<Name>" << path << "</Name>" << std::endl;
  726. }
  727. if ( mod == 'C' )
  728. {
  729. num_conflicting ++;
  730. os << "\t<Conflicting>" << std::endl;
  731. }
  732. else if ( mod == 'M' )
  733. {
  734. num_modified ++;
  735. os << "\t<Modified>" << std::endl;
  736. }
  737. else
  738. {
  739. num_updated ++;
  740. os << "\t<Updated>" << std::endl;
  741. }
  742. if ( srevision2 == "Unknown" )
  743. {
  744. srevision2 = srevision1;
  745. }
  746. os << "\t\t<File Directory=\"" << path << "\">" << fname
  747. << "</File>\n"
  748. << "\t\t<Directory>" << path << "</Directory>\n"
  749. << "\t\t<FullName>" << file << "</FullName>\n"
  750. << "\t\t<CheckinDate>" << sdate1 << "</CheckinDate>\n"
  751. << "\t\t<Author>" << sauthor1 << "</Author>\n"
  752. << "\t\t<Email>" << semail1 << "</Email>\n"
  753. << "\t\t<Log>" << this->MakeXMLSafe(comment1) << "</Log>\n"
  754. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  755. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  756. << std::endl;
  757. if ( srevision2 != srevision1 )
  758. {
  759. os
  760. << "\t\t<Revisions>\n"
  761. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  762. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  763. << "\t\t\t<Author>" << sauthor1<< "</Author>\n"
  764. << "\t\t\t<Date>" << sdate1 << "</Date>\n"
  765. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment1) << "</Comment>\n"
  766. << "\t\t\t<Email>" << semail1 << "</Email>\n"
  767. << "\t\t</Revisions>\n"
  768. << "\t\t<Revisions>\n"
  769. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  770. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  771. << "\t\t\t<Author>" << sauthor2<< "</Author>\n"
  772. << "\t\t\t<Date>" << sdate2 << "</Date>\n"
  773. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment2) << "</Comment>\n"
  774. << "\t\t\t<Email>" << semail2 << "</Email>\n"
  775. << "\t\t</Revisions>" << std::endl;
  776. }
  777. if ( mod == 'C' )
  778. {
  779. os << "\t</Conflicting>" << std::endl;
  780. }
  781. else if ( mod == 'M' )
  782. {
  783. os << "\t</Modified>" << std::endl;
  784. }
  785. else
  786. {
  787. os << "\t</Updated>" << std::endl;
  788. }
  789. cmCTest::UpdateFiles *u = &authors_files_map[sauthor1];
  790. cmCTest::StringPair p;
  791. p.first = path;
  792. p.second = fname;
  793. u->push_back(p);
  794. current_path = path;
  795. }
  796. }
  797. }
  798. if ( num_updated )
  799. {
  800. std::cout << "Found " << num_updated << " updated files" << std::endl;
  801. }
  802. if ( num_modified )
  803. {
  804. std::cout << "Found " << num_modified << " locally modified files"
  805. << std::endl;
  806. }
  807. if ( num_conflicting )
  808. {
  809. std::cout << "Found " << num_conflicting << " conflicting files"
  810. << std::endl;
  811. }
  812. if ( !first_file )
  813. {
  814. os << "\t</Directory>" << std::endl;
  815. }
  816. cmCTest::AuthorsToUpdatesMap::iterator it;
  817. for ( it = authors_files_map.begin();
  818. it != authors_files_map.end();
  819. it ++ )
  820. {
  821. os << "\t<Author>\n"
  822. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  823. cmCTest::UpdateFiles *u = &(it->second);
  824. for ( cc = 0; cc < u->size(); cc ++ )
  825. {
  826. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  827. << (*u)[cc].second << "</File>" << std::endl;
  828. }
  829. os << "\t</Author>" << std::endl;
  830. }
  831. //std::cout << "End" << std::endl;
  832. std::string end_time = ::CurrentTime();
  833. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  834. << "</Update>" << std::endl;
  835. if ( ofs )
  836. {
  837. ofs.close();
  838. }
  839. if (! res || retVal )
  840. {
  841. std::cerr << "Error(s) when updating the project" << std::endl;
  842. std::cerr << "Output: " << goutput << std::endl;
  843. return -1;
  844. }
  845. return count;
  846. }
  847. int cmCTest::ConfigureDirectory()
  848. {
  849. std::cout << "Configure project" << std::endl;
  850. std::string cCommand = m_DartConfiguration["ConfigureCommand"];
  851. if ( cCommand.size() == 0 )
  852. {
  853. std::cerr << "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  854. << std::endl;
  855. return 1;
  856. }
  857. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  858. if ( buildDirectory.size() == 0 )
  859. {
  860. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  861. return 1;
  862. }
  863. std::string output;
  864. int retVal = 0;
  865. int res = 0;
  866. if ( !m_ShowOnly )
  867. {
  868. std::ofstream os;
  869. if ( !this->OpenOutputFile(m_CurrentTag, "Configure.xml", os) )
  870. {
  871. std::cerr << "Cannot open log file" << std::endl;
  872. }
  873. std::string start_time = ::CurrentTime();
  874. std::ofstream ofs;
  875. this->OpenOutputFile("Temporary", "LastConfigure.log", ofs);
  876. res = this->RunMakeCommand(cCommand.c_str(), &output,
  877. &retVal, buildDirectory.c_str(),
  878. m_Verbose, 0, ofs);
  879. if ( ofs )
  880. {
  881. ofs.close();
  882. }
  883. if ( os )
  884. {
  885. this->StartXML(os);
  886. os << "<Configure>\n"
  887. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  888. if ( res == cmsysProcess_State_Exited && retVal )
  889. {
  890. os << retVal;
  891. }
  892. os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>" << std::endl;
  893. //std::cout << "End" << std::endl;
  894. os << "<Log>" << this->MakeXMLSafe(output) << "</Log>" << std::endl;
  895. std::string end_time = ::CurrentTime();
  896. os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
  897. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  898. << "</Configure>" << std::endl;
  899. this->EndXML(os);
  900. }
  901. }
  902. else
  903. {
  904. std::cout << "Configure with command: " << cCommand << std::endl;
  905. }
  906. if (! res || retVal )
  907. {
  908. std::cerr << "Error(s) when updating the project" << std::endl;
  909. return 1;
  910. }
  911. return 0;
  912. }
  913. int cmCTest::BuildDirectory()
  914. {
  915. std::cout << "Build project" << std::endl;
  916. std::string makeCommand = m_DartConfiguration["MakeCommand"];
  917. if ( makeCommand.size() == 0 )
  918. {
  919. std::cerr << "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl;
  920. return 1;
  921. }
  922. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  923. if ( buildDirectory.size() == 0 )
  924. {
  925. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  926. return 1;
  927. }
  928. std::ofstream ofs;
  929. if ( !this->OpenOutputFile("Temporary", "LastBuild.log", ofs) )
  930. {
  931. std::cerr << "Cannot create LastBuild.log file" << std::endl;
  932. }
  933. m_StartBuild = ::CurrentTime();
  934. std::string output;
  935. int retVal = 0;
  936. int res = cmsysProcess_State_Exited;
  937. if ( !m_ShowOnly )
  938. {
  939. res = this->RunMakeCommand(makeCommand.c_str(), &output,
  940. &retVal, buildDirectory.c_str(),
  941. m_Verbose, 0, ofs);
  942. }
  943. else
  944. {
  945. std::cout << "Build with command: " << makeCommand << std::endl;
  946. }
  947. m_EndBuild = ::CurrentTime();
  948. if (res != cmsysProcess_State_Exited || retVal )
  949. {
  950. std::cerr << "Error(s) when building project" << std::endl;
  951. }
  952. if ( ofs )
  953. {
  954. ofs.close();
  955. }
  956. int cc;
  957. std::string srcdir = m_DartConfiguration["SourceDirectory"] + "/";
  958. std::string bindir = m_DartConfiguration["BuildDirectory"] + "/";
  959. std::string srcdirrep;
  960. std::string bindirrep;
  961. for ( cc = srcdir.size()-2; cc > 0; cc -- )
  962. {
  963. if ( srcdir[cc] == '/' )
  964. {
  965. srcdirrep = srcdir.c_str() + cc;
  966. srcdirrep = "/..." + srcdirrep;
  967. break;
  968. }
  969. }
  970. for ( cc = bindir.size()-2; cc > 0; cc -- )
  971. {
  972. if ( bindir[cc] == '/' )
  973. {
  974. bindirrep = bindir.c_str() + cc;
  975. bindirrep = "/..." + bindirrep;
  976. break;
  977. }
  978. }
  979. //std::cout << "Use " << srcdirrep.c_str() << std::endl;
  980. //std::cout << "Use " << bindirrep.c_str() << std::endl;
  981. cmSystemTools::ReplaceString(output, srcdir.c_str(), srcdirrep.c_str());
  982. cmSystemTools::ReplaceString(output, bindir.c_str(), bindirrep.c_str());
  983. // Parsing of output for errors and warnings.
  984. std::vector<cmStdString> lines;
  985. cmSystemTools::Split(output.c_str(), lines);
  986. // Lines are marked:
  987. // 0 - nothing
  988. // 1 - error
  989. // > 1 - warning
  990. std::vector<int> markedLines(lines.size(), 0);
  991. // Errors
  992. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  993. {
  994. cmsys::RegularExpression re(cmCTestErrorMatches[cc]);
  995. cmCTest::tm_VectorOfStrings::size_type kk;
  996. for ( kk = 0; kk < lines.size(); kk ++ )
  997. {
  998. if ( re.find(lines[kk]) )
  999. {
  1000. markedLines[kk] = 1;
  1001. }
  1002. }
  1003. }
  1004. // Warnings
  1005. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  1006. {
  1007. cmsys::RegularExpression re(cmCTestWarningMatches[cc]);
  1008. cmCTest::tm_VectorOfStrings::size_type kk;
  1009. for ( kk = 0; kk < lines.size(); kk ++ )
  1010. {
  1011. if ( re.find(lines[kk]) )
  1012. {
  1013. markedLines[kk] += 2;
  1014. }
  1015. }
  1016. }
  1017. // Errors exceptions
  1018. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  1019. {
  1020. cmsys::RegularExpression re(cmCTestErrorExceptions[cc]);
  1021. std::vector<int>::size_type kk;
  1022. for ( kk =0; kk < markedLines.size(); kk ++ )
  1023. {
  1024. if ( markedLines[kk] == 1 )
  1025. {
  1026. if ( re.find(lines[kk]) )
  1027. {
  1028. markedLines[kk] = 0;
  1029. }
  1030. }
  1031. }
  1032. }
  1033. // Warning exceptions
  1034. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  1035. {
  1036. cmsys::RegularExpression re(cmCTestWarningExceptions[cc]);
  1037. std::vector<int>::size_type kk;
  1038. for ( kk =0; kk < markedLines.size(); kk ++ )
  1039. {
  1040. if ( markedLines[kk] > 1 )
  1041. {
  1042. if ( re.find(lines[kk]) )
  1043. {
  1044. markedLines[kk] = 0;
  1045. }
  1046. }
  1047. }
  1048. }
  1049. std::vector<cmCTestBuildErrorWarning> errorsWarnings;
  1050. int errors = 0;
  1051. int warnings = 0;
  1052. std::vector<int>::size_type kk;
  1053. cmCTestBuildErrorWarning errorwarning;
  1054. for ( kk =0; kk < markedLines.size(); kk ++ )
  1055. {
  1056. errorwarning.m_LineNumber = -1;
  1057. bool found = false;
  1058. if ( markedLines[kk] == 1 )
  1059. {
  1060. //std::cout << "Error: " << lines[kk] << std::endl;
  1061. errorwarning.m_Error = true;
  1062. found = true;
  1063. }
  1064. else if ( markedLines[kk] > 1 )
  1065. {
  1066. //std::cout << "Warning: " << lines[kk] << std::endl;
  1067. errorwarning.m_Error = false;
  1068. found = true;
  1069. }
  1070. if ( found )
  1071. {
  1072. errorwarning.m_LogLine = static_cast<int>(kk+1);
  1073. errorwarning.m_Text = lines[kk];
  1074. errorwarning.m_PreContext = "";
  1075. errorwarning.m_PostContext = "";
  1076. std::vector<int>::size_type jj;
  1077. std::vector<int>::size_type ll = 0;
  1078. if ( kk > 6 )
  1079. {
  1080. ll = kk - 6;
  1081. }
  1082. for ( jj = kk;
  1083. jj > 0 && jj > ll /* && markedLines[jj] == 0 */;
  1084. jj -- );
  1085. for (; jj < kk; jj ++ )
  1086. {
  1087. errorwarning.m_PreContext += lines[jj] + "\n";
  1088. }
  1089. for ( jj = kk+1;
  1090. jj < lines.size() && jj < kk + 7 /* && markedLines[jj] == 0*/;
  1091. jj ++ )
  1092. {
  1093. errorwarning.m_PostContext += lines[jj] + "\n";
  1094. }
  1095. errorsWarnings.push_back(errorwarning);
  1096. if ( errorwarning.m_Error )
  1097. {
  1098. errors ++;
  1099. }
  1100. else
  1101. {
  1102. warnings ++;
  1103. }
  1104. }
  1105. }
  1106. std::cout << " " << errors << " Compiler errors" << std::endl;
  1107. std::cout << " " << warnings << " Compiler warnings" << std::endl;
  1108. if( !this->OpenOutputFile(m_CurrentTag, "Build.xml", ofs) )
  1109. {
  1110. std::cerr << "Cannot create build XML file" << std::endl;
  1111. return 1;
  1112. }
  1113. this->GenerateDartBuildOutput(ofs, errorsWarnings);
  1114. return 0;
  1115. }
  1116. int cmCTest::CoverageDirectory()
  1117. {
  1118. std::cout << "Performing coverage" << std::endl;
  1119. cmCTest::tm_VectorOfStrings files;
  1120. cmCTest::tm_VectorOfStrings cfiles;
  1121. cmCTest::tm_VectorOfStrings cdirs;
  1122. bool done = false;
  1123. std::string::size_type cc;
  1124. std::string glob;
  1125. std::map<std::string, std::string> allsourcefiles;
  1126. std::map<std::string, std::string> allbinaryfiles;
  1127. std::string start_time = ::CurrentTime();
  1128. // Find all source files.
  1129. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  1130. if ( sourceDirectory.size() == 0 )
  1131. {
  1132. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  1133. return 1;
  1134. }
  1135. std::string coverageCommand = m_DartConfiguration["CoverageCommand"];
  1136. if ( coverageCommand.size() == 0 )
  1137. {
  1138. std::cerr << "Coverage command not defined in DartConfiguration.tcl" << std::endl;
  1139. return 1;
  1140. }
  1141. cdirs.push_back(sourceDirectory);
  1142. while ( !done )
  1143. {
  1144. if ( cdirs.size() <= 0 )
  1145. {
  1146. break;
  1147. }
  1148. glob = cdirs[cdirs.size()-1] + "/*";
  1149. //std::cout << "Glob: " << glob << std::endl;
  1150. cdirs.pop_back();
  1151. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1152. {
  1153. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1154. {
  1155. allsourcefiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1156. }
  1157. }
  1158. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1159. {
  1160. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1161. {
  1162. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1163. {
  1164. cdirs.push_back(cfiles[cc]);
  1165. }
  1166. }
  1167. }
  1168. }
  1169. // find all binary files
  1170. cdirs.push_back(cmSystemTools::GetCurrentWorkingDirectory());
  1171. while ( !done )
  1172. {
  1173. if ( cdirs.size() <= 0 )
  1174. {
  1175. break;
  1176. }
  1177. glob = cdirs[cdirs.size()-1] + "/*";
  1178. //std::cout << "Glob: " << glob << std::endl;
  1179. cdirs.pop_back();
  1180. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1181. {
  1182. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1183. {
  1184. allbinaryfiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1185. }
  1186. }
  1187. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1188. {
  1189. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1190. {
  1191. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1192. {
  1193. cdirs.push_back(cfiles[cc]);
  1194. }
  1195. }
  1196. }
  1197. }
  1198. std::map<std::string, std::string>::iterator sit;
  1199. for ( sit = allbinaryfiles.begin(); sit != allbinaryfiles.end(); sit ++ )
  1200. {
  1201. const std::string& fname = sit->second;
  1202. //std::cout << "File: " << fname << std::endl;
  1203. if ( strcmp(fname.substr(fname.size()-3, 3).c_str(), ".da") == 0 )
  1204. {
  1205. files.push_back(fname);
  1206. }
  1207. }
  1208. if ( files.size() == 0 )
  1209. {
  1210. std::cerr << "Cannot find any coverage information files (.da)" << std::endl;
  1211. return 1;
  1212. }
  1213. std::ofstream log;
  1214. if (!this->OpenOutputFile("Temporary", "Coverage.log", log))
  1215. {
  1216. std::cerr << "Cannot open log file" << std::endl;
  1217. return 1;
  1218. }
  1219. log.close();
  1220. if (!this->OpenOutputFile(m_CurrentTag, "Coverage.xml", log))
  1221. {
  1222. std::cerr << "Cannot open log file" << std::endl;
  1223. return 1;
  1224. }
  1225. std::string opath = m_ToplevelPath + "/Testing/Temporary/Coverage";
  1226. cmSystemTools::MakeDirectory(opath.c_str());
  1227. for ( cc = 0; cc < files.size(); cc ++ )
  1228. {
  1229. std::string command = coverageCommand + " -o \"" +
  1230. cmSystemTools::GetFilenamePath(files[cc]) +
  1231. "\" -l \"" + files[cc] + "\"";
  1232. std::string output;
  1233. int retVal = 0;
  1234. //std::cout << "Run gcov on " << files[cc] << std::flush;
  1235. //std::cout << " --- Run [" << command << "]" << std::endl;
  1236. bool res = true;
  1237. if ( !m_ShowOnly )
  1238. {
  1239. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  1240. &retVal, opath.c_str(),
  1241. m_Verbose, 0 /*m_TimeOut*/);
  1242. }
  1243. if ( res && retVal == 0 )
  1244. {
  1245. //std::cout << " - done" << std::endl;
  1246. }
  1247. else
  1248. {
  1249. std::cerr << "Run gcov on " << files[cc] << std::flush;
  1250. std::cerr << " [" << command << "]" << std::endl;
  1251. std::cerr << " - fail" << std::endl;
  1252. }
  1253. }
  1254. files.clear();
  1255. glob = opath + "/*";
  1256. if ( !cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1257. {
  1258. std::cerr << "Cannot found any coverage files" << std::endl;
  1259. return 1;
  1260. }
  1261. std::map<std::string, cmCTest::tm_VectorOfStrings > sourcefiles;
  1262. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1263. {
  1264. std::string& fname = cfiles[cc];
  1265. // std::cout << "File: " << fname << std::endl;
  1266. if ( strcmp(fname.substr(fname.size()-5, 5).c_str(), ".gcov") == 0 )
  1267. {
  1268. files.push_back(fname);
  1269. std::string::size_type pos = fname.find(".da.");
  1270. std::string::size_type pos2 = fname.find(".da##");
  1271. if(pos2 != fname.npos)
  1272. {
  1273. pos = pos2+1;
  1274. }
  1275. if ( pos != fname.npos )
  1276. {
  1277. pos += 4;
  1278. std::string::size_type epos = fname.size() - pos - strlen(".gcov");
  1279. std::string nf = fname.substr(pos, epos);
  1280. //std::cout << "Substring: " << nf << std::endl;
  1281. if ( allsourcefiles.find(nf) != allsourcefiles.end() ||
  1282. allbinaryfiles.find(nf) != allbinaryfiles.end() )
  1283. {
  1284. cmCTest::tm_VectorOfStrings &cvec = sourcefiles[nf];
  1285. cvec.push_back(fname);
  1286. }
  1287. }
  1288. }
  1289. }
  1290. // for ( cc = 0; cc < files.size(); cc ++ )
  1291. // {
  1292. // std::cout << "File: " << files[cc] << std::endl;
  1293. // }
  1294. std::map<std::string, cmCTest::tm_VectorOfStrings >::iterator it;
  1295. cmCTest::tm_CoverageMap coverageresults;
  1296. this->StartXML(log);
  1297. log << "<Coverage>\n"
  1298. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  1299. int total_tested = 0;
  1300. int total_untested = 0;
  1301. for ( it = sourcefiles.begin(); it != sourcefiles.end(); it ++ )
  1302. {
  1303. //std::cerr << "Source file: " << it->first << std::endl;
  1304. cmCTest::tm_VectorOfStrings &gfiles = it->second;
  1305. for ( cc = 0; cc < gfiles.size(); cc ++ )
  1306. {
  1307. //std::cout << "\t" << gfiles[cc] << std::endl;
  1308. std::ifstream ifile(gfiles[cc].c_str());
  1309. if ( !ifile )
  1310. {
  1311. std::cerr << "Cannot open file: " << gfiles[cc].c_str() << std::endl;
  1312. }
  1313. ifile.seekg (0, std::ios::end);
  1314. int length = ifile.tellg();
  1315. ifile.seekg (0, std::ios::beg);
  1316. char *buffer = new char [ length + 1 ];
  1317. ifile.read(buffer, length);
  1318. buffer [length] = 0;
  1319. //std::cout << "Read: " << buffer << std::endl;
  1320. std::vector<cmStdString> lines;
  1321. cmSystemTools::Split(buffer, lines);
  1322. delete [] buffer;
  1323. cmCTest::cmCTestCoverage& cov = coverageresults[it->first];
  1324. std::vector<int>& covlines = cov.m_Lines;
  1325. if ( cov.m_FullPath == "" )
  1326. {
  1327. covlines.insert(covlines.begin(), lines.size(), -1);
  1328. if ( allsourcefiles.find(it->first) != allsourcefiles.end() )
  1329. {
  1330. cov.m_FullPath = allsourcefiles[it->first];
  1331. }
  1332. else if ( allbinaryfiles.find(it->first) != allbinaryfiles.end() )
  1333. {
  1334. cov.m_FullPath = allbinaryfiles[it->first];
  1335. }
  1336. cov.m_AbsolutePath = cov.m_FullPath;
  1337. std::string src_dir = m_DartConfiguration["SourceDirectory"];
  1338. if ( src_dir[src_dir.size()-1] != '/' )
  1339. {
  1340. src_dir = src_dir + "/";
  1341. }
  1342. std::string::size_type spos = cov.m_FullPath.find(src_dir);
  1343. if ( spos == 0 )
  1344. {
  1345. cov.m_FullPath = std::string("./") + cov.m_FullPath.substr(src_dir.size());
  1346. }
  1347. else
  1348. {
  1349. //std::cerr << "Compare -- " << cov.m_FullPath << std::endl;
  1350. //std::cerr << " -- " << src_dir << std::endl;
  1351. cov.m_Show = false;
  1352. continue;
  1353. }
  1354. cov.m_Show = true;
  1355. }
  1356. std::string::size_type kk;
  1357. // std::cerr << "number of lines " << lines.size() << "\n";
  1358. for ( kk = 0; kk < lines.size(); kk ++ )
  1359. {
  1360. std::string& line = lines[kk];
  1361. //std::cerr << line << "\n";
  1362. std::string sub1 = line.substr(0, strlen(" #####"));
  1363. std::string sub2 = line.substr(0, strlen(" ######"));
  1364. int count = atoi(sub2.c_str());
  1365. if ( sub1.compare(" #####") == 0 ||
  1366. sub2.compare(" ######") == 0 )
  1367. {
  1368. if ( covlines[kk] == -1 )
  1369. {
  1370. covlines[kk] = 0;
  1371. }
  1372. cov.m_UnTested ++;
  1373. //std::cout << "Untested - ";
  1374. }
  1375. else if ( count > 0 )
  1376. {
  1377. if ( covlines[kk] == -1 )
  1378. {
  1379. covlines[kk] = 0;
  1380. }
  1381. cov.m_Tested ++;
  1382. covlines[kk] += count;
  1383. //std::cout << "Tested[" << count << "] - ";
  1384. }
  1385. //std::cout << line << std::endl;
  1386. }
  1387. }
  1388. }
  1389. //std::cerr << "Finalizing" << std::endl;
  1390. cmCTest::tm_CoverageMap::iterator cit;
  1391. int ccount = 0;
  1392. std::ofstream cfileoutput;
  1393. int cfileoutputcount = 0;
  1394. char cfileoutputname[100];
  1395. std::string local_start_time = ::CurrentTime();
  1396. std::string local_end_time;
  1397. for ( cit = coverageresults.begin(); cit != coverageresults.end(); cit ++ )
  1398. {
  1399. cmCTest::cmCTestCoverage &cov = cit->second;
  1400. if ( !cov.m_Show )
  1401. {
  1402. continue;
  1403. }
  1404. if ( ccount == 100 )
  1405. {
  1406. local_end_time = ::CurrentTime();
  1407. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1408. << "</CoverageLog>" << std::endl;
  1409. this->EndXML(cfileoutput);
  1410. cfileoutput.close();
  1411. std::cout << "Close file: " << cfileoutputname << std::endl;
  1412. ccount = 0;
  1413. }
  1414. if ( ccount == 0 )
  1415. {
  1416. sprintf(cfileoutputname, "CoverageLog-%d.xml", cfileoutputcount++);
  1417. std::cout << "Open file: " << cfileoutputname << std::endl;
  1418. if (!this->OpenOutputFile(m_CurrentTag, cfileoutputname, cfileoutput))
  1419. {
  1420. std::cerr << "Cannot open log file: " << cfileoutputname << std::endl;
  1421. return 1;
  1422. }
  1423. local_start_time = ::CurrentTime();
  1424. this->StartXML(cfileoutput);
  1425. cfileoutput << "<CoverageLog>\n"
  1426. << "\t<StartDateTime>" << local_start_time << "</StartDateTime>" << std::endl;
  1427. }
  1428. //std::cerr << "Final process of Source file: " << cit->first << std::endl;
  1429. std::ifstream ifile(cov.m_AbsolutePath.c_str());
  1430. if ( !ifile )
  1431. {
  1432. std::cerr << "Cannot open file: " << cov.m_FullPath.c_str() << std::endl;
  1433. }
  1434. ifile.seekg (0, std::ios::end);
  1435. int length = ifile.tellg();
  1436. ifile.seekg (0, std::ios::beg);
  1437. char *buffer = new char [ length + 1 ];
  1438. ifile.read(buffer, length);
  1439. buffer [length] = 0;
  1440. //std::cout << "Read: " << buffer << std::endl;
  1441. std::vector<cmStdString> lines;
  1442. cmSystemTools::Split(buffer, lines);
  1443. delete [] buffer;
  1444. cfileoutput << "\t<File Name=\"" << cit->first << "\" FullPath=\""
  1445. << cov.m_FullPath << "\">\n"
  1446. << "\t\t<Report>" << std::endl;
  1447. for ( cc = 0; cc < lines.size(); cc ++ )
  1448. {
  1449. cfileoutput << "\t\t<Line Number=\""
  1450. << static_cast<int>(cc) << "\" Count=\""
  1451. << cov.m_Lines[cc] << "\">"
  1452. << cmCTest::MakeXMLSafe(lines[cc]) << "</Line>" << std::endl;
  1453. }
  1454. cfileoutput << "\t\t</Report>\n"
  1455. << "\t</File>" << std::endl;
  1456. total_tested += cov.m_Tested;
  1457. total_untested += cov.m_UnTested;
  1458. float cper = 0;
  1459. float cmet = 0;
  1460. if ( total_tested + total_untested > 0 && (cov.m_Tested + cov.m_UnTested) > 0)
  1461. {
  1462. cper = (100 * SAFEDIV(static_cast<float>(cov.m_Tested),
  1463. static_cast<float>(cov.m_Tested + cov.m_UnTested)));
  1464. cmet = ( SAFEDIV(static_cast<float>(cov.m_Tested + 10),
  1465. static_cast<float>(cov.m_Tested + cov.m_UnTested + 10)));
  1466. }
  1467. log << "\t<File Name=\"" << cit->first << "\" FullPath=\"" << cov.m_FullPath
  1468. << "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n"
  1469. << "\t\t<LOCTested>" << cov.m_Tested << "</LOCTested>\n"
  1470. << "\t\t<LOCUnTested>" << cov.m_UnTested << "</LOCUnTested>\n"
  1471. << "\t\t<PercentCoverage>";
  1472. log.setf(std::ios::fixed, std::ios::floatfield);
  1473. log.precision(2);
  1474. log << (cper) << "</PercentCoverage>\n"
  1475. << "\t\t<CoverageMetric>";
  1476. log.setf(std::ios::fixed, std::ios::floatfield);
  1477. log.precision(2);
  1478. log << (cmet) << "</CoverageMetric>\n"
  1479. << "\t</File>" << std::endl;
  1480. ccount ++;
  1481. }
  1482. if ( ccount > 0 )
  1483. {
  1484. local_end_time = ::CurrentTime();
  1485. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1486. << "</CoverageLog>" << std::endl;
  1487. this->EndXML(cfileoutput);
  1488. cfileoutput.close();
  1489. }
  1490. int total_lines = total_tested + total_untested;
  1491. float percent_coverage = 100 * SAFEDIV(static_cast<float>(total_tested),
  1492. static_cast<float>(total_lines));
  1493. if ( total_lines == 0 )
  1494. {
  1495. percent_coverage = 0;
  1496. }
  1497. std::string end_time = ::CurrentTime();
  1498. log << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
  1499. << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
  1500. << "\t<LOC>" << total_lines << "</LOC>\n"
  1501. << "\t<PercentCoverage>";
  1502. log.setf(std::ios::fixed, std::ios::floatfield);
  1503. log.precision(2);
  1504. log << (percent_coverage)<< "</PercentCoverage>\n"
  1505. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  1506. << "</Coverage>" << std::endl;
  1507. this->EndXML(log);
  1508. std::cout << "\tCovered LOC: " << total_tested << std::endl
  1509. << "\tNot covered LOC: " << total_untested << std::endl
  1510. << "\tTotal LOC: " << total_lines << std::endl
  1511. << "\tPercentage Coverage: ";
  1512. std::cout.setf(std::ios::fixed, std::ios::floatfield);
  1513. std::cout.precision(2);
  1514. std::cout << (percent_coverage) << "%" << std::endl;
  1515. return 1;
  1516. }
  1517. bool cmCTest::OpenOutputFile(const std::string& path,
  1518. const std::string& name, std::ofstream& stream)
  1519. {
  1520. std::string testingDir = m_ToplevelPath + "/Testing";
  1521. if ( path.size() > 0 )
  1522. {
  1523. testingDir += "/" + path;
  1524. }
  1525. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  1526. {
  1527. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  1528. {
  1529. std::cerr << "File " << testingDir
  1530. << " is in the place of the testing directory"
  1531. << std::endl;
  1532. return false;
  1533. }
  1534. }
  1535. else
  1536. {
  1537. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  1538. {
  1539. std::cerr << "Cannot create directory " << testingDir
  1540. << std::endl;
  1541. return false;
  1542. }
  1543. }
  1544. std::string filename = testingDir + "/" + name;
  1545. stream.open(filename.c_str());
  1546. if( !stream )
  1547. {
  1548. std::cerr << "Problem opening file: " << filename << std::endl;
  1549. return false;
  1550. }
  1551. return true;
  1552. }
  1553. void cmCTest::GenerateDartBuildOutput(std::ostream& os,
  1554. std::vector<cmCTestBuildErrorWarning> ew)
  1555. {
  1556. this->StartXML(os);
  1557. os << "<Build>\n"
  1558. << "\t<StartDateTime>" << m_StartBuild << "</StartDateTime>\n"
  1559. << "<BuildCommand>"
  1560. << this->MakeXMLSafe(m_DartConfiguration["MakeCommand"])
  1561. << "</BuildCommand>" << std::endl;
  1562. std::vector<cmCTestBuildErrorWarning>::iterator it;
  1563. for ( it = ew.begin(); it != ew.end(); it++ )
  1564. {
  1565. cmCTestBuildErrorWarning *cm = &(*it);
  1566. os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n"
  1567. << "\t\t<BuildLogLine>" << cm->m_LogLine << "</BuildLogLine>\n"
  1568. << "\t\t<Text>" << this->MakeXMLSafe(cm->m_Text)
  1569. << "\n</Text>" << std::endl;
  1570. if ( cm->m_SourceFile.size() > 0 )
  1571. {
  1572. os << "\t\t<SourceFile>" << cm->m_SourceFile << "</SourceFile>"
  1573. << std::endl;
  1574. }
  1575. if ( cm->m_SourceFileTail.size() > 0 )
  1576. {
  1577. os << "\t\t<SourceFileTail>" << cm->m_SourceFileTail
  1578. << "</SourceFileTail>" << std::endl;
  1579. }
  1580. if ( cm->m_LineNumber >= 0 )
  1581. {
  1582. os << "\t\t<SourceLineNumber>" << cm->m_LineNumber
  1583. << "</SourceLineNumber>" << std::endl;
  1584. }
  1585. os << "\t\t<PreContext>" << this->MakeXMLSafe(cm->m_PreContext)
  1586. << "</PreContext>\n"
  1587. << "\t\t<PostContext>" << this->MakeXMLSafe(cm->m_PostContext)
  1588. << "</PostContext>\n"
  1589. << "\t\t<RepeatCount>0</RepeatCount>\n"
  1590. << "</" << (cm->m_Error ? "Error" : "Warning") << ">\n\n"
  1591. << std::endl;
  1592. }
  1593. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  1594. << "\t<EndDateTime>" << m_EndBuild << "</EndDateTime>\n"
  1595. << "</Build>" << std::endl;
  1596. this->EndXML(os);
  1597. }
  1598. void cmCTest::ProcessDirectory(cmCTest::tm_VectorOfStrings &passed,
  1599. cmCTest::tm_VectorOfStrings &failed,
  1600. bool memcheck)
  1601. {
  1602. // does the DartTestfile.txt exist ?
  1603. if(!cmSystemTools::FileExists("DartTestfile.txt"))
  1604. {
  1605. return;
  1606. }
  1607. // parse the file
  1608. std::ifstream fin("DartTestfile.txt");
  1609. if(!fin)
  1610. {
  1611. return;
  1612. }
  1613. int firstTest = 1;
  1614. cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
  1615. cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
  1616. cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  1617. cmListFileCache cache;
  1618. cmListFile* listFile = cache.GetFileCache("DartTestfile.txt", false);
  1619. for(std::vector<cmListFileFunction>::const_iterator f =
  1620. listFile->m_Functions.begin(); f != listFile->m_Functions.end(); ++f)
  1621. {
  1622. const cmListFileFunction& lff = *f;
  1623. const std::string& name = lff.m_Name;
  1624. const std::vector<cmListFileArgument>& args = lff.m_Arguments;
  1625. if (name == "SUBDIRS")
  1626. {
  1627. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1628. for(std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1629. j != args.end(); ++j)
  1630. {
  1631. std::string nwd = cwd + "/";
  1632. nwd += j->Value;
  1633. if (cmSystemTools::FileIsDirectory(nwd.c_str()))
  1634. {
  1635. cmSystemTools::ChangeDirectory(nwd.c_str());
  1636. this->ProcessDirectory(passed, failed, memcheck);
  1637. }
  1638. }
  1639. // return to the original directory
  1640. cmSystemTools::ChangeDirectory(cwd.c_str());
  1641. }
  1642. if (name == "ADD_TEST")
  1643. {
  1644. if (this->m_UseExcludeRegExp &&
  1645. this->m_UseExcludeRegExpFirst &&
  1646. ereg.find(args[0].Value.c_str()))
  1647. {
  1648. continue;
  1649. }
  1650. if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
  1651. {
  1652. continue;
  1653. }
  1654. if (this->m_UseExcludeRegExp &&
  1655. !this->m_UseExcludeRegExpFirst &&
  1656. ereg.find(args[0].Value.c_str()))
  1657. {
  1658. continue;
  1659. }
  1660. cmCTestTestResult cres;
  1661. cres.m_Status = cmCTest::NOT_RUN;
  1662. if (firstTest)
  1663. {
  1664. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1665. if ( m_Verbose )
  1666. {
  1667. std::cerr << "Changing directory into " << nwd.c_str() << "\n";
  1668. }
  1669. firstTest = 0;
  1670. }
  1671. cres.m_Name = args[0].Value;
  1672. if ( m_ShowOnly )
  1673. {
  1674. std::cout << args[0].Value << std::endl;
  1675. }
  1676. else
  1677. {
  1678. fprintf(stderr,"Testing %-30s ",args[0].Value.c_str());
  1679. fflush(stderr);
  1680. }
  1681. //std::cerr << "Testing " << args[0] << " ... ";
  1682. // find the test executable
  1683. std::string actualCommand = this->FindTheExecutable(args[1].Value.c_str());
  1684. std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
  1685. std::string memcheckcommand = "";
  1686. // continue if we did not find the executable
  1687. if (testCommand == "")
  1688. {
  1689. std::cerr << "Unable to find executable: " <<
  1690. args[1].Value.c_str() << "\n";
  1691. m_TestResults.push_back( cres );
  1692. continue;
  1693. }
  1694. // add the arguments
  1695. std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1696. ++j;
  1697. ++j;
  1698. std::vector<const char*> arguments;
  1699. if ( memcheck )
  1700. {
  1701. cmCTest::tm_VectorOfStrings::size_type pp;
  1702. arguments.push_back(m_MemoryTester.c_str());
  1703. memcheckcommand = m_MemoryTester;
  1704. for ( pp = 0; pp < m_MemoryTesterOptionsParsed.size(); pp ++ )
  1705. {
  1706. arguments.push_back(m_MemoryTesterOptionsParsed[pp].c_str());
  1707. memcheckcommand += " ";
  1708. memcheckcommand += cmSystemTools::EscapeSpaces(m_MemoryTesterOptionsParsed[pp].c_str());
  1709. }
  1710. }
  1711. arguments.push_back(actualCommand.c_str());
  1712. for(;j != args.end(); ++j)
  1713. {
  1714. testCommand += " ";
  1715. testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
  1716. arguments.push_back(j->Value.c_str());
  1717. }
  1718. arguments.push_back(0);
  1719. /**
  1720. * Run an executable command and put the stdout in output.
  1721. */
  1722. std::string output;
  1723. int retVal = 0;
  1724. double clock_start, clock_finish;
  1725. clock_start = cmSystemTools::GetTime();
  1726. if ( m_Verbose )
  1727. {
  1728. std::cout << std::endl << (memcheck?"MemCheck":"Test") << " command: " << testCommand << std::endl;
  1729. if ( memcheck )
  1730. {
  1731. std::cout << "Memory check command: " << memcheckcommand << std::endl;
  1732. }
  1733. }
  1734. int res = 0;
  1735. if ( !m_ShowOnly )
  1736. {
  1737. res = this->RunTest(arguments, &output, &retVal);
  1738. }
  1739. clock_finish = cmSystemTools::GetTime();
  1740. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  1741. cres.m_FullCommandLine = testCommand;
  1742. if ( !m_ShowOnly )
  1743. {
  1744. if (res == cmsysProcess_State_Exited && retVal == 0)
  1745. {
  1746. fprintf(stderr," Passed\n");
  1747. passed.push_back(args[0].Value);
  1748. cres.m_Status = cmCTest::COMPLETED;
  1749. }
  1750. else
  1751. {
  1752. cres.m_Status = cmCTest::FAILED;
  1753. if ( res == cmsysProcess_State_Expired )
  1754. {
  1755. fprintf(stderr,"***Timeout\n");
  1756. cres.m_Status = cmCTest::TIMEOUT;
  1757. }
  1758. else if ( res == cmsysProcess_State_Exception )
  1759. {
  1760. fprintf(stderr,"***Exception: ");
  1761. switch ( retVal )
  1762. {
  1763. case cmsysProcess_Exception_Fault:
  1764. fprintf(stderr,"SegFault");
  1765. cres.m_Status = cmCTest::SEGFAULT;
  1766. break;
  1767. case cmsysProcess_Exception_Illegal:
  1768. fprintf(stderr,"Illegal");
  1769. cres.m_Status = cmCTest::ILLEGAL;
  1770. break;
  1771. case cmsysProcess_Exception_Interrupt:
  1772. fprintf(stderr,"Interrupt");
  1773. cres.m_Status = cmCTest::INTERRUPT;
  1774. break;
  1775. case cmsysProcess_Exception_Numerical:
  1776. fprintf(stderr,"Numerical");
  1777. cres.m_Status = cmCTest::NUMERICAL;
  1778. break;
  1779. default:
  1780. fprintf(stderr,"Other");
  1781. cres.m_Status = cmCTest::OTHER_FAULT;
  1782. }
  1783. fprintf(stderr,"\n");
  1784. }
  1785. else if ( res == cmsysProcess_State_Error )
  1786. {
  1787. fprintf(stderr,"***Bad command\n");
  1788. cres.m_Status = cmCTest::BAD_COMMAND;
  1789. }
  1790. else
  1791. {
  1792. fprintf(stderr,"***Failed\n");
  1793. }
  1794. failed.push_back(args[0].Value);
  1795. }
  1796. if (output != "")
  1797. {
  1798. if (dartStuff.find(output.c_str()))
  1799. {
  1800. std::string dartString = dartStuff.match(1);
  1801. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  1802. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  1803. }
  1804. }
  1805. }
  1806. cres.m_Output = output;
  1807. cres.m_ReturnValue = retVal;
  1808. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1809. if ( nwd.size() > m_ToplevelPath.size() )
  1810. {
  1811. nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
  1812. }
  1813. cmSystemTools::ReplaceString(nwd, "\\", "/");
  1814. cres.m_Path = nwd;
  1815. cres.m_CompletionStatus = "Completed";
  1816. m_TestResults.push_back( cres );
  1817. }
  1818. }
  1819. }
  1820. bool cmCTest::InitializeMemoryChecking()
  1821. {
  1822. // Setup the command
  1823. if ( cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckCommand"].c_str()) )
  1824. {
  1825. m_MemoryTester
  1826. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["MemoryCheckCommand"].c_str());
  1827. }
  1828. else if ( cmSystemTools::FileExists(m_DartConfiguration["PurifyCommand"].c_str()) )
  1829. {
  1830. m_MemoryTester
  1831. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["PurifyCommand"].c_str());
  1832. }
  1833. else if ( cmSystemTools::FileExists(m_DartConfiguration["ValgrindCommand"].c_str()) )
  1834. {
  1835. m_MemoryTester
  1836. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["ValgrindCommand"].c_str());
  1837. }
  1838. else
  1839. {
  1840. std::cerr << "Memory checker (MemoryCheckCommand) not set, or cannot find the specified program."
  1841. << std::endl;
  1842. return false;
  1843. }
  1844. if ( m_MemoryTester[0] == '\"' && m_MemoryTester[m_MemoryTester.size()-1] == '\"' )
  1845. {
  1846. m_MemoryTester = m_MemoryTester.substr(1, m_MemoryTester.size()-2);
  1847. }
  1848. // Setup the options
  1849. if ( m_DartConfiguration["MemoryCheckCommandOptions"].size() )
  1850. {
  1851. m_MemoryTesterOptions = m_DartConfiguration["MemoryCheckCommandOptions"];
  1852. }
  1853. else if ( m_DartConfiguration["ValgrindCommandOptions"].size() )
  1854. {
  1855. m_MemoryTesterOptions = m_DartConfiguration["ValgrindCommandOptions"];
  1856. }
  1857. m_MemoryTesterOutputFile = m_ToplevelPath + "/Testing/Temporary/MemoryChecker.log";
  1858. m_MemoryTesterOutputFile = cmSystemTools::EscapeSpaces(m_MemoryTesterOutputFile.c_str());
  1859. if ( m_MemoryTester.find("valgrind") != std::string::npos )
  1860. {
  1861. m_MemoryTesterStyle = cmCTest::VALGRIND;
  1862. if ( !m_MemoryTesterOptions.size() )
  1863. {
  1864. m_MemoryTesterOptions = "-q --skin=memcheck --leak-check=yes --show-reachable=yes --workaround-gcc296-bugs=yes --num-callers=100";
  1865. }
  1866. if ( m_DartConfiguration["MemoryCheckSuppressionFile"].size() )
  1867. {
  1868. if ( !cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) )
  1869. {
  1870. std::cerr << "Cannot find memory checker suppression file: "
  1871. << m_DartConfiguration["MemoryCheckSuppressionFile"].c_str() << std::endl;
  1872. return false;
  1873. }
  1874. m_MemoryTesterOptions += " --suppressions=" + cmSystemTools::EscapeSpaces(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) + "";
  1875. }
  1876. }
  1877. else if ( m_MemoryTester.find("purify") != std::string::npos )
  1878. {
  1879. m_MemoryTesterStyle = cmCTest::PURIFY;
  1880. #ifdef _WIN32
  1881. m_MemoryTesterOptions += " /SAVETEXTDATA=" + m_MemoryTesterOutputFile;
  1882. #else
  1883. m_MemoryTesterOptions += " -log-file=" + m_MemoryTesterOutputFile;
  1884. #endif
  1885. }
  1886. else if ( m_MemoryTester.find("boundschecker") != std::string::npos )
  1887. {
  1888. m_MemoryTesterStyle = cmCTest::BOUNDS_CHECKER;
  1889. std::cerr << "Bounds checker not yet implemented" << std::endl;
  1890. return false;
  1891. }
  1892. else
  1893. {
  1894. std::cerr << "Do not understand memory checker: " << m_MemoryTester.c_str() << std::endl;
  1895. return false;
  1896. }
  1897. m_MemoryTesterOptionsParsed = cmSystemTools::ParseArguments(m_MemoryTesterOptions.c_str());
  1898. cmCTest::tm_VectorOfStrings::size_type cc;
  1899. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  1900. {
  1901. m_MemoryTesterGlobalResults[cc] = 0;
  1902. }
  1903. return true;
  1904. }
  1905. int cmCTest::TestDirectory(bool memcheck)
  1906. {
  1907. std::cout << (memcheck ? "Memory check" : "Test") << " project" << std::endl;
  1908. if ( memcheck )
  1909. {
  1910. if ( !this->InitializeMemoryChecking() )
  1911. {
  1912. return 1;
  1913. }
  1914. }
  1915. cmCTest::tm_VectorOfStrings passed;
  1916. cmCTest::tm_VectorOfStrings failed;
  1917. int total;
  1918. m_StartTest = ::CurrentTime();
  1919. this->ProcessDirectory(passed, failed, memcheck);
  1920. m_EndTest = ::CurrentTime();
  1921. total = int(passed.size()) + int(failed.size());
  1922. if (total == 0)
  1923. {
  1924. if ( !m_ShowOnly )
  1925. {
  1926. std::cerr << "No tests were found!!!\n";
  1927. }
  1928. }
  1929. else
  1930. {
  1931. if (m_Verbose && passed.size() &&
  1932. (m_UseIncludeRegExp || m_UseExcludeRegExp))
  1933. {
  1934. std::cerr << "\nThe following tests passed:\n";
  1935. for(cmCTest::tm_VectorOfStrings::iterator j = passed.begin();
  1936. j != passed.end(); ++j)
  1937. {
  1938. std::cerr << "\t" << *j << "\n";
  1939. }
  1940. }
  1941. float percent = float(passed.size()) * 100.0f / total;
  1942. fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  1943. percent, int(failed.size()), total);
  1944. if (failed.size())
  1945. {
  1946. std::cerr << "\nThe following tests FAILED:\n";
  1947. for(cmCTest::tm_VectorOfStrings::iterator j = failed.begin();
  1948. j != failed.end(); ++j)
  1949. {
  1950. std::cerr << "\t" << *j << "\n";
  1951. }
  1952. }
  1953. }
  1954. if ( m_DartMode )
  1955. {
  1956. std::ofstream ofs;
  1957. if( !this->OpenOutputFile(m_CurrentTag,
  1958. (memcheck ? (m_CompatibilityMode?"Purify.xml":"MemCheck.xml") : "Test.xml"), ofs) )
  1959. {
  1960. std::cerr << "Cannot create " << (memcheck ? "memory check" : "testing")
  1961. << " XML file" << std::endl;
  1962. return 1;
  1963. }
  1964. if ( memcheck )
  1965. {
  1966. this->GenerateDartMemCheckOutput(ofs);
  1967. }
  1968. else
  1969. {
  1970. this->GenerateDartTestOutput(ofs);
  1971. }
  1972. }
  1973. return int(failed.size());
  1974. }
  1975. int cmCTest::SubmitResults()
  1976. {
  1977. cmCTest::tm_VectorOfStrings files;
  1978. std::string prefix = this->GetSubmitResultsPrefix();
  1979. // TODO:
  1980. // Check if test is enabled
  1981. if ( this->CTestFileExists("Update.xml") )
  1982. {
  1983. files.push_back("Update.xml");
  1984. }
  1985. if ( this->CTestFileExists("Configure.xml") )
  1986. {
  1987. files.push_back("Configure.xml");
  1988. }
  1989. if ( this->CTestFileExists("Build.xml") )
  1990. {
  1991. files.push_back("Build.xml");
  1992. }
  1993. if ( this->CTestFileExists("Test.xml") )
  1994. {
  1995. files.push_back("Test.xml");
  1996. }
  1997. if ( this->CTestFileExists("Coverage.xml") )
  1998. {
  1999. files.push_back("Coverage.xml");
  2000. cmCTest::tm_VectorOfStrings gfiles;
  2001. std::string gpath = m_ToplevelPath + "/Testing/" + m_CurrentTag;
  2002. std::string::size_type glen = gpath.size() + 1;
  2003. gpath = gpath + "/CoverageLog*";
  2004. //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
  2005. if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
  2006. {
  2007. size_t cc;
  2008. for ( cc = 0; cc < gfiles.size(); cc ++ )
  2009. {
  2010. gfiles[cc] = gfiles[cc].substr(glen);
  2011. //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
  2012. files.push_back(gfiles[cc]);
  2013. }
  2014. }
  2015. else
  2016. {
  2017. std::cerr << "Problem globbing" << std::endl;
  2018. }
  2019. }
  2020. if ( this->CTestFileExists("MemCheck.xml") )
  2021. {
  2022. files.push_back("MemCheck.xml");
  2023. }
  2024. if ( this->CTestFileExists("Purify.xml") )
  2025. {
  2026. files.push_back("Purify.xml");
  2027. }
  2028. cmCTestSubmit submit;
  2029. submit.SetVerbose(m_Verbose);
  2030. if ( m_DartConfiguration["DropMethod"] == "" ||
  2031. m_DartConfiguration["DropMethod"] == "ftp" )
  2032. {
  2033. std::cout << " Using FTP submit method" << std::endl;
  2034. std::string url = "ftp://";
  2035. url += cmCTest::MakeURLSafe(m_DartConfiguration["DropSiteUser"]) + ":" +
  2036. cmCTest::MakeURLSafe(m_DartConfiguration["DropSitePassword"]) + "@" +
  2037. m_DartConfiguration["DropSite"] +
  2038. cmCTest::MakeURLSafe(m_DartConfiguration["DropLocation"]);
  2039. if ( !submit.SubmitUsingFTP(m_ToplevelPath+"/Testing/"+m_CurrentTag,
  2040. files, prefix, url) )
  2041. {
  2042. std::cerr << " Problems when submitting via FTP" << std::endl;
  2043. return 0;
  2044. }
  2045. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  2046. {
  2047. std::cerr << " Problems when triggering via HTTP" << std::endl;
  2048. return 0;
  2049. }
  2050. std::cout << " Submission successfull" << std::endl;
  2051. return 1;
  2052. }
  2053. else if ( m_DartConfiguration["DropMethod"] == "http" )
  2054. {
  2055. std::cout << " Using HTTP submit method" << std::endl;
  2056. std::string url = "http://";
  2057. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  2058. {
  2059. url += m_DartConfiguration["DropSiteUser"];
  2060. if ( m_DartConfiguration["DropSitePassword"].size() > 0 )
  2061. {
  2062. url += ":" + m_DartConfiguration["DropSitePassword"];
  2063. }
  2064. url += "@";
  2065. }
  2066. url += m_DartConfiguration["DropSite"] + m_DartConfiguration["DropLocation"];
  2067. if ( !submit.SubmitUsingHTTP(m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  2068. {
  2069. std::cerr << " Problems when submitting via HTTP" << std::endl;
  2070. return 0;
  2071. }
  2072. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  2073. {
  2074. std::cerr << " Problems when triggering via HTTP" << std::endl;
  2075. return 0;
  2076. }
  2077. std::cout << " Submission successfull" << std::endl;
  2078. return 1;
  2079. }
  2080. else
  2081. {
  2082. std::cerr << "SCP submit not yet implemented" << std::endl;
  2083. }
  2084. return 0;
  2085. }
  2086. bool cmCTest::CTestFileExists(const std::string& filename)
  2087. {
  2088. std::string testingDir = m_ToplevelPath + "/Testing/" + m_CurrentTag + "/" +
  2089. filename;
  2090. return cmSystemTools::FileExists(testingDir.c_str());
  2091. }
  2092. std::string cmCTest::GetSubmitResultsPrefix()
  2093. {
  2094. std::string name = m_DartConfiguration["Site"] +
  2095. "___" + m_DartConfiguration["BuildName"] +
  2096. "___" + m_CurrentTag + "-" +
  2097. this->GetTestModelString() + "___XML___";
  2098. return name;
  2099. }
  2100. void cmCTest::GenerateDartMemCheckOutput(std::ostream& os)
  2101. {
  2102. if ( !m_DartMode )
  2103. {
  2104. return;
  2105. }
  2106. this->StartXML(os);
  2107. if ( m_CompatibilityMode )
  2108. {
  2109. os << "<Purify>" << std::endl;
  2110. }
  2111. else
  2112. {
  2113. os << "<MemCheck>" << std::endl;
  2114. }
  2115. os << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  2116. << "\t<TestList>\n";
  2117. tm_TestResultsVector::size_type cc;
  2118. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2119. {
  2120. cmCTestTestResult *result = &m_TestResults[cc];
  2121. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  2122. << "/" << this->MakeXMLSafe(result->m_Name)
  2123. << "</Test>" << std::endl;
  2124. }
  2125. os << "\t</TestList>\n";
  2126. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2127. {
  2128. cmCTestTestResult *result = &m_TestResults[cc];
  2129. std::string memcheckstr;
  2130. int memcheckresults[cmCTest::NO_MEMORY_FAULT];
  2131. int kk;
  2132. this->ProcessMemCheckOutput(result->m_Output, memcheckstr, memcheckresults);
  2133. os << "\t<Test Status=\"";
  2134. if ( result->m_Status == cmCTest::COMPLETED )
  2135. {
  2136. os << "passed";
  2137. }
  2138. else if ( result->m_Status == cmCTest::NOT_RUN )
  2139. {
  2140. os << "notrun";
  2141. }
  2142. else
  2143. {
  2144. os << "failed";
  2145. }
  2146. os << "\">\n"
  2147. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  2148. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  2149. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  2150. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  2151. << "\t\t<FullCommandLine>"
  2152. << this->MakeXMLSafe(result->m_FullCommandLine)
  2153. << "</FullCommandLine>\n"
  2154. << "\t\t<Results>" << std::endl;
  2155. for ( kk = 0; cmCTestMemCheckResultStrings[kk]; kk ++ )
  2156. {
  2157. os << "\t\t\t<" << cmCTestMemCheckResultStrings[kk] << ">"
  2158. << memcheckresults[kk]
  2159. << "</" << cmCTestMemCheckResultStrings[kk] << ">" << std::endl;
  2160. m_MemoryTesterGlobalResults[kk] += memcheckresults[kk];
  2161. }
  2162. os
  2163. << "\t\t</Results>\n"
  2164. << "\t<Log>\n" << memcheckstr << std::endl
  2165. << "\t</Log>\n"
  2166. << "\t</Test>" << std::endl;
  2167. }
  2168. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>" << std::endl;
  2169. if ( m_CompatibilityMode )
  2170. {
  2171. os << "</Purify>" << std::endl;
  2172. }
  2173. else
  2174. {
  2175. os << "</MemCheck>" << std::endl;
  2176. }
  2177. this->EndXML(os);
  2178. std::cerr << "Memory checking results:" << std::endl;
  2179. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  2180. {
  2181. std::cerr << "\t\t" << cmCTestMemCheckResultStrings[cc] << " - "
  2182. << m_MemoryTesterGlobalResults[cc] << std::endl;
  2183. }
  2184. }
  2185. void cmCTest::GenerateDartTestOutput(std::ostream& os)
  2186. {
  2187. if ( !m_DartMode )
  2188. {
  2189. return;
  2190. }
  2191. this->StartXML(os);
  2192. os << "<Testing>\n"
  2193. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  2194. << "\t<TestList>\n";
  2195. tm_TestResultsVector::size_type cc;
  2196. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2197. {
  2198. cmCTestTestResult *result = &m_TestResults[cc];
  2199. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  2200. << "/" << this->MakeXMLSafe(result->m_Name)
  2201. << "</Test>" << std::endl;
  2202. }
  2203. os << "\t</TestList>\n";
  2204. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2205. {
  2206. cmCTestTestResult *result = &m_TestResults[cc];
  2207. os << "\t<Test Status=\"";
  2208. if ( result->m_Status == cmCTest::COMPLETED )
  2209. {
  2210. os << "passed";
  2211. }
  2212. else if ( result->m_Status == cmCTest::NOT_RUN )
  2213. {
  2214. os << "notrun";
  2215. }
  2216. else
  2217. {
  2218. os << "failed";
  2219. }
  2220. os << "\">\n"
  2221. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  2222. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  2223. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  2224. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  2225. << "\t\t<FullCommandLine>"
  2226. << this->MakeXMLSafe(result->m_FullCommandLine)
  2227. << "</FullCommandLine>\n"
  2228. << "\t\t<Results>" << std::endl;
  2229. if ( result->m_Status != cmCTest::NOT_RUN )
  2230. {
  2231. if ( result->m_Status != cmCTest::COMPLETED || result->m_ReturnValue )
  2232. {
  2233. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  2234. << this->GetTestStatus(result->m_Status) << "</Value></NamedMeasurement>\n"
  2235. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  2236. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  2237. }
  2238. os << result->m_RegressionImages;
  2239. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  2240. << "name=\"Execution Time\"><Value>"
  2241. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n";
  2242. os
  2243. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  2244. << "name=\"Completion Status\"><Value>"
  2245. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n";
  2246. }
  2247. os
  2248. << "\t\t\t<Measurement>\n"
  2249. << "\t\t\t\t<Value>" << this->MakeXMLSafe(result->m_Output)
  2250. << "</Value>\n"
  2251. << "\t\t\t</Measurement>\n"
  2252. << "\t\t</Results>\n"
  2253. << "\t</Test>" << std::endl;
  2254. }
  2255. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  2256. << "</Testing>" << std::endl;
  2257. this->EndXML(os);
  2258. }
  2259. int cmCTest::ProcessTests()
  2260. {
  2261. int res = 0;
  2262. bool notest = true;
  2263. int cc;
  2264. int update_count = 0;
  2265. for ( cc = 0; cc < LAST_TEST; cc ++ )
  2266. {
  2267. if ( m_Tests[cc] )
  2268. {
  2269. notest = false;
  2270. break;
  2271. }
  2272. }
  2273. if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
  2274. {
  2275. update_count = this->UpdateDirectory();
  2276. if ( update_count < 0 )
  2277. {
  2278. res |= CTEST_UPDATE_ERRORS;
  2279. }
  2280. }
  2281. if ( m_TestModel == cmCTest::CONTINUOUS && !update_count )
  2282. {
  2283. return 0;
  2284. }
  2285. if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
  2286. {
  2287. if (this->ConfigureDirectory())
  2288. {
  2289. res |= CTEST_CONFIGURE_ERRORS;
  2290. }
  2291. }
  2292. if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
  2293. {
  2294. if (this->BuildDirectory())
  2295. {
  2296. res |= CTEST_BUILD_ERRORS;
  2297. }
  2298. }
  2299. if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
  2300. {
  2301. if (this->TestDirectory(false))
  2302. {
  2303. res |= CTEST_TEST_ERRORS;
  2304. }
  2305. }
  2306. if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
  2307. {
  2308. this->CoverageDirectory();
  2309. }
  2310. if ( m_Tests[MEMCHECK_TEST] || m_Tests[ALL_TEST] )
  2311. {
  2312. if (this->TestDirectory(true))
  2313. {
  2314. res |= CTEST_MEMORY_ERRORS;
  2315. }
  2316. }
  2317. if ( m_Tests[SUBMIT_TEST] || m_Tests[ALL_TEST] )
  2318. {
  2319. this->SubmitResults();
  2320. }
  2321. return res;
  2322. }
  2323. std::string cmCTest::GetTestModelString()
  2324. {
  2325. switch ( m_TestModel )
  2326. {
  2327. case cmCTest::NIGHTLY:
  2328. return "Nightly";
  2329. case cmCTest::CONTINUOUS:
  2330. return "Continuous";
  2331. }
  2332. return "Experimental";
  2333. }
  2334. #define SPACE_REGEX "[ \t\r\n]"
  2335. std::string cmCTest::GenerateRegressionImages(const std::string& xml)
  2336. {
  2337. cmsys::RegularExpression twoattributes(
  2338. "<DartMeasurement"
  2339. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2340. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2341. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2342. cmsys::RegularExpression threeattributes(
  2343. "<DartMeasurement"
  2344. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2345. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2346. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2347. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2348. cmsys::RegularExpression fourattributes(
  2349. "<DartMeasurement"
  2350. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2351. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2352. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2353. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2354. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2355. cmsys::RegularExpression measurementfile(
  2356. "<DartMeasurementFile"
  2357. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2358. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2359. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  2360. cmOStringStream ostr;
  2361. bool done = false;
  2362. std::string cxml = xml;
  2363. while ( ! done )
  2364. {
  2365. if ( twoattributes.find(cxml) )
  2366. {
  2367. ostr
  2368. << "\t\t\t<NamedMeasurement"
  2369. << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
  2370. << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
  2371. << "><Value>" << twoattributes.match(5)
  2372. << "</Value></NamedMeasurement>"
  2373. << std::endl;
  2374. cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
  2375. }
  2376. else if ( threeattributes.find(cxml) )
  2377. {
  2378. ostr
  2379. << "\t\t\t<NamedMeasurement"
  2380. << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
  2381. << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
  2382. << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
  2383. << "><Value>" << threeattributes.match(7)
  2384. << "</Value></NamedMeasurement>"
  2385. << std::endl;
  2386. cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
  2387. }
  2388. else if ( fourattributes.find(cxml) )
  2389. {
  2390. ostr
  2391. << "\t\t\t<NamedMeasurement"
  2392. << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
  2393. << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
  2394. << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
  2395. << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
  2396. << "><Value>" << fourattributes.match(9)
  2397. << "</Value></NamedMeasurement>"
  2398. << std::endl;
  2399. cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
  2400. }
  2401. else if ( measurementfile.find(cxml) )
  2402. {
  2403. const std::string& filename = measurementfile.match(5);
  2404. if ( cmSystemTools::FileExists(filename.c_str()) )
  2405. {
  2406. long len = cmSystemTools::FileLength(filename.c_str());
  2407. std::ifstream ifs(filename.c_str(), std::ios::in
  2408. #ifdef _WIN32
  2409. | std::ios::binary
  2410. #endif
  2411. );
  2412. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  2413. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  2414. unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 1) ];
  2415. unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  2416. unsigned long cc;
  2417. ostr
  2418. << "\t\t\t<NamedMeasurement"
  2419. << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
  2420. << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
  2421. << " encoding=\"base64\""
  2422. << ">" << std::endl << "\t\t\t\t<Value>";
  2423. for ( cc = 0; cc < rlen; cc ++ )
  2424. {
  2425. ostr << encoded_buffer[cc];
  2426. if ( cc % 60 == 0 && cc )
  2427. {
  2428. ostr << std::endl;
  2429. }
  2430. }
  2431. ostr
  2432. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  2433. << std::endl;
  2434. delete [] file_buffer;
  2435. delete [] encoded_buffer;
  2436. }
  2437. else
  2438. {
  2439. int idx = 4;
  2440. if ( measurementfile.match(1) == "name" )
  2441. {
  2442. idx = 2;
  2443. }
  2444. ostr
  2445. << "\t\t\t<NamedMeasurement"
  2446. << " name=\"" << measurementfile.match(idx) << "\""
  2447. << " text=\"text/string\""
  2448. << "><Value>File " << filename << " not found</Value></NamedMeasurement>"
  2449. << std::endl;
  2450. }
  2451. cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
  2452. }
  2453. else
  2454. {
  2455. done = true;
  2456. }
  2457. }
  2458. return ostr.str();
  2459. }
  2460. int cmCTest::RunMakeCommand(const char* command, std::string* output,
  2461. int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs)
  2462. {
  2463. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  2464. if(args.size() < 1)
  2465. {
  2466. return false;
  2467. }
  2468. std::vector<const char*> argv;
  2469. for(std::vector<cmStdString>::const_iterator a = args.begin();
  2470. a != args.end(); ++a)
  2471. {
  2472. argv.push_back(a->c_str());
  2473. }
  2474. argv.push_back(0);
  2475. if ( output )
  2476. {
  2477. *output = "";
  2478. }
  2479. cmsysProcess* cp = cmsysProcess_New();
  2480. cmsysProcess_SetCommand(cp, &*argv.begin());
  2481. cmsysProcess_SetWorkingDirectory(cp, dir);
  2482. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2483. cmsysProcess_SetTimeout(cp, timeout);
  2484. cmsysProcess_Execute(cp);
  2485. std::string::size_type tick = 0;
  2486. std::string::size_type tick_len = 1024;
  2487. std::string::size_type tick_line_len = 50;
  2488. char* data;
  2489. int length;
  2490. if ( !verbose )
  2491. {
  2492. std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl;
  2493. std::cout << " " << std::flush;
  2494. }
  2495. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  2496. {
  2497. if ( output )
  2498. {
  2499. for(int cc =0; cc < length; ++cc)
  2500. {
  2501. if(data[cc] == 0)
  2502. {
  2503. data[cc] = '\n';
  2504. }
  2505. }
  2506. output->append(data, length);
  2507. if ( !verbose )
  2508. {
  2509. while ( output->size() > (tick * tick_len) )
  2510. {
  2511. tick ++;
  2512. std::cout << "." << std::flush;
  2513. if ( tick % tick_line_len == 0 && tick > 0 )
  2514. {
  2515. std::cout << " Size: ";
  2516. std::cout << int((output->size() / 1024.0) + 1) << "K" << std::endl;
  2517. std::cout << " " << std::flush;
  2518. }
  2519. }
  2520. }
  2521. }
  2522. if(verbose)
  2523. {
  2524. std::cout.write(data, length);
  2525. std::cout.flush();
  2526. }
  2527. if ( ofs )
  2528. {
  2529. ofs.write(data, length);
  2530. ofs.flush();
  2531. }
  2532. }
  2533. std::cout << " Size of output: ";
  2534. std::cout << int(output->size() / 1024.0) << "K" << std::endl;
  2535. cmsysProcess_WaitForExit(cp, 0);
  2536. int result = cmsysProcess_GetState(cp);
  2537. if(result == cmsysProcess_State_Exited)
  2538. {
  2539. *retVal = cmsysProcess_GetExitValue(cp);
  2540. }
  2541. else if(result == cmsysProcess_State_Exception)
  2542. {
  2543. *retVal = cmsysProcess_GetExitException(cp);
  2544. std::cout << "There was an exception: " << *retVal << std::endl;
  2545. }
  2546. else if(result == cmsysProcess_State_Expired)
  2547. {
  2548. std::cout << "There was a timeout" << std::endl;
  2549. }
  2550. else if(result == cmsysProcess_State_Error)
  2551. {
  2552. *output += "\n*** ERROR executing: ";
  2553. *output += cmsysProcess_GetErrorString(cp);
  2554. }
  2555. cmsysProcess_Delete(cp);
  2556. return result;
  2557. }
  2558. int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *retVal)
  2559. {
  2560. std::vector<char> tempOutput;
  2561. if ( output )
  2562. {
  2563. *output = "";
  2564. }
  2565. cmsysProcess* cp = cmsysProcess_New();
  2566. cmsysProcess_SetCommand(cp, &*argv.begin());
  2567. //std::cout << "Command is: " << argv[0] << std::endl;
  2568. if(cmSystemTools::GetRunCommandHideConsole())
  2569. {
  2570. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2571. }
  2572. cmsysProcess_SetTimeout(cp, m_TimeOut);
  2573. cmsysProcess_Execute(cp);
  2574. char* data;
  2575. int length;
  2576. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  2577. {
  2578. if ( output )
  2579. {
  2580. tempOutput.insert(tempOutput.end(), data, data+length);
  2581. }
  2582. if ( m_Verbose )
  2583. {
  2584. std::cout.write(data, length);
  2585. std::cout.flush();
  2586. }
  2587. }
  2588. cmsysProcess_WaitForExit(cp, 0);
  2589. if(output)
  2590. {
  2591. output->append(&*tempOutput.begin(), tempOutput.size());
  2592. }
  2593. int result = cmsysProcess_GetState(cp);
  2594. if(result == cmsysProcess_State_Exited)
  2595. {
  2596. *retVal = cmsysProcess_GetExitValue(cp);
  2597. }
  2598. else if(result == cmsysProcess_State_Exception)
  2599. {
  2600. *retVal = cmsysProcess_GetExitException(cp);
  2601. }
  2602. else if(result == cmsysProcess_State_Error)
  2603. {
  2604. std::string outerr = "\n*** ERROR executing: ";
  2605. outerr += cmsysProcess_GetErrorString(cp);
  2606. *output += outerr;
  2607. if ( m_Verbose )
  2608. {
  2609. std::cout << outerr.c_str() << "\n";
  2610. std::cout.flush();
  2611. }
  2612. }
  2613. cmsysProcess_Delete(cp);
  2614. return result;
  2615. }
  2616. const char* cmCTest::GetTestStatus(int status)
  2617. {
  2618. static const char statuses[][100] = {
  2619. "Not Run",
  2620. "Timeout",
  2621. "SEGFAULT",
  2622. "ILLEGAL",
  2623. "INTERRUPT",
  2624. "NUMERICAL",
  2625. "OTHER_FAULT",
  2626. "Failed",
  2627. "BAD_COMMAND",
  2628. "Completed"
  2629. };
  2630. if ( status < cmCTest::NOT_RUN || status > cmCTest::COMPLETED )
  2631. {
  2632. return "No Status";
  2633. }
  2634. return statuses[status];
  2635. }
  2636. int cmCTest::RunConfigurationScript()
  2637. {
  2638. m_ConfigurationScript =
  2639. cmSystemTools::CollapseFullPath(m_ConfigurationScript.c_str());
  2640. // make sure the file exists
  2641. if (!cmSystemTools::FileExists(m_ConfigurationScript.c_str()))
  2642. {
  2643. return -1;
  2644. }
  2645. // create a cmake instance to read the configuration script
  2646. cmake cm;
  2647. cmGlobalGenerator gg;
  2648. gg.SetCMakeInstance(&cm);
  2649. // read in the list file to fill the cache
  2650. cmLocalGenerator *lg = gg.CreateLocalGenerator();
  2651. lg->SetGlobalGenerator(&gg);
  2652. // set a variable with the path to the current script
  2653. lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_DIRECTORY",
  2654. cmSystemTools::GetFilenamePath(
  2655. m_ConfigurationScript).c_str());
  2656. lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_NAME",
  2657. cmSystemTools::GetFilenameName(
  2658. m_ConfigurationScript).c_str());
  2659. if (!lg->GetMakefile()->ReadListFile(0, m_ConfigurationScript.c_str()))
  2660. {
  2661. return -2;
  2662. }
  2663. // no popup widows
  2664. cmSystemTools::SetRunCommandHideConsole(true);
  2665. // get some info that should be set
  2666. cmMakefile *mf = lg->GetMakefile();
  2667. const char *srcDir = mf->GetDefinition("CTEST_SOURCE_DIRECTORY");
  2668. const char *binDir = mf->GetDefinition("CTEST_BINARY_DIRECTORY");
  2669. const char *ctestCmd = mf->GetDefinition("CTEST_COMMAND");
  2670. const char *ctestEnv = mf->GetDefinition("CTEST_ENVIRONMENT");
  2671. bool backup = mf->IsOn("CTEST_BACKUP_AND_RESTORE");
  2672. // make sure the required info is here
  2673. if (!srcDir || !binDir || !ctestCmd)
  2674. {
  2675. cmSystemTools::Error("Some required settings in the configuration file were missing");
  2676. return -3;
  2677. }
  2678. // set any environment variables
  2679. if (ctestEnv)
  2680. {
  2681. static char ctestEnvStatic[100][5000];
  2682. std::vector<std::string> envArgs;
  2683. cmSystemTools::ExpandListArgument(ctestEnv,envArgs);
  2684. int numArgs = envArgs.size();
  2685. // we have a hard limit of 100 env args due to stupid format of putenv
  2686. if (numArgs > 100)
  2687. {
  2688. numArgs = 100;
  2689. }
  2690. // for each variable/argument do a putenv
  2691. int i;
  2692. for (i = 0; i < numArgs; ++i)
  2693. {
  2694. // also limit args to be at most 4K long
  2695. std::string::size_type size = envArgs[i].size();
  2696. if(size > 4999)
  2697. {
  2698. size = 4999;
  2699. }
  2700. strncpy(ctestEnvStatic[i], envArgs[i].c_str(), size);
  2701. ctestEnvStatic[i][4999] = 0;
  2702. putenv(ctestEnvStatic[i]);
  2703. }
  2704. }
  2705. // compute the backup names
  2706. std::string backupSrcDir = srcDir;
  2707. backupSrcDir += "_CMakeBackup";
  2708. std::string backupBinDir = binDir;
  2709. backupBinDir += "_CMakeBackup";
  2710. // backup the binary and src directories if requested
  2711. if (backup)
  2712. {
  2713. // if for some reason those directories exist then first delete them
  2714. if (cmSystemTools::FileExists(backupSrcDir.c_str()))
  2715. {
  2716. cmSystemTools::RemoveADirectory(backupSrcDir.c_str());
  2717. }
  2718. if (cmSystemTools::FileExists(backupBinDir.c_str()))
  2719. {
  2720. cmSystemTools::RemoveADirectory(backupBinDir.c_str());
  2721. }
  2722. // first rename the src and binary directories
  2723. rename(srcDir, backupSrcDir.c_str());
  2724. rename(binDir, backupBinDir.c_str());
  2725. }
  2726. // clear the binary directory?
  2727. if (mf->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY"))
  2728. {
  2729. // try to avoid deleting directories that we shouldn't
  2730. std::string check = binDir;
  2731. check += "/CMakeCache.txt";
  2732. if (cmSystemTools::FileExists(check.c_str()))
  2733. {
  2734. cmSystemTools::RemoveADirectory(binDir);
  2735. }
  2736. }
  2737. // make sure the binary directory exists
  2738. if (!cmSystemTools::FileExists(binDir))
  2739. {
  2740. if (!cmSystemTools::MakeDirectory(binDir))
  2741. {
  2742. cmSystemTools::Error("Unable to create the binary directory");
  2743. return -4;
  2744. }
  2745. }
  2746. std::string command;
  2747. std::string output;
  2748. int retVal = 0;
  2749. bool res = 0;
  2750. // do an initial cvs update on the src dir
  2751. const char *cvsCmd = mf->GetDefinition("CTEST_CVS_COMMAND");
  2752. if (cvsCmd)
  2753. {
  2754. command = cvsCmd;
  2755. char updateVar[40];
  2756. int i;
  2757. for (i = 1; i < 10; ++i)
  2758. {
  2759. sprintf(updateVar,"CTEST_EXTRA_UPDATES_%i",i);
  2760. const char *updateVal = mf->GetDefinition(updateVar);
  2761. if (updateVal)
  2762. {
  2763. std::vector<std::string> cvsArgs;
  2764. cmSystemTools::ExpandListArgument(updateVal,cvsArgs);
  2765. if (cvsArgs.size() == 2)
  2766. {
  2767. std::string fullCommand = command;
  2768. fullCommand += " update ";
  2769. fullCommand += cvsArgs[1];
  2770. output.empty();
  2771. retVal = 0;
  2772. res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output,
  2773. &retVal, cvsArgs[0].c_str(),
  2774. m_Verbose, 0 /*m_TimeOut*/);
  2775. if (!res || retVal != 0)
  2776. {
  2777. cmSystemTools::Error("Unable to perform extra cvs updates");
  2778. return -5;
  2779. }
  2780. }
  2781. }
  2782. }
  2783. }
  2784. // put the initial cache into the bin dir
  2785. if (mf->GetDefinition("CTEST_INITIAL_CACHE"))
  2786. {
  2787. const char *initCache = mf->GetDefinition("CTEST_INITIAL_CACHE");
  2788. std::string cacheFile = binDir;
  2789. cacheFile += "/CMakeCache.txt";
  2790. std::ofstream fout(cacheFile.c_str());
  2791. if(!fout)
  2792. {
  2793. return -6;
  2794. }
  2795. fout.write(initCache, strlen(initCache));
  2796. // Make sure the operating system has finished writing the file
  2797. // before closing it. This will ensure the file is finished before
  2798. // the check below.
  2799. fout.flush();
  2800. fout.close();
  2801. }
  2802. // do an initial cmake to setup the DartConfig file
  2803. const char *cmakeCmd = mf->GetDefinition("CTEST_CMAKE_COMMAND");
  2804. if (cmakeCmd)
  2805. {
  2806. command = cmakeCmd;
  2807. command += " \"";
  2808. command += srcDir;
  2809. output.empty();
  2810. command += "\"";
  2811. retVal = 0;
  2812. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  2813. &retVal, binDir,
  2814. m_Verbose, 0 /*m_TimeOut*/);
  2815. if (!res || retVal != 0)
  2816. {
  2817. cmSystemTools::Error("Unable to run cmake");
  2818. return -7;
  2819. }
  2820. }
  2821. // run ctest
  2822. command = ctestCmd;
  2823. output.empty();
  2824. retVal = 0;
  2825. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  2826. &retVal, binDir,
  2827. m_Verbose, 0 /*m_TimeOut*/);
  2828. // did something critical fail in ctest
  2829. if (!res ||
  2830. retVal & CTEST_BUILD_ERRORS)
  2831. {
  2832. // if we backed up the dirs and the build failed, then restore
  2833. // the backed up dirs
  2834. if (backup)
  2835. {
  2836. // if for some reason those directories exist then first delete them
  2837. if (cmSystemTools::FileExists(srcDir))
  2838. {
  2839. cmSystemTools::RemoveADirectory(srcDir);
  2840. }
  2841. if (cmSystemTools::FileExists(binDir))
  2842. {
  2843. cmSystemTools::RemoveADirectory(binDir);
  2844. }
  2845. // rename the src and binary directories
  2846. rename(backupSrcDir.c_str(), srcDir);
  2847. rename(backupBinDir.c_str(), binDir);
  2848. }
  2849. cmSystemTools::Error("Unable to run ctest");
  2850. if (!res)
  2851. {
  2852. return -8;
  2853. }
  2854. return retVal;
  2855. }
  2856. return 0;
  2857. }
  2858. void cmCTest::StartXML(std::ostream& ostr)
  2859. {
  2860. ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2861. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  2862. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  2863. << this->GetTestModelString() << "\" Name=\""
  2864. << m_DartConfiguration["Site"] << "\">" << std::endl;
  2865. }
  2866. void cmCTest::EndXML(std::ostream& ostr)
  2867. {
  2868. ostr << "</Site>" << std::endl;
  2869. }
  2870. bool cmCTest::ProcessMemCheckPurifyOutput(const std::string&, std::string& log,
  2871. int* results)
  2872. {
  2873. if ( !cmSystemTools::FileExists(m_MemoryTesterOutputFile.c_str()) )
  2874. {
  2875. log = "Cannot find Purify output file: " + m_MemoryTesterOutputFile;
  2876. std::cerr << log.c_str() << std::endl;
  2877. return false;
  2878. }
  2879. std::ifstream ifs(m_MemoryTesterOutputFile.c_str());
  2880. if ( !ifs )
  2881. {
  2882. log = "Cannot read Purify output file: " + m_MemoryTesterOutputFile;
  2883. std::cerr << log.c_str() << std::endl;
  2884. return false;
  2885. }
  2886. cmOStringStream ostr;
  2887. log = "";
  2888. cmsys::RegularExpression pfW("^\\[[WEI]\\] ([A-Z][A-Z][A-Z][A-Z]*): ");
  2889. std::string line;
  2890. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  2891. {
  2892. int failure = cmCTest::NO_MEMORY_FAULT;
  2893. if ( pfW.find(line) )
  2894. {
  2895. int cc;
  2896. for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
  2897. {
  2898. if ( pfW.match(1) == cmCTestMemCheckResultStrings[cc] )
  2899. {
  2900. failure = cc;
  2901. break;
  2902. }
  2903. }
  2904. if ( cc == cmCTest::NO_MEMORY_FAULT )
  2905. {
  2906. std::cerr<< "Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  2907. ostr << "*** Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  2908. }
  2909. }
  2910. if ( failure != NO_MEMORY_FAULT )
  2911. {
  2912. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  2913. results[failure] ++;
  2914. }
  2915. ostr << cmCTest::MakeXMLSafe(line) << std::endl;
  2916. }
  2917. log = ostr.str();
  2918. return true;
  2919. }
  2920. bool cmCTest::ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
  2921. int* results)
  2922. {
  2923. std::vector<cmStdString> lines;
  2924. cmSystemTools::Split(str.c_str(), lines);
  2925. std::string::size_type cc;
  2926. cmOStringStream ostr;
  2927. log = "";
  2928. cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
  2929. cmsys::RegularExpression vgFIM(
  2930. "== .*Invalid free\\(\\) / delete / delete\\[\\]");
  2931. cmsys::RegularExpression vgFMM(
  2932. "== .*Mismatched free\\(\\) / delete / delete \\[\\]");
  2933. cmsys::RegularExpression vgMLK(
  2934. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are definitely lost"
  2935. " in loss record [0-9][0-9]* of [0-9]");
  2936. cmsys::RegularExpression vgPAR(
  2937. "== .*Syscall param .* contains unaddressable byte\\(s\\)");
  2938. cmsys::RegularExpression vgMPK1(
  2939. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are possibly lost in"
  2940. " loss record [0-9][0-9]* of [0-9]");
  2941. cmsys::RegularExpression vgMPK2(
  2942. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are still reachable"
  2943. " in loss record [0-9][0-9]* of [0-9]");
  2944. cmsys::RegularExpression vgUMC(
  2945. "== .*Conditional jump or move depends on uninitialised value\\(s\\)");
  2946. cmsys::RegularExpression vgUMR1("== .*Use of uninitialised value of size [0-9][0-9]*");
  2947. cmsys::RegularExpression vgUMR2("== .*Invalid read of size [0-9][0-9]*");
  2948. cmsys::RegularExpression vgUMR3("== .*Jump to the invalid address ");
  2949. cmsys::RegularExpression vgUMR4(
  2950. "== .*Syscall param .* contains uninitialised or unaddressable byte\\(s\\)");
  2951. cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9]");
  2952. for ( cc = 0; cc < lines.size(); cc ++ )
  2953. {
  2954. if ( valgrindLine.find(lines[cc]) )
  2955. {
  2956. int failure = cmCTest::NO_MEMORY_FAULT;
  2957. if ( vgFIM.find(lines[cc]) ) { failure = cmCTest::FIM; }
  2958. else if ( vgFMM.find(lines[cc]) ) { failure = cmCTest::FMM; }
  2959. else if ( vgMLK.find(lines[cc]) ) { failure = cmCTest::MLK; }
  2960. else if ( vgPAR.find(lines[cc]) ) { failure = cmCTest::PAR; }
  2961. else if ( vgMPK1.find(lines[cc]) ){ failure = cmCTest::MPK; }
  2962. else if ( vgMPK2.find(lines[cc]) ){ failure = cmCTest::MPK; }
  2963. else if ( vgUMC.find(lines[cc]) ) { failure = cmCTest::UMC; }
  2964. else if ( vgUMR1.find(lines[cc]) ){ failure = cmCTest::UMR; }
  2965. else if ( vgUMR2.find(lines[cc]) ){ failure = cmCTest::UMR; }
  2966. else if ( vgUMR3.find(lines[cc]) ){ failure = cmCTest::UMR; }
  2967. else if ( vgUMR4.find(lines[cc]) ){ failure = cmCTest::UMR; }
  2968. else if ( vgIPW.find(lines[cc]) ) { failure = cmCTest::IPW; }
  2969. if ( failure != cmCTest::NO_MEMORY_FAULT )
  2970. {
  2971. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  2972. results[failure] ++;
  2973. }
  2974. ostr << cmCTest::MakeXMLSafe(lines[cc]) << std::endl;
  2975. }
  2976. }
  2977. log = ostr.str();
  2978. return true;
  2979. }
  2980. bool cmCTest::ProcessMemCheckOutput(const std::string& str, std::string& log, int* results)
  2981. {
  2982. std::string::size_type cc;
  2983. for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
  2984. {
  2985. results[cc] = 0;
  2986. }
  2987. if ( m_MemoryTesterStyle == cmCTest::VALGRIND )
  2988. {
  2989. return ProcessMemCheckValgrindOutput(str, log, results);
  2990. }
  2991. else if ( m_MemoryTesterStyle == cmCTest::PURIFY )
  2992. {
  2993. return ProcessMemCheckPurifyOutput(str, log, results);
  2994. }
  2995. else if ( m_MemoryTesterStyle == cmCTest::BOUNDS_CHECKER )
  2996. {
  2997. log.append("\nMemory checking style used was: ");
  2998. log.append("Bounds Checker");
  2999. }
  3000. else
  3001. {
  3002. log.append("\nMemory checking style used was: ");
  3003. log.append("None that I know");
  3004. log = str;
  3005. }
  3006. return true;
  3007. }