cmCTest.cxx 78 KB

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