cmCTest.cxx 91 KB

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