cmCTest.cxx 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844
  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 <algorithm>
  14. #include <ctype.h>
  15. #include <iostream>
  16. #include <map>
  17. #include <sstream>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <string>
  22. #include <time.h>
  23. #include <utility>
  24. #include <vector>
  25. #include "cmAlgorithms.h"
  26. #include "cmCTestBuildAndTestHandler.h"
  27. #include "cmCTestBuildHandler.h"
  28. #include "cmCTestConfigureHandler.h"
  29. #include "cmCTestCoverageHandler.h"
  30. #include "cmCTestGenericHandler.h"
  31. #include "cmCTestMemCheckHandler.h"
  32. #include "cmCTestScriptHandler.h"
  33. #include "cmCTestStartCommand.h"
  34. #include "cmCTestSubmitHandler.h"
  35. #include "cmCTestTestHandler.h"
  36. #include "cmCTestUpdateHandler.h"
  37. #include "cmCTestUploadHandler.h"
  38. #include "cmCurl.h"
  39. #include "cmDynamicLoader.h"
  40. #include "cmGeneratedFileStream.h"
  41. #include "cmGlobalGenerator.h"
  42. #include "cmMakefile.h"
  43. #include "cmProcessOutput.h"
  44. #include "cmState.h"
  45. #include "cmStateSnapshot.h"
  46. #include "cmStateTypes.h"
  47. #include "cmSystemTools.h"
  48. #include "cmVersion.h"
  49. #include "cmVersionConfig.h"
  50. #include "cmXMLWriter.h"
  51. #include "cm_auto_ptr.hxx"
  52. #include "cmake.h"
  53. #if defined(__BEOS__) || defined(__HAIKU__)
  54. #include <be/kernel/OS.h> /* disable_debugger() API. */
  55. #endif
  56. #define DEBUGOUT \
  57. std::cout << __LINE__ << " "; \
  58. std::cout
  59. #define DEBUGERR \
  60. std::cerr << __LINE__ << " "; \
  61. std::cerr
  62. struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag)
  63. {
  64. struct tm* lctime;
  65. time_t tctime = time(nullptr);
  66. lctime = gmtime(&tctime);
  67. char buf[1024];
  68. // add todays year day and month to the time in str because
  69. // curl_getdate no longer assumes the day is today
  70. sprintf(buf, "%d%02d%02d %s", lctime->tm_year + 1900, lctime->tm_mon + 1,
  71. lctime->tm_mday, str.c_str());
  72. cmCTestLog(this, OUTPUT, "Determine Nightly Start Time"
  73. << std::endl
  74. << " Specified time: " << str << std::endl);
  75. // Convert the nightly start time to seconds. Since we are
  76. // providing only a time and a timezone, the current date of
  77. // the local machine is assumed. Consequently, nightlySeconds
  78. // is the time at which the nightly dashboard was opened or
  79. // will be opened on the date of the current client machine.
  80. // As such, this time may be in the past or in the future.
  81. time_t ntime = curl_getdate(buf, &tctime);
  82. cmCTestLog(this, DEBUG, " Get curl time: " << ntime << std::endl);
  83. tctime = time(nullptr);
  84. cmCTestLog(this, DEBUG, " Get the current time: " << tctime << std::endl);
  85. const int dayLength = 24 * 60 * 60;
  86. cmCTestLog(this, DEBUG, "Seconds: " << tctime << std::endl);
  87. while (ntime > tctime) {
  88. // If nightlySeconds is in the past, this is the current
  89. // open dashboard, then return nightlySeconds. If
  90. // nightlySeconds is in the future, this is the next
  91. // dashboard to be opened, so subtract 24 hours to get the
  92. // time of the current open dashboard
  93. ntime -= dayLength;
  94. cmCTestLog(this, DEBUG, "Pick yesterday" << std::endl);
  95. cmCTestLog(this, DEBUG, " Future time, subtract day: " << ntime
  96. << std::endl);
  97. }
  98. while (tctime > (ntime + dayLength)) {
  99. ntime += dayLength;
  100. cmCTestLog(this, DEBUG, " Past time, add day: " << ntime << std::endl);
  101. }
  102. cmCTestLog(this, DEBUG, "nightlySeconds: " << ntime << std::endl);
  103. cmCTestLog(this, DEBUG, " Current time: " << tctime << " Nightly time: "
  104. << ntime << std::endl);
  105. if (tomorrowtag) {
  106. cmCTestLog(this, OUTPUT, " Use future tag, Add a day" << std::endl);
  107. ntime += dayLength;
  108. }
  109. lctime = gmtime(&ntime);
  110. return lctime;
  111. }
  112. std::string cmCTest::CleanString(const std::string& str)
  113. {
  114. std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
  115. std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
  116. if (spos == std::string::npos) {
  117. return std::string();
  118. }
  119. if (epos != std::string::npos) {
  120. epos = epos - spos + 1;
  121. }
  122. return str.substr(spos, epos);
  123. }
  124. std::string cmCTest::CurrentTime()
  125. {
  126. time_t currenttime = time(nullptr);
  127. struct tm* t = localtime(&currenttime);
  128. // return ::CleanString(ctime(&currenttime));
  129. char current_time[1024];
  130. if (this->ShortDateFormat) {
  131. strftime(current_time, 1000, "%b %d %H:%M %Z", t);
  132. } else {
  133. strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
  134. }
  135. cmCTestLog(this, DEBUG, " Current_Time: " << current_time << std::endl);
  136. return cmCTest::CleanString(current_time);
  137. }
  138. std::string cmCTest::GetCostDataFile()
  139. {
  140. std::string fname = this->GetCTestConfiguration("CostDataFile");
  141. if (fname == "") {
  142. fname = this->GetBinaryDir() + "/Testing/Temporary/CTestCostData.txt";
  143. }
  144. return fname;
  145. }
  146. #ifdef CMAKE_BUILD_WITH_CMAKE
  147. static size_t HTTPResponseCallback(void* ptr, size_t size, size_t nmemb,
  148. void* data)
  149. {
  150. int realsize = static_cast<int>(size * nmemb);
  151. std::string* response = static_cast<std::string*>(data);
  152. const char* chPtr = static_cast<char*>(ptr);
  153. *response += chPtr;
  154. return realsize;
  155. }
  156. int cmCTest::HTTPRequest(std::string url, HTTPMethod method,
  157. std::string& response, std::string const& fields,
  158. std::string const& putFile, int timeout)
  159. {
  160. CURL* curl;
  161. FILE* file;
  162. ::curl_global_init(CURL_GLOBAL_ALL);
  163. curl = ::curl_easy_init();
  164. cmCurlSetCAInfo(curl);
  165. // set request options based on method
  166. switch (method) {
  167. case cmCTest::HTTP_POST:
  168. ::curl_easy_setopt(curl, CURLOPT_POST, 1);
  169. ::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str());
  170. break;
  171. case cmCTest::HTTP_PUT:
  172. if (!cmSystemTools::FileExists(putFile.c_str())) {
  173. response = "Error: File ";
  174. response += putFile + " does not exist.\n";
  175. return -1;
  176. }
  177. ::curl_easy_setopt(curl, CURLOPT_PUT, 1);
  178. file = cmsys::SystemTools::Fopen(putFile, "rb");
  179. ::curl_easy_setopt(curl, CURLOPT_INFILE, file);
  180. // fall through to append GET fields
  181. CM_FALLTHROUGH;
  182. case cmCTest::HTTP_GET:
  183. if (!fields.empty()) {
  184. url += "?" + fields;
  185. }
  186. break;
  187. }
  188. ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  189. ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
  190. ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
  191. // set response options
  192. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPResponseCallback);
  193. ::curl_easy_setopt(curl, CURLOPT_FILE, &response);
  194. ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
  195. CURLcode res = ::curl_easy_perform(curl);
  196. ::curl_easy_cleanup(curl);
  197. ::curl_global_cleanup();
  198. return static_cast<int>(res);
  199. }
  200. #endif
  201. std::string cmCTest::MakeURLSafe(const std::string& str)
  202. {
  203. std::ostringstream ost;
  204. char buffer[10];
  205. for (unsigned char ch : str) {
  206. if ((ch > 126 || ch < 32 || ch == '&' || ch == '%' || ch == '+' ||
  207. ch == '=' || ch == '@') &&
  208. ch != 9) {
  209. sprintf(buffer, "%02x;", static_cast<unsigned int>(ch));
  210. ost << buffer;
  211. } else {
  212. ost << ch;
  213. }
  214. }
  215. return ost.str();
  216. }
  217. std::string cmCTest::DecodeURL(const std::string& in)
  218. {
  219. std::string out;
  220. for (const char* c = in.c_str(); *c; ++c) {
  221. if (*c == '%' && isxdigit(*(c + 1)) && isxdigit(*(c + 2))) {
  222. char buf[3] = { *(c + 1), *(c + 2), 0 };
  223. out.append(1, char(strtoul(buf, nullptr, 16)));
  224. c += 2;
  225. } else {
  226. out.append(1, *c);
  227. }
  228. }
  229. return out;
  230. }
  231. cmCTest::cmCTest()
  232. {
  233. this->LabelSummary = true;
  234. this->SubprojectSummary = true;
  235. this->ParallelLevel = 1;
  236. this->ParallelLevelSetInCli = false;
  237. this->TestLoad = 0;
  238. this->SubmitIndex = 0;
  239. this->Failover = false;
  240. this->BatchJobs = false;
  241. this->ForceNewCTestProcess = false;
  242. this->TomorrowTag = false;
  243. this->Verbose = false;
  244. this->Debug = false;
  245. this->ShowLineNumbers = false;
  246. this->Quiet = false;
  247. this->ExtraVerbose = false;
  248. this->ProduceXML = false;
  249. this->ShowOnly = false;
  250. this->RunConfigurationScript = false;
  251. this->UseHTTP10 = false;
  252. this->PrintLabels = false;
  253. this->CompressTestOutput = true;
  254. this->TestModel = cmCTest::EXPERIMENTAL;
  255. this->MaxTestNameWidth = 30;
  256. this->InteractiveDebugMode = true;
  257. this->TimeOut = 0;
  258. this->GlobalTimeout = 0;
  259. this->LastStopTimeout = 24 * 60 * 60;
  260. this->CompressXMLFiles = false;
  261. this->CTestConfigFile.clear();
  262. this->ScheduleType.clear();
  263. this->StopTime.clear();
  264. this->NextDayStopTime = false;
  265. this->OutputLogFile = nullptr;
  266. this->OutputLogFileLastTag = -1;
  267. this->SuppressUpdatingCTestConfiguration = false;
  268. this->DartVersion = 1;
  269. this->DropSiteCDash = false;
  270. this->OutputTestOutputOnTestFailure = false;
  271. this->RepeatTests = 1; // default to run each test once
  272. this->RepeatUntilFail = false;
  273. std::string outOnFail;
  274. if (cmSystemTools::GetEnv("CTEST_OUTPUT_ON_FAILURE", outOnFail)) {
  275. this->OutputTestOutputOnTestFailure =
  276. !cmSystemTools::IsOff(outOnFail.c_str());
  277. }
  278. this->InitStreams();
  279. this->Parts[PartStart].SetName("Start");
  280. this->Parts[PartUpdate].SetName("Update");
  281. this->Parts[PartConfigure].SetName("Configure");
  282. this->Parts[PartBuild].SetName("Build");
  283. this->Parts[PartTest].SetName("Test");
  284. this->Parts[PartCoverage].SetName("Coverage");
  285. this->Parts[PartMemCheck].SetName("MemCheck");
  286. this->Parts[PartSubmit].SetName("Submit");
  287. this->Parts[PartNotes].SetName("Notes");
  288. this->Parts[PartExtraFiles].SetName("ExtraFiles");
  289. this->Parts[PartUpload].SetName("Upload");
  290. // Fill the part name-to-id map.
  291. for (Part p = PartStart; p != PartCount; p = Part(p + 1)) {
  292. this->PartMap[cmSystemTools::LowerCase(this->Parts[p].GetName())] = p;
  293. }
  294. this->ShortDateFormat = true;
  295. this->TestingHandlers["build"] = new cmCTestBuildHandler;
  296. this->TestingHandlers["buildtest"] = new cmCTestBuildAndTestHandler;
  297. this->TestingHandlers["coverage"] = new cmCTestCoverageHandler;
  298. this->TestingHandlers["script"] = new cmCTestScriptHandler;
  299. this->TestingHandlers["test"] = new cmCTestTestHandler;
  300. this->TestingHandlers["update"] = new cmCTestUpdateHandler;
  301. this->TestingHandlers["configure"] = new cmCTestConfigureHandler;
  302. this->TestingHandlers["memcheck"] = new cmCTestMemCheckHandler;
  303. this->TestingHandlers["submit"] = new cmCTestSubmitHandler;
  304. this->TestingHandlers["upload"] = new cmCTestUploadHandler;
  305. for (auto& handler : this->TestingHandlers) {
  306. handler.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(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(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.clear();
  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() || (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 (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 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 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::string const& a : args) {
  896. argv.push_back(a.c_str());
  897. }
  898. argv.push_back(nullptr);
  899. output.clear();
  900. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Run command:");
  901. for (char const* arg : argv) {
  902. if (!arg) {
  903. break;
  904. }
  905. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, " \"" << arg << "\"");
  906. }
  907. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, std::endl);
  908. // Now create process object
  909. cmsysProcess* cp = cmsysProcess_New();
  910. cmsysProcess_SetCommand(cp, &*argv.begin());
  911. cmsysProcess_SetWorkingDirectory(cp, dir);
  912. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  913. cmsysProcess_SetTimeout(cp, timeout);
  914. cmsysProcess_Execute(cp);
  915. // Initialize tick's
  916. std::string::size_type tick = 0;
  917. std::string::size_type tick_len = 1024;
  918. std::string::size_type tick_line_len = 50;
  919. char* data;
  920. int length;
  921. cmProcessOutput processOutput(encoding);
  922. std::string strdata;
  923. cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Each . represents "
  924. << tick_len << " bytes of output" << std::endl
  925. << " " << std::flush);
  926. while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
  927. processOutput.DecodeText(data, length, strdata);
  928. for (char& cc : strdata) {
  929. if (cc == 0) {
  930. cc = '\n';
  931. }
  932. }
  933. output.append(strdata);
  934. while (output.size() > (tick * tick_len)) {
  935. tick++;
  936. cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, "." << std::flush);
  937. if (tick % tick_line_len == 0 && tick > 0) {
  938. cmCTestLog(this, HANDLER_PROGRESS_OUTPUT,
  939. " Size: " << int((double(output.size()) / 1024.0) + 1)
  940. << "K" << std::endl
  941. << " " << std::flush);
  942. }
  943. }
  944. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  945. cmCTestLogWrite(strdata.c_str(), strdata.size()));
  946. if (ofs) {
  947. ofs << cmCTestLogWrite(strdata.c_str(), strdata.size());
  948. }
  949. }
  950. processOutput.DecodeText(std::string(), strdata);
  951. if (!strdata.empty()) {
  952. output.append(strdata);
  953. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  954. cmCTestLogWrite(strdata.c_str(), strdata.size()));
  955. if (ofs) {
  956. ofs << cmCTestLogWrite(strdata.c_str(), strdata.size());
  957. }
  958. }
  959. cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Size of output: "
  960. << int(double(output.size()) / 1024.0) << "K" << std::endl);
  961. cmsysProcess_WaitForExit(cp, nullptr);
  962. int result = cmsysProcess_GetState(cp);
  963. if (result == cmsysProcess_State_Exited) {
  964. *retVal = cmsysProcess_GetExitValue(cp);
  965. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  966. "Command exited with the value: " << *retVal << std::endl);
  967. } else if (result == cmsysProcess_State_Exception) {
  968. *retVal = cmsysProcess_GetExitException(cp);
  969. cmCTestLog(this, WARNING, "There was an exception: " << *retVal
  970. << std::endl);
  971. } else if (result == cmsysProcess_State_Expired) {
  972. cmCTestLog(this, WARNING, "There was a timeout" << std::endl);
  973. } else if (result == cmsysProcess_State_Error) {
  974. output += "\n*** ERROR executing: ";
  975. output += cmsysProcess_GetErrorString(cp);
  976. output += "\n***The build process failed.";
  977. cmCTestLog(this, ERROR_MESSAGE, "There was an error: "
  978. << cmsysProcess_GetErrorString(cp) << std::endl);
  979. }
  980. cmsysProcess_Delete(cp);
  981. return result;
  982. }
  983. //######################################################################
  984. //######################################################################
  985. //######################################################################
  986. //######################################################################
  987. int cmCTest::RunTest(std::vector<const char*> argv, std::string* output,
  988. int* retVal, std::ostream* log, double testTimeOut,
  989. std::vector<std::string>* environment, Encoding encoding)
  990. {
  991. bool modifyEnv = (environment && !environment->empty());
  992. // determine how much time we have
  993. double timeout = this->GetRemainingTimeAllowed() - 120;
  994. if (this->TimeOut > 0 && this->TimeOut < timeout) {
  995. timeout = this->TimeOut;
  996. }
  997. if (testTimeOut > 0 && testTimeOut < this->GetRemainingTimeAllowed()) {
  998. timeout = testTimeOut;
  999. }
  1000. // always have at least 1 second if we got to here
  1001. if (timeout <= 0) {
  1002. timeout = 1;
  1003. }
  1004. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  1005. "Test timeout computed to be: " << timeout << "\n");
  1006. if (cmSystemTools::SameFile(argv[0], cmSystemTools::GetCTestCommand()) &&
  1007. !this->ForceNewCTestProcess) {
  1008. cmCTest inst;
  1009. inst.ConfigType = this->ConfigType;
  1010. inst.TimeOut = timeout;
  1011. // Capture output of the child ctest.
  1012. std::ostringstream oss;
  1013. inst.SetStreams(&oss, &oss);
  1014. std::vector<std::string> args;
  1015. for (char const* i : argv) {
  1016. if (i) {
  1017. // make sure we pass the timeout in for any build and test
  1018. // invocations. Since --build-generator is required this is a
  1019. // good place to check for it, and to add the arguments in
  1020. if (strcmp(i, "--build-generator") == 0 && timeout > 0) {
  1021. args.push_back("--test-timeout");
  1022. std::ostringstream msg;
  1023. msg << timeout;
  1024. args.push_back(msg.str());
  1025. }
  1026. args.push_back(i);
  1027. }
  1028. }
  1029. if (log) {
  1030. *log << "* Run internal CTest" << std::endl;
  1031. }
  1032. CM_AUTO_PTR<cmSystemTools::SaveRestoreEnvironment> saveEnv;
  1033. if (modifyEnv) {
  1034. saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment);
  1035. cmSystemTools::AppendEnv(*environment);
  1036. }
  1037. *retVal = inst.Run(args, output);
  1038. if (output) {
  1039. *output += oss.str();
  1040. }
  1041. if (log && output) {
  1042. *log << *output;
  1043. }
  1044. if (output) {
  1045. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  1046. "Internal cmCTest object used to run test." << std::endl
  1047. << *output
  1048. << std::endl);
  1049. }
  1050. return cmsysProcess_State_Exited;
  1051. }
  1052. std::vector<char> tempOutput;
  1053. if (output) {
  1054. output->clear();
  1055. }
  1056. CM_AUTO_PTR<cmSystemTools::SaveRestoreEnvironment> saveEnv;
  1057. if (modifyEnv) {
  1058. saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment);
  1059. cmSystemTools::AppendEnv(*environment);
  1060. }
  1061. cmsysProcess* cp = cmsysProcess_New();
  1062. cmsysProcess_SetCommand(cp, &*argv.begin());
  1063. cmCTestLog(this, DEBUG, "Command is: " << argv[0] << std::endl);
  1064. if (cmSystemTools::GetRunCommandHideConsole()) {
  1065. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  1066. }
  1067. cmsysProcess_SetTimeout(cp, timeout);
  1068. cmsysProcess_Execute(cp);
  1069. char* data;
  1070. int length;
  1071. cmProcessOutput processOutput(encoding);
  1072. std::string strdata;
  1073. while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
  1074. processOutput.DecodeText(data, length, strdata);
  1075. if (output) {
  1076. tempOutput.insert(tempOutput.end(), data, data + length);
  1077. }
  1078. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  1079. cmCTestLogWrite(strdata.c_str(), strdata.size()));
  1080. if (log) {
  1081. log->write(strdata.c_str(), strdata.size());
  1082. }
  1083. }
  1084. processOutput.DecodeText(std::string(), strdata);
  1085. if (!strdata.empty()) {
  1086. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  1087. cmCTestLogWrite(strdata.c_str(), strdata.size()));
  1088. if (log) {
  1089. log->write(strdata.c_str(), strdata.size());
  1090. }
  1091. }
  1092. cmsysProcess_WaitForExit(cp, nullptr);
  1093. processOutput.DecodeText(tempOutput, tempOutput);
  1094. if (output && tempOutput.begin() != tempOutput.end()) {
  1095. output->append(&*tempOutput.begin(), tempOutput.size());
  1096. }
  1097. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "-- Process completed"
  1098. << std::endl);
  1099. int result = cmsysProcess_GetState(cp);
  1100. if (result == cmsysProcess_State_Exited) {
  1101. *retVal = cmsysProcess_GetExitValue(cp);
  1102. if (*retVal != 0 && this->OutputTestOutputOnTestFailure) {
  1103. OutputTestErrors(tempOutput);
  1104. }
  1105. } else if (result == cmsysProcess_State_Exception) {
  1106. if (this->OutputTestOutputOnTestFailure) {
  1107. OutputTestErrors(tempOutput);
  1108. }
  1109. *retVal = cmsysProcess_GetExitException(cp);
  1110. std::string outerr = "\n*** Exception executing: ";
  1111. outerr += cmsysProcess_GetExceptionString(cp);
  1112. if (output) {
  1113. *output += outerr;
  1114. }
  1115. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl
  1116. << std::flush);
  1117. } else if (result == cmsysProcess_State_Error) {
  1118. std::string outerr = "\n*** ERROR executing: ";
  1119. outerr += cmsysProcess_GetErrorString(cp);
  1120. if (output) {
  1121. *output += outerr;
  1122. }
  1123. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl
  1124. << std::flush);
  1125. }
  1126. cmsysProcess_Delete(cp);
  1127. return result;
  1128. }
  1129. std::string cmCTest::SafeBuildIdField(const std::string& value)
  1130. {
  1131. std::string safevalue(value);
  1132. if (safevalue != "") {
  1133. // Disallow non-filename and non-space whitespace characters.
  1134. // If they occur, replace them with ""
  1135. //
  1136. const char* disallowed = "\\:*?\"<>|\n\r\t\f\v";
  1137. if (safevalue.find_first_of(disallowed) != std::string::npos) {
  1138. std::string::size_type i = 0;
  1139. std::string::size_type n = strlen(disallowed);
  1140. char replace[2];
  1141. replace[1] = 0;
  1142. for (i = 0; i < n; ++i) {
  1143. replace[0] = disallowed[i];
  1144. cmSystemTools::ReplaceString(safevalue, replace, "");
  1145. }
  1146. }
  1147. }
  1148. if (safevalue == "") {
  1149. safevalue = "(empty)";
  1150. }
  1151. return safevalue;
  1152. }
  1153. void cmCTest::StartXML(cmXMLWriter& xml, bool append)
  1154. {
  1155. if (this->CurrentTag.empty()) {
  1156. cmCTestLog(this, ERROR_MESSAGE, "Current Tag empty, this may mean"
  1157. " NightlStartTime was not set correctly."
  1158. << std::endl);
  1159. cmSystemTools::SetFatalErrorOccured();
  1160. }
  1161. // find out about the system
  1162. cmsys::SystemInformation info;
  1163. info.RunCPUCheck();
  1164. info.RunOSCheck();
  1165. info.RunMemoryCheck();
  1166. std::string buildname =
  1167. cmCTest::SafeBuildIdField(this->GetCTestConfiguration("BuildName"));
  1168. std::string stamp = cmCTest::SafeBuildIdField(this->CurrentTag + "-" +
  1169. this->GetTestModelString());
  1170. std::string site =
  1171. cmCTest::SafeBuildIdField(this->GetCTestConfiguration("Site"));
  1172. xml.StartDocument();
  1173. xml.StartElement("Site");
  1174. xml.Attribute("BuildName", buildname);
  1175. xml.BreakAttributes();
  1176. xml.Attribute("BuildStamp", stamp);
  1177. xml.Attribute("Name", site);
  1178. xml.Attribute("Generator",
  1179. std::string("ctest-") + cmVersion::GetCMakeVersion());
  1180. if (append) {
  1181. xml.Attribute("Append", "true");
  1182. }
  1183. xml.Attribute("CompilerName", this->GetCTestConfiguration("Compiler"));
  1184. xml.Attribute("CompilerVersion",
  1185. this->GetCTestConfiguration("CompilerVersion"));
  1186. xml.Attribute("OSName", info.GetOSName());
  1187. xml.Attribute("Hostname", info.GetHostname());
  1188. xml.Attribute("OSRelease", info.GetOSRelease());
  1189. xml.Attribute("OSVersion", info.GetOSVersion());
  1190. xml.Attribute("OSPlatform", info.GetOSPlatform());
  1191. xml.Attribute("Is64Bits", info.Is64Bits());
  1192. xml.Attribute("VendorString", info.GetVendorString());
  1193. xml.Attribute("VendorID", info.GetVendorID());
  1194. xml.Attribute("FamilyID", info.GetFamilyID());
  1195. xml.Attribute("ModelID", info.GetModelID());
  1196. xml.Attribute("ProcessorCacheSize", info.GetProcessorCacheSize());
  1197. xml.Attribute("NumberOfLogicalCPU", info.GetNumberOfLogicalCPU());
  1198. xml.Attribute("NumberOfPhysicalCPU", info.GetNumberOfPhysicalCPU());
  1199. xml.Attribute("TotalVirtualMemory", info.GetTotalVirtualMemory());
  1200. xml.Attribute("TotalPhysicalMemory", info.GetTotalPhysicalMemory());
  1201. xml.Attribute("LogicalProcessorsPerPhysical",
  1202. info.GetLogicalProcessorsPerPhysical());
  1203. xml.Attribute("ProcessorClockFrequency", info.GetProcessorClockFrequency());
  1204. std::string changeId = this->GetCTestConfiguration("ChangeId");
  1205. if (!changeId.empty()) {
  1206. xml.Attribute("ChangeId", changeId);
  1207. }
  1208. this->AddSiteProperties(xml);
  1209. }
  1210. void cmCTest::AddSiteProperties(cmXMLWriter& xml)
  1211. {
  1212. cmCTestScriptHandler* ch =
  1213. static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1214. cmake* cm = ch->GetCMake();
  1215. // if no CMake then this is the old style script and props like
  1216. // this will not work anyway.
  1217. if (!cm) {
  1218. return;
  1219. }
  1220. // This code should go when cdash is changed to use labels only
  1221. const char* subproject = cm->GetState()->GetGlobalProperty("SubProject");
  1222. if (subproject) {
  1223. xml.StartElement("Subproject");
  1224. xml.Attribute("name", subproject);
  1225. const char* labels =
  1226. ch->GetCMake()->GetState()->GetGlobalProperty("SubProjectLabels");
  1227. if (labels) {
  1228. xml.StartElement("Labels");
  1229. std::string l = labels;
  1230. std::vector<std::string> args;
  1231. cmSystemTools::ExpandListArgument(l, args);
  1232. for (std::string const& i : args) {
  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::GenerateSubprojectsOutput(cmXMLWriter& xml)
  1248. {
  1249. for (std::string const& subproj : this->GetLabelsForSubprojects()) {
  1250. xml.StartElement("Subproject");
  1251. xml.Attribute("name", subproj);
  1252. xml.Element("Label", subproj);
  1253. xml.EndElement(); // Subproject
  1254. }
  1255. }
  1256. std::vector<std::string> cmCTest::GetLabelsForSubprojects()
  1257. {
  1258. std::string labelsForSubprojects =
  1259. this->GetCTestConfiguration("LabelsForSubprojects");
  1260. std::vector<std::string> subprojects;
  1261. cmSystemTools::ExpandListArgument(labelsForSubprojects, subprojects);
  1262. // sort the array
  1263. std::sort(subprojects.begin(), subprojects.end());
  1264. // remove duplicates
  1265. std::vector<std::string>::iterator new_end =
  1266. std::unique(subprojects.begin(), subprojects.end());
  1267. subprojects.erase(new_end, subprojects.end());
  1268. return subprojects;
  1269. }
  1270. void cmCTest::EndXML(cmXMLWriter& xml)
  1271. {
  1272. xml.EndElement(); // Site
  1273. xml.EndDocument();
  1274. }
  1275. int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml,
  1276. const cmCTest::VectorOfStrings& files)
  1277. {
  1278. std::string buildname =
  1279. cmCTest::SafeBuildIdField(this->GetCTestConfiguration("BuildName"));
  1280. xml.StartDocument();
  1281. xml.ProcessingInstruction("xml-stylesheet",
  1282. "type=\"text/xsl\" "
  1283. "href=\"Dart/Source/Server/XSL/Build.xsl "
  1284. "<file:///Dart/Source/Server/XSL/Build.xsl> \"");
  1285. xml.StartElement("Site");
  1286. xml.Attribute("BuildName", buildname);
  1287. xml.Attribute("BuildStamp",
  1288. this->CurrentTag + "-" + this->GetTestModelString());
  1289. xml.Attribute("Name", this->GetCTestConfiguration("Site"));
  1290. xml.Attribute("Generator",
  1291. std::string("ctest") + cmVersion::GetCMakeVersion());
  1292. this->AddSiteProperties(xml);
  1293. xml.StartElement("Notes");
  1294. for (cmsys::String const& file : files) {
  1295. cmCTestLog(this, OUTPUT, "\tAdd file: " << file << std::endl);
  1296. std::string note_time = this->CurrentTime();
  1297. xml.StartElement("Note");
  1298. xml.Attribute("Name", file);
  1299. xml.Element("Time", cmSystemTools::GetTime());
  1300. xml.Element("DateTime", note_time);
  1301. xml.StartElement("Text");
  1302. cmsys::ifstream ifs(file.c_str());
  1303. if (ifs) {
  1304. std::string line;
  1305. while (cmSystemTools::GetLineFromStream(ifs, line)) {
  1306. xml.Content(line);
  1307. xml.Content("\n");
  1308. }
  1309. ifs.close();
  1310. } else {
  1311. xml.Content("Problem reading file: " + file + "\n");
  1312. cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: "
  1313. << file << " while creating notes" << std::endl);
  1314. }
  1315. xml.EndElement(); // Text
  1316. xml.EndElement(); // Note
  1317. }
  1318. xml.EndElement(); // Notes
  1319. xml.EndElement(); // Site
  1320. xml.EndDocument();
  1321. return 1;
  1322. }
  1323. int cmCTest::GenerateNotesFile(const VectorOfStrings& files)
  1324. {
  1325. cmGeneratedFileStream ofs;
  1326. if (!this->OpenOutputFile(this->CurrentTag, "Notes.xml", ofs)) {
  1327. cmCTestLog(this, ERROR_MESSAGE, "Cannot open notes file" << std::endl);
  1328. return 1;
  1329. }
  1330. cmXMLWriter xml(ofs);
  1331. this->GenerateCTestNotesOutput(xml, files);
  1332. return 0;
  1333. }
  1334. int cmCTest::GenerateNotesFile(const char* cfiles)
  1335. {
  1336. if (!cfiles) {
  1337. return 1;
  1338. }
  1339. VectorOfStrings files;
  1340. cmCTestLog(this, OUTPUT, "Create notes file" << std::endl);
  1341. files = cmSystemTools::SplitString(cfiles, ';');
  1342. if (files.empty()) {
  1343. return 1;
  1344. }
  1345. return this->GenerateNotesFile(files);
  1346. }
  1347. std::string cmCTest::Base64GzipEncodeFile(std::string const& file)
  1348. {
  1349. std::string tarFile = file + "_temp.tar.gz";
  1350. std::vector<std::string> files;
  1351. files.push_back(file);
  1352. if (!cmSystemTools::CreateTar(tarFile.c_str(), files,
  1353. cmSystemTools::TarCompressGZip, false)) {
  1354. cmCTestLog(this, ERROR_MESSAGE, "Error creating tar while "
  1355. "encoding file: "
  1356. << file << std::endl);
  1357. return "";
  1358. }
  1359. std::string base64 = this->Base64EncodeFile(tarFile);
  1360. cmSystemTools::RemoveFile(tarFile);
  1361. return base64;
  1362. }
  1363. std::string cmCTest::Base64EncodeFile(std::string const& file)
  1364. {
  1365. size_t const len = cmSystemTools::FileLength(file);
  1366. cmsys::ifstream ifs(file.c_str(), std::ios::in
  1367. #ifdef _WIN32
  1368. | std::ios::binary
  1369. #endif
  1370. );
  1371. std::vector<char> file_buffer(len + 1);
  1372. ifs.read(&file_buffer[0], len);
  1373. ifs.close();
  1374. std::vector<char> encoded_buffer((len * 3) / 2 + 5);
  1375. size_t const rlen = cmsysBase64_Encode(
  1376. reinterpret_cast<unsigned char*>(&file_buffer[0]), len,
  1377. reinterpret_cast<unsigned char*>(&encoded_buffer[0]), 1);
  1378. return std::string(&encoded_buffer[0], rlen);
  1379. }
  1380. bool cmCTest::SubmitExtraFiles(const VectorOfStrings& files)
  1381. {
  1382. for (cmsys::String const& file : files) {
  1383. if (!cmSystemTools::FileExists(file.c_str())) {
  1384. cmCTestLog(this, ERROR_MESSAGE, "Cannot find extra file: "
  1385. << file << " to submit." << std::endl;);
  1386. return false;
  1387. }
  1388. this->AddSubmitFile(PartExtraFiles, file.c_str());
  1389. }
  1390. return true;
  1391. }
  1392. bool cmCTest::SubmitExtraFiles(const char* cfiles)
  1393. {
  1394. if (!cfiles) {
  1395. return true;
  1396. }
  1397. VectorOfStrings files;
  1398. cmCTestLog(this, OUTPUT, "Submit extra files" << std::endl);
  1399. files = cmSystemTools::SplitString(cfiles, ';');
  1400. if (files.empty()) {
  1401. return true;
  1402. }
  1403. return this->SubmitExtraFiles(files);
  1404. }
  1405. // for a -D argument convert the next argument into
  1406. // the proper list of dashboard steps via SetTest
  1407. bool cmCTest::AddTestsForDashboardType(std::string& targ)
  1408. {
  1409. if (targ == "Experimental") {
  1410. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1411. this->SetTest("Start");
  1412. this->SetTest("Configure");
  1413. this->SetTest("Build");
  1414. this->SetTest("Test");
  1415. this->SetTest("Coverage");
  1416. this->SetTest("Submit");
  1417. } else if (targ == "ExperimentalStart") {
  1418. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1419. this->SetTest("Start");
  1420. } else if (targ == "ExperimentalUpdate") {
  1421. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1422. this->SetTest("Update");
  1423. } else if (targ == "ExperimentalConfigure") {
  1424. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1425. this->SetTest("Configure");
  1426. } else if (targ == "ExperimentalBuild") {
  1427. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1428. this->SetTest("Build");
  1429. } else if (targ == "ExperimentalTest") {
  1430. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1431. this->SetTest("Test");
  1432. } else if (targ == "ExperimentalMemCheck" || targ == "ExperimentalPurify") {
  1433. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1434. this->SetTest("MemCheck");
  1435. } else if (targ == "ExperimentalCoverage") {
  1436. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1437. this->SetTest("Coverage");
  1438. } else if (targ == "ExperimentalSubmit") {
  1439. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1440. this->SetTest("Submit");
  1441. } else if (targ == "Continuous") {
  1442. this->SetTestModel(cmCTest::CONTINUOUS);
  1443. this->SetTest("Start");
  1444. this->SetTest("Update");
  1445. this->SetTest("Configure");
  1446. this->SetTest("Build");
  1447. this->SetTest("Test");
  1448. this->SetTest("Coverage");
  1449. this->SetTest("Submit");
  1450. } else if (targ == "ContinuousStart") {
  1451. this->SetTestModel(cmCTest::CONTINUOUS);
  1452. this->SetTest("Start");
  1453. } else if (targ == "ContinuousUpdate") {
  1454. this->SetTestModel(cmCTest::CONTINUOUS);
  1455. this->SetTest("Update");
  1456. } else if (targ == "ContinuousConfigure") {
  1457. this->SetTestModel(cmCTest::CONTINUOUS);
  1458. this->SetTest("Configure");
  1459. } else if (targ == "ContinuousBuild") {
  1460. this->SetTestModel(cmCTest::CONTINUOUS);
  1461. this->SetTest("Build");
  1462. } else if (targ == "ContinuousTest") {
  1463. this->SetTestModel(cmCTest::CONTINUOUS);
  1464. this->SetTest("Test");
  1465. } else if (targ == "ContinuousMemCheck" || targ == "ContinuousPurify") {
  1466. this->SetTestModel(cmCTest::CONTINUOUS);
  1467. this->SetTest("MemCheck");
  1468. } else if (targ == "ContinuousCoverage") {
  1469. this->SetTestModel(cmCTest::CONTINUOUS);
  1470. this->SetTest("Coverage");
  1471. } else if (targ == "ContinuousSubmit") {
  1472. this->SetTestModel(cmCTest::CONTINUOUS);
  1473. this->SetTest("Submit");
  1474. } else if (targ == "Nightly") {
  1475. this->SetTestModel(cmCTest::NIGHTLY);
  1476. this->SetTest("Start");
  1477. this->SetTest("Update");
  1478. this->SetTest("Configure");
  1479. this->SetTest("Build");
  1480. this->SetTest("Test");
  1481. this->SetTest("Coverage");
  1482. this->SetTest("Submit");
  1483. } else if (targ == "NightlyStart") {
  1484. this->SetTestModel(cmCTest::NIGHTLY);
  1485. this->SetTest("Start");
  1486. } else if (targ == "NightlyUpdate") {
  1487. this->SetTestModel(cmCTest::NIGHTLY);
  1488. this->SetTest("Update");
  1489. } else if (targ == "NightlyConfigure") {
  1490. this->SetTestModel(cmCTest::NIGHTLY);
  1491. this->SetTest("Configure");
  1492. } else if (targ == "NightlyBuild") {
  1493. this->SetTestModel(cmCTest::NIGHTLY);
  1494. this->SetTest("Build");
  1495. } else if (targ == "NightlyTest") {
  1496. this->SetTestModel(cmCTest::NIGHTLY);
  1497. this->SetTest("Test");
  1498. } else if (targ == "NightlyMemCheck" || targ == "NightlyPurify") {
  1499. this->SetTestModel(cmCTest::NIGHTLY);
  1500. this->SetTest("MemCheck");
  1501. } else if (targ == "NightlyCoverage") {
  1502. this->SetTestModel(cmCTest::NIGHTLY);
  1503. this->SetTest("Coverage");
  1504. } else if (targ == "NightlySubmit") {
  1505. this->SetTestModel(cmCTest::NIGHTLY);
  1506. this->SetTest("Submit");
  1507. } else if (targ == "MemoryCheck") {
  1508. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1509. this->SetTest("Start");
  1510. this->SetTest("Configure");
  1511. this->SetTest("Build");
  1512. this->SetTest("MemCheck");
  1513. this->SetTest("Coverage");
  1514. this->SetTest("Submit");
  1515. } else if (targ == "NightlyMemoryCheck") {
  1516. this->SetTestModel(cmCTest::NIGHTLY);
  1517. this->SetTest("Start");
  1518. this->SetTest("Update");
  1519. this->SetTest("Configure");
  1520. this->SetTest("Build");
  1521. this->SetTest("MemCheck");
  1522. this->SetTest("Coverage");
  1523. this->SetTest("Submit");
  1524. } else {
  1525. return false;
  1526. }
  1527. return true;
  1528. }
  1529. void cmCTest::ErrorMessageUnknownDashDValue(std::string& val)
  1530. {
  1531. cmCTestLog(this, ERROR_MESSAGE,
  1532. "CTest -D called with incorrect option: " << val << std::endl);
  1533. cmCTestLog(
  1534. this, ERROR_MESSAGE, "Available options are:"
  1535. << std::endl
  1536. << " ctest -D Continuous" << std::endl
  1537. << " ctest -D Continuous(Start|Update|Configure|Build)" << std::endl
  1538. << " ctest -D Continuous(Test|Coverage|MemCheck|Submit)" << std::endl
  1539. << " ctest -D Experimental" << std::endl
  1540. << " ctest -D Experimental(Start|Update|Configure|Build)" << std::endl
  1541. << " ctest -D Experimental(Test|Coverage|MemCheck|Submit)" << std::endl
  1542. << " ctest -D Nightly" << std::endl
  1543. << " ctest -D Nightly(Start|Update|Configure|Build)" << std::endl
  1544. << " ctest -D Nightly(Test|Coverage|MemCheck|Submit)" << std::endl
  1545. << " ctest -D NightlyMemoryCheck" << std::endl);
  1546. }
  1547. bool cmCTest::CheckArgument(const std::string& arg, const char* varg1,
  1548. const char* varg2)
  1549. {
  1550. return (varg1 && arg == varg1) || (varg2 && arg == varg2);
  1551. }
  1552. // Processes one command line argument (and its arguments if any)
  1553. // for many simple options and then returns
  1554. bool cmCTest::HandleCommandLineArguments(size_t& i,
  1555. std::vector<std::string>& args,
  1556. std::string& errormsg)
  1557. {
  1558. std::string arg = args[i];
  1559. if (this->CheckArgument(arg, "-F")) {
  1560. this->Failover = true;
  1561. }
  1562. if (this->CheckArgument(arg, "-j", "--parallel") && i < args.size() - 1) {
  1563. i++;
  1564. int plevel = atoi(args[i].c_str());
  1565. this->SetParallelLevel(plevel);
  1566. this->ParallelLevelSetInCli = true;
  1567. } else if (arg.find("-j") == 0) {
  1568. int plevel = atoi(arg.substr(2).c_str());
  1569. this->SetParallelLevel(plevel);
  1570. this->ParallelLevelSetInCli = true;
  1571. }
  1572. if (this->CheckArgument(arg, "--repeat-until-fail")) {
  1573. if (i >= args.size() - 1) {
  1574. errormsg = "'--repeat-until-fail' requires an argument";
  1575. return false;
  1576. }
  1577. i++;
  1578. long repeat = 1;
  1579. if (!cmSystemTools::StringToLong(args[i].c_str(), &repeat)) {
  1580. errormsg =
  1581. "'--repeat-until-fail' given non-integer value '" + args[i] + "'";
  1582. return false;
  1583. }
  1584. this->RepeatTests = static_cast<int>(repeat);
  1585. if (repeat > 1) {
  1586. this->RepeatUntilFail = true;
  1587. }
  1588. }
  1589. if (this->CheckArgument(arg, "--test-load") && i < args.size() - 1) {
  1590. i++;
  1591. unsigned long load;
  1592. if (cmSystemTools::StringToULong(args[i].c_str(), &load)) {
  1593. this->SetTestLoad(load);
  1594. } else {
  1595. cmCTestLog(this, WARNING,
  1596. "Invalid value for 'Test Load' : " << args[i] << std::endl);
  1597. }
  1598. }
  1599. if (this->CheckArgument(arg, "--no-compress-output")) {
  1600. this->CompressTestOutput = false;
  1601. }
  1602. if (this->CheckArgument(arg, "--print-labels")) {
  1603. this->PrintLabels = true;
  1604. }
  1605. if (this->CheckArgument(arg, "--http1.0")) {
  1606. this->UseHTTP10 = true;
  1607. }
  1608. if (this->CheckArgument(arg, "--timeout") && i < args.size() - 1) {
  1609. i++;
  1610. double timeout = atof(args[i].c_str());
  1611. this->GlobalTimeout = timeout;
  1612. }
  1613. if (this->CheckArgument(arg, "--stop-time") && i < args.size() - 1) {
  1614. i++;
  1615. this->SetStopTime(args[i]);
  1616. }
  1617. if (this->CheckArgument(arg, "-C", "--build-config") &&
  1618. i < args.size() - 1) {
  1619. i++;
  1620. this->SetConfigType(args[i].c_str());
  1621. }
  1622. if (this->CheckArgument(arg, "--debug")) {
  1623. this->Debug = true;
  1624. this->ShowLineNumbers = true;
  1625. }
  1626. if (this->CheckArgument(arg, "--track") && i < args.size() - 1) {
  1627. i++;
  1628. this->SpecificTrack = args[i];
  1629. }
  1630. if (this->CheckArgument(arg, "--show-line-numbers")) {
  1631. this->ShowLineNumbers = true;
  1632. }
  1633. if (this->CheckArgument(arg, "--no-label-summary")) {
  1634. this->LabelSummary = false;
  1635. }
  1636. if (this->CheckArgument(arg, "--no-subproject-summary")) {
  1637. this->SubprojectSummary = false;
  1638. }
  1639. if (this->CheckArgument(arg, "-Q", "--quiet")) {
  1640. this->Quiet = true;
  1641. }
  1642. if (this->CheckArgument(arg, "-V", "--verbose")) {
  1643. this->Verbose = true;
  1644. }
  1645. if (this->CheckArgument(arg, "-B")) {
  1646. this->BatchJobs = true;
  1647. }
  1648. if (this->CheckArgument(arg, "-VV", "--extra-verbose")) {
  1649. this->ExtraVerbose = true;
  1650. this->Verbose = true;
  1651. }
  1652. if (this->CheckArgument(arg, "--output-on-failure")) {
  1653. this->OutputTestOutputOnTestFailure = true;
  1654. }
  1655. if (this->CheckArgument(arg, "--test-output-size-passed") &&
  1656. i < args.size() - 1) {
  1657. i++;
  1658. long outputSize;
  1659. if (cmSystemTools::StringToLong(args[i].c_str(), &outputSize)) {
  1660. if (cmCTestTestHandler* pCTestTestHandler =
  1661. static_cast<cmCTestTestHandler*>(this->TestingHandlers["test"])) {
  1662. pCTestTestHandler->SetTestOutputSizePassed(int(outputSize));
  1663. }
  1664. } else {
  1665. cmCTestLog(this, WARNING,
  1666. "Invalid value for '--test-output-size-passed': " << args[i]
  1667. << "\n");
  1668. }
  1669. }
  1670. if (this->CheckArgument(arg, "--test-output-size-failed") &&
  1671. i < args.size() - 1) {
  1672. i++;
  1673. long outputSize;
  1674. if (cmSystemTools::StringToLong(args[i].c_str(), &outputSize)) {
  1675. if (cmCTestTestHandler* pCTestTestHandler =
  1676. static_cast<cmCTestTestHandler*>(this->TestingHandlers["test"])) {
  1677. pCTestTestHandler->SetTestOutputSizeFailed(int(outputSize));
  1678. }
  1679. } else {
  1680. cmCTestLog(this, WARNING,
  1681. "Invalid value for '--test-output-size-failed': " << args[i]
  1682. << "\n");
  1683. }
  1684. }
  1685. if (this->CheckArgument(arg, "-N", "--show-only")) {
  1686. this->ShowOnly = true;
  1687. }
  1688. if (this->CheckArgument(arg, "-O", "--output-log") && i < args.size() - 1) {
  1689. i++;
  1690. this->SetOutputLogFileName(args[i].c_str());
  1691. }
  1692. if (this->CheckArgument(arg, "--tomorrow-tag")) {
  1693. this->TomorrowTag = true;
  1694. }
  1695. if (this->CheckArgument(arg, "--force-new-ctest-process")) {
  1696. this->ForceNewCTestProcess = true;
  1697. }
  1698. if (this->CheckArgument(arg, "-W", "--max-width") && i < args.size() - 1) {
  1699. i++;
  1700. this->MaxTestNameWidth = atoi(args[i].c_str());
  1701. }
  1702. if (this->CheckArgument(arg, "--interactive-debug-mode") &&
  1703. i < args.size() - 1) {
  1704. i++;
  1705. this->InteractiveDebugMode = cmSystemTools::IsOn(args[i].c_str());
  1706. }
  1707. if (this->CheckArgument(arg, "--submit-index") && i < args.size() - 1) {
  1708. i++;
  1709. this->SubmitIndex = atoi(args[i].c_str());
  1710. if (this->SubmitIndex < 0) {
  1711. this->SubmitIndex = 0;
  1712. }
  1713. }
  1714. if (this->CheckArgument(arg, "--overwrite") && i < args.size() - 1) {
  1715. i++;
  1716. this->AddCTestConfigurationOverwrite(args[i]);
  1717. }
  1718. if (this->CheckArgument(arg, "-A", "--add-notes") && i < args.size() - 1) {
  1719. this->ProduceXML = true;
  1720. this->SetTest("Notes");
  1721. i++;
  1722. this->SetNotesFiles(args[i].c_str());
  1723. }
  1724. // options that control what tests are run
  1725. if (this->CheckArgument(arg, "-I", "--tests-information") &&
  1726. i < args.size() - 1) {
  1727. i++;
  1728. this->GetHandler("test")->SetPersistentOption("TestsToRunInformation",
  1729. args[i].c_str());
  1730. this->GetHandler("memcheck")
  1731. ->SetPersistentOption("TestsToRunInformation", args[i].c_str());
  1732. }
  1733. if (this->CheckArgument(arg, "-U", "--union")) {
  1734. this->GetHandler("test")->SetPersistentOption("UseUnion", "true");
  1735. this->GetHandler("memcheck")->SetPersistentOption("UseUnion", "true");
  1736. }
  1737. if (this->CheckArgument(arg, "-R", "--tests-regex") && i < args.size() - 1) {
  1738. i++;
  1739. this->GetHandler("test")->SetPersistentOption("IncludeRegularExpression",
  1740. args[i].c_str());
  1741. this->GetHandler("memcheck")
  1742. ->SetPersistentOption("IncludeRegularExpression", args[i].c_str());
  1743. }
  1744. if (this->CheckArgument(arg, "-L", "--label-regex") && i < args.size() - 1) {
  1745. i++;
  1746. this->GetHandler("test")->SetPersistentOption("LabelRegularExpression",
  1747. args[i].c_str());
  1748. this->GetHandler("memcheck")
  1749. ->SetPersistentOption("LabelRegularExpression", args[i].c_str());
  1750. }
  1751. if (this->CheckArgument(arg, "-LE", "--label-exclude") &&
  1752. i < args.size() - 1) {
  1753. i++;
  1754. this->GetHandler("test")->SetPersistentOption(
  1755. "ExcludeLabelRegularExpression", args[i].c_str());
  1756. this->GetHandler("memcheck")
  1757. ->SetPersistentOption("ExcludeLabelRegularExpression", args[i].c_str());
  1758. }
  1759. if (this->CheckArgument(arg, "-E", "--exclude-regex") &&
  1760. i < args.size() - 1) {
  1761. i++;
  1762. this->GetHandler("test")->SetPersistentOption("ExcludeRegularExpression",
  1763. args[i].c_str());
  1764. this->GetHandler("memcheck")
  1765. ->SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
  1766. }
  1767. if (this->CheckArgument(arg, "-FA", "--fixture-exclude-any") &&
  1768. i < args.size() - 1) {
  1769. i++;
  1770. this->GetHandler("test")->SetPersistentOption(
  1771. "ExcludeFixtureRegularExpression", args[i].c_str());
  1772. this->GetHandler("memcheck")
  1773. ->SetPersistentOption("ExcludeFixtureRegularExpression",
  1774. args[i].c_str());
  1775. }
  1776. if (this->CheckArgument(arg, "-FS", "--fixture-exclude-setup") &&
  1777. i < args.size() - 1) {
  1778. i++;
  1779. this->GetHandler("test")->SetPersistentOption(
  1780. "ExcludeFixtureSetupRegularExpression", args[i].c_str());
  1781. this->GetHandler("memcheck")
  1782. ->SetPersistentOption("ExcludeFixtureSetupRegularExpression",
  1783. args[i].c_str());
  1784. }
  1785. if (this->CheckArgument(arg, "-FC", "--fixture-exclude-cleanup") &&
  1786. i < args.size() - 1) {
  1787. i++;
  1788. this->GetHandler("test")->SetPersistentOption(
  1789. "ExcludeFixtureCleanupRegularExpression", args[i].c_str());
  1790. this->GetHandler("memcheck")
  1791. ->SetPersistentOption("ExcludeFixtureCleanupRegularExpression",
  1792. args[i].c_str());
  1793. }
  1794. if (this->CheckArgument(arg, "--rerun-failed")) {
  1795. this->GetHandler("test")->SetPersistentOption("RerunFailed", "true");
  1796. this->GetHandler("memcheck")->SetPersistentOption("RerunFailed", "true");
  1797. }
  1798. return true;
  1799. }
  1800. // handle the -S -SR and -SP arguments
  1801. void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args,
  1802. bool& SRArgumentSpecified)
  1803. {
  1804. std::string arg = args[i];
  1805. if (this->CheckArgument(arg, "-SP", "--script-new-process") &&
  1806. i < args.size() - 1) {
  1807. this->RunConfigurationScript = true;
  1808. i++;
  1809. cmCTestScriptHandler* ch =
  1810. static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1811. // -SR is an internal argument, -SP should be ignored when it is passed
  1812. if (!SRArgumentSpecified) {
  1813. ch->AddConfigurationScript(args[i].c_str(), false);
  1814. }
  1815. }
  1816. if (this->CheckArgument(arg, "-SR", "--script-run") && i < args.size() - 1) {
  1817. SRArgumentSpecified = true;
  1818. this->RunConfigurationScript = true;
  1819. i++;
  1820. cmCTestScriptHandler* ch =
  1821. static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1822. ch->AddConfigurationScript(args[i].c_str(), true);
  1823. }
  1824. if (this->CheckArgument(arg, "-S", "--script") && i < args.size() - 1) {
  1825. this->RunConfigurationScript = true;
  1826. i++;
  1827. cmCTestScriptHandler* ch =
  1828. static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1829. // -SR is an internal argument, -S should be ignored when it is passed
  1830. if (!SRArgumentSpecified) {
  1831. ch->AddConfigurationScript(args[i].c_str(), true);
  1832. }
  1833. }
  1834. }
  1835. bool cmCTest::AddVariableDefinition(const std::string& arg)
  1836. {
  1837. std::string name;
  1838. std::string value;
  1839. cmStateEnums::CacheEntryType type = cmStateEnums::UNINITIALIZED;
  1840. if (cmake::ParseCacheEntry(arg, name, value, type)) {
  1841. this->Definitions[name] = value;
  1842. return true;
  1843. }
  1844. return false;
  1845. }
  1846. // the main entry point of ctest, called from main
  1847. int cmCTest::Run(std::vector<std::string>& args, std::string* output)
  1848. {
  1849. const char* ctestExec = "ctest";
  1850. bool cmakeAndTest = false;
  1851. bool executeTests = true;
  1852. bool SRArgumentSpecified = false;
  1853. // copy the command line
  1854. this->InitialCommandLineArguments.insert(
  1855. this->InitialCommandLineArguments.end(), args.begin(), args.end());
  1856. // process the command line arguments
  1857. for (size_t i = 1; i < args.size(); ++i) {
  1858. // handle the simple commandline arguments
  1859. std::string errormsg;
  1860. if (!this->HandleCommandLineArguments(i, args, errormsg)) {
  1861. cmSystemTools::Error(errormsg.c_str());
  1862. return 1;
  1863. }
  1864. // handle the script arguments -S -SR -SP
  1865. this->HandleScriptArguments(i, args, SRArgumentSpecified);
  1866. // --dashboard: handle a request for a dashboard
  1867. std::string arg = args[i];
  1868. if (this->CheckArgument(arg, "-D", "--dashboard") && i < args.size() - 1) {
  1869. this->ProduceXML = true;
  1870. i++;
  1871. std::string targ = args[i];
  1872. // AddTestsForDashboard parses the dashboard type and converts it
  1873. // into the separate stages
  1874. if (!this->AddTestsForDashboardType(targ)) {
  1875. if (!this->AddVariableDefinition(targ)) {
  1876. this->ErrorMessageUnknownDashDValue(targ);
  1877. executeTests = false;
  1878. }
  1879. }
  1880. }
  1881. // If it's not exactly -D, but it starts with -D, then try to parse out
  1882. // a variable definition from it, same as CMake does. Unsuccessful
  1883. // attempts are simply ignored since previous ctest versions ignore
  1884. // this too. (As well as many other unknown command line args.)
  1885. //
  1886. if (arg != "-D" && cmSystemTools::StringStartsWith(arg.c_str(), "-D")) {
  1887. std::string input = arg.substr(2);
  1888. this->AddVariableDefinition(input);
  1889. }
  1890. // --test-action: calls SetTest(<stage>, /*report=*/ false) to enable
  1891. // the corresponding stage
  1892. if (!this->HandleTestActionArgument(ctestExec, i, args)) {
  1893. executeTests = false;
  1894. }
  1895. // --test-model: what type of test model
  1896. if (!this->HandleTestModelArgument(ctestExec, i, args)) {
  1897. executeTests = false;
  1898. }
  1899. // --extra-submit
  1900. if (this->CheckArgument(arg, "--extra-submit") && i < args.size() - 1) {
  1901. this->ProduceXML = true;
  1902. this->SetTest("Submit");
  1903. i++;
  1904. if (!this->SubmitExtraFiles(args[i].c_str())) {
  1905. return 0;
  1906. }
  1907. }
  1908. // --build-and-test options
  1909. if (this->CheckArgument(arg, "--build-and-test") && i < args.size() - 1) {
  1910. cmakeAndTest = true;
  1911. }
  1912. // --schedule-random
  1913. if (this->CheckArgument(arg, "--schedule-random")) {
  1914. this->ScheduleType = "Random";
  1915. }
  1916. // pass the argument to all the handlers as well, but i may no longer be
  1917. // set to what it was originally so I'm not sure this is working as
  1918. // intended
  1919. for (auto& handler : this->TestingHandlers) {
  1920. if (!handler.second->ProcessCommandLineArguments(arg, i, args)) {
  1921. cmCTestLog(this, ERROR_MESSAGE,
  1922. "Problem parsing command line arguments within a handler");
  1923. return 0;
  1924. }
  1925. }
  1926. } // the close of the for argument loop
  1927. // handle CTEST_PARALLEL_LEVEL environment variable
  1928. if (!this->ParallelLevelSetInCli) {
  1929. std::string parallel;
  1930. if (cmSystemTools::GetEnv("CTEST_PARALLEL_LEVEL", parallel)) {
  1931. int plevel = atoi(parallel.c_str());
  1932. this->SetParallelLevel(plevel);
  1933. }
  1934. }
  1935. // now what should cmake do? if --build-and-test was specified then
  1936. // we run the build and test handler and return
  1937. if (cmakeAndTest) {
  1938. return this->RunCMakeAndTest(output);
  1939. }
  1940. if (executeTests) {
  1941. return this->ExecuteTests();
  1942. }
  1943. return 1;
  1944. }
  1945. bool cmCTest::HandleTestActionArgument(const char* ctestExec, size_t& i,
  1946. const std::vector<std::string>& args)
  1947. {
  1948. bool success = true;
  1949. std::string arg = args[i];
  1950. if (this->CheckArgument(arg, "-T", "--test-action") &&
  1951. (i < args.size() - 1)) {
  1952. this->ProduceXML = true;
  1953. i++;
  1954. if (!this->SetTest(args[i].c_str(), false)) {
  1955. success = false;
  1956. cmCTestLog(this, ERROR_MESSAGE, "CTest -T called with incorrect option: "
  1957. << args[i] << std::endl);
  1958. cmCTestLog(this, ERROR_MESSAGE, "Available options are:"
  1959. << std::endl
  1960. << " " << ctestExec << " -T all" << std::endl
  1961. << " " << ctestExec << " -T start" << std::endl
  1962. << " " << ctestExec << " -T update" << std::endl
  1963. << " " << ctestExec << " -T configure" << std::endl
  1964. << " " << ctestExec << " -T build" << std::endl
  1965. << " " << ctestExec << " -T test" << std::endl
  1966. << " " << ctestExec << " -T coverage" << std::endl
  1967. << " " << ctestExec << " -T memcheck" << std::endl
  1968. << " " << ctestExec << " -T notes" << std::endl
  1969. << " " << ctestExec << " -T submit" << std::endl);
  1970. }
  1971. }
  1972. return success;
  1973. }
  1974. bool cmCTest::HandleTestModelArgument(const char* ctestExec, size_t& i,
  1975. const std::vector<std::string>& args)
  1976. {
  1977. bool success = true;
  1978. std::string arg = args[i];
  1979. if (this->CheckArgument(arg, "-M", "--test-model") &&
  1980. (i < args.size() - 1)) {
  1981. i++;
  1982. std::string const& str = args[i];
  1983. if (cmSystemTools::LowerCase(str) == "nightly") {
  1984. this->SetTestModel(cmCTest::NIGHTLY);
  1985. } else if (cmSystemTools::LowerCase(str) == "continuous") {
  1986. this->SetTestModel(cmCTest::CONTINUOUS);
  1987. } else if (cmSystemTools::LowerCase(str) == "experimental") {
  1988. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1989. } else {
  1990. success = false;
  1991. cmCTestLog(this, ERROR_MESSAGE, "CTest -M called with incorrect option: "
  1992. << str << std::endl);
  1993. cmCTestLog(this, ERROR_MESSAGE, "Available options are:"
  1994. << std::endl
  1995. << " " << ctestExec << " -M Continuous" << std::endl
  1996. << " " << ctestExec << " -M Experimental" << std::endl
  1997. << " " << ctestExec << " -M Nightly" << std::endl);
  1998. }
  1999. }
  2000. return success;
  2001. }
  2002. int cmCTest::ExecuteTests()
  2003. {
  2004. int res;
  2005. // call process directory
  2006. if (this->RunConfigurationScript) {
  2007. if (this->ExtraVerbose) {
  2008. cmCTestLog(this, OUTPUT, "* Extra verbosity turned on" << std::endl);
  2009. }
  2010. for (auto& handler : this->TestingHandlers) {
  2011. handler.second->SetVerbose(this->ExtraVerbose);
  2012. handler.second->SetSubmitIndex(this->SubmitIndex);
  2013. }
  2014. this->GetHandler("script")->SetVerbose(this->Verbose);
  2015. res = this->GetHandler("script")->ProcessHandler();
  2016. if (res != 0) {
  2017. cmCTestLog(this, DEBUG,
  2018. "running script failing returning: " << res << std::endl);
  2019. }
  2020. } else {
  2021. // What is this? -V seems to be the same as -VV,
  2022. // and Verbose is always on in this case
  2023. this->ExtraVerbose = this->Verbose;
  2024. this->Verbose = true;
  2025. for (auto& handler : this->TestingHandlers) {
  2026. handler.second->SetVerbose(this->Verbose);
  2027. handler.second->SetSubmitIndex(this->SubmitIndex);
  2028. }
  2029. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  2030. if (!this->Initialize(cwd.c_str(), nullptr)) {
  2031. res = 12;
  2032. cmCTestLog(this, ERROR_MESSAGE, "Problem initializing the dashboard."
  2033. << std::endl);
  2034. } else {
  2035. res = this->ProcessSteps();
  2036. }
  2037. this->Finalize();
  2038. }
  2039. if (res != 0) {
  2040. cmCTestLog(this, DEBUG,
  2041. "Running a test(s) failed returning : " << res << std::endl);
  2042. }
  2043. return res;
  2044. }
  2045. int cmCTest::RunCMakeAndTest(std::string* output)
  2046. {
  2047. this->Verbose = true;
  2048. cmCTestBuildAndTestHandler* handler =
  2049. static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest"));
  2050. int retv = handler->ProcessHandler();
  2051. *output = handler->GetOutput();
  2052. #ifdef CMAKE_BUILD_WITH_CMAKE
  2053. cmDynamicLoader::FlushCache();
  2054. #endif
  2055. if (retv != 0) {
  2056. cmCTestLog(this, DEBUG, "build and test failing returning: " << retv
  2057. << std::endl);
  2058. }
  2059. return retv;
  2060. }
  2061. void cmCTest::SetNotesFiles(const char* notes)
  2062. {
  2063. if (!notes) {
  2064. return;
  2065. }
  2066. this->NotesFiles = notes;
  2067. }
  2068. void cmCTest::SetStopTime(std::string const& time)
  2069. {
  2070. this->StopTime = time;
  2071. this->DetermineNextDayStop();
  2072. }
  2073. int cmCTest::ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf)
  2074. {
  2075. bool found = false;
  2076. VectorOfStrings dirs;
  2077. VectorOfStrings ndirs;
  2078. cmCTestLog(this, DEBUG, "* Read custom CTest configuration directory: "
  2079. << dir << std::endl);
  2080. std::string fname = dir;
  2081. fname += "/CTestCustom.cmake";
  2082. cmCTestLog(this, DEBUG, "* Check for file: " << fname << std::endl);
  2083. if (cmSystemTools::FileExists(fname.c_str())) {
  2084. cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: "
  2085. << fname << std::endl);
  2086. bool erroroc = cmSystemTools::GetErrorOccuredFlag();
  2087. cmSystemTools::ResetErrorOccuredFlag();
  2088. if (!mf->ReadListFile(fname.c_str()) ||
  2089. cmSystemTools::GetErrorOccuredFlag()) {
  2090. cmCTestLog(this, ERROR_MESSAGE, "Problem reading custom configuration: "
  2091. << fname << std::endl);
  2092. }
  2093. found = true;
  2094. if (erroroc) {
  2095. cmSystemTools::SetErrorOccured();
  2096. }
  2097. }
  2098. std::string rexpr = dir;
  2099. rexpr += "/CTestCustom.ctest";
  2100. cmCTestLog(this, DEBUG, "* Check for file: " << rexpr << std::endl);
  2101. if (!found && cmSystemTools::FileExists(rexpr.c_str())) {
  2102. cmsys::Glob gl;
  2103. gl.RecurseOn();
  2104. gl.FindFiles(rexpr);
  2105. std::vector<std::string>& files = gl.GetFiles();
  2106. std::vector<std::string>::iterator fileIt;
  2107. for (fileIt = files.begin(); fileIt != files.end(); ++fileIt) {
  2108. cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: "
  2109. << *fileIt << std::endl);
  2110. if (!mf->ReadListFile(fileIt->c_str()) ||
  2111. cmSystemTools::GetErrorOccuredFlag()) {
  2112. cmCTestLog(this, ERROR_MESSAGE,
  2113. "Problem reading custom configuration: " << *fileIt
  2114. << std::endl);
  2115. }
  2116. }
  2117. found = true;
  2118. }
  2119. if (found) {
  2120. for (auto& handler : this->TestingHandlers) {
  2121. cmCTestLog(
  2122. this, DEBUG, "* Read custom CTest configuration vectors for handler: "
  2123. << handler.first << " (" << handler.second << ")" << std::endl);
  2124. handler.second->PopulateCustomVectors(mf);
  2125. }
  2126. }
  2127. return 1;
  2128. }
  2129. void cmCTest::PopulateCustomVector(cmMakefile* mf, const std::string& def,
  2130. std::vector<std::string>& vec)
  2131. {
  2132. const char* dval = mf->GetDefinition(def);
  2133. if (!dval) {
  2134. return;
  2135. }
  2136. cmCTestLog(this, DEBUG, "PopulateCustomVector: " << def << std::endl);
  2137. vec.clear();
  2138. cmSystemTools::ExpandListArgument(dval, vec);
  2139. for (std::string const& it : vec) {
  2140. cmCTestLog(this, DEBUG, " -- " << it << std::endl);
  2141. }
  2142. }
  2143. void cmCTest::PopulateCustomInteger(cmMakefile* mf, const std::string& def,
  2144. int& val)
  2145. {
  2146. const char* dval = mf->GetDefinition(def);
  2147. if (!dval) {
  2148. return;
  2149. }
  2150. val = atoi(dval);
  2151. }
  2152. std::string cmCTest::GetShortPathToFile(const char* cfname)
  2153. {
  2154. const std::string& sourceDir = cmSystemTools::CollapseFullPath(
  2155. this->GetCTestConfiguration("SourceDirectory"));
  2156. const std::string& buildDir = cmSystemTools::CollapseFullPath(
  2157. this->GetCTestConfiguration("BuildDirectory"));
  2158. std::string fname = cmSystemTools::CollapseFullPath(cfname);
  2159. // Find relative paths to both directories
  2160. std::string srcRelpath =
  2161. cmSystemTools::RelativePath(sourceDir.c_str(), fname.c_str());
  2162. std::string bldRelpath =
  2163. cmSystemTools::RelativePath(buildDir.c_str(), fname.c_str());
  2164. // If any contains "." it is not parent directory
  2165. bool inSrc = srcRelpath.find("..") == std::string::npos;
  2166. bool inBld = bldRelpath.find("..") == std::string::npos;
  2167. // TODO: Handle files with .. in their name
  2168. std::string* res = nullptr;
  2169. if (inSrc && inBld) {
  2170. // If both have relative path with no dots, pick the shorter one
  2171. if (srcRelpath.size() < bldRelpath.size()) {
  2172. res = &srcRelpath;
  2173. } else {
  2174. res = &bldRelpath;
  2175. }
  2176. } else if (inSrc) {
  2177. res = &srcRelpath;
  2178. } else if (inBld) {
  2179. res = &bldRelpath;
  2180. }
  2181. std::string path;
  2182. if (!res) {
  2183. path = fname;
  2184. } else {
  2185. cmSystemTools::ConvertToUnixSlashes(*res);
  2186. path = "./" + *res;
  2187. if (path[path.size() - 1] == '/') {
  2188. path = path.substr(0, path.size() - 1);
  2189. }
  2190. }
  2191. cmsys::SystemTools::ReplaceString(path, ":", "_");
  2192. cmsys::SystemTools::ReplaceString(path, " ", "_");
  2193. return path;
  2194. }
  2195. std::string cmCTest::GetCTestConfiguration(const std::string& name)
  2196. {
  2197. if (this->CTestConfigurationOverwrites.find(name) !=
  2198. this->CTestConfigurationOverwrites.end()) {
  2199. return this->CTestConfigurationOverwrites[name];
  2200. }
  2201. return this->CTestConfiguration[name];
  2202. }
  2203. void cmCTest::EmptyCTestConfiguration()
  2204. {
  2205. this->CTestConfiguration.clear();
  2206. }
  2207. void cmCTest::DetermineNextDayStop()
  2208. {
  2209. struct tm* lctime;
  2210. time_t current_time = time(nullptr);
  2211. lctime = gmtime(&current_time);
  2212. int gm_hour = lctime->tm_hour;
  2213. time_t gm_time = mktime(lctime);
  2214. lctime = localtime(&current_time);
  2215. int local_hour = lctime->tm_hour;
  2216. int tzone_offset = local_hour - gm_hour;
  2217. if (gm_time > current_time && gm_hour < local_hour) {
  2218. // this means gm_time is on the next day
  2219. tzone_offset -= 24;
  2220. } else if (gm_time < current_time && gm_hour > local_hour) {
  2221. // this means gm_time is on the previous day
  2222. tzone_offset += 24;
  2223. }
  2224. tzone_offset *= 100;
  2225. char buf[1024];
  2226. sprintf(buf, "%d%02d%02d %s %+05i", lctime->tm_year + 1900,
  2227. lctime->tm_mon + 1, lctime->tm_mday, this->StopTime.c_str(),
  2228. tzone_offset);
  2229. time_t stop_time = curl_getdate(buf, &current_time);
  2230. if (stop_time < current_time) {
  2231. this->NextDayStopTime = true;
  2232. }
  2233. }
  2234. void cmCTest::SetCTestConfiguration(const char* name, const char* value,
  2235. bool suppress)
  2236. {
  2237. cmCTestOptionalLog(this, HANDLER_VERBOSE_OUTPUT, "SetCTestConfiguration:"
  2238. << name << ":" << (value ? value : "(null)") << "\n",
  2239. suppress);
  2240. if (!name) {
  2241. return;
  2242. }
  2243. if (!value) {
  2244. this->CTestConfiguration.erase(name);
  2245. return;
  2246. }
  2247. this->CTestConfiguration[name] = value;
  2248. }
  2249. std::string cmCTest::GetCurrentTag()
  2250. {
  2251. return this->CurrentTag;
  2252. }
  2253. std::string cmCTest::GetBinaryDir()
  2254. {
  2255. return this->BinaryDir;
  2256. }
  2257. std::string const& cmCTest::GetConfigType()
  2258. {
  2259. return this->ConfigType;
  2260. }
  2261. bool cmCTest::GetShowOnly()
  2262. {
  2263. return this->ShowOnly;
  2264. }
  2265. int cmCTest::GetMaxTestNameWidth() const
  2266. {
  2267. return this->MaxTestNameWidth;
  2268. }
  2269. void cmCTest::SetProduceXML(bool v)
  2270. {
  2271. this->ProduceXML = v;
  2272. }
  2273. bool cmCTest::GetProduceXML()
  2274. {
  2275. return this->ProduceXML;
  2276. }
  2277. const char* cmCTest::GetSpecificTrack()
  2278. {
  2279. if (this->SpecificTrack.empty()) {
  2280. return nullptr;
  2281. }
  2282. return this->SpecificTrack.c_str();
  2283. }
  2284. void cmCTest::SetSpecificTrack(const char* track)
  2285. {
  2286. if (!track) {
  2287. this->SpecificTrack.clear();
  2288. return;
  2289. }
  2290. this->SpecificTrack = track;
  2291. }
  2292. void cmCTest::AddSubmitFile(Part part, const char* name)
  2293. {
  2294. this->Parts[part].SubmitFiles.push_back(name);
  2295. }
  2296. void cmCTest::AddCTestConfigurationOverwrite(const std::string& overStr)
  2297. {
  2298. size_t epos = overStr.find('=');
  2299. if (epos == std::string::npos) {
  2300. cmCTestLog(this, ERROR_MESSAGE,
  2301. "CTest configuration overwrite specified in the wrong format."
  2302. << std::endl
  2303. << "Valid format is: --overwrite key=value" << std::endl
  2304. << "The specified was: --overwrite " << overStr << std::endl);
  2305. return;
  2306. }
  2307. std::string key = overStr.substr(0, epos);
  2308. std::string value = overStr.substr(epos + 1);
  2309. this->CTestConfigurationOverwrites[key] = value;
  2310. }
  2311. void cmCTest::SetConfigType(const char* ct)
  2312. {
  2313. this->ConfigType = ct ? ct : "";
  2314. cmSystemTools::ReplaceString(this->ConfigType, ".\\", "");
  2315. std::string confTypeEnv = "CMAKE_CONFIG_TYPE=" + this->ConfigType;
  2316. cmSystemTools::PutEnv(confTypeEnv);
  2317. }
  2318. bool cmCTest::SetCTestConfigurationFromCMakeVariable(
  2319. cmMakefile* mf, const char* dconfig, const std::string& cmake_var,
  2320. bool suppress)
  2321. {
  2322. const char* ctvar;
  2323. ctvar = mf->GetDefinition(cmake_var);
  2324. if (!ctvar) {
  2325. return false;
  2326. }
  2327. cmCTestOptionalLog(this, HANDLER_VERBOSE_OUTPUT,
  2328. "SetCTestConfigurationFromCMakeVariable:"
  2329. << dconfig << ":" << cmake_var << std::endl,
  2330. suppress);
  2331. this->SetCTestConfiguration(dconfig, ctvar, suppress);
  2332. return true;
  2333. }
  2334. bool cmCTest::RunCommand(std::vector<std::string> const& args,
  2335. std::string* stdOut, std::string* stdErr, int* retVal,
  2336. const char* dir, double timeout, Encoding encoding)
  2337. {
  2338. std::vector<const char*> argv;
  2339. for (std::string const& a : args) {
  2340. argv.push_back(a.c_str());
  2341. }
  2342. argv.push_back(nullptr);
  2343. stdOut->clear();
  2344. stdErr->clear();
  2345. cmsysProcess* cp = cmsysProcess_New();
  2346. cmsysProcess_SetCommand(cp, &*argv.begin());
  2347. cmsysProcess_SetWorkingDirectory(cp, dir);
  2348. if (cmSystemTools::GetRunCommandHideConsole()) {
  2349. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2350. }
  2351. cmsysProcess_SetTimeout(cp, timeout);
  2352. cmsysProcess_Execute(cp);
  2353. std::vector<char> tempOutput;
  2354. std::vector<char> tempError;
  2355. char* data;
  2356. int length;
  2357. cmProcessOutput processOutput(encoding);
  2358. std::string strdata;
  2359. int res;
  2360. bool done = false;
  2361. while (!done) {
  2362. res = cmsysProcess_WaitForData(cp, &data, &length, nullptr);
  2363. switch (res) {
  2364. case cmsysProcess_Pipe_STDOUT:
  2365. tempOutput.insert(tempOutput.end(), data, data + length);
  2366. break;
  2367. case cmsysProcess_Pipe_STDERR:
  2368. tempError.insert(tempError.end(), data, data + length);
  2369. break;
  2370. default:
  2371. done = true;
  2372. }
  2373. if ((res == cmsysProcess_Pipe_STDOUT || res == cmsysProcess_Pipe_STDERR) &&
  2374. this->ExtraVerbose) {
  2375. processOutput.DecodeText(data, length, strdata);
  2376. cmSystemTools::Stdout(strdata.c_str(), strdata.size());
  2377. }
  2378. }
  2379. if (this->ExtraVerbose) {
  2380. processOutput.DecodeText(std::string(), strdata);
  2381. if (!strdata.empty()) {
  2382. cmSystemTools::Stdout(strdata.c_str(), strdata.size());
  2383. }
  2384. }
  2385. cmsysProcess_WaitForExit(cp, nullptr);
  2386. if (!tempOutput.empty()) {
  2387. processOutput.DecodeText(tempOutput, tempOutput);
  2388. stdOut->append(&*tempOutput.begin(), tempOutput.size());
  2389. }
  2390. if (!tempError.empty()) {
  2391. processOutput.DecodeText(tempError, tempError);
  2392. stdErr->append(&*tempError.begin(), tempError.size());
  2393. }
  2394. bool result = true;
  2395. if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exited) {
  2396. if (retVal) {
  2397. *retVal = cmsysProcess_GetExitValue(cp);
  2398. } else {
  2399. if (cmsysProcess_GetExitValue(cp) != 0) {
  2400. result = false;
  2401. }
  2402. }
  2403. } else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exception) {
  2404. const char* exception_str = cmsysProcess_GetExceptionString(cp);
  2405. cmCTestLog(this, ERROR_MESSAGE, exception_str << std::endl);
  2406. stdErr->append(exception_str, strlen(exception_str));
  2407. result = false;
  2408. } else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Error) {
  2409. const char* error_str = cmsysProcess_GetErrorString(cp);
  2410. cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
  2411. stdErr->append(error_str, strlen(error_str));
  2412. result = false;
  2413. } else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Expired) {
  2414. const char* error_str = "Process terminated due to timeout\n";
  2415. cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
  2416. stdErr->append(error_str, strlen(error_str));
  2417. result = false;
  2418. }
  2419. cmsysProcess_Delete(cp);
  2420. return result;
  2421. }
  2422. void cmCTest::SetOutputLogFileName(const char* name)
  2423. {
  2424. if (this->OutputLogFile) {
  2425. delete this->OutputLogFile;
  2426. this->OutputLogFile = nullptr;
  2427. }
  2428. if (name) {
  2429. this->OutputLogFile = new cmGeneratedFileStream(name);
  2430. }
  2431. }
  2432. static const char* cmCTestStringLogType[] = { "DEBUG",
  2433. "OUTPUT",
  2434. "HANDLER_OUTPUT",
  2435. "HANDLER_PROGRESS_OUTPUT",
  2436. "HANDLER_VERBOSE_OUTPUT",
  2437. "WARNING",
  2438. "ERROR_MESSAGE",
  2439. nullptr };
  2440. #define cmCTestLogOutputFileLine(stream) \
  2441. if (this->ShowLineNumbers) { \
  2442. (stream) << std::endl << file << ":" << line << " "; \
  2443. }
  2444. void cmCTest::InitStreams()
  2445. {
  2446. // By default we write output to the process output streams.
  2447. this->StreamOut = &std::cout;
  2448. this->StreamErr = &std::cerr;
  2449. }
  2450. void cmCTest::Log(int logType, const char* file, int line, const char* msg,
  2451. bool suppress)
  2452. {
  2453. if (!msg || !*msg) {
  2454. return;
  2455. }
  2456. if (suppress && logType != cmCTest::ERROR_MESSAGE) {
  2457. return;
  2458. }
  2459. if (logType == cmCTest::HANDLER_PROGRESS_OUTPUT &&
  2460. (this->Debug || this->ExtraVerbose)) {
  2461. return;
  2462. }
  2463. if (this->OutputLogFile) {
  2464. bool display = true;
  2465. if (logType == cmCTest::DEBUG && !this->Debug) {
  2466. display = false;
  2467. }
  2468. if (logType == cmCTest::HANDLER_VERBOSE_OUTPUT && !this->Debug &&
  2469. !this->ExtraVerbose) {
  2470. display = false;
  2471. }
  2472. if (display) {
  2473. cmCTestLogOutputFileLine(*this->OutputLogFile);
  2474. if (logType != this->OutputLogFileLastTag) {
  2475. *this->OutputLogFile << "[";
  2476. if (logType >= OTHER || logType < 0) {
  2477. *this->OutputLogFile << "OTHER";
  2478. } else {
  2479. *this->OutputLogFile << cmCTestStringLogType[logType];
  2480. }
  2481. *this->OutputLogFile << "] " << std::endl << std::flush;
  2482. }
  2483. *this->OutputLogFile << msg << std::flush;
  2484. if (logType != this->OutputLogFileLastTag) {
  2485. *this->OutputLogFile << std::endl << std::flush;
  2486. this->OutputLogFileLastTag = logType;
  2487. }
  2488. }
  2489. }
  2490. if (!this->Quiet) {
  2491. std::ostream& out = *this->StreamOut;
  2492. std::ostream& err = *this->StreamErr;
  2493. switch (logType) {
  2494. case DEBUG:
  2495. if (this->Debug) {
  2496. cmCTestLogOutputFileLine(out);
  2497. out << msg;
  2498. out.flush();
  2499. }
  2500. break;
  2501. case OUTPUT:
  2502. case HANDLER_OUTPUT:
  2503. if (this->Debug || this->Verbose) {
  2504. cmCTestLogOutputFileLine(out);
  2505. out << msg;
  2506. out.flush();
  2507. }
  2508. break;
  2509. case HANDLER_VERBOSE_OUTPUT:
  2510. if (this->Debug || this->ExtraVerbose) {
  2511. cmCTestLogOutputFileLine(out);
  2512. out << msg;
  2513. out.flush();
  2514. }
  2515. break;
  2516. case WARNING:
  2517. cmCTestLogOutputFileLine(err);
  2518. err << msg;
  2519. err.flush();
  2520. break;
  2521. case ERROR_MESSAGE:
  2522. cmCTestLogOutputFileLine(err);
  2523. err << msg;
  2524. err.flush();
  2525. cmSystemTools::SetErrorOccured();
  2526. break;
  2527. default:
  2528. cmCTestLogOutputFileLine(out);
  2529. out << msg;
  2530. out.flush();
  2531. }
  2532. }
  2533. }
  2534. double cmCTest::GetRemainingTimeAllowed()
  2535. {
  2536. if (!this->GetHandler("script")) {
  2537. return 1.0e7;
  2538. }
  2539. cmCTestScriptHandler* ch =
  2540. static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  2541. return ch->GetRemainingTimeAllowed();
  2542. }
  2543. void cmCTest::OutputTestErrors(std::vector<char> const& process_output)
  2544. {
  2545. std::string test_outputs("\n*** Test Failed:\n");
  2546. if (!process_output.empty()) {
  2547. test_outputs.append(&*process_output.begin(), process_output.size());
  2548. }
  2549. cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl << std::flush);
  2550. }
  2551. bool cmCTest::CompressString(std::string& str)
  2552. {
  2553. int ret;
  2554. z_stream strm;
  2555. strm.zalloc = Z_NULL;
  2556. strm.zfree = Z_NULL;
  2557. strm.opaque = Z_NULL;
  2558. ret = deflateInit(&strm, -1); // default compression level
  2559. if (ret != Z_OK) {
  2560. return false;
  2561. }
  2562. unsigned char* in =
  2563. reinterpret_cast<unsigned char*>(const_cast<char*>(str.c_str()));
  2564. // zlib makes the guarantee that this is the maximum output size
  2565. int outSize =
  2566. static_cast<int>(static_cast<double>(str.size()) * 1.001 + 13.0);
  2567. std::vector<unsigned char> out(outSize);
  2568. strm.avail_in = static_cast<uInt>(str.size());
  2569. strm.next_in = in;
  2570. strm.avail_out = outSize;
  2571. strm.next_out = &out[0];
  2572. ret = deflate(&strm, Z_FINISH);
  2573. if (ret != Z_STREAM_END) {
  2574. cmCTestLog(this, ERROR_MESSAGE, "Error during gzip compression."
  2575. << std::endl);
  2576. return false;
  2577. }
  2578. (void)deflateEnd(&strm);
  2579. // Now base64 encode the resulting binary string
  2580. std::vector<unsigned char> base64EncodedBuffer((outSize * 3) / 2);
  2581. size_t rlen =
  2582. cmsysBase64_Encode(&out[0], strm.total_out, &base64EncodedBuffer[0], 1);
  2583. str.assign(reinterpret_cast<char*>(&base64EncodedBuffer[0]), rlen);
  2584. return true;
  2585. }