2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2008-07-03 13:31:33 +00:00
|
|
|
#include "cmCTestMultiProcessHandler.h"
|
2016-04-29 13:40:20 +00:00
|
|
|
|
2008-07-03 13:31:33 +00:00
|
|
|
#include "cmCTest.h"
|
2016-08-24 20:01:40 +00:00
|
|
|
#include "cmCTestRunTest.h"
|
2015-06-09 12:50:44 +00:00
|
|
|
#include "cmCTestScriptHandler.h"
|
2016-08-24 20:01:40 +00:00
|
|
|
#include "cmCTestTestHandler.h"
|
2009-08-27 14:37:30 +00:00
|
|
|
#include "cmSystemTools.h"
|
2016-08-24 20:01:40 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
2014-01-04 05:47:13 +00:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-08-24 20:01:40 +00:00
|
|
|
#include <cmsys/String.hxx>
|
2015-06-09 12:50:44 +00:00
|
|
|
#include <cmsys/SystemInformation.hxx>
|
2016-08-24 20:01:40 +00:00
|
|
|
#include <iomanip>
|
2016-04-29 14:53:13 +00:00
|
|
|
#include <list>
|
|
|
|
#include <math.h>
|
2016-08-24 20:01:40 +00:00
|
|
|
#include <sstream>
|
2016-04-29 14:53:13 +00:00
|
|
|
#include <stack>
|
|
|
|
#include <stdlib.h>
|
2016-08-24 20:01:40 +00:00
|
|
|
#include <utility>
|
2008-07-03 13:31:33 +00:00
|
|
|
|
2010-07-01 18:10:49 +00:00
|
|
|
class TestComparator
|
|
|
|
{
|
|
|
|
public:
|
2016-05-16 14:34:04 +00:00
|
|
|
TestComparator(cmCTestMultiProcessHandler* handler)
|
|
|
|
: Handler(handler)
|
|
|
|
{
|
|
|
|
}
|
2010-07-01 18:10:49 +00:00
|
|
|
~TestComparator() {}
|
|
|
|
|
|
|
|
// Sorts tests in descending order of cost
|
2016-05-16 14:34:04 +00:00
|
|
|
bool operator()(int index1, int index2) const
|
|
|
|
{
|
2010-07-01 18:10:49 +00:00
|
|
|
return Handler->Properties[index1]->Cost >
|
|
|
|
Handler->Properties[index2]->Cost;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-07-01 18:10:49 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
cmCTestMultiProcessHandler* Handler;
|
|
|
|
};
|
|
|
|
|
2008-07-03 13:31:33 +00:00
|
|
|
cmCTestMultiProcessHandler::cmCTestMultiProcessHandler()
|
|
|
|
{
|
|
|
|
this->ParallelLevel = 1;
|
2015-06-09 12:50:44 +00:00
|
|
|
this->TestLoad = 0;
|
2009-08-28 15:08:39 +00:00
|
|
|
this->Completed = 0;
|
2009-09-07 14:26:17 +00:00
|
|
|
this->RunningCount = 0;
|
2010-06-15 14:29:35 +00:00
|
|
|
this->StopTimePassed = false;
|
2013-10-19 07:28:18 +00:00
|
|
|
this->HasCycles = false;
|
2015-06-01 13:42:44 +00:00
|
|
|
this->SerialTestRunning = false;
|
2008-07-03 13:31:33 +00:00
|
|
|
}
|
2009-09-10 15:16:08 +00:00
|
|
|
|
|
|
|
cmCTestMultiProcessHandler::~cmCTestMultiProcessHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
// Set the tests
|
|
|
|
void cmCTestMultiProcessHandler::SetTests(TestMap& tests,
|
|
|
|
PropertiesMap& properties)
|
2008-07-03 13:31:33 +00:00
|
|
|
{
|
2009-09-08 17:39:13 +00:00
|
|
|
this->Tests = tests;
|
|
|
|
this->Properties = properties;
|
|
|
|
this->Total = this->Tests.size();
|
2008-07-03 13:31:33 +00:00
|
|
|
// set test run map to false for all
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestMap::iterator i = this->Tests.begin(); i != this->Tests.end();
|
|
|
|
++i) {
|
2008-07-03 13:31:33 +00:00
|
|
|
this->TestRunningMap[i->first] = false;
|
|
|
|
this->TestFinishMap[i->first] = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!this->CTest->GetShowOnly()) {
|
2009-11-16 15:58:43 +00:00
|
|
|
this->ReadCostData();
|
2013-10-19 07:28:18 +00:00
|
|
|
this->HasCycles = !this->CheckCycles();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->HasCycles) {
|
2013-10-19 07:28:18 +00:00
|
|
|
return;
|
2009-11-16 15:58:43 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
this->CreateTestCostList();
|
|
|
|
}
|
2008-07-03 13:31:33 +00:00
|
|
|
}
|
2009-08-27 14:37:30 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
// Set the max number of tests that can be run at the same time.
|
2009-08-26 16:09:06 +00:00
|
|
|
void cmCTestMultiProcessHandler::SetParallelLevel(size_t level)
|
2008-07-03 13:31:33 +00:00
|
|
|
{
|
2009-08-26 16:09:06 +00:00
|
|
|
this->ParallelLevel = level < 1 ? 1 : level;
|
2008-07-03 13:31:33 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 12:50:44 +00:00
|
|
|
void cmCTestMultiProcessHandler::SetTestLoad(unsigned long load)
|
|
|
|
{
|
|
|
|
this->TestLoad = load;
|
|
|
|
}
|
|
|
|
|
2008-07-03 13:31:33 +00:00
|
|
|
void cmCTestMultiProcessHandler::RunTests()
|
|
|
|
{
|
2009-08-27 14:37:30 +00:00
|
|
|
this->CheckResume();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->HasCycles) {
|
2009-11-02 17:52:50 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-02 14:08:40 +00:00
|
|
|
this->TestHandler->SetMaxIndex(this->FindMaxIndex());
|
2008-07-03 13:31:33 +00:00
|
|
|
this->StartNextTests();
|
2016-05-16 14:34:04 +00:00
|
|
|
while (!this->Tests.empty()) {
|
|
|
|
if (this->StopTimePassed) {
|
2010-06-15 14:29:35 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-07-03 13:31:33 +00:00
|
|
|
this->CheckOutput();
|
|
|
|
this->StartNextTests();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-07-03 13:31:33 +00:00
|
|
|
// let all running tests finish
|
2016-05-16 14:34:04 +00:00
|
|
|
while (this->CheckOutput()) {
|
|
|
|
}
|
2009-08-27 14:37:30 +00:00
|
|
|
this->MarkFinished();
|
2010-02-25 21:23:49 +00:00
|
|
|
this->UpdateCostData();
|
2008-07-03 13:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestMultiProcessHandler::StartTestProcess(int test)
|
|
|
|
{
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"test " << test << "\n", this->Quiet);
|
2008-07-03 13:31:33 +00:00
|
|
|
this->TestRunningMap[test] = true; // mark the test as running
|
|
|
|
// now remove the test itself
|
2009-09-08 17:39:13 +00:00
|
|
|
this->EraseTest(test);
|
2010-06-23 21:18:59 +00:00
|
|
|
this->RunningCount += GetProcessorsUsed(test);
|
2009-09-08 17:39:13 +00:00
|
|
|
|
2009-09-11 14:09:48 +00:00
|
|
|
cmCTestRunTest* testRun = new cmCTestRunTest(this->TestHandler);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->CTest->GetRepeatUntilFail()) {
|
2015-03-05 21:51:10 +00:00
|
|
|
testRun->SetRunUntilFailOn();
|
|
|
|
testRun->SetNumberOfRuns(this->CTest->GetTestRepeat());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
testRun->SetIndex(test);
|
|
|
|
testRun->SetTestProperties(this->Properties[test]);
|
2009-10-20 14:54:02 +00:00
|
|
|
|
2016-09-07 04:04:07 +00:00
|
|
|
// Find any failed dependencies for this test. We assume the more common
|
|
|
|
// scenario has no failed tests, so make it the outer loop.
|
|
|
|
for (std::vector<std::string>::const_iterator it = this->Failed->begin();
|
|
|
|
it != this->Failed->end(); ++it) {
|
|
|
|
if (this->Properties[test]->RequireSuccessDepends.find(*it) !=
|
|
|
|
this->Properties[test]->RequireSuccessDepends.end()) {
|
|
|
|
testRun->AddFailedDependency(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-20 14:54:02 +00:00
|
|
|
std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
|
2014-10-15 12:54:05 +00:00
|
|
|
cmSystemTools::ChangeDirectory(this->Properties[test]->Directory);
|
2009-10-20 14:54:02 +00:00
|
|
|
|
2010-03-02 20:34:37 +00:00
|
|
|
// Lock the resources we'll be using
|
|
|
|
this->LockResources(test);
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (testRun->StartTest(this->Total)) {
|
2009-08-26 16:09:06 +00:00
|
|
|
this->RunningTests.insert(testRun);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (testRun->IsStopTimePassed()) {
|
2010-06-15 14:29:35 +00:00
|
|
|
this->StopTimePassed = true;
|
|
|
|
delete testRun;
|
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2013-12-20 21:44:37 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestMap::iterator j = this->Tests.begin(); j != this->Tests.end();
|
|
|
|
++j) {
|
2013-12-20 21:44:37 +00:00
|
|
|
j->second.erase(test);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-12-20 21:44:37 +00:00
|
|
|
|
2010-03-02 20:34:37 +00:00
|
|
|
this->UnlockResources(test);
|
2009-09-03 19:33:44 +00:00
|
|
|
this->Completed++;
|
2009-11-05 16:03:07 +00:00
|
|
|
this->TestFinishMap[test] = true;
|
|
|
|
this->TestRunningMap[test] = false;
|
2009-09-07 14:26:17 +00:00
|
|
|
this->RunningCount -= GetProcessorsUsed(test);
|
2009-09-03 19:33:44 +00:00
|
|
|
testRun->EndTest(this->Completed, this->Total, false);
|
2009-09-23 19:37:50 +00:00
|
|
|
this->Failed->push_back(this->Properties[test]->Name);
|
2009-12-10 14:39:19 +00:00
|
|
|
delete testRun;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-10-15 12:54:05 +00:00
|
|
|
cmSystemTools::ChangeDirectory(current_dir);
|
2008-07-03 13:31:33 +00:00
|
|
|
}
|
|
|
|
|
2010-03-02 20:34:37 +00:00
|
|
|
void cmCTestMultiProcessHandler::LockResources(int index)
|
|
|
|
{
|
2014-11-25 15:33:00 +00:00
|
|
|
this->LockedResources.insert(
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Properties[index]->LockedResources.begin(),
|
|
|
|
this->Properties[index]->LockedResources.end());
|
2015-06-01 13:42:44 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->Properties[index]->RunSerial) {
|
2015-06-01 13:42:44 +00:00
|
|
|
this->SerialTestRunning = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-03-02 20:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestMultiProcessHandler::UnlockResources(int index)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::set<std::string>::iterator i =
|
|
|
|
this->Properties[index]->LockedResources.begin();
|
|
|
|
i != this->Properties[index]->LockedResources.end(); ++i) {
|
2010-03-02 20:34:37 +00:00
|
|
|
this->LockedResources.erase(*i);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (this->Properties[index]->RunSerial) {
|
2015-10-23 13:25:25 +00:00
|
|
|
this->SerialTestRunning = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-03-02 20:34:37 +00:00
|
|
|
}
|
|
|
|
|
2009-09-08 17:39:13 +00:00
|
|
|
void cmCTestMultiProcessHandler::EraseTest(int test)
|
|
|
|
{
|
|
|
|
this->Tests.erase(test);
|
2010-07-01 18:10:49 +00:00
|
|
|
this->SortedTests.erase(
|
|
|
|
std::find(this->SortedTests.begin(), this->SortedTests.end(), test));
|
2009-09-08 17:39:13 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 14:26:17 +00:00
|
|
|
inline size_t cmCTestMultiProcessHandler::GetProcessorsUsed(int test)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
size_t processors = static_cast<int>(this->Properties[test]->Processors);
|
|
|
|
// If processors setting is set higher than the -j
|
|
|
|
// setting, we default to using all of the process slots.
|
|
|
|
if (processors > this->ParallelLevel) {
|
2009-09-07 14:26:17 +00:00
|
|
|
processors = this->ParallelLevel;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-07 14:26:17 +00:00
|
|
|
return processors;
|
|
|
|
}
|
|
|
|
|
2015-06-09 12:50:44 +00:00
|
|
|
std::string cmCTestMultiProcessHandler::GetName(int test)
|
|
|
|
{
|
|
|
|
return this->Properties[test]->Name;
|
|
|
|
}
|
|
|
|
|
2008-07-03 13:31:33 +00:00
|
|
|
bool cmCTestMultiProcessHandler::StartTest(int test)
|
|
|
|
{
|
2016-05-16 14:34:04 +00: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()) {
|
2010-03-02 20:34:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-03-02 20:34:37 +00:00
|
|
|
|
2008-07-03 13:31:33 +00:00
|
|
|
// if there are no depends left then run this test
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->Tests[test].empty()) {
|
2008-07-03 13:31:33 +00:00
|
|
|
this->StartTestProcess(test);
|
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
// This test was not able to start because it is waiting
|
2008-07-03 13:31:33 +00:00
|
|
|
// on depends to run
|
2009-08-26 16:09:06 +00:00
|
|
|
return false;
|
2008-07-03 13:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestMultiProcessHandler::StartNextTests()
|
|
|
|
{
|
2012-12-18 18:09:53 +00:00
|
|
|
size_t numToStart = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->RunningCount < this->ParallelLevel) {
|
2012-12-18 18:09:53 +00:00
|
|
|
numToStart = this->ParallelLevel - this->RunningCount;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-12-18 18:09:53 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (numToStart == 0) {
|
2008-07-03 13:31:33 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-04 14:16:06 +00:00
|
|
|
|
2015-06-01 13:42:44 +00:00
|
|
|
// Don't start any new tests if one with the RUN_SERIAL property
|
|
|
|
// is already running.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->SerialTestRunning) {
|
2015-06-01 13:42:44 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-06-01 13:42:44 +00:00
|
|
|
|
2015-06-09 12:50:44 +00:00
|
|
|
bool allTestsFailedTestLoadCheck = false;
|
|
|
|
bool usedFakeLoadForTesting = false;
|
|
|
|
size_t minProcessorsRequired = this->ParallelLevel;
|
2016-12-10 13:53:06 +00:00
|
|
|
std::string testWithMinProcessors;
|
2015-06-09 12:50:44 +00:00
|
|
|
|
|
|
|
cmsys::SystemInformation info;
|
|
|
|
|
|
|
|
unsigned long systemLoad = 0;
|
|
|
|
size_t spareLoad = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->TestLoad > 0) {
|
2015-06-09 12:50:44 +00:00
|
|
|
// Activate possible wait.
|
|
|
|
allTestsFailedTestLoadCheck = true;
|
|
|
|
|
|
|
|
// Check for a fake load average value used in testing.
|
2016-07-07 21:54:05 +00:00
|
|
|
std::string fake_load_value;
|
|
|
|
if (cmSystemTools::GetEnv("__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING",
|
|
|
|
fake_load_value)) {
|
2015-06-09 12:50:44 +00:00
|
|
|
usedFakeLoadForTesting = true;
|
2016-07-07 21:54:05 +00:00
|
|
|
if (!cmSystemTools::StringToULong(fake_load_value.c_str(),
|
|
|
|
&systemLoad)) {
|
2015-06-09 12:50:44 +00:00
|
|
|
cmSystemTools::Error("Failed to parse fake load value: ",
|
2016-07-07 21:54:05 +00:00
|
|
|
fake_load_value.c_str());
|
2015-06-09 12:50:44 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-06-09 12:50:44 +00:00
|
|
|
// If it's not set, look up the true load average.
|
2016-05-16 14:34:04 +00:00
|
|
|
else {
|
2015-06-09 12:50:44 +00:00
|
|
|
systemLoad = static_cast<unsigned long>(ceil(info.GetLoadAverage()));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
spareLoad =
|
|
|
|
(this->TestLoad > systemLoad ? this->TestLoad - systemLoad : 0);
|
2015-06-09 12:50:44 +00:00
|
|
|
|
|
|
|
// Don't start more tests than the spare load can support.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (numToStart > spareLoad) {
|
2015-06-09 12:50:44 +00:00
|
|
|
numToStart = spareLoad;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-06-09 12:50:44 +00:00
|
|
|
|
2010-07-01 18:10:49 +00:00
|
|
|
TestList copy = this->SortedTests;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestList::iterator test = copy.begin(); test != copy.end(); ++test) {
|
2015-06-01 13:42:44 +00:00
|
|
|
// Take a nap if we're currently performing a RUN_SERIAL test.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->SerialTestRunning) {
|
2015-06-01 13:42:44 +00:00
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-06-01 13:42:44 +00:00
|
|
|
// We can only start a RUN_SERIAL test if no other tests are also running.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->Properties[*test]->RunSerial && this->RunningCount > 0) {
|
2015-06-01 13:42:44 +00:00
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-06-01 13:42:44 +00:00
|
|
|
|
2010-07-01 18:10:49 +00:00
|
|
|
size_t processors = GetProcessorsUsed(*test);
|
2015-06-09 12:50:44 +00:00
|
|
|
bool testLoadOk = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->TestLoad > 0) {
|
|
|
|
if (processors <= spareLoad) {
|
|
|
|
cmCTestLog(this->CTest, DEBUG, "OK to run "
|
|
|
|
<< GetName(*test) << ", it requires " << processors
|
|
|
|
<< " procs & system load is: " << systemLoad
|
|
|
|
<< std::endl);
|
2015-06-09 12:50:44 +00:00
|
|
|
allTestsFailedTestLoadCheck = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2015-06-09 12:50:44 +00:00
|
|
|
testLoadOk = false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-10-17 20:10:35 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (processors <= minProcessorsRequired) {
|
2015-06-09 12:50:44 +00:00
|
|
|
minProcessorsRequired = processors;
|
|
|
|
testWithMinProcessors = GetName(*test);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-06-09 12:50:44 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (testLoadOk && processors <= numToStart && this->StartTest(*test)) {
|
|
|
|
if (this->StopTimePassed) {
|
2015-06-09 12:50:44 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-06-09 12:50:44 +00:00
|
|
|
|
|
|
|
numToStart -= processors;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (numToStart == 0) {
|
2015-06-09 12:50:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-06-09 12:50:44 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (allTestsFailedTestLoadCheck) {
|
2015-06-09 12:50:44 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***** WAITING, ");
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->SerialTestRunning) {
|
2015-06-09 12:50:44 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
|
|
|
"Waiting for RUN_SERIAL test to finish.");
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2016-05-06 18:19:04 +00:00
|
|
|
/* clang-format off */
|
2015-06-09 12:50:44 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
|
|
|
"System Load: " << systemLoad << ", "
|
|
|
|
"Max Allowed Load: " << this->TestLoad << ", "
|
|
|
|
"Smallest test " << testWithMinProcessors <<
|
|
|
|
" requires " << minProcessorsRequired);
|
2016-05-06 18:19:04 +00:00
|
|
|
/* clang-format on */
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-06-09 12:50:44 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "*****" << std::endl);
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (usedFakeLoadForTesting) {
|
2015-06-09 12:50:44 +00:00
|
|
|
// Break out of the infinite loop of waiting for our fake load
|
|
|
|
// to come down.
|
|
|
|
this->StopTimePassed = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2015-06-09 12:50:44 +00:00
|
|
|
// Wait between 1 and 5 seconds before trying again.
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestScriptHandler::SleepInSeconds(cmSystemTools::RandomSeed() % 5 +
|
|
|
|
1);
|
2008-07-03 13:31:33 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-07-03 13:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestMultiProcessHandler::CheckOutput()
|
|
|
|
{
|
|
|
|
// no more output we are done
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->RunningTests.empty()) {
|
2008-07-03 13:31:33 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
std::vector<cmCTestRunTest*> finished;
|
2008-07-03 13:31:33 +00:00
|
|
|
std::string out, err;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::set<cmCTestRunTest*>::const_iterator i =
|
|
|
|
this->RunningTests.begin();
|
|
|
|
i != this->RunningTests.end(); ++i) {
|
2009-08-26 16:09:06 +00:00
|
|
|
cmCTestRunTest* p = *i;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!p->CheckOutput()) {
|
2008-07-03 13:31:33 +00:00
|
|
|
finished.push_back(p);
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
for (std::vector<cmCTestRunTest*>::iterator i = finished.begin();
|
|
|
|
i != finished.end(); ++i) {
|
2009-08-28 15:08:39 +00:00
|
|
|
this->Completed++;
|
2009-08-26 16:09:06 +00:00
|
|
|
cmCTestRunTest* p = *i;
|
|
|
|
int test = p->GetIndex();
|
2009-08-28 15:08:39 +00:00
|
|
|
|
2015-03-05 21:51:10 +00:00
|
|
|
bool testResult = p->EndTest(this->Completed, this->Total, true);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (p->StartAgain()) {
|
2015-03-05 21:51:10 +00:00
|
|
|
this->Completed--; // remove the completed test because run again
|
|
|
|
continue;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (testResult) {
|
2009-08-28 15:08:39 +00:00
|
|
|
this->Passed->push_back(p->GetTestProperties()->Name);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2009-08-28 15:08:39 +00:00
|
|
|
this->Failed->push_back(p->GetTestProperties()->Name);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
for (TestMap::iterator j = this->Tests.begin(); j != this->Tests.end();
|
|
|
|
++j) {
|
2009-09-04 14:16:06 +00:00
|
|
|
j->second.erase(test);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
this->TestFinishMap[test] = true;
|
|
|
|
this->TestRunningMap[test] = false;
|
|
|
|
this->RunningTests.erase(p);
|
2009-08-27 14:37:30 +00:00
|
|
|
this->WriteCheckpoint(test);
|
2010-03-02 20:34:37 +00:00
|
|
|
this->UnlockResources(test);
|
2009-09-07 14:26:17 +00:00
|
|
|
this->RunningCount -= GetProcessorsUsed(test);
|
2009-08-26 16:09:06 +00:00
|
|
|
delete p;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
return true;
|
2008-07-03 13:31:33 +00:00
|
|
|
}
|
|
|
|
|
2010-02-25 21:23:49 +00:00
|
|
|
void cmCTestMultiProcessHandler::UpdateCostData()
|
2009-09-08 21:10:35 +00:00
|
|
|
{
|
2010-03-01 16:00:23 +00:00
|
|
|
std::string fname = this->CTest->GetCostDataFile();
|
2010-02-25 21:23:49 +00:00
|
|
|
std::string tmpout = fname + ".tmp";
|
2014-10-04 20:19:13 +00:00
|
|
|
cmsys::ofstream fout;
|
|
|
|
fout.open(tmpout.c_str());
|
2010-02-25 21:23:49 +00:00
|
|
|
|
|
|
|
PropertiesMap temp = this->Properties;
|
2009-09-08 21:10:35 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSystemTools::FileExists(fname.c_str())) {
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream fin;
|
2009-09-08 21:10:35 +00:00
|
|
|
fin.open(fname.c_str());
|
2010-02-25 21:23:49 +00:00
|
|
|
|
2009-09-08 21:10:35 +00:00
|
|
|
std::string line;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (std::getline(fin, line)) {
|
2016-06-10 16:36:24 +00:00
|
|
|
if (line == "---") {
|
2016-05-16 14:34:04 +00:00
|
|
|
break;
|
2016-06-10 16:36:24 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
std::vector<cmsys::String> parts = cmSystemTools::SplitString(line, ' ');
|
|
|
|
// Format: <name> <previous_runs> <avg_cost>
|
2016-06-10 16:36:24 +00:00
|
|
|
if (parts.size() < 3) {
|
2016-05-16 14:34:04 +00:00
|
|
|
break;
|
2016-06-10 16:36:24 +00:00
|
|
|
}
|
2010-02-25 21:23:49 +00: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);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (index == -1) {
|
2010-02-25 21:23:49 +00:00
|
|
|
// This test is not in memory. We just rewrite the entry
|
|
|
|
fout << name << " " << prev << " " << cost << "\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2010-02-25 21:23:49 +00:00
|
|
|
// Update with our new average cost
|
|
|
|
fout << name << " " << this->Properties[index]->PreviousRuns << " "
|
2016-05-16 14:34:04 +00:00
|
|
|
<< this->Properties[index]->Cost << "\n";
|
2010-02-25 21:23:49 +00:00
|
|
|
temp.erase(index);
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-02-25 21:23:49 +00:00
|
|
|
fin.close();
|
2014-10-15 12:54:05 +00:00
|
|
|
cmSystemTools::RemoveFile(fname);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-02-25 21:23:49 +00:00
|
|
|
|
|
|
|
// Add all tests not previously listed in the file
|
2016-05-16 14:34:04 +00:00
|
|
|
for (PropertiesMap::iterator i = temp.begin(); i != temp.end(); ++i) {
|
2010-02-25 21:23:49 +00:00
|
|
|
fout << i->second->Name << " " << i->second->PreviousRuns << " "
|
2016-05-16 14:34:04 +00:00
|
|
|
<< i->second->Cost << "\n";
|
|
|
|
}
|
2010-03-01 16:59:00 +00:00
|
|
|
|
|
|
|
// Write list of failed tests
|
|
|
|
fout << "---\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<std::string>::iterator i = this->Failed->begin();
|
|
|
|
i != this->Failed->end(); ++i) {
|
2016-06-06 21:53:32 +00:00
|
|
|
fout << *i << "\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-02-25 21:23:49 +00:00
|
|
|
fout.close();
|
|
|
|
cmSystemTools::RenameFile(tmpout.c_str(), fname.c_str());
|
|
|
|
}
|
2009-09-08 21:10:35 +00:00
|
|
|
|
2010-02-25 21:23:49 +00:00
|
|
|
void cmCTestMultiProcessHandler::ReadCostData()
|
|
|
|
{
|
2010-03-01 16:00:23 +00:00
|
|
|
std::string fname = this->CTest->GetCostDataFile();
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSystemTools::FileExists(fname.c_str(), true)) {
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream fin;
|
2010-02-25 21:23:49 +00:00
|
|
|
fin.open(fname.c_str());
|
|
|
|
std::string line;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (std::getline(fin, line)) {
|
2016-06-10 16:36:24 +00:00
|
|
|
if (line == "---") {
|
2016-05-16 14:34:04 +00:00
|
|
|
break;
|
2016-06-10 16:36:24 +00:00
|
|
|
}
|
2010-03-01 16:59:00 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::vector<cmsys::String> parts = cmSystemTools::SplitString(line, ' ');
|
2010-02-25 21:23:49 +00:00
|
|
|
|
|
|
|
// Probably an older version of the file, will be fixed next run
|
2016-05-16 14:34:04 +00:00
|
|
|
if (parts.size() < 3) {
|
2010-03-01 17:05:58 +00:00
|
|
|
fin.close();
|
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-02-25 21:23:49 +00: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);
|
2016-06-10 16:36:24 +00:00
|
|
|
if (index == -1) {
|
2016-05-16 14:34:04 +00:00
|
|
|
continue;
|
2016-06-10 16:36:24 +00:00
|
|
|
}
|
2010-02-25 21:23:49 +00:00
|
|
|
|
|
|
|
this->Properties[index]->PreviousRuns = prev;
|
2011-01-03 16:25:46 +00:00
|
|
|
// When not running in parallel mode, don't use cost data
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->ParallelLevel > 1 && this->Properties[index] &&
|
|
|
|
this->Properties[index]->Cost == 0) {
|
2009-09-08 21:10:35 +00:00
|
|
|
this->Properties[index]->Cost = cost;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-03-01 16:59:00 +00:00
|
|
|
// Next part of the file is the failed tests
|
2016-05-16 14:34:04 +00:00
|
|
|
while (std::getline(fin, line)) {
|
|
|
|
if (line != "") {
|
2010-03-01 16:59:00 +00:00
|
|
|
this->LastTestsFailed.push_back(line);
|
|
|
|
}
|
2009-09-08 21:10:35 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
fin.close();
|
|
|
|
}
|
2009-09-08 21:10:35 +00:00
|
|
|
}
|
|
|
|
|
2016-05-26 19:58:51 +00:00
|
|
|
int cmCTestMultiProcessHandler::SearchByName(std::string const& name)
|
2009-09-08 21:10:35 +00:00
|
|
|
{
|
2010-02-25 21:23:49 +00:00
|
|
|
int index = -1;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (PropertiesMap::iterator i = this->Properties.begin();
|
|
|
|
i != this->Properties.end(); ++i) {
|
|
|
|
if (i->second->Name == name) {
|
2010-02-25 21:23:49 +00:00
|
|
|
index = i->first;
|
2009-09-08 21:10:35 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-02-25 21:23:49 +00:00
|
|
|
return index;
|
2009-09-08 21:10:35 +00:00
|
|
|
}
|
|
|
|
|
2010-02-25 21:23:49 +00:00
|
|
|
void cmCTestMultiProcessHandler::CreateTestCostList()
|
2013-12-20 21:44:37 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->ParallelLevel > 1) {
|
2013-12-20 21:44:37 +00:00
|
|
|
CreateParallelTestCostList();
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2013-12-20 21:44:37 +00:00
|
|
|
CreateSerialTestCostList();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-12-20 21:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestMultiProcessHandler::CreateParallelTestCostList()
|
2009-09-08 21:10:35 +00:00
|
|
|
{
|
2013-10-31 21:10:56 +00:00
|
|
|
TestSet alreadySortedTests;
|
|
|
|
|
2013-10-18 22:38:35 +00:00
|
|
|
std::list<TestSet> priorityStack;
|
|
|
|
priorityStack.push_back(TestSet());
|
2016-05-16 14:34:04 +00:00
|
|
|
TestSet& topLevel = priorityStack.back();
|
2013-10-18 22:38:35 +00:00
|
|
|
|
2013-10-27 07:44:55 +00:00
|
|
|
// In parallel test runs add previously failed tests to the front
|
|
|
|
// of the cost list and queue other tests for further sorting
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestMap::const_iterator i = this->Tests.begin(); i != this->Tests.end();
|
|
|
|
++i) {
|
|
|
|
if (std::find(this->LastTestsFailed.begin(), this->LastTestsFailed.end(),
|
|
|
|
this->Properties[i->first]->Name) !=
|
|
|
|
this->LastTestsFailed.end()) {
|
|
|
|
// If the test failed last time, it should be run first.
|
2013-10-19 06:52:28 +00:00
|
|
|
this->SortedTests.push_back(i->first);
|
2013-10-31 21:10:56 +00:00
|
|
|
alreadySortedTests.insert(i->first);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2013-10-19 06:52:28 +00:00
|
|
|
topLevel.insert(i->first);
|
2013-10-18 22:38:35 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-10-18 22:38:35 +00:00
|
|
|
|
2013-12-20 21:44:37 +00:00
|
|
|
// In parallel test runs repeatedly move dependencies of the tests on
|
|
|
|
// the current dependency level to the next level until no
|
|
|
|
// further dependencies exist.
|
2016-05-16 14:34:04 +00:00
|
|
|
while (priorityStack.back().size()) {
|
|
|
|
TestSet& previousSet = priorityStack.back();
|
2013-10-18 22:38:35 +00:00
|
|
|
priorityStack.push_back(TestSet());
|
2016-05-16 14:34:04 +00:00
|
|
|
TestSet& currentSet = priorityStack.back();
|
2013-10-18 22:38:35 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestSet::const_iterator i = previousSet.begin();
|
|
|
|
i != previousSet.end(); ++i) {
|
2013-10-18 22:38:35 +00:00
|
|
|
TestSet const& dependencies = this->Tests[*i];
|
2014-11-25 15:33:00 +00:00
|
|
|
currentSet.insert(dependencies.begin(), dependencies.end());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-10-18 22:38:35 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestSet::const_iterator i = currentSet.begin(); i != currentSet.end();
|
|
|
|
++i) {
|
2013-10-18 22:38:35 +00:00
|
|
|
previousSet.erase(*i);
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-10-18 22:38:35 +00:00
|
|
|
|
2013-10-21 17:55:14 +00:00
|
|
|
// Remove the empty dependency level
|
2013-10-18 22:38:35 +00:00
|
|
|
priorityStack.pop_back();
|
|
|
|
|
2013-10-21 17:55:14 +00:00
|
|
|
// Reverse iterate over the different dependency levels (deepest first).
|
|
|
|
// Sort tests within each level by COST and append them to the cost list.
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::list<TestSet>::reverse_iterator i = priorityStack.rbegin();
|
|
|
|
i != priorityStack.rend(); ++i) {
|
2013-10-23 19:47:32 +00:00
|
|
|
TestSet const& currentSet = *i;
|
2013-10-18 22:38:35 +00:00
|
|
|
TestComparator comp(this);
|
|
|
|
|
|
|
|
TestList sortedCopy;
|
2013-10-23 19:47:32 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
sortedCopy.insert(sortedCopy.end(), currentSet.begin(), currentSet.end());
|
2013-10-23 19:47:32 +00:00
|
|
|
|
2013-10-18 22:38:35 +00:00
|
|
|
std::stable_sort(sortedCopy.begin(), sortedCopy.end(), comp);
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestList::const_iterator j = sortedCopy.begin();
|
|
|
|
j != sortedCopy.end(); ++j) {
|
|
|
|
if (alreadySortedTests.find(*j) == alreadySortedTests.end()) {
|
2013-10-31 21:10:56 +00:00
|
|
|
this->SortedTests.push_back(*j);
|
|
|
|
alreadySortedTests.insert(*j);
|
2013-10-23 19:47:32 +00:00
|
|
|
}
|
2013-10-18 22:38:35 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-08 21:10:35 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void cmCTestMultiProcessHandler::GetAllTestDependencies(int test,
|
|
|
|
TestList& dependencies)
|
2013-12-20 21:44:37 +00:00
|
|
|
{
|
|
|
|
TestSet const& dependencySet = this->Tests[test];
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestSet::const_iterator i = dependencySet.begin();
|
|
|
|
i != dependencySet.end(); ++i) {
|
2013-12-20 21:44:37 +00:00
|
|
|
GetAllTestDependencies(*i, dependencies);
|
|
|
|
dependencies.push_back(*i);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-12-20 21:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestMultiProcessHandler::CreateSerialTestCostList()
|
|
|
|
{
|
|
|
|
TestList presortedList;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestMap::iterator i = this->Tests.begin(); i != this->Tests.end();
|
|
|
|
++i) {
|
2013-12-20 21:44:37 +00:00
|
|
|
presortedList.push_back(i->first);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2013-12-20 21:44:37 +00:00
|
|
|
|
|
|
|
TestComparator comp(this);
|
|
|
|
std::stable_sort(presortedList.begin(), presortedList.end(), comp);
|
|
|
|
|
|
|
|
TestSet alreadySortedTests;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestList::const_iterator i = presortedList.begin();
|
|
|
|
i != presortedList.end(); ++i) {
|
|
|
|
int test = *i;
|
2013-12-20 21:44:37 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (alreadySortedTests.find(test) != alreadySortedTests.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-20 21:44:37 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
TestList dependencies;
|
|
|
|
GetAllTestDependencies(test, dependencies);
|
2013-12-20 21:44:37 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (TestList::const_iterator j = dependencies.begin();
|
|
|
|
j != dependencies.end(); ++j) {
|
|
|
|
int testDependency = *j;
|
2013-12-20 21:44:37 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (alreadySortedTests.find(testDependency) ==
|
|
|
|
alreadySortedTests.end()) {
|
|
|
|
alreadySortedTests.insert(testDependency);
|
|
|
|
this->SortedTests.push_back(testDependency);
|
|
|
|
}
|
2013-12-20 21:44:37 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
|
|
|
|
alreadySortedTests.insert(test);
|
|
|
|
this->SortedTests.push_back(test);
|
|
|
|
}
|
2013-12-20 21:44:37 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 14:37:30 +00:00
|
|
|
void cmCTestMultiProcessHandler::WriteCheckpoint(int index)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string fname =
|
|
|
|
this->CTest->GetBinaryDir() + "/Testing/Temporary/CTestCheckpoint.txt";
|
2014-10-04 20:19:13 +00:00
|
|
|
cmsys::ofstream fout;
|
|
|
|
fout.open(fname.c_str(), std::ios::app);
|
2009-08-27 14:37:30 +00:00
|
|
|
fout << index << "\n";
|
|
|
|
fout.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestMultiProcessHandler::MarkFinished()
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string fname =
|
|
|
|
this->CTest->GetBinaryDir() + "/Testing/Temporary/CTestCheckpoint.txt";
|
2014-10-15 12:54:05 +00:00
|
|
|
cmSystemTools::RemoveFile(fname);
|
2009-08-27 14:37:30 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
// For ShowOnly mode
|
2009-08-28 15:08:39 +00:00
|
|
|
void cmCTestMultiProcessHandler::PrintTestList()
|
2008-07-03 13:31:33 +00:00
|
|
|
{
|
2009-09-25 15:45:19 +00:00
|
|
|
this->TestHandler->SetMaxIndex(this->FindMaxIndex());
|
2009-08-28 15:08:39 +00:00
|
|
|
int count = 0;
|
2010-08-31 14:41:23 +00:00
|
|
|
|
2009-08-28 15:08:39 +00:00
|
|
|
for (PropertiesMap::iterator it = this->Properties.begin();
|
2016-05-16 14:34:04 +00:00
|
|
|
it != this->Properties.end(); ++it) {
|
2009-08-28 15:08:39 +00:00
|
|
|
count++;
|
|
|
|
cmCTestTestHandler::cmCTestTestProperties& p = *it->second;
|
2010-08-31 14:41:23 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
// push working dir
|
2009-10-27 14:16:01 +00:00
|
|
|
std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
|
2014-10-15 12:54:05 +00:00
|
|
|
cmSystemTools::ChangeDirectory(p.Directory);
|
2009-08-28 15:08:39 +00:00
|
|
|
|
2009-09-11 14:09:48 +00:00
|
|
|
cmCTestRunTest testRun(this->TestHandler);
|
2009-08-28 15:08:39 +00:00
|
|
|
testRun.SetIndex(p.Index);
|
|
|
|
testRun.SetTestProperties(&p);
|
2016-05-16 14:34:04 +00:00
|
|
|
testRun.ComputeArguments(); // logs the command in verbose mode
|
2009-08-28 15:08:39 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!p.Labels.empty()) // print the labels
|
|
|
|
{
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Labels:",
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
|
|
|
}
|
|
|
|
for (std::vector<std::string>::iterator label = p.Labels.begin();
|
|
|
|
label != p.Labels.end(); ++label) {
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " " << *label,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
|
|
|
}
|
|
|
|
if (!p.Labels.empty()) // print the labels
|
|
|
|
{
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl,
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
|
|
|
}
|
2010-08-31 14:41:23 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->TestHandler->MemCheck) {
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Memory Check",
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Quiet);
|
|
|
|
} else {
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Test", this->Quiet);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream indexStr;
|
2009-09-24 13:49:46 +00:00
|
|
|
indexStr << " #" << p.Index << ":";
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(
|
|
|
|
this->CTest, HANDLER_OUTPUT,
|
2009-09-24 13:49:46 +00:00
|
|
|
std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
|
2016-05-16 14:34:04 +00:00
|
|
|
<< indexStr.str(),
|
|
|
|
this->Quiet);
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet);
|
2016-06-06 21:53:32 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, p.Name << std::endl,
|
|
|
|
this->Quiet);
|
2016-05-16 14:34:04 +00:00
|
|
|
// pop working dir
|
2014-10-15 12:54:05 +00:00
|
|
|
cmSystemTools::ChangeDirectory(current_dir);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-08-31 14:41:23 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, std::endl
|
|
|
|
<< "Total Tests: " << this->Total << std::endl,
|
|
|
|
this->Quiet);
|
2008-07-03 13:31:33 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 14:41:23 +00:00
|
|
|
void cmCTestMultiProcessHandler::PrintLabels()
|
|
|
|
{
|
|
|
|
std::set<std::string> allLabels;
|
|
|
|
for (PropertiesMap::iterator it = this->Properties.begin();
|
2016-05-16 14:34:04 +00:00
|
|
|
it != this->Properties.end(); ++it) {
|
2010-08-31 14:41:23 +00:00
|
|
|
cmCTestTestHandler::cmCTestTestProperties& p = *it->second;
|
|
|
|
allLabels.insert(p.Labels.begin(), p.Labels.end());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-08-31 14:41:23 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!allLabels.empty()) {
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "All Labels:" << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
} else {
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"No Labels Exist" << std::endl, this->Quiet);
|
|
|
|
}
|
|
|
|
for (std::set<std::string>::iterator label = allLabels.begin();
|
|
|
|
label != allLabels.end(); ++label) {
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
" " << *label << std::endl, this->Quiet);
|
|
|
|
}
|
2010-08-31 14:41:23 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 14:37:30 +00:00
|
|
|
void cmCTestMultiProcessHandler::CheckResume()
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
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
|
2009-08-27 14:37:30 +00:00
|
|
|
<< "----------------------------------------------------------"
|
|
|
|
<< std::endl;
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2014-01-04 05:47:13 +00:00
|
|
|
cmsys::ifstream fin;
|
2009-08-27 14:37:30 +00:00
|
|
|
fin.open(fname.c_str());
|
|
|
|
std::string line;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (std::getline(fin, line)) {
|
2009-08-27 14:37:30 +00:00
|
|
|
int index = atoi(line.c_str());
|
|
|
|
this->RemoveTest(index);
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
fin.close();
|
2009-08-27 14:37:30 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (cmSystemTools::FileExists(fname.c_str(), true)) {
|
2014-10-15 12:54:05 +00:00
|
|
|
cmSystemTools::RemoveFile(fname);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-27 14:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestMultiProcessHandler::RemoveTest(int index)
|
|
|
|
{
|
2009-09-08 17:39:13 +00:00
|
|
|
this->EraseTest(index);
|
2009-08-27 14:37:30 +00:00
|
|
|
this->Properties.erase(index);
|
|
|
|
this->TestRunningMap[index] = false;
|
|
|
|
this->TestFinishMap[index] = true;
|
2009-08-28 15:08:39 +00:00
|
|
|
this->Completed++;
|
2009-08-27 14:37:30 +00:00
|
|
|
}
|
2009-09-02 14:08:40 +00:00
|
|
|
|
|
|
|
int cmCTestMultiProcessHandler::FindMaxIndex()
|
|
|
|
{
|
|
|
|
int max = 0;
|
|
|
|
cmCTestMultiProcessHandler::TestMap::iterator i = this->Tests.begin();
|
2016-05-16 14:34:04 +00:00
|
|
|
for (; i != this->Tests.end(); ++i) {
|
|
|
|
if (i->first > max) {
|
2009-09-02 14:08:40 +00:00
|
|
|
max = i->first;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-02 14:08:40 +00:00
|
|
|
return max;
|
|
|
|
}
|
2009-11-02 17:52:50 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
// Returns true if no cycles exist in the dependency graph
|
2009-11-02 17:52:50 +00:00
|
|
|
bool cmCTestMultiProcessHandler::CheckCycles()
|
|
|
|
{
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Checking test dependency graph..." << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
for (TestMap::iterator it = this->Tests.begin(); it != this->Tests.end();
|
|
|
|
++it) {
|
|
|
|
// DFS from each element to itself
|
2010-12-15 21:49:34 +00:00
|
|
|
int root = it->first;
|
|
|
|
std::set<int> visited;
|
2009-11-02 17:52:50 +00:00
|
|
|
std::stack<int> s;
|
2010-12-15 21:49:34 +00:00
|
|
|
s.push(root);
|
2016-05-16 14:34:04 +00:00
|
|
|
while (!s.empty()) {
|
2009-11-02 17:52:50 +00:00
|
|
|
int test = s.top();
|
|
|
|
s.pop();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (visited.insert(test).second) {
|
|
|
|
for (TestSet::iterator d = this->Tests[test].begin();
|
|
|
|
d != this->Tests[test].end(); ++d) {
|
|
|
|
if (*d == root) {
|
|
|
|
// cycle exists
|
|
|
|
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-15 21:49:34 +00:00
|
|
|
return false;
|
2009-11-02 17:52:50 +00:00
|
|
|
}
|
2016-08-18 18:04:21 +00:00
|
|
|
s.push(*d);
|
2009-11-02 17:52:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-02-17 19:23:56 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Checking test dependency graph end" << std::endl,
|
|
|
|
this->Quiet);
|
2009-11-02 17:52:50 +00:00
|
|
|
return true;
|
|
|
|
}
|