cmCTest.cxx 90 KB

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