2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2009-08-19 12:58:36 +00:00
|
|
|
#include "cmCTestRunTest.h"
|
2016-04-29 13:40:20 +00:00
|
|
|
|
2009-08-19 12:58:36 +00:00
|
|
|
#include "cmCTest.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmCTestMemCheckHandler.h"
|
2016-08-24 20:01:40 +00:00
|
|
|
#include "cmCTestTestHandler.h"
|
|
|
|
#include "cmProcess.h"
|
2009-08-19 12:58:36 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2016-08-24 20:01:40 +00:00
|
|
|
#include <cmConfigure.h>
|
|
|
|
#include <cm_curl.h>
|
2009-12-17 16:14:49 +00:00
|
|
|
#include <cm_zlib.h>
|
|
|
|
#include <cmsys/Base64.h>
|
2016-08-24 20:01:40 +00:00
|
|
|
#include <cmsys/Process.h>
|
|
|
|
#include <cmsys/RegularExpression.hxx>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <utility>
|
2009-12-17 16:14:49 +00:00
|
|
|
|
2009-09-11 14:09:48 +00:00
|
|
|
cmCTestRunTest::cmCTestRunTest(cmCTestTestHandler* handler)
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-09-11 14:09:48 +00:00
|
|
|
this->CTest = handler->CTest;
|
|
|
|
this->TestHandler = handler;
|
2016-06-27 20:44:16 +00:00
|
|
|
this->TestProcess = CM_NULLPTR;
|
2016-05-16 14:34:04 +00:00
|
|
|
this->TestResult.ExecutionTime = 0;
|
2009-09-16 15:49:09 +00:00
|
|
|
this->TestResult.ReturnValue = 0;
|
2009-12-18 16:42:58 +00:00
|
|
|
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
|
2009-09-16 15:49:09 +00:00
|
|
|
this->TestResult.TestCount = 0;
|
2016-06-27 20:44:16 +00:00
|
|
|
this->TestResult.Properties = CM_NULLPTR;
|
2009-12-17 16:14:49 +00:00
|
|
|
this->ProcessOutput = "";
|
|
|
|
this->CompressedOutput = "";
|
|
|
|
this->CompressionRatio = 2;
|
2010-06-15 14:29:35 +00:00
|
|
|
this->StopTimePassed = false;
|
2015-03-05 21:51:10 +00:00
|
|
|
this->NumberOfRunsLeft = 1; // default to 1 run of the test
|
|
|
|
this->RunUntilFail = false; // default to run the test once
|
2016-05-16 14:34:04 +00:00
|
|
|
this->RunAgain = false; // default to not having to run again
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmCTestRunTest::~cmCTestRunTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-11 16:26:41 +00:00
|
|
|
bool cmCTestRunTest::CheckOutput()
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-09-11 16:26:41 +00:00
|
|
|
// Read lines for up to 0.1 seconds of total time.
|
|
|
|
double timeout = 0.1;
|
|
|
|
double timeEnd = cmSystemTools::GetTime() + timeout;
|
|
|
|
std::string line;
|
2016-05-16 14:34:04 +00:00
|
|
|
while ((timeout = timeEnd - cmSystemTools::GetTime(), timeout > 0)) {
|
2009-09-11 16:26:41 +00:00
|
|
|
int p = this->TestProcess->GetNextOutputLine(line, timeout);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (p == cmsysProcess_Pipe_None) {
|
2009-09-11 16:26:41 +00:00
|
|
|
// Process has terminated and all output read.
|
|
|
|
return false;
|
2016-08-18 18:04:21 +00:00
|
|
|
}
|
|
|
|
if (p == cmsysProcess_Pipe_STDOUT) {
|
2009-09-11 16:26:41 +00:00
|
|
|
// Store this line of output.
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->GetIndex()
|
|
|
|
<< ": " << line << std::endl);
|
2009-09-11 16:26:41 +00:00
|
|
|
this->ProcessOutput += line;
|
|
|
|
this->ProcessOutput += "\n";
|
2016-02-18 18:59:18 +00:00
|
|
|
|
|
|
|
// Check for TIMEOUT_AFTER_MATCH property.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->TestProperties->TimeoutRegularExpressions.empty()) {
|
|
|
|
std::vector<
|
|
|
|
std::pair<cmsys::RegularExpression, std::string> >::iterator regIt;
|
|
|
|
for (regIt = this->TestProperties->TimeoutRegularExpressions.begin();
|
|
|
|
regIt != this->TestProperties->TimeoutRegularExpressions.end();
|
|
|
|
++regIt) {
|
|
|
|
if (regIt->first.find(this->ProcessOutput.c_str())) {
|
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->GetIndex()
|
|
|
|
<< ": "
|
|
|
|
<< "Test timeout changed to "
|
|
|
|
<< this->TestProperties->AlternateTimeout
|
|
|
|
<< std::endl);
|
2016-02-18 18:59:18 +00:00
|
|
|
this->TestProcess->ResetStartTime();
|
|
|
|
this->TestProcess->ChangeTimeout(
|
|
|
|
this->TestProperties->AlternateTimeout);
|
2016-03-23 16:09:41 +00:00
|
|
|
this->TestProperties->TimeoutRegularExpressions.clear();
|
2016-02-18 18:59:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-09-03 19:33:44 +00:00
|
|
|
}
|
2016-08-18 18:04:21 +00:00
|
|
|
} else { // if(p == cmsysProcess_Pipe_Timeout)
|
2009-09-03 19:33:44 +00:00
|
|
|
break;
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-11 16:26:41 +00:00
|
|
|
return true;
|
2009-08-26 16:09:06 +00:00
|
|
|
}
|
2009-08-19 12:58:36 +00:00
|
|
|
|
2009-12-17 16:14:49 +00:00
|
|
|
// Streamed compression of test output. The compressed data
|
|
|
|
// is appended to this->CompressedOutput
|
|
|
|
void cmCTestRunTest::CompressOutput()
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
z_stream strm;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
unsigned char* in = reinterpret_cast<unsigned char*>(
|
2009-12-17 16:14:49 +00:00
|
|
|
const_cast<char*>(this->ProcessOutput.c_str()));
|
2016-05-16 14:34:04 +00:00
|
|
|
// zlib makes the guarantee that this is the maximum output size
|
2010-06-27 15:22:05 +00:00
|
|
|
int outSize = static_cast<int>(
|
|
|
|
static_cast<double>(this->ProcessOutput.size()) * 1.001 + 13.0);
|
2009-12-17 16:14:49 +00:00
|
|
|
unsigned char* out = new unsigned char[outSize];
|
|
|
|
|
|
|
|
strm.zalloc = Z_NULL;
|
|
|
|
strm.zfree = Z_NULL;
|
|
|
|
strm.opaque = Z_NULL;
|
2016-05-16 14:34:04 +00:00
|
|
|
ret = deflateInit(&strm, -1); // default compression level
|
|
|
|
if (ret != Z_OK) {
|
2011-09-01 19:56:53 +00:00
|
|
|
delete[] out;
|
2009-12-17 16:14:49 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-12-17 16:14:49 +00:00
|
|
|
|
2009-12-21 14:52:56 +00:00
|
|
|
strm.avail_in = static_cast<uInt>(this->ProcessOutput.size());
|
2009-12-17 16:14:49 +00:00
|
|
|
strm.next_in = in;
|
|
|
|
strm.avail_out = outSize;
|
|
|
|
strm.next_out = out;
|
|
|
|
ret = deflate(&strm, Z_FINISH);
|
|
|
|
|
2016-12-10 15:55:49 +00:00
|
|
|
if (ret != Z_STREAM_END) {
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-12-10 15:55:49 +00:00
|
|
|
"Error during output compression. Sending uncompressed output."
|
2016-05-16 14:34:04 +00:00
|
|
|
<< std::endl);
|
2011-09-01 19:56:53 +00:00
|
|
|
delete[] out;
|
2009-12-17 16:14:49 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-12-17 16:14:49 +00:00
|
|
|
|
|
|
|
(void)deflateEnd(&strm);
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
unsigned char* encoded_buffer =
|
|
|
|
new unsigned char[static_cast<int>(outSize * 1.5)];
|
2009-12-17 16:14:49 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
size_t rlen = cmsysBase64_Encode(out, strm.total_out, encoded_buffer, 1);
|
2009-12-18 16:42:58 +00:00
|
|
|
|
2017-01-12 10:32:58 +00:00
|
|
|
this->CompressedOutput.clear();
|
2016-05-16 14:34:04 +00:00
|
|
|
for (size_t i = 0; i < rlen; i++) {
|
2009-12-17 16:14:49 +00:00
|
|
|
this->CompressedOutput += encoded_buffer[i];
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-12-17 16:14:49 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (strm.total_in) {
|
|
|
|
this->CompressionRatio =
|
|
|
|
static_cast<double>(strm.total_out) / static_cast<double>(strm.total_in);
|
|
|
|
}
|
2009-12-17 16:14:49 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
delete[] encoded_buffer;
|
|
|
|
delete[] out;
|
2009-12-17 16:14:49 +00:00
|
|
|
}
|
|
|
|
|
2009-09-03 19:33:44 +00:00
|
|
|
bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
|
2009-08-26 16:09:06 +00:00
|
|
|
{
|
2011-05-26 18:42:41 +00:00
|
|
|
if ((!this->TestHandler->MemCheck &&
|
2016-05-16 14:34:04 +00:00
|
|
|
this->CTest->ShouldCompressTestOutput()) ||
|
2011-05-26 18:42:41 +00:00
|
|
|
(this->TestHandler->MemCheck &&
|
2016-11-08 20:36:29 +00:00
|
|
|
this->CTest->ShouldCompressTestOutput())) {
|
2009-12-17 16:14:49 +00:00
|
|
|
this->CompressOutput();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-12-17 16:14:49 +00:00
|
|
|
|
2009-08-28 15:08:39 +00:00
|
|
|
this->WriteLogOutputTop(completed, total);
|
2009-08-19 12:58:36 +00:00
|
|
|
std::string reason;
|
|
|
|
bool passed = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
int res =
|
|
|
|
started ? this->TestProcess->GetProcessStatus() : cmsysProcess_State_Error;
|
2009-08-26 16:09:06 +00:00
|
|
|
int retVal = this->TestProcess->GetExitValue();
|
2016-05-16 14:34:04 +00:00
|
|
|
std::vector<std::pair<cmsys::RegularExpression, std::string> >::iterator
|
|
|
|
passIt;
|
2009-08-27 14:37:30 +00:00
|
|
|
bool forceFail = false;
|
2009-09-29 13:45:43 +00:00
|
|
|
bool outputTestErrorsToConsole = false;
|
2016-09-07 04:04:07 +00:00
|
|
|
if (!this->TestProperties->RequiredRegularExpressions.empty() &&
|
|
|
|
this->FailedDependencies.empty()) {
|
2009-08-27 14:37:30 +00:00
|
|
|
bool found = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (passIt = this->TestProperties->RequiredRegularExpressions.begin();
|
|
|
|
passIt != this->TestProperties->RequiredRegularExpressions.end();
|
|
|
|
++passIt) {
|
|
|
|
if (passIt->first.find(this->ProcessOutput.c_str())) {
|
2009-08-27 14:37:30 +00:00
|
|
|
found = true;
|
|
|
|
reason = "Required regular expression found.";
|
2013-05-11 10:14:37 +00:00
|
|
|
break;
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!found) {
|
2009-08-27 14:37:30 +00:00
|
|
|
reason = "Required regular expression not found.";
|
|
|
|
forceFail = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
reason += "Regex=[";
|
|
|
|
for (passIt = this->TestProperties->RequiredRegularExpressions.begin();
|
|
|
|
passIt != this->TestProperties->RequiredRegularExpressions.end();
|
|
|
|
++passIt) {
|
2009-08-27 14:37:30 +00:00
|
|
|
reason += passIt->second;
|
|
|
|
reason += "\n";
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
reason += "]";
|
|
|
|
}
|
2016-09-07 04:04:07 +00:00
|
|
|
if (!this->TestProperties->ErrorRegularExpressions.empty() &&
|
|
|
|
this->FailedDependencies.empty()) {
|
2016-05-16 14:34:04 +00:00
|
|
|
for (passIt = this->TestProperties->ErrorRegularExpressions.begin();
|
|
|
|
passIt != this->TestProperties->ErrorRegularExpressions.end();
|
|
|
|
++passIt) {
|
|
|
|
if (passIt->first.find(this->ProcessOutput.c_str())) {
|
2009-08-27 14:37:30 +00:00
|
|
|
reason = "Error regular expression found in output.";
|
|
|
|
reason += " Regex=[";
|
|
|
|
reason += passIt->second;
|
|
|
|
reason += "]";
|
|
|
|
forceFail = true;
|
2013-05-11 10:14:37 +00:00
|
|
|
break;
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
2009-08-27 14:37:30 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (res == cmsysProcess_State_Exited) {
|
|
|
|
bool success = !forceFail &&
|
2016-05-26 21:05:30 +00:00
|
|
|
(retVal == 0 ||
|
|
|
|
!this->TestProperties->RequiredRegularExpressions.empty());
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->TestProperties->SkipReturnCode >= 0 &&
|
|
|
|
this->TestProperties->SkipReturnCode == retVal) {
|
2012-09-21 15:37:08 +00:00
|
|
|
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Skipped ");
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if ((success && !this->TestProperties->WillFail) ||
|
|
|
|
(!success && this->TestProperties->WillFail)) {
|
2009-08-27 14:37:30 +00:00
|
|
|
this->TestResult.Status = cmCTestTestHandler::COMPLETED;
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Passed ");
|
|
|
|
} else {
|
2009-08-27 14:37:30 +00:00
|
|
|
this->TestResult.Status = cmCTestTestHandler::FAILED;
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Failed " << reason);
|
2009-09-29 13:45:43 +00:00
|
|
|
outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
|
2009-08-27 14:37:30 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (res == cmsysProcess_State_Expired) {
|
2009-11-30 21:09:00 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Timeout ");
|
2009-08-27 14:37:30 +00:00
|
|
|
this->TestResult.Status = cmCTestTestHandler::TIMEOUT;
|
2009-09-29 13:45:43 +00:00
|
|
|
outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (res == cmsysProcess_State_Exception) {
|
2009-09-29 13:45:43 +00:00
|
|
|
outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
|
2009-08-27 14:37:30 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: ");
|
2016-05-16 14:34:04 +00:00
|
|
|
switch (this->TestProcess->GetExitException()) {
|
2009-08-27 14:37:30 +00:00
|
|
|
case cmsysProcess_Exception_Fault:
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault");
|
|
|
|
this->TestResult.Status = cmCTestTestHandler::SEGFAULT;
|
|
|
|
break;
|
|
|
|
case cmsysProcess_Exception_Illegal:
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Illegal");
|
|
|
|
this->TestResult.Status = cmCTestTestHandler::ILLEGAL;
|
|
|
|
break;
|
|
|
|
case cmsysProcess_Exception_Interrupt:
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Interrupt");
|
|
|
|
this->TestResult.Status = cmCTestTestHandler::INTERRUPT;
|
|
|
|
break;
|
|
|
|
case cmsysProcess_Exception_Numerical:
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Numerical");
|
|
|
|
this->TestResult.Status = cmCTestTestHandler::NUMERICAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Other");
|
|
|
|
this->TestResult.Status = cmCTestTestHandler::OTHER_FAULT;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else // cmsysProcess_State_Error
|
|
|
|
{
|
2009-12-10 20:51:56 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Not Run ");
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-12-10 20:51:56 +00:00
|
|
|
|
2009-08-27 14:37:30 +00:00
|
|
|
passed = this->TestResult.Status == cmCTestTestHandler::COMPLETED;
|
|
|
|
char buf[1024];
|
|
|
|
sprintf(buf, "%6.2f sec", this->TestProcess->GetTotalTime());
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, buf << "\n");
|
2009-09-29 13:45:43 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (outputTestErrorsToConsole) {
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, this->ProcessOutput << std::endl);
|
|
|
|
}
|
2009-09-29 13:45:43 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->TestHandler->LogFile) {
|
2009-08-27 14:37:30 +00:00
|
|
|
*this->TestHandler->LogFile << "Test time = " << buf << std::endl;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-10-19 20:15:32 +00:00
|
|
|
|
|
|
|
// Set the working directory to the tests directory
|
|
|
|
std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
|
2014-10-15 12:54:05 +00:00
|
|
|
cmSystemTools::ChangeDirectory(this->TestProperties->Directory);
|
2010-10-19 20:15:32 +00:00
|
|
|
|
2009-08-27 14:37:30 +00:00
|
|
|
this->DartProcessing();
|
2010-10-19 20:15:32 +00:00
|
|
|
|
|
|
|
// restore working directory
|
2014-10-15 12:54:05 +00:00
|
|
|
cmSystemTools::ChangeDirectory(oldpath);
|
2010-10-19 20:15:32 +00:00
|
|
|
|
2009-08-19 12:58:36 +00:00
|
|
|
// if this is doing MemCheck then all the output needs to be put into
|
|
|
|
// Output since that is what is parsed by cmCTestMemCheckHandler
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->TestHandler->MemCheck && started) {
|
|
|
|
this->TestHandler->CleanTestOutput(
|
|
|
|
this->ProcessOutput,
|
|
|
|
static_cast<size_t>(
|
|
|
|
this->TestResult.Status == cmCTestTestHandler::COMPLETED
|
|
|
|
? this->TestHandler->CustomMaximumPassedTestOutputSize
|
|
|
|
: this->TestHandler->CustomMaximumFailedTestOutputSize));
|
|
|
|
}
|
2009-08-19 12:58:36 +00:00
|
|
|
this->TestResult.Reason = reason;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->TestHandler->LogFile) {
|
2009-08-19 12:58:36 +00:00
|
|
|
bool pass = true;
|
|
|
|
const char* reasonType = "Test Pass Reason";
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->TestResult.Status != cmCTestTestHandler::COMPLETED &&
|
|
|
|
this->TestResult.Status != cmCTestTestHandler::NOT_RUN) {
|
2009-08-19 12:58:36 +00:00
|
|
|
reasonType = "Test Fail Reason";
|
|
|
|
pass = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
double ttime = this->TestProcess->GetTotalTime();
|
2009-08-19 12:58:36 +00:00
|
|
|
int hours = static_cast<int>(ttime / (60 * 60));
|
|
|
|
int minutes = static_cast<int>(ttime / 60) % 60;
|
|
|
|
int seconds = static_cast<int>(ttime) % 60;
|
|
|
|
char buffer[100];
|
|
|
|
sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
|
|
|
|
*this->TestHandler->LogFile
|
|
|
|
<< "----------------------------------------------------------"
|
|
|
|
<< std::endl;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->TestResult.Reason.empty()) {
|
2012-08-13 17:42:58 +00:00
|
|
|
*this->TestHandler->LogFile << reasonType << ":\n"
|
2016-05-16 14:34:04 +00:00
|
|
|
<< this->TestResult.Reason << "\n";
|
|
|
|
} else {
|
|
|
|
if (pass) {
|
2009-08-19 12:58:36 +00:00
|
|
|
*this->TestHandler->LogFile << "Test Passed.\n";
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2009-08-19 12:58:36 +00:00
|
|
|
*this->TestHandler->LogFile << "Test Failed.\n";
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
*this->TestHandler->LogFile
|
|
|
|
<< "\"" << this->TestProperties->Name
|
2009-08-26 16:09:06 +00:00
|
|
|
<< "\" end time: " << this->CTest->CurrentTime() << std::endl
|
2016-05-16 14:34:04 +00:00
|
|
|
<< "\"" << this->TestProperties->Name << "\" time elapsed: " << buffer
|
|
|
|
<< std::endl
|
2009-08-19 12:58:36 +00:00
|
|
|
<< "----------------------------------------------------------"
|
2016-05-16 14:34:04 +00:00
|
|
|
<< std::endl
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
// if the test actually started and ran
|
|
|
|
// record the results in TestResult
|
2016-05-16 14:34:04 +00:00
|
|
|
if (started) {
|
2011-04-29 16:12:26 +00:00
|
|
|
bool compress = !this->TestHandler->MemCheck &&
|
2016-05-16 14:34:04 +00:00
|
|
|
this->CompressionRatio < 1 && this->CTest->ShouldCompressTestOutput();
|
|
|
|
this->TestResult.Output =
|
|
|
|
compress ? this->CompressedOutput : this->ProcessOutput;
|
2009-12-17 16:14:49 +00:00
|
|
|
this->TestResult.CompressOutput = compress;
|
2009-09-03 19:33:44 +00:00
|
|
|
this->TestResult.ReturnValue = this->TestProcess->GetExitValue();
|
|
|
|
this->TestResult.CompletionStatus = "Completed";
|
|
|
|
this->TestResult.ExecutionTime = this->TestProcess->GetTotalTime();
|
2009-09-10 15:16:08 +00:00
|
|
|
this->MemCheckPostProcess();
|
2010-02-25 21:23:49 +00:00
|
|
|
this->ComputeWeightedCost();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-03-05 21:51:10 +00:00
|
|
|
// If the test does not need to rerun push the current TestResult onto the
|
2009-12-02 21:37:43 +00:00
|
|
|
// TestHandler vector
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->NeedsToRerun()) {
|
2015-03-05 21:51:10 +00:00
|
|
|
this->TestHandler->TestResults.push_back(this->TestResult);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
delete this->TestProcess;
|
2009-08-19 12:58:36 +00:00
|
|
|
return passed;
|
|
|
|
}
|
|
|
|
|
2015-03-05 21:51:10 +00:00
|
|
|
bool cmCTestRunTest::StartAgain()
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->RunAgain) {
|
2015-03-05 21:51:10 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-03-05 21:51:10 +00:00
|
|
|
this->RunAgain = false; // reset
|
|
|
|
// change to tests directory
|
|
|
|
std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
|
|
|
|
cmSystemTools::ChangeDirectory(this->TestProperties->Directory);
|
|
|
|
this->StartTest(this->TotalNumberOfTests);
|
|
|
|
// change back
|
|
|
|
cmSystemTools::ChangeDirectory(current_dir);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestRunTest::NeedsToRerun()
|
|
|
|
{
|
|
|
|
this->NumberOfRunsLeft--;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->NumberOfRunsLeft == 0) {
|
2015-03-05 21:51:10 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-03-05 21:51:10 +00:00
|
|
|
// if number of runs left is not 0, and we are running until
|
|
|
|
// we find a failed test, then return true so the test can be
|
|
|
|
// restarted
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->RunUntilFail &&
|
|
|
|
this->TestResult.Status == cmCTestTestHandler::COMPLETED) {
|
2015-03-05 21:51:10 +00:00
|
|
|
this->RunAgain = true;
|
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-03-05 21:51:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-02-25 21:23:49 +00:00
|
|
|
void cmCTestRunTest::ComputeWeightedCost()
|
|
|
|
{
|
2010-06-27 15:22:05 +00:00
|
|
|
double prev = static_cast<double>(this->TestProperties->PreviousRuns);
|
|
|
|
double avgcost = static_cast<double>(this->TestProperties->Cost);
|
2010-02-25 21:23:49 +00:00
|
|
|
double current = this->TestResult.ExecutionTime;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->TestResult.Status == cmCTestTestHandler::COMPLETED) {
|
2010-06-27 15:22:05 +00:00
|
|
|
this->TestProperties->Cost =
|
|
|
|
static_cast<float>(((prev * avgcost) + current) / (prev + 1.0));
|
2010-02-25 21:23:49 +00:00
|
|
|
this->TestProperties->PreviousRuns++;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-02-25 21:23:49 +00:00
|
|
|
}
|
|
|
|
|
2009-08-28 19:08:03 +00:00
|
|
|
void cmCTestRunTest::MemCheckPostProcess()
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->TestHandler->MemCheck) {
|
2009-08-28 19:08:03 +00:00
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-02-17 22:15:00 +00:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index
|
2016-05-16 14:34:04 +00:00
|
|
|
<< ": process test output now: "
|
|
|
|
<< this->TestProperties->Name << " "
|
|
|
|
<< this->TestResult.Name << std::endl,
|
|
|
|
this->TestHandler->GetQuiet());
|
|
|
|
cmCTestMemCheckHandler* handler =
|
|
|
|
static_cast<cmCTestMemCheckHandler*>(this->TestHandler);
|
2014-07-07 19:58:02 +00:00
|
|
|
handler->PostProcessTest(this->TestResult, this->Index);
|
2009-08-28 19:08:03 +00:00
|
|
|
}
|
|
|
|
|
2009-08-26 16:09:06 +00:00
|
|
|
// Starts the execution of a test. Returns once it has started
|
2009-10-05 14:20:52 +00:00
|
|
|
bool cmCTestRunTest::StartTest(size_t total)
|
2009-08-26 16:09:06 +00:00
|
|
|
{
|
2015-03-05 21:51:10 +00:00
|
|
|
this->TotalNumberOfTests = total; // save for rerun case
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(2 * getNumWidth(total) + 8)
|
|
|
|
<< "Start "
|
|
|
|
<< std::setw(getNumWidth(this->TestHandler->GetMaxIndex()))
|
|
|
|
<< this->TestProperties->Index << ": "
|
|
|
|
<< this->TestProperties->Name << std::endl);
|
2017-01-12 10:32:58 +00:00
|
|
|
this->ProcessOutput.clear();
|
2009-08-28 15:08:39 +00:00
|
|
|
this->ComputeArguments();
|
2009-08-26 16:09:06 +00:00
|
|
|
std::vector<std::string>& args = this->TestProperties->Args;
|
|
|
|
this->TestResult.Properties = this->TestProperties;
|
|
|
|
this->TestResult.ExecutionTime = 0;
|
2009-12-17 16:14:49 +00:00
|
|
|
this->TestResult.CompressOutput = false;
|
2009-08-26 16:09:06 +00:00
|
|
|
this->TestResult.ReturnValue = -1;
|
2009-12-02 21:37:43 +00:00
|
|
|
this->TestResult.CompletionStatus = "Failed to start";
|
|
|
|
this->TestResult.Status = cmCTestTestHandler::BAD_COMMAND;
|
2012-08-13 17:42:58 +00:00
|
|
|
this->TestResult.TestCount = this->TestProperties->Index;
|
2009-08-26 16:09:06 +00:00
|
|
|
this->TestResult.Name = this->TestProperties->Name;
|
2016-05-26 20:52:22 +00:00
|
|
|
this->TestResult.Path = this->TestProperties->Directory;
|
2011-06-10 13:29:30 +00:00
|
|
|
|
2016-09-07 04:04:07 +00:00
|
|
|
if (!this->FailedDependencies.empty()) {
|
|
|
|
this->TestProcess = new cmProcess;
|
|
|
|
std::string msg = "Failed test dependencies:";
|
|
|
|
for (std::set<std::string>::const_iterator it =
|
|
|
|
this->FailedDependencies.begin();
|
|
|
|
it != this->FailedDependencies.end(); ++it) {
|
|
|
|
msg += " " + *it;
|
|
|
|
}
|
|
|
|
*this->TestHandler->LogFile << msg << std::endl;
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, msg << std::endl);
|
|
|
|
this->TestResult.Output = msg;
|
|
|
|
this->TestResult.FullCommandLine = "";
|
|
|
|
this->TestResult.CompletionStatus = "Not Run";
|
|
|
|
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() >= 2 && args[1] == "NOT_AVAILABLE") {
|
2011-06-10 13:29:30 +00:00
|
|
|
this->TestProcess = new cmProcess;
|
|
|
|
std::string msg;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->CTest->GetConfigType().empty()) {
|
2011-06-10 13:29:30 +00:00
|
|
|
msg = "Test not available without configuration.";
|
|
|
|
msg += " (Missing \"-C <config>\"?)";
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2011-06-10 13:29:30 +00:00
|
|
|
msg = "Test not available in configuration \"";
|
|
|
|
msg += this->CTest->GetConfigType();
|
|
|
|
msg += "\".";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-06-10 13:29:30 +00:00
|
|
|
*this->TestHandler->LogFile << msg << std::endl;
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, msg << std::endl);
|
|
|
|
this->TestResult.Output = msg;
|
|
|
|
this->TestResult.FullCommandLine = "";
|
|
|
|
this->TestResult.CompletionStatus = "Not Run";
|
|
|
|
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2009-12-10 20:37:04 +00:00
|
|
|
// Check if all required files exist
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<std::string>::iterator i =
|
|
|
|
this->TestProperties->RequiredFiles.begin();
|
|
|
|
i != this->TestProperties->RequiredFiles.end(); ++i) {
|
2009-12-10 20:37:04 +00:00
|
|
|
std::string file = *i;
|
2009-12-10 19:38:32 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmSystemTools::FileExists(file.c_str())) {
|
|
|
|
// Required file was not found
|
2009-12-10 20:37:04 +00:00
|
|
|
this->TestProcess = new cmProcess;
|
2016-05-16 14:34:04 +00:00
|
|
|
*this->TestHandler->LogFile << "Unable to find required file: " << file
|
|
|
|
<< std::endl;
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unable to find required file: " << file << std::endl);
|
2009-12-10 20:37:04 +00:00
|
|
|
this->TestResult.Output = "Unable to find required file: " + file;
|
|
|
|
this->TestResult.FullCommandLine = "";
|
|
|
|
this->TestResult.CompletionStatus = "Not Run";
|
|
|
|
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-10 15:16:08 +00:00
|
|
|
// log and return if we did not find the executable
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->ActualCommand == "") {
|
2009-12-10 20:37:04 +00:00
|
|
|
// if the command was not found create a TestResult object
|
2012-08-13 17:42:58 +00:00
|
|
|
// that has that information
|
2009-12-10 20:37:04 +00:00
|
|
|
this->TestProcess = new cmProcess;
|
2016-05-16 14:34:04 +00:00
|
|
|
*this->TestHandler->LogFile << "Unable to find executable: " << args[1]
|
|
|
|
<< std::endl;
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Unable to find executable: " << args[1] << std::endl);
|
2009-12-10 20:37:04 +00:00
|
|
|
this->TestResult.Output = "Unable to find executable: " + args[1];
|
|
|
|
this->TestResult.FullCommandLine = "";
|
|
|
|
this->TestResult.CompletionStatus = "Not Run";
|
|
|
|
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
|
2009-09-10 15:16:08 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-28 15:08:39 +00:00
|
|
|
this->StartTime = this->CTest->CurrentTime();
|
|
|
|
|
2010-06-15 14:29:35 +00:00
|
|
|
double timeout = this->ResolveTimeout();
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->StopTimePassed) {
|
2010-06-15 14:29:35 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-01-03 19:41:25 +00:00
|
|
|
return this->ForkProcess(timeout, this->TestProperties->ExplicitTimeout,
|
|
|
|
&this->TestProperties->Environment);
|
2009-08-28 15:08:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestRunTest::ComputeArguments()
|
|
|
|
{
|
2015-03-05 21:51:10 +00:00
|
|
|
this->Arguments.clear(); // reset becaue this might be a rerun
|
2010-03-02 20:34:37 +00:00
|
|
|
std::vector<std::string>::const_iterator j =
|
2009-08-28 15:08:39 +00:00
|
|
|
this->TestProperties->Args.begin();
|
|
|
|
++j; // skip test name
|
2009-08-28 19:08:03 +00:00
|
|
|
// find the test executable
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->TestHandler->MemCheck) {
|
|
|
|
cmCTestMemCheckHandler* handler =
|
|
|
|
static_cast<cmCTestMemCheckHandler*>(this->TestHandler);
|
2016-05-26 20:52:22 +00:00
|
|
|
this->ActualCommand = handler->MemoryTester;
|
2010-02-04 16:24:57 +00:00
|
|
|
this->TestProperties->Args[1] = this->TestHandler->FindTheExecutable(
|
|
|
|
this->TestProperties->Args[1].c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
|
|
|
this->ActualCommand = this->TestHandler->FindTheExecutable(
|
2009-08-28 19:08:03 +00:00
|
|
|
this->TestProperties->Args[1].c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
++j; // skip the executable (it will be actualCommand)
|
|
|
|
}
|
|
|
|
std::string testCommand =
|
|
|
|
cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str());
|
2009-08-28 19:08:03 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
// Prepends memcheck args to our command string
|
2013-08-07 20:25:48 +00:00
|
|
|
this->TestHandler->GenerateTestCommand(this->Arguments, this->Index);
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<std::string>::iterator i = this->Arguments.begin();
|
|
|
|
i != this->Arguments.end(); ++i) {
|
2010-08-18 14:14:09 +00:00
|
|
|
testCommand += " \"";
|
|
|
|
testCommand += *i;
|
|
|
|
testCommand += "\"";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-28 19:08:03 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (; j != this->TestProperties->Args.end(); ++j) {
|
2010-08-18 14:14:09 +00:00
|
|
|
testCommand += " \"";
|
|
|
|
testCommand += *j;
|
|
|
|
testCommand += "\"";
|
2009-08-28 15:08:39 +00:00
|
|
|
this->Arguments.push_back(*j);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-08-18 14:14:09 +00:00
|
|
|
this->TestResult.FullCommandLine = testCommand;
|
2009-08-26 16:09:06 +00:00
|
|
|
|
2015-03-15 17:00:31 +00:00
|
|
|
// Print the test command in verbose mode
|
2009-08-26 16:09:06 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
|
2016-05-16 14:34:04 +00:00
|
|
|
<< this->Index << ": "
|
|
|
|
<< (this->TestHandler->MemCheck ? "MemCheck" : "Test")
|
|
|
|
<< " command: " << testCommand << std::endl);
|
2015-03-15 17:00:31 +00:00
|
|
|
|
|
|
|
// Print any test-specific env vars in verbose mode
|
2016-05-26 21:05:30 +00:00
|
|
|
if (!this->TestProperties->Environment.empty()) {
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index
|
|
|
|
<< ": "
|
|
|
|
<< "Environment variables: " << std::endl);
|
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator e =
|
|
|
|
this->TestProperties->Environment.begin();
|
|
|
|
e != this->TestProperties->Environment.end(); ++e) {
|
2015-03-15 17:00:31 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index << ": " << *e
|
2016-05-16 14:34:04 +00:00
|
|
|
<< std::endl);
|
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCTestRunTest::DartProcessing()
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2012-08-13 17:42:58 +00:00
|
|
|
if (!this->ProcessOutput.empty() &&
|
2016-05-16 14:34:04 +00:00
|
|
|
this->ProcessOutput.find("<DartMeasurement") !=
|
|
|
|
this->ProcessOutput.npos) {
|
|
|
|
if (this->TestHandler->DartStuff.find(this->ProcessOutput.c_str())) {
|
2015-05-23 23:00:12 +00:00
|
|
|
this->TestResult.DartString = this->TestHandler->DartStuff.match(1);
|
2009-08-19 12:58:36 +00:00
|
|
|
// keep searching and replacing until none are left
|
2016-05-16 14:34:04 +00:00
|
|
|
while (this->TestHandler->DartStuff1.find(this->ProcessOutput.c_str())) {
|
2009-08-19 12:58:36 +00:00
|
|
|
// replace the exact match for the string
|
2016-05-16 14:34:04 +00:00
|
|
|
cmSystemTools::ReplaceString(
|
|
|
|
this->ProcessOutput, this->TestHandler->DartStuff1.match(1).c_str(),
|
|
|
|
"");
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 19:33:55 +00:00
|
|
|
double cmCTestRunTest::ResolveTimeout()
|
|
|
|
{
|
|
|
|
double timeout = this->TestProperties->Timeout;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->CTest->GetStopTime() == "") {
|
2010-03-16 19:33:55 +00:00
|
|
|
return timeout;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-03-16 19:33:55 +00:00
|
|
|
struct tm* lctime;
|
2016-06-27 20:44:16 +00:00
|
|
|
time_t current_time = time(CM_NULLPTR);
|
2010-03-16 19:33:55 +00:00
|
|
|
lctime = gmtime(¤t_time);
|
|
|
|
int gm_hour = lctime->tm_hour;
|
2010-03-18 17:51:40 +00:00
|
|
|
time_t gm_time = mktime(lctime);
|
2010-03-16 19:33:55 +00:00
|
|
|
lctime = localtime(¤t_time);
|
|
|
|
int local_hour = lctime->tm_hour;
|
|
|
|
|
2010-03-18 18:48:42 +00:00
|
|
|
int tzone_offset = local_hour - gm_hour;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gm_time > current_time && gm_hour < local_hour) {
|
2010-03-18 17:51:40 +00:00
|
|
|
// this means gm_time is on the next day
|
2010-03-18 18:48:42 +00:00
|
|
|
tzone_offset -= 24;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (gm_time < current_time && gm_hour > local_hour) {
|
2010-03-18 18:48:42 +00:00
|
|
|
// this means gm_time is on the previous day
|
|
|
|
tzone_offset += 24;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-03-18 17:51:40 +00:00
|
|
|
|
|
|
|
tzone_offset *= 100;
|
2010-03-16 19:33:55 +00:00
|
|
|
char buf[1024];
|
|
|
|
// add todays year day and month to the time in str because
|
|
|
|
// curl_getdate no longer assumes the day is today
|
2016-05-16 14:34:04 +00:00
|
|
|
sprintf(buf, "%d%02d%02d %s %+05i", lctime->tm_year + 1900,
|
|
|
|
lctime->tm_mon + 1, lctime->tm_mday,
|
|
|
|
this->CTest->GetStopTime().c_str(), tzone_offset);
|
2010-03-16 19:33:55 +00:00
|
|
|
|
|
|
|
time_t stop_time = curl_getdate(buf, ¤t_time);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (stop_time == -1) {
|
2010-03-16 19:33:55 +00:00
|
|
|
return timeout;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// the stop time refers to the next day
|
|
|
|
if (this->CTest->NextDayStopTime) {
|
|
|
|
stop_time += 24 * 60 * 60;
|
|
|
|
}
|
|
|
|
int stop_timeout =
|
|
|
|
static_cast<int>(stop_time - current_time) % (24 * 60 * 60);
|
2010-03-19 13:08:57 +00:00
|
|
|
this->CTest->LastStopTimeout = stop_timeout;
|
2010-03-16 19:33:55 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (stop_timeout <= 0 || stop_timeout > this->CTest->LastStopTimeout) {
|
2010-03-16 19:33:55 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "The stop time has been passed. "
|
2016-05-16 14:34:04 +00:00
|
|
|
"Stopping all tests."
|
|
|
|
<< std::endl);
|
2010-06-15 14:29:35 +00:00
|
|
|
this->StopTimePassed = true;
|
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
return timeout == 0 ? stop_timeout
|
|
|
|
: (timeout < stop_timeout ? timeout : stop_timeout);
|
2010-03-16 19:33:55 +00:00
|
|
|
}
|
|
|
|
|
2011-01-03 19:41:25 +00:00
|
|
|
bool cmCTestRunTest::ForkProcess(double testTimeOut, bool explicitTimeout,
|
2016-05-16 14:34:04 +00:00
|
|
|
std::vector<std::string>* environment)
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-26 16:09:06 +00:00
|
|
|
this->TestProcess = new cmProcess;
|
|
|
|
this->TestProcess->SetId(this->Index);
|
2009-08-30 14:57:30 +00:00
|
|
|
this->TestProcess->SetWorkingDirectory(
|
2016-05-16 14:34:04 +00:00
|
|
|
this->TestProperties->Directory.c_str());
|
2009-12-10 20:37:04 +00:00
|
|
|
this->TestProcess->SetCommand(this->ActualCommand.c_str());
|
2009-08-28 15:08:39 +00:00
|
|
|
this->TestProcess->SetCommandArguments(this->Arguments);
|
2009-08-26 16:09:06 +00:00
|
|
|
|
2009-08-19 12:58:36 +00:00
|
|
|
// determine how much time we have
|
|
|
|
double timeout = this->CTest->GetRemainingTimeAllowed() - 120;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->CTest->GetTimeOut() > 0 && this->CTest->GetTimeOut() < timeout) {
|
2009-08-19 12:58:36 +00:00
|
|
|
timeout = this->CTest->GetTimeOut();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (testTimeOut > 0 &&
|
|
|
|
testTimeOut < this->CTest->GetRemainingTimeAllowed()) {
|
2009-08-19 12:58:36 +00:00
|
|
|
timeout = testTimeOut;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-19 12:58:36 +00:00
|
|
|
// always have at least 1 second if we got to here
|
2016-05-16 14:34:04 +00:00
|
|
|
if (timeout <= 0) {
|
2009-08-19 12:58:36 +00:00
|
|
|
timeout = 1;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-01-03 19:41:25 +00:00
|
|
|
// handle timeout explicitly set to 0
|
2016-05-16 14:34:04 +00:00
|
|
|
if (testTimeOut == 0 && explicitTimeout) {
|
2011-01-03 19:41:25 +00:00
|
|
|
timeout = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index
|
|
|
|
<< ": "
|
|
|
|
<< "Test timeout computed to be: " << timeout << "\n",
|
|
|
|
this->TestHandler->GetQuiet());
|
2009-08-19 12:58:36 +00:00
|
|
|
|
2009-09-29 18:31:58 +00:00
|
|
|
this->TestProcess->SetTimeout(timeout);
|
|
|
|
|
2010-03-30 18:08:31 +00:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
|
|
|
cmSystemTools::SaveRestoreEnvironment sre;
|
|
|
|
#endif
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (environment && !environment->empty()) {
|
2012-04-24 20:24:17 +00:00
|
|
|
cmSystemTools::AppendEnv(*environment);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-19 12:58:36 +00:00
|
|
|
|
2009-08-26 16:09:06 +00:00
|
|
|
return this->TestProcess->StartProcess();
|
|
|
|
}
|
|
|
|
|
2009-08-31 13:50:35 +00:00
|
|
|
void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
|
2009-08-26 16:09:06 +00:00
|
|
|
{
|
2015-03-05 21:51:10 +00:00
|
|
|
// if this is the last or only run of this test
|
|
|
|
// then print out completed / total
|
|
|
|
// Only issue is if a test fails and we are running until fail
|
|
|
|
// then it will never print out the completed / total, same would
|
|
|
|
// got for run until pass. Trick is when this is called we don't
|
|
|
|
// yet know if we are passing or failing.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->NumberOfRunsLeft == 1) {
|
2015-03-05 21:51:10 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
|
2016-05-16 14:34:04 +00:00
|
|
|
<< completed << "/");
|
2015-03-05 21:51:10 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
|
2016-05-16 14:34:04 +00:00
|
|
|
<< total << " ");
|
|
|
|
}
|
2015-03-05 21:51:10 +00:00
|
|
|
// if this is one of several runs of a test just print blank space
|
|
|
|
// to keep things neat
|
2016-05-16 14:34:04 +00:00
|
|
|
else {
|
2015-03-05 21:51:10 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
|
2016-05-16 14:34:04 +00:00
|
|
|
<< " "
|
|
|
|
<< " ");
|
2015-03-05 21:51:10 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
|
2016-05-16 14:34:04 +00:00
|
|
|
<< " "
|
|
|
|
<< " ");
|
|
|
|
}
|
2009-08-28 15:08:39 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->TestHandler->MemCheck) {
|
2009-09-03 14:47:14 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "MemCheck");
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2009-09-01 15:58:04 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Test");
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-08-28 15:08:39 +00:00
|
|
|
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream indexStr;
|
2009-09-01 15:58:04 +00:00
|
|
|
indexStr << " #" << this->Index << ":";
|
2012-08-13 17:42:58 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
2009-09-02 14:08:40 +00:00
|
|
|
std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
|
2016-05-16 14:34:04 +00:00
|
|
|
<< indexStr.str());
|
2009-08-26 16:09:06 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
|
|
|
|
const int maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
|
|
|
|
std::string outname = this->TestProperties->Name + " ";
|
2009-09-07 14:26:17 +00:00
|
|
|
outname.resize(maxTestNameWidth + 4, '.');
|
2009-08-19 12:58:36 +00:00
|
|
|
|
2009-08-28 19:08:03 +00:00
|
|
|
*this->TestHandler->LogFile << this->TestProperties->Index << "/"
|
2016-05-16 14:34:04 +00:00
|
|
|
<< this->TestHandler->TotalNumberOfTests
|
|
|
|
<< " Testing: " << this->TestProperties->Name
|
|
|
|
<< std::endl;
|
2009-08-28 19:08:03 +00:00
|
|
|
*this->TestHandler->LogFile << this->TestProperties->Index << "/"
|
2016-05-16 14:34:04 +00:00
|
|
|
<< this->TestHandler->TotalNumberOfTests
|
|
|
|
<< " Test: " << this->TestProperties->Name
|
|
|
|
<< std::endl;
|
2009-08-28 15:08:39 +00:00
|
|
|
*this->TestHandler->LogFile << "Command: \"" << this->ActualCommand << "\"";
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2009-08-28 15:08:39 +00:00
|
|
|
for (std::vector<std::string>::iterator i = this->Arguments.begin();
|
2016-05-16 14:34:04 +00:00
|
|
|
i != this->Arguments.end(); ++i) {
|
|
|
|
*this->TestHandler->LogFile << " \"" << *i << "\"";
|
|
|
|
}
|
|
|
|
*this->TestHandler->LogFile
|
|
|
|
<< std::endl
|
2009-08-26 16:09:06 +00:00
|
|
|
<< "Directory: " << this->TestProperties->Directory << std::endl
|
2016-05-16 14:34:04 +00:00
|
|
|
<< "\"" << this->TestProperties->Name
|
|
|
|
<< "\" start time: " << this->StartTime << std::endl;
|
2009-08-19 12:58:36 +00:00
|
|
|
|
2009-08-26 16:09:06 +00:00
|
|
|
*this->TestHandler->LogFile
|
|
|
|
<< "Output:" << std::endl
|
|
|
|
<< "----------------------------------------------------------"
|
|
|
|
<< std::endl;
|
2016-05-16 14:34:04 +00:00
|
|
|
*this->TestHandler->LogFile << this->ProcessOutput << "<end of output>"
|
|
|
|
<< std::endl;
|
2009-08-19 12:58:36 +00:00
|
|
|
|
2009-08-27 14:37:30 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
cmCTestLog(this->CTest, DEBUG, "Testing " << this->TestProperties->Name
|
|
|
|
<< " ... ");
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|