cmCTest.cxx 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cm_curl.h"
  14. #include "cmCTest.h"
  15. #include "cmake.h"
  16. #include "cmMakefile.h"
  17. #include "cmLocalGenerator.h"
  18. #include "cmGlobalGenerator.h"
  19. #include <cmsys/Directory.hxx>
  20. #include "cmDynamicLoader.h"
  21. #include "cmGeneratedFileStream.h"
  22. #include "cmCTestCommand.h"
  23. #include "cmCTestBuildHandler.h"
  24. #include "cmCTestBuildAndTestHandler.h"
  25. #include "cmCTestConfigureHandler.h"
  26. #include "cmCTestCoverageHandler.h"
  27. #include "cmCTestMemCheckHandler.h"
  28. #include "cmCTestScriptHandler.h"
  29. #include "cmCTestTestHandler.h"
  30. #include "cmCTestUpdateHandler.h"
  31. #include "cmCTestSubmitHandler.h"
  32. #include "cmVersion.h"
  33. #include <cmsys/RegularExpression.hxx>
  34. #include <cmsys/Process.h>
  35. #include <cmsys/Glob.hxx>
  36. #include <stdlib.h>
  37. #include <math.h>
  38. #include <float.h>
  39. #include <memory> // auto_ptr
  40. #if defined(__BEOS__)
  41. #include <be/kernel/OS.h> /* disable_debugger() API. */
  42. #endif
  43. #define DEBUGOUT std::cout << __LINE__ << " "; std::cout
  44. #define DEBUGERR std::cerr << __LINE__ << " "; std::cerr
  45. //----------------------------------------------------------------------
  46. struct tm* cmCTest::GetNightlyTime(std::string str,
  47. bool tomorrowtag)
  48. {
  49. struct tm* lctime;
  50. time_t tctime = time(0);
  51. lctime = gmtime(&tctime);
  52. char buf[1024];
  53. // add todays year day and month to the time in str because
  54. // curl_getdate no longer assumes the day is today
  55. sprintf(buf, "%d%02d%02d %s", lctime->tm_year+1900, lctime->tm_mday,
  56. lctime->tm_mon, str.c_str());
  57. cmCTestLog(this, OUTPUT, "Determine Nightly Start Time" << std::endl
  58. << " Specified time: " << str.c_str() << std::endl);
  59. //Convert the nightly start time to seconds. Since we are
  60. //providing only a time and a timezone, the current date of
  61. //the local machine is assumed. Consequently, nightlySeconds
  62. //is the time at which the nightly dashboard was opened or
  63. //will be opened on the date of the current client machine.
  64. //As such, this time may be in the past or in the future.
  65. time_t ntime = curl_getdate(buf, &tctime);
  66. cmCTestLog(this, DEBUG, " Get curl time: " << ntime << std::endl);
  67. tctime = time(0);
  68. cmCTestLog(this, DEBUG, " Get the current time: " << tctime << std::endl);
  69. const int dayLength = 24 * 60 * 60;
  70. cmCTestLog(this, DEBUG, "Seconds: " << tctime << std::endl);
  71. while ( ntime > tctime )
  72. {
  73. // If nightlySeconds is in the past, this is the current
  74. // open dashboard, then return nightlySeconds. If
  75. // nightlySeconds is in the future, this is the next
  76. // dashboard to be opened, so subtract 24 hours to get the
  77. // time of the current open dashboard
  78. ntime -= dayLength;
  79. cmCTestLog(this, DEBUG, "Pick yesterday" << std::endl);
  80. cmCTestLog(this, DEBUG, " Future time, subtract day: " << ntime
  81. << std::endl);
  82. }
  83. while ( tctime > (ntime + dayLength) )
  84. {
  85. ntime += dayLength;
  86. cmCTestLog(this, DEBUG, " Past time, add day: " << ntime << std::endl);
  87. }
  88. cmCTestLog(this, DEBUG, "nightlySeconds: " << ntime << std::endl);
  89. cmCTestLog(this, DEBUG, " Current time: " << tctime
  90. << " Nightly time: " << ntime << std::endl);
  91. if ( tomorrowtag )
  92. {
  93. cmCTestLog(this, OUTPUT, " Use future tag, Add a day" << std::endl);
  94. ntime += dayLength;
  95. }
  96. lctime = gmtime(&ntime);
  97. return lctime;
  98. }
  99. //----------------------------------------------------------------------
  100. std::string cmCTest::CleanString(const std::string& str)
  101. {
  102. std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
  103. std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
  104. if ( spos == str.npos )
  105. {
  106. return std::string();
  107. }
  108. if ( epos != str.npos )
  109. {
  110. epos = epos - spos + 1;
  111. }
  112. return str.substr(spos, epos);
  113. }
  114. //----------------------------------------------------------------------
  115. std::string cmCTest::CurrentTime()
  116. {
  117. time_t currenttime = time(0);
  118. struct tm* t = localtime(&currenttime);
  119. //return ::CleanString(ctime(&currenttime));
  120. char current_time[1024];
  121. if ( this->ShortDateFormat )
  122. {
  123. strftime(current_time, 1000, "%b %d %H:%M %Z", t);
  124. }
  125. else
  126. {
  127. strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
  128. }
  129. cmCTestLog(this, DEBUG, " Current_Time: " << current_time << std::endl);
  130. return cmCTest::MakeXMLSafe(cmCTest::CleanString(current_time));
  131. }
  132. //----------------------------------------------------------------------
  133. std::string cmCTest::MakeXMLSafe(const std::string& str)
  134. {
  135. std::vector<char> result;
  136. result.reserve(500);
  137. const char* pos = str.c_str();
  138. for ( ;*pos; ++pos)
  139. {
  140. char ch = *pos;
  141. if ( (ch > 126 || ch < 32) && ch != 9 &&
  142. ch != 10 && ch != 13 && ch != '\r' )
  143. {
  144. char buffer[33];
  145. sprintf(buffer, "&lt;%d&gt;", (int)ch);
  146. //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
  147. result.insert(result.end(), buffer, buffer+strlen(buffer));
  148. }
  149. else
  150. {
  151. const char* const encodedChars[] = {
  152. "&amp;",
  153. "&lt;",
  154. "&gt;"
  155. };
  156. switch ( ch )
  157. {
  158. case '&':
  159. result.insert(result.end(), encodedChars[0], encodedChars[0]+5);
  160. break;
  161. case '<':
  162. result.insert(result.end(), encodedChars[1], encodedChars[1]+4);
  163. break;
  164. case '>':
  165. result.insert(result.end(), encodedChars[2], encodedChars[2]+4);
  166. break;
  167. case '\n':
  168. result.push_back('\n');
  169. break;
  170. case '\r': break; // Ignore \r
  171. default:
  172. result.push_back(ch);
  173. }
  174. }
  175. }
  176. if ( result.size() == 0 )
  177. {
  178. return "";
  179. }
  180. return std::string(&*result.begin(), result.size());
  181. }
  182. //----------------------------------------------------------------------
  183. std::string cmCTest::MakeURLSafe(const std::string& str)
  184. {
  185. cmOStringStream ost;
  186. char buffer[10];
  187. for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
  188. {
  189. unsigned char ch = str[pos];
  190. if ( ( ch > 126 || ch < 32 ||
  191. ch == '&' ||
  192. ch == '%' ||
  193. ch == '+' ||
  194. ch == '=' ||
  195. ch == '@'
  196. ) && ch != 9 )
  197. {
  198. sprintf(buffer, "%02x;", (unsigned int)ch);
  199. ost << buffer;
  200. }
  201. else
  202. {
  203. ost << ch;
  204. }
  205. }
  206. return ost.str();
  207. }
  208. //----------------------------------------------------------------------
  209. cmCTest::cmCTest()
  210. {
  211. this->SubmitIndex = 0;
  212. this->ForceNewCTestProcess = false;
  213. this->TomorrowTag = false;
  214. this->Verbose = false;
  215. this->Debug = false;
  216. this->ShowLineNumbers = false;
  217. this->Quiet = false;
  218. this->ExtraVerbose = false;
  219. this->ProduceXML = false;
  220. this->ShowOnly = false;
  221. this->RunConfigurationScript = false;
  222. this->TestModel = cmCTest::EXPERIMENTAL;
  223. this->InteractiveDebugMode = true;
  224. this->TimeOut = 0;
  225. this->CompressXMLFiles = false;
  226. this->CTestConfigFile = "";
  227. this->OutputLogFile = 0;
  228. this->OutputLogFileLastTag = -1;
  229. this->SuppressUpdatingCTestConfiguration = false;
  230. this->DartVersion = 1;
  231. int cc;
  232. for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
  233. {
  234. this->Tests[cc] = 0;
  235. }
  236. this->ShortDateFormat = true;
  237. this->TestingHandlers["build"] = new cmCTestBuildHandler;
  238. this->TestingHandlers["buildtest"] = new cmCTestBuildAndTestHandler;
  239. this->TestingHandlers["coverage"] = new cmCTestCoverageHandler;
  240. this->TestingHandlers["script"] = new cmCTestScriptHandler;
  241. this->TestingHandlers["test"] = new cmCTestTestHandler;
  242. this->TestingHandlers["update"] = new cmCTestUpdateHandler;
  243. this->TestingHandlers["configure"] = new cmCTestConfigureHandler;
  244. this->TestingHandlers["memcheck"] = new cmCTestMemCheckHandler;
  245. this->TestingHandlers["submit"] = new cmCTestSubmitHandler;
  246. cmCTest::t_TestingHandlers::iterator it;
  247. for ( it = this->TestingHandlers.begin();
  248. it != this->TestingHandlers.end(); ++ it )
  249. {
  250. it->second->SetCTestInstance(this);
  251. }
  252. // Make sure we can capture the build tool output.
  253. cmSystemTools::EnableVSConsoleOutput();
  254. }
  255. //----------------------------------------------------------------------
  256. cmCTest::~cmCTest()
  257. {
  258. cmCTest::t_TestingHandlers::iterator it;
  259. for ( it = this->TestingHandlers.begin();
  260. it != this->TestingHandlers.end(); ++ it )
  261. {
  262. delete it->second;
  263. it->second = 0;
  264. }
  265. this->SetOutputLogFileName(0);
  266. }
  267. //----------------------------------------------------------------------
  268. int cmCTest::Initialize(const char* binary_dir, bool new_tag,
  269. bool verbose_tag)
  270. {
  271. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  272. if(!this->InteractiveDebugMode)
  273. {
  274. this->BlockTestErrorDiagnostics();
  275. }
  276. else
  277. {
  278. cmSystemTools::PutEnv("CTEST_INTERACTIVE_DEBUG_MODE=1");
  279. }
  280. this->BinaryDir = binary_dir;
  281. cmSystemTools::ConvertToUnixSlashes(this->BinaryDir);
  282. this->UpdateCTestConfiguration();
  283. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  284. if ( this->ProduceXML )
  285. {
  286. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  287. cmCTestLog(this, OUTPUT,
  288. " Site: " << this->GetCTestConfiguration("Site") << std::endl
  289. << " Build name: " << this->GetCTestConfiguration("BuildName")
  290. << std::endl);
  291. cmCTestLog(this, DEBUG, "Produce XML is on" << std::endl);
  292. if ( this->GetCTestConfiguration("NightlyStartTime").empty() )
  293. {
  294. cmCTestLog(this, DEBUG, "No nightly start time" << std::endl);
  295. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  296. return 0;
  297. }
  298. }
  299. cmake cm;
  300. cmGlobalGenerator gg;
  301. gg.SetCMakeInstance(&cm);
  302. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  303. lg->SetGlobalGenerator(&gg);
  304. cmMakefile *mf = lg->GetMakefile();
  305. if ( !this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), mf) )
  306. {
  307. cmCTestLog(this, DEBUG, "Cannot find custom configuration file tree"
  308. << std::endl);
  309. return 0;
  310. }
  311. if ( this->ProduceXML )
  312. {
  313. std::string testingDir = this->BinaryDir + "/Testing";
  314. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  315. {
  316. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  317. {
  318. cmCTestLog(this, ERROR_MESSAGE, "File " << testingDir
  319. << " is in the place of the testing directory" << std::endl);
  320. return 0;
  321. }
  322. }
  323. else
  324. {
  325. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  326. {
  327. cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory "
  328. << testingDir << std::endl);
  329. return 0;
  330. }
  331. }
  332. std::string tagfile = testingDir + "/TAG";
  333. std::ifstream tfin(tagfile.c_str());
  334. std::string tag;
  335. time_t tctime = time(0);
  336. if ( this->TomorrowTag )
  337. {
  338. tctime += ( 24 * 60 * 60 );
  339. }
  340. struct tm *lctime = gmtime(&tctime);
  341. if ( tfin && cmSystemTools::GetLineFromStream(tfin, tag) )
  342. {
  343. int year = 0;
  344. int mon = 0;
  345. int day = 0;
  346. int hour = 0;
  347. int min = 0;
  348. sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
  349. &year, &mon, &day, &hour, &min);
  350. if ( year != lctime->tm_year + 1900 ||
  351. mon != lctime->tm_mon+1 ||
  352. day != lctime->tm_mday )
  353. {
  354. tag = "";
  355. }
  356. std::string tagmode;
  357. if ( cmSystemTools::GetLineFromStream(tfin, tagmode) )
  358. {
  359. if ( tagmode.size() > 4 && !( this->Tests[cmCTest::START_TEST] ||
  360. this->Tests[ALL_TEST] ))
  361. {
  362. this->TestModel = cmCTest::GetTestModelFromString(tagmode.c_str());
  363. }
  364. }
  365. tfin.close();
  366. }
  367. if ( tag.size() == 0 || new_tag || this->Tests[cmCTest::START_TEST] ||
  368. this->Tests[ALL_TEST])
  369. {
  370. cmCTestLog(this, DEBUG, "TestModel: " << this->GetTestModelString()
  371. << std::endl);
  372. cmCTestLog(this, DEBUG, "TestModel: " << this->TestModel << std::endl);
  373. if ( this->TestModel == cmCTest::NIGHTLY )
  374. {
  375. lctime = this->GetNightlyTime(
  376. this->GetCTestConfiguration("NightlyStartTime"), this->TomorrowTag);
  377. }
  378. char datestring[100];
  379. sprintf(datestring, "%04d%02d%02d-%02d%02d",
  380. lctime->tm_year + 1900,
  381. lctime->tm_mon+1,
  382. lctime->tm_mday,
  383. lctime->tm_hour,
  384. lctime->tm_min);
  385. tag = datestring;
  386. std::ofstream ofs(tagfile.c_str());
  387. if ( ofs )
  388. {
  389. ofs << tag << std::endl;
  390. ofs << this->GetTestModelString() << std::endl;
  391. }
  392. ofs.close();
  393. if ( verbose_tag )
  394. {
  395. cmCTestLog(this, OUTPUT, "Create new tag: " << tag << " - "
  396. << this->GetTestModelString() << std::endl);
  397. }
  398. }
  399. this->CurrentTag = tag;
  400. }
  401. return 1;
  402. }
  403. //----------------------------------------------------------------------
  404. bool cmCTest::InitializeFromCommand(cmCTestCommand* command, bool first)
  405. {
  406. if ( !first && !this->CurrentTag.empty() )
  407. {
  408. return true;
  409. }
  410. std::string src_dir
  411. = this->GetCTestConfiguration("SourceDirectory").c_str();
  412. std::string bld_dir = this->GetCTestConfiguration("BuildDirectory").c_str();
  413. this->DartVersion = 1;
  414. this->SubmitFiles.clear();
  415. cmMakefile* mf = command->GetMakefile();
  416. std::string fname = src_dir;
  417. fname += "/CTestConfig.cmake";
  418. cmSystemTools::ConvertToUnixSlashes(fname);
  419. if ( cmSystemTools::FileExists(fname.c_str()) )
  420. {
  421. cmCTestLog(this, OUTPUT, " Reading ctest configuration file: "
  422. << fname.c_str() << std::endl);
  423. bool readit = mf->ReadListFile(mf->GetCurrentListFile(),
  424. fname.c_str() );
  425. if(!readit)
  426. {
  427. std::string m = "Could not find include file: ";
  428. m += fname;
  429. command->SetError(m.c_str());
  430. return false;
  431. }
  432. }
  433. else if ( !first )
  434. {
  435. cmCTestLog(this, WARNING, "Cannot locate CTest configuration: "
  436. << fname.c_str() << std::endl);
  437. }
  438. else
  439. {
  440. cmCTestLog(this, HANDLER_OUTPUT, " Cannot locate CTest configuration: "
  441. << fname.c_str() << std::endl
  442. << " Delay the initialization of CTest" << std::endl);
  443. }
  444. this->SetCTestConfigurationFromCMakeVariable(mf, "NightlyStartTime",
  445. "CTEST_NIGHTLY_START_TIME");
  446. this->SetCTestConfigurationFromCMakeVariable(mf, "Site", "CTEST_SITE");
  447. this->SetCTestConfigurationFromCMakeVariable(mf, "BuildName",
  448. "CTEST_BUILD_NAME");
  449. const char* dartVersion = mf->GetDefinition("CTEST_DART_SERVER_VERSION");
  450. if ( dartVersion )
  451. {
  452. this->DartVersion = atoi(dartVersion);
  453. if ( this->DartVersion < 0 )
  454. {
  455. cmCTestLog(this, ERROR_MESSAGE, "Invalid Dart server version: "
  456. << dartVersion << ". Please specify the version number."
  457. << std::endl);
  458. return false;
  459. }
  460. }
  461. if ( !this->Initialize(bld_dir.c_str(), true, false) )
  462. {
  463. if ( this->GetCTestConfiguration("NightlyStartTime").empty() && first)
  464. {
  465. return true;
  466. }
  467. return false;
  468. }
  469. cmCTestLog(this, OUTPUT, " Use " << this->GetTestModelString()
  470. << " tag: " << this->GetCurrentTag() << std::endl);
  471. return true;
  472. }
  473. //----------------------------------------------------------------------
  474. bool cmCTest::UpdateCTestConfiguration()
  475. {
  476. if ( this->SuppressUpdatingCTestConfiguration )
  477. {
  478. return true;
  479. }
  480. std::string fileName = this->CTestConfigFile;
  481. if ( fileName.empty() )
  482. {
  483. fileName = this->BinaryDir + "/DartConfiguration.tcl";
  484. if ( !cmSystemTools::FileExists(fileName.c_str()) )
  485. {
  486. fileName = this->BinaryDir + "/CTestConfiguration.ini";
  487. }
  488. }
  489. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "UpdateCTestConfiguration from :"
  490. << fileName.c_str() << "\n");
  491. if ( !cmSystemTools::FileExists(fileName.c_str()) )
  492. {
  493. // No need to exit if we are not producing XML
  494. if ( this->ProduceXML )
  495. {
  496. cmCTestLog(this, ERROR_MESSAGE, "Cannot find file: " << fileName.c_str()
  497. << std::endl);
  498. return false;
  499. }
  500. }
  501. else
  502. {
  503. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Parse Config file:"
  504. << fileName.c_str() << "\n");
  505. // parse the dart test file
  506. std::ifstream fin(fileName.c_str());
  507. if(!fin)
  508. {
  509. return false;
  510. }
  511. char buffer[1024];
  512. while ( fin )
  513. {
  514. buffer[0] = 0;
  515. fin.getline(buffer, 1023);
  516. buffer[1023] = 0;
  517. std::string line = cmCTest::CleanString(buffer);
  518. if(line.size() == 0)
  519. {
  520. continue;
  521. }
  522. while ( fin && (line[line.size()-1] == '\\') )
  523. {
  524. line = line.substr(0, line.size()-1);
  525. buffer[0] = 0;
  526. fin.getline(buffer, 1023);
  527. buffer[1023] = 0;
  528. line += cmCTest::CleanString(buffer);
  529. }
  530. if ( line[0] == '#' )
  531. {
  532. continue;
  533. }
  534. std::string::size_type cpos = line.find_first_of(":");
  535. if ( cpos == line.npos )
  536. {
  537. continue;
  538. }
  539. std::string key = line.substr(0, cpos);
  540. std::string value
  541. = cmCTest::CleanString(line.substr(cpos+1, line.npos));
  542. this->CTestConfiguration[key] = value;
  543. }
  544. fin.close();
  545. }
  546. if ( !this->GetCTestConfiguration("BuildDirectory").empty() )
  547. {
  548. this->BinaryDir = this->GetCTestConfiguration("BuildDirectory");
  549. cmSystemTools::ChangeDirectory(this->BinaryDir.c_str());
  550. }
  551. this->TimeOut = atoi(this->GetCTestConfiguration("TimeOut").c_str());
  552. if ( this->ProduceXML )
  553. {
  554. this->CompressXMLFiles = cmSystemTools::IsOn(
  555. this->GetCTestConfiguration("CompressSubmission").c_str());
  556. }
  557. return true;
  558. }
  559. //----------------------------------------------------------------------
  560. void cmCTest::BlockTestErrorDiagnostics()
  561. {
  562. cmSystemTools::PutEnv("DART_TEST_FROM_DART=1");
  563. cmSystemTools::PutEnv("DASHBOARD_TEST_FROM_CTEST=" CMake_VERSION);
  564. #if defined(_WIN32)
  565. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  566. #elif defined(__BEOS__)
  567. disable_debugger(1);
  568. #endif
  569. }
  570. //----------------------------------------------------------------------
  571. void cmCTest::SetTestModel(int mode)
  572. {
  573. this->InteractiveDebugMode = false;
  574. this->TestModel = mode;
  575. }
  576. //----------------------------------------------------------------------
  577. bool cmCTest::SetTest(const char* ttype, bool report)
  578. {
  579. if ( cmSystemTools::LowerCase(ttype) == "all" )
  580. {
  581. this->Tests[cmCTest::ALL_TEST] = 1;
  582. }
  583. else if ( cmSystemTools::LowerCase(ttype) == "start" )
  584. {
  585. this->Tests[cmCTest::START_TEST] = 1;
  586. }
  587. else if ( cmSystemTools::LowerCase(ttype) == "update" )
  588. {
  589. this->Tests[cmCTest::UPDATE_TEST] = 1;
  590. }
  591. else if ( cmSystemTools::LowerCase(ttype) == "configure" )
  592. {
  593. this->Tests[cmCTest::CONFIGURE_TEST] = 1;
  594. }
  595. else if ( cmSystemTools::LowerCase(ttype) == "build" )
  596. {
  597. this->Tests[cmCTest::BUILD_TEST] = 1;
  598. }
  599. else if ( cmSystemTools::LowerCase(ttype) == "test" )
  600. {
  601. this->Tests[cmCTest::TEST_TEST] = 1;
  602. }
  603. else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
  604. {
  605. this->Tests[cmCTest::COVERAGE_TEST] = 1;
  606. }
  607. else if ( cmSystemTools::LowerCase(ttype) == "memcheck" )
  608. {
  609. this->Tests[cmCTest::MEMCHECK_TEST] = 1;
  610. }
  611. else if ( cmSystemTools::LowerCase(ttype) == "notes" )
  612. {
  613. this->Tests[cmCTest::NOTES_TEST] = 1;
  614. }
  615. else if ( cmSystemTools::LowerCase(ttype) == "submit" )
  616. {
  617. this->Tests[cmCTest::SUBMIT_TEST] = 1;
  618. }
  619. else
  620. {
  621. if ( report )
  622. {
  623. cmCTestLog(this, ERROR_MESSAGE, "Don't know about test \"" << ttype
  624. << "\" yet..." << std::endl);
  625. }
  626. return false;
  627. }
  628. return true;
  629. }
  630. //----------------------------------------------------------------------
  631. void cmCTest::Finalize()
  632. {
  633. }
  634. //----------------------------------------------------------------------
  635. bool cmCTest::OpenOutputFile(const std::string& path,
  636. const std::string& name, cmGeneratedFileStream& stream,
  637. bool compress)
  638. {
  639. std::string testingDir = this->BinaryDir + "/Testing";
  640. if ( path.size() > 0 )
  641. {
  642. testingDir += "/" + path;
  643. }
  644. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  645. {
  646. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  647. {
  648. cmCTestLog(this, ERROR_MESSAGE, "File " << testingDir
  649. << " is in the place of the testing directory"
  650. << std::endl);
  651. return false;
  652. }
  653. }
  654. else
  655. {
  656. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  657. {
  658. cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory " << testingDir
  659. << std::endl);
  660. return false;
  661. }
  662. }
  663. std::string filename = testingDir + "/" + name;
  664. stream.Open(filename.c_str());
  665. if( !stream )
  666. {
  667. cmCTestLog(this, ERROR_MESSAGE, "Problem opening file: " << filename
  668. << std::endl);
  669. return false;
  670. }
  671. if ( compress )
  672. {
  673. if ( this->CompressXMLFiles )
  674. {
  675. stream.SetCompression(true);
  676. }
  677. }
  678. return true;
  679. }
  680. //----------------------------------------------------------------------
  681. bool cmCTest::AddIfExists(SetOfStrings& files, const char* file)
  682. {
  683. if ( this->CTestFileExists(file) )
  684. {
  685. files.insert(file);
  686. }
  687. else
  688. {
  689. std::string name = file;
  690. name += ".gz";
  691. if ( this->CTestFileExists(name.c_str()) )
  692. {
  693. files.insert(name.c_str());
  694. }
  695. else
  696. {
  697. return false;
  698. }
  699. }
  700. return true;
  701. }
  702. //----------------------------------------------------------------------
  703. bool cmCTest::CTestFileExists(const std::string& filename)
  704. {
  705. std::string testingDir = this->BinaryDir + "/Testing/" +
  706. this->CurrentTag + "/" + filename;
  707. return cmSystemTools::FileExists(testingDir.c_str());
  708. }
  709. //----------------------------------------------------------------------
  710. cmCTestGenericHandler* cmCTest::GetInitializedHandler(const char* handler)
  711. {
  712. cmCTest::t_TestingHandlers::iterator it =
  713. this->TestingHandlers.find(handler);
  714. if ( it == this->TestingHandlers.end() )
  715. {
  716. return 0;
  717. }
  718. it->second->Initialize();
  719. return it->second;
  720. }
  721. //----------------------------------------------------------------------
  722. cmCTestGenericHandler* cmCTest::GetHandler(const char* handler)
  723. {
  724. cmCTest::t_TestingHandlers::iterator it =
  725. this->TestingHandlers.find(handler);
  726. if ( it == this->TestingHandlers.end() )
  727. {
  728. return 0;
  729. }
  730. return it->second;
  731. }
  732. //----------------------------------------------------------------------
  733. int cmCTest::ExecuteHandler(const char* shandler)
  734. {
  735. cmCTestGenericHandler* handler = this->GetHandler(shandler);
  736. if ( !handler )
  737. {
  738. return -1;
  739. }
  740. handler->Initialize();
  741. return handler->ProcessHandler();
  742. }
  743. //----------------------------------------------------------------------
  744. int cmCTest::ProcessTests()
  745. {
  746. int res = 0;
  747. bool notest = true;
  748. int cc;
  749. int update_count = 0;
  750. cmCTestLog(this, OUTPUT, "Start processing tests" << std::endl);
  751. for ( cc = 0; cc < LAST_TEST; cc ++ )
  752. {
  753. if ( this->Tests[cc] )
  754. {
  755. notest = false;
  756. break;
  757. }
  758. }
  759. if (( this->Tests[UPDATE_TEST] || this->Tests[ALL_TEST] ) &&
  760. (this->GetRemainingTimeAllowed() - 120 > 0))
  761. {
  762. cmCTestGenericHandler* uphandler = this->GetHandler("update");
  763. uphandler->SetPersistentOption("SourceDirectory",
  764. this->GetCTestConfiguration("SourceDirectory").c_str());
  765. update_count = uphandler->ProcessHandler();
  766. if ( update_count < 0 )
  767. {
  768. res |= cmCTest::UPDATE_ERRORS;
  769. }
  770. }
  771. if ( this->TestModel == cmCTest::CONTINUOUS && !update_count )
  772. {
  773. return 0;
  774. }
  775. if (( this->Tests[CONFIGURE_TEST] || this->Tests[ALL_TEST] )&&
  776. (this->GetRemainingTimeAllowed() - 120 > 0))
  777. {
  778. if (this->GetHandler("configure")->ProcessHandler() < 0)
  779. {
  780. res |= cmCTest::CONFIGURE_ERRORS;
  781. }
  782. }
  783. if (( this->Tests[BUILD_TEST] || this->Tests[ALL_TEST] )&&
  784. (this->GetRemainingTimeAllowed() - 120 > 0))
  785. {
  786. this->UpdateCTestConfiguration();
  787. if (this->GetHandler("build")->ProcessHandler() < 0)
  788. {
  789. res |= cmCTest::BUILD_ERRORS;
  790. }
  791. }
  792. if (( this->Tests[TEST_TEST] || this->Tests[ALL_TEST] || notest ) &&
  793. (this->GetRemainingTimeAllowed() - 120 > 0))
  794. {
  795. this->UpdateCTestConfiguration();
  796. if (this->GetHandler("test")->ProcessHandler() < 0)
  797. {
  798. res |= cmCTest::TEST_ERRORS;
  799. }
  800. }
  801. if (( this->Tests[COVERAGE_TEST] || this->Tests[ALL_TEST] ) &&
  802. (this->GetRemainingTimeAllowed() - 120 > 0))
  803. {
  804. this->UpdateCTestConfiguration();
  805. if (this->GetHandler("coverage")->ProcessHandler() < 0)
  806. {
  807. res |= cmCTest::COVERAGE_ERRORS;
  808. }
  809. }
  810. if (( this->Tests[MEMCHECK_TEST] || this->Tests[ALL_TEST] )&&
  811. (this->GetRemainingTimeAllowed() - 120 > 0))
  812. {
  813. this->UpdateCTestConfiguration();
  814. if (this->GetHandler("memcheck")->ProcessHandler() < 0)
  815. {
  816. res |= cmCTest::MEMORY_ERRORS;
  817. }
  818. }
  819. if ( !notest )
  820. {
  821. std::string notes_dir = this->BinaryDir + "/Testing/Notes";
  822. if ( cmSystemTools::FileIsDirectory(notes_dir.c_str()) )
  823. {
  824. cmsys::Directory d;
  825. d.Load(notes_dir.c_str());
  826. unsigned long kk;
  827. for ( kk = 0; kk < d.GetNumberOfFiles(); kk ++ )
  828. {
  829. const char* file = d.GetFile(kk);
  830. std::string fullname = notes_dir + "/" + file;
  831. if ( cmSystemTools::FileExists(fullname.c_str()) &&
  832. !cmSystemTools::FileIsDirectory(fullname.c_str()) )
  833. {
  834. if ( this->NotesFiles.size() > 0 )
  835. {
  836. this->NotesFiles += ";";
  837. }
  838. this->NotesFiles += fullname;
  839. this->Tests[NOTES_TEST] = 1;
  840. }
  841. }
  842. }
  843. }
  844. if ( this->Tests[NOTES_TEST] || this->Tests[ALL_TEST] )
  845. {
  846. this->UpdateCTestConfiguration();
  847. if ( this->NotesFiles.size() )
  848. {
  849. this->GenerateNotesFile(this->NotesFiles.c_str());
  850. }
  851. }
  852. if ( this->Tests[SUBMIT_TEST] || this->Tests[ALL_TEST] )
  853. {
  854. this->UpdateCTestConfiguration();
  855. if (this->GetHandler("submit")->ProcessHandler() < 0)
  856. {
  857. res |= cmCTest::SUBMIT_ERRORS;
  858. }
  859. }
  860. if ( res != 0 )
  861. {
  862. cmCTestLog(this, ERROR_MESSAGE, "Errors while running CTest"
  863. << std::endl);
  864. }
  865. return res;
  866. }
  867. //----------------------------------------------------------------------
  868. std::string cmCTest::GetTestModelString()
  869. {
  870. if ( !this->SpecificTrack.empty() )
  871. {
  872. return this->SpecificTrack;
  873. }
  874. switch ( this->TestModel )
  875. {
  876. case cmCTest::NIGHTLY:
  877. return "Nightly";
  878. case cmCTest::CONTINUOUS:
  879. return "Continuous";
  880. }
  881. return "Experimental";
  882. }
  883. //----------------------------------------------------------------------
  884. int cmCTest::GetTestModelFromString(const char* str)
  885. {
  886. if ( !str )
  887. {
  888. return cmCTest::EXPERIMENTAL;
  889. }
  890. std::string rstr = cmSystemTools::LowerCase(str);
  891. if ( strncmp(rstr.c_str(), "cont", 4) == 0 )
  892. {
  893. return cmCTest::CONTINUOUS;
  894. }
  895. if ( strncmp(rstr.c_str(), "nigh", 4) == 0 )
  896. {
  897. return cmCTest::NIGHTLY;
  898. }
  899. return cmCTest::EXPERIMENTAL;
  900. }
  901. //######################################################################
  902. //######################################################################
  903. //######################################################################
  904. //######################################################################
  905. //----------------------------------------------------------------------
  906. int cmCTest::RunMakeCommand(const char* command, std::string* output,
  907. int* retVal, const char* dir, int timeout, std::ofstream& ofs)
  908. {
  909. // First generate the command and arguments
  910. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  911. if(args.size() < 1)
  912. {
  913. return false;
  914. }
  915. std::vector<const char*> argv;
  916. for(std::vector<cmStdString>::const_iterator a = args.begin();
  917. a != args.end(); ++a)
  918. {
  919. argv.push_back(a->c_str());
  920. }
  921. argv.push_back(0);
  922. if ( output )
  923. {
  924. *output = "";
  925. }
  926. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Run command:");
  927. std::vector<const char*>::iterator ait;
  928. for ( ait = argv.begin(); ait != argv.end() && *ait; ++ ait )
  929. {
  930. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\"");
  931. }
  932. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, std::endl);
  933. // Now create process object
  934. cmsysProcess* cp = cmsysProcess_New();
  935. cmsysProcess_SetCommand(cp, &*argv.begin());
  936. cmsysProcess_SetWorkingDirectory(cp, dir);
  937. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  938. cmsysProcess_SetTimeout(cp, timeout);
  939. cmsysProcess_Execute(cp);
  940. // Initialize tick's
  941. std::string::size_type tick = 0;
  942. std::string::size_type tick_len = 1024;
  943. std::string::size_type tick_line_len = 50;
  944. char* data;
  945. int length;
  946. cmCTestLog(this, HANDLER_OUTPUT,
  947. " Each . represents " << tick_len << " bytes of output" << std::endl
  948. << " " << std::flush);
  949. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  950. {
  951. if ( output )
  952. {
  953. for(int cc =0; cc < length; ++cc)
  954. {
  955. if(data[cc] == 0)
  956. {
  957. data[cc] = '\n';
  958. }
  959. }
  960. output->append(data, length);
  961. while ( output->size() > (tick * tick_len) )
  962. {
  963. tick ++;
  964. cmCTestLog(this, HANDLER_OUTPUT, "." << std::flush);
  965. if ( tick % tick_line_len == 0 && tick > 0 )
  966. {
  967. cmCTestLog(this, HANDLER_OUTPUT, " Size: "
  968. << int((output->size() / 1024.0) + 1) << "K" << std::endl
  969. << " " << std::flush);
  970. }
  971. }
  972. }
  973. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length));
  974. if ( ofs )
  975. {
  976. ofs << cmCTestLogWrite(data, length);
  977. }
  978. }
  979. cmCTestLog(this, OUTPUT, " Size of output: "
  980. << int(output->size() / 1024.0) << "K" << std::endl);
  981. cmsysProcess_WaitForExit(cp, 0);
  982. int result = cmsysProcess_GetState(cp);
  983. if(result == cmsysProcess_State_Exited)
  984. {
  985. *retVal = cmsysProcess_GetExitValue(cp);
  986. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Command exited with the value: "
  987. << *retVal << std::endl);
  988. }
  989. else if(result == cmsysProcess_State_Exception)
  990. {
  991. *retVal = cmsysProcess_GetExitException(cp);
  992. cmCTestLog(this, WARNING, "There was an exception: " << *retVal
  993. << std::endl);
  994. }
  995. else if(result == cmsysProcess_State_Expired)
  996. {
  997. cmCTestLog(this, WARNING, "There was a timeout" << std::endl);
  998. }
  999. else if(result == cmsysProcess_State_Error)
  1000. {
  1001. *output += "\n*** ERROR executing: ";
  1002. *output += cmsysProcess_GetErrorString(cp);
  1003. *output += "\n***The build process failed.";
  1004. cmCTestLog(this, ERROR_MESSAGE, "There was an error: "
  1005. << cmsysProcess_GetErrorString(cp) << std::endl);
  1006. }
  1007. cmsysProcess_Delete(cp);
  1008. return result;
  1009. }
  1010. //######################################################################
  1011. //######################################################################
  1012. //######################################################################
  1013. //######################################################################
  1014. //----------------------------------------------------------------------
  1015. int cmCTest::RunTest(std::vector<const char*> argv,
  1016. std::string* output, int *retVal,
  1017. std::ostream* log, double testTimeOut)
  1018. {
  1019. // determine how much time we have
  1020. double timeout = this->GetRemainingTimeAllowed() - 120;
  1021. if (this->TimeOut && this->TimeOut < timeout)
  1022. {
  1023. timeout = this->TimeOut;
  1024. }
  1025. if (testTimeOut && testTimeOut < timeout)
  1026. {
  1027. timeout = testTimeOut;
  1028. }
  1029. // always have at least 1 second if we got to here
  1030. if (timeout <= 0)
  1031. {
  1032. timeout = 1;
  1033. }
  1034. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  1035. "Test timeout computed to be: " << timeout << "\n");
  1036. if(cmSystemTools::SameFile(argv[0], this->CTestSelf.c_str()) &&
  1037. !this->ForceNewCTestProcess)
  1038. {
  1039. cmCTest inst;
  1040. inst.ConfigType = this->ConfigType;
  1041. inst.TimeOut = timeout;
  1042. std::vector<std::string> args;
  1043. for(unsigned int i =0; i < argv.size(); ++i)
  1044. {
  1045. if(argv[i])
  1046. {
  1047. // make sure we pass the timeout in for any build and test
  1048. // invocations. Since --build-generator is required this is a
  1049. // good place to check for it, and to add the arguments in
  1050. if (strcmp(argv[i],"--build-generator") == 0 && timeout)
  1051. {
  1052. args.push_back("--test-timeout");
  1053. cmOStringStream msg;
  1054. msg << timeout;
  1055. args.push_back(msg.str());
  1056. }
  1057. args.push_back(argv[i]);
  1058. }
  1059. }
  1060. if ( *log )
  1061. {
  1062. *log << "* Run internal CTest" << std::endl;
  1063. }
  1064. std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
  1065. *retVal = inst.Run(args, output);
  1066. if ( *log )
  1067. {
  1068. *log << output->c_str();
  1069. }
  1070. cmSystemTools::ChangeDirectory(oldpath.c_str());
  1071. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  1072. "Internal cmCTest object used to run test." << std::endl
  1073. << *output << std::endl);
  1074. return cmsysProcess_State_Exited;
  1075. }
  1076. std::vector<char> tempOutput;
  1077. if ( output )
  1078. {
  1079. *output = "";
  1080. }
  1081. cmsysProcess* cp = cmsysProcess_New();
  1082. cmsysProcess_SetCommand(cp, &*argv.begin());
  1083. cmCTestLog(this, DEBUG, "Command is: " << argv[0] << std::endl);
  1084. if(cmSystemTools::GetRunCommandHideConsole())
  1085. {
  1086. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  1087. }
  1088. cmsysProcess_SetTimeout(cp, timeout);
  1089. cmsysProcess_Execute(cp);
  1090. char* data;
  1091. int length;
  1092. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  1093. {
  1094. if ( output )
  1095. {
  1096. tempOutput.insert(tempOutput.end(), data, data+length);
  1097. }
  1098. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length));
  1099. if ( log )
  1100. {
  1101. log->write(data, length);
  1102. }
  1103. }
  1104. cmsysProcess_WaitForExit(cp, 0);
  1105. if(output && tempOutput.begin() != tempOutput.end())
  1106. {
  1107. output->append(&*tempOutput.begin(), tempOutput.size());
  1108. }
  1109. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "-- Process completed"
  1110. << std::endl);
  1111. int result = cmsysProcess_GetState(cp);
  1112. if(result == cmsysProcess_State_Exited)
  1113. {
  1114. *retVal = cmsysProcess_GetExitValue(cp);
  1115. }
  1116. else if(result == cmsysProcess_State_Exception)
  1117. {
  1118. *retVal = cmsysProcess_GetExitException(cp);
  1119. std::string outerr = "\n*** Exception executing: ";
  1120. outerr += cmsysProcess_GetExceptionString(cp);
  1121. *output += outerr;
  1122. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl
  1123. << std::flush);
  1124. }
  1125. else if(result == cmsysProcess_State_Error)
  1126. {
  1127. std::string outerr = "\n*** ERROR executing: ";
  1128. outerr += cmsysProcess_GetErrorString(cp);
  1129. *output += outerr;
  1130. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl
  1131. << std::flush);
  1132. }
  1133. cmsysProcess_Delete(cp);
  1134. return result;
  1135. }
  1136. //----------------------------------------------------------------------
  1137. void cmCTest::StartXML(std::ostream& ostr)
  1138. {
  1139. ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1140. << "<Site BuildName=\"" << this->GetCTestConfiguration("BuildName")
  1141. << "\" BuildStamp=\"" << this->CurrentTag << "-"
  1142. << this->GetTestModelString() << "\" Name=\""
  1143. << this->GetCTestConfiguration("Site") << "\" Generator=\"ctest"
  1144. << cmVersion::GetCMakeVersion()
  1145. << "\">" << std::endl;
  1146. }
  1147. //----------------------------------------------------------------------
  1148. void cmCTest::EndXML(std::ostream& ostr)
  1149. {
  1150. ostr << "</Site>" << std::endl;
  1151. }
  1152. //----------------------------------------------------------------------
  1153. int cmCTest::GenerateCTestNotesOutput(std::ostream& os,
  1154. const cmCTest::VectorOfStrings& files)
  1155. {
  1156. cmCTest::VectorOfStrings::const_iterator it;
  1157. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1158. << "<?xml-stylesheet type=\"text/xsl\" "
  1159. "href=\"Dart/Source/Server/XSL/Build.xsl "
  1160. "<file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
  1161. << "<Site BuildName=\"" << this->GetCTestConfiguration("BuildName")
  1162. << "\" BuildStamp=\""
  1163. << this->CurrentTag << "-" << this->GetTestModelString() << "\" Name=\""
  1164. << this->GetCTestConfiguration("Site") << "\" Generator=\"ctest"
  1165. << cmVersion::GetCMakeVersion()
  1166. << "\">\n"
  1167. << "<Notes>" << std::endl;
  1168. for ( it = files.begin(); it != files.end(); it ++ )
  1169. {
  1170. cmCTestLog(this, OUTPUT, "\tAdd file: " << it->c_str() << std::endl);
  1171. std::string note_time = this->CurrentTime();
  1172. os << "<Note Name=\"" << this->MakeXMLSafe(it->c_str()) << "\">\n"
  1173. << "<DateTime>" << note_time << "</DateTime>\n"
  1174. << "<Text>" << std::endl;
  1175. std::ifstream ifs(it->c_str());
  1176. if ( ifs )
  1177. {
  1178. std::string line;
  1179. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  1180. {
  1181. os << this->MakeXMLSafe(line) << std::endl;
  1182. }
  1183. ifs.close();
  1184. }
  1185. else
  1186. {
  1187. os << "Problem reading file: " << it->c_str() << std::endl;
  1188. cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: " << it->c_str()
  1189. << " while creating notes" << std::endl);
  1190. }
  1191. os << "</Text>\n"
  1192. << "</Note>" << std::endl;
  1193. }
  1194. os << "</Notes>\n"
  1195. << "</Site>" << std::endl;
  1196. return 1;
  1197. }
  1198. //----------------------------------------------------------------------
  1199. int cmCTest::GenerateNotesFile(const std::vector<cmStdString> &files)
  1200. {
  1201. cmGeneratedFileStream ofs;
  1202. if ( !this->OpenOutputFile(this->CurrentTag, "Notes.xml", ofs) )
  1203. {
  1204. cmCTestLog(this, ERROR_MESSAGE, "Cannot open notes file" << std::endl);
  1205. return 1;
  1206. }
  1207. this->GenerateCTestNotesOutput(ofs, files);
  1208. return 0;
  1209. }
  1210. //----------------------------------------------------------------------
  1211. int cmCTest::GenerateNotesFile(const char* cfiles)
  1212. {
  1213. if ( !cfiles )
  1214. {
  1215. return 1;
  1216. }
  1217. std::vector<cmStdString> files;
  1218. cmCTestLog(this, OUTPUT, "Create notes file" << std::endl);
  1219. files = cmSystemTools::SplitString(cfiles, ';');
  1220. if ( files.size() == 0 )
  1221. {
  1222. return 1;
  1223. }
  1224. return this->GenerateNotesFile(files);
  1225. }
  1226. //----------------------------------------------------------------------
  1227. bool cmCTest::SubmitExtraFiles(const std::vector<cmStdString> &files)
  1228. {
  1229. std::vector<cmStdString>::const_iterator it;
  1230. for ( it = files.begin();
  1231. it != files.end();
  1232. ++ it )
  1233. {
  1234. if ( !cmSystemTools::FileExists(it->c_str()) )
  1235. {
  1236. cmCTestLog(this, ERROR_MESSAGE, "Cannot find extra file: "
  1237. << it->c_str() << " to submit."
  1238. << std::endl;);
  1239. return false;
  1240. }
  1241. this->AddSubmitFile(it->c_str());
  1242. }
  1243. return true;
  1244. }
  1245. //----------------------------------------------------------------------
  1246. bool cmCTest::SubmitExtraFiles(const char* cfiles)
  1247. {
  1248. if ( !cfiles )
  1249. {
  1250. return 1;
  1251. }
  1252. std::vector<cmStdString> files;
  1253. cmCTestLog(this, OUTPUT, "Submit extra files" << std::endl);
  1254. files = cmSystemTools::SplitString(cfiles, ';');
  1255. if ( files.size() == 0 )
  1256. {
  1257. return 1;
  1258. }
  1259. return this->SubmitExtraFiles(files);
  1260. }
  1261. //-------------------------------------------------------
  1262. // for a -D argument convert the next argument into
  1263. // the proper list of dashboard steps via SetTest
  1264. bool cmCTest::AddTestsForDashboardType(std::string &targ)
  1265. {
  1266. if ( targ == "Experimental" )
  1267. {
  1268. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1269. this->SetTest("Start");
  1270. this->SetTest("Configure");
  1271. this->SetTest("Build");
  1272. this->SetTest("Test");
  1273. this->SetTest("Coverage");
  1274. this->SetTest("Submit");
  1275. }
  1276. else if ( targ == "ExperimentalStart" )
  1277. {
  1278. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1279. this->SetTest("Start");
  1280. }
  1281. else if ( targ == "ExperimentalUpdate" )
  1282. {
  1283. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1284. this->SetTest("Update");
  1285. }
  1286. else if ( targ == "ExperimentalConfigure" )
  1287. {
  1288. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1289. this->SetTest("Configure");
  1290. }
  1291. else if ( targ == "ExperimentalBuild" )
  1292. {
  1293. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1294. this->SetTest("Build");
  1295. }
  1296. else if ( targ == "ExperimentalTest" )
  1297. {
  1298. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1299. this->SetTest("Test");
  1300. }
  1301. else if ( targ == "ExperimentalMemCheck"
  1302. || targ == "ExperimentalPurify" )
  1303. {
  1304. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1305. this->SetTest("MemCheck");
  1306. }
  1307. else if ( targ == "ExperimentalCoverage" )
  1308. {
  1309. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1310. this->SetTest("Coverage");
  1311. }
  1312. else if ( targ == "ExperimentalSubmit" )
  1313. {
  1314. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1315. this->SetTest("Submit");
  1316. }
  1317. else if ( targ == "Continuous" )
  1318. {
  1319. this->SetTestModel(cmCTest::CONTINUOUS);
  1320. this->SetTest("Start");
  1321. this->SetTest("Update");
  1322. this->SetTest("Configure");
  1323. this->SetTest("Build");
  1324. this->SetTest("Test");
  1325. this->SetTest("Coverage");
  1326. this->SetTest("Submit");
  1327. }
  1328. else if ( targ == "ContinuousStart" )
  1329. {
  1330. this->SetTestModel(cmCTest::CONTINUOUS);
  1331. this->SetTest("Start");
  1332. }
  1333. else if ( targ == "ContinuousUpdate" )
  1334. {
  1335. this->SetTestModel(cmCTest::CONTINUOUS);
  1336. this->SetTest("Update");
  1337. }
  1338. else if ( targ == "ContinuousConfigure" )
  1339. {
  1340. this->SetTestModel(cmCTest::CONTINUOUS);
  1341. this->SetTest("Configure");
  1342. }
  1343. else if ( targ == "ContinuousBuild" )
  1344. {
  1345. this->SetTestModel(cmCTest::CONTINUOUS);
  1346. this->SetTest("Build");
  1347. }
  1348. else if ( targ == "ContinuousTest" )
  1349. {
  1350. this->SetTestModel(cmCTest::CONTINUOUS);
  1351. this->SetTest("Test");
  1352. }
  1353. else if ( targ == "ContinuousMemCheck"
  1354. || targ == "ContinuousPurify" )
  1355. {
  1356. this->SetTestModel(cmCTest::CONTINUOUS);
  1357. this->SetTest("MemCheck");
  1358. }
  1359. else if ( targ == "ContinuousCoverage" )
  1360. {
  1361. this->SetTestModel(cmCTest::CONTINUOUS);
  1362. this->SetTest("Coverage");
  1363. }
  1364. else if ( targ == "ContinuousSubmit" )
  1365. {
  1366. this->SetTestModel(cmCTest::CONTINUOUS);
  1367. this->SetTest("Submit");
  1368. }
  1369. else if ( targ == "Nightly" )
  1370. {
  1371. this->SetTestModel(cmCTest::NIGHTLY);
  1372. this->SetTest("Start");
  1373. this->SetTest("Update");
  1374. this->SetTest("Configure");
  1375. this->SetTest("Build");
  1376. this->SetTest("Test");
  1377. this->SetTest("Coverage");
  1378. this->SetTest("Submit");
  1379. }
  1380. else if ( targ == "NightlyStart" )
  1381. {
  1382. this->SetTestModel(cmCTest::NIGHTLY);
  1383. this->SetTest("Start");
  1384. }
  1385. else if ( targ == "NightlyUpdate" )
  1386. {
  1387. this->SetTestModel(cmCTest::NIGHTLY);
  1388. this->SetTest("Update");
  1389. }
  1390. else if ( targ == "NightlyConfigure" )
  1391. {
  1392. this->SetTestModel(cmCTest::NIGHTLY);
  1393. this->SetTest("Configure");
  1394. }
  1395. else if ( targ == "NightlyBuild" )
  1396. {
  1397. this->SetTestModel(cmCTest::NIGHTLY);
  1398. this->SetTest("Build");
  1399. }
  1400. else if ( targ == "NightlyTest" )
  1401. {
  1402. this->SetTestModel(cmCTest::NIGHTLY);
  1403. this->SetTest("Test");
  1404. }
  1405. else if ( targ == "NightlyMemCheck"
  1406. || targ == "NightlyPurify" )
  1407. {
  1408. this->SetTestModel(cmCTest::NIGHTLY);
  1409. this->SetTest("MemCheck");
  1410. }
  1411. else if ( targ == "NightlyCoverage" )
  1412. {
  1413. this->SetTestModel(cmCTest::NIGHTLY);
  1414. this->SetTest("Coverage");
  1415. }
  1416. else if ( targ == "NightlySubmit" )
  1417. {
  1418. this->SetTestModel(cmCTest::NIGHTLY);
  1419. this->SetTest("Submit");
  1420. }
  1421. else if ( targ == "MemoryCheck" )
  1422. {
  1423. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1424. this->SetTest("Start");
  1425. this->SetTest("Configure");
  1426. this->SetTest("Build");
  1427. this->SetTest("MemCheck");
  1428. this->SetTest("Coverage");
  1429. this->SetTest("Submit");
  1430. }
  1431. else if ( targ == "NightlyMemoryCheck" )
  1432. {
  1433. this->SetTestModel(cmCTest::NIGHTLY);
  1434. this->SetTest("Start");
  1435. this->SetTest("Update");
  1436. this->SetTest("Configure");
  1437. this->SetTest("Build");
  1438. this->SetTest("MemCheck");
  1439. this->SetTest("Coverage");
  1440. this->SetTest("Submit");
  1441. }
  1442. else
  1443. {
  1444. cmCTestLog(this, ERROR_MESSAGE,
  1445. "CTest -D called with incorrect option: "
  1446. << targ << std::endl);
  1447. cmCTestLog(this, ERROR_MESSAGE, "Available options are:" << std::endl
  1448. << " " << "ctest" << " -D Continuous" << std::endl
  1449. << " " << "ctest"
  1450. << " -D Continuous(Start|Update|Configure|Build)" << std::endl
  1451. << " " << "ctest"
  1452. << " -D Continuous(Test|Coverage|MemCheck|Submit)"
  1453. << std::endl
  1454. << " " << "ctest" << " -D Experimental" << std::endl
  1455. << " " << "ctest"
  1456. << " -D Experimental(Start|Update|Configure|Build)"
  1457. << std::endl
  1458. << " " << "ctest"
  1459. << " -D Experimental(Test|Coverage|MemCheck|Submit)"
  1460. << std::endl
  1461. << " " << "ctest" << " -D Nightly" << std::endl
  1462. << " " << "ctest"
  1463. << " -D Nightly(Start|Update|Configure|Build)" << std::endl
  1464. << " " << "ctest"
  1465. << " -D Nightly(Test|Coverage|MemCheck|Submit)" << std::endl
  1466. << " " << "ctest" << " -D NightlyMemoryCheck" << std::endl);
  1467. return false;
  1468. }
  1469. return true;
  1470. }
  1471. //----------------------------------------------------------------------
  1472. bool cmCTest::CheckArgument(const std::string& arg, const char* varg1,
  1473. const char* varg2)
  1474. {
  1475. if ( varg1 && arg == varg1 || varg2 && arg == varg2 )
  1476. {
  1477. return true;
  1478. }
  1479. return false;
  1480. }
  1481. //----------------------------------------------------------------------
  1482. // Processes one command line argument (and its arguments if any)
  1483. // for many simple options and then returns
  1484. void cmCTest::HandleCommandLineArguments(size_t &i,
  1485. std::vector<std::string> &args)
  1486. {
  1487. std::string arg = args[i];
  1488. if(this->CheckArgument(arg, "--ctest-config") && i < args.size() - 1)
  1489. {
  1490. i++;
  1491. this->CTestConfigFile= args[i];
  1492. }
  1493. if(this->CheckArgument(arg, "-C", "--build-config") &&
  1494. i < args.size() - 1)
  1495. {
  1496. i++;
  1497. this->SetConfigType(args[i].c_str());
  1498. }
  1499. if(this->CheckArgument(arg, "--debug"))
  1500. {
  1501. this->Debug = true;
  1502. this->ShowLineNumbers = true;
  1503. }
  1504. if(this->CheckArgument(arg, "--track") && i < args.size() - 1)
  1505. {
  1506. i++;
  1507. this->SpecificTrack = args[i];
  1508. }
  1509. if(this->CheckArgument(arg, "--show-line-numbers"))
  1510. {
  1511. this->ShowLineNumbers = true;
  1512. }
  1513. if(this->CheckArgument(arg, "-Q", "--quiet"))
  1514. {
  1515. this->Quiet = true;
  1516. }
  1517. if(this->CheckArgument(arg, "-V", "--verbose"))
  1518. {
  1519. this->Verbose = true;
  1520. }
  1521. if(this->CheckArgument(arg, "-VV", "--extra-verbose"))
  1522. {
  1523. this->ExtraVerbose = true;
  1524. this->Verbose = true;
  1525. }
  1526. if(this->CheckArgument(arg, "-N", "--show-only"))
  1527. {
  1528. this->ShowOnly = true;
  1529. }
  1530. if(this->CheckArgument(arg, "-O", "--output-log") && i < args.size() - 1 )
  1531. {
  1532. i++;
  1533. this->SetOutputLogFileName(args[i].c_str());
  1534. }
  1535. if(this->CheckArgument(arg, "--tomorrow-tag"))
  1536. {
  1537. this->TomorrowTag = true;
  1538. }
  1539. if(this->CheckArgument(arg, "--force-new-ctest-process"))
  1540. {
  1541. this->ForceNewCTestProcess = true;
  1542. }
  1543. if(this->CheckArgument(arg, "--interactive-debug-mode") &&
  1544. i < args.size() - 1 )
  1545. {
  1546. i++;
  1547. this->InteractiveDebugMode = cmSystemTools::IsOn(args[i].c_str());
  1548. }
  1549. if(this->CheckArgument(arg, "--submit-index") && i < args.size() - 1 )
  1550. {
  1551. i++;
  1552. this->SubmitIndex = atoi(args[i].c_str());
  1553. if ( this->SubmitIndex < 0 )
  1554. {
  1555. this->SubmitIndex = 0;
  1556. }
  1557. }
  1558. if(this->CheckArgument(arg, "--overwrite") && i < args.size() - 1)
  1559. {
  1560. i++;
  1561. this->AddCTestConfigurationOverwrite(args[i].c_str());
  1562. }
  1563. if(this->CheckArgument(arg, "-A", "--add-notes") && i < args.size() - 1)
  1564. {
  1565. this->ProduceXML = true;
  1566. this->SetTest("Notes");
  1567. i++;
  1568. this->SetNotesFiles(args[i].c_str());
  1569. }
  1570. // options that control what tests are run
  1571. if(this->CheckArgument(arg, "-I", "--tests-information") &&
  1572. i < args.size() - 1)
  1573. {
  1574. i++;
  1575. this->GetHandler("test")->SetPersistentOption("TestsToRunInformation",
  1576. args[i].c_str());
  1577. this->GetHandler("memcheck")->
  1578. SetPersistentOption("TestsToRunInformation",args[i].c_str());
  1579. }
  1580. if(this->CheckArgument(arg, "-U", "--union"))
  1581. {
  1582. this->GetHandler("test")->SetPersistentOption("UseUnion", "true");
  1583. this->GetHandler("memcheck")->SetPersistentOption("UseUnion", "true");
  1584. }
  1585. if(this->CheckArgument(arg, "-R", "--tests-regex") && i < args.size() - 1)
  1586. {
  1587. i++;
  1588. this->GetHandler("test")->
  1589. SetPersistentOption("IncludeRegularExpression", args[i].c_str());
  1590. this->GetHandler("memcheck")->
  1591. SetPersistentOption("IncludeRegularExpression", args[i].c_str());
  1592. }
  1593. if(this->CheckArgument(arg, "-E", "--exclude-regex") &&
  1594. i < args.size() - 1)
  1595. {
  1596. i++;
  1597. this->GetHandler("test")->
  1598. SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
  1599. this->GetHandler("memcheck")->
  1600. SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
  1601. }
  1602. }
  1603. //----------------------------------------------------------------------
  1604. // handle the -S -SR and -SP arguments
  1605. void cmCTest::HandleScriptArguments(size_t &i,
  1606. std::vector<std::string> &args,
  1607. bool &SRArgumentSpecified)
  1608. {
  1609. std::string arg = args[i];
  1610. if(this->CheckArgument(arg, "-SP", "--script-new-process") &&
  1611. i < args.size() - 1 )
  1612. {
  1613. this->RunConfigurationScript = true;
  1614. i++;
  1615. cmCTestScriptHandler* ch
  1616. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1617. // -SR is an internal argument, -SP should be ignored when it is passed
  1618. if (!SRArgumentSpecified)
  1619. {
  1620. ch->AddConfigurationScript(args[i].c_str(),false);
  1621. }
  1622. }
  1623. if(this->CheckArgument(arg, "-SR", "--script-run") &&
  1624. i < args.size() - 1 )
  1625. {
  1626. SRArgumentSpecified = true;
  1627. this->RunConfigurationScript = true;
  1628. i++;
  1629. cmCTestScriptHandler* ch
  1630. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1631. ch->AddConfigurationScript(args[i].c_str(),true);
  1632. }
  1633. if(this->CheckArgument(arg, "-S", "--script") && i < args.size() - 1 )
  1634. {
  1635. this->RunConfigurationScript = true;
  1636. i++;
  1637. cmCTestScriptHandler* ch
  1638. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1639. // -SR is an internal argument, -S should be ignored when it is passed
  1640. if (!SRArgumentSpecified)
  1641. {
  1642. ch->AddConfigurationScript(args[i].c_str(),true);
  1643. }
  1644. }
  1645. }
  1646. //----------------------------------------------------------------------
  1647. // the main entry point of ctest, called from main
  1648. int cmCTest::Run(std::vector<std::string> &args, std::string* output)
  1649. {
  1650. this->FindRunningCMake(args[0].c_str());
  1651. const char* ctestExec = "ctest";
  1652. bool cmakeAndTest = false;
  1653. bool performSomeTest = true;
  1654. bool SRArgumentSpecified = false;
  1655. // copy the command line
  1656. for(size_t i=0; i < args.size(); ++i)
  1657. {
  1658. this->InitialCommandLineArguments.push_back(args[i]);
  1659. }
  1660. // process the command line arguments
  1661. for(size_t i=1; i < args.size(); ++i)
  1662. {
  1663. // handle the simple commandline arguments
  1664. this->HandleCommandLineArguments(i,args);
  1665. // handle the script arguments -S -SR -SP
  1666. this->HandleScriptArguments(i,args,SRArgumentSpecified);
  1667. // handle a request for a dashboard
  1668. std::string arg = args[i];
  1669. if(this->CheckArgument(arg, "-D", "--dashboard") && i < args.size() - 1 )
  1670. {
  1671. this->ProduceXML = true;
  1672. i++;
  1673. std::string targ = args[i];
  1674. // AddTestsForDashboard parses the dashborad type and converts it
  1675. // into the seperate stages
  1676. if (!this->AddTestsForDashboardType(targ))
  1677. {
  1678. performSomeTest = false;
  1679. }
  1680. }
  1681. if(this->CheckArgument(arg, "-T", "--test-action") &&
  1682. (i < args.size() -1) )
  1683. {
  1684. this->ProduceXML = true;
  1685. i++;
  1686. if ( !this->SetTest(args[i].c_str(), false) )
  1687. {
  1688. performSomeTest = false;
  1689. cmCTestLog(this, ERROR_MESSAGE,
  1690. "CTest -T called with incorrect option: "
  1691. << args[i].c_str() << std::endl);
  1692. cmCTestLog(this, ERROR_MESSAGE, "Available options are:" << std::endl
  1693. << " " << ctestExec << " -T all" << std::endl
  1694. << " " << ctestExec << " -T start" << std::endl
  1695. << " " << ctestExec << " -T update" << std::endl
  1696. << " " << ctestExec << " -T configure" << std::endl
  1697. << " " << ctestExec << " -T build" << std::endl
  1698. << " " << ctestExec << " -T test" << std::endl
  1699. << " " << ctestExec << " -T coverage" << std::endl
  1700. << " " << ctestExec << " -T memcheck" << std::endl
  1701. << " " << ctestExec << " -T notes" << std::endl
  1702. << " " << ctestExec << " -T submit" << std::endl);
  1703. }
  1704. }
  1705. // what type of test model
  1706. if(this->CheckArgument(arg, "-M", "--test-model") &&
  1707. (i < args.size() -1) )
  1708. {
  1709. i++;
  1710. std::string const& str = args[i];
  1711. if ( cmSystemTools::LowerCase(str) == "nightly" )
  1712. {
  1713. this->SetTestModel(cmCTest::NIGHTLY);
  1714. }
  1715. else if ( cmSystemTools::LowerCase(str) == "continuous" )
  1716. {
  1717. this->SetTestModel(cmCTest::CONTINUOUS);
  1718. }
  1719. else if ( cmSystemTools::LowerCase(str) == "experimental" )
  1720. {
  1721. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1722. }
  1723. else
  1724. {
  1725. performSomeTest = false;
  1726. cmCTestLog(this, ERROR_MESSAGE,
  1727. "CTest -M called with incorrect option: " << str.c_str()
  1728. << std::endl);
  1729. cmCTestLog(this, ERROR_MESSAGE, "Available options are:" << std::endl
  1730. << " " << ctestExec << " -M Continuous" << std::endl
  1731. << " " << ctestExec << " -M Experimental" << std::endl
  1732. << " " << ctestExec << " -M Nightly" << std::endl);
  1733. }
  1734. }
  1735. if(this->CheckArgument(arg, "--extra-submit") && i < args.size() - 1)
  1736. {
  1737. this->ProduceXML = true;
  1738. this->SetTest("Submit");
  1739. i++;
  1740. if ( !this->SubmitExtraFiles(args[i].c_str()) )
  1741. {
  1742. return 0;
  1743. }
  1744. }
  1745. // --build-and-test options
  1746. if(this->CheckArgument(arg, "--build-and-test") && i < args.size() - 1)
  1747. {
  1748. cmakeAndTest = true;
  1749. }
  1750. // pass the argument to all the handlers as well, but i may no longer be
  1751. // set to what it was originally so I'm not sure this is working as
  1752. // intended
  1753. cmCTest::t_TestingHandlers::iterator it;
  1754. for ( it = this->TestingHandlers.begin();
  1755. it != this->TestingHandlers.end();
  1756. ++ it )
  1757. {
  1758. if ( !it->second->ProcessCommandLineArguments(arg, i, args) )
  1759. {
  1760. cmCTestLog(this, ERROR_MESSAGE,
  1761. "Problem parsing command line arguments within a handler");
  1762. return 0;
  1763. }
  1764. }
  1765. } // the close of the for argument loop
  1766. // default to the build type of ctest itself if there is one
  1767. #ifdef CMAKE_INTDIR
  1768. if(this->ConfigType.size() == 0)
  1769. {
  1770. this->SetConfigType(CMAKE_INTDIR);
  1771. }
  1772. #endif
  1773. // now what sould cmake do? if --build-and-test was specified then
  1774. // we run the build and test handler and return
  1775. if(cmakeAndTest)
  1776. {
  1777. this->Verbose = true;
  1778. cmCTestBuildAndTestHandler* handler =
  1779. static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest"));
  1780. int retv = handler->ProcessHandler();
  1781. *output = handler->GetOutput();
  1782. #ifdef CMAKE_BUILD_WITH_CMAKE
  1783. cmDynamicLoader::FlushCache();
  1784. #endif
  1785. return retv;
  1786. }
  1787. // if some tests must be run
  1788. if(performSomeTest)
  1789. {
  1790. int res;
  1791. // call process directory
  1792. if (this->RunConfigurationScript)
  1793. {
  1794. if ( this->ExtraVerbose )
  1795. {
  1796. cmCTestLog(this, OUTPUT, "* Extra verbosity turned on" << std::endl);
  1797. }
  1798. cmCTest::t_TestingHandlers::iterator it;
  1799. for ( it = this->TestingHandlers.begin();
  1800. it != this->TestingHandlers.end();
  1801. ++ it )
  1802. {
  1803. it->second->SetVerbose(this->ExtraVerbose);
  1804. it->second->SetSubmitIndex(this->SubmitIndex);
  1805. }
  1806. this->GetHandler("script")->SetVerbose(this->Verbose);
  1807. res = this->GetHandler("script")->ProcessHandler();
  1808. }
  1809. else
  1810. {
  1811. this->ExtraVerbose = this->Verbose;
  1812. this->Verbose = true;
  1813. cmCTest::t_TestingHandlers::iterator it;
  1814. for ( it = this->TestingHandlers.begin();
  1815. it != this->TestingHandlers.end();
  1816. ++ it )
  1817. {
  1818. it->second->SetVerbose(this->Verbose);
  1819. it->second->SetSubmitIndex(this->SubmitIndex);
  1820. }
  1821. if ( !this->Initialize(
  1822. cmSystemTools::GetCurrentWorkingDirectory().c_str()) )
  1823. {
  1824. res = 12;
  1825. cmCTestLog(this, ERROR_MESSAGE, "Problem initializing the dashboard."
  1826. << std::endl);
  1827. }
  1828. else
  1829. {
  1830. res = this->ProcessTests();
  1831. }
  1832. this->Finalize();
  1833. }
  1834. return res;
  1835. }
  1836. return 1;
  1837. }
  1838. //----------------------------------------------------------------------
  1839. void cmCTest::FindRunningCMake(const char* arg0)
  1840. {
  1841. // Find our own executable.
  1842. std::vector<cmStdString> failures;
  1843. this->CTestSelf = arg0;
  1844. cmSystemTools::ConvertToUnixSlashes(this->CTestSelf);
  1845. failures.push_back(this->CTestSelf);
  1846. this->CTestSelf = cmSystemTools::FindProgram(this->CTestSelf.c_str());
  1847. if(!cmSystemTools::FileExists(this->CTestSelf.c_str()))
  1848. {
  1849. failures.push_back(this->CTestSelf);
  1850. this->CTestSelf = "/usr/local/bin/ctest";
  1851. }
  1852. if(!cmSystemTools::FileExists(this->CTestSelf.c_str()))
  1853. {
  1854. failures.push_back(this->CTestSelf);
  1855. cmOStringStream msg;
  1856. msg << "CTEST can not find the command line program ctest.\n";
  1857. msg << " argv[0] = \"" << arg0 << "\"\n";
  1858. msg << " Attempted paths:\n";
  1859. std::vector<cmStdString>::iterator i;
  1860. for(i=failures.begin(); i != failures.end(); ++i)
  1861. {
  1862. msg << " \"" << i->c_str() << "\"\n";
  1863. }
  1864. cmSystemTools::Error(msg.str().c_str());
  1865. }
  1866. std::string dir;
  1867. std::string file;
  1868. if(cmSystemTools::SplitProgramPath(this->CTestSelf.c_str(),
  1869. dir, file, true))
  1870. {
  1871. this->CMakeSelf = dir += "/cmake";
  1872. this->CMakeSelf += cmSystemTools::GetExecutableExtension();
  1873. if(cmSystemTools::FileExists(this->CMakeSelf.c_str()))
  1874. {
  1875. return;
  1876. }
  1877. }
  1878. failures.push_back(this->CMakeSelf);
  1879. #ifdef CMAKE_BUILD_DIR
  1880. std::string intdir = ".";
  1881. #ifdef CMAKE_INTDIR
  1882. intdir = CMAKE_INTDIR;
  1883. #endif
  1884. this->CMakeSelf = CMAKE_BUILD_DIR;
  1885. this->CMakeSelf += "/bin/";
  1886. this->CMakeSelf += intdir;
  1887. this->CMakeSelf += "/cmake";
  1888. this->CMakeSelf += cmSystemTools::GetExecutableExtension();
  1889. #endif
  1890. if(!cmSystemTools::FileExists(this->CMakeSelf.c_str()))
  1891. {
  1892. failures.push_back(this->CMakeSelf);
  1893. cmOStringStream msg;
  1894. msg << "CTEST can not find the command line program cmake.\n";
  1895. msg << " argv[0] = \"" << arg0 << "\"\n";
  1896. msg << " Attempted paths:\n";
  1897. std::vector<cmStdString>::iterator i;
  1898. for(i=failures.begin(); i != failures.end(); ++i)
  1899. {
  1900. msg << " \"" << i->c_str() << "\"\n";
  1901. }
  1902. cmSystemTools::Error(msg.str().c_str());
  1903. }
  1904. }
  1905. //----------------------------------------------------------------------
  1906. void cmCTest::SetNotesFiles(const char* notes)
  1907. {
  1908. if ( !notes )
  1909. {
  1910. return;
  1911. }
  1912. this->NotesFiles = notes;
  1913. }
  1914. //----------------------------------------------------------------------
  1915. int cmCTest::ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf)
  1916. {
  1917. bool found = false;
  1918. VectorOfStrings dirs;
  1919. VectorOfStrings ndirs;
  1920. cmCTestLog(this, DEBUG, "* Read custom CTest configuration directory: "
  1921. << dir << std::endl);
  1922. std::string fname = dir;
  1923. fname += "/CTestCustom.cmake";
  1924. cmCTestLog(this, DEBUG, "* Check for file: "
  1925. << fname.c_str() << std::endl);
  1926. if ( cmSystemTools::FileExists(fname.c_str()) )
  1927. {
  1928. cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: "
  1929. << fname.c_str() << std::endl);
  1930. bool erroroc = cmSystemTools::GetErrorOccuredFlag();
  1931. cmSystemTools::ResetErrorOccuredFlag();
  1932. if ( !mf->ReadListFile(0, fname.c_str()) ||
  1933. cmSystemTools::GetErrorOccuredFlag() )
  1934. {
  1935. cmCTestLog(this, ERROR_MESSAGE,
  1936. "Problem reading custom configuration: "
  1937. << fname.c_str() << std::endl);
  1938. }
  1939. found = true;
  1940. if ( erroroc )
  1941. {
  1942. cmSystemTools::SetErrorOccured();
  1943. }
  1944. }
  1945. std::string rexpr = dir;
  1946. rexpr += "/CTestCustom.ctest";
  1947. cmCTestLog(this, DEBUG, "* Check for file: "
  1948. << rexpr.c_str() << std::endl);
  1949. if ( !found && cmSystemTools::FileExists(rexpr.c_str()) )
  1950. {
  1951. cmsys::Glob gl;
  1952. gl.RecurseOn();
  1953. gl.FindFiles(rexpr);
  1954. std::vector<std::string>& files = gl.GetFiles();
  1955. std::vector<std::string>::iterator fileIt;
  1956. for ( fileIt = files.begin(); fileIt != files.end();
  1957. ++ fileIt )
  1958. {
  1959. cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: "
  1960. << fileIt->c_str() << std::endl);
  1961. if ( !mf->ReadListFile(0, fileIt->c_str()) ||
  1962. cmSystemTools::GetErrorOccuredFlag() )
  1963. {
  1964. cmCTestLog(this, ERROR_MESSAGE,
  1965. "Problem reading custom configuration: "
  1966. << fileIt->c_str() << std::endl);
  1967. }
  1968. }
  1969. found = true;
  1970. }
  1971. if ( found )
  1972. {
  1973. cmCTest::t_TestingHandlers::iterator it;
  1974. for ( it = this->TestingHandlers.begin();
  1975. it != this->TestingHandlers.end(); ++ it )
  1976. {
  1977. cmCTestLog(this, DEBUG,
  1978. "* Read custom CTest configuration vectors for handler: "
  1979. << it->first.c_str() << " (" << it->second << ")" << std::endl);
  1980. it->second->PopulateCustomVectors(mf);
  1981. }
  1982. }
  1983. return 1;
  1984. }
  1985. //----------------------------------------------------------------------
  1986. void cmCTest::PopulateCustomVector(cmMakefile* mf, const char* def,
  1987. VectorOfStrings& vec)
  1988. {
  1989. if ( !def)
  1990. {
  1991. return;
  1992. }
  1993. const char* dval = mf->GetDefinition(def);
  1994. if ( !dval )
  1995. {
  1996. return;
  1997. }
  1998. cmCTestLog(this, DEBUG, "PopulateCustomVector: " << def << std::endl);
  1999. std::vector<std::string> slist;
  2000. cmSystemTools::ExpandListArgument(dval, slist);
  2001. std::vector<std::string>::iterator it;
  2002. for ( it = slist.begin(); it != slist.end(); ++it )
  2003. {
  2004. cmCTestLog(this, DEBUG, " -- " << it->c_str() << std::endl);
  2005. vec.push_back(it->c_str());
  2006. }
  2007. }
  2008. //----------------------------------------------------------------------
  2009. void cmCTest::PopulateCustomInteger(cmMakefile* mf, const char* def, int& val)
  2010. {
  2011. if ( !def)
  2012. {
  2013. return;
  2014. }
  2015. const char* dval = mf->GetDefinition(def);
  2016. if ( !dval )
  2017. {
  2018. return;
  2019. }
  2020. val = atoi(dval);
  2021. }
  2022. //----------------------------------------------------------------------
  2023. std::string cmCTest::GetShortPathToFile(const char* cfname)
  2024. {
  2025. const std::string& sourceDir
  2026. = cmSystemTools::CollapseFullPath(
  2027. this->GetCTestConfiguration("SourceDirectory").c_str());
  2028. const std::string& buildDir
  2029. = cmSystemTools::CollapseFullPath(
  2030. this->GetCTestConfiguration("BuildDirectory").c_str());
  2031. std::string fname = cmSystemTools::CollapseFullPath(cfname);
  2032. // Find relative paths to both directories
  2033. std::string srcRelpath
  2034. = cmSystemTools::RelativePath(sourceDir.c_str(), fname.c_str());
  2035. std::string bldRelpath
  2036. = cmSystemTools::RelativePath(buildDir.c_str(), fname.c_str());
  2037. // If any contains "." it is not parent directory
  2038. bool inSrc = srcRelpath.find("..") == srcRelpath.npos;
  2039. bool inBld = bldRelpath.find("..") == bldRelpath.npos;
  2040. // TODO: Handle files with .. in their name
  2041. std::string* res = 0;
  2042. if ( inSrc && inBld )
  2043. {
  2044. // If both have relative path with no dots, pick the shorter one
  2045. if ( srcRelpath.size() < bldRelpath.size() )
  2046. {
  2047. res = &srcRelpath;
  2048. }
  2049. else
  2050. {
  2051. res = &bldRelpath;
  2052. }
  2053. }
  2054. else if ( inSrc )
  2055. {
  2056. res = &srcRelpath;
  2057. }
  2058. else if ( inBld )
  2059. {
  2060. res = &bldRelpath;
  2061. }
  2062. std::string path;
  2063. if ( !res )
  2064. {
  2065. path = fname;
  2066. }
  2067. else
  2068. {
  2069. cmSystemTools::ConvertToUnixSlashes(*res);
  2070. path = "./" + *res;
  2071. if ( path[path.size()-1] == '/' )
  2072. {
  2073. path = path.substr(0, path.size()-1);
  2074. }
  2075. }
  2076. cmsys::SystemTools::ReplaceString(path, ":", "_");
  2077. cmsys::SystemTools::ReplaceString(path, " ", "_");
  2078. return path;
  2079. }
  2080. //----------------------------------------------------------------------
  2081. std::string cmCTest::GetCTestConfiguration(const char *name)
  2082. {
  2083. if ( this->CTestConfigurationOverwrites.find(name) !=
  2084. this->CTestConfigurationOverwrites.end() )
  2085. {
  2086. return this->CTestConfigurationOverwrites[name];
  2087. }
  2088. return this->CTestConfiguration[name];
  2089. }
  2090. //----------------------------------------------------------------------
  2091. void cmCTest::EmptyCTestConfiguration()
  2092. {
  2093. this->CTestConfiguration.clear();
  2094. }
  2095. //----------------------------------------------------------------------
  2096. void cmCTest::SetCTestConfiguration(const char *name, const char* value)
  2097. {
  2098. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "SetCTestConfiguration:"
  2099. << name << ":" << value << "\n");
  2100. if ( !name )
  2101. {
  2102. return;
  2103. }
  2104. if ( !value )
  2105. {
  2106. this->CTestConfiguration.erase(name);
  2107. return;
  2108. }
  2109. this->CTestConfiguration[name] = value;
  2110. }
  2111. //----------------------------------------------------------------------
  2112. std::string cmCTest::GetCurrentTag()
  2113. {
  2114. return this->CurrentTag;
  2115. }
  2116. //----------------------------------------------------------------------
  2117. std::string cmCTest::GetBinaryDir()
  2118. {
  2119. return this->BinaryDir;
  2120. }
  2121. //----------------------------------------------------------------------
  2122. std::string cmCTest::GetConfigType()
  2123. {
  2124. return this->ConfigType;
  2125. }
  2126. //----------------------------------------------------------------------
  2127. bool cmCTest::GetShowOnly()
  2128. {
  2129. return this->ShowOnly;
  2130. }
  2131. //----------------------------------------------------------------------
  2132. void cmCTest::SetProduceXML(bool v)
  2133. {
  2134. this->ProduceXML = v;
  2135. }
  2136. //----------------------------------------------------------------------
  2137. bool cmCTest::GetProduceXML()
  2138. {
  2139. return this->ProduceXML;
  2140. }
  2141. //----------------------------------------------------------------------
  2142. const char* cmCTest::GetSpecificTrack()
  2143. {
  2144. if ( this->SpecificTrack.empty() )
  2145. {
  2146. return 0;
  2147. }
  2148. return this->SpecificTrack.c_str();
  2149. }
  2150. //----------------------------------------------------------------------
  2151. void cmCTest::SetSpecificTrack(const char* track)
  2152. {
  2153. if ( !track )
  2154. {
  2155. this->SpecificTrack = "";
  2156. return;
  2157. }
  2158. this->SpecificTrack = track;
  2159. }
  2160. //----------------------------------------------------------------------
  2161. void cmCTest::AddSubmitFile(const char* name)
  2162. {
  2163. this->SubmitFiles.insert(name);
  2164. }
  2165. //----------------------------------------------------------------------
  2166. void cmCTest::AddCTestConfigurationOverwrite(const char* encstr)
  2167. {
  2168. std::string overStr = encstr;
  2169. size_t epos = overStr.find("=");
  2170. if ( epos == overStr.npos )
  2171. {
  2172. cmCTestLog(this, ERROR_MESSAGE,
  2173. "CTest configuration overwrite specified in the wrong format."
  2174. << std::endl
  2175. << "Valid format is: --overwrite key=value" << std::endl
  2176. << "The specified was: --overwrite " << overStr.c_str() << std::endl);
  2177. return;
  2178. }
  2179. std::string key = overStr.substr(0, epos);
  2180. std::string value = overStr.substr(epos+1, overStr.npos);
  2181. this->CTestConfigurationOverwrites[key] = value;
  2182. }
  2183. //----------------------------------------------------------------------
  2184. void cmCTest::SetConfigType(const char* ct)
  2185. {
  2186. this->ConfigType = ct?ct:"";
  2187. cmSystemTools::ReplaceString(this->ConfigType, ".\\", "");
  2188. std::string confTypeEnv
  2189. = "CMAKE_CONFIG_TYPE=" + this->ConfigType;
  2190. cmSystemTools::PutEnv(confTypeEnv.c_str());
  2191. }
  2192. //----------------------------------------------------------------------
  2193. bool cmCTest::SetCTestConfigurationFromCMakeVariable(cmMakefile* mf,
  2194. const char* dconfig, const char* cmake_var)
  2195. {
  2196. const char* ctvar;
  2197. ctvar = mf->GetDefinition(cmake_var);
  2198. if ( !ctvar )
  2199. {
  2200. return false;
  2201. }
  2202. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  2203. "SetCTestConfigurationFromCMakeVariable:"
  2204. << dconfig << ":" << cmake_var);
  2205. this->SetCTestConfiguration(dconfig, ctvar);
  2206. return true;
  2207. }
  2208. bool cmCTest::RunCommand(
  2209. const char* command,
  2210. std::string* stdOut,
  2211. std::string* stdErr,
  2212. int *retVal,
  2213. const char* dir,
  2214. double timeout)
  2215. {
  2216. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  2217. if(args.size() < 1)
  2218. {
  2219. return false;
  2220. }
  2221. std::vector<const char*> argv;
  2222. for(std::vector<cmStdString>::const_iterator a = args.begin();
  2223. a != args.end(); ++a)
  2224. {
  2225. argv.push_back(a->c_str());
  2226. }
  2227. argv.push_back(0);
  2228. *stdOut = "";
  2229. *stdErr = "";
  2230. cmsysProcess* cp = cmsysProcess_New();
  2231. cmsysProcess_SetCommand(cp, &*argv.begin());
  2232. cmsysProcess_SetWorkingDirectory(cp, dir);
  2233. if(cmSystemTools::GetRunCommandHideConsole())
  2234. {
  2235. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2236. }
  2237. cmsysProcess_SetTimeout(cp, timeout);
  2238. cmsysProcess_Execute(cp);
  2239. std::vector<char> tempOutput;
  2240. std::vector<char> tempError;
  2241. char* data;
  2242. int length;
  2243. int res;
  2244. bool done = false;
  2245. while(!done)
  2246. {
  2247. res = cmsysProcess_WaitForData(cp, &data, &length, 0);
  2248. switch ( res )
  2249. {
  2250. case cmsysProcess_Pipe_STDOUT:
  2251. tempOutput.insert(tempOutput.end(), data, data+length);
  2252. break;
  2253. case cmsysProcess_Pipe_STDERR:
  2254. tempError.insert(tempError.end(), data, data+length);
  2255. break;
  2256. default:
  2257. done = true;
  2258. }
  2259. if ( (res == cmsysProcess_Pipe_STDOUT ||
  2260. res == cmsysProcess_Pipe_STDERR) && this->ExtraVerbose )
  2261. {
  2262. cmSystemTools::Stdout(data, length);
  2263. }
  2264. }
  2265. cmsysProcess_WaitForExit(cp, 0);
  2266. if ( tempOutput.size() > 0 )
  2267. {
  2268. stdOut->append(&*tempOutput.begin(), tempOutput.size());
  2269. }
  2270. if ( tempError.size() > 0 )
  2271. {
  2272. stdErr->append(&*tempError.begin(), tempError.size());
  2273. }
  2274. bool result = true;
  2275. if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
  2276. {
  2277. if ( retVal )
  2278. {
  2279. *retVal = cmsysProcess_GetExitValue(cp);
  2280. }
  2281. else
  2282. {
  2283. if ( cmsysProcess_GetExitValue(cp) != 0 )
  2284. {
  2285. result = false;
  2286. }
  2287. }
  2288. }
  2289. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exception)
  2290. {
  2291. const char* exception_str = cmsysProcess_GetExceptionString(cp);
  2292. cmCTestLog(this, ERROR_MESSAGE, exception_str << std::endl);
  2293. stdErr->append(exception_str, strlen(exception_str));
  2294. result = false;
  2295. }
  2296. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
  2297. {
  2298. const char* error_str = cmsysProcess_GetErrorString(cp);
  2299. cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
  2300. stdErr->append(error_str, strlen(error_str));
  2301. result = false;
  2302. }
  2303. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Expired)
  2304. {
  2305. const char* error_str = "Process terminated due to timeout\n";
  2306. cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
  2307. stdErr->append(error_str, strlen(error_str));
  2308. result = false;
  2309. }
  2310. cmsysProcess_Delete(cp);
  2311. return result;
  2312. }
  2313. //----------------------------------------------------------------------
  2314. void cmCTest::SetOutputLogFileName(const char* name)
  2315. {
  2316. if ( this->OutputLogFile)
  2317. {
  2318. delete this->OutputLogFile;
  2319. this->OutputLogFile= 0;
  2320. }
  2321. if ( name )
  2322. {
  2323. this->OutputLogFile = new cmGeneratedFileStream(name);
  2324. }
  2325. }
  2326. //----------------------------------------------------------------------
  2327. static const char* cmCTestStringLogType[] =
  2328. {
  2329. "DEBUG",
  2330. "OUTPUT",
  2331. "HANDLER_OUTPUT",
  2332. "HANDLER_VERBOSE_OUTPUT",
  2333. "WARNING",
  2334. "ERROR_MESSAGE",
  2335. 0
  2336. };
  2337. //----------------------------------------------------------------------
  2338. #ifdef cerr
  2339. # undef cerr
  2340. #endif
  2341. #ifdef cout
  2342. # undef cout
  2343. #endif
  2344. #define cmCTestLogOutputFileLine(stream) \
  2345. if ( this->ShowLineNumbers ) \
  2346. { \
  2347. (stream) << std::endl << file << ":" << line << " "; \
  2348. }
  2349. void cmCTest::Log(int logType, const char* file, int line, const char* msg)
  2350. {
  2351. if ( !msg || !*msg )
  2352. {
  2353. return;
  2354. }
  2355. if ( this->OutputLogFile )
  2356. {
  2357. bool display = true;
  2358. if ( logType == cmCTest::DEBUG && !this->Debug ) { display = false; }
  2359. if ( logType == cmCTest::HANDLER_VERBOSE_OUTPUT && !this->Debug &&
  2360. !this->ExtraVerbose ) { display = false; }
  2361. if ( display )
  2362. {
  2363. cmCTestLogOutputFileLine(*this->OutputLogFile);
  2364. if ( logType != this->OutputLogFileLastTag )
  2365. {
  2366. *this->OutputLogFile << "[";
  2367. if ( logType >= OTHER || logType < 0 )
  2368. {
  2369. *this->OutputLogFile << "OTHER";
  2370. }
  2371. else
  2372. {
  2373. *this->OutputLogFile << cmCTestStringLogType[logType];
  2374. }
  2375. *this->OutputLogFile << "] " << std::endl << std::flush;
  2376. }
  2377. *this->OutputLogFile << msg << std::flush;
  2378. if ( logType != this->OutputLogFileLastTag )
  2379. {
  2380. *this->OutputLogFile << std::endl << std::flush;
  2381. this->OutputLogFileLastTag = logType;
  2382. }
  2383. }
  2384. }
  2385. if ( !this->Quiet )
  2386. {
  2387. switch ( logType )
  2388. {
  2389. case DEBUG:
  2390. if ( this->Debug )
  2391. {
  2392. cmCTestLogOutputFileLine(std::cout);
  2393. std::cout << msg;
  2394. std::cout.flush();
  2395. }
  2396. break;
  2397. case OUTPUT: case HANDLER_OUTPUT:
  2398. if ( this->Debug || this->Verbose )
  2399. {
  2400. cmCTestLogOutputFileLine(std::cout);
  2401. std::cout << msg;
  2402. std::cout.flush();
  2403. }
  2404. break;
  2405. case HANDLER_VERBOSE_OUTPUT:
  2406. if ( this->Debug || this->ExtraVerbose )
  2407. {
  2408. cmCTestLogOutputFileLine(std::cout);
  2409. std::cout << msg;
  2410. std::cout.flush();
  2411. }
  2412. break;
  2413. case WARNING:
  2414. cmCTestLogOutputFileLine(std::cerr);
  2415. std::cerr << msg;
  2416. std::cerr.flush();
  2417. break;
  2418. case ERROR_MESSAGE:
  2419. cmCTestLogOutputFileLine(std::cerr);
  2420. std::cerr << msg;
  2421. std::cerr.flush();
  2422. cmSystemTools::SetErrorOccured();
  2423. break;
  2424. default:
  2425. cmCTestLogOutputFileLine(std::cout);
  2426. std::cout << msg;
  2427. std::cout.flush();
  2428. }
  2429. }
  2430. }
  2431. //-------------------------------------------------------------------------
  2432. double cmCTest::GetRemainingTimeAllowed()
  2433. {
  2434. if (!this->GetHandler("script"))
  2435. {
  2436. return 1.0e7;
  2437. }
  2438. cmCTestScriptHandler* ch
  2439. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  2440. return ch->GetRemainingTimeAllowed();
  2441. }