cmCTest.cxx 90 KB

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