cmake/Source/CTest/cmCTestMultiProcessHandler.h

155 lines
4.0 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2009-10-04 10:30:41 +03:00
#ifndef cmCTestMultiProcessHandler_h
#define cmCTestMultiProcessHandler_h
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
2017-07-20 19:35:53 +02:00
#include "cmCTestTestHandler.h"
2016-10-30 18:24:19 +01:00
#include <map>
#include <set>
#include <stddef.h>
#include <string>
#include <vector>
2016-07-09 11:21:54 +02:00
2018-10-07 12:27:06 +02:00
#include "cmUVHandlePtr.h"
2018-04-23 21:13:27 +02:00
#include "cm_uv.h"
2016-10-30 18:24:19 +01:00
class cmCTest;
class cmCTestRunTest;
2009-10-04 10:30:41 +03:00
/** \class cmCTestMultiProcessHandler
* \brief run parallel ctest
*
2013-03-16 19:13:01 +02:00
* cmCTestMultiProcessHandler
2009-10-04 10:30:41 +03:00
*/
2013-03-16 19:13:01 +02:00
class cmCTestMultiProcessHandler
2009-10-04 10:30:41 +03:00
{
2010-11-13 01:00:53 +02:00
friend class TestComparator;
2018-04-23 21:13:27 +02:00
friend class cmCTestRunTest;
2016-07-09 11:21:54 +02:00
2009-10-04 10:30:41 +03:00
public:
2016-07-09 11:21:54 +02:00
struct TestSet : public std::set<int>
{
};
struct TestMap : public std::map<int, TestSet>
{
};
struct TestList : public std::vector<int>
{
};
struct PropertiesMap
: public std::map<int, cmCTestTestHandler::cmCTestTestProperties*>
{
};
2009-10-04 10:30:41 +03:00
cmCTestMultiProcessHandler();
virtual ~cmCTestMultiProcessHandler();
// Set the tests
void SetTests(TestMap& tests, PropertiesMap& properties);
// Set the max number of tests that can be run at the same time.
void SetParallelLevel(size_t);
2015-11-17 17:22:37 +01:00
void SetTestLoad(unsigned long load);
2009-10-04 10:30:41 +03:00
virtual void RunTests();
void PrintTestList();
2010-11-13 01:00:53 +02:00
void PrintLabels();
2009-10-04 10:30:41 +03:00
2015-04-27 22:25:09 +02:00
void SetPassFailVectors(std::vector<std::string>* passed,
std::vector<std::string>* failed)
2016-07-09 11:21:54 +02:00
{
2009-10-04 10:30:41 +03:00
this->Passed = passed;
this->Failed = failed;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
void SetTestResults(std::vector<cmCTestTestHandler::cmCTestTestResult>* r)
2016-07-09 11:21:54 +02:00
{
this->TestResults = r;
}
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
void SetCTest(cmCTest* ctest) { this->CTest = ctest; }
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
void SetTestHandler(cmCTestTestHandler* handler)
{
this->TestHandler = handler;
}
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
cmCTestTestHandler* GetTestHandler() { return this->TestHandler; }
2015-08-17 11:37:30 +02:00
void SetQuiet(bool b) { this->Quiet = b; }
2018-08-09 18:06:22 +02:00
2010-06-23 01:18:35 +03:00
protected:
2009-10-04 10:30:41 +03:00
// Start the next test or tests as many as are allowed by
// ParallelLevel
void StartNextTests();
2018-04-23 21:13:27 +02:00
bool StartTestProcess(int test);
2009-10-04 10:30:41 +03:00
bool StartTest(int test);
// Mark the checkpoint for the given test
void WriteCheckpoint(int index);
2010-06-23 01:18:35 +03:00
void UpdateCostData();
2009-10-04 10:30:41 +03:00
void ReadCostData();
2010-06-23 01:18:35 +03:00
// Return index of a test based on its name
2016-07-09 11:21:54 +02:00
int SearchByName(std::string const& name);
2010-06-23 01:18:35 +03:00
2009-10-04 10:30:41 +03:00
void CreateTestCostList();
2014-08-03 19:52:23 +02:00
void GetAllTestDependencies(int test, TestList& dependencies);
void CreateSerialTestCostList();
void CreateParallelTestCostList();
2009-10-04 10:30:41 +03:00
// Removes the checkpoint file
void MarkFinished();
void EraseTest(int index);
2018-04-23 21:13:27 +02:00
void FinishTestProcess(cmCTestRunTest* runner, bool started);
2018-10-07 12:27:06 +02:00
static void OnTestLoadRetryCB(uv_timer_t* timer);
2009-10-04 10:30:41 +03:00
void RemoveTest(int index);
2016-07-09 11:21:54 +02:00
// Check if we need to resume an interrupted test set
2009-10-04 10:30:41 +03:00
void CheckResume();
2016-07-09 11:21:54 +02:00
// Check if there are any circular dependencies
2009-11-06 22:07:41 +02:00
bool CheckCycles();
2009-10-04 10:30:41 +03:00
int FindMaxIndex();
inline size_t GetProcessorsUsed(int index);
2015-11-17 17:22:37 +01:00
std::string GetName(int index);
2010-06-23 01:18:35 +03:00
2018-10-28 12:09:07 +01:00
bool CheckStopTimePassed();
void SetStopTimePassed();
2010-06-23 01:18:35 +03:00
void LockResources(int index);
void UnlockResources(int index);
2009-10-04 10:30:41 +03:00
// map from test number to set of depend tests
TestMap Tests;
2010-11-13 01:00:53 +02:00
TestList SortedTests;
2016-07-09 11:21:54 +02:00
// Total number of tests we'll be running
2009-10-04 10:30:41 +03:00
size_t Total;
2016-07-09 11:21:54 +02:00
// Number of tests that are complete
2009-10-04 10:30:41 +03:00
size_t Completed;
size_t RunningCount;
2018-08-09 18:06:22 +02:00
std::set<size_t> ProcessorsAvailable;
size_t HaveAffinity;
2018-10-28 12:09:07 +01:00
bool StopTimePassed = false;
2016-07-09 11:21:54 +02:00
// list of test properties (indices concurrent to the test map)
2009-10-04 10:30:41 +03:00
PropertiesMap Properties;
std::map<int, bool> TestRunningMap;
std::map<int, bool> TestFinishMap;
2015-04-27 22:25:09 +02:00
std::map<int, std::string> TestOutput;
std::vector<std::string>* Passed;
std::vector<std::string>* Failed;
2010-06-23 01:18:35 +03:00
std::vector<std::string> LastTestsFailed;
std::set<std::string> LockedResources;
2009-10-04 10:30:41 +03:00
std::vector<cmCTestTestHandler::cmCTestTestResult>* TestResults;
size_t ParallelLevel; // max number of process that can be run at once
2015-11-17 17:22:37 +01:00
unsigned long TestLoad;
2018-10-07 12:27:06 +02:00
unsigned long FakeLoadForTesting;
2018-04-23 21:13:27 +02:00
uv_loop_t Loop;
2018-10-07 12:27:06 +02:00
cm::uv_timer_ptr TestLoadRetryTimer;
2016-07-09 11:21:54 +02:00
cmCTestTestHandler* TestHandler;
2010-06-23 01:18:35 +03:00
cmCTest* CTest;
2014-08-03 19:52:23 +02:00
bool HasCycles;
2015-08-17 11:37:30 +02:00
bool Quiet;
2015-11-17 17:22:37 +01:00
bool SerialTestRunning;
2009-10-04 10:30:41 +03:00
};
#endif