cmCTestTestHandler.cxx 67 KB

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