cmake/Source/CTest/cmCTestRunTest.h

133 lines
3.5 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 cmCTestRunTest_h
#define cmCTestRunTest_h
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
2017-04-14 19:02:05 +02:00
#include <set>
2016-10-30 18:24:19 +01:00
#include <stddef.h>
#include <string>
#include <vector>
2016-07-09 11:21:54 +02:00
2017-04-14 19:02:05 +02:00
#include "cmCTestTestHandler.h"
2018-04-23 21:13:27 +02:00
#include "cmDuration.h"
#include "cmProcess.h" // IWYU pragma: keep (for unique_ptr)
2017-04-14 19:02:05 +02:00
2016-10-30 18:24:19 +01:00
class cmCTest;
2018-04-23 21:13:27 +02:00
class cmCTestMultiProcessHandler;
2009-10-04 10:30:41 +03:00
/** \class cmRunTest
* \brief represents a single test to be run
*
* cmRunTest contains the information related to running a single test
*/
class cmCTestRunTest
{
public:
2018-04-23 21:13:27 +02:00
explicit cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler);
~cmCTestRunTest() = default;
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
void SetNumberOfRuns(int n) { this->NumberOfRunsLeft = n; }
void SetRunUntilFailOn() { this->RunUntilFail = true; }
void SetTestProperties(cmCTestTestHandler::cmCTestTestProperties* prop)
{
this->TestProperties = prop;
}
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
cmCTestTestHandler::cmCTestTestProperties* GetTestProperties()
{
return this->TestProperties;
}
2009-10-04 10:30:41 +03:00
void SetIndex(int i) { this->Index = i; }
int GetIndex() { return this->Index; }
2016-10-30 18:24:19 +01:00
void AddFailedDependency(const std::string& failedTest)
{
this->FailedDependencies.insert(failedTest);
}
2009-10-04 10:30:41 +03:00
std::string GetProcessOutput() { return this->ProcessOutput; }
cmCTestTestHandler::cmCTestTestResult GetTestResults()
2016-07-09 11:21:54 +02:00
{
return this->TestResult;
}
2009-10-04 10:30:41 +03:00
// Read and store output. Returns true if it must be called again.
2018-04-23 21:13:27 +02:00
void CheckOutput(std::string const& line);
2009-10-04 10:30:41 +03:00
2010-03-17 14:00:29 +02:00
// Compresses the output, writing to CompressedOutput
void CompressOutput();
2016-07-09 11:21:54 +02:00
// launch the test process, return whether it started correctly
2018-10-28 12:09:07 +01:00
bool StartTest(size_t completed, size_t total);
2016-07-09 11:21:54 +02:00
// capture and report the test results
2009-10-04 10:30:41 +03:00
bool EndTest(size_t completed, size_t total, bool started);
2016-07-09 11:21:54 +02:00
// Called by ctest -N to log the command string
2009-10-04 10:30:41 +03:00
void ComputeArguments();
2010-06-23 01:18:35 +03:00
void ComputeWeightedCost();
2015-08-17 11:37:30 +02:00
2018-10-28 12:09:07 +01:00
bool StartAgain(size_t completed);
2016-07-09 11:21:54 +02:00
2018-08-09 18:06:22 +02:00
void StartFailure(std::string const& output);
2018-04-23 21:13:27 +02:00
cmCTest* GetCTest() const { return this->CTest; }
void FinalizeTest();
2018-10-28 12:09:07 +01:00
bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; }
2009-10-04 10:30:41 +03:00
private:
2015-08-17 11:37:30 +02:00
bool NeedsToRerun();
2009-10-04 10:30:41 +03:00
void DartProcessing();
2010-03-17 14:00:29 +02:00
void ExeNotFound(std::string exe);
2018-04-23 21:13:27 +02:00
bool ForkProcess(cmDuration testTimeOut, bool explicitTimeout,
2018-08-09 18:06:22 +02:00
std::vector<std::string>* environment,
std::vector<size_t>* affinity);
2009-10-04 10:30:41 +03:00
void WriteLogOutputTop(size_t completed, size_t total);
2016-07-09 11:21:54 +02:00
// Run post processing of the process output for MemCheck
2009-10-04 10:30:41 +03:00
void MemCheckPostProcess();
2018-10-28 12:09:07 +01:00
// Returns "completed/total Test #Index: "
std::string GetTestPrefix(size_t completed, size_t total) const;
2016-07-09 11:21:54 +02:00
cmCTestTestHandler::cmCTestTestProperties* TestProperties;
2018-10-28 12:09:07 +01:00
bool TimeoutIsForStopTime = false;
2016-07-09 11:21:54 +02:00
// Pointer back to the "parent"; the handler that invoked this test run
cmCTestTestHandler* TestHandler;
cmCTest* CTest;
2018-04-23 21:13:27 +02:00
std::unique_ptr<cmProcess> TestProcess;
2009-10-04 10:30:41 +03:00
std::string ProcessOutput;
2010-03-17 14:00:29 +02:00
std::string CompressedOutput;
double CompressionRatio;
2016-07-09 11:21:54 +02:00
// The test results
2009-10-04 10:30:41 +03:00
cmCTestTestHandler::cmCTestTestResult TestResult;
2018-04-23 21:13:27 +02:00
cmCTestMultiProcessHandler& MultiTestHandler;
2009-10-04 10:30:41 +03:00
int Index;
2016-10-30 18:24:19 +01:00
std::set<std::string> FailedDependencies;
2009-10-04 10:30:41 +03:00
std::string StartTime;
std::string ActualCommand;
std::vector<std::string> Arguments;
2015-08-17 11:37:30 +02:00
bool RunUntilFail;
int NumberOfRunsLeft;
bool RunAgain;
size_t TotalNumberOfTests;
2009-10-04 10:30:41 +03:00
};
inline int getNumWidth(size_t n)
{
2018-10-28 12:09:07 +01:00
int w = 1;
while (n >= 10) {
n /= 10;
++w;
2016-07-09 11:21:54 +02:00
}
2018-10-28 12:09:07 +01:00
return w;
2009-10-04 10:30:41 +03:00
}
2010-03-17 14:00:29 +02:00
2009-10-04 10:30:41 +03:00
#endif