cmCTest.cxx 78 KB

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