cmake/Source/CTest/cmCTestRunTest.h

126 lines
3.2 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
2009-10-11 10:55:36 +03:00
bool StartTest(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
bool StartAgain();
2016-07-09 11:21:54 +02:00
2018-04-23 21:13:27 +02:00
cmCTest* GetCTest() const { return this->CTest; }
void FinalizeTest();
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,
2011-01-16 11:35:12 +01:00
std::vector<std::string>* environment);
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();
2016-07-09 11:21:54 +02:00
cmCTestTestHandler::cmCTestTestProperties* TestProperties;
// 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)
{
int numWidth = 1;
2016-07-09 11:21:54 +02:00
if (n >= 10) {
2009-10-04 10:30:41 +03:00
numWidth = 2;
2016-07-09 11:21:54 +02:00
}
if (n >= 100) {
2009-10-04 10:30:41 +03:00
numWidth = 3;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
return numWidth;
}
2010-03-17 14:00:29 +02:00
2009-10-04 10:30:41 +03:00
#endif