mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-05 07:10:26 +00:00
CTest: Simplify std::chrono::duration<double> conversion to double
The ratio of ticks to seconds for this type is 1, so we can just use its `count()` directly. This also avoids converting through the integer representation of `std::chrono::milliseconds`, which has a much smaller allowed range. Drop our `cmsysProcess_SetTimeout` wrapper as it is now very thin.
This commit is contained in:
@@ -11,7 +11,6 @@
|
|||||||
#include "cmParseGTMCoverage.h"
|
#include "cmParseGTMCoverage.h"
|
||||||
#include "cmParseJacocoCoverage.h"
|
#include "cmParseJacocoCoverage.h"
|
||||||
#include "cmParsePHPCoverage.h"
|
#include "cmParsePHPCoverage.h"
|
||||||
#include "cmProcess.h"
|
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmWorkingDirectory.h"
|
#include "cmWorkingDirectory.h"
|
||||||
#include "cmXMLWriter.h"
|
#include "cmXMLWriter.h"
|
||||||
@@ -81,7 +80,7 @@ public:
|
|||||||
|
|
||||||
cmsysProcess_SetOption(this->Process, cmsysProcess_Option_HideWindow, 1);
|
cmsysProcess_SetOption(this->Process, cmsysProcess_Option_HideWindow, 1);
|
||||||
if (this->TimeOut >= std::chrono::duration<double>::zero()) {
|
if (this->TimeOut >= std::chrono::duration<double>::zero()) {
|
||||||
cmsysProcess_SetTimeout(this->Process, this->TimeOut);
|
cmsysProcess_SetTimeout(this->Process, this->TimeOut.count());
|
||||||
}
|
}
|
||||||
cmsysProcess_Execute(this->Process);
|
cmsysProcess_Execute(this->Process);
|
||||||
this->PipeState = cmsysProcess_GetState(this->Process);
|
this->PipeState = cmsysProcess_GetState(this->Process);
|
||||||
|
|||||||
@@ -265,11 +265,7 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
|
|||||||
|
|
||||||
passed = this->TestResult.Status == cmCTestTestHandler::COMPLETED;
|
passed = this->TestResult.Status == cmCTestTestHandler::COMPLETED;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
sprintf(buf, "%6.2f sec",
|
sprintf(buf, "%6.2f sec", this->TestProcess->GetTotalTime().count());
|
||||||
double(std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
||||||
this->TestProcess->GetTotalTime())
|
|
||||||
.count()) /
|
|
||||||
1000.0);
|
|
||||||
cmCTestLog(this->CTest, HANDLER_OUTPUT, buf << "\n");
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, buf << "\n");
|
||||||
|
|
||||||
if (outputTestErrorsToConsole) {
|
if (outputTestErrorsToConsole) {
|
||||||
@@ -394,11 +390,7 @@ void cmCTestRunTest::ComputeWeightedCost()
|
|||||||
{
|
{
|
||||||
double prev = static_cast<double>(this->TestProperties->PreviousRuns);
|
double prev = static_cast<double>(this->TestProperties->PreviousRuns);
|
||||||
double avgcost = static_cast<double>(this->TestProperties->Cost);
|
double avgcost = static_cast<double>(this->TestProperties->Cost);
|
||||||
double current =
|
double current = this->TestResult.ExecutionTime.count();
|
||||||
double(std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
||||||
this->TestResult.ExecutionTime)
|
|
||||||
.count()) /
|
|
||||||
1000.0;
|
|
||||||
|
|
||||||
if (this->TestResult.Status == cmCTestTestHandler::COMPLETED) {
|
if (this->TestResult.Status == cmCTestTestHandler::COMPLETED) {
|
||||||
this->TestProperties->Cost =
|
this->TestProperties->Cost =
|
||||||
|
|||||||
@@ -540,10 +540,8 @@ int cmCTestTestHandler::ProcessHandler()
|
|||||||
this->PrintLabelOrSubprojectSummary(false);
|
this->PrintLabelOrSubprojectSummary(false);
|
||||||
}
|
}
|
||||||
char realBuf[1024];
|
char realBuf[1024];
|
||||||
auto durationInMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
std::chrono::duration<double> durationInSecs = clock_finish - clock_start;
|
||||||
clock_finish - clock_start)
|
sprintf(realBuf, "%6.2f sec", durationInSecs.count());
|
||||||
.count();
|
|
||||||
sprintf(realBuf, "%6.2f sec", static_cast<double>(durationInMs) / 1000.0);
|
|
||||||
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
||||||
"\nTotal Test time (real) = " << realBuf << "\n",
|
"\nTotal Test time (real) = " << realBuf << "\n",
|
||||||
this->Quiet);
|
this->Quiet);
|
||||||
@@ -654,10 +652,7 @@ void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject)
|
|||||||
// only use labels found in labels
|
// only use labels found in labels
|
||||||
if (labels.find(l) != labels.end()) {
|
if (labels.find(l) != labels.end()) {
|
||||||
labelTimes[l] +=
|
labelTimes[l] +=
|
||||||
double(std::chrono::duration_cast<std::chrono::milliseconds>(
|
result.ExecutionTime.count() * result.Properties->Processors;
|
||||||
result.ExecutionTime)
|
|
||||||
.count()) /
|
|
||||||
1000.0 * result.Properties->Processors;
|
|
||||||
++labelCounts[l];
|
++labelCounts[l];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1327,11 +1322,7 @@ void cmCTestTestHandler::GenerateDartOutput(cmXMLWriter& xml)
|
|||||||
xml.StartElement("NamedMeasurement");
|
xml.StartElement("NamedMeasurement");
|
||||||
xml.Attribute("type", "numeric/double");
|
xml.Attribute("type", "numeric/double");
|
||||||
xml.Attribute("name", "Execution Time");
|
xml.Attribute("name", "Execution Time");
|
||||||
xml.Element("Value",
|
xml.Element("Value", result.ExecutionTime.count());
|
||||||
double(std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
||||||
result.ExecutionTime)
|
|
||||||
.count()) /
|
|
||||||
1000.0);
|
|
||||||
xml.EndElement(); // NamedMeasurement
|
xml.EndElement(); // NamedMeasurement
|
||||||
if (!result.Reason.empty()) {
|
if (!result.Reason.empty()) {
|
||||||
const char* reasonType = "Pass Reason";
|
const char* reasonType = "Pass Reason";
|
||||||
|
|||||||
@@ -5,16 +5,6 @@
|
|||||||
#include "cmProcessOutput.h"
|
#include "cmProcessOutput.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void cmsysProcess_SetTimeout(cmsysProcess* process,
|
|
||||||
std::chrono::duration<double> timeout)
|
|
||||||
{
|
|
||||||
cmsysProcess_SetTimeout(
|
|
||||||
process,
|
|
||||||
double(
|
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count()) /
|
|
||||||
1000.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
cmProcess::cmProcess()
|
cmProcess::cmProcess()
|
||||||
{
|
{
|
||||||
this->Process = nullptr;
|
this->Process = nullptr;
|
||||||
@@ -59,7 +49,7 @@ bool cmProcess::StartProcess()
|
|||||||
cmsysProcess_SetWorkingDirectory(this->Process,
|
cmsysProcess_SetWorkingDirectory(this->Process,
|
||||||
this->WorkingDirectory.c_str());
|
this->WorkingDirectory.c_str());
|
||||||
}
|
}
|
||||||
cmsysProcess_SetTimeout(this->Process, this->Timeout);
|
cmsysProcess_SetTimeout(this->Process, this->Timeout.count());
|
||||||
cmsysProcess_SetOption(this->Process, cmsysProcess_Option_MergeOutput, 1);
|
cmsysProcess_SetOption(this->Process, cmsysProcess_Option_MergeOutput, 1);
|
||||||
cmsysProcess_Execute(this->Process);
|
cmsysProcess_Execute(this->Process);
|
||||||
return (cmsysProcess_GetState(this->Process) ==
|
return (cmsysProcess_GetState(this->Process) ==
|
||||||
@@ -115,10 +105,7 @@ int cmProcess::GetNextOutputLine(std::string& line,
|
|||||||
{
|
{
|
||||||
cmProcessOutput processOutput(cmProcessOutput::UTF8);
|
cmProcessOutput processOutput(cmProcessOutput::UTF8);
|
||||||
std::string strdata;
|
std::string strdata;
|
||||||
double waitTimeout =
|
double waitTimeout = timeout.count();
|
||||||
double(
|
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count()) /
|
|
||||||
1000.0;
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Look for lines already buffered.
|
// Look for lines already buffered.
|
||||||
if (this->Output.GetLine(line)) {
|
if (this->Output.GetLine(line)) {
|
||||||
@@ -240,7 +227,7 @@ int cmProcess::ReportStatus()
|
|||||||
void cmProcess::ChangeTimeout(std::chrono::duration<double> t)
|
void cmProcess::ChangeTimeout(std::chrono::duration<double> t)
|
||||||
{
|
{
|
||||||
this->Timeout = t;
|
this->Timeout = t;
|
||||||
cmsysProcess_SetTimeout(this->Process, this->Timeout);
|
cmsysProcess_SetTimeout(this->Process, this->Timeout.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmProcess::ResetStartTime()
|
void cmProcess::ResetStartTime()
|
||||||
|
|||||||
@@ -10,13 +10,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/*
|
|
||||||
* A wrapper function for cmsysProcess_SetTimeout that takes an
|
|
||||||
* std::chrono::duration. For convenience only.
|
|
||||||
*/
|
|
||||||
void cmsysProcess_SetTimeout(cmsysProcess* process,
|
|
||||||
std::chrono::duration<double> timeout);
|
|
||||||
|
|
||||||
/** \class cmProcess
|
/** \class cmProcess
|
||||||
* \brief run a process with c++
|
* \brief run a process with c++
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -50,7 +50,6 @@
|
|||||||
#include "cmGeneratedFileStream.h"
|
#include "cmGeneratedFileStream.h"
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmProcess.h"
|
|
||||||
#include "cmProcessOutput.h"
|
#include "cmProcessOutput.h"
|
||||||
#include "cmState.h"
|
#include "cmState.h"
|
||||||
#include "cmStateSnapshot.h"
|
#include "cmStateSnapshot.h"
|
||||||
@@ -998,7 +997,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output,
|
|||||||
cmsysProcess_SetCommand(cp, &*argv.begin());
|
cmsysProcess_SetCommand(cp, &*argv.begin());
|
||||||
cmsysProcess_SetWorkingDirectory(cp, dir);
|
cmsysProcess_SetWorkingDirectory(cp, dir);
|
||||||
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
|
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
|
||||||
cmsysProcess_SetTimeout(cp, timeout);
|
cmsysProcess_SetTimeout(cp, timeout.count());
|
||||||
cmsysProcess_Execute(cp);
|
cmsysProcess_Execute(cp);
|
||||||
|
|
||||||
// Initialize tick's
|
// Initialize tick's
|
||||||
@@ -1186,7 +1185,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output,
|
|||||||
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
|
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmsysProcess_SetTimeout(cp, timeout);
|
cmsysProcess_SetTimeout(cp, timeout.count());
|
||||||
cmsysProcess_Execute(cp);
|
cmsysProcess_Execute(cp);
|
||||||
|
|
||||||
char* data;
|
char* data;
|
||||||
@@ -2610,7 +2609,7 @@ bool cmCTest::RunCommand(std::vector<std::string> const& args,
|
|||||||
if (cmSystemTools::GetRunCommandHideConsole()) {
|
if (cmSystemTools::GetRunCommandHideConsole()) {
|
||||||
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
|
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
|
||||||
}
|
}
|
||||||
cmsysProcess_SetTimeout(cp, timeout);
|
cmsysProcess_SetTimeout(cp, timeout.count());
|
||||||
cmsysProcess_Execute(cp);
|
cmsysProcess_Execute(cp);
|
||||||
|
|
||||||
std::vector<char> tempOutput;
|
std::vector<char> tempOutput;
|
||||||
|
|||||||
Reference in New Issue
Block a user