cmCTest.cxx 73 KB

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