cmCTest.cxx 91 KB

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