cmCTest.cxx 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609
  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 "cm_curl.h"
  14. #include "cmCTest.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmGlobalGenerator.h"
  19. #include <cmsys/Directory.hxx>
  20. #include "cmDynamicLoader.h"
  21. #include "cmGeneratedFileStream.h"
  22. #include "cmCTestCommand.h"
  23. #include "cmCTestBuildHandler.h"
  24. #include "cmCTestBuildAndTestHandler.h"
  25. #include "cmCTestConfigureHandler.h"
  26. #include "cmCTestCoverageHandler.h"
  27. #include "cmCTestMemCheckHandler.h"
  28. #include "cmCTestScriptHandler.h"
  29. #include "cmCTestTestHandler.h"
  30. #include "cmCTestUpdateHandler.h"
  31. #include "cmCTestSubmitHandler.h"
  32. #include "cmVersion.h"
  33. #include <cmsys/RegularExpression.hxx>
  34. #include <cmsys/Process.h>
  35. #include <cmsys/Glob.hxx>
  36. #include <stdlib.h>
  37. #include <math.h>
  38. #include <float.h>
  39. #include <memory> // auto_ptr
  40. #if defined(__BEOS__)
  41. #include <be/kernel/OS.h> /* disable_debugger() API. */
  42. #endif
  43. #define DEBUGOUT std::cout << __LINE__ << " "; std::cout
  44. #define DEBUGERR std::cerr << __LINE__ << " "; std::cerr
  45. //----------------------------------------------------------------------
  46. struct tm* cmCTest::GetNightlyTime(std::string str,
  47. bool tomorrowtag)
  48. {
  49. struct tm* lctime;
  50. time_t tctime = time(0);
  51. lctime = gmtime(&tctime);
  52. char buf[1024];
  53. // add todays year day and month to the time in str because
  54. // curl_getdate no longer assumes the day is today
  55. sprintf(buf, "%d%02d%02d %s", lctime->tm_year+1900, lctime->tm_mday,
  56. lctime->tm_mon, str.c_str());
  57. cmCTestLog(this, OUTPUT, "Determine Nightly Start Time" << std::endl
  58. << " Specified time: " << str.c_str() << std::endl);
  59. //Convert the nightly start time to seconds. Since we are
  60. //providing only a time and a timezone, the current date of
  61. //the local machine is assumed. Consequently, nightlySeconds
  62. //is the time at which the nightly dashboard was opened or
  63. //will be opened on the date of the current client machine.
  64. //As such, this time may be in the past or in the future.
  65. time_t ntime = curl_getdate(buf, &tctime);
  66. cmCTestLog(this, DEBUG, " Get curl time: " << ntime << std::endl);
  67. tctime = time(0);
  68. cmCTestLog(this, DEBUG, " Get the current time: " << tctime << std::endl);
  69. const int dayLength = 24 * 60 * 60;
  70. cmCTestLog(this, DEBUG, "Seconds: " << tctime << std::endl);
  71. while ( ntime > tctime )
  72. {
  73. // If nightlySeconds is in the past, this is the current
  74. // open dashboard, then return nightlySeconds. If
  75. // nightlySeconds is in the future, this is the next
  76. // dashboard to be opened, so subtract 24 hours to get the
  77. // time of the current open dashboard
  78. ntime -= dayLength;
  79. cmCTestLog(this, DEBUG, "Pick yesterday" << std::endl);
  80. cmCTestLog(this, DEBUG, " Future time, subtract day: " << ntime
  81. << std::endl);
  82. }
  83. while ( tctime > (ntime + dayLength) )
  84. {
  85. ntime += dayLength;
  86. cmCTestLog(this, DEBUG, " Past time, add day: " << ntime << std::endl);
  87. }
  88. cmCTestLog(this, DEBUG, "nightlySeconds: " << ntime << std::endl);
  89. cmCTestLog(this, DEBUG, " Current time: " << tctime
  90. << " Nightly time: " << ntime << std::endl);
  91. if ( tomorrowtag )
  92. {
  93. cmCTestLog(this, OUTPUT, " Use future tag, Add a day" << std::endl);
  94. ntime += dayLength;
  95. }
  96. lctime = gmtime(&ntime);
  97. return lctime;
  98. }
  99. //----------------------------------------------------------------------
  100. std::string cmCTest::CleanString(const std::string& str)
  101. {
  102. std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
  103. std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
  104. if ( spos == str.npos )
  105. {
  106. return std::string();
  107. }
  108. if ( epos != str.npos )
  109. {
  110. epos = epos - spos + 1;
  111. }
  112. return str.substr(spos, epos);
  113. }
  114. //----------------------------------------------------------------------
  115. std::string cmCTest::CurrentTime()
  116. {
  117. time_t currenttime = time(0);
  118. struct tm* t = localtime(&currenttime);
  119. //return ::CleanString(ctime(&currenttime));
  120. char current_time[1024];
  121. if ( this->ShortDateFormat )
  122. {
  123. strftime(current_time, 1000, "%b %d %H:%M %Z", t);
  124. }
  125. else
  126. {
  127. strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
  128. }
  129. cmCTestLog(this, DEBUG, " Current_Time: " << current_time << std::endl);
  130. return cmCTest::MakeXMLSafe(cmCTest::CleanString(current_time));
  131. }
  132. //----------------------------------------------------------------------
  133. std::string cmCTest::MakeXMLSafe(const std::string& str)
  134. {
  135. std::vector<char> result;
  136. result.reserve(500);
  137. const char* pos = str.c_str();
  138. for ( ;*pos; ++pos)
  139. {
  140. char ch = *pos;
  141. if ( (ch > 126 || ch < 32) && ch != 9 &&
  142. ch != 10 && ch != 13 && ch != '\r' )
  143. {
  144. char buffer[33];
  145. sprintf(buffer, "&lt;%d&gt;", (int)ch);
  146. //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
  147. result.insert(result.end(), buffer, buffer+strlen(buffer));
  148. }
  149. else
  150. {
  151. const char* const encodedChars[] = {
  152. "&amp;",
  153. "&lt;",
  154. "&gt;"
  155. };
  156. switch ( ch )
  157. {
  158. case '&':
  159. result.insert(result.end(), encodedChars[0], encodedChars[0]+5);
  160. break;
  161. case '<':
  162. result.insert(result.end(), encodedChars[1], encodedChars[1]+4);
  163. break;
  164. case '>':
  165. result.insert(result.end(), encodedChars[2], encodedChars[2]+4);
  166. break;
  167. case '\n':
  168. result.push_back('\n');
  169. break;
  170. case '\r': break; // Ignore \r
  171. default:
  172. result.push_back(ch);
  173. }
  174. }
  175. }
  176. if ( result.size() == 0 )
  177. {
  178. return "";
  179. }
  180. return std::string(&*result.begin(), result.size());
  181. }
  182. //----------------------------------------------------------------------
  183. std::string cmCTest::MakeURLSafe(const std::string& str)
  184. {
  185. cmOStringStream ost;
  186. char buffer[10];
  187. for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
  188. {
  189. unsigned char ch = str[pos];
  190. if ( ( ch > 126 || ch < 32 ||
  191. ch == '&' ||
  192. ch == '%' ||
  193. ch == '+' ||
  194. ch == '=' ||
  195. ch == '@'
  196. ) && ch != 9 )
  197. {
  198. sprintf(buffer, "%02x;", (unsigned int)ch);
  199. ost << buffer;
  200. }
  201. else
  202. {
  203. ost << ch;
  204. }
  205. }
  206. return ost.str();
  207. }
  208. //----------------------------------------------------------------------
  209. cmCTest::cmCTest()
  210. {
  211. this->SubmitIndex = 0;
  212. this->ForceNewCTestProcess = false;
  213. this->TomorrowTag = false;
  214. this->Verbose = false;
  215. this->Debug = false;
  216. this->ShowLineNumbers = false;
  217. this->Quiet = false;
  218. this->ExtraVerbose = false;
  219. this->ProduceXML = false;
  220. this->ShowOnly = false;
  221. this->RunConfigurationScript = false;
  222. this->TestModel = cmCTest::EXPERIMENTAL;
  223. this->InteractiveDebugMode = true;
  224. this->TimeOut = 0;
  225. this->CompressXMLFiles = false;
  226. this->CTestConfigFile = "";
  227. this->OutputLogFile = 0;
  228. this->OutputLogFileLastTag = -1;
  229. this->SuppressUpdatingCTestConfiguration = false;
  230. this->DartVersion = 1;
  231. int cc;
  232. for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
  233. {
  234. this->Tests[cc] = 0;
  235. }
  236. this->ShortDateFormat = true;
  237. this->TestingHandlers["build"] = new cmCTestBuildHandler;
  238. this->TestingHandlers["buildtest"] = new cmCTestBuildAndTestHandler;
  239. this->TestingHandlers["coverage"] = new cmCTestCoverageHandler;
  240. this->TestingHandlers["script"] = new cmCTestScriptHandler;
  241. this->TestingHandlers["test"] = new cmCTestTestHandler;
  242. this->TestingHandlers["update"] = new cmCTestUpdateHandler;
  243. this->TestingHandlers["configure"] = new cmCTestConfigureHandler;
  244. this->TestingHandlers["memcheck"] = new cmCTestMemCheckHandler;
  245. this->TestingHandlers["submit"] = new cmCTestSubmitHandler;
  246. cmCTest::t_TestingHandlers::iterator it;
  247. for ( it = this->TestingHandlers.begin();
  248. it != this->TestingHandlers.end(); ++ it )
  249. {
  250. it->second->SetCTestInstance(this);
  251. }
  252. // Make sure we can capture the build tool output.
  253. cmSystemTools::EnableVSConsoleOutput();
  254. }
  255. //----------------------------------------------------------------------
  256. cmCTest::~cmCTest()
  257. {
  258. cmCTest::t_TestingHandlers::iterator it;
  259. for ( it = this->TestingHandlers.begin();
  260. it != this->TestingHandlers.end(); ++ it )
  261. {
  262. delete it->second;
  263. it->second = 0;
  264. }
  265. this->SetOutputLogFileName(0);
  266. }
  267. //----------------------------------------------------------------------
  268. int cmCTest::Initialize(const char* binary_dir, bool new_tag,
  269. bool verbose_tag)
  270. {
  271. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  272. if(!this->InteractiveDebugMode)
  273. {
  274. this->BlockTestErrorDiagnostics();
  275. }
  276. else
  277. {
  278. cmSystemTools::PutEnv("CTEST_INTERACTIVE_DEBUG_MODE=1");
  279. }
  280. this->BinaryDir = binary_dir;
  281. cmSystemTools::ConvertToUnixSlashes(this->BinaryDir);
  282. this->UpdateCTestConfiguration();
  283. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  284. if ( this->ProduceXML )
  285. {
  286. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  287. cmCTestLog(this, OUTPUT,
  288. " Site: " << this->GetCTestConfiguration("Site") << std::endl
  289. << " Build name: " << this->GetCTestConfiguration("BuildName")
  290. << std::endl);
  291. cmCTestLog(this, DEBUG, "Produce XML is on" << std::endl);
  292. if ( this->GetCTestConfiguration("NightlyStartTime").empty() )
  293. {
  294. cmCTestLog(this, DEBUG, "No nightly start time" << std::endl);
  295. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  296. return 0;
  297. }
  298. }
  299. cmake cm;
  300. cmGlobalGenerator gg;
  301. gg.SetCMakeInstance(&cm);
  302. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  303. lg->SetGlobalGenerator(&gg);
  304. cmMakefile *mf = lg->GetMakefile();
  305. if ( !this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), mf) )
  306. {
  307. cmCTestLog(this, DEBUG, "Cannot find custom configuration file tree"
  308. << std::endl);
  309. return 0;
  310. }
  311. if ( this->ProduceXML )
  312. {
  313. std::string testingDir = this->BinaryDir + "/Testing";
  314. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  315. {
  316. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  317. {
  318. cmCTestLog(this, ERROR_MESSAGE, "File " << testingDir
  319. << " is in the place of the testing directory" << std::endl);
  320. return 0;
  321. }
  322. }
  323. else
  324. {
  325. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  326. {
  327. cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory "
  328. << testingDir << std::endl);
  329. return 0;
  330. }
  331. }
  332. std::string tagfile = testingDir + "/TAG";
  333. std::ifstream tfin(tagfile.c_str());
  334. std::string tag;
  335. time_t tctime = time(0);
  336. if ( this->TomorrowTag )
  337. {
  338. tctime += ( 24 * 60 * 60 );
  339. }
  340. struct tm *lctime = gmtime(&tctime);
  341. if ( tfin && cmSystemTools::GetLineFromStream(tfin, tag) )
  342. {
  343. int year = 0;
  344. int mon = 0;
  345. int day = 0;
  346. int hour = 0;
  347. int min = 0;
  348. sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
  349. &year, &mon, &day, &hour, &min);
  350. if ( year != lctime->tm_year + 1900 ||
  351. mon != lctime->tm_mon+1 ||
  352. day != lctime->tm_mday )
  353. {
  354. tag = "";
  355. }
  356. std::string tagmode;
  357. if ( cmSystemTools::GetLineFromStream(tfin, tagmode) )
  358. {
  359. if ( tagmode.size() > 4 && !( this->Tests[cmCTest::START_TEST] ||
  360. this->Tests[ALL_TEST] ))
  361. {
  362. this->TestModel = cmCTest::GetTestModelFromString(tagmode.c_str());
  363. }
  364. }
  365. tfin.close();
  366. }
  367. if ( tag.size() == 0 || new_tag || this->Tests[cmCTest::START_TEST] ||
  368. this->Tests[ALL_TEST])
  369. {
  370. cmCTestLog(this, DEBUG, "TestModel: " << this->GetTestModelString()
  371. << std::endl);
  372. cmCTestLog(this, DEBUG, "TestModel: " << this->TestModel << std::endl);
  373. if ( this->TestModel == cmCTest::NIGHTLY )
  374. {
  375. lctime = this->GetNightlyTime(
  376. this->GetCTestConfiguration("NightlyStartTime"), this->TomorrowTag);
  377. }
  378. char datestring[100];
  379. sprintf(datestring, "%04d%02d%02d-%02d%02d",
  380. lctime->tm_year + 1900,
  381. lctime->tm_mon+1,
  382. lctime->tm_mday,
  383. lctime->tm_hour,
  384. lctime->tm_min);
  385. tag = datestring;
  386. std::ofstream ofs(tagfile.c_str());
  387. if ( ofs )
  388. {
  389. ofs << tag << std::endl;
  390. ofs << this->GetTestModelString() << std::endl;
  391. }
  392. ofs.close();
  393. if ( verbose_tag )
  394. {
  395. cmCTestLog(this, OUTPUT, "Create new tag: " << tag << " - "
  396. << this->GetTestModelString() << std::endl);
  397. }
  398. }
  399. this->CurrentTag = tag;
  400. }
  401. return 1;
  402. }
  403. //----------------------------------------------------------------------
  404. bool cmCTest::InitializeFromCommand(cmCTestCommand* command, bool first)
  405. {
  406. if ( !first && !this->CurrentTag.empty() )
  407. {
  408. return true;
  409. }
  410. std::string src_dir
  411. = this->GetCTestConfiguration("SourceDirectory").c_str();
  412. std::string bld_dir = this->GetCTestConfiguration("BuildDirectory").c_str();
  413. this->DartVersion = 1;
  414. this->SubmitFiles.clear();
  415. cmMakefile* mf = command->GetMakefile();
  416. std::string fname = src_dir;
  417. fname += "/CTestConfig.cmake";
  418. cmSystemTools::ConvertToUnixSlashes(fname);
  419. if ( cmSystemTools::FileExists(fname.c_str()) )
  420. {
  421. cmCTestLog(this, OUTPUT, " Reading ctest configuration file: "
  422. << fname.c_str() << std::endl);
  423. bool readit = mf->ReadListFile(mf->GetCurrentListFile(),
  424. fname.c_str() );
  425. if(!readit)
  426. {
  427. std::string m = "Could not find include file: ";
  428. m += fname;
  429. command->SetError(m.c_str());
  430. return false;
  431. }
  432. }
  433. else if ( !first )
  434. {
  435. cmCTestLog(this, WARNING, "Cannot locate CTest configuration: "
  436. << fname.c_str() << std::endl);
  437. }
  438. else
  439. {
  440. cmCTestLog(this, HANDLER_OUTPUT, " Cannot locate CTest configuration: "
  441. << fname.c_str() << std::endl
  442. << " Delay the initialization of CTest" << std::endl);
  443. }
  444. this->SetCTestConfigurationFromCMakeVariable(mf, "NightlyStartTime",
  445. "CTEST_NIGHTLY_START_TIME");
  446. this->SetCTestConfigurationFromCMakeVariable(mf, "Site", "CTEST_SITE");
  447. this->SetCTestConfigurationFromCMakeVariable(mf, "BuildName",
  448. "CTEST_BUILD_NAME");
  449. const char* dartVersion = mf->GetDefinition("CTEST_DART_SERVER_VERSION");
  450. if ( dartVersion )
  451. {
  452. this->DartVersion = atoi(dartVersion);
  453. if ( this->DartVersion < 0 )
  454. {
  455. cmCTestLog(this, ERROR_MESSAGE, "Invalid Dart server version: "
  456. << dartVersion << ". Please specify the version number."
  457. << std::endl);
  458. return false;
  459. }
  460. }
  461. if ( !this->Initialize(bld_dir.c_str(), true, false) )
  462. {
  463. if ( this->GetCTestConfiguration("NightlyStartTime").empty() && first)
  464. {
  465. return true;
  466. }
  467. return false;
  468. }
  469. cmCTestLog(this, OUTPUT, " Use " << this->GetTestModelString()
  470. << " tag: " << this->GetCurrentTag() << std::endl);
  471. return true;
  472. }
  473. //----------------------------------------------------------------------
  474. bool cmCTest::UpdateCTestConfiguration()
  475. {
  476. if ( this->SuppressUpdatingCTestConfiguration )
  477. {
  478. return true;
  479. }
  480. std::string fileName = this->CTestConfigFile;
  481. if ( fileName.empty() )
  482. {
  483. fileName = this->BinaryDir + "/DartConfiguration.tcl";
  484. if ( !cmSystemTools::FileExists(fileName.c_str()) )
  485. {
  486. fileName = this->BinaryDir + "/CTestConfiguration.ini";
  487. }
  488. }
  489. if ( !cmSystemTools::FileExists(fileName.c_str()) )
  490. {
  491. // No need to exit if we are not producing XML
  492. if ( this->ProduceXML )
  493. {
  494. cmCTestLog(this, ERROR_MESSAGE, "Cannot find file: " << fileName.c_str()
  495. << std::endl);
  496. return false;
  497. }
  498. }
  499. else
  500. {
  501. // parse the dart test file
  502. std::ifstream fin(fileName.c_str());
  503. if(!fin)
  504. {
  505. return false;
  506. }
  507. char buffer[1024];
  508. while ( fin )
  509. {
  510. buffer[0] = 0;
  511. fin.getline(buffer, 1023);
  512. buffer[1023] = 0;
  513. std::string line = cmCTest::CleanString(buffer);
  514. if(line.size() == 0)
  515. {
  516. continue;
  517. }
  518. while ( fin && (line[line.size()-1] == '\\') )
  519. {
  520. line = line.substr(0, line.size()-1);
  521. buffer[0] = 0;
  522. fin.getline(buffer, 1023);
  523. buffer[1023] = 0;
  524. line += cmCTest::CleanString(buffer);
  525. }
  526. if ( line[0] == '#' )
  527. {
  528. continue;
  529. }
  530. std::string::size_type cpos = line.find_first_of(":");
  531. if ( cpos == line.npos )
  532. {
  533. continue;
  534. }
  535. std::string key = line.substr(0, cpos);
  536. std::string value
  537. = cmCTest::CleanString(line.substr(cpos+1, line.npos));
  538. this->CTestConfiguration[key] = value;
  539. }
  540. fin.close();
  541. }
  542. if ( !this->GetCTestConfiguration("BuildDirectory").empty() )
  543. {
  544. this->BinaryDir = this->GetCTestConfiguration("BuildDirectory");
  545. cmSystemTools::ChangeDirectory(this->BinaryDir.c_str());
  546. }
  547. this->TimeOut = atoi(this->GetCTestConfiguration("TimeOut").c_str());
  548. if ( this->ProduceXML )
  549. {
  550. this->CompressXMLFiles = cmSystemTools::IsOn(
  551. this->GetCTestConfiguration("CompressSubmission").c_str());
  552. }
  553. return true;
  554. }
  555. //----------------------------------------------------------------------
  556. void cmCTest::BlockTestErrorDiagnostics()
  557. {
  558. cmSystemTools::PutEnv("DART_TEST_FROM_DART=1");
  559. cmSystemTools::PutEnv("DASHBOARD_TEST_FROM_CTEST=" CMake_VERSION);
  560. #if defined(_WIN32)
  561. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  562. #elif defined(__BEOS__)
  563. disable_debugger(1);
  564. #endif
  565. }
  566. //----------------------------------------------------------------------
  567. void cmCTest::SetTestModel(int mode)
  568. {
  569. this->InteractiveDebugMode = false;
  570. this->TestModel = mode;
  571. }
  572. //----------------------------------------------------------------------
  573. bool cmCTest::SetTest(const char* ttype, bool report)
  574. {
  575. if ( cmSystemTools::LowerCase(ttype) == "all" )
  576. {
  577. this->Tests[cmCTest::ALL_TEST] = 1;
  578. }
  579. else if ( cmSystemTools::LowerCase(ttype) == "start" )
  580. {
  581. this->Tests[cmCTest::START_TEST] = 1;
  582. }
  583. else if ( cmSystemTools::LowerCase(ttype) == "update" )
  584. {
  585. this->Tests[cmCTest::UPDATE_TEST] = 1;
  586. }
  587. else if ( cmSystemTools::LowerCase(ttype) == "configure" )
  588. {
  589. this->Tests[cmCTest::CONFIGURE_TEST] = 1;
  590. }
  591. else if ( cmSystemTools::LowerCase(ttype) == "build" )
  592. {
  593. this->Tests[cmCTest::BUILD_TEST] = 1;
  594. }
  595. else if ( cmSystemTools::LowerCase(ttype) == "test" )
  596. {
  597. this->Tests[cmCTest::TEST_TEST] = 1;
  598. }
  599. else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
  600. {
  601. this->Tests[cmCTest::COVERAGE_TEST] = 1;
  602. }
  603. else if ( cmSystemTools::LowerCase(ttype) == "memcheck" )
  604. {
  605. this->Tests[cmCTest::MEMCHECK_TEST] = 1;
  606. }
  607. else if ( cmSystemTools::LowerCase(ttype) == "notes" )
  608. {
  609. this->Tests[cmCTest::NOTES_TEST] = 1;
  610. }
  611. else if ( cmSystemTools::LowerCase(ttype) == "submit" )
  612. {
  613. this->Tests[cmCTest::SUBMIT_TEST] = 1;
  614. }
  615. else
  616. {
  617. if ( report )
  618. {
  619. cmCTestLog(this, ERROR_MESSAGE, "Don't know about test \"" << ttype
  620. << "\" yet..." << std::endl);
  621. }
  622. return false;
  623. }
  624. return true;
  625. }
  626. //----------------------------------------------------------------------
  627. void cmCTest::Finalize()
  628. {
  629. }
  630. //----------------------------------------------------------------------
  631. bool cmCTest::OpenOutputFile(const std::string& path,
  632. const std::string& name, cmGeneratedFileStream& stream,
  633. bool compress)
  634. {
  635. std::string testingDir = this->BinaryDir + "/Testing";
  636. if ( path.size() > 0 )
  637. {
  638. testingDir += "/" + path;
  639. }
  640. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  641. {
  642. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  643. {
  644. cmCTestLog(this, ERROR_MESSAGE, "File " << testingDir
  645. << " is in the place of the testing directory"
  646. << std::endl);
  647. return false;
  648. }
  649. }
  650. else
  651. {
  652. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  653. {
  654. cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory " << testingDir
  655. << std::endl);
  656. return false;
  657. }
  658. }
  659. std::string filename = testingDir + "/" + name;
  660. stream.Open(filename.c_str());
  661. if( !stream )
  662. {
  663. cmCTestLog(this, ERROR_MESSAGE, "Problem opening file: " << filename
  664. << std::endl);
  665. return false;
  666. }
  667. if ( compress )
  668. {
  669. if ( this->CompressXMLFiles )
  670. {
  671. stream.SetCompression(true);
  672. }
  673. }
  674. return true;
  675. }
  676. //----------------------------------------------------------------------
  677. bool cmCTest::AddIfExists(SetOfStrings& files, const char* file)
  678. {
  679. if ( this->CTestFileExists(file) )
  680. {
  681. files.insert(file);
  682. }
  683. else
  684. {
  685. std::string name = file;
  686. name += ".gz";
  687. if ( this->CTestFileExists(name.c_str()) )
  688. {
  689. files.insert(name.c_str());
  690. }
  691. else
  692. {
  693. return false;
  694. }
  695. }
  696. return true;
  697. }
  698. //----------------------------------------------------------------------
  699. bool cmCTest::CTestFileExists(const std::string& filename)
  700. {
  701. std::string testingDir = this->BinaryDir + "/Testing/" +
  702. this->CurrentTag + "/" + filename;
  703. return cmSystemTools::FileExists(testingDir.c_str());
  704. }
  705. //----------------------------------------------------------------------
  706. cmCTestGenericHandler* cmCTest::GetInitializedHandler(const char* handler)
  707. {
  708. cmCTest::t_TestingHandlers::iterator it =
  709. this->TestingHandlers.find(handler);
  710. if ( it == this->TestingHandlers.end() )
  711. {
  712. return 0;
  713. }
  714. it->second->Initialize();
  715. return it->second;
  716. }
  717. //----------------------------------------------------------------------
  718. cmCTestGenericHandler* cmCTest::GetHandler(const char* handler)
  719. {
  720. cmCTest::t_TestingHandlers::iterator it =
  721. this->TestingHandlers.find(handler);
  722. if ( it == this->TestingHandlers.end() )
  723. {
  724. return 0;
  725. }
  726. return it->second;
  727. }
  728. //----------------------------------------------------------------------
  729. int cmCTest::ExecuteHandler(const char* shandler)
  730. {
  731. cmCTestGenericHandler* handler = this->GetHandler(shandler);
  732. if ( !handler )
  733. {
  734. return -1;
  735. }
  736. handler->Initialize();
  737. return handler->ProcessHandler();
  738. }
  739. //----------------------------------------------------------------------
  740. int cmCTest::ProcessTests()
  741. {
  742. int res = 0;
  743. bool notest = true;
  744. int cc;
  745. int update_count = 0;
  746. cmCTestLog(this, OUTPUT, "Start processing tests" << std::endl);
  747. for ( cc = 0; cc < LAST_TEST; cc ++ )
  748. {
  749. if ( this->Tests[cc] )
  750. {
  751. notest = false;
  752. break;
  753. }
  754. }
  755. if (( this->Tests[UPDATE_TEST] || this->Tests[ALL_TEST] ) &&
  756. (this->GetRemainingTimeAllowed() - 120 > 0))
  757. {
  758. cmCTestGenericHandler* uphandler = this->GetHandler("update");
  759. uphandler->SetPersistentOption("SourceDirectory",
  760. this->GetCTestConfiguration("SourceDirectory").c_str());
  761. update_count = uphandler->ProcessHandler();
  762. if ( update_count < 0 )
  763. {
  764. res |= cmCTest::UPDATE_ERRORS;
  765. }
  766. }
  767. if ( this->TestModel == cmCTest::CONTINUOUS && !update_count )
  768. {
  769. return 0;
  770. }
  771. if (( this->Tests[CONFIGURE_TEST] || this->Tests[ALL_TEST] )&&
  772. (this->GetRemainingTimeAllowed() - 120 > 0))
  773. {
  774. if (this->GetHandler("configure")->ProcessHandler() < 0)
  775. {
  776. res |= cmCTest::CONFIGURE_ERRORS;
  777. }
  778. }
  779. if (( this->Tests[BUILD_TEST] || this->Tests[ALL_TEST] )&&
  780. (this->GetRemainingTimeAllowed() - 120 > 0))
  781. {
  782. this->UpdateCTestConfiguration();
  783. if (this->GetHandler("build")->ProcessHandler() < 0)
  784. {
  785. res |= cmCTest::BUILD_ERRORS;
  786. }
  787. }
  788. if (( this->Tests[TEST_TEST] || this->Tests[ALL_TEST] || notest ) &&
  789. (this->GetRemainingTimeAllowed() - 120 > 0))
  790. {
  791. this->UpdateCTestConfiguration();
  792. if (this->GetHandler("test")->ProcessHandler() < 0)
  793. {
  794. res |= cmCTest::TEST_ERRORS;
  795. }
  796. }
  797. if (( this->Tests[COVERAGE_TEST] || this->Tests[ALL_TEST] ) &&
  798. (this->GetRemainingTimeAllowed() - 120 > 0))
  799. {
  800. this->UpdateCTestConfiguration();
  801. if (this->GetHandler("coverage")->ProcessHandler() < 0)
  802. {
  803. res |= cmCTest::COVERAGE_ERRORS;
  804. }
  805. }
  806. if (( this->Tests[MEMCHECK_TEST] || this->Tests[ALL_TEST] )&&
  807. (this->GetRemainingTimeAllowed() - 120 > 0))
  808. {
  809. this->UpdateCTestConfiguration();
  810. if (this->GetHandler("memcheck")->ProcessHandler() < 0)
  811. {
  812. res |= cmCTest::MEMORY_ERRORS;
  813. }
  814. }
  815. if ( !notest )
  816. {
  817. std::string notes_dir = this->BinaryDir + "/Testing/Notes";
  818. if ( cmSystemTools::FileIsDirectory(notes_dir.c_str()) )
  819. {
  820. cmsys::Directory d;
  821. d.Load(notes_dir.c_str());
  822. unsigned long kk;
  823. for ( kk = 0; kk < d.GetNumberOfFiles(); kk ++ )
  824. {
  825. const char* file = d.GetFile(kk);
  826. std::string fullname = notes_dir + "/" + file;
  827. if ( cmSystemTools::FileExists(fullname.c_str()) &&
  828. !cmSystemTools::FileIsDirectory(fullname.c_str()) )
  829. {
  830. if ( this->NotesFiles.size() > 0 )
  831. {
  832. this->NotesFiles += ";";
  833. }
  834. this->NotesFiles += fullname;
  835. this->Tests[NOTES_TEST] = 1;
  836. }
  837. }
  838. }
  839. }
  840. if ( this->Tests[NOTES_TEST] || this->Tests[ALL_TEST] )
  841. {
  842. this->UpdateCTestConfiguration();
  843. if ( this->NotesFiles.size() )
  844. {
  845. this->GenerateNotesFile(this->NotesFiles.c_str());
  846. }
  847. }
  848. if ( this->Tests[SUBMIT_TEST] || this->Tests[ALL_TEST] )
  849. {
  850. this->UpdateCTestConfiguration();
  851. if (this->GetHandler("submit")->ProcessHandler() < 0)
  852. {
  853. res |= cmCTest::SUBMIT_ERRORS;
  854. }
  855. }
  856. if ( res != 0 )
  857. {
  858. cmCTestLog(this, ERROR_MESSAGE, "Errors while running CTest"
  859. << std::endl);
  860. }
  861. return res;
  862. }
  863. //----------------------------------------------------------------------
  864. std::string cmCTest::GetTestModelString()
  865. {
  866. if ( !this->SpecificTrack.empty() )
  867. {
  868. return this->SpecificTrack;
  869. }
  870. switch ( this->TestModel )
  871. {
  872. case cmCTest::NIGHTLY:
  873. return "Nightly";
  874. case cmCTest::CONTINUOUS:
  875. return "Continuous";
  876. }
  877. return "Experimental";
  878. }
  879. //----------------------------------------------------------------------
  880. int cmCTest::GetTestModelFromString(const char* str)
  881. {
  882. if ( !str )
  883. {
  884. return cmCTest::EXPERIMENTAL;
  885. }
  886. std::string rstr = cmSystemTools::LowerCase(str);
  887. if ( strncmp(rstr.c_str(), "cont", 4) == 0 )
  888. {
  889. return cmCTest::CONTINUOUS;
  890. }
  891. if ( strncmp(rstr.c_str(), "nigh", 4) == 0 )
  892. {
  893. return cmCTest::NIGHTLY;
  894. }
  895. return cmCTest::EXPERIMENTAL;
  896. }
  897. //######################################################################
  898. //######################################################################
  899. //######################################################################
  900. //######################################################################
  901. //----------------------------------------------------------------------
  902. int cmCTest::RunMakeCommand(const char* command, std::string* output,
  903. int* retVal, const char* dir, int timeout, std::ofstream& ofs)
  904. {
  905. // First generate the command and arguments
  906. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  907. if(args.size() < 1)
  908. {
  909. return false;
  910. }
  911. std::vector<const char*> argv;
  912. for(std::vector<cmStdString>::const_iterator a = args.begin();
  913. a != args.end(); ++a)
  914. {
  915. argv.push_back(a->c_str());
  916. }
  917. argv.push_back(0);
  918. if ( output )
  919. {
  920. *output = "";
  921. }
  922. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Run command:");
  923. std::vector<const char*>::iterator ait;
  924. for ( ait = argv.begin(); ait != argv.end() && *ait; ++ ait )
  925. {
  926. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\"");
  927. }
  928. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, std::endl);
  929. // Now create process object
  930. cmsysProcess* cp = cmsysProcess_New();
  931. cmsysProcess_SetCommand(cp, &*argv.begin());
  932. cmsysProcess_SetWorkingDirectory(cp, dir);
  933. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  934. cmsysProcess_SetTimeout(cp, timeout);
  935. cmsysProcess_Execute(cp);
  936. // Initialize tick's
  937. std::string::size_type tick = 0;
  938. std::string::size_type tick_len = 1024;
  939. std::string::size_type tick_line_len = 50;
  940. char* data;
  941. int length;
  942. cmCTestLog(this, HANDLER_OUTPUT,
  943. " Each . represents " << tick_len << " bytes of output" << std::endl
  944. << " " << std::flush);
  945. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  946. {
  947. if ( output )
  948. {
  949. for(int cc =0; cc < length; ++cc)
  950. {
  951. if(data[cc] == 0)
  952. {
  953. data[cc] = '\n';
  954. }
  955. }
  956. output->append(data, length);
  957. while ( output->size() > (tick * tick_len) )
  958. {
  959. tick ++;
  960. cmCTestLog(this, HANDLER_OUTPUT, "." << std::flush);
  961. if ( tick % tick_line_len == 0 && tick > 0 )
  962. {
  963. cmCTestLog(this, HANDLER_OUTPUT, " Size: "
  964. << int((output->size() / 1024.0) + 1) << "K" << std::endl
  965. << " " << std::flush);
  966. }
  967. }
  968. }
  969. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length));
  970. if ( ofs )
  971. {
  972. ofs << cmCTestLogWrite(data, length);
  973. }
  974. }
  975. cmCTestLog(this, OUTPUT, " Size of output: "
  976. << int(output->size() / 1024.0) << "K" << std::endl);
  977. cmsysProcess_WaitForExit(cp, 0);
  978. int result = cmsysProcess_GetState(cp);
  979. if(result == cmsysProcess_State_Exited)
  980. {
  981. *retVal = cmsysProcess_GetExitValue(cp);
  982. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Command exited with the value: "
  983. << *retVal << std::endl);
  984. }
  985. else if(result == cmsysProcess_State_Exception)
  986. {
  987. *retVal = cmsysProcess_GetExitException(cp);
  988. cmCTestLog(this, WARNING, "There was an exception: " << *retVal
  989. << std::endl);
  990. }
  991. else if(result == cmsysProcess_State_Expired)
  992. {
  993. cmCTestLog(this, WARNING, "There was a timeout" << std::endl);
  994. }
  995. else if(result == cmsysProcess_State_Error)
  996. {
  997. *output += "\n*** ERROR executing: ";
  998. *output += cmsysProcess_GetErrorString(cp);
  999. *output += "\n***The build process failed.";
  1000. cmCTestLog(this, ERROR_MESSAGE, "There was an error: "
  1001. << cmsysProcess_GetErrorString(cp) << std::endl);
  1002. }
  1003. cmsysProcess_Delete(cp);
  1004. return result;
  1005. }
  1006. //######################################################################
  1007. //######################################################################
  1008. //######################################################################
  1009. //######################################################################
  1010. //----------------------------------------------------------------------
  1011. int cmCTest::RunTest(std::vector<const char*> argv,
  1012. std::string* output, int *retVal,
  1013. std::ostream* log, double testTimeOut)
  1014. {
  1015. // determine how much time we have
  1016. double timeout = this->GetRemainingTimeAllowed() - 120;
  1017. if (this->TimeOut && this->TimeOut < timeout)
  1018. {
  1019. timeout = this->TimeOut;
  1020. }
  1021. if (testTimeOut && testTimeOut < timeout)
  1022. {
  1023. timeout = testTimeOut;
  1024. }
  1025. // always have at least 1 second if we got to here
  1026. if (timeout <= 0)
  1027. {
  1028. timeout = 1;
  1029. }
  1030. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  1031. "Test timeout computed to be: " << timeout << "\n");
  1032. if(cmSystemTools::SameFile(argv[0], this->CTestSelf.c_str()) &&
  1033. !this->ForceNewCTestProcess)
  1034. {
  1035. cmCTest inst;
  1036. inst.ConfigType = this->ConfigType;
  1037. inst.TimeOut = timeout;
  1038. std::vector<std::string> args;
  1039. for(unsigned int i =0; i < argv.size(); ++i)
  1040. {
  1041. if(argv[i])
  1042. {
  1043. // make sure we pass the timeout in for any build and test
  1044. // invocations. Since --build-generator is required this is a
  1045. // good place to check for it, and to add the arguments in
  1046. if (strcmp(argv[i],"--build-generator") == 0 && timeout)
  1047. {
  1048. args.push_back("--test-timeout");
  1049. cmOStringStream msg;
  1050. msg << timeout;
  1051. args.push_back(msg.str());
  1052. }
  1053. args.push_back(argv[i]);
  1054. }
  1055. }
  1056. if ( *log )
  1057. {
  1058. *log << "* Run internal CTest" << std::endl;
  1059. }
  1060. std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
  1061. *retVal = inst.Run(args, output);
  1062. if ( *log )
  1063. {
  1064. *log << output->c_str();
  1065. }
  1066. cmSystemTools::ChangeDirectory(oldpath.c_str());
  1067. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  1068. "Internal cmCTest object used to run test." << std::endl
  1069. << *output << std::endl);
  1070. return cmsysProcess_State_Exited;
  1071. }
  1072. std::vector<char> tempOutput;
  1073. if ( output )
  1074. {
  1075. *output = "";
  1076. }
  1077. cmsysProcess* cp = cmsysProcess_New();
  1078. cmsysProcess_SetCommand(cp, &*argv.begin());
  1079. cmCTestLog(this, DEBUG, "Command is: " << argv[0] << std::endl);
  1080. if(cmSystemTools::GetRunCommandHideConsole())
  1081. {
  1082. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  1083. }
  1084. cmsysProcess_SetTimeout(cp, timeout);
  1085. cmsysProcess_Execute(cp);
  1086. char* data;
  1087. int length;
  1088. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  1089. {
  1090. if ( output )
  1091. {
  1092. tempOutput.insert(tempOutput.end(), data, data+length);
  1093. }
  1094. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length));
  1095. if ( log )
  1096. {
  1097. log->write(data, length);
  1098. }
  1099. }
  1100. cmsysProcess_WaitForExit(cp, 0);
  1101. if(output && tempOutput.begin() != tempOutput.end())
  1102. {
  1103. output->append(&*tempOutput.begin(), tempOutput.size());
  1104. }
  1105. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "-- Process completed"
  1106. << std::endl);
  1107. int result = cmsysProcess_GetState(cp);
  1108. if(result == cmsysProcess_State_Exited)
  1109. {
  1110. *retVal = cmsysProcess_GetExitValue(cp);
  1111. }
  1112. else if(result == cmsysProcess_State_Exception)
  1113. {
  1114. *retVal = cmsysProcess_GetExitException(cp);
  1115. std::string outerr = "\n*** Exception executing: ";
  1116. outerr += cmsysProcess_GetExceptionString(cp);
  1117. *output += outerr;
  1118. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl
  1119. << std::flush);
  1120. }
  1121. else if(result == cmsysProcess_State_Error)
  1122. {
  1123. std::string outerr = "\n*** ERROR executing: ";
  1124. outerr += cmsysProcess_GetErrorString(cp);
  1125. *output += outerr;
  1126. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl
  1127. << std::flush);
  1128. }
  1129. cmsysProcess_Delete(cp);
  1130. return result;
  1131. }
  1132. //----------------------------------------------------------------------
  1133. void cmCTest::StartXML(std::ostream& ostr)
  1134. {
  1135. ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1136. << "<Site BuildName=\"" << this->GetCTestConfiguration("BuildName")
  1137. << "\" BuildStamp=\"" << this->CurrentTag << "-"
  1138. << this->GetTestModelString() << "\" Name=\""
  1139. << this->GetCTestConfiguration("Site") << "\" Generator=\"ctest"
  1140. << cmVersion::GetCMakeVersion()
  1141. << "\">" << std::endl;
  1142. }
  1143. //----------------------------------------------------------------------
  1144. void cmCTest::EndXML(std::ostream& ostr)
  1145. {
  1146. ostr << "</Site>" << std::endl;
  1147. }
  1148. //----------------------------------------------------------------------
  1149. int cmCTest::GenerateCTestNotesOutput(std::ostream& os,
  1150. const cmCTest::VectorOfStrings& files)
  1151. {
  1152. cmCTest::VectorOfStrings::const_iterator it;
  1153. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1154. << "<?xml-stylesheet type=\"text/xsl\" "
  1155. "href=\"Dart/Source/Server/XSL/Build.xsl "
  1156. "<file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
  1157. << "<Site BuildName=\"" << this->GetCTestConfiguration("BuildName")
  1158. << "\" BuildStamp=\""
  1159. << this->CurrentTag << "-" << this->GetTestModelString() << "\" Name=\""
  1160. << this->GetCTestConfiguration("Site") << "\" Generator=\"ctest"
  1161. << cmVersion::GetCMakeVersion()
  1162. << "\">\n"
  1163. << "<Notes>" << std::endl;
  1164. for ( it = files.begin(); it != files.end(); it ++ )
  1165. {
  1166. cmCTestLog(this, OUTPUT, "\tAdd file: " << it->c_str() << std::endl);
  1167. std::string note_time = this->CurrentTime();
  1168. os << "<Note Name=\"" << this->MakeXMLSafe(it->c_str()) << "\">\n"
  1169. << "<DateTime>" << note_time << "</DateTime>\n"
  1170. << "<Text>" << std::endl;
  1171. std::ifstream ifs(it->c_str());
  1172. if ( ifs )
  1173. {
  1174. std::string line;
  1175. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  1176. {
  1177. os << this->MakeXMLSafe(line) << std::endl;
  1178. }
  1179. ifs.close();
  1180. }
  1181. else
  1182. {
  1183. os << "Problem reading file: " << it->c_str() << std::endl;
  1184. cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: " << it->c_str()
  1185. << " while creating notes" << std::endl);
  1186. }
  1187. os << "</Text>\n"
  1188. << "</Note>" << std::endl;
  1189. }
  1190. os << "</Notes>\n"
  1191. << "</Site>" << std::endl;
  1192. return 1;
  1193. }
  1194. //----------------------------------------------------------------------
  1195. int cmCTest::GenerateNotesFile(const std::vector<cmStdString> &files)
  1196. {
  1197. cmGeneratedFileStream ofs;
  1198. if ( !this->OpenOutputFile(this->CurrentTag, "Notes.xml", ofs) )
  1199. {
  1200. cmCTestLog(this, ERROR_MESSAGE, "Cannot open notes file" << std::endl);
  1201. return 1;
  1202. }
  1203. this->GenerateCTestNotesOutput(ofs, files);
  1204. return 0;
  1205. }
  1206. //----------------------------------------------------------------------
  1207. int cmCTest::GenerateNotesFile(const char* cfiles)
  1208. {
  1209. if ( !cfiles )
  1210. {
  1211. return 1;
  1212. }
  1213. std::vector<cmStdString> files;
  1214. cmCTestLog(this, OUTPUT, "Create notes file" << std::endl);
  1215. files = cmSystemTools::SplitString(cfiles, ';');
  1216. if ( files.size() == 0 )
  1217. {
  1218. return 1;
  1219. }
  1220. return this->GenerateNotesFile(files);
  1221. }
  1222. //----------------------------------------------------------------------
  1223. bool cmCTest::SubmitExtraFiles(const std::vector<cmStdString> &files)
  1224. {
  1225. std::vector<cmStdString>::const_iterator it;
  1226. for ( it = files.begin();
  1227. it != files.end();
  1228. ++ it )
  1229. {
  1230. if ( !cmSystemTools::FileExists(it->c_str()) )
  1231. {
  1232. cmCTestLog(this, ERROR_MESSAGE, "Cannot find extra file: "
  1233. << it->c_str() << " to submit."
  1234. << std::endl;);
  1235. return false;
  1236. }
  1237. this->AddSubmitFile(it->c_str());
  1238. }
  1239. return true;
  1240. }
  1241. //----------------------------------------------------------------------
  1242. bool cmCTest::SubmitExtraFiles(const char* cfiles)
  1243. {
  1244. if ( !cfiles )
  1245. {
  1246. return 1;
  1247. }
  1248. std::vector<cmStdString> files;
  1249. cmCTestLog(this, OUTPUT, "Submit extra files" << std::endl);
  1250. files = cmSystemTools::SplitString(cfiles, ';');
  1251. if ( files.size() == 0 )
  1252. {
  1253. return 1;
  1254. }
  1255. return this->SubmitExtraFiles(files);
  1256. }
  1257. //-------------------------------------------------------
  1258. // for a -D argument convert the next argument into
  1259. // the proper list of dashboard steps via SetTest
  1260. bool cmCTest::AddTestsForDashboardType(std::string &targ)
  1261. {
  1262. if ( targ == "Experimental" )
  1263. {
  1264. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1265. this->SetTest("Start");
  1266. this->SetTest("Configure");
  1267. this->SetTest("Build");
  1268. this->SetTest("Test");
  1269. this->SetTest("Coverage");
  1270. this->SetTest("Submit");
  1271. }
  1272. else if ( targ == "ExperimentalStart" )
  1273. {
  1274. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1275. this->SetTest("Start");
  1276. }
  1277. else if ( targ == "ExperimentalUpdate" )
  1278. {
  1279. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1280. this->SetTest("Update");
  1281. }
  1282. else if ( targ == "ExperimentalConfigure" )
  1283. {
  1284. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1285. this->SetTest("Configure");
  1286. }
  1287. else if ( targ == "ExperimentalBuild" )
  1288. {
  1289. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1290. this->SetTest("Build");
  1291. }
  1292. else if ( targ == "ExperimentalTest" )
  1293. {
  1294. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1295. this->SetTest("Test");
  1296. }
  1297. else if ( targ == "ExperimentalMemCheck"
  1298. || targ == "ExperimentalPurify" )
  1299. {
  1300. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1301. this->SetTest("MemCheck");
  1302. }
  1303. else if ( targ == "ExperimentalCoverage" )
  1304. {
  1305. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1306. this->SetTest("Coverage");
  1307. }
  1308. else if ( targ == "ExperimentalSubmit" )
  1309. {
  1310. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1311. this->SetTest("Submit");
  1312. }
  1313. else if ( targ == "Continuous" )
  1314. {
  1315. this->SetTestModel(cmCTest::CONTINUOUS);
  1316. this->SetTest("Start");
  1317. this->SetTest("Update");
  1318. this->SetTest("Configure");
  1319. this->SetTest("Build");
  1320. this->SetTest("Test");
  1321. this->SetTest("Coverage");
  1322. this->SetTest("Submit");
  1323. }
  1324. else if ( targ == "ContinuousStart" )
  1325. {
  1326. this->SetTestModel(cmCTest::CONTINUOUS);
  1327. this->SetTest("Start");
  1328. }
  1329. else if ( targ == "ContinuousUpdate" )
  1330. {
  1331. this->SetTestModel(cmCTest::CONTINUOUS);
  1332. this->SetTest("Update");
  1333. }
  1334. else if ( targ == "ContinuousConfigure" )
  1335. {
  1336. this->SetTestModel(cmCTest::CONTINUOUS);
  1337. this->SetTest("Configure");
  1338. }
  1339. else if ( targ == "ContinuousBuild" )
  1340. {
  1341. this->SetTestModel(cmCTest::CONTINUOUS);
  1342. this->SetTest("Build");
  1343. }
  1344. else if ( targ == "ContinuousTest" )
  1345. {
  1346. this->SetTestModel(cmCTest::CONTINUOUS);
  1347. this->SetTest("Test");
  1348. }
  1349. else if ( targ == "ContinuousMemCheck"
  1350. || targ == "ContinuousPurify" )
  1351. {
  1352. this->SetTestModel(cmCTest::CONTINUOUS);
  1353. this->SetTest("MemCheck");
  1354. }
  1355. else if ( targ == "ContinuousCoverage" )
  1356. {
  1357. this->SetTestModel(cmCTest::CONTINUOUS);
  1358. this->SetTest("Coverage");
  1359. }
  1360. else if ( targ == "ContinuousSubmit" )
  1361. {
  1362. this->SetTestModel(cmCTest::CONTINUOUS);
  1363. this->SetTest("Submit");
  1364. }
  1365. else if ( targ == "Nightly" )
  1366. {
  1367. this->SetTestModel(cmCTest::NIGHTLY);
  1368. this->SetTest("Start");
  1369. this->SetTest("Update");
  1370. this->SetTest("Configure");
  1371. this->SetTest("Build");
  1372. this->SetTest("Test");
  1373. this->SetTest("Coverage");
  1374. this->SetTest("Submit");
  1375. }
  1376. else if ( targ == "NightlyStart" )
  1377. {
  1378. this->SetTestModel(cmCTest::NIGHTLY);
  1379. this->SetTest("Start");
  1380. }
  1381. else if ( targ == "NightlyUpdate" )
  1382. {
  1383. this->SetTestModel(cmCTest::NIGHTLY);
  1384. this->SetTest("Update");
  1385. }
  1386. else if ( targ == "NightlyConfigure" )
  1387. {
  1388. this->SetTestModel(cmCTest::NIGHTLY);
  1389. this->SetTest("Configure");
  1390. }
  1391. else if ( targ == "NightlyBuild" )
  1392. {
  1393. this->SetTestModel(cmCTest::NIGHTLY);
  1394. this->SetTest("Build");
  1395. }
  1396. else if ( targ == "NightlyTest" )
  1397. {
  1398. this->SetTestModel(cmCTest::NIGHTLY);
  1399. this->SetTest("Test");
  1400. }
  1401. else if ( targ == "NightlyMemCheck"
  1402. || targ == "NightlyPurify" )
  1403. {
  1404. this->SetTestModel(cmCTest::NIGHTLY);
  1405. this->SetTest("MemCheck");
  1406. }
  1407. else if ( targ == "NightlyCoverage" )
  1408. {
  1409. this->SetTestModel(cmCTest::NIGHTLY);
  1410. this->SetTest("Coverage");
  1411. }
  1412. else if ( targ == "NightlySubmit" )
  1413. {
  1414. this->SetTestModel(cmCTest::NIGHTLY);
  1415. this->SetTest("Submit");
  1416. }
  1417. else if ( targ == "MemoryCheck" )
  1418. {
  1419. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1420. this->SetTest("Start");
  1421. this->SetTest("Configure");
  1422. this->SetTest("Build");
  1423. this->SetTest("MemCheck");
  1424. this->SetTest("Coverage");
  1425. this->SetTest("Submit");
  1426. }
  1427. else if ( targ == "NightlyMemoryCheck" )
  1428. {
  1429. this->SetTestModel(cmCTest::NIGHTLY);
  1430. this->SetTest("Start");
  1431. this->SetTest("Update");
  1432. this->SetTest("Configure");
  1433. this->SetTest("Build");
  1434. this->SetTest("MemCheck");
  1435. this->SetTest("Coverage");
  1436. this->SetTest("Submit");
  1437. }
  1438. else
  1439. {
  1440. cmCTestLog(this, ERROR_MESSAGE,
  1441. "CTest -D called with incorrect option: "
  1442. << targ << std::endl);
  1443. cmCTestLog(this, ERROR_MESSAGE, "Available options are:" << std::endl
  1444. << " " << "ctest" << " -D Continuous" << std::endl
  1445. << " " << "ctest"
  1446. << " -D Continuous(Start|Update|Configure|Build)" << std::endl
  1447. << " " << "ctest"
  1448. << " -D Continuous(Test|Coverage|MemCheck|Submit)"
  1449. << std::endl
  1450. << " " << "ctest" << " -D Experimental" << std::endl
  1451. << " " << "ctest"
  1452. << " -D Experimental(Start|Update|Configure|Build)"
  1453. << std::endl
  1454. << " " << "ctest"
  1455. << " -D Experimental(Test|Coverage|MemCheck|Submit)"
  1456. << std::endl
  1457. << " " << "ctest" << " -D Nightly" << std::endl
  1458. << " " << "ctest"
  1459. << " -D Nightly(Start|Update|Configure|Build)" << std::endl
  1460. << " " << "ctest"
  1461. << " -D Nightly(Test|Coverage|MemCheck|Submit)" << std::endl
  1462. << " " << "ctest" << " -D NightlyMemoryCheck" << std::endl);
  1463. return false;
  1464. }
  1465. return true;
  1466. }
  1467. //----------------------------------------------------------------------
  1468. bool cmCTest::CheckArgument(const std::string& arg, const char* varg1,
  1469. const char* varg2)
  1470. {
  1471. if ( varg1 && arg == varg1 || varg2 && arg == varg2 )
  1472. {
  1473. return true;
  1474. }
  1475. return false;
  1476. }
  1477. //----------------------------------------------------------------------
  1478. // Processes one command line argument (and its arguments if any)
  1479. // for many simple options and then returns
  1480. void cmCTest::HandleCommandLineArguments(size_t &i,
  1481. std::vector<std::string> &args)
  1482. {
  1483. std::string arg = args[i];
  1484. if(this->CheckArgument(arg, "--ctest-config") && i < args.size() - 1)
  1485. {
  1486. i++;
  1487. this->CTestConfigFile= args[i];
  1488. }
  1489. if(this->CheckArgument(arg, "-C", "--build-config") &&
  1490. i < args.size() - 1)
  1491. {
  1492. i++;
  1493. this->SetConfigType(args[i].c_str());
  1494. }
  1495. if(this->CheckArgument(arg, "--debug"))
  1496. {
  1497. this->Debug = true;
  1498. this->ShowLineNumbers = true;
  1499. }
  1500. if(this->CheckArgument(arg, "--track") && i < args.size() - 1)
  1501. {
  1502. i++;
  1503. this->SpecificTrack = args[i];
  1504. }
  1505. if(this->CheckArgument(arg, "--show-line-numbers"))
  1506. {
  1507. this->ShowLineNumbers = true;
  1508. }
  1509. if(this->CheckArgument(arg, "-Q", "--quiet"))
  1510. {
  1511. this->Quiet = true;
  1512. }
  1513. if(this->CheckArgument(arg, "-V", "--verbose"))
  1514. {
  1515. this->Verbose = true;
  1516. }
  1517. if(this->CheckArgument(arg, "-VV", "--extra-verbose"))
  1518. {
  1519. this->ExtraVerbose = true;
  1520. this->Verbose = true;
  1521. }
  1522. if(this->CheckArgument(arg, "-N", "--show-only"))
  1523. {
  1524. this->ShowOnly = true;
  1525. }
  1526. if(this->CheckArgument(arg, "-O", "--output-log") && i < args.size() - 1 )
  1527. {
  1528. i++;
  1529. this->SetOutputLogFileName(args[i].c_str());
  1530. }
  1531. if(this->CheckArgument(arg, "--tomorrow-tag"))
  1532. {
  1533. this->TomorrowTag = true;
  1534. }
  1535. if(this->CheckArgument(arg, "--force-new-ctest-process"))
  1536. {
  1537. this->ForceNewCTestProcess = true;
  1538. }
  1539. if(this->CheckArgument(arg, "--interactive-debug-mode") &&
  1540. i < args.size() - 1 )
  1541. {
  1542. i++;
  1543. this->InteractiveDebugMode = cmSystemTools::IsOn(args[i].c_str());
  1544. }
  1545. if(this->CheckArgument(arg, "--submit-index") && i < args.size() - 1 )
  1546. {
  1547. i++;
  1548. this->SubmitIndex = atoi(args[i].c_str());
  1549. if ( this->SubmitIndex < 0 )
  1550. {
  1551. this->SubmitIndex = 0;
  1552. }
  1553. }
  1554. if(this->CheckArgument(arg, "--overwrite") && i < args.size() - 1)
  1555. {
  1556. i++;
  1557. this->AddCTestConfigurationOverwrite(args[i].c_str());
  1558. }
  1559. if(this->CheckArgument(arg, "-A", "--add-notes") && i < args.size() - 1)
  1560. {
  1561. this->ProduceXML = true;
  1562. this->SetTest("Notes");
  1563. i++;
  1564. this->SetNotesFiles(args[i].c_str());
  1565. }
  1566. // options that control what tests are run
  1567. if(this->CheckArgument(arg, "-I", "--tests-information") &&
  1568. i < args.size() - 1)
  1569. {
  1570. i++;
  1571. this->GetHandler("test")->SetPersistentOption("TestsToRunInformation",
  1572. args[i].c_str());
  1573. this->GetHandler("memcheck")->
  1574. SetPersistentOption("TestsToRunInformation",args[i].c_str());
  1575. }
  1576. if(this->CheckArgument(arg, "-U", "--union"))
  1577. {
  1578. this->GetHandler("test")->SetPersistentOption("UseUnion", "true");
  1579. this->GetHandler("memcheck")->SetPersistentOption("UseUnion", "true");
  1580. }
  1581. if(this->CheckArgument(arg, "-R", "--tests-regex") && i < args.size() - 1)
  1582. {
  1583. i++;
  1584. this->GetHandler("test")->
  1585. SetPersistentOption("IncludeRegularExpression", args[i].c_str());
  1586. this->GetHandler("memcheck")->
  1587. SetPersistentOption("IncludeRegularExpression", args[i].c_str());
  1588. }
  1589. if(this->CheckArgument(arg, "-E", "--exclude-regex") &&
  1590. i < args.size() - 1)
  1591. {
  1592. i++;
  1593. this->GetHandler("test")->
  1594. SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
  1595. this->GetHandler("memcheck")->
  1596. SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
  1597. }
  1598. }
  1599. //----------------------------------------------------------------------
  1600. // handle the -S -SR and -SP arguments
  1601. void cmCTest::HandleScriptArguments(size_t &i,
  1602. std::vector<std::string> &args,
  1603. bool &SRArgumentSpecified)
  1604. {
  1605. std::string arg = args[i];
  1606. if(this->CheckArgument(arg, "-SP", "--script-new-process") &&
  1607. i < args.size() - 1 )
  1608. {
  1609. this->RunConfigurationScript = true;
  1610. i++;
  1611. cmCTestScriptHandler* ch
  1612. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1613. // -SR is an internal argument, -SP should be ignored when it is passed
  1614. if (!SRArgumentSpecified)
  1615. {
  1616. ch->AddConfigurationScript(args[i].c_str(),false);
  1617. }
  1618. }
  1619. if(this->CheckArgument(arg, "-SR", "--script-run") &&
  1620. i < args.size() - 1 )
  1621. {
  1622. SRArgumentSpecified = true;
  1623. this->RunConfigurationScript = true;
  1624. i++;
  1625. cmCTestScriptHandler* ch
  1626. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1627. ch->AddConfigurationScript(args[i].c_str(),true);
  1628. }
  1629. if(this->CheckArgument(arg, "-S", "--script") && i < args.size() - 1 )
  1630. {
  1631. this->RunConfigurationScript = true;
  1632. i++;
  1633. cmCTestScriptHandler* ch
  1634. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1635. // -SR is an internal argument, -S should be ignored when it is passed
  1636. if (!SRArgumentSpecified)
  1637. {
  1638. ch->AddConfigurationScript(args[i].c_str(),true);
  1639. }
  1640. }
  1641. }
  1642. //----------------------------------------------------------------------
  1643. // the main entry point of ctest, called from main
  1644. int cmCTest::Run(std::vector<std::string> &args, std::string* output)
  1645. {
  1646. this->FindRunningCMake(args[0].c_str());
  1647. const char* ctestExec = "ctest";
  1648. bool cmakeAndTest = false;
  1649. bool performSomeTest = true;
  1650. bool SRArgumentSpecified = false;
  1651. // copy the command line
  1652. for(size_t i=0; i < args.size(); ++i)
  1653. {
  1654. this->InitialCommandLineArguments.push_back(args[i]);
  1655. }
  1656. // process the command line arguments
  1657. for(size_t i=1; i < args.size(); ++i)
  1658. {
  1659. // handle the simple commandline arguments
  1660. this->HandleCommandLineArguments(i,args);
  1661. // handle the script arguments -S -SR -SP
  1662. this->HandleScriptArguments(i,args,SRArgumentSpecified);
  1663. // handle a request for a dashboard
  1664. std::string arg = args[i];
  1665. if(this->CheckArgument(arg, "-D", "--dashboard") && i < args.size() - 1 )
  1666. {
  1667. this->ProduceXML = true;
  1668. i++;
  1669. std::string targ = args[i];
  1670. // AddTestsForDashboard parses the dashborad type and converts it
  1671. // into the seperate stages
  1672. if (!this->AddTestsForDashboardType(targ))
  1673. {
  1674. performSomeTest = false;
  1675. }
  1676. }
  1677. if(this->CheckArgument(arg, "-T", "--test-action") &&
  1678. (i < args.size() -1) )
  1679. {
  1680. this->ProduceXML = true;
  1681. i++;
  1682. if ( !this->SetTest(args[i].c_str(), false) )
  1683. {
  1684. performSomeTest = false;
  1685. cmCTestLog(this, ERROR_MESSAGE,
  1686. "CTest -T called with incorrect option: "
  1687. << args[i].c_str() << std::endl);
  1688. cmCTestLog(this, ERROR_MESSAGE, "Available options are:" << std::endl
  1689. << " " << ctestExec << " -T all" << std::endl
  1690. << " " << ctestExec << " -T start" << std::endl
  1691. << " " << ctestExec << " -T update" << std::endl
  1692. << " " << ctestExec << " -T configure" << std::endl
  1693. << " " << ctestExec << " -T build" << std::endl
  1694. << " " << ctestExec << " -T test" << std::endl
  1695. << " " << ctestExec << " -T coverage" << std::endl
  1696. << " " << ctestExec << " -T memcheck" << std::endl
  1697. << " " << ctestExec << " -T notes" << std::endl
  1698. << " " << ctestExec << " -T submit" << std::endl);
  1699. }
  1700. }
  1701. // what type of test model
  1702. if(this->CheckArgument(arg, "-M", "--test-model") &&
  1703. (i < args.size() -1) )
  1704. {
  1705. i++;
  1706. std::string const& str = args[i];
  1707. if ( cmSystemTools::LowerCase(str) == "nightly" )
  1708. {
  1709. this->SetTestModel(cmCTest::NIGHTLY);
  1710. }
  1711. else if ( cmSystemTools::LowerCase(str) == "continuous" )
  1712. {
  1713. this->SetTestModel(cmCTest::CONTINUOUS);
  1714. }
  1715. else if ( cmSystemTools::LowerCase(str) == "experimental" )
  1716. {
  1717. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1718. }
  1719. else
  1720. {
  1721. performSomeTest = false;
  1722. cmCTestLog(this, ERROR_MESSAGE,
  1723. "CTest -M called with incorrect option: " << str.c_str()
  1724. << std::endl);
  1725. cmCTestLog(this, ERROR_MESSAGE, "Available options are:" << std::endl
  1726. << " " << ctestExec << " -M Continuous" << std::endl
  1727. << " " << ctestExec << " -M Experimental" << std::endl
  1728. << " " << ctestExec << " -M Nightly" << std::endl);
  1729. }
  1730. }
  1731. if(this->CheckArgument(arg, "--extra-submit") && i < args.size() - 1)
  1732. {
  1733. this->ProduceXML = true;
  1734. this->SetTest("Submit");
  1735. i++;
  1736. if ( !this->SubmitExtraFiles(args[i].c_str()) )
  1737. {
  1738. return 0;
  1739. }
  1740. }
  1741. // --build-and-test options
  1742. if(this->CheckArgument(arg, "--build-and-test") && i < args.size() - 1)
  1743. {
  1744. cmakeAndTest = true;
  1745. }
  1746. // pass the argument to all the handlers as well, but i may no longer be
  1747. // set to what it was originally so I'm not sure this is working as
  1748. // intended
  1749. cmCTest::t_TestingHandlers::iterator it;
  1750. for ( it = this->TestingHandlers.begin();
  1751. it != this->TestingHandlers.end();
  1752. ++ it )
  1753. {
  1754. if ( !it->second->ProcessCommandLineArguments(arg, i, args) )
  1755. {
  1756. cmCTestLog(this, ERROR_MESSAGE,
  1757. "Problem parsing command line arguments within a handler");
  1758. return 0;
  1759. }
  1760. }
  1761. } // the close of the for argument loop
  1762. // default to the build type of ctest itself if there is one
  1763. #ifdef CMAKE_INTDIR
  1764. if(this->ConfigType.size() == 0)
  1765. {
  1766. this->SetConfigType(CMAKE_INTDIR);
  1767. }
  1768. #endif
  1769. // now what sould cmake do? if --build-and-test was specified then
  1770. // we run the build and test handler and return
  1771. if(cmakeAndTest)
  1772. {
  1773. this->Verbose = true;
  1774. cmCTestBuildAndTestHandler* handler =
  1775. static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest"));
  1776. int retv = handler->ProcessHandler();
  1777. *output = handler->GetOutput();
  1778. #ifdef CMAKE_BUILD_WITH_CMAKE
  1779. cmDynamicLoader::FlushCache();
  1780. #endif
  1781. return retv;
  1782. }
  1783. // if some tests must be run
  1784. if(performSomeTest)
  1785. {
  1786. int res;
  1787. // call process directory
  1788. if (this->RunConfigurationScript)
  1789. {
  1790. if ( this->ExtraVerbose )
  1791. {
  1792. cmCTestLog(this, OUTPUT, "* Extra verbosity turned on" << std::endl);
  1793. }
  1794. cmCTest::t_TestingHandlers::iterator it;
  1795. for ( it = this->TestingHandlers.begin();
  1796. it != this->TestingHandlers.end();
  1797. ++ it )
  1798. {
  1799. it->second->SetVerbose(this->ExtraVerbose);
  1800. it->second->SetSubmitIndex(this->SubmitIndex);
  1801. }
  1802. this->GetHandler("script")->SetVerbose(this->Verbose);
  1803. res = this->GetHandler("script")->ProcessHandler();
  1804. }
  1805. else
  1806. {
  1807. this->ExtraVerbose = this->Verbose;
  1808. this->Verbose = true;
  1809. cmCTest::t_TestingHandlers::iterator it;
  1810. for ( it = this->TestingHandlers.begin();
  1811. it != this->TestingHandlers.end();
  1812. ++ it )
  1813. {
  1814. it->second->SetVerbose(this->Verbose);
  1815. it->second->SetSubmitIndex(this->SubmitIndex);
  1816. }
  1817. if ( !this->Initialize(
  1818. cmSystemTools::GetCurrentWorkingDirectory().c_str()) )
  1819. {
  1820. res = 12;
  1821. cmCTestLog(this, ERROR_MESSAGE, "Problem initializing the dashboard."
  1822. << std::endl);
  1823. }
  1824. else
  1825. {
  1826. res = this->ProcessTests();
  1827. }
  1828. this->Finalize();
  1829. }
  1830. return res;
  1831. }
  1832. return 1;
  1833. }
  1834. //----------------------------------------------------------------------
  1835. void cmCTest::FindRunningCMake(const char* arg0)
  1836. {
  1837. // Find our own executable.
  1838. std::vector<cmStdString> failures;
  1839. this->CTestSelf = arg0;
  1840. cmSystemTools::ConvertToUnixSlashes(this->CTestSelf);
  1841. failures.push_back(this->CTestSelf);
  1842. this->CTestSelf = cmSystemTools::FindProgram(this->CTestSelf.c_str());
  1843. if(!cmSystemTools::FileExists(this->CTestSelf.c_str()))
  1844. {
  1845. failures.push_back(this->CTestSelf);
  1846. this->CTestSelf = "/usr/local/bin/ctest";
  1847. }
  1848. if(!cmSystemTools::FileExists(this->CTestSelf.c_str()))
  1849. {
  1850. failures.push_back(this->CTestSelf);
  1851. cmOStringStream msg;
  1852. msg << "CTEST can not find the command line program ctest.\n";
  1853. msg << " argv[0] = \"" << arg0 << "\"\n";
  1854. msg << " Attempted paths:\n";
  1855. std::vector<cmStdString>::iterator i;
  1856. for(i=failures.begin(); i != failures.end(); ++i)
  1857. {
  1858. msg << " \"" << i->c_str() << "\"\n";
  1859. }
  1860. cmSystemTools::Error(msg.str().c_str());
  1861. }
  1862. std::string dir;
  1863. std::string file;
  1864. if(cmSystemTools::SplitProgramPath(this->CTestSelf.c_str(),
  1865. dir, file, true))
  1866. {
  1867. this->CMakeSelf = dir += "/cmake";
  1868. this->CMakeSelf += cmSystemTools::GetExecutableExtension();
  1869. if(cmSystemTools::FileExists(this->CMakeSelf.c_str()))
  1870. {
  1871. return;
  1872. }
  1873. }
  1874. failures.push_back(this->CMakeSelf);
  1875. #ifdef CMAKE_BUILD_DIR
  1876. std::string intdir = ".";
  1877. #ifdef CMAKE_INTDIR
  1878. intdir = CMAKE_INTDIR;
  1879. #endif
  1880. this->CMakeSelf = CMAKE_BUILD_DIR;
  1881. this->CMakeSelf += "/bin/";
  1882. this->CMakeSelf += intdir;
  1883. this->CMakeSelf += "/cmake";
  1884. this->CMakeSelf += cmSystemTools::GetExecutableExtension();
  1885. #endif
  1886. if(!cmSystemTools::FileExists(this->CMakeSelf.c_str()))
  1887. {
  1888. failures.push_back(this->CMakeSelf);
  1889. cmOStringStream msg;
  1890. msg << "CTEST can not find the command line program cmake.\n";
  1891. msg << " argv[0] = \"" << arg0 << "\"\n";
  1892. msg << " Attempted paths:\n";
  1893. std::vector<cmStdString>::iterator i;
  1894. for(i=failures.begin(); i != failures.end(); ++i)
  1895. {
  1896. msg << " \"" << i->c_str() << "\"\n";
  1897. }
  1898. cmSystemTools::Error(msg.str().c_str());
  1899. }
  1900. }
  1901. //----------------------------------------------------------------------
  1902. void cmCTest::SetNotesFiles(const char* notes)
  1903. {
  1904. if ( !notes )
  1905. {
  1906. return;
  1907. }
  1908. this->NotesFiles = notes;
  1909. }
  1910. //----------------------------------------------------------------------
  1911. int cmCTest::ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf,
  1912. bool fast /* = false */)
  1913. {
  1914. bool found = false;
  1915. VectorOfStrings dirs;
  1916. VectorOfStrings ndirs;
  1917. cmCTestLog(this, DEBUG, "* Read custom CTest configuration directory: "
  1918. << dir << std::endl);
  1919. std::string fname = dir;
  1920. fname += "/CTestCustom.cmake";
  1921. cmCTestLog(this, DEBUG, "* Check for file: "
  1922. << fname.c_str() << std::endl);
  1923. if ( cmSystemTools::FileExists(fname.c_str()) )
  1924. {
  1925. cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: "
  1926. << fname.c_str() << std::endl);
  1927. bool erroroc = cmSystemTools::GetErrorOccuredFlag();
  1928. cmSystemTools::ResetErrorOccuredFlag();
  1929. if ( !mf->ReadListFile(0, fname.c_str()) ||
  1930. cmSystemTools::GetErrorOccuredFlag() )
  1931. {
  1932. cmCTestLog(this, ERROR_MESSAGE,
  1933. "Problem reading custom configuration: "
  1934. << fname.c_str() << std::endl);
  1935. }
  1936. found = true;
  1937. if ( erroroc )
  1938. {
  1939. cmSystemTools::SetErrorOccured();
  1940. }
  1941. }
  1942. if ( !fast )
  1943. {
  1944. std::string rexpr = dir;
  1945. rexpr += "/CTestCustom.ctest";
  1946. cmCTestLog(this, DEBUG, "* Check for file: "
  1947. << rexpr.c_str() << std::endl);
  1948. if ( !found && cmSystemTools::FileExists(rexpr.c_str()) )
  1949. {
  1950. cmsys::Glob gl;
  1951. gl.RecurseOn();
  1952. gl.FindFiles(rexpr);
  1953. std::vector<std::string>& files = gl.GetFiles();
  1954. std::vector<std::string>::iterator fileIt;
  1955. for ( fileIt = files.begin(); fileIt != files.end();
  1956. ++ fileIt )
  1957. {
  1958. cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: "
  1959. << fileIt->c_str() << std::endl);
  1960. if ( !mf->ReadListFile(0, fileIt->c_str()) ||
  1961. cmSystemTools::GetErrorOccuredFlag() )
  1962. {
  1963. cmCTestLog(this, ERROR_MESSAGE,
  1964. "Problem reading custom configuration: "
  1965. << fileIt->c_str() << std::endl);
  1966. }
  1967. }
  1968. found = true;
  1969. }
  1970. }
  1971. if ( found )
  1972. {
  1973. cmCTest::t_TestingHandlers::iterator it;
  1974. for ( it = this->TestingHandlers.begin();
  1975. it != this->TestingHandlers.end(); ++ it )
  1976. {
  1977. cmCTestLog(this, DEBUG,
  1978. "* Read custom CTest configuration vectors for handler: "
  1979. << it->first.c_str() << " (" << it->second << ")" << std::endl);
  1980. it->second->PopulateCustomVectors(mf);
  1981. }
  1982. }
  1983. return 1;
  1984. }
  1985. //----------------------------------------------------------------------
  1986. void cmCTest::PopulateCustomVector(cmMakefile* mf, const char* def,
  1987. VectorOfStrings& vec)
  1988. {
  1989. if ( !def)
  1990. {
  1991. return;
  1992. }
  1993. const char* dval = mf->GetDefinition(def);
  1994. if ( !dval )
  1995. {
  1996. return;
  1997. }
  1998. cmCTestLog(this, DEBUG, "PopulateCustomVector: " << def << std::endl);
  1999. std::vector<std::string> slist;
  2000. cmSystemTools::ExpandListArgument(dval, slist);
  2001. std::vector<std::string>::iterator it;
  2002. for ( it = slist.begin(); it != slist.end(); ++it )
  2003. {
  2004. cmCTestLog(this, DEBUG, " -- " << it->c_str() << std::endl);
  2005. vec.push_back(it->c_str());
  2006. }
  2007. }
  2008. //----------------------------------------------------------------------
  2009. void cmCTest::PopulateCustomInteger(cmMakefile* mf, const char* def, int& val)
  2010. {
  2011. if ( !def)
  2012. {
  2013. return;
  2014. }
  2015. const char* dval = mf->GetDefinition(def);
  2016. if ( !dval )
  2017. {
  2018. return;
  2019. }
  2020. val = atoi(dval);
  2021. }
  2022. //----------------------------------------------------------------------
  2023. std::string cmCTest::GetShortPathToFile(const char* cfname)
  2024. {
  2025. const std::string& sourceDir
  2026. = cmSystemTools::CollapseFullPath(
  2027. this->GetCTestConfiguration("SourceDirectory").c_str());
  2028. const std::string& buildDir
  2029. = cmSystemTools::CollapseFullPath(
  2030. this->GetCTestConfiguration("BuildDirectory").c_str());
  2031. std::string fname = cmSystemTools::CollapseFullPath(cfname);
  2032. // Find relative paths to both directories
  2033. std::string srcRelpath
  2034. = cmSystemTools::RelativePath(sourceDir.c_str(), fname.c_str());
  2035. std::string bldRelpath
  2036. = cmSystemTools::RelativePath(buildDir.c_str(), fname.c_str());
  2037. // If any contains "." it is not parent directory
  2038. bool inSrc = srcRelpath.find("..") == srcRelpath.npos;
  2039. bool inBld = bldRelpath.find("..") == bldRelpath.npos;
  2040. // TODO: Handle files with .. in their name
  2041. std::string* res = 0;
  2042. if ( inSrc && inBld )
  2043. {
  2044. // If both have relative path with no dots, pick the shorter one
  2045. if ( srcRelpath.size() < bldRelpath.size() )
  2046. {
  2047. res = &srcRelpath;
  2048. }
  2049. else
  2050. {
  2051. res = &bldRelpath;
  2052. }
  2053. }
  2054. else if ( inSrc )
  2055. {
  2056. res = &srcRelpath;
  2057. }
  2058. else if ( inBld )
  2059. {
  2060. res = &bldRelpath;
  2061. }
  2062. if ( !res )
  2063. {
  2064. return fname;
  2065. }
  2066. cmSystemTools::ConvertToUnixSlashes(*res);
  2067. std::string path = "./" + *res;
  2068. if ( path[path.size()-1] == '/' )
  2069. {
  2070. path = path.substr(0, path.size()-1);
  2071. }
  2072. return path;
  2073. }
  2074. //----------------------------------------------------------------------
  2075. std::string cmCTest::GetCTestConfiguration(const char *name)
  2076. {
  2077. if ( this->CTestConfigurationOverwrites.find(name) !=
  2078. this->CTestConfigurationOverwrites.end() )
  2079. {
  2080. return this->CTestConfigurationOverwrites[name];
  2081. }
  2082. return this->CTestConfiguration[name];
  2083. }
  2084. //----------------------------------------------------------------------
  2085. void cmCTest::EmptyCTestConfiguration()
  2086. {
  2087. this->CTestConfiguration.clear();
  2088. }
  2089. //----------------------------------------------------------------------
  2090. void cmCTest::SetCTestConfiguration(const char *name, const char* value)
  2091. {
  2092. if ( !name )
  2093. {
  2094. return;
  2095. }
  2096. if ( !value )
  2097. {
  2098. this->CTestConfiguration.erase(name);
  2099. return;
  2100. }
  2101. this->CTestConfiguration[name] = value;
  2102. }
  2103. //----------------------------------------------------------------------
  2104. std::string cmCTest::GetCurrentTag()
  2105. {
  2106. return this->CurrentTag;
  2107. }
  2108. //----------------------------------------------------------------------
  2109. std::string cmCTest::GetBinaryDir()
  2110. {
  2111. return this->BinaryDir;
  2112. }
  2113. //----------------------------------------------------------------------
  2114. std::string cmCTest::GetConfigType()
  2115. {
  2116. return this->ConfigType;
  2117. }
  2118. //----------------------------------------------------------------------
  2119. bool cmCTest::GetShowOnly()
  2120. {
  2121. return this->ShowOnly;
  2122. }
  2123. //----------------------------------------------------------------------
  2124. void cmCTest::SetProduceXML(bool v)
  2125. {
  2126. this->ProduceXML = v;
  2127. }
  2128. //----------------------------------------------------------------------
  2129. bool cmCTest::GetProduceXML()
  2130. {
  2131. return this->ProduceXML;
  2132. }
  2133. //----------------------------------------------------------------------
  2134. const char* cmCTest::GetSpecificTrack()
  2135. {
  2136. if ( this->SpecificTrack.empty() )
  2137. {
  2138. return 0;
  2139. }
  2140. return this->SpecificTrack.c_str();
  2141. }
  2142. //----------------------------------------------------------------------
  2143. void cmCTest::SetSpecificTrack(const char* track)
  2144. {
  2145. if ( !track )
  2146. {
  2147. this->SpecificTrack = "";
  2148. return;
  2149. }
  2150. this->SpecificTrack = track;
  2151. }
  2152. //----------------------------------------------------------------------
  2153. void cmCTest::AddSubmitFile(const char* name)
  2154. {
  2155. this->SubmitFiles.insert(name);
  2156. }
  2157. //----------------------------------------------------------------------
  2158. void cmCTest::AddCTestConfigurationOverwrite(const char* encstr)
  2159. {
  2160. std::string overStr = encstr;
  2161. size_t epos = overStr.find("=");
  2162. if ( epos == overStr.npos )
  2163. {
  2164. cmCTestLog(this, ERROR_MESSAGE,
  2165. "CTest configuration overwrite specified in the wrong format."
  2166. << std::endl
  2167. << "Valid format is: --overwrite key=value" << std::endl
  2168. << "The specified was: --overwrite " << overStr.c_str() << std::endl);
  2169. return;
  2170. }
  2171. std::string key = overStr.substr(0, epos);
  2172. std::string value = overStr.substr(epos+1, overStr.npos);
  2173. this->CTestConfigurationOverwrites[key] = value;
  2174. }
  2175. //----------------------------------------------------------------------
  2176. void cmCTest::SetConfigType(const char* ct)
  2177. {
  2178. this->ConfigType = ct?ct:"";
  2179. cmSystemTools::ReplaceString(this->ConfigType, ".\\", "");
  2180. std::string confTypeEnv
  2181. = "CMAKE_CONFIG_TYPE=" + this->ConfigType;
  2182. cmSystemTools::PutEnv(confTypeEnv.c_str());
  2183. }
  2184. //----------------------------------------------------------------------
  2185. bool cmCTest::SetCTestConfigurationFromCMakeVariable(cmMakefile* mf,
  2186. const char* dconfig, const char* cmake_var)
  2187. {
  2188. const char* ctvar;
  2189. ctvar = mf->GetDefinition(cmake_var);
  2190. if ( !ctvar )
  2191. {
  2192. return false;
  2193. }
  2194. this->SetCTestConfiguration(dconfig, ctvar);
  2195. return true;
  2196. }
  2197. bool cmCTest::RunCommand(
  2198. const char* command,
  2199. std::string* stdOut,
  2200. std::string* stdErr,
  2201. int *retVal,
  2202. const char* dir,
  2203. double timeout)
  2204. {
  2205. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  2206. if(args.size() < 1)
  2207. {
  2208. return false;
  2209. }
  2210. std::vector<const char*> argv;
  2211. for(std::vector<cmStdString>::const_iterator a = args.begin();
  2212. a != args.end(); ++a)
  2213. {
  2214. argv.push_back(a->c_str());
  2215. }
  2216. argv.push_back(0);
  2217. *stdOut = "";
  2218. *stdErr = "";
  2219. cmsysProcess* cp = cmsysProcess_New();
  2220. cmsysProcess_SetCommand(cp, &*argv.begin());
  2221. cmsysProcess_SetWorkingDirectory(cp, dir);
  2222. if(cmSystemTools::GetRunCommandHideConsole())
  2223. {
  2224. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2225. }
  2226. cmsysProcess_SetTimeout(cp, timeout);
  2227. cmsysProcess_Execute(cp);
  2228. std::vector<char> tempOutput;
  2229. std::vector<char> tempError;
  2230. char* data;
  2231. int length;
  2232. int res;
  2233. bool done = false;
  2234. while(!done)
  2235. {
  2236. res = cmsysProcess_WaitForData(cp, &data, &length, 0);
  2237. switch ( res )
  2238. {
  2239. case cmsysProcess_Pipe_STDOUT:
  2240. tempOutput.insert(tempOutput.end(), data, data+length);
  2241. break;
  2242. case cmsysProcess_Pipe_STDERR:
  2243. tempError.insert(tempError.end(), data, data+length);
  2244. break;
  2245. default:
  2246. done = true;
  2247. }
  2248. if ( (res == cmsysProcess_Pipe_STDOUT ||
  2249. res == cmsysProcess_Pipe_STDERR) && this->ExtraVerbose )
  2250. {
  2251. cmSystemTools::Stdout(data, length);
  2252. }
  2253. }
  2254. cmsysProcess_WaitForExit(cp, 0);
  2255. if ( tempOutput.size() > 0 )
  2256. {
  2257. stdOut->append(&*tempOutput.begin(), tempOutput.size());
  2258. }
  2259. if ( tempError.size() > 0 )
  2260. {
  2261. stdErr->append(&*tempError.begin(), tempError.size());
  2262. }
  2263. bool result = true;
  2264. if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
  2265. {
  2266. if ( retVal )
  2267. {
  2268. *retVal = cmsysProcess_GetExitValue(cp);
  2269. }
  2270. else
  2271. {
  2272. if ( cmsysProcess_GetExitValue(cp) != 0 )
  2273. {
  2274. result = false;
  2275. }
  2276. }
  2277. }
  2278. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exception)
  2279. {
  2280. const char* exception_str = cmsysProcess_GetExceptionString(cp);
  2281. cmCTestLog(this, ERROR_MESSAGE, exception_str << std::endl);
  2282. stdErr->append(exception_str, strlen(exception_str));
  2283. result = false;
  2284. }
  2285. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
  2286. {
  2287. const char* error_str = cmsysProcess_GetErrorString(cp);
  2288. cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
  2289. stdErr->append(error_str, strlen(error_str));
  2290. result = false;
  2291. }
  2292. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Expired)
  2293. {
  2294. const char* error_str = "Process terminated due to timeout\n";
  2295. cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
  2296. stdErr->append(error_str, strlen(error_str));
  2297. result = false;
  2298. }
  2299. cmsysProcess_Delete(cp);
  2300. return result;
  2301. }
  2302. //----------------------------------------------------------------------
  2303. void cmCTest::SetOutputLogFileName(const char* name)
  2304. {
  2305. if ( this->OutputLogFile)
  2306. {
  2307. delete this->OutputLogFile;
  2308. this->OutputLogFile= 0;
  2309. }
  2310. if ( name )
  2311. {
  2312. this->OutputLogFile = new cmGeneratedFileStream(name);
  2313. }
  2314. }
  2315. //----------------------------------------------------------------------
  2316. static const char* cmCTestStringLogType[] =
  2317. {
  2318. "DEBUG",
  2319. "OUTPUT",
  2320. "HANDLER_OUTPUT",
  2321. "HANDLER_VERBOSE_OUTPUT",
  2322. "WARNING",
  2323. "ERROR_MESSAGE",
  2324. 0
  2325. };
  2326. //----------------------------------------------------------------------
  2327. #ifdef cerr
  2328. # undef cerr
  2329. #endif
  2330. #ifdef cout
  2331. # undef cout
  2332. #endif
  2333. #define cmCTestLogOutputFileLine(stream) \
  2334. if ( this->ShowLineNumbers ) \
  2335. { \
  2336. (stream) << std::endl << file << ":" << line << " "; \
  2337. }
  2338. void cmCTest::Log(int logType, const char* file, int line, const char* msg)
  2339. {
  2340. if ( !msg || !*msg )
  2341. {
  2342. return;
  2343. }
  2344. if ( this->OutputLogFile )
  2345. {
  2346. bool display = true;
  2347. if ( logType == cmCTest::DEBUG && !this->Debug ) { display = false; }
  2348. if ( logType == cmCTest::HANDLER_VERBOSE_OUTPUT && !this->Debug &&
  2349. !this->ExtraVerbose ) { display = false; }
  2350. if ( display )
  2351. {
  2352. cmCTestLogOutputFileLine(*this->OutputLogFile);
  2353. if ( logType != this->OutputLogFileLastTag )
  2354. {
  2355. *this->OutputLogFile << "[";
  2356. if ( logType >= OTHER || logType < 0 )
  2357. {
  2358. *this->OutputLogFile << "OTHER";
  2359. }
  2360. else
  2361. {
  2362. *this->OutputLogFile << cmCTestStringLogType[logType];
  2363. }
  2364. *this->OutputLogFile << "] " << std::endl << std::flush;
  2365. }
  2366. *this->OutputLogFile << msg << std::flush;
  2367. if ( logType != this->OutputLogFileLastTag )
  2368. {
  2369. *this->OutputLogFile << std::endl << std::flush;
  2370. this->OutputLogFileLastTag = logType;
  2371. }
  2372. }
  2373. }
  2374. if ( !this->Quiet )
  2375. {
  2376. switch ( logType )
  2377. {
  2378. case DEBUG:
  2379. if ( this->Debug )
  2380. {
  2381. cmCTestLogOutputFileLine(std::cout);
  2382. std::cout << msg;
  2383. std::cout.flush();
  2384. }
  2385. break;
  2386. case OUTPUT: case HANDLER_OUTPUT:
  2387. if ( this->Debug || this->Verbose )
  2388. {
  2389. cmCTestLogOutputFileLine(std::cout);
  2390. std::cout << msg;
  2391. std::cout.flush();
  2392. }
  2393. break;
  2394. case HANDLER_VERBOSE_OUTPUT:
  2395. if ( this->Debug || this->ExtraVerbose )
  2396. {
  2397. cmCTestLogOutputFileLine(std::cout);
  2398. std::cout << msg;
  2399. std::cout.flush();
  2400. }
  2401. break;
  2402. case WARNING:
  2403. cmCTestLogOutputFileLine(std::cerr);
  2404. std::cerr << msg;
  2405. std::cerr.flush();
  2406. break;
  2407. case ERROR_MESSAGE:
  2408. cmCTestLogOutputFileLine(std::cerr);
  2409. std::cerr << msg;
  2410. std::cerr.flush();
  2411. cmSystemTools::SetErrorOccured();
  2412. break;
  2413. default:
  2414. cmCTestLogOutputFileLine(std::cout);
  2415. std::cout << msg;
  2416. std::cout.flush();
  2417. }
  2418. }
  2419. }
  2420. //-------------------------------------------------------------------------
  2421. double cmCTest::GetRemainingTimeAllowed()
  2422. {
  2423. if (!this->GetHandler("script"))
  2424. {
  2425. return 1.0e7;
  2426. }
  2427. cmCTestScriptHandler* ch
  2428. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  2429. return ch->GetRemainingTimeAllowed();
  2430. }