cmCTest.cxx 44 KB

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