cmCTest.cxx 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496
  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\r\f\v");
  60. std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
  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. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d UTC",
  502. t->tm_year + 1900,
  503. t->tm_mon + 1,
  504. t->tm_mday,
  505. t->tm_hour,
  506. t->tm_min,
  507. t->tm_sec);
  508. std::string today_update_date = current_time;
  509. extra_update_opts += "-D \"" + today_update_date +"\"";
  510. //std::cout << "Update: " << extra_update_opts << std::endl;
  511. }
  512. #endif
  513. std::string command = cvsCommand + " -z3 update " + cvsOptions +
  514. " " + extra_update_opts;
  515. std::ofstream os;
  516. if ( !this->OpenOutputFile(m_CurrentTag, "Update.xml", os) )
  517. {
  518. std::cout << "Cannot open log file" << std::endl;
  519. }
  520. std::string start_time = ::CurrentTime();
  521. std::string goutput;
  522. int retVal = 0;
  523. bool res = true;
  524. std::ofstream ofs;
  525. if ( !m_ShowOnly )
  526. {
  527. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  528. &retVal, sourceDirectory.c_str(),
  529. m_Verbose, 0 /*m_TimeOut*/);
  530. if ( this->OpenOutputFile("Temporary", "LastUpdate.log", ofs) )
  531. {
  532. ofs << goutput << std::endl;;
  533. }
  534. }
  535. else
  536. {
  537. std::cout << "Update with command: " << command << std::endl;
  538. }
  539. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  540. << "<Update mode=\"Client\">\n"
  541. << "\t<Site>" <<m_DartConfiguration["Site"] << "</Site>\n"
  542. << "\t<BuildName>" << m_DartConfiguration["BuildName"]
  543. << "</BuildName>\n"
  544. << "\t<BuildStamp>" << m_CurrentTag << "-"
  545. << this->GetTestModelString() << "</BuildStamp>\n"
  546. << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  547. << "\t<UpdateCommand>" << command << "</UpdateCommand>\n"
  548. << "\t<UpdateReturnStatus>";
  549. if ( retVal )
  550. {
  551. os << goutput;
  552. }
  553. os << "</UpdateReturnStatus>" << std::endl;
  554. std::vector<cmStdString> lines;
  555. cmSystemTools::Split(goutput.c_str(), lines);
  556. std::cout << "Updated; gathering version information" << std::endl;
  557. cmsys::RegularExpression date_author("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  558. cmsys::RegularExpression revision("^revision +([^ ]*) *$");
  559. cmsys::RegularExpression end_of_file("^=============================================================================$");
  560. cmsys::RegularExpression end_of_comment("^----------------------------$");
  561. std::string current_path = "";
  562. bool first_file = true;
  563. cmCTest::AuthorsToUpdatesMap authors_files_map;
  564. int num_updated = 0;
  565. int num_modified = 0;
  566. int num_conflicting = 0;
  567. for ( cc= 0 ; cc < lines.size(); cc ++ )
  568. {
  569. const char* line = lines[cc].c_str();
  570. char mod = line[0];
  571. if ( line[1] == ' ' && mod != '?' )
  572. {
  573. count ++;
  574. const char* file = line + 2;
  575. //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl;
  576. std::string logcommand = cvsCommand + " -z3 log -N " + file;
  577. //std::cout << "Do log: " << logcommand << std::endl;
  578. std::string output;
  579. res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output,
  580. &retVal, sourceDirectory.c_str(),
  581. m_Verbose, 0 /*m_TimeOut*/);
  582. if ( ofs )
  583. {
  584. ofs << output << std::endl;
  585. }
  586. if ( res && retVal == 0)
  587. {
  588. //std::cout << output << std::endl;
  589. std::vector<cmStdString> ulines;
  590. cmSystemTools::Split(output.c_str(), ulines);
  591. std::string::size_type sline = 0;
  592. std::string srevision1 = "Unknown";
  593. std::string sdate1 = "Unknown";
  594. std::string sauthor1 = "Unknown";
  595. std::string semail1 = "Unknown";
  596. std::string comment1 = "";
  597. std::string srevision2 = "Unknown";
  598. std::string sdate2 = "Unknown";
  599. std::string sauthor2 = "Unknown";
  600. std::string comment2 = "";
  601. std::string semail2 = "Unknown";
  602. bool have_first = false;
  603. bool have_second = false;
  604. for ( kk = 0; kk < ulines.size(); kk ++ )
  605. {
  606. const char* clp = ulines[kk].c_str();
  607. if ( !have_second && !sline && revision.find(clp) )
  608. {
  609. if ( !have_first )
  610. {
  611. srevision1 = revision.match(1);
  612. }
  613. else
  614. {
  615. srevision2 = revision.match(1);
  616. }
  617. }
  618. else if ( !have_second && !sline && date_author.find(clp) )
  619. {
  620. sline = kk + 1;
  621. if ( !have_first )
  622. {
  623. sdate1 = date_author.match(1);
  624. sauthor1 = date_author.match(2);
  625. }
  626. else
  627. {
  628. sdate2 = date_author.match(1);
  629. sauthor2 = date_author.match(2);
  630. }
  631. }
  632. else if ( sline && end_of_comment.find(clp) || end_of_file.find(clp))
  633. {
  634. if ( !have_first )
  635. {
  636. have_first = true;
  637. }
  638. else if ( !have_second )
  639. {
  640. have_second = true;
  641. }
  642. sline = 0;
  643. }
  644. else if ( sline )
  645. {
  646. if ( !have_first )
  647. {
  648. comment1 += clp;
  649. comment1 += "\n";
  650. }
  651. else
  652. {
  653. comment2 += clp;
  654. comment2 += "\n";
  655. }
  656. }
  657. }
  658. if ( mod == 'M' )
  659. {
  660. comment1 = "Locally modified file\n";
  661. }
  662. if ( mod == 'C' )
  663. {
  664. comment1 = "Conflict while updating\n";
  665. }
  666. std::string path = cmSystemTools::GetFilenamePath(file);
  667. std::string fname = cmSystemTools::GetFilenameName(file);
  668. if ( path != current_path )
  669. {
  670. if ( !first_file )
  671. {
  672. os << "\t</Directory>" << std::endl;
  673. }
  674. else
  675. {
  676. first_file = false;
  677. }
  678. os << "\t<Directory>\n"
  679. << "\t\t<Name>" << path << "</Name>" << std::endl;
  680. }
  681. if ( mod == 'C' )
  682. {
  683. num_conflicting ++;
  684. os << "\t<Conflicting>" << std::endl;
  685. }
  686. else if ( mod == 'M' )
  687. {
  688. num_modified ++;
  689. os << "\t<Modified>" << std::endl;
  690. }
  691. else
  692. {
  693. num_updated ++;
  694. os << "\t<Updated>" << std::endl;
  695. }
  696. if ( srevision2 == "Unknown" )
  697. {
  698. srevision2 = srevision1;
  699. }
  700. os << "\t\t<File Directory=\"" << path << "\">" << fname
  701. << "</File>\n"
  702. << "\t\t<Directory>" << path << "</Directory>\n"
  703. << "\t\t<FullName>" << file << "</FullName>\n"
  704. << "\t\t<CheckinDate>" << sdate1 << "</CheckinDate>\n"
  705. << "\t\t<Author>" << sauthor1 << "</Author>\n"
  706. << "\t\t<Email>" << semail1 << "</Email>\n"
  707. << "\t\t<Log>" << this->MakeXMLSafe(comment1) << "</Log>\n"
  708. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  709. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  710. << std::endl;
  711. if ( srevision2 != srevision1 )
  712. {
  713. os
  714. << "\t\t<Revisions>\n"
  715. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  716. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  717. << "\t\t\t<Author>" << sauthor1<< "</Author>\n"
  718. << "\t\t\t<Date>" << sdate1 << "</Date>\n"
  719. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment1) << "</Comment>\n"
  720. << "\t\t\t<Email>" << semail1 << "</Email>\n"
  721. << "\t\t</Revisions>\n"
  722. << "\t\t<Revisions>\n"
  723. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  724. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  725. << "\t\t\t<Author>" << sauthor2<< "</Author>\n"
  726. << "\t\t\t<Date>" << sdate2 << "</Date>\n"
  727. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment2) << "</Comment>\n"
  728. << "\t\t\t<Email>" << semail2 << "</Email>\n"
  729. << "\t\t</Revisions>" << std::endl;
  730. }
  731. if ( mod == 'C' )
  732. {
  733. os << "\t</Conflicting>" << std::endl;
  734. }
  735. else if ( mod == 'M' )
  736. {
  737. os << "\t</Modified>" << std::endl;
  738. }
  739. else
  740. {
  741. os << "\t</Updated>" << std::endl;
  742. }
  743. cmCTest::UpdateFiles *u = &authors_files_map[sauthor1];
  744. cmCTest::StringPair p;
  745. p.first = path;
  746. p.second = fname;
  747. u->push_back(p);
  748. current_path = path;
  749. }
  750. }
  751. }
  752. if ( num_updated )
  753. {
  754. std::cout << "Found " << num_updated << " updated files" << std::endl;
  755. }
  756. if ( num_modified )
  757. {
  758. std::cout << "Found " << num_modified << " locally modified files"
  759. << std::endl;
  760. }
  761. if ( num_conflicting )
  762. {
  763. std::cout << "Found " << num_conflicting << " conflicting files"
  764. << std::endl;
  765. }
  766. if ( !first_file )
  767. {
  768. os << "\t</Directory>" << std::endl;
  769. }
  770. cmCTest::AuthorsToUpdatesMap::iterator it;
  771. for ( it = authors_files_map.begin();
  772. it != authors_files_map.end();
  773. it ++ )
  774. {
  775. os << "\t<Author>\n"
  776. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  777. cmCTest::UpdateFiles *u = &(it->second);
  778. for ( cc = 0; cc < u->size(); cc ++ )
  779. {
  780. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  781. << (*u)[cc].second << "</File>" << std::endl;
  782. }
  783. os << "\t</Author>" << std::endl;
  784. }
  785. //std::cout << "End" << std::endl;
  786. std::string end_time = ::CurrentTime();
  787. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  788. << "</Update>" << std::endl;
  789. if ( ofs )
  790. {
  791. ofs.close();
  792. }
  793. if (! res || retVal )
  794. {
  795. std::cerr << "Error(s) when updating the project" << std::endl;
  796. std::cerr << "Output: " << goutput << std::endl;
  797. return -1;
  798. }
  799. return count;
  800. }
  801. int cmCTest::ConfigureDirectory()
  802. {
  803. std::cout << "Configure project" << std::endl;
  804. std::string cCommand = m_DartConfiguration["ConfigureCommand"];
  805. if ( cCommand.size() == 0 )
  806. {
  807. std::cerr << "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  808. << std::endl;
  809. return 1;
  810. }
  811. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  812. if ( buildDirectory.size() == 0 )
  813. {
  814. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  815. return 1;
  816. }
  817. std::string output;
  818. int retVal = 0;
  819. int res = 0;
  820. if ( !m_ShowOnly )
  821. {
  822. std::ofstream os;
  823. if ( !this->OpenOutputFile(m_CurrentTag, "Configure.xml", os) )
  824. {
  825. std::cout << "Cannot open log file" << std::endl;
  826. }
  827. std::string start_time = ::CurrentTime();
  828. std::ofstream ofs;
  829. this->OpenOutputFile("Temporary", "LastConfigure.log", ofs);
  830. res = this->RunMakeCommand(cCommand.c_str(), &output,
  831. &retVal, buildDirectory.c_str(),
  832. m_Verbose, 0, ofs);
  833. if ( ofs )
  834. {
  835. ofs.close();
  836. }
  837. if ( os )
  838. {
  839. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  840. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  841. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  842. << this->GetTestModelString() << "\" Name=\""
  843. << m_DartConfiguration["Site"] << "\">\n"
  844. << "<Configure>\n"
  845. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  846. if ( res == cmsysProcess_State_Exited && retVal )
  847. {
  848. os << retVal;
  849. }
  850. os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>" << std::endl;
  851. //std::cout << "End" << std::endl;
  852. os << "<Log>" << this->MakeXMLSafe(output) << "</Log>" << std::endl;
  853. std::string end_time = ::CurrentTime();
  854. os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
  855. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  856. << "</Configure>\n"
  857. << "</Site>" << std::endl;
  858. }
  859. }
  860. else
  861. {
  862. std::cout << "Configure with command: " << cCommand << std::endl;
  863. }
  864. if (! res || retVal )
  865. {
  866. std::cerr << "Error(s) when updating the project" << std::endl;
  867. return 1;
  868. }
  869. return 0;
  870. }
  871. int cmCTest::BuildDirectory()
  872. {
  873. std::cout << "Build project" << std::endl;
  874. std::string makeCommand = m_DartConfiguration["MakeCommand"];
  875. if ( makeCommand.size() == 0 )
  876. {
  877. std::cerr << "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl;
  878. return 1;
  879. }
  880. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  881. if ( buildDirectory.size() == 0 )
  882. {
  883. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  884. return 1;
  885. }
  886. std::ofstream ofs;
  887. if ( !this->OpenOutputFile("Temporary", "LastBuild.log", ofs) )
  888. {
  889. std::cerr << "Cannot create LastBuild.log file" << std::endl;
  890. }
  891. m_StartBuild = ::CurrentTime();
  892. std::string output;
  893. int retVal = 0;
  894. int res = cmsysProcess_State_Exited;
  895. if ( !m_ShowOnly )
  896. {
  897. res = this->RunMakeCommand(makeCommand.c_str(), &output,
  898. &retVal, buildDirectory.c_str(),
  899. m_Verbose, 0, ofs);
  900. }
  901. else
  902. {
  903. std::cout << "Build with command: " << makeCommand << std::endl;
  904. }
  905. m_EndBuild = ::CurrentTime();
  906. if (res != cmsysProcess_State_Exited || retVal )
  907. {
  908. std::cerr << "Error(s) when building project" << std::endl;
  909. }
  910. if ( ofs )
  911. {
  912. ofs.close();
  913. }
  914. // Parsing of output for errors and warnings.
  915. std::vector<cmStdString> lines;
  916. cmSystemTools::Split(output.c_str(), lines);
  917. // Lines are marked:
  918. // 0 - nothing
  919. // 1 - error
  920. // > 1 - warning
  921. std::vector<int> markedLines(lines.size(), 0);
  922. int cc;
  923. // Errors
  924. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  925. {
  926. cmsys::RegularExpression re(cmCTestErrorMatches[cc]);
  927. std::vector<std::string>::size_type kk;
  928. for ( kk = 0; kk < lines.size(); kk ++ )
  929. {
  930. if ( re.find(lines[kk]) )
  931. {
  932. markedLines[kk] = 1;
  933. }
  934. }
  935. }
  936. // Warnings
  937. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  938. {
  939. cmsys::RegularExpression re(cmCTestWarningMatches[cc]);
  940. std::vector<std::string>::size_type kk;
  941. for ( kk = 0; kk < lines.size(); kk ++ )
  942. {
  943. if ( re.find(lines[kk]) )
  944. {
  945. markedLines[kk] += 2;
  946. }
  947. }
  948. }
  949. // Errors exceptions
  950. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  951. {
  952. cmsys::RegularExpression re(cmCTestErrorExceptions[cc]);
  953. std::vector<int>::size_type kk;
  954. for ( kk =0; kk < markedLines.size(); kk ++ )
  955. {
  956. if ( markedLines[kk] == 1 )
  957. {
  958. if ( re.find(lines[kk]) )
  959. {
  960. markedLines[kk] = 0;
  961. }
  962. }
  963. }
  964. }
  965. // Warning exceptions
  966. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  967. {
  968. cmsys::RegularExpression re(cmCTestWarningExceptions[cc]);
  969. std::vector<int>::size_type kk;
  970. for ( kk =0; kk < markedLines.size(); kk ++ )
  971. {
  972. if ( markedLines[kk] > 1 )
  973. {
  974. if ( re.find(lines[kk]) )
  975. {
  976. markedLines[kk] = 0;
  977. }
  978. }
  979. }
  980. }
  981. std::vector<cmCTestBuildErrorWarning> errorsWarnings;
  982. int errors = 0;
  983. int warnings = 0;
  984. std::vector<int>::size_type kk;
  985. cmCTestBuildErrorWarning errorwarning;
  986. for ( kk =0; kk < markedLines.size(); kk ++ )
  987. {
  988. errorwarning.m_LineNumber = -1;
  989. bool found = false;
  990. if ( markedLines[kk] == 1 )
  991. {
  992. //std::cout << "Error: " << lines[kk] << std::endl;
  993. errorwarning.m_Error = true;
  994. found = true;
  995. }
  996. else if ( markedLines[kk] > 1 )
  997. {
  998. //std::cout << "Warning: " << lines[kk] << std::endl;
  999. errorwarning.m_Error = false;
  1000. found = true;
  1001. }
  1002. if ( found )
  1003. {
  1004. errorwarning.m_LogLine = static_cast<int>(kk+1);
  1005. errorwarning.m_Text = lines[kk];
  1006. errorwarning.m_PreContext = "";
  1007. errorwarning.m_PostContext = "";
  1008. std::vector<int>::size_type jj;
  1009. std::vector<int>::size_type ll = 0;
  1010. if ( kk > 6 )
  1011. {
  1012. ll = kk - 6;
  1013. }
  1014. for ( jj = kk;
  1015. jj > 0 && jj > ll /* && markedLines[jj] == 0 */;
  1016. jj -- );
  1017. for (; jj < kk; jj ++ )
  1018. {
  1019. errorwarning.m_PreContext += lines[jj] + "\n";
  1020. }
  1021. for ( jj = kk+1;
  1022. jj < lines.size() && jj < kk + 7 /* && markedLines[jj] == 0*/;
  1023. jj ++ )
  1024. {
  1025. errorwarning.m_PostContext += lines[jj] + "\n";
  1026. }
  1027. errorsWarnings.push_back(errorwarning);
  1028. if ( errorwarning.m_Error )
  1029. {
  1030. errors ++;
  1031. }
  1032. else
  1033. {
  1034. warnings ++;
  1035. }
  1036. }
  1037. }
  1038. std::cout << " " << errors << " Compiler errors" << std::endl;
  1039. std::cout << " " << warnings << " Compiler warnings" << std::endl;
  1040. if( !this->OpenOutputFile(m_CurrentTag, "Build.xml", ofs) )
  1041. {
  1042. std::cerr << "Cannot create build XML file" << std::endl;
  1043. return 1;
  1044. }
  1045. this->GenerateDartBuildOutput(ofs, errorsWarnings);
  1046. return 0;
  1047. }
  1048. int cmCTest::CoverageDirectory()
  1049. {
  1050. std::cout << "Performing coverage" << std::endl;
  1051. std::vector<std::string> files;
  1052. std::vector<std::string> cfiles;
  1053. std::vector<std::string> cdirs;
  1054. bool done = false;
  1055. std::string::size_type cc;
  1056. std::string glob;
  1057. std::map<std::string, std::string> allsourcefiles;
  1058. std::map<std::string, std::string> allbinaryfiles;
  1059. std::string start_time = ::CurrentTime();
  1060. // Find all source files.
  1061. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  1062. if ( sourceDirectory.size() == 0 )
  1063. {
  1064. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  1065. return 1;
  1066. }
  1067. cdirs.push_back(sourceDirectory);
  1068. while ( !done )
  1069. {
  1070. if ( cdirs.size() <= 0 )
  1071. {
  1072. break;
  1073. }
  1074. glob = cdirs[cdirs.size()-1] + "/*";
  1075. //std::cout << "Glob: " << glob << std::endl;
  1076. cdirs.pop_back();
  1077. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1078. {
  1079. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1080. {
  1081. allsourcefiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1082. }
  1083. }
  1084. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1085. {
  1086. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1087. {
  1088. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1089. {
  1090. cdirs.push_back(cfiles[cc]);
  1091. }
  1092. }
  1093. }
  1094. }
  1095. // find all binary files
  1096. cdirs.push_back(cmSystemTools::GetCurrentWorkingDirectory());
  1097. while ( !done )
  1098. {
  1099. if ( cdirs.size() <= 0 )
  1100. {
  1101. break;
  1102. }
  1103. glob = cdirs[cdirs.size()-1] + "/*";
  1104. //std::cout << "Glob: " << glob << std::endl;
  1105. cdirs.pop_back();
  1106. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1107. {
  1108. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1109. {
  1110. allbinaryfiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1111. }
  1112. }
  1113. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1114. {
  1115. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1116. {
  1117. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1118. {
  1119. cdirs.push_back(cfiles[cc]);
  1120. }
  1121. }
  1122. }
  1123. }
  1124. std::map<std::string, std::string>::iterator sit;
  1125. for ( sit = allbinaryfiles.begin(); sit != allbinaryfiles.end(); sit ++ )
  1126. {
  1127. const std::string& fname = sit->second;
  1128. //std::cout << "File: " << fname << std::endl;
  1129. if ( strcmp(fname.substr(fname.size()-3, 3).c_str(), ".da") == 0 )
  1130. {
  1131. files.push_back(fname);
  1132. }
  1133. }
  1134. if ( files.size() == 0 )
  1135. {
  1136. std::cout << "Cannot find any coverage information files (.da)" << std::endl;
  1137. return 1;
  1138. }
  1139. std::ofstream log;
  1140. if (!this->OpenOutputFile("Temporary", "Coverage.log", log))
  1141. {
  1142. std::cout << "Cannot open log file" << std::endl;
  1143. return 1;
  1144. }
  1145. log.close();
  1146. if (!this->OpenOutputFile(m_CurrentTag, "Coverage.xml", log))
  1147. {
  1148. std::cout << "Cannot open log file" << std::endl;
  1149. return 1;
  1150. }
  1151. std::string opath = m_ToplevelPath + "/Testing/Temporary/Coverage";
  1152. cmSystemTools::MakeDirectory(opath.c_str());
  1153. for ( cc = 0; cc < files.size(); cc ++ )
  1154. {
  1155. std::string command = "gcov -l \"" + files[cc] + "\"";
  1156. std::string output;
  1157. int retVal = 0;
  1158. //std::cout << "Run gcov on " << files[cc] << std::flush;
  1159. //std::cout << " --- Run [" << command << "]" << std::endl;
  1160. bool res = true;
  1161. if ( !m_ShowOnly )
  1162. {
  1163. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  1164. &retVal, opath.c_str(),
  1165. m_Verbose, 0 /*m_TimeOut*/);
  1166. }
  1167. if ( res && retVal == 0 )
  1168. {
  1169. //std::cout << " - done" << std::endl;
  1170. }
  1171. else
  1172. {
  1173. //std::cout << " - fail" << std::endl;
  1174. }
  1175. }
  1176. files.clear();
  1177. glob = opath + "/*";
  1178. if ( !cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1179. {
  1180. std::cout << "Cannot found any coverage files" << std::endl;
  1181. return 1;
  1182. }
  1183. std::map<std::string, std::vector<std::string> > sourcefiles;
  1184. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1185. {
  1186. std::string& fname = cfiles[cc];
  1187. //std::cout << "File: " << fname << std::endl;
  1188. if ( strcmp(fname.substr(fname.size()-5, 5).c_str(), ".gcov") == 0 )
  1189. {
  1190. files.push_back(fname);
  1191. std::string::size_type pos = fname.find(".da.");
  1192. if ( pos != fname.npos )
  1193. {
  1194. pos += 4;
  1195. std::string::size_type epos = fname.size() - pos - strlen(".gcov");
  1196. std::string nf = fname.substr(pos, epos);
  1197. //std::cout << "Substring: " << nf << std::endl;
  1198. if ( allsourcefiles.find(nf) != allsourcefiles.end() ||
  1199. allbinaryfiles.find(nf) != allbinaryfiles.end() )
  1200. {
  1201. std::vector<std::string> &cvec = sourcefiles[nf];
  1202. cvec.push_back(fname);
  1203. }
  1204. }
  1205. }
  1206. }
  1207. for ( cc = 0; cc < files.size(); cc ++ )
  1208. {
  1209. //std::cout << "File: " << files[cc] << std::endl;
  1210. }
  1211. std::map<std::string, std::vector<std::string> >::iterator it;
  1212. cmCTest::tm_CoverageMap coverageresults;
  1213. log << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1214. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1215. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1216. << this->GetTestModelString() << "\" Name=\""
  1217. << m_DartConfiguration["Site"] << "\">\n"
  1218. << "<Coverage>\n"
  1219. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  1220. int total_tested = 0;
  1221. int total_untested = 0;
  1222. for ( it = sourcefiles.begin(); it != sourcefiles.end(); it ++ )
  1223. {
  1224. //std::cerr << "Source file: " << it->first << std::endl;
  1225. std::vector<std::string> &gfiles = it->second;
  1226. for ( cc = 0; cc < gfiles.size(); cc ++ )
  1227. {
  1228. //std::cout << "\t" << gfiles[cc] << std::endl;
  1229. std::ifstream ifile(gfiles[cc].c_str());
  1230. if ( !ifile )
  1231. {
  1232. std::cout << "Cannot open file: " << gfiles[cc].c_str() << std::endl;
  1233. }
  1234. ifile.seekg (0, std::ios::end);
  1235. int length = ifile.tellg();
  1236. ifile.seekg (0, std::ios::beg);
  1237. char *buffer = new char [ length + 1 ];
  1238. ifile.read(buffer, length);
  1239. buffer [length] = 0;
  1240. //std::cout << "Read: " << buffer << std::endl;
  1241. std::vector<cmStdString> lines;
  1242. cmSystemTools::Split(buffer, lines);
  1243. delete [] buffer;
  1244. cmCTest::cmCTestCoverage& cov = coverageresults[it->first];
  1245. std::vector<int>& covlines = cov.m_Lines;
  1246. if ( cov.m_FullPath == "" )
  1247. {
  1248. covlines.insert(covlines.begin(), lines.size(), -1);
  1249. if ( allsourcefiles.find(it->first) != allsourcefiles.end() )
  1250. {
  1251. cov.m_FullPath = allsourcefiles[it->first];
  1252. }
  1253. else if ( allbinaryfiles.find(it->first) != allbinaryfiles.end() )
  1254. {
  1255. cov.m_FullPath = allbinaryfiles[it->first];
  1256. }
  1257. cov.m_AbsolutePath = cov.m_FullPath;
  1258. std::string src_dir = m_DartConfiguration["SourceDirectory"];
  1259. if ( src_dir[src_dir.size()-1] != '/' )
  1260. {
  1261. src_dir = src_dir + "/";
  1262. }
  1263. std::string::size_type spos = cov.m_FullPath.find(src_dir);
  1264. if ( spos == 0 )
  1265. {
  1266. cov.m_FullPath = std::string("./") + cov.m_FullPath.substr(src_dir.size());
  1267. }
  1268. else
  1269. {
  1270. //std::cerr << "Compare -- " << cov.m_FullPath << std::endl;
  1271. //std::cerr << " -- " << src_dir << std::endl;
  1272. cov.m_Show = false;
  1273. continue;
  1274. }
  1275. cov.m_Show = true;
  1276. }
  1277. for ( cc = 0; cc < lines.size(); cc ++ )
  1278. {
  1279. std::string& line = lines[cc];
  1280. std::string sub = line.substr(0, strlen(" ######"));
  1281. int count = atoi(sub.c_str());
  1282. if ( sub.compare(" ######") == 0 )
  1283. {
  1284. if ( covlines[cc] == -1 )
  1285. {
  1286. covlines[cc] = 0;
  1287. }
  1288. cov.m_UnTested ++;
  1289. //std::cout << "Untested - ";
  1290. }
  1291. else if ( count > 0 )
  1292. {
  1293. if ( covlines[cc] == -1 )
  1294. {
  1295. covlines[cc] = 0;
  1296. }
  1297. cov.m_Tested ++;
  1298. covlines[cc] += count;
  1299. //std::cout << "Tested[" << count << "] - ";
  1300. }
  1301. //std::cout << line << std::endl;
  1302. }
  1303. }
  1304. }
  1305. //std::cerr << "Finalizing" << std::endl;
  1306. cmCTest::tm_CoverageMap::iterator cit;
  1307. int ccount = 0;
  1308. std::ofstream cfileoutput;
  1309. int cfileoutputcount = 0;
  1310. char cfileoutputname[100];
  1311. std::string local_start_time = ::CurrentTime();
  1312. std::string local_end_time;
  1313. for ( cit = coverageresults.begin(); cit != coverageresults.end(); cit ++ )
  1314. {
  1315. cmCTest::cmCTestCoverage &cov = cit->second;
  1316. if ( !cov.m_Show )
  1317. {
  1318. continue;
  1319. }
  1320. if ( ccount == 100 )
  1321. {
  1322. local_end_time = ::CurrentTime();
  1323. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1324. << "</CoverageLog>\n"
  1325. << "</Site>" << std::endl;
  1326. cfileoutput.close();
  1327. std::cout << "Close file: " << cfileoutputname << std::endl;
  1328. ccount = 0;
  1329. }
  1330. if ( ccount == 0 )
  1331. {
  1332. sprintf(cfileoutputname, "CoverageLog-%d.xml", cfileoutputcount++);
  1333. std::cout << "Open file: " << cfileoutputname << std::endl;
  1334. if (!this->OpenOutputFile(m_CurrentTag, cfileoutputname, cfileoutput))
  1335. {
  1336. std::cout << "Cannot open log file: " << cfileoutputname << std::endl;
  1337. return 1;
  1338. }
  1339. local_start_time = ::CurrentTime();
  1340. cfileoutput << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1341. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1342. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1343. << this->GetTestModelString() << "\" Site=\""
  1344. << m_DartConfiguration["Site"] << "\">\n"
  1345. << "<CoverageLog>\n"
  1346. << "\t<StartDateTime>" << local_start_time << "</StartDateTime>" << std::endl;
  1347. }
  1348. //std::cerr << "Final process of Source file: " << cit->first << std::endl;
  1349. std::ifstream ifile(cov.m_AbsolutePath.c_str());
  1350. if ( !ifile )
  1351. {
  1352. std::cerr << "Cannot open file: " << cov.m_FullPath.c_str() << std::endl;
  1353. }
  1354. ifile.seekg (0, std::ios::end);
  1355. int length = ifile.tellg();
  1356. ifile.seekg (0, std::ios::beg);
  1357. char *buffer = new char [ length + 1 ];
  1358. ifile.read(buffer, length);
  1359. buffer [length] = 0;
  1360. //std::cout << "Read: " << buffer << std::endl;
  1361. std::vector<cmStdString> lines;
  1362. cmSystemTools::Split(buffer, lines);
  1363. delete [] buffer;
  1364. cfileoutput << "\t<File Name=\"" << cit->first << "\" FullPath=\""
  1365. << cov.m_FullPath << "\">\n"
  1366. << "\t\t<Report>" << std::endl;
  1367. for ( cc = 0; cc < lines.size(); cc ++ )
  1368. {
  1369. cfileoutput << "\t\t<Line Number=\""
  1370. << static_cast<int>(cc) << "\" Count=\""
  1371. << cov.m_Lines[cc] << "\">"
  1372. << cmCTest::MakeXMLSafe(lines[cc]) << "</Line>" << std::endl;
  1373. }
  1374. cfileoutput << "\t\t</Report>\n"
  1375. << "\t</File>" << std::endl;
  1376. total_tested += cov.m_Tested;
  1377. total_untested += cov.m_UnTested;
  1378. float cper = 0;
  1379. float cmet = 0;
  1380. if ( total_tested + total_untested > 0 && (cov.m_Tested + cov.m_UnTested) > 0)
  1381. {
  1382. cper = (100 * SAFEDIV(static_cast<float>(cov.m_Tested),
  1383. static_cast<float>(cov.m_Tested + cov.m_UnTested)));
  1384. cmet = ( SAFEDIV(static_cast<float>(cov.m_Tested + 10),
  1385. static_cast<float>(cov.m_Tested + cov.m_UnTested + 10)));
  1386. }
  1387. log << "\t<File Name=\"" << cit->first << "\" FullPath=\"" << cov.m_FullPath
  1388. << "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n"
  1389. << "\t\t<LOCTested>" << cov.m_Tested << "</LOCTested>\n"
  1390. << "\t\t<LOCUnTested>" << cov.m_UnTested << "</LOCUnTested>\n"
  1391. << "\t\t<PercentCoverage>";
  1392. log.setf(std::ios::fixed, std::ios::floatfield);
  1393. log.precision(2);
  1394. log << (cper) << "</PercentCoverage>\n"
  1395. << "\t\t<CoverageMetric>";
  1396. log.setf(std::ios::fixed, std::ios::floatfield);
  1397. log.precision(2);
  1398. log << (cmet) << "</CoverageMetric>\n"
  1399. << "\t</File>" << std::endl;
  1400. ccount ++;
  1401. }
  1402. if ( ccount > 0 )
  1403. {
  1404. local_end_time = ::CurrentTime();
  1405. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1406. << "</CoverageLog>\n"
  1407. << "</Site>" << std::endl;
  1408. cfileoutput.close();
  1409. }
  1410. int total_lines = total_tested + total_untested;
  1411. float percent_coverage = 100 * SAFEDIV(static_cast<float>(total_tested),
  1412. static_cast<float>(total_lines));
  1413. if ( total_lines == 0 )
  1414. {
  1415. percent_coverage = 0;
  1416. }
  1417. std::string end_time = ::CurrentTime();
  1418. log << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
  1419. << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
  1420. << "\t<LOC>" << total_lines << "</LOC>\n"
  1421. << "\t<PercentCoverage>";
  1422. log.setf(std::ios::fixed, std::ios::floatfield);
  1423. log.precision(2);
  1424. log << (percent_coverage)<< "</PercentCoverage>\n"
  1425. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  1426. << "</Coverage>\n"
  1427. << "</Site>" << std::endl;
  1428. std::cout << "\tCovered LOC: " << total_tested << std::endl
  1429. << "\tNot covered LOC: " << total_untested << std::endl
  1430. << "\tTotal LOC: " << total_lines << std::endl
  1431. << "\tPercentage Coverage: ";
  1432. std::cout.setf(std::ios::fixed, std::ios::floatfield);
  1433. std::cout.precision(2);
  1434. std::cout << (percent_coverage) << "%" << std::endl;
  1435. return 1;
  1436. }
  1437. bool cmCTest::OpenOutputFile(const std::string& path,
  1438. const std::string& name, std::ofstream& stream)
  1439. {
  1440. std::string testingDir = m_ToplevelPath + "/Testing";
  1441. if ( path.size() > 0 )
  1442. {
  1443. testingDir += "/" + path;
  1444. }
  1445. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  1446. {
  1447. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  1448. {
  1449. std::cerr << "File " << testingDir
  1450. << " is in the place of the testing directory"
  1451. << std::endl;
  1452. return false;
  1453. }
  1454. }
  1455. else
  1456. {
  1457. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  1458. {
  1459. std::cerr << "Cannot create directory " << testingDir
  1460. << std::endl;
  1461. return false;
  1462. }
  1463. }
  1464. std::string filename = testingDir + "/" + name;
  1465. stream.open(filename.c_str());
  1466. if( !stream )
  1467. {
  1468. std::cout << "Problem opening file: " << filename << std::endl;
  1469. return false;
  1470. }
  1471. return true;
  1472. }
  1473. void cmCTest::GenerateDartBuildOutput(std::ostream& os,
  1474. std::vector<cmCTestBuildErrorWarning> ew)
  1475. {
  1476. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1477. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1478. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1479. << this->GetTestModelString() << "\" Name=\""
  1480. << m_DartConfiguration["Site"] << "\">\n"
  1481. << "<Build>\n"
  1482. << "\t<StartDateTime>" << m_StartBuild << "</StartDateTime>\n"
  1483. << "<BuildCommand>"
  1484. << this->MakeXMLSafe(m_DartConfiguration["MakeCommand"])
  1485. << "</BuildCommand>" << std::endl;
  1486. std::vector<cmCTestBuildErrorWarning>::iterator it;
  1487. for ( it = ew.begin(); it != ew.end(); it++ )
  1488. {
  1489. cmCTestBuildErrorWarning *cm = &(*it);
  1490. os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n"
  1491. << "\t\t<BuildLogLine>" << cm->m_LogLine << "</BuildLogLine>\n"
  1492. << "\t\t<Text>" << this->MakeXMLSafe(cm->m_Text)
  1493. << "\n</Text>" << std::endl;
  1494. if ( cm->m_SourceFile.size() > 0 )
  1495. {
  1496. os << "\t\t<SourceFile>" << cm->m_SourceFile << "</SourceFile>"
  1497. << std::endl;
  1498. }
  1499. if ( cm->m_SourceFileTail.size() > 0 )
  1500. {
  1501. os << "\t\t<SourceFileTail>" << cm->m_SourceFileTail
  1502. << "</SourceFileTail>" << std::endl;
  1503. }
  1504. if ( cm->m_LineNumber >= 0 )
  1505. {
  1506. os << "\t\t<SourceLineNumber>" << cm->m_LineNumber
  1507. << "</SourceLineNumber>" << std::endl;
  1508. }
  1509. os << "\t\t<PreContext>" << this->MakeXMLSafe(cm->m_PreContext)
  1510. << "</PreContext>\n"
  1511. << "\t\t<PostContext>" << this->MakeXMLSafe(cm->m_PostContext)
  1512. << "</PostContext>\n"
  1513. << "\t\t<RepeatCount>0</RepeatCount>\n"
  1514. << "</" << (cm->m_Error ? "Error" : "Warning") << ">\n\n"
  1515. << std::endl;
  1516. }
  1517. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  1518. << "\t<EndDateTime>" << m_EndBuild << "</EndDateTime>\n"
  1519. << "</Build>\n"
  1520. << "</Site>" << std::endl;
  1521. }
  1522. void cmCTest::ProcessDirectory(std::vector<std::string> &passed,
  1523. std::vector<std::string> &failed)
  1524. {
  1525. // does the DartTestfile.txt exist ?
  1526. if(!cmSystemTools::FileExists("DartTestfile.txt"))
  1527. {
  1528. return;
  1529. }
  1530. // parse the file
  1531. std::ifstream fin("DartTestfile.txt");
  1532. if(!fin)
  1533. {
  1534. return;
  1535. }
  1536. int firstTest = 1;
  1537. long line = 0;
  1538. #define SPACE_REGEX "[ \t\r\n]"
  1539. cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
  1540. cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
  1541. cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  1542. bool parseError;
  1543. while ( fin )
  1544. {
  1545. cmListFileFunction lff;
  1546. if(cmListFileCache::ParseFunction(fin, lff, "DartTestfile.txt",
  1547. parseError, line))
  1548. {
  1549. const std::string& name = lff.m_Name;
  1550. const std::vector<cmListFileArgument>& args = lff.m_Arguments;
  1551. if (name == "SUBDIRS")
  1552. {
  1553. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1554. for(std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1555. j != args.end(); ++j)
  1556. {
  1557. std::string nwd = cwd + "/";
  1558. nwd += j->Value;
  1559. if (cmSystemTools::FileIsDirectory(nwd.c_str()))
  1560. {
  1561. cmSystemTools::ChangeDirectory(nwd.c_str());
  1562. this->ProcessDirectory(passed, failed);
  1563. }
  1564. }
  1565. // return to the original directory
  1566. cmSystemTools::ChangeDirectory(cwd.c_str());
  1567. }
  1568. if (name == "ADD_TEST")
  1569. {
  1570. if (this->m_UseExcludeRegExp &&
  1571. this->m_UseExcludeRegExpFirst &&
  1572. ereg.find(args[0].Value.c_str()))
  1573. {
  1574. continue;
  1575. }
  1576. if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
  1577. {
  1578. continue;
  1579. }
  1580. if (this->m_UseExcludeRegExp &&
  1581. !this->m_UseExcludeRegExpFirst &&
  1582. ereg.find(args[0].Value.c_str()))
  1583. {
  1584. continue;
  1585. }
  1586. cmCTestTestResult cres;
  1587. cres.m_Status = cmCTest::NOT_RUN;
  1588. if (firstTest)
  1589. {
  1590. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1591. std::cerr << "Changing directory into " << nwd.c_str() << "\n";
  1592. firstTest = 0;
  1593. }
  1594. cres.m_Name = args[0].Value;
  1595. if ( m_ShowOnly )
  1596. {
  1597. std::cout << args[0].Value << std::endl;
  1598. }
  1599. else
  1600. {
  1601. fprintf(stderr,"Testing %-30s ",args[0].Value.c_str());
  1602. fflush(stderr);
  1603. }
  1604. //std::cerr << "Testing " << args[0] << " ... ";
  1605. // find the test executable
  1606. std::string testCommand = this->FindTheExecutable(args[1].Value.c_str());
  1607. testCommand = cmSystemTools::ConvertToOutputPath(testCommand.c_str());
  1608. std::string actualCommand = testCommand;
  1609. // continue if we did not find the executable
  1610. if (testCommand == "")
  1611. {
  1612. std::cerr << "Unable to find executable: " <<
  1613. args[1].Value.c_str() << "\n";
  1614. m_TestResults.push_back( cres );
  1615. continue;
  1616. }
  1617. // add the arguments
  1618. std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1619. ++j;
  1620. ++j;
  1621. std::vector<const char*> arguments;
  1622. arguments.push_back(actualCommand.c_str());
  1623. for(;j != args.end(); ++j)
  1624. {
  1625. testCommand += " ";
  1626. testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
  1627. arguments.push_back(j->Value.c_str());
  1628. }
  1629. arguments.push_back(0);
  1630. /**
  1631. * Run an executable command and put the stdout in output.
  1632. */
  1633. std::string output;
  1634. int retVal = 0;
  1635. double clock_start, clock_finish;
  1636. clock_start = cmSystemTools::GetTime();
  1637. if ( m_Verbose )
  1638. {
  1639. std::cout << std::endl << "Test command: " << testCommand << std::endl;
  1640. }
  1641. int res = 0;
  1642. if ( !m_ShowOnly )
  1643. {
  1644. res = this->RunTest(arguments, &output, &retVal);
  1645. }
  1646. clock_finish = cmSystemTools::GetTime();
  1647. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  1648. cres.m_FullCommandLine = testCommand;
  1649. if ( !m_ShowOnly )
  1650. {
  1651. if (res == cmsysProcess_State_Exited && retVal == 0)
  1652. {
  1653. fprintf(stderr," Passed\n");
  1654. passed.push_back(args[0].Value);
  1655. cres.m_Status = cmCTest::COMPLETED;
  1656. }
  1657. else
  1658. {
  1659. cres.m_Status = cmCTest::FAILED;
  1660. if ( res == cmsysProcess_State_Expired )
  1661. {
  1662. fprintf(stderr,"***Timeout\n");
  1663. cres.m_Status = cmCTest::TIMEOUT;
  1664. }
  1665. else if ( res == cmsysProcess_State_Exception )
  1666. {
  1667. fprintf(stderr,"***Exception: ");
  1668. switch ( retVal )
  1669. {
  1670. case cmsysProcess_Exception_Fault:
  1671. fprintf(stderr,"SegFault");
  1672. cres.m_Status = cmCTest::SEGFAULT;
  1673. break;
  1674. case cmsysProcess_Exception_Illegal:
  1675. fprintf(stderr,"Illegal");
  1676. cres.m_Status = cmCTest::ILLEGAL;
  1677. break;
  1678. case cmsysProcess_Exception_Interrupt:
  1679. fprintf(stderr,"Interrupt");
  1680. cres.m_Status = cmCTest::INTERRUPT;
  1681. break;
  1682. case cmsysProcess_Exception_Numerical:
  1683. fprintf(stderr,"Numerical");
  1684. cres.m_Status = cmCTest::NUMERICAL;
  1685. break;
  1686. default:
  1687. fprintf(stderr,"Other");
  1688. cres.m_Status = cmCTest::OTHER_FAULT;
  1689. }
  1690. fprintf(stderr,"\n");
  1691. }
  1692. else if ( res == cmsysProcess_State_Error )
  1693. {
  1694. fprintf(stderr,"***Bad command\n");
  1695. cres.m_Status = cmCTest::BAD_COMMAND;
  1696. }
  1697. else
  1698. {
  1699. fprintf(stderr,"***Failed\n");
  1700. }
  1701. failed.push_back(args[0].Value);
  1702. }
  1703. if (output != "")
  1704. {
  1705. if (dartStuff.find(output.c_str()))
  1706. {
  1707. std::string dartString = dartStuff.match(1);
  1708. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  1709. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  1710. }
  1711. }
  1712. }
  1713. cres.m_Output = output;
  1714. cres.m_ReturnValue = retVal;
  1715. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1716. if ( nwd.size() > m_ToplevelPath.size() )
  1717. {
  1718. nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
  1719. }
  1720. cmSystemTools::ReplaceString(nwd, "\\", "/");
  1721. cres.m_Path = nwd;
  1722. cres.m_CompletionStatus = "Completed";
  1723. m_TestResults.push_back( cres );
  1724. }
  1725. }
  1726. }
  1727. }
  1728. int cmCTest::TestDirectory()
  1729. {
  1730. std::cout << "Test project" << std::endl;
  1731. std::vector<std::string> passed;
  1732. std::vector<std::string> failed;
  1733. int total;
  1734. m_StartTest = ::CurrentTime();
  1735. this->ProcessDirectory(passed, failed);
  1736. m_EndTest = ::CurrentTime();
  1737. total = int(passed.size()) + int(failed.size());
  1738. if (total == 0)
  1739. {
  1740. if ( !m_ShowOnly )
  1741. {
  1742. std::cerr << "No tests were found!!!\n";
  1743. }
  1744. }
  1745. else
  1746. {
  1747. if (passed.size() && (m_UseIncludeRegExp || m_UseExcludeRegExp))
  1748. {
  1749. std::cerr << "\nThe following tests passed:\n";
  1750. for(std::vector<std::string>::iterator j = passed.begin();
  1751. j != passed.end(); ++j)
  1752. {
  1753. std::cerr << "\t" << *j << "\n";
  1754. }
  1755. }
  1756. float percent = float(passed.size()) * 100.0f / total;
  1757. fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  1758. percent, int(failed.size()), total);
  1759. if (failed.size())
  1760. {
  1761. std::cerr << "\nThe following tests FAILED:\n";
  1762. for(std::vector<std::string>::iterator j = failed.begin();
  1763. j != failed.end(); ++j)
  1764. {
  1765. std::cerr << "\t" << *j << "\n";
  1766. }
  1767. }
  1768. }
  1769. if ( m_DartMode )
  1770. {
  1771. std::ofstream ofs;
  1772. if( !this->OpenOutputFile(m_CurrentTag, "Test.xml", ofs) )
  1773. {
  1774. std::cerr << "Cannot create testing XML file" << std::endl;
  1775. return 1;
  1776. }
  1777. this->GenerateDartTestOutput(ofs);
  1778. }
  1779. return int(failed.size());
  1780. }
  1781. int cmCTest::SubmitResults()
  1782. {
  1783. #ifdef HAVE_CURL
  1784. std::vector<std::string> files;
  1785. std::string prefix = this->GetSubmitResultsPrefix();
  1786. // TODO:
  1787. // Check if test is enabled
  1788. if ( this->CTestFileExists("Update.xml") )
  1789. {
  1790. files.push_back("Update.xml");
  1791. }
  1792. if ( this->CTestFileExists("Configure.xml") )
  1793. {
  1794. files.push_back("Configure.xml");
  1795. }
  1796. if ( this->CTestFileExists("Build.xml") )
  1797. {
  1798. files.push_back("Build.xml");
  1799. }
  1800. if ( this->CTestFileExists("Test.xml") )
  1801. {
  1802. files.push_back("Test.xml");
  1803. }
  1804. if ( this->CTestFileExists("Coverage.xml") )
  1805. {
  1806. files.push_back("Coverage.xml");
  1807. std::vector<std::string> gfiles;
  1808. std::string gpath = m_ToplevelPath + "/Testing/" + m_CurrentTag;
  1809. std::string::size_type glen = gpath.size() + 1;
  1810. gpath = gpath + "/CoverageLog*";
  1811. //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
  1812. if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
  1813. {
  1814. size_t cc;
  1815. for ( cc = 0; cc < gfiles.size(); cc ++ )
  1816. {
  1817. gfiles[cc] = gfiles[cc].substr(glen);
  1818. //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
  1819. files.push_back(gfiles[cc]);
  1820. }
  1821. }
  1822. else
  1823. {
  1824. std::cout << "Problem globbing" << std::endl;
  1825. }
  1826. }
  1827. if ( this->CTestFileExists("Purify.xml") )
  1828. {
  1829. files.push_back("Purify.xml");
  1830. }
  1831. cmCTestSubmit submit;
  1832. submit.SetVerbose(m_Verbose);
  1833. if ( m_DartConfiguration["DropMethod"] == "" ||
  1834. m_DartConfiguration["DropMethod"] == "ftp" )
  1835. {
  1836. std::cout << " Using FTP submit method" << std::endl;
  1837. std::string url = "ftp://";
  1838. url += cmCTest::MakeURLSafe(m_DartConfiguration["DropSiteUser"]) + ":" +
  1839. cmCTest::MakeURLSafe(m_DartConfiguration["DropSitePassword"]) + "@" +
  1840. m_DartConfiguration["DropSite"] +
  1841. cmCTest::MakeURLSafe(m_DartConfiguration["DropLocation"]);
  1842. if ( !submit.SubmitUsingFTP(m_ToplevelPath+"/Testing/"+m_CurrentTag,
  1843. files, prefix, url) )
  1844. {
  1845. std::cout << " Problems when submitting via FTP" << std::endl;
  1846. return 0;
  1847. }
  1848. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  1849. {
  1850. std::cout << " Problems when triggering via HTTP" << std::endl;
  1851. return 0;
  1852. }
  1853. std::cout << " Submission successfull" << std::endl;
  1854. return 1;
  1855. }
  1856. else if ( m_DartConfiguration["DropMethod"] == "http" )
  1857. {
  1858. std::cout << " Using HTTP submit method" << std::endl;
  1859. std::string url = "http://";
  1860. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  1861. {
  1862. url += m_DartConfiguration["DropSiteUser"];
  1863. if ( m_DartConfiguration["DropSitePassword"].size() > 0 )
  1864. {
  1865. url += ":" + m_DartConfiguration["DropSitePassword"];
  1866. }
  1867. url += "@";
  1868. }
  1869. url += m_DartConfiguration["DropSite"] + m_DartConfiguration["DropLocation"];
  1870. if ( !submit.SubmitUsingHTTP(m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  1871. {
  1872. std::cout << " Problems when submitting via HTTP" << std::endl;
  1873. return 0;
  1874. }
  1875. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  1876. {
  1877. std::cout << " Problems when triggering via HTTP" << std::endl;
  1878. return 0;
  1879. }
  1880. std::cout << " Submission successfull" << std::endl;
  1881. return 1;
  1882. }
  1883. else
  1884. {
  1885. std::cout << "SCP submit not yet implemented" << std::endl;
  1886. }
  1887. #endif
  1888. return 0;
  1889. }
  1890. bool cmCTest::CTestFileExists(const std::string& filename)
  1891. {
  1892. std::string testingDir = m_ToplevelPath + "/Testing/" + m_CurrentTag + "/" +
  1893. filename;
  1894. return cmSystemTools::FileExists(testingDir.c_str());
  1895. }
  1896. std::string cmCTest::GetSubmitResultsPrefix()
  1897. {
  1898. std::string name = m_DartConfiguration["Site"] +
  1899. "___" + m_DartConfiguration["BuildName"] +
  1900. "___" + m_CurrentTag + "-" +
  1901. this->GetTestModelString() + "___XML___";
  1902. return name;
  1903. }
  1904. void cmCTest::GenerateDartTestOutput(std::ostream& os)
  1905. {
  1906. if ( !m_DartMode )
  1907. {
  1908. return;
  1909. }
  1910. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1911. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1912. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1913. << this->GetTestModelString() << "\" Name=\""
  1914. << m_DartConfiguration["Site"] << "\">\n"
  1915. << "<Testing>\n"
  1916. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  1917. << "\t<TestList>\n";
  1918. tm_TestResultsVector::size_type cc;
  1919. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  1920. {
  1921. cmCTestTestResult *result = &m_TestResults[cc];
  1922. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  1923. << "/" << this->MakeXMLSafe(result->m_Name)
  1924. << "</Test>" << std::endl;
  1925. }
  1926. os << "\t</TestList>\n";
  1927. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  1928. {
  1929. cmCTestTestResult *result = &m_TestResults[cc];
  1930. os << "\t<Test Status=\"";
  1931. if ( result->m_Status == cmCTest::COMPLETED )
  1932. {
  1933. os << "passed";
  1934. }
  1935. else if ( result->m_Status == cmCTest::NOT_RUN )
  1936. {
  1937. os << "notrun";
  1938. }
  1939. else
  1940. {
  1941. os << "failed";
  1942. }
  1943. os << "\">\n"
  1944. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  1945. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  1946. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  1947. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  1948. << "\t\t<FullCommandLine>"
  1949. << this->MakeXMLSafe(result->m_FullCommandLine)
  1950. << "</FullCommandLine>\n"
  1951. << "\t\t<Results>" << std::endl;
  1952. if ( result->m_Status != cmCTest::NOT_RUN )
  1953. {
  1954. if ( result->m_Status != cmCTest::COMPLETED || result->m_ReturnValue )
  1955. {
  1956. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  1957. << this->GetTestStatus(result->m_Status) << "</Value></NamedMeasurement>\n"
  1958. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  1959. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  1960. }
  1961. os << result->m_RegressionImages;
  1962. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  1963. << "name=\"Execution Time\"><Value>"
  1964. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n";
  1965. os
  1966. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1967. << "name=\"Completion Status\"><Value>"
  1968. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n";
  1969. }
  1970. os
  1971. << "\t\t\t<Measurement>\n"
  1972. << "\t\t\t\t<Value>" << this->MakeXMLSafe(result->m_Output)
  1973. << "</Value>\n"
  1974. << "\t\t\t</Measurement>\n"
  1975. << "\t\t</Results>\n"
  1976. << "\t</Test>" << std::endl;
  1977. }
  1978. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  1979. << "</Testing>\n"
  1980. << "</Site>" << std::endl;
  1981. }
  1982. int cmCTest::ProcessTests()
  1983. {
  1984. int res = 0;
  1985. bool notest = true;
  1986. int cc;
  1987. int update_count = 0;
  1988. for ( cc = 0; cc < LAST_TEST; cc ++ )
  1989. {
  1990. if ( m_Tests[cc] )
  1991. {
  1992. notest = false;
  1993. break;
  1994. }
  1995. }
  1996. if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
  1997. {
  1998. update_count = this->UpdateDirectory();
  1999. if ( update_count < 0 )
  2000. {
  2001. res += 1;
  2002. }
  2003. }
  2004. if ( m_TestModel == cmCTest::CONTINUOUS && !update_count )
  2005. {
  2006. return 0;
  2007. }
  2008. if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
  2009. {
  2010. res += this->ConfigureDirectory();
  2011. }
  2012. if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
  2013. {
  2014. res += this->BuildDirectory();
  2015. }
  2016. if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
  2017. {
  2018. res += this->TestDirectory();
  2019. }
  2020. if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
  2021. {
  2022. this->CoverageDirectory();
  2023. }
  2024. if ( m_Tests[PURIFY_TEST] || m_Tests[ALL_TEST] )
  2025. {
  2026. std::cerr << "Purify test is not yet implemented" << std::endl;
  2027. }
  2028. if ( m_Tests[SUBMIT_TEST] || m_Tests[ALL_TEST] )
  2029. {
  2030. #ifdef HAVE_CURL
  2031. this->SubmitResults();
  2032. #else
  2033. std::cerr << "Submit test is not yet implemented" << std::endl;
  2034. #endif
  2035. }
  2036. return res;
  2037. }
  2038. std::string cmCTest::GetTestModelString()
  2039. {
  2040. switch ( m_TestModel )
  2041. {
  2042. case cmCTest::NIGHTLY:
  2043. return "Nightly";
  2044. case cmCTest::CONTINUOUS:
  2045. return "Continuous";
  2046. }
  2047. return "Experimental";
  2048. }
  2049. std::string cmCTest::GenerateRegressionImages(const std::string& xml)
  2050. {
  2051. cmsys::RegularExpression twoattributes(
  2052. "<DartMeasurement"
  2053. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2054. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2055. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2056. cmsys::RegularExpression threeattributes(
  2057. "<DartMeasurement"
  2058. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2059. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2060. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2061. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2062. cmsys::RegularExpression fourattributes(
  2063. "<DartMeasurement"
  2064. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2065. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2066. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2067. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2068. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2069. cmsys::RegularExpression measurementfile(
  2070. "<DartMeasurementFile"
  2071. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2072. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2073. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  2074. cmOStringStream ostr;
  2075. bool done = false;
  2076. std::string cxml = xml;
  2077. while ( ! done )
  2078. {
  2079. if ( twoattributes.find(cxml) )
  2080. {
  2081. ostr
  2082. << "\t\t\t<NamedMeasurement"
  2083. << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
  2084. << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
  2085. << "><Value>" << twoattributes.match(5)
  2086. << "</Value></NamedMeasurement>"
  2087. << std::endl;
  2088. cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
  2089. }
  2090. else if ( threeattributes.find(cxml) )
  2091. {
  2092. ostr
  2093. << "\t\t\t<NamedMeasurement"
  2094. << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
  2095. << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
  2096. << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
  2097. << "><Value>" << threeattributes.match(7)
  2098. << "</Value></NamedMeasurement>"
  2099. << std::endl;
  2100. cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
  2101. }
  2102. else if ( fourattributes.find(cxml) )
  2103. {
  2104. ostr
  2105. << "\t\t\t<NamedMeasurement"
  2106. << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
  2107. << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
  2108. << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
  2109. << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
  2110. << "><Value>" << fourattributes.match(9)
  2111. << "</Value></NamedMeasurement>"
  2112. << std::endl;
  2113. cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
  2114. }
  2115. else if ( measurementfile.find(cxml) )
  2116. {
  2117. const std::string& filename = measurementfile.match(5);
  2118. if ( cmSystemTools::FileExists(filename.c_str()) )
  2119. {
  2120. long len = cmSystemTools::FileLength(filename.c_str());
  2121. std::ifstream ifs(filename.c_str(), std::ios::in
  2122. #ifdef _WIN32
  2123. | std::ios::binary
  2124. #endif
  2125. );
  2126. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  2127. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  2128. unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 1) ];
  2129. unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  2130. unsigned long cc;
  2131. ostr
  2132. << "\t\t\t<NamedMeasurement"
  2133. << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
  2134. << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
  2135. << " encoding=\"base64\""
  2136. << ">" << std::endl << "\t\t\t\t<Value>";
  2137. for ( cc = 0; cc < rlen; cc ++ )
  2138. {
  2139. ostr << encoded_buffer[cc];
  2140. if ( cc % 60 == 0 && cc )
  2141. {
  2142. ostr << std::endl;
  2143. }
  2144. }
  2145. ostr
  2146. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  2147. << std::endl;
  2148. delete [] file_buffer;
  2149. delete [] encoded_buffer;
  2150. }
  2151. else
  2152. {
  2153. int idx = 4;
  2154. if ( measurementfile.match(1) == "name" )
  2155. {
  2156. idx = 2;
  2157. }
  2158. ostr
  2159. << "\t\t\t<NamedMeasurement"
  2160. << " name=\"" << measurementfile.match(idx) << "\""
  2161. << " text=\"text/string\""
  2162. << "><Value>File " << filename << " not found</Value></NamedMeasurement>"
  2163. << std::endl;
  2164. }
  2165. cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
  2166. }
  2167. else
  2168. {
  2169. done = true;
  2170. }
  2171. }
  2172. return ostr.str();
  2173. }
  2174. int cmCTest::RunMakeCommand(const char* command, std::string* output,
  2175. int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs)
  2176. {
  2177. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  2178. if(args.size() < 1)
  2179. {
  2180. return false;
  2181. }
  2182. std::vector<const char*> argv;
  2183. for(std::vector<cmStdString>::const_iterator a = args.begin();
  2184. a != args.end(); ++a)
  2185. {
  2186. argv.push_back(a->c_str());
  2187. }
  2188. argv.push_back(0);
  2189. if ( output )
  2190. {
  2191. *output = "";
  2192. }
  2193. cmsysProcess* cp = cmsysProcess_New();
  2194. cmsysProcess_SetCommand(cp, &*argv.begin());
  2195. cmsysProcess_SetWorkingDirectory(cp, dir);
  2196. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2197. cmsysProcess_SetTimeout(cp, timeout);
  2198. cmsysProcess_Execute(cp);
  2199. std::string::size_type tick = 0;
  2200. std::string::size_type tick_len = 1024;
  2201. std::string::size_type tick_line_len = 50;
  2202. char* data;
  2203. int length;
  2204. if ( !verbose )
  2205. {
  2206. std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl;
  2207. std::cout << " " << std::flush;
  2208. }
  2209. while(cmsysProcess_WaitForData(cp, (cmsysProcess_Pipe_STDOUT |
  2210. cmsysProcess_Pipe_STDERR),
  2211. &data, &length, 0))
  2212. {
  2213. if ( output )
  2214. {
  2215. output->append(data, length);
  2216. if ( !verbose )
  2217. {
  2218. while ( output->size() > (tick * tick_len) )
  2219. {
  2220. tick ++;
  2221. std::cout << "." << std::flush;
  2222. if ( tick % tick_line_len == 0 && tick > 0 )
  2223. {
  2224. std::cout << " Size: ";
  2225. std::cout << int((output->size() / 1024.0) + 1) << "K" << std::endl;
  2226. std::cout << " " << std::flush;
  2227. }
  2228. }
  2229. }
  2230. }
  2231. if(verbose)
  2232. {
  2233. std::cout.write(data, length);
  2234. std::cout.flush();
  2235. }
  2236. if ( ofs )
  2237. {
  2238. ofs.write(data, length);
  2239. ofs.flush();
  2240. }
  2241. }
  2242. std::cout << " Size of output: ";
  2243. std::cout << int(output->size() / 1024.0) << "K" << std::endl;
  2244. cmsysProcess_WaitForExit(cp, 0);
  2245. int result = cmsysProcess_GetState(cp);
  2246. if(result == cmsysProcess_State_Exited)
  2247. {
  2248. *retVal = cmsysProcess_GetExitValue(cp);
  2249. }
  2250. else if(result == cmsysProcess_State_Exception)
  2251. {
  2252. *retVal = cmsysProcess_GetExitException(cp);
  2253. std::cout << "There was an exception: " << *retVal << std::endl;
  2254. }
  2255. else if(result == cmsysProcess_State_Expired)
  2256. {
  2257. std::cout << "There was a timeout" << std::endl;
  2258. }
  2259. else if(result == cmsysProcess_State_Error)
  2260. {
  2261. *output += "\n*** ERROR executing: ";
  2262. *output += cmsysProcess_GetErrorString(cp);
  2263. }
  2264. cmsysProcess_Delete(cp);
  2265. return result;
  2266. }
  2267. int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *retVal)
  2268. {
  2269. if ( output )
  2270. {
  2271. *output = "";
  2272. }
  2273. cmsysProcess* cp = cmsysProcess_New();
  2274. cmsysProcess_SetCommand(cp, &*argv.begin());
  2275. if(cmSystemTools::GetRunCommandHideConsole())
  2276. {
  2277. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2278. }
  2279. cmsysProcess_SetTimeout(cp, m_TimeOut);
  2280. cmsysProcess_Execute(cp);
  2281. char* data;
  2282. int length;
  2283. while(cmsysProcess_WaitForData(cp, (cmsysProcess_Pipe_STDOUT |
  2284. cmsysProcess_Pipe_STDERR),
  2285. &data, &length, 0))
  2286. {
  2287. if ( output )
  2288. {
  2289. output->append(data, length);
  2290. }
  2291. if ( m_Verbose )
  2292. {
  2293. std::cout.write(data, length);
  2294. std::cout.flush();
  2295. }
  2296. }
  2297. cmsysProcess_WaitForExit(cp, 0);
  2298. int result = cmsysProcess_GetState(cp);
  2299. if(result == cmsysProcess_State_Exited)
  2300. {
  2301. *retVal = cmsysProcess_GetExitValue(cp);
  2302. }
  2303. else if(result == cmsysProcess_State_Exception)
  2304. {
  2305. *retVal = cmsysProcess_GetExitException(cp);
  2306. }
  2307. else if(result == cmsysProcess_State_Error)
  2308. {
  2309. *output += "\n*** ERROR executing: ";
  2310. *output += cmsysProcess_GetErrorString(cp);
  2311. }
  2312. cmsysProcess_Delete(cp);
  2313. return result;
  2314. }
  2315. const char* cmCTest::GetTestStatus(int status)
  2316. {
  2317. static const char statuses[][100] = {
  2318. "Not Run",
  2319. "Timeout",
  2320. "SEGFAULT",
  2321. "ILLEGAL",
  2322. "INTERRUPT",
  2323. "NUMERICAL",
  2324. "OTHER_FAULT",
  2325. "Failed",
  2326. "BAD_COMMAND",
  2327. "Completed"
  2328. };
  2329. if ( status < cmCTest::NOT_RUN || status > cmCTest::COMPLETED )
  2330. {
  2331. return "No Status";
  2332. }
  2333. return statuses[status];
  2334. }