cmCTest.cxx 65 KB

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