cmCTest.cxx 97 KB

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