cmCTest.cxx 83 KB

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