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. */
|
2021-09-14 00:13:48 +02:00
|
|
|
#pragma once
|
2009-10-04 10:30:41 +03:00
|
|
|
|
2017-07-20 19:35:53 +02:00
|
|
|
#include "cmConfigure.h" // IWYU pragma: keep
|
2016-10-30 18:24:19 +01:00
|
|
|
|
2022-03-29 21:10:50 +02:00
|
|
|
#include <cstddef>
|
2020-02-01 23:06:01 +01:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2017-04-14 19:02:05 +02:00
|
|
|
#include <set>
|
2016-10-30 18:24:19 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2016-07-09 11:21:54 +02:00
|
|
|
|
2020-08-30 11:54:41 +02:00
|
|
|
#include "cmCTest.h"
|
2020-02-01 23:06:01 +01:00
|
|
|
#include "cmCTestMultiProcessHandler.h"
|
2017-04-14 19:02:05 +02:00
|
|
|
#include "cmCTestTestHandler.h"
|
2020-02-01 23:06:01 +01:00
|
|
|
#include "cmProcess.h"
|
2017-04-14 19:02:05 +02:00
|
|
|
|
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:
|
2024-04-14 22:45:38 +02:00
|
|
|
explicit cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler, int index);
|
2018-04-23 21:13:27 +02:00
|
|
|
|
2020-08-30 11:54:41 +02:00
|
|
|
void SetNumberOfRuns(int n)
|
|
|
|
{
|
|
|
|
this->NumberOfRunsLeft = n;
|
|
|
|
this->NumberOfRunsTotal = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetRepeatMode(cmCTest::Repeat r) { this->RepeatMode = r; }
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2024-04-14 22:45:38 +02:00
|
|
|
static void StartTest(std::unique_ptr<cmCTestRunTest> runner,
|
2020-08-30 11:54:41 +02:00
|
|
|
size_t completed, size_t total);
|
|
|
|
static bool StartAgain(std::unique_ptr<cmCTestRunTest> runner,
|
|
|
|
size_t completed);
|
|
|
|
|
|
|
|
static void StartFailure(std::unique_ptr<cmCTestRunTest> runner,
|
2023-12-07 09:12:54 +01:00
|
|
|
size_t total, std::string const& output,
|
2020-08-30 11:54:41 +02:00
|
|
|
std::string const& detail);
|
|
|
|
|
2023-07-02 19:51:09 +02:00
|
|
|
struct EndTestResult
|
|
|
|
{
|
|
|
|
bool Passed = false;
|
|
|
|
bool StopTimePassed = false;
|
|
|
|
};
|
|
|
|
|
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
|
2023-07-02 19:51:09 +02:00
|
|
|
EndTestResult 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
|
|
|
|
2023-12-07 09:12:54 +01:00
|
|
|
void StartFailure(size_t total, std::string const& output,
|
|
|
|
std::string const& detail);
|
2018-08-09 18:06:22 +02:00
|
|
|
|
2018-04-23 21:13:27 +02:00
|
|
|
cmCTest* GetCTest() const { return this->CTest; }
|
|
|
|
|
2019-11-11 23:01:05 +01:00
|
|
|
std::string& GetActualCommand() { return this->ActualCommand; }
|
|
|
|
|
|
|
|
const std::vector<std::string>& GetArguments() { return this->Arguments; }
|
|
|
|
|
2020-08-30 11:54:41 +02:00
|
|
|
void FinalizeTest(bool started = true);
|
2018-04-23 21:13:27 +02:00
|
|
|
|
2020-02-01 23:06:01 +01:00
|
|
|
void SetUseAllocatedResources(bool use)
|
|
|
|
{
|
|
|
|
this->UseAllocatedResources = use;
|
|
|
|
}
|
|
|
|
void SetAllocatedResources(
|
|
|
|
const std::vector<
|
|
|
|
std::map<std::string,
|
|
|
|
std::vector<cmCTestMultiProcessHandler::ResourceAllocation>>>&
|
|
|
|
resources)
|
|
|
|
{
|
|
|
|
this->AllocatedResources = resources;
|
|
|
|
}
|
|
|
|
|
2009-10-04 10:30:41 +03:00
|
|
|
private:
|
2020-08-30 11:54:41 +02:00
|
|
|
bool NeedsToRepeat();
|
2021-11-20 13:41:27 +01:00
|
|
|
void ParseOutputForMeasurements();
|
2010-03-17 14:00:29 +02:00
|
|
|
void ExeNotFound(std::string exe);
|
2023-07-02 19:51:09 +02:00
|
|
|
bool ForkProcess();
|
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();
|
|
|
|
|
2020-08-30 11:54:41 +02:00
|
|
|
void SetupResourcesEnvironment(std::vector<std::string>* log = nullptr);
|
2020-02-01 23:06:01 +01:00
|
|
|
|
2018-10-28 12:09:07 +01:00
|
|
|
// Returns "completed/total Test #Index: "
|
|
|
|
std::string GetTestPrefix(size_t completed, size_t total) const;
|
|
|
|
|
2024-04-14 22:45:38 +02:00
|
|
|
cmCTestMultiProcessHandler& MultiTestHandler;
|
|
|
|
int Index;
|
2016-07-09 11:21:54 +02:00
|
|
|
cmCTest* CTest;
|
2024-04-14 22:45:38 +02:00
|
|
|
cmCTestTestHandler* TestHandler;
|
|
|
|
cmCTestTestHandler::cmCTestTestProperties* TestProperties;
|
|
|
|
|
2018-04-23 21:13:27 +02:00
|
|
|
std::unique_ptr<cmProcess> TestProcess;
|
2009-10-04 10:30:41 +03:00
|
|
|
std::string ProcessOutput;
|
|
|
|
cmCTestTestHandler::cmCTestTestResult TestResult;
|
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;
|
2020-02-01 23:06:01 +01:00
|
|
|
bool UseAllocatedResources = false;
|
|
|
|
std::vector<std::map<
|
|
|
|
std::string, std::vector<cmCTestMultiProcessHandler::ResourceAllocation>>>
|
|
|
|
AllocatedResources;
|
2020-08-30 11:54:41 +02:00
|
|
|
cmCTest::Repeat RepeatMode = cmCTest::Repeat::Never;
|
|
|
|
int NumberOfRunsLeft = 1; // default to 1 run of the test
|
|
|
|
int NumberOfRunsTotal = 1; // default to 1 run of the test
|
|
|
|
bool RunAgain = false; // default to not having to run again
|
2015-08-17 11:37:30 +02:00
|
|
|
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
|
|
|
}
|