ENH: Add support for CTestCustom.ctest, which modifies some behavior of ctest

This commit is contained in:
Andy Cedilnik 2004-01-26 13:57:26 -05:00
parent 222e9a2876
commit 2db971afb4
2 changed files with 368 additions and 157 deletions

View File

@ -21,6 +21,7 @@
#include "cmGlobalGenerator.h"
#include <cmsys/Directory.hxx>
#include "cmListFileCache.h"
#include "cmGlob.h"
#include "cmCTestSubmit.h"
#include "curl/curl.h"
@ -324,10 +325,14 @@ cmCTest::cmCTest()
}
}
void cmCTest::Initialize()
int cmCTest::Initialize()
{
m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
cmSystemTools::ConvertToUnixSlashes(m_ToplevelPath);
if ( !this->ReadCustomConfigurationFileTree(m_ToplevelPath.c_str()) )
{
return 0;
}
this->UpdateCTestConfiguration();
if ( m_DartMode )
{
@ -338,7 +343,7 @@ void cmCTest::Initialize()
{
std::cerr << "File " << testingDir << " is in the place of the testing directory"
<< std::endl;
return;
return 0;
}
}
else
@ -347,7 +352,7 @@ void cmCTest::Initialize()
{
std::cerr << "Cannot create directory " << testingDir
<< std::endl;
return;
return 0;
}
}
std::string tagfile = testingDir + "/TAG";
@ -408,6 +413,7 @@ void cmCTest::Initialize()
}
m_CurrentTag = tag;
}
return 1;
}
void cmCTest::UpdateCTestConfiguration()
@ -1042,7 +1048,7 @@ int cmCTest::BuildDirectory()
ofs.close();
}
int cc;
tm_VectorOfStrings::size_type cc;
if ( m_DartConfiguration["SourceDirectory"].size() > 20 ||
m_DartConfiguration["BuildDirectory"].size() > 20 )
{
@ -1090,7 +1096,24 @@ int cmCTest::BuildDirectory()
// Errors
for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
{
cmsys::RegularExpression re(cmCTestErrorMatches[cc]);
m_CustomErrorMatches.push_back(cmCTestErrorMatches[cc]);
}
for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
{
m_CustomErrorExceptions.push_back(cmCTestErrorExceptions[cc]);
}
for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
{
m_CustomWarningMatches.push_back(cmCTestWarningMatches[cc]);
}
for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
{
m_CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]);
}
for ( cc = 0; cc < m_CustomErrorMatches.size(); cc ++ )
{
cmsys::RegularExpression re(m_CustomErrorMatches[cc].c_str());
cmCTest::tm_VectorOfStrings::size_type kk;
for ( kk = 0; kk < lines.size(); kk ++ )
{
@ -1101,9 +1124,9 @@ int cmCTest::BuildDirectory()
}
}
// Warnings
for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
for ( cc = 0; cc < m_CustomWarningMatches.size(); cc ++ )
{
cmsys::RegularExpression re(cmCTestWarningMatches[cc]);
cmsys::RegularExpression re(m_CustomWarningMatches[cc].c_str());
cmCTest::tm_VectorOfStrings::size_type kk;
for ( kk = 0; kk < lines.size(); kk ++ )
{
@ -1114,9 +1137,9 @@ int cmCTest::BuildDirectory()
}
}
// Errors exceptions
for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
for ( cc = 0; cc < m_CustomErrorExceptions.size(); cc ++ )
{
cmsys::RegularExpression re(cmCTestErrorExceptions[cc]);
cmsys::RegularExpression re(m_CustomErrorExceptions[cc].c_str());
std::vector<int>::size_type kk;
for ( kk =0; kk < markedLines.size(); kk ++ )
{
@ -1130,9 +1153,9 @@ int cmCTest::BuildDirectory()
}
}
// Warning exceptions
for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
for ( cc = 0; cc < m_CustomWarningExceptions.size(); cc ++ )
{
cmsys::RegularExpression re(cmCTestWarningExceptions[cc]);
cmsys::RegularExpression re(m_CustomWarningExceptions[cc].c_str());
std::vector<int>::size_type kk;
for ( kk =0; kk < markedLines.size(); kk ++ )
{
@ -1818,6 +1841,52 @@ void cmCTest::ProcessDirectory(cmCTest::tm_VectorOfStrings &passed,
{
continue;
}
if ( memcheck )
{
tm_VectorOfStrings::iterator it;
bool found = false;
for ( it = m_CustomMemCheckIgnore.begin();
it != m_CustomMemCheckIgnore.end(); ++ it )
{
if ( *it == args[0].Value )
{
found = true;
break;
}
}
if ( found )
{
if ( m_Verbose )
{
std::cout << "Ignore memcheck: " << *it << std::endl;
}
continue;
}
}
else
{
tm_VectorOfStrings::iterator it;
bool found = false;
for ( it = m_CustomTestsIgnore.begin();
it != m_CustomTestsIgnore.end(); ++ it )
{
if ( *it == args[0].Value )
{
found = true;
break;
}
}
if ( found )
{
if ( m_Verbose )
{
std::cout << "Ignore test: " << *it << std::endl;
}
continue;
}
}
if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
{
continue;
@ -2101,6 +2170,23 @@ int cmCTest::TestDirectory(bool memcheck)
}
}
if ( memcheck )
{
if ( !this->ExecuteCommands(m_CustomPreMemCheck) )
{
std::cerr << "Problem executing pre-memcheck command(s)." << std::endl;
return 1;
}
}
else
{
if ( !this->ExecuteCommands(m_CustomPreTest) )
{
std::cerr << "Problem executing pre-test command(s)." << std::endl;
return 1;
}
}
cmCTest::tm_VectorOfStrings passed;
cmCTest::tm_VectorOfStrings failed;
int total;
@ -2170,6 +2256,23 @@ int cmCTest::TestDirectory(bool memcheck)
}
}
if ( memcheck )
{
if ( !this->ExecuteCommands(m_CustomPostMemCheck) )
{
std::cerr << "Problem executing post-memcheck command(s)." << std::endl;
return 1;
}
}
else
{
if ( !this->ExecuteCommands(m_CustomPostTest) )
{
std::cerr << "Problem executing post-test command(s)." << std::endl;
return 1;
}
}
return int(failed.size());
}
@ -2854,7 +2957,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *re
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin());
// std::cout << "Command is: " << argv[0] << std::endl;
// std::cout << "Command is: " << argv[0] << std::endl;
if(cmSystemTools::GetRunCommandHideConsole())
{
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
@ -3846,8 +3949,14 @@ int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
}
else
{
this->Initialize();
if ( !this->Initialize() )
{
res = 12;
}
else
{
res = this->ProcessTests();
}
this->Finalize();
}
return res;
@ -4153,7 +4262,7 @@ int cmCTest::RunCMakeAndTest(std::string* outstring)
return retVal;
}
// now run the compiled test if we can find it
// now run the compiled test if we can find it
// See if the executable exists as written.
std::vector<std::string> failed;
std::string fullPath;
@ -4296,3 +4405,85 @@ void cmCTest::SetNotesFiles(const char* notes)
}
m_NotesFiles = notes;
}
int cmCTest::ReadCustomConfigurationFileTree(const char* dir)
{
tm_VectorOfStrings dirs;
tm_VectorOfStrings ndirs;
dirs.push_back(dir);
cmake cm;
cmGlobalGenerator gg;
gg.SetCMakeInstance(&cm);
cmLocalGenerator *lg = gg.CreateLocalGenerator();
lg->SetGlobalGenerator(&gg);
cmMakefile *mf = lg->GetMakefile();
while ( dirs.size() > 0 )
{
tm_VectorOfStrings::iterator cdir = dirs.end()-1;
std::string rexpr = *cdir + "/*";
std::string fname = *cdir + "/CTestCustom.ctest";
if ( cmSystemTools::FileExists(fname.c_str()) &&
(!lg->GetMakefile()->ReadListFile(0, fname.c_str()) ||
cmSystemTools::GetErrorOccuredFlag() ) )
{
std::cerr << "Problem reading custom configuration" << std::endl;
return 0;
}
dirs.erase(dirs.end()-1, dirs.end());
cmSystemTools::SimpleGlob(rexpr, ndirs, -1);
dirs.insert(dirs.end(), ndirs.begin(), ndirs.end());
}
this->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_MATCH", m_CustomErrorMatches);
this->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_EXCEPTION", m_CustomErrorExceptions);
this->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_MATCH", m_CustomWarningMatches);
this->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_EXCEPTION", m_CustomWarningExceptions);
this->PopulateCustomVector(mf, "CTEST_CUSTOM_TESTS_IGNORE", m_CustomTestsIgnore);
this->PopulateCustomVector(mf, "CTEST_CUSTOM_MEMCHECK_IGNORE", m_CustomMemCheckIgnore);
this->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST", m_CustomPreTest);
this->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST", m_CustomPostTest);
this->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_MEMCHECK", m_CustomPreMemCheck);
this->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_MEMCHECK", m_CustomPostMemCheck);
return 1;
}
void cmCTest::PopulateCustomVector(cmMakefile* mf, const char* def, tm_VectorOfStrings& vec)
{
if ( !def)
{
return;
}
const char* dval = mf->GetDefinition(def);
if ( !dval )
{
return;
}
std::vector<std::string> slist;
cmSystemTools::ExpandListArgument(dval, slist);
vec.insert(vec.end(), slist.begin(), slist.end());
}
int cmCTest::ExecuteCommands(tm_VectorOfStrings& vec)
{
tm_VectorOfStrings::iterator it;
for ( it = vec.begin(); it != vec.end(); ++it )
{
int retVal = 0;
if ( m_Verbose )
{
std::cout << "Run command: " << *it << std::endl;
}
if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true /*m_Verbose*/) ||
retVal != 0 )
{
std::cerr << "Problem running command: " << *it << std::endl;
return 0;
}
}
return 1;
}

