cmCTest.cxx 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348
  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. #include "cmCTestSubmit.h"
  21. #include "curl/curl.h"
  22. #include <cmsys/RegularExpression.hxx>
  23. #include <cmsys/Process.h>
  24. #include <cmsys/Base64.h>
  25. #include <stdlib.h>
  26. #include <time.h>
  27. #include <math.h>
  28. #include <float.h>
  29. #define SAFEDIV(x,y) (((y)!=0)?((x)/(y)):(0))
  30. // provide some more detailed info on the return code for ctest
  31. #define CTEST_UPDATE_ERRORS 0x01
  32. #define CTEST_CONFIGURE_ERRORS 0x02
  33. #define CTEST_BUILD_ERRORS 0x04
  34. #define CTEST_TEST_ERRORS 0x08
  35. #define CTEST_MEMORY_ERRORS 0x10
  36. static struct tm* GetNightlyTime(std::string str)
  37. {
  38. struct tm* lctime;
  39. time_t tctime = time(0);
  40. //Convert the nightly start time to seconds. Since we are
  41. //providing only a time and a timezone, the current date of
  42. //the local machine is assumed. Consequently, nightlySeconds
  43. //is the time at which the nightly dashboard was opened or
  44. //will be opened on the date of the current client machine.
  45. //As such, this time may be in the past or in the future.
  46. time_t ntime = curl_getdate(str.c_str(), &tctime);
  47. tctime = time(0);
  48. //std::cout << "Seconds: " << tctime << std::endl;
  49. if ( ntime > tctime )
  50. {
  51. // If nightlySeconds is in the past, this is the current
  52. // open dashboard, then return nightlySeconds. If
  53. // nightlySeconds is in the future, this is the next
  54. // dashboard to be opened, so subtract 24 hours to get the
  55. // time of the current open dashboard
  56. ntime -= (24 * 60 * 60 );
  57. //std::cout << "Pick yesterday" << std::endl;
  58. }
  59. //std::cout << "nightlySeconds: " << ntime << std::endl;
  60. lctime = gmtime(&ntime);
  61. return lctime;
  62. }
  63. static std::string CleanString(std::string str)
  64. {
  65. std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
  66. std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
  67. if ( spos == str.npos )
  68. {
  69. return std::string();
  70. }
  71. if ( epos != str.npos )
  72. {
  73. epos = epos - spos + 1;
  74. }
  75. return str.substr(spos, epos);
  76. }
  77. static std::string CurrentTime()
  78. {
  79. time_t currenttime = time(0);
  80. struct tm* t = localtime(&currenttime);
  81. //return ::CleanString(ctime(&currenttime));
  82. char current_time[1024];
  83. strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
  84. //std::cout << "Current_Time: " << current_time << std::endl;
  85. return ::CleanString(current_time);
  86. }
  87. static const char* cmCTestErrorMatches[] = {
  88. "^[Bb]us [Ee]rror",
  89. "^[Ss]egmentation [Vv]iolation",
  90. "^[Ss]egmentation [Ff]ault",
  91. "([^ :]+):([0-9]+): ([^ \\t])",
  92. "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
  93. "^Error ([0-9]+):",
  94. "^Fatal",
  95. "^Error: ",
  96. "^Error ",
  97. "[0-9] ERROR: ",
  98. "^\"[^\"]+\", line [0-9]+: [^Ww]",
  99. "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
  100. "^ld([^:])*:([ \\t])*ERROR([^:])*:",
  101. "^ild:([ \\t])*\\(undefined symbol\\)",
  102. "([^ :]+) : (error|fatal error|catastrophic error)",
  103. "([^:]+): (Error:|error|undefined reference|multiply defined)",
  104. "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
  105. "^fatal error C[0-9]+:",
  106. ": syntax error ",
  107. "^collect2: ld returned 1 exit status",
  108. "Unsatisfied symbols:",
  109. "Undefined symbols:",
  110. "^Undefined[ \\t]+first referenced",
  111. "^CMake Error:",
  112. ":[ \\t]cannot find",
  113. ":[ \\t]can't find",
  114. ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
  115. ": Invalid loader fixup for symbol",
  116. ": internal link edit command failed",
  117. ": Unrecognized option \\`.*\\'",
  118. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^W]\\)",
  119. "ld: 0706-006 Cannot find or open library file: -l ",
  120. 0
  121. };
  122. static const char* cmCTestErrorExceptions[] = {
  123. "instantiated from ",
  124. "candidates are:",
  125. ": warning",
  126. "makefile:",
  127. "Makefile:",
  128. ":[ \\t]+Where:",
  129. 0
  130. };
  131. static const char* cmCTestWarningMatches[] = {
  132. "([^ :]+):([0-9]+): warning:",
  133. "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
  134. "^ld([^:])*:([ \\t])*WARNING([^:])*:",
  135. "([^:]+): warning ([0-9]+):",
  136. "^\"[^\"]+\", line [0-9]+: [Ww]arning",
  137. "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
  138. "^Warning ([0-9]+):",
  139. "^Warning ",
  140. "WARNING: ",
  141. "([^ :]+) : warning",
  142. "([^:]+): warning",
  143. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\(W\\)",
  144. 0
  145. };
  146. static const char* cmCTestWarningExceptions[] = {
  147. "/usr/openwin/include/X11/Xlib\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  148. "/usr/openwin/include/X11/Xutil\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  149. "/usr/openwin/include/X11/XResource\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  150. "WARNING 84 :",
  151. "WARNING 47 :",
  152. "makefile:",
  153. "Makefile:",
  154. "warning: Clock skew detected. Your build may be incomplete.",
  155. "/usr/openwin/include/GL/[^:]+:",
  156. "bind_at_load",
  157. "XrmQGetResource",
  158. "IceFlush",
  159. "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
  160. "ld32: WARNING 85: definition of dataKey in",
  161. "cc: warning 422: Unknown option \"\\+b\\.\" ignored",
  162. "_with_warning_C",
  163. 0
  164. };
  165. static const char* cmCTestMemCheckResultStrings[] = {
  166. "ABR",
  167. "ABW",
  168. "ABWL",
  169. "COR",
  170. "EXU",
  171. "FFM",
  172. "FIM",
  173. "FMM",
  174. "FMR",
  175. "FMW",
  176. "FUM",
  177. "IPR",
  178. "IPW",
  179. "MAF",
  180. "MLK",
  181. "MPK",
  182. "NPR",
  183. "ODS",
  184. "PAR",
  185. "PLK",
  186. "UMC",
  187. "UMR",
  188. 0
  189. };
  190. std::string cmCTest::MakeXMLSafe(const std::string& str)
  191. {
  192. cmOStringStream ost;
  193. char buffer[10];
  194. int lcnt = 0;
  195. for (std::string::size_type pos = 0; pos < str.size(); pos ++ )
  196. {
  197. unsigned char ch = str[pos];
  198. if ( (ch > 126 || ch < 32) && ch != 9 && ch != 10 && ch != 13 )
  199. {
  200. sprintf(buffer, "&gt;%d&lt;", (int)ch);
  201. //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
  202. ost << buffer;
  203. lcnt += 4;
  204. }
  205. else
  206. {
  207. switch ( ch )
  208. {
  209. case '&': ost << "&amp;"; break;
  210. case '<': ost << "&lt;"; break;
  211. case '>': ost << "&gt;"; break;
  212. case '\n': ost << "\n"; lcnt = 0; break;
  213. default: ost << ch;
  214. }
  215. lcnt ++;
  216. }
  217. //if ( lcnt > 120 )
  218. // {
  219. // ost << "\n";
  220. // lcnt = 0;
  221. // }
  222. }
  223. return ost.str();
  224. }
  225. std::string cmCTest::MakeURLSafe(const std::string& str)
  226. {
  227. cmOStringStream ost;
  228. char buffer[10];
  229. for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
  230. {
  231. unsigned char ch = str[pos];
  232. if ( ( ch > 126 || ch < 32 ||
  233. ch == '&' ||
  234. ch == '%' ||
  235. ch == '+' ||
  236. ch == '=' ||
  237. ch == '@'
  238. ) && ch != 9 )
  239. {
  240. sprintf(buffer, "%02x;", (unsigned int)ch);
  241. ost << buffer;
  242. }
  243. else
  244. {
  245. ost << ch;
  246. }
  247. }
  248. return ost.str();
  249. }
  250. bool TryExecutable(const char *dir, const char *file,
  251. std::string *fullPath, const char *subdir)
  252. {
  253. // try current directory
  254. std::string tryPath;
  255. if (dir && strcmp(dir,""))
  256. {
  257. tryPath = dir;
  258. tryPath += "/";
  259. }
  260. if (subdir && strcmp(subdir,""))
  261. {
  262. tryPath += subdir;
  263. tryPath += "/";
  264. }
  265. tryPath += file;
  266. if(cmSystemTools::FileExists(tryPath.c_str()))
  267. {
  268. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  269. return true;
  270. }
  271. tryPath += cmSystemTools::GetExecutableExtension();
  272. if(cmSystemTools::FileExists(tryPath.c_str()))
  273. {
  274. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  275. return true;
  276. }
  277. return false;
  278. }
  279. cmCTest::cmCTest()
  280. {
  281. m_UseIncludeRegExp = false;
  282. m_UseExcludeRegExp = false;
  283. m_UseExcludeRegExpFirst = false;
  284. m_Verbose = false;
  285. m_DartMode = false;
  286. m_ShowOnly = false;
  287. m_RunConfigurationScript = false;
  288. m_TestModel = cmCTest::EXPERIMENTAL;
  289. m_TimeOut = 0;
  290. m_CompatibilityMode = 1;
  291. int cc;
  292. for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
  293. {
  294. m_Tests[cc] = 0;
  295. }
  296. }
  297. void cmCTest::Initialize()
  298. {
  299. m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
  300. cmSystemTools::ConvertToUnixSlashes(m_ToplevelPath);
  301. // parse the dart test file
  302. std::ifstream fin("DartConfiguration.tcl");
  303. if(!fin)
  304. {
  305. return;
  306. }
  307. char buffer[1024];
  308. while ( fin )
  309. {
  310. buffer[0] = 0;
  311. fin.getline(buffer, 1023);
  312. buffer[1023] = 0;
  313. std::string line = ::CleanString(buffer);
  314. if(line.size() == 0)
  315. {
  316. continue;
  317. }
  318. while ( fin && (line[line.size()-1] == '\\') )
  319. {
  320. line = line.substr(0, line.size()-1);
  321. buffer[0] = 0;
  322. fin.getline(buffer, 1023);
  323. buffer[1023] = 0;
  324. line += ::CleanString(buffer);
  325. }
  326. if ( line[0] == '#' )
  327. {
  328. continue;
  329. }
  330. std::string::size_type cpos = line.find_first_of(":");
  331. if ( cpos == line.npos )
  332. {
  333. continue;
  334. }
  335. std::string key = line.substr(0, cpos);
  336. std::string value = ::CleanString(line.substr(cpos+1, line.npos));
  337. m_DartConfiguration[key] = value;
  338. }
  339. fin.close();
  340. if ( m_DartMode )
  341. {
  342. m_TimeOut = atoi(m_DartConfiguration["TimeOut"].c_str());
  343. std::string testingDir = m_ToplevelPath + "/Testing";
  344. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  345. {
  346. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  347. {
  348. std::cerr << "File " << testingDir << " is in the place of the testing directory"
  349. << std::endl;
  350. return;
  351. }
  352. }
  353. else
  354. {
  355. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  356. {
  357. std::cerr << "Cannot create directory " << testingDir
  358. << std::endl;
  359. return;
  360. }
  361. }
  362. std::string tagfile = testingDir + "/TAG";
  363. std::ifstream tfin(tagfile.c_str());
  364. std::string tag;
  365. time_t tctime = time(0);
  366. struct tm *lctime = gmtime(&tctime);
  367. if ( tfin )
  368. {
  369. tfin >> tag;
  370. tfin.close();
  371. int year = 0;
  372. int mon = 0;
  373. int day = 0;
  374. int hour = 0;
  375. int min = 0;
  376. sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
  377. &year, &mon, &day, &hour, &min);
  378. if ( year != lctime->tm_year + 1900 ||
  379. mon != lctime->tm_mon+1 ||
  380. day != lctime->tm_mday )
  381. {
  382. tag = "";
  383. }
  384. }
  385. if ( tag.size() == 0 || m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST])
  386. {
  387. //std::cout << "TestModel: " << this->GetTestModelString() << std::endl;
  388. //std::cout << "TestModel: " << m_TestModel << std::endl;
  389. if ( m_TestModel == cmCTest::NIGHTLY )
  390. {
  391. lctime = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"]);
  392. }
  393. char datestring[100];
  394. sprintf(datestring, "%04d%02d%02d-%02d%02d",
  395. lctime->tm_year + 1900,
  396. lctime->tm_mon+1,
  397. lctime->tm_mday,
  398. lctime->tm_hour,
  399. lctime->tm_min);
  400. tag = datestring;
  401. std::ofstream ofs(tagfile.c_str());
  402. if ( ofs )
  403. {
  404. ofs << tag << std::endl;
  405. }
  406. ofs.close();
  407. std::cout << "Create new tag: " << tag << std::endl;
  408. }
  409. m_CurrentTag = tag;
  410. }
  411. }
  412. bool cmCTest::SetTest(const char* ttype)
  413. {
  414. if ( cmSystemTools::LowerCase(ttype) == "all" )
  415. {
  416. m_Tests[cmCTest::ALL_TEST] = 1;
  417. }
  418. else if ( cmSystemTools::LowerCase(ttype) == "start" )
  419. {
  420. m_Tests[cmCTest::START_TEST] = 1;
  421. }
  422. else if ( cmSystemTools::LowerCase(ttype) == "update" )
  423. {
  424. m_Tests[cmCTest::UPDATE_TEST] = 1;
  425. }
  426. else if ( cmSystemTools::LowerCase(ttype) == "configure" )
  427. {
  428. m_Tests[cmCTest::CONFIGURE_TEST] = 1;
  429. }
  430. else if ( cmSystemTools::LowerCase(ttype) == "build" )
  431. {
  432. m_Tests[cmCTest::BUILD_TEST] = 1;
  433. }
  434. else if ( cmSystemTools::LowerCase(ttype) == "test" )
  435. {
  436. m_Tests[cmCTest::TEST_TEST] = 1;
  437. }
  438. else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
  439. {
  440. m_Tests[cmCTest::COVERAGE_TEST] = 1;
  441. }
  442. else if ( cmSystemTools::LowerCase(ttype) == "memcheck" )
  443. {
  444. m_Tests[cmCTest::MEMCHECK_TEST] = 1;
  445. }
  446. else if ( cmSystemTools::LowerCase(ttype) == "notes" )
  447. {
  448. m_Tests[cmCTest::NOTES_TEST] = 1;
  449. }
  450. else if ( cmSystemTools::LowerCase(ttype) == "submit" )
  451. {
  452. m_Tests[cmCTest::SUBMIT_TEST] = 1;
  453. }
  454. else
  455. {
  456. std::cerr << "Don't know about test \"" << ttype << "\" yet..." << std::endl;
  457. return false;
  458. }
  459. return true;
  460. }
  461. void cmCTest::Finalize()
  462. {
  463. }
  464. std::string cmCTest::FindTheExecutable(const char *exe)
  465. {
  466. std::string fullPath = "";
  467. std::string dir;
  468. std::string file;
  469. cmSystemTools::SplitProgramPath(exe, dir, file);
  470. if(m_ConfigType != "" &&
  471. ::TryExecutable(dir.c_str(), file.c_str(), &fullPath,
  472. m_ConfigType.c_str()))
  473. {
  474. return fullPath;
  475. }
  476. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
  477. {
  478. return fullPath;
  479. }
  480. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
  481. {
  482. return fullPath;
  483. }
  484. if ( m_ConfigType == "" )
  485. {
  486. // No config type, so try to guess it
  487. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
  488. {
  489. return fullPath;
  490. }
  491. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
  492. {
  493. return fullPath;
  494. }
  495. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
  496. {
  497. return fullPath;
  498. }
  499. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
  500. {
  501. return fullPath;
  502. }
  503. }
  504. // if everything else failed, check the users path
  505. if (dir != "")
  506. {
  507. std::string path = cmSystemTools::FindProgram(file.c_str());
  508. if (path != "")
  509. {
  510. return path;
  511. }
  512. }
  513. if ( m_ConfigType != "" )
  514. {
  515. dir += "/";
  516. dir += m_ConfigType;
  517. dir += "/";
  518. dir += file;
  519. cmSystemTools::Error("config type specified on the command line, but test executable not found.",
  520. dir.c_str());
  521. return "";
  522. }
  523. return fullPath;
  524. }
  525. int cmCTest::UpdateDirectory()
  526. {
  527. int count = 0;
  528. std::string::size_type cc, kk;
  529. std::string cvsCommand = m_DartConfiguration["CVSCommand"];
  530. if ( cvsCommand.size() == 0 )
  531. {
  532. std::cerr << "Cannot find CVSCommand key in the DartConfiguration.tcl" << std::endl;
  533. return -1;
  534. }
  535. std::string cvsOptions = m_DartConfiguration["CVSUpdateOptions"];
  536. if ( cvsOptions.size() == 0 )
  537. {
  538. std::cerr << "Cannot find CVSUpdateOptions key in the DartConfiguration.tcl" << std::endl;
  539. return -1;
  540. }
  541. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  542. if ( sourceDirectory.size() == 0 )
  543. {
  544. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  545. return -1;
  546. }
  547. std::string extra_update_opts;
  548. if ( m_TestModel == cmCTest::NIGHTLY )
  549. {
  550. struct tm* t = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"]);
  551. char current_time[1024];
  552. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d UTC",
  553. t->tm_year + 1900,
  554. t->tm_mon + 1,
  555. t->tm_mday,
  556. t->tm_hour,
  557. t->tm_min,
  558. t->tm_sec);
  559. std::string today_update_date = current_time;
  560. extra_update_opts += "-D \"" + today_update_date +"\"";
  561. //std::cout << "Update: " << extra_update_opts << std::endl;
  562. }
  563. std::string command = cvsCommand + " -z3 update " + cvsOptions +
  564. " " + extra_update_opts;
  565. std::ofstream os;
  566. if ( !this->OpenOutputFile(m_CurrentTag, "Update.xml", os) )
  567. {
  568. std::cerr << "Cannot open log file" << std::endl;
  569. }
  570. std::string start_time = ::CurrentTime();
  571. std::string goutput;
  572. int retVal = 0;
  573. bool res = true;
  574. std::ofstream ofs;
  575. if ( !m_ShowOnly )
  576. {
  577. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  578. &retVal, sourceDirectory.c_str(),
  579. m_Verbose, 0 /*m_TimeOut*/);
  580. if ( this->OpenOutputFile("Temporary", "LastUpdate.log", ofs) )
  581. {
  582. ofs << goutput << std::endl;;
  583. }
  584. }
  585. else
  586. {
  587. std::cout << "Update with command: " << command << std::endl;
  588. }
  589. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  590. << "<Update mode=\"Client\">\n"
  591. << "\t<Site>" <<m_DartConfiguration["Site"] << "</Site>\n"
  592. << "\t<BuildName>" << m_DartConfiguration["BuildName"]
  593. << "</BuildName>\n"
  594. << "\t<BuildStamp>" << m_CurrentTag << "-"
  595. << this->GetTestModelString() << "</BuildStamp>" << std::endl;
  596. os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  597. << "\t<UpdateCommand>" << command << "</UpdateCommand>\n"
  598. << "\t<UpdateReturnStatus>";
  599. if ( retVal )
  600. {
  601. os << goutput;
  602. }
  603. os << "</UpdateReturnStatus>" << std::endl;
  604. std::vector<cmStdString> lines;
  605. cmSystemTools::Split(goutput.c_str(), lines);
  606. std::cout << "Updated; gathering version information" << std::endl;
  607. cmsys::RegularExpression date_author("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  608. cmsys::RegularExpression revision("^revision +([^ ]*) *$");
  609. cmsys::RegularExpression end_of_file("^=============================================================================$");
  610. cmsys::RegularExpression end_of_comment("^----------------------------$");
  611. std::string current_path = "";
  612. bool first_file = true;
  613. cmCTest::AuthorsToUpdatesMap authors_files_map;
  614. int num_updated = 0;
  615. int num_modified = 0;
  616. int num_conflicting = 0;
  617. for ( cc= 0 ; cc < lines.size(); cc ++ )
  618. {
  619. const char* line = lines[cc].c_str();
  620. char mod = line[0];
  621. if ( line[1] == ' ' && mod != '?' )
  622. {
  623. count ++;
  624. const char* file = line + 2;
  625. //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl;
  626. std::string logcommand = cvsCommand + " -z3 log -N " + file;
  627. //std::cout << "Do log: " << logcommand << std::endl;
  628. std::string output;
  629. res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output,
  630. &retVal, sourceDirectory.c_str(),
  631. m_Verbose, 0 /*m_TimeOut*/);
  632. if ( ofs )
  633. {
  634. ofs << output << std::endl;
  635. }
  636. if ( res && retVal == 0)
  637. {
  638. //std::cout << output << std::endl;
  639. std::vector<cmStdString> ulines;
  640. cmSystemTools::Split(output.c_str(), ulines);
  641. std::string::size_type sline = 0;
  642. std::string srevision1 = "Unknown";
  643. std::string sdate1 = "Unknown";
  644. std::string sauthor1 = "Unknown";
  645. std::string semail1 = "Unknown";
  646. std::string comment1 = "";
  647. std::string srevision2 = "Unknown";
  648. std::string sdate2 = "Unknown";
  649. std::string sauthor2 = "Unknown";
  650. std::string comment2 = "";
  651. std::string semail2 = "Unknown";
  652. bool have_first = false;
  653. bool have_second = false;
  654. for ( kk = 0; kk < ulines.size(); kk ++ )
  655. {
  656. const char* clp = ulines[kk].c_str();
  657. if ( !have_second && !sline && revision.find(clp) )
  658. {
  659. if ( !have_first )
  660. {
  661. srevision1 = revision.match(1);
  662. }
  663. else
  664. {
  665. srevision2 = revision.match(1);
  666. }
  667. }
  668. else if ( !have_second && !sline && date_author.find(clp) )
  669. {
  670. sline = kk + 1;
  671. if ( !have_first )
  672. {
  673. sdate1 = date_author.match(1);
  674. sauthor1 = date_author.match(2);
  675. }
  676. else
  677. {
  678. sdate2 = date_author.match(1);
  679. sauthor2 = date_author.match(2);
  680. }
  681. }
  682. else if ( sline && end_of_comment.find(clp) || end_of_file.find(clp))
  683. {
  684. if ( !have_first )
  685. {
  686. have_first = true;
  687. }
  688. else if ( !have_second )
  689. {
  690. have_second = true;
  691. }
  692. sline = 0;
  693. }
  694. else if ( sline )
  695. {
  696. if ( !have_first )
  697. {
  698. comment1 += clp;
  699. comment1 += "\n";
  700. }
  701. else
  702. {
  703. comment2 += clp;
  704. comment2 += "\n";
  705. }
  706. }
  707. }
  708. if ( mod == 'M' )
  709. {
  710. comment1 = "Locally modified file\n";
  711. }
  712. if ( mod == 'C' )
  713. {
  714. comment1 = "Conflict while updating\n";
  715. }
  716. std::string path = cmSystemTools::GetFilenamePath(file);
  717. std::string fname = cmSystemTools::GetFilenameName(file);
  718. if ( path != current_path )
  719. {
  720. if ( !first_file )
  721. {
  722. os << "\t</Directory>" << std::endl;
  723. }
  724. else
  725. {
  726. first_file = false;
  727. }
  728. os << "\t<Directory>\n"
  729. << "\t\t<Name>" << path << "</Name>" << std::endl;
  730. }
  731. if ( mod == 'C' )
  732. {
  733. num_conflicting ++;
  734. os << "\t<Conflicting>" << std::endl;
  735. }
  736. else if ( mod == 'M' )
  737. {
  738. num_modified ++;
  739. os << "\t<Modified>" << std::endl;
  740. }
  741. else
  742. {
  743. num_updated ++;
  744. os << "\t<Updated>" << std::endl;
  745. }
  746. if ( srevision2 == "Unknown" )
  747. {
  748. srevision2 = srevision1;
  749. }
  750. os << "\t\t<File Directory=\"" << path << "\">" << fname
  751. << "</File>\n"
  752. << "\t\t<Directory>" << path << "</Directory>\n"
  753. << "\t\t<FullName>" << file << "</FullName>\n"
  754. << "\t\t<CheckinDate>" << sdate1 << "</CheckinDate>\n"
  755. << "\t\t<Author>" << sauthor1 << "</Author>\n"
  756. << "\t\t<Email>" << semail1 << "</Email>\n"
  757. << "\t\t<Log>" << this->MakeXMLSafe(comment1) << "</Log>\n"
  758. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  759. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  760. << std::endl;
  761. if ( srevision2 != srevision1 )
  762. {
  763. os
  764. << "\t\t<Revisions>\n"
  765. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  766. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  767. << "\t\t\t<Author>" << sauthor1<< "</Author>\n"
  768. << "\t\t\t<Date>" << sdate1 << "</Date>\n"
  769. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment1) << "</Comment>\n"
  770. << "\t\t\t<Email>" << semail1 << "</Email>\n"
  771. << "\t\t</Revisions>\n"
  772. << "\t\t<Revisions>\n"
  773. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  774. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  775. << "\t\t\t<Author>" << sauthor2<< "</Author>\n"
  776. << "\t\t\t<Date>" << sdate2 << "</Date>\n"
  777. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment2) << "</Comment>\n"
  778. << "\t\t\t<Email>" << semail2 << "</Email>\n"
  779. << "\t\t</Revisions>" << std::endl;
  780. }
  781. if ( mod == 'C' )
  782. {
  783. os << "\t</Conflicting>" << std::endl;
  784. }
  785. else if ( mod == 'M' )
  786. {
  787. os << "\t</Modified>" << std::endl;
  788. }
  789. else
  790. {
  791. os << "\t</Updated>" << std::endl;
  792. }
  793. cmCTest::UpdateFiles *u = &authors_files_map[sauthor1];
  794. cmCTest::StringPair p;
  795. p.first = path;
  796. p.second = fname;
  797. u->push_back(p);
  798. current_path = path;
  799. }
  800. }
  801. }
  802. if ( num_updated )
  803. {
  804. std::cout << "Found " << num_updated << " updated files" << std::endl;
  805. }
  806. if ( num_modified )
  807. {
  808. std::cout << "Found " << num_modified << " locally modified files"
  809. << std::endl;
  810. }
  811. if ( num_conflicting )
  812. {
  813. std::cout << "Found " << num_conflicting << " conflicting files"
  814. << std::endl;
  815. }
  816. if ( !first_file )
  817. {
  818. os << "\t</Directory>" << std::endl;
  819. }
  820. cmCTest::AuthorsToUpdatesMap::iterator it;
  821. for ( it = authors_files_map.begin();
  822. it != authors_files_map.end();
  823. it ++ )
  824. {
  825. os << "\t<Author>\n"
  826. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  827. cmCTest::UpdateFiles *u = &(it->second);
  828. for ( cc = 0; cc < u->size(); cc ++ )
  829. {
  830. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  831. << (*u)[cc].second << "</File>" << std::endl;
  832. }
  833. os << "\t</Author>" << std::endl;
  834. }
  835. //std::cout << "End" << std::endl;
  836. std::string end_time = ::CurrentTime();
  837. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  838. << "</Update>" << std::endl;
  839. if ( ofs )
  840. {
  841. ofs.close();
  842. }
  843. if (! res || retVal )
  844. {
  845. std::cerr << "Error(s) when updating the project" << std::endl;
  846. std::cerr << "Output: " << goutput << std::endl;
  847. return -1;
  848. }
  849. return count;
  850. }
  851. int cmCTest::ConfigureDirectory()
  852. {
  853. std::cout << "Configure project" << std::endl;
  854. std::string cCommand = m_DartConfiguration["ConfigureCommand"];
  855. if ( cCommand.size() == 0 )
  856. {
  857. std::cerr << "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  858. << std::endl;
  859. return 1;
  860. }
  861. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  862. if ( buildDirectory.size() == 0 )
  863. {
  864. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  865. return 1;
  866. }
  867. std::string output;
  868. int retVal = 0;
  869. int res = 0;
  870. if ( !m_ShowOnly )
  871. {
  872. std::ofstream os;
  873. if ( !this->OpenOutputFile(m_CurrentTag, "Configure.xml", os) )
  874. {
  875. std::cerr << "Cannot open configure file" << std::endl;
  876. return 1;
  877. }
  878. std::string start_time = ::CurrentTime();
  879. std::ofstream ofs;
  880. this->OpenOutputFile("Temporary", "LastConfigure.log", ofs);
  881. res = this->RunMakeCommand(cCommand.c_str(), &output,
  882. &retVal, buildDirectory.c_str(),
  883. m_Verbose, 0, ofs);
  884. if ( ofs )
  885. {
  886. ofs.close();
  887. }
  888. if ( os )
  889. {
  890. this->StartXML(os);
  891. os << "<Configure>\n"
  892. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  893. if ( res == cmsysProcess_State_Exited && retVal )
  894. {
  895. os << retVal;
  896. }
  897. os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>" << std::endl;
  898. //std::cout << "End" << std::endl;
  899. os << "<Log>" << this->MakeXMLSafe(output) << "</Log>" << std::endl;
  900. std::string end_time = ::CurrentTime();
  901. os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
  902. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  903. << "</Configure>" << std::endl;
  904. this->EndXML(os);
  905. }
  906. }
  907. else
  908. {
  909. std::cout << "Configure with command: " << cCommand << std::endl;
  910. }
  911. if (! res || retVal )
  912. {
  913. std::cerr << "Error(s) when updating the project" << std::endl;
  914. return 1;
  915. }
  916. return 0;
  917. }
  918. int cmCTest::BuildDirectory()
  919. {
  920. std::cout << "Build project" << std::endl;
  921. std::string makeCommand = m_DartConfiguration["MakeCommand"];
  922. if ( makeCommand.size() == 0 )
  923. {
  924. std::cerr << "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl;
  925. return 1;
  926. }
  927. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  928. if ( buildDirectory.size() == 0 )
  929. {
  930. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  931. return 1;
  932. }
  933. std::ofstream ofs;
  934. if ( !this->OpenOutputFile("Temporary", "LastBuild.log", ofs) )
  935. {
  936. std::cerr << "Cannot create LastBuild.log file" << std::endl;
  937. }
  938. m_StartBuild = ::CurrentTime();
  939. std::string output;
  940. int retVal = 0;
  941. int res = cmsysProcess_State_Exited;
  942. if ( !m_ShowOnly )
  943. {
  944. res = this->RunMakeCommand(makeCommand.c_str(), &output,
  945. &retVal, buildDirectory.c_str(),
  946. m_Verbose, 0, ofs);
  947. }
  948. else
  949. {
  950. std::cout << "Build with command: " << makeCommand << std::endl;
  951. }
  952. m_EndBuild = ::CurrentTime();
  953. if (res != cmsysProcess_State_Exited || retVal )
  954. {
  955. std::cerr << "Error(s) when building project" << std::endl;
  956. }
  957. if ( ofs )
  958. {
  959. ofs.close();
  960. }
  961. int cc;
  962. if ( m_DartConfiguration["SourceDirectory"].size() > 20 ||
  963. m_DartConfiguration["BuildDirectory"].size() > 20 )
  964. {
  965. std::string srcdir = m_DartConfiguration["SourceDirectory"] + "/";
  966. std::string bindir = m_DartConfiguration["BuildDirectory"] + "/";
  967. std::string srcdirrep;
  968. std::string bindirrep;
  969. for ( cc = srcdir.size()-2; cc > 0; cc -- )
  970. {
  971. if ( srcdir[cc] == '/' )
  972. {
  973. srcdirrep = srcdir.c_str() + cc;
  974. srcdirrep = "/..." + srcdirrep;
  975. srcdir = srcdir.substr(0, cc+1);
  976. break;
  977. }
  978. }
  979. for ( cc = bindir.size()-2; cc > 0; cc -- )
  980. {
  981. if ( bindir[cc] == '/' )
  982. {
  983. bindirrep = bindir.c_str() + cc;
  984. bindirrep = "/..." + bindirrep;
  985. bindir = bindir.substr(0, cc+1);
  986. break;
  987. }
  988. }
  989. cmSystemTools::ReplaceString(output, srcdir.c_str(), "/.../"); //srcdirrep.c_str());
  990. cmSystemTools::ReplaceString(output, bindir.c_str(), "/.../"); //bindirrep.c_str());
  991. }
  992. // Parsing of output for errors and warnings.
  993. std::vector<cmStdString> lines;
  994. cmSystemTools::Split(output.c_str(), lines);
  995. // Lines are marked:
  996. // 0 - nothing
  997. // 1 - error
  998. // > 1 - warning
  999. std::vector<int> markedLines(lines.size(), 0);
  1000. // Errors
  1001. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  1002. {
  1003. cmsys::RegularExpression re(cmCTestErrorMatches[cc]);
  1004. cmCTest::tm_VectorOfStrings::size_type kk;
  1005. for ( kk = 0; kk < lines.size(); kk ++ )
  1006. {
  1007. if ( re.find(lines[kk]) )
  1008. {
  1009. markedLines[kk] = 1;
  1010. }
  1011. }
  1012. }
  1013. // Warnings
  1014. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  1015. {
  1016. cmsys::RegularExpression re(cmCTestWarningMatches[cc]);
  1017. cmCTest::tm_VectorOfStrings::size_type kk;
  1018. for ( kk = 0; kk < lines.size(); kk ++ )
  1019. {
  1020. if ( re.find(lines[kk]) )
  1021. {
  1022. markedLines[kk] += 2;
  1023. }
  1024. }
  1025. }
  1026. // Errors exceptions
  1027. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  1028. {
  1029. cmsys::RegularExpression re(cmCTestErrorExceptions[cc]);
  1030. std::vector<int>::size_type kk;
  1031. for ( kk =0; kk < markedLines.size(); kk ++ )
  1032. {
  1033. if ( markedLines[kk] == 1 )
  1034. {
  1035. if ( re.find(lines[kk]) )
  1036. {
  1037. markedLines[kk] = 0;
  1038. }
  1039. }
  1040. }
  1041. }
  1042. // Warning exceptions
  1043. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  1044. {
  1045. cmsys::RegularExpression re(cmCTestWarningExceptions[cc]);
  1046. std::vector<int>::size_type kk;
  1047. for ( kk =0; kk < markedLines.size(); kk ++ )
  1048. {
  1049. if ( markedLines[kk] > 1 )
  1050. {
  1051. if ( re.find(lines[kk]) )
  1052. {
  1053. markedLines[kk] = 0;
  1054. }
  1055. }
  1056. }
  1057. }
  1058. std::vector<cmCTestBuildErrorWarning> errorsWarnings;
  1059. int errors = 0;
  1060. int warnings = 0;
  1061. std::vector<int>::size_type kk;
  1062. cmCTestBuildErrorWarning errorwarning;
  1063. for ( kk =0; kk < markedLines.size(); kk ++ )
  1064. {
  1065. errorwarning.m_LineNumber = -1;
  1066. bool found = false;
  1067. if ( markedLines[kk] == 1 )
  1068. {
  1069. //std::cout << "Error: " << lines[kk] << std::endl;
  1070. errorwarning.m_Error = true;
  1071. found = true;
  1072. }
  1073. else if ( markedLines[kk] > 1 )
  1074. {
  1075. //std::cout << "Warning: " << lines[kk] << std::endl;
  1076. errorwarning.m_Error = false;
  1077. found = true;
  1078. }
  1079. if ( found )
  1080. {
  1081. errorwarning.m_LogLine = static_cast<int>(kk+1);
  1082. errorwarning.m_Text = lines[kk];
  1083. errorwarning.m_PreContext = "";
  1084. errorwarning.m_PostContext = "";
  1085. std::vector<int>::size_type jj;
  1086. std::vector<int>::size_type ll = 0;
  1087. if ( kk > 6 )
  1088. {
  1089. ll = kk - 6;
  1090. }
  1091. for ( jj = kk;
  1092. jj > 0 && jj > ll /* && markedLines[jj] == 0 */;
  1093. jj -- );
  1094. for (; jj < kk; jj ++ )
  1095. {
  1096. errorwarning.m_PreContext += lines[jj] + "\n";
  1097. }
  1098. for ( jj = kk+1;
  1099. jj < lines.size() && jj < kk + 7 /* && markedLines[jj] == 0*/;
  1100. jj ++ )
  1101. {
  1102. errorwarning.m_PostContext += lines[jj] + "\n";
  1103. }
  1104. errorsWarnings.push_back(errorwarning);
  1105. if ( errorwarning.m_Error )
  1106. {
  1107. errors ++;
  1108. }
  1109. else
  1110. {
  1111. warnings ++;
  1112. }
  1113. }
  1114. }
  1115. std::cout << " " << errors << " Compiler errors" << std::endl;
  1116. std::cout << " " << warnings << " Compiler warnings" << std::endl;
  1117. if( !this->OpenOutputFile(m_CurrentTag, "Build.xml", ofs) )
  1118. {
  1119. std::cerr << "Cannot create build XML file" << std::endl;
  1120. return 1;
  1121. }
  1122. this->GenerateDartBuildOutput(ofs, errorsWarnings);
  1123. return 0;
  1124. }
  1125. int cmCTest::CoverageDirectory()
  1126. {
  1127. std::cout << "Performing coverage" << std::endl;
  1128. cmCTest::tm_VectorOfStrings files;
  1129. cmCTest::tm_VectorOfStrings cfiles;
  1130. cmCTest::tm_VectorOfStrings cdirs;
  1131. bool done = false;
  1132. std::string::size_type cc;
  1133. std::string glob;
  1134. std::map<std::string, std::string> allsourcefiles;
  1135. std::map<std::string, std::string> allbinaryfiles;
  1136. std::string start_time = ::CurrentTime();
  1137. // Find all source files.
  1138. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  1139. if ( sourceDirectory.size() == 0 )
  1140. {
  1141. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  1142. return 1;
  1143. }
  1144. std::string coverageCommand = m_DartConfiguration["CoverageCommand"];
  1145. if ( coverageCommand.size() == 0 )
  1146. {
  1147. std::cerr << "Coverage command not defined in DartConfiguration.tcl" << std::endl;
  1148. return 1;
  1149. }
  1150. cdirs.push_back(sourceDirectory);
  1151. while ( !done )
  1152. {
  1153. if ( cdirs.size() <= 0 )
  1154. {
  1155. break;
  1156. }
  1157. glob = cdirs[cdirs.size()-1] + "/*";
  1158. //std::cout << "Glob: " << glob << std::endl;
  1159. cdirs.pop_back();
  1160. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1161. {
  1162. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1163. {
  1164. allsourcefiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1165. }
  1166. }
  1167. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1168. {
  1169. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1170. {
  1171. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1172. {
  1173. cdirs.push_back(cfiles[cc]);
  1174. }
  1175. }
  1176. }
  1177. }
  1178. // find all binary files
  1179. cdirs.push_back(cmSystemTools::GetCurrentWorkingDirectory());
  1180. while ( !done )
  1181. {
  1182. if ( cdirs.size() <= 0 )
  1183. {
  1184. break;
  1185. }
  1186. glob = cdirs[cdirs.size()-1] + "/*";
  1187. //std::cout << "Glob: " << glob << std::endl;
  1188. cdirs.pop_back();
  1189. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1190. {
  1191. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1192. {
  1193. allbinaryfiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1194. }
  1195. }
  1196. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1197. {
  1198. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1199. {
  1200. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1201. {
  1202. cdirs.push_back(cfiles[cc]);
  1203. }
  1204. }
  1205. }
  1206. }
  1207. std::map<std::string, std::string>::iterator sit;
  1208. for ( sit = allbinaryfiles.begin(); sit != allbinaryfiles.end(); sit ++ )
  1209. {
  1210. const std::string& fname = sit->second;
  1211. //std::cout << "File: " << fname << std::endl;
  1212. if ( strcmp(fname.substr(fname.size()-3, 3).c_str(), ".da") == 0 )
  1213. {
  1214. files.push_back(fname);
  1215. }
  1216. }
  1217. if ( files.size() == 0 )
  1218. {
  1219. std::cerr << "Cannot find any coverage information files (.da)" << std::endl;
  1220. return 1;
  1221. }
  1222. std::ofstream log;
  1223. if (!this->OpenOutputFile("Temporary", "Coverage.log", log))
  1224. {
  1225. std::cerr << "Cannot open log file" << std::endl;
  1226. return 1;
  1227. }
  1228. log.close();
  1229. if (!this->OpenOutputFile(m_CurrentTag, "Coverage.xml", log))
  1230. {
  1231. std::cerr << "Cannot open log file" << std::endl;
  1232. return 1;
  1233. }
  1234. std::string opath = m_ToplevelPath + "/Testing/Temporary/Coverage";
  1235. cmSystemTools::MakeDirectory(opath.c_str());
  1236. for ( cc = 0; cc < files.size(); cc ++ )
  1237. {
  1238. std::string command = coverageCommand + " -o \"" +
  1239. cmSystemTools::GetFilenamePath(files[cc]) +
  1240. "\" -l \"" + files[cc] + "\"";
  1241. std::string output;
  1242. int retVal = 0;
  1243. //std::cout << "Run gcov on " << files[cc] << std::flush;
  1244. //std::cout << " --- Run [" << command << "]" << std::endl;
  1245. bool res = true;
  1246. if ( !m_ShowOnly )
  1247. {
  1248. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  1249. &retVal, opath.c_str(),
  1250. m_Verbose, 0 /*m_TimeOut*/);
  1251. }
  1252. if ( res && retVal == 0 )
  1253. {
  1254. //std::cout << " - done" << std::endl;
  1255. }
  1256. else
  1257. {
  1258. std::cerr << "Run gcov on " << files[cc] << std::flush;
  1259. std::cerr << " [" << command << "]" << std::endl;
  1260. std::cerr << " - fail" << std::endl;
  1261. }
  1262. }
  1263. files.clear();
  1264. glob = opath + "/*";
  1265. if ( !cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1266. {
  1267. std::cerr << "Cannot found any coverage files" << std::endl;
  1268. return 1;
  1269. }
  1270. std::map<std::string, cmCTest::tm_VectorOfStrings > sourcefiles;
  1271. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1272. {
  1273. std::string& fname = cfiles[cc];
  1274. // std::cout << "File: " << fname << std::endl;
  1275. if ( strcmp(fname.substr(fname.size()-5, 5).c_str(), ".gcov") == 0 )
  1276. {
  1277. files.push_back(fname);
  1278. std::string::size_type pos = fname.find(".da.");
  1279. std::string::size_type pos2 = fname.find(".da##");
  1280. if(pos2 != fname.npos)
  1281. {
  1282. pos = pos2+1;
  1283. }
  1284. if ( pos != fname.npos )
  1285. {
  1286. pos += 4;
  1287. std::string::size_type epos = fname.size() - pos - strlen(".gcov");
  1288. std::string nf = fname.substr(pos, epos);
  1289. //std::cout << "Substring: " << nf << std::endl;
  1290. if ( allsourcefiles.find(nf) != allsourcefiles.end() ||
  1291. allbinaryfiles.find(nf) != allbinaryfiles.end() )
  1292. {
  1293. cmCTest::tm_VectorOfStrings &cvec = sourcefiles[nf];
  1294. cvec.push_back(fname);
  1295. }
  1296. }
  1297. }
  1298. }
  1299. // for ( cc = 0; cc < files.size(); cc ++ )
  1300. // {
  1301. // std::cout << "File: " << files[cc] << std::endl;
  1302. // }
  1303. std::map<std::string, cmCTest::tm_VectorOfStrings >::iterator it;
  1304. cmCTest::tm_CoverageMap coverageresults;
  1305. this->StartXML(log);
  1306. log << "<Coverage>\n"
  1307. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  1308. int total_tested = 0;
  1309. int total_untested = 0;
  1310. for ( it = sourcefiles.begin(); it != sourcefiles.end(); it ++ )
  1311. {
  1312. //std::cerr << "Source file: " << it->first << std::endl;
  1313. cmCTest::tm_VectorOfStrings &gfiles = it->second;
  1314. for ( cc = 0; cc < gfiles.size(); cc ++ )
  1315. {
  1316. //std::cout << "\t" << gfiles[cc] << std::endl;
  1317. std::ifstream ifile(gfiles[cc].c_str());
  1318. if ( !ifile )
  1319. {
  1320. std::cerr << "Cannot open file: " << gfiles[cc].c_str() << std::endl;
  1321. }
  1322. ifile.seekg (0, std::ios::end);
  1323. int length = ifile.tellg();
  1324. ifile.seekg (0, std::ios::beg);
  1325. char *buffer = new char [ length + 1 ];
  1326. ifile.read(buffer, length);
  1327. buffer [length] = 0;
  1328. //std::cout << "Read: " << buffer << std::endl;
  1329. std::vector<cmStdString> lines;
  1330. cmSystemTools::Split(buffer, lines);
  1331. delete [] buffer;
  1332. cmCTest::cmCTestCoverage& cov = coverageresults[it->first];
  1333. std::vector<int>& covlines = cov.m_Lines;
  1334. if ( cov.m_FullPath == "" )
  1335. {
  1336. covlines.insert(covlines.begin(), lines.size(), -1);
  1337. if ( allsourcefiles.find(it->first) != allsourcefiles.end() )
  1338. {
  1339. cov.m_FullPath = allsourcefiles[it->first];
  1340. }
  1341. else if ( allbinaryfiles.find(it->first) != allbinaryfiles.end() )
  1342. {
  1343. cov.m_FullPath = allbinaryfiles[it->first];
  1344. }
  1345. cov.m_AbsolutePath = cov.m_FullPath;
  1346. std::string src_dir = m_DartConfiguration["SourceDirectory"];
  1347. if ( src_dir[src_dir.size()-1] != '/' )
  1348. {
  1349. src_dir = src_dir + "/";
  1350. }
  1351. std::string::size_type spos = cov.m_FullPath.find(src_dir);
  1352. if ( spos == 0 )
  1353. {
  1354. cov.m_FullPath = std::string("./") + cov.m_FullPath.substr(src_dir.size());
  1355. }
  1356. else
  1357. {
  1358. //std::cerr << "Compare -- " << cov.m_FullPath << std::endl;
  1359. //std::cerr << " -- " << src_dir << std::endl;
  1360. cov.m_Show = false;
  1361. continue;
  1362. }
  1363. cov.m_Show = true;
  1364. }
  1365. std::string::size_type kk;
  1366. // std::cerr << "number of lines " << lines.size() << "\n";
  1367. for ( kk = 0; kk < lines.size(); kk ++ )
  1368. {
  1369. std::string& line = lines[kk];
  1370. //std::cerr << line << "\n";
  1371. std::string sub1 = line.substr(0, strlen(" #####"));
  1372. std::string sub2 = line.substr(0, strlen(" ######"));
  1373. int count = atoi(sub2.c_str());
  1374. if ( sub1.compare(" #####") == 0 ||
  1375. sub2.compare(" ######") == 0 )
  1376. {
  1377. if ( covlines[kk] == -1 )
  1378. {
  1379. covlines[kk] = 0;
  1380. }
  1381. cov.m_UnTested ++;
  1382. //std::cout << "Untested - ";
  1383. }
  1384. else if ( count > 0 )
  1385. {
  1386. if ( covlines[kk] == -1 )
  1387. {
  1388. covlines[kk] = 0;
  1389. }
  1390. cov.m_Tested ++;
  1391. covlines[kk] ++;
  1392. //std::cout << "Tested[" << count << "] - ";
  1393. }
  1394. //std::cout << line << std::endl;
  1395. }
  1396. }
  1397. }
  1398. //std::cerr << "Finalizing" << std::endl;
  1399. cmCTest::tm_CoverageMap::iterator cit;
  1400. int ccount = 0;
  1401. std::ofstream cfileoutput;
  1402. int cfileoutputcount = 0;
  1403. char cfileoutputname[100];
  1404. std::string local_start_time = ::CurrentTime();
  1405. std::string local_end_time;
  1406. for ( cit = coverageresults.begin(); cit != coverageresults.end(); cit ++ )
  1407. {
  1408. cmCTest::cmCTestCoverage &cov = cit->second;
  1409. if ( !cov.m_Show )
  1410. {
  1411. continue;
  1412. }
  1413. // Check if we should ignore the directory
  1414. std::string coverage_dir = cmSystemTools::GetFilenamePath(cov.m_AbsolutePath.c_str());
  1415. coverage_dir += "/.NoDartCoverage";
  1416. if ( cmSystemTools::FileExists(coverage_dir.c_str()) )
  1417. {
  1418. if ( m_Verbose )
  1419. {
  1420. std::cout << "Ignore file: " << cov.m_FullPath.c_str() << std::endl;
  1421. }
  1422. continue;
  1423. }
  1424. if ( ccount == 100 )
  1425. {
  1426. local_end_time = ::CurrentTime();
  1427. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1428. << "</CoverageLog>" << std::endl;
  1429. this->EndXML(cfileoutput);
  1430. cfileoutput.close();
  1431. std::cout << "Close file: " << cfileoutputname << std::endl;
  1432. ccount = 0;
  1433. }
  1434. if ( ccount == 0 )
  1435. {
  1436. sprintf(cfileoutputname, "CoverageLog-%d.xml", cfileoutputcount++);
  1437. std::cout << "Open file: " << cfileoutputname << std::endl;
  1438. if (!this->OpenOutputFile(m_CurrentTag, cfileoutputname, cfileoutput))
  1439. {
  1440. std::cerr << "Cannot open log file: " << cfileoutputname << std::endl;
  1441. return 1;
  1442. }
  1443. local_start_time = ::CurrentTime();
  1444. this->StartXML(cfileoutput);
  1445. cfileoutput << "<CoverageLog>\n"
  1446. << "\t<StartDateTime>" << local_start_time << "</StartDateTime>" << std::endl;
  1447. }
  1448. //std::cerr << "Final process of Source file: " << cit->first << std::endl;
  1449. cov.m_UnTested = 0;
  1450. cov.m_Tested = 0;
  1451. for ( cc = 0; cc < cov.m_Lines.size(); cc ++ )
  1452. {
  1453. if ( cov.m_Lines[cc] == 0 )
  1454. {
  1455. cov.m_UnTested ++;
  1456. }
  1457. else if ( cov.m_Lines[cc] > 0 )
  1458. {
  1459. cov.m_Tested ++;
  1460. }
  1461. }
  1462. std::ifstream ifile(cov.m_AbsolutePath.c_str());
  1463. if ( !ifile )
  1464. {
  1465. std::cerr << "Cannot open file: " << cov.m_FullPath.c_str() << std::endl;
  1466. }
  1467. ifile.seekg (0, std::ios::end);
  1468. int length = ifile.tellg();
  1469. ifile.seekg (0, std::ios::beg);
  1470. char *buffer = new char [ length + 1 ];
  1471. ifile.read(buffer, length);
  1472. buffer [length] = 0;
  1473. //std::cout << "Read: " << buffer << std::endl;
  1474. std::vector<cmStdString> lines;
  1475. cmSystemTools::Split(buffer, lines);
  1476. delete [] buffer;
  1477. cfileoutput << "\t<File Name=\"" << cit->first << "\" FullPath=\""
  1478. << cov.m_FullPath << "\">\n"
  1479. << "\t\t<Report>" << std::endl;
  1480. for ( cc = 0; cc < lines.size(); cc ++ )
  1481. {
  1482. cfileoutput << "\t\t<Line Number=\""
  1483. << static_cast<int>(cc) << "\" Count=\""
  1484. << cov.m_Lines[cc] << "\">"
  1485. << cmCTest::MakeXMLSafe(lines[cc]) << "</Line>" << std::endl;
  1486. }
  1487. cfileoutput << "\t\t</Report>\n"
  1488. << "\t</File>" << std::endl;
  1489. total_tested += cov.m_Tested;
  1490. total_untested += cov.m_UnTested;
  1491. float cper = 0;
  1492. float cmet = 0;
  1493. if ( total_tested + total_untested > 0 && (cov.m_Tested + cov.m_UnTested) > 0)
  1494. {
  1495. cper = (100 * SAFEDIV(static_cast<float>(cov.m_Tested),
  1496. static_cast<float>(cov.m_Tested + cov.m_UnTested)));
  1497. cmet = ( SAFEDIV(static_cast<float>(cov.m_Tested + 10),
  1498. static_cast<float>(cov.m_Tested + cov.m_UnTested + 10)));
  1499. }
  1500. log << "\t<File Name=\"" << cit->first << "\" FullPath=\"" << cov.m_FullPath
  1501. << "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n"
  1502. << "\t\t<LOCTested>" << cov.m_Tested << "</LOCTested>\n"
  1503. << "\t\t<LOCUnTested>" << cov.m_UnTested << "</LOCUnTested>\n"
  1504. << "\t\t<PercentCoverage>";
  1505. log.setf(std::ios::fixed, std::ios::floatfield);
  1506. log.precision(2);
  1507. log << (cper) << "</PercentCoverage>\n"
  1508. << "\t\t<CoverageMetric>";
  1509. log.setf(std::ios::fixed, std::ios::floatfield);
  1510. log.precision(2);
  1511. log << (cmet) << "</CoverageMetric>\n"
  1512. << "\t</File>" << std::endl;
  1513. ccount ++;
  1514. }
  1515. if ( ccount > 0 )
  1516. {
  1517. local_end_time = ::CurrentTime();
  1518. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1519. << "</CoverageLog>" << std::endl;
  1520. this->EndXML(cfileoutput);
  1521. cfileoutput.close();
  1522. }
  1523. int total_lines = total_tested + total_untested;
  1524. float percent_coverage = 100 * SAFEDIV(static_cast<float>(total_tested),
  1525. static_cast<float>(total_lines));
  1526. if ( total_lines == 0 )
  1527. {
  1528. percent_coverage = 0;
  1529. }
  1530. std::string end_time = ::CurrentTime();
  1531. log << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
  1532. << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
  1533. << "\t<LOC>" << total_lines << "</LOC>\n"
  1534. << "\t<PercentCoverage>";
  1535. log.setf(std::ios::fixed, std::ios::floatfield);
  1536. log.precision(2);
  1537. log << (percent_coverage)<< "</PercentCoverage>\n"
  1538. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  1539. << "</Coverage>" << std::endl;
  1540. this->EndXML(log);
  1541. std::cout << "\tCovered LOC: " << total_tested << std::endl
  1542. << "\tNot covered LOC: " << total_untested << std::endl
  1543. << "\tTotal LOC: " << total_lines << std::endl
  1544. << "\tPercentage Coverage: ";
  1545. std::cout.setf(std::ios::fixed, std::ios::floatfield);
  1546. std::cout.precision(2);
  1547. std::cout << (percent_coverage) << "%" << std::endl;
  1548. return 1;
  1549. }
  1550. bool cmCTest::OpenOutputFile(const std::string& path,
  1551. const std::string& name, std::ofstream& stream)
  1552. {
  1553. std::string testingDir = m_ToplevelPath + "/Testing";
  1554. if ( path.size() > 0 )
  1555. {
  1556. testingDir += "/" + path;
  1557. }
  1558. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  1559. {
  1560. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  1561. {
  1562. std::cerr << "File " << testingDir
  1563. << " is in the place of the testing directory"
  1564. << std::endl;
  1565. return false;
  1566. }
  1567. }
  1568. else
  1569. {
  1570. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  1571. {
  1572. std::cerr << "Cannot create directory " << testingDir
  1573. << std::endl;
  1574. return false;
  1575. }
  1576. }
  1577. std::string filename = testingDir + "/" + name;
  1578. stream.open(filename.c_str());
  1579. if( !stream )
  1580. {
  1581. std::cerr << "Problem opening file: " << filename << std::endl;
  1582. return false;
  1583. }
  1584. return true;
  1585. }
  1586. void cmCTest::GenerateDartBuildOutput(std::ostream& os,
  1587. std::vector<cmCTestBuildErrorWarning> ew)
  1588. {
  1589. this->StartXML(os);
  1590. os << "<Build>\n"
  1591. << "\t<StartDateTime>" << m_StartBuild << "</StartDateTime>\n"
  1592. << "<BuildCommand>"
  1593. << this->MakeXMLSafe(m_DartConfiguration["MakeCommand"])
  1594. << "</BuildCommand>" << std::endl;
  1595. std::vector<cmCTestBuildErrorWarning>::iterator it;
  1596. for ( it = ew.begin(); it != ew.end(); it++ )
  1597. {
  1598. cmCTestBuildErrorWarning *cm = &(*it);
  1599. os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n"
  1600. << "\t\t<BuildLogLine>" << cm->m_LogLine << "</BuildLogLine>\n"
  1601. << "\t\t<Text>" << this->MakeXMLSafe(cm->m_Text)
  1602. << "\n</Text>" << std::endl;
  1603. if ( cm->m_SourceFile.size() > 0 )
  1604. {
  1605. os << "\t\t<SourceFile>" << cm->m_SourceFile << "</SourceFile>"
  1606. << std::endl;
  1607. }
  1608. if ( cm->m_SourceFileTail.size() > 0 )
  1609. {
  1610. os << "\t\t<SourceFileTail>" << cm->m_SourceFileTail
  1611. << "</SourceFileTail>" << std::endl;
  1612. }
  1613. if ( cm->m_LineNumber >= 0 )
  1614. {
  1615. os << "\t\t<SourceLineNumber>" << cm->m_LineNumber
  1616. << "</SourceLineNumber>" << std::endl;
  1617. }
  1618. os << "\t\t<PreContext>" << this->MakeXMLSafe(cm->m_PreContext)
  1619. << "</PreContext>\n"
  1620. << "\t\t<PostContext>" << this->MakeXMLSafe(cm->m_PostContext)
  1621. << "</PostContext>\n"
  1622. << "\t\t<RepeatCount>0</RepeatCount>\n"
  1623. << "</" << (cm->m_Error ? "Error" : "Warning") << ">\n\n"
  1624. << std::endl;
  1625. }
  1626. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  1627. << "\t<EndDateTime>" << m_EndBuild << "</EndDateTime>\n"
  1628. << "</Build>" << std::endl;
  1629. this->EndXML(os);
  1630. }
  1631. void cmCTest::ProcessDirectory(cmCTest::tm_VectorOfStrings &passed,
  1632. cmCTest::tm_VectorOfStrings &failed,
  1633. bool memcheck)
  1634. {
  1635. // does the DartTestfile.txt exist ?
  1636. if(!cmSystemTools::FileExists("DartTestfile.txt"))
  1637. {
  1638. return;
  1639. }
  1640. // parse the file
  1641. std::ifstream fin("DartTestfile.txt");
  1642. if(!fin)
  1643. {
  1644. return;
  1645. }
  1646. int firstTest = 1;
  1647. cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
  1648. cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
  1649. cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  1650. cmListFileCache cache;
  1651. cmListFile* listFile = cache.GetFileCache("DartTestfile.txt", false);
  1652. for(std::vector<cmListFileFunction>::const_iterator f =
  1653. listFile->m_Functions.begin(); f != listFile->m_Functions.end(); ++f)
  1654. {
  1655. const cmListFileFunction& lff = *f;
  1656. const std::string& name = lff.m_Name;
  1657. const std::vector<cmListFileArgument>& args = lff.m_Arguments;
  1658. if (name == "SUBDIRS")
  1659. {
  1660. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1661. for(std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1662. j != args.end(); ++j)
  1663. {
  1664. std::string nwd = cwd + "/";
  1665. nwd += j->Value;
  1666. if (cmSystemTools::FileIsDirectory(nwd.c_str()))
  1667. {
  1668. cmSystemTools::ChangeDirectory(nwd.c_str());
  1669. this->ProcessDirectory(passed, failed, memcheck);
  1670. }
  1671. }
  1672. // return to the original directory
  1673. cmSystemTools::ChangeDirectory(cwd.c_str());
  1674. }
  1675. if (name == "ADD_TEST")
  1676. {
  1677. if (this->m_UseExcludeRegExp &&
  1678. this->m_UseExcludeRegExpFirst &&
  1679. ereg.find(args[0].Value.c_str()))
  1680. {
  1681. continue;
  1682. }
  1683. if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
  1684. {
  1685. continue;
  1686. }
  1687. if (this->m_UseExcludeRegExp &&
  1688. !this->m_UseExcludeRegExpFirst &&
  1689. ereg.find(args[0].Value.c_str()))
  1690. {
  1691. continue;
  1692. }
  1693. cmCTestTestResult cres;
  1694. cres.m_Status = cmCTest::NOT_RUN;
  1695. if (firstTest)
  1696. {
  1697. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1698. if ( m_Verbose )
  1699. {
  1700. std::cerr << "Changing directory into " << nwd.c_str() << "\n";
  1701. }
  1702. firstTest = 0;
  1703. }
  1704. cres.m_Name = args[0].Value;
  1705. if ( m_ShowOnly )
  1706. {
  1707. std::cout << args[0].Value << std::endl;
  1708. }
  1709. else
  1710. {
  1711. fprintf(stderr,"Testing %-30s ",args[0].Value.c_str());
  1712. fflush(stderr);
  1713. }
  1714. //std::cerr << "Testing " << args[0] << " ... ";
  1715. // find the test executable
  1716. std::string actualCommand = this->FindTheExecutable(args[1].Value.c_str());
  1717. std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
  1718. std::string memcheckcommand = "";
  1719. // continue if we did not find the executable
  1720. if (testCommand == "")
  1721. {
  1722. std::cerr << "Unable to find executable: " <<
  1723. args[1].Value.c_str() << "\n";
  1724. m_TestResults.push_back( cres );
  1725. continue;
  1726. }
  1727. // add the arguments
  1728. std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1729. ++j;
  1730. ++j;
  1731. std::vector<const char*> arguments;
  1732. if ( memcheck )
  1733. {
  1734. cmCTest::tm_VectorOfStrings::size_type pp;
  1735. arguments.push_back(m_MemoryTester.c_str());
  1736. memcheckcommand = m_MemoryTester;
  1737. for ( pp = 0; pp < m_MemoryTesterOptionsParsed.size(); pp ++ )
  1738. {
  1739. arguments.push_back(m_MemoryTesterOptionsParsed[pp].c_str());
  1740. memcheckcommand += " ";
  1741. memcheckcommand += cmSystemTools::EscapeSpaces(m_MemoryTesterOptionsParsed[pp].c_str());
  1742. }
  1743. }
  1744. arguments.push_back(actualCommand.c_str());
  1745. for(;j != args.end(); ++j)
  1746. {
  1747. testCommand += " ";
  1748. testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
  1749. arguments.push_back(j->Value.c_str());
  1750. }
  1751. arguments.push_back(0);
  1752. /**
  1753. * Run an executable command and put the stdout in output.
  1754. */
  1755. std::string output;
  1756. int retVal = 0;
  1757. double clock_start, clock_finish;
  1758. clock_start = cmSystemTools::GetTime();
  1759. if ( m_Verbose )
  1760. {
  1761. std::cout << std::endl << (memcheck?"MemCheck":"Test") << " command: " << testCommand << std::endl;
  1762. if ( memcheck )
  1763. {
  1764. std::cout << "Memory check command: " << memcheckcommand << std::endl;
  1765. }
  1766. }
  1767. int res = 0;
  1768. if ( !m_ShowOnly )
  1769. {
  1770. res = this->RunTest(arguments, &output, &retVal);
  1771. }
  1772. clock_finish = cmSystemTools::GetTime();
  1773. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  1774. cres.m_FullCommandLine = testCommand;
  1775. if ( !m_ShowOnly )
  1776. {
  1777. if (res == cmsysProcess_State_Exited && retVal == 0)
  1778. {
  1779. fprintf(stderr," Passed\n");
  1780. passed.push_back(args[0].Value);
  1781. cres.m_Status = cmCTest::COMPLETED;
  1782. }
  1783. else
  1784. {
  1785. cres.m_Status = cmCTest::FAILED;
  1786. if ( res == cmsysProcess_State_Expired )
  1787. {
  1788. fprintf(stderr,"***Timeout\n");
  1789. cres.m_Status = cmCTest::TIMEOUT;
  1790. }
  1791. else if ( res == cmsysProcess_State_Exception )
  1792. {
  1793. fprintf(stderr,"***Exception: ");
  1794. switch ( retVal )
  1795. {
  1796. case cmsysProcess_Exception_Fault:
  1797. fprintf(stderr,"SegFault");
  1798. cres.m_Status = cmCTest::SEGFAULT;
  1799. break;
  1800. case cmsysProcess_Exception_Illegal:
  1801. fprintf(stderr,"Illegal");
  1802. cres.m_Status = cmCTest::ILLEGAL;
  1803. break;
  1804. case cmsysProcess_Exception_Interrupt:
  1805. fprintf(stderr,"Interrupt");
  1806. cres.m_Status = cmCTest::INTERRUPT;
  1807. break;
  1808. case cmsysProcess_Exception_Numerical:
  1809. fprintf(stderr,"Numerical");
  1810. cres.m_Status = cmCTest::NUMERICAL;
  1811. break;
  1812. default:
  1813. fprintf(stderr,"Other");
  1814. cres.m_Status = cmCTest::OTHER_FAULT;
  1815. }
  1816. fprintf(stderr,"\n");
  1817. }
  1818. else if ( res == cmsysProcess_State_Error )
  1819. {
  1820. fprintf(stderr,"***Bad command\n");
  1821. cres.m_Status = cmCTest::BAD_COMMAND;
  1822. }
  1823. else
  1824. {
  1825. fprintf(stderr,"***Failed\n");
  1826. }
  1827. failed.push_back(args[0].Value);
  1828. }
  1829. if (output != "")
  1830. {
  1831. if (dartStuff.find(output.c_str()))
  1832. {
  1833. std::string dartString = dartStuff.match(1);
  1834. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  1835. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  1836. }
  1837. }
  1838. }
  1839. cres.m_Output = output;
  1840. cres.m_ReturnValue = retVal;
  1841. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1842. if ( nwd.size() > m_ToplevelPath.size() )
  1843. {
  1844. nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
  1845. }
  1846. cmSystemTools::ReplaceString(nwd, "\\", "/");
  1847. cres.m_Path = nwd;
  1848. cres.m_CompletionStatus = "Completed";
  1849. m_TestResults.push_back( cres );
  1850. }
  1851. }
  1852. }
  1853. bool cmCTest::InitializeMemoryChecking()
  1854. {
  1855. // Setup the command
  1856. if ( cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckCommand"].c_str()) )
  1857. {
  1858. m_MemoryTester
  1859. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["MemoryCheckCommand"].c_str());
  1860. }
  1861. else if ( cmSystemTools::FileExists(m_DartConfiguration["PurifyCommand"].c_str()) )
  1862. {
  1863. m_MemoryTester
  1864. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["PurifyCommand"].c_str());
  1865. }
  1866. else if ( cmSystemTools::FileExists(m_DartConfiguration["ValgrindCommand"].c_str()) )
  1867. {
  1868. m_MemoryTester
  1869. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["ValgrindCommand"].c_str());
  1870. }
  1871. else
  1872. {
  1873. std::cerr << "Memory checker (MemoryCheckCommand) not set, or cannot find the specified program."
  1874. << std::endl;
  1875. return false;
  1876. }
  1877. if ( m_MemoryTester[0] == '\"' && m_MemoryTester[m_MemoryTester.size()-1] == '\"' )
  1878. {
  1879. m_MemoryTester = m_MemoryTester.substr(1, m_MemoryTester.size()-2);
  1880. }
  1881. // Setup the options
  1882. if ( m_DartConfiguration["MemoryCheckCommandOptions"].size() )
  1883. {
  1884. m_MemoryTesterOptions = m_DartConfiguration["MemoryCheckCommandOptions"];
  1885. }
  1886. else if ( m_DartConfiguration["ValgrindCommandOptions"].size() )
  1887. {
  1888. m_MemoryTesterOptions = m_DartConfiguration["ValgrindCommandOptions"];
  1889. }
  1890. m_MemoryTesterOutputFile = m_ToplevelPath + "/Testing/Temporary/MemoryChecker.log";
  1891. m_MemoryTesterOutputFile = cmSystemTools::EscapeSpaces(m_MemoryTesterOutputFile.c_str());
  1892. if ( m_MemoryTester.find("valgrind") != std::string::npos )
  1893. {
  1894. m_MemoryTesterStyle = cmCTest::VALGRIND;
  1895. if ( !m_MemoryTesterOptions.size() )
  1896. {
  1897. m_MemoryTesterOptions = "-q --skin=memcheck --leak-check=yes --show-reachable=yes --workaround-gcc296-bugs=yes --num-callers=100";
  1898. }
  1899. if ( m_DartConfiguration["MemoryCheckSuppressionFile"].size() )
  1900. {
  1901. if ( !cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) )
  1902. {
  1903. std::cerr << "Cannot find memory checker suppression file: "
  1904. << m_DartConfiguration["MemoryCheckSuppressionFile"].c_str() << std::endl;
  1905. return false;
  1906. }
  1907. m_MemoryTesterOptions += " --suppressions=" + cmSystemTools::EscapeSpaces(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) + "";
  1908. }
  1909. }
  1910. else if ( m_MemoryTester.find("purify") != std::string::npos )
  1911. {
  1912. m_MemoryTesterStyle = cmCTest::PURIFY;
  1913. #ifdef _WIN32
  1914. m_MemoryTesterOptions += " /SAVETEXTDATA=" + m_MemoryTesterOutputFile;
  1915. #else
  1916. m_MemoryTesterOptions += " -log-file=" + m_MemoryTesterOutputFile;
  1917. #endif
  1918. }
  1919. else if ( m_MemoryTester.find("boundschecker") != std::string::npos )
  1920. {
  1921. m_MemoryTesterStyle = cmCTest::BOUNDS_CHECKER;
  1922. std::cerr << "Bounds checker not yet implemented" << std::endl;
  1923. return false;
  1924. }
  1925. else
  1926. {
  1927. std::cerr << "Do not understand memory checker: " << m_MemoryTester.c_str() << std::endl;
  1928. return false;
  1929. }
  1930. m_MemoryTesterOptionsParsed = cmSystemTools::ParseArguments(m_MemoryTesterOptions.c_str());
  1931. cmCTest::tm_VectorOfStrings::size_type cc;
  1932. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  1933. {
  1934. m_MemoryTesterGlobalResults[cc] = 0;
  1935. }
  1936. return true;
  1937. }
  1938. int cmCTest::TestDirectory(bool memcheck)
  1939. {
  1940. std::cout << (memcheck ? "Memory check" : "Test") << " project" << std::endl;
  1941. if ( memcheck )
  1942. {
  1943. if ( !this->InitializeMemoryChecking() )
  1944. {
  1945. return 1;
  1946. }
  1947. }
  1948. cmCTest::tm_VectorOfStrings passed;
  1949. cmCTest::tm_VectorOfStrings failed;
  1950. int total;
  1951. m_StartTest = ::CurrentTime();
  1952. this->ProcessDirectory(passed, failed, memcheck);
  1953. m_EndTest = ::CurrentTime();
  1954. total = int(passed.size()) + int(failed.size());
  1955. if (total == 0)
  1956. {
  1957. if ( !m_ShowOnly )
  1958. {
  1959. std::cerr << "No tests were found!!!\n";
  1960. }
  1961. }
  1962. else
  1963. {
  1964. if (m_Verbose && passed.size() &&
  1965. (m_UseIncludeRegExp || m_UseExcludeRegExp))
  1966. {
  1967. std::cerr << "\nThe following tests passed:\n";
  1968. for(cmCTest::tm_VectorOfStrings::iterator j = passed.begin();
  1969. j != passed.end(); ++j)
  1970. {
  1971. std::cerr << "\t" << *j << "\n";
  1972. }
  1973. }
  1974. float percent = float(passed.size()) * 100.0f / total;
  1975. fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  1976. percent, int(failed.size()), total);
  1977. if (failed.size())
  1978. {
  1979. std::cerr << "\nThe following tests FAILED:\n";
  1980. for(cmCTest::tm_VectorOfStrings::iterator j = failed.begin();
  1981. j != failed.end(); ++j)
  1982. {
  1983. std::cerr << "\t" << *j << "\n";
  1984. }
  1985. }
  1986. }
  1987. if ( m_DartMode )
  1988. {
  1989. std::ofstream ofs;
  1990. if( !this->OpenOutputFile(m_CurrentTag,
  1991. (memcheck ? (m_CompatibilityMode?"Purify.xml":"MemCheck.xml") : "Test.xml"), ofs) )
  1992. {
  1993. std::cerr << "Cannot create " << (memcheck ? "memory check" : "testing")
  1994. << " XML file" << std::endl;
  1995. return 1;
  1996. }
  1997. if ( memcheck )
  1998. {
  1999. this->GenerateDartMemCheckOutput(ofs);
  2000. }
  2001. else
  2002. {
  2003. this->GenerateDartTestOutput(ofs);
  2004. }
  2005. }
  2006. return int(failed.size());
  2007. }
  2008. int cmCTest::SubmitResults()
  2009. {
  2010. cmCTest::tm_VectorOfStrings files;
  2011. std::string prefix = this->GetSubmitResultsPrefix();
  2012. // TODO:
  2013. // Check if test is enabled
  2014. if ( this->CTestFileExists("Update.xml") )
  2015. {
  2016. files.push_back("Update.xml");
  2017. }
  2018. if ( this->CTestFileExists("Configure.xml") )
  2019. {
  2020. files.push_back("Configure.xml");
  2021. }
  2022. if ( this->CTestFileExists("Build.xml") )
  2023. {
  2024. files.push_back("Build.xml");
  2025. }
  2026. if ( this->CTestFileExists("Test.xml") )
  2027. {
  2028. files.push_back("Test.xml");
  2029. }
  2030. if ( this->CTestFileExists("Coverage.xml") )
  2031. {
  2032. files.push_back("Coverage.xml");
  2033. cmCTest::tm_VectorOfStrings gfiles;
  2034. std::string gpath = m_ToplevelPath + "/Testing/" + m_CurrentTag;
  2035. std::string::size_type glen = gpath.size() + 1;
  2036. gpath = gpath + "/CoverageLog*";
  2037. //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
  2038. if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
  2039. {
  2040. size_t cc;
  2041. for ( cc = 0; cc < gfiles.size(); cc ++ )
  2042. {
  2043. gfiles[cc] = gfiles[cc].substr(glen);
  2044. //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
  2045. files.push_back(gfiles[cc]);
  2046. }
  2047. }
  2048. else
  2049. {
  2050. std::cerr << "Problem globbing" << std::endl;
  2051. }
  2052. }
  2053. if ( this->CTestFileExists("MemCheck.xml") )
  2054. {
  2055. files.push_back("MemCheck.xml");
  2056. }
  2057. if ( this->CTestFileExists("Purify.xml") )
  2058. {
  2059. files.push_back("Purify.xml");
  2060. }
  2061. if ( this->CTestFileExists("Notes.xml") )
  2062. {
  2063. files.push_back("Notes.xml");
  2064. }
  2065. cmCTestSubmit submit;
  2066. submit.SetVerbose(m_Verbose);
  2067. if ( m_DartConfiguration["DropMethod"] == "" ||
  2068. m_DartConfiguration["DropMethod"] == "ftp" )
  2069. {
  2070. std::cout << " Using FTP submit method" << std::endl;
  2071. std::string url = "ftp://";
  2072. url += cmCTest::MakeURLSafe(m_DartConfiguration["DropSiteUser"]) + ":" +
  2073. cmCTest::MakeURLSafe(m_DartConfiguration["DropSitePassword"]) + "@" +
  2074. m_DartConfiguration["DropSite"] +
  2075. cmCTest::MakeURLSafe(m_DartConfiguration["DropLocation"]);
  2076. if ( !submit.SubmitUsingFTP(m_ToplevelPath+"/Testing/"+m_CurrentTag,
  2077. files, prefix, url) )
  2078. {
  2079. std::cerr << " Problems when submitting via FTP" << std::endl;
  2080. return 0;
  2081. }
  2082. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  2083. {
  2084. std::cerr << " Problems when triggering via HTTP" << std::endl;
  2085. return 0;
  2086. }
  2087. std::cout << " Submission successfull" << std::endl;
  2088. return 1;
  2089. }
  2090. else if ( m_DartConfiguration["DropMethod"] == "http" )
  2091. {
  2092. std::cout << " Using HTTP submit method" << std::endl;
  2093. std::string url = "http://";
  2094. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  2095. {
  2096. url += m_DartConfiguration["DropSiteUser"];
  2097. if ( m_DartConfiguration["DropSitePassword"].size() > 0 )
  2098. {
  2099. url += ":" + m_DartConfiguration["DropSitePassword"];
  2100. }
  2101. url += "@";
  2102. }
  2103. url += m_DartConfiguration["DropSite"] + m_DartConfiguration["DropLocation"];
  2104. if ( !submit.SubmitUsingHTTP(m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  2105. {
  2106. std::cerr << " Problems when submitting via HTTP" << std::endl;
  2107. return 0;
  2108. }
  2109. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  2110. {
  2111. std::cerr << " Problems when triggering via HTTP" << std::endl;
  2112. return 0;
  2113. }
  2114. std::cout << " Submission successfull" << std::endl;
  2115. return 1;
  2116. }
  2117. else
  2118. {
  2119. std::cerr << "SCP submit not yet implemented" << std::endl;
  2120. }
  2121. return 0;
  2122. }
  2123. bool cmCTest::CTestFileExists(const std::string& filename)
  2124. {
  2125. std::string testingDir = m_ToplevelPath + "/Testing/" + m_CurrentTag + "/" +
  2126. filename;
  2127. return cmSystemTools::FileExists(testingDir.c_str());
  2128. }
  2129. std::string cmCTest::GetSubmitResultsPrefix()
  2130. {
  2131. std::string name = m_DartConfiguration["Site"] +
  2132. "___" + m_DartConfiguration["BuildName"] +
  2133. "___" + m_CurrentTag + "-" +
  2134. this->GetTestModelString() + "___XML___";
  2135. return name;
  2136. }
  2137. void cmCTest::GenerateDartMemCheckOutput(std::ostream& os)
  2138. {
  2139. if ( !m_DartMode )
  2140. {
  2141. return;
  2142. }
  2143. this->StartXML(os);
  2144. if ( m_CompatibilityMode )
  2145. {
  2146. os << "<Purify>" << std::endl;
  2147. }
  2148. else
  2149. {
  2150. os << "<MemCheck>" << std::endl;
  2151. }
  2152. os << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  2153. << "\t<TestList>\n";
  2154. tm_TestResultsVector::size_type cc;
  2155. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2156. {
  2157. cmCTestTestResult *result = &m_TestResults[cc];
  2158. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  2159. << "/" << this->MakeXMLSafe(result->m_Name)
  2160. << "</Test>" << std::endl;
  2161. }
  2162. os << "\t</TestList>\n";
  2163. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2164. {
  2165. cmCTestTestResult *result = &m_TestResults[cc];
  2166. std::string memcheckstr;
  2167. int memcheckresults[cmCTest::NO_MEMORY_FAULT];
  2168. int kk;
  2169. this->ProcessMemCheckOutput(result->m_Output, memcheckstr, memcheckresults);
  2170. os << "\t<Test Status=\"";
  2171. if ( result->m_Status == cmCTest::COMPLETED )
  2172. {
  2173. os << "passed";
  2174. }
  2175. else if ( result->m_Status == cmCTest::NOT_RUN )
  2176. {
  2177. os << "notrun";
  2178. }
  2179. else
  2180. {
  2181. os << "failed";
  2182. }
  2183. os << "\">\n"
  2184. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  2185. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  2186. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  2187. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  2188. << "\t\t<FullCommandLine>"
  2189. << this->MakeXMLSafe(result->m_FullCommandLine)
  2190. << "</FullCommandLine>\n"
  2191. << "\t\t<Results>" << std::endl;
  2192. for ( kk = 0; cmCTestMemCheckResultStrings[kk]; kk ++ )
  2193. {
  2194. os << "\t\t\t<" << cmCTestMemCheckResultStrings[kk] << ">"
  2195. << memcheckresults[kk]
  2196. << "</" << cmCTestMemCheckResultStrings[kk] << ">" << std::endl;
  2197. m_MemoryTesterGlobalResults[kk] += memcheckresults[kk];
  2198. }
  2199. os
  2200. << "\t\t</Results>\n"
  2201. << "\t<Log>\n" << memcheckstr << std::endl
  2202. << "\t</Log>\n"
  2203. << "\t</Test>" << std::endl;
  2204. }
  2205. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>" << std::endl;
  2206. if ( m_CompatibilityMode )
  2207. {
  2208. os << "</Purify>" << std::endl;
  2209. }
  2210. else
  2211. {
  2212. os << "</MemCheck>" << std::endl;
  2213. }
  2214. this->EndXML(os);
  2215. std::cerr << "Memory checking results:" << std::endl;
  2216. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  2217. {
  2218. std::cerr << "\t\t" << cmCTestMemCheckResultStrings[cc] << " - "
  2219. << m_MemoryTesterGlobalResults[cc] << std::endl;
  2220. }
  2221. }
  2222. void cmCTest::GenerateDartTestOutput(std::ostream& os)
  2223. {
  2224. if ( !m_DartMode )
  2225. {
  2226. return;
  2227. }
  2228. this->StartXML(os);
  2229. os << "<Testing>\n"
  2230. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  2231. << "\t<TestList>\n";
  2232. tm_TestResultsVector::size_type cc;
  2233. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2234. {
  2235. cmCTestTestResult *result = &m_TestResults[cc];
  2236. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  2237. << "/" << this->MakeXMLSafe(result->m_Name)
  2238. << "</Test>" << std::endl;
  2239. }
  2240. os << "\t</TestList>\n";
  2241. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2242. {
  2243. cmCTestTestResult *result = &m_TestResults[cc];
  2244. os << "\t<Test Status=\"";
  2245. if ( result->m_Status == cmCTest::COMPLETED )
  2246. {
  2247. os << "passed";
  2248. }
  2249. else if ( result->m_Status == cmCTest::NOT_RUN )
  2250. {
  2251. os << "notrun";
  2252. }
  2253. else
  2254. {
  2255. os << "failed";
  2256. }
  2257. os << "\">\n"
  2258. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  2259. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  2260. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  2261. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  2262. << "\t\t<FullCommandLine>"
  2263. << this->MakeXMLSafe(result->m_FullCommandLine)
  2264. << "</FullCommandLine>\n"
  2265. << "\t\t<Results>" << std::endl;
  2266. if ( result->m_Status != cmCTest::NOT_RUN )
  2267. {
  2268. if ( result->m_Status != cmCTest::COMPLETED || result->m_ReturnValue )
  2269. {
  2270. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  2271. << this->GetTestStatus(result->m_Status) << "</Value></NamedMeasurement>\n"
  2272. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  2273. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  2274. }
  2275. os << result->m_RegressionImages;
  2276. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  2277. << "name=\"Execution Time\"><Value>"
  2278. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n";
  2279. os
  2280. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  2281. << "name=\"Completion Status\"><Value>"
  2282. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n";
  2283. }
  2284. os
  2285. << "\t\t\t<Measurement>\n"
  2286. << "\t\t\t\t<Value>" << this->MakeXMLSafe(result->m_Output)
  2287. << "</Value>\n"
  2288. << "\t\t\t</Measurement>\n"
  2289. << "\t\t</Results>\n"
  2290. << "\t</Test>" << std::endl;
  2291. }
  2292. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  2293. << "</Testing>" << std::endl;
  2294. this->EndXML(os);
  2295. }
  2296. int cmCTest::ProcessTests()
  2297. {
  2298. int res = 0;
  2299. bool notest = true;
  2300. int cc;
  2301. int update_count = 0;
  2302. for ( cc = 0; cc < LAST_TEST; cc ++ )
  2303. {
  2304. if ( m_Tests[cc] )
  2305. {
  2306. notest = false;
  2307. break;
  2308. }
  2309. }
  2310. if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
  2311. {
  2312. update_count = this->UpdateDirectory();
  2313. if ( update_count < 0 )
  2314. {
  2315. res |= CTEST_UPDATE_ERRORS;
  2316. }
  2317. }
  2318. if ( m_TestModel == cmCTest::CONTINUOUS && !update_count )
  2319. {
  2320. return 0;
  2321. }
  2322. if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
  2323. {
  2324. if (this->ConfigureDirectory())
  2325. {
  2326. res |= CTEST_CONFIGURE_ERRORS;
  2327. }
  2328. }
  2329. if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
  2330. {
  2331. if (this->BuildDirectory())
  2332. {
  2333. res |= CTEST_BUILD_ERRORS;
  2334. }
  2335. }
  2336. if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
  2337. {
  2338. if (this->TestDirectory(false))
  2339. {
  2340. res |= CTEST_TEST_ERRORS;
  2341. }
  2342. }
  2343. if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
  2344. {
  2345. this->CoverageDirectory();
  2346. }
  2347. if ( m_Tests[MEMCHECK_TEST] || m_Tests[ALL_TEST] )
  2348. {
  2349. if (this->TestDirectory(true))
  2350. {
  2351. res |= CTEST_MEMORY_ERRORS;
  2352. }
  2353. }
  2354. if ( m_Tests[SUBMIT_TEST] || m_Tests[ALL_TEST] )
  2355. {
  2356. this->SubmitResults();
  2357. }
  2358. return res;
  2359. }
  2360. std::string cmCTest::GetTestModelString()
  2361. {
  2362. switch ( m_TestModel )
  2363. {
  2364. case cmCTest::NIGHTLY:
  2365. return "Nightly";
  2366. case cmCTest::CONTINUOUS:
  2367. return "Continuous";
  2368. }
  2369. return "Experimental";
  2370. }
  2371. #define SPACE_REGEX "[ \t\r\n]"
  2372. std::string cmCTest::GenerateRegressionImages(const std::string& xml)
  2373. {
  2374. cmsys::RegularExpression twoattributes(
  2375. "<DartMeasurement"
  2376. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2377. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2378. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2379. cmsys::RegularExpression threeattributes(
  2380. "<DartMeasurement"
  2381. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2382. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2383. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2384. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2385. cmsys::RegularExpression fourattributes(
  2386. "<DartMeasurement"
  2387. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2388. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2389. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2390. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2391. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2392. cmsys::RegularExpression measurementfile(
  2393. "<DartMeasurementFile"
  2394. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2395. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2396. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  2397. cmOStringStream ostr;
  2398. bool done = false;
  2399. std::string cxml = xml;
  2400. while ( ! done )
  2401. {
  2402. if ( twoattributes.find(cxml) )
  2403. {
  2404. ostr
  2405. << "\t\t\t<NamedMeasurement"
  2406. << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
  2407. << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
  2408. << "><Value>" << twoattributes.match(5)
  2409. << "</Value></NamedMeasurement>"
  2410. << std::endl;
  2411. cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
  2412. }
  2413. else if ( threeattributes.find(cxml) )
  2414. {
  2415. ostr
  2416. << "\t\t\t<NamedMeasurement"
  2417. << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
  2418. << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
  2419. << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
  2420. << "><Value>" << threeattributes.match(7)
  2421. << "</Value></NamedMeasurement>"
  2422. << std::endl;
  2423. cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
  2424. }
  2425. else if ( fourattributes.find(cxml) )
  2426. {
  2427. ostr
  2428. << "\t\t\t<NamedMeasurement"
  2429. << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
  2430. << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
  2431. << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
  2432. << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
  2433. << "><Value>" << fourattributes.match(9)
  2434. << "</Value></NamedMeasurement>"
  2435. << std::endl;
  2436. cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
  2437. }
  2438. else if ( measurementfile.find(cxml) )
  2439. {
  2440. const std::string& filename = measurementfile.match(5);
  2441. if ( cmSystemTools::FileExists(filename.c_str()) )
  2442. {
  2443. long len = cmSystemTools::FileLength(filename.c_str());
  2444. std::ifstream ifs(filename.c_str(), std::ios::in
  2445. #ifdef _WIN32
  2446. | std::ios::binary
  2447. #endif
  2448. );
  2449. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  2450. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  2451. unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 1) ];
  2452. unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  2453. unsigned long cc;
  2454. ostr
  2455. << "\t\t\t<NamedMeasurement"
  2456. << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
  2457. << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
  2458. << " encoding=\"base64\""
  2459. << ">" << std::endl << "\t\t\t\t<Value>";
  2460. for ( cc = 0; cc < rlen; cc ++ )
  2461. {
  2462. ostr << encoded_buffer[cc];
  2463. if ( cc % 60 == 0 && cc )
  2464. {
  2465. ostr << std::endl;
  2466. }
  2467. }
  2468. ostr
  2469. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  2470. << std::endl;
  2471. delete [] file_buffer;
  2472. delete [] encoded_buffer;
  2473. }
  2474. else
  2475. {
  2476. int idx = 4;
  2477. if ( measurementfile.match(1) == "name" )
  2478. {
  2479. idx = 2;
  2480. }
  2481. ostr
  2482. << "\t\t\t<NamedMeasurement"
  2483. << " name=\"" << measurementfile.match(idx) << "\""
  2484. << " text=\"text/string\""
  2485. << "><Value>File " << filename << " not found</Value></NamedMeasurement>"
  2486. << std::endl;
  2487. }
  2488. cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
  2489. }
  2490. else
  2491. {
  2492. done = true;
  2493. }
  2494. }
  2495. return ostr.str();
  2496. }
  2497. int cmCTest::RunMakeCommand(const char* command, std::string* output,
  2498. int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs)
  2499. {
  2500. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  2501. if(args.size() < 1)
  2502. {
  2503. return false;
  2504. }
  2505. std::vector<const char*> argv;
  2506. for(std::vector<cmStdString>::const_iterator a = args.begin();
  2507. a != args.end(); ++a)
  2508. {
  2509. argv.push_back(a->c_str());
  2510. }
  2511. argv.push_back(0);
  2512. if ( output )
  2513. {
  2514. *output = "";
  2515. }
  2516. cmsysProcess* cp = cmsysProcess_New();
  2517. cmsysProcess_SetCommand(cp, &*argv.begin());
  2518. cmsysProcess_SetWorkingDirectory(cp, dir);
  2519. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2520. cmsysProcess_SetTimeout(cp, timeout);
  2521. cmsysProcess_Execute(cp);
  2522. std::string::size_type tick = 0;
  2523. std::string::size_type tick_len = 1024;
  2524. std::string::size_type tick_line_len = 50;
  2525. char* data;
  2526. int length;
  2527. if ( !verbose )
  2528. {
  2529. std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl;
  2530. std::cout << " " << std::flush;
  2531. }
  2532. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  2533. {
  2534. if ( output )
  2535. {
  2536. for(int cc =0; cc < length; ++cc)
  2537. {
  2538. if(data[cc] == 0)
  2539. {
  2540. data[cc] = '\n';
  2541. }
  2542. }
  2543. output->append(data, length);
  2544. if ( !verbose )
  2545. {
  2546. while ( output->size() > (tick * tick_len) )
  2547. {
  2548. tick ++;
  2549. std::cout << "." << std::flush;
  2550. if ( tick % tick_line_len == 0 && tick > 0 )
  2551. {
  2552. std::cout << " Size: ";
  2553. std::cout << int((output->size() / 1024.0) + 1) << "K" << std::endl;
  2554. std::cout << " " << std::flush;
  2555. }
  2556. }
  2557. }
  2558. }
  2559. if(verbose)
  2560. {
  2561. std::cout.write(data, length);
  2562. std::cout.flush();
  2563. }
  2564. if ( ofs )
  2565. {
  2566. ofs.write(data, length);
  2567. ofs.flush();
  2568. }
  2569. }
  2570. std::cout << " Size of output: ";
  2571. std::cout << int(output->size() / 1024.0) << "K" << std::endl;
  2572. cmsysProcess_WaitForExit(cp, 0);
  2573. int result = cmsysProcess_GetState(cp);
  2574. if(result == cmsysProcess_State_Exited)
  2575. {
  2576. *retVal = cmsysProcess_GetExitValue(cp);
  2577. }
  2578. else if(result == cmsysProcess_State_Exception)
  2579. {
  2580. *retVal = cmsysProcess_GetExitException(cp);
  2581. std::cout << "There was an exception: " << *retVal << std::endl;
  2582. }
  2583. else if(result == cmsysProcess_State_Expired)
  2584. {
  2585. std::cout << "There was a timeout" << std::endl;
  2586. }
  2587. else if(result == cmsysProcess_State_Error)
  2588. {
  2589. *output += "\n*** ERROR executing: ";
  2590. *output += cmsysProcess_GetErrorString(cp);
  2591. }
  2592. cmsysProcess_Delete(cp);
  2593. return result;
  2594. }
  2595. int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *retVal)
  2596. {
  2597. std::vector<char> tempOutput;
  2598. if ( output )
  2599. {
  2600. *output = "";
  2601. }
  2602. cmsysProcess* cp = cmsysProcess_New();
  2603. cmsysProcess_SetCommand(cp, &*argv.begin());
  2604. //std::cout << "Command is: " << argv[0] << std::endl;
  2605. if(cmSystemTools::GetRunCommandHideConsole())
  2606. {
  2607. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2608. }
  2609. cmsysProcess_SetTimeout(cp, m_TimeOut);
  2610. cmsysProcess_Execute(cp);
  2611. char* data;
  2612. int length;
  2613. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  2614. {
  2615. if ( output )
  2616. {
  2617. tempOutput.insert(tempOutput.end(), data, data+length);
  2618. }
  2619. if ( m_Verbose )
  2620. {
  2621. std::cout.write(data, length);
  2622. std::cout.flush();
  2623. }
  2624. }
  2625. cmsysProcess_WaitForExit(cp, 0);
  2626. if(output)
  2627. {
  2628. output->append(&*tempOutput.begin(), tempOutput.size());
  2629. }
  2630. int result = cmsysProcess_GetState(cp);
  2631. if(result == cmsysProcess_State_Exited)
  2632. {
  2633. *retVal = cmsysProcess_GetExitValue(cp);
  2634. }
  2635. else if(result == cmsysProcess_State_Exception)
  2636. {
  2637. *retVal = cmsysProcess_GetExitException(cp);
  2638. }
  2639. else if(result == cmsysProcess_State_Error)
  2640. {
  2641. std::string outerr = "\n*** ERROR executing: ";
  2642. outerr += cmsysProcess_GetErrorString(cp);
  2643. *output += outerr;
  2644. if ( m_Verbose )
  2645. {
  2646. std::cout << outerr.c_str() << "\n";
  2647. std::cout.flush();
  2648. }
  2649. }
  2650. cmsysProcess_Delete(cp);
  2651. return result;
  2652. }
  2653. const char* cmCTest::GetTestStatus(int status)
  2654. {
  2655. static const char statuses[][100] = {
  2656. "Not Run",
  2657. "Timeout",
  2658. "SEGFAULT",
  2659. "ILLEGAL",
  2660. "INTERRUPT",
  2661. "NUMERICAL",
  2662. "OTHER_FAULT",
  2663. "Failed",
  2664. "BAD_COMMAND",
  2665. "Completed"
  2666. };
  2667. if ( status < cmCTest::NOT_RUN || status > cmCTest::COMPLETED )
  2668. {
  2669. return "No Status";
  2670. }
  2671. return statuses[status];
  2672. }
  2673. int cmCTest::RunConfigurationScript()
  2674. {
  2675. m_ConfigurationScript =
  2676. cmSystemTools::CollapseFullPath(m_ConfigurationScript.c_str());
  2677. // make sure the file exists
  2678. if (!cmSystemTools::FileExists(m_ConfigurationScript.c_str()))
  2679. {
  2680. return -1;
  2681. }
  2682. // create a cmake instance to read the configuration script
  2683. cmake cm;
  2684. cmGlobalGenerator gg;
  2685. gg.SetCMakeInstance(&cm);
  2686. // read in the list file to fill the cache
  2687. cmLocalGenerator *lg = gg.CreateLocalGenerator();
  2688. lg->SetGlobalGenerator(&gg);
  2689. // set a variable with the path to the current script
  2690. lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_DIRECTORY",
  2691. cmSystemTools::GetFilenamePath(
  2692. m_ConfigurationScript).c_str());
  2693. lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_NAME",
  2694. cmSystemTools::GetFilenameName(
  2695. m_ConfigurationScript).c_str());
  2696. if (!lg->GetMakefile()->ReadListFile(0, m_ConfigurationScript.c_str()))
  2697. {
  2698. return -2;
  2699. }
  2700. // no popup widows
  2701. cmSystemTools::SetRunCommandHideConsole(true);
  2702. // get some info that should be set
  2703. cmMakefile *mf = lg->GetMakefile();
  2704. const char *srcDir = mf->GetDefinition("CTEST_SOURCE_DIRECTORY");
  2705. const char *binDir = mf->GetDefinition("CTEST_BINARY_DIRECTORY");
  2706. const char *ctestCmd = mf->GetDefinition("CTEST_COMMAND");
  2707. const char *ctestEnv = mf->GetDefinition("CTEST_ENVIRONMENT");
  2708. bool backup = mf->IsOn("CTEST_BACKUP_AND_RESTORE");
  2709. // make sure the required info is here
  2710. if (!srcDir || !binDir || !ctestCmd)
  2711. {
  2712. cmSystemTools::Error("Some required settings in the configuration file were missing");
  2713. return -3;
  2714. }
  2715. // set any environment variables
  2716. if (ctestEnv)
  2717. {
  2718. static char ctestEnvStatic[100][5000];
  2719. std::vector<std::string> envArgs;
  2720. cmSystemTools::ExpandListArgument(ctestEnv,envArgs);
  2721. int numArgs = envArgs.size();
  2722. // we have a hard limit of 100 env args due to stupid format of putenv
  2723. if (numArgs > 100)
  2724. {
  2725. numArgs = 100;
  2726. }
  2727. // for each variable/argument do a putenv
  2728. int i;
  2729. for (i = 0; i < numArgs; ++i)
  2730. {
  2731. // also limit args to be at most 4K long
  2732. std::string::size_type size = envArgs[i].size();
  2733. if(size > 4999)
  2734. {
  2735. size = 4999;
  2736. }
  2737. strncpy(ctestEnvStatic[i], envArgs[i].c_str(), size);
  2738. ctestEnvStatic[i][4999] = 0;
  2739. putenv(ctestEnvStatic[i]);
  2740. }
  2741. }
  2742. // compute the backup names
  2743. std::string backupSrcDir = srcDir;
  2744. backupSrcDir += "_CMakeBackup";
  2745. std::string backupBinDir = binDir;
  2746. backupBinDir += "_CMakeBackup";
  2747. // backup the binary and src directories if requested
  2748. if (backup)
  2749. {
  2750. // if for some reason those directories exist then first delete them
  2751. if (cmSystemTools::FileExists(backupSrcDir.c_str()))
  2752. {
  2753. cmSystemTools::RemoveADirectory(backupSrcDir.c_str());
  2754. }
  2755. if (cmSystemTools::FileExists(backupBinDir.c_str()))
  2756. {
  2757. cmSystemTools::RemoveADirectory(backupBinDir.c_str());
  2758. }
  2759. // first rename the src and binary directories
  2760. rename(srcDir, backupSrcDir.c_str());
  2761. rename(binDir, backupBinDir.c_str());
  2762. }
  2763. // clear the binary directory?
  2764. if (mf->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY"))
  2765. {
  2766. // try to avoid deleting directories that we shouldn't
  2767. std::string check = binDir;
  2768. check += "/CMakeCache.txt";
  2769. if (cmSystemTools::FileExists(check.c_str()))
  2770. {
  2771. cmSystemTools::RemoveADirectory(binDir);
  2772. }
  2773. }
  2774. // make sure the binary directory exists
  2775. if (!cmSystemTools::FileExists(binDir))
  2776. {
  2777. if (!cmSystemTools::MakeDirectory(binDir))
  2778. {
  2779. cmSystemTools::Error("Unable to create the binary directory");
  2780. return -4;
  2781. }
  2782. }
  2783. std::string command;
  2784. std::string output;
  2785. int retVal = 0;
  2786. bool res = 0;
  2787. // do an initial cvs update on the src dir
  2788. const char *cvsCmd = mf->GetDefinition("CTEST_CVS_COMMAND");
  2789. if (cvsCmd)
  2790. {
  2791. command = cvsCmd;
  2792. char updateVar[40];
  2793. int i;
  2794. for (i = 1; i < 10; ++i)
  2795. {
  2796. sprintf(updateVar,"CTEST_EXTRA_UPDATES_%i",i);
  2797. const char *updateVal = mf->GetDefinition(updateVar);
  2798. if (updateVal)
  2799. {
  2800. std::vector<std::string> cvsArgs;
  2801. cmSystemTools::ExpandListArgument(updateVal,cvsArgs);
  2802. if (cvsArgs.size() == 2)
  2803. {
  2804. std::string fullCommand = command;
  2805. fullCommand += " update ";
  2806. fullCommand += cvsArgs[1];
  2807. output.empty();
  2808. retVal = 0;
  2809. res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output,
  2810. &retVal, cvsArgs[0].c_str(),
  2811. m_Verbose, 0 /*m_TimeOut*/);
  2812. if (!res || retVal != 0)
  2813. {
  2814. cmSystemTools::Error("Unable to perform extra cvs updates");
  2815. return -5;
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. // put the initial cache into the bin dir
  2822. if (mf->GetDefinition("CTEST_INITIAL_CACHE"))
  2823. {
  2824. const char *initCache = mf->GetDefinition("CTEST_INITIAL_CACHE");
  2825. std::string cacheFile = binDir;
  2826. cacheFile += "/CMakeCache.txt";
  2827. std::ofstream fout(cacheFile.c_str());
  2828. if(!fout)
  2829. {
  2830. return -6;
  2831. }
  2832. fout.write(initCache, strlen(initCache));
  2833. // Make sure the operating system has finished writing the file
  2834. // before closing it. This will ensure the file is finished before
  2835. // the check below.
  2836. fout.flush();
  2837. fout.close();
  2838. }
  2839. // do an initial cmake to setup the DartConfig file
  2840. const char *cmakeCmd = mf->GetDefinition("CTEST_CMAKE_COMMAND");
  2841. if (cmakeCmd)
  2842. {
  2843. command = cmakeCmd;
  2844. command += " \"";
  2845. command += srcDir;
  2846. output.empty();
  2847. command += "\"";
  2848. retVal = 0;
  2849. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  2850. &retVal, binDir,
  2851. m_Verbose, 0 /*m_TimeOut*/);
  2852. if (!res || retVal != 0)
  2853. {
  2854. cmSystemTools::Error("Unable to run cmake");
  2855. return -7;
  2856. }
  2857. }
  2858. // run ctest
  2859. command = ctestCmd;
  2860. output.empty();
  2861. retVal = 0;
  2862. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  2863. &retVal, binDir,
  2864. m_Verbose, 0 /*m_TimeOut*/);
  2865. // did something critical fail in ctest
  2866. if (!res ||
  2867. retVal & CTEST_BUILD_ERRORS)
  2868. {
  2869. // if we backed up the dirs and the build failed, then restore
  2870. // the backed up dirs
  2871. if (backup)
  2872. {
  2873. // if for some reason those directories exist then first delete them
  2874. if (cmSystemTools::FileExists(srcDir))
  2875. {
  2876. cmSystemTools::RemoveADirectory(srcDir);
  2877. }
  2878. if (cmSystemTools::FileExists(binDir))
  2879. {
  2880. cmSystemTools::RemoveADirectory(binDir);
  2881. }
  2882. // rename the src and binary directories
  2883. rename(backupSrcDir.c_str(), srcDir);
  2884. rename(backupBinDir.c_str(), binDir);
  2885. }
  2886. cmSystemTools::Error("Unable to run ctest");
  2887. if (!res)
  2888. {
  2889. return -8;
  2890. }
  2891. return retVal;
  2892. }
  2893. return 0;
  2894. }
  2895. void cmCTest::StartXML(std::ostream& ostr)
  2896. {
  2897. ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  2898. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  2899. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  2900. << this->GetTestModelString() << "\" Name=\""
  2901. << m_DartConfiguration["Site"] << "\">" << std::endl;
  2902. }
  2903. void cmCTest::EndXML(std::ostream& ostr)
  2904. {
  2905. ostr << "</Site>" << std::endl;
  2906. }
  2907. bool cmCTest::ProcessMemCheckPurifyOutput(const std::string&, std::string& log,
  2908. int* results)
  2909. {
  2910. if ( !cmSystemTools::FileExists(m_MemoryTesterOutputFile.c_str()) )
  2911. {
  2912. log = "Cannot find Purify output file: " + m_MemoryTesterOutputFile;
  2913. std::cerr << log.c_str() << std::endl;
  2914. return false;
  2915. }
  2916. std::ifstream ifs(m_MemoryTesterOutputFile.c_str());
  2917. if ( !ifs )
  2918. {
  2919. log = "Cannot read Purify output file: " + m_MemoryTesterOutputFile;
  2920. std::cerr << log.c_str() << std::endl;
  2921. return false;
  2922. }
  2923. cmOStringStream ostr;
  2924. log = "";
  2925. cmsys::RegularExpression pfW("^\\[[WEI]\\] ([A-Z][A-Z][A-Z][A-Z]*): ");
  2926. std::string line;
  2927. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  2928. {
  2929. int failure = cmCTest::NO_MEMORY_FAULT;
  2930. if ( pfW.find(line) )
  2931. {
  2932. int cc;
  2933. for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
  2934. {
  2935. if ( pfW.match(1) == cmCTestMemCheckResultStrings[cc] )
  2936. {
  2937. failure = cc;
  2938. break;
  2939. }
  2940. }
  2941. if ( cc == cmCTest::NO_MEMORY_FAULT )
  2942. {
  2943. std::cerr<< "Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  2944. ostr << "*** Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  2945. }
  2946. }
  2947. if ( failure != NO_MEMORY_FAULT )
  2948. {
  2949. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  2950. results[failure] ++;
  2951. }
  2952. ostr << cmCTest::MakeXMLSafe(line) << std::endl;
  2953. }
  2954. log = ostr.str();
  2955. return true;
  2956. }
  2957. bool cmCTest::ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
  2958. int* results)
  2959. {
  2960. std::vector<cmStdString> lines;
  2961. cmSystemTools::Split(str.c_str(), lines);
  2962. std::string::size_type cc;
  2963. cmOStringStream ostr;
  2964. log = "";
  2965. cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
  2966. cmsys::RegularExpression vgFIM(
  2967. "== .*Invalid free\\(\\) / delete / delete\\[\\]");
  2968. cmsys::RegularExpression vgFMM(
  2969. "== .*Mismatched free\\(\\) / delete / delete \\[\\]");
  2970. cmsys::RegularExpression vgMLK(
  2971. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are definitely lost"
  2972. " in loss record [0-9][0-9]* of [0-9]");
  2973. cmsys::RegularExpression vgPAR(
  2974. "== .*Syscall param .* contains unaddressable byte\\(s\\)");
  2975. cmsys::RegularExpression vgMPK1(
  2976. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are possibly lost in"
  2977. " loss record [0-9][0-9]* of [0-9]");
  2978. cmsys::RegularExpression vgMPK2(
  2979. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are still reachable"
  2980. " in loss record [0-9][0-9]* of [0-9]");
  2981. cmsys::RegularExpression vgUMC(
  2982. "== .*Conditional jump or move depends on uninitialised value\\(s\\)");
  2983. cmsys::RegularExpression vgUMR1("== .*Use of uninitialised value of size [0-9][0-9]*");
  2984. cmsys::RegularExpression vgUMR2("== .*Invalid read of size [0-9][0-9]*");
  2985. cmsys::RegularExpression vgUMR3("== .*Jump to the invalid address ");
  2986. cmsys::RegularExpression vgUMR4(
  2987. "== .*Syscall param .* contains uninitialised or unaddressable byte\\(s\\)");
  2988. cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9]");
  2989. for ( cc = 0; cc < lines.size(); cc ++ )
  2990. {
  2991. if ( valgrindLine.find(lines[cc]) )
  2992. {
  2993. int failure = cmCTest::NO_MEMORY_FAULT;
  2994. if ( vgFIM.find(lines[cc]) ) { failure = cmCTest::FIM; }
  2995. else if ( vgFMM.find(lines[cc]) ) { failure = cmCTest::FMM; }
  2996. else if ( vgMLK.find(lines[cc]) ) { failure = cmCTest::MLK; }
  2997. else if ( vgPAR.find(lines[cc]) ) { failure = cmCTest::PAR; }
  2998. else if ( vgMPK1.find(lines[cc]) ){ failure = cmCTest::MPK; }
  2999. else if ( vgMPK2.find(lines[cc]) ){ failure = cmCTest::MPK; }
  3000. else if ( vgUMC.find(lines[cc]) ) { failure = cmCTest::UMC; }
  3001. else if ( vgUMR1.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3002. else if ( vgUMR2.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3003. else if ( vgUMR3.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3004. else if ( vgUMR4.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3005. else if ( vgIPW.find(lines[cc]) ) { failure = cmCTest::IPW; }
  3006. if ( failure != cmCTest::NO_MEMORY_FAULT )
  3007. {
  3008. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  3009. results[failure] ++;
  3010. }
  3011. ostr << cmCTest::MakeXMLSafe(lines[cc]) << std::endl;
  3012. }
  3013. }
  3014. log = ostr.str();
  3015. return true;
  3016. }
  3017. bool cmCTest::ProcessMemCheckOutput(const std::string& str, std::string& log, int* results)
  3018. {
  3019. std::string::size_type cc;
  3020. for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
  3021. {
  3022. results[cc] = 0;
  3023. }
  3024. if ( m_MemoryTesterStyle == cmCTest::VALGRIND )
  3025. {
  3026. return ProcessMemCheckValgrindOutput(str, log, results);
  3027. }
  3028. else if ( m_MemoryTesterStyle == cmCTest::PURIFY )
  3029. {
  3030. return ProcessMemCheckPurifyOutput(str, log, results);
  3031. }
  3032. else if ( m_MemoryTesterStyle == cmCTest::BOUNDS_CHECKER )
  3033. {
  3034. log.append("\nMemory checking style used was: ");
  3035. log.append("Bounds Checker");
  3036. }
  3037. else
  3038. {
  3039. log.append("\nMemory checking style used was: ");
  3040. log.append("None that I know");
  3041. log = str;
  3042. }
  3043. return true;
  3044. }
  3045. int cmCTest::GenerateDartNotesOutput(std::ostream& os, const cmCTest::tm_VectorOfStrings& files)
  3046. {
  3047. cmCTest::tm_VectorOfStrings::const_iterator it;
  3048. for ( it = files.begin(); it != files.end(); it ++ )
  3049. {
  3050. if ( !cmSystemTools::FileExists(it->c_str()) )
  3051. {
  3052. std::cerr << "Error creating notes. File " << it->c_str() << " does not exists" << std::endl;
  3053. return 0;
  3054. }
  3055. }
  3056. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  3057. << "<?xml-stylesheet type=\"text/xsl\" href=\"Dart/Source/Server/XSL/Build.xsl <file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
  3058. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"] << "\" BuildStamp=\""
  3059. << m_CurrentTag << "-" << this->GetTestModelString() << "\" Name=\""
  3060. << m_DartConfiguration["Site"] << "\">\n"
  3061. << "<Notes>" << std::endl;
  3062. for ( it = files.begin(); it != files.end(); it ++ )
  3063. {
  3064. std::cout << "\tAdd file: " << it->c_str() << std::endl;
  3065. std::string note_time = ::CurrentTime();
  3066. os << "<Note>\n"
  3067. << "<DateTime>" << note_time << "</DateTime>\n"
  3068. << "<Text>" << std::endl;
  3069. std::ifstream ifs(it->c_str());
  3070. if ( ifs )
  3071. {
  3072. std::string line;
  3073. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  3074. {
  3075. os << this->MakeXMLSafe(line) << std::endl;
  3076. }
  3077. ifs.close();
  3078. }
  3079. else
  3080. {
  3081. os << "Problem reading file: " << it->c_str() << std::endl;
  3082. std::cerr << "Problem reading file: " << it->c_str() << " while creating notes" << std::endl;
  3083. }
  3084. os << "</Text>\n"
  3085. << "</Note>" << std::endl;
  3086. }
  3087. os << "</Notes>\n"
  3088. << "</Site>" << std::endl;
  3089. return 1;
  3090. }
  3091. int cmCTest::GenerateNotesFile(const char* cfiles)
  3092. {
  3093. if ( !cfiles )
  3094. {
  3095. return 1;
  3096. }
  3097. std::vector<cmStdString> files;
  3098. std::cout << "Create notes file" << std::endl;
  3099. files = cmSystemTools::SplitString(cfiles, ';');
  3100. if ( files.size() == 0 )
  3101. {
  3102. return 1;
  3103. }
  3104. std::ofstream ofs;
  3105. if ( !this->OpenOutputFile(m_CurrentTag, "Notes.xml", ofs) )
  3106. {
  3107. std::cerr << "Cannot open notes file" << std::endl;
  3108. return 1;
  3109. }
  3110. this->GenerateDartNotesOutput(ofs, files);
  3111. return 0;
  3112. }