cmCTest.cxx 90 KB

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