View File

@ -21,6 +21,8 @@
#include "cmStandardIncludes.h"
class cmMakefile;
class cmCTest
{
public:
@ -37,7 +39,7 @@ public:
/**
* Initialize and finalize testing
*/
void Initialize();
int Initialize();
void Finalize();
/**
@ -315,6 +317,24 @@ private:
bool m_BuildNoCMake;
std::string m_NotesFiles;
int ReadCustomConfigurationFileTree(const char* dir);
void PopulateCustomVector(cmMakefile* mf, const char* definition, tm_VectorOfStrings& vec);
tm_VectorOfStrings m_CustomErrorMatches;
tm_VectorOfStrings m_CustomErrorExceptions;
tm_VectorOfStrings m_CustomWarningMatches;
tm_VectorOfStrings m_CustomWarningExceptions;
tm_VectorOfStrings m_CustomTestsIgnore;
tm_VectorOfStrings m_CustomMemCheckIgnore;
tm_VectorOfStrings m_CustomPreTest;
tm_VectorOfStrings m_CustomPostTest;
tm_VectorOfStrings m_CustomPreMemCheck;
tm_VectorOfStrings m_CustomPostMemCheck;
int ExecuteCommands(tm_VectorOfStrings& vec);
//! Reread the configuration file
void UpdateCTestConfiguration();