cmCTest.cxx 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273
  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_DartMode = 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()
  247. {
  248. if(!m_InteractiveDebugMode)
  249. {
  250. this->BlockTestErrorDiagnostics();
  251. }
  252. m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
  253. cmSystemTools::ConvertToUnixSlashes(m_ToplevelPath);
  254. if ( !this->ReadCustomConfigurationFileTree(m_ToplevelPath.c_str()) )
  255. {
  256. return 0;
  257. }
  258. this->UpdateCTestConfiguration();
  259. if ( m_DartMode )
  260. {
  261. std::string testingDir = m_ToplevelPath + "/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. void cmCTest::UpdateCTestConfiguration()
  347. {
  348. // parse the dart test file
  349. std::ifstream fin("DartConfiguration.tcl");
  350. if(!fin)
  351. {
  352. return;
  353. }
  354. char buffer[1024];
  355. while ( fin )
  356. {
  357. buffer[0] = 0;
  358. fin.getline(buffer, 1023);
  359. buffer[1023] = 0;
  360. std::string line = cmCTest::CleanString(buffer);
  361. if(line.size() == 0)
  362. {
  363. continue;
  364. }
  365. while ( fin && (line[line.size()-1] == '\\') )
  366. {
  367. line = line.substr(0, line.size()-1);
  368. buffer[0] = 0;
  369. fin.getline(buffer, 1023);
  370. buffer[1023] = 0;
  371. line += cmCTest::CleanString(buffer);
  372. }
  373. if ( line[0] == '#' )
  374. {
  375. continue;
  376. }
  377. std::string::size_type cpos = line.find_first_of(":");
  378. if ( cpos == line.npos )
  379. {
  380. continue;
  381. }
  382. std::string key = line.substr(0, cpos);
  383. std::string value = cmCTest::CleanString(line.substr(cpos+1, line.npos));
  384. m_DartConfiguration[key] = value;
  385. }
  386. fin.close();
  387. if ( m_DartMode )
  388. {
  389. m_TimeOut = atoi(m_DartConfiguration["TimeOut"].c_str());
  390. m_CompressXMLFiles = cmSystemTools::IsOn(m_DartConfiguration["CompressSubmission"].c_str());
  391. }
  392. }
  393. void cmCTest::BlockTestErrorDiagnostics()
  394. {
  395. cmSystemTools::PutEnv("DART_TEST_FROM_DART=1");
  396. cmSystemTools::PutEnv("DASHBOARD_TEST_FROM_CTEST=1");
  397. #if defined(_WIN32)
  398. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  399. #endif
  400. }
  401. void cmCTest::SetTestModel(int mode)
  402. {
  403. m_InteractiveDebugMode = false;
  404. m_TestModel = mode;
  405. }
  406. bool cmCTest::SetTest(const char* ttype, bool report)
  407. {
  408. if ( cmSystemTools::LowerCase(ttype) == "all" )
  409. {
  410. m_Tests[cmCTest::ALL_TEST] = 1;
  411. }
  412. else if ( cmSystemTools::LowerCase(ttype) == "start" )
  413. {
  414. m_Tests[cmCTest::START_TEST] = 1;
  415. }
  416. else if ( cmSystemTools::LowerCase(ttype) == "update" )
  417. {
  418. m_Tests[cmCTest::UPDATE_TEST] = 1;
  419. }
  420. else if ( cmSystemTools::LowerCase(ttype) == "configure" )
  421. {
  422. m_Tests[cmCTest::CONFIGURE_TEST] = 1;
  423. }
  424. else if ( cmSystemTools::LowerCase(ttype) == "build" )
  425. {
  426. m_Tests[cmCTest::BUILD_TEST] = 1;
  427. }
  428. else if ( cmSystemTools::LowerCase(ttype) == "test" )
  429. {
  430. m_Tests[cmCTest::TEST_TEST] = 1;
  431. }
  432. else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
  433. {
  434. m_Tests[cmCTest::COVERAGE_TEST] = 1;
  435. }
  436. else if ( cmSystemTools::LowerCase(ttype) == "memcheck" )
  437. {
  438. m_Tests[cmCTest::MEMCHECK_TEST] = 1;
  439. }
  440. else if ( cmSystemTools::LowerCase(ttype) == "notes" )
  441. {
  442. m_Tests[cmCTest::NOTES_TEST] = 1;
  443. }
  444. else if ( cmSystemTools::LowerCase(ttype) == "submit" )
  445. {
  446. m_Tests[cmCTest::SUBMIT_TEST] = 1;
  447. }
  448. else
  449. {
  450. if ( report )
  451. {
  452. std::cerr << "Don't know about test \"" << ttype << "\" yet..." << std::endl;
  453. }
  454. return false;
  455. }
  456. return true;
  457. }
  458. void cmCTest::Finalize()
  459. {
  460. }
  461. bool cmCTest::OpenOutputFile(const std::string& path,
  462. const std::string& name, cmGeneratedFileStream& stream,
  463. bool compress)
  464. {
  465. std::string testingDir = m_ToplevelPath + "/Testing";
  466. if ( path.size() > 0 )
  467. {
  468. testingDir += "/" + path;
  469. }
  470. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  471. {
  472. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  473. {
  474. std::cerr << "File " << testingDir
  475. << " is in the place of the testing directory"
  476. << std::endl;
  477. return false;
  478. }
  479. }
  480. else
  481. {
  482. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  483. {
  484. std::cerr << "Cannot create directory " << testingDir
  485. << std::endl;
  486. return false;
  487. }
  488. }
  489. std::string filename = testingDir + "/" + name;
  490. stream.Open(filename.c_str());
  491. if( !stream )
  492. {
  493. std::cerr << "Problem opening file: " << filename << std::endl;
  494. return false;
  495. }
  496. if ( compress )
  497. {
  498. if ( m_CompressXMLFiles )
  499. {
  500. stream.SetCompression(true);
  501. }
  502. }
  503. return true;
  504. }
  505. bool cmCTest::AddIfExists(tm_VectorOfStrings& files, const char* file)
  506. {
  507. if ( this->CTestFileExists(file) )
  508. {
  509. files.push_back(file);
  510. }
  511. else
  512. {
  513. std::string name = file;
  514. name += ".gz";
  515. if ( this->CTestFileExists(name.c_str()) )
  516. {
  517. files.push_back(name.c_str());
  518. }
  519. else
  520. {
  521. return false;
  522. }
  523. }
  524. return true;
  525. }
  526. int cmCTest::SubmitResults()
  527. {
  528. cmGeneratedFileStream ofs;
  529. this->OpenOutputFile("Temporary", "LastSubmit.log", ofs);
  530. cmCTest::tm_VectorOfStrings files;
  531. std::string prefix = this->GetSubmitResultsPrefix();
  532. // TODO:
  533. // Check if test is enabled
  534. this->AddIfExists(files, "Update.xml");
  535. this->AddIfExists(files, "Configure.xml");
  536. this->AddIfExists(files, "Build.xml");
  537. this->AddIfExists(files, "Test.xml");
  538. if ( this->AddIfExists(files, "Coverage.xml") )
  539. {
  540. cmCTest::tm_VectorOfStrings gfiles;
  541. std::string gpath = m_ToplevelPath + "/Testing/" + m_CurrentTag;
  542. std::string::size_type glen = gpath.size() + 1;
  543. gpath = gpath + "/CoverageLog*";
  544. //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
  545. if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
  546. {
  547. size_t cc;
  548. for ( cc = 0; cc < gfiles.size(); cc ++ )
  549. {
  550. gfiles[cc] = gfiles[cc].substr(glen);
  551. //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
  552. files.push_back(gfiles[cc]);
  553. }
  554. }
  555. else
  556. {
  557. std::cerr << "Problem globbing" << std::endl;
  558. }
  559. }
  560. this->AddIfExists(files, "DynamicAnalysis.xml");
  561. this->AddIfExists(files, "Purify.xml");
  562. this->AddIfExists(files, "Notes.xml");
  563. if ( ofs )
  564. {
  565. ofs << "Upload files:" << std::endl;
  566. int cnt = 0;
  567. cmCTest::tm_VectorOfStrings::iterator it;
  568. for ( it = files.begin(); it != files.end(); ++ it )
  569. {
  570. ofs << cnt << "\t" << it->c_str() << std::endl;
  571. cnt ++;
  572. }
  573. }
  574. std::cout << "Submit files (using " << m_DartConfiguration["DropMethod"] << ")"
  575. << std::endl;
  576. cmCTestSubmit submit;
  577. submit.SetVerbose(m_Verbose);
  578. submit.SetLogFile(&ofs);
  579. if ( m_DartConfiguration["DropMethod"] == "" ||
  580. m_DartConfiguration["DropMethod"] == "ftp" )
  581. {
  582. ofs << "Using drop method: FTP" << std::endl;
  583. std::cout << " Using FTP submit method" << std::endl;
  584. std::string url = "ftp://";
  585. url += cmCTest::MakeURLSafe(m_DartConfiguration["DropSiteUser"]) + ":" +
  586. cmCTest::MakeURLSafe(m_DartConfiguration["DropSitePassword"]) + "@" +
  587. m_DartConfiguration["DropSite"] +
  588. cmCTest::MakeURLSafe(m_DartConfiguration["DropLocation"]);
  589. if ( !submit.SubmitUsingFTP(m_ToplevelPath+"/Testing/"+m_CurrentTag,
  590. files, prefix, url) )
  591. {
  592. std::cerr << " Problems when submitting via FTP" << std::endl;
  593. ofs << " Problems when submitting via FTP" << std::endl;
  594. return 0;
  595. }
  596. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  597. {
  598. std::cerr << " Problems when triggering via HTTP" << std::endl;
  599. ofs << " Problems when triggering via HTTP" << std::endl;
  600. return 0;
  601. }
  602. std::cout << " Submission successfull" << std::endl;
  603. ofs << " Submission succesfull" << std::endl;
  604. return 1;
  605. }
  606. else if ( m_DartConfiguration["DropMethod"] == "http" )
  607. {
  608. ofs << "Using drop method: HTTP" << std::endl;
  609. std::cout << " Using HTTP submit method" << std::endl;
  610. std::string url = "http://";
  611. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  612. {
  613. url += m_DartConfiguration["DropSiteUser"];
  614. if ( m_DartConfiguration["DropSitePassword"].size() > 0 )
  615. {
  616. url += ":" + m_DartConfiguration["DropSitePassword"];
  617. }
  618. url += "@";
  619. }
  620. url += m_DartConfiguration["DropSite"] + m_DartConfiguration["DropLocation"];
  621. if ( !submit.SubmitUsingHTTP(m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  622. {
  623. std::cerr << " Problems when submitting via HTTP" << std::endl;
  624. ofs << " Problems when submitting via HTTP" << std::endl;
  625. return 0;
  626. }
  627. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  628. {
  629. std::cerr << " Problems when triggering via HTTP" << std::endl;
  630. ofs << " Problems when triggering via HTTP" << std::endl;
  631. return 0;
  632. }
  633. std::cout << " Submission successfull" << std::endl;
  634. ofs << " Submission succesfull" << std::endl;
  635. return 1;
  636. }
  637. else
  638. {
  639. std::string url;
  640. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  641. {
  642. url += m_DartConfiguration["DropSiteUser"] + "@";
  643. }
  644. url += m_DartConfiguration["DropSite"] + ":" + m_DartConfiguration["DropLocation"];
  645. if ( !submit.SubmitUsingSCP(m_DartConfiguration["ScpCommand"],
  646. m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  647. {
  648. std::cerr << " Problems when submitting via SCP" << std::endl;
  649. ofs << " Problems when submitting via SCP" << std::endl;
  650. return 0;
  651. }
  652. std::cout << " Submission successfull" << std::endl;
  653. ofs << " Submission succesfull" << std::endl;
  654. }
  655. return 0;
  656. }
  657. bool cmCTest::CTestFileExists(const std::string& filename)
  658. {
  659. std::string testingDir = m_ToplevelPath + "/Testing/" + m_CurrentTag + "/" +
  660. filename;
  661. return cmSystemTools::FileExists(testingDir.c_str());
  662. }
  663. std::string cmCTest::GetSubmitResultsPrefix()
  664. {
  665. std::string name = m_DartConfiguration["Site"] +
  666. "___" + m_DartConfiguration["BuildName"] +
  667. "___" + m_CurrentTag + "-" +
  668. this->GetTestModelString() + "___XML___";
  669. return name;
  670. }
  671. int cmCTest::ProcessTests()
  672. {
  673. int res = 0;
  674. bool notest = true;
  675. int cc;
  676. int update_count = 0;
  677. for ( cc = 0; cc < LAST_TEST; cc ++ )
  678. {
  679. if ( m_Tests[cc] )
  680. {
  681. notest = false;
  682. break;
  683. }
  684. }
  685. if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
  686. {
  687. update_count = m_TestingHandlers["update"]->ProcessHandler();
  688. if ( update_count < 0 )
  689. {
  690. res |= cmCTest::UPDATE_ERRORS;
  691. }
  692. }
  693. if ( m_TestModel == cmCTest::CONTINUOUS && !update_count )
  694. {
  695. return 0;
  696. }
  697. if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
  698. {
  699. if (m_TestingHandlers["configure"]->ProcessHandler() < 0)
  700. {
  701. res |= cmCTest::CONFIGURE_ERRORS;
  702. }
  703. }
  704. if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
  705. {
  706. this->UpdateCTestConfiguration();
  707. if (m_TestingHandlers["build"]->ProcessHandler() < 0)
  708. {
  709. res |= cmCTest::BUILD_ERRORS;
  710. }
  711. }
  712. if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
  713. {
  714. this->UpdateCTestConfiguration();
  715. if (m_TestingHandlers["test"]->ProcessHandler() < 0)
  716. {
  717. res |= cmCTest::TEST_ERRORS;
  718. }
  719. }
  720. if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
  721. {
  722. this->UpdateCTestConfiguration();
  723. if (m_TestingHandlers["coverage"]->ProcessHandler() < 0)
  724. {
  725. res |= cmCTest::COVERAGE_ERRORS;
  726. }
  727. }
  728. if ( m_Tests[MEMCHECK_TEST] || m_Tests[ALL_TEST] )
  729. {
  730. this->UpdateCTestConfiguration();
  731. if (m_TestingHandlers["memcheck"]->ProcessHandler() < 0)
  732. {
  733. res |= cmCTest::MEMORY_ERRORS;
  734. }
  735. }
  736. if ( !notest )
  737. {
  738. std::string notes_dir = m_ToplevelPath + "/Testing/Notes";
  739. if ( cmSystemTools::FileIsDirectory(notes_dir.c_str()) )
  740. {
  741. cmsys::Directory d;
  742. d.Load(notes_dir.c_str());
  743. unsigned long kk;
  744. for ( kk = 0; kk < d.GetNumberOfFiles(); kk ++ )
  745. {
  746. const char* file = d.GetFile(kk);
  747. std::string fullname = notes_dir + "/" + file;
  748. if ( cmSystemTools::FileExists(fullname.c_str()) &&
  749. !cmSystemTools::FileIsDirectory(fullname.c_str()) )
  750. {
  751. if ( m_NotesFiles.size() > 0 )
  752. {
  753. m_NotesFiles += ";";
  754. }
  755. m_NotesFiles += fullname;
  756. m_Tests[NOTES_TEST] = 1;
  757. }
  758. }
  759. }
  760. }
  761. if ( m_Tests[NOTES_TEST] || m_Tests[ALL_TEST] )
  762. {
  763. this->UpdateCTestConfiguration();
  764. if ( m_NotesFiles.size() )
  765. {
  766. this->GenerateNotesFile(m_NotesFiles.c_str());
  767. }
  768. }
  769. if ( m_Tests[SUBMIT_TEST] || m_Tests[ALL_TEST] )
  770. {
  771. this->UpdateCTestConfiguration();
  772. this->SubmitResults();
  773. }
  774. return res;
  775. }
  776. std::string cmCTest::GetTestModelString()
  777. {
  778. switch ( m_TestModel )
  779. {
  780. case cmCTest::NIGHTLY:
  781. return "Nightly";
  782. case cmCTest::CONTINUOUS:
  783. return "Continuous";
  784. }
  785. return "Experimental";
  786. }
  787. int cmCTest::GetTestModelFromString(const char* str)
  788. {
  789. if ( !str )
  790. {
  791. return cmCTest::EXPERIMENTAL;
  792. }
  793. std::string rstr = cmSystemTools::LowerCase(str);
  794. if ( strncmp(rstr.c_str(), "cont", 4) == 0 )
  795. {
  796. return cmCTest::CONTINUOUS;
  797. }
  798. if ( strncmp(rstr.c_str(), "nigh", 4) == 0 )
  799. {
  800. return cmCTest::NIGHTLY;
  801. }
  802. return cmCTest::EXPERIMENTAL;
  803. }
  804. int cmCTest::RunMakeCommand(const char* command, std::string* output,
  805. int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs)
  806. {
  807. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  808. if(args.size() < 1)
  809. {
  810. return false;
  811. }
  812. std::vector<const char*> argv;
  813. for(std::vector<cmStdString>::const_iterator a = args.begin();
  814. a != args.end(); ++a)
  815. {
  816. argv.push_back(a->c_str());
  817. }
  818. argv.push_back(0);
  819. if ( output )
  820. {
  821. *output = "";
  822. }
  823. cmsysProcess* cp = cmsysProcess_New();
  824. cmsysProcess_SetCommand(cp, &*argv.begin());
  825. cmsysProcess_SetWorkingDirectory(cp, dir);
  826. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  827. cmsysProcess_SetTimeout(cp, timeout);
  828. cmsysProcess_Execute(cp);
  829. std::string::size_type tick = 0;
  830. std::string::size_type tick_len = 1024;
  831. std::string::size_type tick_line_len = 50;
  832. char* data;
  833. int length;
  834. if ( !verbose )
  835. {
  836. std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl;
  837. std::cout << " " << std::flush;
  838. }
  839. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  840. {
  841. if ( output )
  842. {
  843. for(int cc =0; cc < length; ++cc)
  844. {
  845. if(data[cc] == 0)
  846. {
  847. data[cc] = '\n';
  848. }
  849. }
  850. output->append(data, length);
  851. if ( !verbose )
  852. {
  853. while ( output->size() > (tick * tick_len) )
  854. {
  855. tick ++;
  856. std::cout << "." << std::flush;
  857. if ( tick % tick_line_len == 0 && tick > 0 )
  858. {
  859. std::cout << " Size: ";
  860. std::cout << int((output->size() / 1024.0) + 1) << "K" << std::endl;
  861. std::cout << " " << std::flush;
  862. }
  863. }
  864. }
  865. }
  866. if(verbose)
  867. {
  868. std::cout.write(data, length);
  869. std::cout.flush();
  870. }
  871. if ( ofs )
  872. {
  873. ofs.write(data, length);
  874. ofs.flush();
  875. }
  876. }
  877. std::cout << " Size of output: ";
  878. std::cout << int(output->size() / 1024.0) << "K" << std::endl;
  879. cmsysProcess_WaitForExit(cp, 0);
  880. int result = cmsysProcess_GetState(cp);
  881. if(result == cmsysProcess_State_Exited)
  882. {
  883. *retVal = cmsysProcess_GetExitValue(cp);
  884. }
  885. else if(result == cmsysProcess_State_Exception)
  886. {
  887. *retVal = cmsysProcess_GetExitException(cp);
  888. std::cout << "There was an exception: " << *retVal << std::endl;
  889. }
  890. else if(result == cmsysProcess_State_Expired)
  891. {
  892. std::cout << "There was a timeout" << std::endl;
  893. }
  894. else if(result == cmsysProcess_State_Error)
  895. {
  896. *output += "\n*** ERROR executing: ";
  897. *output += cmsysProcess_GetErrorString(cp);
  898. }
  899. cmsysProcess_Delete(cp);
  900. return result;
  901. }
  902. int cmCTest::RunTest(std::vector<const char*> argv,
  903. std::string* output, int *retVal,
  904. std::ostream* log)
  905. {
  906. if(cmSystemTools::SameFile(argv[0], m_CTestSelf.c_str()) &&
  907. !m_ForceNewCTestProcess)
  908. {
  909. cmCTest inst;
  910. inst.m_ConfigType = m_ConfigType;
  911. inst.m_TimeOut = m_TimeOut;
  912. std::vector<std::string> args;
  913. for(unsigned int i =0; i < argv.size(); ++i)
  914. {
  915. if(argv[i])
  916. {
  917. args.push_back(argv[i]);
  918. }
  919. }
  920. if ( *log )
  921. {
  922. *log << "* Run internal CTest" << std::endl;
  923. }
  924. std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
  925. *retVal = inst.Run(args, output);
  926. if ( *log )
  927. {
  928. *log << output->c_str();
  929. }
  930. cmSystemTools::ChangeDirectory(oldpath.c_str());
  931. if(m_Verbose)
  932. {
  933. std::cout << "Internal cmCTest object used to run test.\n";
  934. std::cout << *output << "\n";
  935. }
  936. return cmsysProcess_State_Exited;
  937. }
  938. std::vector<char> tempOutput;
  939. if ( output )
  940. {
  941. *output = "";
  942. }
  943. cmsysProcess* cp = cmsysProcess_New();
  944. cmsysProcess_SetCommand(cp, &*argv.begin());
  945. // std::cout << "Command is: " << argv[0] << std::endl;
  946. if(cmSystemTools::GetRunCommandHideConsole())
  947. {
  948. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  949. }
  950. cmsysProcess_SetTimeout(cp, m_TimeOut);
  951. cmsysProcess_Execute(cp);
  952. char* data;
  953. int length;
  954. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  955. {
  956. if ( output )
  957. {
  958. tempOutput.insert(tempOutput.end(), data, data+length);
  959. }
  960. if ( m_Verbose )
  961. {
  962. std::cout.write(data, length);
  963. std::cout.flush();
  964. }
  965. if ( log )
  966. {
  967. log->write(data, length);
  968. log->flush();
  969. }
  970. }
  971. cmsysProcess_WaitForExit(cp, 0);
  972. if(output)
  973. {
  974. output->append(&*tempOutput.begin(), tempOutput.size());
  975. }
  976. if ( m_Verbose )
  977. {
  978. std::cout << "-- Process completed" << std::endl;
  979. }
  980. int result = cmsysProcess_GetState(cp);
  981. if(result == cmsysProcess_State_Exited)
  982. {
  983. *retVal = cmsysProcess_GetExitValue(cp);
  984. }
  985. else if(result == cmsysProcess_State_Exception)
  986. {
  987. *retVal = cmsysProcess_GetExitException(cp);
  988. std::string outerr = "\n*** Exception executing: ";
  989. outerr += cmsysProcess_GetExceptionString(cp);
  990. *output += outerr;
  991. if ( m_Verbose )
  992. {
  993. std::cout << outerr.c_str() << "\n";
  994. std::cout.flush();
  995. }
  996. }
  997. else if(result == cmsysProcess_State_Error)
  998. {
  999. std::string outerr = "\n*** ERROR executing: ";
  1000. outerr += cmsysProcess_GetErrorString(cp);
  1001. *output += outerr;
  1002. if ( m_Verbose )
  1003. {
  1004. std::cout << outerr.c_str() << "\n";
  1005. std::cout.flush();
  1006. }
  1007. }
  1008. cmsysProcess_Delete(cp);
  1009. return result;
  1010. }
  1011. void cmCTest::StartXML(std::ostream& ostr)
  1012. {
  1013. ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1014. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  1015. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  1016. << this->GetTestModelString() << "\" Name=\""
  1017. << m_DartConfiguration["Site"] << "\" Generator=\"ctest"
  1018. << cmVersion::GetCMakeVersion()
  1019. << "\">" << std::endl;
  1020. }
  1021. void cmCTest::EndXML(std::ostream& ostr)
  1022. {
  1023. ostr << "</Site>" << std::endl;
  1024. }
  1025. int cmCTest::GenerateDartNotesOutput(std::ostream& os, const cmCTest::tm_VectorOfStrings& files)
  1026. {
  1027. cmCTest::tm_VectorOfStrings::const_iterator it;
  1028. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1029. << "<?xml-stylesheet type=\"text/xsl\" href=\"Dart/Source/Server/XSL/Build.xsl <file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
  1030. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"] << "\" BuildStamp=\""
  1031. << m_CurrentTag << "-" << this->GetTestModelString() << "\" Name=\""
  1032. << m_DartConfiguration["Site"] << "\" Generator=\"ctest"
  1033. << cmVersion::GetCMakeVersion()
  1034. << "\">\n"
  1035. << "<Notes>" << std::endl;
  1036. for ( it = files.begin(); it != files.end(); it ++ )
  1037. {
  1038. std::cout << "\tAdd file: " << it->c_str() << std::endl;
  1039. std::string note_time = this->CurrentTime();
  1040. os << "<Note Name=\"" << this->MakeXMLSafe(it->c_str()) << "\">\n"
  1041. << "<DateTime>" << note_time << "</DateTime>\n"
  1042. << "<Text>" << std::endl;
  1043. std::ifstream ifs(it->c_str());
  1044. if ( ifs )
  1045. {
  1046. std::string line;
  1047. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  1048. {
  1049. os << this->MakeXMLSafe(line) << std::endl;
  1050. }
  1051. ifs.close();
  1052. }
  1053. else
  1054. {
  1055. os << "Problem reading file: " << it->c_str() << std::endl;
  1056. std::cerr << "Problem reading file: " << it->c_str() << " while creating notes" << std::endl;
  1057. }
  1058. os << "</Text>\n"
  1059. << "</Note>" << std::endl;
  1060. }
  1061. os << "</Notes>\n"
  1062. << "</Site>" << std::endl;
  1063. return 1;
  1064. }
  1065. int cmCTest::GenerateNotesFile(const char* cfiles)
  1066. {
  1067. if ( !cfiles )
  1068. {
  1069. return 1;
  1070. }
  1071. std::vector<cmStdString> files;
  1072. std::cout << "Create notes file" << std::endl;
  1073. files = cmSystemTools::SplitString(cfiles, ';');
  1074. if ( files.size() == 0 )
  1075. {
  1076. return 1;
  1077. }
  1078. cmGeneratedFileStream ofs;
  1079. if ( !this->OpenOutputFile(m_CurrentTag, "Notes.xml", ofs) )
  1080. {
  1081. std::cerr << "Cannot open notes file" << std::endl;
  1082. return 1;
  1083. }
  1084. this->GenerateDartNotesOutput(ofs, files);
  1085. return 0;
  1086. }
  1087. int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
  1088. {
  1089. this->FindRunningCMake(args[0].c_str());
  1090. const char* ctestExec = "ctest";
  1091. bool cmakeAndTest = false;
  1092. bool performSomeTest = true;
  1093. for(unsigned int i=1; i < args.size(); ++i)
  1094. {
  1095. std::string arg = args[i];
  1096. if(arg.find("-C",0) == 0 && i < args.size() - 1)
  1097. {
  1098. i++;
  1099. this->m_ConfigType = args[i];
  1100. cmSystemTools::ReplaceString(this->m_ConfigType, ".\\", "");
  1101. }
  1102. if( arg.find("-V",0) == 0 || arg.find("--verbose",0) == 0 )
  1103. {
  1104. this->m_Verbose = true;
  1105. cmCTest::t_TestingHandlers::iterator it;
  1106. for ( it = m_TestingHandlers.begin(); it != m_TestingHandlers.end(); ++ it )
  1107. {
  1108. it->second->SetVerbose(this->m_Verbose);
  1109. }
  1110. }
  1111. if( arg.find("-N",0) == 0 || arg.find("--show-only",0) == 0 )
  1112. {
  1113. this->m_ShowOnly = true;
  1114. }
  1115. if( arg.find("-S",0) == 0 && i < args.size() - 1 )
  1116. {
  1117. this->m_RunConfigurationScript = true;
  1118. i++;
  1119. cmCTestScriptHandler* ch = static_cast<cmCTestScriptHandler*>(m_TestingHandlers["script"]);
  1120. ch->AddConfigurationScript(args[i].c_str());
  1121. }
  1122. if( arg.find("--tomorrow-tag",0) == 0 )
  1123. {
  1124. m_TomorrowTag = true;
  1125. }
  1126. if( arg.find("--force-new-ctest-process",0) == 0 )
  1127. {
  1128. m_ForceNewCTestProcess = true;
  1129. }
  1130. if( arg.find("--interactive-debug-mode",0) == 0 && i < args.size() - 1 )
  1131. {
  1132. i++;
  1133. m_InteractiveDebugMode = cmSystemTools::IsOn(args[i].c_str());
  1134. }
  1135. if( arg.find("-D",0) == 0 && i < args.size() - 1 )
  1136. {
  1137. this->m_DartMode = true;
  1138. i++;
  1139. std::string targ = args[i];
  1140. if ( targ == "Experimental" )
  1141. {
  1142. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1143. this->SetTest("Start");
  1144. this->SetTest("Configure");
  1145. this->SetTest("Build");
  1146. this->SetTest("Test");
  1147. this->SetTest("Coverage");
  1148. this->SetTest("Submit");
  1149. }
  1150. else if ( targ == "ExperimentalStart" )
  1151. {
  1152. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1153. this->SetTest("Start");
  1154. }
  1155. else if ( targ == "ExperimentalUpdate" )
  1156. {
  1157. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1158. this->SetTest("Update");
  1159. }
  1160. else if ( targ == "ExperimentalConfigure" )
  1161. {
  1162. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1163. this->SetTest("Configure");
  1164. }
  1165. else if ( targ == "ExperimentalBuild" )
  1166. {
  1167. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1168. this->SetTest("Build");
  1169. }
  1170. else if ( targ == "ExperimentalTest" )
  1171. {
  1172. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1173. this->SetTest("Test");
  1174. }
  1175. else if ( targ == "ExperimentalMemCheck"
  1176. || targ == "ExperimentalPurify" )
  1177. {
  1178. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1179. this->SetTest("MemCheck");
  1180. }
  1181. else if ( targ == "ExperimentalCoverage" )
  1182. {
  1183. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1184. this->SetTest("Coverage");
  1185. }
  1186. else if ( targ == "ExperimentalSubmit" )
  1187. {
  1188. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1189. this->SetTest("Submit");
  1190. }
  1191. else if ( targ == "Continuous" )
  1192. {
  1193. this->SetTestModel(cmCTest::CONTINUOUS);
  1194. this->SetTest("Start");
  1195. this->SetTest("Update");
  1196. this->SetTest("Configure");
  1197. this->SetTest("Build");
  1198. this->SetTest("Test");
  1199. this->SetTest("Coverage");
  1200. this->SetTest("Submit");
  1201. }
  1202. else if ( targ == "ContinuousStart" )
  1203. {
  1204. this->SetTestModel(cmCTest::CONTINUOUS);
  1205. this->SetTest("Start");
  1206. }
  1207. else if ( targ == "ContinuousUpdate" )
  1208. {
  1209. this->SetTestModel(cmCTest::CONTINUOUS);
  1210. this->SetTest("Update");
  1211. }
  1212. else if ( targ == "ContinuousConfigure" )
  1213. {
  1214. this->SetTestModel(cmCTest::CONTINUOUS);
  1215. this->SetTest("Configure");
  1216. }
  1217. else if ( targ == "ContinuousBuild" )
  1218. {
  1219. this->SetTestModel(cmCTest::CONTINUOUS);
  1220. this->SetTest("Build");
  1221. }
  1222. else if ( targ == "ContinuousTest" )
  1223. {
  1224. this->SetTestModel(cmCTest::CONTINUOUS);
  1225. this->SetTest("Test");
  1226. }
  1227. else if ( targ == "ContinuousMemCheck"
  1228. || targ == "ContinuousPurify" )
  1229. {
  1230. this->SetTestModel(cmCTest::CONTINUOUS);
  1231. this->SetTest("MemCheck");
  1232. }
  1233. else if ( targ == "ContinuousCoverage" )
  1234. {
  1235. this->SetTestModel(cmCTest::CONTINUOUS);
  1236. this->SetTest("Coverage");
  1237. }
  1238. else if ( targ == "ContinuousSubmit" )
  1239. {
  1240. this->SetTestModel(cmCTest::CONTINUOUS);
  1241. this->SetTest("Submit");
  1242. }
  1243. else if ( targ == "Nightly" )
  1244. {
  1245. this->SetTestModel(cmCTest::NIGHTLY);
  1246. this->SetTest("Start");
  1247. this->SetTest("Update");
  1248. this->SetTest("Configure");
  1249. this->SetTest("Build");
  1250. this->SetTest("Test");
  1251. this->SetTest("Coverage");
  1252. this->SetTest("Submit");
  1253. }
  1254. else if ( targ == "NightlyStart" )
  1255. {
  1256. this->SetTestModel(cmCTest::NIGHTLY);
  1257. this->SetTest("Start");
  1258. }
  1259. else if ( targ == "NightlyUpdate" )
  1260. {
  1261. this->SetTestModel(cmCTest::NIGHTLY);
  1262. this->SetTest("Update");
  1263. }
  1264. else if ( targ == "NightlyConfigure" )
  1265. {
  1266. this->SetTestModel(cmCTest::NIGHTLY);
  1267. this->SetTest("Configure");
  1268. }
  1269. else if ( targ == "NightlyBuild" )
  1270. {
  1271. this->SetTestModel(cmCTest::NIGHTLY);
  1272. this->SetTest("Build");
  1273. }
  1274. else if ( targ == "NightlyTest" )
  1275. {
  1276. this->SetTestModel(cmCTest::NIGHTLY);
  1277. this->SetTest("Test");
  1278. }
  1279. else if ( targ == "NightlyMemCheck"
  1280. || targ == "NightlyPurify" )
  1281. {
  1282. this->SetTestModel(cmCTest::NIGHTLY);
  1283. this->SetTest("MemCheck");
  1284. }
  1285. else if ( targ == "NightlyCoverage" )
  1286. {
  1287. this->SetTestModel(cmCTest::NIGHTLY);
  1288. this->SetTest("Coverage");
  1289. }
  1290. else if ( targ == "NightlySubmit" )
  1291. {
  1292. this->SetTestModel(cmCTest::NIGHTLY);
  1293. this->SetTest("Submit");
  1294. }
  1295. else if ( targ == "MemoryCheck" )
  1296. {
  1297. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1298. this->SetTest("Start");
  1299. this->SetTest("Configure");
  1300. this->SetTest("Build");
  1301. this->SetTest("MemCheck");
  1302. this->SetTest("Coverage");
  1303. this->SetTest("Submit");
  1304. }
  1305. else if ( targ == "NightlyMemoryCheck" )
  1306. {
  1307. this->SetTestModel(cmCTest::NIGHTLY);
  1308. this->SetTest("Start");
  1309. this->SetTest("Update");
  1310. this->SetTest("Configure");
  1311. this->SetTest("Build");
  1312. this->SetTest("MemCheck");
  1313. this->SetTest("Coverage");
  1314. this->SetTest("Submit");
  1315. }
  1316. else
  1317. {
  1318. performSomeTest = false;
  1319. std::cerr << "CTest -D called with incorrect option: " << targ << std::endl;
  1320. std::cerr << "Available options are:" << std::endl
  1321. << " " << ctestExec << " -D Continuous" << std::endl
  1322. << " " << ctestExec << " -D Continuous(Start|Update|Configure|Build)" << std::endl
  1323. << " " << ctestExec << " -D Continuous(Test|Coverage|MemCheck|Submit)" << std::endl
  1324. << " " << ctestExec << " -D Experimental" << std::endl
  1325. << " " << ctestExec << " -D Experimental(Start|Update|Configure|Build)" << std::endl
  1326. << " " << ctestExec << " -D Experimental(Test|Coverage|MemCheck|Submit)" << std::endl
  1327. << " " << ctestExec << " -D Nightly" << std::endl
  1328. << " " << ctestExec << " -D Nightly(Start|Update|Configure|Build)" << std::endl
  1329. << " " << ctestExec << " -D Nightly(Test|Coverage|MemCheck|Submit)" << std::endl
  1330. << " " << ctestExec << " -D NightlyMemoryCheck" << std::endl;
  1331. ;
  1332. }
  1333. }
  1334. if( ( arg.find("-T",0) == 0 ) &&
  1335. (i < args.size() -1) )
  1336. {
  1337. this->m_DartMode = true;
  1338. i++;
  1339. if ( !this->SetTest(args[i].c_str(), false) )
  1340. {
  1341. performSomeTest = false;
  1342. std::cerr << "CTest -T called with incorrect option: " << args[i].c_str() << std::endl;
  1343. std::cerr << "Available options are:" << std::endl
  1344. << " " << ctestExec << " -T all" << std::endl
  1345. << " " << ctestExec << " -T start" << std::endl
  1346. << " " << ctestExec << " -T update" << std::endl
  1347. << " " << ctestExec << " -T configure" << std::endl
  1348. << " " << ctestExec << " -T build" << std::endl
  1349. << " " << ctestExec << " -T test" << std::endl
  1350. << " " << ctestExec << " -T coverage" << std::endl
  1351. << " " << ctestExec << " -T memcheck" << std::endl
  1352. << " " << ctestExec << " -T notes" << std::endl
  1353. << " " << ctestExec << " -T submit" << std::endl;
  1354. }
  1355. }
  1356. if( ( arg.find("-M",0) == 0 || arg.find("--test-model",0) == 0 ) &&
  1357. (i < args.size() -1) )
  1358. {
  1359. i++;
  1360. std::string const& str = args[i];
  1361. if ( cmSystemTools::LowerCase(str) == "nightly" )
  1362. {
  1363. this->SetTestModel(cmCTest::NIGHTLY);
  1364. }
  1365. else if ( cmSystemTools::LowerCase(str) == "continuous" )
  1366. {
  1367. this->SetTestModel(cmCTest::CONTINUOUS);
  1368. }
  1369. else if ( cmSystemTools::LowerCase(str) == "experimental" )
  1370. {
  1371. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1372. }
  1373. else
  1374. {
  1375. performSomeTest = false;
  1376. std::cerr << "CTest -M called with incorrect option: " << str.c_str() << std::endl;
  1377. std::cerr << "Available options are:" << std::endl
  1378. << " " << ctestExec << " -M Continuous" << std::endl
  1379. << " " << ctestExec << " -M Experimental" << std::endl
  1380. << " " << ctestExec << " -M Nightly" << std::endl;
  1381. }
  1382. }
  1383. if(arg.find("-I",0) == 0 && i < args.size() - 1)
  1384. {
  1385. i++;
  1386. cmCTestTestHandler* th = static_cast<cmCTestTestHandler*>(m_TestingHandlers["test"]);
  1387. th->SetTestsToRunInformation(args[i].c_str());
  1388. }
  1389. if(arg.find("-U",0) == 0)
  1390. {
  1391. cmCTestTestHandler* th = static_cast<cmCTestTestHandler*>(m_TestingHandlers["test"]);
  1392. th->SetUseUnion(true);
  1393. }
  1394. if(arg.find("-R",0) == 0 && i < args.size() - 1)
  1395. {
  1396. cmCTestTestHandler* th = static_cast<cmCTestTestHandler*>(m_TestingHandlers["test"]);
  1397. th->UseIncludeRegExp();
  1398. i++;
  1399. th->SetIncludeRegExp(args[i].c_str());
  1400. }
  1401. if(arg.find("-E",0) == 0 && i < args.size() - 1)
  1402. {
  1403. cmCTestTestHandler* th = static_cast<cmCTestTestHandler*>(m_TestingHandlers["test"]);
  1404. th->UseExcludeRegExp();
  1405. i++;
  1406. th->SetExcludeRegExp(args[i].c_str());
  1407. }
  1408. if(arg.find("-A",0) == 0 && i < args.size() - 1)
  1409. {
  1410. this->m_DartMode = true;
  1411. this->SetTest("Notes");
  1412. i++;
  1413. this->SetNotesFiles(args[i].c_str());
  1414. }
  1415. // --build-and-test options
  1416. if(arg.find("--build-and-test",0) == 0 && i < args.size() - 1)
  1417. {
  1418. cmakeAndTest = true;
  1419. if(i+2 < args.size())
  1420. {
  1421. i++;
  1422. m_SourceDir = args[i];
  1423. i++;
  1424. m_BinaryDir = args[i];
  1425. // dir must exist before CollapseFullPath is called
  1426. cmSystemTools::MakeDirectory(m_BinaryDir.c_str());
  1427. m_BinaryDir = cmSystemTools::CollapseFullPath(m_BinaryDir.c_str());
  1428. m_SourceDir = cmSystemTools::CollapseFullPath(m_SourceDir.c_str());
  1429. }
  1430. else
  1431. {
  1432. std::cerr << "--build-and-test must have source and binary dir\n";
  1433. }
  1434. }
  1435. if(arg.find("--build-target",0) == 0 && i < args.size() - 1)
  1436. {
  1437. i++;
  1438. m_BuildTarget = args[i];
  1439. }
  1440. if(arg.find("--build-nocmake",0) == 0)
  1441. {
  1442. m_BuildNoCMake = true;
  1443. }
  1444. if(arg.find("--build-run-dir",0) == 0 && i < args.size() - 1)
  1445. {
  1446. i++;
  1447. m_BuildRunDir = args[i];
  1448. }
  1449. if(arg.find("--build-two-config",0) == 0)
  1450. {
  1451. m_BuildTwoConfig = true;
  1452. }
  1453. if(arg.find("--build-exe-dir",0) == 0 && i < args.size() - 1)
  1454. {
  1455. i++;
  1456. m_ExecutableDirectory = args[i];
  1457. }
  1458. if(arg.find("--build-generator",0) == 0 && i < args.size() - 1)
  1459. {
  1460. i++;
  1461. m_BuildGenerator = args[i];
  1462. }
  1463. if(arg.find("--build-project",0) == 0 && i < args.size() - 1)
  1464. {
  1465. i++;
  1466. m_BuildProject = args[i];
  1467. }
  1468. if(arg.find("--build-makeprogram",0) == 0 && i < args.size() - 1)
  1469. {
  1470. i++;
  1471. m_BuildMakeProgram = args[i];
  1472. }
  1473. if(arg.find("--build-noclean",0) == 0)
  1474. {
  1475. m_BuildNoClean = true;
  1476. }
  1477. if(arg.find("--build-options",0) == 0 && i < args.size() - 1)
  1478. {
  1479. ++i;
  1480. bool done = false;
  1481. while(i < args.size() && !done)
  1482. {
  1483. m_BuildOptions.push_back(args[i]);
  1484. if(i+1 < args.size()
  1485. && (args[i+1] == "--build-target" || args[i+1] == "--test-command"))
  1486. {
  1487. done = true;
  1488. }
  1489. else
  1490. {
  1491. ++i;
  1492. }
  1493. }
  1494. }
  1495. if(arg.find("--test-command",0) == 0 && i < args.size() - 1)
  1496. {
  1497. ++i;
  1498. m_TestCommand = args[i];
  1499. while(i+1 < args.size())
  1500. {
  1501. ++i;
  1502. m_TestCommandArgs.push_back(args[i]);
  1503. }
  1504. }
  1505. }
  1506. if(cmakeAndTest)
  1507. {
  1508. cmSystemTools::ResetErrorOccuredFlag();
  1509. cmListFileCache::ClearCache();
  1510. int retv = this->RunCMakeAndTest(output);
  1511. cmSystemTools::ResetErrorOccuredFlag();
  1512. cmListFileCache::ClearCache();
  1513. #ifdef CMAKE_BUILD_WITH_CMAKE
  1514. cmDynamicLoader::FlushCache();
  1515. #endif
  1516. return retv;
  1517. }
  1518. if(performSomeTest )
  1519. {
  1520. int res;
  1521. // call process directory
  1522. if (this->m_RunConfigurationScript)
  1523. {
  1524. res = m_TestingHandlers["script"]->ProcessHandler();
  1525. }
  1526. else
  1527. {
  1528. if ( !this->Initialize() )
  1529. {
  1530. res = 12;
  1531. }
  1532. else
  1533. {
  1534. res = this->ProcessTests();
  1535. }
  1536. this->Finalize();
  1537. }
  1538. return res;
  1539. }
  1540. return 1;
  1541. }
  1542. void cmCTest::FindRunningCMake(const char* arg0)
  1543. {
  1544. // Find our own executable.
  1545. std::vector<cmStdString> failures;
  1546. m_CTestSelf = arg0;
  1547. cmSystemTools::ConvertToUnixSlashes(m_CTestSelf);
  1548. failures.push_back(m_CTestSelf);
  1549. m_CTestSelf = cmSystemTools::FindProgram(m_CTestSelf.c_str());
  1550. if(!cmSystemTools::FileExists(m_CTestSelf.c_str()))
  1551. {
  1552. failures.push_back(m_CTestSelf);
  1553. m_CTestSelf = "/usr/local/bin/ctest";
  1554. }
  1555. if(!cmSystemTools::FileExists(m_CTestSelf.c_str()))
  1556. {
  1557. failures.push_back(m_CTestSelf);
  1558. cmOStringStream msg;
  1559. msg << "CTEST can not find the command line program ctest.\n";
  1560. msg << " argv[0] = \"" << arg0 << "\"\n";
  1561. msg << " Attempted paths:\n";
  1562. std::vector<cmStdString>::iterator i;
  1563. for(i=failures.begin(); i != failures.end(); ++i)
  1564. {
  1565. msg << " \"" << i->c_str() << "\"\n";
  1566. }
  1567. cmSystemTools::Error(msg.str().c_str());
  1568. }
  1569. std::string dir;
  1570. std::string file;
  1571. if(cmSystemTools::SplitProgramPath(m_CTestSelf.c_str(),
  1572. dir, file, true))
  1573. {
  1574. m_CMakeSelf = dir += "/cmake";
  1575. m_CMakeSelf += cmSystemTools::GetExecutableExtension();
  1576. if(cmSystemTools::FileExists(m_CMakeSelf.c_str()))
  1577. {
  1578. return;
  1579. }
  1580. }
  1581. failures.push_back(m_CMakeSelf);
  1582. #ifdef CMAKE_BUILD_DIR
  1583. std::string intdir = ".";
  1584. #ifdef CMAKE_INTDIR
  1585. intdir = CMAKE_INTDIR;
  1586. #endif
  1587. m_CMakeSelf = CMAKE_BUILD_DIR;
  1588. m_CMakeSelf += "/bin/";
  1589. m_CMakeSelf += intdir;
  1590. m_CMakeSelf += "/cmake";
  1591. m_CMakeSelf += cmSystemTools::GetExecutableExtension();
  1592. #endif
  1593. if(!cmSystemTools::FileExists(m_CMakeSelf.c_str()))
  1594. {
  1595. failures.push_back(m_CMakeSelf);
  1596. cmOStringStream msg;
  1597. msg << "CTEST can not find the command line program cmake.\n";
  1598. msg << " argv[0] = \"" << arg0 << "\"\n";
  1599. msg << " Attempted paths:\n";
  1600. std::vector<cmStdString>::iterator i;
  1601. for(i=failures.begin(); i != failures.end(); ++i)
  1602. {
  1603. msg << " \"" << i->c_str() << "\"\n";
  1604. }
  1605. cmSystemTools::Error(msg.str().c_str());
  1606. }
  1607. }
  1608. void CMakeMessageCallback(const char* m, const char*, bool&, void* s)
  1609. {
  1610. std::string* out = (std::string*)s;
  1611. *out += m;
  1612. *out += "\n";
  1613. }
  1614. void CMakeStdoutCallback(const char* m, int len, void* s)
  1615. {
  1616. std::string* out = (std::string*)s;
  1617. out->append(m, len);
  1618. }
  1619. int cmCTest::RunCMakeAndTest(std::string* outstring)
  1620. {
  1621. unsigned int k;
  1622. std::string cmakeOutString;
  1623. cmSystemTools::SetErrorCallback(CMakeMessageCallback, &cmakeOutString);
  1624. cmSystemTools::SetStdoutCallback(CMakeStdoutCallback, &cmakeOutString);
  1625. cmOStringStream out;
  1626. cmake cm;
  1627. double timeout = m_TimeOut;
  1628. // default to the build type of ctest itself
  1629. if(m_ConfigType.size() == 0)
  1630. {
  1631. #ifdef CMAKE_INTDIR
  1632. m_ConfigType = CMAKE_INTDIR;
  1633. #endif
  1634. }
  1635. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1636. out << "Internal cmake changing into directory: " << m_BinaryDir << "\n";
  1637. if (!cmSystemTools::FileIsDirectory(m_BinaryDir.c_str()))
  1638. {
  1639. cmSystemTools::MakeDirectory(m_BinaryDir.c_str());
  1640. }
  1641. cmSystemTools::ChangeDirectory(m_BinaryDir.c_str());
  1642. if(!m_BuildNoCMake)
  1643. {
  1644. std::vector<std::string> args;
  1645. args.push_back(m_CMakeSelf);
  1646. args.push_back(m_SourceDir);
  1647. if(m_BuildGenerator.size())
  1648. {
  1649. std::string generator = "-G";
  1650. generator += m_BuildGenerator;
  1651. args.push_back(generator);
  1652. }
  1653. if ( m_ConfigType.size() > 0 )
  1654. {
  1655. std::string btype = "-DBUILD_TYPE:STRING=" + m_ConfigType;
  1656. args.push_back(btype);
  1657. }
  1658. for(k=0; k < m_BuildOptions.size(); ++k)
  1659. {
  1660. args.push_back(m_BuildOptions[k]);
  1661. }
  1662. if (cm.Run(args) != 0)
  1663. {
  1664. out << "Error: cmake execution failed\n";
  1665. out << cmakeOutString << "\n";
  1666. // return to the original directory
  1667. cmSystemTools::ChangeDirectory(cwd.c_str());
  1668. if(outstring)
  1669. {
  1670. *outstring = out.str();
  1671. }
  1672. else
  1673. {
  1674. std::cerr << out.str() << "\n";
  1675. }
  1676. return 1;
  1677. }
  1678. if(m_BuildTwoConfig)
  1679. {
  1680. if (cm.Run(args) != 0)
  1681. {
  1682. out << "Error: cmake execution failed\n";
  1683. out << cmakeOutString << "\n";
  1684. // return to the original directory
  1685. cmSystemTools::ChangeDirectory(cwd.c_str());
  1686. if(outstring)
  1687. {
  1688. *outstring = out.str();
  1689. }
  1690. else
  1691. {
  1692. std::cerr << out.str() << "\n";
  1693. }
  1694. return 1;
  1695. }
  1696. }
  1697. }
  1698. cmSystemTools::SetErrorCallback(0, 0);
  1699. out << cmakeOutString << "\n";
  1700. if(m_BuildMakeProgram.size() == 0)
  1701. {
  1702. out << "Error: cmake does not have a valid MAKEPROGRAM\n";
  1703. out << "Did you specify a --build-makeprogram and a --build-generator?\n";
  1704. if(outstring)
  1705. {
  1706. *outstring = out.str();
  1707. }
  1708. else
  1709. {
  1710. std::cerr << out.str() << "\n";
  1711. }
  1712. return 1;
  1713. }
  1714. int retVal = 0;
  1715. std::string makeCommand = cmSystemTools::ConvertToOutputPath(m_BuildMakeProgram.c_str());
  1716. std::string lowerCaseCommand = cmSystemTools::LowerCase(makeCommand);
  1717. // if msdev is the make program then do the following
  1718. // MSDEV 6.0
  1719. if(lowerCaseCommand.find("msdev") != std::string::npos)
  1720. {
  1721. // if there are spaces in the makeCommand, assume a full path
  1722. // and convert it to a path with no spaces in it as the
  1723. // RunSingleCommand does not like spaces
  1724. #if defined(_WIN32) && !defined(__CYGWIN__)
  1725. if(makeCommand.find(' ') != std::string::npos)
  1726. {
  1727. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  1728. }
  1729. #endif
  1730. makeCommand += " ";
  1731. makeCommand += m_BuildProject;
  1732. makeCommand += ".dsw /MAKE \"ALL_BUILD - ";
  1733. makeCommand += m_ConfigType;
  1734. if(m_BuildNoClean)
  1735. {
  1736. makeCommand += "\" /BUILD";
  1737. }
  1738. else
  1739. {
  1740. makeCommand += "\" /REBUILD";
  1741. }
  1742. }
  1743. // MSDEV 7.0 .NET
  1744. else if (lowerCaseCommand.find("devenv") != std::string::npos)
  1745. {
  1746. #if defined(_WIN32) && !defined(__CYGWIN__)
  1747. if(makeCommand.find(' ') != std::string::npos)
  1748. {
  1749. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  1750. }
  1751. #endif
  1752. makeCommand += " ";
  1753. makeCommand += m_BuildProject;
  1754. makeCommand += ".sln ";
  1755. if(m_BuildNoClean)
  1756. {
  1757. makeCommand += "/build ";
  1758. }
  1759. else
  1760. {
  1761. makeCommand += "/rebuild ";
  1762. }
  1763. makeCommand += m_ConfigType + " /project ALL_BUILD";
  1764. }
  1765. else if (lowerCaseCommand.find("make") != std::string::npos)
  1766. {
  1767. // assume a make sytle program
  1768. // clean first
  1769. if(!m_BuildNoClean)
  1770. {
  1771. std::string cleanCommand = makeCommand;
  1772. cleanCommand += " clean";
  1773. out << "Running make clean command: " << cleanCommand.c_str() << " ...\n";
  1774. retVal = 0;
  1775. std::string output;
  1776. if (!cmSystemTools::RunSingleCommand(cleanCommand.c_str(), &output, &retVal, 0,
  1777. false, timeout) ||
  1778. retVal)
  1779. {
  1780. out << "Error: " << cleanCommand.c_str() << " execution failed\n";
  1781. out << output.c_str() << "\n";
  1782. // return to the original directory
  1783. cmSystemTools::ChangeDirectory(cwd.c_str());
  1784. out << "Return value: " << retVal << std::endl;
  1785. if(outstring)
  1786. {
  1787. *outstring = out.str();
  1788. }
  1789. else
  1790. {
  1791. std::cerr << out.str() << "\n";
  1792. }
  1793. return 1;
  1794. }
  1795. out << output;
  1796. }
  1797. if(m_BuildTarget.size())
  1798. {
  1799. makeCommand += " ";
  1800. makeCommand += m_BuildTarget;
  1801. }
  1802. }
  1803. // command line make program
  1804. out << "Running make command: " << makeCommand.c_str() << "\n";
  1805. retVal = 0;
  1806. std::string output;
  1807. if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), &output, &retVal, 0, false, timeout))
  1808. {
  1809. out << "Error: " << makeCommand.c_str() << " execution failed\n";
  1810. out << output.c_str() << "\n";
  1811. // return to the original directory
  1812. cmSystemTools::ChangeDirectory(cwd.c_str());
  1813. out << "Return value: " << retVal << std::endl;
  1814. if(outstring)
  1815. {
  1816. *outstring = out.str();
  1817. }
  1818. else
  1819. {
  1820. std::cerr << out.str() << "\n";
  1821. }
  1822. return 1;
  1823. }
  1824. if ( retVal )
  1825. {
  1826. if(outstring)
  1827. {
  1828. *outstring = out.str();
  1829. *outstring += "Building of project failed\n";
  1830. *outstring += output;
  1831. *outstring += "\n";
  1832. }
  1833. else
  1834. {
  1835. std::cerr << "Building of project failed\n";
  1836. std::cerr << out.str() << output << "\n";
  1837. }
  1838. // return to the original directory
  1839. cmSystemTools::ChangeDirectory(cwd.c_str());
  1840. return 1;
  1841. }
  1842. out << output;
  1843. if(m_TestCommand.size() == 0)
  1844. {
  1845. if(outstring)
  1846. {
  1847. *outstring = out.str();
  1848. }
  1849. else
  1850. {
  1851. std::cout << out.str() << "\n";
  1852. }
  1853. return retVal;
  1854. }
  1855. // now run the compiled test if we can find it
  1856. std::vector<std::string> attempted;
  1857. std::vector<std::string> failed;
  1858. std::string tempPath;
  1859. std::string filepath =
  1860. cmSystemTools::GetFilenamePath(m_TestCommand);
  1861. std::string filename =
  1862. cmSystemTools::GetFilenameName(m_TestCommand);
  1863. // if full path specified then search that first
  1864. if (filepath.size())
  1865. {
  1866. tempPath = filepath;
  1867. tempPath += "/";
  1868. tempPath += filename;
  1869. attempted.push_back(tempPath);
  1870. if(m_ConfigType.size())
  1871. {
  1872. tempPath = filepath;
  1873. tempPath += "/";
  1874. tempPath += m_ConfigType;
  1875. tempPath += "/";
  1876. tempPath += filename;
  1877. attempted.push_back(tempPath);
  1878. }
  1879. }
  1880. // otherwise search local dirs
  1881. else
  1882. {
  1883. attempted.push_back(filename);
  1884. if(m_ConfigType.size())
  1885. {
  1886. tempPath = m_ConfigType;
  1887. tempPath += "/";
  1888. tempPath += filename;
  1889. attempted.push_back(tempPath);
  1890. }
  1891. }
  1892. // if m_ExecutableDirectory is set try that as well
  1893. if (m_ExecutableDirectory.size())
  1894. {
  1895. tempPath = m_ExecutableDirectory;
  1896. tempPath += "/";
  1897. tempPath += m_TestCommand;
  1898. attempted.push_back(tempPath);
  1899. if(m_ConfigType.size())
  1900. {
  1901. tempPath = m_ExecutableDirectory;
  1902. tempPath += "/";
  1903. tempPath += m_ConfigType;
  1904. tempPath += "/";
  1905. tempPath += filename;
  1906. attempted.push_back(tempPath);
  1907. }
  1908. }
  1909. // store the final location in fullPath
  1910. std::string fullPath;
  1911. // now look in the paths we specified above
  1912. for(unsigned int ai=0;
  1913. ai < attempted.size() && fullPath.size() == 0; ++ai)
  1914. {
  1915. // first check without exe extension
  1916. if(cmSystemTools::FileExists(attempted[ai].c_str())
  1917. && !cmSystemTools::FileIsDirectory(attempted[ai].c_str()))
  1918. {
  1919. fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str());
  1920. }
  1921. // then try with the exe extension
  1922. else
  1923. {
  1924. failed.push_back(attempted[ai].c_str());
  1925. tempPath = attempted[ai];
  1926. tempPath += cmSystemTools::GetExecutableExtension();
  1927. if(cmSystemTools::FileExists(tempPath.c_str())
  1928. && !cmSystemTools::FileIsDirectory(tempPath.c_str()))
  1929. {
  1930. fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str());
  1931. }
  1932. else
  1933. {
  1934. failed.push_back(tempPath.c_str());
  1935. }
  1936. }
  1937. }
  1938. if(!cmSystemTools::FileExists(fullPath.c_str()))
  1939. {
  1940. out << "Could not find path to executable, perhaps it was not built: " <<
  1941. m_TestCommand << "\n";
  1942. out << "tried to find it in these places:\n";
  1943. out << fullPath.c_str() << "\n";
  1944. for(unsigned int i=0; i < failed.size(); ++i)
  1945. {
  1946. out << failed[i] << "\n";
  1947. }
  1948. if(outstring)
  1949. {
  1950. *outstring = out.str();
  1951. }
  1952. else
  1953. {
  1954. std::cerr << out.str();
  1955. }
  1956. // return to the original directory
  1957. cmSystemTools::ChangeDirectory(cwd.c_str());
  1958. return 1;
  1959. }
  1960. std::vector<const char*> testCommand;
  1961. testCommand.push_back(fullPath.c_str());
  1962. for(k=0; k < m_TestCommandArgs.size(); ++k)
  1963. {
  1964. testCommand.push_back(m_TestCommandArgs[k].c_str());
  1965. }
  1966. testCommand.push_back(0);
  1967. std::string outs;
  1968. int retval = 0;
  1969. // run the test from the m_BuildRunDir if set
  1970. if(m_BuildRunDir.size())
  1971. {
  1972. out << "Run test in directory: " << m_BuildRunDir << "\n";
  1973. cmSystemTools::ChangeDirectory(m_BuildRunDir.c_str());
  1974. }
  1975. out << "Running test executable: " << fullPath << " ";
  1976. for(k=0; k < m_TestCommandArgs.size(); ++k)
  1977. {
  1978. out << m_TestCommandArgs[k] << " ";
  1979. }
  1980. out << "\n";
  1981. m_TimeOut = timeout;
  1982. int runTestRes = this->RunTest(testCommand, &outs, &retval, 0);
  1983. if(runTestRes != cmsysProcess_State_Exited || retval != 0)
  1984. {
  1985. out << "Failed to run test command: " << testCommand[0] << "\n";
  1986. retval = 1;
  1987. }
  1988. out << outs << "\n";
  1989. if(outstring)
  1990. {
  1991. *outstring = out.str();
  1992. }
  1993. else
  1994. {
  1995. std::cout << out.str() << "\n";
  1996. }
  1997. return retval;
  1998. }
  1999. void cmCTest::SetNotesFiles(const char* notes)
  2000. {
  2001. if ( !notes )
  2002. {
  2003. return;
  2004. }
  2005. m_NotesFiles = notes;
  2006. }
  2007. int cmCTest::ReadCustomConfigurationFileTree(const char* dir)
  2008. {
  2009. tm_VectorOfStrings dirs;
  2010. tm_VectorOfStrings ndirs;
  2011. dirs.push_back(dir);
  2012. cmake cm;
  2013. cmGlobalGenerator gg;
  2014. gg.SetCMakeInstance(&cm);
  2015. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  2016. lg->SetGlobalGenerator(&gg);
  2017. cmMakefile *mf = lg->GetMakefile();
  2018. while ( dirs.size() > 0 )
  2019. {
  2020. tm_VectorOfStrings::iterator cdir = dirs.end()-1;
  2021. std::string rexpr = *cdir + "/*";
  2022. std::string fname = *cdir + "/CTestCustom.ctest";
  2023. if ( cmSystemTools::FileExists(fname.c_str()) &&
  2024. (!lg->GetMakefile()->ReadListFile(0, fname.c_str()) ||
  2025. cmSystemTools::GetErrorOccuredFlag() ) )
  2026. {
  2027. std::cerr << "Problem reading custom configuration" << std::endl;
  2028. }
  2029. dirs.erase(dirs.end()-1, dirs.end());
  2030. cmSystemTools::SimpleGlob(rexpr, ndirs, -1);
  2031. dirs.insert(dirs.end(), ndirs.begin(), ndirs.end());
  2032. }
  2033. cmCTest::t_TestingHandlers::iterator it;
  2034. for ( it = m_TestingHandlers.begin(); it != m_TestingHandlers.end(); ++ it )
  2035. {
  2036. it->second->PopulateCustomVectors(mf);
  2037. }
  2038. return 1;
  2039. }
  2040. void cmCTest::PopulateCustomVector(cmMakefile* mf, const char* def, tm_VectorOfStrings& vec)
  2041. {
  2042. if ( !def)
  2043. {
  2044. return;
  2045. }
  2046. const char* dval = mf->GetDefinition(def);
  2047. if ( !dval )
  2048. {
  2049. return;
  2050. }
  2051. std::vector<std::string> slist;
  2052. cmSystemTools::ExpandListArgument(dval, slist);
  2053. std::vector<std::string>::iterator it;
  2054. for ( it = slist.begin(); it != slist.end(); ++it )
  2055. {
  2056. vec.push_back(it->c_str());
  2057. }
  2058. }
  2059. void cmCTest::PopulateCustomInteger(cmMakefile* mf, const char* def, int& val)
  2060. {
  2061. if ( !def)
  2062. {
  2063. return;
  2064. }
  2065. const char* dval = mf->GetDefinition(def);
  2066. if ( !dval )
  2067. {
  2068. return;
  2069. }
  2070. val = atoi(dval);
  2071. }
  2072. std::string cmCTest::GetShortPathToFile(const char* cfname)
  2073. {
  2074. const std::string& sourceDir = GetDartConfiguration("SourceDirectory");
  2075. const std::string& buildDir = GetDartConfiguration("BuildDirectory");
  2076. std::string fname = cmSystemTools::CollapseFullPath(cfname);
  2077. // Find relative paths to both directories
  2078. std::string srcRelpath
  2079. = cmSystemTools::RelativePath(sourceDir.c_str(), fname.c_str());
  2080. std::string bldRelpath
  2081. = cmSystemTools::RelativePath(buildDir.c_str(), fname.c_str());
  2082. // If any contains "." it is not parent directory
  2083. bool inSrc = srcRelpath.find("..") == srcRelpath.npos;
  2084. bool inBld = bldRelpath.find("..") == bldRelpath.npos;
  2085. // TODO: Handle files with .. in their name
  2086. std::string* res = 0;
  2087. if ( inSrc && inBld )
  2088. {
  2089. // If both have relative path with no dots, pick the shorter one
  2090. if ( srcRelpath.size() < bldRelpath.size() )
  2091. {
  2092. res = &srcRelpath;
  2093. }
  2094. else
  2095. {
  2096. res = &bldRelpath;
  2097. }
  2098. }
  2099. else if ( inSrc )
  2100. {
  2101. res = &srcRelpath;
  2102. }
  2103. else if ( inBld )
  2104. {
  2105. res = &bldRelpath;
  2106. }
  2107. if ( !res )
  2108. {
  2109. return fname;
  2110. }
  2111. cmSystemTools::ConvertToUnixSlashes(*res);
  2112. std::string path = "./" + *res;
  2113. if ( path[path.size()-1] == '/' )
  2114. {
  2115. path = path.substr(0, path.size()-1);
  2116. }
  2117. return path;
  2118. }
  2119. std::string cmCTest::GetDartConfiguration(const char *name)
  2120. {
  2121. return m_DartConfiguration[name];
  2122. }
  2123. std::string cmCTest::GetCurrentTag()
  2124. {
  2125. return m_CurrentTag;
  2126. }
  2127. std::string cmCTest::GetToplevelPath()
  2128. {
  2129. return m_ToplevelPath;
  2130. }
  2131. std::string cmCTest::GetConfigType()
  2132. {
  2133. return m_ConfigType;
  2134. }
  2135. bool cmCTest::GetShowOnly()
  2136. {
  2137. return m_ShowOnly;
  2138. }
  2139. bool cmCTest::GetProduceXML()
  2140. {
  2141. return m_DartMode;
  2142. }