cmCTest.cxx 92 KB

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