cmCTestTestHandler.cxx 68 KB

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