cmCTest.cxx 94 KB

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