cmCTest.cxx 60 KB

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