cmCTest.cxx 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  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. #include <stdio.h>
  18. #include <time.h>
  19. static std::string CleanString(std::string str)
  20. {
  21. std::string::size_type spos = str.find_first_not_of(" \n\t");
  22. std::string::size_type epos = str.find_last_not_of(" \n\t");
  23. if ( spos == str.npos )
  24. {
  25. return std::string();
  26. }
  27. if ( epos != str.npos )
  28. {
  29. epos = epos - spos + 1;
  30. }
  31. return str.substr(spos, epos);
  32. }
  33. static std::string CurrentTime()
  34. {
  35. time_t currenttime = time(0);
  36. return ::CleanString(ctime(&currenttime));
  37. }
  38. static const char* cmCTestErrorMatches[] = {
  39. "^[Bb]us [Ee]rror",
  40. "^[Ss]egmentation [Vv]iolation",
  41. "^[Ss]egmentation [Ff]ault",
  42. "([^ :]+):([0-9]+): ([^ \\t])",
  43. "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
  44. "^Error ([0-9]+):",
  45. "^Error ",
  46. "^\"[^\"]+\", line [0-9]+: [^Ww]",
  47. "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
  48. "^ld([^:])*:([ \\t])*ERROR([^:])*:",
  49. "^ild:([ \\t])*\\(undefined symbol\\)",
  50. "([^ :]+) : (error|fatal error|catastrophic error)",
  51. "([^:]+): (Error:|error|undefined reference|multiply defined)",
  52. "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
  53. "^fatal error C[0-9]+:",
  54. ": syntax error ",
  55. "^collect2: ld returned 1 exit status",
  56. "Unsatisfied symbols:",
  57. "Undefined symbols:",
  58. "^Undefined[ \\t]+first referenced",
  59. "^CMake Error:",
  60. ":[ \\t]cannot find",
  61. 0
  62. };
  63. static const char* cmCTestErrorExceptions[] = {
  64. 0
  65. };
  66. static const char* cmCTestWarningMatches[] = {
  67. "([^ :]+):([0-9]+): warning:",
  68. "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
  69. "^ld([^:])*:([ \\t])*WARNING([^:])*:",
  70. "([^:]+): warning ([0-9]+):",
  71. "^\"[^\"]+\", line [0-9]+: [Ww]arning",
  72. "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
  73. "^Warning ([0-9]+):",
  74. "^Warning ",
  75. "([^ :]+) : warning",
  76. "([^:]+): warning",
  77. 0
  78. };
  79. static const char* cmCTestWarningExceptions[] = {
  80. "/usr/openwin/include/X11/Xlib\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  81. "/usr/openwin/include/X11/Xutil\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  82. "/usr/openwin/include/X11/XResource\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  83. "WARNING 84 :",
  84. "WARNING 47 :",
  85. "makefile:",
  86. "Makefile:",
  87. "warning: Clock skew detected. Your build may be incomplete.",
  88. "/usr/openwin/include/GL/[^:]+:",
  89. "bind_at_load",
  90. "XrmQGetResource",
  91. "IceFlush",
  92. "warning LNK4089: all references to .GDI32.dll. discarded by .OPT:REF",
  93. "warning LNK4089: all references to .USER32.dll. discarded by .OPT:REF",
  94. "ld32: WARNING 85: definition of dataKey in",
  95. 0
  96. };
  97. std::string cmCTest::MakeXMLSafe(const std::string& str)
  98. {
  99. std::string::size_type pos = 0;
  100. cmOStringStream ost;
  101. char buffer[10];
  102. for ( pos = 0; pos < str.size(); pos ++ )
  103. {
  104. char ch = str[pos];
  105. if ( ch > 126 )
  106. {
  107. sprintf(buffer, "&%x", (int)ch);
  108. ost << buffer;
  109. }
  110. else
  111. {
  112. switch ( ch )
  113. {
  114. case '&': ost << "&amp;"; break;
  115. case '<': ost << "&lt;"; break;
  116. case '>': ost << "&gt;"; break;
  117. default: ost << ch;
  118. }
  119. }
  120. }
  121. return ost.str();
  122. }
  123. bool TryExecutable(const char *dir, const char *file,
  124. std::string *fullPath, const char *subdir)
  125. {
  126. // try current directory
  127. std::string tryPath;
  128. if (dir && strcmp(dir,""))
  129. {
  130. tryPath = dir;
  131. tryPath += "/";
  132. }
  133. if (subdir && strcmp(subdir,""))
  134. {
  135. tryPath += subdir;
  136. tryPath += "/";
  137. }
  138. tryPath += file;
  139. if(cmSystemTools::FileExists(tryPath.c_str()))
  140. {
  141. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  142. return true;
  143. }
  144. tryPath += cmSystemTools::GetExecutableExtension();
  145. if(cmSystemTools::FileExists(tryPath.c_str()))
  146. {
  147. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  148. return true;
  149. }
  150. return false;
  151. }
  152. cmCTest::cmCTest()
  153. {
  154. m_UseIncludeRegExp = false;
  155. m_UseExcludeRegExp = false;
  156. m_UseExcludeRegExpFirst = false;
  157. m_Verbose = false;
  158. m_DartMode = false;
  159. m_ShowOnly = false;
  160. int cc;
  161. for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
  162. {
  163. m_Tests[cc] = 0;
  164. }
  165. }
  166. void cmCTest::Initialize()
  167. {
  168. m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
  169. // parse the dart test file
  170. std::ifstream fin("DartConfiguration.tcl");
  171. if(!fin)
  172. {
  173. return;
  174. }
  175. char buffer[1024];
  176. while ( fin )
  177. {
  178. buffer[0] = 0;
  179. fin.getline(buffer, 1023);
  180. buffer[1023] = 0;
  181. std::string line = ::CleanString(buffer);
  182. if(line.size() == 0)
  183. {
  184. continue;
  185. }
  186. while ( fin && (line[line.size()-1] == '\\') )
  187. {
  188. line = line.substr(0, line.size()-1);
  189. buffer[0] = 0;
  190. fin.getline(buffer, 1023);
  191. buffer[1023] = 0;
  192. line += ::CleanString(buffer);
  193. }
  194. if ( line[0] == '#' )
  195. {
  196. continue;
  197. }
  198. std::string::size_type cpos = line.find_first_of(":");
  199. if ( cpos == line.npos )
  200. {
  201. continue;
  202. }
  203. std::string key = line.substr(0, cpos);
  204. std::string value = ::CleanString(line.substr(cpos+1, line.npos));
  205. m_DartConfiguration[key] = value;
  206. }
  207. fin.close();
  208. if ( m_DartMode )
  209. {
  210. std::string testingDir = m_ToplevelPath + "/Testing/CDart";
  211. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  212. {
  213. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  214. {
  215. std::cerr << "File " << testingDir << " is in the place of the testing directory"
  216. << std::endl;
  217. return;
  218. }
  219. }
  220. else
  221. {
  222. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  223. {
  224. std::cerr << "Cannot create directory " << testingDir
  225. << std::endl;
  226. return;
  227. }
  228. }
  229. std::string tagfile = testingDir + "/TAG";
  230. std::ifstream tfin(tagfile.c_str());
  231. std::string tag;
  232. time_t tctime = time(0);
  233. struct tm *lctime = gmtime(&tctime);
  234. if ( tfin )
  235. {
  236. tfin >> tag;
  237. tfin.close();
  238. int year = 0;
  239. int mon = 0;
  240. int day = 0;
  241. int hour = 0;
  242. int min = 0;
  243. sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
  244. &year, &mon, &day, &hour, &min);
  245. if ( year != lctime->tm_year + 1900 ||
  246. mon != lctime->tm_mon ||
  247. day != lctime->tm_mday )
  248. {
  249. tag = "";
  250. }
  251. }
  252. if ( tag.size() == 0 )
  253. {
  254. char datestring[100];
  255. sprintf(datestring, "%04d%02d%02d-%02d%02d",
  256. lctime->tm_year + 1900,
  257. lctime->tm_mon,
  258. lctime->tm_mday,
  259. lctime->tm_hour,
  260. lctime->tm_min);
  261. tag = datestring;
  262. std::ofstream ofs(tagfile.c_str());
  263. if ( ofs )
  264. {
  265. ofs << tag << std::endl;
  266. }
  267. ofs.close();
  268. std::cout << "Create new tag: " << tag << std::endl;
  269. }
  270. m_CurrentTag = tag;
  271. }
  272. }
  273. bool cmCTest::SetTest(const char* ttype)
  274. {
  275. if ( cmSystemTools::LowerCase(ttype) == "all" )
  276. {
  277. m_Tests[cmCTest::ALL_TEST] = 1;
  278. }
  279. else if ( cmSystemTools::LowerCase(ttype) == "update" )
  280. {
  281. m_Tests[cmCTest::UPDATE_TEST] = 1;
  282. }
  283. else if ( cmSystemTools::LowerCase(ttype) == "configure" )
  284. {
  285. m_Tests[cmCTest::CONFIGURE_TEST] = 1;
  286. }
  287. else if ( cmSystemTools::LowerCase(ttype) == "build" )
  288. {
  289. m_Tests[cmCTest::BUILD_TEST] = 1;
  290. }
  291. else if ( cmSystemTools::LowerCase(ttype) == "test" )
  292. {
  293. m_Tests[cmCTest::TEST_TEST] = 1;
  294. }
  295. else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
  296. {
  297. m_Tests[cmCTest::COVERAGE_TEST] = 1;
  298. }
  299. else if ( cmSystemTools::LowerCase(ttype) == "purify" )
  300. {
  301. m_Tests[cmCTest::PURIFY_TEST] = 1;
  302. }
  303. else
  304. {
  305. std::cerr << "Don't know about test \"" << ttype << "\" yet..." << std::endl;
  306. return false;
  307. }
  308. return true;
  309. }
  310. void cmCTest::Finalize()
  311. {
  312. }
  313. std::string cmCTest::FindExecutable(const char *exe)
  314. {
  315. std::string fullPath = "";
  316. std::string dir;
  317. std::string file;
  318. cmSystemTools::SplitProgramPath(exe, dir, file);
  319. if(m_ConfigType != "")
  320. {
  321. if(TryExecutable(dir.c_str(), file.c_str(), &fullPath,
  322. m_ConfigType.c_str()))
  323. {
  324. return fullPath;
  325. }
  326. dir += "/";
  327. dir += m_ConfigType;
  328. dir += "/";
  329. dir += file;
  330. cmSystemTools::Error("config type specified on the command line, but test executable not found.",
  331. dir.c_str());
  332. return "";
  333. }
  334. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
  335. {
  336. return fullPath;
  337. }
  338. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
  339. {
  340. return fullPath;
  341. }
  342. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
  343. {
  344. return fullPath;
  345. }
  346. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
  347. {
  348. return fullPath;
  349. }
  350. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
  351. {
  352. return fullPath;
  353. }
  354. if (TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
  355. {
  356. return fullPath;
  357. }
  358. // if everything else failed, check the users path
  359. if (dir != "")
  360. {
  361. std::string path = cmSystemTools::FindProgram(file.c_str());
  362. if (path != "")
  363. {
  364. return path;
  365. }
  366. }
  367. return fullPath;
  368. }
  369. int cmCTest::UpdateDirectory()
  370. {
  371. std::string cvsCommand = m_DartConfiguration["CVSCommand"];
  372. if ( cvsCommand.size() == 0 )
  373. {
  374. std::cerr << "Cannot find CVSCommand key in the DartConfiguration.tcl" << std::endl;
  375. return 1;
  376. }
  377. std::string cvsOptions = m_DartConfiguration["CVSUpdateOptions"];
  378. if ( cvsOptions.size() == 0 )
  379. {
  380. std::cerr << "Cannot find CVSUpdateOptions key in the DartConfiguration.tcl" << std::endl;
  381. return 1;
  382. }
  383. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  384. if ( sourceDirectory.size() == 0 )
  385. {
  386. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  387. return 1;
  388. }
  389. std::string command = cvsCommand + " update " + cvsOptions;
  390. std::string output;
  391. int retVal = 0;
  392. bool res = true;
  393. if ( !m_ShowOnly )
  394. {
  395. res = cmSystemTools::RunCommand(command.c_str(), output,
  396. retVal, sourceDirectory.c_str(),
  397. m_Verbose);
  398. }
  399. else
  400. {
  401. std::cout << "Update with command: " << command << std::endl;
  402. }
  403. if (! res || retVal )
  404. {
  405. std::cerr << "Error(s) when updating the project" << std::endl;
  406. return 1;
  407. }
  408. return 0;
  409. }
  410. int cmCTest::ConfigureDirectory()
  411. {
  412. std::string cCommand = m_DartConfiguration["ConfigureCommand"];
  413. if ( cCommand.size() == 0 )
  414. {
  415. std::cerr << "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  416. << std::endl;
  417. return 1;
  418. }
  419. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  420. if ( buildDirectory.size() == 0 )
  421. {
  422. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  423. return 1;
  424. }
  425. std::string output;
  426. int retVal = 0;
  427. bool res = true;
  428. if ( !m_ShowOnly )
  429. {
  430. res = cmSystemTools::RunCommand(cCommand.c_str(), output,
  431. retVal, buildDirectory.c_str(),
  432. m_Verbose);
  433. }
  434. else
  435. {
  436. std::cout << "Configure with command: " << cCommand << std::endl;
  437. }
  438. if (! res || retVal )
  439. {
  440. std::cerr << "Error(s) when updating the project" << std::endl;
  441. return 1;
  442. }
  443. return 0;
  444. }
  445. int cmCTest::BuildDirectory()
  446. {
  447. std::string makeCommand = m_DartConfiguration["MakeCommand"];
  448. if ( makeCommand.size() == 0 )
  449. {
  450. std::cerr << "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl;
  451. return 1;
  452. }
  453. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  454. if ( buildDirectory.size() == 0 )
  455. {
  456. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  457. return 1;
  458. }
  459. m_StartBuild = ::CurrentTime();
  460. std::string output;
  461. int retVal = 0;
  462. bool res = true;
  463. if ( !m_ShowOnly )
  464. {
  465. res = cmSystemTools::RunCommand(makeCommand.c_str(), output,
  466. retVal, buildDirectory.c_str(),
  467. m_Verbose);
  468. }
  469. else
  470. {
  471. std::cout << "Build with command: " << makeCommand << std::endl;
  472. }
  473. m_EndBuild = ::CurrentTime();
  474. if (! res || retVal )
  475. {
  476. std::cerr << "Error(s) when building project" << std::endl;
  477. }
  478. // Parsing of output for errors and warnings.
  479. std::vector<cmStdString> lines;
  480. cmSystemTools::Split(output.c_str(), lines);
  481. std::ofstream ofs;
  482. if ( this->OpenOutputFile("Temporary", "LastBuild.log", ofs) )
  483. {
  484. ofs << output;
  485. ofs.close();
  486. }
  487. else
  488. {
  489. std::cerr << "Cannot create LastBuild.log file" << std::endl;
  490. }
  491. // Lines are marked:
  492. // 0 - nothing
  493. // 1 - error
  494. // > 1 - warning
  495. std::vector<int> markedLines(lines.size(), 0);
  496. int cc;
  497. // Errors
  498. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  499. {
  500. cmRegularExpression re(cmCTestErrorMatches[cc]);
  501. std::vector<std::string>::size_type kk;
  502. for ( kk = 0; kk < lines.size(); kk ++ )
  503. {
  504. if ( re.find(lines[kk]) )
  505. {
  506. markedLines[kk] = 1;
  507. }
  508. }
  509. }
  510. // Warnings
  511. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  512. {
  513. cmRegularExpression re(cmCTestWarningMatches[cc]);
  514. std::vector<std::string>::size_type kk;
  515. for ( kk = 0; kk < lines.size(); kk ++ )
  516. {
  517. if ( re.find(lines[kk]) )
  518. {
  519. markedLines[kk] += 2;
  520. }
  521. }
  522. }
  523. // Errors exceptions
  524. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  525. {
  526. cmRegularExpression re(cmCTestErrorExceptions[cc]);
  527. std::vector<int>::size_type kk;
  528. for ( kk =0; kk < markedLines.size(); kk ++ )
  529. {
  530. if ( markedLines[cc] == 1 )
  531. {
  532. if ( re.find(lines[kk]) )
  533. {
  534. markedLines[cc] = 0;
  535. }
  536. }
  537. }
  538. }
  539. // Warning exceptions
  540. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  541. {
  542. cmRegularExpression re(cmCTestWarningExceptions[cc]);
  543. std::vector<int>::size_type kk;
  544. for ( kk =0; kk < markedLines.size(); kk ++ )
  545. {
  546. if ( markedLines[cc] > 1 )
  547. {
  548. if ( re.find(lines[kk]) )
  549. {
  550. markedLines[cc] = 0;
  551. }
  552. }
  553. }
  554. }
  555. std::vector<cmCTestBuildErrorWarning> errorsWarnings;
  556. std::vector<int>::size_type kk;
  557. cmCTestBuildErrorWarning errorwarning;
  558. for ( kk =0; kk < markedLines.size(); kk ++ )
  559. {
  560. errorwarning.m_LineNumber = -1;
  561. bool found = false;
  562. if ( markedLines[kk] == 1 )
  563. {
  564. std::cout << "Error: " << lines[kk] << std::endl;
  565. errorwarning.m_Error = true;
  566. found = true;
  567. }
  568. else if ( markedLines[kk] > 1 )
  569. {
  570. std::cout << "Warning: " << lines[kk] << std::endl;
  571. errorwarning.m_Error = false;
  572. found = true;
  573. }
  574. if ( found )
  575. {
  576. errorwarning.m_LogLine = static_cast<int>(kk+1);
  577. errorwarning.m_Text = lines[kk];
  578. errorwarning.m_PreContext = "";
  579. errorwarning.m_PostContext = "";
  580. std::vector<int>::size_type jj;
  581. std::vector<int>::size_type ll = 0;
  582. if ( kk > 6 )
  583. {
  584. ll = kk - 6;
  585. }
  586. for ( jj = kk;
  587. jj > 0 && jj > ll /* && markedLines[jj] == 0 */;
  588. jj -- );
  589. for (; jj < kk; jj ++ )
  590. {
  591. errorwarning.m_PreContext += lines[jj] + "\n";
  592. }
  593. for ( jj = kk+1;
  594. jj < lines.size() && jj < kk + 7 /* && markedLines[jj] == 0*/;
  595. jj ++ )
  596. {
  597. errorwarning.m_PostContext += lines[jj] + "\n";
  598. }
  599. errorsWarnings.push_back(errorwarning);
  600. }
  601. }
  602. if( !this->OpenOutputFile("", "Build.xml", ofs) )
  603. {
  604. std::cerr << "Cannot create build XML file" << std::endl;
  605. return 1;
  606. }
  607. this->GenerateDartBuildOutput(ofs, errorsWarnings);
  608. return 0;
  609. }
  610. int cmCTest::CoverageDirectory()
  611. {
  612. std::vector<std::string> files;
  613. std::vector<std::string> cfiles;
  614. std::vector<std::string> cdirs;
  615. bool done = false;
  616. std::string::size_type cc;
  617. std::string glob;
  618. std::map<std::string, std::string> allsourcefiles;
  619. std::map<std::string, std::string> allbinaryfiles;
  620. std::string start_time = ::CurrentTime();
  621. // Find all source files.
  622. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  623. if ( sourceDirectory.size() == 0 )
  624. {
  625. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  626. return 1;
  627. }
  628. cdirs.push_back(sourceDirectory);
  629. while ( !done )
  630. {
  631. if ( cdirs.size() <= 0 )
  632. {
  633. break;
  634. }
  635. glob = cdirs[cdirs.size()-1] + "/*";
  636. //std::cout << "Glob: " << glob << std::endl;
  637. cdirs.pop_back();
  638. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  639. {
  640. for ( cc = 0; cc < cfiles.size(); cc ++ )
  641. {
  642. allsourcefiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  643. }
  644. }
  645. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  646. {
  647. for ( cc = 0; cc < cfiles.size(); cc ++ )
  648. {
  649. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  650. {
  651. cdirs.push_back(cfiles[cc]);
  652. }
  653. }
  654. }
  655. }
  656. // find all binary files
  657. cdirs.push_back(cmSystemTools::GetCurrentWorkingDirectory());
  658. while ( !done )
  659. {
  660. if ( cdirs.size() <= 0 )
  661. {
  662. break;
  663. }
  664. glob = cdirs[cdirs.size()-1] + "/*";
  665. //std::cout << "Glob: " << glob << std::endl;
  666. cdirs.pop_back();
  667. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  668. {
  669. for ( cc = 0; cc < cfiles.size(); cc ++ )
  670. {
  671. allbinaryfiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  672. }
  673. }
  674. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  675. {
  676. for ( cc = 0; cc < cfiles.size(); cc ++ )
  677. {
  678. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  679. {
  680. cdirs.push_back(cfiles[cc]);
  681. }
  682. }
  683. }
  684. }
  685. std::map<std::string, std::string>::iterator sit;
  686. for ( sit = allbinaryfiles.begin(); sit != allbinaryfiles.end(); sit ++ )
  687. {
  688. const std::string& fname = sit->second;
  689. //std::cout << "File: " << fname << std::endl;
  690. if ( strcmp(fname.substr(fname.size()-3, 3).c_str(), ".da") == 0 )
  691. {
  692. files.push_back(fname);
  693. }
  694. }
  695. if ( files.size() == 0 )
  696. {
  697. std::cout << "Cannot find any coverage information files (.da)" << std::endl;
  698. return 1;
  699. }
  700. std::ofstream log;
  701. if (!this->OpenOutputFile("Coverage", "Coverage.log", log))
  702. {
  703. std::cout << "Cannot open log file" << std::endl;
  704. return 1;
  705. }
  706. log.close();
  707. if (!this->OpenOutputFile("", "Coverage.xml", log))
  708. {
  709. std::cout << "Cannot open log file" << std::endl;
  710. return 1;
  711. }
  712. std::string opath = m_ToplevelPath + "/Testing/CDart/Coverage";
  713. for ( cc = 0; cc < files.size(); cc ++ )
  714. {
  715. std::string command = "gcov -l \"" + files[cc] + "\"";
  716. std::string output;
  717. int retVal = 0;
  718. //std::cout << "Run gcov on " << files[cc] << std::flush;
  719. bool res = true;
  720. if ( !m_ShowOnly )
  721. {
  722. res = cmSystemTools::RunCommand(command.c_str(), output,
  723. retVal, opath.c_str(),
  724. m_Verbose);
  725. }
  726. if ( res && retVal == 0 )
  727. {
  728. //std::cout << " - done" << std::endl;
  729. }
  730. else
  731. {
  732. //std::cout << " - fail" << std::endl;
  733. }
  734. }
  735. files.clear();
  736. glob = opath + "/*";
  737. if ( !cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  738. {
  739. std::cout << "Cannot found any coverage files" << std::endl;
  740. return 1;
  741. }
  742. std::map<std::string, std::vector<std::string> > sourcefiles;
  743. for ( cc = 0; cc < cfiles.size(); cc ++ )
  744. {
  745. std::string& fname = cfiles[cc];
  746. //std::cout << "File: " << fname << std::endl;
  747. if ( strcmp(fname.substr(fname.size()-5, 5).c_str(), ".gcov") == 0 )
  748. {
  749. files.push_back(fname);
  750. std::string::size_type pos = fname.find(".da.");
  751. if ( pos != fname.npos )
  752. {
  753. pos += 4;
  754. std::string::size_type epos = fname.size() - pos - strlen(".gcov");
  755. std::string nf = fname.substr(pos, epos);
  756. //std::cout << "Substring: " << nf << std::endl;
  757. if ( allsourcefiles.find(nf) != allsourcefiles.end() ||
  758. allbinaryfiles.find(nf) != allbinaryfiles.end() )
  759. {
  760. std::vector<std::string> &cvec = sourcefiles[nf];
  761. cvec.push_back(fname);
  762. }
  763. }
  764. }
  765. }
  766. for ( cc = 0; cc < files.size(); cc ++ )
  767. {
  768. //std::cout << "File: " << files[cc] << std::endl;
  769. }
  770. std::map<std::string, std::vector<std::string> >::iterator it;
  771. cmCTest::tm_CoverageMap coverageresults;
  772. log << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  773. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  774. << "\" BuildStamp=\"" << m_CurrentTag << "-Experimental\" Name=\""
  775. << m_DartConfiguration["Site"] << "\">\n"
  776. << "<Coverage>\n"
  777. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  778. int total_tested = 0;
  779. int total_untested = 0;
  780. for ( it = sourcefiles.begin(); it != sourcefiles.end(); it ++ )
  781. {
  782. //std::cerr << "Source file: " << it->first << std::endl;
  783. std::vector<std::string> &gfiles = it->second;
  784. for ( cc = 0; cc < gfiles.size(); cc ++ )
  785. {
  786. //std::cout << "\t" << gfiles[cc] << std::endl;
  787. std::ifstream ifile(gfiles[cc].c_str());
  788. ifile.seekg (0, std::ios::end);
  789. int length = ifile.tellg();
  790. ifile.seekg (0, std::ios::beg);
  791. char *buffer = new char [ length + 1 ];
  792. ifile.read(buffer, length);
  793. buffer [length] = 0;
  794. //std::cout << "Read: " << buffer << std::endl;
  795. std::vector<cmStdString> lines;
  796. cmSystemTools::Split(buffer, lines);
  797. delete [] buffer;
  798. cmCTest::cmCTestCoverage& cov = coverageresults[it->first];
  799. std::vector<int>& covlines = cov.m_Lines;
  800. if ( cov.m_FullPath == "" )
  801. {
  802. covlines.insert(covlines.begin(), lines.size(), -1);
  803. if ( allsourcefiles.find(it->first) != allsourcefiles.end() )
  804. {
  805. cov.m_FullPath = allsourcefiles[it->first];
  806. }
  807. else if ( allbinaryfiles.find(it->first) != allbinaryfiles.end() )
  808. {
  809. cov.m_FullPath = allbinaryfiles[it->first];
  810. }
  811. //std::cerr << "Full path: " << cov.m_FullPath << std::endl;
  812. }
  813. for ( cc = 0; cc < lines.size(); cc ++ )
  814. {
  815. std::string& line = lines[cc];
  816. std::string sub = line.substr(0, strlen(" ######"));
  817. int count = atoi(sub.c_str());
  818. if ( sub.compare(" ######") == 0 )
  819. {
  820. if ( covlines[cc] == -1 )
  821. {
  822. covlines[cc] = 0;
  823. }
  824. cov.m_UnTested ++;
  825. //std::cout << "Untested - ";
  826. }
  827. else if ( count > 0 )
  828. {
  829. if ( covlines[cc] == -1 )
  830. {
  831. covlines[cc] = 0;
  832. }
  833. cov.m_Tested ++;
  834. covlines[cc] += count;
  835. //std::cout << "Tested[" << count << "] - ";
  836. }
  837. //std::cout << line << std::endl;
  838. }
  839. }
  840. }
  841. //std::cerr << "Finalizing" << std::endl;
  842. cmCTest::tm_CoverageMap::iterator cit;
  843. int ccount = 0;
  844. std::ofstream cfileoutput;
  845. int cfileoutputcount = 0;
  846. char cfileoutputname[100];
  847. sprintf(cfileoutputname, "CoverageLog-%d.xml", cfileoutputcount++);
  848. if (!this->OpenOutputFile("", cfileoutputname, cfileoutput))
  849. {
  850. std::cout << "Cannot open log file" << std::endl;
  851. return 1;
  852. }
  853. std::string local_start_time = ::CurrentTime();
  854. std::string local_end_time;
  855. for ( cit = coverageresults.begin(); cit != coverageresults.end(); cit ++ )
  856. {
  857. if ( ccount == 100 )
  858. {
  859. local_end_time = ::CurrentTime();
  860. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  861. << "</CoverageLog>\n"
  862. << "</Site>" << std::endl;
  863. cfileoutput.close();
  864. sprintf(cfileoutputname, "CoverageLog-%d.xml", cfileoutputcount++);
  865. if (!this->OpenOutputFile("", cfileoutputname, cfileoutput))
  866. {
  867. std::cout << "Cannot open log file" << std::endl;
  868. return 1;
  869. }
  870. ccount = 0;
  871. }
  872. if ( ccount == 0 )
  873. {
  874. local_start_time = ::CurrentTime();
  875. cfileoutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  876. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  877. << "\" BuildStamp=\"" << m_CurrentTag << "-Experimental\" Name=\""
  878. << m_DartConfiguration["Site"] << "\">\n"
  879. << "<CoverageLog>\n"
  880. << "\t<StartDateTime>" << local_start_time << "</StartDateTime>" << std::endl;
  881. }
  882. //std::cerr << "Final process of Source file: " << cit->first << std::endl;
  883. cmCTest::cmCTestCoverage &cov = cit->second;
  884. std::ifstream ifile(cov.m_FullPath.c_str());
  885. ifile.seekg (0, std::ios::end);
  886. int length = ifile.tellg();
  887. ifile.seekg (0, std::ios::beg);
  888. char *buffer = new char [ length + 1 ];
  889. ifile.read(buffer, length);
  890. buffer [length] = 0;
  891. //std::cout << "Read: " << buffer << std::endl;
  892. std::vector<cmStdString> lines;
  893. cmSystemTools::Split(buffer, lines);
  894. delete [] buffer;
  895. cfileoutput << "\t<File Name=\"" << cit->first << "\" FullPath=\""
  896. << cov.m_FullPath << std::endl << "\">\n"
  897. << "\t\t<Report>" << std::endl;
  898. for ( cc = 0; cc < lines.size(); cc ++ )
  899. {
  900. cfileoutput << "\t\t<Line Number=\""
  901. << static_cast<int>(cc) << "\" Count=\""
  902. << cov.m_Lines[cc] << "\">"
  903. << lines[cc] << "</Line>" << std::endl;
  904. }
  905. cfileoutput << "\t\t</Report>\n"
  906. << "\t</File>" << std::endl;
  907. total_tested += cov.m_Tested;
  908. total_untested += cov.m_UnTested;
  909. float cper = 0;
  910. float cmet = 0;
  911. if ( total_tested + total_untested > 0 )
  912. {
  913. cper = (100 * static_cast<float>(cov.m_Tested)/
  914. static_cast<float>(cov.m_Tested + cov.m_UnTested));
  915. cmet = ( static_cast<float>(cov.m_Tested + 10) /
  916. static_cast<float>(cov.m_Tested + cov.m_UnTested + 10));
  917. }
  918. log << "\t<File Name=\"" << cit->first << "\" FullPath=\"" << cov.m_FullPath
  919. << "\" Covered=\"" << cov.m_Covered << "\">\n"
  920. << "\t\t<LOCTested>" << cov.m_Tested << "</LOCTested>\n"
  921. << "\t\t<LOCUnTested>" << cov.m_UnTested << "</LOCUnTested>\n"
  922. << "\t\t<PercentCoverage>" << cper << "</PercentCoverage>\n"
  923. << "\t\t<CoverageMetric>" << cmet << "</CoverageMetric>\n"
  924. << "\t</File>" << std::endl;
  925. }
  926. if ( ccount > 0 )
  927. {
  928. local_end_time = ::CurrentTime();
  929. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  930. << "</CoverageLog>\n"
  931. << "</Site>" << std::endl;
  932. cfileoutput.close();
  933. }
  934. int total_lines = total_tested + total_untested;
  935. float percent_coverage = 100 * static_cast<float>(total_tested) /
  936. static_cast<float>(total_lines);
  937. if ( total_lines == 0 )
  938. {
  939. percent_coverage = 0;
  940. }
  941. std::string end_time = ::CurrentTime();
  942. log << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
  943. << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
  944. << "\t<LOC>" << total_lines << "</LOC>\n"
  945. << "\t<PercentCoverage>" << percent_coverage << "</PercentCoverage>\n"
  946. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  947. << "</Coverage>\n"
  948. << "</Site>" << std::endl;
  949. std::cout << "\tCovered LOC: " << total_tested << std::endl
  950. << "\tNot covered LOC: " << total_untested << std::endl
  951. << "\tTotal LOC: " << total_lines << std::endl
  952. << "\tPercentage Coverage: " << percent_coverage << "%" << std::endl;
  953. std::cerr << "Coverage test is not yet implemented" << std::endl;
  954. return 1;
  955. }
  956. bool cmCTest::OpenOutputFile(const std::string& path,
  957. const std::string& name, std::ofstream& stream)
  958. {
  959. std::string testingDir = m_ToplevelPath + "/Testing/CDart";
  960. if ( path.size() > 0 )
  961. {
  962. testingDir += "/" + path;
  963. }
  964. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  965. {
  966. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  967. {
  968. std::cerr << "File " << testingDir
  969. << " is in the place of the testing directory"
  970. << std::endl;
  971. return false;
  972. }
  973. }
  974. else
  975. {
  976. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  977. {
  978. std::cerr << "Cannot create directory " << testingDir
  979. << std::endl;
  980. return false;
  981. }
  982. }
  983. std::string filename = testingDir + "/" + name;
  984. stream.open(filename.c_str());
  985. if( !stream )
  986. {
  987. return false;
  988. }
  989. return true;
  990. }
  991. void cmCTest::GenerateDartBuildOutput(std::ostream& os,
  992. std::vector<cmCTestBuildErrorWarning> ew)
  993. {
  994. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  995. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  996. << "\" BuildStamp=\"" << m_CurrentTag << "-Experimental\" Name=\""
  997. << m_DartConfiguration["Site"] << "\">\n"
  998. << "<Build>\n"
  999. << "\t<StartDateTime>" << m_StartBuild << "</StartDateTime>\n"
  1000. << "<BuildCommand>"
  1001. << this->MakeXMLSafe(m_DartConfiguration["MakeCommand"])
  1002. << "</BuildCommand>" << std::endl;
  1003. std::vector<cmCTestBuildErrorWarning>::iterator it;
  1004. for ( it = ew.begin(); it != ew.end(); it++ )
  1005. {
  1006. cmCTestBuildErrorWarning *cm = &(*it);
  1007. os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n"
  1008. << "\t\t<BuildLogLine>" << cm->m_LogLine << "</BuildLogLine>\n"
  1009. << "\t\t<Text>" << this->MakeXMLSafe(cm->m_Text)
  1010. << "\n</Text>" << std::endl;
  1011. if ( cm->m_SourceFile.size() > 0 )
  1012. {
  1013. os << "\t\t<SourceFile>" << cm->m_SourceFile << "</SourceFile>"
  1014. << std::endl;
  1015. }
  1016. if ( cm->m_SourceFileTail.size() > 0 )
  1017. {
  1018. os << "\t\t<SourceFileTail>" << cm->m_SourceFileTail
  1019. << "</SourceFileTail>" << std::endl;
  1020. }
  1021. if ( cm->m_LineNumber >= 0 )
  1022. {
  1023. os << "\t\t<SourceLineNumber>" << cm->m_LineNumber
  1024. << "</SourceLineNumber>" << std::endl;
  1025. }
  1026. os << "\t\t<PreContext>" << this->MakeXMLSafe(cm->m_PreContext)
  1027. << "</PreContext>\n"
  1028. << "\t\t<PostContext>" << this->MakeXMLSafe(cm->m_PostContext)
  1029. << "</PostContext>\n"
  1030. << "\t\t<RepeatCount>0</RepeatCount>\n"
  1031. << "</" << (cm->m_Error ? "Error" : "Warning") << ">\n\n"
  1032. << std::endl;
  1033. }
  1034. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  1035. << "\t<EndDateTime>" << m_EndBuild << "</EndDateTime>\n"
  1036. << "</Build>\n"
  1037. << "</Site>" << std::endl;
  1038. }
  1039. void cmCTest::ProcessDirectory(std::vector<std::string> &passed,
  1040. std::vector<std::string> &failed)
  1041. {
  1042. // does the DartTestfile.txt exist ?
  1043. if(!cmSystemTools::FileExists("DartTestfile.txt"))
  1044. {
  1045. return;
  1046. }
  1047. // parse the file
  1048. std::ifstream fin("DartTestfile.txt");
  1049. if(!fin)
  1050. {
  1051. return;
  1052. }
  1053. int firstTest = 1;
  1054. long line = 0;
  1055. cmRegularExpression ireg(this->m_IncludeRegExp.c_str());
  1056. cmRegularExpression ereg(this->m_ExcludeRegExp.c_str());
  1057. cmRegularExpression dartStuff("([\t\n ]*<DartMeasurement.*/DartMeasurement[a-zA-Z]*>[\t ]*[\n]*)");
  1058. bool parseError;
  1059. while ( fin )
  1060. {
  1061. cmListFileFunction lff;
  1062. if(cmListFileCache::ParseFunction(fin, lff, "DartTestfile.txt",
  1063. parseError, line))
  1064. {
  1065. const std::string& name = lff.m_Name;
  1066. const std::vector<cmListFileArgument>& args = lff.m_Arguments;
  1067. if (name == "SUBDIRS")
  1068. {
  1069. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1070. for(std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1071. j != args.end(); ++j)
  1072. {
  1073. std::string nwd = cwd + "/";
  1074. nwd += j->Value;
  1075. if (cmSystemTools::FileIsDirectory(nwd.c_str()))
  1076. {
  1077. cmSystemTools::ChangeDirectory(nwd.c_str());
  1078. this->ProcessDirectory(passed, failed);
  1079. }
  1080. }
  1081. // return to the original directory
  1082. cmSystemTools::ChangeDirectory(cwd.c_str());
  1083. }
  1084. if (name == "ADD_TEST")
  1085. {
  1086. if (this->m_UseExcludeRegExp &&
  1087. this->m_UseExcludeRegExpFirst &&
  1088. ereg.find(args[0].Value.c_str()))
  1089. {
  1090. continue;
  1091. }
  1092. if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
  1093. {
  1094. continue;
  1095. }
  1096. if (this->m_UseExcludeRegExp &&
  1097. !this->m_UseExcludeRegExpFirst &&
  1098. ereg.find(args[0].Value.c_str()))
  1099. {
  1100. continue;
  1101. }
  1102. cmCTestTestResult cres;
  1103. if (firstTest)
  1104. {
  1105. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1106. std::cerr << "Changing directory into " << nwd.c_str() << "\n";
  1107. firstTest = 0;
  1108. }
  1109. cres.m_Name = args[0].Value;
  1110. if ( m_ShowOnly )
  1111. {
  1112. std::cout << args[0].Value << std::endl;
  1113. }
  1114. else
  1115. {
  1116. fprintf(stderr,"Testing %-30s ",args[0].Value.c_str());
  1117. fflush(stderr);
  1118. }
  1119. //std::cerr << "Testing " << args[0] << " ... ";
  1120. // find the test executable
  1121. std::string testCommand = this->FindExecutable(args[1].Value.c_str());
  1122. testCommand = cmSystemTools::ConvertToOutputPath(testCommand.c_str());
  1123. // continue if we did not find the executable
  1124. if (testCommand == "")
  1125. {
  1126. std::cerr << "Unable to find executable: " <<
  1127. args[1].Value.c_str() << "\n";
  1128. continue;
  1129. }
  1130. // add the arguments
  1131. std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1132. ++j;
  1133. ++j;
  1134. for(;j != args.end(); ++j)
  1135. {
  1136. testCommand += " ";
  1137. testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
  1138. }
  1139. /**
  1140. * Run an executable command and put the stdout in output.
  1141. */
  1142. std::string output;
  1143. int retVal = 0;
  1144. double clock_start, clock_finish;
  1145. clock_start = cmSystemTools::GetTime();
  1146. if ( m_Verbose )
  1147. {
  1148. std::cout << std::endl << "Test command: " << testCommand << std::endl;
  1149. }
  1150. bool res = true;
  1151. if ( !m_ShowOnly )
  1152. {
  1153. res = cmSystemTools::RunCommand(testCommand.c_str(), output,
  1154. retVal, 0, false);
  1155. }
  1156. clock_finish = cmSystemTools::GetTime();
  1157. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  1158. cres.m_FullCommandLine = testCommand;
  1159. if ( !m_ShowOnly )
  1160. {
  1161. if (!res || retVal != 0)
  1162. {
  1163. fprintf(stderr,"***Failed\n");
  1164. if (output != "")
  1165. {
  1166. if (dartStuff.find(output.c_str()))
  1167. {
  1168. cmSystemTools::ReplaceString(output,
  1169. dartStuff.match(1).c_str(),"");
  1170. }
  1171. if (output != "" && m_Verbose)
  1172. {
  1173. std::cerr << output.c_str() << "\n";
  1174. }
  1175. }
  1176. failed.push_back(args[0].Value);
  1177. }
  1178. else
  1179. {
  1180. fprintf(stderr," Passed\n");
  1181. if (output != "")
  1182. {
  1183. if (dartStuff.find(output.c_str()))
  1184. {
  1185. cmSystemTools::ReplaceString(output,
  1186. dartStuff.match(1).c_str(),"");
  1187. }
  1188. if (output != "" && m_Verbose)
  1189. {
  1190. std::cerr << output.c_str() << "\n";
  1191. }
  1192. }
  1193. passed.push_back(args[0].Value);
  1194. }
  1195. }
  1196. cres.m_Output = output;
  1197. cres.m_ReturnValue = retVal;
  1198. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1199. if ( nwd.size() > m_ToplevelPath.size() )
  1200. {
  1201. nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
  1202. }
  1203. cres.m_Path = nwd;
  1204. cres.m_CompletionStatus = "Completed";
  1205. m_TestResults.push_back( cres );
  1206. }
  1207. }
  1208. }
  1209. }
  1210. int cmCTest::TestDirectory()
  1211. {
  1212. std::vector<std::string> passed;
  1213. std::vector<std::string> failed;
  1214. int total;
  1215. m_StartTest = ::CurrentTime();
  1216. this->ProcessDirectory(passed, failed);
  1217. m_EndTest = ::CurrentTime();
  1218. total = int(passed.size()) + int(failed.size());
  1219. if (total == 0)
  1220. {
  1221. if ( !m_ShowOnly )
  1222. {
  1223. std::cerr << "No tests were found!!!\n";
  1224. }
  1225. }
  1226. else
  1227. {
  1228. if (passed.size() && (m_UseIncludeRegExp || m_UseExcludeRegExp))
  1229. {
  1230. std::cerr << "\nThe following tests passed:\n";
  1231. for(std::vector<std::string>::iterator j = passed.begin();
  1232. j != passed.end(); ++j)
  1233. {
  1234. std::cerr << "\t" << *j << "\n";
  1235. }
  1236. }
  1237. float percent = float(passed.size()) * 100.0f / total;
  1238. fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  1239. percent, int(failed.size()), total);
  1240. if (failed.size())
  1241. {
  1242. std::cerr << "\nThe following tests FAILED:\n";
  1243. for(std::vector<std::string>::iterator j = failed.begin();
  1244. j != failed.end(); ++j)
  1245. {
  1246. std::cerr << "\t" << *j << "\n";
  1247. }
  1248. }
  1249. }
  1250. if ( m_DartMode )
  1251. {
  1252. std::ofstream ofs;
  1253. if( !this->OpenOutputFile("", "Test.xml", ofs) )
  1254. {
  1255. std::cerr << "Cannot create testing XML file" << std::endl;
  1256. return 1;
  1257. }
  1258. this->GenerateDartOutput(ofs);
  1259. }
  1260. return int(failed.size());
  1261. }
  1262. void cmCTest::GenerateDartOutput(std::ostream& os)
  1263. {
  1264. if ( !m_DartMode )
  1265. {
  1266. return;
  1267. }
  1268. if ( m_TestResults.size() == 0 )
  1269. {
  1270. return;
  1271. }
  1272. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1273. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1274. << "\" BuildStamp=\"" << m_CurrentTag << "-Experimental\" Name=\""
  1275. << m_DartConfiguration["Site"] << "\">\n"
  1276. << "<Testing>\n"
  1277. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  1278. << "\t<TestList>\n";
  1279. tm_TestResultsVector::size_type cc;
  1280. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  1281. {
  1282. cmCTestTestResult *result = &m_TestResults[cc];
  1283. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  1284. << "/" << this->MakeXMLSafe(result->m_Name)
  1285. << "</Test>" << std::endl;
  1286. }
  1287. os << "\t</TestList>\n";
  1288. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  1289. {
  1290. cmCTestTestResult *result = &m_TestResults[cc];
  1291. os << "\t<Test Status=\"" << (result->m_ReturnValue?"failed":"passed")
  1292. << "\">\n"
  1293. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  1294. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  1295. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  1296. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  1297. << "\t\t<FullCommandLine>"
  1298. << this->MakeXMLSafe(result->m_FullCommandLine)
  1299. << "</FullCommandLine>\n"
  1300. << "\t\t<Results>" << std::endl;
  1301. if ( result->m_ReturnValue )
  1302. {
  1303. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  1304. << "CHILDSTATUS" << "</Value></NamedMeasurement>\n"
  1305. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  1306. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  1307. }
  1308. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  1309. << "name=\"Execution Time\"><Value>"
  1310. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n"
  1311. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1312. << "name=\"Completion Status\"><Value>"
  1313. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n"
  1314. << "\t\t\t<Measurement>\n"
  1315. << "\t\t\t\t<Value>" << this->MakeXMLSafe(result->m_Output)
  1316. << "</Value>\n"
  1317. << "\t\t\t</Measurement>\n"
  1318. << "\t\t</Results>\n"
  1319. << "\t</Test>" << std::endl;
  1320. }
  1321. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  1322. << "</Testing>\n"
  1323. << "</Site>" << std::endl;
  1324. }
  1325. int cmCTest::ProcessTests()
  1326. {
  1327. int res = 0;
  1328. bool notest = true;
  1329. int cc;
  1330. for ( cc = 0; cc < LAST_TEST; cc ++ )
  1331. {
  1332. if ( m_Tests[cc] )
  1333. {
  1334. notest = false;
  1335. break;
  1336. }
  1337. }
  1338. if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
  1339. {
  1340. res += this->UpdateDirectory();
  1341. }
  1342. if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
  1343. {
  1344. res += this->ConfigureDirectory();
  1345. }
  1346. if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
  1347. {
  1348. res += this->BuildDirectory();
  1349. }
  1350. if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
  1351. {
  1352. res += this->TestDirectory();
  1353. }
  1354. if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
  1355. {
  1356. this->CoverageDirectory();
  1357. }
  1358. if ( m_Tests[PURIFY_TEST] || m_Tests[ALL_TEST] )
  1359. {
  1360. std::cerr << "Purify test is not yet implemented" << std::endl;
  1361. }
  1362. return res;
  1363. }