cmCTest.cxx 69 KB

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