cmCTest.cxx 63 KB

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