2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2008-07-03 17:31:33 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2008-07-03 17:31:33 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2008-07-03 17:31:33 +04:00
|
|
|
#include "cmCTestMultiProcessHandler.h"
|
|
|
|
#include "cmProcess.h"
|
|
|
|
#include "cmStandardIncludes.h"
|
|
|
|
#include "cmCTest.h"
|
2009-08-27 18:37:30 +04:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include <stdlib.h>
|
2009-11-02 20:52:50 +03:00
|
|
|
#include <stack>
|
2010-03-01 19:59:00 +03:00
|
|
|
#include <float.h>
|
2008-07-03 17:31:33 +04:00
|
|
|
|
2010-07-01 22:10:49 +04:00
|
|
|
class TestComparator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TestComparator(cmCTestMultiProcessHandler* handler) : Handler(handler) {}
|
|
|
|
~TestComparator() {}
|
|
|
|
|
|
|
|
// Sorts tests in descending order of cost
|
|
|
|
bool operator() (int index1, int index2) const
|
|
|
|
{
|
|
|
|
return Handler->Properties[index1]->Cost >
|
|
|
|
Handler->Properties[index2]->Cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
cmCTestMultiProcessHandler* Handler;
|
|
|
|
};
|
|
|
|
|
2008-07-03 17:31:33 +04:00
|
|
|
cmCTestMultiProcessHandler::cmCTestMultiProcessHandler()
|
|
|
|
{
|
|
|
|
this->ParallelLevel = 1;
|
2009-08-28 19:08:39 +04:00
|
|
|
this->Completed = 0;
|
2009-09-07 18:26:17 +04:00
|
|
|
this->RunningCount = 0;
|
2010-06-15 18:29:35 +04:00
|
|
|
this->StopTimePassed = false;
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
2009-09-10 19:16:08 +04:00
|
|
|
|
|
|
|
cmCTestMultiProcessHandler::~cmCTestMultiProcessHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:31:33 +04:00
|
|
|
// Set the tests
|
2012-08-13 21:42:58 +04:00
|
|
|
void
|
2008-07-04 18:28:22 +04:00
|
|
|
cmCTestMultiProcessHandler::SetTests(TestMap& tests,
|
2009-08-26 20:09:06 +04:00
|
|
|
PropertiesMap& properties)
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
2009-09-08 21:39:13 +04:00
|
|
|
this->Tests = tests;
|
|
|
|
this->Properties = properties;
|
|
|
|
this->Total = this->Tests.size();
|
2008-07-03 17:31:33 +04:00
|
|
|
// set test run map to false for all
|
2008-07-04 18:28:22 +04:00
|
|
|
for(TestMap::iterator i = this->Tests.begin();
|
2008-07-03 17:31:33 +04:00
|
|
|
i != this->Tests.end(); ++i)
|
|
|
|
{
|
|
|
|
this->TestRunningMap[i->first] = false;
|
|
|
|
this->TestFinishMap[i->first] = false;
|
|
|
|
}
|
2009-11-16 18:58:43 +03:00
|
|
|
if(!this->CTest->GetShowOnly())
|
|
|
|
{
|
|
|
|
this->ReadCostData();
|
|
|
|
this->CreateTestCostList();
|
|
|
|
}
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
2009-08-27 18:37:30 +04:00
|
|
|
|
2008-07-03 17:31:33 +04:00
|
|
|
// Set the max number of tests that can be run at the same time.
|
2009-08-26 20:09:06 +04:00
|
|
|
void cmCTestMultiProcessHandler::SetParallelLevel(size_t level)
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
2009-08-26 20:09:06 +04:00
|
|
|
this->ParallelLevel = level < 1 ? 1 : level;
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
|
|
|
|
2009-09-08 21:39:13 +04:00
|
|
|
//---------------------------------------------------------
|
2008-07-03 17:31:33 +04:00
|
|
|
void cmCTestMultiProcessHandler::RunTests()
|
|
|
|
{
|
2009-08-27 18:37:30 +04:00
|
|
|
this->CheckResume();
|
2009-11-02 20:52:50 +03:00
|
|
|
if(!this->CheckCycles())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2009-09-02 18:08:40 +04:00
|
|
|
this->TestHandler->SetMaxIndex(this->FindMaxIndex());
|
2008-07-03 17:31:33 +04:00
|
|
|
this->StartNextTests();
|
2009-09-08 21:39:13 +04:00
|
|
|
while(this->Tests.size() != 0)
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
2010-06-15 18:29:35 +04:00
|
|
|
if(this->StopTimePassed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 17:31:33 +04:00
|
|
|
this->CheckOutput();
|
|
|
|
this->StartNextTests();
|
|
|
|
}
|
|
|
|
// let all running tests finish
|
|
|
|
while(this->CheckOutput())
|
|
|
|
{
|
|
|
|
}
|
2009-08-27 18:37:30 +04:00
|
|
|
this->MarkFinished();
|
2010-02-26 00:23:49 +03:00
|
|
|
this->UpdateCostData();
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
|
|
|
|
2009-09-08 21:39:13 +04:00
|
|
|
//---------------------------------------------------------
|
2008-07-03 17:31:33 +04:00
|
|
|
void cmCTestMultiProcessHandler::StartTestProcess(int test)
|
|
|
|
{
|
2009-09-08 22:48:23 +04:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "test " << test << "\n");
|
2008-07-03 17:31:33 +04:00
|
|
|
this->TestRunningMap[test] = true; // mark the test as running
|
|
|
|
// now remove the test itself
|
2009-09-08 21:39:13 +04:00
|
|
|
this->EraseTest(test);
|
2010-06-24 01:18:59 +04:00
|
|
|
this->RunningCount += GetProcessorsUsed(test);
|
2009-09-08 21:39:13 +04:00
|
|
|
|
2009-09-11 18:09:48 +04:00
|
|
|
cmCTestRunTest* testRun = new cmCTestRunTest(this->TestHandler);
|
2009-08-26 20:09:06 +04:00
|
|
|
testRun->SetIndex(test);
|
|
|
|
testRun->SetTestProperties(this->Properties[test]);
|
2009-10-20 18:54:02 +04:00
|
|
|
|
|
|
|
std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
|
|
|
|
cmSystemTools::ChangeDirectory(this->Properties[test]->Directory.c_str());
|
|
|
|
|
2010-03-02 23:34:37 +03:00
|
|
|
// Lock the resources we'll be using
|
|
|
|
this->LockResources(test);
|
|
|
|
|
2009-10-05 18:20:52 +04:00
|
|
|
if(testRun->StartTest(this->Total))
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
2009-08-26 20:09:06 +04:00
|
|
|
this->RunningTests.insert(testRun);
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
2010-06-15 18:29:35 +04:00
|
|
|
else if(testRun->IsStopTimePassed())
|
|
|
|
{
|
|
|
|
this->StopTimePassed = true;
|
|
|
|
delete testRun;
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 17:31:33 +04:00
|
|
|
else
|
|
|
|
{
|
2010-03-02 23:34:37 +03:00
|
|
|
this->UnlockResources(test);
|
2009-09-03 23:33:44 +04:00
|
|
|
this->Completed++;
|
2009-11-05 19:03:07 +03:00
|
|
|
this->TestFinishMap[test] = true;
|
|
|
|
this->TestRunningMap[test] = false;
|
2009-09-07 18:26:17 +04:00
|
|
|
this->RunningCount -= GetProcessorsUsed(test);
|
2009-09-03 23:33:44 +04:00
|
|
|
testRun->EndTest(this->Completed, this->Total, false);
|
2009-09-23 23:37:50 +04:00
|
|
|
this->Failed->push_back(this->Properties[test]->Name);
|
2009-12-10 17:39:19 +03:00
|
|
|
delete testRun;
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
2009-10-20 18:54:02 +04:00
|
|
|
cmSystemTools::ChangeDirectory(current_dir.c_str());
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
|
|
|
|
2010-03-02 23:34:37 +03:00
|
|
|
//---------------------------------------------------------
|
|
|
|
void cmCTestMultiProcessHandler::LockResources(int index)
|
|
|
|
{
|
2010-03-03 18:32:03 +03:00
|
|
|
for(std::set<std::string>::iterator i =
|
|
|
|
this->Properties[index]->LockedResources.begin();
|
|
|
|
i != this->Properties[index]->LockedResources.end(); ++i)
|
|
|
|
{
|
|
|
|
this->LockedResources.insert(*i);
|
|
|
|
}
|
2010-03-02 23:34:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
void cmCTestMultiProcessHandler::UnlockResources(int index)
|
|
|
|
{
|
|
|
|
for(std::set<std::string>::iterator i =
|
|
|
|
this->Properties[index]->LockedResources.begin();
|
|
|
|
i != this->Properties[index]->LockedResources.end(); ++i)
|
|
|
|
{
|
|
|
|
this->LockedResources.erase(*i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-08 21:39:13 +04:00
|
|
|
//---------------------------------------------------------
|
|
|
|
void cmCTestMultiProcessHandler::EraseTest(int test)
|
|
|
|
{
|
|
|
|
this->Tests.erase(test);
|
2010-07-01 22:10:49 +04:00
|
|
|
this->SortedTests.erase(
|
|
|
|
std::find(this->SortedTests.begin(), this->SortedTests.end(), test));
|
2009-09-08 21:39:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2009-09-07 18:26:17 +04:00
|
|
|
inline size_t cmCTestMultiProcessHandler::GetProcessorsUsed(int test)
|
|
|
|
{
|
2012-08-13 21:42:58 +04:00
|
|
|
size_t processors =
|
2009-09-07 18:26:17 +04:00
|
|
|
static_cast<int>(this->Properties[test]->Processors);
|
|
|
|
//If this is set to run serially, it must run alone.
|
|
|
|
//Also, if processors setting is set higher than the -j
|
|
|
|
//setting, we default to using all of the process slots.
|
|
|
|
if(this->Properties[test]->RunSerial
|
|
|
|
|| processors > this->ParallelLevel)
|
|
|
|
{
|
|
|
|
processors = this->ParallelLevel;
|
|
|
|
}
|
|
|
|
return processors;
|
|
|
|
}
|
|
|
|
|
2009-09-08 21:39:13 +04:00
|
|
|
//---------------------------------------------------------
|
2008-07-03 17:31:33 +04:00
|
|
|
bool cmCTestMultiProcessHandler::StartTest(int test)
|
|
|
|
{
|
2010-03-02 23:34:37 +03:00
|
|
|
//Check for locked resources
|
|
|
|
for(std::set<std::string>::iterator i =
|
|
|
|
this->Properties[test]->LockedResources.begin();
|
|
|
|
i != this->Properties[test]->LockedResources.end(); ++i)
|
|
|
|
{
|
|
|
|
if(this->LockedResources.find(*i) != this->LockedResources.end())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
// copy the depend tests locally because when
|
2008-07-03 17:31:33 +04:00
|
|
|
// a test is finished it will be removed from the depend list
|
|
|
|
// and we don't want to be iterating a list while removing from it
|
2008-07-04 18:28:22 +04:00
|
|
|
TestSet depends = this->Tests[test];
|
2008-07-03 17:31:33 +04:00
|
|
|
size_t totalDepends = depends.size();
|
|
|
|
if(totalDepends)
|
|
|
|
{
|
2008-07-04 18:28:22 +04:00
|
|
|
for(TestSet::const_iterator i = depends.begin();
|
2008-07-03 17:31:33 +04:00
|
|
|
i != depends.end(); ++i)
|
|
|
|
{
|
|
|
|
// if the test is not already running then start it
|
|
|
|
if(!this->TestRunningMap[*i])
|
|
|
|
{
|
|
|
|
// this test might be finished, but since
|
|
|
|
// this is a copy of the depend map we might
|
|
|
|
// still have it
|
|
|
|
if(!this->TestFinishMap[*i])
|
|
|
|
{
|
|
|
|
// only start one test in this function
|
|
|
|
return this->StartTest(*i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// the depend has been and finished
|
|
|
|
totalDepends--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if there are no depends left then run this test
|
|
|
|
if(totalDepends == 0)
|
|
|
|
{
|
|
|
|
this->StartTestProcess(test);
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
// This test was not able to start because it is waiting
|
2008-07-03 17:31:33 +04:00
|
|
|
// on depends to run
|
2009-08-26 20:09:06 +04:00
|
|
|
return false;
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
|
|
|
|
2009-09-08 21:39:13 +04:00
|
|
|
//---------------------------------------------------------
|
2008-07-03 17:31:33 +04:00
|
|
|
void cmCTestMultiProcessHandler::StartNextTests()
|
|
|
|
{
|
2012-12-18 22:09:53 +04:00
|
|
|
size_t numToStart = 0;
|
|
|
|
if(this->RunningCount < this->ParallelLevel)
|
|
|
|
{
|
|
|
|
numToStart = this->ParallelLevel - this->RunningCount;
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:31:33 +04:00
|
|
|
if(numToStart == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2009-09-04 18:16:06 +04:00
|
|
|
|
2010-07-01 22:10:49 +04:00
|
|
|
TestList copy = this->SortedTests;
|
|
|
|
for(TestList::iterator test = copy.begin(); test != copy.end(); ++test)
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
2010-07-01 22:10:49 +04:00
|
|
|
//in case this test has already been started due to dependency
|
|
|
|
if(this->TestRunningMap[*test] || this->TestFinishMap[*test])
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
2010-07-01 22:10:49 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
size_t processors = GetProcessorsUsed(*test);
|
|
|
|
if(processors > numToStart)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(this->StartTest(*test))
|
|
|
|
{
|
|
|
|
if(this->StopTimePassed)
|
2009-09-08 21:39:13 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-07-01 22:10:49 +04:00
|
|
|
numToStart -= processors;
|
|
|
|
}
|
|
|
|
if(numToStart == 0)
|
|
|
|
{
|
|
|
|
return;
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-08 21:39:13 +04:00
|
|
|
//---------------------------------------------------------
|
2008-07-03 17:31:33 +04:00
|
|
|
bool cmCTestMultiProcessHandler::CheckOutput()
|
|
|
|
{
|
|
|
|
// no more output we are done
|
|
|
|
if(this->RunningTests.size() == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-08-26 20:09:06 +04:00
|
|
|
std::vector<cmCTestRunTest*> finished;
|
2008-07-03 17:31:33 +04:00
|
|
|
std::string out, err;
|
2009-08-26 20:09:06 +04:00
|
|
|
for(std::set<cmCTestRunTest*>::const_iterator i = this->RunningTests.begin();
|
2008-07-03 17:31:33 +04:00
|
|
|
i != this->RunningTests.end(); ++i)
|
|
|
|
{
|
2009-08-26 20:09:06 +04:00
|
|
|
cmCTestRunTest* p = *i;
|
2009-09-11 20:26:41 +04:00
|
|
|
if(!p->CheckOutput())
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
|
|
|
finished.push_back(p);
|
|
|
|
}
|
|
|
|
}
|
2009-08-26 20:09:06 +04:00
|
|
|
for( std::vector<cmCTestRunTest*>::iterator i = finished.begin();
|
|
|
|
i != finished.end(); ++i)
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
2009-08-28 19:08:39 +04:00
|
|
|
this->Completed++;
|
2009-08-26 20:09:06 +04:00
|
|
|
cmCTestRunTest* p = *i;
|
|
|
|
int test = p->GetIndex();
|
2009-08-28 19:08:39 +04:00
|
|
|
|
2009-09-03 23:33:44 +04:00
|
|
|
if(p->EndTest(this->Completed, this->Total, true))
|
2009-08-26 20:09:06 +04:00
|
|
|
{
|
2009-08-28 19:08:39 +04:00
|
|
|
this->Passed->push_back(p->GetTestProperties()->Name);
|
2009-08-26 20:09:06 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-28 19:08:39 +04:00
|
|
|
this->Failed->push_back(p->GetTestProperties()->Name);
|
2009-08-26 20:09:06 +04:00
|
|
|
}
|
|
|
|
for(TestMap::iterator j = this->Tests.begin();
|
2009-09-04 18:16:06 +04:00
|
|
|
j != this->Tests.end(); ++j)
|
|
|
|
{
|
|
|
|
j->second.erase(test);
|
|
|
|
}
|
2009-08-26 20:09:06 +04:00
|
|
|
this->TestFinishMap[test] = true;
|
|
|
|
this->TestRunningMap[test] = false;
|
|
|
|
this->RunningTests.erase(p);
|
2009-08-27 18:37:30 +04:00
|
|
|
this->WriteCheckpoint(test);
|
2010-03-02 23:34:37 +03:00
|
|
|
this->UnlockResources(test);
|
2009-09-07 18:26:17 +04:00
|
|
|
this->RunningCount -= GetProcessorsUsed(test);
|
2009-08-26 20:09:06 +04:00
|
|
|
delete p;
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
2009-08-26 20:09:06 +04:00
|
|
|
return true;
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
|
|
|
|
2009-09-09 01:10:35 +04:00
|
|
|
//---------------------------------------------------------
|
2010-02-26 00:23:49 +03:00
|
|
|
void cmCTestMultiProcessHandler::UpdateCostData()
|
2009-09-09 01:10:35 +04:00
|
|
|
{
|
2010-03-01 19:00:23 +03:00
|
|
|
std::string fname = this->CTest->GetCostDataFile();
|
2010-02-26 00:23:49 +03:00
|
|
|
std::string tmpout = fname + ".tmp";
|
|
|
|
std::fstream fout;
|
|
|
|
fout.open(tmpout.c_str(), std::ios::out);
|
|
|
|
|
|
|
|
PropertiesMap temp = this->Properties;
|
2009-09-09 01:10:35 +04:00
|
|
|
|
2010-02-26 00:23:49 +03:00
|
|
|
if(cmSystemTools::FileExists(fname.c_str()))
|
|
|
|
{
|
2009-09-09 01:10:35 +04:00
|
|
|
std::ifstream fin;
|
|
|
|
fin.open(fname.c_str());
|
2010-02-26 00:23:49 +03:00
|
|
|
|
2009-09-09 01:10:35 +04:00
|
|
|
std::string line;
|
|
|
|
while(std::getline(fin, line))
|
|
|
|
{
|
2010-03-01 19:59:00 +03:00
|
|
|
if(line == "---") break;
|
2012-08-13 21:42:58 +04:00
|
|
|
std::vector<cmsys::String> parts =
|
2009-09-09 01:10:35 +04:00
|
|
|
cmSystemTools::SplitString(line.c_str(), ' ');
|
2010-02-26 00:23:49 +03:00
|
|
|
//Format: <name> <previous_runs> <avg_cost>
|
|
|
|
if(parts.size() < 3) break;
|
|
|
|
|
|
|
|
std::string name = parts[0];
|
|
|
|
int prev = atoi(parts[1].c_str());
|
|
|
|
float cost = static_cast<float>(atof(parts[2].c_str()));
|
|
|
|
|
|
|
|
int index = this->SearchByName(name);
|
|
|
|
if(index == -1)
|
|
|
|
{
|
|
|
|
// This test is not in memory. We just rewrite the entry
|
|
|
|
fout << name << " " << prev << " " << cost << "\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Update with our new average cost
|
|
|
|
fout << name << " " << this->Properties[index]->PreviousRuns << " "
|
|
|
|
<< this->Properties[index]->Cost << "\n";
|
|
|
|
temp.erase(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fin.close();
|
|
|
|
cmSystemTools::RemoveFile(fname.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add all tests not previously listed in the file
|
|
|
|
for(PropertiesMap::iterator i = temp.begin(); i != temp.end(); ++i)
|
|
|
|
{
|
|
|
|
fout << i->second->Name << " " << i->second->PreviousRuns << " "
|
|
|
|
<< i->second->Cost << "\n";
|
|
|
|
}
|
2010-03-01 19:59:00 +03:00
|
|
|
|
|
|
|
// Write list of failed tests
|
|
|
|
fout << "---\n";
|
|
|
|
for(std::vector<cmStdString>::iterator i = this->Failed->begin();
|
|
|
|
i != this->Failed->end(); ++i)
|
|
|
|
{
|
|
|
|
fout << i->c_str() << "\n";
|
|
|
|
}
|
2010-02-26 00:23:49 +03:00
|
|
|
fout.close();
|
|
|
|
cmSystemTools::RenameFile(tmpout.c_str(), fname.c_str());
|
|
|
|
}
|
2009-09-09 01:10:35 +04:00
|
|
|
|
2010-02-26 00:23:49 +03:00
|
|
|
//---------------------------------------------------------
|
|
|
|
void cmCTestMultiProcessHandler::ReadCostData()
|
|
|
|
{
|
2010-03-01 19:00:23 +03:00
|
|
|
std::string fname = this->CTest->GetCostDataFile();
|
|
|
|
|
2010-02-26 00:23:49 +03:00
|
|
|
if(cmSystemTools::FileExists(fname.c_str(), true))
|
|
|
|
{
|
|
|
|
std::ifstream fin;
|
|
|
|
fin.open(fname.c_str());
|
|
|
|
std::string line;
|
|
|
|
while(std::getline(fin, line))
|
|
|
|
{
|
2010-03-01 19:59:00 +03:00
|
|
|
if(line == "---") break;
|
|
|
|
|
2010-02-26 00:23:49 +03:00
|
|
|
std::vector<cmsys::String> parts =
|
|
|
|
cmSystemTools::SplitString(line.c_str(), ' ');
|
|
|
|
|
|
|
|
// Probably an older version of the file, will be fixed next run
|
2010-03-01 20:05:58 +03:00
|
|
|
if(parts.size() < 3)
|
|
|
|
{
|
|
|
|
fin.close();
|
|
|
|
return;
|
|
|
|
}
|
2010-02-26 00:23:49 +03:00
|
|
|
|
|
|
|
std::string name = parts[0];
|
|
|
|
int prev = atoi(parts[1].c_str());
|
|
|
|
float cost = static_cast<float>(atof(parts[2].c_str()));
|
|
|
|
|
|
|
|
int index = this->SearchByName(name);
|
|
|
|
if(index == -1) continue;
|
|
|
|
|
|
|
|
this->Properties[index]->PreviousRuns = prev;
|
2011-01-03 19:25:46 +03:00
|
|
|
// When not running in parallel mode, don't use cost data
|
|
|
|
if(this->ParallelLevel > 1 &&
|
|
|
|
this->Properties[index] &&
|
|
|
|
this->Properties[index]->Cost == 0)
|
2009-09-09 01:10:35 +04:00
|
|
|
{
|
|
|
|
this->Properties[index]->Cost = cost;
|
|
|
|
}
|
|
|
|
}
|
2010-03-01 19:59:00 +03:00
|
|
|
// Next part of the file is the failed tests
|
|
|
|
while(std::getline(fin, line))
|
|
|
|
{
|
|
|
|
if(line != "")
|
|
|
|
{
|
|
|
|
this->LastTestsFailed.push_back(line);
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 01:10:35 +04:00
|
|
|
fin.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2010-02-26 00:23:49 +03:00
|
|
|
int cmCTestMultiProcessHandler::SearchByName(std::string name)
|
2009-09-09 01:10:35 +04:00
|
|
|
{
|
2010-02-26 00:23:49 +03:00
|
|
|
int index = -1;
|
|
|
|
|
|
|
|
for(PropertiesMap::iterator i = this->Properties.begin();
|
|
|
|
i != this->Properties.end(); ++i)
|
2009-09-09 01:10:35 +04:00
|
|
|
{
|
2010-02-26 00:23:49 +03:00
|
|
|
if(i->second->Name == name)
|
|
|
|
{
|
|
|
|
index = i->first;
|
|
|
|
}
|
2009-09-09 01:10:35 +04:00
|
|
|
}
|
2010-02-26 00:23:49 +03:00
|
|
|
return index;
|
2009-09-09 01:10:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
2010-02-26 00:23:49 +03:00
|
|
|
void cmCTestMultiProcessHandler::CreateTestCostList()
|
2009-09-09 01:10:35 +04:00
|
|
|
{
|
2010-02-26 00:23:49 +03:00
|
|
|
for(TestMap::iterator i = this->Tests.begin();
|
|
|
|
i != this->Tests.end(); ++i)
|
|
|
|
{
|
2010-07-01 22:10:49 +04:00
|
|
|
SortedTests.push_back(i->first);
|
|
|
|
|
2011-01-03 19:25:46 +03:00
|
|
|
//If the test failed last time, it should be run first, so max the cost.
|
|
|
|
//Only do this for parallel runs; in non-parallel runs, avoid clobbering
|
|
|
|
//the test's explicitly set cost.
|
|
|
|
if(this->ParallelLevel > 1 &&
|
|
|
|
std::find(this->LastTestsFailed.begin(), this->LastTestsFailed.end(),
|
|
|
|
this->Properties[i->first]->Name) != this->LastTestsFailed.end())
|
2010-03-01 19:59:00 +03:00
|
|
|
{
|
2010-07-01 22:10:49 +04:00
|
|
|
this->Properties[i->first]->Cost = FLT_MAX;
|
2010-03-01 19:59:00 +03:00
|
|
|
}
|
2010-02-26 00:23:49 +03:00
|
|
|
}
|
2011-01-03 19:25:46 +03:00
|
|
|
|
|
|
|
TestComparator comp(this);
|
2011-02-18 21:10:26 +03:00
|
|
|
std::stable_sort(SortedTests.begin(), SortedTests.end(), comp);
|
2009-09-09 01:10:35 +04:00
|
|
|
}
|
|
|
|
|
2009-09-08 21:39:13 +04:00
|
|
|
//---------------------------------------------------------
|
2009-08-27 18:37:30 +04:00
|
|
|
void cmCTestMultiProcessHandler::WriteCheckpoint(int index)
|
|
|
|
{
|
|
|
|
std::string fname = this->CTest->GetBinaryDir()
|
|
|
|
+ "/Testing/Temporary/CTestCheckpoint.txt";
|
|
|
|
std::fstream fout;
|
2010-02-26 00:23:49 +03:00
|
|
|
fout.open(fname.c_str(), std::ios::app | std::ios::out);
|
2009-08-27 18:37:30 +04:00
|
|
|
fout << index << "\n";
|
|
|
|
fout.close();
|
|
|
|
}
|
|
|
|
|
2009-09-09 01:10:35 +04:00
|
|
|
//---------------------------------------------------------
|
2009-08-27 18:37:30 +04:00
|
|
|
void cmCTestMultiProcessHandler::MarkFinished()
|
|
|
|
{
|
|
|
|
std::string fname = this->CTest->GetBinaryDir()
|
|
|
|
+ "/Testing/Temporary/CTestCheckpoint.txt";
|
|
|
|
cmSystemTools::RemoveFile(fname.c_str());
|
|
|
|
}
|
|
|
|
|
2009-09-09 01:10:35 +04:00
|
|
|
//---------------------------------------------------------
|
2009-08-28 19:08:39 +04:00
|
|
|
//For ShowOnly mode
|
|
|
|
void cmCTestMultiProcessHandler::PrintTestList()
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
2009-09-25 19:45:19 +04:00
|
|
|
this->TestHandler->SetMaxIndex(this->FindMaxIndex());
|
2009-08-28 19:08:39 +04:00
|
|
|
int count = 0;
|
2010-08-31 18:41:23 +04:00
|
|
|
|
2009-08-28 19:08:39 +04:00
|
|
|
for (PropertiesMap::iterator it = this->Properties.begin();
|
2009-11-02 20:52:50 +03:00
|
|
|
it != this->Properties.end(); ++it)
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
2009-08-28 19:08:39 +04:00
|
|
|
count++;
|
|
|
|
cmCTestTestHandler::cmCTestTestProperties& p = *it->second;
|
2010-08-31 18:41:23 +04:00
|
|
|
|
2009-10-27 17:16:01 +03:00
|
|
|
//push working dir
|
|
|
|
std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
|
|
|
|
cmSystemTools::ChangeDirectory(p.Directory.c_str());
|
2009-08-28 19:08:39 +04:00
|
|
|
|
2009-09-11 18:09:48 +04:00
|
|
|
cmCTestRunTest testRun(this->TestHandler);
|
2009-08-28 19:08:39 +04:00
|
|
|
testRun.SetIndex(p.Index);
|
|
|
|
testRun.SetTestProperties(&p);
|
|
|
|
testRun.ComputeArguments(); //logs the command in verbose mode
|
|
|
|
|
2010-08-31 18:41:23 +04:00
|
|
|
if(p.Labels.size()) //print the labels
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Labels:");
|
|
|
|
}
|
|
|
|
for(std::vector<std::string>::iterator label = p.Labels.begin();
|
|
|
|
label != p.Labels.end(); ++label)
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " " << *label);
|
|
|
|
}
|
|
|
|
if(p.Labels.size()) //print the labels
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl);
|
|
|
|
}
|
|
|
|
|
2009-08-28 19:08:39 +04:00
|
|
|
if (this->TestHandler->MemCheck)
|
|
|
|
{
|
2009-09-24 17:49:46 +04:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Memory Check");
|
2009-08-28 19:08:39 +04:00
|
|
|
}
|
|
|
|
else
|
2008-07-03 17:31:33 +04:00
|
|
|
{
|
2009-09-24 17:49:46 +04:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Test");
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
2009-09-24 17:49:46 +04:00
|
|
|
cmOStringStream indexStr;
|
|
|
|
indexStr << " #" << p.Index << ":";
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
2009-09-24 17:49:46 +04:00
|
|
|
std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
|
|
|
|
<< indexStr.str().c_str());
|
2009-08-28 19:08:39 +04:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, p.Name.c_str() << std::endl);
|
2009-10-27 17:16:01 +03:00
|
|
|
//pop working dir
|
|
|
|
cmSystemTools::ChangeDirectory(current_dir.c_str());
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
2010-08-31 18:41:23 +04:00
|
|
|
|
2009-09-24 17:49:46 +04:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl << "Total Tests: "
|
|
|
|
<< this->Total << std::endl);
|
2008-07-03 17:31:33 +04:00
|
|
|
}
|
|
|
|
|
2010-08-31 18:41:23 +04:00
|
|
|
void cmCTestMultiProcessHandler::PrintLabels()
|
|
|
|
{
|
|
|
|
std::set<std::string> allLabels;
|
|
|
|
for (PropertiesMap::iterator it = this->Properties.begin();
|
|
|
|
it != this->Properties.end(); ++it)
|
|
|
|
{
|
|
|
|
cmCTestTestHandler::cmCTestTestProperties& p = *it->second;
|
|
|
|
allLabels.insert(p.Labels.begin(), p.Labels.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(allLabels.size())
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "All Labels:" << std::endl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "No Labels Exist" << std::endl);
|
|
|
|
}
|
|
|
|
for(std::set<std::string>::iterator label = allLabels.begin();
|
|
|
|
label != allLabels.end(); ++label)
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " " << *label << std::endl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-09 01:10:35 +04:00
|
|
|
//---------------------------------------------------------
|
2009-08-27 18:37:30 +04:00
|
|
|
void cmCTestMultiProcessHandler::CheckResume()
|
|
|
|
{
|
|
|
|
std::string fname = this->CTest->GetBinaryDir()
|
|
|
|
+ "/Testing/Temporary/CTestCheckpoint.txt";
|
|
|
|
if(this->CTest->GetFailover())
|
|
|
|
{
|
|
|
|
if(cmSystemTools::FileExists(fname.c_str(), true))
|
|
|
|
{
|
|
|
|
*this->TestHandler->LogFile << "Resuming previously interrupted test set"
|
|
|
|
<< std::endl
|
|
|
|
<< "----------------------------------------------------------"
|
|
|
|
<< std::endl;
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2009-08-27 18:37:30 +04:00
|
|
|
std::ifstream fin;
|
|
|
|
fin.open(fname.c_str());
|
|
|
|
std::string line;
|
|
|
|
while(std::getline(fin, line))
|
|
|
|
{
|
|
|
|
int index = atoi(line.c_str());
|
|
|
|
this->RemoveTest(index);
|
|
|
|
}
|
|
|
|
fin.close();
|
|
|
|
}
|
|
|
|
}
|
2009-11-05 19:37:47 +03:00
|
|
|
else if(cmSystemTools::FileExists(fname.c_str(), true))
|
2009-08-27 18:37:30 +04:00
|
|
|
{
|
2009-11-05 19:37:47 +03:00
|
|
|
cmSystemTools::RemoveFile(fname.c_str());
|
2009-08-27 18:37:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-08 21:39:13 +04:00
|
|
|
//---------------------------------------------------------
|
2009-08-27 18:37:30 +04:00
|
|
|
void cmCTestMultiProcessHandler::RemoveTest(int index)
|
|
|
|
{
|
2009-09-08 21:39:13 +04:00
|
|
|
this->EraseTest(index);
|
2009-08-27 18:37:30 +04:00
|
|
|
this->Properties.erase(index);
|
|
|
|
this->TestRunningMap[index] = false;
|
|
|
|
this->TestFinishMap[index] = true;
|
2009-08-28 19:08:39 +04:00
|
|
|
this->Completed++;
|
2009-08-27 18:37:30 +04:00
|
|
|
}
|
2009-09-02 18:08:40 +04:00
|
|
|
|
2009-09-08 21:39:13 +04:00
|
|
|
//---------------------------------------------------------
|
2009-09-02 18:08:40 +04:00
|
|
|
int cmCTestMultiProcessHandler::FindMaxIndex()
|
|
|
|
{
|
|
|
|
int max = 0;
|
|
|
|
cmCTestMultiProcessHandler::TestMap::iterator i = this->Tests.begin();
|
|
|
|
for(; i != this->Tests.end(); ++i)
|
|
|
|
{
|
|
|
|
if(i->first > max)
|
|
|
|
{
|
|
|
|
max = i->first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
2009-11-02 20:52:50 +03:00
|
|
|
|
|
|
|
//Returns true if no cycles exist in the dependency graph
|
|
|
|
bool cmCTestMultiProcessHandler::CheckCycles()
|
|
|
|
{
|
2010-06-30 18:39:17 +04:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2009-11-02 20:52:50 +03:00
|
|
|
"Checking test dependency graph..." << std::endl);
|
|
|
|
for(TestMap::iterator it = this->Tests.begin();
|
|
|
|
it != this->Tests.end(); ++it)
|
|
|
|
{
|
|
|
|
//DFS from each element to itself
|
2010-12-16 00:49:34 +03:00
|
|
|
int root = it->first;
|
|
|
|
std::set<int> visited;
|
2009-11-02 20:52:50 +03:00
|
|
|
std::stack<int> s;
|
2010-12-16 00:49:34 +03:00
|
|
|
s.push(root);
|
2009-11-02 20:52:50 +03:00
|
|
|
while(!s.empty())
|
|
|
|
{
|
|
|
|
int test = s.top();
|
|
|
|
s.pop();
|
2010-12-16 00:49:34 +03:00
|
|
|
if(visited.insert(test).second)
|
2009-11-02 20:52:50 +03:00
|
|
|
{
|
2010-12-16 00:49:34 +03:00
|
|
|
for(TestSet::iterator d = this->Tests[test].begin();
|
|
|
|
d != this->Tests[test].end(); ++d)
|
2009-11-02 20:52:50 +03:00
|
|
|
{
|
2010-12-16 00:49:34 +03:00
|
|
|
if(*d == root)
|
|
|
|
{
|
|
|
|
//cycle exists
|
2010-12-16 16:07:43 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Error: a cycle exists in the test dependency graph "
|
|
|
|
"for the test \"" << this->Properties[root]->Name <<
|
|
|
|
"\".\nPlease fix the cycle and run ctest again.\n");
|
2010-12-16 00:49:34 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s.push(*d);
|
|
|
|
}
|
2009-11-02 20:52:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-16 00:49:34 +03:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"Checking test dependency graph end" << std::endl);
|
2009-11-02 20:52:50 +03:00
|
|
|
return true;
|
|
|
|
}
|