cmCTest.cxx 62 KB

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