cmCTest.cxx 88 KB

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