cmCTest.cxx 44 KB

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