1
0

cmCTest.cxx 61 KB

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