cmCTest.cxx 72 KB

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