cmCTest.cxx 59 KB

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