cmCTest.cxx 69 KB

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