cmCTest.cxx 93 KB

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