cmCTestTestHandler.cxx 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862
  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 "cmSystemTools.h"
  25. #include <stdlib.h>
  26. #include <math.h>
  27. #include <float.h>
  28. #include <memory> // auto_ptr
  29. //----------------------------------------------------------------------
  30. class cmCTestSubdirCommand : public cmCommand
  31. {
  32. public:
  33. /**
  34. * This is a virtual constructor for the command.
  35. */
  36. virtual cmCommand* Clone()
  37. {
  38. cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
  39. c->TestHandler = this->TestHandler;
  40. return c;
  41. }
  42. /**
  43. * This is called when the command is first encountered in
  44. * the CMakeLists.txt file.
  45. */
  46. virtual bool InitialPass(std::vector<std::string> const& args);
  47. /**
  48. * The name of the command as specified in CMakeList.txt.
  49. */
  50. virtual const char* GetName() { return "SUBDIRS";}
  51. // Unused methods
  52. virtual const char* GetTerseDocumentation() { return ""; }
  53. virtual const char* GetFullDocumentation() { return ""; }
  54. cmTypeMacro(cmCTestSubdirCommand, cmCommand);
  55. cmCTestTestHandler* TestHandler;
  56. };
  57. //----------------------------------------------------------------------
  58. bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args)
  59. {
  60. if(args.size() < 1 )
  61. {
  62. this->SetError("called with incorrect number of arguments");
  63. return false;
  64. }
  65. std::vector<std::string>::const_iterator it;
  66. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  67. for ( it = args.begin(); it != args.end(); ++ it )
  68. {
  69. cmSystemTools::ChangeDirectory(cwd.c_str());
  70. std::string fname = cwd;
  71. fname += "/";
  72. fname += *it;
  73. if ( !cmSystemTools::FileExists(fname.c_str()) )
  74. {
  75. // No subdirectory? So what...
  76. continue;
  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. // No DartTestfile.txt? Who cares...
  93. cmSystemTools::ChangeDirectory(cwd.c_str());
  94. continue;
  95. }
  96. fname += "/";
  97. fname += testFilename;
  98. bool readit =
  99. this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),
  100. fname.c_str());
  101. cmSystemTools::ChangeDirectory(cwd.c_str());
  102. if(!readit)
  103. {
  104. std::string m = "Could not find include file: ";
  105. m += fname;
  106. this->SetError(m.c_str());
  107. return false;
  108. }
  109. }
  110. return true;
  111. }
  112. //----------------------------------------------------------------------
  113. class cmCTestAddTestCommand : public cmCommand
  114. {
  115. public:
  116. /**
  117. * This is a virtual constructor for the command.
  118. */
  119. virtual cmCommand* Clone()
  120. {
  121. cmCTestAddTestCommand* c = new cmCTestAddTestCommand;
  122. c->TestHandler = this->TestHandler;
  123. return c;
  124. }
  125. /**
  126. * This is called when the command is first encountered in
  127. * the CMakeLists.txt file.
  128. */
  129. virtual bool InitialPass(std::vector<std::string> const&);
  130. /**
  131. * The name of the command as specified in CMakeList.txt.
  132. */
  133. virtual const char* GetName() { return "ADD_TEST";}
  134. // Unused methods
  135. virtual const char* GetTerseDocumentation() { return ""; }
  136. virtual const char* GetFullDocumentation() { return ""; }
  137. cmTypeMacro(cmCTestAddTestCommand, cmCommand);
  138. cmCTestTestHandler* TestHandler;
  139. };
  140. //----------------------------------------------------------------------
  141. bool cmCTestAddTestCommand::InitialPass(std::vector<std::string> const& args)
  142. {
  143. if ( args.size() < 2 )
  144. {
  145. this->SetError("called with incorrect number of arguments");
  146. return false;
  147. }
  148. return this->TestHandler->AddTest(args);
  149. }
  150. //----------------------------------------------------------------------
  151. class cmCTestSetTestsPropertiesCommand : public cmCommand
  152. {
  153. public:
  154. /**
  155. * This is a virtual constructor for the command.
  156. */
  157. virtual cmCommand* Clone()
  158. {
  159. cmCTestSetTestsPropertiesCommand* c
  160. = new cmCTestSetTestsPropertiesCommand;
  161. c->TestHandler = this->TestHandler;
  162. return c;
  163. }
  164. /**
  165. * This is called when the command is first encountered in
  166. * the CMakeLists.txt file.
  167. */
  168. virtual bool InitialPass(std::vector<std::string> const&);
  169. /**
  170. * The name of the command as specified in CMakeList.txt.
  171. */
  172. virtual const char* GetName() { return "SET_TESTS_PROPERTIES";}
  173. // Unused methods
  174. virtual const char* GetTerseDocumentation() { return ""; }
  175. virtual const char* GetFullDocumentation() { return ""; }
  176. cmTypeMacro(cmCTestSetTestsPropertiesCommand, cmCommand);
  177. cmCTestTestHandler* TestHandler;
  178. };
  179. //----------------------------------------------------------------------
  180. bool cmCTestSetTestsPropertiesCommand::InitialPass(
  181. std::vector<std::string> const& args)
  182. {
  183. return this->TestHandler->SetTestsProperties(args);
  184. }
  185. //----------------------------------------------------------------------
  186. // get the next number in a string with numbers separated by ,
  187. // pos is the start of the search and pos2 is the end of the search
  188. // pos becomes pos2 after a call to GetNextNumber.
  189. // -1 is returned at the end of the list.
  190. inline int GetNextNumber(std::string const& in,
  191. int& val,
  192. std::string::size_type& pos,
  193. std::string::size_type& pos2)
  194. {
  195. pos2 = in.find(',', pos);
  196. if(pos2 != in.npos)
  197. {
  198. if(pos2-pos == 0)
  199. {
  200. val = -1;
  201. }
  202. else
  203. {
  204. val = atoi(in.substr(pos, pos2-pos).c_str());
  205. }
  206. pos = pos2+1;
  207. return 1;
  208. }
  209. else
  210. {
  211. if(in.size()-pos == 0)
  212. {
  213. val = -1;
  214. }
  215. else
  216. {
  217. val = atoi(in.substr(pos, in.size()-pos).c_str());
  218. }
  219. return 0;
  220. }
  221. }
  222. //----------------------------------------------------------------------
  223. // get the next number in a string with numbers separated by ,
  224. // pos is the start of the search and pos2 is the end of the search
  225. // pos becomes pos2 after a call to GetNextNumber.
  226. // -1 is returned at the end of the list.
  227. inline int GetNextRealNumber(std::string const& in,
  228. double& val,
  229. std::string::size_type& pos,
  230. std::string::size_type& pos2)
  231. {
  232. pos2 = in.find(',', pos);
  233. if(pos2 != in.npos)
  234. {
  235. if(pos2-pos == 0)
  236. {
  237. val = -1;
  238. }
  239. else
  240. {
  241. val = atof(in.substr(pos, pos2-pos).c_str());
  242. }
  243. pos = pos2+1;
  244. return 1;
  245. }
  246. else
  247. {
  248. if(in.size()-pos == 0)
  249. {
  250. val = -1;
  251. }
  252. else
  253. {
  254. val = atof(in.substr(pos, in.size()-pos).c_str());
  255. }
  256. return 0;
  257. }
  258. }
  259. //----------------------------------------------------------------------
  260. cmCTestTestHandler::cmCTestTestHandler()
  261. {
  262. this->UseUnion = false;
  263. this->UseIncludeRegExpFlag = false;
  264. this->UseExcludeRegExpFlag = false;
  265. this->UseExcludeRegExpFirst = false;
  266. this->CustomMaximumPassedTestOutputSize = 1 * 1024;
  267. this->CustomMaximumFailedTestOutputSize = 300 * 1024;
  268. this->MemCheck = false;
  269. this->LogFile = 0;
  270. this->DartStuff.compile("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  271. }
  272. //----------------------------------------------------------------------
  273. void cmCTestTestHandler::Initialize()
  274. {
  275. this->Superclass::Initialize();
  276. this->ElapsedTestingTime = -1;
  277. this->TestResults.clear();
  278. this->CustomTestsIgnore.clear();
  279. this->StartTest = "";
  280. this->EndTest = "";
  281. this->CustomPreTest.clear();
  282. this->CustomPostTest.clear();
  283. this->CustomMaximumPassedTestOutputSize = 1 * 1024;
  284. this->CustomMaximumFailedTestOutputSize = 300 * 1024;
  285. this->TestsToRun.clear();
  286. this->UseIncludeRegExpFlag = false;
  287. this->UseExcludeRegExpFlag = false;
  288. this->UseExcludeRegExpFirst = false;
  289. this->IncludeRegExp = "";
  290. this->ExcludeRegExp = "";
  291. TestsToRunString = "";
  292. this->UseUnion = false;
  293. this->TestList.clear();
  294. }
  295. //----------------------------------------------------------------------
  296. void cmCTestTestHandler::PopulateCustomVectors(cmMakefile *mf)
  297. {
  298. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST",
  299. this->CustomPreTest);
  300. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST",
  301. this->CustomPostTest);
  302. this->CTest->PopulateCustomVector(mf,
  303. "CTEST_CUSTOM_TESTS_IGNORE",
  304. this->CustomTestsIgnore);
  305. this->CTest->PopulateCustomInteger(mf,
  306. "CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE",
  307. this->CustomMaximumPassedTestOutputSize);
  308. this->CTest->PopulateCustomInteger(mf,
  309. "CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE",
  310. this->CustomMaximumFailedTestOutputSize);
  311. }
  312. //----------------------------------------------------------------------
  313. int cmCTestTestHandler::PreProcessHandler()
  314. {
  315. if ( !this->ExecuteCommands(this->CustomPreTest) )
  316. {
  317. cmCTestLog(this->CTest, ERROR_MESSAGE,
  318. "Problem executing pre-test command(s)." << std::endl);
  319. return 0;
  320. }
  321. return 1;
  322. }
  323. //----------------------------------------------------------------------
  324. int cmCTestTestHandler::PostProcessHandler()
  325. {
  326. if ( !this->ExecuteCommands(this->CustomPostTest) )
  327. {
  328. cmCTestLog(this->CTest, ERROR_MESSAGE,
  329. "Problem executing post-test command(s)." << std::endl);
  330. return 0;
  331. }
  332. return 1;
  333. }
  334. //----------------------------------------------------------------------
  335. //clearly it would be nice if this were broken up into a few smaller
  336. //functions and commented...
  337. int cmCTestTestHandler::ProcessHandler()
  338. {
  339. // Update internal data structure from generic one
  340. this->SetTestsToRunInformation(this->GetOption("TestsToRunInformation"));
  341. this->SetUseUnion(cmSystemTools::IsOn(this->GetOption("UseUnion")));
  342. const char* val;
  343. val = this->GetOption("IncludeRegularExpression");
  344. if ( val )
  345. {
  346. this->UseIncludeRegExp();
  347. this->SetIncludeRegExp(val);
  348. }
  349. val = this->GetOption("ExcludeRegularExpression");
  350. if ( val )
  351. {
  352. this->UseExcludeRegExp();
  353. this->SetExcludeRegExp(val);
  354. }
  355. this->TestResults.clear();
  356. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  357. (this->MemCheck ? "Memory check" : "Test")
  358. << " project " << cmSystemTools::GetCurrentWorkingDirectory()
  359. << std::endl);
  360. if ( ! this->PreProcessHandler() )
  361. {
  362. return -1;
  363. }
  364. cmGeneratedFileStream mLogFile;
  365. this->StartLogFile((this->MemCheck ? "DynamicAnalysis" : "Test"), mLogFile);
  366. this->LogFile = &mLogFile;
  367. std::vector<cmStdString> passed;
  368. std::vector<cmStdString> failed;
  369. int total;
  370. this->ProcessDirectory(passed, failed);
  371. total = int(passed.size()) + int(failed.size());
  372. if (total == 0)
  373. {
  374. if ( !this->CTest->GetShowOnly() )
  375. {
  376. cmCTestLog(this->CTest, ERROR_MESSAGE, "No tests were found!!!"
  377. << std::endl);
  378. }
  379. }
  380. else
  381. {
  382. if (this->HandlerVerbose && passed.size() &&
  383. (this->UseIncludeRegExpFlag || this->UseExcludeRegExpFlag))
  384. {
  385. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
  386. << "The following tests passed:" << std::endl);
  387. for(std::vector<cmStdString>::iterator j = passed.begin();
  388. j != passed.end(); ++j)
  389. {
  390. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "\t" << *j
  391. << std::endl);
  392. }
  393. }
  394. float percent = float(passed.size()) * 100.0f / total;
  395. if ( failed.size() > 0 && percent > 99)
  396. {
  397. percent = 99;
  398. }
  399. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
  400. << static_cast<int>(percent + .5) << "% tests passed, "
  401. << failed.size() << " tests failed out of " << total << std::endl);
  402. //fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  403. // percent, int(failed.size()), total);
  404. if (failed.size())
  405. {
  406. cmGeneratedFileStream ofs;
  407. cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl
  408. << "The following tests FAILED:" << std::endl);
  409. this->StartLogFile("TestsFailed", ofs);
  410. std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator ftit;
  411. for(ftit = this->TestResults.begin();
  412. ftit != this->TestResults.end(); ++ftit)
  413. {
  414. if ( ftit->Status != cmCTestTestHandler::COMPLETED )
  415. {
  416. ofs << ftit->TestCount << ":" << ftit->Name << std::endl;
  417. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t" << std::setw(3)
  418. << ftit->TestCount << " - " << ftit->Name.c_str() << " ("
  419. << this->GetTestStatus(ftit->Status) << ")" << std::endl);
  420. }
  421. }
  422. }
  423. }
  424. if ( this->CTest->GetProduceXML() )
  425. {
  426. cmGeneratedFileStream xmlfile;
  427. if( !this->StartResultingXML(
  428. (this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile) )
  429. {
  430. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create "
  431. << (this->MemCheck ? "memory check" : "testing")
  432. << " XML file" << std::endl);
  433. this->LogFile = 0;
  434. return 1;
  435. }
  436. this->GenerateDartOutput(xmlfile);
  437. }
  438. if ( ! this->PostProcessHandler() )
  439. {
  440. this->LogFile = 0;
  441. return -1;
  442. }
  443. if ( !failed.empty() )
  444. {
  445. this->LogFile = 0;
  446. return -1;
  447. }
  448. this->LogFile = 0;
  449. return 0;
  450. }
  451. //----------------------------------------------------------------------
  452. void cmCTestTestHandler::ProcessOneTest(cmCTestTestProperties *it,
  453. std::vector<cmStdString> &passed,
  454. std::vector<cmStdString> &failed,
  455. int cnt, int tmsize)
  456. {
  457. const std::string& testname = it->Name;
  458. std::vector<std::string>& args = it->Args;
  459. cmCTestTestResult cres;
  460. cres.Properties = &*it;
  461. cres.ExecutionTime = 0;
  462. cres.ReturnValue = -1;
  463. cres.Status = cmCTestTestHandler::NOT_RUN;
  464. cres.TestCount = cnt;
  465. cres.Name = testname;
  466. cres.Path = it->Directory.c_str();
  467. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << cnt << "/");
  468. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << tmsize << " ");
  469. if ( this->MemCheck )
  470. {
  471. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Memory Check");
  472. }
  473. else
  474. {
  475. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Testing");
  476. }
  477. cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
  478. std::string outname = testname;
  479. outname.resize(30, ' ');
  480. *this->LogFile << cnt << "/" << tmsize << " Testing: " << testname
  481. << std::endl;
  482. if ( this->CTest->GetShowOnly() )
  483. {
  484. cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str() << std::endl);
  485. }
  486. else
  487. {
  488. cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str());
  489. }
  490. cmCTestLog(this->CTest, DEBUG, "Testing " << args[0].c_str() << " ... ");
  491. // find the test executable
  492. std::string actualCommand = this->FindTheExecutable(args[1].c_str());
  493. std::string testCommand
  494. = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
  495. // continue if we did not find the executable
  496. if (testCommand == "")
  497. {
  498. *this->LogFile << "Unable to find executable: " << args[1].c_str()
  499. << std::endl;
  500. cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find executable: "
  501. << args[1].c_str() << std::endl);
  502. cres.Output = "Unable to find executable: " + args[1];
  503. if ( !this->CTest->GetShowOnly() )
  504. {
  505. cres.FullCommandLine = actualCommand;
  506. this->TestResults.push_back( cres );
  507. failed.push_back(testname);
  508. return;
  509. }
  510. }
  511. // add the arguments
  512. std::vector<std::string>::const_iterator j = args.begin();
  513. ++j;
  514. ++j;
  515. std::vector<const char*> arguments;
  516. this->GenerateTestCommand(arguments);
  517. arguments.push_back(actualCommand.c_str());
  518. for(;j != args.end(); ++j)
  519. {
  520. testCommand += " ";
  521. testCommand += cmSystemTools::EscapeSpaces(j->c_str());
  522. arguments.push_back(j->c_str());
  523. }
  524. arguments.push_back(0);
  525. /**
  526. * Run an executable command and put the stdout in output.
  527. */
  528. std::string output;
  529. int retVal = 0;
  530. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
  531. << (this->MemCheck?"MemCheck":"Test")
  532. << " command: " << testCommand
  533. << std::endl);
  534. *this->LogFile << cnt << "/" << tmsize
  535. << " Test: " << testname.c_str() << std::endl;
  536. *this->LogFile << "Command: ";
  537. std::vector<cmStdString>::size_type ll;
  538. for ( ll = 0; ll < arguments.size()-1; ll ++ )
  539. {
  540. *this->LogFile << "\"" << arguments[ll] << "\" ";
  541. }
  542. *this->LogFile
  543. << std::endl
  544. << "Directory: " << it->Directory << std::endl
  545. << "\"" << testname.c_str() << "\" start time: "
  546. << this->CTest->CurrentTime() << std::endl
  547. << "Output:" << std::endl
  548. << "----------------------------------------------------------"
  549. << std::endl;
  550. int res = 0;
  551. double clock_start, clock_finish;
  552. clock_start = cmSystemTools::GetTime();
  553. if ( !this->CTest->GetShowOnly() )
  554. {
  555. res = this->CTest->RunTest(arguments, &output, &retVal, this->LogFile,
  556. it->Timeout);
  557. }
  558. clock_finish = cmSystemTools::GetTime();
  559. if ( this->LogFile )
  560. {
  561. double ttime = clock_finish - clock_start;
  562. int hours = static_cast<int>(ttime / (60 * 60));
  563. int minutes = static_cast<int>(ttime / 60) % 60;
  564. int seconds = static_cast<int>(ttime) % 60;
  565. char buffer[100];
  566. sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
  567. *this->LogFile
  568. << "----------------------------------------------------------"
  569. << std::endl
  570. << "\"" << testname.c_str() << "\" end time: "
  571. << this->CTest->CurrentTime() << std::endl
  572. << "\"" << testname.c_str() << "\" time elapsed: "
  573. << buffer << std::endl
  574. << "----------------------------------------------------------"
  575. << std::endl << std::endl;
  576. }
  577. cres.ExecutionTime = (double)(clock_finish - clock_start);
  578. cres.FullCommandLine = testCommand;
  579. std::string reason;
  580. if ( !this->CTest->GetShowOnly() )
  581. {
  582. bool testFailed = false;
  583. std::vector<std::pair<cmsys::RegularExpression,
  584. std::string> >::iterator passIt;
  585. bool forceFail = false;
  586. if ( it->RequiredRegularExpressions.size() > 0 )
  587. {
  588. bool found = false;
  589. for ( passIt = it->RequiredRegularExpressions.begin();
  590. passIt != it->RequiredRegularExpressions.end();
  591. ++ passIt )
  592. {
  593. if ( passIt->first.find(output.c_str()) )
  594. {
  595. found = true;
  596. }
  597. }
  598. if ( !found )
  599. {
  600. reason = "Required regular expression not found.";
  601. reason += "Regex=[";
  602. for ( passIt = it->RequiredRegularExpressions.begin();
  603. passIt != it->RequiredRegularExpressions.end();
  604. ++ passIt )
  605. {
  606. reason += passIt->second;
  607. reason += "\n";
  608. }
  609. reason += "]";
  610. forceFail = true;
  611. }
  612. }
  613. if ( it->ErrorRegularExpressions.size() > 0 )
  614. {
  615. for ( passIt = it->ErrorRegularExpressions.begin();
  616. passIt != it->ErrorRegularExpressions.end();
  617. ++ passIt )
  618. {
  619. if ( passIt->first.find(output.c_str()) )
  620. {
  621. reason = "Error regular expression found in output.";
  622. reason += " Regex=[";
  623. reason += passIt->second;
  624. reason += "]";
  625. forceFail = true;
  626. }
  627. }
  628. }
  629. if (res == cmsysProcess_State_Exited &&
  630. (retVal == 0 || it->RequiredRegularExpressions.size()) &&
  631. !forceFail)
  632. {
  633. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Passed");
  634. if ( it->WillFail )
  635. {
  636. cmCTestLog(this->CTest, HANDLER_OUTPUT, " - But it should fail!");
  637. cres.Status = cmCTestTestHandler::FAILED;
  638. testFailed = true;
  639. }
  640. else
  641. {
  642. cres.Status = cmCTestTestHandler::COMPLETED;
  643. }
  644. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  645. }
  646. else
  647. {
  648. testFailed = true;
  649. cres.Status = cmCTestTestHandler::FAILED;
  650. if ( res == cmsysProcess_State_Expired )
  651. {
  652. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Timeout" << std::endl);
  653. cres.Status = cmCTestTestHandler::TIMEOUT;
  654. }
  655. else if ( res == cmsysProcess_State_Exception )
  656. {
  657. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: ");
  658. switch ( retVal )
  659. {
  660. case cmsysProcess_Exception_Fault:
  661. cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault");
  662. cres.Status = cmCTestTestHandler::SEGFAULT;
  663. break;
  664. case cmsysProcess_Exception_Illegal:
  665. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Illegal");
  666. cres.Status = cmCTestTestHandler::ILLEGAL;
  667. break;
  668. case cmsysProcess_Exception_Interrupt:
  669. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Interrupt");
  670. cres.Status = cmCTestTestHandler::INTERRUPT;
  671. break;
  672. case cmsysProcess_Exception_Numerical:
  673. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Numerical");
  674. cres.Status = cmCTestTestHandler::NUMERICAL;
  675. break;
  676. default:
  677. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Other");
  678. cres.Status = cmCTestTestHandler::OTHER_FAULT;
  679. }
  680. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  681. }
  682. else if ( res == cmsysProcess_State_Error )
  683. {
  684. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Bad command " << res
  685. << std::endl);
  686. cres.Status = cmCTestTestHandler::BAD_COMMAND;
  687. }
  688. else
  689. {
  690. // Force fail will also be here?
  691. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Failed " << reason);
  692. if ( it->WillFail )
  693. {
  694. cres.Status = cmCTestTestHandler::COMPLETED;
  695. cmCTestLog(this->CTest, HANDLER_OUTPUT, " - supposed to fail");
  696. testFailed = false;
  697. }
  698. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  699. }
  700. }
  701. if ( testFailed )
  702. {
  703. failed.push_back(testname);
  704. }
  705. else
  706. {
  707. passed.push_back(testname);
  708. }
  709. if (!output.empty() && output.find("<DartMeasurement") != output.npos)
  710. {
  711. if (this->DartStuff.find(output.c_str()))
  712. {
  713. std::string dartString = this->DartStuff.match(1);
  714. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  715. cres.RegressionImages
  716. = this->GenerateRegressionImages(dartString);
  717. }
  718. }
  719. }
  720. // if this is doing MemCheck then all the output needs to be put into
  721. // Output since that it what is parsed to by cmCTestMemCheckHandler
  722. if(!this->MemCheck)
  723. {
  724. if ( cres.Status == cmCTestTestHandler::COMPLETED )
  725. {
  726. this->CleanTestOutput(output, static_cast<size_t>
  727. (this->CustomMaximumPassedTestOutputSize));
  728. }
  729. else
  730. {
  731. this->CleanTestOutput(output, static_cast<size_t>
  732. (this->CustomMaximumFailedTestOutputSize));
  733. }
  734. }
  735. cres.Output = output;
  736. cres.ReturnValue = retVal;
  737. cres.CompletionStatus = "Completed";
  738. this->TestResults.push_back( cres );
  739. }
  740. //----------------------------------------------------------------------
  741. void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
  742. std::vector<cmStdString> &failed)
  743. {
  744. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  745. this->TestList.clear();
  746. this->GetListOfTests();
  747. cmCTestTestHandler::ListOfTests::size_type tmsize = this->TestList.size();
  748. this->StartTest = this->CTest->CurrentTime();
  749. double elapsed_time_start = cmSystemTools::GetTime();
  750. *this->LogFile << "Start testing: " << this->StartTest << std::endl
  751. << "----------------------------------------------------------"
  752. << std::endl;
  753. // how many tests are in based on RegExp?
  754. int inREcnt = 0;
  755. cmCTestTestHandler::ListOfTests::iterator it;
  756. for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
  757. {
  758. if (it->IsInBasedOnREOptions)
  759. {
  760. inREcnt ++;
  761. }
  762. }
  763. // expand the test list based on the union flag
  764. if (this->UseUnion)
  765. {
  766. this->ExpandTestsToRunInformation((int)tmsize);
  767. }
  768. else
  769. {
  770. this->ExpandTestsToRunInformation(inREcnt);
  771. }
  772. int cnt = 0;
  773. inREcnt = 0;
  774. std::string last_directory = "";
  775. for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
  776. {
  777. cnt ++;
  778. if (it->IsInBasedOnREOptions)
  779. {
  780. inREcnt++;
  781. }
  782. // if we are out of time then skip this test, we leave two minutes
  783. // to submit results
  784. if (this->CTest->GetRemainingTimeAllowed() - 120 <= 0)
  785. {
  786. continue;
  787. }
  788. if (!(last_directory == it->Directory))
  789. {
  790. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  791. "Changing directory into " << it->Directory.c_str() << "\n");
  792. *this->LogFile << "Changing directory into: " << it->Directory.c_str()
  793. << std::endl;
  794. last_directory = it->Directory;
  795. cmSystemTools::ChangeDirectory(it->Directory.c_str());
  796. }
  797. if (this->UseUnion)
  798. {
  799. // if it is not in the list and not in the regexp then skip
  800. if ((this->TestsToRun.size() &&
  801. std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt)
  802. == this->TestsToRun.end()) && !it->IsInBasedOnREOptions)
  803. {
  804. continue;
  805. }
  806. }
  807. else
  808. {
  809. // is this test in the list of tests to run? If not then skip it
  810. if ((this->TestsToRun.size() &&
  811. std::find(this->TestsToRun.begin(),
  812. this->TestsToRun.end(), inREcnt)
  813. == this->TestsToRun.end()) || !it->IsInBasedOnREOptions)
  814. {
  815. continue;
  816. }
  817. }
  818. // process this one test
  819. this->ProcessOneTest(&(*it), passed, failed, cnt,
  820. static_cast<int>(tmsize));
  821. }
  822. this->EndTest = this->CTest->CurrentTime();
  823. this->ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
  824. if ( this->LogFile )
  825. {
  826. *this->LogFile << "End testing: " << this->EndTest << std::endl;
  827. }
  828. cmSystemTools::ChangeDirectory(current_dir.c_str());
  829. }
  830. //----------------------------------------------------------------------
  831. void cmCTestTestHandler::GenerateTestCommand(std::vector<const char*>&)
  832. {
  833. }
  834. //----------------------------------------------------------------------
  835. void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
  836. {
  837. if ( !this->CTest->GetProduceXML() )
  838. {
  839. return;
  840. }
  841. this->CTest->StartXML(os);
  842. os << "<Testing>\n"
  843. << "\t<StartDateTime>" << this->StartTest << "</StartDateTime>\n"
  844. << "\t<TestList>\n";
  845. cmCTestTestHandler::TestResultsVector::size_type cc;
  846. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  847. {
  848. cmCTestTestResult *result = &this->TestResults[cc];
  849. std::string testPath = result->Path + "/" + result->Name;
  850. os << "\t\t<Test>" << cmCTest::MakeXMLSafe(
  851. this->CTest->GetShortPathToFile(testPath.c_str()))
  852. << "</Test>" << std::endl;
  853. }
  854. os << "\t</TestList>\n";
  855. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  856. {
  857. cmCTestTestResult *result = &this->TestResults[cc];
  858. os << "\t<Test Status=\"";
  859. if ( result->Status == cmCTestTestHandler::COMPLETED )
  860. {
  861. os << "passed";
  862. }
  863. else if ( result->Status == cmCTestTestHandler::NOT_RUN )
  864. {
  865. os << "notrun";
  866. }
  867. else
  868. {
  869. os << "failed";
  870. }
  871. std::string testPath = result->Path + "/" + result->Name;
  872. os << "\">\n"
  873. << "\t\t<Name>" << cmCTest::MakeXMLSafe(result->Name) << "</Name>\n"
  874. << "\t\t<Path>" << cmCTest::MakeXMLSafe(
  875. this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
  876. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(
  877. this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
  878. << "\t\t<FullCommandLine>"
  879. << cmCTest::MakeXMLSafe(result->FullCommandLine)
  880. << "</FullCommandLine>\n"
  881. << "\t\t<Results>" << std::endl;
  882. if ( result->Status != cmCTestTestHandler::NOT_RUN )
  883. {
  884. if ( result->Status != cmCTestTestHandler::COMPLETED ||
  885. result->ReturnValue )
  886. {
  887. os << "\t\t\t<NamedMeasurement type=\"text/string\" "
  888. "name=\"Exit Code\"><Value>"
  889. << this->GetTestStatus(result->Status) << "</Value>"
  890. "</NamedMeasurement>\n"
  891. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  892. "name=\"Exit Value\"><Value>"
  893. << result->ReturnValue << "</Value></NamedMeasurement>"
  894. << std::endl;
  895. }
  896. os << result->RegressionImages;
  897. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  898. << "name=\"Execution Time\"><Value>"
  899. << result->ExecutionTime << "</Value></NamedMeasurement>\n";
  900. os
  901. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  902. << "name=\"Completion Status\"><Value>"
  903. << result->CompletionStatus << "</Value></NamedMeasurement>\n";
  904. }
  905. os
  906. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  907. << "name=\"Command Line\"><Value>"
  908. << result->FullCommandLine << "</Value></NamedMeasurement>\n";
  909. std::map<cmStdString,cmStdString>::iterator measureIt;
  910. for ( measureIt = result->Properties->Measurements.begin();
  911. measureIt != result->Properties->Measurements.end();
  912. ++ measureIt )
  913. {
  914. os
  915. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  916. << "name=\"" << measureIt->first.c_str() << "\"><Value>"
  917. << measureIt->second.c_str() << "</Value></NamedMeasurement>\n";
  918. }
  919. os
  920. << "\t\t\t<Measurement>\n"
  921. << "\t\t\t\t<Value>";
  922. os << cmCTest::MakeXMLSafe(result->Output);
  923. os
  924. << "</Value>\n"
  925. << "\t\t\t</Measurement>\n"
  926. << "\t\t</Results>\n"
  927. << "\t</Test>" << std::endl;
  928. }
  929. os << "\t<EndDateTime>" << this->EndTest << "</EndDateTime>\n"
  930. << "<ElapsedMinutes>"
  931. << static_cast<int>(this->ElapsedTestingTime/6)/10.0
  932. << "</ElapsedMinutes>"
  933. << "</Testing>" << std::endl;
  934. this->CTest->EndXML(os);
  935. }
  936. //----------------------------------------------------------------------
  937. int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
  938. {
  939. std::vector<cmStdString>::iterator it;
  940. for ( it = vec.begin(); it != vec.end(); ++it )
  941. {
  942. int retVal = 0;
  943. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it
  944. << std::endl);
  945. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true
  946. /*this->Verbose*/) || retVal != 0 )
  947. {
  948. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem running command: "
  949. << *it << std::endl);
  950. return 0;
  951. }
  952. }
  953. return 1;
  954. }
  955. //----------------------------------------------------------------------
  956. // Find the appropriate executable to run for a test
  957. std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
  958. {
  959. std::string resConfig;
  960. std::vector<std::string> extraPaths;
  961. std::vector<std::string> failedPaths;
  962. return cmCTestTestHandler::FindExecutable(this->CTest,
  963. exe, resConfig,
  964. extraPaths,
  965. failedPaths);
  966. }
  967. // add additional configuraitons to the search path
  968. void cmCTestTestHandler
  969. ::AddConfigurations(cmCTest *ctest,
  970. std::vector<std::string> &attempted,
  971. std::vector<std::string> &attemptedConfigs,
  972. std::string filepath,
  973. std::string &filename)
  974. {
  975. std::string tempPath;
  976. if (filepath.size())
  977. {
  978. filepath += "/";
  979. }
  980. tempPath = filepath + filename;
  981. attempted.push_back(tempPath);
  982. attemptedConfigs.push_back("");
  983. if(ctest->GetConfigType().size())
  984. {
  985. tempPath = filepath;
  986. tempPath += ctest->GetConfigType();
  987. tempPath += "/";
  988. tempPath += filename;
  989. attempted.push_back(tempPath);
  990. attemptedConfigs.push_back(ctest->GetConfigType());
  991. // If the file is an OSX bundle then the configtyp
  992. // will be at the start of the path
  993. tempPath = ctest->GetConfigType();
  994. tempPath += "/";
  995. tempPath += filepath;
  996. tempPath += filename;
  997. attempted.push_back(tempPath);
  998. attemptedConfigs.push_back(ctest->GetConfigType());
  999. }
  1000. else
  1001. {
  1002. // no config specified to try some options
  1003. tempPath = filepath;
  1004. tempPath += "Release/";
  1005. tempPath += filename;
  1006. attempted.push_back(tempPath);
  1007. attemptedConfigs.push_back("Release");
  1008. tempPath = filepath;
  1009. tempPath += "Debug/";
  1010. tempPath += filename;
  1011. attempted.push_back(tempPath);
  1012. attemptedConfigs.push_back("Debug");
  1013. tempPath = filepath;
  1014. tempPath += "MinSizeRel/";
  1015. tempPath += filename;
  1016. attempted.push_back(tempPath);
  1017. attemptedConfigs.push_back("MinSizeRel");
  1018. tempPath = filepath;
  1019. tempPath += "RelWithDebInfo/";
  1020. tempPath += filename;
  1021. attempted.push_back(tempPath);
  1022. attemptedConfigs.push_back("RelWithDebInfo");
  1023. tempPath = filepath;
  1024. tempPath += "Deployment/";
  1025. tempPath += filename;
  1026. attempted.push_back(tempPath);
  1027. attemptedConfigs.push_back("Deployment");
  1028. tempPath = filepath;
  1029. tempPath += "Development/";
  1030. tempPath += filename;
  1031. attempted.push_back(tempPath);
  1032. attemptedConfigs.push_back("Deployment");
  1033. }
  1034. }
  1035. //----------------------------------------------------------------------
  1036. // Find the appropriate executable to run for a test
  1037. std::string cmCTestTestHandler
  1038. ::FindExecutable(cmCTest *ctest,
  1039. const char *testCommand,
  1040. std::string &resultingConfig,
  1041. std::vector<std::string> &extraPaths,
  1042. std::vector<std::string> &failed)
  1043. {
  1044. // now run the compiled test if we can find it
  1045. std::vector<std::string> attempted;
  1046. std::vector<std::string> attemptedConfigs;
  1047. std::string tempPath;
  1048. std::string filepath =
  1049. cmSystemTools::GetFilenamePath(testCommand);
  1050. std::string filename =
  1051. cmSystemTools::GetFilenameName(testCommand);
  1052. cmCTestTestHandler::AddConfigurations(ctest, attempted,
  1053. attemptedConfigs,
  1054. filepath,filename);
  1055. // if extraPaths are provided and we were not passed a full path, try them,
  1056. // try any extra paths
  1057. if (filepath.size() == 0)
  1058. {
  1059. for (unsigned int i = 0; i < extraPaths.size(); ++i)
  1060. {
  1061. std::string filepathExtra =
  1062. cmSystemTools::GetFilenamePath(extraPaths[i]);
  1063. std::string filenameExtra =
  1064. cmSystemTools::GetFilenameName(extraPaths[i]);
  1065. cmCTestTestHandler::AddConfigurations(ctest,attempted,
  1066. attemptedConfigs,
  1067. filepathExtra,
  1068. filenameExtra);
  1069. }
  1070. }
  1071. // store the final location in fullPath
  1072. std::string fullPath;
  1073. // now look in the paths we specified above
  1074. for(unsigned int ai=0;
  1075. ai < attempted.size() && fullPath.size() == 0; ++ai)
  1076. {
  1077. // first check without exe extension
  1078. if(cmSystemTools::FileExists(attempted[ai].c_str())
  1079. && !cmSystemTools::FileIsDirectory(attempted[ai].c_str()))
  1080. {
  1081. fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str());
  1082. resultingConfig = attemptedConfigs[ai];
  1083. }
  1084. // then try with the exe extension
  1085. else
  1086. {
  1087. failed.push_back(attempted[ai].c_str());
  1088. tempPath = attempted[ai];
  1089. tempPath += cmSystemTools::GetExecutableExtension();
  1090. if(cmSystemTools::FileExists(tempPath.c_str())
  1091. && !cmSystemTools::FileIsDirectory(tempPath.c_str()))
  1092. {
  1093. fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str());
  1094. resultingConfig = attemptedConfigs[ai];
  1095. }
  1096. else
  1097. {
  1098. failed.push_back(tempPath.c_str());
  1099. }
  1100. }
  1101. }
  1102. // if everything else failed, check the users path, but only if a full path
  1103. // wasn't specified
  1104. if (fullPath.size() == 0 && filepath.size() == 0)
  1105. {
  1106. std::string path = cmSystemTools::FindProgram(filename.c_str());
  1107. if (path != "")
  1108. {
  1109. resultingConfig = "";
  1110. return path;
  1111. }
  1112. }
  1113. if(fullPath.size() == 0)
  1114. {
  1115. cmCTestLog(ctest, HANDLER_OUTPUT,
  1116. "Could not find executable " << testCommand << "\n"
  1117. << "Looked in the following places:\n");
  1118. for(std::vector<std::string>::iterator i = failed.begin();
  1119. i != failed.end(); ++i)
  1120. {
  1121. cmCTestLog(ctest, HANDLER_OUTPUT,
  1122. i->c_str() << "\n");
  1123. }
  1124. }
  1125. return fullPath;
  1126. }
  1127. //----------------------------------------------------------------------
  1128. void cmCTestTestHandler::GetListOfTests()
  1129. {
  1130. if ( !this->IncludeRegExp.empty() )
  1131. {
  1132. this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
  1133. }
  1134. if ( !this->ExcludeRegExp.empty() )
  1135. {
  1136. this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
  1137. }
  1138. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1139. "Constructing a list of tests" << std::endl);
  1140. cmake cm;
  1141. cmGlobalGenerator gg;
  1142. gg.SetCMakeInstance(&cm);
  1143. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  1144. lg->SetGlobalGenerator(&gg);
  1145. cmMakefile *mf = lg->GetMakefile();
  1146. mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
  1147. this->CTest->GetConfigType().c_str());
  1148. // Add handler for ADD_TEST
  1149. cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
  1150. newCom1->TestHandler = this;
  1151. cm.AddCommand(newCom1);
  1152. // Add handler for SUBDIR
  1153. cmCTestSubdirCommand* newCom2 = new cmCTestSubdirCommand;
  1154. newCom2->TestHandler = this;
  1155. cm.AddCommand(newCom2);
  1156. // Add handler for SET_SOURCE_FILES_PROPERTIES
  1157. cmCTestSetTestsPropertiesCommand* newCom3
  1158. = new cmCTestSetTestsPropertiesCommand;
  1159. newCom3->TestHandler = this;
  1160. cm.AddCommand(newCom3);
  1161. const char* testFilename;
  1162. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  1163. {
  1164. // does the CTestTestfile.cmake exist ?
  1165. testFilename = "CTestTestfile.cmake";
  1166. }
  1167. else if( cmSystemTools::FileExists("DartTestfile.txt") )
  1168. {
  1169. // does the DartTestfile.txt exist ?
  1170. testFilename = "DartTestfile.txt";
  1171. }
  1172. else
  1173. {
  1174. return;
  1175. }
  1176. if ( !mf->ReadListFile(0, testFilename) )
  1177. {
  1178. return;
  1179. }
  1180. if ( cmSystemTools::GetErrorOccuredFlag() )
  1181. {
  1182. return;
  1183. }
  1184. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1185. "Done constructing a list of tests" << std::endl);
  1186. }
  1187. //----------------------------------------------------------------------
  1188. void cmCTestTestHandler::UseIncludeRegExp()
  1189. {
  1190. this->UseIncludeRegExpFlag = true;
  1191. }
  1192. //----------------------------------------------------------------------
  1193. void cmCTestTestHandler::UseExcludeRegExp()
  1194. {
  1195. this->UseExcludeRegExpFlag = true;
  1196. this->UseExcludeRegExpFirst = this->UseIncludeRegExpFlag ? false : true;
  1197. }
  1198. //----------------------------------------------------------------------
  1199. const char* cmCTestTestHandler::GetTestStatus(int status)
  1200. {
  1201. static const char statuses[][100] = {
  1202. "Not Run",
  1203. "Timeout",
  1204. "SEGFAULT",
  1205. "ILLEGAL",
  1206. "INTERRUPT",
  1207. "NUMERICAL",
  1208. "OTHER_FAULT",
  1209. "Failed",
  1210. "BAD_COMMAND",
  1211. "Completed"
  1212. };
  1213. if ( status < cmCTestTestHandler::NOT_RUN ||
  1214. status > cmCTestTestHandler::COMPLETED )
  1215. {
  1216. return "No Status";
  1217. }
  1218. return statuses[status];
  1219. }
  1220. //----------------------------------------------------------------------
  1221. void cmCTestTestHandler::ExpandTestsToRunInformation(int numTests)
  1222. {
  1223. if (this->TestsToRunString.empty())
  1224. {
  1225. return;
  1226. }
  1227. int start;
  1228. int end = -1;
  1229. double stride = -1;
  1230. std::string::size_type pos = 0;
  1231. std::string::size_type pos2;
  1232. // read start
  1233. if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
  1234. {
  1235. // read end
  1236. if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
  1237. {
  1238. // read stride
  1239. if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
  1240. {
  1241. int val =0;
  1242. // now read specific numbers
  1243. while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
  1244. {
  1245. this->TestsToRun.push_back(val);
  1246. }
  1247. this->TestsToRun.push_back(val);
  1248. }
  1249. }
  1250. }
  1251. // if start is not specified then we assume we start at 1
  1252. if(start == -1)
  1253. {
  1254. start = 1;
  1255. }
  1256. // if end isnot specified then we assume we end with the last test
  1257. if(end == -1)
  1258. {
  1259. end = numTests;
  1260. }
  1261. // if the stride wasn't specified then it defaults to 1
  1262. if(stride == -1)
  1263. {
  1264. stride = 1;
  1265. }
  1266. // if we have a range then add it
  1267. if(end != -1 && start != -1 && stride > 0)
  1268. {
  1269. int i = 0;
  1270. while (i*stride + start <= end)
  1271. {
  1272. this->TestsToRun.push_back(static_cast<int>(i*stride+start));
  1273. ++i;
  1274. }
  1275. }
  1276. // sort the array
  1277. std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
  1278. std::less<int>());
  1279. // remove duplicates
  1280. std::vector<int>::iterator new_end =
  1281. std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
  1282. this->TestsToRun.erase(new_end, this->TestsToRun.end());
  1283. }
  1284. //----------------------------------------------------------------------
  1285. // Just for convenience
  1286. #define SPACE_REGEX "[ \t\r\n]"
  1287. //----------------------------------------------------------------------
  1288. std::string cmCTestTestHandler::GenerateRegressionImages(
  1289. const std::string& xml)
  1290. {
  1291. cmsys::RegularExpression twoattributes(
  1292. "<DartMeasurement"
  1293. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1294. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1295. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1296. cmsys::RegularExpression threeattributes(
  1297. "<DartMeasurement"
  1298. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1299. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1300. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1301. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1302. cmsys::RegularExpression fourattributes(
  1303. "<DartMeasurement"
  1304. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1305. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1306. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1307. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1308. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1309. cmsys::RegularExpression measurementfile(
  1310. "<DartMeasurementFile"
  1311. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1312. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1313. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  1314. cmOStringStream ostr;
  1315. bool done = false;
  1316. std::string cxml = xml;
  1317. while ( ! done )
  1318. {
  1319. if ( twoattributes.find(cxml) )
  1320. {
  1321. ostr
  1322. << "\t\t\t<NamedMeasurement"
  1323. << " " << twoattributes.match(1) << "=\""
  1324. << twoattributes.match(2) << "\""
  1325. << " " << twoattributes.match(3) << "=\""
  1326. << twoattributes.match(4) << "\""
  1327. << "><Value>" << twoattributes.match(5)
  1328. << "</Value></NamedMeasurement>"
  1329. << std::endl;
  1330. cxml.erase(twoattributes.start(),
  1331. twoattributes.end() - twoattributes.start());
  1332. }
  1333. else if ( threeattributes.find(cxml) )
  1334. {
  1335. ostr
  1336. << "\t\t\t<NamedMeasurement"
  1337. << " " << threeattributes.match(1) << "=\""
  1338. << threeattributes.match(2) << "\""
  1339. << " " << threeattributes.match(3) << "=\""
  1340. << threeattributes.match(4) << "\""
  1341. << " " << threeattributes.match(5) << "=\""
  1342. << threeattributes.match(6) << "\""
  1343. << "><Value>" << threeattributes.match(7)
  1344. << "</Value></NamedMeasurement>"
  1345. << std::endl;
  1346. cxml.erase(threeattributes.start(),
  1347. threeattributes.end() - threeattributes.start());
  1348. }
  1349. else if ( fourattributes.find(cxml) )
  1350. {
  1351. ostr
  1352. << "\t\t\t<NamedMeasurement"
  1353. << " " << fourattributes.match(1) << "=\""
  1354. << fourattributes.match(2) << "\""
  1355. << " " << fourattributes.match(3) << "=\""
  1356. << fourattributes.match(4) << "\""
  1357. << " " << fourattributes.match(5) << "=\""
  1358. << fourattributes.match(6) << "\""
  1359. << " " << fourattributes.match(7) << "=\""
  1360. << fourattributes.match(8) << "\""
  1361. << "><Value>" << fourattributes.match(9)
  1362. << "</Value></NamedMeasurement>"
  1363. << std::endl;
  1364. cxml.erase(fourattributes.start(),
  1365. fourattributes.end() - fourattributes.start());
  1366. }
  1367. else if ( measurementfile.find(cxml) )
  1368. {
  1369. const std::string& filename =
  1370. cmCTest::CleanString(measurementfile.match(5));
  1371. if ( cmSystemTools::FileExists(filename.c_str()) )
  1372. {
  1373. long len = cmSystemTools::FileLength(filename.c_str());
  1374. if ( len == 0 )
  1375. {
  1376. std::string k1 = measurementfile.match(1);
  1377. std::string v1 = measurementfile.match(2);
  1378. std::string k2 = measurementfile.match(3);
  1379. std::string v2 = measurementfile.match(4);
  1380. if ( cmSystemTools::LowerCase(k1) == "type" )
  1381. {
  1382. v1 = "text/string";
  1383. }
  1384. if ( cmSystemTools::LowerCase(k2) == "type" )
  1385. {
  1386. v2 = "text/string";
  1387. }
  1388. ostr
  1389. << "\t\t\t<NamedMeasurement"
  1390. << " " << k1 << "=\"" << v1 << "\""
  1391. << " " << k2 << "=\"" << v2 << "\""
  1392. << " encoding=\"none\""
  1393. << "><Value>Image " << filename.c_str()
  1394. << " is empty</Value></NamedMeasurement>";
  1395. }
  1396. else
  1397. {
  1398. std::ifstream ifs(filename.c_str(), std::ios::in
  1399. #ifdef _WIN32
  1400. | std::ios::binary
  1401. #endif
  1402. );
  1403. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  1404. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1405. unsigned char *encoded_buffer
  1406. = new unsigned char [ static_cast<int>(len * 1.5 + 5) ];
  1407. unsigned long rlen
  1408. = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1409. unsigned long cc;
  1410. ostr
  1411. << "\t\t\t<NamedMeasurement"
  1412. << " " << measurementfile.match(1) << "=\""
  1413. << measurementfile.match(2) << "\""
  1414. << " " << measurementfile.match(3) << "=\""
  1415. << measurementfile.match(4) << "\""
  1416. << " encoding=\"base64\""
  1417. << ">" << std::endl << "\t\t\t\t<Value>";
  1418. for ( cc = 0; cc < rlen; cc ++ )
  1419. {
  1420. ostr << encoded_buffer[cc];
  1421. if ( cc % 60 == 0 && cc )
  1422. {
  1423. ostr << std::endl;
  1424. }
  1425. }
  1426. ostr
  1427. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  1428. << std::endl;
  1429. delete [] file_buffer;
  1430. delete [] encoded_buffer;
  1431. }
  1432. }
  1433. else
  1434. {
  1435. int idx = 4;
  1436. if ( measurementfile.match(1) == "name" )
  1437. {
  1438. idx = 2;
  1439. }
  1440. ostr
  1441. << "\t\t\t<NamedMeasurement"
  1442. << " name=\"" << measurementfile.match(idx) << "\""
  1443. << " text=\"text/string\""
  1444. << "><Value>File " << filename.c_str()
  1445. << " not found</Value></NamedMeasurement>"
  1446. << std::endl;
  1447. cmCTestLog(this->CTest, HANDLER_OUTPUT, "File \"" << filename.c_str()
  1448. << "\" not found." << std::endl);
  1449. }
  1450. cxml.erase(measurementfile.start(),
  1451. measurementfile.end() - measurementfile.start());
  1452. }
  1453. else
  1454. {
  1455. done = true;
  1456. }
  1457. }
  1458. return ostr.str();
  1459. }
  1460. //----------------------------------------------------------------------
  1461. void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
  1462. {
  1463. this->IncludeRegExp = arg;
  1464. }
  1465. //----------------------------------------------------------------------
  1466. void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
  1467. {
  1468. this->ExcludeRegExp = arg;
  1469. }
  1470. //----------------------------------------------------------------------
  1471. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1472. {
  1473. if ( !in )
  1474. {
  1475. return;
  1476. }
  1477. this->TestsToRunString = in;
  1478. // if the argument is a file, then read it and use the contents as the
  1479. // string
  1480. if(cmSystemTools::FileExists(in))
  1481. {
  1482. std::ifstream fin(in);
  1483. unsigned long filelen = cmSystemTools::FileLength(in);
  1484. char* buff = new char[filelen+1];
  1485. fin.getline(buff, filelen);
  1486. buff[fin.gcount()] = 0;
  1487. this->TestsToRunString = buff;
  1488. }
  1489. }
  1490. //----------------------------------------------------------------------
  1491. bool cmCTestTestHandler::CleanTestOutput(std::string& output,
  1492. size_t remove_threshold)
  1493. {
  1494. if ( remove_threshold == 0 )
  1495. {
  1496. return true;
  1497. }
  1498. if ( output.find("CTEST_FULL_OUTPUT") != output.npos )
  1499. {
  1500. return true;
  1501. }
  1502. cmOStringStream ostr;
  1503. std::string::size_type cc;
  1504. std::string::size_type skipsize = 0;
  1505. int inTag = 0;
  1506. int skipped = 0;
  1507. for ( cc = 0; cc < output.size(); cc ++ )
  1508. {
  1509. int ch = output[cc];
  1510. if ( ch < 0 || ch > 255 )
  1511. {
  1512. break;
  1513. }
  1514. if ( ch == '<' )
  1515. {
  1516. inTag = 1;
  1517. }
  1518. if ( !inTag )
  1519. {
  1520. int notskip = 0;
  1521. // Skip
  1522. if ( skipsize < remove_threshold )
  1523. {
  1524. ostr << static_cast<char>(ch);
  1525. notskip = 1;
  1526. }
  1527. skipsize ++;
  1528. if ( notskip && skipsize >= remove_threshold )
  1529. {
  1530. skipped = 1;
  1531. }
  1532. }
  1533. else
  1534. {
  1535. ostr << static_cast<char>(ch);
  1536. }
  1537. if ( ch == '>' )
  1538. {
  1539. inTag = 0;
  1540. }
  1541. }
  1542. if ( skipped )
  1543. {
  1544. ostr << "..." << std::endl << "The rest of the test output was removed "
  1545. "since it exceeds the threshold of "
  1546. << remove_threshold << " characters." << std::endl;
  1547. }
  1548. output = ostr.str();
  1549. return true;
  1550. }
  1551. //----------------------------------------------------------------------
  1552. bool cmCTestTestHandler::SetTestsProperties(
  1553. const std::vector<std::string>& args)
  1554. {
  1555. std::vector<std::string>::const_iterator it;
  1556. std::vector<cmStdString> tests;
  1557. bool found = false;
  1558. for ( it = args.begin(); it != args.end(); ++ it )
  1559. {
  1560. if ( *it == "PROPERTIES" )
  1561. {
  1562. found = true;
  1563. break;
  1564. }
  1565. tests.push_back(*it);
  1566. }
  1567. if ( !found )
  1568. {
  1569. return false;
  1570. }
  1571. ++ it; // skip PROPERTIES
  1572. for ( ; it != args.end(); ++ it )
  1573. {
  1574. std::string key = *it;
  1575. ++ it;
  1576. if ( it == args.end() )
  1577. {
  1578. break;
  1579. }
  1580. std::string val = *it;
  1581. std::vector<cmStdString>::const_iterator tit;
  1582. for ( tit = tests.begin(); tit != tests.end(); ++ tit )
  1583. {
  1584. cmCTestTestHandler::ListOfTests::iterator rtit;
  1585. for ( rtit = this->TestList.begin();
  1586. rtit != this->TestList.end();
  1587. ++ rtit )
  1588. {
  1589. if ( *tit == rtit->Name )
  1590. {
  1591. if ( key == "WILL_FAIL" )
  1592. {
  1593. rtit->WillFail = cmSystemTools::IsOn(val.c_str());
  1594. }
  1595. if ( key == "TIMEOUT" )
  1596. {
  1597. rtit->Timeout = atof(val.c_str());
  1598. }
  1599. if ( key == "FAIL_REGULAR_EXPRESSION" )
  1600. {
  1601. std::vector<std::string> lval;
  1602. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1603. std::vector<std::string>::iterator crit;
  1604. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1605. {
  1606. rtit->ErrorRegularExpressions.push_back(
  1607. std::pair<cmsys::RegularExpression, std::string>(
  1608. cmsys::RegularExpression(crit->c_str()),
  1609. std::string(crit->c_str())));
  1610. }
  1611. }
  1612. if ( key == "MEASUREMENT" )
  1613. {
  1614. size_t pos = val.find_first_of("=");
  1615. if ( pos != val.npos )
  1616. {
  1617. std::string mKey = val.substr(0, pos);
  1618. const char* mVal = val.c_str() + pos + 1;
  1619. rtit->Measurements[mKey] = mVal;
  1620. }
  1621. else
  1622. {
  1623. rtit->Measurements[val] = "1";
  1624. }
  1625. }
  1626. if ( key == "PASS_REGULAR_EXPRESSION" )
  1627. {
  1628. std::vector<std::string> lval;
  1629. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1630. std::vector<std::string>::iterator crit;
  1631. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1632. {
  1633. rtit->RequiredRegularExpressions.push_back(
  1634. std::pair<cmsys::RegularExpression, std::string>(
  1635. cmsys::RegularExpression(crit->c_str()),
  1636. std::string(crit->c_str())));
  1637. }
  1638. }
  1639. }
  1640. }
  1641. }
  1642. }
  1643. return true;
  1644. }
  1645. //----------------------------------------------------------------------
  1646. bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
  1647. {
  1648. const std::string& testname = args[0];
  1649. cmCTestLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl);
  1650. if (this->UseExcludeRegExpFlag &&
  1651. this->UseExcludeRegExpFirst &&
  1652. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  1653. {
  1654. return true;
  1655. }
  1656. if ( this->MemCheck )
  1657. {
  1658. std::vector<cmStdString>::iterator it;
  1659. bool found = false;
  1660. for ( it = this->CustomTestsIgnore.begin();
  1661. it != this->CustomTestsIgnore.end(); ++ it )
  1662. {
  1663. if ( *it == testname )
  1664. {
  1665. found = true;
  1666. break;
  1667. }
  1668. }
  1669. if ( found )
  1670. {
  1671. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: "
  1672. << *it << std::endl);
  1673. return true;
  1674. }
  1675. }
  1676. else
  1677. {
  1678. std::vector<cmStdString>::iterator it;
  1679. bool found = false;
  1680. for ( it = this->CustomTestsIgnore.begin();
  1681. it != this->CustomTestsIgnore.end(); ++ it )
  1682. {
  1683. if ( *it == testname )
  1684. {
  1685. found = true;
  1686. break;
  1687. }
  1688. }
  1689. if ( found )
  1690. {
  1691. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: "
  1692. << *it << std::endl);
  1693. return true;
  1694. }
  1695. }
  1696. cmCTestTestProperties test;
  1697. test.Name = testname;
  1698. test.Args = args;
  1699. test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
  1700. cmCTestLog(this->CTest, DEBUG, "Set test directory: "
  1701. << test.Directory << std::endl);
  1702. test.IsInBasedOnREOptions = true;
  1703. test.WillFail = false;
  1704. test.Timeout = 0;
  1705. if (this->UseIncludeRegExpFlag &&
  1706. !this->IncludeTestsRegularExpression.find(testname.c_str()))
  1707. {
  1708. test.IsInBasedOnREOptions = false;
  1709. }
  1710. else if (this->UseExcludeRegExpFlag &&
  1711. !this->UseExcludeRegExpFirst &&
  1712. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  1713. {
  1714. test.IsInBasedOnREOptions = false;
  1715. }
  1716. this->TestList.push_back(test);
  1717. return true;
  1718. }