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 "cmGlobalGenerator.h"
#include <cmsys/Directory.hxx> #include <cmsys/Directory.hxx>
#include "cmListFileCache.h" #include "cmListFileCache.h"
#include "cmGlob.h"
#include "cmCTestSubmit.h" #include "cmCTestSubmit.h"
#include "curl/curl.h" #include "curl/curl.h"
@ -324,10 +325,14 @@ cmCTest::cmCTest()
} }
} }
void cmCTest::Initialize() int cmCTest::Initialize()
{ {
m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory(); m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
cmSystemTools::ConvertToUnixSlashes(m_ToplevelPath); cmSystemTools::ConvertToUnixSlashes(m_ToplevelPath);
if ( !this->ReadCustomConfigurationFileTree(m_ToplevelPath.c_str()) )
{
return 0;
}
this->UpdateCTestConfiguration(); this->UpdateCTestConfiguration();
if ( m_DartMode ) if ( m_DartMode )
{ {
@ -338,7 +343,7 @@ void cmCTest::Initialize()
{ {
std::cerr << "File " << testingDir << " is in the place of the testing directory" std::cerr << "File " << testingDir << " is in the place of the testing directory"
<< std::endl; << std::endl;
return; return 0;
} }
} }
else else
@ -347,7 +352,7 @@ void cmCTest::Initialize()
{ {
std::cerr << "Cannot create directory " << testingDir std::cerr << "Cannot create directory " << testingDir
<< std::endl; << std::endl;
return; return 0;
} }
} }
std::string tagfile = testingDir + "/TAG"; std::string tagfile = testingDir + "/TAG";
@ -408,6 +413,7 @@ void cmCTest::Initialize()
} }
m_CurrentTag = tag; m_CurrentTag = tag;
} }
return 1;
} }
void cmCTest::UpdateCTestConfiguration() void cmCTest::UpdateCTestConfiguration()
@ -1042,7 +1048,7 @@ int cmCTest::BuildDirectory()
ofs.close(); ofs.close();
} }
int cc; tm_VectorOfStrings::size_type cc;
if ( m_DartConfiguration["SourceDirectory"].size() > 20 || if ( m_DartConfiguration["SourceDirectory"].size() > 20 ||
m_DartConfiguration["BuildDirectory"].size() > 20 ) m_DartConfiguration["BuildDirectory"].size() > 20 )
{ {
@ -1090,7 +1096,24 @@ int cmCTest::BuildDirectory()
// Errors // Errors
for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ ) 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; cmCTest::tm_VectorOfStrings::size_type kk;
for ( kk = 0; kk < lines.size(); kk ++ ) for ( kk = 0; kk < lines.size(); kk ++ )
{ {
@ -1101,9 +1124,9 @@ int cmCTest::BuildDirectory()
} }
} }
// Warnings // 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; cmCTest::tm_VectorOfStrings::size_type kk;
for ( kk = 0; kk < lines.size(); kk ++ ) for ( kk = 0; kk < lines.size(); kk ++ )
{ {
@ -1114,9 +1137,9 @@ int cmCTest::BuildDirectory()
} }
} }
// Errors exceptions // 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; std::vector<int>::size_type kk;
for ( kk =0; kk < markedLines.size(); kk ++ ) for ( kk =0; kk < markedLines.size(); kk ++ )
{ {
@ -1130,9 +1153,9 @@ int cmCTest::BuildDirectory()
} }
} }
// Warning exceptions // 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; std::vector<int>::size_type kk;
for ( kk =0; kk < markedLines.size(); kk ++ ) for ( kk =0; kk < markedLines.size(); kk ++ )
{ {
@ -1818,13 +1841,59 @@ void cmCTest::ProcessDirectory(cmCTest::tm_VectorOfStrings &passed,
{ {
continue; 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())) if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
{ {
continue; continue;
} }
if (this->m_UseExcludeRegExp && if (this->m_UseExcludeRegExp &&
!this->m_UseExcludeRegExpFirst && !this->m_UseExcludeRegExpFirst &&
ereg.find(args[0].Value.c_str())) ereg.find(args[0].Value.c_str()))
{ {
continue; continue;
} }
@ -1941,25 +2010,25 @@ void cmCTest::ProcessDirectory(cmCTest::tm_VectorOfStrings &passed,
fprintf(stderr,"***Exception: "); fprintf(stderr,"***Exception: ");
switch ( retVal ) switch ( retVal )
{ {
case cmsysProcess_Exception_Fault: case cmsysProcess_Exception_Fault:
fprintf(stderr,"SegFault"); fprintf(stderr,"SegFault");
cres.m_Status = cmCTest::SEGFAULT; cres.m_Status = cmCTest::SEGFAULT;
break; break;
case cmsysProcess_Exception_Illegal: case cmsysProcess_Exception_Illegal:
fprintf(stderr,"Illegal"); fprintf(stderr,"Illegal");
cres.m_Status = cmCTest::ILLEGAL; cres.m_Status = cmCTest::ILLEGAL;
break; break;
case cmsysProcess_Exception_Interrupt: case cmsysProcess_Exception_Interrupt:
fprintf(stderr,"Interrupt"); fprintf(stderr,"Interrupt");
cres.m_Status = cmCTest::INTERRUPT; cres.m_Status = cmCTest::INTERRUPT;
break; break;
case cmsysProcess_Exception_Numerical: case cmsysProcess_Exception_Numerical:
fprintf(stderr,"Numerical"); fprintf(stderr,"Numerical");
cres.m_Status = cmCTest::NUMERICAL; cres.m_Status = cmCTest::NUMERICAL;
break; break;
default: default:
fprintf(stderr,"Other"); fprintf(stderr,"Other");
cres.m_Status = cmCTest::OTHER_FAULT; cres.m_Status = cmCTest::OTHER_FAULT;
} }
fprintf(stderr,"\n"); fprintf(stderr,"\n");
} }
@ -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 passed;
cmCTest::tm_VectorOfStrings failed; cmCTest::tm_VectorOfStrings failed;
int total; int total;
@ -2125,7 +2211,7 @@ int cmCTest::TestDirectory(bool memcheck)
{ {
std::cerr << "\nThe following tests passed:\n"; std::cerr << "\nThe following tests passed:\n";
for(cmCTest::tm_VectorOfStrings::iterator j = passed.begin(); for(cmCTest::tm_VectorOfStrings::iterator j = passed.begin();
j != passed.end(); ++j) j != passed.end(); ++j)
{ {
std::cerr << "\t" << *j << "\n"; std::cerr << "\t" << *j << "\n";
} }
@ -2137,13 +2223,13 @@ int cmCTest::TestDirectory(bool memcheck)
percent = 99; percent = 99;
} }
fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n", fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
percent, int(failed.size()), total); percent, int(failed.size()), total);
if (failed.size()) if (failed.size())
{ {
std::cerr << "\nThe following tests FAILED:\n"; std::cerr << "\nThe following tests FAILED:\n";
for(cmCTest::tm_VectorOfStrings::iterator j = failed.begin(); for(cmCTest::tm_VectorOfStrings::iterator j = failed.begin();
j != failed.end(); ++j) j != failed.end(); ++j)
{ {
std::cerr << "\t" << *j << "\n"; std::cerr << "\t" << *j << "\n";
} }
@ -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()); return int(failed.size());
} }
@ -2233,7 +2336,7 @@ int cmCTest::SubmitResults()
cmCTestSubmit submit; cmCTestSubmit submit;
submit.SetVerbose(m_Verbose); submit.SetVerbose(m_Verbose);
if ( m_DartConfiguration["DropMethod"] == "" || if ( m_DartConfiguration["DropMethod"] == "" ||
m_DartConfiguration["DropMethod"] == "ftp" ) m_DartConfiguration["DropMethod"] == "ftp" )
{ {
std::cout << " Using FTP submit method" << std::endl; std::cout << " Using FTP submit method" << std::endl;
std::string url = "ftp://"; std::string url = "ftp://";
@ -2323,14 +2426,14 @@ void cmCTest::GenerateDartMemCheckOutput(std::ostream& os)
os << "<MemCheck>" << std::endl; os << "<MemCheck>" << std::endl;
} }
os << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n" os << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
<< "\t<TestList>\n"; << "\t<TestList>\n";
tm_TestResultsVector::size_type cc; tm_TestResultsVector::size_type cc;
for ( cc = 0; cc < m_TestResults.size(); cc ++ ) for ( cc = 0; cc < m_TestResults.size(); cc ++ )
{ {
cmCTestTestResult *result = &m_TestResults[cc]; cmCTestTestResult *result = &m_TestResults[cc];
os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path) os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
<< "/" << this->MakeXMLSafe(result->m_Name) << "/" << this->MakeXMLSafe(result->m_Name)
<< "</Test>" << std::endl; << "</Test>" << std::endl;
} }
os << "\t</TestList>\n"; os << "\t</TestList>\n";
for ( cc = 0; cc < m_TestResults.size(); cc ++ ) for ( cc = 0; cc < m_TestResults.size(); cc ++ )
@ -2405,15 +2508,15 @@ void cmCTest::GenerateDartTestOutput(std::ostream& os)
this->StartXML(os); this->StartXML(os);
os << "<Testing>\n" os << "<Testing>\n"
<< "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n" << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
<< "\t<TestList>\n"; << "\t<TestList>\n";
tm_TestResultsVector::size_type cc; tm_TestResultsVector::size_type cc;
for ( cc = 0; cc < m_TestResults.size(); cc ++ ) for ( cc = 0; cc < m_TestResults.size(); cc ++ )
{ {
cmCTestTestResult *result = &m_TestResults[cc]; cmCTestTestResult *result = &m_TestResults[cc];
os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path) os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
<< "/" << this->MakeXMLSafe(result->m_Name) << "/" << this->MakeXMLSafe(result->m_Name)
<< "</Test>" << std::endl; << "</Test>" << std::endl;
} }
os << "\t</TestList>\n"; os << "\t</TestList>\n";
for ( cc = 0; cc < m_TestResults.size(); cc ++ ) for ( cc = 0; cc < m_TestResults.size(); cc ++ )
@ -2469,7 +2572,7 @@ void cmCTest::GenerateDartTestOutput(std::ostream& os)
} }
os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n" os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
<< "</Testing>" << std::endl; << "</Testing>" << std::endl;
this->EndXML(os); this->EndXML(os);
} }
@ -2556,10 +2659,10 @@ std::string cmCTest::GetTestModelString()
{ {
switch ( m_TestModel ) switch ( m_TestModel )
{ {
case cmCTest::NIGHTLY: case cmCTest::NIGHTLY:
return "Nightly"; return "Nightly";
case cmCTest::CONTINUOUS: case cmCTest::CONTINUOUS:
return "Continuous"; return "Continuous";
} }
return "Experimental"; return "Experimental";
} }
@ -2661,7 +2764,7 @@ std::string cmCTest::GenerateRegressionImages(const std::string& xml)
#ifdef _WIN32 #ifdef _WIN32
| std::ios::binary | std::ios::binary
#endif #endif
); );
unsigned char *file_buffer = new unsigned char [ len + 1 ]; unsigned char *file_buffer = new unsigned char [ len + 1 ];
ifs.read(reinterpret_cast<char*>(file_buffer), len); ifs.read(reinterpret_cast<char*>(file_buffer), len);
unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 1) ]; unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 1) ];
@ -2715,7 +2818,7 @@ std::string cmCTest::GenerateRegressionImages(const std::string& xml)
} }
int cmCTest::RunMakeCommand(const char* command, std::string* output, int cmCTest::RunMakeCommand(const char* command, std::string* output,
int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs) int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs)
{ {
std::vector<cmStdString> args = cmSystemTools::ParseArguments(command); std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
@ -2726,7 +2829,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string* output,
std::vector<const char*> argv; std::vector<const char*> argv;
for(std::vector<cmStdString>::const_iterator a = args.begin(); for(std::vector<cmStdString>::const_iterator a = args.begin();
a != args.end(); ++a) a != args.end(); ++a)
{ {
argv.push_back(a->c_str()); argv.push_back(a->c_str());
} }
@ -2854,7 +2957,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *re
cmsysProcess* cp = cmsysProcess_New(); cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_SetCommand(cp, &*argv.begin()); cmsysProcess_SetCommand(cp, &*argv.begin());
// std::cout << "Command is: " << argv[0] << std::endl; // std::cout << "Command is: " << argv[0] << std::endl;
if(cmSystemTools::GetRunCommandHideConsole()) if(cmSystemTools::GetRunCommandHideConsole())
{ {
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
@ -2932,27 +3035,27 @@ const char* cmCTest::GetTestStatus(int status)
} }
void cmCTest::RestoreBackupDirectories(bool backup, void cmCTest::RestoreBackupDirectories(bool backup,
const char *srcDir, const char *srcDir,
const char *binDir, const char *binDir,
const char *backupSrcDir, const char *backupSrcDir,
const char *backupBinDir) const char *backupBinDir)
{ {
// if we backed up the dirs and the build failed, then restore // if we backed up the dirs and the build failed, then restore
// the backed up dirs // the backed up dirs
if (backup) if (backup)
{ {
// if for some reason those directories exist then first delete them // if for some reason those directories exist then first delete them
if (cmSystemTools::FileExists(srcDir)) if (cmSystemTools::FileExists(srcDir))
{ {
cmSystemTools::RemoveADirectory(srcDir); cmSystemTools::RemoveADirectory(srcDir);
} }
if (cmSystemTools::FileExists(binDir)) if (cmSystemTools::FileExists(binDir))
{ {
cmSystemTools::RemoveADirectory(binDir); cmSystemTools::RemoveADirectory(binDir);
} }
// rename the src and binary directories // rename the src and binary directories
rename(backupSrcDir, srcDir); rename(backupSrcDir, srcDir);
rename(backupBinDir, binDir); rename(backupBinDir, binDir);
} }
} }
@ -2978,11 +3081,11 @@ int cmCTest::RunConfigurationScript()
// set a variable with the path to the current script // set a variable with the path to the current script
lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_DIRECTORY", lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_DIRECTORY",
cmSystemTools::GetFilenamePath( cmSystemTools::GetFilenamePath(
m_ConfigurationScript).c_str()); m_ConfigurationScript).c_str());
lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_NAME", lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_NAME",
cmSystemTools::GetFilenameName( cmSystemTools::GetFilenameName(
m_ConfigurationScript).c_str()); m_ConfigurationScript).c_str());
if (!lg->GetMakefile()->ReadListFile(0, m_ConfigurationScript.c_str())) if (!lg->GetMakefile()->ReadListFile(0, m_ConfigurationScript.c_str()))
{ {
return 2; return 2;
@ -3062,22 +3165,22 @@ int cmCTest::RunConfigurationScript()
{ {
cmSystemTools::Error("Unable to create the src directory"); cmSystemTools::Error("Unable to create the src directory");
this->RestoreBackupDirectories(backup, srcDir, binDir, this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(), backupSrcDir.c_str(),
backupBinDir.c_str()); backupBinDir.c_str());
return 5; return 5;
} }
// then do the checkout // then do the checkout
output = ""; output = "";
res = cmSystemTools::RunSingleCommand(cvsCheckOut, &output, res = cmSystemTools::RunSingleCommand(cvsCheckOut, &output,
&retVal, ctestRoot, &retVal, ctestRoot,
m_Verbose, 0 /*m_TimeOut*/); m_Verbose, 0 /*m_TimeOut*/);
if (!res || retVal != 0) if (!res || retVal != 0)
{ {
cmSystemTools::Error("Unable to perform cvs checkout "); cmSystemTools::Error("Unable to perform cvs checkout ");
this->RestoreBackupDirectories(backup, srcDir, binDir, this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(), backupSrcDir.c_str(),
backupBinDir.c_str()); backupBinDir.c_str());
return 6; return 6;
} }
} }
@ -3101,8 +3204,8 @@ int cmCTest::RunConfigurationScript()
{ {
cmSystemTools::Error("Unable to create the binary directory"); cmSystemTools::Error("Unable to create the binary directory");
this->RestoreBackupDirectories(backup, srcDir, binDir, this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(), backupSrcDir.c_str(),
backupBinDir.c_str()); backupBinDir.c_str());
return 7; return 7;
} }
} }
@ -3130,14 +3233,14 @@ int cmCTest::RunConfigurationScript()
output = ""; output = "";
retVal = 0; retVal = 0;
res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output, res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output,
&retVal, cvsArgs[0].c_str(), &retVal, cvsArgs[0].c_str(),
m_Verbose, 0 /*m_TimeOut*/); m_Verbose, 0 /*m_TimeOut*/);
if (!res || retVal != 0) if (!res || retVal != 0)
{ {
cmSystemTools::Error("Unable to perform extra cvs updates"); cmSystemTools::Error("Unable to perform extra cvs updates");
this->RestoreBackupDirectories(backup, srcDir, binDir, this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(), backupSrcDir.c_str(),
backupBinDir.c_str()); backupBinDir.c_str());
return 8; return 8;
} }
} }
@ -3155,8 +3258,8 @@ int cmCTest::RunConfigurationScript()
if(!fout) if(!fout)
{ {
this->RestoreBackupDirectories(backup, srcDir, binDir, this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(), backupSrcDir.c_str(),
backupBinDir.c_str()); backupBinDir.c_str());
return 9; return 9;
} }
@ -3181,8 +3284,8 @@ int cmCTest::RunConfigurationScript()
command += "\""; command += "\"";
retVal = 0; retVal = 0;
res = cmSystemTools::RunSingleCommand(command.c_str(), &output, res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
&retVal, binDir, &retVal, binDir,
m_Verbose, 0 /*m_TimeOut*/); m_Verbose, 0 /*m_TimeOut*/);
if (!res || retVal != 0) if (!res || retVal != 0)
{ {
// even if this fails continue to the next step // even if this fails continue to the next step
@ -3195,16 +3298,16 @@ int cmCTest::RunConfigurationScript()
output = ""; output = "";
retVal = 0; retVal = 0;
res = cmSystemTools::RunSingleCommand(command.c_str(), &output, res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
&retVal, binDir, &retVal, binDir,
m_Verbose, 0 /*m_TimeOut*/); m_Verbose, 0 /*m_TimeOut*/);
// did something critical fail in ctest // did something critical fail in ctest
if (!res || cmakeFailed || if (!res || cmakeFailed ||
retVal & CTEST_BUILD_ERRORS) retVal & CTEST_BUILD_ERRORS)
{ {
this->RestoreBackupDirectories(backup, srcDir, binDir, this->RestoreBackupDirectories(backup, srcDir, binDir,
backupSrcDir.c_str(), backupSrcDir.c_str(),
backupBinDir.c_str()); backupBinDir.c_str());
if (cmakeFailed) if (cmakeFailed)
{ {
cmSystemTools::Error("Unable to run cmake"); cmSystemTools::Error("Unable to run cmake");
@ -3340,7 +3443,7 @@ bool cmCTest::ProcessMemCheckValgrindOutput(const std::string& str, std::string&
if ( valgrindLine.find(lines[cc]) ) if ( valgrindLine.find(lines[cc]) )
{ {
int failure = cmCTest::NO_MEMORY_FAULT; int failure = cmCTest::NO_MEMORY_FAULT;
if ( vgFIM.find(lines[cc]) ) { failure = cmCTest::FIM; } if ( vgFIM.find(lines[cc]) ) { failure = cmCTest::FIM; }
else if ( vgFMM.find(lines[cc]) ) { failure = cmCTest::FMM; } else if ( vgFMM.find(lines[cc]) ) { failure = cmCTest::FMM; }
else if ( vgMLK.find(lines[cc]) ) { failure = cmCTest::MLK; } else if ( vgMLK.find(lines[cc]) ) { failure = cmCTest::MLK; }
else if ( vgPAR.find(lines[cc]) ) { failure = cmCTest::PAR; } else if ( vgPAR.find(lines[cc]) ) { failure = cmCTest::PAR; }
@ -3685,7 +3788,7 @@ int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
} }
if( ( arg.find("-T",0) == 0 ) && if( ( arg.find("-T",0) == 0 ) &&
(i < args.size() -1) ) (i < args.size() -1) )
{ {
this->m_DartMode = true; this->m_DartMode = true;
i++; i++;
@ -3693,7 +3796,7 @@ int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
} }
if( ( arg.find("-M",0) == 0 || arg.find("--test-model",0) == 0 ) && if( ( arg.find("-M",0) == 0 || arg.find("--test-model",0) == 0 ) &&
(i < args.size() -1) ) (i < args.size() -1) )
{ {
i++; i++;
std::string const& str = args[i]; std::string const& str = args[i];
@ -3702,7 +3805,7 @@ int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
this->SetTestModel(cmCTest::NIGHTLY); this->SetTestModel(cmCTest::NIGHTLY);
} }
else if ( str == "CONTINUOUS" || str == "continuous" || else if ( str == "CONTINUOUS" || str == "continuous" ||
str == "Continuous" ) str == "Continuous" )
{ {
this->SetTestModel(cmCTest::CONTINUOUS); this->SetTestModel(cmCTest::CONTINUOUS);
std::cout << "Continuous" << std::endl; std::cout << "Continuous" << std::endl;
@ -3806,7 +3909,7 @@ int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
{ {
m_BuildOptions.push_back(args[i]); m_BuildOptions.push_back(args[i]);
if(i+1 < args.size() if(i+1 < args.size()
&& (args[i+1] == "--build-target" || args[i+1] == "--test-command")) && (args[i+1] == "--build-target" || args[i+1] == "--test-command"))
{ {
done = true; done = true;
} }
@ -3846,8 +3949,14 @@ int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
} }
else else
{ {
this->Initialize(); if ( !this->Initialize() )
res = this->ProcessTests(); {
res = 12;
}
else
{
res = this->ProcessTests();
}
this->Finalize(); this->Finalize();
} }
return res; return res;
@ -3883,9 +3992,9 @@ void cmCTest::FindRunningCMake(const char* arg0)
std::string dir; std::string dir;
std::string file; std::string file;
if(cmSystemTools::SplitProgramPath(m_CTestSelf.c_str(), if(cmSystemTools::SplitProgramPath(m_CTestSelf.c_str(),
dir, dir,
file, file,
true)) true))
{ {
m_CMakeSelf = dir += "/cmake"; m_CMakeSelf = dir += "/cmake";
m_CMakeSelf += cmSystemTools::GetExecutableExtension(); m_CMakeSelf += cmSystemTools::GetExecutableExtension();
@ -4071,7 +4180,7 @@ int cmCTest::RunCMakeAndTest(std::string* outstring)
retVal = 0; retVal = 0;
std::string output; std::string output;
if (!cmSystemTools::RunSingleCommand(cleanCommand.c_str(), &output, &retVal) || if (!cmSystemTools::RunSingleCommand(cleanCommand.c_str(), &output, &retVal) ||
retVal) retVal)
{ {
out << "Error: " << cleanCommand.c_str() << " execution failed\n"; out << "Error: " << cleanCommand.c_str() << " execution failed\n";
out << output.c_str() << "\n"; out << output.c_str() << "\n";
@ -4153,7 +4262,7 @@ int cmCTest::RunCMakeAndTest(std::string* outstring)
return retVal; 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. // See if the executable exists as written.
std::vector<std::string> failed; std::vector<std::string> failed;
std::string fullPath; std::string fullPath;
@ -4168,7 +4277,7 @@ int cmCTest::RunCMakeAndTest(std::string* outstring)
std::string tryPath = m_TestCommand; std::string tryPath = m_TestCommand;
tryPath += cmSystemTools::GetExecutableExtension(); tryPath += cmSystemTools::GetExecutableExtension();
if(cmSystemTools::FileExists(tryPath.c_str()) if(cmSystemTools::FileExists(tryPath.c_str())
&& !cmSystemTools::FileIsDirectory(tryPath.c_str())) && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
{ {
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str()); fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
} }
@ -4179,7 +4288,7 @@ int cmCTest::RunCMakeAndTest(std::string* outstring)
tryPath = m_ConfigType + "/"; tryPath = m_ConfigType + "/";
tryPath += cmSystemTools::GetFilenameName(m_TestCommand); tryPath += cmSystemTools::GetFilenameName(m_TestCommand);
if(cmSystemTools::FileExists(tryPath.c_str()) if(cmSystemTools::FileExists(tryPath.c_str())
&& !cmSystemTools::FileIsDirectory(tryPath.c_str())) && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
{ {
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str()); fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
} }
@ -4188,7 +4297,7 @@ int cmCTest::RunCMakeAndTest(std::string* outstring)
failed.push_back(tryPath); failed.push_back(tryPath);
tryPath += cmSystemTools::GetExecutableExtension(); tryPath += cmSystemTools::GetExecutableExtension();
if(cmSystemTools::FileExists(tryPath.c_str()) if(cmSystemTools::FileExists(tryPath.c_str())
&& !cmSystemTools::FileIsDirectory(tryPath.c_str())) && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
{ {
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str()); fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
} }
@ -4200,7 +4309,7 @@ int cmCTest::RunCMakeAndTest(std::string* outstring)
tryPath += m_TestCommand; tryPath += m_TestCommand;
tryPath += cmSystemTools::GetExecutableExtension(); tryPath += cmSystemTools::GetExecutableExtension();
if(cmSystemTools::FileExists(tryPath.c_str()) if(cmSystemTools::FileExists(tryPath.c_str())
&& !cmSystemTools::FileIsDirectory(tryPath.c_str())) && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
{ {
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str()); fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
} }
@ -4213,7 +4322,7 @@ int cmCTest::RunCMakeAndTest(std::string* outstring)
tryPath += m_TestCommand; tryPath += m_TestCommand;
tryPath += cmSystemTools::GetExecutableExtension(); tryPath += cmSystemTools::GetExecutableExtension();
if(cmSystemTools::FileExists(tryPath.c_str()) if(cmSystemTools::FileExists(tryPath.c_str())
&& !cmSystemTools::FileIsDirectory(tryPath.c_str())) && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
{ {
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str()); fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
} }
@ -4296,3 +4405,85 @@ void cmCTest::SetNotesFiles(const char* notes)
} }
m_NotesFiles = 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" #include "cmStandardIncludes.h"
class cmMakefile;
class cmCTest class cmCTest
{ {
public: public:
@ -37,7 +39,7 @@ public:
/** /**
* Initialize and finalize testing * Initialize and finalize testing
*/ */
void Initialize(); int Initialize();
void Finalize(); void Finalize();
/** /**
@ -315,6 +317,24 @@ private:
bool m_BuildNoCMake; bool m_BuildNoCMake;
std::string m_NotesFiles; 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 //! Reread the configuration file
void UpdateCTestConfiguration(); void UpdateCTestConfiguration();