cmCTestTestHandler.cxx 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146
  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::TestMap tests;
  919. cmCTestMultiProcessHandler::TestMap expensiveTests;
  920. cmCTestMultiProcessHandler::PropertiesMap properties;
  921. for (ListOfTests::iterator it = this->TestList.begin();
  922. it != this->TestList.end(); it ++ )
  923. {
  924. cmCTestTestProperties& p = *it;
  925. cmCTestMultiProcessHandler::TestSet depends;
  926. if(p.Depends.size())
  927. {
  928. for(std::vector<std::string>::iterator i = p.Depends.begin();
  929. i != p.Depends.end(); ++i)
  930. {
  931. for(ListOfTests::iterator it2 = this->TestList.begin();
  932. it2 != this->TestList.end(); it2 ++ )
  933. {
  934. if(it2->Name == *i)
  935. {
  936. depends.insert(it2->Index);
  937. break; // break out of test loop as name can only match 1
  938. }
  939. }
  940. }
  941. }
  942. tests[it->Index] = depends;
  943. properties[it->Index] = &*it;
  944. if(it->Expensive)
  945. {
  946. expensiveTests[it->Index] = depends;
  947. }
  948. }
  949. parallel.SetTests(tests, expensiveTests, properties);
  950. parallel.SetPassFailVectors(&passed, &failed);
  951. this->TestResults.clear();
  952. parallel.SetTestResults(&this->TestResults);
  953. if(this->CTest->GetShowOnly())
  954. {
  955. parallel.PrintTestList();
  956. }
  957. else
  958. {
  959. parallel.RunTests();
  960. }
  961. this->EndTest = this->CTest->CurrentTime();
  962. this->EndTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
  963. this->ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
  964. *this->LogFile << "End testing: "
  965. << this->CTest->CurrentTime() << std::endl;
  966. }
  967. //----------------------------------------------------------------------
  968. void cmCTestTestHandler::GenerateTestCommand(std::vector<std::string>&)
  969. {
  970. }
  971. //----------------------------------------------------------------------
  972. void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
  973. {
  974. if ( !this->CTest->GetProduceXML() )
  975. {
  976. return;
  977. }
  978. this->CTest->StartXML(os, this->AppendXML);
  979. os << "<Testing>\n"
  980. << "\t<StartDateTime>" << this->StartTest << "</StartDateTime>\n"
  981. << "\t<StartTestTime>" << this->StartTestTime << "</StartTestTime>\n"
  982. << "\t<TestList>\n";
  983. cmCTestTestHandler::TestResultsVector::size_type cc;
  984. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  985. {
  986. cmCTestTestResult *result = &this->TestResults[cc];
  987. std::string testPath = result->Path + "/" + result->Name;
  988. os << "\t\t<Test>" << cmXMLSafe(
  989. this->CTest->GetShortPathToFile(testPath.c_str()))
  990. << "</Test>" << std::endl;
  991. }
  992. os << "\t</TestList>\n";
  993. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  994. {
  995. cmCTestTestResult *result = &this->TestResults[cc];
  996. this->WriteTestResultHeader(os, result);
  997. os << "\t\t<Results>" << std::endl;
  998. if ( result->Status != cmCTestTestHandler::NOT_RUN )
  999. {
  1000. if ( result->Status != cmCTestTestHandler::COMPLETED ||
  1001. result->ReturnValue )
  1002. {
  1003. os << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1004. "name=\"Exit Code\"><Value>"
  1005. << cmXMLSafe(this->GetTestStatus(result->Status))
  1006. << "</Value>"
  1007. "</NamedMeasurement>\n"
  1008. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1009. "name=\"Exit Value\"><Value>"
  1010. << result->ReturnValue
  1011. << "</Value></NamedMeasurement>"
  1012. << std::endl;
  1013. }
  1014. os << result->RegressionImages;
  1015. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  1016. << "name=\"Execution Time\"><Value>"
  1017. << result->ExecutionTime
  1018. << "</Value></NamedMeasurement>\n";
  1019. if(result->Reason.size())
  1020. {
  1021. const char* reasonType = "Pass Reason";
  1022. if(result->Status != cmCTestTestHandler::COMPLETED &&
  1023. result->Status != cmCTestTestHandler::NOT_RUN)
  1024. {
  1025. reasonType = "Fail Reason";
  1026. }
  1027. os << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1028. << "name=\"" << reasonType << "\"><Value>"
  1029. << cmXMLSafe(result->Reason)
  1030. << "</Value></NamedMeasurement>\n";
  1031. }
  1032. os
  1033. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1034. << "name=\"Completion Status\"><Value>"
  1035. << cmXMLSafe(result->CompletionStatus)
  1036. << "</Value></NamedMeasurement>\n";
  1037. }
  1038. os
  1039. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1040. << "name=\"Command Line\"><Value>"
  1041. << cmXMLSafe(result->FullCommandLine)
  1042. << "</Value></NamedMeasurement>\n";
  1043. std::map<cmStdString,cmStdString>::iterator measureIt;
  1044. for ( measureIt = result->Properties->Measurements.begin();
  1045. measureIt != result->Properties->Measurements.end();
  1046. ++ measureIt )
  1047. {
  1048. os
  1049. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1050. << "name=\"" << measureIt->first.c_str() << "\"><Value>"
  1051. << cmXMLSafe(measureIt->second)
  1052. << "</Value></NamedMeasurement>\n";
  1053. }
  1054. os
  1055. << "\t\t\t<Measurement>\n"
  1056. << "\t\t\t\t<Value>";
  1057. os << cmXMLSafe(result->Output);
  1058. os
  1059. << "</Value>\n"
  1060. << "\t\t\t</Measurement>\n"
  1061. << "\t\t</Results>\n";
  1062. this->WriteTestResultFooter(os, result);
  1063. }
  1064. os << "\t<EndDateTime>" << this->EndTest << "</EndDateTime>\n"
  1065. << "\t<EndTestTime>" << this->EndTestTime << "</EndTestTime>\n"
  1066. << "<ElapsedMinutes>"
  1067. << static_cast<int>(this->ElapsedTestingTime/6)/10.0
  1068. << "</ElapsedMinutes>"
  1069. << "</Testing>" << std::endl;
  1070. this->CTest->EndXML(os);
  1071. }
  1072. //----------------------------------------------------------------------------
  1073. void cmCTestTestHandler::WriteTestResultHeader(std::ostream& os,
  1074. cmCTestTestResult* result)
  1075. {
  1076. os << "\t<Test Status=\"";
  1077. if ( result->Status == cmCTestTestHandler::COMPLETED )
  1078. {
  1079. os << "passed";
  1080. }
  1081. else if ( result->Status == cmCTestTestHandler::NOT_RUN )
  1082. {
  1083. os << "notrun";
  1084. }
  1085. else
  1086. {
  1087. os << "failed";
  1088. }
  1089. std::string testPath = result->Path + "/" + result->Name;
  1090. os << "\">\n"
  1091. << "\t\t<Name>" << cmXMLSafe(result->Name) << "</Name>\n"
  1092. << "\t\t<Path>" << cmXMLSafe(
  1093. this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
  1094. << "\t\t<FullName>" << cmXMLSafe(
  1095. this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
  1096. << "\t\t<FullCommandLine>"
  1097. << cmXMLSafe(result->FullCommandLine)
  1098. << "</FullCommandLine>\n";
  1099. }
  1100. //----------------------------------------------------------------------------
  1101. void cmCTestTestHandler::WriteTestResultFooter(std::ostream& os,
  1102. cmCTestTestResult* result)
  1103. {
  1104. if(!result->Properties->Labels.empty())
  1105. {
  1106. os << "\t\t<Labels>\n";
  1107. std::vector<std::string> const& labels = result->Properties->Labels;
  1108. for(std::vector<std::string>::const_iterator li = labels.begin();
  1109. li != labels.end(); ++li)
  1110. {
  1111. os << "\t\t\t<Label>" << cmXMLSafe(*li) << "</Label>\n";
  1112. }
  1113. os << "\t\t</Labels>\n";
  1114. }
  1115. os
  1116. << "\t</Test>" << std::endl;
  1117. }
  1118. //----------------------------------------------------------------------
  1119. int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
  1120. {
  1121. std::vector<cmStdString>::iterator it;
  1122. for ( it = vec.begin(); it != vec.end(); ++it )
  1123. {
  1124. int retVal = 0;
  1125. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it
  1126. << std::endl);
  1127. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true
  1128. /*this->Verbose*/) || retVal != 0 )
  1129. {
  1130. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem running command: "
  1131. << *it << std::endl);
  1132. return 0;
  1133. }
  1134. }
  1135. return 1;
  1136. }
  1137. //----------------------------------------------------------------------
  1138. // Find the appropriate executable to run for a test
  1139. std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
  1140. {
  1141. std::string resConfig;
  1142. std::vector<std::string> extraPaths;
  1143. std::vector<std::string> failedPaths;
  1144. return cmCTestTestHandler::FindExecutable(this->CTest,
  1145. exe, resConfig,
  1146. extraPaths,
  1147. failedPaths);
  1148. }
  1149. // add additional configurations to the search path
  1150. void cmCTestTestHandler
  1151. ::AddConfigurations(cmCTest *ctest,
  1152. std::vector<std::string> &attempted,
  1153. std::vector<std::string> &attemptedConfigs,
  1154. std::string filepath,
  1155. std::string &filename)
  1156. {
  1157. std::string tempPath;
  1158. if (filepath.size() &&
  1159. filepath[filepath.size()-1] != '/')
  1160. {
  1161. filepath += "/";
  1162. }
  1163. tempPath = filepath + filename;
  1164. attempted.push_back(tempPath);
  1165. attemptedConfigs.push_back("");
  1166. if(ctest->GetConfigType().size())
  1167. {
  1168. tempPath = filepath;
  1169. tempPath += ctest->GetConfigType();
  1170. tempPath += "/";
  1171. tempPath += filename;
  1172. attempted.push_back(tempPath);
  1173. attemptedConfigs.push_back(ctest->GetConfigType());
  1174. // If the file is an OSX bundle then the configtyp
  1175. // will be at the start of the path
  1176. tempPath = ctest->GetConfigType();
  1177. tempPath += "/";
  1178. tempPath += filepath;
  1179. tempPath += filename;
  1180. attempted.push_back(tempPath);
  1181. attemptedConfigs.push_back(ctest->GetConfigType());
  1182. }
  1183. else
  1184. {
  1185. // no config specified to try some options
  1186. tempPath = filepath;
  1187. tempPath += "Release/";
  1188. tempPath += filename;
  1189. attempted.push_back(tempPath);
  1190. attemptedConfigs.push_back("Release");
  1191. tempPath = filepath;
  1192. tempPath += "Debug/";
  1193. tempPath += filename;
  1194. attempted.push_back(tempPath);
  1195. attemptedConfigs.push_back("Debug");
  1196. tempPath = filepath;
  1197. tempPath += "MinSizeRel/";
  1198. tempPath += filename;
  1199. attempted.push_back(tempPath);
  1200. attemptedConfigs.push_back("MinSizeRel");
  1201. tempPath = filepath;
  1202. tempPath += "RelWithDebInfo/";
  1203. tempPath += filename;
  1204. attempted.push_back(tempPath);
  1205. attemptedConfigs.push_back("RelWithDebInfo");
  1206. tempPath = filepath;
  1207. tempPath += "Deployment/";
  1208. tempPath += filename;
  1209. attempted.push_back(tempPath);
  1210. attemptedConfigs.push_back("Deployment");
  1211. tempPath = filepath;
  1212. tempPath += "Development/";
  1213. tempPath += filename;
  1214. attempted.push_back(tempPath);
  1215. attemptedConfigs.push_back("Deployment");
  1216. }
  1217. }
  1218. //----------------------------------------------------------------------
  1219. // Find the appropriate executable to run for a test
  1220. std::string cmCTestTestHandler
  1221. ::FindExecutable(cmCTest *ctest,
  1222. const char *testCommand,
  1223. std::string &resultingConfig,
  1224. std::vector<std::string> &extraPaths,
  1225. std::vector<std::string> &failed)
  1226. {
  1227. // now run the compiled test if we can find it
  1228. std::vector<std::string> attempted;
  1229. std::vector<std::string> attemptedConfigs;
  1230. std::string tempPath;
  1231. std::string filepath =
  1232. cmSystemTools::GetFilenamePath(testCommand);
  1233. std::string filename =
  1234. cmSystemTools::GetFilenameName(testCommand);
  1235. cmCTestTestHandler::AddConfigurations(ctest, attempted,
  1236. attemptedConfigs,
  1237. filepath,filename);
  1238. // even if a fullpath was specified also try it relative to the current
  1239. // directory
  1240. if (filepath.size() && filepath[0] == '/')
  1241. {
  1242. std::string localfilepath = filepath.substr(1,filepath.size()-1);
  1243. cmCTestTestHandler::AddConfigurations(ctest, attempted,
  1244. attemptedConfigs,
  1245. localfilepath,filename);
  1246. }
  1247. // if extraPaths are provided and we were not passed a full path, try them,
  1248. // try any extra paths
  1249. if (filepath.size() == 0)
  1250. {
  1251. for (unsigned int i = 0; i < extraPaths.size(); ++i)
  1252. {
  1253. std::string filepathExtra =
  1254. cmSystemTools::GetFilenamePath(extraPaths[i]);
  1255. std::string filenameExtra =
  1256. cmSystemTools::GetFilenameName(extraPaths[i]);
  1257. cmCTestTestHandler::AddConfigurations(ctest,attempted,
  1258. attemptedConfigs,
  1259. filepathExtra,
  1260. filenameExtra);
  1261. }
  1262. }
  1263. // store the final location in fullPath
  1264. std::string fullPath;
  1265. // now look in the paths we specified above
  1266. for(unsigned int ai=0;
  1267. ai < attempted.size() && fullPath.size() == 0; ++ai)
  1268. {
  1269. // first check without exe extension
  1270. if(cmSystemTools::FileExists(attempted[ai].c_str())
  1271. && !cmSystemTools::FileIsDirectory(attempted[ai].c_str()))
  1272. {
  1273. fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str());
  1274. resultingConfig = attemptedConfigs[ai];
  1275. }
  1276. // then try with the exe extension
  1277. else
  1278. {
  1279. failed.push_back(attempted[ai].c_str());
  1280. tempPath = attempted[ai];
  1281. tempPath += cmSystemTools::GetExecutableExtension();
  1282. if(cmSystemTools::FileExists(tempPath.c_str())
  1283. && !cmSystemTools::FileIsDirectory(tempPath.c_str()))
  1284. {
  1285. fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str());
  1286. resultingConfig = attemptedConfigs[ai];
  1287. }
  1288. else
  1289. {
  1290. failed.push_back(tempPath.c_str());
  1291. }
  1292. }
  1293. }
  1294. // if everything else failed, check the users path, but only if a full path
  1295. // wasn't specified
  1296. if (fullPath.size() == 0 && filepath.size() == 0)
  1297. {
  1298. std::string path = cmSystemTools::FindProgram(filename.c_str());
  1299. if (path != "")
  1300. {
  1301. resultingConfig = "";
  1302. return path;
  1303. }
  1304. }
  1305. if(fullPath.size() == 0)
  1306. {
  1307. cmCTestLog(ctest, HANDLER_OUTPUT,
  1308. "Could not find executable " << testCommand << "\n"
  1309. << "Looked in the following places:\n");
  1310. for(std::vector<std::string>::iterator i = failed.begin();
  1311. i != failed.end(); ++i)
  1312. {
  1313. cmCTestLog(ctest, HANDLER_OUTPUT,
  1314. i->c_str() << "\n");
  1315. }
  1316. }
  1317. return fullPath;
  1318. }
  1319. //----------------------------------------------------------------------
  1320. void cmCTestTestHandler::GetListOfTests()
  1321. {
  1322. if ( !this->IncludeLabelRegExp.empty() )
  1323. {
  1324. this->IncludeLabelRegularExpression.
  1325. compile(this->IncludeLabelRegExp.c_str());
  1326. }
  1327. if ( !this->IncludeLabelRegExp.empty() )
  1328. {
  1329. this->ExcludeLabelRegularExpression.
  1330. compile(this->ExcludeLabelRegExp.c_str());
  1331. }
  1332. if ( !this->IncludeRegExp.empty() )
  1333. {
  1334. this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
  1335. }
  1336. if ( !this->ExcludeRegExp.empty() )
  1337. {
  1338. this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
  1339. }
  1340. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1341. "Constructing a list of tests" << std::endl);
  1342. cmake cm;
  1343. cmGlobalGenerator gg;
  1344. gg.SetCMakeInstance(&cm);
  1345. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  1346. cmMakefile *mf = lg->GetMakefile();
  1347. mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
  1348. this->CTest->GetConfigType().c_str());
  1349. // Add handler for ADD_TEST
  1350. cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
  1351. newCom1->TestHandler = this;
  1352. cm.AddCommand(newCom1);
  1353. // Add handler for SUBDIRS
  1354. cmCTestSubdirCommand* newCom2 =
  1355. new cmCTestSubdirCommand;
  1356. newCom2->TestHandler = this;
  1357. cm.AddCommand(newCom2);
  1358. // Add handler for ADD_SUBDIRECTORY
  1359. cmCTestAddSubdirectoryCommand* newCom3 =
  1360. new cmCTestAddSubdirectoryCommand;
  1361. newCom3->TestHandler = this;
  1362. cm.AddCommand(newCom3);
  1363. // Add handler for SET_SOURCE_FILES_PROPERTIES
  1364. cmCTestSetTestsPropertiesCommand* newCom4
  1365. = new cmCTestSetTestsPropertiesCommand;
  1366. newCom4->TestHandler = this;
  1367. cm.AddCommand(newCom4);
  1368. const char* testFilename;
  1369. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  1370. {
  1371. // does the CTestTestfile.cmake exist ?
  1372. testFilename = "CTestTestfile.cmake";
  1373. }
  1374. else if( cmSystemTools::FileExists("DartTestfile.txt") )
  1375. {
  1376. // does the DartTestfile.txt exist ?
  1377. testFilename = "DartTestfile.txt";
  1378. }
  1379. else
  1380. {
  1381. return;
  1382. }
  1383. if ( !mf->ReadListFile(0, testFilename) )
  1384. {
  1385. return;
  1386. }
  1387. if ( cmSystemTools::GetErrorOccuredFlag() )
  1388. {
  1389. return;
  1390. }
  1391. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1392. "Done constructing a list of tests" << std::endl);
  1393. }
  1394. //----------------------------------------------------------------------
  1395. void cmCTestTestHandler::UseIncludeRegExp()
  1396. {
  1397. this->UseIncludeRegExpFlag = true;
  1398. }
  1399. //----------------------------------------------------------------------
  1400. void cmCTestTestHandler::UseExcludeRegExp()
  1401. {
  1402. this->UseExcludeRegExpFlag = true;
  1403. this->UseExcludeRegExpFirst = this->UseIncludeRegExpFlag ? false : true;
  1404. }
  1405. //----------------------------------------------------------------------
  1406. const char* cmCTestTestHandler::GetTestStatus(int status)
  1407. {
  1408. static const char statuses[][100] = {
  1409. "Not Run",
  1410. "Timeout",
  1411. "SEGFAULT",
  1412. "ILLEGAL",
  1413. "INTERRUPT",
  1414. "NUMERICAL",
  1415. "OTHER_FAULT",
  1416. "Failed",
  1417. "BAD_COMMAND",
  1418. "Completed"
  1419. };
  1420. if ( status < cmCTestTestHandler::NOT_RUN ||
  1421. status > cmCTestTestHandler::COMPLETED )
  1422. {
  1423. return "No Status";
  1424. }
  1425. return statuses[status];
  1426. }
  1427. //----------------------------------------------------------------------
  1428. void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests)
  1429. {
  1430. if (this->TestsToRunString.empty())
  1431. {
  1432. return;
  1433. }
  1434. int start;
  1435. int end = -1;
  1436. double stride = -1;
  1437. std::string::size_type pos = 0;
  1438. std::string::size_type pos2;
  1439. // read start
  1440. if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
  1441. {
  1442. // read end
  1443. if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
  1444. {
  1445. // read stride
  1446. if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
  1447. {
  1448. int val =0;
  1449. // now read specific numbers
  1450. while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
  1451. {
  1452. this->TestsToRun.push_back(val);
  1453. }
  1454. this->TestsToRun.push_back(val);
  1455. }
  1456. }
  1457. }
  1458. // if start is not specified then we assume we start at 1
  1459. if(start == -1)
  1460. {
  1461. start = 1;
  1462. }
  1463. // if end isnot specified then we assume we end with the last test
  1464. if(end == -1)
  1465. {
  1466. end = static_cast<int>(numTests);
  1467. }
  1468. // if the stride wasn't specified then it defaults to 1
  1469. if(stride == -1)
  1470. {
  1471. stride = 1;
  1472. }
  1473. // if we have a range then add it
  1474. if(end != -1 && start != -1 && stride > 0)
  1475. {
  1476. int i = 0;
  1477. while (i*stride + start <= end)
  1478. {
  1479. this->TestsToRun.push_back(static_cast<int>(i*stride+start));
  1480. ++i;
  1481. }
  1482. }
  1483. // sort the array
  1484. std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
  1485. std::less<int>());
  1486. // remove duplicates
  1487. std::vector<int>::iterator new_end =
  1488. std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
  1489. this->TestsToRun.erase(new_end, this->TestsToRun.end());
  1490. }
  1491. //----------------------------------------------------------------------
  1492. // Just for convenience
  1493. #define SPACE_REGEX "[ \t\r\n]"
  1494. //----------------------------------------------------------------------
  1495. std::string cmCTestTestHandler::GenerateRegressionImages(
  1496. const std::string& xml)
  1497. {
  1498. cmsys::RegularExpression twoattributes(
  1499. "<DartMeasurement"
  1500. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1501. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1502. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1503. cmsys::RegularExpression threeattributes(
  1504. "<DartMeasurement"
  1505. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1506. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1507. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1508. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1509. cmsys::RegularExpression fourattributes(
  1510. "<DartMeasurement"
  1511. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1512. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1513. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1514. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1515. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1516. cmsys::RegularExpression cdatastart(
  1517. "<DartMeasurement"
  1518. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1519. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1520. SPACE_REGEX "*>"
  1521. SPACE_REGEX "*<!\\[CDATA\\[");
  1522. cmsys::RegularExpression cdataend(
  1523. "]]>"
  1524. SPACE_REGEX "*</DartMeasurement>");
  1525. cmsys::RegularExpression measurementfile(
  1526. "<DartMeasurementFile"
  1527. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1528. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1529. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  1530. cmOStringStream ostr;
  1531. bool done = false;
  1532. std::string cxml = xml;
  1533. while ( ! done )
  1534. {
  1535. if ( twoattributes.find(cxml) )
  1536. {
  1537. ostr
  1538. << "\t\t\t<NamedMeasurement"
  1539. << " " << twoattributes.match(1) << "=\""
  1540. << twoattributes.match(2) << "\""
  1541. << " " << twoattributes.match(3) << "=\""
  1542. << twoattributes.match(4) << "\""
  1543. << "><Value>" << twoattributes.match(5)
  1544. << "</Value></NamedMeasurement>"
  1545. << std::endl;
  1546. cxml.erase(twoattributes.start(),
  1547. twoattributes.end() - twoattributes.start());
  1548. }
  1549. else if ( threeattributes.find(cxml) )
  1550. {
  1551. ostr
  1552. << "\t\t\t<NamedMeasurement"
  1553. << " " << threeattributes.match(1) << "=\""
  1554. << threeattributes.match(2) << "\""
  1555. << " " << threeattributes.match(3) << "=\""
  1556. << threeattributes.match(4) << "\""
  1557. << " " << threeattributes.match(5) << "=\""
  1558. << threeattributes.match(6) << "\""
  1559. << "><Value>" << threeattributes.match(7)
  1560. << "</Value></NamedMeasurement>"
  1561. << std::endl;
  1562. cxml.erase(threeattributes.start(),
  1563. threeattributes.end() - threeattributes.start());
  1564. }
  1565. else if ( fourattributes.find(cxml) )
  1566. {
  1567. ostr
  1568. << "\t\t\t<NamedMeasurement"
  1569. << " " << fourattributes.match(1) << "=\""
  1570. << fourattributes.match(2) << "\""
  1571. << " " << fourattributes.match(3) << "=\""
  1572. << fourattributes.match(4) << "\""
  1573. << " " << fourattributes.match(5) << "=\""
  1574. << fourattributes.match(6) << "\""
  1575. << " " << fourattributes.match(7) << "=\""
  1576. << fourattributes.match(8) << "\""
  1577. << "><Value>" << fourattributes.match(9)
  1578. << "</Value></NamedMeasurement>"
  1579. << std::endl;
  1580. cxml.erase(fourattributes.start(),
  1581. fourattributes.end() - fourattributes.start());
  1582. }
  1583. else if ( cdatastart.find(cxml) && cdataend.find(cxml) )
  1584. {
  1585. ostr
  1586. << "\t\t\t<NamedMeasurement"
  1587. << " " << cdatastart.match(1) << "=\""
  1588. << cdatastart.match(2) << "\""
  1589. << " " << cdatastart.match(3) << "=\""
  1590. << cdatastart.match(4) << "\""
  1591. << "><Value><![CDATA["
  1592. << cxml.substr(cdatastart.end(), cdataend.start() - cdatastart.end())
  1593. << "]]></Value></NamedMeasurement>"
  1594. << std::endl;
  1595. cxml.erase(cdatastart.start(),
  1596. cdataend.end() - cdatastart.start());
  1597. }
  1598. else if ( measurementfile.find(cxml) )
  1599. {
  1600. const std::string& filename =
  1601. cmCTest::CleanString(measurementfile.match(5));
  1602. if ( cmSystemTools::FileExists(filename.c_str()) )
  1603. {
  1604. long len = cmSystemTools::FileLength(filename.c_str());
  1605. if ( len == 0 )
  1606. {
  1607. std::string k1 = measurementfile.match(1);
  1608. std::string v1 = measurementfile.match(2);
  1609. std::string k2 = measurementfile.match(3);
  1610. std::string v2 = measurementfile.match(4);
  1611. if ( cmSystemTools::LowerCase(k1) == "type" )
  1612. {
  1613. v1 = "text/string";
  1614. }
  1615. if ( cmSystemTools::LowerCase(k2) == "type" )
  1616. {
  1617. v2 = "text/string";
  1618. }
  1619. ostr
  1620. << "\t\t\t<NamedMeasurement"
  1621. << " " << k1 << "=\"" << v1 << "\""
  1622. << " " << k2 << "=\"" << v2 << "\""
  1623. << " encoding=\"none\""
  1624. << "><Value>Image " << filename.c_str()
  1625. << " is empty</Value></NamedMeasurement>";
  1626. }
  1627. else
  1628. {
  1629. std::ifstream ifs(filename.c_str(), std::ios::in
  1630. #ifdef _WIN32
  1631. | std::ios::binary
  1632. #endif
  1633. );
  1634. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  1635. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1636. unsigned char *encoded_buffer
  1637. = new unsigned char [ static_cast<int>(len * 1.5 + 5) ];
  1638. unsigned long rlen
  1639. = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1640. unsigned long cc;
  1641. ostr
  1642. << "\t\t\t<NamedMeasurement"
  1643. << " " << measurementfile.match(1) << "=\""
  1644. << measurementfile.match(2) << "\""
  1645. << " " << measurementfile.match(3) << "=\""
  1646. << measurementfile.match(4) << "\""
  1647. << " encoding=\"base64\""
  1648. << ">" << std::endl << "\t\t\t\t<Value>";
  1649. for ( cc = 0; cc < rlen; cc ++ )
  1650. {
  1651. ostr << encoded_buffer[cc];
  1652. if ( cc % 60 == 0 && cc )
  1653. {
  1654. ostr << std::endl;
  1655. }
  1656. }
  1657. ostr
  1658. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  1659. << std::endl;
  1660. delete [] file_buffer;
  1661. delete [] encoded_buffer;
  1662. }
  1663. }
  1664. else
  1665. {
  1666. int idx = 4;
  1667. if ( measurementfile.match(1) == "name" )
  1668. {
  1669. idx = 2;
  1670. }
  1671. ostr
  1672. << "\t\t\t<NamedMeasurement"
  1673. << " name=\"" << measurementfile.match(idx) << "\""
  1674. << " text=\"text/string\""
  1675. << "><Value>File " << filename.c_str()
  1676. << " not found</Value></NamedMeasurement>"
  1677. << std::endl;
  1678. cmCTestLog(this->CTest, HANDLER_OUTPUT, "File \"" << filename.c_str()
  1679. << "\" not found." << std::endl);
  1680. }
  1681. cxml.erase(measurementfile.start(),
  1682. measurementfile.end() - measurementfile.start());
  1683. }
  1684. else
  1685. {
  1686. done = true;
  1687. }
  1688. }
  1689. return ostr.str();
  1690. }
  1691. //----------------------------------------------------------------------
  1692. void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
  1693. {
  1694. this->IncludeRegExp = arg;
  1695. }
  1696. //----------------------------------------------------------------------
  1697. void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
  1698. {
  1699. this->ExcludeRegExp = arg;
  1700. }
  1701. //----------------------------------------------------------------------
  1702. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1703. {
  1704. if ( !in )
  1705. {
  1706. return;
  1707. }
  1708. this->TestsToRunString = in;
  1709. // if the argument is a file, then read it and use the contents as the
  1710. // string
  1711. if(cmSystemTools::FileExists(in))
  1712. {
  1713. std::ifstream fin(in);
  1714. unsigned long filelen = cmSystemTools::FileLength(in);
  1715. char* buff = new char[filelen+1];
  1716. fin.getline(buff, filelen);
  1717. buff[fin.gcount()] = 0;
  1718. this->TestsToRunString = buff;
  1719. }
  1720. }
  1721. //----------------------------------------------------------------------
  1722. bool cmCTestTestHandler::CleanTestOutput(std::string& output,
  1723. size_t remove_threshold)
  1724. {
  1725. if ( remove_threshold == 0 )
  1726. {
  1727. return true;
  1728. }
  1729. if ( output.find("CTEST_FULL_OUTPUT") != output.npos )
  1730. {
  1731. return true;
  1732. }
  1733. cmOStringStream ostr;
  1734. std::string::size_type cc;
  1735. std::string::size_type skipsize = 0;
  1736. int inTag = 0;
  1737. int skipped = 0;
  1738. for ( cc = 0; cc < output.size(); cc ++ )
  1739. {
  1740. int ch = output[cc];
  1741. if ( ch < 0 || ch > 255 )
  1742. {
  1743. break;
  1744. }
  1745. if ( ch == '<' )
  1746. {
  1747. inTag = 1;
  1748. }
  1749. if ( !inTag )
  1750. {
  1751. int notskip = 0;
  1752. // Skip
  1753. if ( skipsize < remove_threshold )
  1754. {
  1755. ostr << static_cast<char>(ch);
  1756. notskip = 1;
  1757. }
  1758. skipsize ++;
  1759. if ( notskip && skipsize >= remove_threshold )
  1760. {
  1761. skipped = 1;
  1762. }
  1763. }
  1764. else
  1765. {
  1766. ostr << static_cast<char>(ch);
  1767. }
  1768. if ( ch == '>' )
  1769. {
  1770. inTag = 0;
  1771. }
  1772. }
  1773. if ( skipped )
  1774. {
  1775. ostr << "..." << std::endl << "The rest of the test output was removed "
  1776. "since it exceeds the threshold of "
  1777. << remove_threshold << " characters." << std::endl;
  1778. }
  1779. output = ostr.str();
  1780. return true;
  1781. }
  1782. //----------------------------------------------------------------------
  1783. bool cmCTestTestHandler::SetTestsProperties(
  1784. const std::vector<std::string>& args)
  1785. {
  1786. std::vector<std::string>::const_iterator it;
  1787. std::vector<cmStdString> tests;
  1788. bool found = false;
  1789. for ( it = args.begin(); it != args.end(); ++ it )
  1790. {
  1791. if ( *it == "PROPERTIES" )
  1792. {
  1793. found = true;
  1794. break;
  1795. }
  1796. tests.push_back(*it);
  1797. }
  1798. if ( !found )
  1799. {
  1800. return false;
  1801. }
  1802. ++ it; // skip PROPERTIES
  1803. for ( ; it != args.end(); ++ it )
  1804. {
  1805. std::string key = *it;
  1806. ++ it;
  1807. if ( it == args.end() )
  1808. {
  1809. break;
  1810. }
  1811. std::string val = *it;
  1812. std::vector<cmStdString>::const_iterator tit;
  1813. for ( tit = tests.begin(); tit != tests.end(); ++ tit )
  1814. {
  1815. cmCTestTestHandler::ListOfTests::iterator rtit;
  1816. for ( rtit = this->TestList.begin();
  1817. rtit != this->TestList.end();
  1818. ++ rtit )
  1819. {
  1820. if ( *tit == rtit->Name )
  1821. {
  1822. if ( key == "WILL_FAIL" )
  1823. {
  1824. rtit->WillFail = cmSystemTools::IsOn(val.c_str());
  1825. }
  1826. if ( key == "TIMEOUT" )
  1827. {
  1828. rtit->Timeout = atof(val.c_str());
  1829. }
  1830. if ( key == "EXPENSIVE" )
  1831. {
  1832. rtit->Expensive = cmSystemTools::IsOn(val.c_str());
  1833. }
  1834. if ( key == "FAIL_REGULAR_EXPRESSION" )
  1835. {
  1836. std::vector<std::string> lval;
  1837. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1838. std::vector<std::string>::iterator crit;
  1839. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1840. {
  1841. rtit->ErrorRegularExpressions.push_back(
  1842. std::pair<cmsys::RegularExpression, std::string>(
  1843. cmsys::RegularExpression(crit->c_str()),
  1844. std::string(crit->c_str())));
  1845. }
  1846. }
  1847. if ( key == "PROCESSORS" )
  1848. {
  1849. rtit->Processors = atoi(val.c_str());
  1850. if(rtit->Processors < 1)
  1851. {
  1852. rtit->Processors = 1;
  1853. }
  1854. }
  1855. if ( key == "DEPENDS" )
  1856. {
  1857. std::vector<std::string> lval;
  1858. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1859. std::vector<std::string>::iterator crit;
  1860. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1861. {
  1862. rtit->Depends.push_back(*crit);
  1863. }
  1864. }
  1865. if ( key == "ENVIRONMENT" )
  1866. {
  1867. std::vector<std::string> lval;
  1868. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1869. std::vector<std::string>::iterator crit;
  1870. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1871. {
  1872. rtit->Environment.push_back(*crit);
  1873. }
  1874. }
  1875. if ( key == "LABELS" )
  1876. {
  1877. std::vector<std::string> lval;
  1878. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1879. std::vector<std::string>::iterator crit;
  1880. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1881. {
  1882. rtit->Labels.push_back(*crit);
  1883. }
  1884. }
  1885. if ( key == "MEASUREMENT" )
  1886. {
  1887. size_t pos = val.find_first_of("=");
  1888. if ( pos != val.npos )
  1889. {
  1890. std::string mKey = val.substr(0, pos);
  1891. const char* mVal = val.c_str() + pos + 1;
  1892. rtit->Measurements[mKey] = mVal;
  1893. }
  1894. else
  1895. {
  1896. rtit->Measurements[val] = "1";
  1897. }
  1898. }
  1899. if ( key == "PASS_REGULAR_EXPRESSION" )
  1900. {
  1901. std::vector<std::string> lval;
  1902. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1903. std::vector<std::string>::iterator crit;
  1904. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1905. {
  1906. rtit->RequiredRegularExpressions.push_back(
  1907. std::pair<cmsys::RegularExpression, std::string>(
  1908. cmsys::RegularExpression(crit->c_str()),
  1909. std::string(crit->c_str())));
  1910. }
  1911. }
  1912. }
  1913. }
  1914. }
  1915. }
  1916. return true;
  1917. }
  1918. //----------------------------------------------------------------------
  1919. bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
  1920. {
  1921. const std::string& testname = args[0];
  1922. cmCTestLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl);
  1923. if (this->UseExcludeRegExpFlag &&
  1924. this->UseExcludeRegExpFirst &&
  1925. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  1926. {
  1927. return true;
  1928. }
  1929. if ( this->MemCheck )
  1930. {
  1931. std::vector<cmStdString>::iterator it;
  1932. bool found = false;
  1933. for ( it = this->CustomTestsIgnore.begin();
  1934. it != this->CustomTestsIgnore.end(); ++ it )
  1935. {
  1936. if ( *it == testname )
  1937. {
  1938. found = true;
  1939. break;
  1940. }
  1941. }
  1942. if ( found )
  1943. {
  1944. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: "
  1945. << *it << std::endl);
  1946. return true;
  1947. }
  1948. }
  1949. else
  1950. {
  1951. std::vector<cmStdString>::iterator it;
  1952. bool found = false;
  1953. for ( it = this->CustomTestsIgnore.begin();
  1954. it != this->CustomTestsIgnore.end(); ++ it )
  1955. {
  1956. if ( *it == testname )
  1957. {
  1958. found = true;
  1959. break;
  1960. }
  1961. }
  1962. if ( found )
  1963. {
  1964. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: "
  1965. << *it << std::endl);
  1966. return true;
  1967. }
  1968. }
  1969. cmCTestTestProperties test;
  1970. test.Name = testname;
  1971. test.Args = args;
  1972. test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
  1973. cmCTestLog(this->CTest, DEBUG, "Set test directory: "
  1974. << test.Directory << std::endl);
  1975. test.IsInBasedOnREOptions = true;
  1976. test.WillFail = false;
  1977. test.Expensive = false;
  1978. test.Timeout = 0;
  1979. test.Processors = 1;
  1980. if (this->UseIncludeRegExpFlag &&
  1981. !this->IncludeTestsRegularExpression.find(testname.c_str()))
  1982. {
  1983. test.IsInBasedOnREOptions = false;
  1984. }
  1985. else if (this->UseExcludeRegExpFlag &&
  1986. !this->UseExcludeRegExpFirst &&
  1987. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  1988. {
  1989. test.IsInBasedOnREOptions = false;
  1990. }
  1991. this->TestList.push_back(test);
  1992. return true;
  1993. }