cmCTest.cxx 89 KB

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