cmCTestTestHandler.cxx 59 KB

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