cmCTest.cxx 75 KB

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