cmCTest.cxx 88 KB

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