cmCTest.cxx 93 KB

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