1
0

cmCTestMultiProcessHandler.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestMultiProcessHandler.h"
  11. #include "cmProcess.h"
  12. #include "cmStandardIncludes.h"
  13. #include "cmCTest.h"
  14. #include "cmSystemTools.h"
  15. #include <stdlib.h>
  16. #include <stack>
  17. #include <float.h>
  18. class TestComparator
  19. {
  20. public:
  21. TestComparator(cmCTestMultiProcessHandler* handler) : Handler(handler) {}
  22. ~TestComparator() {}
  23. // Sorts tests in descending order of cost
  24. bool operator() (int index1, int index2) const
  25. {
  26. return Handler->Properties[index1]->Cost >
  27. Handler->Properties[index2]->Cost;
  28. }
  29. private:
  30. cmCTestMultiProcessHandler* Handler;
  31. };
  32. cmCTestMultiProcessHandler::cmCTestMultiProcessHandler()
  33. {
  34. this->ParallelLevel = 1;
  35. this->Completed = 0;
  36. this->RunningCount = 0;
  37. this->StopTimePassed = false;
  38. this->HasCycles = false;
  39. }
  40. cmCTestMultiProcessHandler::~cmCTestMultiProcessHandler()
  41. {
  42. }
  43. // Set the tests
  44. void
  45. cmCTestMultiProcessHandler::SetTests(TestMap& tests,
  46. PropertiesMap& properties)
  47. {
  48. this->Tests = tests;
  49. this->Properties = properties;
  50. this->Total = this->Tests.size();
  51. // set test run map to false for all
  52. for(TestMap::iterator i = this->Tests.begin();
  53. i != this->Tests.end(); ++i)
  54. {
  55. this->TestRunningMap[i->first] = false;
  56. this->TestFinishMap[i->first] = false;
  57. }
  58. if(!this->CTest->GetShowOnly())
  59. {
  60. this->ReadCostData();
  61. this->HasCycles = !this->CheckCycles();
  62. if(this->HasCycles)
  63. {
  64. return;
  65. }
  66. this->CreateTestCostList();
  67. }
  68. }
  69. // Set the max number of tests that can be run at the same time.
  70. void cmCTestMultiProcessHandler::SetParallelLevel(size_t level)
  71. {
  72. this->ParallelLevel = level < 1 ? 1 : level;
  73. }
  74. //---------------------------------------------------------
  75. void cmCTestMultiProcessHandler::RunTests()
  76. {
  77. this->CheckResume();
  78. if(this->HasCycles)
  79. {
  80. return;
  81. }
  82. this->TestHandler->SetMaxIndex(this->FindMaxIndex());
  83. this->StartNextTests();
  84. while(this->Tests.size() != 0)
  85. {
  86. if(this->StopTimePassed)
  87. {
  88. return;
  89. }
  90. this->CheckOutput();
  91. this->StartNextTests();
  92. }
  93. // let all running tests finish
  94. while(this->CheckOutput())
  95. {
  96. }
  97. this->MarkFinished();
  98. this->UpdateCostData();
  99. }
  100. //---------------------------------------------------------
  101. void cmCTestMultiProcessHandler::StartTestProcess(int test)
  102. {
  103. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "test " << test << "\n");
  104. this->TestRunningMap[test] = true; // mark the test as running
  105. // now remove the test itself
  106. this->EraseTest(test);
  107. this->RunningCount += GetProcessorsUsed(test);
  108. cmCTestRunTest* testRun = new cmCTestRunTest(this->TestHandler);
  109. testRun->SetIndex(test);
  110. testRun->SetTestProperties(this->Properties[test]);
  111. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  112. cmSystemTools::ChangeDirectory(this->Properties[test]->Directory.c_str());
  113. // Lock the resources we'll be using
  114. this->LockResources(test);
  115. if(testRun->StartTest(this->Total))
  116. {
  117. this->RunningTests.insert(testRun);
  118. }
  119. else if(testRun->IsStopTimePassed())
  120. {
  121. this->StopTimePassed = true;
  122. delete testRun;
  123. return;
  124. }
  125. else
  126. {
  127. this->UnlockResources(test);
  128. this->Completed++;
  129. this->TestFinishMap[test] = true;
  130. this->TestRunningMap[test] = false;
  131. this->RunningCount -= GetProcessorsUsed(test);
  132. testRun->EndTest(this->Completed, this->Total, false);
  133. this->Failed->push_back(this->Properties[test]->Name);
  134. delete testRun;
  135. }
  136. cmSystemTools::ChangeDirectory(current_dir.c_str());
  137. }
  138. //---------------------------------------------------------
  139. void cmCTestMultiProcessHandler::LockResources(int index)
  140. {
  141. for(std::set<std::string>::iterator i =
  142. this->Properties[index]->LockedResources.begin();
  143. i != this->Properties[index]->LockedResources.end(); ++i)
  144. {
  145. this->LockedResources.insert(*i);
  146. }
  147. }
  148. //---------------------------------------------------------
  149. void cmCTestMultiProcessHandler::UnlockResources(int index)
  150. {
  151. for(std::set<std::string>::iterator i =
  152. this->Properties[index]->LockedResources.begin();
  153. i != this->Properties[index]->LockedResources.end(); ++i)
  154. {
  155. this->LockedResources.erase(*i);
  156. }
  157. }
  158. //---------------------------------------------------------
  159. void cmCTestMultiProcessHandler::EraseTest(int test)
  160. {
  161. this->Tests.erase(test);
  162. this->SortedTests.erase(
  163. std::find(this->SortedTests.begin(), this->SortedTests.end(), test));
  164. }
  165. //---------------------------------------------------------
  166. inline size_t cmCTestMultiProcessHandler::GetProcessorsUsed(int test)
  167. {
  168. size_t processors =
  169. static_cast<int>(this->Properties[test]->Processors);
  170. //If this is set to run serially, it must run alone.
  171. //Also, if processors setting is set higher than the -j
  172. //setting, we default to using all of the process slots.
  173. if(this->Properties[test]->RunSerial
  174. || processors > this->ParallelLevel)
  175. {
  176. processors = this->ParallelLevel;
  177. }
  178. return processors;
  179. }
  180. //---------------------------------------------------------
  181. bool cmCTestMultiProcessHandler::StartTest(int test)
  182. {
  183. //Check for locked resources
  184. for(std::set<std::string>::iterator i =
  185. this->Properties[test]->LockedResources.begin();
  186. i != this->Properties[test]->LockedResources.end(); ++i)
  187. {
  188. if(this->LockedResources.find(*i) != this->LockedResources.end())
  189. {
  190. return false;
  191. }
  192. }
  193. // if there are no depends left then run this test
  194. if(this->Tests[test].empty())
  195. {
  196. this->StartTestProcess(test);
  197. return true;
  198. }
  199. // This test was not able to start because it is waiting
  200. // on depends to run
  201. return false;
  202. }
  203. //---------------------------------------------------------
  204. void cmCTestMultiProcessHandler::StartNextTests()
  205. {
  206. size_t numToStart = 0;
  207. if(this->RunningCount < this->ParallelLevel)
  208. {
  209. numToStart = this->ParallelLevel - this->RunningCount;
  210. }
  211. if(numToStart == 0)
  212. {
  213. return;
  214. }
  215. TestList copy = this->SortedTests;
  216. for(TestList::iterator test = copy.begin(); test != copy.end(); ++test)
  217. {
  218. size_t processors = GetProcessorsUsed(*test);
  219. if(processors <= numToStart && this->StartTest(*test))
  220. {
  221. if(this->StopTimePassed)
  222. {
  223. return;
  224. }
  225. numToStart -= processors;
  226. }
  227. else if(numToStart == 0)
  228. {
  229. return;
  230. }
  231. }
  232. }
  233. //---------------------------------------------------------
  234. bool cmCTestMultiProcessHandler::CheckOutput()
  235. {
  236. // no more output we are done
  237. if(this->RunningTests.size() == 0)
  238. {
  239. return false;
  240. }
  241. std::vector<cmCTestRunTest*> finished;
  242. std::string out, err;
  243. for(std::set<cmCTestRunTest*>::const_iterator i = this->RunningTests.begin();
  244. i != this->RunningTests.end(); ++i)
  245. {
  246. cmCTestRunTest* p = *i;
  247. if(!p->CheckOutput())
  248. {
  249. finished.push_back(p);
  250. }
  251. }
  252. for( std::vector<cmCTestRunTest*>::iterator i = finished.begin();
  253. i != finished.end(); ++i)
  254. {
  255. this->Completed++;
  256. cmCTestRunTest* p = *i;
  257. int test = p->GetIndex();
  258. if(p->EndTest(this->Completed, this->Total, true))
  259. {
  260. this->Passed->push_back(p->GetTestProperties()->Name);
  261. }
  262. else
  263. {
  264. this->Failed->push_back(p->GetTestProperties()->Name);
  265. }
  266. for(TestMap::iterator j = this->Tests.begin();
  267. j != this->Tests.end(); ++j)
  268. {
  269. j->second.erase(test);
  270. }
  271. this->TestFinishMap[test] = true;
  272. this->TestRunningMap[test] = false;
  273. this->RunningTests.erase(p);
  274. this->WriteCheckpoint(test);
  275. this->UnlockResources(test);
  276. this->RunningCount -= GetProcessorsUsed(test);
  277. delete p;
  278. }
  279. return true;
  280. }
  281. //---------------------------------------------------------
  282. void cmCTestMultiProcessHandler::UpdateCostData()
  283. {
  284. std::string fname = this->CTest->GetCostDataFile();
  285. std::string tmpout = fname + ".tmp";
  286. std::fstream fout;
  287. fout.open(tmpout.c_str(), std::ios::out);
  288. PropertiesMap temp = this->Properties;
  289. if(cmSystemTools::FileExists(fname.c_str()))
  290. {
  291. std::ifstream fin;
  292. fin.open(fname.c_str());
  293. std::string line;
  294. while(std::getline(fin, line))
  295. {
  296. if(line == "---") break;
  297. std::vector<cmsys::String> parts =
  298. cmSystemTools::SplitString(line.c_str(), ' ');
  299. //Format: <name> <previous_runs> <avg_cost>
  300. if(parts.size() < 3) break;
  301. std::string name = parts[0];
  302. int prev = atoi(parts[1].c_str());
  303. float cost = static_cast<float>(atof(parts[2].c_str()));
  304. int index = this->SearchByName(name);
  305. if(index == -1)
  306. {
  307. // This test is not in memory. We just rewrite the entry
  308. fout << name << " " << prev << " " << cost << "\n";
  309. }
  310. else
  311. {
  312. // Update with our new average cost
  313. fout << name << " " << this->Properties[index]->PreviousRuns << " "
  314. << this->Properties[index]->Cost << "\n";
  315. temp.erase(index);
  316. }
  317. }
  318. fin.close();
  319. cmSystemTools::RemoveFile(fname.c_str());
  320. }
  321. // Add all tests not previously listed in the file
  322. for(PropertiesMap::iterator i = temp.begin(); i != temp.end(); ++i)
  323. {
  324. fout << i->second->Name << " " << i->second->PreviousRuns << " "
  325. << i->second->Cost << "\n";
  326. }
  327. // Write list of failed tests
  328. fout << "---\n";
  329. for(std::vector<cmStdString>::iterator i = this->Failed->begin();
  330. i != this->Failed->end(); ++i)
  331. {
  332. fout << i->c_str() << "\n";
  333. }
  334. fout.close();
  335. cmSystemTools::RenameFile(tmpout.c_str(), fname.c_str());
  336. }
  337. //---------------------------------------------------------
  338. void cmCTestMultiProcessHandler::ReadCostData()
  339. {
  340. std::string fname = this->CTest->GetCostDataFile();
  341. if(cmSystemTools::FileExists(fname.c_str(), true))
  342. {
  343. std::ifstream fin;
  344. fin.open(fname.c_str());
  345. std::string line;
  346. while(std::getline(fin, line))
  347. {
  348. if(line == "---") break;
  349. std::vector<cmsys::String> parts =
  350. cmSystemTools::SplitString(line.c_str(), ' ');
  351. // Probably an older version of the file, will be fixed next run
  352. if(parts.size() < 3)
  353. {
  354. fin.close();
  355. return;
  356. }
  357. std::string name = parts[0];
  358. int prev = atoi(parts[1].c_str());
  359. float cost = static_cast<float>(atof(parts[2].c_str()));
  360. int index = this->SearchByName(name);
  361. if(index == -1) continue;
  362. this->Properties[index]->PreviousRuns = prev;
  363. // When not running in parallel mode, don't use cost data
  364. if(this->ParallelLevel > 1 &&
  365. this->Properties[index] &&
  366. this->Properties[index]->Cost == 0)
  367. {
  368. this->Properties[index]->Cost = cost;
  369. }
  370. }
  371. // Next part of the file is the failed tests
  372. while(std::getline(fin, line))
  373. {
  374. if(line != "")
  375. {
  376. this->LastTestsFailed.push_back(line);
  377. }
  378. }
  379. fin.close();
  380. }
  381. }
  382. //---------------------------------------------------------
  383. int cmCTestMultiProcessHandler::SearchByName(std::string name)
  384. {
  385. int index = -1;
  386. for(PropertiesMap::iterator i = this->Properties.begin();
  387. i != this->Properties.end(); ++i)
  388. {
  389. if(i->second->Name == name)
  390. {
  391. index = i->first;
  392. }
  393. }
  394. return index;
  395. }
  396. //---------------------------------------------------------
  397. void cmCTestMultiProcessHandler::CreateTestCostList()
  398. {
  399. TestSet alreadySortedTests;
  400. std::list<TestSet> priorityStack;
  401. priorityStack.push_back(TestSet());
  402. TestSet &topLevel = priorityStack.back();
  403. // In parallel test runs add previously failed tests to the front
  404. // of the cost list and queue other tests for further sorting
  405. for(TestMap::const_iterator i = this->Tests.begin();
  406. i != this->Tests.end(); ++i)
  407. {
  408. if(this->ParallelLevel > 1 &&
  409. std::find(this->LastTestsFailed.begin(), this->LastTestsFailed.end(),
  410. this->Properties[i->first]->Name) != this->LastTestsFailed.end())
  411. {
  412. //If the test failed last time, it should be run first.
  413. this->SortedTests.push_back(i->first);
  414. alreadySortedTests.insert(i->first);
  415. }
  416. else
  417. {
  418. topLevel.insert(i->first);
  419. }
  420. }
  421. // Repeatedly move dependencies of the tests on the current dependency level
  422. // to the next level until no further dependencies exist.
  423. while(priorityStack.back().size())
  424. {
  425. TestSet &previousSet = priorityStack.back();
  426. priorityStack.push_back(TestSet());
  427. TestSet &currentSet = priorityStack.back();
  428. for(TestSet::const_iterator i = previousSet.begin();
  429. i != previousSet.end(); ++i)
  430. {
  431. TestSet const& dependencies = this->Tests[*i];
  432. for(TestSet::const_iterator j = dependencies.begin();
  433. j != dependencies.end(); ++j)
  434. {
  435. currentSet.insert(*j);
  436. }
  437. }
  438. for(TestSet::const_iterator i = currentSet.begin();
  439. i != currentSet.end(); ++i)
  440. {
  441. previousSet.erase(*i);
  442. }
  443. }
  444. // Remove the empty dependency level
  445. priorityStack.pop_back();
  446. // Reverse iterate over the different dependency levels (deepest first).
  447. // Sort tests within each level by COST and append them to the cost list.
  448. for(std::list<TestSet>::reverse_iterator i = priorityStack.rbegin();
  449. i != priorityStack.rend(); ++i)
  450. {
  451. TestSet const& currentSet = *i;
  452. TestComparator comp(this);
  453. TestList sortedCopy;
  454. for(TestSet::const_iterator j = currentSet.begin();
  455. j != currentSet.end(); ++j)
  456. {
  457. sortedCopy.push_back(*j);
  458. }
  459. std::stable_sort(sortedCopy.begin(), sortedCopy.end(), comp);
  460. for(TestList::const_iterator j = sortedCopy.begin();
  461. j != sortedCopy.end(); ++j)
  462. {
  463. if(alreadySortedTests.find(*j) == alreadySortedTests.end())
  464. {
  465. this->SortedTests.push_back(*j);
  466. alreadySortedTests.insert(*j);
  467. }
  468. }
  469. }
  470. }
  471. //---------------------------------------------------------
  472. void cmCTestMultiProcessHandler::WriteCheckpoint(int index)
  473. {
  474. std::string fname = this->CTest->GetBinaryDir()
  475. + "/Testing/Temporary/CTestCheckpoint.txt";
  476. std::fstream fout;
  477. fout.open(fname.c_str(), std::ios::app | std::ios::out);
  478. fout << index << "\n";
  479. fout.close();
  480. }
  481. //---------------------------------------------------------
  482. void cmCTestMultiProcessHandler::MarkFinished()
  483. {
  484. std::string fname = this->CTest->GetBinaryDir()
  485. + "/Testing/Temporary/CTestCheckpoint.txt";
  486. cmSystemTools::RemoveFile(fname.c_str());
  487. }
  488. //---------------------------------------------------------
  489. //For ShowOnly mode
  490. void cmCTestMultiProcessHandler::PrintTestList()
  491. {
  492. this->TestHandler->SetMaxIndex(this->FindMaxIndex());
  493. int count = 0;
  494. for (PropertiesMap::iterator it = this->Properties.begin();
  495. it != this->Properties.end(); ++it)
  496. {
  497. count++;
  498. cmCTestTestHandler::cmCTestTestProperties& p = *it->second;
  499. //push working dir
  500. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  501. cmSystemTools::ChangeDirectory(p.Directory.c_str());
  502. cmCTestRunTest testRun(this->TestHandler);
  503. testRun.SetIndex(p.Index);
  504. testRun.SetTestProperties(&p);
  505. testRun.ComputeArguments(); //logs the command in verbose mode
  506. if(p.Labels.size()) //print the labels
  507. {
  508. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Labels:");
  509. }
  510. for(std::vector<std::string>::iterator label = p.Labels.begin();
  511. label != p.Labels.end(); ++label)
  512. {
  513. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " " << *label);
  514. }
  515. if(p.Labels.size()) //print the labels
  516. {
  517. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl);
  518. }
  519. if (this->TestHandler->MemCheck)
  520. {
  521. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Memory Check");
  522. }
  523. else
  524. {
  525. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Test");
  526. }
  527. cmOStringStream indexStr;
  528. indexStr << " #" << p.Index << ":";
  529. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  530. std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
  531. << indexStr.str().c_str());
  532. cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
  533. cmCTestLog(this->CTest, HANDLER_OUTPUT, p.Name.c_str() << std::endl);
  534. //pop working dir
  535. cmSystemTools::ChangeDirectory(current_dir.c_str());
  536. }
  537. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl << "Total Tests: "
  538. << this->Total << std::endl);
  539. }
  540. void cmCTestMultiProcessHandler::PrintLabels()
  541. {
  542. std::set<std::string> allLabels;
  543. for (PropertiesMap::iterator it = this->Properties.begin();
  544. it != this->Properties.end(); ++it)
  545. {
  546. cmCTestTestHandler::cmCTestTestProperties& p = *it->second;
  547. allLabels.insert(p.Labels.begin(), p.Labels.end());
  548. }
  549. if(allLabels.size())
  550. {
  551. cmCTestLog(this->CTest, HANDLER_OUTPUT, "All Labels:" << std::endl);
  552. }
  553. else
  554. {
  555. cmCTestLog(this->CTest, HANDLER_OUTPUT, "No Labels Exist" << std::endl);
  556. }
  557. for(std::set<std::string>::iterator label = allLabels.begin();
  558. label != allLabels.end(); ++label)
  559. {
  560. cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << *label << std::endl);
  561. }
  562. }
  563. //---------------------------------------------------------
  564. void cmCTestMultiProcessHandler::CheckResume()
  565. {
  566. std::string fname = this->CTest->GetBinaryDir()
  567. + "/Testing/Temporary/CTestCheckpoint.txt";
  568. if(this->CTest->GetFailover())
  569. {
  570. if(cmSystemTools::FileExists(fname.c_str(), true))
  571. {
  572. *this->TestHandler->LogFile << "Resuming previously interrupted test set"
  573. << std::endl
  574. << "----------------------------------------------------------"
  575. << std::endl;
  576. std::ifstream fin;
  577. fin.open(fname.c_str());
  578. std::string line;
  579. while(std::getline(fin, line))
  580. {
  581. int index = atoi(line.c_str());
  582. this->RemoveTest(index);
  583. }
  584. fin.close();
  585. }
  586. }
  587. else if(cmSystemTools::FileExists(fname.c_str(), true))
  588. {
  589. cmSystemTools::RemoveFile(fname.c_str());
  590. }
  591. }
  592. //---------------------------------------------------------
  593. void cmCTestMultiProcessHandler::RemoveTest(int index)
  594. {
  595. this->EraseTest(index);
  596. this->Properties.erase(index);
  597. this->TestRunningMap[index] = false;
  598. this->TestFinishMap[index] = true;
  599. this->Completed++;
  600. }
  601. //---------------------------------------------------------
  602. int cmCTestMultiProcessHandler::FindMaxIndex()
  603. {
  604. int max = 0;
  605. cmCTestMultiProcessHandler::TestMap::iterator i = this->Tests.begin();
  606. for(; i != this->Tests.end(); ++i)
  607. {
  608. if(i->first > max)
  609. {
  610. max = i->first;
  611. }
  612. }
  613. return max;
  614. }
  615. //Returns true if no cycles exist in the dependency graph
  616. bool cmCTestMultiProcessHandler::CheckCycles()
  617. {
  618. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  619. "Checking test dependency graph..." << std::endl);
  620. for(TestMap::iterator it = this->Tests.begin();
  621. it != this->Tests.end(); ++it)
  622. {
  623. //DFS from each element to itself
  624. int root = it->first;
  625. std::set<int> visited;
  626. std::stack<int> s;
  627. s.push(root);
  628. while(!s.empty())
  629. {
  630. int test = s.top();
  631. s.pop();
  632. if(visited.insert(test).second)
  633. {
  634. for(TestSet::iterator d = this->Tests[test].begin();
  635. d != this->Tests[test].end(); ++d)
  636. {
  637. if(*d == root)
  638. {
  639. //cycle exists
  640. cmCTestLog(this->CTest, ERROR_MESSAGE,
  641. "Error: a cycle exists in the test dependency graph "
  642. "for the test \"" << this->Properties[root]->Name <<
  643. "\".\nPlease fix the cycle and run ctest again.\n");
  644. return false;
  645. }
  646. else
  647. {
  648. s.push(*d);
  649. }
  650. }
  651. }
  652. }
  653. }
  654. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  655. "Checking test dependency graph end" << std::endl);
  656. return true;
  657. }