cmCTest.cxx 61 KB

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