cmCTest.cxx 77 KB

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