cmCTest.cxx 61 KB

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