cmCTest.cxx 90 KB

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