CMake/Source/CTest/cmCTestTestHandler.cxx

2318 lines
68 KiB
C++
Raw Normal View History

2004-09-09 16:41:05 +04:00
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
2006-03-09 19:17:10 +03:00
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
2004-09-09 16:41:05 +04:00
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmCTestTestHandler.h"
2008-07-03 17:31:33 +04:00
#include "cmCTestMultiProcessHandler.h"
2004-09-09 16:41:05 +04:00
#include "cmCTest.h"
#include "cmake.h"
#include "cmGeneratedFileStream.h"
2004-09-09 16:41:05 +04:00
#include <cmsys/Process.h>
#include <cmsys/RegularExpression.hxx>
#include <cmsys/Base64.h>
#include "cmMakefile.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmCommand.h"
#include "cmSystemTools.h"
2004-09-09 16:41:05 +04:00
2006-03-09 19:17:10 +03:00
#include <stdlib.h>
2004-09-09 18:52:51 +04:00
#include <math.h>
#include <float.h>
#include <memory> // auto_ptr
2008-01-19 23:09:36 +03:00
//----------------------------------------------------------------------
class cmCTestSubdirCommand : public cmCommand
{
public:
/**
* This is a virtual constructor for the command.
*/
virtual cmCommand* Clone()
{
cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
c->TestHandler = this->TestHandler;
return c;
}
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
virtual bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus &);
2008-01-19 23:09:36 +03:00
/**
* The name of the command as specified in CMakeList.txt.
*/
virtual const char* GetName() { return "subdirs";}
// Unused methods
virtual const char* GetTerseDocumentation() { return ""; }
virtual const char* GetFullDocumentation() { return ""; }
cmTypeMacro(cmCTestSubdirCommand, cmCommand);
cmCTestTestHandler* TestHandler;
};
//----------------------------------------------------------------------
bool cmCTestSubdirCommand
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
2008-01-19 23:09:36 +03:00
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
std::vector<std::string>::const_iterator it;
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
for ( it = args.begin(); it != args.end(); ++ it )
{
cmSystemTools::ChangeDirectory(cwd.c_str());
std::string fname = cwd;
fname += "/";
fname += *it;
if ( !cmSystemTools::FileExists(fname.c_str()) )
{
// No subdirectory? So what...
continue;
}
cmSystemTools::ChangeDirectory(fname.c_str());
const char* testFilename;
if( cmSystemTools::FileExists("CTestTestfile.cmake") )
{
// does the CTestTestfile.cmake exist ?
testFilename = "CTestTestfile.cmake";
}
else if( cmSystemTools::FileExists("DartTestfile.txt") )
{
// does the DartTestfile.txt exist ?
testFilename = "DartTestfile.txt";
}
2008-01-19 23:09:36 +03:00
else
{
// No CTestTestfile? Who cares...
cmSystemTools::ChangeDirectory(cwd.c_str());
continue;
}
fname += "/";
fname += testFilename;
bool readit =
this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),
fname.c_str());
cmSystemTools::ChangeDirectory(cwd.c_str());
if(!readit)
{
std::string m = "Could not find include file: ";
m += fname;
this->SetError(m.c_str());
return false;
}
}
return true;
}
//----------------------------------------------------------------------
class cmCTestAddSubdirectoryCommand : public cmCommand
{
public:
/**
* This is a virtual constructor for the command.
*/
2006-03-09 19:17:10 +03:00
virtual cmCommand* Clone()
{
cmCTestAddSubdirectoryCommand* c = new cmCTestAddSubdirectoryCommand;
2006-03-10 23:03:09 +03:00
c->TestHandler = this->TestHandler;
return c;
}
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
virtual bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus &);
/**
* The name of the command as specified in CMakeList.txt.
*/
virtual const char* GetName() { return "add_subdirectory";}
// Unused methods
virtual const char* GetTerseDocumentation() { return ""; }
virtual const char* GetFullDocumentation() { return ""; }
cmTypeMacro(cmCTestAddSubdirectoryCommand, cmCommand);
2006-03-10 23:03:09 +03:00
cmCTestTestHandler* TestHandler;
};
//----------------------------------------------------------------------
bool cmCTestAddSubdirectoryCommand
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
2006-03-09 19:17:10 +03:00
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
cmSystemTools::ChangeDirectory(cwd.c_str());
std::string fname = cwd;
fname += "/";
fname += args[1];
2006-03-09 19:17:10 +03:00
if ( !cmSystemTools::FileExists(fname.c_str()) )
{
// No subdirectory? So what...
return true;
}
cmSystemTools::ChangeDirectory(fname.c_str());
const char* testFilename;
if( cmSystemTools::FileExists("CTestTestfile.cmake") )
{
// does the CTestTestfile.cmake exist ?
testFilename = "CTestTestfile.cmake";
}
else if( cmSystemTools::FileExists("DartTestfile.txt") )
{
// does the DartTestfile.txt exist ?
testFilename = "DartTestfile.txt";
}
else
{
// No CTestTestfile? Who cares...
cmSystemTools::ChangeDirectory(cwd.c_str());
return true;
}
fname += "/";
fname += testFilename;
bool readit =
this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),
fname.c_str());
cmSystemTools::ChangeDirectory(cwd.c_str());
if(!readit)
{
std::string m = "Could not find include file: ";
m += fname;
this->SetError(m.c_str());
return false;
}
return true;
}
//----------------------------------------------------------------------
class cmCTestAddTestCommand : public cmCommand
{
public:
/**
* This is a virtual constructor for the command.
*/
2006-03-09 19:17:10 +03:00
virtual cmCommand* Clone()
{
cmCTestAddTestCommand* c = new cmCTestAddTestCommand;
2006-03-10 23:03:09 +03:00
c->TestHandler = this->TestHandler;
return c;
}
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
virtual bool InitialPass(std::vector<std::string> const&,
cmExecutionStatus &);
/**
* The name of the command as specified in CMakeList.txt.
*/
virtual const char* GetName() { return "ADD_TEST";}
// Unused methods
virtual const char* GetTerseDocumentation() { return ""; }
virtual const char* GetFullDocumentation() { return ""; }
cmTypeMacro(cmCTestAddTestCommand, cmCommand);
2006-03-10 23:03:09 +03:00
cmCTestTestHandler* TestHandler;
};
//----------------------------------------------------------------------
bool cmCTestAddTestCommand
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
{
if ( args.size() < 2 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
2006-03-10 23:03:09 +03:00
return this->TestHandler->AddTest(args);
}
//----------------------------------------------------------------------
class cmCTestSetTestsPropertiesCommand : public cmCommand
{
public:
/**
* This is a virtual constructor for the command.
*/
2006-03-09 19:17:10 +03:00
virtual cmCommand* Clone()
{
2006-03-09 19:17:10 +03:00
cmCTestSetTestsPropertiesCommand* c
= new cmCTestSetTestsPropertiesCommand;
2006-03-10 23:03:09 +03:00
c->TestHandler = this->TestHandler;
return c;
}
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
virtual bool InitialPass(std::vector<std::string> const&,
cmExecutionStatus &);
/**
* The name of the command as specified in CMakeList.txt.
*/
virtual const char* GetName() { return "SET_TESTS_PROPERTIES";}
// Unused methods
virtual const char* GetTerseDocumentation() { return ""; }
virtual const char* GetFullDocumentation() { return ""; }
cmTypeMacro(cmCTestSetTestsPropertiesCommand, cmCommand);
2006-03-10 23:03:09 +03:00
cmCTestTestHandler* TestHandler;
};
//----------------------------------------------------------------------
bool cmCTestSetTestsPropertiesCommand
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
{
2006-03-10 23:03:09 +03:00
return this->TestHandler->SetTestsProperties(args);
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
// get the next number in a string with numbers separated by ,
// pos is the start of the search and pos2 is the end of the search
2006-03-09 19:17:10 +03:00
// pos becomes pos2 after a call to GetNextNumber.
2004-09-09 16:41:05 +04:00
// -1 is returned at the end of the list.
2006-03-09 19:17:10 +03:00
inline int GetNextNumber(std::string const& in,
2004-09-09 16:41:05 +04:00
int& val,
std::string::size_type& pos,
std::string::size_type& pos2)
{
pos2 = in.find(',', pos);
if(pos2 != in.npos)
{
if(pos2-pos == 0)
{
val = -1;
}
else
{
val = atoi(in.substr(pos, pos2-pos).c_str());
}
pos = pos2+1;
return 1;
}
else
{
if(in.size()-pos == 0)
{
val = -1;
}
else
{
val = atoi(in.substr(pos, in.size()-pos).c_str());
}
return 0;
}
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
// get the next number in a string with numbers separated by ,
// pos is the start of the search and pos2 is the end of the search
2006-03-09 19:17:10 +03:00
// pos becomes pos2 after a call to GetNextNumber.
2004-09-09 16:41:05 +04:00
// -1 is returned at the end of the list.
2006-03-09 19:17:10 +03:00
inline int GetNextRealNumber(std::string const& in,
2004-09-09 16:41:05 +04:00
double& val,
std::string::size_type& pos,
std::string::size_type& pos2)
{
pos2 = in.find(',', pos);
if(pos2 != in.npos)
{
if(pos2-pos == 0)
{
val = -1;
}
else
{
val = atof(in.substr(pos, pos2-pos).c_str());
}
pos = pos2+1;
return 1;
}
else
{
if(in.size()-pos == 0)
{
val = -1;
}
else
{
val = atof(in.substr(pos, in.size()-pos).c_str());
}
return 0;
}
}
2006-03-09 19:17:10 +03:00
2004-09-09 16:41:05 +04:00
//----------------------------------------------------------------------
cmCTestTestHandler::cmCTestTestHandler()
{
2006-03-10 23:03:09 +03:00
this->UseUnion = false;
2006-03-09 19:17:10 +03:00
2006-03-10 23:03:09 +03:00
this->UseIncludeRegExpFlag = false;
this->UseExcludeRegExpFlag = false;
this->UseExcludeRegExpFirst = false;
2006-03-10 23:03:09 +03:00
this->CustomMaximumPassedTestOutputSize = 1 * 1024;
this->CustomMaximumFailedTestOutputSize = 300 * 1024;
2006-03-09 19:17:10 +03:00
2006-03-10 23:03:09 +03:00
this->MemCheck = false;
2006-03-10 23:03:09 +03:00
this->LogFile = 0;
2005-08-18 21:50:16 +04:00
2006-03-10 23:03:09 +03:00
this->DartStuff.compile("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
2004-09-09 16:41:05 +04:00
}
//----------------------------------------------------------------------
void cmCTestTestHandler::Initialize()
{
this->Superclass::Initialize();
2006-03-10 23:03:09 +03:00
this->ElapsedTestingTime = -1;
2006-03-10 23:03:09 +03:00
this->TestResults.clear();
2006-03-10 23:03:09 +03:00
this->CustomTestsIgnore.clear();
this->StartTest = "";
this->EndTest = "";
2006-03-10 23:03:09 +03:00
this->CustomPreTest.clear();
this->CustomPostTest.clear();
this->CustomMaximumPassedTestOutputSize = 1 * 1024;
this->CustomMaximumFailedTestOutputSize = 300 * 1024;
2006-03-10 23:03:09 +03:00
this->TestsToRun.clear();
2006-03-10 23:03:09 +03:00
this->UseIncludeRegExpFlag = false;
this->UseExcludeRegExpFlag = false;
this->UseExcludeRegExpFirst = false;
this->IncludeRegExp = "";
this->ExcludeRegExp = "";
TestsToRunString = "";
2006-03-10 23:03:09 +03:00
this->UseUnion = false;
this->TestList.clear();
}
2004-09-09 16:41:05 +04:00
//----------------------------------------------------------------------
void cmCTestTestHandler::PopulateCustomVectors(cmMakefile *mf)
{
this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST",
2006-03-10 23:03:09 +03:00
this->CustomPreTest);
this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST",
2006-03-10 23:03:09 +03:00
this->CustomPostTest);
this->CTest->PopulateCustomVector(mf,
2006-03-09 19:17:10 +03:00
"CTEST_CUSTOM_TESTS_IGNORE",
2006-03-10 23:03:09 +03:00
this->CustomTestsIgnore);
this->CTest->PopulateCustomInteger(mf,
2006-03-09 19:17:10 +03:00
"CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE",
2006-03-10 23:03:09 +03:00
this->CustomMaximumPassedTestOutputSize);
this->CTest->PopulateCustomInteger(mf,
2006-03-09 19:17:10 +03:00
"CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE",
2006-03-10 23:03:09 +03:00
this->CustomMaximumFailedTestOutputSize);
2004-09-09 16:41:05 +04:00
}
//----------------------------------------------------------------------
2005-01-27 23:54:47 +03:00
int cmCTestTestHandler::PreProcessHandler()
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
if ( !this->ExecuteCommands(this->CustomPreTest) )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
2006-03-09 19:17:10 +03:00
"Problem executing pre-test command(s)." << std::endl);
2005-01-27 23:54:47 +03:00
return 0;
2004-09-09 16:41:05 +04:00
}
2005-01-27 23:54:47 +03:00
return 1;
}
2004-09-09 16:41:05 +04:00
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
int cmCTestTestHandler::PostProcessHandler()
{
2006-03-10 23:03:09 +03:00
if ( !this->ExecuteCommands(this->CustomPostTest) )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
2006-03-09 19:17:10 +03:00
"Problem executing post-test command(s)." << std::endl);
2005-01-27 23:54:47 +03:00
return 0;
2004-09-09 16:41:05 +04:00
}
2005-01-27 23:54:47 +03:00
return 1;
}
//----------------------------------------------------------------------
//clearly it would be nice if this were broken up into a few smaller
//functions and commented...
int cmCTestTestHandler::ProcessHandler()
{
2005-02-18 00:11:10 +03:00
// Update internal data structure from generic one
this->SetTestsToRunInformation(this->GetOption("TestsToRunInformation"));
this->SetUseUnion(cmSystemTools::IsOn(this->GetOption("UseUnion")));
const char* val;
val = this->GetOption("IncludeRegularExpression");
if ( val )
{
this->UseIncludeRegExp();
this->SetIncludeRegExp(val);
}
val = this->GetOption("ExcludeRegularExpression");
if ( val )
{
this->UseExcludeRegExp();
this->SetExcludeRegExp(val);
}
2006-03-10 23:03:09 +03:00
this->TestResults.clear();
2008-07-03 17:31:33 +04:00
// do not output startup if this is a sub-process for parallel tests
if(!this->CTest->GetParallelSubprocess())
{
cmCTestLog(this->CTest, HANDLER_OUTPUT,
(this->MemCheck ? "Memory check" : "Test")
<< " project " << cmSystemTools::GetCurrentWorkingDirectory()
<< std::endl);
}
2005-01-27 23:54:47 +03:00
if ( ! this->PreProcessHandler() )
2004-09-09 16:41:05 +04:00
{
2005-01-27 23:54:47 +03:00
return -1;
2004-09-09 16:41:05 +04:00
}
2005-08-18 21:50:16 +04:00
cmGeneratedFileStream mLogFile;
this->StartLogFile((this->MemCheck ? "DynamicAnalysis" : "Test"), mLogFile);
2006-03-10 23:03:09 +03:00
this->LogFile = &mLogFile;
2005-08-18 21:50:16 +04:00
2004-09-09 16:41:05 +04:00
std::vector<cmStdString> passed;
std::vector<cmStdString> failed;
int total;
2005-01-27 23:54:47 +03:00
this->ProcessDirectory(passed, failed);
2004-09-09 16:41:05 +04:00
total = int(passed.size()) + int(failed.size());
if (total == 0)
{
2006-03-10 23:03:09 +03:00
if ( !this->CTest->GetShowOnly() )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, ERROR_MESSAGE, "No tests were found!!!"
2006-03-09 19:17:10 +03:00
<< std::endl);
2004-09-09 16:41:05 +04:00
}
}
else
{
2006-03-10 23:03:09 +03:00
if (this->HandlerVerbose && passed.size() &&
(this->UseIncludeRegExpFlag || this->UseExcludeRegExpFlag))
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
2006-03-09 19:17:10 +03:00
<< "The following tests passed:" << std::endl);
2004-09-09 16:41:05 +04:00
for(std::vector<cmStdString>::iterator j = passed.begin();
j != passed.end(); ++j)
2006-03-09 19:17:10 +03:00
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "\t" << *j
<< std::endl);
2004-09-09 16:41:05 +04:00
}
}
float percent = float(passed.size()) * 100.0f / total;
if ( failed.size() > 0 && percent > 99)
{
percent = 99;
}
2008-07-03 17:31:33 +04:00
if(!this->CTest->GetParallelSubprocess())
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
<< static_cast<int>(percent + .5) << "% tests passed, "
<< failed.size() << " tests failed out of "
<< total << std::endl);
}
2004-09-09 16:41:05 +04:00
2006-03-09 19:17:10 +03:00
if (failed.size())
2004-09-09 16:41:05 +04:00
{
cmGeneratedFileStream ofs;
2008-07-03 17:31:33 +04:00
if(!this->CTest->GetParallelSubprocess())
2004-09-09 16:41:05 +04:00
{
2008-07-03 17:31:33 +04:00
cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl
<< "The following tests FAILED:" << std::endl);
this->StartLogFile("TestsFailed", ofs);
std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator ftit;
for(ftit = this->TestResults.begin();
ftit != this->TestResults.end(); ++ftit)
2004-09-09 16:41:05 +04:00
{
2008-07-03 17:31:33 +04:00
if ( ftit->Status != cmCTestTestHandler::COMPLETED )
{
ofs << ftit->TestCount << ":" << ftit->Name << std::endl;
cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t" << std::setw(3)
<< ftit->TestCount << " - " << ftit->Name.c_str() << " ("
<< this->GetTestStatus(ftit->Status) << ")" << std::endl);
}
2004-09-09 16:41:05 +04:00
}
2008-07-03 17:31:33 +04:00
2004-09-09 16:41:05 +04:00
}
}
}
2006-03-10 23:03:09 +03:00
if ( this->CTest->GetProduceXML() )
2004-09-09 16:41:05 +04:00
{
cmGeneratedFileStream xmlfile;
2006-03-10 23:03:09 +03:00
if( !this->StartResultingXML(
(this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile) )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create "
<< (this->MemCheck ? "memory check" : "testing")
<< " XML file" << std::endl);
2006-03-10 23:03:09 +03:00
this->LogFile = 0;
2004-09-09 16:41:05 +04:00
return 1;
}
2005-01-27 23:54:47 +03:00
this->GenerateDartOutput(xmlfile);
2004-09-09 16:41:05 +04:00
}
2005-01-27 23:54:47 +03:00
if ( ! this->PostProcessHandler() )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
this->LogFile = 0;
2005-01-27 23:54:47 +03:00
return -1;
2004-09-09 16:41:05 +04:00
}
2005-01-27 23:54:47 +03:00
if ( !failed.empty() )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
this->LogFile = 0;
2005-01-27 23:54:47 +03:00
return -1;
2004-09-09 16:41:05 +04:00
}
2006-03-10 23:03:09 +03:00
this->LogFile = 0;
2005-01-27 23:54:47 +03:00
return 0;
2004-09-09 16:41:05 +04:00
}
2007-01-25 19:16:16 +03:00
//----------------------------------------------------------------------
void cmCTestTestHandler::ProcessOneTest(cmCTestTestProperties *it,
std::vector<cmStdString> &passed,
std::vector<cmStdString> &failed,
int cnt, int tmsize)
{
const std::string& testname = it->Name;
std::vector<std::string>& args = it->Args;
cmCTestTestResult cres;
cres.Properties = &*it;
cres.ExecutionTime = 0;
cres.ReturnValue = -1;
cres.Status = cmCTestTestHandler::NOT_RUN;
cres.TestCount = cnt;
cres.Name = testname;
cres.Path = it->Directory.c_str();
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << cnt << "/");
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << tmsize << " ");
if ( this->MemCheck )
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Memory Check");
}
else
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Testing");
}
cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
std::string outname = testname;
outname.resize(30, ' ');
*this->LogFile << cnt << "/" << tmsize << " Testing: " << testname
<< std::endl;
if ( this->CTest->GetShowOnly() )
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str() << std::endl);
}
else
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str());
}
cmCTestLog(this->CTest, DEBUG, "Testing " << args[0].c_str() << " ... ");
// find the test executable
std::string actualCommand = this->FindTheExecutable(args[1].c_str());
std::string testCommand
= cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
// continue if we did not find the executable
if (testCommand == "")
{
*this->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);
cres.Output = "Unable to find executable: " + args[1];
if ( !this->CTest->GetShowOnly() )
{
cres.FullCommandLine = actualCommand;
this->TestResults.push_back( cres );
failed.push_back(testname);
return;
}
}
// add the arguments
std::vector<std::string>::const_iterator j = args.begin();
2008-07-03 17:31:33 +04:00
++j; // skip test name
++j; // skip command as it is in actualCommand
2007-01-25 19:16:16 +03:00
std::vector<const char*> arguments;
this->GenerateTestCommand(arguments);
arguments.push_back(actualCommand.c_str());
for(;j != args.end(); ++j)
{
testCommand += " ";
testCommand += cmSystemTools::EscapeSpaces(j->c_str());
arguments.push_back(j->c_str());
}
arguments.push_back(0);
/**
* Run an executable command and put the stdout in output.
*/
std::string output;
int retVal = 0;
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
<< (this->MemCheck?"MemCheck":"Test")
<< " command: " << testCommand
<< std::endl);
*this->LogFile << cnt << "/" << tmsize
<< " Test: " << testname.c_str() << std::endl;
*this->LogFile << "Command: ";
std::vector<cmStdString>::size_type ll;
for ( ll = 0; ll < arguments.size()-1; ll ++ )
{
*this->LogFile << "\"" << arguments[ll] << "\" ";
}
*this->LogFile
<< std::endl
<< "Directory: " << it->Directory << std::endl
<< "\"" << testname.c_str() << "\" start time: "
<< this->CTest->CurrentTime() << std::endl
<< "Output:" << std::endl
<< "----------------------------------------------------------"
<< std::endl;
int res = 0;
double clock_start, clock_finish;
clock_start = cmSystemTools::GetTime();
if ( !this->CTest->GetShowOnly() )
{
res = this->CTest->RunTest(arguments, &output, &retVal, this->LogFile,
it->Timeout);
}
clock_finish = cmSystemTools::GetTime();
if ( this->LogFile )
{
double ttime = clock_finish - clock_start;
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->LogFile
<< "----------------------------------------------------------"
<< std::endl
<< "\"" << testname.c_str() << "\" end time: "
<< this->CTest->CurrentTime() << std::endl
<< "\"" << testname.c_str() << "\" time elapsed: "
<< buffer << std::endl
<< "----------------------------------------------------------"
<< std::endl << std::endl;
}
cres.ExecutionTime = (double)(clock_finish - clock_start);
cres.FullCommandLine = testCommand;
std::string reason;
2007-01-25 19:16:16 +03:00
if ( !this->CTest->GetShowOnly() )
{
bool testFailed = false;
2007-09-24 19:10:55 +04:00
std::vector<std::pair<cmsys::RegularExpression,
std::string> >::iterator passIt;
2007-01-25 19:16:16 +03:00
bool forceFail = false;
if ( it->RequiredRegularExpressions.size() > 0 )
{
bool found = false;
for ( passIt = it->RequiredRegularExpressions.begin();
passIt != it->RequiredRegularExpressions.end();
++ passIt )
{
if ( passIt->first.find(output.c_str()) )
2007-01-25 19:16:16 +03:00
{
found = true;
}
}
if ( !found )
{
reason = "Required regular expression not found.";
2007-11-08 21:03:37 +03:00
reason += "Regex=[";
for ( passIt = it->RequiredRegularExpressions.begin();
passIt != it->RequiredRegularExpressions.end();
++ passIt )
{
reason += passIt->second;
reason += "\n";
}
reason += "]";
2007-01-25 19:16:16 +03:00
forceFail = true;
}
}
if ( it->ErrorRegularExpressions.size() > 0 )
{
for ( passIt = it->ErrorRegularExpressions.begin();
passIt != it->ErrorRegularExpressions.end();
++ passIt )
{
if ( passIt->first.find(output.c_str()) )
2007-01-25 19:16:16 +03:00
{
reason = "Error regular expression found in output.";
reason += " Regex=[";
reason += passIt->second;
reason += "]";
2007-01-25 19:16:16 +03:00
forceFail = true;
}
}
}
if (res == cmsysProcess_State_Exited &&
(retVal == 0 || it->RequiredRegularExpressions.size()) &&
!forceFail)
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Passed");
if ( it->WillFail )
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, " - But it should fail!");
cres.Status = cmCTestTestHandler::FAILED;
testFailed = true;
}
2007-01-25 19:16:16 +03:00
else
{
cres.Status = cmCTestTestHandler::COMPLETED;
}
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
}
else
{
testFailed = true;
cres.Status = cmCTestTestHandler::FAILED;
if ( res == cmsysProcess_State_Expired )
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Timeout" << std::endl);
cres.Status = cmCTestTestHandler::TIMEOUT;
}
else if ( res == cmsysProcess_State_Exception )
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: ");
switch ( retVal )
{
case cmsysProcess_Exception_Fault:
cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault");
cres.Status = cmCTestTestHandler::SEGFAULT;
break;
case cmsysProcess_Exception_Illegal:
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Illegal");
cres.Status = cmCTestTestHandler::ILLEGAL;
break;
case cmsysProcess_Exception_Interrupt:
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Interrupt");
cres.Status = cmCTestTestHandler::INTERRUPT;
break;
case cmsysProcess_Exception_Numerical:
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Numerical");
cres.Status = cmCTestTestHandler::NUMERICAL;
break;
default:
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Other");
cres.Status = cmCTestTestHandler::OTHER_FAULT;
}
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
}
else if ( res == cmsysProcess_State_Error )
{
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Bad command " << res
<< std::endl);
cres.Status = cmCTestTestHandler::BAD_COMMAND;
}
else
{
// Force fail will also be here?
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Failed " << reason);
2007-01-25 19:16:16 +03:00
if ( it->WillFail )
{
cres.Status = cmCTestTestHandler::COMPLETED;
cmCTestLog(this->CTest, HANDLER_OUTPUT, " - supposed to fail");
testFailed = false;
}
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
}
}
if ( testFailed )
{
failed.push_back(testname);
}
else
{
passed.push_back(testname);
}
if (!output.empty() && output.find("<DartMeasurement") != output.npos)
{
if (this->DartStuff.find(output.c_str()))
{
std::string dartString = this->DartStuff.match(1);
cmSystemTools::ReplaceString(output, dartString.c_str(),"");
cres.RegressionImages
= this->GenerateRegressionImages(dartString);
}
}
}
// if this is doing MemCheck then all the output needs to be put into
// Output since that it what is parsed to by cmCTestMemCheckHandler
if(!this->MemCheck)
2007-01-25 19:16:16 +03:00
{
if ( cres.Status == cmCTestTestHandler::COMPLETED )
{
this->CleanTestOutput(output, static_cast<size_t>
(this->CustomMaximumPassedTestOutputSize));
}
else
{
this->CleanTestOutput(output, static_cast<size_t>
(this->CustomMaximumFailedTestOutputSize));
}
2007-01-25 19:16:16 +03:00
}
cres.Output = output;
cres.ReturnValue = retVal;
cres.CompletionStatus = "Completed";
this->TestResults.push_back( cres );
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2008-07-03 17:31:33 +04:00
void cmCTestTestHandler::ComputeTestList()
2004-09-09 16:41:05 +04:00
{
2008-07-03 17:31:33 +04:00
this->TestList.clear(); // clear list of test
if(this->CTest->GetParallelSubprocess())
{
this->LoadTestList();
return;
}
else
{
this->GetListOfTests();
}
2006-03-10 23:03:09 +03:00
cmCTestTestHandler::ListOfTests::size_type tmsize = this->TestList.size();
2004-09-09 16:41:05 +04:00
// how many tests are in based on RegExp?
int inREcnt = 0;
2006-03-10 23:03:09 +03:00
cmCTestTestHandler::ListOfTests::iterator it;
for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
{
2006-03-10 23:03:09 +03:00
if (it->IsInBasedOnREOptions)
{
inREcnt ++;
}
}
// expand the test list based on the union flag
2006-03-10 23:03:09 +03:00
if (this->UseUnion)
{
this->ExpandTestsToRunInformation((int)tmsize);
}
else
{
this->ExpandTestsToRunInformation(inREcnt);
}
2008-07-03 17:31:33 +04:00
// Now create a final list of tests to run
2004-09-09 16:41:05 +04:00
int cnt = 0;
inREcnt = 0;
2008-07-03 17:31:33 +04:00
std::string last_directory = "";
ListOfTests finalList;
2006-03-10 23:03:09 +03:00
for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
2004-09-09 16:41:05 +04:00
{
cnt ++;
2006-03-10 23:03:09 +03:00
if (it->IsInBasedOnREOptions)
{
inREcnt++;
}
2006-03-10 23:03:09 +03:00
if (this->UseUnion)
2004-09-09 16:41:05 +04:00
{
// if it is not in the list and not in the regexp then skip
2006-03-10 23:03:09 +03:00
if ((this->TestsToRun.size() &&
std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt)
== this->TestsToRun.end()) && !it->IsInBasedOnREOptions)
{
continue;
}
2004-09-09 16:41:05 +04:00
}
else
{
// is this test in the list of tests to run? If not then skip it
2006-03-10 23:03:09 +03:00
if ((this->TestsToRun.size() &&
std::find(this->TestsToRun.begin(),
2007-01-25 19:16:16 +03:00
this->TestsToRun.end(), inREcnt)
2006-03-10 23:03:09 +03:00
== this->TestsToRun.end()) || !it->IsInBasedOnREOptions)
{
continue;
}
}
2008-07-03 17:31:33 +04:00
it->Index = cnt; // save the index into the test list for this test
finalList.push_back(*it);
}
// Save the total number of tests before exclusions
this->TotalNumberOfTests = this->TestList.size();
// Set the TestList to the final list of all test
this->TestList = finalList;
}
bool cmCTestTestHandler::GetValue(const char* tag,
int& value,
std::ifstream& fin)
{
std::string line;
2008-07-04 18:10:30 +04:00
bool ret = true;
2008-07-03 17:31:33 +04:00
cmSystemTools::GetLineFromStream(fin, line);
if(line == tag)
{
fin >> value;
2008-07-04 18:10:30 +04:00
ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
2008-07-03 17:31:33 +04:00
}
else
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"parse error: missing tag: "
<< tag << " found [" << line << "]" << std::endl);
2008-07-04 18:10:30 +04:00
ret = false;
2008-07-03 17:31:33 +04:00
}
2008-07-04 18:10:30 +04:00
return ret;
2008-07-03 17:31:33 +04:00
}
bool cmCTestTestHandler::GetValue(const char* tag,
double& value,
std::ifstream& fin)
{
std::string line;
cmSystemTools::GetLineFromStream(fin, line);
2008-07-04 18:10:30 +04:00
bool ret = true;
2008-07-03 17:31:33 +04:00
if(line == tag)
{
fin >> value;
2008-07-04 18:10:30 +04:00
ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
2008-07-03 17:31:33 +04:00
}
else
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"parse error: missing tag: "
<< tag << " found [" << line << "]" << std::endl);
2008-07-04 18:10:30 +04:00
ret = false;
2008-07-03 17:31:33 +04:00
}
2008-07-04 18:10:30 +04:00
return ret;
2008-07-03 17:31:33 +04:00
}
bool cmCTestTestHandler::GetValue(const char* tag,
bool& value,
std::ifstream& fin)
{
std::string line;
cmSystemTools::GetLineFromStream(fin, line);
2008-07-04 18:10:30 +04:00
bool ret = true;
2008-07-03 17:31:33 +04:00
if(line == tag)
{
fin >> value;
2008-07-04 18:10:30 +04:00
ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
2008-07-03 17:31:33 +04:00
}
else
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"parse error: missing tag: "
<< tag << " found [" << line << "]" << std::endl);
2008-07-04 18:10:30 +04:00
ret = false;
2008-07-03 17:31:33 +04:00
}
2008-07-04 18:10:30 +04:00
return ret;
2008-07-03 17:31:33 +04:00
}
bool cmCTestTestHandler::GetValue(const char* tag,
size_t& value,
std::ifstream& fin)
{
std::string line;
cmSystemTools::GetLineFromStream(fin, line);
2008-07-04 18:10:30 +04:00
bool ret = true;
2008-07-03 17:31:33 +04:00
if(line == tag)
{
fin >> value;
2008-07-04 18:10:30 +04:00
ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
2008-07-03 17:31:33 +04:00
}
else
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"parse error: missing tag: "
<< tag << " found [" << line.c_str() << "]" << std::endl);
2008-07-04 18:10:30 +04:00
ret = false;
2008-07-03 17:31:33 +04:00
}
2008-07-04 18:10:30 +04:00
return ret;
2008-07-03 17:31:33 +04:00
}
bool cmCTestTestHandler::GetValue(const char* tag,
std::string& value,
std::ifstream& fin)
{
std::string line;
cmSystemTools::GetLineFromStream(fin, line);
2008-07-04 18:10:30 +04:00
bool ret = true;
2008-07-03 17:31:33 +04:00
if(line == tag)
{
2008-07-04 18:10:30 +04:00
ret = cmSystemTools::GetLineFromStream(fin, value);
2008-07-03 17:31:33 +04:00
}
else
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"parse error: missing tag: "
<< tag << " found [" << line << "]" << std::endl);
2008-07-04 18:10:30 +04:00
ret = false;
2008-07-03 17:31:33 +04:00
}
2008-07-04 18:10:30 +04:00
return ret;
2008-07-03 17:31:33 +04:00
}
// This should load only one test and is used in -j N mode.
// it is used by the sub-process ctest runs which should have
// only one -I N test to run.
void cmCTestTestHandler::LoadTestList()
{
this->TestList.clear();
std::string fname = this->CTest->GetBinaryDir()
+ "/Testing/Temporary/PCache.txt";
std::ifstream fin(fname.c_str());
std::string line;
if(!fin)
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Could not load PCache.txt file: "
<< fname.c_str() << std::endl);
return;
}
bool ok = true;
2008-07-04 17:55:26 +04:00
int numTestsToRun = 0;
2008-07-03 17:31:33 +04:00
ok = ok && this->GetValue("TotalNumberOfTests:",
this->TotalNumberOfTests, fin);
ok = ok && this->GetValue("NumberOfTestsToRun:", numTestsToRun, fin);
this->ExpandTestsToRunInformation(this->TotalNumberOfTests);
if(this->TestsToRun.size() != 1)
{
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Error when in parallel mode only one test should be run: "
<< this->TestsToRun.size() << std::endl);
}
int testIndexToRun = this->TestsToRun[0];
this->CTest->SetParallelSubprocessId(testIndexToRun);
if(!ok)
{
return;
}
for(int i =0; i < numTestsToRun; i++)
{
cmCTestTestProperties p;
2008-07-07 03:58:38 +04:00
int numArgs = 0;
2008-07-04 17:50:32 +04:00
ok = this->GetValue("Name:", p.Name, fin);
2008-07-03 17:31:33 +04:00
ok = ok && this->GetValue("Directory:", p.Directory, fin);
ok = ok && this->GetValue("Args:", numArgs, fin);
for(int j =0; j < numArgs; ++j)
{
cmSystemTools::GetLineFromStream(fin, line);
p.Args.push_back(line);
}
int numDep = 0;
ok = ok && this->GetValue("Depends:", numDep, fin);
for(int j =0; j < numDep; ++j)
{
cmSystemTools::GetLineFromStream(fin, line);
p.Depends.push_back(line);
}
int isinre;
ok = ok && this->GetValue("IsInBasedOnREOptions:", isinre, fin);
ok = ok && this->GetValue("WillFail:", p.WillFail, fin);
ok = ok && this->GetValue("TimeOut:", p.Timeout, fin);
ok = ok && this->GetValue("Index:", p.Index, fin);
if(!ok)
{
return;
}
if(p.Index == testIndexToRun)
{
// add the one test and stop reading
this->TestList.push_back(p);
return;
}
}
}
std::string cmCTestTestHandler::SaveTestList()
{
std::string fname = this->CTest->GetBinaryDir()
+ "/Testing/Temporary/PCache.txt";
cmGeneratedFileStream fout(fname.c_str());
if(!fout)
{
cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl
<< "Could not open PCache.txt for write:"
<< fname.c_str()
<< std::endl);
}
fout << "TotalNumberOfTests:\n";
fout << this->TotalNumberOfTests << "\n";
fout << "NumberOfTestsToRun:\n";
fout << this->TestList.size() << "\n";
for (ListOfTests::iterator it = this->TestList.begin();
it != this->TestList.end(); it ++ )
{
cmCTestTestProperties& p = *it;
fout << "Name:\n"
<< p.Name.c_str()
<< "\nDirectory:\n"
<< p.Directory.c_str()
<< "\nArgs:\n"
<< p.Args.size() << "\n";
for(std::vector<std::string>::iterator i = p.Args.begin();
i != p.Args.end(); ++i)
{
fout << i->c_str() << "\n";
}
fout << "Depends:\n" << p.Depends.size() << "\n";
for(std::vector<std::string>::iterator i = p.Depends.begin();
i != p.Depends.end(); ++i)
{
fout << i->c_str() << "\n";
}
fout << "IsInBasedOnREOptions:\n"
<< p.IsInBasedOnREOptions
<< "\nWillFail:\n"
<< p.WillFail
<< "\nTimeOut:\n"
<< p.Timeout
<< "\nIndex:\n"
<< p.Index << "\n";
}
fout.close();
return fname;
}
void cmCTestTestHandler::ProcessParallel(std::vector<cmStdString> &passed,
std::vector<cmStdString> &failed)
{
this->ComputeTestList();
cmCTestMultiProcessHandler parallel;
parallel.SetCTest(this->CTest);
parallel.SetParallelLevel(this->CTest->GetParallelLevel());
cmCTestMultiProcessHandler::TestSet depends;
cmCTestMultiProcessHandler::TestMap tests;
2008-07-03 17:31:33 +04:00
std::map<int, cmStdString> testnames;
for (ListOfTests::iterator it = this->TestList.begin();
it != this->TestList.end(); it ++ )
{
cmCTestTestProperties& p = *it;
testnames[p.Index] = p.Name;
if(p.Depends.size())
{
for(std::vector<std::string>::iterator i = p.Depends.begin();
i != p.Depends.end(); ++i)
{
for(ListOfTests::iterator it2 = this->TestList.begin();
it2 != this->TestList.end(); it2 ++ )
{
if(it2->Name == *i)
{
depends.insert(it2->Index);
break; // break out of test loop as name can only match 1
}
}
}
}
tests[it->Index] = depends;
}
parallel.SetCTestCommand(this->CTest->GetCTestExecutable());
parallel.SetTests(tests, testnames);
std::string fname = this->SaveTestList();
parallel.SetTestCacheFile(fname.c_str());
parallel.SetPassFailVectors(&passed, &failed);
this->TestResults.clear();
parallel.SetTestResults(&this->TestResults);
parallel.RunTests();
cmSystemTools::RemoveFile(fname.c_str());
}
//----------------------------------------------------------------------
void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
std::vector<cmStdString> &failed)
{
if(this->CTest->GetParallelLevel() > 0)
{
this->ProcessParallel(passed, failed);
return;
}
// save the current working directory
std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
// compute the list of tests to run
this->ComputeTestList();
this->StartTest = this->CTest->CurrentTime();
this->StartTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
double elapsed_time_start = cmSystemTools::GetTime();
*this->LogFile << "Start testing: " << this->StartTest << std::endl
<< "----------------------------------------------------------"
<< std::endl;
std::string last_directory = "";
// run each test
for (ListOfTests::iterator it = this->TestList.begin();
it != this->TestList.end(); it ++ )
{
if (!(last_directory == it->Directory))
{
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Changing directory into " << it->Directory.c_str() << "\n");
*this->LogFile << "Changing directory into: " << it->Directory.c_str()
<< std::endl;
last_directory = it->Directory;
cmSystemTools::ChangeDirectory(it->Directory.c_str());
}
2007-01-25 19:16:16 +03:00
// process this one test
2008-07-03 17:31:33 +04:00
this->ProcessOneTest(&(*it), passed, failed, it->Index,
static_cast<int>(this->TotalNumberOfTests));
2004-09-09 16:41:05 +04:00
}
2006-03-10 23:03:09 +03:00
this->EndTest = this->CTest->CurrentTime();
2008-01-30 19:54:55 +03:00
this->EndTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
2006-03-10 23:03:09 +03:00
this->ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
if ( this->LogFile )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
*this->LogFile << "End testing: " << this->EndTest << std::endl;
2004-09-09 16:41:05 +04:00
}
cmSystemTools::ChangeDirectory(current_dir.c_str());
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
void cmCTestTestHandler::GenerateTestCommand(std::vector<const char*>&)
2004-09-09 16:41:05 +04:00
{
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
if ( !this->CTest->GetProduceXML() )
2004-09-09 16:41:05 +04:00
{
return;
}
2006-03-10 23:03:09 +03:00
this->CTest->StartXML(os);
2004-09-09 16:41:05 +04:00
os << "<Testing>\n"
2006-03-10 23:03:09 +03:00
<< "\t<StartDateTime>" << this->StartTest << "</StartDateTime>\n"
<< "\t<StartTestTime>" << this->StartTestTime << "</StartTestTime>\n"
2004-09-09 16:41:05 +04:00
<< "\t<TestList>\n";
2006-03-10 23:03:09 +03:00
cmCTestTestHandler::TestResultsVector::size_type cc;
for ( cc = 0; cc < this->TestResults.size(); cc ++ )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
cmCTestTestResult *result = &this->TestResults[cc];
std::string testPath = result->Path + "/" + result->Name;
2004-10-18 06:47:15 +04:00
os << "\t\t<Test>" << cmCTest::MakeXMLSafe(
2006-03-10 23:03:09 +03:00
this->CTest->GetShortPathToFile(testPath.c_str()))
2004-09-09 16:41:05 +04:00
<< "</Test>" << std::endl;
}
os << "\t</TestList>\n";
2006-03-10 23:03:09 +03:00
for ( cc = 0; cc < this->TestResults.size(); cc ++ )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
cmCTestTestResult *result = &this->TestResults[cc];
2004-09-09 16:41:05 +04:00
os << "\t<Test Status=\"";
2006-03-10 23:03:09 +03:00
if ( result->Status == cmCTestTestHandler::COMPLETED )
2004-09-09 16:41:05 +04:00
{
os << "passed";
}
2006-03-10 23:03:09 +03:00
else if ( result->Status == cmCTestTestHandler::NOT_RUN )
2004-09-09 16:41:05 +04:00
{
os << "notrun";
}
else
{
os << "failed";
}
2006-03-10 23:03:09 +03:00
std::string testPath = result->Path + "/" + result->Name;
2004-09-09 16:41:05 +04:00
os << "\">\n"
2006-03-10 23:03:09 +03:00
<< "\t\t<Name>" << cmCTest::MakeXMLSafe(result->Name) << "</Name>\n"
2004-10-18 06:47:15 +04:00
<< "\t\t<Path>" << cmCTest::MakeXMLSafe(
2006-03-10 23:03:09 +03:00
this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
2004-10-18 06:47:15 +04:00
<< "\t\t<FullName>" << cmCTest::MakeXMLSafe(
2006-03-10 23:03:09 +03:00
this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
2006-03-09 19:17:10 +03:00
<< "\t\t<FullCommandLine>"
2006-03-10 23:03:09 +03:00
<< cmCTest::MakeXMLSafe(result->FullCommandLine)
2004-09-09 16:41:05 +04:00
<< "</FullCommandLine>\n"
<< "\t\t<Results>" << std::endl;
2006-03-10 23:03:09 +03:00
if ( result->Status != cmCTestTestHandler::NOT_RUN )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
if ( result->Status != cmCTestTestHandler::COMPLETED ||
result->ReturnValue )
2004-09-09 16:41:05 +04:00
{
2006-03-09 19:17:10 +03:00
os << "\t\t\t<NamedMeasurement type=\"text/string\" "
"name=\"Exit Code\"><Value>"
2006-03-10 23:03:09 +03:00
<< this->GetTestStatus(result->Status) << "</Value>"
2006-03-09 19:17:10 +03:00
"</NamedMeasurement>\n"
<< "\t\t\t<NamedMeasurement type=\"text/string\" "
"name=\"Exit Value\"><Value>"
2006-03-10 23:03:09 +03:00
<< result->ReturnValue << "</Value></NamedMeasurement>"
2006-03-09 19:17:10 +03:00
<< std::endl;
2004-09-09 16:41:05 +04:00
}
2006-03-10 23:03:09 +03:00
os << result->RegressionImages;
2004-09-09 16:41:05 +04:00
os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
<< "name=\"Execution Time\"><Value>"
2006-03-10 23:03:09 +03:00
<< result->ExecutionTime << "</Value></NamedMeasurement>\n";
2006-03-09 19:17:10 +03:00
os
2004-09-09 16:41:05 +04:00
<< "\t\t\t<NamedMeasurement type=\"text/string\" "
<< "name=\"Completion Status\"><Value>"
2006-03-10 23:03:09 +03:00
<< result->CompletionStatus << "</Value></NamedMeasurement>\n";
2004-09-09 16:41:05 +04:00
}
os
<< "\t\t\t<NamedMeasurement type=\"text/string\" "
<< "name=\"Command Line\"><Value>"
<< result->FullCommandLine << "</Value></NamedMeasurement>\n";
std::map<cmStdString,cmStdString>::iterator measureIt;
for ( measureIt = result->Properties->Measurements.begin();
measureIt != result->Properties->Measurements.end();
++ measureIt )
{
os
<< "\t\t\t<NamedMeasurement type=\"text/string\" "
<< "name=\"" << measureIt->first.c_str() << "\"><Value>"
<< measureIt->second.c_str() << "</Value></NamedMeasurement>\n";
}
2006-03-09 19:17:10 +03:00
os
2004-09-09 16:41:05 +04:00
<< "\t\t\t<Measurement>\n"
<< "\t\t\t\t<Value>";
2006-03-10 23:03:09 +03:00
os << cmCTest::MakeXMLSafe(result->Output);
2004-09-09 16:41:05 +04:00
os
<< "</Value>\n"
<< "\t\t\t</Measurement>\n"
<< "\t\t</Results>\n"
<< "\t</Test>" << std::endl;
}
2006-03-10 23:03:09 +03:00
os << "\t<EndDateTime>" << this->EndTest << "</EndDateTime>\n"
<< "\t<EndTestTime>" << this->EndTestTime << "</EndTestTime>\n"
2006-03-09 19:17:10 +03:00
<< "<ElapsedMinutes>"
2006-03-10 23:03:09 +03:00
<< static_cast<int>(this->ElapsedTestingTime/6)/10.0
2004-09-09 16:41:05 +04:00
<< "</ElapsedMinutes>"
<< "</Testing>" << std::endl;
2006-03-10 23:03:09 +03:00
this->CTest->EndXML(os);
2004-09-09 16:41:05 +04:00
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
{
std::vector<cmStdString>::iterator it;
for ( it = vec.begin(); it != vec.end(); ++it )
{
int retVal = 0;
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it
2006-03-09 19:17:10 +03:00
<< std::endl);
if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true
2006-03-10 23:03:09 +03:00
/*this->Verbose*/) || retVal != 0 )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem running command: "
<< *it << std::endl);
2004-09-09 16:41:05 +04:00
return 0;
}
}
return 1;
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
// Find the appropriate executable to run for a test
2004-09-09 16:41:05 +04:00
std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
{
std::string resConfig;
std::vector<std::string> extraPaths;
std::vector<std::string> failedPaths;
return cmCTestTestHandler::FindExecutable(this->CTest,
exe, resConfig,
extraPaths,
failedPaths);
}
2004-09-09 16:41:05 +04:00
// add additional configurations to the search path
void cmCTestTestHandler
::AddConfigurations(cmCTest *ctest,
std::vector<std::string> &attempted,
std::vector<std::string> &attemptedConfigs,
std::string filepath,
std::string &filename)
{
std::string tempPath;
if (filepath.size() &&
filepath[filepath.size()-1] != '/')
2004-09-09 16:41:05 +04:00
{
filepath += "/";
2004-09-09 16:41:05 +04:00
}
tempPath = filepath + filename;
attempted.push_back(tempPath);
attemptedConfigs.push_back("");
if(ctest->GetConfigType().size())
2004-09-09 16:41:05 +04:00
{
tempPath = filepath;
tempPath += ctest->GetConfigType();
tempPath += "/";
tempPath += filename;
attempted.push_back(tempPath);
attemptedConfigs.push_back(ctest->GetConfigType());
// If the file is an OSX bundle then the configtyp
// will be at the start of the path
tempPath = ctest->GetConfigType();
tempPath += "/";
tempPath += filepath;
tempPath += filename;
attempted.push_back(tempPath);
attemptedConfigs.push_back(ctest->GetConfigType());
2004-09-09 16:41:05 +04:00
}
else
2004-09-09 16:41:05 +04:00
{
// no config specified to try some options
tempPath = filepath;
tempPath += "Release/";
tempPath += filename;
attempted.push_back(tempPath);
attemptedConfigs.push_back("Release");
tempPath = filepath;
tempPath += "Debug/";
tempPath += filename;
attempted.push_back(tempPath);
attemptedConfigs.push_back("Debug");
tempPath = filepath;
tempPath += "MinSizeRel/";
tempPath += filename;
attempted.push_back(tempPath);
attemptedConfigs.push_back("MinSizeRel");
tempPath = filepath;
tempPath += "RelWithDebInfo/";
tempPath += filename;
attempted.push_back(tempPath);
attemptedConfigs.push_back("RelWithDebInfo");
tempPath = filepath;
tempPath += "Deployment/";
tempPath += filename;
attempted.push_back(tempPath);
attemptedConfigs.push_back("Deployment");
tempPath = filepath;
tempPath += "Development/";
tempPath += filename;
attempted.push_back(tempPath);
attemptedConfigs.push_back("Deployment");
}
}
//----------------------------------------------------------------------
// Find the appropriate executable to run for a test
std::string cmCTestTestHandler
::FindExecutable(cmCTest *ctest,
const char *testCommand,
std::string &resultingConfig,
std::vector<std::string> &extraPaths,
std::vector<std::string> &failed)
{
// now run the compiled test if we can find it
std::vector<std::string> attempted;
std::vector<std::string> attemptedConfigs;
std::string tempPath;
std::string filepath =
cmSystemTools::GetFilenamePath(testCommand);
std::string filename =
cmSystemTools::GetFilenameName(testCommand);
cmCTestTestHandler::AddConfigurations(ctest, attempted,
attemptedConfigs,
filepath,filename);
// even if a fullpath was specified also try it relative to the current directory
if (filepath.size() && filepath[0] == '/')
{
std::string localfilepath = filepath.substr(1,filepath.size()-1);
cmCTestTestHandler::AddConfigurations(ctest, attempted,
attemptedConfigs,
localfilepath,filename);
}
// if extraPaths are provided and we were not passed a full path, try them,
// try any extra paths
if (filepath.size() == 0)
{
for (unsigned int i = 0; i < extraPaths.size(); ++i)
2004-09-09 16:41:05 +04:00
{
std::string filepathExtra =
cmSystemTools::GetFilenamePath(extraPaths[i]);
std::string filenameExtra =
cmSystemTools::GetFilenameName(extraPaths[i]);
cmCTestTestHandler::AddConfigurations(ctest,attempted,
attemptedConfigs,
filepathExtra,
filenameExtra);
2004-09-09 16:41:05 +04:00
}
}
// store the final location in fullPath
std::string fullPath;
2004-09-09 16:41:05 +04:00
// now look in the paths we specified above
for(unsigned int ai=0;
ai < attempted.size() && fullPath.size() == 0; ++ai)
{
// first check without exe extension
if(cmSystemTools::FileExists(attempted[ai].c_str())
&& !cmSystemTools::FileIsDirectory(attempted[ai].c_str()))
2004-09-09 16:41:05 +04:00
{
fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str());
resultingConfig = attemptedConfigs[ai];
2004-09-09 16:41:05 +04:00
}
// then try with the exe extension
else
2004-09-09 16:41:05 +04:00
{
failed.push_back(attempted[ai].c_str());
tempPath = attempted[ai];
tempPath += cmSystemTools::GetExecutableExtension();
if(cmSystemTools::FileExists(tempPath.c_str())
&& !cmSystemTools::FileIsDirectory(tempPath.c_str()))
{
fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str());
resultingConfig = attemptedConfigs[ai];
}
else
{
failed.push_back(tempPath.c_str());
}
2004-09-09 16:41:05 +04:00
}
}
// if everything else failed, check the users path, but only if a full path
// wasn't specified
if (fullPath.size() == 0 && filepath.size() == 0)
2004-09-09 16:41:05 +04:00
{
std::string path = cmSystemTools::FindProgram(filename.c_str());
2004-09-09 16:41:05 +04:00
if (path != "")
{
resultingConfig = "";
2004-09-09 16:41:05 +04:00
return path;
}
}
if(fullPath.size() == 0)
{
cmCTestLog(ctest, HANDLER_OUTPUT,
"Could not find executable " << testCommand << "\n"
<< "Looked in the following places:\n");
for(std::vector<std::string>::iterator i = failed.begin();
i != failed.end(); ++i)
{
cmCTestLog(ctest, HANDLER_OUTPUT,
i->c_str() << "\n");
}
}
2004-09-09 16:41:05 +04:00
return fullPath;
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
void cmCTestTestHandler::GetListOfTests()
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
if ( !this->IncludeRegExp.empty() )
{
2006-03-10 23:03:09 +03:00
this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
}
2006-03-10 23:03:09 +03:00
if ( !this->ExcludeRegExp.empty() )
{
2006-03-10 23:03:09 +03:00
this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
}
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Constructing a list of tests" << std::endl);
cmake cm;
cmGlobalGenerator gg;
gg.SetCMakeInstance(&cm);
std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
lg->SetGlobalGenerator(&gg);
cmMakefile *mf = lg->GetMakefile();
2006-03-09 19:17:10 +03:00
mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
2006-03-10 23:03:09 +03:00
this->CTest->GetConfigType().c_str());
// Add handler for ADD_TEST
cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
2006-03-10 23:03:09 +03:00
newCom1->TestHandler = this;
cm.AddCommand(newCom1);
2008-01-19 23:09:36 +03:00
// Add handler for SUBDIRS
cmCTestSubdirCommand* newCom2 =
new cmCTestSubdirCommand;
2006-03-10 23:03:09 +03:00
newCom2->TestHandler = this;
cm.AddCommand(newCom2);
2008-01-19 23:09:36 +03:00
// Add handler for ADD_SUBDIRECTORY
cmCTestAddSubdirectoryCommand* newCom3 =
new cmCTestAddSubdirectoryCommand;
2006-03-10 23:03:09 +03:00
newCom3->TestHandler = this;
cm.AddCommand(newCom3);
2008-01-19 23:09:36 +03:00
// Add handler for SET_SOURCE_FILES_PROPERTIES
cmCTestSetTestsPropertiesCommand* newCom4
= new cmCTestSetTestsPropertiesCommand;
newCom4->TestHandler = this;
cm.AddCommand(newCom4);
2005-06-20 16:59:33 +04:00
const char* testFilename;
if( cmSystemTools::FileExists("CTestTestfile.cmake") )
{
// does the CTestTestfile.cmake exist ?
testFilename = "CTestTestfile.cmake";
}
2008-02-01 00:33:07 +03:00
else if( cmSystemTools::FileExists("DartTestfile.txt") )
{
// does the DartTestfile.txt exist ?
testFilename = "DartTestfile.txt";
}
else
2004-09-09 16:41:05 +04:00
{
return;
}
if ( !mf->ReadListFile(0, testFilename) )
2004-09-09 16:41:05 +04:00
{
return;
}
if ( cmSystemTools::GetErrorOccuredFlag() )
2004-09-09 16:41:05 +04:00
{
return;
2004-09-09 16:41:05 +04:00
}
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2006-03-09 19:17:10 +03:00
"Done constructing a list of tests" << std::endl);
2004-09-09 16:41:05 +04:00
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
void cmCTestTestHandler::UseIncludeRegExp()
{
2006-03-10 23:03:09 +03:00
this->UseIncludeRegExpFlag = true;
2004-09-09 16:41:05 +04:00
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
void cmCTestTestHandler::UseExcludeRegExp()
{
2006-03-10 23:03:09 +03:00
this->UseExcludeRegExpFlag = true;
this->UseExcludeRegExpFirst = this->UseIncludeRegExpFlag ? false : true;
2004-09-09 16:41:05 +04:00
}
2006-03-09 19:17:10 +03:00
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
const char* cmCTestTestHandler::GetTestStatus(int status)
{
static const char statuses[][100] = {
"Not Run",
"Timeout",
"SEGFAULT",
"ILLEGAL",
"INTERRUPT",
"NUMERICAL",
"OTHER_FAULT",
"Failed",
"BAD_COMMAND",
"Completed"
};
2006-03-09 19:17:10 +03:00
if ( status < cmCTestTestHandler::NOT_RUN ||
2004-09-09 16:41:05 +04:00
status > cmCTestTestHandler::COMPLETED )
{
return "No Status";
}
return statuses[status];
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2008-07-07 03:58:38 +04:00
void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests)
2004-09-09 16:41:05 +04:00
{
if (this->TestsToRunString.empty())
{
return;
}
2006-03-09 19:17:10 +03:00
2004-09-09 16:41:05 +04:00
int start;
int end = -1;
double stride = -1;
std::string::size_type pos = 0;
std::string::size_type pos2;
// read start
if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
{
// read end
if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
{
// read stride
if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
{
int val =0;
// now read specific numbers
while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
{
2006-03-10 23:03:09 +03:00
this->TestsToRun.push_back(val);
2004-09-09 16:41:05 +04:00
}
2006-03-10 23:03:09 +03:00
this->TestsToRun.push_back(val);
2004-09-09 16:41:05 +04:00
}
}
}
// if start is not specified then we assume we start at 1
if(start == -1)
{
start = 1;
}
// if end isnot specified then we assume we end with the last test
if(end == -1)
{
2008-07-07 06:06:08 +04:00
end = static_cast<int>(numTests);
2004-09-09 16:41:05 +04:00
}
2006-03-09 19:17:10 +03:00
2004-09-09 16:41:05 +04:00
// if the stride wasn't specified then it defaults to 1
if(stride == -1)
{
stride = 1;
}
// if we have a range then add it
if(end != -1 && start != -1 && stride > 0)
{
int i = 0;
while (i*stride + start <= end)
{
2006-03-10 23:03:09 +03:00
this->TestsToRun.push_back(static_cast<int>(i*stride+start));
2004-09-09 16:41:05 +04:00
++i;
}
}
// sort the array
2006-03-10 23:03:09 +03:00
std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
std::less<int>());
2004-09-09 16:41:05 +04:00
// remove duplicates
2006-03-09 19:17:10 +03:00
std::vector<int>::iterator new_end =
2006-03-10 23:03:09 +03:00
std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
this->TestsToRun.erase(new_end, this->TestsToRun.end());
2004-09-09 16:41:05 +04:00
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
// Just for convenience
2004-09-09 16:41:05 +04:00
#define SPACE_REGEX "[ \t\r\n]"
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
std::string cmCTestTestHandler::GenerateRegressionImages(
const std::string& xml)
{
cmsys::RegularExpression twoattributes(
2006-03-09 19:17:10 +03:00
"<DartMeasurement"
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
2004-09-09 16:41:05 +04:00
SPACE_REGEX "*>([^<]*)</DartMeasurement>");
cmsys::RegularExpression threeattributes(
2006-03-09 19:17:10 +03:00
"<DartMeasurement"
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
2004-09-09 16:41:05 +04:00
SPACE_REGEX "*>([^<]*)</DartMeasurement>");
cmsys::RegularExpression fourattributes(
2006-03-09 19:17:10 +03:00
"<DartMeasurement"
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
2004-09-09 16:41:05 +04:00
SPACE_REGEX "*>([^<]*)</DartMeasurement>");
2008-06-17 22:03:49 +04:00
cmsys::RegularExpression cdatastart(
"<DartMeasurement"
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
2008-06-17 22:03:49 +04:00
SPACE_REGEX "*>"
SPACE_REGEX "*<!\\[CDATA\\[");
cmsys::RegularExpression cdataend(
"]]>"
SPACE_REGEX "*</DartMeasurement>");
2004-09-09 16:41:05 +04:00
cmsys::RegularExpression measurementfile(
2006-03-09 19:17:10 +03:00
"<DartMeasurementFile"
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
2004-09-09 16:41:05 +04:00
SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
cmOStringStream ostr;
bool done = false;
std::string cxml = xml;
while ( ! done )
{
if ( twoattributes.find(cxml) )
{
ostr
2006-03-09 19:17:10 +03:00
<< "\t\t\t<NamedMeasurement"
<< " " << twoattributes.match(1) << "=\""
<< twoattributes.match(2) << "\""
<< " " << twoattributes.match(3) << "=\""
<< twoattributes.match(4) << "\""
<< "><Value>" << twoattributes.match(5)
<< "</Value></NamedMeasurement>"
2004-09-09 16:41:05 +04:00
<< std::endl;
2006-03-09 19:17:10 +03:00
cxml.erase(twoattributes.start(),
twoattributes.end() - twoattributes.start());
2004-09-09 16:41:05 +04:00
}
else if ( threeattributes.find(cxml) )
{
ostr
2006-03-09 19:17:10 +03:00
<< "\t\t\t<NamedMeasurement"
<< " " << threeattributes.match(1) << "=\""
<< threeattributes.match(2) << "\""
<< " " << threeattributes.match(3) << "=\""
<< threeattributes.match(4) << "\""
<< " " << threeattributes.match(5) << "=\""
<< threeattributes.match(6) << "\""
<< "><Value>" << threeattributes.match(7)
<< "</Value></NamedMeasurement>"
2004-09-09 16:41:05 +04:00
<< std::endl;
2006-03-09 19:17:10 +03:00
cxml.erase(threeattributes.start(),
threeattributes.end() - threeattributes.start());
2004-09-09 16:41:05 +04:00
}
else if ( fourattributes.find(cxml) )
{
ostr
2006-03-09 19:17:10 +03:00
<< "\t\t\t<NamedMeasurement"
<< " " << fourattributes.match(1) << "=\""
<< fourattributes.match(2) << "\""
<< " " << fourattributes.match(3) << "=\""
<< fourattributes.match(4) << "\""
<< " " << fourattributes.match(5) << "=\""
<< fourattributes.match(6) << "\""
<< " " << fourattributes.match(7) << "=\""
<< fourattributes.match(8) << "\""
<< "><Value>" << fourattributes.match(9)
<< "</Value></NamedMeasurement>"
2004-09-09 16:41:05 +04:00
<< std::endl;
2006-03-09 19:17:10 +03:00
cxml.erase(fourattributes.start(),
fourattributes.end() - fourattributes.start());
2004-09-09 16:41:05 +04:00
}
2008-06-17 22:03:49 +04:00
else if ( cdatastart.find(cxml) && cdataend.find(cxml) )
{
ostr
<< "\t\t\t<NamedMeasurement"
2008-06-17 22:03:49 +04:00
<< " " << cdatastart.match(1) << "=\""
<< cdatastart.match(2) << "\""
<< " " << cdatastart.match(3) << "=\""
<< cdatastart.match(4) << "\""
<< "><Value><![CDATA["
<< cxml.substr(cdatastart.end(), cdataend.start() - cdatastart.end())
<< "]]></Value></NamedMeasurement>"
<< std::endl;
2008-06-17 22:03:49 +04:00
cxml.erase(cdatastart.start(),
cdataend.end() - cdatastart.start());
}
2004-09-09 16:41:05 +04:00
else if ( measurementfile.find(cxml) )
{
2006-03-09 19:17:10 +03:00
const std::string& filename =
2004-09-09 16:41:05 +04:00
cmCTest::CleanString(measurementfile.match(5));
if ( cmSystemTools::FileExists(filename.c_str()) )
{
long len = cmSystemTools::FileLength(filename.c_str());
if ( len == 0 )
{
std::string k1 = measurementfile.match(1);
std::string v1 = measurementfile.match(2);
std::string k2 = measurementfile.match(3);
std::string v2 = measurementfile.match(4);
if ( cmSystemTools::LowerCase(k1) == "type" )
{
v1 = "text/string";
}
if ( cmSystemTools::LowerCase(k2) == "type" )
{
v2 = "text/string";
2006-03-09 19:17:10 +03:00
}
2004-09-09 16:41:05 +04:00
ostr
2006-03-09 19:17:10 +03:00
<< "\t\t\t<NamedMeasurement"
2004-09-09 16:41:05 +04:00
<< " " << k1 << "=\"" << v1 << "\""
<< " " << k2 << "=\"" << v2 << "\""
<< " encoding=\"none\""
2006-03-09 19:17:10 +03:00
<< "><Value>Image " << filename.c_str()
2004-09-09 16:41:05 +04:00
<< " is empty</Value></NamedMeasurement>";
}
else
{
2006-03-09 19:17:10 +03:00
std::ifstream ifs(filename.c_str(), std::ios::in
2004-09-09 16:41:05 +04:00
#ifdef _WIN32
| std::ios::binary
#endif
);
unsigned char *file_buffer = new unsigned char [ len + 1 ];
ifs.read(reinterpret_cast<char*>(file_buffer), len);
2006-03-09 19:17:10 +03:00
unsigned char *encoded_buffer
= new unsigned char [ static_cast<int>(len * 1.5 + 5) ];
unsigned long rlen
= cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
2004-09-09 16:41:05 +04:00
unsigned long cc;
2006-03-09 19:17:10 +03:00
2004-09-09 16:41:05 +04:00
ostr
2006-03-09 19:17:10 +03:00
<< "\t\t\t<NamedMeasurement"
<< " " << measurementfile.match(1) << "=\""
<< measurementfile.match(2) << "\""
<< " " << measurementfile.match(3) << "=\""
<< measurementfile.match(4) << "\""
2004-09-09 16:41:05 +04:00
<< " encoding=\"base64\""
<< ">" << std::endl << "\t\t\t\t<Value>";
for ( cc = 0; cc < rlen; cc ++ )
{
ostr << encoded_buffer[cc];
if ( cc % 60 == 0 && cc )
{
ostr << std::endl;
}
}
ostr
2006-03-09 19:17:10 +03:00
<< "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
2004-09-09 16:41:05 +04:00
<< std::endl;
delete [] file_buffer;
delete [] encoded_buffer;
}
}
else
{
int idx = 4;
if ( measurementfile.match(1) == "name" )
{
idx = 2;
}
ostr
2006-03-09 19:17:10 +03:00
<< "\t\t\t<NamedMeasurement"
2004-09-09 16:41:05 +04:00
<< " name=\"" << measurementfile.match(idx) << "\""
<< " text=\"text/string\""
2006-03-09 19:17:10 +03:00
<< "><Value>File " << filename.c_str()
<< " not found</Value></NamedMeasurement>"
2004-09-09 16:41:05 +04:00
<< std::endl;
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "File \"" << filename.c_str()
2006-03-09 19:17:10 +03:00
<< "\" not found." << std::endl);
2004-09-09 16:41:05 +04:00
}
2006-03-09 19:17:10 +03:00
cxml.erase(measurementfile.start(),
measurementfile.end() - measurementfile.start());
2004-09-09 16:41:05 +04:00
}
else
{
done = true;
}
}
return ostr.str();
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
{
2006-03-10 23:03:09 +03:00
this->IncludeRegExp = arg;
2004-09-09 16:41:05 +04:00
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
{
2006-03-10 23:03:09 +03:00
this->ExcludeRegExp = arg;
2004-09-09 16:41:05 +04:00
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
{
if ( !in )
{
return;
}
2004-09-09 16:41:05 +04:00
this->TestsToRunString = in;
2006-03-09 19:17:10 +03:00
// if the argument is a file, then read it and use the contents as the
// string
2004-09-09 16:41:05 +04:00
if(cmSystemTools::FileExists(in))
{
std::ifstream fin(in);
unsigned long filelen = cmSystemTools::FileLength(in);
char* buff = new char[filelen+1];
fin.getline(buff, filelen);
buff[fin.gcount()] = 0;
this->TestsToRunString = buff;
}
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2006-03-09 19:17:10 +03:00
bool cmCTestTestHandler::CleanTestOutput(std::string& output,
size_t remove_threshold)
{
if ( remove_threshold == 0 )
{
return true;
}
if ( output.find("CTEST_FULL_OUTPUT") != output.npos )
{
return true;
}
cmOStringStream ostr;
std::string::size_type cc;
std::string::size_type skipsize = 0;
int inTag = 0;
int skipped = 0;
for ( cc = 0; cc < output.size(); cc ++ )
{
int ch = output[cc];
if ( ch < 0 || ch > 255 )
{
break;
}
if ( ch == '<' )
{
inTag = 1;
}
if ( !inTag )
{
int notskip = 0;
// Skip
if ( skipsize < remove_threshold )
{
ostr << static_cast<char>(ch);
notskip = 1;
}
skipsize ++;
if ( notskip && skipsize >= remove_threshold )
{
skipped = 1;
}
}
else
{
ostr << static_cast<char>(ch);
}
if ( ch == '>' )
{
inTag = 0;
}
}
if ( skipped )
{
2006-03-09 19:17:10 +03:00
ostr << "..." << std::endl << "The rest of the test output was removed "
"since it exceeds the threshold of "
<< remove_threshold << " characters." << std::endl;
}
output = ostr.str();
return true;
}
//----------------------------------------------------------------------
2006-03-09 19:17:10 +03:00
bool cmCTestTestHandler::SetTestsProperties(
const std::vector<std::string>& args)
{
std::vector<std::string>::const_iterator it;
std::vector<cmStdString> tests;
bool found = false;
for ( it = args.begin(); it != args.end(); ++ it )
{
if ( *it == "PROPERTIES" )
{
found = true;
break;
}
tests.push_back(*it);
}
if ( !found )
{
return false;
}
++ it; // skip PROPERTIES
for ( ; it != args.end(); ++ it )
{
std::string key = *it;
++ it;
if ( it == args.end() )
{
break;
}
std::string val = *it;
std::vector<cmStdString>::const_iterator tit;
for ( tit = tests.begin(); tit != tests.end(); ++ tit )
{
2006-03-10 23:03:09 +03:00
cmCTestTestHandler::ListOfTests::iterator rtit;
for ( rtit = this->TestList.begin();
rtit != this->TestList.end();
++ rtit )
{
2006-03-10 23:03:09 +03:00
if ( *tit == rtit->Name )
{
if ( key == "WILL_FAIL" )
{
2006-03-10 23:03:09 +03:00
rtit->WillFail = cmSystemTools::IsOn(val.c_str());
}
2007-01-25 19:16:16 +03:00
if ( key == "TIMEOUT" )
{
rtit->Timeout = atof(val.c_str());
}
if ( key == "FAIL_REGULAR_EXPRESSION" )
{
std::vector<std::string> lval;
cmSystemTools::ExpandListArgument(val.c_str(), lval);
std::vector<std::string>::iterator crit;
for ( crit = lval.begin(); crit != lval.end(); ++ crit )
{
2006-03-10 23:03:09 +03:00
rtit->ErrorRegularExpressions.push_back(
std::pair<cmsys::RegularExpression, std::string>(
cmsys::RegularExpression(crit->c_str()),
std::string(crit->c_str())));
}
}
2008-07-03 17:31:33 +04:00
if ( key == "DEPENDS" )
{
std::vector<std::string> lval;
cmSystemTools::ExpandListArgument(val.c_str(), lval);
std::vector<std::string>::iterator crit;
for ( crit = lval.begin(); crit != lval.end(); ++ crit )
{
rtit->Depends.push_back(*crit);
}
}
if ( key == "MEASUREMENT" )
{
size_t pos = val.find_first_of("=");
if ( pos != val.npos )
{
std::string mKey = val.substr(0, pos);
const char* mVal = val.c_str() + pos + 1;
rtit->Measurements[mKey] = mVal;
}
else
{
rtit->Measurements[val] = "1";
}
}
if ( key == "PASS_REGULAR_EXPRESSION" )
{
std::vector<std::string> lval;
cmSystemTools::ExpandListArgument(val.c_str(), lval);
std::vector<std::string>::iterator crit;
for ( crit = lval.begin(); crit != lval.end(); ++ crit )
{
2006-03-10 23:03:09 +03:00
rtit->RequiredRegularExpressions.push_back(
std::pair<cmsys::RegularExpression, std::string>(
cmsys::RegularExpression(crit->c_str()),
std::string(crit->c_str())));
}
}
}
}
}
}
return true;
}
//----------------------------------------------------------------------
bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
{
const std::string& testname = args[0];
2006-07-13 00:30:14 +04:00
cmCTestLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl);
2006-03-10 23:03:09 +03:00
if (this->UseExcludeRegExpFlag &&
this->UseExcludeRegExpFirst &&
this->ExcludeTestsRegularExpression.find(testname.c_str()))
{
return true;
}
2006-03-10 23:03:09 +03:00
if ( this->MemCheck )
{
std::vector<cmStdString>::iterator it;
bool found = false;
2006-03-10 23:03:09 +03:00
for ( it = this->CustomTestsIgnore.begin();
it != this->CustomTestsIgnore.end(); ++ it )
{
if ( *it == testname )
{
found = true;
break;
}
}
if ( found )
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: "
2006-03-09 19:17:10 +03:00
<< *it << std::endl);
return true;
}
}
else
{
std::vector<cmStdString>::iterator it;
bool found = false;
2006-03-10 23:03:09 +03:00
for ( it = this->CustomTestsIgnore.begin();
it != this->CustomTestsIgnore.end(); ++ it )
{
if ( *it == testname )
{
found = true;
break;
}
}
if ( found )
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: "
2006-03-09 19:17:10 +03:00
<< *it << std::endl);
return true;
}
}
cmCTestTestProperties test;
2006-03-10 23:03:09 +03:00
test.Name = testname;
test.Args = args;
test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
2006-07-13 17:13:29 +04:00
cmCTestLog(this->CTest, DEBUG, "Set test directory: "
<< test.Directory << std::endl);
2006-03-10 23:03:09 +03:00
test.IsInBasedOnREOptions = true;
test.WillFail = false;
2007-01-25 19:16:16 +03:00
test.Timeout = 0;
2006-03-10 23:03:09 +03:00
if (this->UseIncludeRegExpFlag &&
!this->IncludeTestsRegularExpression.find(testname.c_str()))
{
2006-03-10 23:03:09 +03:00
test.IsInBasedOnREOptions = false;
}
2006-03-10 23:03:09 +03:00
else if (this->UseExcludeRegExpFlag &&
!this->UseExcludeRegExpFirst &&
this->ExcludeTestsRegularExpression.find(testname.c_str()))
{
2006-03-10 23:03:09 +03:00
test.IsInBasedOnREOptions = false;
}
2006-03-10 23:03:09 +03:00
this->TestList.push_back(test);
return true;
}