cmCTest.cxx 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352
  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 <cmsys/Base64.h>
  23. #include <stdlib.h> // required for atoi
  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. std::ofstream ofs;
  821. this->OpenOutputFile("Temporary", "LastConfigure.log", ofs);
  822. res = this->RunMakeCommand(cCommand.c_str(), &output,
  823. &retVal, buildDirectory.c_str(),
  824. m_Verbose, m_TimeOut, ofs);
  825. if ( ofs )
  826. {
  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. int errors = 0;
  975. int warnings = 0;
  976. std::vector<int>::size_type kk;
  977. cmCTestBuildErrorWarning errorwarning;
  978. for ( kk =0; kk < markedLines.size(); kk ++ )
  979. {
  980. errorwarning.m_LineNumber = -1;
  981. bool found = false;
  982. if ( markedLines[kk] == 1 )
  983. {
  984. //std::cout << "Error: " << lines[kk] << std::endl;
  985. errorwarning.m_Error = true;
  986. found = true;
  987. }
  988. else if ( markedLines[kk] > 1 )
  989. {
  990. //std::cout << "Warning: " << lines[kk] << std::endl;
  991. errorwarning.m_Error = false;
  992. found = true;
  993. }
  994. if ( found )
  995. {
  996. errorwarning.m_LogLine = static_cast<int>(kk+1);
  997. errorwarning.m_Text = lines[kk];
  998. errorwarning.m_PreContext = "";
  999. errorwarning.m_PostContext = "";
  1000. std::vector<int>::size_type jj;
  1001. std::vector<int>::size_type ll = 0;
  1002. if ( kk > 6 )
  1003. {
  1004. ll = kk - 6;
  1005. }
  1006. for ( jj = kk;
  1007. jj > 0 && jj > ll /* && markedLines[jj] == 0 */;
  1008. jj -- );
  1009. for (; jj < kk; jj ++ )
  1010. {
  1011. errorwarning.m_PreContext += lines[jj] + "\n";
  1012. }
  1013. for ( jj = kk+1;
  1014. jj < lines.size() && jj < kk + 7 /* && markedLines[jj] == 0*/;
  1015. jj ++ )
  1016. {
  1017. errorwarning.m_PostContext += lines[jj] + "\n";
  1018. }
  1019. errorsWarnings.push_back(errorwarning);
  1020. if ( errorwarning.m_Error )
  1021. {
  1022. errors ++;
  1023. }
  1024. else
  1025. {
  1026. warnings ++;
  1027. }
  1028. }
  1029. }
  1030. std::cout << " " << errors << " Compiler errors" << std::endl;
  1031. std::cout << " " << warnings << " Compiler warnings" << std::endl;
  1032. if( !this->OpenOutputFile(m_CurrentTag, "Build.xml", ofs) )
  1033. {
  1034. std::cerr << "Cannot create build XML file" << std::endl;
  1035. return 1;
  1036. }
  1037. this->GenerateDartBuildOutput(ofs, errorsWarnings);
  1038. return 0;
  1039. }
  1040. int cmCTest::CoverageDirectory()
  1041. {
  1042. std::cout << "Performing coverage" << std::endl;
  1043. std::vector<std::string> files;
  1044. std::vector<std::string> cfiles;
  1045. std::vector<std::string> cdirs;
  1046. bool done = false;
  1047. std::string::size_type cc;
  1048. std::string glob;
  1049. std::map<std::string, std::string> allsourcefiles;
  1050. std::map<std::string, std::string> allbinaryfiles;
  1051. std::string start_time = ::CurrentTime();
  1052. // Find all source files.
  1053. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  1054. if ( sourceDirectory.size() == 0 )
  1055. {
  1056. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  1057. return 1;
  1058. }
  1059. cdirs.push_back(sourceDirectory);
  1060. while ( !done )
  1061. {
  1062. if ( cdirs.size() <= 0 )
  1063. {
  1064. break;
  1065. }
  1066. glob = cdirs[cdirs.size()-1] + "/*";
  1067. //std::cout << "Glob: " << glob << std::endl;
  1068. cdirs.pop_back();
  1069. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1070. {
  1071. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1072. {
  1073. allsourcefiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1074. }
  1075. }
  1076. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1077. {
  1078. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1079. {
  1080. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1081. {
  1082. cdirs.push_back(cfiles[cc]);
  1083. }
  1084. }
  1085. }
  1086. }
  1087. // find all binary files
  1088. cdirs.push_back(cmSystemTools::GetCurrentWorkingDirectory());
  1089. while ( !done )
  1090. {
  1091. if ( cdirs.size() <= 0 )
  1092. {
  1093. break;
  1094. }
  1095. glob = cdirs[cdirs.size()-1] + "/*";
  1096. //std::cout << "Glob: " << glob << std::endl;
  1097. cdirs.pop_back();
  1098. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1099. {
  1100. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1101. {
  1102. allbinaryfiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1103. }
  1104. }
  1105. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1106. {
  1107. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1108. {
  1109. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1110. {
  1111. cdirs.push_back(cfiles[cc]);
  1112. }
  1113. }
  1114. }
  1115. }
  1116. std::map<std::string, std::string>::iterator sit;
  1117. for ( sit = allbinaryfiles.begin(); sit != allbinaryfiles.end(); sit ++ )
  1118. {
  1119. const std::string& fname = sit->second;
  1120. //std::cout << "File: " << fname << std::endl;
  1121. if ( strcmp(fname.substr(fname.size()-3, 3).c_str(), ".da") == 0 )
  1122. {
  1123. files.push_back(fname);
  1124. }
  1125. }
  1126. if ( files.size() == 0 )
  1127. {
  1128. std::cout << "Cannot find any coverage information files (.da)" << std::endl;
  1129. return 1;
  1130. }
  1131. std::ofstream log;
  1132. if (!this->OpenOutputFile("Temporary", "Coverage.log", log))
  1133. {
  1134. std::cout << "Cannot open log file" << std::endl;
  1135. return 1;
  1136. }
  1137. log.close();
  1138. if (!this->OpenOutputFile(m_CurrentTag, "Coverage.xml", log))
  1139. {
  1140. std::cout << "Cannot open log file" << std::endl;
  1141. return 1;
  1142. }
  1143. std::string opath = m_ToplevelPath + "/Testing/Temporary/Coverage";
  1144. cmSystemTools::MakeDirectory(opath.c_str());
  1145. for ( cc = 0; cc < files.size(); cc ++ )
  1146. {
  1147. std::string command = "gcov -l \"" + files[cc] + "\"";
  1148. std::string output;
  1149. int retVal = 0;
  1150. //std::cout << "Run gcov on " << files[cc] << std::flush;
  1151. //std::cout << " --- Run [" << command << "]" << std::endl;
  1152. bool res = true;
  1153. if ( !m_ShowOnly )
  1154. {
  1155. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  1156. &retVal, opath.c_str(),
  1157. m_Verbose, m_TimeOut);
  1158. }
  1159. if ( res && retVal == 0 )
  1160. {
  1161. //std::cout << " - done" << std::endl;
  1162. }
  1163. else
  1164. {
  1165. //std::cout << " - fail" << std::endl;
  1166. }
  1167. }
  1168. files.clear();
  1169. glob = opath + "/*";
  1170. if ( !cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1171. {
  1172. std::cout << "Cannot found any coverage files" << std::endl;
  1173. return 1;
  1174. }
  1175. std::map<std::string, std::vector<std::string> > sourcefiles;
  1176. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1177. {
  1178. std::string& fname = cfiles[cc];
  1179. //std::cout << "File: " << fname << std::endl;
  1180. if ( strcmp(fname.substr(fname.size()-5, 5).c_str(), ".gcov") == 0 )
  1181. {
  1182. files.push_back(fname);
  1183. std::string::size_type pos = fname.find(".da.");
  1184. if ( pos != fname.npos )
  1185. {
  1186. pos += 4;
  1187. std::string::size_type epos = fname.size() - pos - strlen(".gcov");
  1188. std::string nf = fname.substr(pos, epos);
  1189. //std::cout << "Substring: " << nf << std::endl;
  1190. if ( allsourcefiles.find(nf) != allsourcefiles.end() ||
  1191. allbinaryfiles.find(nf) != allbinaryfiles.end() )
  1192. {
  1193. std::vector<std::string> &cvec = sourcefiles[nf];
  1194. cvec.push_back(fname);
  1195. }
  1196. }
  1197. }
  1198. }
  1199. for ( cc = 0; cc < files.size(); cc ++ )
  1200. {
  1201. //std::cout << "File: " << files[cc] << std::endl;
  1202. }
  1203. std::map<std::string, std::vector<std::string> >::iterator it;
  1204. cmCTest::tm_CoverageMap coverageresults;
  1205. log << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1206. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1207. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1208. << this->GetTestModelString() << "\" Name=\""
  1209. << m_DartConfiguration["Site"] << "\">\n"
  1210. << "<Coverage>\n"
  1211. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  1212. int total_tested = 0;
  1213. int total_untested = 0;
  1214. for ( it = sourcefiles.begin(); it != sourcefiles.end(); it ++ )
  1215. {
  1216. //std::cerr << "Source file: " << it->first << std::endl;
  1217. std::vector<std::string> &gfiles = it->second;
  1218. for ( cc = 0; cc < gfiles.size(); cc ++ )
  1219. {
  1220. //std::cout << "\t" << gfiles[cc] << std::endl;
  1221. std::ifstream ifile(gfiles[cc].c_str());
  1222. if ( !ifile )
  1223. {
  1224. std::cout << "Cannot open file: " << gfiles[cc].c_str() << std::endl;
  1225. }
  1226. ifile.seekg (0, std::ios::end);
  1227. int length = ifile.tellg();
  1228. ifile.seekg (0, std::ios::beg);
  1229. char *buffer = new char [ length + 1 ];
  1230. ifile.read(buffer, length);
  1231. buffer [length] = 0;
  1232. //std::cout << "Read: " << buffer << std::endl;
  1233. std::vector<cmStdString> lines;
  1234. cmSystemTools::Split(buffer, lines);
  1235. delete [] buffer;
  1236. cmCTest::cmCTestCoverage& cov = coverageresults[it->first];
  1237. std::vector<int>& covlines = cov.m_Lines;
  1238. if ( cov.m_FullPath == "" )
  1239. {
  1240. covlines.insert(covlines.begin(), lines.size(), -1);
  1241. if ( allsourcefiles.find(it->first) != allsourcefiles.end() )
  1242. {
  1243. cov.m_FullPath = allsourcefiles[it->first];
  1244. }
  1245. else if ( allbinaryfiles.find(it->first) != allbinaryfiles.end() )
  1246. {
  1247. cov.m_FullPath = allbinaryfiles[it->first];
  1248. }
  1249. cov.m_AbsolutePath = cov.m_FullPath;
  1250. std::string src_dir = m_DartConfiguration["SourceDirectory"];
  1251. if ( src_dir[src_dir.size()-1] != '/' )
  1252. {
  1253. src_dir = src_dir + "/";
  1254. }
  1255. std::string::size_type spos = cov.m_FullPath.find(src_dir);
  1256. if ( spos == 0 )
  1257. {
  1258. cov.m_FullPath = std::string("./") + cov.m_FullPath.substr(src_dir.size());
  1259. }
  1260. else
  1261. {
  1262. //std::cerr << "Compare -- " << cov.m_FullPath << std::endl;
  1263. //std::cerr << " -- " << src_dir << std::endl;
  1264. cov.m_Show = false;
  1265. continue;
  1266. }
  1267. cov.m_Show = true;
  1268. }
  1269. for ( cc = 0; cc < lines.size(); cc ++ )
  1270. {
  1271. std::string& line = lines[cc];
  1272. std::string sub = line.substr(0, strlen(" ######"));
  1273. int count = atoi(sub.c_str());
  1274. if ( sub.compare(" ######") == 0 )
  1275. {
  1276. if ( covlines[cc] == -1 )
  1277. {
  1278. covlines[cc] = 0;
  1279. }
  1280. cov.m_UnTested ++;
  1281. //std::cout << "Untested - ";
  1282. }
  1283. else if ( count > 0 )
  1284. {
  1285. if ( covlines[cc] == -1 )
  1286. {
  1287. covlines[cc] = 0;
  1288. }
  1289. cov.m_Tested ++;
  1290. covlines[cc] += count;
  1291. //std::cout << "Tested[" << count << "] - ";
  1292. }
  1293. //std::cout << line << std::endl;
  1294. }
  1295. }
  1296. }
  1297. //std::cerr << "Finalizing" << std::endl;
  1298. cmCTest::tm_CoverageMap::iterator cit;
  1299. int ccount = 0;
  1300. std::ofstream cfileoutput;
  1301. int cfileoutputcount = 0;
  1302. char cfileoutputname[100];
  1303. std::string local_start_time = ::CurrentTime();
  1304. std::string local_end_time;
  1305. for ( cit = coverageresults.begin(); cit != coverageresults.end(); cit ++ )
  1306. {
  1307. cmCTest::cmCTestCoverage &cov = cit->second;
  1308. if ( !cov.m_Show )
  1309. {
  1310. continue;
  1311. }
  1312. if ( ccount == 100 )
  1313. {
  1314. local_end_time = ::CurrentTime();
  1315. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1316. << "</CoverageLog>\n"
  1317. << "</Site>" << std::endl;
  1318. cfileoutput.close();
  1319. std::cout << "Close file: " << cfileoutputname << std::endl;
  1320. ccount = 0;
  1321. }
  1322. if ( ccount == 0 )
  1323. {
  1324. sprintf(cfileoutputname, "CoverageLog-%d.xml", cfileoutputcount++);
  1325. std::cout << "Open file: " << cfileoutputname << std::endl;
  1326. if (!this->OpenOutputFile(m_CurrentTag, cfileoutputname, cfileoutput))
  1327. {
  1328. std::cout << "Cannot open log file: " << cfileoutputname << std::endl;
  1329. return 1;
  1330. }
  1331. local_start_time = ::CurrentTime();
  1332. cfileoutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1333. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1334. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1335. << this->GetTestModelString() << "\" Site=\""
  1336. << m_DartConfiguration["Site"] << "\">\n"
  1337. << "<CoverageLog>\n"
  1338. << "\t<StartDateTime>" << local_start_time << "</StartDateTime>" << std::endl;
  1339. }
  1340. //std::cerr << "Final process of Source file: " << cit->first << std::endl;
  1341. std::ifstream ifile(cov.m_AbsolutePath.c_str());
  1342. if ( !ifile )
  1343. {
  1344. std::cerr << "Cannot open file: " << cov.m_FullPath.c_str() << std::endl;
  1345. }
  1346. ifile.seekg (0, std::ios::end);
  1347. int length = ifile.tellg();
  1348. ifile.seekg (0, std::ios::beg);
  1349. char *buffer = new char [ length + 1 ];
  1350. ifile.read(buffer, length);
  1351. buffer [length] = 0;
  1352. //std::cout << "Read: " << buffer << std::endl;
  1353. std::vector<cmStdString> lines;
  1354. cmSystemTools::Split(buffer, lines);
  1355. delete [] buffer;
  1356. cfileoutput << "\t<File Name=\"" << cit->first << "\" FullPath=\""
  1357. << cov.m_FullPath << "\">\n"
  1358. << "\t\t<Report>" << std::endl;
  1359. for ( cc = 0; cc < lines.size(); cc ++ )
  1360. {
  1361. cfileoutput << "\t\t<Line Number=\""
  1362. << static_cast<int>(cc) << "\" Count=\""
  1363. << cov.m_Lines[cc] << "\">"
  1364. << cmCTest::MakeXMLSafe(lines[cc]) << "</Line>" << std::endl;
  1365. }
  1366. cfileoutput << "\t\t</Report>\n"
  1367. << "\t</File>" << std::endl;
  1368. total_tested += cov.m_Tested;
  1369. total_untested += cov.m_UnTested;
  1370. float cper = 0;
  1371. float cmet = 0;
  1372. if ( total_tested + total_untested > 0 && (cov.m_Tested + cov.m_UnTested) > 0)
  1373. {
  1374. cper = (100 * SAFEDIV(static_cast<float>(cov.m_Tested),
  1375. static_cast<float>(cov.m_Tested + cov.m_UnTested)));
  1376. cmet = ( SAFEDIV(static_cast<float>(cov.m_Tested + 10),
  1377. static_cast<float>(cov.m_Tested + cov.m_UnTested + 10)));
  1378. }
  1379. log << "\t<File Name=\"" << cit->first << "\" FullPath=\"" << cov.m_FullPath
  1380. << "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n"
  1381. << "\t\t<LOCTested>" << cov.m_Tested << "</LOCTested>\n"
  1382. << "\t\t<LOCUnTested>" << cov.m_UnTested << "</LOCUnTested>\n"
  1383. << "\t\t<PercentCoverage>";
  1384. log.setf(std::ios::fixed, std::ios::floatfield);
  1385. log.precision(2);
  1386. log << (cper) << "</PercentCoverage>\n"
  1387. << "\t\t<CoverageMetric>";
  1388. log.setf(std::ios::fixed, std::ios::floatfield);
  1389. log.precision(2);
  1390. log << (cmet) << "</CoverageMetric>\n"
  1391. << "\t</File>" << std::endl;
  1392. ccount ++;
  1393. }
  1394. if ( ccount > 0 )
  1395. {
  1396. local_end_time = ::CurrentTime();
  1397. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1398. << "</CoverageLog>\n"
  1399. << "</Site>" << std::endl;
  1400. cfileoutput.close();
  1401. }
  1402. int total_lines = total_tested + total_untested;
  1403. float percent_coverage = 100 * SAFEDIV(static_cast<float>(total_tested),
  1404. static_cast<float>(total_lines));
  1405. if ( total_lines == 0 )
  1406. {
  1407. percent_coverage = 0;
  1408. }
  1409. std::string end_time = ::CurrentTime();
  1410. log << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
  1411. << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
  1412. << "\t<LOC>" << total_lines << "</LOC>\n"
  1413. << "\t<PercentCoverage>";
  1414. log.setf(std::ios::fixed, std::ios::floatfield);
  1415. log.precision(2);
  1416. log << (percent_coverage)<< "</PercentCoverage>\n"
  1417. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  1418. << "</Coverage>\n"
  1419. << "</Site>" << std::endl;
  1420. std::cout << "\tCovered LOC: " << total_tested << std::endl
  1421. << "\tNot covered LOC: " << total_untested << std::endl
  1422. << "\tTotal LOC: " << total_lines << std::endl
  1423. << "\tPercentage Coverage: ";
  1424. std::cout.setf(std::ios::fixed, std::ios::floatfield);
  1425. std::cout.precision(2);
  1426. std::cout << (percent_coverage) << "%" << std::endl;
  1427. return 1;
  1428. }
  1429. bool cmCTest::OpenOutputFile(const std::string& path,
  1430. const std::string& name, std::ofstream& stream)
  1431. {
  1432. std::string testingDir = m_ToplevelPath + "/Testing";
  1433. if ( path.size() > 0 )
  1434. {
  1435. testingDir += "/" + path;
  1436. }
  1437. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  1438. {
  1439. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  1440. {
  1441. std::cerr << "File " << testingDir
  1442. << " is in the place of the testing directory"
  1443. << std::endl;
  1444. return false;
  1445. }
  1446. }
  1447. else
  1448. {
  1449. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  1450. {
  1451. std::cerr << "Cannot create directory " << testingDir
  1452. << std::endl;
  1453. return false;
  1454. }
  1455. }
  1456. std::string filename = testingDir + "/" + name;
  1457. stream.open(filename.c_str());
  1458. if( !stream )
  1459. {
  1460. std::cout << "Problem opening file: " << filename << std::endl;
  1461. return false;
  1462. }
  1463. return true;
  1464. }
  1465. void cmCTest::GenerateDartBuildOutput(std::ostream& os,
  1466. std::vector<cmCTestBuildErrorWarning> ew)
  1467. {
  1468. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1469. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1470. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1471. << this->GetTestModelString() << "\" Name=\""
  1472. << m_DartConfiguration["Site"] << "\">\n"
  1473. << "<Build>\n"
  1474. << "\t<StartDateTime>" << m_StartBuild << "</StartDateTime>\n"
  1475. << "<BuildCommand>"
  1476. << this->MakeXMLSafe(m_DartConfiguration["MakeCommand"])
  1477. << "</BuildCommand>" << std::endl;
  1478. std::vector<cmCTestBuildErrorWarning>::iterator it;
  1479. for ( it = ew.begin(); it != ew.end(); it++ )
  1480. {
  1481. cmCTestBuildErrorWarning *cm = &(*it);
  1482. os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n"
  1483. << "\t\t<BuildLogLine>" << cm->m_LogLine << "</BuildLogLine>\n"
  1484. << "\t\t<Text>" << this->MakeXMLSafe(cm->m_Text)
  1485. << "\n</Text>" << std::endl;
  1486. if ( cm->m_SourceFile.size() > 0 )
  1487. {
  1488. os << "\t\t<SourceFile>" << cm->m_SourceFile << "</SourceFile>"
  1489. << std::endl;
  1490. }
  1491. if ( cm->m_SourceFileTail.size() > 0 )
  1492. {
  1493. os << "\t\t<SourceFileTail>" << cm->m_SourceFileTail
  1494. << "</SourceFileTail>" << std::endl;
  1495. }
  1496. if ( cm->m_LineNumber >= 0 )
  1497. {
  1498. os << "\t\t<SourceLineNumber>" << cm->m_LineNumber
  1499. << "</SourceLineNumber>" << std::endl;
  1500. }
  1501. os << "\t\t<PreContext>" << this->MakeXMLSafe(cm->m_PreContext)
  1502. << "</PreContext>\n"
  1503. << "\t\t<PostContext>" << this->MakeXMLSafe(cm->m_PostContext)
  1504. << "</PostContext>\n"
  1505. << "\t\t<RepeatCount>0</RepeatCount>\n"
  1506. << "</" << (cm->m_Error ? "Error" : "Warning") << ">\n\n"
  1507. << std::endl;
  1508. }
  1509. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  1510. << "\t<EndDateTime>" << m_EndBuild << "</EndDateTime>\n"
  1511. << "</Build>\n"
  1512. << "</Site>" << std::endl;
  1513. }
  1514. void cmCTest::ProcessDirectory(std::vector<std::string> &passed,
  1515. std::vector<std::string> &failed)
  1516. {
  1517. // does the DartTestfile.txt exist ?
  1518. if(!cmSystemTools::FileExists("DartTestfile.txt"))
  1519. {
  1520. return;
  1521. }
  1522. // parse the file
  1523. std::ifstream fin("DartTestfile.txt");
  1524. if(!fin)
  1525. {
  1526. return;
  1527. }
  1528. int firstTest = 1;
  1529. long line = 0;
  1530. #define SPACE_REGEX "[ \t\r\n]"
  1531. cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
  1532. cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
  1533. cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  1534. bool parseError;
  1535. while ( fin )
  1536. {
  1537. cmListFileFunction lff;
  1538. if(cmListFileCache::ParseFunction(fin, lff, "DartTestfile.txt",
  1539. parseError, line))
  1540. {
  1541. const std::string& name = lff.m_Name;
  1542. const std::vector<cmListFileArgument>& args = lff.m_Arguments;
  1543. if (name == "SUBDIRS")
  1544. {
  1545. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1546. for(std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1547. j != args.end(); ++j)
  1548. {
  1549. std::string nwd = cwd + "/";
  1550. nwd += j->Value;
  1551. if (cmSystemTools::FileIsDirectory(nwd.c_str()))
  1552. {
  1553. cmSystemTools::ChangeDirectory(nwd.c_str());
  1554. this->ProcessDirectory(passed, failed);
  1555. }
  1556. }
  1557. // return to the original directory
  1558. cmSystemTools::ChangeDirectory(cwd.c_str());
  1559. }
  1560. if (name == "ADD_TEST")
  1561. {
  1562. if (this->m_UseExcludeRegExp &&
  1563. this->m_UseExcludeRegExpFirst &&
  1564. ereg.find(args[0].Value.c_str()))
  1565. {
  1566. continue;
  1567. }
  1568. if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
  1569. {
  1570. continue;
  1571. }
  1572. if (this->m_UseExcludeRegExp &&
  1573. !this->m_UseExcludeRegExpFirst &&
  1574. ereg.find(args[0].Value.c_str()))
  1575. {
  1576. continue;
  1577. }
  1578. cmCTestTestResult cres;
  1579. if (firstTest)
  1580. {
  1581. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1582. std::cerr << "Changing directory into " << nwd.c_str() << "\n";
  1583. firstTest = 0;
  1584. }
  1585. cres.m_Name = args[0].Value;
  1586. if ( m_ShowOnly )
  1587. {
  1588. std::cout << args[0].Value << std::endl;
  1589. }
  1590. else
  1591. {
  1592. fprintf(stderr,"Testing %-30s ",args[0].Value.c_str());
  1593. fflush(stderr);
  1594. }
  1595. //std::cerr << "Testing " << args[0] << " ... ";
  1596. // find the test executable
  1597. std::string testCommand = this->FindTheExecutable(args[1].Value.c_str());
  1598. testCommand = cmSystemTools::ConvertToOutputPath(testCommand.c_str());
  1599. // continue if we did not find the executable
  1600. if (testCommand == "")
  1601. {
  1602. std::cerr << "Unable to find executable: " <<
  1603. args[1].Value.c_str() << "\n";
  1604. continue;
  1605. }
  1606. // add the arguments
  1607. std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1608. ++j;
  1609. ++j;
  1610. for(;j != args.end(); ++j)
  1611. {
  1612. testCommand += " ";
  1613. testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
  1614. }
  1615. /**
  1616. * Run an executable command and put the stdout in output.
  1617. */
  1618. std::string output;
  1619. int retVal = 0;
  1620. double clock_start, clock_finish;
  1621. clock_start = cmSystemTools::GetTime();
  1622. if ( m_Verbose )
  1623. {
  1624. std::cout << std::endl << "Test command: " << testCommand << std::endl;
  1625. }
  1626. bool res = true;
  1627. if ( !m_ShowOnly )
  1628. {
  1629. res = cmSystemTools::RunSingleCommand(testCommand.c_str(), &output,
  1630. &retVal, 0, false, m_TimeOut);
  1631. }
  1632. clock_finish = cmSystemTools::GetTime();
  1633. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  1634. cres.m_FullCommandLine = testCommand;
  1635. if ( !m_ShowOnly )
  1636. {
  1637. if (!res || retVal != 0)
  1638. {
  1639. fprintf(stderr,"***Failed\n");
  1640. if (output != "")
  1641. {
  1642. if (dartStuff.find(output.c_str()))
  1643. {
  1644. std::string dartString = dartStuff.match(1);
  1645. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  1646. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  1647. }
  1648. if (output != "" && m_Verbose)
  1649. {
  1650. std::cerr << output.c_str() << "\n";
  1651. }
  1652. }
  1653. failed.push_back(args[0].Value);
  1654. }
  1655. else
  1656. {
  1657. fprintf(stderr," Passed\n");
  1658. if (output != "")
  1659. {
  1660. std::cout << "Before dart check" << std::endl;
  1661. if (dartStuff.find(output.c_str()))
  1662. {
  1663. std::string dartString = dartStuff.match(1);
  1664. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  1665. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  1666. }
  1667. if (output != "" && m_Verbose)
  1668. {
  1669. std::cerr << output.c_str() << "\n";
  1670. }
  1671. }
  1672. passed.push_back(args[0].Value);
  1673. }
  1674. }
  1675. cres.m_Output = output;
  1676. cres.m_ReturnValue = retVal;
  1677. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1678. if ( nwd.size() > m_ToplevelPath.size() )
  1679. {
  1680. nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
  1681. }
  1682. cmSystemTools::ReplaceString(nwd, "\\", "/");
  1683. cres.m_Path = nwd;
  1684. cres.m_CompletionStatus = "Completed";
  1685. m_TestResults.push_back( cres );
  1686. }
  1687. }
  1688. }
  1689. }
  1690. int cmCTest::TestDirectory()
  1691. {
  1692. std::cout << "Test project" << std::endl;
  1693. std::vector<std::string> passed;
  1694. std::vector<std::string> failed;
  1695. int total;
  1696. m_StartTest = ::CurrentTime();
  1697. this->ProcessDirectory(passed, failed);
  1698. m_EndTest = ::CurrentTime();
  1699. total = int(passed.size()) + int(failed.size());
  1700. if (total == 0)
  1701. {
  1702. if ( !m_ShowOnly )
  1703. {
  1704. std::cerr << "No tests were found!!!\n";
  1705. }
  1706. }
  1707. else
  1708. {
  1709. if (passed.size() && (m_UseIncludeRegExp || m_UseExcludeRegExp))
  1710. {
  1711. std::cerr << "\nThe following tests passed:\n";
  1712. for(std::vector<std::string>::iterator j = passed.begin();
  1713. j != passed.end(); ++j)
  1714. {
  1715. std::cerr << "\t" << *j << "\n";
  1716. }
  1717. }
  1718. float percent = float(passed.size()) * 100.0f / total;
  1719. fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  1720. percent, int(failed.size()), total);
  1721. if (failed.size())
  1722. {
  1723. std::cerr << "\nThe following tests FAILED:\n";
  1724. for(std::vector<std::string>::iterator j = failed.begin();
  1725. j != failed.end(); ++j)
  1726. {
  1727. std::cerr << "\t" << *j << "\n";
  1728. }
  1729. }
  1730. }
  1731. if ( m_DartMode )
  1732. {
  1733. std::ofstream ofs;
  1734. if( !this->OpenOutputFile(m_CurrentTag, "Test.xml", ofs) )
  1735. {
  1736. std::cerr << "Cannot create testing XML file" << std::endl;
  1737. return 1;
  1738. }
  1739. this->GenerateDartTestOutput(ofs);
  1740. }
  1741. return int(failed.size());
  1742. }
  1743. int cmCTest::SubmitResults()
  1744. {
  1745. #ifdef HAVE_CURL
  1746. std::vector<std::string> files;
  1747. std::string prefix = this->GetSubmitResultsPrefix();
  1748. // TODO:
  1749. // Check if test is enabled
  1750. if ( this->CTestFileExists("Update.xml") )
  1751. {
  1752. files.push_back("Update.xml");
  1753. }
  1754. if ( this->CTestFileExists("Configure.xml") )
  1755. {
  1756. files.push_back("Configure.xml");
  1757. }
  1758. if ( this->CTestFileExists("Build.xml") )
  1759. {
  1760. files.push_back("Build.xml");
  1761. }
  1762. if ( this->CTestFileExists("Test.xml") )
  1763. {
  1764. files.push_back("Test.xml");
  1765. }
  1766. if ( this->CTestFileExists("Coverage.xml") )
  1767. {
  1768. files.push_back("Coverage.xml");
  1769. std::vector<std::string> gfiles;
  1770. std::string gpath = m_ToplevelPath + "/Testing/" + m_CurrentTag;
  1771. std::string::size_type glen = gpath.size() + 1;
  1772. gpath = gpath + "/CoverageLog*";
  1773. //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
  1774. if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
  1775. {
  1776. size_t cc;
  1777. for ( cc = 0; cc < gfiles.size(); cc ++ )
  1778. {
  1779. gfiles[cc] = gfiles[cc].substr(glen);
  1780. //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
  1781. files.push_back(gfiles[cc]);
  1782. }
  1783. }
  1784. else
  1785. {
  1786. std::cout << "Problem globbing" << std::endl;
  1787. }
  1788. }
  1789. if ( this->CTestFileExists("Purify.xml") )
  1790. {
  1791. files.push_back("Purify.xml");
  1792. }
  1793. cmCTestSubmit submit;
  1794. submit.SetVerbose(m_Verbose);
  1795. if ( m_DartConfiguration["DropMethod"] == "" ||
  1796. m_DartConfiguration["DropMethod"] == "ftp" )
  1797. {
  1798. std::cout << "FTP submit method" << std::endl;
  1799. std::string url = "ftp://";
  1800. url += cmCTest::MakeURLSafe(m_DartConfiguration["DropSiteUser"]) + ":" +
  1801. cmCTest::MakeURLSafe(m_DartConfiguration["DropSitePassword"]) + "@" +
  1802. m_DartConfiguration["DropSite"] +
  1803. cmCTest::MakeURLSafe(m_DartConfiguration["DropLocation"]);
  1804. if ( !submit.SubmitUsingFTP(m_ToplevelPath+"/Testing/"+m_CurrentTag,
  1805. files, prefix, url) )
  1806. {
  1807. return 0;
  1808. }
  1809. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  1810. {
  1811. return 0;
  1812. }
  1813. return 1;
  1814. }
  1815. else if ( m_DartConfiguration["DropMethod"] == "http" )
  1816. {
  1817. std::cout << "HTTP submit method" << std::endl;
  1818. std::string url = "http://";
  1819. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  1820. {
  1821. url += m_DartConfiguration["DropSiteUser"];
  1822. if ( m_DartConfiguration["DropSitePassword"].size() > 0 )
  1823. {
  1824. url += ":" + m_DartConfiguration["DropSitePassword"];
  1825. }
  1826. url += "@";
  1827. }
  1828. url += m_DartConfiguration["DropSite"] + m_DartConfiguration["DropLocation"];
  1829. if ( !submit.SubmitUsingHTTP(m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  1830. {
  1831. return 0;
  1832. }
  1833. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  1834. {
  1835. return 0;
  1836. }
  1837. std::cout << "Submission successfull" << std::endl;
  1838. return 1;
  1839. }
  1840. else
  1841. {
  1842. std::cout << "SCP submit not yet implemented" << std::endl;
  1843. }
  1844. #endif
  1845. return 0;
  1846. }
  1847. bool cmCTest::CTestFileExists(const std::string& filename)
  1848. {
  1849. std::string testingDir = m_ToplevelPath + "/Testing/" + m_CurrentTag + "/" +
  1850. filename;
  1851. return cmSystemTools::FileExists(testingDir.c_str());
  1852. }
  1853. std::string cmCTest::GetSubmitResultsPrefix()
  1854. {
  1855. std::string name = m_DartConfiguration["Site"] +
  1856. "___" + m_DartConfiguration["BuildName"] +
  1857. "___" + m_CurrentTag + "-" +
  1858. this->GetTestModelString() + "___XML___";
  1859. return name;
  1860. }
  1861. void cmCTest::GenerateDartTestOutput(std::ostream& os)
  1862. {
  1863. if ( !m_DartMode )
  1864. {
  1865. return;
  1866. }
  1867. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1868. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1869. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1870. << this->GetTestModelString() << "\" Name=\""
  1871. << m_DartConfiguration["Site"] << "\">\n"
  1872. << "<Testing>\n"
  1873. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  1874. << "\t<TestList>\n";
  1875. tm_TestResultsVector::size_type cc;
  1876. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  1877. {
  1878. cmCTestTestResult *result = &m_TestResults[cc];
  1879. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  1880. << "/" << this->MakeXMLSafe(result->m_Name)
  1881. << "</Test>" << std::endl;
  1882. }
  1883. os << "\t</TestList>\n";
  1884. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  1885. {
  1886. cmCTestTestResult *result = &m_TestResults[cc];
  1887. os << "\t<Test Status=\"" << (result->m_ReturnValue?"failed":"passed")
  1888. << "\">\n"
  1889. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  1890. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  1891. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  1892. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  1893. << "\t\t<FullCommandLine>"
  1894. << this->MakeXMLSafe(result->m_FullCommandLine)
  1895. << "</FullCommandLine>\n"
  1896. << "\t\t<Results>" << std::endl;
  1897. if ( result->m_ReturnValue )
  1898. {
  1899. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  1900. << "CHILDSTATUS" << "</Value></NamedMeasurement>\n"
  1901. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  1902. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  1903. os << result->m_RegressionImages;
  1904. }
  1905. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  1906. << "name=\"Execution Time\"><Value>"
  1907. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n"
  1908. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1909. << "name=\"Completion Status\"><Value>"
  1910. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n"
  1911. << "\t\t\t<Measurement>\n"
  1912. << "\t\t\t\t<Value>" << this->MakeXMLSafe(result->m_Output)
  1913. << "</Value>\n"
  1914. << "\t\t\t</Measurement>\n"
  1915. << "\t\t</Results>\n"
  1916. << "\t</Test>" << std::endl;
  1917. }
  1918. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  1919. << "</Testing>\n"
  1920. << "</Site>" << std::endl;
  1921. }
  1922. int cmCTest::ProcessTests()
  1923. {
  1924. int res = 0;
  1925. bool notest = true;
  1926. int cc;
  1927. int update_count = 0;
  1928. for ( cc = 0; cc < LAST_TEST; cc ++ )
  1929. {
  1930. if ( m_Tests[cc] )
  1931. {
  1932. notest = false;
  1933. break;
  1934. }
  1935. }
  1936. if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
  1937. {
  1938. update_count = this->UpdateDirectory();
  1939. if ( update_count < 0 )
  1940. {
  1941. res += 1;
  1942. }
  1943. }
  1944. if ( m_TestModel == cmCTest::CONTINUOUS && !update_count )
  1945. {
  1946. return 0;
  1947. }
  1948. if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
  1949. {
  1950. res += this->ConfigureDirectory();
  1951. }
  1952. if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
  1953. {
  1954. res += this->BuildDirectory();
  1955. }
  1956. if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
  1957. {
  1958. res += this->TestDirectory();
  1959. }
  1960. if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
  1961. {
  1962. this->CoverageDirectory();
  1963. }
  1964. if ( m_Tests[PURIFY_TEST] || m_Tests[ALL_TEST] )
  1965. {
  1966. std::cerr << "Purify test is not yet implemented" << std::endl;
  1967. }
  1968. if ( m_Tests[SUBMIT_TEST] || m_Tests[ALL_TEST] )
  1969. {
  1970. #ifdef HAVE_CURL
  1971. this->SubmitResults();
  1972. #else
  1973. std::cerr << "Submit test is not yet implemented" << std::endl;
  1974. #endif
  1975. }
  1976. return res;
  1977. }
  1978. std::string cmCTest::GetTestModelString()
  1979. {
  1980. switch ( m_TestModel )
  1981. {
  1982. case cmCTest::NIGHTLY:
  1983. return "Nightly";
  1984. case cmCTest::CONTINUOUS:
  1985. return "Continuous";
  1986. }
  1987. return "Experimental";
  1988. }
  1989. std::string cmCTest::GenerateRegressionImages(const std::string& xml)
  1990. {
  1991. cmsys::RegularExpression twoattributes(
  1992. "<DartMeasurement"
  1993. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1994. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1995. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1996. cmsys::RegularExpression threeattributes(
  1997. "<DartMeasurement"
  1998. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1999. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2000. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2001. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2002. cmsys::RegularExpression fourattributes(
  2003. "<DartMeasurement"
  2004. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2005. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2006. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2007. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2008. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2009. cmsys::RegularExpression measurementfile(
  2010. "<DartMeasurementFile"
  2011. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2012. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2013. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  2014. cmOStringStream ostr;
  2015. bool done = false;
  2016. std::string cxml = xml;
  2017. while ( ! done )
  2018. {
  2019. if ( twoattributes.find(cxml) )
  2020. {
  2021. ostr
  2022. << "\t\t\t<NamedMeasurement"
  2023. << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
  2024. << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
  2025. << "><Value>" << twoattributes.match(5)
  2026. << "</Value></NamedMeasurement>"
  2027. << std::endl;
  2028. cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
  2029. }
  2030. else if ( threeattributes.find(cxml) )
  2031. {
  2032. ostr
  2033. << "\t\t\t<NamedMeasurement"
  2034. << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
  2035. << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
  2036. << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
  2037. << "><Value>" << threeattributes.match(7)
  2038. << "</Value></NamedMeasurement>"
  2039. << std::endl;
  2040. cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
  2041. }
  2042. else if ( fourattributes.find(cxml) )
  2043. {
  2044. ostr
  2045. << "\t\t\t<NamedMeasurement"
  2046. << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
  2047. << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
  2048. << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
  2049. << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
  2050. << "><Value>" << fourattributes.match(9)
  2051. << "</Value></NamedMeasurement>"
  2052. << std::endl;
  2053. cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
  2054. }
  2055. else if ( measurementfile.find(cxml) )
  2056. {
  2057. const std::string& filename = measurementfile.match(5);
  2058. if ( cmSystemTools::FileExists(filename.c_str()) )
  2059. {
  2060. long len = cmSystemTools::FileLength(filename.c_str());
  2061. std::ifstream ifs(filename.c_str(), std::ios::in
  2062. #ifdef _WIN32
  2063. | std::ios::binary
  2064. #endif
  2065. );
  2066. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  2067. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  2068. unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 1) ];
  2069. unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  2070. unsigned long cc;
  2071. ostr
  2072. << "\t\t\t<NamedMeasurement"
  2073. << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
  2074. << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
  2075. << " encoding=\"base64\""
  2076. << ">" << std::endl << "\t\t\t\t<Value>";
  2077. for ( cc = 0; cc < rlen; cc ++ )
  2078. {
  2079. ostr << encoded_buffer[cc];
  2080. if ( cc % 60 == 0 && cc )
  2081. {
  2082. ostr << std::endl;
  2083. }
  2084. }
  2085. ostr
  2086. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  2087. << std::endl;
  2088. delete [] file_buffer;
  2089. delete [] encoded_buffer;
  2090. }
  2091. else
  2092. {
  2093. int idx = 4;
  2094. if ( measurementfile.match(1) == "name" )
  2095. {
  2096. idx = 2;
  2097. }
  2098. ostr
  2099. << "\t\t\t<NamedMeasurement"
  2100. << " name=\"" << measurementfile.match(idx) << "\""
  2101. << " text=\"text/string\""
  2102. << "><Value>File " << filename << " not found</Value></NamedMeasurement>"
  2103. << std::endl;
  2104. }
  2105. cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
  2106. }
  2107. else
  2108. {
  2109. done = true;
  2110. }
  2111. }
  2112. return ostr.str();
  2113. }
  2114. bool cmCTest::RunMakeCommand(const char* command, std::string* output,
  2115. int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs)
  2116. {
  2117. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  2118. if(args.size() < 1)
  2119. {
  2120. return false;
  2121. }
  2122. std::vector<const char*> argv;
  2123. for(std::vector<cmStdString>::const_iterator a = args.begin();
  2124. a != args.end(); ++a)
  2125. {
  2126. argv.push_back(a->c_str());
  2127. }
  2128. argv.push_back(0);
  2129. if ( output )
  2130. {
  2131. *output = "";
  2132. }
  2133. cmsysProcess* cp = cmsysProcess_New();
  2134. cmsysProcess_SetCommand(cp, &*argv.begin());
  2135. cmsysProcess_SetWorkingDirectory(cp, dir);
  2136. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2137. cmsysProcess_SetTimeout(cp, timeout);
  2138. cmsysProcess_Execute(cp);
  2139. std::string::size_type tick = 0;
  2140. std::string::size_type tick_len = 1024;
  2141. std::string::size_type tick_line_len = 50;
  2142. char* data;
  2143. int length;
  2144. if ( !verbose )
  2145. {
  2146. std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl;
  2147. std::cout << " " << std::flush;
  2148. }
  2149. while(cmsysProcess_WaitForData(cp, (cmsysProcess_Pipe_STDOUT |
  2150. cmsysProcess_Pipe_STDERR),
  2151. &data, &length, 0))
  2152. {
  2153. if ( output )
  2154. {
  2155. output->append(data, length);
  2156. while ( output->size() > (tick * tick_len) )
  2157. {
  2158. tick ++;
  2159. std::cout << "." << std::flush;
  2160. if ( tick % tick_line_len == 0 && tick > 0 )
  2161. {
  2162. std::cout << " Size: ";
  2163. std::cout << int((output->size() / 1024.0) + 1) << "K" << std::endl;
  2164. std::cout << " " << std::flush;
  2165. }
  2166. }
  2167. }
  2168. if(verbose)
  2169. {
  2170. std::cout.write(data, length);
  2171. }
  2172. if ( ofs )
  2173. {
  2174. ofs.write(data, length);
  2175. ofs.flush();
  2176. }
  2177. }
  2178. std::cout << " Size of output: ";
  2179. std::cout << int(output->size() / 1024.0) << "K" << std::endl;
  2180. cmsysProcess_WaitForExit(cp, 0);
  2181. bool result = true;
  2182. if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
  2183. {
  2184. if ( retVal )
  2185. {
  2186. *retVal = cmsysProcess_GetExitValue(cp);
  2187. }
  2188. else
  2189. {
  2190. if ( cmsysProcess_GetExitValue(cp) != 0 )
  2191. {
  2192. result = false;
  2193. }
  2194. }
  2195. }
  2196. else
  2197. {
  2198. result = false;
  2199. }
  2200. cmsysProcess_Delete(cp);
  2201. return result;
  2202. }