cmCTest.cxx 89 KB

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