cmCTest.cxx 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100
  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 "cmSystemTools.h"
  15. #include "cmListFileCache.h"
  16. #include <cmsys/RegularExpression.hxx>
  17. #ifdef HAVE_CURL
  18. # include "cmCTestSubmit.h"
  19. # include "curl/curl.h"
  20. #endif
  21. #include <stdlib.h> // required for atoi
  22. #include <stdio.h>
  23. #include <time.h>
  24. #include <math.h>
  25. #include <float.h>
  26. #define SAFEDIV(x,y) (((y)!=0)?((x)/(y)):(0))
  27. #ifdef HAVE_CURL
  28. static struct tm* GetNightlyTime(std::string str)
  29. {
  30. struct tm* lctime;
  31. time_t tctime = time(0);
  32. //Convert the nightly start time to seconds. Since we are
  33. //providing only a time and a timezone, the current date of
  34. //the local machine is assumed. Consequently, nightlySeconds
  35. //is the time at which the nightly dashboard was opened or
  36. //will be opened on the date of the current client machine.
  37. //As such, this time may be in the past or in the future.
  38. time_t ntime = curl_getdate(str.c_str(), &tctime);
  39. tctime = time(0);
  40. //std::cout << "Seconds: " << tctime << std::endl;
  41. if ( ntime > tctime )
  42. {
  43. // If nightlySeconds is in the past, this is the current
  44. // open dashboard, then return nightlySeconds. If
  45. // nightlySeconds is in the future, this is the next
  46. // dashboard to be opened, so subtract 24 hours to get the
  47. // time of the current open dashboard
  48. ntime -= (24 * 60 * 60 );
  49. //std::cout << "Pick yesterday" << std::endl;
  50. }
  51. //std::cout << "nightlySeconds: " << ntime << std::endl;
  52. lctime = gmtime(&ntime);
  53. return lctime;
  54. }
  55. #endif
  56. static std::string CleanString(std::string str)
  57. {
  58. std::string::size_type spos = str.find_first_not_of(" \n\t");
  59. std::string::size_type epos = str.find_last_not_of(" \n\t");
  60. if ( spos == str.npos )
  61. {
  62. return std::string();
  63. }
  64. if ( epos != str.npos )
  65. {
  66. epos = epos - spos + 1;
  67. }
  68. return str.substr(spos, epos);
  69. }
  70. static std::string CurrentTime()
  71. {
  72. time_t currenttime = time(0);
  73. struct tm* t = localtime(&currenttime);
  74. //return ::CleanString(ctime(&currenttime));
  75. char current_time[1024];
  76. strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
  77. //std::cout << "Current_Time: " << current_time << std::endl;
  78. return ::CleanString(current_time);
  79. }
  80. static const char* cmCTestErrorMatches[] = {
  81. "^[Bb]us [Ee]rror",
  82. "^[Ss]egmentation [Vv]iolation",
  83. "^[Ss]egmentation [Ff]ault",
  84. "([^ :]+):([0-9]+): ([^ \\t])",
  85. "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
  86. "^Error ([0-9]+):",
  87. "^Fatal",
  88. "^Error: ",
  89. "^Error ",
  90. "[0-9] ERROR: ",
  91. "^\"[^\"]+\", line [0-9]+: [^Ww]",
  92. "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
  93. "^ld([^:])*:([ \\t])*ERROR([^:])*:",
  94. "^ild:([ \\t])*\\(undefined symbol\\)",
  95. "([^ :]+) : (error|fatal error|catastrophic error)",
  96. "([^:]+): (Error:|error|undefined reference|multiply defined)",
  97. "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
  98. "^fatal error C[0-9]+:",
  99. ": syntax error ",
  100. "^collect2: ld returned 1 exit status",
  101. "Unsatisfied symbols:",
  102. "Undefined symbols:",
  103. "^Undefined[ \\t]+first referenced",
  104. "^CMake Error:",
  105. ":[ \\t]cannot find",
  106. ":[ \\t]can't find",
  107. ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
  108. ": Invalid loader fixup for symbol",
  109. ": internal link edit command failed",
  110. ": Unrecognized option \\`.*\\'",
  111. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^W]\\)",
  112. 0
  113. };
  114. static const char* cmCTestErrorExceptions[] = {
  115. "instantiated from ",
  116. "candidates are:",
  117. ": warning",
  118. "makefile:",
  119. "Makefile:",
  120. ":[ \\t]+Where:",
  121. 0
  122. };
  123. static const char* cmCTestWarningMatches[] = {
  124. "([^ :]+):([0-9]+): warning:",
  125. "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
  126. "^ld([^:])*:([ \\t])*WARNING([^:])*:",
  127. "([^:]+): warning ([0-9]+):",
  128. "^\"[^\"]+\", line [0-9]+: [Ww]arning",
  129. "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
  130. "^Warning ([0-9]+):",
  131. "^Warning ",
  132. "WARNING: ",
  133. "([^ :]+) : warning",
  134. "([^:]+): warning",
  135. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\(W\\)",
  136. 0
  137. };
  138. static const char* cmCTestWarningExceptions[] = {
  139. "/usr/openwin/include/X11/Xlib\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  140. "/usr/openwin/include/X11/Xutil\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  141. "/usr/openwin/include/X11/XResource\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  142. "WARNING 84 :",
  143. "WARNING 47 :",
  144. "makefile:",
  145. "Makefile:",
  146. "warning: Clock skew detected. Your build may be incomplete.",
  147. "/usr/openwin/include/GL/[^:]+:",
  148. "bind_at_load",
  149. "XrmQGetResource",
  150. "IceFlush",
  151. "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
  152. "ld32: WARNING 85: definition of dataKey in",
  153. "cc: warning 422: Unknown option \"\\+b\\.\" ignored",
  154. 0
  155. };
  156. std::string cmCTest::MakeXMLSafe(const std::string& str)
  157. {
  158. cmOStringStream ost;
  159. char buffer[10];
  160. for (std::string::size_type pos = 0; pos < str.size(); pos ++ )
  161. {
  162. unsigned char ch = str[pos];
  163. if ( (ch > 126 || ch < 32) && ch != 9 && ch != 10 && ch != 13 )
  164. {
  165. sprintf(buffer, "&gt;%d&lt;", (int)ch);
  166. //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
  167. ost << buffer;
  168. }
  169. else
  170. {
  171. switch ( ch )
  172. {
  173. case '&': ost << "&amp;"; break;
  174. case '<': ost << "&lt;"; break;
  175. case '>': ost << "&gt;"; break;
  176. default: ost << ch;
  177. }
  178. }
  179. }
  180. return ost.str();
  181. }
  182. std::string cmCTest::MakeURLSafe(const std::string& str)
  183. {
  184. cmOStringStream ost;
  185. char buffer[10];
  186. for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
  187. {
  188. unsigned char ch = str[pos];
  189. if ( ( ch > 126 || ch < 32 ||
  190. ch == '&' ||
  191. ch == '%' ||
  192. ch == '+' ||
  193. ch == '=' ||
  194. ch == '@'
  195. ) && ch != 9 )
  196. {
  197. sprintf(buffer, "%02x;", (unsigned int)ch);
  198. ost << buffer;
  199. }
  200. else
  201. {
  202. ost << ch;
  203. }
  204. }
  205. return ost.str();
  206. }
  207. bool TryExecutable(const char *dir, const char *file,
  208. std::string *fullPath, const char *subdir)
  209. {
  210. // try current directory
  211. std::string tryPath;
  212. if (dir && strcmp(dir,""))
  213. {
  214. tryPath = dir;
  215. tryPath += "/";
  216. }
  217. if (subdir && strcmp(subdir,""))
  218. {
  219. tryPath += subdir;
  220. tryPath += "/";
  221. }
  222. tryPath += file;
  223. if(cmSystemTools::FileExists(tryPath.c_str()))
  224. {
  225. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  226. return true;
  227. }
  228. tryPath += cmSystemTools::GetExecutableExtension();
  229. if(cmSystemTools::FileExists(tryPath.c_str()))
  230. {
  231. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  232. return true;
  233. }
  234. return false;
  235. }
  236. cmCTest::cmCTest()
  237. {
  238. m_UseIncludeRegExp = false;
  239. m_UseExcludeRegExp = false;
  240. m_UseExcludeRegExpFirst = false;
  241. m_Verbose = false;
  242. m_DartMode = false;
  243. m_ShowOnly = false;
  244. m_TestModel = cmCTest::EXPERIMENTAL;
  245. int cc;
  246. for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
  247. {
  248. m_Tests[cc] = 0;
  249. }
  250. }
  251. void cmCTest::Initialize()
  252. {
  253. m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
  254. // parse the dart test file
  255. std::ifstream fin("DartConfiguration.tcl");
  256. if(!fin)
  257. {
  258. return;
  259. }
  260. char buffer[1024];
  261. while ( fin )
  262. {
  263. buffer[0] = 0;
  264. fin.getline(buffer, 1023);
  265. buffer[1023] = 0;
  266. std::string line = ::CleanString(buffer);
  267. if(line.size() == 0)
  268. {
  269. continue;
  270. }
  271. while ( fin && (line[line.size()-1] == '\\') )
  272. {
  273. line = line.substr(0, line.size()-1);
  274. buffer[0] = 0;
  275. fin.getline(buffer, 1023);
  276. buffer[1023] = 0;
  277. line += ::CleanString(buffer);
  278. }
  279. if ( line[0] == '#' )
  280. {
  281. continue;
  282. }
  283. std::string::size_type cpos = line.find_first_of(":");
  284. if ( cpos == line.npos )
  285. {
  286. continue;
  287. }
  288. std::string key = line.substr(0, cpos);
  289. std::string value = ::CleanString(line.substr(cpos+1, line.npos));
  290. m_DartConfiguration[key] = value;
  291. }
  292. fin.close();
  293. if ( m_DartMode )
  294. {
  295. std::string testingDir = m_ToplevelPath + "/Testing";
  296. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  297. {
  298. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  299. {
  300. std::cerr << "File " << testingDir << " is in the place of the testing directory"
  301. << std::endl;
  302. return;
  303. }
  304. }
  305. else
  306. {
  307. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  308. {
  309. std::cerr << "Cannot create directory " << testingDir
  310. << std::endl;
  311. return;
  312. }
  313. }
  314. std::string tagfile = testingDir + "/TAG";
  315. std::ifstream tfin(tagfile.c_str());
  316. std::string tag;
  317. time_t tctime = time(0);
  318. struct tm *lctime = gmtime(&tctime);
  319. if ( tfin )
  320. {
  321. tfin >> tag;
  322. tfin.close();
  323. int year = 0;
  324. int mon = 0;
  325. int day = 0;
  326. int hour = 0;
  327. int min = 0;
  328. sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
  329. &year, &mon, &day, &hour, &min);
  330. if ( year != lctime->tm_year + 1900 ||
  331. mon != lctime->tm_mon+1 ||
  332. day != lctime->tm_mday )
  333. {
  334. tag = "";
  335. }
  336. }
  337. if ( tag.size() == 0 || m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST])
  338. {
  339. #ifdef HAVE_CURL
  340. //std::cout << "TestModel: " << this->GetTestModelString() << std::endl;
  341. //std::cout << "TestModel: " << m_TestModel << std::endl;
  342. if ( m_TestModel == cmCTest::NIGHTLY )
  343. {
  344. lctime = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"]);
  345. }
  346. #endif
  347. char datestring[100];
  348. sprintf(datestring, "%04d%02d%02d-%02d%02d",
  349. lctime->tm_year + 1900,
  350. lctime->tm_mon+1,
  351. lctime->tm_mday,
  352. lctime->tm_hour,
  353. lctime->tm_min);
  354. tag = datestring;
  355. std::ofstream ofs(tagfile.c_str());
  356. if ( ofs )
  357. {
  358. ofs << tag << std::endl;
  359. }
  360. ofs.close();
  361. std::cout << "Create new tag: " << tag << std::endl;
  362. }
  363. m_CurrentTag = tag;
  364. }
  365. }
  366. bool cmCTest::SetTest(const char* ttype)
  367. {
  368. if ( cmSystemTools::LowerCase(ttype) == "all" )
  369. {
  370. m_Tests[cmCTest::ALL_TEST] = 1;
  371. }
  372. else if ( cmSystemTools::LowerCase(ttype) == "start" )
  373. {
  374. m_Tests[cmCTest::START_TEST] = 1;
  375. }
  376. else if ( cmSystemTools::LowerCase(ttype) == "update" )
  377. {
  378. m_Tests[cmCTest::UPDATE_TEST] = 1;
  379. }
  380. else if ( cmSystemTools::LowerCase(ttype) == "configure" )
  381. {
  382. m_Tests[cmCTest::CONFIGURE_TEST] = 1;
  383. }
  384. else if ( cmSystemTools::LowerCase(ttype) == "build" )
  385. {
  386. m_Tests[cmCTest::BUILD_TEST] = 1;
  387. }
  388. else if ( cmSystemTools::LowerCase(ttype) == "test" )
  389. {
  390. m_Tests[cmCTest::TEST_TEST] = 1;
  391. }
  392. else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
  393. {
  394. m_Tests[cmCTest::COVERAGE_TEST] = 1;
  395. }
  396. else if ( cmSystemTools::LowerCase(ttype) == "purify" )
  397. {
  398. m_Tests[cmCTest::PURIFY_TEST] = 1;
  399. }
  400. else if ( cmSystemTools::LowerCase(ttype) == "submit" )
  401. {
  402. m_Tests[cmCTest::SUBMIT_TEST] = 1;
  403. }
  404. else
  405. {
  406. std::cerr << "Don't know about test \"" << ttype << "\" yet..." << std::endl;
  407. return false;
  408. }
  409. return true;
  410. }
  411. void cmCTest::Finalize()
  412. {
  413. }
  414. std::string cmCTest::FindTheExecutable(const char *exe)
  415. {
  416. std::string fullPath = "";
  417. std::string dir;
  418. std::string file;
  419. cmSystemTools::SplitProgramPath(exe, dir, file);
  420. if(m_ConfigType != "")
  421. {
  422. if(TryExecutable(dir.c_str(), file.c_str(), &fullPath,
  423. m_ConfigType.c_str()))
  424. {
  425. return fullPath;
  426. }
  427. dir += "/";
  428. dir += m_ConfigType;
  429. dir += "/";
  430. dir += file;
  431. cmSystemTools::Error("config type specified on the command line, but test executable not found.",
  432. dir.c_str());
  433. return "";
  434. }
  435. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
  436. {
  437. return fullPath;
  438. }
  439. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
  440. {
  441. return fullPath;
  442. }
  443. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
  444. {
  445. return fullPath;
  446. }
  447. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
  448. {
  449. return fullPath;
  450. }
  451. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
  452. {
  453. return fullPath;
  454. }
  455. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
  456. {
  457. return fullPath;
  458. }
  459. // if everything else failed, check the users path
  460. if (dir != "")
  461. {
  462. std::string path = cmSystemTools::FindProgram(file.c_str());
  463. if (path != "")
  464. {
  465. return path;
  466. }
  467. }
  468. return fullPath;
  469. }
  470. int cmCTest::UpdateDirectory()
  471. {
  472. int count = 0;
  473. std::string::size_type cc, kk;
  474. std::string cvsCommand = m_DartConfiguration["CVSCommand"];
  475. if ( cvsCommand.size() == 0 )
  476. {
  477. std::cerr << "Cannot find CVSCommand key in the DartConfiguration.tcl" << std::endl;
  478. return -1;
  479. }
  480. std::string cvsOptions = m_DartConfiguration["CVSUpdateOptions"];
  481. if ( cvsOptions.size() == 0 )
  482. {
  483. std::cerr << "Cannot find CVSUpdateOptions key in the DartConfiguration.tcl" << std::endl;
  484. return -1;
  485. }
  486. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  487. if ( sourceDirectory.size() == 0 )
  488. {
  489. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  490. return -1;
  491. }
  492. std::string extra_update_opts;
  493. #ifdef HAVE_CURL
  494. if ( m_TestModel == cmCTest::NIGHTLY )
  495. {
  496. struct tm* t = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"]);
  497. char current_time[1024];
  498. strftime(current_time, 1000, "%Y-%m-%d %H:%M:%S %Z", t);
  499. std::string today_update_date = current_time;
  500. //std::string today_update_date = current_time +
  501. // m_DartConfiguration["NightlyStartTime"];
  502. extra_update_opts += "-D \"" + today_update_date +"\"";
  503. //std::cout << "Update: " << extra_update_opts << std::endl;
  504. }
  505. #endif
  506. std::string command = cvsCommand + " -z3 update " + cvsOptions +
  507. " " + extra_update_opts;
  508. std::ofstream os;
  509. if ( !this->OpenOutputFile(m_CurrentTag, "Update.xml", os) )
  510. {
  511. std::cout << "Cannot open log file" << std::endl;
  512. }
  513. std::string start_time = ::CurrentTime();
  514. std::string goutput;
  515. int retVal = 0;
  516. bool res = true;
  517. std::ofstream ofs;
  518. if ( !m_ShowOnly )
  519. {
  520. res = cmSystemTools::RunCommand(command.c_str(), goutput,
  521. retVal, sourceDirectory.c_str(),
  522. m_Verbose);
  523. if ( this->OpenOutputFile("Temporary", "LastUpdate.log", ofs) )
  524. {
  525. ofs << goutput << std::endl;;
  526. }
  527. }
  528. else
  529. {
  530. std::cout << "Update with command: " << command << std::endl;
  531. }
  532. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  533. << "<Update mode=\"Client\">\n"
  534. << "\t<Site>" <<m_DartConfiguration["Site"] << "</Site>\n"
  535. << "\t<BuildName>" << m_DartConfiguration["BuildName"]
  536. << "</BuildName>\n"
  537. << "\t<BuildStamp>" << m_CurrentTag << "-"
  538. << this->GetTestModelString() << "</BuildStamp>\n"
  539. << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  540. << "\t<UpdateCommand>" << command << "</UpdateCommand>\n"
  541. << "\t<UpdateReturnStatus>";
  542. if ( retVal )
  543. {
  544. os << goutput;
  545. }
  546. os << "</UpdateReturnStatus>" << std::endl;
  547. std::vector<cmStdString> lines;
  548. cmSystemTools::Split(goutput.c_str(), lines);
  549. std::cout << "Updated; gathering version information" << std::endl;
  550. cmsys::RegularExpression date_author("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  551. cmsys::RegularExpression revision("^revision +([^ ]*) *$");
  552. cmsys::RegularExpression end_of_file("^=============================================================================$");
  553. cmsys::RegularExpression end_of_comment("^----------------------------$");
  554. std::string current_path = "";
  555. bool first_file = true;
  556. cmCTest::AuthorsToUpdatesMap authors_files_map;
  557. int num_updated = 0;
  558. int num_modified = 0;
  559. int num_conflicting = 0;
  560. for ( cc= 0 ; cc < lines.size(); cc ++ )
  561. {
  562. const char* line = lines[cc].c_str();
  563. char mod = line[0];
  564. if ( line[1] == ' ' && mod != '?' )
  565. {
  566. count ++;
  567. const char* file = line + 2;
  568. //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl;
  569. std::string logcommand = cvsCommand + " -z3 log -N " + file;
  570. //std::cout << "Do log: " << logcommand << std::endl;
  571. std::string output;
  572. res = cmSystemTools::RunCommand(logcommand.c_str(), output,
  573. retVal, sourceDirectory.c_str(),
  574. m_Verbose);
  575. if ( ofs )
  576. {
  577. ofs << output << std::endl;
  578. }
  579. if ( res && retVal == 0)
  580. {
  581. //std::cout << output << std::endl;
  582. std::vector<cmStdString> ulines;
  583. cmSystemTools::Split(output.c_str(), ulines);
  584. std::string::size_type sline = 0;
  585. std::string srevision1 = "Unknown";
  586. std::string sdate1 = "Unknown";
  587. std::string sauthor1 = "Unknown";
  588. std::string semail1 = "Unknown";
  589. std::string comment1 = "";
  590. std::string srevision2 = "Unknown";
  591. std::string sdate2 = "Unknown";
  592. std::string sauthor2 = "Unknown";
  593. std::string comment2 = "";
  594. std::string semail2 = "Unknown";
  595. bool have_first = false;
  596. bool have_second = false;
  597. for ( kk = 0; kk < ulines.size(); kk ++ )
  598. {
  599. const char* clp = ulines[kk].c_str();
  600. if ( !have_second && !sline && revision.find(clp) )
  601. {
  602. if ( !have_first )
  603. {
  604. srevision1 = revision.match(1);
  605. }
  606. else
  607. {
  608. srevision2 = revision.match(1);
  609. }
  610. }
  611. else if ( !have_second && !sline && date_author.find(clp) )
  612. {
  613. sline = kk + 1;
  614. if ( !have_first )
  615. {
  616. sdate1 = date_author.match(1);
  617. sauthor1 = date_author.match(2);
  618. }
  619. else
  620. {
  621. sdate2 = date_author.match(1);
  622. sauthor2 = date_author.match(2);
  623. }
  624. }
  625. else if ( sline && end_of_comment.find(clp) || end_of_file.find(clp))
  626. {
  627. if ( !have_first )
  628. {
  629. have_first = true;
  630. }
  631. else if ( !have_second )
  632. {
  633. have_second = true;
  634. }
  635. sline = 0;
  636. }
  637. else if ( sline )
  638. {
  639. if ( !have_first )
  640. {
  641. comment1 += clp;
  642. comment1 += "\n";
  643. }
  644. else
  645. {
  646. comment2 += clp;
  647. comment2 += "\n";
  648. }
  649. }
  650. }
  651. if ( mod == 'M' )
  652. {
  653. comment1 = "Locally modified file\n";
  654. }
  655. std::string path = cmSystemTools::GetFilenamePath(file);
  656. std::string fname = cmSystemTools::GetFilenameName(file);
  657. if ( path != current_path )
  658. {
  659. if ( !first_file )
  660. {
  661. os << "\t</Directory>" << std::endl;
  662. }
  663. else
  664. {
  665. first_file = false;
  666. }
  667. os << "\t<Directory>\n"
  668. << "\t\t<Name>" << path << "</Name>" << std::endl;
  669. }
  670. if ( mod == 'C' )
  671. {
  672. num_conflicting ++;
  673. os << "\t<Conflicting>" << std::endl;
  674. }
  675. else if ( mod == 'M' )
  676. {
  677. num_modified ++;
  678. os << "\t<Modified>" << std::endl;
  679. }
  680. else
  681. {
  682. num_updated ++;
  683. os << "\t<Updated>" << std::endl;
  684. }
  685. if ( srevision2 == "Unknown" )
  686. {
  687. srevision2 = srevision1;
  688. }
  689. os << "\t\t<File Directory=\"" << path << "\">" << fname
  690. << "</File>\n"
  691. << "\t\t<Directory>" << path << "</Directory>\n"
  692. << "\t\t<FullName>" << file << "</FullName>\n"
  693. << "\t\t<CheckinDate>" << sdate1 << "</CheckinDate>\n"
  694. << "\t\t<Author>" << sauthor1 << "</Author>\n"
  695. << "\t\t<Email>" << semail1 << "</Email>\n"
  696. << "\t\t<Log>" << this->MakeXMLSafe(comment1) << "</Log>\n"
  697. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  698. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  699. << std::endl;
  700. if ( srevision2 != srevision1 )
  701. {
  702. os
  703. << "\t\t<Revisions>\n"
  704. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  705. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  706. << "\t\t\t<Author>" << sauthor1<< "</Author>\n"
  707. << "\t\t\t<Date>" << sdate1 << "</Date>\n"
  708. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment1) << "</Comment>\n"
  709. << "\t\t\t<Email>" << semail1 << "</Email>\n"
  710. << "\t\t</Revisions>\n"
  711. << "\t\t<Revisions>\n"
  712. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  713. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  714. << "\t\t\t<Author>" << sauthor2<< "</Author>\n"
  715. << "\t\t\t<Date>" << sdate2 << "</Date>\n"
  716. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment2) << "</Comment>\n"
  717. << "\t\t\t<Email>" << semail2 << "</Email>\n"
  718. << "\t\t</Revisions>" << std::endl;
  719. }
  720. if ( mod == 'C' )
  721. {
  722. os << "\t</Conflicting>" << std::endl;
  723. }
  724. else if ( mod == 'M' )
  725. {
  726. os << "\t</Modified>" << std::endl;
  727. }
  728. else
  729. {
  730. os << "\t</Updated>" << std::endl;
  731. }
  732. cmCTest::UpdateFiles *u = &authors_files_map[sauthor1];
  733. cmCTest::StringPair p;
  734. p.first = path;
  735. p.second = fname;
  736. u->push_back(p);
  737. current_path = path;
  738. }
  739. }
  740. }
  741. if ( num_updated )
  742. {
  743. std::cout << "Found " << num_updated << " updated files" << std::endl;
  744. }
  745. if ( num_modified )
  746. {
  747. std::cout << "Found " << num_modified << " locally modified files"
  748. << std::endl;
  749. }
  750. if ( num_conflicting )
  751. {
  752. std::cout << "Found " << num_conflicting << " conflicting files"
  753. << std::endl;
  754. }
  755. if ( !first_file )
  756. {
  757. os << "\t</Directory>" << std::endl;
  758. }
  759. cmCTest::AuthorsToUpdatesMap::iterator it;
  760. for ( it = authors_files_map.begin();
  761. it != authors_files_map.end();
  762. it ++ )
  763. {
  764. os << "\t<Author>\n"
  765. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  766. cmCTest::UpdateFiles *u = &(it->second);
  767. for ( cc = 0; cc < u->size(); cc ++ )
  768. {
  769. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  770. << (*u)[cc].second << "</File>" << std::endl;
  771. }
  772. os << "\t</Author>" << std::endl;
  773. }
  774. //std::cout << "End" << std::endl;
  775. std::string end_time = ::CurrentTime();
  776. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  777. << "</Update>" << std::endl;
  778. if ( ofs )
  779. {
  780. ofs.close();
  781. }
  782. if (! res || retVal )
  783. {
  784. std::cerr << "Error(s) when updating the project" << std::endl;
  785. std::cerr << "Output: " << goutput << std::endl;
  786. return -1;
  787. }
  788. return count;
  789. }
  790. int cmCTest::ConfigureDirectory()
  791. {
  792. std::cout << "Configure project" << std::endl;
  793. std::string cCommand = m_DartConfiguration["ConfigureCommand"];
  794. if ( cCommand.size() == 0 )
  795. {
  796. std::cerr << "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  797. << std::endl;
  798. return 1;
  799. }
  800. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  801. if ( buildDirectory.size() == 0 )
  802. {
  803. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  804. return 1;
  805. }
  806. std::string output;
  807. int retVal = 0;
  808. bool res = true;
  809. if ( !m_ShowOnly )
  810. {
  811. std::ofstream os;
  812. if ( !this->OpenOutputFile(m_CurrentTag, "Configure.xml", os) )
  813. {
  814. std::cout << "Cannot open log file" << std::endl;
  815. }
  816. std::string start_time = ::CurrentTime();
  817. res = cmSystemTools::RunCommand(cCommand.c_str(), output,
  818. retVal, buildDirectory.c_str(),
  819. m_Verbose);
  820. std::ofstream ofs;
  821. if ( this->OpenOutputFile("Temporary", "LastConfigure.log", ofs) )
  822. {
  823. ofs << output;
  824. ofs.close();
  825. }
  826. if ( os )
  827. {
  828. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  829. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  830. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  831. << this->GetTestModelString() << "\" Name=\""
  832. << m_DartConfiguration["Site"] << "\">\n"
  833. << "<Configure>\n"
  834. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  835. if ( retVal )
  836. {
  837. os << retVal;
  838. }
  839. os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>" << std::endl;
  840. //std::cout << "End" << std::endl;
  841. os << "<Log>" << this->MakeXMLSafe(output) << "</Log>" << std::endl;
  842. std::string end_time = ::CurrentTime();
  843. os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
  844. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  845. << "</Configure>\n"
  846. << "</Site>" << std::endl;
  847. }
  848. }
  849. else
  850. {
  851. std::cout << "Configure with command: " << cCommand << std::endl;
  852. }
  853. if (! res || retVal )
  854. {
  855. std::cerr << "Error(s) when updating the project" << std::endl;
  856. return 1;
  857. }
  858. return 0;
  859. }
  860. int cmCTest::BuildDirectory()
  861. {
  862. std::cout << "Build project" << std::endl;
  863. std::string makeCommand = m_DartConfiguration["MakeCommand"];
  864. if ( makeCommand.size() == 0 )
  865. {
  866. std::cerr << "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl;
  867. return 1;
  868. }
  869. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  870. if ( buildDirectory.size() == 0 )
  871. {
  872. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  873. return 1;
  874. }
  875. m_StartBuild = ::CurrentTime();
  876. std::string output;
  877. int retVal = 0;
  878. bool res = true;
  879. if ( !m_ShowOnly )
  880. {
  881. res = cmSystemTools::RunCommand(makeCommand.c_str(), output,
  882. retVal, buildDirectory.c_str(),
  883. m_Verbose);
  884. }
  885. else
  886. {
  887. std::cout << "Build with command: " << makeCommand << std::endl;
  888. }
  889. m_EndBuild = ::CurrentTime();
  890. if (! res || retVal )
  891. {
  892. std::cerr << "Error(s) when building project" << std::endl;
  893. }
  894. // Parsing of output for errors and warnings.
  895. std::vector<cmStdString> lines;
  896. cmSystemTools::Split(output.c_str(), lines);
  897. std::ofstream ofs;
  898. if ( this->OpenOutputFile("Temporary", "LastBuild.log", ofs) )
  899. {
  900. ofs << output;
  901. ofs.close();
  902. }
  903. else
  904. {
  905. std::cerr << "Cannot create LastBuild.log file" << std::endl;
  906. }
  907. // Lines are marked:
  908. // 0 - nothing
  909. // 1 - error
  910. // > 1 - warning
  911. std::vector<int> markedLines(lines.size(), 0);
  912. int cc;
  913. // Errors
  914. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  915. {
  916. cmsys::RegularExpression re(cmCTestErrorMatches[cc]);
  917. std::vector<std::string>::size_type kk;
  918. for ( kk = 0; kk < lines.size(); kk ++ )
  919. {
  920. if ( re.find(lines[kk]) )
  921. {
  922. markedLines[kk] = 1;
  923. }
  924. }
  925. }
  926. // Warnings
  927. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  928. {
  929. cmsys::RegularExpression re(cmCTestWarningMatches[cc]);
  930. std::vector<std::string>::size_type kk;
  931. for ( kk = 0; kk < lines.size(); kk ++ )
  932. {
  933. if ( re.find(lines[kk]) )
  934. {
  935. markedLines[kk] += 2;
  936. }
  937. }
  938. }
  939. // Errors exceptions
  940. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  941. {
  942. cmsys::RegularExpression re(cmCTestErrorExceptions[cc]);
  943. std::vector<int>::size_type kk;
  944. for ( kk =0; kk < markedLines.size(); kk ++ )
  945. {
  946. if ( markedLines[kk] == 1 )
  947. {
  948. if ( re.find(lines[kk]) )
  949. {
  950. markedLines[kk] = 0;
  951. }
  952. }
  953. }
  954. }
  955. // Warning exceptions
  956. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  957. {
  958. cmsys::RegularExpression re(cmCTestWarningExceptions[cc]);
  959. std::vector<int>::size_type kk;
  960. for ( kk =0; kk < markedLines.size(); kk ++ )
  961. {
  962. if ( markedLines[kk] > 1 )
  963. {
  964. if ( re.find(lines[kk]) )
  965. {
  966. markedLines[kk] = 0;
  967. }
  968. }
  969. }
  970. }
  971. std::vector<cmCTestBuildErrorWarning> errorsWarnings;
  972. std::vector<int>::size_type kk;
  973. cmCTestBuildErrorWarning errorwarning;
  974. for ( kk =0; kk < markedLines.size(); kk ++ )
  975. {
  976. errorwarning.m_LineNumber = -1;
  977. bool found = false;
  978. if ( markedLines[kk] == 1 )
  979. {
  980. std::cout << "Error: " << lines[kk] << std::endl;
  981. errorwarning.m_Error = true;
  982. found = true;
  983. }
  984. else if ( markedLines[kk] > 1 )
  985. {
  986. std::cout << "Warning: " << lines[kk] << std::endl;
  987. errorwarning.m_Error = false;
  988. found = true;
  989. }
  990. if ( found )
  991. {
  992. errorwarning.m_LogLine = static_cast<int>(kk+1);
  993. errorwarning.m_Text = lines[kk];
  994. errorwarning.m_PreContext = "";
  995. errorwarning.m_PostContext = "";
  996. std::vector<int>::size_type jj;
  997. std::vector<int>::size_type ll = 0;
  998. if ( kk > 6 )
  999. {
  1000. ll = kk - 6;
  1001. }
  1002. for ( jj = kk;
  1003. jj > 0 && jj > ll /* && markedLines[jj] == 0 */;
  1004. jj -- );
  1005. for (; jj < kk; jj ++ )
  1006. {
  1007. errorwarning.m_PreContext += lines[jj] + "\n";
  1008. }
  1009. for ( jj = kk+1;
  1010. jj < lines.size() && jj < kk + 7 /* && markedLines[jj] == 0*/;
  1011. jj ++ )
  1012. {
  1013. errorwarning.m_PostContext += lines[jj] + "\n";
  1014. }
  1015. errorsWarnings.push_back(errorwarning);
  1016. }
  1017. }
  1018. if( !this->OpenOutputFile(m_CurrentTag, "Build.xml", ofs) )
  1019. {
  1020. std::cerr << "Cannot create build XML file" << std::endl;
  1021. return 1;
  1022. }
  1023. this->GenerateDartBuildOutput(ofs, errorsWarnings);
  1024. return 0;
  1025. }
  1026. int cmCTest::CoverageDirectory()
  1027. {
  1028. std::cout << "Performing coverage" << std::endl;
  1029. std::vector<std::string> files;
  1030. std::vector<std::string> cfiles;
  1031. std::vector<std::string> cdirs;
  1032. bool done = false;
  1033. std::string::size_type cc;
  1034. std::string glob;
  1035. std::map<std::string, std::string> allsourcefiles;
  1036. std::map<std::string, std::string> allbinaryfiles;
  1037. std::string start_time = ::CurrentTime();
  1038. // Find all source files.
  1039. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  1040. if ( sourceDirectory.size() == 0 )
  1041. {
  1042. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  1043. return 1;
  1044. }
  1045. cdirs.push_back(sourceDirectory);
  1046. while ( !done )
  1047. {
  1048. if ( cdirs.size() <= 0 )
  1049. {
  1050. break;
  1051. }
  1052. glob = cdirs[cdirs.size()-1] + "/*";
  1053. //std::cout << "Glob: " << glob << std::endl;
  1054. cdirs.pop_back();
  1055. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1056. {
  1057. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1058. {
  1059. allsourcefiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1060. }
  1061. }
  1062. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1063. {
  1064. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1065. {
  1066. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1067. {
  1068. cdirs.push_back(cfiles[cc]);
  1069. }
  1070. }
  1071. }
  1072. }
  1073. // find all binary files
  1074. cdirs.push_back(cmSystemTools::GetCurrentWorkingDirectory());
  1075. while ( !done )
  1076. {
  1077. if ( cdirs.size() <= 0 )
  1078. {
  1079. break;
  1080. }
  1081. glob = cdirs[cdirs.size()-1] + "/*";
  1082. //std::cout << "Glob: " << glob << std::endl;
  1083. cdirs.pop_back();
  1084. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1085. {
  1086. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1087. {
  1088. allbinaryfiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1089. }
  1090. }
  1091. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1092. {
  1093. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1094. {
  1095. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1096. {
  1097. cdirs.push_back(cfiles[cc]);
  1098. }
  1099. }
  1100. }
  1101. }
  1102. std::map<std::string, std::string>::iterator sit;
  1103. for ( sit = allbinaryfiles.begin(); sit != allbinaryfiles.end(); sit ++ )
  1104. {
  1105. const std::string& fname = sit->second;
  1106. //std::cout << "File: " << fname << std::endl;
  1107. if ( strcmp(fname.substr(fname.size()-3, 3).c_str(), ".da") == 0 )
  1108. {
  1109. files.push_back(fname);
  1110. }
  1111. }
  1112. if ( files.size() == 0 )
  1113. {
  1114. std::cout << "Cannot find any coverage information files (.da)" << std::endl;
  1115. return 1;
  1116. }
  1117. std::ofstream log;
  1118. if (!this->OpenOutputFile("Temporary", "Coverage.log", log))
  1119. {
  1120. std::cout << "Cannot open log file" << std::endl;
  1121. return 1;
  1122. }
  1123. log.close();
  1124. if (!this->OpenOutputFile(m_CurrentTag, "Coverage.xml", log))
  1125. {
  1126. std::cout << "Cannot open log file" << std::endl;
  1127. return 1;
  1128. }
  1129. std::string opath = m_ToplevelPath + "/Testing/Temporary/Coverage";
  1130. cmSystemTools::MakeDirectory(opath.c_str());
  1131. for ( cc = 0; cc < files.size(); cc ++ )
  1132. {
  1133. std::string command = "gcov -l \"" + files[cc] + "\"";
  1134. std::string output;
  1135. int retVal = 0;
  1136. //std::cout << "Run gcov on " << files[cc] << std::flush;
  1137. //std::cout << " --- Run [" << command << "]" << std::endl;
  1138. bool res = true;
  1139. if ( !m_ShowOnly )
  1140. {
  1141. res = cmSystemTools::RunCommand(command.c_str(), output,
  1142. retVal, opath.c_str(),
  1143. m_Verbose);
  1144. }
  1145. if ( res && retVal == 0 )
  1146. {
  1147. //std::cout << " - done" << std::endl;
  1148. }
  1149. else
  1150. {
  1151. //std::cout << " - fail" << std::endl;
  1152. }
  1153. }
  1154. files.clear();
  1155. glob = opath + "/*";
  1156. if ( !cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1157. {
  1158. std::cout << "Cannot found any coverage files" << std::endl;
  1159. return 1;
  1160. }
  1161. std::map<std::string, std::vector<std::string> > sourcefiles;
  1162. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1163. {
  1164. std::string& fname = cfiles[cc];
  1165. //std::cout << "File: " << fname << std::endl;
  1166. if ( strcmp(fname.substr(fname.size()-5, 5).c_str(), ".gcov") == 0 )
  1167. {
  1168. files.push_back(fname);
  1169. std::string::size_type pos = fname.find(".da.");
  1170. if ( pos != fname.npos )
  1171. {
  1172. pos += 4;
  1173. std::string::size_type epos = fname.size() - pos - strlen(".gcov");
  1174. std::string nf = fname.substr(pos, epos);
  1175. //std::cout << "Substring: " << nf << std::endl;
  1176. if ( allsourcefiles.find(nf) != allsourcefiles.end() ||
  1177. allbinaryfiles.find(nf) != allbinaryfiles.end() )
  1178. {
  1179. std::vector<std::string> &cvec = sourcefiles[nf];
  1180. cvec.push_back(fname);
  1181. }
  1182. }
  1183. }
  1184. }
  1185. for ( cc = 0; cc < files.size(); cc ++ )
  1186. {
  1187. //std::cout << "File: " << files[cc] << std::endl;
  1188. }
  1189. std::map<std::string, std::vector<std::string> >::iterator it;
  1190. cmCTest::tm_CoverageMap coverageresults;
  1191. log << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1192. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1193. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1194. << this->GetTestModelString() << "\" Name=\""
  1195. << m_DartConfiguration["Site"] << "\">\n"
  1196. << "<Coverage>\n"
  1197. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  1198. int total_tested = 0;
  1199. int total_untested = 0;
  1200. for ( it = sourcefiles.begin(); it != sourcefiles.end(); it ++ )
  1201. {
  1202. //std::cerr << "Source file: " << it->first << std::endl;
  1203. std::vector<std::string> &gfiles = it->second;
  1204. for ( cc = 0; cc < gfiles.size(); cc ++ )
  1205. {
  1206. //std::cout << "\t" << gfiles[cc] << std::endl;
  1207. std::ifstream ifile(gfiles[cc].c_str());
  1208. if ( !ifile )
  1209. {
  1210. std::cout << "Cannot open file: " << gfiles[cc].c_str() << std::endl;
  1211. }
  1212. ifile.seekg (0, std::ios::end);
  1213. int length = ifile.tellg();
  1214. ifile.seekg (0, std::ios::beg);
  1215. char *buffer = new char [ length + 1 ];
  1216. ifile.read(buffer, length);
  1217. buffer [length] = 0;
  1218. //std::cout << "Read: " << buffer << std::endl;
  1219. std::vector<cmStdString> lines;
  1220. cmSystemTools::Split(buffer, lines);
  1221. delete [] buffer;
  1222. cmCTest::cmCTestCoverage& cov = coverageresults[it->first];
  1223. std::vector<int>& covlines = cov.m_Lines;
  1224. if ( cov.m_FullPath == "" )
  1225. {
  1226. covlines.insert(covlines.begin(), lines.size(), -1);
  1227. if ( allsourcefiles.find(it->first) != allsourcefiles.end() )
  1228. {
  1229. cov.m_FullPath = allsourcefiles[it->first];
  1230. }
  1231. else if ( allbinaryfiles.find(it->first) != allbinaryfiles.end() )
  1232. {
  1233. cov.m_FullPath = allbinaryfiles[it->first];
  1234. }
  1235. cov.m_AbsolutePath = cov.m_FullPath;
  1236. std::string src_dir = m_DartConfiguration["SourceDirectory"];
  1237. if ( src_dir[src_dir.size()-1] != '/' )
  1238. {
  1239. src_dir = src_dir + "/";
  1240. }
  1241. std::string::size_type spos = cov.m_FullPath.find(src_dir);
  1242. if ( spos == 0 )
  1243. {
  1244. cov.m_FullPath = std::string("./") + cov.m_FullPath.substr(src_dir.size());
  1245. }
  1246. else
  1247. {
  1248. //std::cerr << "Compare -- " << cov.m_FullPath << std::endl;
  1249. //std::cerr << " -- " << src_dir << std::endl;
  1250. cov.m_Show = false;
  1251. continue;
  1252. }
  1253. cov.m_Show = true;
  1254. }
  1255. for ( cc = 0; cc < lines.size(); cc ++ )
  1256. {
  1257. std::string& line = lines[cc];
  1258. std::string sub = line.substr(0, strlen(" ######"));
  1259. int count = atoi(sub.c_str());
  1260. if ( sub.compare(" ######") == 0 )
  1261. {
  1262. if ( covlines[cc] == -1 )
  1263. {
  1264. covlines[cc] = 0;
  1265. }
  1266. cov.m_UnTested ++;
  1267. //std::cout << "Untested - ";
  1268. }
  1269. else if ( count > 0 )
  1270. {
  1271. if ( covlines[cc] == -1 )
  1272. {
  1273. covlines[cc] = 0;
  1274. }
  1275. cov.m_Tested ++;
  1276. covlines[cc] += count;
  1277. //std::cout << "Tested[" << count << "] - ";
  1278. }
  1279. //std::cout << line << std::endl;
  1280. }
  1281. }
  1282. }
  1283. //std::cerr << "Finalizing" << std::endl;
  1284. cmCTest::tm_CoverageMap::iterator cit;
  1285. int ccount = 0;
  1286. std::ofstream cfileoutput;
  1287. int cfileoutputcount = 0;
  1288. char cfileoutputname[100];
  1289. std::string local_start_time = ::CurrentTime();
  1290. std::string local_end_time;
  1291. for ( cit = coverageresults.begin(); cit != coverageresults.end(); cit ++ )
  1292. {
  1293. cmCTest::cmCTestCoverage &cov = cit->second;
  1294. if ( !cov.m_Show )
  1295. {
  1296. continue;
  1297. }
  1298. if ( ccount == 100 )
  1299. {
  1300. local_end_time = ::CurrentTime();
  1301. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1302. << "</CoverageLog>\n"
  1303. << "</Site>" << std::endl;
  1304. cfileoutput.close();
  1305. std::cout << "Close file: " << cfileoutputname << std::endl;
  1306. ccount = 0;
  1307. }
  1308. if ( ccount == 0 )
  1309. {
  1310. sprintf(cfileoutputname, "CoverageLog-%d.xml", cfileoutputcount++);
  1311. std::cout << "Open file: " << cfileoutputname << std::endl;
  1312. if (!this->OpenOutputFile(m_CurrentTag, cfileoutputname, cfileoutput))
  1313. {
  1314. std::cout << "Cannot open log file: " << cfileoutputname << std::endl;
  1315. return 1;
  1316. }
  1317. local_start_time = ::CurrentTime();
  1318. cfileoutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1319. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1320. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1321. << this->GetTestModelString() << "\" Site=\""
  1322. << m_DartConfiguration["Site"] << "\">\n"
  1323. << "<CoverageLog>\n"
  1324. << "\t<StartDateTime>" << local_start_time << "</StartDateTime>" << std::endl;
  1325. }
  1326. //std::cerr << "Final process of Source file: " << cit->first << std::endl;
  1327. std::ifstream ifile(cov.m_AbsolutePath.c_str());
  1328. if ( !ifile )
  1329. {
  1330. std::cerr << "Cannot open file: " << cov.m_FullPath.c_str() << std::endl;
  1331. }
  1332. ifile.seekg (0, std::ios::end);
  1333. int length = ifile.tellg();
  1334. ifile.seekg (0, std::ios::beg);
  1335. char *buffer = new char [ length + 1 ];
  1336. ifile.read(buffer, length);
  1337. buffer [length] = 0;
  1338. //std::cout << "Read: " << buffer << std::endl;
  1339. std::vector<cmStdString> lines;
  1340. cmSystemTools::Split(buffer, lines);
  1341. delete [] buffer;
  1342. cfileoutput << "\t<File Name=\"" << cit->first << "\" FullPath=\""
  1343. << cov.m_FullPath << "\">\n"
  1344. << "\t\t<Report>" << std::endl;
  1345. for ( cc = 0; cc < lines.size(); cc ++ )
  1346. {
  1347. cfileoutput << "\t\t<Line Number=\""
  1348. << static_cast<int>(cc) << "\" Count=\""
  1349. << cov.m_Lines[cc] << "\">"
  1350. << cmCTest::MakeXMLSafe(lines[cc]) << "</Line>" << std::endl;
  1351. }
  1352. cfileoutput << "\t\t</Report>\n"
  1353. << "\t</File>" << std::endl;
  1354. total_tested += cov.m_Tested;
  1355. total_untested += cov.m_UnTested;
  1356. float cper = 0;
  1357. float cmet = 0;
  1358. if ( total_tested + total_untested > 0 && (cov.m_Tested + cov.m_UnTested) > 0)
  1359. {
  1360. cper = (100 * SAFEDIV(static_cast<float>(cov.m_Tested),
  1361. static_cast<float>(cov.m_Tested + cov.m_UnTested)));
  1362. cmet = ( SAFEDIV(static_cast<float>(cov.m_Tested + 10),
  1363. static_cast<float>(cov.m_Tested + cov.m_UnTested + 10)));
  1364. }
  1365. log << "\t<File Name=\"" << cit->first << "\" FullPath=\"" << cov.m_FullPath
  1366. << "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n"
  1367. << "\t\t<LOCTested>" << cov.m_Tested << "</LOCTested>\n"
  1368. << "\t\t<LOCUnTested>" << cov.m_UnTested << "</LOCUnTested>\n"
  1369. << "\t\t<PercentCoverage>";
  1370. log.setf(std::ios::fixed, std::ios::floatfield);
  1371. log.precision(2);
  1372. log << (cper) << "</PercentCoverage>\n"
  1373. << "\t\t<CoverageMetric>";
  1374. log.setf(std::ios::fixed, std::ios::floatfield);
  1375. log.precision(2);
  1376. log << (cmet) << "</CoverageMetric>\n"
  1377. << "\t</File>" << std::endl;
  1378. ccount ++;
  1379. }
  1380. if ( ccount > 0 )
  1381. {
  1382. local_end_time = ::CurrentTime();
  1383. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1384. << "</CoverageLog>\n"
  1385. << "</Site>" << std::endl;
  1386. cfileoutput.close();
  1387. }
  1388. int total_lines = total_tested + total_untested;
  1389. float percent_coverage = 100 * SAFEDIV(static_cast<float>(total_tested),
  1390. static_cast<float>(total_lines));
  1391. if ( total_lines == 0 )
  1392. {
  1393. percent_coverage = 0;
  1394. }
  1395. std::string end_time = ::CurrentTime();
  1396. log << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
  1397. << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
  1398. << "\t<LOC>" << total_lines << "</LOC>\n"
  1399. << "\t<PercentCoverage>";
  1400. log.setf(std::ios::fixed, std::ios::floatfield);
  1401. log.precision(2);
  1402. log << (percent_coverage)<< "</PercentCoverage>\n"
  1403. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  1404. << "</Coverage>\n"
  1405. << "</Site>" << std::endl;
  1406. std::cout << "\tCovered LOC: " << total_tested << std::endl
  1407. << "\tNot covered LOC: " << total_untested << std::endl
  1408. << "\tTotal LOC: " << total_lines << std::endl
  1409. << "\tPercentage Coverage: ";
  1410. std::cout.setf(std::ios::fixed, std::ios::floatfield);
  1411. std::cout.precision(2);
  1412. std::cout << (percent_coverage) << "%" << std::endl;
  1413. return 1;
  1414. }
  1415. bool cmCTest::OpenOutputFile(const std::string& path,
  1416. const std::string& name, std::ofstream& stream)
  1417. {
  1418. std::string testingDir = m_ToplevelPath + "/Testing";
  1419. if ( path.size() > 0 )
  1420. {
  1421. testingDir += "/" + path;
  1422. }
  1423. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  1424. {
  1425. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  1426. {
  1427. std::cerr << "File " << testingDir
  1428. << " is in the place of the testing directory"
  1429. << std::endl;
  1430. return false;
  1431. }
  1432. }
  1433. else
  1434. {
  1435. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  1436. {
  1437. std::cerr << "Cannot create directory " << testingDir
  1438. << std::endl;
  1439. return false;
  1440. }
  1441. }
  1442. std::string filename = testingDir + "/" + name;
  1443. stream.open(filename.c_str());
  1444. if( !stream )
  1445. {
  1446. std::cout << "Problem opening file: " << filename << std::endl;
  1447. return false;
  1448. }
  1449. return true;
  1450. }
  1451. void cmCTest::GenerateDartBuildOutput(std::ostream& os,
  1452. std::vector<cmCTestBuildErrorWarning> ew)
  1453. {
  1454. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1455. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1456. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1457. << this->GetTestModelString() << "\" Name=\""
  1458. << m_DartConfiguration["Site"] << "\">\n"
  1459. << "<Build>\n"
  1460. << "\t<StartDateTime>" << m_StartBuild << "</StartDateTime>\n"
  1461. << "<BuildCommand>"
  1462. << this->MakeXMLSafe(m_DartConfiguration["MakeCommand"])
  1463. << "</BuildCommand>" << std::endl;
  1464. std::vector<cmCTestBuildErrorWarning>::iterator it;
  1465. for ( it = ew.begin(); it != ew.end(); it++ )
  1466. {
  1467. cmCTestBuildErrorWarning *cm = &(*it);
  1468. os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n"
  1469. << "\t\t<BuildLogLine>" << cm->m_LogLine << "</BuildLogLine>\n"
  1470. << "\t\t<Text>" << this->MakeXMLSafe(cm->m_Text)
  1471. << "\n</Text>" << std::endl;
  1472. if ( cm->m_SourceFile.size() > 0 )
  1473. {
  1474. os << "\t\t<SourceFile>" << cm->m_SourceFile << "</SourceFile>"
  1475. << std::endl;
  1476. }
  1477. if ( cm->m_SourceFileTail.size() > 0 )
  1478. {
  1479. os << "\t\t<SourceFileTail>" << cm->m_SourceFileTail
  1480. << "</SourceFileTail>" << std::endl;
  1481. }
  1482. if ( cm->m_LineNumber >= 0 )
  1483. {
  1484. os << "\t\t<SourceLineNumber>" << cm->m_LineNumber
  1485. << "</SourceLineNumber>" << std::endl;
  1486. }
  1487. os << "\t\t<PreContext>" << this->MakeXMLSafe(cm->m_PreContext)
  1488. << "</PreContext>\n"
  1489. << "\t\t<PostContext>" << this->MakeXMLSafe(cm->m_PostContext)
  1490. << "</PostContext>\n"
  1491. << "\t\t<RepeatCount>0</RepeatCount>\n"
  1492. << "</" << (cm->m_Error ? "Error" : "Warning") << ">\n\n"
  1493. << std::endl;
  1494. }
  1495. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  1496. << "\t<EndDateTime>" << m_EndBuild << "</EndDateTime>\n"
  1497. << "</Build>\n"
  1498. << "</Site>" << std::endl;
  1499. }
  1500. void cmCTest::ProcessDirectory(std::vector<std::string> &passed,
  1501. std::vector<std::string> &failed)
  1502. {
  1503. // does the DartTestfile.txt exist ?
  1504. if(!cmSystemTools::FileExists("DartTestfile.txt"))
  1505. {
  1506. return;
  1507. }
  1508. // parse the file
  1509. std::ifstream fin("DartTestfile.txt");
  1510. if(!fin)
  1511. {
  1512. return;
  1513. }
  1514. int firstTest = 1;
  1515. long line = 0;
  1516. cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
  1517. cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
  1518. cmsys::RegularExpression dartStuff("([\t\n ]*<DartMeasurement.*/DartMeasurement[a-zA-Z]*>[\t ]*[\n]*)");
  1519. bool parseError;
  1520. while ( fin )
  1521. {
  1522. cmListFileFunction lff;
  1523. if(cmListFileCache::ParseFunction(fin, lff, "DartTestfile.txt",
  1524. parseError, line))
  1525. {
  1526. const std::string& name = lff.m_Name;
  1527. const std::vector<cmListFileArgument>& args = lff.m_Arguments;
  1528. if (name == "SUBDIRS")
  1529. {
  1530. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1531. for(std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1532. j != args.end(); ++j)
  1533. {
  1534. std::string nwd = cwd + "/";
  1535. nwd += j->Value;
  1536. if (cmSystemTools::FileIsDirectory(nwd.c_str()))
  1537. {
  1538. cmSystemTools::ChangeDirectory(nwd.c_str());
  1539. this->ProcessDirectory(passed, failed);
  1540. }
  1541. }
  1542. // return to the original directory
  1543. cmSystemTools::ChangeDirectory(cwd.c_str());
  1544. }
  1545. if (name == "ADD_TEST")
  1546. {
  1547. if (this->m_UseExcludeRegExp &&
  1548. this->m_UseExcludeRegExpFirst &&
  1549. ereg.find(args[0].Value.c_str()))
  1550. {
  1551. continue;
  1552. }
  1553. if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
  1554. {
  1555. continue;
  1556. }
  1557. if (this->m_UseExcludeRegExp &&
  1558. !this->m_UseExcludeRegExpFirst &&
  1559. ereg.find(args[0].Value.c_str()))
  1560. {
  1561. continue;
  1562. }
  1563. cmCTestTestResult cres;
  1564. if (firstTest)
  1565. {
  1566. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1567. std::cerr << "Changing directory into " << nwd.c_str() << "\n";
  1568. firstTest = 0;
  1569. }
  1570. cres.m_Name = args[0].Value;
  1571. if ( m_ShowOnly )
  1572. {
  1573. std::cout << args[0].Value << std::endl;
  1574. }
  1575. else
  1576. {
  1577. fprintf(stderr,"Testing %-30s ",args[0].Value.c_str());
  1578. fflush(stderr);
  1579. }
  1580. //std::cerr << "Testing " << args[0] << " ... ";
  1581. // find the test executable
  1582. std::string testCommand = this->FindTheExecutable(args[1].Value.c_str());
  1583. testCommand = cmSystemTools::ConvertToOutputPath(testCommand.c_str());
  1584. // continue if we did not find the executable
  1585. if (testCommand == "")
  1586. {
  1587. std::cerr << "Unable to find executable: " <<
  1588. args[1].Value.c_str() << "\n";
  1589. continue;
  1590. }
  1591. // add the arguments
  1592. std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1593. ++j;
  1594. ++j;
  1595. for(;j != args.end(); ++j)
  1596. {
  1597. testCommand += " ";
  1598. testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
  1599. }
  1600. /**
  1601. * Run an executable command and put the stdout in output.
  1602. */
  1603. std::string output;
  1604. int retVal = 0;
  1605. double clock_start, clock_finish;
  1606. clock_start = cmSystemTools::GetTime();
  1607. if ( m_Verbose )
  1608. {
  1609. std::cout << std::endl << "Test command: " << testCommand << std::endl;
  1610. }
  1611. bool res = true;
  1612. if ( !m_ShowOnly )
  1613. {
  1614. res = cmSystemTools::RunCommand(testCommand.c_str(), output,
  1615. retVal, 0, false);
  1616. }
  1617. clock_finish = cmSystemTools::GetTime();
  1618. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  1619. cres.m_FullCommandLine = testCommand;
  1620. if ( !m_ShowOnly )
  1621. {
  1622. if (!res || retVal != 0)
  1623. {
  1624. fprintf(stderr,"***Failed\n");
  1625. if (output != "")
  1626. {
  1627. if (dartStuff.find(output.c_str()))
  1628. {
  1629. cmSystemTools::ReplaceString(output,
  1630. dartStuff.match(1).c_str(),"");
  1631. }
  1632. if (output != "" && m_Verbose)
  1633. {
  1634. std::cerr << output.c_str() << "\n";
  1635. }
  1636. }
  1637. failed.push_back(args[0].Value);
  1638. }
  1639. else
  1640. {
  1641. fprintf(stderr," Passed\n");
  1642. if (output != "")
  1643. {
  1644. if (dartStuff.find(output.c_str()))
  1645. {
  1646. cmSystemTools::ReplaceString(output,
  1647. dartStuff.match(1).c_str(),"");
  1648. }
  1649. if (output != "" && m_Verbose)
  1650. {
  1651. std::cerr << output.c_str() << "\n";
  1652. }
  1653. }
  1654. passed.push_back(args[0].Value);
  1655. }
  1656. }
  1657. cres.m_Output = output;
  1658. cres.m_ReturnValue = retVal;
  1659. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1660. if ( nwd.size() > m_ToplevelPath.size() )
  1661. {
  1662. nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
  1663. }
  1664. cmSystemTools::ReplaceString(nwd, "\\", "/");
  1665. cres.m_Path = nwd;
  1666. cres.m_CompletionStatus = "Completed";
  1667. m_TestResults.push_back( cres );
  1668. }
  1669. }
  1670. }
  1671. }
  1672. int cmCTest::TestDirectory()
  1673. {
  1674. std::cout << "Test project" << std::endl;
  1675. std::vector<std::string> passed;
  1676. std::vector<std::string> failed;
  1677. int total;
  1678. m_StartTest = ::CurrentTime();
  1679. this->ProcessDirectory(passed, failed);
  1680. m_EndTest = ::CurrentTime();
  1681. total = int(passed.size()) + int(failed.size());
  1682. if (total == 0)
  1683. {
  1684. if ( !m_ShowOnly )
  1685. {
  1686. std::cerr << "No tests were found!!!\n";
  1687. }
  1688. }
  1689. else
  1690. {
  1691. if (passed.size() && (m_UseIncludeRegExp || m_UseExcludeRegExp))
  1692. {
  1693. std::cerr << "\nThe following tests passed:\n";
  1694. for(std::vector<std::string>::iterator j = passed.begin();
  1695. j != passed.end(); ++j)
  1696. {
  1697. std::cerr << "\t" << *j << "\n";
  1698. }
  1699. }
  1700. float percent = float(passed.size()) * 100.0f / total;
  1701. fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  1702. percent, int(failed.size()), total);
  1703. if (failed.size())
  1704. {
  1705. std::cerr << "\nThe following tests FAILED:\n";
  1706. for(std::vector<std::string>::iterator j = failed.begin();
  1707. j != failed.end(); ++j)
  1708. {
  1709. std::cerr << "\t" << *j << "\n";
  1710. }
  1711. }
  1712. }
  1713. if ( m_DartMode )
  1714. {
  1715. std::ofstream ofs;
  1716. if( !this->OpenOutputFile(m_CurrentTag, "Test.xml", ofs) )
  1717. {
  1718. std::cerr << "Cannot create testing XML file" << std::endl;
  1719. return 1;
  1720. }
  1721. this->GenerateDartOutput(ofs);
  1722. }
  1723. return int(failed.size());
  1724. }
  1725. int cmCTest::SubmitResults()
  1726. {
  1727. #ifdef HAVE_CURL
  1728. std::vector<std::string> files;
  1729. std::string prefix = this->GetSubmitResultsPrefix();
  1730. // TODO:
  1731. // Check if test is enabled
  1732. if ( this->CTestFileExists("Update.xml") )
  1733. {
  1734. files.push_back("Update.xml");
  1735. }
  1736. if ( this->CTestFileExists("Configure.xml") )
  1737. {
  1738. files.push_back("Configure.xml");
  1739. }
  1740. if ( this->CTestFileExists("Build.xml") )
  1741. {
  1742. files.push_back("Build.xml");
  1743. }
  1744. if ( this->CTestFileExists("Test.xml") )
  1745. {
  1746. files.push_back("Test.xml");
  1747. }
  1748. if ( this->CTestFileExists("Coverage.xml") )
  1749. {
  1750. files.push_back("Coverage.xml");
  1751. std::vector<std::string> gfiles;
  1752. std::string gpath = m_ToplevelPath + "/Testing/" + m_CurrentTag;
  1753. std::string::size_type glen = gpath.size() + 1;
  1754. gpath = gpath + "/CoverageLog*";
  1755. //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
  1756. if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
  1757. {
  1758. size_t cc;
  1759. for ( cc = 0; cc < gfiles.size(); cc ++ )
  1760. {
  1761. gfiles[cc] = gfiles[cc].substr(glen);
  1762. //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
  1763. files.push_back(gfiles[cc]);
  1764. }
  1765. }
  1766. else
  1767. {
  1768. std::cout << "Problem globbing" << std::endl;
  1769. }
  1770. }
  1771. if ( this->CTestFileExists("Purify.xml") )
  1772. {
  1773. files.push_back("Purify.xml");
  1774. }
  1775. cmCTestSubmit submit;
  1776. submit.SetVerbose(m_Verbose);
  1777. if ( m_DartConfiguration["DropMethod"] == "" ||
  1778. m_DartConfiguration["DropMethod"] == "ftp" )
  1779. {
  1780. std::cout << "FTP submit method" << std::endl;
  1781. std::string url = "ftp://";
  1782. url += cmCTest::MakeURLSafe(m_DartConfiguration["DropSiteUser"]) + ":" +
  1783. cmCTest::MakeURLSafe(m_DartConfiguration["DropSitePassword"]) + "@" +
  1784. m_DartConfiguration["DropSite"] +
  1785. cmCTest::MakeURLSafe(m_DartConfiguration["DropLocation"]);
  1786. if ( !submit.SubmitUsingFTP(m_ToplevelPath+"/Testing/"+m_CurrentTag,
  1787. files, prefix, url) )
  1788. {
  1789. return 0;
  1790. }
  1791. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  1792. {
  1793. return 0;
  1794. }
  1795. return 1;
  1796. }
  1797. else if ( m_DartConfiguration["DropMethod"] == "http" )
  1798. {
  1799. std::cout << "HTTP submit method" << std::endl;
  1800. std::string url = "http://";
  1801. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  1802. {
  1803. url += m_DartConfiguration["DropSiteUser"];
  1804. if ( m_DartConfiguration["DropSitePassword"].size() > 0 )
  1805. {
  1806. url += ":" + m_DartConfiguration["DropSitePassword"];
  1807. }
  1808. url += "@";
  1809. }
  1810. url += m_DartConfiguration["DropSite"] + m_DartConfiguration["DropLocation"];
  1811. if ( !submit.SubmitUsingHTTP(m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  1812. {
  1813. return 0;
  1814. }
  1815. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  1816. {
  1817. return 0;
  1818. }
  1819. std::cout << "Submission successfull" << std::endl;
  1820. return 1;
  1821. }
  1822. else
  1823. {
  1824. std::cout << "SCP submit not yet implemented" << std::endl;
  1825. }
  1826. #endif
  1827. return 0;
  1828. }
  1829. bool cmCTest::CTestFileExists(const std::string& filename)
  1830. {
  1831. std::string testingDir = m_ToplevelPath + "/Testing/" + m_CurrentTag + "/" +
  1832. filename;
  1833. return cmSystemTools::FileExists(testingDir.c_str());
  1834. }
  1835. std::string cmCTest::GetSubmitResultsPrefix()
  1836. {
  1837. std::string name = m_DartConfiguration["Site"] +
  1838. "___" + m_DartConfiguration["BuildName"] +
  1839. "___" + m_CurrentTag + "-" +
  1840. this->GetTestModelString() + "___XML___";
  1841. return name;
  1842. }
  1843. void cmCTest::GenerateDartOutput(std::ostream& os)
  1844. {
  1845. if ( !m_DartMode )
  1846. {
  1847. return;
  1848. }
  1849. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1850. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1851. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1852. << this->GetTestModelString() << "\" Name=\""
  1853. << m_DartConfiguration["Site"] << "\">\n"
  1854. << "<Testing>\n"
  1855. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  1856. << "\t<TestList>\n";
  1857. tm_TestResultsVector::size_type cc;
  1858. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  1859. {
  1860. cmCTestTestResult *result = &m_TestResults[cc];
  1861. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  1862. << "/" << this->MakeXMLSafe(result->m_Name)
  1863. << "</Test>" << std::endl;
  1864. }
  1865. os << "\t</TestList>\n";
  1866. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  1867. {
  1868. cmCTestTestResult *result = &m_TestResults[cc];
  1869. os << "\t<Test Status=\"" << (result->m_ReturnValue?"failed":"passed")
  1870. << "\">\n"
  1871. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  1872. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  1873. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  1874. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  1875. << "\t\t<FullCommandLine>"
  1876. << this->MakeXMLSafe(result->m_FullCommandLine)
  1877. << "</FullCommandLine>\n"
  1878. << "\t\t<Results>" << std::endl;
  1879. if ( result->m_ReturnValue )
  1880. {
  1881. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  1882. << "CHILDSTATUS" << "</Value></NamedMeasurement>\n"
  1883. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  1884. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  1885. }
  1886. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  1887. << "name=\"Execution Time\"><Value>"
  1888. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n"
  1889. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1890. << "name=\"Completion Status\"><Value>"
  1891. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n"
  1892. << "\t\t\t<Measurement>\n"
  1893. << "\t\t\t\t<Value>" << this->MakeXMLSafe(result->m_Output)
  1894. << "</Value>\n"
  1895. << "\t\t\t</Measurement>\n"
  1896. << "\t\t</Results>\n"
  1897. << "\t</Test>" << std::endl;
  1898. }
  1899. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  1900. << "</Testing>\n"
  1901. << "</Site>" << std::endl;
  1902. }
  1903. int cmCTest::ProcessTests()
  1904. {
  1905. int res = 0;
  1906. bool notest = true;
  1907. int cc;
  1908. int update_count = 0;
  1909. for ( cc = 0; cc < LAST_TEST; cc ++ )
  1910. {
  1911. if ( m_Tests[cc] )
  1912. {
  1913. notest = false;
  1914. break;
  1915. }
  1916. }
  1917. if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
  1918. {
  1919. update_count = this->UpdateDirectory();
  1920. if ( update_count < 0 )
  1921. {
  1922. res += 1;
  1923. }
  1924. }
  1925. if ( m_TestModel == cmCTest::CONTINUOUS && !update_count )
  1926. {
  1927. return 0;
  1928. }
  1929. if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
  1930. {
  1931. res += this->ConfigureDirectory();
  1932. }
  1933. if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
  1934. {
  1935. res += this->BuildDirectory();
  1936. }
  1937. if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
  1938. {
  1939. res += this->TestDirectory();
  1940. }
  1941. if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
  1942. {
  1943. this->CoverageDirectory();
  1944. }
  1945. if ( m_Tests[PURIFY_TEST] || m_Tests[ALL_TEST] )
  1946. {
  1947. std::cerr << "Purify test is not yet implemented" << std::endl;
  1948. }
  1949. if ( m_Tests[SUBMIT_TEST] || m_Tests[ALL_TEST] )
  1950. {
  1951. #ifdef HAVE_CURL
  1952. this->SubmitResults();
  1953. #else
  1954. std::cerr << "Submit test is not yet implemented" << std::endl;
  1955. #endif
  1956. }
  1957. return res;
  1958. }
  1959. std::string cmCTest::GetTestModelString()
  1960. {
  1961. switch ( m_TestModel )
  1962. {
  1963. case cmCTest::NIGHTLY:
  1964. return "Nightly";
  1965. case cmCTest::CONTINUOUS:
  1966. return "Continuous";
  1967. }
  1968. return "Experimental";
  1969. }