cmCTestTestHandler.cxx 77 KB

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