2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2009-08-19 12:58:36 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2009-08-19 12:58:36 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2009-08-19 12:58:36 +00:00
|
|
|
|
|
|
|
#include "cmCTestRunTest.h"
|
2009-08-28 19:08:03 +00:00
|
|
|
#include "cmCTestMemCheckHandler.h"
|
2009-08-19 12:58:36 +00:00
|
|
|
#include "cmCTest.h"
|
|
|
|
#include "cmSystemTools.h"
|
2010-03-16 19:33:55 +00:00
|
|
|
#include "cm_curl.h"
|
2009-08-19 12:58:36 +00:00
|
|
|
|
2009-12-17 16:14:49 +00:00
|
|
|
#include <cm_zlib.h>
|
|
|
|
#include <cmsys/Base64.h>
|
|
|
|
|
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;
|
2009-09-16 15:49:09 +00:00
|
|
|
this->ModifyEnv = false;
|
|
|
|
this->TestProcess = 0;
|
|
|
|
this->TestResult.ExecutionTime =0;
|
|
|
|
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;
|
|
|
|
this->TestResult.Properties = 0;
|
2009-12-17 16:14:49 +00:00
|
|
|
this->ProcessOutput = "";
|
|
|
|
this->CompressedOutput = "";
|
|
|
|
this->CompressionRatio = 2;
|
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;
|
|
|
|
while((timeout = timeEnd - cmSystemTools::GetTime(), timeout > 0))
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-09-11 16:26:41 +00:00
|
|
|
int p = this->TestProcess->GetNextOutputLine(line, timeout);
|
|
|
|
if(p == cmsysProcess_Pipe_None)
|
|
|
|
{
|
|
|
|
// Process has terminated and all output read.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(p == cmsysProcess_Pipe_STDOUT ||
|
|
|
|
p == cmsysProcess_Pipe_STDERR)
|
2009-09-03 19:33:44 +00:00
|
|
|
{
|
2009-09-11 16:26:41 +00:00
|
|
|
// Store this line of output.
|
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2009-12-17 16:14:49 +00:00
|
|
|
this->GetIndex() << ": " << line << std::endl);
|
2009-09-11 16:26:41 +00:00
|
|
|
this->ProcessOutput += line;
|
|
|
|
this->ProcessOutput += "\n";
|
2009-09-03 19:33:44 +00:00
|
|
|
}
|
2009-09-11 16:26:41 +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
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
unsigned char* in =
|
|
|
|
reinterpret_cast<unsigned char*>(
|
|
|
|
const_cast<char*>(this->ProcessOutput.c_str()));
|
|
|
|
//zlib makes the guarantee that this is the maximum output size
|
|
|
|
int outSize = static_cast<int>(this->ProcessOutput.size() * 1.001 + 13);
|
|
|
|
unsigned char* out = new unsigned char[outSize];
|
|
|
|
|
|
|
|
strm.zalloc = Z_NULL;
|
|
|
|
strm.zfree = Z_NULL;
|
|
|
|
strm.opaque = Z_NULL;
|
|
|
|
ret = deflateInit(&strm, -1); //default compression level
|
|
|
|
if (ret != Z_OK)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if(ret == Z_STREAM_ERROR || ret != Z_STREAM_END)
|
|
|
|
{
|
2009-12-17 16:17:57 +00:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Error during output "
|
2009-12-17 16:14:49 +00:00
|
|
|
"compression. Sending uncompressed output." << std::endl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)deflateEnd(&strm);
|
2009-12-18 16:42:58 +00:00
|
|
|
|
2009-12-17 16:14:49 +00:00
|
|
|
unsigned char *encoded_buffer
|
|
|
|
= new unsigned char[static_cast<int>(outSize * 1.5)];
|
|
|
|
|
|
|
|
unsigned long rlen
|
|
|
|
= cmsysBase64_Encode(out, strm.total_out, encoded_buffer, 1);
|
2009-12-18 16:42:58 +00:00
|
|
|
|
2009-12-17 16:14:49 +00:00
|
|
|
for(unsigned long i = 0; i < rlen; i++)
|
|
|
|
{
|
|
|
|
this->CompressedOutput += encoded_buffer[i];
|
|
|
|
}
|
|
|
|
|
2009-12-18 16:42:58 +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
|
|
|
|
|
|
|
delete [] encoded_buffer;
|
|
|
|
delete [] out;
|
|
|
|
}
|
|
|
|
|
2009-08-26 16:09:06 +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
|
|
|
{
|
2009-12-17 16:14:49 +00:00
|
|
|
if (this->CTest->ShouldCompressTestOutput())
|
|
|
|
{
|
|
|
|
this->CompressOutput();
|
|
|
|
}
|
|
|
|
|
2009-08-26 16:09:06 +00:00
|
|
|
//restore the old environment
|
|
|
|
if (this->ModifyEnv)
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-26 16:09:06 +00:00
|
|
|
cmSystemTools::RestoreEnv(this->OrigEnv);
|
2009-08-19 12:58:36 +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;
|
2009-09-10 15:16:08 +00:00
|
|
|
int res = started ? this->TestProcess->GetProcessStatus()
|
|
|
|
: cmsysProcess_State_Error;
|
2009-08-26 16:09:06 +00:00
|
|
|
int retVal = this->TestProcess->GetExitValue();
|
2009-08-27 14:37:30 +00:00
|
|
|
std::vector<std::pair<cmsys::RegularExpression,
|
|
|
|
std::string> >::iterator passIt;
|
|
|
|
bool forceFail = false;
|
2009-09-29 13:45:43 +00:00
|
|
|
bool outputTestErrorsToConsole = false;
|
2009-08-27 14:37:30 +00:00
|
|
|
if ( this->TestProperties->RequiredRegularExpressions.size() > 0 )
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-27 14:37:30 +00:00
|
|
|
bool found = false;
|
|
|
|
for ( passIt = this->TestProperties->RequiredRegularExpressions.begin();
|
|
|
|
passIt != this->TestProperties->RequiredRegularExpressions.end();
|
|
|
|
++ passIt )
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-27 14:37:30 +00:00
|
|
|
if ( passIt->first.find(this->ProcessOutput.c_str()) )
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-27 14:37:30 +00:00
|
|
|
found = true;
|
|
|
|
reason = "Required regular expression found.";
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-27 14:37:30 +00:00
|
|
|
if ( !found )
|
|
|
|
{
|
|
|
|
reason = "Required regular expression not found.";
|
|
|
|
forceFail = true;
|
|
|
|
}
|
|
|
|
reason += "Regex=[";
|
|
|
|
for ( passIt = this->TestProperties->RequiredRegularExpressions.begin();
|
|
|
|
passIt != this->TestProperties->RequiredRegularExpressions.end();
|
|
|
|
++ passIt )
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-27 14:37:30 +00:00
|
|
|
reason += passIt->second;
|
|
|
|
reason += "\n";
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
2009-08-27 14:37:30 +00:00
|
|
|
reason += "]";
|
|
|
|
}
|
|
|
|
if ( this->TestProperties->ErrorRegularExpressions.size() > 0 )
|
|
|
|
{
|
|
|
|
for ( passIt = this->TestProperties->ErrorRegularExpressions.begin();
|
|
|
|
passIt != this->TestProperties->ErrorRegularExpressions.end();
|
|
|
|
++ passIt )
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-27 14:37:30 +00:00
|
|
|
if ( passIt->first.find(this->ProcessOutput.c_str()) )
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-27 14:37:30 +00:00
|
|
|
reason = "Error regular expression found in output.";
|
|
|
|
reason += " Regex=[";
|
|
|
|
reason += passIt->second;
|
|
|
|
reason += "]";
|
|
|
|
forceFail = true;
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-27 14:37:30 +00:00
|
|
|
}
|
|
|
|
if (res == cmsysProcess_State_Exited)
|
|
|
|
{
|
|
|
|
bool success =
|
|
|
|
!forceFail && (retVal == 0 ||
|
|
|
|
this->TestProperties->RequiredRegularExpressions.size());
|
|
|
|
if((success && !this->TestProperties->WillFail)
|
|
|
|
|| (!success && this->TestProperties->WillFail))
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-27 14:37:30 +00:00
|
|
|
this->TestResult.Status = cmCTestTestHandler::COMPLETED;
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Passed " );
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
2009-08-27 14:37:30 +00:00
|
|
|
else
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-27 14:37:30 +00:00
|
|
|
this->TestResult.Status = cmCTestTestHandler::FAILED;
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Failed " << reason );
|
2009-09-29 13:45:43 +00:00
|
|
|
outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
2009-08-27 14:37:30 +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;
|
2009-08-27 14:37:30 +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: ");
|
|
|
|
switch ( retVal )
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
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;
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
2009-08-27 14:37:30 +00:00
|
|
|
}
|
2009-12-10 20:51:56 +00:00
|
|
|
else //cmsysProcess_State_Error
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Not Run ");
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, buf << "\n" );
|
2009-09-29 13:45:43 +00:00
|
|
|
|
|
|
|
if ( outputTestErrorsToConsole )
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, this->ProcessOutput << std::endl );
|
|
|
|
}
|
|
|
|
|
2009-08-27 14:37:30 +00:00
|
|
|
if ( this->TestHandler->LogFile )
|
|
|
|
{
|
|
|
|
*this->TestHandler->LogFile << "Test time = " << buf << std::endl;
|
|
|
|
}
|
|
|
|
this->DartProcessing();
|
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
|
2009-09-10 15:16:08 +00:00
|
|
|
if(!this->TestHandler->MemCheck && started)
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-26 16:09:06 +00:00
|
|
|
this->TestHandler->CleanTestOutput(this->ProcessOutput,
|
|
|
|
static_cast<size_t>
|
2009-12-18 16:42:58 +00:00
|
|
|
(this->TestResult.Status == cmCTestTestHandler::COMPLETED ?
|
|
|
|
this->TestHandler->CustomMaximumPassedTestOutputSize :
|
|
|
|
this->TestHandler->CustomMaximumFailedTestOutputSize));
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
|
|
|
this->TestResult.Reason = reason;
|
2009-09-10 15:16:08 +00:00
|
|
|
if (this->TestHandler->LogFile)
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
|
|
|
bool pass = true;
|
|
|
|
const char* reasonType = "Test Pass Reason";
|
|
|
|
if(this->TestResult.Status != cmCTestTestHandler::COMPLETED &&
|
|
|
|
this->TestResult.Status != cmCTestTestHandler::NOT_RUN)
|
|
|
|
{
|
|
|
|
reasonType = "Test Fail Reason";
|
|
|
|
pass = false;
|
|
|
|
}
|
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;
|
|
|
|
if(this->TestResult.Reason.size())
|
|
|
|
{
|
|
|
|
*this->TestHandler->LogFile << reasonType << ":\n"
|
|
|
|
<< this->TestResult.Reason << "\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(pass)
|
|
|
|
{
|
|
|
|
*this->TestHandler->LogFile << "Test Passed.\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*this->TestHandler->LogFile << "Test Failed.\n";
|
|
|
|
}
|
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
*this->TestHandler->LogFile << "\"" << this->TestProperties->Name.c_str()
|
|
|
|
<< "\" end time: " << this->CTest->CurrentTime() << std::endl
|
|
|
|
<< "\"" << this->TestProperties->Name.c_str() << "\" time elapsed: "
|
2009-08-19 12:58:36 +00:00
|
|
|
<< buffer << std::endl
|
|
|
|
<< "----------------------------------------------------------"
|
|
|
|
<< std::endl << std::endl;
|
|
|
|
}
|
2009-12-18 16:42:58 +00:00
|
|
|
// if the test actually started and ran
|
2009-12-02 21:37:43 +00:00
|
|
|
// record the results in TestResult
|
2009-09-03 19:33:44 +00:00
|
|
|
if(started)
|
|
|
|
{
|
2009-12-17 16:14:49 +00:00
|
|
|
bool compress = this->CompressionRatio < 1 &&
|
|
|
|
this->CTest->ShouldCompressTestOutput();
|
|
|
|
this->TestResult.Output = compress ? this->CompressedOutput
|
|
|
|
: this->ProcessOutput;
|
|
|
|
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();
|
2009-09-10 15:16:08 +00:00
|
|
|
}
|
2009-12-02 21:37:43 +00:00
|
|
|
// Always push the current TestResult onto the
|
|
|
|
// TestHandler vector
|
|
|
|
this->TestHandler->TestResults.push_back(this->TestResult);
|
2009-08-26 16:09:06 +00:00
|
|
|
delete this->TestProcess;
|
2009-08-19 12:58:36 +00:00
|
|
|
return passed;
|
|
|
|
}
|
|
|
|
|
2010-02-25 21:23:49 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void cmCTestRunTest::ComputeWeightedCost()
|
|
|
|
{
|
|
|
|
int prev = this->TestProperties->PreviousRuns;
|
|
|
|
float avgcost = this->TestProperties->Cost;
|
|
|
|
double current = this->TestResult.ExecutionTime;
|
|
|
|
|
|
|
|
if(this->TestResult.Status == cmCTestTestHandler::COMPLETED)
|
|
|
|
{
|
|
|
|
this->TestProperties->Cost = ((prev * avgcost) + current) / (prev + 1);
|
|
|
|
this->TestProperties->PreviousRuns++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2009-08-28 19:08:03 +00:00
|
|
|
void cmCTestRunTest::MemCheckPostProcess()
|
|
|
|
{
|
|
|
|
if(!this->TestHandler->MemCheck)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index
|
|
|
|
<< ": process test output now: "
|
|
|
|
<< this->TestProperties->Name.c_str() << " "
|
|
|
|
<< this->TestResult.Name.c_str() << std::endl);
|
|
|
|
cmCTestMemCheckHandler * handler = static_cast<cmCTestMemCheckHandler*>
|
|
|
|
(this->TestHandler);
|
|
|
|
if(handler->MemoryTesterStyle == cmCTestMemCheckHandler::BOUNDS_CHECKER)
|
|
|
|
{
|
|
|
|
handler->PostProcessBoundsCheckerTest(this->TestResult);
|
|
|
|
}
|
|
|
|
else if(handler->MemoryTesterStyle == cmCTestMemCheckHandler::PURIFY)
|
|
|
|
{
|
|
|
|
handler->PostProcessPurifyTest(this->TestResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-10-05 14:20:52 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(2*getNumWidth(total) + 8)
|
|
|
|
<< "Start "
|
2009-10-15 16:02:22 +00:00
|
|
|
<< std::setw(getNumWidth(this->TestHandler->GetMaxIndex()))
|
2009-09-24 17:49:20 +00:00
|
|
|
<< this->TestProperties->Index << ": "
|
|
|
|
<< this->TestProperties->Name << std::endl);
|
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;
|
2009-12-10 20:37:04 +00:00
|
|
|
this->TestResult.TestCount = this->TestProperties->Index;
|
2009-08-26 16:09:06 +00:00
|
|
|
this->TestResult.Name = this->TestProperties->Name;
|
|
|
|
this->TestResult.Path = this->TestProperties->Directory.c_str();
|
|
|
|
|
2009-12-10 20:37:04 +00:00
|
|
|
// Check if all required files exist
|
|
|
|
for(std::vector<std::string>::iterator i =
|
|
|
|
this->TestProperties->RequiredFiles.begin();
|
|
|
|
i != this->TestProperties->RequiredFiles.end(); ++i)
|
2009-12-10 19:38:32 +00:00
|
|
|
{
|
2009-12-10 20:37:04 +00:00
|
|
|
std::string file = *i;
|
2009-12-10 19:38:32 +00:00
|
|
|
|
2009-12-10 20:37:04 +00:00
|
|
|
if(!cmSystemTools::FileExists(file.c_str()))
|
|
|
|
{
|
|
|
|
//Required file was not found
|
|
|
|
this->TestProcess = new cmProcess;
|
|
|
|
*this->TestHandler->LogFile << "Unable to find required file: "
|
|
|
|
<< file.c_str() << std::endl;
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find required file: "
|
|
|
|
<< file.c_str() << std::endl);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2009-09-10 15:16:08 +00:00
|
|
|
// log and return if we did not find the executable
|
|
|
|
if (this->ActualCommand == "")
|
2009-08-26 16:09:06 +00:00
|
|
|
{
|
2009-12-10 20:37:04 +00:00
|
|
|
// if the command was not found create a TestResult object
|
|
|
|
// that has that information
|
|
|
|
this->TestProcess = new cmProcess;
|
|
|
|
*this->TestHandler->LogFile << "Unable to find executable: "
|
|
|
|
<< args[1].c_str() << std::endl;
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find executable: "
|
|
|
|
<< args[1].c_str() << std::endl);
|
|
|
|
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;
|
2009-08-26 16:09:06 +00:00
|
|
|
}
|
2009-08-28 15:08:39 +00:00
|
|
|
this->StartTime = this->CTest->CurrentTime();
|
|
|
|
|
2010-03-16 19:33:55 +00:00
|
|
|
return this->ForkProcess(this->ResolveTimeout(),
|
2009-08-28 15:08:39 +00:00
|
|
|
&this->TestProperties->Environment);
|
|
|
|
}
|
|
|
|
|
2010-02-25 21:23:49 +00:00
|
|
|
//----------------------------------------------------------------------
|
2009-08-28 15:08:39 +00:00
|
|
|
void cmCTestRunTest::ComputeArguments()
|
|
|
|
{
|
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
|
|
|
|
if(this->TestHandler->MemCheck)
|
|
|
|
{
|
|
|
|
cmCTestMemCheckHandler * handler = static_cast<cmCTestMemCheckHandler*>
|
|
|
|
(this->TestHandler);
|
|
|
|
this->ActualCommand = handler->MemoryTester.c_str();
|
2010-02-04 16:24:57 +00:00
|
|
|
this->TestProperties->Args[1] = this->TestHandler->FindTheExecutable(
|
|
|
|
this->TestProperties->Args[1].c_str());
|
2009-08-28 19:08:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-02 20:34:37 +00:00
|
|
|
this->ActualCommand =
|
2009-08-28 19:08:03 +00:00
|
|
|
this->TestHandler->FindTheExecutable(
|
|
|
|
this->TestProperties->Args[1].c_str());
|
|
|
|
++j; //skip the executable (it will be actualCommand)
|
|
|
|
}
|
2009-12-10 20:37:04 +00:00
|
|
|
this->TestCommand
|
|
|
|
= cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str());
|
2009-08-28 19:08:03 +00:00
|
|
|
|
|
|
|
//Prepends memcheck args to our command string
|
|
|
|
this->TestHandler->GenerateTestCommand(this->Arguments);
|
|
|
|
for(std::vector<std::string>::iterator i = this->Arguments.begin();
|
|
|
|
i != this->Arguments.end(); ++i)
|
|
|
|
{
|
|
|
|
this->TestCommand += " ";
|
2010-02-04 16:24:57 +00:00
|
|
|
this->TestCommand += cmSystemTools::EscapeSpaces(i->c_str());
|
2009-08-28 19:08:03 +00:00
|
|
|
}
|
|
|
|
|
2009-08-28 15:08:39 +00:00
|
|
|
for(;j != this->TestProperties->Args.end(); ++j)
|
|
|
|
{
|
|
|
|
this->TestCommand += " ";
|
|
|
|
this->TestCommand += cmSystemTools::EscapeSpaces(j->c_str());
|
|
|
|
this->Arguments.push_back(*j);
|
|
|
|
}
|
|
|
|
this->TestResult.FullCommandLine = this->TestCommand;
|
2009-08-26 16:09:06 +00:00
|
|
|
|
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
|
|
|
|
<< this->Index << ": "
|
|
|
|
<< (this->TestHandler->MemCheck?"MemCheck":"Test")
|
|
|
|
<< " command: " << this->TestCommand
|
|
|
|
<< std::endl);
|
|
|
|
}
|
|
|
|
|
2009-08-19 12:58:36 +00:00
|
|
|
//----------------------------------------------------------------------
|
2009-08-26 16:09:06 +00:00
|
|
|
void cmCTestRunTest::DartProcessing()
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-26 16:09:06 +00:00
|
|
|
if (!this->ProcessOutput.empty() &&
|
|
|
|
this->ProcessOutput.find("<DartMeasurement") != this->ProcessOutput.npos)
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-26 16:09:06 +00:00
|
|
|
if (this->TestHandler->DartStuff.find(this->ProcessOutput.c_str()))
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
|
|
|
std::string dartString = this->TestHandler->DartStuff.match(1);
|
|
|
|
// keep searching and replacing until none are left
|
2009-08-26 16:09:06 +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
|
2009-08-26 16:09:06 +00:00
|
|
|
cmSystemTools::ReplaceString(this->ProcessOutput,
|
2009-08-19 12:58:36 +00:00
|
|
|
this->TestHandler->DartStuff1.match(1).c_str(), "");
|
|
|
|
}
|
|
|
|
this->TestResult.RegressionImages
|
|
|
|
= this->TestHandler->GenerateRegressionImages(dartString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2010-03-16 19:33:55 +00:00
|
|
|
double cmCTestRunTest::ResolveTimeout()
|
|
|
|
{
|
|
|
|
double timeout = this->TestProperties->Timeout;
|
|
|
|
|
|
|
|
if(this->CTest->GetStopTime() == "")
|
|
|
|
{
|
|
|
|
return timeout;
|
|
|
|
}
|
|
|
|
struct tm* lctime;
|
|
|
|
time_t current_time = time(0);
|
|
|
|
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;
|
2010-03-18 17:51:40 +00:00
|
|
|
if(gm_time > current_time && gm_hour < local_hour)
|
|
|
|
{
|
|
|
|
// this means gm_time is on the next day
|
2010-03-18 18:48:42 +00:00
|
|
|
tzone_offset -= 24;
|
2010-03-18 17:51:40 +00:00
|
|
|
}
|
2010-03-18 18:48:42 +00:00
|
|
|
else if(gm_time < current_time && gm_hour > local_hour)
|
2010-03-18 17:51:40 +00:00
|
|
|
{
|
2010-03-18 18:48:42 +00:00
|
|
|
// this means gm_time is on the previous day
|
|
|
|
tzone_offset += 24;
|
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
|
|
|
|
sprintf(buf, "%d%02d%02d %s %+05i",
|
|
|
|
lctime->tm_year + 1900,
|
|
|
|
lctime->tm_mon + 1,
|
|
|
|
lctime->tm_mday,
|
|
|
|
this->CTest->GetStopTime().c_str(),
|
2010-03-18 17:51:40 +00:00
|
|
|
tzone_offset);
|
2010-03-16 19:33:55 +00:00
|
|
|
|
|
|
|
time_t stop_time = curl_getdate(buf, ¤t_time);
|
|
|
|
if(stop_time == -1)
|
|
|
|
{
|
|
|
|
return timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
//the stop time refers to the next day
|
|
|
|
if(this->CTest->NextDayStopTime)
|
|
|
|
{
|
|
|
|
stop_time += 24*60*60;
|
|
|
|
}
|
2010-03-18 17:51:40 +00:00
|
|
|
int stop_timeout = (stop_time - current_time) % (24*60*60);
|
2010-03-16 19:33:55 +00:00
|
|
|
|
|
|
|
if(stop_timeout <= 0)
|
|
|
|
{
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "The stop time has been passed. "
|
|
|
|
"Exiting ctest." << std::endl);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2010-03-17 16:12:04 +00:00
|
|
|
#undef min
|
2010-03-18 17:51:40 +00:00
|
|
|
return timeout == 0 ? stop_timeout :
|
|
|
|
std::min(timeout, static_cast<double>(stop_timeout));
|
2010-03-16 19:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool cmCTestRunTest::ForkProcess(double testTimeOut,
|
2009-08-19 12:58:36 +00:00
|
|
|
std::vector<std::string>* environment)
|
|
|
|
{
|
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(
|
|
|
|
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
|
|
|
std::vector<std::string> origEnv;
|
2009-08-26 16:09:06 +00:00
|
|
|
this->ModifyEnv = (environment && environment->size()>0);
|
2009-08-19 12:58:36 +00:00
|
|
|
|
|
|
|
// determine how much time we have
|
|
|
|
double timeout = this->CTest->GetRemainingTimeAllowed() - 120;
|
2009-10-13 20:39:48 +00:00
|
|
|
if (this->CTest->GetTimeOut() > 0 && this->CTest->GetTimeOut() < timeout)
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
|
|
|
timeout = this->CTest->GetTimeOut();
|
|
|
|
}
|
2009-10-13 20:39:48 +00:00
|
|
|
if (testTimeOut > 0
|
2009-08-19 12:58:36 +00:00
|
|
|
&& testTimeOut < this->CTest->GetRemainingTimeAllowed())
|
|
|
|
{
|
|
|
|
timeout = testTimeOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
// always have at least 1 second if we got to here
|
|
|
|
if (timeout <= 0)
|
|
|
|
{
|
|
|
|
timeout = 1;
|
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index << ": "
|
|
|
|
<< "Test timeout computed to be: " << timeout << "\n");
|
2009-08-19 12:58:36 +00:00
|
|
|
|
2009-09-29 18:31:58 +00:00
|
|
|
this->TestProcess->SetTimeout(timeout);
|
|
|
|
|
2009-08-26 16:09:06 +00:00
|
|
|
if (this->ModifyEnv)
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-26 16:09:06 +00:00
|
|
|
this->OrigEnv = cmSystemTools::AppendEnv(environment);
|
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
|
|
|
{
|
2009-09-02 14:08:40 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
|
2009-08-28 15:08:39 +00:00
|
|
|
<< completed << "/");
|
2009-09-02 14:08:40 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
|
2009-08-28 15:08:39 +00:00
|
|
|
<< total << " ");
|
|
|
|
|
2009-08-26 16:09:06 +00:00
|
|
|
if ( this->TestHandler->MemCheck )
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-09-03 14:47:14 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "MemCheck");
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
else
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-09-01 15:58:04 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Test");
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
2009-08-28 15:08:39 +00:00
|
|
|
|
2009-08-28 15:40:34 +00:00
|
|
|
cmOStringStream indexStr;
|
2009-09-01 15:58:04 +00:00
|
|
|
indexStr << " #" << this->Index << ":";
|
2009-09-02 14:08:40 +00:00
|
|
|
cmCTestLog(this->CTest, HANDLER_OUTPUT,
|
|
|
|
std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
|
2009-08-28 15:08:39 +00:00
|
|
|
<< indexStr.str().c_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 << "/"
|
2009-08-26 16:09:06 +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 << "/"
|
2009-08-26 16:09:06 +00:00
|
|
|
<< this->TestHandler->TotalNumberOfTests
|
|
|
|
<< " Test: " << this->TestProperties->Name.c_str() << std::endl;
|
2009-08-28 15:08:39 +00:00
|
|
|
*this->TestHandler->LogFile << "Command: \"" << this->ActualCommand << "\"";
|
|
|
|
|
|
|
|
for (std::vector<std::string>::iterator i = this->Arguments.begin();
|
|
|
|
i != this->Arguments.end(); ++i)
|
2009-08-19 12:58:36 +00:00
|
|
|
{
|
2009-08-28 15:08:39 +00:00
|
|
|
*this->TestHandler->LogFile
|
|
|
|
<< " \"" << i->c_str() << "\"";
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|
2009-08-26 16:09:06 +00:00
|
|
|
*this->TestHandler->LogFile << std::endl
|
|
|
|
<< "Directory: " << this->TestProperties->Directory << std::endl
|
|
|
|
<< "\"" << this->TestProperties->Name.c_str() << "\" 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;
|
|
|
|
*this->TestHandler->LogFile
|
|
|
|
<< this->ProcessOutput.c_str() << "<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());
|
2009-08-26 16:09:06 +00:00
|
|
|
cmCTestLog(this->CTest, DEBUG, "Testing "
|
|
|
|
<< this->TestProperties->Name.c_str() << " ... ");
|
2009-08-19 12:58:36 +00:00
|
|
|
}
|