cmCTest.cxx 91 KB

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