cmCTest.cxx 80 KB

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