cmCTest.cxx 61 KB

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