cmCTest.cxx 78 KB

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