cmCTest.cxx 58 KB

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