cmCTest.cxx 89 KB

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