cmCTest.cxx 89 KB

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