cmCTest.cxx 80 KB

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