cmCTest.cxx 71 KB

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