cmCTest.cxx 88 KB

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