cmCTest.cxx 59 KB

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