cmCTest.cxx 78 KB

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