CMake/Source/CTest/cmCTestTestHandler.cxx

1730 lines
50 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"
#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
//----------------------------------------------------------------------
class cmCTestSubdirCommand : public cmCommand
{
public:
/**
* This is a virtual constructor for the command.
*/
2006-03-09 19:17:10 +03:00
virtual cmCommand* Clone()
{
cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
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);
/**
* 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);
2006-03-10 23:03:09 +03:00
cmCTestTestHandler* TestHandler;
};
//----------------------------------------------------------------------
bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args)
{
if(args.size() < 1 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
std::vector<std::string>::const_iterator it;
2006-03-09 19:17:10 +03:00
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;
2006-03-09 19:17:10 +03:00
if ( !cmSystemTools::FileExists(fname.c_str()) )
{
// No subdirectory? So what...
continue;
}
cmSystemTools::ChangeDirectory(fname.c_str());
2005-06-20 16:59:33 +04:00
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 DartTestfile.txt? Who cares...
cmSystemTools::ChangeDirectory(cwd.c_str());
continue;
}
fname += "/";
fname += testFilename;
2006-05-10 21:50:44 +04:00
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&);
/**
* 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)
{
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&);
/**
* 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;
};
//----------------------------------------------------------------------
2006-03-09 19:17:10 +03:00
bool cmCTestSetTestsPropertiesCommand::InitialPass(
std::vector<std::string> const& args)
{
2006-03-10 23:03:09 +03:00
return this->TestHandler->SetTestsProperties(args);
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
// Try to find an executable, if found fullPath will be set to the full path
// of where it was found. The directory and filename to search for are passed
// in as well an a subdir (typically used for configuraitons such as
// Release/Debug/etc)
2004-09-09 16:41:05 +04:00
bool TryExecutable(const char *dir, const char *file,
std::string *fullPath, const char *subdir)
{
// try current directory
std::string tryPath;
if (dir && strcmp(dir,""))
{
tryPath = dir;
tryPath += "/";
}
2006-03-09 19:17:10 +03:00
2004-09-09 16:41:05 +04:00
if (subdir && strcmp(subdir,""))
{
tryPath += subdir;
tryPath += "/";
}
2006-03-09 19:17:10 +03:00
2004-09-09 16:41:05 +04:00
tryPath += file;
2006-03-09 19:17:10 +03:00
// find the file without an executable extension
2004-09-09 16:41:05 +04:00
if(cmSystemTools::FileExists(tryPath.c_str()))
{
*fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
return true;
}
// if not found try it with the executable extension
2004-09-09 16:41:05 +04:00
tryPath += cmSystemTools::GetExecutableExtension();
if(cmSystemTools::FileExists(tryPath.c_str()))
{
*fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
return true;
}
2006-03-09 19:17:10 +03:00
// not found at all, return false
2004-09-09 16:41:05 +04:00
return false;
}
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();
2005-01-27 23:54:47 +03:00
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT,
(this->MemCheck ? "Memory check" : "Test")
2006-03-09 19:17:10 +03:00
<< " project" << 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;
}
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
2006-03-09 19:17:10 +03:00
<< static_cast<int>(percent + .5) << "% tests passed, "
<< failed.size() << " tests failed out of " << total << std::endl);
//fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
// percent, int(failed.size()), total);
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;
2004-09-09 16:41:05 +04:00
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl
2006-03-09 19:17:10 +03:00
<< "The following tests FAILED:" << std::endl);
this->StartLogFile("TestsFailed", ofs);
2004-09-09 16:41:05 +04:00
std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator ftit;
2006-03-10 23:03:09 +03:00
for(ftit = this->TestResults.begin();
ftit != this->TestResults.end(); ++ftit)
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
if ( ftit->Status != cmCTestTestHandler::COMPLETED )
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
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
}
}
}
}
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
}
2005-01-27 23:54:47 +03:00
//----------------------------------------------------------------------
2006-03-09 19:17:10 +03:00
void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
2005-01-27 23:54:47 +03:00
std::vector<cmStdString> &failed)
2004-09-09 16:41:05 +04:00
{
std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
2006-03-10 23:03:09 +03:00
this->TestList.clear();
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
2006-03-10 23:03:09 +03:00
this->StartTest = this->CTest->CurrentTime();
2004-09-09 16:41:05 +04:00
double elapsed_time_start = cmSystemTools::GetTime();
2006-03-10 23:03:09 +03:00
*this->LogFile << "Start testing: " << this->StartTest << std::endl
2005-08-18 21:50:16 +04:00
<< "----------------------------------------------------------"
<< std::endl;
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);
}
2006-03-09 19:17:10 +03:00
2004-09-09 16:41:05 +04:00
int cnt = 0;
inREcnt = 0;
2004-09-09 16:41:05 +04:00
std::string last_directory = "";
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
const std::string& testname = it->Name;
std::vector<std::string>& args = it->Args;
2004-09-09 16:41:05 +04:00
cmCTestTestResult cres;
2006-03-10 23:03:09 +03:00
cres.ExecutionTime = 0;
cres.ReturnValue = -1;
cres.Status = cmCTestTestHandler::NOT_RUN;
cres.TestCount = cnt;
2004-09-09 16:41:05 +04:00
2006-03-10 23:03:09 +03:00
if (!(last_directory == it->Directory))
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Changing directory into " << it->Directory.c_str() << "\n");
*this->LogFile << "Changing directory into: " << it->Directory.c_str()
2005-08-18 21:50:16 +04:00
<< std::endl;
2006-03-10 23:03:09 +03:00
last_directory = it->Directory;
cmSystemTools::ChangeDirectory(it->Directory.c_str());
2004-09-09 16:41:05 +04:00
}
2006-03-10 23:03:09 +03:00
cres.Name = testname;
cres.Path = it->Directory.c_str();
2006-03-09 19:17:10 +03:00
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(),
this->TestsToRun.end(), inREcnt)
== this->TestsToRun.end()) || !it->IsInBasedOnREOptions)
{
continue;
}
}
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << cnt << "/");
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << tmsize << " ");
if ( this->MemCheck )
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Memory Check");
}
else
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Testing");
}
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
std::string outname = testname;
outname.resize(30, ' ');
2006-03-10 23:03:09 +03:00
*this->LogFile << cnt << "/" << tmsize << " Testing: " << testname
2005-08-18 21:50:16 +04:00
<< std::endl;
2004-09-09 16:41:05 +04:00
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, HANDLER_OUTPUT, outname.c_str() << std::endl);
}
2004-09-09 16:41:05 +04:00
else
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str());
2004-09-09 16:41:05 +04:00
}
2006-03-09 19:17:10 +03:00
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, DEBUG, "Testing " << args[0].c_str() << " ... ");
2004-09-09 16:41:05 +04:00
// find the test executable
std::string actualCommand = this->FindTheExecutable(args[1].c_str());
2006-03-09 19:17:10 +03:00
std::string testCommand
= cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
2004-09-09 16:41:05 +04:00
// continue if we did not find the executable
if (testCommand == "")
{
2006-03-10 23:03:09 +03:00
*this->LogFile << "Unable to find executable: " << args[1].c_str()
2005-08-18 21:50:16 +04:00
<< std::endl;
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find executable: "
<< args[1].c_str() << std::endl);
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
cres.FullCommandLine = actualCommand;
this->TestResults.push_back( cres );
2004-09-09 16:41:05 +04:00
failed.push_back(testname);
continue;
}
}
// add the arguments
std::vector<std::string>::const_iterator j = args.begin();
2004-09-09 16:41:05 +04:00
++j;
++j;
std::vector<const char*> arguments;
2005-01-27 23:54:47 +03:00
this->GenerateTestCommand(arguments);
2004-09-09 16:41:05 +04:00
arguments.push_back(actualCommand.c_str());
for(;j != args.end(); ++j)
{
testCommand += " ";
testCommand += cmSystemTools::EscapeSpaces(j->c_str());
arguments.push_back(j->c_str());
2004-09-09 16:41:05 +04:00
}
arguments.push_back(0);
/**
* Run an executable command and put the stdout in output.
*/
std::string output;
int retVal = 0;
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
<< (this->MemCheck?"MemCheck":"Test") << " command: " << testCommand
2006-03-09 19:17:10 +03:00
<< std::endl);
2006-03-10 23:03:09 +03:00
*this->LogFile << cnt << "/" << tmsize
2005-08-18 21:50:16 +04:00
<< " Test: " << testname.c_str() << std::endl;
2006-03-10 23:03:09 +03:00
*this->LogFile << "Command: ";
2005-08-18 21:50:16 +04:00
std::vector<cmStdString>::size_type ll;
for ( ll = 0; ll < arguments.size()-1; ll ++ )
{
2006-03-10 23:03:09 +03:00
*this->LogFile << "\"" << arguments[ll] << "\" ";
2005-08-18 21:50:16 +04:00
}
2006-03-10 23:03:09 +03:00
*this->LogFile
2006-03-09 19:17:10 +03:00
<< std::endl
2006-03-10 23:03:09 +03:00
<< "Directory: " << it->Directory << std::endl
2006-03-09 19:17:10 +03:00
<< "\"" << testname.c_str() << "\" start time: "
2006-03-10 23:03:09 +03:00
<< this->CTest->CurrentTime() << std::endl
2006-03-09 19:17:10 +03:00
<< "Output:" << std::endl
2005-08-18 21:50:16 +04:00
<< "----------------------------------------------------------"
<< std::endl;
2004-09-09 16:41:05 +04:00
int res = 0;
double clock_start, clock_finish;
clock_start = cmSystemTools::GetTime();
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
res = this->CTest->RunTest(arguments, &output, &retVal, this->LogFile);
2004-09-09 16:41:05 +04:00
}
clock_finish = cmSystemTools::GetTime();
2006-03-10 23:03:09 +03:00
if ( this->LogFile )
2004-09-09 16:41:05 +04:00
{
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);
2006-03-10 23:03:09 +03:00
*this->LogFile
2004-09-09 16:41:05 +04:00
<< "----------------------------------------------------------"
<< std::endl
2006-03-09 19:17:10 +03:00
<< "\"" << testname.c_str() << "\" end time: "
2006-03-10 23:03:09 +03:00
<< this->CTest->CurrentTime() << std::endl
2006-03-09 19:17:10 +03:00
<< "\"" << testname.c_str() << "\" time elapsed: "
2004-09-09 16:41:05 +04:00
<< buffer << std::endl
<< "----------------------------------------------------------"
<< std::endl << std::endl;
}
2006-03-10 23:03:09 +03:00
cres.ExecutionTime = (double)(clock_finish - clock_start);
cres.FullCommandLine = testCommand;
2004-09-09 16:41:05 +04:00
2006-03-10 23:03:09 +03:00
if ( !this->CTest->GetShowOnly() )
2004-09-09 16:41:05 +04:00
{
2005-09-20 23:08:41 +04:00
bool testFailed = false;
std::vector<cmsys::RegularExpression>::iterator passIt;
bool forceFail = false;
2006-03-10 23:03:09 +03:00
if ( it->RequiredRegularExpressions.size() > 0 )
{
bool found = false;
2006-03-10 23:03:09 +03:00
for ( passIt = it->RequiredRegularExpressions.begin();
passIt != it->RequiredRegularExpressions.end();
++ passIt )
{
if ( passIt->find(output.c_str()) )
{
found = true;
}
}
if ( !found )
{
forceFail = true;
}
}
2006-03-10 23:03:09 +03:00
if ( it->ErrorRegularExpressions.size() > 0 )
{
2006-03-10 23:03:09 +03:00
for ( passIt = it->ErrorRegularExpressions.begin();
passIt != it->ErrorRegularExpressions.end();
++ passIt )
{
if ( passIt->find(output.c_str()) )
{
forceFail = true;
}
}
}
2006-03-09 19:17:10 +03:00
if (res == cmsysProcess_State_Exited &&
2006-03-10 23:03:09 +03:00
(retVal == 0 || it->RequiredRegularExpressions.size()) &&
!forceFail)
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Passed");
if ( it->WillFail )
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, " - But it should fail!");
cres.Status = cmCTestTestHandler::FAILED;
testFailed = true;
}
else
{
2006-03-10 23:03:09 +03:00
cres.Status = cmCTestTestHandler::COMPLETED;
}
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
2004-09-09 16:41:05 +04:00
}
else
{
2005-09-20 23:08:41 +04:00
testFailed = true;
2006-03-10 23:03:09 +03:00
cres.Status = cmCTestTestHandler::FAILED;
2004-09-09 16:41:05 +04:00
if ( res == cmsysProcess_State_Expired )
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Timeout" << std::endl);
cres.Status = cmCTestTestHandler::TIMEOUT;
2004-09-09 16:41:05 +04:00
}
else if ( res == cmsysProcess_State_Exception )
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: ");
2004-09-09 16:41:05 +04:00
switch ( retVal )
{
case cmsysProcess_Exception_Fault:
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault");
cres.Status = cmCTestTestHandler::SEGFAULT;
2004-09-09 16:41:05 +04:00
break;
case cmsysProcess_Exception_Illegal:
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Illegal");
cres.Status = cmCTestTestHandler::ILLEGAL;
2004-09-09 16:41:05 +04:00
break;
case cmsysProcess_Exception_Interrupt:
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Interrupt");
cres.Status = cmCTestTestHandler::INTERRUPT;
2004-09-09 16:41:05 +04:00
break;
case cmsysProcess_Exception_Numerical:
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Numerical");
cres.Status = cmCTestTestHandler::NUMERICAL;
2004-09-09 16:41:05 +04:00
break;
default:
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "Other");
cres.Status = cmCTestTestHandler::OTHER_FAULT;
2004-09-09 16:41:05 +04:00
}
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
2004-09-09 16:41:05 +04:00
}
else if ( res == cmsysProcess_State_Error )
{
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Bad command " << res
2006-03-09 19:17:10 +03:00
<< std::endl);
2006-03-10 23:03:09 +03:00
cres.Status = cmCTestTestHandler::BAD_COMMAND;
2004-09-09 16:41:05 +04:00
}
else
{
// Force fail will also be here?
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Failed");
if ( it->WillFail )
{
2006-03-10 23:03:09 +03:00
cres.Status = cmCTestTestHandler::COMPLETED;
cmCTestLog(this->CTest, HANDLER_OUTPUT, " - supposed to fail");
2005-09-20 23:08:41 +04:00
testFailed = false;
}
2006-03-10 23:03:09 +03:00
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
2004-09-09 16:41:05 +04:00
}
2005-09-20 23:08:41 +04:00
}
if ( testFailed )
{
2004-09-09 16:41:05 +04:00
failed.push_back(testname);
}
2005-09-20 23:08:41 +04:00
else
{
passed.push_back(testname);
}
if (!output.empty() && output.find("<DartMeasurement") != output.npos)
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
if (this->DartStuff.find(output.c_str()))
2004-09-09 16:41:05 +04:00
{
2006-03-10 23:03:09 +03:00
std::string dartString = this->DartStuff.match(1);
2004-09-09 16:41:05 +04:00
cmSystemTools::ReplaceString(output, dartString.c_str(),"");
2006-03-10 23:03:09 +03:00
cres.RegressionImages
2006-03-09 19:17:10 +03:00
= this->GenerateRegressionImages(dartString);
2004-09-09 16:41:05 +04:00
}
}
}
2006-03-10 23:03:09 +03:00
if ( cres.Status == cmCTestTestHandler::COMPLETED )
{
2006-03-09 19:17:10 +03:00
this->CleanTestOutput(output, static_cast<size_t>(
2006-03-10 23:03:09 +03:00
this->CustomMaximumPassedTestOutputSize));
}
else
{
2006-03-09 19:17:10 +03:00
this->CleanTestOutput(output, static_cast<size_t>(
2006-03-10 23:03:09 +03:00
this->CustomMaximumFailedTestOutputSize));
}
2006-03-10 23:03:09 +03:00
cres.Output = output;
cres.ReturnValue = retVal;
cres.CompletionStatus = "Completed";
this->TestResults.push_back( cres );
2004-09-09 16:41:05 +04:00
}
2006-03-10 23:03:09 +03:00
this->EndTest = this->CTest->CurrentTime();
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"
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
}
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"
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 fullPath = "";
std::string dir;
std::string file;
cmSystemTools::SplitProgramPath(exe, dir, file);
2006-03-09 19:17:10 +03:00
// first try to find the executable given a config type subdir if there is
// one
2006-03-10 23:03:09 +03:00
if(this->CTest->GetConfigType() != "" &&
2006-03-09 19:17:10 +03:00
::TryExecutable(dir.c_str(), file.c_str(), &fullPath,
2006-03-10 23:03:09 +03:00
this->CTest->GetConfigType().c_str()))
2004-09-09 16:41:05 +04:00
{
return fullPath;
}
// next try the current directory as the subdir
2004-09-09 16:41:05 +04:00
if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
{
return fullPath;
}
// try without the config subdir
2004-09-09 16:41:05 +04:00
if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
{
return fullPath;
}
2006-03-10 23:03:09 +03:00
if ( this->CTest->GetConfigType() == "" )
2004-09-09 16:41:05 +04:00
{
// No config type, so try to guess it
if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Deployment"))
{
return fullPath;
}
if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Development"))
{
return fullPath;
}
2004-09-09 16:41:05 +04:00
if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
{
return fullPath;
}
if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
{
return fullPath;
}
if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
{
return fullPath;
}
if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
{
return fullPath;
}
}
// if everything else failed, check the users path, but only if a full path
// wasn;t specified
if (dir.size() == 0)
2004-09-09 16:41:05 +04:00
{
std::string path = cmSystemTools::FindProgram(file.c_str());
if (path != "")
{
return path;
}
}
2006-03-10 23:03:09 +03:00
if ( this->CTest->GetConfigType() != "" )
2004-09-09 16:41:05 +04:00
{
dir += "/";
2006-03-10 23:03:09 +03:00
dir += this->CTest->GetConfigType();
2004-09-09 16:41:05 +04:00
dir += "/";
dir += file;
2006-03-09 19:17:10 +03:00
cmSystemTools::Error("config type specified on the command line, but "
"test executable not found.",
2004-09-09 16:41:05 +04:00
dir.c_str());
return "";
}
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);
2006-03-09 19:17:10 +03:00
// Add handler for SUBDIR
cmCTestSubdirCommand* newCom2 = new cmCTestSubdirCommand;
2006-03-10 23:03:09 +03:00
newCom2->TestHandler = this;
cm.AddCommand(newCom2);
// Add handler for SET_SOURCE_FILES_PROPERTIES
2006-03-09 19:17:10 +03:00
cmCTestSetTestsPropertiesCommand* newCom3
= new cmCTestSetTestsPropertiesCommand;
2006-03-10 23:03:09 +03:00
newCom3->TestHandler = this;
cm.AddCommand(newCom3);
2005-06-20 16:59:33 +04:00
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
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
//----------------------------------------------------------------------
2004-09-09 16:41:05 +04:00
void cmCTestTestHandler::ExpandTestsToRunInformation(int numTests)
{
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)
{
end = numTests;
}
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>");
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
}
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());
}
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(
2006-03-09 19:17:10 +03:00
cmsys::RegularExpression(crit->c_str()));
}
}
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(
2006-03-09 19:17:10 +03:00
cmsys::RegularExpression(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;
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;
}