cmCTestTestHandler.cxx 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149
  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 "cmCTestTestHandler.h"
  14. #include "cmCTestMultiProcessHandler.h"
  15. #include "cmCTestBatchTestHandler.h"
  16. #include "cmCTest.h"
  17. #include "cmCTestRunTest.h"
  18. #include "cmake.h"
  19. #include "cmGeneratedFileStream.h"
  20. #include <cmsys/Process.h>
  21. #include <cmsys/RegularExpression.hxx>
  22. #include <cmsys/Base64.h>
  23. #include "cmMakefile.h"
  24. #include "cmGlobalGenerator.h"
  25. #include "cmLocalGenerator.h"
  26. #include "cmCommand.h"
  27. #include "cmSystemTools.h"
  28. #include "cmXMLSafe.h"
  29. #include <stdlib.h>
  30. #include <math.h>
  31. #include <float.h>
  32. #include <memory> // auto_ptr
  33. //----------------------------------------------------------------------
  34. class cmCTestSubdirCommand : public cmCommand
  35. {
  36. public:
  37. /**
  38. * This is a virtual constructor for the command.
  39. */
  40. virtual cmCommand* Clone()
  41. {
  42. cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
  43. c->TestHandler = this->TestHandler;
  44. return c;
  45. }
  46. /**
  47. * This is called when the command is first encountered in
  48. * the CMakeLists.txt file.
  49. */
  50. virtual bool InitialPass(std::vector<std::string> const& args,
  51. cmExecutionStatus &);
  52. /**
  53. * The name of the command as specified in CMakeList.txt.
  54. */
  55. virtual const char* GetName() { return "subdirs";}
  56. // Unused methods
  57. virtual const char* GetTerseDocumentation() { return ""; }
  58. virtual const char* GetFullDocumentation() { return ""; }
  59. cmTypeMacro(cmCTestSubdirCommand, cmCommand);
  60. cmCTestTestHandler* TestHandler;
  61. };
  62. //----------------------------------------------------------------------
  63. bool cmCTestSubdirCommand
  64. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  65. {
  66. if(args.size() < 1 )
  67. {
  68. this->SetError("called with incorrect number of arguments");
  69. return false;
  70. }
  71. std::vector<std::string>::const_iterator it;
  72. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  73. for ( it = args.begin(); it != args.end(); ++ it )
  74. {
  75. cmSystemTools::ChangeDirectory(cwd.c_str());
  76. std::string fname = cwd;
  77. fname += "/";
  78. fname += *it;
  79. if ( !cmSystemTools::FileExists(fname.c_str()) )
  80. {
  81. // No subdirectory? So what...
  82. continue;
  83. }
  84. cmSystemTools::ChangeDirectory(fname.c_str());
  85. const char* testFilename;
  86. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  87. {
  88. // does the CTestTestfile.cmake exist ?
  89. testFilename = "CTestTestfile.cmake";
  90. }
  91. else if( cmSystemTools::FileExists("DartTestfile.txt") )
  92. {
  93. // does the DartTestfile.txt exist ?
  94. testFilename = "DartTestfile.txt";
  95. }
  96. else
  97. {
  98. // No CTestTestfile? Who cares...
  99. cmSystemTools::ChangeDirectory(cwd.c_str());
  100. continue;
  101. }
  102. fname += "/";
  103. fname += testFilename;
  104. bool readit =
  105. this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),
  106. fname.c_str());
  107. cmSystemTools::ChangeDirectory(cwd.c_str());
  108. if(!readit)
  109. {
  110. std::string m = "Could not find include file: ";
  111. m += fname;
  112. this->SetError(m.c_str());
  113. return false;
  114. }
  115. }
  116. return true;
  117. }
  118. //----------------------------------------------------------------------
  119. class cmCTestAddSubdirectoryCommand : public cmCommand
  120. {
  121. public:
  122. /**
  123. * This is a virtual constructor for the command.
  124. */
  125. virtual cmCommand* Clone()
  126. {
  127. cmCTestAddSubdirectoryCommand* c = new cmCTestAddSubdirectoryCommand;
  128. c->TestHandler = this->TestHandler;
  129. return c;
  130. }
  131. /**
  132. * This is called when the command is first encountered in
  133. * the CMakeLists.txt file.
  134. */
  135. virtual bool InitialPass(std::vector<std::string> const& args,
  136. cmExecutionStatus &);
  137. /**
  138. * The name of the command as specified in CMakeList.txt.
  139. */
  140. virtual const char* GetName() { return "add_subdirectory";}
  141. // Unused methods
  142. virtual const char* GetTerseDocumentation() { return ""; }
  143. virtual const char* GetFullDocumentation() { return ""; }
  144. cmTypeMacro(cmCTestAddSubdirectoryCommand, cmCommand);
  145. cmCTestTestHandler* TestHandler;
  146. };
  147. //----------------------------------------------------------------------
  148. bool cmCTestAddSubdirectoryCommand
  149. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  150. {
  151. if(args.size() < 1 )
  152. {
  153. this->SetError("called with incorrect number of arguments");
  154. return false;
  155. }
  156. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  157. cmSystemTools::ChangeDirectory(cwd.c_str());
  158. std::string fname = cwd;
  159. fname += "/";
  160. fname += args[1];
  161. if ( !cmSystemTools::FileExists(fname.c_str()) )
  162. {
  163. // No subdirectory? So what...
  164. return true;
  165. }
  166. cmSystemTools::ChangeDirectory(fname.c_str());
  167. const char* testFilename;
  168. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  169. {
  170. // does the CTestTestfile.cmake exist ?
  171. testFilename = "CTestTestfile.cmake";
  172. }
  173. else if( cmSystemTools::FileExists("DartTestfile.txt") )
  174. {
  175. // does the DartTestfile.txt exist ?
  176. testFilename = "DartTestfile.txt";
  177. }
  178. else
  179. {
  180. // No CTestTestfile? Who cares...
  181. cmSystemTools::ChangeDirectory(cwd.c_str());
  182. return true;
  183. }
  184. fname += "/";
  185. fname += testFilename;
  186. bool readit =
  187. this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),
  188. fname.c_str());
  189. cmSystemTools::ChangeDirectory(cwd.c_str());
  190. if(!readit)
  191. {
  192. std::string m = "Could not find include file: ";
  193. m += fname;
  194. this->SetError(m.c_str());
  195. return false;
  196. }
  197. return true;
  198. }
  199. //----------------------------------------------------------------------
  200. class cmCTestAddTestCommand : public cmCommand
  201. {
  202. public:
  203. /**
  204. * This is a virtual constructor for the command.
  205. */
  206. virtual cmCommand* Clone()
  207. {
  208. cmCTestAddTestCommand* c = new cmCTestAddTestCommand;
  209. c->TestHandler = this->TestHandler;
  210. return c;
  211. }
  212. /**
  213. * This is called when the command is first encountered in
  214. * the CMakeLists.txt file.
  215. */
  216. virtual bool InitialPass(std::vector<std::string> const&,
  217. cmExecutionStatus &);
  218. /**
  219. * The name of the command as specified in CMakeList.txt.
  220. */
  221. virtual const char* GetName() { return "ADD_TEST";}
  222. // Unused methods
  223. virtual const char* GetTerseDocumentation() { return ""; }
  224. virtual const char* GetFullDocumentation() { return ""; }
  225. cmTypeMacro(cmCTestAddTestCommand, cmCommand);
  226. cmCTestTestHandler* TestHandler;
  227. };
  228. //----------------------------------------------------------------------
  229. bool cmCTestAddTestCommand
  230. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  231. {
  232. if ( args.size() < 2 )
  233. {
  234. this->SetError("called with incorrect number of arguments");
  235. return false;
  236. }
  237. return this->TestHandler->AddTest(args);
  238. }
  239. //----------------------------------------------------------------------
  240. class cmCTestSetTestsPropertiesCommand : public cmCommand
  241. {
  242. public:
  243. /**
  244. * This is a virtual constructor for the command.
  245. */
  246. virtual cmCommand* Clone()
  247. {
  248. cmCTestSetTestsPropertiesCommand* c
  249. = new cmCTestSetTestsPropertiesCommand;
  250. c->TestHandler = this->TestHandler;
  251. return c;
  252. }
  253. /**
  254. * This is called when the command is first encountered in
  255. * the CMakeLists.txt file.
  256. */
  257. virtual bool InitialPass(std::vector<std::string> const&,
  258. cmExecutionStatus &);
  259. /**
  260. * The name of the command as specified in CMakeList.txt.
  261. */
  262. virtual const char* GetName() { return "SET_TESTS_PROPERTIES";}
  263. // Unused methods
  264. virtual const char* GetTerseDocumentation() { return ""; }
  265. virtual const char* GetFullDocumentation() { return ""; }
  266. cmTypeMacro(cmCTestSetTestsPropertiesCommand, cmCommand);
  267. cmCTestTestHandler* TestHandler;
  268. };
  269. //----------------------------------------------------------------------
  270. bool cmCTestSetTestsPropertiesCommand
  271. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  272. {
  273. return this->TestHandler->SetTestsProperties(args);
  274. }
  275. //----------------------------------------------------------------------
  276. // get the next number in a string with numbers separated by ,
  277. // pos is the start of the search and pos2 is the end of the search
  278. // pos becomes pos2 after a call to GetNextNumber.
  279. // -1 is returned at the end of the list.
  280. inline int GetNextNumber(std::string const& in,
  281. int& val,
  282. std::string::size_type& pos,
  283. std::string::size_type& pos2)
  284. {
  285. pos2 = in.find(',', pos);
  286. if(pos2 != in.npos)
  287. {
  288. if(pos2-pos == 0)
  289. {
  290. val = -1;
  291. }
  292. else
  293. {
  294. val = atoi(in.substr(pos, pos2-pos).c_str());
  295. }
  296. pos = pos2+1;
  297. return 1;
  298. }
  299. else
  300. {
  301. if(in.size()-pos == 0)
  302. {
  303. val = -1;
  304. }
  305. else
  306. {
  307. val = atoi(in.substr(pos, in.size()-pos).c_str());
  308. }
  309. return 0;
  310. }
  311. }
  312. //----------------------------------------------------------------------
  313. // get the next number in a string with numbers separated by ,
  314. // pos is the start of the search and pos2 is the end of the search
  315. // pos becomes pos2 after a call to GetNextNumber.
  316. // -1 is returned at the end of the list.
  317. inline int GetNextRealNumber(std::string const& in,
  318. double& val,
  319. std::string::size_type& pos,
  320. std::string::size_type& pos2)
  321. {
  322. pos2 = in.find(',', pos);
  323. if(pos2 != in.npos)
  324. {
  325. if(pos2-pos == 0)
  326. {
  327. val = -1;
  328. }
  329. else
  330. {
  331. val = atof(in.substr(pos, pos2-pos).c_str());
  332. }
  333. pos = pos2+1;
  334. return 1;
  335. }
  336. else
  337. {
  338. if(in.size()-pos == 0)
  339. {
  340. val = -1;
  341. }
  342. else
  343. {
  344. val = atof(in.substr(pos, in.size()-pos).c_str());
  345. }
  346. return 0;
  347. }
  348. }
  349. //----------------------------------------------------------------------
  350. cmCTestTestHandler::cmCTestTestHandler()
  351. {
  352. this->UseUnion = false;
  353. this->UseIncludeLabelRegExpFlag = false;
  354. this->UseExcludeLabelRegExpFlag = false;
  355. this->UseIncludeRegExpFlag = false;
  356. this->UseExcludeRegExpFlag = false;
  357. this->UseExcludeRegExpFirst = false;
  358. this->CustomMaximumPassedTestOutputSize = 1 * 1024;
  359. this->CustomMaximumFailedTestOutputSize = 300 * 1024;
  360. this->MemCheck = false;
  361. this->LogFile = 0;
  362. // regex to detect <DartMeasurement>...</DartMeasurement>
  363. this->DartStuff.compile(
  364. "(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  365. // regex to detect each individual <DartMeasurement>...</DartMeasurement>
  366. this->DartStuff1.compile(
  367. "(<DartMeasurement[^<]*</DartMeasurement[a-zA-Z]*>)");
  368. }
  369. //----------------------------------------------------------------------
  370. void cmCTestTestHandler::Initialize()
  371. {
  372. this->Superclass::Initialize();
  373. this->ElapsedTestingTime = -1;
  374. this->TestResults.clear();
  375. this->CustomTestsIgnore.clear();
  376. this->StartTest = "";
  377. this->EndTest = "";
  378. this->CustomPreTest.clear();
  379. this->CustomPostTest.clear();
  380. this->CustomMaximumPassedTestOutputSize = 1 * 1024;
  381. this->CustomMaximumFailedTestOutputSize = 300 * 1024;
  382. this->TestsToRun.clear();
  383. this->UseIncludeRegExpFlag = false;
  384. this->UseExcludeRegExpFlag = false;
  385. this->UseExcludeRegExpFirst = false;
  386. this->IncludeLabelRegularExpression = "";
  387. this->ExcludeLabelRegularExpression = "";
  388. this->IncludeRegExp = "";
  389. this->ExcludeRegExp = "";
  390. TestsToRunString = "";
  391. this->UseUnion = false;
  392. this->TestList.clear();
  393. }
  394. //----------------------------------------------------------------------
  395. void cmCTestTestHandler::PopulateCustomVectors(cmMakefile *mf)
  396. {
  397. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST",
  398. this->CustomPreTest);
  399. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST",
  400. this->CustomPostTest);
  401. this->CTest->PopulateCustomVector(mf,
  402. "CTEST_CUSTOM_TESTS_IGNORE",
  403. this->CustomTestsIgnore);
  404. this->CTest->PopulateCustomInteger(mf,
  405. "CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE",
  406. this->CustomMaximumPassedTestOutputSize);
  407. this->CTest->PopulateCustomInteger(mf,
  408. "CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE",
  409. this->CustomMaximumFailedTestOutputSize);
  410. }
  411. //----------------------------------------------------------------------
  412. int cmCTestTestHandler::PreProcessHandler()
  413. {
  414. if ( !this->ExecuteCommands(this->CustomPreTest) )
  415. {
  416. cmCTestLog(this->CTest, ERROR_MESSAGE,
  417. "Problem executing pre-test command(s)." << std::endl);
  418. return 0;
  419. }
  420. return 1;
  421. }
  422. //----------------------------------------------------------------------
  423. int cmCTestTestHandler::PostProcessHandler()
  424. {
  425. if ( !this->ExecuteCommands(this->CustomPostTest) )
  426. {
  427. cmCTestLog(this->CTest, ERROR_MESSAGE,
  428. "Problem executing post-test command(s)." << std::endl);
  429. return 0;
  430. }
  431. return 1;
  432. }
  433. //----------------------------------------------------------------------
  434. //clearly it would be nice if this were broken up into a few smaller
  435. //functions and commented...
  436. int cmCTestTestHandler::ProcessHandler()
  437. {
  438. // Update internal data structure from generic one
  439. this->SetTestsToRunInformation(this->GetOption("TestsToRunInformation"));
  440. this->SetUseUnion(cmSystemTools::IsOn(this->GetOption("UseUnion")));
  441. if(this->GetOption("ParallelLevel"))
  442. {
  443. this->CTest->SetParallelLevel(atoi(this->GetOption("ParallelLevel")));
  444. }
  445. const char* val;
  446. val = this->GetOption("LabelRegularExpression");
  447. if ( val )
  448. {
  449. this->UseIncludeLabelRegExpFlag = true;
  450. this->IncludeLabelRegExp = val;
  451. }
  452. val = this->GetOption("ExcludeLabelRegularExpression");
  453. if ( val )
  454. {
  455. this->UseExcludeLabelRegExpFlag = true;
  456. this->ExcludeLabelRegularExpression = val;
  457. }
  458. val = this->GetOption("IncludeRegularExpression");
  459. if ( val )
  460. {
  461. this->UseIncludeRegExp();
  462. this->SetIncludeRegExp(val);
  463. }
  464. val = this->GetOption("ExcludeRegularExpression");
  465. if ( val )
  466. {
  467. this->UseExcludeRegExp();
  468. this->SetExcludeRegExp(val);
  469. }
  470. this->TestResults.clear();
  471. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  472. (this->MemCheck ? "Memory check" : "Test")
  473. << " project " << cmSystemTools::GetCurrentWorkingDirectory()
  474. << std::endl);
  475. if ( ! this->PreProcessHandler() )
  476. {
  477. return -1;
  478. }
  479. cmGeneratedFileStream mLogFile;
  480. this->StartLogFile((this->MemCheck ? "DynamicAnalysis" : "Test"), mLogFile);
  481. this->LogFile = &mLogFile;
  482. std::vector<cmStdString> passed;
  483. std::vector<cmStdString> failed;
  484. int total;
  485. //start the real time clock
  486. double clock_start, clock_finish;
  487. clock_start = cmSystemTools::GetTime();
  488. this->ProcessDirectory(passed, failed);
  489. clock_finish = cmSystemTools::GetTime();
  490. total = int(passed.size()) + int(failed.size());
  491. if (total == 0)
  492. {
  493. if ( !this->CTest->GetShowOnly() )
  494. {
  495. cmCTestLog(this->CTest, ERROR_MESSAGE, "No tests were found!!!"
  496. << std::endl);
  497. }
  498. }
  499. else
  500. {
  501. if (this->HandlerVerbose && passed.size() &&
  502. (this->UseIncludeRegExpFlag || this->UseExcludeRegExpFlag))
  503. {
  504. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
  505. << "The following tests passed:" << std::endl);
  506. for(std::vector<cmStdString>::iterator j = passed.begin();
  507. j != passed.end(); ++j)
  508. {
  509. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "\t" << *j
  510. << std::endl);
  511. }
  512. }
  513. float percent = float(passed.size()) * 100.0f / total;
  514. if ( failed.size() > 0 && percent > 99)
  515. {
  516. percent = 99;
  517. }
  518. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
  519. << static_cast<int>(percent + .5) << "% tests passed, "
  520. << failed.size() << " tests failed out of "
  521. << total << std::endl);
  522. double totalTestTime = 0;
  523. for(cmCTestTestHandler::TestResultsVector::size_type cc = 0;
  524. cc < this->TestResults.size(); cc ++ )
  525. {
  526. cmCTestTestResult *result = &this->TestResults[cc];
  527. totalTestTime += result->ExecutionTime;
  528. }
  529. char realBuf[1024];
  530. sprintf(realBuf, "%6.2f sec", (double)(clock_finish - clock_start));
  531. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\nTotal Test time (real) = "
  532. << realBuf << "\n" );
  533. char totalBuf[1024];
  534. sprintf(totalBuf, "%6.2f sec", totalTestTime);
  535. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\nTotal Test time (parallel) = "
  536. << totalBuf << "\n" );
  537. if (failed.size())
  538. {
  539. cmGeneratedFileStream ofs;
  540. cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl
  541. << "The following tests FAILED:" << std::endl);
  542. this->StartLogFile("TestsFailed", ofs);
  543. std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator ftit;
  544. for(ftit = this->TestResults.begin();
  545. ftit != this->TestResults.end(); ++ftit)
  546. {
  547. if ( ftit->Status != cmCTestTestHandler::COMPLETED )
  548. {
  549. ofs << ftit->TestCount << ":" << ftit->Name << std::endl;
  550. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t" << std::setw(3)
  551. << ftit->TestCount << " - "
  552. << ftit->Name.c_str() << " ("
  553. << this->GetTestStatus(ftit->Status) << ")"
  554. << std::endl);
  555. }
  556. }
  557. }
  558. }
  559. if ( this->CTest->GetProduceXML() )
  560. {
  561. cmGeneratedFileStream xmlfile;
  562. if( !this->StartResultingXML(
  563. (this->MemCheck ? cmCTest::PartMemCheck : cmCTest::PartTest),
  564. (this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile) )
  565. {
  566. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create "
  567. << (this->MemCheck ? "memory check" : "testing")
  568. << " XML file" << std::endl);
  569. this->LogFile = 0;
  570. return 1;
  571. }
  572. this->GenerateDartOutput(xmlfile);
  573. }
  574. if ( ! this->PostProcessHandler() )
  575. {
  576. this->LogFile = 0;
  577. return -1;
  578. }
  579. if ( !failed.empty() )
  580. {
  581. this->LogFile = 0;
  582. return -1;
  583. }
  584. this->LogFile = 0;
  585. return 0;
  586. }
  587. //----------------------------------------------------------------------
  588. void cmCTestTestHandler::PrintLabelSummary()
  589. {
  590. cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin();
  591. cmCTestTestHandler::TestResultsVector::iterator ri =
  592. this->TestResults.begin();
  593. std::map<cmStdString, double> labelTimes;
  594. std::set<cmStdString> labels;
  595. // initialize maps
  596. for(; it != this->TestList.end(); ++it)
  597. {
  598. cmCTestTestProperties& p = *it;
  599. if(p.Labels.size() != 0)
  600. {
  601. for(std::vector<std::string>::iterator l = p.Labels.begin();
  602. l != p.Labels.end(); ++l)
  603. {
  604. labels.insert(*l);
  605. labelTimes[*l] = 0;
  606. }
  607. }
  608. }
  609. it = this->TestList.begin();
  610. ri = this->TestResults.begin();
  611. // fill maps
  612. for(; it != this->TestList.end(); ++it, ++ri)
  613. {
  614. cmCTestTestProperties& p = *it;
  615. cmCTestTestResult &result = *ri;
  616. if(p.Labels.size() != 0)
  617. {
  618. for(std::vector<std::string>::iterator l = p.Labels.begin();
  619. l != p.Labels.end(); ++l)
  620. {
  621. labelTimes[*l] += result.ExecutionTime;
  622. }
  623. }
  624. }
  625. // now print times
  626. for(std::set<cmStdString>::const_iterator i = labels.begin();
  627. i != labels.end(); ++i)
  628. {
  629. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\nTime in "
  630. << *i << " = " << labelTimes[*i] << " sec" );
  631. if ( this->LogFile )
  632. {
  633. *this->LogFile << "\nTime in " << *i << " = "
  634. << labelTimes[*i] << " sec" << std::endl;
  635. }
  636. }
  637. }
  638. //----------------------------------------------------------------------
  639. void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it)
  640. {
  641. // if not using Labels to filter then return
  642. if (!this->UseIncludeLabelRegExpFlag )
  643. {
  644. return;
  645. }
  646. // if there are no labels and we are filtering by labels
  647. // then exclude the test as it does not have the label
  648. if(it.Labels.size() == 0 )
  649. {
  650. it.IsInBasedOnREOptions = false;
  651. return;
  652. }
  653. // check to see if the label regular expression matches
  654. bool found = false; // assume it does not match
  655. // loop over all labels and look for match
  656. for(std::vector<std::string>::iterator l = it.Labels.begin();
  657. l != it.Labels.end(); ++l)
  658. {
  659. if(this->IncludeLabelRegularExpression.find(*l))
  660. {
  661. found = true;
  662. }
  663. }
  664. // if no match was found, exclude the test
  665. if(!found)
  666. {
  667. it.IsInBasedOnREOptions = false;
  668. }
  669. }
  670. //----------------------------------------------------------------------
  671. void cmCTestTestHandler::CheckLabelFilterExclude(cmCTestTestProperties& it)
  672. {
  673. // if not using Labels to filter then return
  674. if (!this->UseExcludeLabelRegExpFlag )
  675. {
  676. return;
  677. }
  678. // if there are no labels and we are excluding by labels
  679. // then do nothing as a no label can not be a match
  680. if(it.Labels.size() == 0 )
  681. {
  682. return;
  683. }
  684. // check to see if the label regular expression matches
  685. bool found = false; // assume it does not match
  686. // loop over all labels and look for match
  687. for(std::vector<std::string>::iterator l = it.Labels.begin();
  688. l != it.Labels.end(); ++l)
  689. {
  690. if(this->ExcludeLabelRegularExpression.find(*l))
  691. {
  692. found = true;
  693. }
  694. }
  695. // if match was found, exclude the test
  696. if(found)
  697. {
  698. it.IsInBasedOnREOptions = false;
  699. }
  700. }
  701. //----------------------------------------------------------------------
  702. void cmCTestTestHandler::CheckLabelFilter(cmCTestTestProperties& it)
  703. {
  704. this->CheckLabelFilterInclude(it);
  705. this->CheckLabelFilterExclude(it);
  706. }
  707. //----------------------------------------------------------------------
  708. void cmCTestTestHandler::ComputeTestList()
  709. {
  710. this->TestList.clear(); // clear list of test
  711. this->GetListOfTests();
  712. cmCTestTestHandler::ListOfTests::size_type tmsize = this->TestList.size();
  713. // how many tests are in based on RegExp?
  714. int inREcnt = 0;
  715. cmCTestTestHandler::ListOfTests::iterator it;
  716. for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
  717. {
  718. this->CheckLabelFilter(*it);
  719. if (it->IsInBasedOnREOptions)
  720. {
  721. inREcnt ++;
  722. }
  723. }
  724. // expand the test list based on the union flag
  725. if (this->UseUnion)
  726. {
  727. this->ExpandTestsToRunInformation((int)tmsize);
  728. }
  729. else
  730. {
  731. this->ExpandTestsToRunInformation(inREcnt);
  732. }
  733. // Now create a final list of tests to run
  734. int cnt = 0;
  735. inREcnt = 0;
  736. std::string last_directory = "";
  737. ListOfTests finalList;
  738. for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
  739. {
  740. cnt ++;
  741. if (it->IsInBasedOnREOptions)
  742. {
  743. inREcnt++;
  744. }
  745. if (this->UseUnion)
  746. {
  747. // if it is not in the list and not in the regexp then skip
  748. if ((this->TestsToRun.size() &&
  749. std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt)
  750. == this->TestsToRun.end()) && !it->IsInBasedOnREOptions)
  751. {
  752. continue;
  753. }
  754. }
  755. else
  756. {
  757. // is this test in the list of tests to run? If not then skip it
  758. if ((this->TestsToRun.size() &&
  759. std::find(this->TestsToRun.begin(),
  760. this->TestsToRun.end(), inREcnt)
  761. == this->TestsToRun.end()) || !it->IsInBasedOnREOptions)
  762. {
  763. continue;
  764. }
  765. }
  766. it->Index = cnt; // save the index into the test list for this test
  767. finalList.push_back(*it);
  768. }
  769. // Save the total number of tests before exclusions
  770. this->TotalNumberOfTests = this->TestList.size();
  771. // Set the TestList to the final list of all test
  772. this->TestList = finalList;
  773. std::string::size_type max = this->CTest->GetMaxTestNameWidth();
  774. for (it = this->TestList.begin();
  775. it != this->TestList.end(); it ++ )
  776. {
  777. cmCTestTestProperties& p = *it;
  778. if(max < p.Name.size())
  779. {
  780. max = p.Name.size();
  781. }
  782. }
  783. if(static_cast<std::string::size_type>(this->CTest->GetMaxTestNameWidth())
  784. != max)
  785. {
  786. this->CTest->SetMaxTestNameWidth(static_cast<int>(max));
  787. }
  788. }
  789. bool cmCTestTestHandler::GetValue(const char* tag,
  790. int& value,
  791. std::ifstream& fin)
  792. {
  793. std::string line;
  794. bool ret = true;
  795. cmSystemTools::GetLineFromStream(fin, line);
  796. if(line == tag)
  797. {
  798. fin >> value;
  799. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  800. }
  801. else
  802. {
  803. cmCTestLog(this->CTest, ERROR_MESSAGE,
  804. "parse error: missing tag: "
  805. << tag << " found [" << line << "]" << std::endl);
  806. ret = false;
  807. }
  808. return ret;
  809. }
  810. bool cmCTestTestHandler::GetValue(const char* tag,
  811. double& value,
  812. std::ifstream& fin)
  813. {
  814. std::string line;
  815. cmSystemTools::GetLineFromStream(fin, line);
  816. bool ret = true;
  817. if(line == tag)
  818. {
  819. fin >> value;
  820. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  821. }
  822. else
  823. {
  824. cmCTestLog(this->CTest, ERROR_MESSAGE,
  825. "parse error: missing tag: "
  826. << tag << " found [" << line << "]" << std::endl);
  827. ret = false;
  828. }
  829. return ret;
  830. }
  831. bool cmCTestTestHandler::GetValue(const char* tag,
  832. bool& value,
  833. std::ifstream& fin)
  834. {
  835. std::string line;
  836. cmSystemTools::GetLineFromStream(fin, line);
  837. bool ret = true;
  838. if(line == tag)
  839. {
  840. #ifdef __HAIKU__
  841. int tmp = 0;
  842. fin >> tmp;
  843. value = false;
  844. if(tmp)
  845. {
  846. value = true;
  847. }
  848. #else
  849. fin >> value;
  850. #endif
  851. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  852. }
  853. else
  854. {
  855. cmCTestLog(this->CTest, ERROR_MESSAGE,
  856. "parse error: missing tag: "
  857. << tag << " found [" << line << "]" << std::endl);
  858. ret = false;
  859. }
  860. return ret;
  861. }
  862. bool cmCTestTestHandler::GetValue(const char* tag,
  863. size_t& value,
  864. std::ifstream& fin)
  865. {
  866. std::string line;
  867. cmSystemTools::GetLineFromStream(fin, line);
  868. bool ret = true;
  869. if(line == tag)
  870. {
  871. fin >> value;
  872. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  873. }
  874. else
  875. {
  876. cmCTestLog(this->CTest, ERROR_MESSAGE,
  877. "parse error: missing tag: "
  878. << tag << " found [" << line.c_str() << "]" << std::endl);
  879. ret = false;
  880. }
  881. return ret;
  882. }
  883. bool cmCTestTestHandler::GetValue(const char* tag,
  884. std::string& value,
  885. std::ifstream& fin)
  886. {
  887. std::string line;
  888. cmSystemTools::GetLineFromStream(fin, line);
  889. bool ret = true;
  890. if(line == tag)
  891. {
  892. ret = cmSystemTools::GetLineFromStream(fin, value);
  893. }
  894. else
  895. {
  896. cmCTestLog(this->CTest, ERROR_MESSAGE,
  897. "parse error: missing tag: "
  898. << tag << " found [" << line << "]" << std::endl);
  899. ret = false;
  900. }
  901. return ret;
  902. }
  903. //---------------------------------------------------------------------
  904. void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
  905. std::vector<cmStdString> &failed)
  906. {
  907. this->ComputeTestList();
  908. this->StartTest = this->CTest->CurrentTime();
  909. this->StartTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
  910. double elapsed_time_start = cmSystemTools::GetTime();
  911. cmCTestMultiProcessHandler* parallel = this->CTest->GetBatchJobs() ?
  912. new cmCTestBatchTestHandler : new cmCTestMultiProcessHandler;
  913. parallel->SetCTest(this->CTest);
  914. parallel->SetParallelLevel(this->CTest->GetParallelLevel());
  915. parallel->SetTestHandler(this);
  916. *this->LogFile << "Start testing: "
  917. << this->CTest->CurrentTime() << std::endl
  918. << "----------------------------------------------------------"
  919. << std::endl;
  920. cmCTestMultiProcessHandler::TestMap tests;
  921. cmCTestMultiProcessHandler::PropertiesMap properties;
  922. for (ListOfTests::iterator it = this->TestList.begin();
  923. it != this->TestList.end(); ++it)
  924. {
  925. cmCTestTestProperties& p = *it;
  926. cmCTestMultiProcessHandler::TestSet depends;
  927. if(p.Depends.size())
  928. {
  929. for(std::vector<std::string>::iterator i = p.Depends.begin();
  930. i != p.Depends.end(); ++i)
  931. {
  932. for(ListOfTests::iterator it2 = this->TestList.begin();
  933. it2 != this->TestList.end(); ++it2)
  934. {
  935. if(it2->Name == *i)
  936. {
  937. depends.insert(it2->Index);
  938. break; // break out of test loop as name can only match 1
  939. }
  940. }
  941. }
  942. }
  943. tests[it->Index] = depends;
  944. properties[it->Index] = &*it;
  945. }
  946. parallel->SetTests(tests, properties);
  947. parallel->SetPassFailVectors(&passed, &failed);
  948. this->TestResults.clear();
  949. parallel->SetTestResults(&this->TestResults);
  950. if(this->CTest->GetShowOnly())
  951. {
  952. parallel->PrintTestList();
  953. }
  954. else
  955. {
  956. parallel->RunTests();
  957. }
  958. delete parallel;
  959. this->EndTest = this->CTest->CurrentTime();
  960. this->EndTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
  961. this->ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
  962. *this->LogFile << "End testing: "
  963. << this->CTest->CurrentTime() << std::endl;
  964. }
  965. //----------------------------------------------------------------------
  966. void cmCTestTestHandler::GenerateTestCommand(std::vector<std::string>&)
  967. {
  968. }
  969. //----------------------------------------------------------------------
  970. void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
  971. {
  972. if ( !this->CTest->GetProduceXML() )
  973. {
  974. return;
  975. }
  976. this->CTest->StartXML(os, this->AppendXML);
  977. os << "<Testing>\n"
  978. << "\t<StartDateTime>" << this->StartTest << "</StartDateTime>\n"
  979. << "\t<StartTestTime>" << this->StartTestTime << "</StartTestTime>\n"
  980. << "\t<TestList>\n";
  981. cmCTestTestHandler::TestResultsVector::size_type cc;
  982. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  983. {
  984. cmCTestTestResult *result = &this->TestResults[cc];
  985. std::string testPath = result->Path + "/" + result->Name;
  986. os << "\t\t<Test>" << cmXMLSafe(
  987. this->CTest->GetShortPathToFile(testPath.c_str()))
  988. << "</Test>" << std::endl;
  989. }
  990. os << "\t</TestList>\n";
  991. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  992. {
  993. cmCTestTestResult *result = &this->TestResults[cc];
  994. this->WriteTestResultHeader(os, result);
  995. os << "\t\t<Results>" << std::endl;
  996. if ( result->Status != cmCTestTestHandler::NOT_RUN )
  997. {
  998. if ( result->Status != cmCTestTestHandler::COMPLETED ||
  999. result->ReturnValue )
  1000. {
  1001. os << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1002. "name=\"Exit Code\"><Value>"
  1003. << cmXMLSafe(this->GetTestStatus(result->Status))
  1004. << "</Value>"
  1005. "</NamedMeasurement>\n"
  1006. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1007. "name=\"Exit Value\"><Value>"
  1008. << result->ReturnValue
  1009. << "</Value></NamedMeasurement>"
  1010. << std::endl;
  1011. }
  1012. os << result->RegressionImages;
  1013. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  1014. << "name=\"Execution Time\"><Value>"
  1015. << result->ExecutionTime
  1016. << "</Value></NamedMeasurement>\n";
  1017. if(result->Reason.size())
  1018. {
  1019. const char* reasonType = "Pass Reason";
  1020. if(result->Status != cmCTestTestHandler::COMPLETED &&
  1021. result->Status != cmCTestTestHandler::NOT_RUN)
  1022. {
  1023. reasonType = "Fail Reason";
  1024. }
  1025. os << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1026. << "name=\"" << reasonType << "\"><Value>"
  1027. << cmXMLSafe(result->Reason)
  1028. << "</Value></NamedMeasurement>\n";
  1029. }
  1030. os
  1031. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1032. << "name=\"Completion Status\"><Value>"
  1033. << cmXMLSafe(result->CompletionStatus)
  1034. << "</Value></NamedMeasurement>\n";
  1035. }
  1036. os
  1037. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1038. << "name=\"Command Line\"><Value>"
  1039. << cmXMLSafe(result->FullCommandLine)
  1040. << "</Value></NamedMeasurement>\n";
  1041. std::map<cmStdString,cmStdString>::iterator measureIt;
  1042. for ( measureIt = result->Properties->Measurements.begin();
  1043. measureIt != result->Properties->Measurements.end();
  1044. ++ measureIt )
  1045. {
  1046. os
  1047. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1048. << "name=\"" << measureIt->first.c_str() << "\"><Value>"
  1049. << cmXMLSafe(measureIt->second)
  1050. << "</Value></NamedMeasurement>\n";
  1051. }
  1052. os
  1053. << "\t\t\t<Measurement>\n"
  1054. << "\t\t\t\t<Value>";
  1055. os << cmXMLSafe(result->Output);
  1056. os
  1057. << "</Value>\n"
  1058. << "\t\t\t</Measurement>\n"
  1059. << "\t\t</Results>\n";
  1060. this->WriteTestResultFooter(os, result);
  1061. }
  1062. os << "\t<EndDateTime>" << this->EndTest << "</EndDateTime>\n"
  1063. << "\t<EndTestTime>" << this->EndTestTime << "</EndTestTime>\n"
  1064. << "<ElapsedMinutes>"
  1065. << static_cast<int>(this->ElapsedTestingTime/6)/10.0
  1066. << "</ElapsedMinutes>"
  1067. << "</Testing>" << std::endl;
  1068. this->CTest->EndXML(os);
  1069. }
  1070. //----------------------------------------------------------------------------
  1071. void cmCTestTestHandler::WriteTestResultHeader(std::ostream& os,
  1072. cmCTestTestResult* result)
  1073. {
  1074. os << "\t<Test Status=\"";
  1075. if ( result->Status == cmCTestTestHandler::COMPLETED )
  1076. {
  1077. os << "passed";
  1078. }
  1079. else if ( result->Status == cmCTestTestHandler::NOT_RUN )
  1080. {
  1081. os << "notrun";
  1082. }
  1083. else
  1084. {
  1085. os << "failed";
  1086. }
  1087. std::string testPath = result->Path + "/" + result->Name;
  1088. os << "\">\n"
  1089. << "\t\t<Name>" << cmXMLSafe(result->Name) << "</Name>\n"
  1090. << "\t\t<Path>" << cmXMLSafe(
  1091. this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
  1092. << "\t\t<FullName>" << cmXMLSafe(
  1093. this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
  1094. << "\t\t<FullCommandLine>"
  1095. << cmXMLSafe(result->FullCommandLine)
  1096. << "</FullCommandLine>\n";
  1097. }
  1098. //----------------------------------------------------------------------------
  1099. void cmCTestTestHandler::WriteTestResultFooter(std::ostream& os,
  1100. cmCTestTestResult* result)
  1101. {
  1102. if(!result->Properties->Labels.empty())
  1103. {
  1104. os << "\t\t<Labels>\n";
  1105. std::vector<std::string> const& labels = result->Properties->Labels;
  1106. for(std::vector<std::string>::const_iterator li = labels.begin();
  1107. li != labels.end(); ++li)
  1108. {
  1109. os << "\t\t\t<Label>" << cmXMLSafe(*li) << "</Label>\n";
  1110. }
  1111. os << "\t\t</Labels>\n";
  1112. }
  1113. os
  1114. << "\t</Test>" << std::endl;
  1115. }
  1116. //----------------------------------------------------------------------
  1117. int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
  1118. {
  1119. std::vector<cmStdString>::iterator it;
  1120. for ( it = vec.begin(); it != vec.end(); ++it )
  1121. {
  1122. int retVal = 0;
  1123. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it
  1124. << std::endl);
  1125. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true
  1126. /*this->Verbose*/) || retVal != 0 )
  1127. {
  1128. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem running command: "
  1129. << *it << std::endl);
  1130. return 0;
  1131. }
  1132. }
  1133. return 1;
  1134. }
  1135. //----------------------------------------------------------------------
  1136. // Find the appropriate executable to run for a test
  1137. std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
  1138. {
  1139. std::string resConfig;
  1140. std::vector<std::string> extraPaths;
  1141. std::vector<std::string> failedPaths;
  1142. return cmCTestTestHandler::FindExecutable(this->CTest,
  1143. exe, resConfig,
  1144. extraPaths,
  1145. failedPaths);
  1146. }
  1147. // add additional configurations to the search path
  1148. void cmCTestTestHandler
  1149. ::AddConfigurations(cmCTest *ctest,
  1150. std::vector<std::string> &attempted,
  1151. std::vector<std::string> &attemptedConfigs,
  1152. std::string filepath,
  1153. std::string &filename)
  1154. {
  1155. std::string tempPath;
  1156. if (filepath.size() &&
  1157. filepath[filepath.size()-1] != '/')
  1158. {
  1159. filepath += "/";
  1160. }
  1161. tempPath = filepath + filename;
  1162. attempted.push_back(tempPath);
  1163. attemptedConfigs.push_back("");
  1164. if(ctest->GetConfigType().size())
  1165. {
  1166. tempPath = filepath;
  1167. tempPath += ctest->GetConfigType();
  1168. tempPath += "/";
  1169. tempPath += filename;
  1170. attempted.push_back(tempPath);
  1171. attemptedConfigs.push_back(ctest->GetConfigType());
  1172. // If the file is an OSX bundle then the configtyp
  1173. // will be at the start of the path
  1174. tempPath = ctest->GetConfigType();
  1175. tempPath += "/";
  1176. tempPath += filepath;
  1177. tempPath += filename;
  1178. attempted.push_back(tempPath);
  1179. attemptedConfigs.push_back(ctest->GetConfigType());
  1180. }
  1181. else
  1182. {
  1183. // no config specified to try some options
  1184. tempPath = filepath;
  1185. tempPath += "Release/";
  1186. tempPath += filename;
  1187. attempted.push_back(tempPath);
  1188. attemptedConfigs.push_back("Release");
  1189. tempPath = filepath;
  1190. tempPath += "Debug/";
  1191. tempPath += filename;
  1192. attempted.push_back(tempPath);
  1193. attemptedConfigs.push_back("Debug");
  1194. tempPath = filepath;
  1195. tempPath += "MinSizeRel/";
  1196. tempPath += filename;
  1197. attempted.push_back(tempPath);
  1198. attemptedConfigs.push_back("MinSizeRel");
  1199. tempPath = filepath;
  1200. tempPath += "RelWithDebInfo/";
  1201. tempPath += filename;
  1202. attempted.push_back(tempPath);
  1203. attemptedConfigs.push_back("RelWithDebInfo");
  1204. tempPath = filepath;
  1205. tempPath += "Deployment/";
  1206. tempPath += filename;
  1207. attempted.push_back(tempPath);
  1208. attemptedConfigs.push_back("Deployment");
  1209. tempPath = filepath;
  1210. tempPath += "Development/";
  1211. tempPath += filename;
  1212. attempted.push_back(tempPath);
  1213. attemptedConfigs.push_back("Deployment");
  1214. }
  1215. }
  1216. //----------------------------------------------------------------------
  1217. // Find the appropriate executable to run for a test
  1218. std::string cmCTestTestHandler
  1219. ::FindExecutable(cmCTest *ctest,
  1220. const char *testCommand,
  1221. std::string &resultingConfig,
  1222. std::vector<std::string> &extraPaths,
  1223. std::vector<std::string> &failed)
  1224. {
  1225. // now run the compiled test if we can find it
  1226. std::vector<std::string> attempted;
  1227. std::vector<std::string> attemptedConfigs;
  1228. std::string tempPath;
  1229. std::string filepath =
  1230. cmSystemTools::GetFilenamePath(testCommand);
  1231. std::string filename =
  1232. cmSystemTools::GetFilenameName(testCommand);
  1233. cmCTestTestHandler::AddConfigurations(ctest, attempted,
  1234. attemptedConfigs,
  1235. filepath,filename);
  1236. // even if a fullpath was specified also try it relative to the current
  1237. // directory
  1238. if (filepath.size() && filepath[0] == '/')
  1239. {
  1240. std::string localfilepath = filepath.substr(1,filepath.size()-1);
  1241. cmCTestTestHandler::AddConfigurations(ctest, attempted,
  1242. attemptedConfigs,
  1243. localfilepath,filename);
  1244. }
  1245. // if extraPaths are provided and we were not passed a full path, try them,
  1246. // try any extra paths
  1247. if (filepath.size() == 0)
  1248. {
  1249. for (unsigned int i = 0; i < extraPaths.size(); ++i)
  1250. {
  1251. std::string filepathExtra =
  1252. cmSystemTools::GetFilenamePath(extraPaths[i]);
  1253. std::string filenameExtra =
  1254. cmSystemTools::GetFilenameName(extraPaths[i]);
  1255. cmCTestTestHandler::AddConfigurations(ctest,attempted,
  1256. attemptedConfigs,
  1257. filepathExtra,
  1258. filenameExtra);
  1259. }
  1260. }
  1261. // store the final location in fullPath
  1262. std::string fullPath;
  1263. // now look in the paths we specified above
  1264. for(unsigned int ai=0;
  1265. ai < attempted.size() && fullPath.size() == 0; ++ai)
  1266. {
  1267. // first check without exe extension
  1268. if(cmSystemTools::FileExists(attempted[ai].c_str())
  1269. && !cmSystemTools::FileIsDirectory(attempted[ai].c_str()))
  1270. {
  1271. fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str());
  1272. resultingConfig = attemptedConfigs[ai];
  1273. }
  1274. // then try with the exe extension
  1275. else
  1276. {
  1277. failed.push_back(attempted[ai].c_str());
  1278. tempPath = attempted[ai];
  1279. tempPath += cmSystemTools::GetExecutableExtension();
  1280. if(cmSystemTools::FileExists(tempPath.c_str())
  1281. && !cmSystemTools::FileIsDirectory(tempPath.c_str()))
  1282. {
  1283. fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str());
  1284. resultingConfig = attemptedConfigs[ai];
  1285. }
  1286. else
  1287. {
  1288. failed.push_back(tempPath.c_str());
  1289. }
  1290. }
  1291. }
  1292. // if everything else failed, check the users path, but only if a full path
  1293. // wasn't specified
  1294. if (fullPath.size() == 0 && filepath.size() == 0)
  1295. {
  1296. std::string path = cmSystemTools::FindProgram(filename.c_str());
  1297. if (path != "")
  1298. {
  1299. resultingConfig = "";
  1300. return path;
  1301. }
  1302. }
  1303. if(fullPath.size() == 0)
  1304. {
  1305. cmCTestLog(ctest, HANDLER_OUTPUT,
  1306. "Could not find executable " << testCommand << "\n"
  1307. << "Looked in the following places:\n");
  1308. for(std::vector<std::string>::iterator i = failed.begin();
  1309. i != failed.end(); ++i)
  1310. {
  1311. cmCTestLog(ctest, HANDLER_OUTPUT,
  1312. i->c_str() << "\n");
  1313. }
  1314. }
  1315. return fullPath;
  1316. }
  1317. //----------------------------------------------------------------------
  1318. void cmCTestTestHandler::GetListOfTests()
  1319. {
  1320. if ( !this->IncludeLabelRegExp.empty() )
  1321. {
  1322. this->IncludeLabelRegularExpression.
  1323. compile(this->IncludeLabelRegExp.c_str());
  1324. }
  1325. if ( !this->IncludeLabelRegExp.empty() )
  1326. {
  1327. this->ExcludeLabelRegularExpression.
  1328. compile(this->ExcludeLabelRegExp.c_str());
  1329. }
  1330. if ( !this->IncludeRegExp.empty() )
  1331. {
  1332. this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
  1333. }
  1334. if ( !this->ExcludeRegExp.empty() )
  1335. {
  1336. this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
  1337. }
  1338. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1339. "Constructing a list of tests" << std::endl);
  1340. cmake cm;
  1341. cmGlobalGenerator gg;
  1342. gg.SetCMakeInstance(&cm);
  1343. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  1344. cmMakefile *mf = lg->GetMakefile();
  1345. mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
  1346. this->CTest->GetConfigType().c_str());
  1347. // Add handler for ADD_TEST
  1348. cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
  1349. newCom1->TestHandler = this;
  1350. cm.AddCommand(newCom1);
  1351. // Add handler for SUBDIRS
  1352. cmCTestSubdirCommand* newCom2 =
  1353. new cmCTestSubdirCommand;
  1354. newCom2->TestHandler = this;
  1355. cm.AddCommand(newCom2);
  1356. // Add handler for ADD_SUBDIRECTORY
  1357. cmCTestAddSubdirectoryCommand* newCom3 =
  1358. new cmCTestAddSubdirectoryCommand;
  1359. newCom3->TestHandler = this;
  1360. cm.AddCommand(newCom3);
  1361. // Add handler for SET_SOURCE_FILES_PROPERTIES
  1362. cmCTestSetTestsPropertiesCommand* newCom4
  1363. = new cmCTestSetTestsPropertiesCommand;
  1364. newCom4->TestHandler = this;
  1365. cm.AddCommand(newCom4);
  1366. const char* testFilename;
  1367. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  1368. {
  1369. // does the CTestTestfile.cmake exist ?
  1370. testFilename = "CTestTestfile.cmake";
  1371. }
  1372. else if( cmSystemTools::FileExists("DartTestfile.txt") )
  1373. {
  1374. // does the DartTestfile.txt exist ?
  1375. testFilename = "DartTestfile.txt";
  1376. }
  1377. else
  1378. {
  1379. return;
  1380. }
  1381. if ( !mf->ReadListFile(0, testFilename) )
  1382. {
  1383. return;
  1384. }
  1385. if ( cmSystemTools::GetErrorOccuredFlag() )
  1386. {
  1387. return;
  1388. }
  1389. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1390. "Done constructing a list of tests" << std::endl);
  1391. }
  1392. //----------------------------------------------------------------------
  1393. void cmCTestTestHandler::UseIncludeRegExp()
  1394. {
  1395. this->UseIncludeRegExpFlag = true;
  1396. }
  1397. //----------------------------------------------------------------------
  1398. void cmCTestTestHandler::UseExcludeRegExp()
  1399. {
  1400. this->UseExcludeRegExpFlag = true;
  1401. this->UseExcludeRegExpFirst = this->UseIncludeRegExpFlag ? false : true;
  1402. }
  1403. //----------------------------------------------------------------------
  1404. const char* cmCTestTestHandler::GetTestStatus(int status)
  1405. {
  1406. static const char statuses[][100] = {
  1407. "Not Run",
  1408. "Timeout",
  1409. "SEGFAULT",
  1410. "ILLEGAL",
  1411. "INTERRUPT",
  1412. "NUMERICAL",
  1413. "OTHER_FAULT",
  1414. "Failed",
  1415. "BAD_COMMAND",
  1416. "Completed"
  1417. };
  1418. if ( status < cmCTestTestHandler::NOT_RUN ||
  1419. status > cmCTestTestHandler::COMPLETED )
  1420. {
  1421. return "No Status";
  1422. }
  1423. return statuses[status];
  1424. }
  1425. //----------------------------------------------------------------------
  1426. void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests)
  1427. {
  1428. if (this->TestsToRunString.empty())
  1429. {
  1430. return;
  1431. }
  1432. int start;
  1433. int end = -1;
  1434. double stride = -1;
  1435. std::string::size_type pos = 0;
  1436. std::string::size_type pos2;
  1437. // read start
  1438. if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
  1439. {
  1440. // read end
  1441. if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
  1442. {
  1443. // read stride
  1444. if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
  1445. {
  1446. int val =0;
  1447. // now read specific numbers
  1448. while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
  1449. {
  1450. this->TestsToRun.push_back(val);
  1451. }
  1452. this->TestsToRun.push_back(val);
  1453. }
  1454. }
  1455. }
  1456. // if start is not specified then we assume we start at 1
  1457. if(start == -1)
  1458. {
  1459. start = 1;
  1460. }
  1461. // if end isnot specified then we assume we end with the last test
  1462. if(end == -1)
  1463. {
  1464. end = static_cast<int>(numTests);
  1465. }
  1466. // if the stride wasn't specified then it defaults to 1
  1467. if(stride == -1)
  1468. {
  1469. stride = 1;
  1470. }
  1471. // if we have a range then add it
  1472. if(end != -1 && start != -1 && stride > 0)
  1473. {
  1474. int i = 0;
  1475. while (i*stride + start <= end)
  1476. {
  1477. this->TestsToRun.push_back(static_cast<int>(i*stride+start));
  1478. ++i;
  1479. }
  1480. }
  1481. // sort the array
  1482. std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
  1483. std::less<int>());
  1484. // remove duplicates
  1485. std::vector<int>::iterator new_end =
  1486. std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
  1487. this->TestsToRun.erase(new_end, this->TestsToRun.end());
  1488. }
  1489. //----------------------------------------------------------------------
  1490. // Just for convenience
  1491. #define SPACE_REGEX "[ \t\r\n]"
  1492. //----------------------------------------------------------------------
  1493. std::string cmCTestTestHandler::GenerateRegressionImages(
  1494. const std::string& xml)
  1495. {
  1496. cmsys::RegularExpression twoattributes(
  1497. "<DartMeasurement"
  1498. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1499. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1500. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1501. cmsys::RegularExpression threeattributes(
  1502. "<DartMeasurement"
  1503. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1504. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1505. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1506. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1507. cmsys::RegularExpression fourattributes(
  1508. "<DartMeasurement"
  1509. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1510. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1511. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1512. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1513. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1514. cmsys::RegularExpression cdatastart(
  1515. "<DartMeasurement"
  1516. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1517. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1518. SPACE_REGEX "*>"
  1519. SPACE_REGEX "*<!\\[CDATA\\[");
  1520. cmsys::RegularExpression cdataend(
  1521. "]]>"
  1522. SPACE_REGEX "*</DartMeasurement>");
  1523. cmsys::RegularExpression measurementfile(
  1524. "<DartMeasurementFile"
  1525. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1526. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1527. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  1528. cmOStringStream ostr;
  1529. bool done = false;
  1530. std::string cxml = xml;
  1531. while ( ! done )
  1532. {
  1533. if ( twoattributes.find(cxml) )
  1534. {
  1535. ostr
  1536. << "\t\t\t<NamedMeasurement"
  1537. << " " << twoattributes.match(1) << "=\""
  1538. << twoattributes.match(2) << "\""
  1539. << " " << twoattributes.match(3) << "=\""
  1540. << twoattributes.match(4) << "\""
  1541. << "><Value>" << twoattributes.match(5)
  1542. << "</Value></NamedMeasurement>"
  1543. << std::endl;
  1544. cxml.erase(twoattributes.start(),
  1545. twoattributes.end() - twoattributes.start());
  1546. }
  1547. else if ( threeattributes.find(cxml) )
  1548. {
  1549. ostr
  1550. << "\t\t\t<NamedMeasurement"
  1551. << " " << threeattributes.match(1) << "=\""
  1552. << threeattributes.match(2) << "\""
  1553. << " " << threeattributes.match(3) << "=\""
  1554. << threeattributes.match(4) << "\""
  1555. << " " << threeattributes.match(5) << "=\""
  1556. << threeattributes.match(6) << "\""
  1557. << "><Value>" << threeattributes.match(7)
  1558. << "</Value></NamedMeasurement>"
  1559. << std::endl;
  1560. cxml.erase(threeattributes.start(),
  1561. threeattributes.end() - threeattributes.start());
  1562. }
  1563. else if ( fourattributes.find(cxml) )
  1564. {
  1565. ostr
  1566. << "\t\t\t<NamedMeasurement"
  1567. << " " << fourattributes.match(1) << "=\""
  1568. << fourattributes.match(2) << "\""
  1569. << " " << fourattributes.match(3) << "=\""
  1570. << fourattributes.match(4) << "\""
  1571. << " " << fourattributes.match(5) << "=\""
  1572. << fourattributes.match(6) << "\""
  1573. << " " << fourattributes.match(7) << "=\""
  1574. << fourattributes.match(8) << "\""
  1575. << "><Value>" << fourattributes.match(9)
  1576. << "</Value></NamedMeasurement>"
  1577. << std::endl;
  1578. cxml.erase(fourattributes.start(),
  1579. fourattributes.end() - fourattributes.start());
  1580. }
  1581. else if ( cdatastart.find(cxml) && cdataend.find(cxml) )
  1582. {
  1583. ostr
  1584. << "\t\t\t<NamedMeasurement"
  1585. << " " << cdatastart.match(1) << "=\""
  1586. << cdatastart.match(2) << "\""
  1587. << " " << cdatastart.match(3) << "=\""
  1588. << cdatastart.match(4) << "\""
  1589. << "><Value><![CDATA["
  1590. << cxml.substr(cdatastart.end(), cdataend.start() - cdatastart.end())
  1591. << "]]></Value></NamedMeasurement>"
  1592. << std::endl;
  1593. cxml.erase(cdatastart.start(),
  1594. cdataend.end() - cdatastart.start());
  1595. }
  1596. else if ( measurementfile.find(cxml) )
  1597. {
  1598. const std::string& filename =
  1599. cmCTest::CleanString(measurementfile.match(5));
  1600. if ( cmSystemTools::FileExists(filename.c_str()) )
  1601. {
  1602. long len = cmSystemTools::FileLength(filename.c_str());
  1603. if ( len == 0 )
  1604. {
  1605. std::string k1 = measurementfile.match(1);
  1606. std::string v1 = measurementfile.match(2);
  1607. std::string k2 = measurementfile.match(3);
  1608. std::string v2 = measurementfile.match(4);
  1609. if ( cmSystemTools::LowerCase(k1) == "type" )
  1610. {
  1611. v1 = "text/string";
  1612. }
  1613. if ( cmSystemTools::LowerCase(k2) == "type" )
  1614. {
  1615. v2 = "text/string";
  1616. }
  1617. ostr
  1618. << "\t\t\t<NamedMeasurement"
  1619. << " " << k1 << "=\"" << v1 << "\""
  1620. << " " << k2 << "=\"" << v2 << "\""
  1621. << " encoding=\"none\""
  1622. << "><Value>Image " << filename.c_str()
  1623. << " is empty</Value></NamedMeasurement>";
  1624. }
  1625. else
  1626. {
  1627. std::ifstream ifs(filename.c_str(), std::ios::in
  1628. #ifdef _WIN32
  1629. | std::ios::binary
  1630. #endif
  1631. );
  1632. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  1633. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1634. unsigned char *encoded_buffer
  1635. = new unsigned char [ static_cast<int>(len * 1.5 + 5) ];
  1636. unsigned long rlen
  1637. = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1638. unsigned long cc;
  1639. ostr
  1640. << "\t\t\t<NamedMeasurement"
  1641. << " " << measurementfile.match(1) << "=\""
  1642. << measurementfile.match(2) << "\""
  1643. << " " << measurementfile.match(3) << "=\""
  1644. << measurementfile.match(4) << "\""
  1645. << " encoding=\"base64\""
  1646. << ">" << std::endl << "\t\t\t\t<Value>";
  1647. for ( cc = 0; cc < rlen; cc ++ )
  1648. {
  1649. ostr << encoded_buffer[cc];
  1650. if ( cc % 60 == 0 && cc )
  1651. {
  1652. ostr << std::endl;
  1653. }
  1654. }
  1655. ostr
  1656. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  1657. << std::endl;
  1658. delete [] file_buffer;
  1659. delete [] encoded_buffer;
  1660. }
  1661. }
  1662. else
  1663. {
  1664. int idx = 4;
  1665. if ( measurementfile.match(1) == "name" )
  1666. {
  1667. idx = 2;
  1668. }
  1669. ostr
  1670. << "\t\t\t<NamedMeasurement"
  1671. << " name=\"" << measurementfile.match(idx) << "\""
  1672. << " text=\"text/string\""
  1673. << "><Value>File " << filename.c_str()
  1674. << " not found</Value></NamedMeasurement>"
  1675. << std::endl;
  1676. cmCTestLog(this->CTest, HANDLER_OUTPUT, "File \"" << filename.c_str()
  1677. << "\" not found." << std::endl);
  1678. }
  1679. cxml.erase(measurementfile.start(),
  1680. measurementfile.end() - measurementfile.start());
  1681. }
  1682. else
  1683. {
  1684. done = true;
  1685. }
  1686. }
  1687. return ostr.str();
  1688. }
  1689. //----------------------------------------------------------------------
  1690. void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
  1691. {
  1692. this->IncludeRegExp = arg;
  1693. }
  1694. //----------------------------------------------------------------------
  1695. void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
  1696. {
  1697. this->ExcludeRegExp = arg;
  1698. }
  1699. //----------------------------------------------------------------------
  1700. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1701. {
  1702. if ( !in )
  1703. {
  1704. return;
  1705. }
  1706. this->TestsToRunString = in;
  1707. // if the argument is a file, then read it and use the contents as the
  1708. // string
  1709. if(cmSystemTools::FileExists(in))
  1710. {
  1711. std::ifstream fin(in);
  1712. unsigned long filelen = cmSystemTools::FileLength(in);
  1713. char* buff = new char[filelen+1];
  1714. fin.getline(buff, filelen);
  1715. buff[fin.gcount()] = 0;
  1716. this->TestsToRunString = buff;
  1717. }
  1718. }
  1719. //----------------------------------------------------------------------
  1720. bool cmCTestTestHandler::CleanTestOutput(std::string& output,
  1721. size_t remove_threshold)
  1722. {
  1723. if ( remove_threshold == 0 )
  1724. {
  1725. return true;
  1726. }
  1727. if ( output.find("CTEST_FULL_OUTPUT") != output.npos )
  1728. {
  1729. return true;
  1730. }
  1731. cmOStringStream ostr;
  1732. std::string::size_type cc;
  1733. std::string::size_type skipsize = 0;
  1734. int inTag = 0;
  1735. int skipped = 0;
  1736. for ( cc = 0; cc < output.size(); cc ++ )
  1737. {
  1738. int ch = output[cc];
  1739. if ( ch < 0 || ch > 255 )
  1740. {
  1741. break;
  1742. }
  1743. if ( ch == '<' )
  1744. {
  1745. inTag = 1;
  1746. }
  1747. if ( !inTag )
  1748. {
  1749. int notskip = 0;
  1750. // Skip
  1751. if ( skipsize < remove_threshold )
  1752. {
  1753. ostr << static_cast<char>(ch);
  1754. notskip = 1;
  1755. }
  1756. skipsize ++;
  1757. if ( notskip && skipsize >= remove_threshold )
  1758. {
  1759. skipped = 1;
  1760. }
  1761. }
  1762. else
  1763. {
  1764. ostr << static_cast<char>(ch);
  1765. }
  1766. if ( ch == '>' )
  1767. {
  1768. inTag = 0;
  1769. }
  1770. }
  1771. if ( skipped )
  1772. {
  1773. ostr << "..." << std::endl << "The rest of the test output was removed "
  1774. "since it exceeds the threshold of "
  1775. << remove_threshold << " characters." << std::endl;
  1776. }
  1777. output = ostr.str();
  1778. return true;
  1779. }
  1780. //----------------------------------------------------------------------
  1781. bool cmCTestTestHandler::SetTestsProperties(
  1782. const std::vector<std::string>& args)
  1783. {
  1784. std::vector<std::string>::const_iterator it;
  1785. std::vector<cmStdString> tests;
  1786. bool found = false;
  1787. for ( it = args.begin(); it != args.end(); ++ it )
  1788. {
  1789. if ( *it == "PROPERTIES" )
  1790. {
  1791. found = true;
  1792. break;
  1793. }
  1794. tests.push_back(*it);
  1795. }
  1796. if ( !found )
  1797. {
  1798. return false;
  1799. }
  1800. ++ it; // skip PROPERTIES
  1801. for ( ; it != args.end(); ++ it )
  1802. {
  1803. std::string key = *it;
  1804. ++ it;
  1805. if ( it == args.end() )
  1806. {
  1807. break;
  1808. }
  1809. std::string val = *it;
  1810. std::vector<cmStdString>::const_iterator tit;
  1811. for ( tit = tests.begin(); tit != tests.end(); ++ tit )
  1812. {
  1813. cmCTestTestHandler::ListOfTests::iterator rtit;
  1814. for ( rtit = this->TestList.begin();
  1815. rtit != this->TestList.end();
  1816. ++ rtit )
  1817. {
  1818. if ( *tit == rtit->Name )
  1819. {
  1820. if ( key == "WILL_FAIL" )
  1821. {
  1822. rtit->WillFail = cmSystemTools::IsOn(val.c_str());
  1823. }
  1824. if ( key == "TIMEOUT" )
  1825. {
  1826. rtit->Timeout = atof(val.c_str());
  1827. }
  1828. if ( key == "COST" )
  1829. {
  1830. rtit->Cost = atof(val.c_str());
  1831. }
  1832. if ( key == "RUN_SERIAL" )
  1833. {
  1834. rtit->RunSerial = cmSystemTools::IsOn(val.c_str());
  1835. }
  1836. if ( key == "FAIL_REGULAR_EXPRESSION" )
  1837. {
  1838. std::vector<std::string> lval;
  1839. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1840. std::vector<std::string>::iterator crit;
  1841. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1842. {
  1843. rtit->ErrorRegularExpressions.push_back(
  1844. std::pair<cmsys::RegularExpression, std::string>(
  1845. cmsys::RegularExpression(crit->c_str()),
  1846. std::string(crit->c_str())));
  1847. }
  1848. }
  1849. if ( key == "PROCESSORS" )
  1850. {
  1851. rtit->Processors = atoi(val.c_str());
  1852. if(rtit->Processors < 1)
  1853. {
  1854. rtit->Processors = 1;
  1855. }
  1856. }
  1857. if ( key == "DEPENDS" )
  1858. {
  1859. std::vector<std::string> lval;
  1860. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1861. std::vector<std::string>::iterator crit;
  1862. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1863. {
  1864. rtit->Depends.push_back(*crit);
  1865. }
  1866. }
  1867. if ( key == "ENVIRONMENT" )
  1868. {
  1869. std::vector<std::string> lval;
  1870. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1871. std::vector<std::string>::iterator crit;
  1872. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1873. {
  1874. rtit->Environment.push_back(*crit);
  1875. }
  1876. }
  1877. if ( key == "LABELS" )
  1878. {
  1879. std::vector<std::string> lval;
  1880. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1881. std::vector<std::string>::iterator crit;
  1882. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1883. {
  1884. rtit->Labels.push_back(*crit);
  1885. }
  1886. }
  1887. if ( key == "MEASUREMENT" )
  1888. {
  1889. size_t pos = val.find_first_of("=");
  1890. if ( pos != val.npos )
  1891. {
  1892. std::string mKey = val.substr(0, pos);
  1893. const char* mVal = val.c_str() + pos + 1;
  1894. rtit->Measurements[mKey] = mVal;
  1895. }
  1896. else
  1897. {
  1898. rtit->Measurements[val] = "1";
  1899. }
  1900. }
  1901. if ( key == "PASS_REGULAR_EXPRESSION" )
  1902. {
  1903. std::vector<std::string> lval;
  1904. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1905. std::vector<std::string>::iterator crit;
  1906. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1907. {
  1908. rtit->RequiredRegularExpressions.push_back(
  1909. std::pair<cmsys::RegularExpression, std::string>(
  1910. cmsys::RegularExpression(crit->c_str()),
  1911. std::string(crit->c_str())));
  1912. }
  1913. }
  1914. }
  1915. }
  1916. }
  1917. }
  1918. return true;
  1919. }
  1920. //----------------------------------------------------------------------
  1921. bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
  1922. {
  1923. const std::string& testname = args[0];
  1924. cmCTestLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl);
  1925. if (this->UseExcludeRegExpFlag &&
  1926. this->UseExcludeRegExpFirst &&
  1927. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  1928. {
  1929. return true;
  1930. }
  1931. if ( this->MemCheck )
  1932. {
  1933. std::vector<cmStdString>::iterator it;
  1934. bool found = false;
  1935. for ( it = this->CustomTestsIgnore.begin();
  1936. it != this->CustomTestsIgnore.end(); ++ it )
  1937. {
  1938. if ( *it == testname )
  1939. {
  1940. found = true;
  1941. break;
  1942. }
  1943. }
  1944. if ( found )
  1945. {
  1946. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: "
  1947. << *it << std::endl);
  1948. return true;
  1949. }
  1950. }
  1951. else
  1952. {
  1953. std::vector<cmStdString>::iterator it;
  1954. bool found = false;
  1955. for ( it = this->CustomTestsIgnore.begin();
  1956. it != this->CustomTestsIgnore.end(); ++ it )
  1957. {
  1958. if ( *it == testname )
  1959. {
  1960. found = true;
  1961. break;
  1962. }
  1963. }
  1964. if ( found )
  1965. {
  1966. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: "
  1967. << *it << std::endl);
  1968. return true;
  1969. }
  1970. }
  1971. cmCTestTestProperties test;
  1972. test.Name = testname;
  1973. test.Args = args;
  1974. test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
  1975. cmCTestLog(this->CTest, DEBUG, "Set test directory: "
  1976. << test.Directory << std::endl);
  1977. test.IsInBasedOnREOptions = true;
  1978. test.WillFail = false;
  1979. test.RunSerial = false;
  1980. test.Timeout = 0;
  1981. test.Cost = 0;
  1982. test.Processors = 1;
  1983. if (this->UseIncludeRegExpFlag &&
  1984. !this->IncludeTestsRegularExpression.find(testname.c_str()))
  1985. {
  1986. test.IsInBasedOnREOptions = false;
  1987. }
  1988. else if (this->UseExcludeRegExpFlag &&
  1989. !this->UseExcludeRegExpFirst &&
  1990. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  1991. {
  1992. test.IsInBasedOnREOptions = false;
  1993. }
  1994. this->TestList.push_back(test);
  1995. return true;
  1996. }