cmCTest.cxx 96 KB

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