cmCTestTestHandler.cxx 73 KB

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