mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-23 06:47:08 -05:00
CTest: create one output file per memcheck (#14303)
The output file used for memory checker runs must be unique for every test run in parallel, so simply make them unique for every test run. Simply use the test index to avoid collisions.
This commit is contained in:
@@ -89,7 +89,7 @@ void cmCTestBatchTestHandler::WriteTestCommand(int test, std::fstream& fout)
|
||||
command = cmSystemTools::ConvertToOutputPath(command.c_str());
|
||||
|
||||
//Prepends memcheck args to our command string if this is a memcheck
|
||||
this->TestHandler->GenerateTestCommand(processArgs);
|
||||
this->TestHandler->GenerateTestCommand(processArgs, test);
|
||||
processArgs.push_back(command);
|
||||
|
||||
for(std::vector<std::string>::iterator arg = processArgs.begin();
|
||||
|
||||
@@ -200,6 +200,7 @@ void cmCTestMemCheckHandler::Initialize()
|
||||
this->CustomMaximumPassedTestOutputSize = 0;
|
||||
this->CustomMaximumFailedTestOutputSize = 0;
|
||||
this->MemoryTester = "";
|
||||
this->MemoryTesterDynamicOptions.clear();
|
||||
this->MemoryTesterOptions.clear();
|
||||
this->MemoryTesterStyle = UNKNOWN;
|
||||
this->MemoryTesterOutputFile = "";
|
||||
@@ -242,12 +243,28 @@ int cmCTestMemCheckHandler::PostProcessHandler()
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void cmCTestMemCheckHandler::GenerateTestCommand(
|
||||
std::vector<std::string>& args)
|
||||
std::vector<std::string>& args, int test)
|
||||
{
|
||||
std::vector<cmStdString>::size_type pp;
|
||||
std::string memcheckcommand = "";
|
||||
memcheckcommand
|
||||
cmStdString index;
|
||||
cmOStringStream stream;
|
||||
std::string memcheckcommand
|
||||
= cmSystemTools::ConvertToOutputPath(this->MemoryTester.c_str());
|
||||
stream << test;
|
||||
index = stream.str();
|
||||
for ( pp = 0; pp < this->MemoryTesterDynamicOptions.size(); pp ++ )
|
||||
{
|
||||
cmStdString arg = this->MemoryTesterDynamicOptions[pp];
|
||||
cmStdString::size_type pos = arg.find("??");
|
||||
if (pos != cmStdString::npos)
|
||||
{
|
||||
arg.replace(pos, 2, index);
|
||||
}
|
||||
args.push_back(arg);
|
||||
memcheckcommand += " \"";
|
||||
memcheckcommand += arg;
|
||||
memcheckcommand += "\"";
|
||||
}
|
||||
for ( pp = 0; pp < this->MemoryTesterOptions.size(); pp ++ )
|
||||
{
|
||||
args.push_back(this->MemoryTesterOptions[pp]);
|
||||
@@ -478,7 +495,8 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
|
||||
= cmSystemTools::ParseArguments(memoryTesterOptions.c_str());
|
||||
|
||||
this->MemoryTesterOutputFile
|
||||
= this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.log";
|
||||
= this->CTest->GetBinaryDir()
|
||||
+ "/Testing/Temporary/MemoryChecker.??.log";
|
||||
|
||||
switch ( this->MemoryTesterStyle )
|
||||
{
|
||||
@@ -510,7 +528,7 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
|
||||
}
|
||||
std::string outputFile = "--log-file="
|
||||
+ this->MemoryTesterOutputFile;
|
||||
this->MemoryTesterOptions.push_back(outputFile);
|
||||
this->MemoryTesterDynamicOptions.push_back(outputFile);
|
||||
break;
|
||||
}
|
||||
case cmCTestMemCheckHandler::PURIFY:
|
||||
@@ -538,19 +556,19 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
|
||||
outputFile = "-log-file=";
|
||||
#endif
|
||||
outputFile += this->MemoryTesterOutputFile;
|
||||
this->MemoryTesterOptions.push_back(outputFile);
|
||||
this->MemoryTesterDynamicOptions.push_back(outputFile);
|
||||
break;
|
||||
}
|
||||
case cmCTestMemCheckHandler::BOUNDS_CHECKER:
|
||||
{
|
||||
this->BoundsCheckerXMLFile = this->MemoryTesterOutputFile;
|
||||
std::string dpbdFile = this->CTest->GetBinaryDir()
|
||||
+ "/Testing/Temporary/MemoryChecker.DPbd";
|
||||
+ "/Testing/Temporary/MemoryChecker.??.DPbd";
|
||||
this->BoundsCheckerDPBDFile = dpbdFile;
|
||||
this->MemoryTesterOptions.push_back("/B");
|
||||
this->MemoryTesterOptions.push_back(dpbdFile);
|
||||
this->MemoryTesterOptions.push_back("/X");
|
||||
this->MemoryTesterOptions.push_back(this->MemoryTesterOutputFile);
|
||||
this->MemoryTesterDynamicOptions.push_back("/B");
|
||||
this->MemoryTesterDynamicOptions.push_back(dpbdFile);
|
||||
this->MemoryTesterDynamicOptions.push_back("/X");
|
||||
this->MemoryTesterDynamicOptions.push_back(this->MemoryTesterOutputFile);
|
||||
this->MemoryTesterOptions.push_back("/M");
|
||||
break;
|
||||
}
|
||||
@@ -898,25 +916,23 @@ bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput(
|
||||
// This method puts the bounds checker output file into the output
|
||||
// for the test
|
||||
void
|
||||
cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(cmCTestTestResult& res)
|
||||
cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(cmCTestTestResult& res,
|
||||
int test)
|
||||
{
|
||||
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||
"PostProcessBoundsCheckerTest for : "
|
||||
<< res.Name.c_str() << std::endl);
|
||||
if ( !cmSystemTools::FileExists(this->MemoryTesterOutputFile.c_str()) )
|
||||
cmStdString ofile = testOutputFileName(test);
|
||||
if ( ofile.empty() )
|
||||
{
|
||||
std::string log = "Cannot find memory tester output file: "
|
||||
+ this->MemoryTesterOutputFile;
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
|
||||
return;
|
||||
}
|
||||
// put a scope around this to close ifs so the file can be removed
|
||||
{
|
||||
std::ifstream ifs(this->MemoryTesterOutputFile.c_str());
|
||||
std::ifstream ifs(ofile.c_str());
|
||||
if ( !ifs )
|
||||
{
|
||||
std::string log = "Cannot read memory tester output file: "
|
||||
+ this->MemoryTesterOutputFile;
|
||||
std::string log = "Cannot read memory tester output file: " + ofile;
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
|
||||
return;
|
||||
}
|
||||
@@ -939,38 +955,39 @@ cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(cmCTestTestResult& res)
|
||||
}
|
||||
|
||||
void
|
||||
cmCTestMemCheckHandler::PostProcessPurifyTest(cmCTestTestResult& res)
|
||||
cmCTestMemCheckHandler::PostProcessPurifyTest(cmCTestTestResult& res,
|
||||
int test)
|
||||
{
|
||||
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||
"PostProcessPurifyTest for : "
|
||||
<< res.Name.c_str() << std::endl);
|
||||
appendMemTesterOutput(res);
|
||||
appendMemTesterOutput(res, test);
|
||||
}
|
||||
|
||||
void
|
||||
cmCTestMemCheckHandler::PostProcessValgrindTest(cmCTestTestResult& res)
|
||||
cmCTestMemCheckHandler::PostProcessValgrindTest(cmCTestTestResult& res,
|
||||
int test)
|
||||
{
|
||||
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
||||
"PostProcessValgrindTest for : "
|
||||
<< res.Name.c_str() << std::endl);
|
||||
appendMemTesterOutput(res);
|
||||
appendMemTesterOutput(res, test);
|
||||
}
|
||||
|
||||
void
|
||||
cmCTestMemCheckHandler::appendMemTesterOutput(cmCTestTestResult& res)
|
||||
cmCTestMemCheckHandler::appendMemTesterOutput(cmCTestTestResult& res,
|
||||
int test)
|
||||
{
|
||||
if ( !cmSystemTools::FileExists(this->MemoryTesterOutputFile.c_str()) )
|
||||
cmStdString ofile = testOutputFileName(test);
|
||||
|
||||
if ( ofile.empty() )
|
||||
{
|
||||
std::string log = "Cannot find memory tester output file: "
|
||||
+ this->MemoryTesterOutputFile;
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
|
||||
return;
|
||||
}
|
||||
std::ifstream ifs(this->MemoryTesterOutputFile.c_str());
|
||||
std::ifstream ifs(ofile.c_str());
|
||||
if ( !ifs )
|
||||
{
|
||||
std::string log = "Cannot read memory tester output file: "
|
||||
+ this->MemoryTesterOutputFile;
|
||||
std::string log = "Cannot read memory tester output file: " + ofile;
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
|
||||
return;
|
||||
}
|
||||
@@ -981,3 +998,25 @@ cmCTestMemCheckHandler::appendMemTesterOutput(cmCTestTestResult& res)
|
||||
res.Output += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
cmStdString
|
||||
cmCTestMemCheckHandler::testOutputFileName(int test)
|
||||
{
|
||||
cmStdString index;
|
||||
cmOStringStream stream;
|
||||
stream << test;
|
||||
index = stream.str();
|
||||
cmStdString ofile = this->MemoryTesterOutputFile;
|
||||
cmStdString::size_type pos = ofile.find("??");
|
||||
ofile.replace(pos, 2, index);
|
||||
|
||||
if ( !cmSystemTools::FileExists(ofile.c_str()) )
|
||||
{
|
||||
std::string log = "Cannot find memory tester output file: "
|
||||
+ ofile;
|
||||
cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
|
||||
ofile = "";
|
||||
}
|
||||
|
||||
return ofile;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
protected:
|
||||
virtual int PreProcessHandler();
|
||||
virtual int PostProcessHandler();
|
||||
virtual void GenerateTestCommand(std::vector<std::string>& args);
|
||||
virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
|
||||
|
||||
private:
|
||||
|
||||
@@ -89,6 +89,7 @@ private:
|
||||
std::string BoundsCheckerDPBDFile;
|
||||
std::string BoundsCheckerXMLFile;
|
||||
std::string MemoryTester;
|
||||
std::vector<cmStdString> MemoryTesterDynamicOptions;
|
||||
std::vector<cmStdString> MemoryTesterOptions;
|
||||
int MemoryTesterStyle;
|
||||
std::string MemoryTesterOutputFile;
|
||||
@@ -117,12 +118,16 @@ private:
|
||||
bool ProcessMemCheckBoundsCheckerOutput(const std::string& str,
|
||||
std::string& log, int* results);
|
||||
|
||||
void PostProcessPurifyTest(cmCTestTestResult& res);
|
||||
void PostProcessBoundsCheckerTest(cmCTestTestResult& res);
|
||||
void PostProcessValgrindTest(cmCTestTestResult& res);
|
||||
void PostProcessPurifyTest(cmCTestTestResult& res, int test);
|
||||
void PostProcessBoundsCheckerTest(cmCTestTestResult& res, int test);
|
||||
void PostProcessValgrindTest(cmCTestTestResult& res, int test);
|
||||
|
||||
///! append MemoryTesterOutputFile to the test log
|
||||
void appendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res);
|
||||
void appendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res,
|
||||
int test);
|
||||
|
||||
///! generate the output filename for the given test index
|
||||
cmStdString testOutputFileName(int test);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -389,13 +389,13 @@ void cmCTestRunTest::MemCheckPostProcess()
|
||||
switch ( handler->MemoryTesterStyle )
|
||||
{
|
||||
case cmCTestMemCheckHandler::VALGRIND:
|
||||
handler->PostProcessValgrindTest(this->TestResult);
|
||||
handler->PostProcessValgrindTest(this->TestResult, this->Index);
|
||||
break;
|
||||
case cmCTestMemCheckHandler::PURIFY:
|
||||
handler->PostProcessPurifyTest(this->TestResult);
|
||||
handler->PostProcessPurifyTest(this->TestResult, this->Index);
|
||||
break;
|
||||
case cmCTestMemCheckHandler::BOUNDS_CHECKER:
|
||||
handler->PostProcessBoundsCheckerTest(this->TestResult);
|
||||
handler->PostProcessBoundsCheckerTest(this->TestResult, this->Index);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -524,7 +524,7 @@ void cmCTestRunTest::ComputeArguments()
|
||||
= cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str());
|
||||
|
||||
//Prepends memcheck args to our command string
|
||||
this->TestHandler->GenerateTestCommand(this->Arguments);
|
||||
this->TestHandler->GenerateTestCommand(this->Arguments, this->Index);
|
||||
for(std::vector<std::string>::iterator i = this->Arguments.begin();
|
||||
i != this->Arguments.end(); ++i)
|
||||
{
|
||||
|
||||
@@ -1107,7 +1107,7 @@ void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void cmCTestTestHandler::GenerateTestCommand(std::vector<std::string>&)
|
||||
void cmCTestTestHandler::GenerateTestCommand(std::vector<std::string>&, int)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ protected:
|
||||
// compute a final test list
|
||||
virtual int PreProcessHandler();
|
||||
virtual int PostProcessHandler();
|
||||
virtual void GenerateTestCommand(std::vector<std::string>& args);
|
||||
virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
|
||||
int ExecuteCommands(std::vector<cmStdString>& vec);
|
||||
|
||||
void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
|
||||
|
||||
Reference in New Issue
Block a user