cmCTest.cxx 92 KB

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