cmCTestTestHandler.cxx 62 KB

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