cmCTest.cxx 58 KB

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