cmCTestTestHandler.cxx 78 KB

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