cmCTest.cxx 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845
  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 <memory> // IWYU pragma: keep
  18. #include <sstream>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <string>
  23. #include <time.h>
  24. #include <utility>
  25. #include <vector>
  26. #include "cmAlgorithms.h"
  27. #include "cmCTestBuildAndTestHandler.h"
  28. #include "cmCTestBuildHandler.h"
  29. #include "cmCTestConfigureHandler.h"
  30. #include "cmCTestCoverageHandler.h"
  31. #include "cmCTestGenericHandler.h"
  32. #include "cmCTestMemCheckHandler.h"
  33. #include "cmCTestScriptHandler.h"
  34. #include "cmCTestStartCommand.h"
  35. #include "cmCTestSubmitHandler.h"
  36. #include "cmCTestTestHandler.h"
  37. #include "cmCTestUpdateHandler.h"
  38. #include "cmCTestUploadHandler.h"
  39. #include "cmCurl.h"
  40. #include "cmDynamicLoader.h"
  41. #include "cmGeneratedFileStream.h"
  42. #include "cmGlobalGenerator.h"
  43. #include "cmMakefile.h"
  44. #include "cmProcessOutput.h"
  45. #include "cmState.h"
  46. #include "cmStateSnapshot.h"
  47. #include "cmStateTypes.h"
  48. #include "cmSystemTools.h"
  49. #include "cmVersion.h"
  50. #include "cmVersionConfig.h"
  51. #include "cmXMLWriter.h"
  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.empty()) {
  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. cmMakefile mf(&gg, cm.GetCurrentSnapshot());
  384. if (!this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), &mf)) {
  385. cmCTestOptionalLog(
  386. this, DEBUG, "Cannot find custom configuration file tree" << std::endl,
  387. quiet);
  388. return 0;
  389. }
  390. if (this->ProduceXML) {
  391. // Verify "Testing" directory exists:
  392. //
  393. std::string testingDir = this->BinaryDir + "/Testing";
  394. if (cmSystemTools::FileExists(testingDir.c_str())) {
  395. if (!cmSystemTools::FileIsDirectory(testingDir)) {
  396. cmCTestLog(this, ERROR_MESSAGE, "File "
  397. << testingDir
  398. << " is in the place of the testing directory"
  399. << std::endl);
  400. return 0;
  401. }
  402. } else {
  403. if (!cmSystemTools::MakeDirectory(testingDir.c_str())) {
  404. cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory "
  405. << testingDir << std::endl);
  406. return 0;
  407. }
  408. }
  409. // Create new "TAG" file or read existing one:
  410. //
  411. bool createNewTag = true;
  412. if (command) {
  413. createNewTag = command->ShouldCreateNewTag();
  414. }
  415. std::string tagfile = testingDir + "/TAG";
  416. cmsys::ifstream tfin(tagfile.c_str());
  417. std::string tag;
  418. if (createNewTag) {
  419. time_t tctime = time(nullptr);
  420. if (this->TomorrowTag) {
  421. tctime += (24 * 60 * 60);
  422. }
  423. struct tm* lctime = gmtime(&tctime);
  424. if (tfin && cmSystemTools::GetLineFromStream(tfin, tag)) {
  425. int year = 0;
  426. int mon = 0;
  427. int day = 0;
  428. int hour = 0;
  429. int min = 0;
  430. sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d", &year, &mon, &day, &hour,
  431. &min);
  432. if (year != lctime->tm_year + 1900 || mon != lctime->tm_mon + 1 ||
  433. day != lctime->tm_mday) {
  434. tag.clear();
  435. }
  436. std::string tagmode;
  437. if (cmSystemTools::GetLineFromStream(tfin, tagmode)) {
  438. if (tagmode.size() > 4 && !this->Parts[PartStart]) {
  439. this->TestModel = cmCTest::GetTestModelFromString(tagmode.c_str());
  440. }
  441. }
  442. tfin.close();
  443. }
  444. if (tag.empty() || (nullptr != command) || this->Parts[PartStart]) {
  445. cmCTestOptionalLog(
  446. this, DEBUG,
  447. "TestModel: " << this->GetTestModelString() << std::endl, quiet);
  448. cmCTestOptionalLog(
  449. this, DEBUG, "TestModel: " << this->TestModel << std::endl, quiet);
  450. if (this->TestModel == cmCTest::NIGHTLY) {
  451. lctime = this->GetNightlyTime(
  452. this->GetCTestConfiguration("NightlyStartTime"),
  453. this->TomorrowTag);
  454. }
  455. char datestring[100];
  456. sprintf(datestring, "%04d%02d%02d-%02d%02d", lctime->tm_year + 1900,
  457. lctime->tm_mon + 1, lctime->tm_mday, lctime->tm_hour,
  458. lctime->tm_min);
  459. tag = datestring;
  460. cmsys::ofstream ofs(tagfile.c_str());
  461. if (ofs) {
  462. ofs << tag << std::endl;
  463. ofs << this->GetTestModelString() << std::endl;
  464. }
  465. ofs.close();
  466. if (nullptr == command) {
  467. cmCTestOptionalLog(this, OUTPUT, "Create new tag: "
  468. << tag << " - " << this->GetTestModelString()
  469. << std::endl,
  470. quiet);
  471. }
  472. }
  473. } else {
  474. if (tfin) {
  475. cmSystemTools::GetLineFromStream(tfin, tag);
  476. tfin.close();
  477. }
  478. if (tag.empty()) {
  479. cmCTestLog(this, ERROR_MESSAGE, "Cannot read existing TAG file in "
  480. << testingDir << std::endl);
  481. return 0;
  482. }
  483. cmCTestOptionalLog(this, OUTPUT, " Use existing tag: "
  484. << tag << " - " << this->GetTestModelString()
  485. << std::endl,
  486. quiet);
  487. }
  488. this->CurrentTag = tag;
  489. }
  490. return 1;
  491. }
  492. bool cmCTest::InitializeFromCommand(cmCTestStartCommand* command)
  493. {
  494. std::string src_dir = this->GetCTestConfiguration("SourceDirectory");
  495. std::string bld_dir = this->GetCTestConfiguration("BuildDirectory");
  496. this->DartVersion = 1;
  497. this->DropSiteCDash = false;
  498. for (Part p = PartStart; p != PartCount; p = Part(p + 1)) {
  499. this->Parts[p].SubmitFiles.clear();
  500. }
  501. cmMakefile* mf = command->GetMakefile();
  502. std::string fname;
  503. std::string src_dir_fname = src_dir;
  504. src_dir_fname += "/CTestConfig.cmake";
  505. cmSystemTools::ConvertToUnixSlashes(src_dir_fname);
  506. std::string bld_dir_fname = bld_dir;
  507. bld_dir_fname += "/CTestConfig.cmake";
  508. cmSystemTools::ConvertToUnixSlashes(bld_dir_fname);
  509. if (cmSystemTools::FileExists(bld_dir_fname.c_str())) {
  510. fname = bld_dir_fname;
  511. } else if (cmSystemTools::FileExists(src_dir_fname.c_str())) {
  512. fname = src_dir_fname;
  513. }
  514. if (!fname.empty()) {
  515. cmCTestOptionalLog(this, OUTPUT, " Reading ctest configuration file: "
  516. << fname << std::endl,
  517. command->ShouldBeQuiet());
  518. bool readit = mf->ReadDependentFile(fname.c_str());
  519. if (!readit) {
  520. std::string m = "Could not find include file: ";
  521. m += fname;
  522. command->SetError(m);
  523. return false;
  524. }
  525. } else {
  526. cmCTestOptionalLog(this, WARNING,
  527. "Cannot locate CTest configuration: in BuildDirectory: "
  528. << bld_dir_fname << std::endl,
  529. command->ShouldBeQuiet());
  530. cmCTestOptionalLog(
  531. this, WARNING, "Cannot locate CTest configuration: in SourceDirectory: "
  532. << src_dir_fname << std::endl,
  533. command->ShouldBeQuiet());
  534. }
  535. this->SetCTestConfigurationFromCMakeVariable(mf, "NightlyStartTime",
  536. "CTEST_NIGHTLY_START_TIME",
  537. command->ShouldBeQuiet());
  538. this->SetCTestConfigurationFromCMakeVariable(mf, "Site", "CTEST_SITE",
  539. command->ShouldBeQuiet());
  540. this->SetCTestConfigurationFromCMakeVariable(
  541. mf, "BuildName", "CTEST_BUILD_NAME", command->ShouldBeQuiet());
  542. const char* dartVersion = mf->GetDefinition("CTEST_DART_SERVER_VERSION");
  543. if (dartVersion) {
  544. this->DartVersion = atoi(dartVersion);
  545. if (this->DartVersion < 0) {
  546. cmCTestLog(this, ERROR_MESSAGE, "Invalid Dart server version: "
  547. << dartVersion << ". Please specify the version number."
  548. << std::endl);
  549. return false;
  550. }
  551. }
  552. this->DropSiteCDash = mf->IsOn("CTEST_DROP_SITE_CDASH");
  553. if (!this->Initialize(bld_dir.c_str(), command)) {
  554. return false;
  555. }
  556. cmCTestOptionalLog(this, OUTPUT, " Use "
  557. << this->GetTestModelString()
  558. << " tag: " << this->GetCurrentTag() << std::endl,
  559. command->ShouldBeQuiet());
  560. return true;
  561. }
  562. bool cmCTest::UpdateCTestConfiguration()
  563. {
  564. if (this->SuppressUpdatingCTestConfiguration) {
  565. return true;
  566. }
  567. std::string fileName = this->CTestConfigFile;
  568. if (fileName.empty()) {
  569. fileName = this->BinaryDir + "/CTestConfiguration.ini";
  570. if (!cmSystemTools::FileExists(fileName.c_str())) {
  571. fileName = this->BinaryDir + "/DartConfiguration.tcl";
  572. }
  573. }
  574. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  575. "UpdateCTestConfiguration from :" << fileName << "\n");
  576. if (!cmSystemTools::FileExists(fileName.c_str())) {
  577. // No need to exit if we are not producing XML
  578. if (this->ProduceXML) {
  579. cmCTestLog(this, ERROR_MESSAGE, "Cannot find file: " << fileName
  580. << std::endl);
  581. return false;
  582. }
  583. } else {
  584. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Parse Config file:" << fileName
  585. << "\n");
  586. // parse the dart test file
  587. cmsys::ifstream fin(fileName.c_str());
  588. if (!fin) {
  589. return false;
  590. }
  591. char buffer[1024];
  592. while (fin) {
  593. buffer[0] = 0;
  594. fin.getline(buffer, 1023);
  595. buffer[1023] = 0;
  596. std::string line = cmCTest::CleanString(buffer);
  597. if (line.empty()) {
  598. continue;
  599. }
  600. while (fin && (line[line.size() - 1] == '\\')) {
  601. line = line.substr(0, line.size() - 1);
  602. buffer[0] = 0;
  603. fin.getline(buffer, 1023);
  604. buffer[1023] = 0;
  605. line += cmCTest::CleanString(buffer);
  606. }
  607. if (line[0] == '#') {
  608. continue;
  609. }
  610. std::string::size_type cpos = line.find_first_of(':');
  611. if (cpos == std::string::npos) {
  612. continue;
  613. }
  614. std::string key = line.substr(0, cpos);
  615. std::string value = cmCTest::CleanString(line.substr(cpos + 1));
  616. this->CTestConfiguration[key] = value;
  617. }
  618. fin.close();
  619. }
  620. if (!this->GetCTestConfiguration("BuildDirectory").empty()) {
  621. this->BinaryDir = this->GetCTestConfiguration("BuildDirectory");
  622. cmSystemTools::ChangeDirectory(this->BinaryDir);
  623. }
  624. this->TimeOut = atoi(this->GetCTestConfiguration("TimeOut").c_str());
  625. std::string const& testLoad = this->GetCTestConfiguration("TestLoad");
  626. if (!testLoad.empty()) {
  627. unsigned long load;
  628. if (cmSystemTools::StringToULong(testLoad.c_str(), &load)) {
  629. this->SetTestLoad(load);
  630. } else {
  631. cmCTestLog(this, WARNING,
  632. "Invalid value for 'Test Load' : " << testLoad << std::endl);
  633. }
  634. }
  635. if (this->ProduceXML) {
  636. this->CompressXMLFiles = cmSystemTools::IsOn(
  637. this->GetCTestConfiguration("CompressSubmission").c_str());
  638. }
  639. return true;
  640. }
  641. void cmCTest::BlockTestErrorDiagnostics()
  642. {
  643. cmSystemTools::PutEnv("DART_TEST_FROM_DART=1");
  644. cmSystemTools::PutEnv("DASHBOARD_TEST_FROM_CTEST=" CMake_VERSION);
  645. #if defined(_WIN32)
  646. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  647. #elif defined(__BEOS__) || defined(__HAIKU__)
  648. disable_debugger(1);
  649. #endif
  650. }
  651. void cmCTest::SetTestModel(int mode)
  652. {
  653. this->InteractiveDebugMode = false;
  654. this->TestModel = mode;
  655. }
  656. bool cmCTest::SetTest(const char* ttype, bool report)
  657. {
  658. if (cmSystemTools::LowerCase(ttype) == "all") {
  659. for (Part p = PartStart; p != PartCount; p = Part(p + 1)) {
  660. this->Parts[p].Enable();
  661. }
  662. return true;
  663. }
  664. Part p = this->GetPartFromName(ttype);
  665. if (p != PartCount) {
  666. this->Parts[p].Enable();
  667. return true;
  668. }
  669. if (report) {
  670. cmCTestLog(this, ERROR_MESSAGE, "Don't know about test \""
  671. << ttype << "\" yet..." << std::endl);
  672. }
  673. return false;
  674. }
  675. void cmCTest::Finalize()
  676. {
  677. }
  678. bool cmCTest::OpenOutputFile(const std::string& path, const std::string& name,
  679. cmGeneratedFileStream& stream, bool compress)
  680. {
  681. std::string testingDir = this->BinaryDir + "/Testing";
  682. if (!path.empty()) {
  683. testingDir += "/" + path;
  684. }
  685. if (cmSystemTools::FileExists(testingDir.c_str())) {
  686. if (!cmSystemTools::FileIsDirectory(testingDir)) {
  687. cmCTestLog(this, ERROR_MESSAGE, "File "
  688. << testingDir << " is in the place of the testing directory"
  689. << std::endl);
  690. return false;
  691. }
  692. } else {
  693. if (!cmSystemTools::MakeDirectory(testingDir.c_str())) {
  694. cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory " << testingDir
  695. << std::endl);
  696. return false;
  697. }
  698. }
  699. std::string filename = testingDir + "/" + name;
  700. stream.Open(filename.c_str());
  701. if (!stream) {
  702. cmCTestLog(this, ERROR_MESSAGE, "Problem opening file: " << filename
  703. << std::endl);
  704. return false;
  705. }
  706. if (compress) {
  707. if (this->CompressXMLFiles) {
  708. stream.SetCompression(true);
  709. }
  710. }
  711. return true;
  712. }
  713. bool cmCTest::AddIfExists(Part part, const char* file)
  714. {
  715. if (this->CTestFileExists(file)) {
  716. this->AddSubmitFile(part, file);
  717. } else {
  718. std::string name = file;
  719. name += ".gz";
  720. if (this->CTestFileExists(name)) {
  721. this->AddSubmitFile(part, file);
  722. } else {
  723. return false;
  724. }
  725. }
  726. return true;
  727. }
  728. bool cmCTest::CTestFileExists(const std::string& filename)
  729. {
  730. std::string testingDir =
  731. this->BinaryDir + "/Testing/" + this->CurrentTag + "/" + filename;
  732. return cmSystemTools::FileExists(testingDir.c_str());
  733. }
  734. cmCTestGenericHandler* cmCTest::GetInitializedHandler(const char* handler)
  735. {
  736. cmCTest::t_TestingHandlers::iterator it =
  737. this->TestingHandlers.find(handler);
  738. if (it == this->TestingHandlers.end()) {
  739. return nullptr;
  740. }
  741. it->second->Initialize();
  742. return it->second;
  743. }
  744. cmCTestGenericHandler* cmCTest::GetHandler(const char* handler)
  745. {
  746. cmCTest::t_TestingHandlers::iterator it =
  747. this->TestingHandlers.find(handler);
  748. if (it == this->TestingHandlers.end()) {
  749. return nullptr;
  750. }
  751. return it->second;
  752. }
  753. int cmCTest::ExecuteHandler(const char* shandler)
  754. {
  755. cmCTestGenericHandler* handler = this->GetHandler(shandler);
  756. if (!handler) {
  757. return -1;
  758. }
  759. handler->Initialize();
  760. return handler->ProcessHandler();
  761. }
  762. int cmCTest::ProcessSteps()
  763. {
  764. int res = 0;
  765. bool notest = true;
  766. int update_count = 0;
  767. for (Part p = PartStart; notest && p != PartCount; p = Part(p + 1)) {
  768. notest = !this->Parts[p];
  769. }
  770. if (this->Parts[PartUpdate] && (this->GetRemainingTimeAllowed() - 120 > 0)) {
  771. cmCTestGenericHandler* uphandler = this->GetHandler("update");
  772. uphandler->SetPersistentOption(
  773. "SourceDirectory",
  774. this->GetCTestConfiguration("SourceDirectory").c_str());
  775. update_count = uphandler->ProcessHandler();
  776. if (update_count < 0) {
  777. res |= cmCTest::UPDATE_ERRORS;
  778. }
  779. }
  780. if (this->TestModel == cmCTest::CONTINUOUS && !update_count) {
  781. return 0;
  782. }
  783. if (this->Parts[PartConfigure] &&
  784. (this->GetRemainingTimeAllowed() - 120 > 0)) {
  785. if (this->GetHandler("configure")->ProcessHandler() < 0) {
  786. res |= cmCTest::CONFIGURE_ERRORS;
  787. }
  788. }
  789. if (this->Parts[PartBuild] && (this->GetRemainingTimeAllowed() - 120 > 0)) {
  790. this->UpdateCTestConfiguration();
  791. if (this->GetHandler("build")->ProcessHandler() < 0) {
  792. res |= cmCTest::BUILD_ERRORS;
  793. }
  794. }
  795. if ((this->Parts[PartTest] || notest) &&
  796. (this->GetRemainingTimeAllowed() - 120 > 0)) {
  797. this->UpdateCTestConfiguration();
  798. if (this->GetHandler("test")->ProcessHandler() < 0) {
  799. res |= cmCTest::TEST_ERRORS;
  800. }
  801. }
  802. if (this->Parts[PartCoverage] &&
  803. (this->GetRemainingTimeAllowed() - 120 > 0)) {
  804. this->UpdateCTestConfiguration();
  805. if (this->GetHandler("coverage")->ProcessHandler() < 0) {
  806. res |= cmCTest::COVERAGE_ERRORS;
  807. }
  808. }
  809. if (this->Parts[PartMemCheck] &&
  810. (this->GetRemainingTimeAllowed() - 120 > 0)) {
  811. this->UpdateCTestConfiguration();
  812. if (this->GetHandler("memcheck")->ProcessHandler() < 0) {
  813. res |= cmCTest::MEMORY_ERRORS;
  814. }
  815. }
  816. if (!notest) {
  817. std::string notes_dir = this->BinaryDir + "/Testing/Notes";
  818. if (cmSystemTools::FileIsDirectory(notes_dir)) {
  819. cmsys::Directory d;
  820. d.Load(notes_dir);
  821. unsigned long kk;
  822. for (kk = 0; kk < d.GetNumberOfFiles(); kk++) {
  823. const char* file = d.GetFile(kk);
  824. std::string fullname = notes_dir + "/" + file;
  825. if (cmSystemTools::FileExists(fullname.c_str()) &&
  826. !cmSystemTools::FileIsDirectory(fullname)) {
  827. if (!this->NotesFiles.empty()) {
  828. this->NotesFiles += ";";
  829. }
  830. this->NotesFiles += fullname;
  831. this->Parts[PartNotes].Enable();
  832. }
  833. }
  834. }
  835. }
  836. if (this->Parts[PartNotes]) {
  837. this->UpdateCTestConfiguration();
  838. if (!this->NotesFiles.empty()) {
  839. this->GenerateNotesFile(this->NotesFiles.c_str());
  840. }
  841. }
  842. if (this->Parts[PartSubmit]) {
  843. this->UpdateCTestConfiguration();
  844. if (this->GetHandler("submit")->ProcessHandler() < 0) {
  845. res |= cmCTest::SUBMIT_ERRORS;
  846. }
  847. }
  848. if (res != 0) {
  849. cmCTestLog(this, ERROR_MESSAGE, "Errors while running CTest" << std::endl);
  850. }
  851. return res;
  852. }
  853. std::string cmCTest::GetTestModelString()
  854. {
  855. if (!this->SpecificTrack.empty()) {
  856. return this->SpecificTrack;
  857. }
  858. switch (this->TestModel) {
  859. case cmCTest::NIGHTLY:
  860. return "Nightly";
  861. case cmCTest::CONTINUOUS:
  862. return "Continuous";
  863. }
  864. return "Experimental";
  865. }
  866. int cmCTest::GetTestModelFromString(const char* str)
  867. {
  868. if (!str) {
  869. return cmCTest::EXPERIMENTAL;
  870. }
  871. std::string rstr = cmSystemTools::LowerCase(str);
  872. if (cmHasLiteralPrefix(rstr.c_str(), "cont")) {
  873. return cmCTest::CONTINUOUS;
  874. }
  875. if (cmHasLiteralPrefix(rstr.c_str(), "nigh")) {
  876. return cmCTest::NIGHTLY;
  877. }
  878. return cmCTest::EXPERIMENTAL;
  879. }
  880. //######################################################################
  881. //######################################################################
  882. //######################################################################
  883. //######################################################################
  884. int cmCTest::RunMakeCommand(const char* command, std::string& output,
  885. int* retVal, const char* dir, int timeout,
  886. std::ostream& ofs, Encoding encoding)
  887. {
  888. // First generate the command and arguments
  889. std::vector<std::string> args = cmSystemTools::ParseArguments(command);
  890. if (args.empty()) {
  891. return false;
  892. }
  893. std::vector<const char*> argv;
  894. argv.reserve(args.size() + 1);
  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. std::unique_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv;
  1033. if (modifyEnv) {
  1034. saveEnv = cm::make_unique<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. std::unique_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv;
  1057. if (modifyEnv) {
  1058. saveEnv = cm::make_unique<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.empty()) {
  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.empty()) {
  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. argv.reserve(args.size() + 1);
  2340. for (std::string const& a : args) {
  2341. argv.push_back(a.c_str());
  2342. }
  2343. argv.push_back(nullptr);
  2344. stdOut->clear();
  2345. stdErr->clear();
  2346. cmsysProcess* cp = cmsysProcess_New();
  2347. cmsysProcess_SetCommand(cp, &*argv.begin());
  2348. cmsysProcess_SetWorkingDirectory(cp, dir);
  2349. if (cmSystemTools::GetRunCommandHideConsole()) {
  2350. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2351. }
  2352. cmsysProcess_SetTimeout(cp, timeout);
  2353. cmsysProcess_Execute(cp);
  2354. std::vector<char> tempOutput;
  2355. std::vector<char> tempError;
  2356. char* data;
  2357. int length;
  2358. cmProcessOutput processOutput(encoding);
  2359. std::string strdata;
  2360. int res;
  2361. bool done = false;
  2362. while (!done) {
  2363. res = cmsysProcess_WaitForData(cp, &data, &length, nullptr);
  2364. switch (res) {
  2365. case cmsysProcess_Pipe_STDOUT:
  2366. tempOutput.insert(tempOutput.end(), data, data + length);
  2367. break;
  2368. case cmsysProcess_Pipe_STDERR:
  2369. tempError.insert(tempError.end(), data, data + length);
  2370. break;
  2371. default:
  2372. done = true;
  2373. }
  2374. if ((res == cmsysProcess_Pipe_STDOUT || res == cmsysProcess_Pipe_STDERR) &&
  2375. this->ExtraVerbose) {
  2376. processOutput.DecodeText(data, length, strdata);
  2377. cmSystemTools::Stdout(strdata.c_str(), strdata.size());
  2378. }
  2379. }
  2380. if (this->ExtraVerbose) {
  2381. processOutput.DecodeText(std::string(), strdata);
  2382. if (!strdata.empty()) {
  2383. cmSystemTools::Stdout(strdata.c_str(), strdata.size());
  2384. }
  2385. }
  2386. cmsysProcess_WaitForExit(cp, nullptr);
  2387. if (!tempOutput.empty()) {
  2388. processOutput.DecodeText(tempOutput, tempOutput);
  2389. stdOut->append(&*tempOutput.begin(), tempOutput.size());
  2390. }
  2391. if (!tempError.empty()) {
  2392. processOutput.DecodeText(tempError, tempError);
  2393. stdErr->append(&*tempError.begin(), tempError.size());
  2394. }
  2395. bool result = true;
  2396. if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exited) {
  2397. if (retVal) {
  2398. *retVal = cmsysProcess_GetExitValue(cp);
  2399. } else {
  2400. if (cmsysProcess_GetExitValue(cp) != 0) {
  2401. result = false;
  2402. }
  2403. }
  2404. } else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exception) {
  2405. const char* exception_str = cmsysProcess_GetExceptionString(cp);
  2406. cmCTestLog(this, ERROR_MESSAGE, exception_str << std::endl);
  2407. stdErr->append(exception_str, strlen(exception_str));
  2408. result = false;
  2409. } else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Error) {
  2410. const char* error_str = cmsysProcess_GetErrorString(cp);
  2411. cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
  2412. stdErr->append(error_str, strlen(error_str));
  2413. result = false;
  2414. } else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Expired) {
  2415. const char* error_str = "Process terminated due to timeout\n";
  2416. cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
  2417. stdErr->append(error_str, strlen(error_str));
  2418. result = false;
  2419. }
  2420. cmsysProcess_Delete(cp);
  2421. return result;
  2422. }
  2423. void cmCTest::SetOutputLogFileName(const char* name)
  2424. {
  2425. if (this->OutputLogFile) {
  2426. delete this->OutputLogFile;
  2427. this->OutputLogFile = nullptr;
  2428. }
  2429. if (name) {
  2430. this->OutputLogFile = new cmGeneratedFileStream(name);
  2431. }
  2432. }
  2433. static const char* cmCTestStringLogType[] = { "DEBUG",
  2434. "OUTPUT",
  2435. "HANDLER_OUTPUT",
  2436. "HANDLER_PROGRESS_OUTPUT",
  2437. "HANDLER_VERBOSE_OUTPUT",
  2438. "WARNING",
  2439. "ERROR_MESSAGE",
  2440. nullptr };
  2441. #define cmCTestLogOutputFileLine(stream) \
  2442. if (this->ShowLineNumbers) { \
  2443. (stream) << std::endl << file << ":" << line << " "; \
  2444. }
  2445. void cmCTest::InitStreams()
  2446. {
  2447. // By default we write output to the process output streams.
  2448. this->StreamOut = &std::cout;
  2449. this->StreamErr = &std::cerr;
  2450. }
  2451. void cmCTest::Log(int logType, const char* file, int line, const char* msg,
  2452. bool suppress)
  2453. {
  2454. if (!msg || !*msg) {
  2455. return;
  2456. }
  2457. if (suppress && logType != cmCTest::ERROR_MESSAGE) {
  2458. return;
  2459. }
  2460. if (logType == cmCTest::HANDLER_PROGRESS_OUTPUT &&
  2461. (this->Debug || this->ExtraVerbose)) {
  2462. return;
  2463. }
  2464. if (this->OutputLogFile) {
  2465. bool display = true;
  2466. if (logType == cmCTest::DEBUG && !this->Debug) {
  2467. display = false;
  2468. }
  2469. if (logType == cmCTest::HANDLER_VERBOSE_OUTPUT && !this->Debug &&
  2470. !this->ExtraVerbose) {
  2471. display = false;
  2472. }
  2473. if (display) {
  2474. cmCTestLogOutputFileLine(*this->OutputLogFile);
  2475. if (logType != this->OutputLogFileLastTag) {
  2476. *this->OutputLogFile << "[";
  2477. if (logType >= OTHER || logType < 0) {
  2478. *this->OutputLogFile << "OTHER";
  2479. } else {
  2480. *this->OutputLogFile << cmCTestStringLogType[logType];
  2481. }
  2482. *this->OutputLogFile << "] " << std::endl << std::flush;
  2483. }
  2484. *this->OutputLogFile << msg << std::flush;
  2485. if (logType != this->OutputLogFileLastTag) {
  2486. *this->OutputLogFile << std::endl << std::flush;
  2487. this->OutputLogFileLastTag = logType;
  2488. }
  2489. }
  2490. }
  2491. if (!this->Quiet) {
  2492. std::ostream& out = *this->StreamOut;
  2493. std::ostream& err = *this->StreamErr;
  2494. switch (logType) {
  2495. case DEBUG:
  2496. if (this->Debug) {
  2497. cmCTestLogOutputFileLine(out);
  2498. out << msg;
  2499. out.flush();
  2500. }
  2501. break;
  2502. case OUTPUT:
  2503. case HANDLER_OUTPUT:
  2504. if (this->Debug || this->Verbose) {
  2505. cmCTestLogOutputFileLine(out);
  2506. out << msg;
  2507. out.flush();
  2508. }
  2509. break;
  2510. case HANDLER_VERBOSE_OUTPUT:
  2511. if (this->Debug || this->ExtraVerbose) {
  2512. cmCTestLogOutputFileLine(out);
  2513. out << msg;
  2514. out.flush();
  2515. }
  2516. break;
  2517. case WARNING:
  2518. cmCTestLogOutputFileLine(err);
  2519. err << msg;
  2520. err.flush();
  2521. break;
  2522. case ERROR_MESSAGE:
  2523. cmCTestLogOutputFileLine(err);
  2524. err << msg;
  2525. err.flush();
  2526. cmSystemTools::SetErrorOccured();
  2527. break;
  2528. default:
  2529. cmCTestLogOutputFileLine(out);
  2530. out << msg;
  2531. out.flush();
  2532. }
  2533. }
  2534. }
  2535. double cmCTest::GetRemainingTimeAllowed()
  2536. {
  2537. if (!this->GetHandler("script")) {
  2538. return 1.0e7;
  2539. }
  2540. cmCTestScriptHandler* ch =
  2541. static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  2542. return ch->GetRemainingTimeAllowed();
  2543. }
  2544. void cmCTest::OutputTestErrors(std::vector<char> const& process_output)
  2545. {
  2546. std::string test_outputs("\n*** Test Failed:\n");
  2547. if (!process_output.empty()) {
  2548. test_outputs.append(&*process_output.begin(), process_output.size());
  2549. }
  2550. cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl << std::flush);
  2551. }
  2552. bool cmCTest::CompressString(std::string& str)
  2553. {
  2554. int ret;
  2555. z_stream strm;
  2556. strm.zalloc = Z_NULL;
  2557. strm.zfree = Z_NULL;
  2558. strm.opaque = Z_NULL;
  2559. ret = deflateInit(&strm, -1); // default compression level
  2560. if (ret != Z_OK) {
  2561. return false;
  2562. }
  2563. unsigned char* in =
  2564. reinterpret_cast<unsigned char*>(const_cast<char*>(str.c_str()));
  2565. // zlib makes the guarantee that this is the maximum output size
  2566. int outSize =
  2567. static_cast<int>(static_cast<double>(str.size()) * 1.001 + 13.0);
  2568. std::vector<unsigned char> out(outSize);
  2569. strm.avail_in = static_cast<uInt>(str.size());
  2570. strm.next_in = in;
  2571. strm.avail_out = outSize;
  2572. strm.next_out = &out[0];
  2573. ret = deflate(&strm, Z_FINISH);
  2574. if (ret != Z_STREAM_END) {
  2575. cmCTestLog(this, ERROR_MESSAGE, "Error during gzip compression."
  2576. << std::endl);
  2577. return false;
  2578. }
  2579. (void)deflateEnd(&strm);
  2580. // Now base64 encode the resulting binary string
  2581. std::vector<unsigned char> base64EncodedBuffer((outSize * 3) / 2);
  2582. size_t rlen =
  2583. cmsysBase64_Encode(&out[0], strm.total_out, &base64EncodedBuffer[0], 1);
  2584. str.assign(reinterpret_cast<char*>(&base64EncodedBuffer[0]), rlen);
  2585. return true;
  2586. }