cmCTest.cxx 89 KB

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