cmCTestTestHandler.cxx 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestTestHandler.h"
  14. #include "cmCTest.h"
  15. #include "cmake.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include <cmsys/Process.h>
  18. #include <cmsys/RegularExpression.hxx>
  19. #include <cmsys/Base64.h>
  20. #include "cmMakefile.h"
  21. #include "cmGlobalGenerator.h"
  22. #include "cmLocalGenerator.h"
  23. #include "cmCommand.h"
  24. #include <stdlib.h>
  25. #include <math.h>
  26. #include <float.h>
  27. #include <memory> // auto_ptr
  28. //----------------------------------------------------------------------
  29. class cmCTestSubdirCommand : public cmCommand
  30. {
  31. public:
  32. /**
  33. * This is a virtual constructor for the command.
  34. */
  35. virtual cmCommand* Clone()
  36. {
  37. cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
  38. c->m_TestHandler = m_TestHandler;
  39. return c;
  40. }
  41. /**
  42. * This is called when the command is first encountered in
  43. * the CMakeLists.txt file.
  44. */
  45. virtual bool InitialPass(std::vector<std::string> const& args);
  46. /**
  47. * The name of the command as specified in CMakeList.txt.
  48. */
  49. virtual const char* GetName() { return "SUBDIRS";}
  50. // Unused methods
  51. virtual const char* GetTerseDocumentation() { return ""; }
  52. virtual const char* GetFullDocumentation() { return ""; }
  53. cmTypeMacro(cmCTestSubdirCommand, cmCommand);
  54. cmCTestTestHandler* m_TestHandler;
  55. };
  56. //----------------------------------------------------------------------
  57. bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args)
  58. {
  59. if(args.size() < 1 )
  60. {
  61. this->SetError("called with incorrect number of arguments");
  62. return false;
  63. }
  64. std::vector<std::string>::const_iterator it;
  65. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  66. for ( it = args.begin(); it != args.end(); ++ it )
  67. {
  68. std::string fname = cwd;
  69. fname += "/";
  70. fname += *it;
  71. if ( !cmSystemTools::FileExists(fname.c_str()) )
  72. {
  73. std::string m = "Could not find directory: ";
  74. m += fname;
  75. this->SetError(m.c_str());
  76. return false;
  77. }
  78. cmSystemTools::ChangeDirectory(fname.c_str());
  79. const char* testFilename;
  80. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  81. {
  82. // does the CTestTestfile.cmake exist ?
  83. testFilename = "CTestTestfile.cmake";
  84. }
  85. else if( cmSystemTools::FileExists("DartTestfile.txt") )
  86. {
  87. // does the DartTestfile.txt exist ?
  88. testFilename = "DartTestfile.txt";
  89. }
  90. else
  91. {
  92. cmSystemTools::ChangeDirectory(cwd.c_str());
  93. return false;
  94. }
  95. fname += "/";
  96. fname += testFilename;
  97. bool readit = m_Makefile->ReadListFile( m_Makefile->GetCurrentListFile(), fname.c_str());
  98. cmSystemTools::ChangeDirectory(cwd.c_str());
  99. if(!readit)
  100. {
  101. std::string m = "Could not find include file: ";
  102. m += fname;
  103. this->SetError(m.c_str());
  104. return false;
  105. }
  106. }
  107. return true;
  108. }
  109. //----------------------------------------------------------------------
  110. class cmCTestAddTestCommand : public cmCommand
  111. {
  112. public:
  113. /**
  114. * This is a virtual constructor for the command.
  115. */
  116. virtual cmCommand* Clone()
  117. {
  118. cmCTestAddTestCommand* c = new cmCTestAddTestCommand;
  119. c->m_TestHandler = m_TestHandler;
  120. return c;
  121. }
  122. /**
  123. * This is called when the command is first encountered in
  124. * the CMakeLists.txt file.
  125. */
  126. virtual bool InitialPass(std::vector<std::string> const&);
  127. /**
  128. * The name of the command as specified in CMakeList.txt.
  129. */
  130. virtual const char* GetName() { return "ADD_TEST";}
  131. // Unused methods
  132. virtual const char* GetTerseDocumentation() { return ""; }
  133. virtual const char* GetFullDocumentation() { return ""; }
  134. cmTypeMacro(cmCTestAddTestCommand, cmCommand);
  135. cmCTestTestHandler* m_TestHandler;
  136. };
  137. //----------------------------------------------------------------------
  138. bool cmCTestAddTestCommand::InitialPass(std::vector<std::string> const& args)
  139. {
  140. if ( args.size() < 2 )
  141. {
  142. this->SetError("called with incorrect number of arguments");
  143. return false;
  144. }
  145. return m_TestHandler->AddTest(args);
  146. }
  147. //----------------------------------------------------------------------
  148. bool TryExecutable(const char *dir, const char *file,
  149. std::string *fullPath, const char *subdir)
  150. {
  151. // try current directory
  152. std::string tryPath;
  153. if (dir && strcmp(dir,""))
  154. {
  155. tryPath = dir;
  156. tryPath += "/";
  157. }
  158. if (subdir && strcmp(subdir,""))
  159. {
  160. tryPath += subdir;
  161. tryPath += "/";
  162. }
  163. tryPath += file;
  164. if(cmSystemTools::FileExists(tryPath.c_str()))
  165. {
  166. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  167. return true;
  168. }
  169. tryPath += cmSystemTools::GetExecutableExtension();
  170. if(cmSystemTools::FileExists(tryPath.c_str()))
  171. {
  172. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  173. return true;
  174. }
  175. return false;
  176. }
  177. //----------------------------------------------------------------------
  178. // get the next number in a string with numbers separated by ,
  179. // pos is the start of the search and pos2 is the end of the search
  180. // pos becomes pos2 after a call to GetNextNumber.
  181. // -1 is returned at the end of the list.
  182. inline int GetNextNumber(std::string const& in,
  183. int& val,
  184. std::string::size_type& pos,
  185. std::string::size_type& pos2)
  186. {
  187. pos2 = in.find(',', pos);
  188. if(pos2 != in.npos)
  189. {
  190. if(pos2-pos == 0)
  191. {
  192. val = -1;
  193. }
  194. else
  195. {
  196. val = atoi(in.substr(pos, pos2-pos).c_str());
  197. }
  198. pos = pos2+1;
  199. return 1;
  200. }
  201. else
  202. {
  203. if(in.size()-pos == 0)
  204. {
  205. val = -1;
  206. }
  207. else
  208. {
  209. val = atoi(in.substr(pos, in.size()-pos).c_str());
  210. }
  211. return 0;
  212. }
  213. }
  214. //----------------------------------------------------------------------
  215. // get the next number in a string with numbers separated by ,
  216. // pos is the start of the search and pos2 is the end of the search
  217. // pos becomes pos2 after a call to GetNextNumber.
  218. // -1 is returned at the end of the list.
  219. inline int GetNextRealNumber(std::string const& in,
  220. double& val,
  221. std::string::size_type& pos,
  222. std::string::size_type& pos2)
  223. {
  224. pos2 = in.find(',', pos);
  225. if(pos2 != in.npos)
  226. {
  227. if(pos2-pos == 0)
  228. {
  229. val = -1;
  230. }
  231. else
  232. {
  233. val = atof(in.substr(pos, pos2-pos).c_str());
  234. }
  235. pos = pos2+1;
  236. return 1;
  237. }
  238. else
  239. {
  240. if(in.size()-pos == 0)
  241. {
  242. val = -1;
  243. }
  244. else
  245. {
  246. val = atof(in.substr(pos, in.size()-pos).c_str());
  247. }
  248. return 0;
  249. }
  250. }
  251. //----------------------------------------------------------------------
  252. cmCTestTestHandler::cmCTestTestHandler()
  253. {
  254. m_UseUnion = false;
  255. m_UseIncludeRegExp = false;
  256. m_UseExcludeRegExp = false;
  257. m_UseExcludeRegExpFirst = false;
  258. m_CustomMaximumPassedTestOutputSize = 1 * 1024;
  259. m_CustomMaximumFailedTestOutputSize = 300 * 1024;
  260. m_MemCheck = false;
  261. }
  262. //----------------------------------------------------------------------
  263. void cmCTestTestHandler::Initialize()
  264. {
  265. this->Superclass::Initialize();
  266. m_ElapsedTestingTime = -1;
  267. m_TestResults.clear();
  268. m_CustomTestsIgnore.clear();
  269. m_StartTest = "";
  270. m_EndTest = "";
  271. m_CustomPreTest.clear();
  272. m_CustomPostTest.clear();
  273. m_CustomMaximumPassedTestOutputSize = 1 * 1024;
  274. m_CustomMaximumFailedTestOutputSize = 300 * 1024;
  275. m_TestsToRun.clear();
  276. m_UseIncludeRegExp = false;
  277. m_UseExcludeRegExp = false;
  278. m_UseExcludeRegExpFirst = false;
  279. m_IncludeRegExp = "";
  280. m_ExcludeRegExp = "";
  281. TestsToRunString = "";
  282. m_UseUnion = false;
  283. m_TestList.clear();
  284. }
  285. //----------------------------------------------------------------------
  286. void cmCTestTestHandler::PopulateCustomVectors(cmMakefile *mf)
  287. {
  288. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST",
  289. m_CustomPreTest);
  290. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST",
  291. m_CustomPostTest);
  292. cmCTest::PopulateCustomVector(mf,
  293. "CTEST_CUSTOM_TESTS_IGNORE",
  294. m_CustomTestsIgnore);
  295. cmCTest::PopulateCustomInteger(mf,
  296. "CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE",
  297. m_CustomMaximumPassedTestOutputSize);
  298. cmCTest::PopulateCustomInteger(mf,
  299. "CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE",
  300. m_CustomMaximumFailedTestOutputSize);
  301. }
  302. //----------------------------------------------------------------------
  303. int cmCTestTestHandler::PreProcessHandler()
  304. {
  305. if ( !this->ExecuteCommands(m_CustomPreTest) )
  306. {
  307. cmCTestLog(m_CTest, ERROR_MESSAGE, "Problem executing pre-test command(s)." << std::endl);
  308. return 0;
  309. }
  310. return 1;
  311. }
  312. //----------------------------------------------------------------------
  313. int cmCTestTestHandler::PostProcessHandler()
  314. {
  315. if ( !this->ExecuteCommands(m_CustomPostTest) )
  316. {
  317. cmCTestLog(m_CTest, ERROR_MESSAGE, "Problem executing post-test command(s)." << std::endl);
  318. return 0;
  319. }
  320. return 1;
  321. }
  322. //----------------------------------------------------------------------
  323. //clearly it would be nice if this were broken up into a few smaller
  324. //functions and commented...
  325. int cmCTestTestHandler::ProcessHandler()
  326. {
  327. // Update internal data structure from generic one
  328. this->SetTestsToRunInformation(this->GetOption("TestsToRunInformation"));
  329. this->SetUseUnion(cmSystemTools::IsOn(this->GetOption("UseUnion")));
  330. const char* val;
  331. val = this->GetOption("IncludeRegularExpression");
  332. if ( val )
  333. {
  334. this->UseIncludeRegExp();
  335. this->SetIncludeRegExp(val);
  336. }
  337. val = this->GetOption("ExcludeRegularExpression");
  338. if ( val )
  339. {
  340. this->UseExcludeRegExp();
  341. this->SetExcludeRegExp(val);
  342. }
  343. m_TestResults.clear();
  344. cmCTestLog(m_CTest, HANDLER_OUTPUT, (m_MemCheck ? "Memory check" : "Test") << " project" << std::endl);
  345. if ( ! this->PreProcessHandler() )
  346. {
  347. return -1;
  348. }
  349. std::vector<cmStdString> passed;
  350. std::vector<cmStdString> failed;
  351. int total;
  352. this->ProcessDirectory(passed, failed);
  353. total = int(passed.size()) + int(failed.size());
  354. if (total == 0)
  355. {
  356. if ( !m_CTest->GetShowOnly() )
  357. {
  358. cmCTestLog(m_CTest, ERROR_MESSAGE, "No tests were found!!!" << std::endl);
  359. }
  360. }
  361. else
  362. {
  363. if (m_HandlerVerbose && passed.size() &&
  364. (m_UseIncludeRegExp || m_UseExcludeRegExp))
  365. {
  366. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, std::endl << "The following tests passed:" << std::endl);
  367. for(std::vector<cmStdString>::iterator j = passed.begin();
  368. j != passed.end(); ++j)
  369. {
  370. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "\t" << *j << std::endl);
  371. }
  372. }
  373. float percent = float(passed.size()) * 100.0f / total;
  374. if ( failed.size() > 0 && percent > 99)
  375. {
  376. percent = 99;
  377. }
  378. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl << static_cast<int>(percent + .5) << "% tests passed, "
  379. << failed.size() << " tests failed out of " << total << std::endl);
  380. //fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  381. // percent, int(failed.size()), total);
  382. if (failed.size())
  383. {
  384. cmGeneratedFileStream ofs;
  385. cmCTestLog(m_CTest, ERROR_MESSAGE, std::endl << "The following tests FAILED:" << std::endl);
  386. this->StartLogFile("TestsFailed", ofs);
  387. std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator ftit;
  388. for(ftit = m_TestResults.begin();
  389. ftit != m_TestResults.end(); ++ftit)
  390. {
  391. if ( ftit->m_Status != cmCTestTestHandler::COMPLETED )
  392. {
  393. ofs << ftit->m_TestCount << ":" << ftit->m_Name << std::endl;
  394. cmCTestLog(m_CTest, HANDLER_OUTPUT, "\t" << std::setw(3) << ftit->m_TestCount << " - " << ftit->m_Name.c_str() << " (" << this->GetTestStatus(ftit->m_Status) << ")" << std::endl);
  395. //fprintf(stderr, "\t%3d - %s (%s)\n", ftit->m_TestCount, ftit->m_Name.c_str(),
  396. // this->GetTestStatus(ftit->m_Status));
  397. }
  398. }
  399. }
  400. }
  401. if ( m_CTest->GetProduceXML() )
  402. {
  403. cmGeneratedFileStream xmlfile;
  404. if( !this->StartResultingXML((m_MemCheck ? "DynamicAnalysis" : "Test"), xmlfile) )
  405. {
  406. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot create " << (m_MemCheck ? "memory check" : "testing")
  407. << " XML file" << std::endl);
  408. return 1;
  409. }
  410. this->GenerateDartOutput(xmlfile);
  411. }
  412. if ( ! this->PostProcessHandler() )
  413. {
  414. return -1;
  415. }
  416. if ( !failed.empty() )
  417. {
  418. return -1;
  419. }
  420. return 0;
  421. }
  422. //----------------------------------------------------------------------
  423. void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
  424. std::vector<cmStdString> &failed)
  425. {
  426. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  427. cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  428. m_TestList.clear();
  429. this->GetListOfTests();
  430. tm_ListOfTests::size_type tmsize = m_TestList.size();
  431. cmGeneratedFileStream ofs;
  432. cmGeneratedFileStream *olog = 0;
  433. if ( !m_CTest->GetShowOnly() && tmsize > 0 &&
  434. this->StartResultingXML((m_MemCheck?"MemCheck":"Test"), ofs) )
  435. {
  436. olog = &ofs;
  437. }
  438. m_StartTest = m_CTest->CurrentTime();
  439. double elapsed_time_start = cmSystemTools::GetTime();
  440. if ( olog )
  441. {
  442. *olog << "Start testing: " << m_StartTest << std::endl
  443. << "----------------------------------------------------------"
  444. << std::endl;
  445. }
  446. // how many tests are in based on RegExp?
  447. int inREcnt = 0;
  448. tm_ListOfTests::iterator it;
  449. for ( it = m_TestList.begin(); it != m_TestList.end(); it ++ )
  450. {
  451. if (it->m_IsInBasedOnREOptions)
  452. {
  453. inREcnt ++;
  454. }
  455. }
  456. // expand the test list based on the union flag
  457. if (m_UseUnion)
  458. {
  459. this->ExpandTestsToRunInformation((int)tmsize);
  460. }
  461. else
  462. {
  463. this->ExpandTestsToRunInformation(inREcnt);
  464. }
  465. int cnt = 0;
  466. inREcnt = 0;
  467. std::string last_directory = "";
  468. for ( it = m_TestList.begin(); it != m_TestList.end(); it ++ )
  469. {
  470. cnt ++;
  471. if (it->m_IsInBasedOnREOptions)
  472. {
  473. inREcnt++;
  474. }
  475. const std::string& testname = it->m_Name;
  476. std::vector<std::string>& args = it->m_Args;
  477. cmCTestTestResult cres;
  478. cres.m_Status = cmCTestTestHandler::NOT_RUN;
  479. cres.m_TestCount = cnt;
  480. if (!(last_directory == it->m_Directory))
  481. {
  482. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Changing directory into "
  483. << it->m_Directory.c_str() << "\n");
  484. last_directory = it->m_Directory;
  485. cmSystemTools::ChangeDirectory(it->m_Directory.c_str());
  486. }
  487. cres.m_Name = testname;
  488. cres.m_Path = it->m_Directory.c_str();
  489. if (m_UseUnion)
  490. {
  491. // if it is not in the list and not in the regexp then skip
  492. if ((m_TestsToRun.size() &&
  493. std::find(m_TestsToRun.begin(), m_TestsToRun.end(), cnt)
  494. == m_TestsToRun.end()) && !it->m_IsInBasedOnREOptions)
  495. {
  496. continue;
  497. }
  498. }
  499. else
  500. {
  501. // is this test in the list of tests to run? If not then skip it
  502. if ((m_TestsToRun.size() &&
  503. std::find(m_TestsToRun.begin(), m_TestsToRun.end(), inREcnt)
  504. == m_TestsToRun.end()) || !it->m_IsInBasedOnREOptions)
  505. {
  506. continue;
  507. }
  508. }
  509. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::setw(3) << cnt << "/");
  510. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::setw(3) << tmsize << " Testing ");
  511. std::string outname = testname;
  512. outname.resize(30, ' ');
  513. if ( m_CTest->GetShowOnly() )
  514. {
  515. cmCTestLog(m_CTest, HANDLER_OUTPUT, outname.c_str() << std::endl);
  516. }
  517. else
  518. {
  519. cmCTestLog(m_CTest, HANDLER_OUTPUT, outname.c_str());
  520. }
  521. cmCTestLog(m_CTest, DEBUG, "Testing " << args[0].c_str() << " ... ");
  522. // find the test executable
  523. std::string actualCommand = this->FindTheExecutable(args[1].c_str());
  524. std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
  525. // continue if we did not find the executable
  526. if (testCommand == "")
  527. {
  528. cmCTestLog(m_CTest, ERROR_MESSAGE, "Unable to find executable: "
  529. << args[1].c_str() << std::endl);
  530. if ( !m_CTest->GetShowOnly() )
  531. {
  532. cres.m_FullCommandLine = actualCommand;
  533. m_TestResults.push_back( cres );
  534. failed.push_back(testname);
  535. continue;
  536. }
  537. }
  538. // add the arguments
  539. std::vector<std::string>::const_iterator j = args.begin();
  540. ++j;
  541. ++j;
  542. std::vector<const char*> arguments;
  543. this->GenerateTestCommand(arguments);
  544. arguments.push_back(actualCommand.c_str());
  545. for(;j != args.end(); ++j)
  546. {
  547. testCommand += " ";
  548. testCommand += cmSystemTools::EscapeSpaces(j->c_str());
  549. arguments.push_back(j->c_str());
  550. }
  551. arguments.push_back(0);
  552. /**
  553. * Run an executable command and put the stdout in output.
  554. */
  555. std::string output;
  556. int retVal = 0;
  557. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, std::endl << (m_MemCheck?"MemCheck":"Test") << " command: " << testCommand << std::endl);
  558. if ( olog )
  559. {
  560. *olog << cnt << "/" << tmsize
  561. << " Test: " << testname.c_str() << std::endl;
  562. *olog << "Command: ";
  563. std::vector<cmStdString>::size_type ll;
  564. for ( ll = 0; ll < arguments.size()-1; ll ++ )
  565. {
  566. *olog << "\"" << arguments[ll] << "\" ";
  567. }
  568. *olog
  569. << std::endl
  570. << "Directory: " << it->m_Directory << std::endl
  571. << "\"" << testname.c_str() << "\" start time: "
  572. << m_CTest->CurrentTime() << std::endl
  573. << "Output:" << std::endl
  574. << "----------------------------------------------------------"
  575. << std::endl;
  576. }
  577. int res = 0;
  578. double clock_start, clock_finish;
  579. clock_start = cmSystemTools::GetTime();
  580. if ( !m_CTest->GetShowOnly() )
  581. {
  582. res = m_CTest->RunTest(arguments, &output, &retVal, olog);
  583. }
  584. clock_finish = cmSystemTools::GetTime();
  585. if ( olog )
  586. {
  587. double ttime = clock_finish - clock_start;
  588. int hours = static_cast<int>(ttime / (60 * 60));
  589. int minutes = static_cast<int>(ttime / 60) % 60;
  590. int seconds = static_cast<int>(ttime) % 60;
  591. char buffer[100];
  592. sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
  593. *olog
  594. << "----------------------------------------------------------"
  595. << std::endl
  596. << "\"" << testname.c_str() << "\" end time: "
  597. << m_CTest->CurrentTime() << std::endl
  598. << "\"" << testname.c_str() << "\" time elapsed: "
  599. << buffer << std::endl
  600. << "----------------------------------------------------------"
  601. << std::endl << std::endl;
  602. }
  603. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  604. cres.m_FullCommandLine = testCommand;
  605. if ( !m_CTest->GetShowOnly() )
  606. {
  607. if (res == cmsysProcess_State_Exited && retVal == 0)
  608. {
  609. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Passed" << std::endl);
  610. passed.push_back(testname);
  611. cres.m_Status = cmCTestTestHandler::COMPLETED;
  612. }
  613. else
  614. {
  615. cres.m_Status = cmCTestTestHandler::FAILED;
  616. if ( res == cmsysProcess_State_Expired )
  617. {
  618. cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Timeout" << std::endl);
  619. cres.m_Status = cmCTestTestHandler::TIMEOUT;
  620. }
  621. else if ( res == cmsysProcess_State_Exception )
  622. {
  623. cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Exception: ");
  624. switch ( retVal )
  625. {
  626. case cmsysProcess_Exception_Fault:
  627. cmCTestLog(m_CTest, HANDLER_OUTPUT, "SegFault");
  628. cres.m_Status = cmCTestTestHandler::SEGFAULT;
  629. break;
  630. case cmsysProcess_Exception_Illegal:
  631. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Illegal");
  632. cres.m_Status = cmCTestTestHandler::ILLEGAL;
  633. break;
  634. case cmsysProcess_Exception_Interrupt:
  635. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Interrupt");
  636. cres.m_Status = cmCTestTestHandler::INTERRUPT;
  637. break;
  638. case cmsysProcess_Exception_Numerical:
  639. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Numerical");
  640. cres.m_Status = cmCTestTestHandler::NUMERICAL;
  641. break;
  642. default:
  643. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Other");
  644. cres.m_Status = cmCTestTestHandler::OTHER_FAULT;
  645. }
  646. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl);
  647. }
  648. else if ( res == cmsysProcess_State_Error )
  649. {
  650. cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Bad command " << res << std::endl);
  651. cres.m_Status = cmCTestTestHandler::BAD_COMMAND;
  652. }
  653. else
  654. {
  655. cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Failed" << std::endl);
  656. }
  657. failed.push_back(testname);
  658. }
  659. if (output != "")
  660. {
  661. if (dartStuff.find(output.c_str()))
  662. {
  663. std::string dartString = dartStuff.match(1);
  664. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  665. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  666. }
  667. }
  668. }
  669. if ( cres.m_Status == cmCTestTestHandler::COMPLETED )
  670. {
  671. this->CleanTestOutput(output, static_cast<size_t>(m_CustomMaximumPassedTestOutputSize));
  672. }
  673. else
  674. {
  675. this->CleanTestOutput(output, static_cast<size_t>(m_CustomMaximumFailedTestOutputSize));
  676. }
  677. cres.m_Output = output;
  678. cres.m_ReturnValue = retVal;
  679. cres.m_CompletionStatus = "Completed";
  680. m_TestResults.push_back( cres );
  681. }
  682. m_EndTest = m_CTest->CurrentTime();
  683. m_ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
  684. if ( olog )
  685. {
  686. *olog << "End testing: " << m_EndTest << std::endl;
  687. }
  688. cmSystemTools::ChangeDirectory(current_dir.c_str());
  689. }
  690. //----------------------------------------------------------------------
  691. void cmCTestTestHandler::GenerateTestCommand(std::vector<const char*>&)
  692. {
  693. }
  694. //----------------------------------------------------------------------
  695. void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
  696. {
  697. if ( !m_CTest->GetProduceXML() )
  698. {
  699. return;
  700. }
  701. m_CTest->StartXML(os);
  702. os << "<Testing>\n"
  703. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  704. << "\t<TestList>\n";
  705. tm_TestResultsVector::size_type cc;
  706. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  707. {
  708. cmCTestTestResult *result = &m_TestResults[cc];
  709. std::string testPath = result->m_Path + "/" + result->m_Name;
  710. os << "\t\t<Test>" << cmCTest::MakeXMLSafe(
  711. m_CTest->GetShortPathToFile(testPath.c_str()))
  712. << "</Test>" << std::endl;
  713. }
  714. os << "\t</TestList>\n";
  715. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  716. {
  717. cmCTestTestResult *result = &m_TestResults[cc];
  718. os << "\t<Test Status=\"";
  719. if ( result->m_Status == cmCTestTestHandler::COMPLETED )
  720. {
  721. os << "passed";
  722. }
  723. else if ( result->m_Status == cmCTestTestHandler::NOT_RUN )
  724. {
  725. os << "notrun";
  726. }
  727. else
  728. {
  729. os << "failed";
  730. }
  731. std::string testPath = result->m_Path + "/" + result->m_Name;
  732. os << "\">\n"
  733. << "\t\t<Name>" << cmCTest::MakeXMLSafe(result->m_Name) << "</Name>\n"
  734. << "\t\t<Path>" << cmCTest::MakeXMLSafe(
  735. m_CTest->GetShortPathToFile(result->m_Path.c_str())) << "</Path>\n"
  736. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(
  737. m_CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
  738. << "\t\t<FullCommandLine>"
  739. << cmCTest::MakeXMLSafe(result->m_FullCommandLine)
  740. << "</FullCommandLine>\n"
  741. << "\t\t<Results>" << std::endl;
  742. if ( result->m_Status != cmCTestTestHandler::NOT_RUN )
  743. {
  744. if ( result->m_Status != cmCTestTestHandler::COMPLETED || result->m_ReturnValue )
  745. {
  746. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  747. << this->GetTestStatus(result->m_Status) << "</Value></NamedMeasurement>\n"
  748. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  749. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  750. }
  751. os << result->m_RegressionImages;
  752. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  753. << "name=\"Execution Time\"><Value>"
  754. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n";
  755. os
  756. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  757. << "name=\"Completion Status\"><Value>"
  758. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n";
  759. }
  760. os
  761. << "\t\t\t<Measurement>\n"
  762. << "\t\t\t\t<Value>";
  763. os << cmCTest::MakeXMLSafe(result->m_Output);
  764. os
  765. << "</Value>\n"
  766. << "\t\t\t</Measurement>\n"
  767. << "\t\t</Results>\n"
  768. << "\t</Test>" << std::endl;
  769. }
  770. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  771. << "<ElapsedMinutes>"
  772. << static_cast<int>(m_ElapsedTestingTime/6)/10.0
  773. << "</ElapsedMinutes>"
  774. << "</Testing>" << std::endl;
  775. m_CTest->EndXML(os);
  776. }
  777. //----------------------------------------------------------------------
  778. int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
  779. {
  780. std::vector<cmStdString>::iterator it;
  781. for ( it = vec.begin(); it != vec.end(); ++it )
  782. {
  783. int retVal = 0;
  784. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it << std::endl);
  785. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true /*m_Verbose*/) ||
  786. retVal != 0 )
  787. {
  788. cmCTestLog(m_CTest, ERROR_MESSAGE, "Problem running command: " << *it << std::endl);
  789. return 0;
  790. }
  791. }
  792. return 1;
  793. }
  794. //----------------------------------------------------------------------
  795. std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
  796. {
  797. std::string fullPath = "";
  798. std::string dir;
  799. std::string file;
  800. cmSystemTools::SplitProgramPath(exe, dir, file);
  801. if(m_CTest->GetConfigType() != "" &&
  802. ::TryExecutable(dir.c_str(), file.c_str(), &fullPath,
  803. m_CTest->GetConfigType().c_str()))
  804. {
  805. return fullPath;
  806. }
  807. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
  808. {
  809. return fullPath;
  810. }
  811. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
  812. {
  813. return fullPath;
  814. }
  815. if ( m_CTest->GetConfigType() == "" )
  816. {
  817. // No config type, so try to guess it
  818. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
  819. {
  820. return fullPath;
  821. }
  822. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
  823. {
  824. return fullPath;
  825. }
  826. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
  827. {
  828. return fullPath;
  829. }
  830. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
  831. {
  832. return fullPath;
  833. }
  834. }
  835. // if everything else failed, check the users path
  836. if (dir != "")
  837. {
  838. std::string path = cmSystemTools::FindProgram(file.c_str());
  839. if (path != "")
  840. {
  841. return path;
  842. }
  843. }
  844. if ( m_CTest->GetConfigType() != "" )
  845. {
  846. dir += "/";
  847. dir += m_CTest->GetConfigType();
  848. dir += "/";
  849. dir += file;
  850. cmSystemTools::Error("config type specified on the command line, but test executable not found.",
  851. dir.c_str());
  852. return "";
  853. }
  854. return fullPath;
  855. }
  856. //----------------------------------------------------------------------
  857. void cmCTestTestHandler::GetListOfTests()
  858. {
  859. if ( !m_IncludeRegExp.empty() )
  860. {
  861. m_IncludeTestsRegularExpression.compile(m_IncludeRegExp.c_str());
  862. }
  863. if ( !m_ExcludeRegExp.empty() )
  864. {
  865. m_ExcludeTestsRegularExpression.compile(m_ExcludeRegExp.c_str());
  866. }
  867. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Constructing a list of tests" << std::endl);
  868. cmake cm;
  869. cmGlobalGenerator gg;
  870. gg.SetCMakeInstance(&cm);
  871. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  872. lg->SetGlobalGenerator(&gg);
  873. cmMakefile *mf = lg->GetMakefile();
  874. mf->AddDefinition("CTEST_CONFIGURATION_TYPE", m_CTest->GetConfigType().c_str());
  875. // Add handler for ADD_TEST
  876. cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
  877. newCom1->m_TestHandler = this;
  878. cm.AddCommand(newCom1);
  879. // Add handler for SUBDIR
  880. cmCTestSubdirCommand* newCom2 = new cmCTestSubdirCommand;
  881. newCom2->m_TestHandler = this;
  882. cm.AddCommand(newCom2);
  883. const char* testFilename;
  884. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  885. {
  886. // does the CTestTestfile.cmake exist ?
  887. testFilename = "CTestTestfile.cmake";
  888. }
  889. else if( cmSystemTools::FileExists("DartTestfile.txt") )
  890. {
  891. // does the DartTestfile.txt exist ?
  892. testFilename = "DartTestfile.txt";
  893. }
  894. else
  895. {
  896. return;
  897. }
  898. if ( !mf->ReadListFile(0, testFilename) )
  899. {
  900. return;
  901. }
  902. if ( cmSystemTools::GetErrorOccuredFlag() )
  903. {
  904. return;
  905. }
  906. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Done constructing a list of tests" << std::endl);
  907. }
  908. //----------------------------------------------------------------------
  909. void cmCTestTestHandler::UseIncludeRegExp()
  910. {
  911. this->m_UseIncludeRegExp = true;
  912. }
  913. //----------------------------------------------------------------------
  914. void cmCTestTestHandler::UseExcludeRegExp()
  915. {
  916. this->m_UseExcludeRegExp = true;
  917. this->m_UseExcludeRegExpFirst = this->m_UseIncludeRegExp ? false : true;
  918. }
  919. //----------------------------------------------------------------------
  920. const char* cmCTestTestHandler::GetTestStatus(int status)
  921. {
  922. static const char statuses[][100] = {
  923. "Not Run",
  924. "Timeout",
  925. "SEGFAULT",
  926. "ILLEGAL",
  927. "INTERRUPT",
  928. "NUMERICAL",
  929. "OTHER_FAULT",
  930. "Failed",
  931. "BAD_COMMAND",
  932. "Completed"
  933. };
  934. if ( status < cmCTestTestHandler::NOT_RUN ||
  935. status > cmCTestTestHandler::COMPLETED )
  936. {
  937. return "No Status";
  938. }
  939. return statuses[status];
  940. }
  941. //----------------------------------------------------------------------
  942. void cmCTestTestHandler::ExpandTestsToRunInformation(int numTests)
  943. {
  944. if (this->TestsToRunString.empty())
  945. {
  946. return;
  947. }
  948. int start;
  949. int end = -1;
  950. double stride = -1;
  951. std::string::size_type pos = 0;
  952. std::string::size_type pos2;
  953. // read start
  954. if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
  955. {
  956. // read end
  957. if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
  958. {
  959. // read stride
  960. if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
  961. {
  962. int val =0;
  963. // now read specific numbers
  964. while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
  965. {
  966. m_TestsToRun.push_back(val);
  967. }
  968. m_TestsToRun.push_back(val);
  969. }
  970. }
  971. }
  972. // if start is not specified then we assume we start at 1
  973. if(start == -1)
  974. {
  975. start = 1;
  976. }
  977. // if end isnot specified then we assume we end with the last test
  978. if(end == -1)
  979. {
  980. end = numTests;
  981. }
  982. // if the stride wasn't specified then it defaults to 1
  983. if(stride == -1)
  984. {
  985. stride = 1;
  986. }
  987. // if we have a range then add it
  988. if(end != -1 && start != -1 && stride > 0)
  989. {
  990. int i = 0;
  991. while (i*stride + start <= end)
  992. {
  993. m_TestsToRun.push_back(static_cast<int>(i*stride+start));
  994. ++i;
  995. }
  996. }
  997. // sort the array
  998. std::sort(m_TestsToRun.begin(), m_TestsToRun.end(), std::less<int>());
  999. // remove duplicates
  1000. std::vector<int>::iterator new_end =
  1001. std::unique(m_TestsToRun.begin(), m_TestsToRun.end());
  1002. m_TestsToRun.erase(new_end, m_TestsToRun.end());
  1003. }
  1004. //----------------------------------------------------------------------
  1005. // Just for convenience
  1006. #define SPACE_REGEX "[ \t\r\n]"
  1007. //----------------------------------------------------------------------
  1008. std::string cmCTestTestHandler::GenerateRegressionImages(
  1009. const std::string& xml)
  1010. {
  1011. cmsys::RegularExpression twoattributes(
  1012. "<DartMeasurement"
  1013. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1014. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1015. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1016. cmsys::RegularExpression threeattributes(
  1017. "<DartMeasurement"
  1018. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1019. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1020. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1021. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1022. cmsys::RegularExpression fourattributes(
  1023. "<DartMeasurement"
  1024. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1025. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1026. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1027. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1028. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1029. cmsys::RegularExpression measurementfile(
  1030. "<DartMeasurementFile"
  1031. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1032. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1033. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  1034. cmOStringStream ostr;
  1035. bool done = false;
  1036. std::string cxml = xml;
  1037. while ( ! done )
  1038. {
  1039. if ( twoattributes.find(cxml) )
  1040. {
  1041. ostr
  1042. << "\t\t\t<NamedMeasurement"
  1043. << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
  1044. << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
  1045. << "><Value>" << twoattributes.match(5)
  1046. << "</Value></NamedMeasurement>"
  1047. << std::endl;
  1048. cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
  1049. }
  1050. else if ( threeattributes.find(cxml) )
  1051. {
  1052. ostr
  1053. << "\t\t\t<NamedMeasurement"
  1054. << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
  1055. << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
  1056. << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
  1057. << "><Value>" << threeattributes.match(7)
  1058. << "</Value></NamedMeasurement>"
  1059. << std::endl;
  1060. cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
  1061. }
  1062. else if ( fourattributes.find(cxml) )
  1063. {
  1064. ostr
  1065. << "\t\t\t<NamedMeasurement"
  1066. << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
  1067. << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
  1068. << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
  1069. << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
  1070. << "><Value>" << fourattributes.match(9)
  1071. << "</Value></NamedMeasurement>"
  1072. << std::endl;
  1073. cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
  1074. }
  1075. else if ( measurementfile.find(cxml) )
  1076. {
  1077. const std::string& filename =
  1078. cmCTest::CleanString(measurementfile.match(5));
  1079. if ( cmSystemTools::FileExists(filename.c_str()) )
  1080. {
  1081. long len = cmSystemTools::FileLength(filename.c_str());
  1082. if ( len == 0 )
  1083. {
  1084. std::string k1 = measurementfile.match(1);
  1085. std::string v1 = measurementfile.match(2);
  1086. std::string k2 = measurementfile.match(3);
  1087. std::string v2 = measurementfile.match(4);
  1088. if ( cmSystemTools::LowerCase(k1) == "type" )
  1089. {
  1090. v1 = "text/string";
  1091. }
  1092. if ( cmSystemTools::LowerCase(k2) == "type" )
  1093. {
  1094. v2 = "text/string";
  1095. }
  1096. ostr
  1097. << "\t\t\t<NamedMeasurement"
  1098. << " " << k1 << "=\"" << v1 << "\""
  1099. << " " << k2 << "=\"" << v2 << "\""
  1100. << " encoding=\"none\""
  1101. << "><Value>Image " << filename.c_str()
  1102. << " is empty</Value></NamedMeasurement>";
  1103. }
  1104. else
  1105. {
  1106. std::ifstream ifs(filename.c_str(), std::ios::in
  1107. #ifdef _WIN32
  1108. | std::ios::binary
  1109. #endif
  1110. );
  1111. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  1112. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1113. unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 5) ];
  1114. unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1115. unsigned long cc;
  1116. ostr
  1117. << "\t\t\t<NamedMeasurement"
  1118. << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
  1119. << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
  1120. << " encoding=\"base64\""
  1121. << ">" << std::endl << "\t\t\t\t<Value>";
  1122. for ( cc = 0; cc < rlen; cc ++ )
  1123. {
  1124. ostr << encoded_buffer[cc];
  1125. if ( cc % 60 == 0 && cc )
  1126. {
  1127. ostr << std::endl;
  1128. }
  1129. }
  1130. ostr
  1131. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  1132. << std::endl;
  1133. delete [] file_buffer;
  1134. delete [] encoded_buffer;
  1135. }
  1136. }
  1137. else
  1138. {
  1139. int idx = 4;
  1140. if ( measurementfile.match(1) == "name" )
  1141. {
  1142. idx = 2;
  1143. }
  1144. ostr
  1145. << "\t\t\t<NamedMeasurement"
  1146. << " name=\"" << measurementfile.match(idx) << "\""
  1147. << " text=\"text/string\""
  1148. << "><Value>File " << filename.c_str() << " not found</Value></NamedMeasurement>"
  1149. << std::endl;
  1150. cmCTestLog(m_CTest, HANDLER_OUTPUT, "File \"" << filename.c_str() << "\" not found." << std::endl);
  1151. }
  1152. cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
  1153. }
  1154. else
  1155. {
  1156. done = true;
  1157. }
  1158. }
  1159. return ostr.str();
  1160. }
  1161. //----------------------------------------------------------------------
  1162. void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
  1163. {
  1164. m_IncludeRegExp = arg;
  1165. }
  1166. //----------------------------------------------------------------------
  1167. void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
  1168. {
  1169. m_ExcludeRegExp = arg;
  1170. }
  1171. //----------------------------------------------------------------------
  1172. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1173. {
  1174. if ( !in )
  1175. {
  1176. return;
  1177. }
  1178. this->TestsToRunString = in;
  1179. // if the argument is a file, then read it and use the contents as the string
  1180. if(cmSystemTools::FileExists(in))
  1181. {
  1182. std::ifstream fin(in);
  1183. unsigned long filelen = cmSystemTools::FileLength(in);
  1184. char* buff = new char[filelen+1];
  1185. fin.getline(buff, filelen);
  1186. buff[fin.gcount()] = 0;
  1187. this->TestsToRunString = buff;
  1188. }
  1189. }
  1190. //----------------------------------------------------------------------
  1191. bool cmCTestTestHandler::CleanTestOutput(std::string& output, size_t remove_threshold)
  1192. {
  1193. if ( remove_threshold == 0 )
  1194. {
  1195. return true;
  1196. }
  1197. if ( output.find("CTEST_FULL_OUTPUT") != output.npos )
  1198. {
  1199. return true;
  1200. }
  1201. cmOStringStream ostr;
  1202. std::string::size_type cc;
  1203. std::string::size_type skipsize = 0;
  1204. int inTag = 0;
  1205. int skipped = 0;
  1206. for ( cc = 0; cc < output.size(); cc ++ )
  1207. {
  1208. int ch = output[cc];
  1209. if ( ch < 0 || ch > 255 )
  1210. {
  1211. break;
  1212. }
  1213. if ( ch == '<' )
  1214. {
  1215. inTag = 1;
  1216. }
  1217. if ( !inTag )
  1218. {
  1219. int notskip = 0;
  1220. // Skip
  1221. if ( skipsize < remove_threshold )
  1222. {
  1223. ostr << static_cast<char>(ch);
  1224. notskip = 1;
  1225. }
  1226. skipsize ++;
  1227. if ( notskip && skipsize >= remove_threshold )
  1228. {
  1229. skipped = 1;
  1230. }
  1231. }
  1232. else
  1233. {
  1234. ostr << static_cast<char>(ch);
  1235. }
  1236. if ( ch == '>' )
  1237. {
  1238. inTag = 0;
  1239. }
  1240. }
  1241. if ( skipped )
  1242. {
  1243. ostr << "..." << std::endl << "The rest of the test output was removed since it exceeds the threshold of "
  1244. << remove_threshold << " characters." << std::endl;
  1245. }
  1246. output = ostr.str();
  1247. return true;
  1248. }
  1249. //----------------------------------------------------------------------
  1250. bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
  1251. {
  1252. const std::string& testname = args[0];
  1253. if (this->m_UseExcludeRegExp &&
  1254. this->m_UseExcludeRegExpFirst &&
  1255. m_ExcludeTestsRegularExpression.find(testname.c_str()))
  1256. {
  1257. return true;
  1258. }
  1259. if ( m_MemCheck )
  1260. {
  1261. std::vector<cmStdString>::iterator it;
  1262. bool found = false;
  1263. for ( it = m_CustomTestsIgnore.begin();
  1264. it != m_CustomTestsIgnore.end(); ++ it )
  1265. {
  1266. if ( *it == testname )
  1267. {
  1268. found = true;
  1269. break;
  1270. }
  1271. }
  1272. if ( found )
  1273. {
  1274. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: " << *it << std::endl);
  1275. return true;
  1276. }
  1277. }
  1278. else
  1279. {
  1280. std::vector<cmStdString>::iterator it;
  1281. bool found = false;
  1282. for ( it = m_CustomTestsIgnore.begin();
  1283. it != m_CustomTestsIgnore.end(); ++ it )
  1284. {
  1285. if ( *it == testname )
  1286. {
  1287. found = true;
  1288. break;
  1289. }
  1290. }
  1291. if ( found )
  1292. {
  1293. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: " << *it << std::endl);
  1294. return true;
  1295. }
  1296. }
  1297. cmCTestTestProperties test;
  1298. test.m_Name = testname;
  1299. test.m_Args = args;
  1300. test.m_Directory = cmSystemTools::GetCurrentWorkingDirectory();
  1301. test.m_IsInBasedOnREOptions = true;
  1302. if (this->m_UseIncludeRegExp && !m_IncludeTestsRegularExpression.find(testname.c_str()))
  1303. {
  1304. test.m_IsInBasedOnREOptions = false;
  1305. }
  1306. else if (this->m_UseExcludeRegExp &&
  1307. !this->m_UseExcludeRegExpFirst &&
  1308. m_ExcludeTestsRegularExpression.find(testname.c_str()))
  1309. {
  1310. test.m_IsInBasedOnREOptions = false;
  1311. }
  1312. m_TestList.push_back(test);
  1313. return true;
  1314. }