cmCTest.cxx 98 KB

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