2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2005-01-27 23:54:47 +03:00
|
|
|
#include "cmCTestMemCheckHandler.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2005-01-27 23:54:47 +03:00
|
|
|
#include "cmCTest.h"
|
2016-08-24 23:01:40 +03:00
|
|
|
#include "cmSystemTools.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmXMLParser.h"
|
2015-05-24 21:40:47 +03:00
|
|
|
#include "cmXMLWriter.h"
|
2016-08-24 23:01:40 +03:00
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/FStream.hxx>
|
|
|
|
#include <cmsys/Glob.hxx>
|
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2016-08-24 23:01:40 +03:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string.h>
|
2005-01-27 23:54:47 +03:00
|
|
|
|
2007-07-24 22:43:31 +04:00
|
|
|
struct CatToErrorType
|
|
|
|
{
|
|
|
|
const char* ErrorCategory;
|
|
|
|
int ErrorCode;
|
|
|
|
};
|
|
|
|
|
|
|
|
static CatToErrorType cmCTestMemCheckBoundsChecker[] = {
|
|
|
|
// Error tags
|
2016-05-16 17:34:04 +03:00
|
|
|
{ "Write Overrun", cmCTestMemCheckHandler::ABW },
|
|
|
|
{ "Read Overrun", cmCTestMemCheckHandler::ABR },
|
|
|
|
{ "Memory Overrun", cmCTestMemCheckHandler::ABW },
|
|
|
|
{ "Allocation Conflict", cmCTestMemCheckHandler::FMM },
|
|
|
|
{ "Bad Pointer Use", cmCTestMemCheckHandler::FMW },
|
|
|
|
{ "Dangling Pointer", cmCTestMemCheckHandler::FMR },
|
2016-06-27 23:44:16 +03:00
|
|
|
{ CM_NULLPTR, 0 }
|
2007-07-24 22:43:31 +04:00
|
|
|
};
|
|
|
|
|
2014-07-15 01:01:47 +04:00
|
|
|
static void xmlReportError(int line, const char* msg, void* data)
|
|
|
|
{
|
|
|
|
cmCTest* ctest = (cmCTest*)data;
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestLog(ctest, ERROR_MESSAGE, "Error parsing XML in stream at line "
|
|
|
|
<< line << ": " << msg << std::endl);
|
2014-07-15 01:01:47 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 14:09:02 +04:00
|
|
|
// parse the xml file containing the results of last BoundsChecker run
|
2007-07-24 22:43:31 +04:00
|
|
|
class cmBoundsCheckerParser : public cmXMLParser
|
|
|
|
{
|
|
|
|
public:
|
2014-07-15 01:01:47 +04:00
|
|
|
cmBoundsCheckerParser(cmCTest* c)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
this->CTest = c;
|
|
|
|
this->SetErrorCallback(xmlReportError, (void*)c);
|
|
|
|
}
|
2016-06-23 02:02:39 +03:00
|
|
|
void StartElement(const std::string& name, const char** atts) CM_OVERRIDE
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (name == "MemoryLeak" || name == "ResourceLeak") {
|
|
|
|
this->Errors.push_back(cmCTestMemCheckHandler::MLK);
|
|
|
|
} else if (name == "Error" || name == "Dangling Pointer") {
|
|
|
|
this->ParseError(atts);
|
2007-07-24 22:43:31 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
// Create the log
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << name << ":\n";
|
|
|
|
int i = 0;
|
2016-06-27 23:44:16 +03:00
|
|
|
for (; atts[i] != CM_NULLPTR; i += 2) {
|
2016-05-16 17:34:04 +03:00
|
|
|
ostr << " " << atts[i] << " - " << atts[i + 1] << "\n";
|
2007-07-24 22:43:31 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
ostr << "\n";
|
|
|
|
this->Log += ostr.str();
|
|
|
|
}
|
2016-08-17 02:49:57 +03:00
|
|
|
void EndElement(const std::string& /*name*/) CM_OVERRIDE {}
|
2007-07-24 22:43:31 +04:00
|
|
|
|
|
|
|
const char* GetAttribute(const char* name, const char** atts)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
int i = 0;
|
2016-06-27 23:44:16 +03:00
|
|
|
for (; atts[i] != CM_NULLPTR; ++i) {
|
2016-05-16 17:34:04 +03:00
|
|
|
if (strcmp(name, atts[i]) == 0) {
|
|
|
|
return atts[i + 1];
|
|
|
|
}
|
2007-07-24 22:43:31 +04:00
|
|
|
}
|
2016-06-27 23:44:16 +03:00
|
|
|
return CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-24 22:43:31 +04:00
|
|
|
void ParseError(const char** atts)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
CatToErrorType* ptr = cmCTestMemCheckBoundsChecker;
|
|
|
|
const char* cat = this->GetAttribute("ErrorCategory", atts);
|
|
|
|
if (!cat) {
|
|
|
|
this->Errors.push_back(cmCTestMemCheckHandler::ABW); // do not know
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"No Category found in Bounds checker XML\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (ptr->ErrorCategory && cat) {
|
|
|
|
if (strcmp(ptr->ErrorCategory, cat) == 0) {
|
|
|
|
this->Errors.push_back(ptr->ErrorCode);
|
|
|
|
return; // found it we are done
|
|
|
|
}
|
|
|
|
ptr++;
|
2007-07-24 22:43:31 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ptr->ErrorCategory) {
|
|
|
|
this->Errors.push_back(cmCTestMemCheckHandler::ABW); // do not know
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
|
|
|
"Found unknown Bounds Checker error " << ptr->ErrorCategory
|
|
|
|
<< std::endl);
|
|
|
|
}
|
|
|
|
}
|
2007-07-24 22:43:31 +04:00
|
|
|
cmCTest* CTest;
|
|
|
|
std::vector<int> Errors;
|
|
|
|
std::string Log;
|
|
|
|
};
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
#define BOUNDS_CHECKER_MARKER \
|
|
|
|
"******######*****Begin BOUNDS CHECKER XML******######******"
|
2005-01-27 23:54:47 +03:00
|
|
|
|
|
|
|
cmCTestMemCheckHandler::cmCTestMemCheckHandler()
|
|
|
|
{
|
2006-03-10 23:03:09 +03:00
|
|
|
this->MemCheck = true;
|
2006-03-16 19:29:12 +03:00
|
|
|
this->CustomMaximumPassedTestOutputSize = 0;
|
|
|
|
this->CustomMaximumFailedTestOutputSize = 0;
|
2014-07-07 23:58:02 +04:00
|
|
|
this->LogWithPID = false;
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
|
|
|
|
2005-06-17 21:04:56 +04:00
|
|
|
void cmCTestMemCheckHandler::Initialize()
|
|
|
|
{
|
|
|
|
this->Superclass::Initialize();
|
2014-07-07 23:58:02 +04:00
|
|
|
this->LogWithPID = false;
|
2007-08-11 00:28:48 +04:00
|
|
|
this->CustomMaximumPassedTestOutputSize = 0;
|
|
|
|
this->CustomMaximumFailedTestOutputSize = 0;
|
2006-03-10 23:03:09 +03:00
|
|
|
this->MemoryTester = "";
|
2013-08-08 00:25:48 +04:00
|
|
|
this->MemoryTesterDynamicOptions.clear();
|
2010-08-18 18:14:09 +04:00
|
|
|
this->MemoryTesterOptions.clear();
|
2006-03-10 23:03:09 +03:00
|
|
|
this->MemoryTesterStyle = UNKNOWN;
|
|
|
|
this->MemoryTesterOutputFile = "";
|
2005-06-17 21:04:56 +04:00
|
|
|
}
|
|
|
|
|
2005-01-27 23:54:47 +03:00
|
|
|
int cmCTestMemCheckHandler::PreProcessHandler()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->InitializeMemoryChecking()) {
|
2005-01-27 23:54:47 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->ExecuteCommands(this->CustomPreMemCheck)) {
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Problem executing pre-memcheck command(s)." << std::endl);
|
2005-01-27 23:54:47 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmCTestMemCheckHandler::PostProcessHandler()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->ExecuteCommands(this->CustomPostMemCheck)) {
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Problem executing post-memcheck command(s)." << std::endl);
|
2005-01-27 23:54:47 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-03-09 19:17:10 +03:00
|
|
|
void cmCTestMemCheckHandler::GenerateTestCommand(
|
2013-08-08 00:25:48 +04:00
|
|
|
std::vector<std::string>& args, int test)
|
2005-01-27 23:54:47 +03:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::vector<std::string>::size_type pp;
|
|
|
|
std::string index;
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream stream;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string memcheckcommand =
|
|
|
|
cmSystemTools::ConvertToOutputPath(this->MemoryTester.c_str());
|
2013-08-08 00:25:48 +04:00
|
|
|
stream << test;
|
|
|
|
index = stream.str();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (pp = 0; pp < this->MemoryTesterDynamicOptions.size(); pp++) {
|
2014-07-07 23:58:02 +04:00
|
|
|
std::string arg = this->MemoryTesterDynamicOptions[pp];
|
|
|
|
std::string::size_type pos = arg.find("??");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pos != std::string::npos) {
|
2013-08-08 00:25:48 +04:00
|
|
|
arg.replace(pos, 2, index);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-08-08 00:25:48 +04:00
|
|
|
args.push_back(arg);
|
|
|
|
memcheckcommand += " \"";
|
|
|
|
memcheckcommand += arg;
|
|
|
|
memcheckcommand += "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
// Create a copy of the memory tester environment variable.
|
|
|
|
// This is used for memory testing programs that pass options
|
|
|
|
// via environment varaibles.
|
|
|
|
std::string memTesterEnvironmentVariable =
|
|
|
|
this->MemoryTesterEnvironmentVariable;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (pp = 0; pp < this->MemoryTesterOptions.size(); pp++) {
|
|
|
|
if (!memTesterEnvironmentVariable.empty()) {
|
2014-07-07 23:58:02 +04:00
|
|
|
// If we are using env to pass options, append all the options to
|
|
|
|
// this string with space separation.
|
|
|
|
memTesterEnvironmentVariable += " " + this->MemoryTesterOptions[pp];
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
// for regular options just add them to args and memcheckcommand
|
|
|
|
// which is just used for display
|
2016-05-16 17:34:04 +03:00
|
|
|
else {
|
2014-07-07 23:58:02 +04:00
|
|
|
args.push_back(this->MemoryTesterOptions[pp]);
|
|
|
|
memcheckcommand += " \"";
|
|
|
|
memcheckcommand += this->MemoryTesterOptions[pp];
|
|
|
|
memcheckcommand += "\"";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
// if this is an env option type, then add the env string as a single
|
|
|
|
// argument.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!memTesterEnvironmentVariable.empty()) {
|
2014-07-07 23:58:02 +04:00
|
|
|
std::string::size_type pos = memTesterEnvironmentVariable.find("??");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pos != std::string::npos) {
|
2014-07-07 23:58:02 +04:00
|
|
|
memTesterEnvironmentVariable.replace(pos, 2, index);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
memcheckcommand += " " + memTesterEnvironmentVariable;
|
|
|
|
args.push_back(memTesterEnvironmentVariable);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Memory check command: " << memcheckcommand << std::endl,
|
|
|
|
this->Quiet);
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
|
|
|
|
2014-07-07 23:58:02 +04:00
|
|
|
void cmCTestMemCheckHandler::InitializeResultsVectors()
|
|
|
|
{
|
|
|
|
// fill these members
|
2016-05-16 17:34:04 +03:00
|
|
|
// cmsys::vector<std::string> ResultStrings;
|
|
|
|
// cmsys::vector<std::string> ResultStringsLong;
|
|
|
|
// cmsys::vector<int> GlobalResults;
|
2014-07-07 23:58:02 +04:00
|
|
|
this->ResultStringsLong.clear();
|
|
|
|
this->ResultStrings.clear();
|
|
|
|
this->GlobalResults.clear();
|
|
|
|
// If we are working with style checkers that dynamically fill
|
|
|
|
// the results strings then return.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->MemoryTesterStyle > cmCTestMemCheckHandler::BOUNDS_CHECKER) {
|
2014-07-07 23:58:02 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
|
|
|
|
// define the standard set of errors
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
static const char* cmCTestMemCheckResultStrings[] = {
|
2016-06-27 23:44:16 +03:00
|
|
|
"ABR", "ABW", "ABWL", "COR", "EXU", "FFM", "FIM", "FMM",
|
|
|
|
"FMR", "FMW", "FUM", "IPR", "IPW", "MAF", "MLK", "MPK",
|
|
|
|
"NPR", "ODS", "PAR", "PLK", "UMC", "UMR", CM_NULLPTR
|
2014-07-07 23:58:02 +04:00
|
|
|
};
|
|
|
|
static const char* cmCTestMemCheckResultLongStrings[] = {
|
|
|
|
"Threading Problem",
|
|
|
|
"ABW",
|
|
|
|
"ABWL",
|
|
|
|
"COR",
|
|
|
|
"EXU",
|
|
|
|
"FFM",
|
|
|
|
"FIM",
|
|
|
|
"Mismatched deallocation",
|
|
|
|
"FMR",
|
|
|
|
"FMW",
|
|
|
|
"FUM",
|
|
|
|
"IPR",
|
|
|
|
"IPW",
|
|
|
|
"MAF",
|
|
|
|
"Memory Leak",
|
|
|
|
"Potential Memory Leak",
|
|
|
|
"NPR",
|
|
|
|
"ODS",
|
|
|
|
"Invalid syscall param",
|
|
|
|
"PLK",
|
|
|
|
"Uninitialized Memory Conditional",
|
|
|
|
"Uninitialized Memory Read",
|
2016-06-27 23:44:16 +03:00
|
|
|
CM_NULLPTR
|
2014-07-07 23:58:02 +04:00
|
|
|
};
|
|
|
|
this->GlobalResults.clear();
|
2016-06-27 23:44:16 +03:00
|
|
|
for (int i = 0; cmCTestMemCheckResultStrings[i] != CM_NULLPTR; ++i) {
|
2014-07-07 23:58:02 +04:00
|
|
|
this->ResultStrings.push_back(cmCTestMemCheckResultStrings[i]);
|
|
|
|
this->ResultStringsLong.push_back(cmCTestMemCheckResultLongStrings[i]);
|
|
|
|
this->GlobalResults.push_back(0);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCTestMemCheckHandler::PopulateCustomVectors(cmMakefile* mf)
|
2005-01-27 23:54:47 +03:00
|
|
|
{
|
|
|
|
this->cmCTestTestHandler::PopulateCustomVectors(mf);
|
2006-03-29 21:01:24 +04:00
|
|
|
this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_MEMCHECK",
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CustomPreMemCheck);
|
2006-03-29 21:01:24 +04:00
|
|
|
this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_MEMCHECK",
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CustomPostMemCheck);
|
2005-01-27 23:54:47 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_MEMCHECK_IGNORE",
|
|
|
|
this->CustomTestsIgnore);
|
2014-07-15 22:19:14 +04:00
|
|
|
std::string cmake = cmSystemTools::GetCMakeCommand();
|
2015-02-18 01:15:00 +03:00
|
|
|
this->CTest->SetCTestConfiguration("CMakeCommand", cmake.c_str(),
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Quiet);
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
|
|
|
|
2015-05-24 21:40:47 +03:00
|
|
|
void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml)
|
2005-01-27 23:54:47 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->CTest->GetProduceXML()) {
|
2005-01-27 23:54:47 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-24 21:40:47 +03:00
|
|
|
this->CTest->StartXML(xml, this->AppendXML);
|
|
|
|
xml.StartElement("DynamicAnalysis");
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (this->MemoryTesterStyle) {
|
2005-01-27 23:54:47 +03:00
|
|
|
case cmCTestMemCheckHandler::VALGRIND:
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Attribute("Checker", "Valgrind");
|
2005-01-27 23:54:47 +03:00
|
|
|
break;
|
|
|
|
case cmCTestMemCheckHandler::PURIFY:
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Attribute("Checker", "Purify");
|
2005-01-27 23:54:47 +03:00
|
|
|
break;
|
|
|
|
case cmCTestMemCheckHandler::BOUNDS_CHECKER:
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Attribute("Checker", "BoundsChecker");
|
2005-01-27 23:54:47 +03:00
|
|
|
break;
|
2014-07-15 01:01:47 +04:00
|
|
|
case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Attribute("Checker", "AddressSanitizer");
|
2014-07-15 01:01:47 +04:00
|
|
|
break;
|
2014-10-07 23:14:20 +04:00
|
|
|
case cmCTestMemCheckHandler::THREAD_SANITIZER:
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Attribute("Checker", "ThreadSanitizer");
|
2014-10-07 23:14:20 +04:00
|
|
|
break;
|
2014-10-07 19:34:53 +04:00
|
|
|
case cmCTestMemCheckHandler::MEMORY_SANITIZER:
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Attribute("Checker", "MemorySanitizer");
|
2014-10-07 19:34:53 +04:00
|
|
|
break;
|
2014-10-03 21:46:18 +04:00
|
|
|
case cmCTestMemCheckHandler::UB_SANITIZER:
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Attribute("Checker", "UndefinedBehaviorSanitizer");
|
2014-10-03 21:46:18 +04:00
|
|
|
break;
|
2005-01-27 23:54:47 +03:00
|
|
|
default:
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Attribute("Checker", "Unknown");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Element("StartDateTime", this->StartTest);
|
|
|
|
xml.Element("StartTestTime", this->StartTestTime);
|
|
|
|
xml.StartElement("TestList");
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestMemCheckHandler::TestResultsVector::size_type cc;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cc = 0; cc < this->TestResults.size(); cc++) {
|
|
|
|
cmCTestTestResult* result = &this->TestResults[cc];
|
2006-03-10 23:03:09 +03:00
|
|
|
std::string testPath = result->Path + "/" + result->Name;
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Element("Test", this->CTest->GetShortPathToFile(testPath.c_str()));
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.EndElement(); // TestList
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
2016-05-16 17:34:04 +03:00
|
|
|
"-- Processing memory checking output: ", this->Quiet);
|
2006-03-30 22:49:56 +04:00
|
|
|
size_t total = this->TestResults.size();
|
|
|
|
size_t step = total / 10;
|
|
|
|
size_t current = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cc = 0; cc < this->TestResults.size(); cc++) {
|
|
|
|
cmCTestTestResult* result = &this->TestResults[cc];
|
2005-01-27 23:54:47 +03:00
|
|
|
std::string memcheckstr;
|
2014-07-07 23:58:02 +04:00
|
|
|
std::vector<int> memcheckresults(this->ResultStrings.size(), 0);
|
2006-03-10 23:03:09 +03:00
|
|
|
bool res = this->ProcessMemCheckOutput(result->Output, memcheckstr,
|
2016-05-16 17:34:04 +03:00
|
|
|
memcheckresults);
|
|
|
|
if (res && result->Status == cmCTestMemCheckHandler::COMPLETED) {
|
2005-01-27 23:54:47 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
this->CleanTestOutput(
|
|
|
|
memcheckstr,
|
2006-03-16 19:29:12 +03:00
|
|
|
static_cast<size_t>(this->CustomMaximumFailedTestOutputSize));
|
2015-05-24 21:40:47 +03:00
|
|
|
this->WriteTestResultHeader(xml, result);
|
|
|
|
xml.StartElement("Results");
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<int>::size_type kk = 0; kk < memcheckresults.size();
|
|
|
|
++kk) {
|
|
|
|
if (memcheckresults[kk]) {
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.StartElement("Defect");
|
|
|
|
xml.Attribute("type", this->ResultStringsLong[kk]);
|
|
|
|
xml.Content(memcheckresults[kk]);
|
|
|
|
xml.EndElement(); // Defect
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GlobalResults[kk] += memcheckresults[kk];
|
|
|
|
}
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.EndElement(); // Results
|
2011-05-26 22:42:41 +04:00
|
|
|
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.StartElement("Log");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CTest->ShouldCompressMemCheckOutput()) {
|
2011-05-26 22:42:41 +04:00
|
|
|
this->CTest->CompressString(memcheckstr);
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Attribute("compression", "gzip");
|
|
|
|
xml.Attribute("encoding", "base64");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Content(memcheckstr);
|
|
|
|
xml.EndElement(); // Log
|
2011-05-26 22:42:41 +04:00
|
|
|
|
2015-05-24 21:40:47 +03:00
|
|
|
this->WriteTestResultFooter(xml, result);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (current < cc) {
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "#" << std::flush,
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Quiet);
|
2005-01-27 23:54:47 +03:00
|
|
|
current += step;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, std::endl, this->Quiet);
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
|
|
|
"Memory checking results:" << std::endl, this->Quiet);
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.StartElement("DefectList");
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cc = 0; cc < this->GlobalResults.size(); cc++) {
|
|
|
|
if (this->GlobalResults[cc]) {
|
2005-06-01 01:32:40 +04:00
|
|
|
#ifdef cerr
|
2016-05-16 17:34:04 +03:00
|
|
|
#undef cerr
|
2005-06-01 01:32:40 +04:00
|
|
|
#endif
|
2005-01-27 23:54:47 +03:00
|
|
|
std::cerr.width(35);
|
2005-06-01 01:32:40 +04:00
|
|
|
#define cerr no_cerr
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
|
2016-05-16 17:34:04 +03:00
|
|
|
this->ResultStringsLong[cc]
|
|
|
|
<< " - " << this->GlobalResults[cc] << std::endl,
|
|
|
|
this->Quiet);
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.StartElement("Defect");
|
|
|
|
xml.Attribute("Type", this->ResultStringsLong[cc]);
|
|
|
|
xml.EndElement();
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.EndElement(); // DefectList
|
2005-01-27 23:54:47 +03:00
|
|
|
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.Element("EndDateTime", this->EndTest);
|
|
|
|
xml.Element("EndTestTime", this->EndTestTime);
|
|
|
|
xml.Element("ElapsedMinutes",
|
2016-05-16 17:34:04 +03:00
|
|
|
static_cast<int>(this->ElapsedTestingTime / 6) / 10.0);
|
2006-03-09 19:17:10 +03:00
|
|
|
|
2015-05-24 21:40:47 +03:00
|
|
|
xml.EndElement(); // DynamicAnalysis
|
|
|
|
this->CTest->EndXML(xml);
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestMemCheckHandler::InitializeMemoryChecking()
|
|
|
|
{
|
2014-07-07 23:58:02 +04:00
|
|
|
this->MemoryTesterEnvironmentVariable = "";
|
|
|
|
this->MemoryTester = "";
|
2005-01-27 23:54:47 +03:00
|
|
|
// Setup the command
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(
|
|
|
|
this->CTest->GetCTestConfiguration("MemoryCheckCommand").c_str())) {
|
|
|
|
this->MemoryTester =
|
2016-05-26 23:52:22 +03:00
|
|
|
this->CTest->GetCTestConfiguration("MemoryCheckCommand");
|
2014-06-13 22:42:43 +04:00
|
|
|
std::string testerName =
|
|
|
|
cmSystemTools::GetFilenameName(this->MemoryTester);
|
2012-09-30 22:53:27 +04:00
|
|
|
// determine the checker type
|
2016-05-16 17:34:04 +03:00
|
|
|
if (testerName.find("valgrind") != std::string::npos ||
|
|
|
|
this->CTest->GetCTestConfiguration("MemoryCheckType") == "Valgrind") {
|
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
|
|
|
|
} else if (testerName.find("purify") != std::string::npos) {
|
2012-09-30 22:53:27 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (testerName.find("BC") != std::string::npos) {
|
2012-09-30 22:53:27 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-09-30 22:53:27 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::UNKNOWN;
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmSystemTools::FileExists(
|
|
|
|
this->CTest->GetCTestConfiguration("PurifyCommand").c_str())) {
|
2016-05-26 23:52:22 +03:00
|
|
|
this->MemoryTester = this->CTest->GetCTestConfiguration("PurifyCommand");
|
2012-09-30 22:53:27 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmSystemTools::FileExists(
|
|
|
|
this->CTest->GetCTestConfiguration("ValgrindCommand")
|
|
|
|
.c_str())) {
|
2016-05-26 23:52:22 +03:00
|
|
|
this->MemoryTester = this->CTest->GetCTestConfiguration("ValgrindCommand");
|
2012-09-30 22:53:27 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmSystemTools::FileExists(
|
|
|
|
this->CTest->GetCTestConfiguration("BoundsCheckerCommand")
|
|
|
|
.c_str())) {
|
|
|
|
this->MemoryTester =
|
2016-05-26 23:52:22 +03:00
|
|
|
this->CTest->GetCTestConfiguration("BoundsCheckerCommand");
|
2012-09-30 22:53:27 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
|
|
|
|
"AddressSanitizer") {
|
2016-05-26 23:52:22 +03:00
|
|
|
this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
|
2014-10-07 23:14:20 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::ADDRESS_SANITIZER;
|
2014-07-07 23:58:02 +04:00
|
|
|
this->LogWithPID = true; // even if we give the log file the pid is added
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
|
|
|
|
"ThreadSanitizer") {
|
2016-05-26 23:52:22 +03:00
|
|
|
this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
|
2014-10-07 23:14:20 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::THREAD_SANITIZER;
|
2014-07-15 01:01:47 +04:00
|
|
|
this->LogWithPID = true; // even if we give the log file the pid is added
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
|
|
|
|
"MemorySanitizer") {
|
2016-05-26 23:52:22 +03:00
|
|
|
this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
|
2014-10-07 19:34:53 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::MEMORY_SANITIZER;
|
|
|
|
this->LogWithPID = true; // even if we give the log file the pid is added
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
|
|
|
|
"UndefinedBehaviorSanitizer") {
|
2016-05-26 23:52:22 +03:00
|
|
|
this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
|
2014-10-03 21:46:18 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::UB_SANITIZER;
|
|
|
|
this->LogWithPID = true; // even if we give the log file the pid is added
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
// Check the MemoryCheckType
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->MemoryTesterStyle == cmCTestMemCheckHandler::UNKNOWN) {
|
2014-07-07 23:58:02 +04:00
|
|
|
std::string checkType =
|
|
|
|
this->CTest->GetCTestConfiguration("MemoryCheckType");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (checkType == "Purify") {
|
2014-07-07 23:58:02 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (checkType == "BoundsChecker") {
|
2014-07-07 23:58:02 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (checkType == "Valgrind") {
|
2014-07-07 23:58:02 +04:00
|
|
|
this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->MemoryTester.empty()) {
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, WARNING,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Memory checker (MemoryCheckCommand) "
|
|
|
|
"not set, or cannot find the specified program."
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2005-01-27 23:54:47 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
|
|
|
|
// Setup the options
|
2010-08-18 18:14:09 +04:00
|
|
|
std::string memoryTesterOptions;
|
2016-05-27 00:05:30 +03:00
|
|
|
if (!this->CTest->GetCTestConfiguration("MemoryCheckCommandOptions")
|
|
|
|
.empty()) {
|
2016-05-16 17:34:04 +03:00
|
|
|
memoryTesterOptions =
|
|
|
|
this->CTest->GetCTestConfiguration("MemoryCheckCommandOptions");
|
2016-05-27 00:05:30 +03:00
|
|
|
} else if (!this->CTest->GetCTestConfiguration("ValgrindCommandOptions")
|
|
|
|
.empty()) {
|
2016-05-16 17:34:04 +03:00
|
|
|
memoryTesterOptions =
|
|
|
|
this->CTest->GetCTestConfiguration("ValgrindCommandOptions");
|
|
|
|
}
|
|
|
|
this->MemoryTesterOptions =
|
|
|
|
cmSystemTools::ParseArguments(memoryTesterOptions.c_str());
|
2005-01-27 23:54:47 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
this->MemoryTesterOutputFile =
|
|
|
|
this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.??.log";
|
2005-01-27 23:54:47 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (this->MemoryTesterStyle) {
|
|
|
|
case cmCTestMemCheckHandler::VALGRIND: {
|
|
|
|
if (this->MemoryTesterOptions.empty()) {
|
2012-09-30 22:53:27 +04:00
|
|
|
this->MemoryTesterOptions.push_back("-q");
|
|
|
|
this->MemoryTesterOptions.push_back("--tool=memcheck");
|
|
|
|
this->MemoryTesterOptions.push_back("--leak-check=yes");
|
|
|
|
this->MemoryTesterOptions.push_back("--show-reachable=yes");
|
|
|
|
this->MemoryTesterOptions.push_back("--num-callers=50");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-05-27 00:05:30 +03:00
|
|
|
if (!this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
|
|
|
|
.empty()) {
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(
|
|
|
|
this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
|
|
|
|
.c_str())) {
|
2012-09-30 22:53:27 +04:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Cannot find memory checker suppression file: "
|
|
|
|
<< this->CTest->GetCTestConfiguration(
|
|
|
|
"MemoryCheckSuppressionFile")
|
|
|
|
<< std::endl);
|
2012-09-30 22:53:27 +04:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string suppressions = "--suppressions=" +
|
|
|
|
this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile");
|
|
|
|
this->MemoryTesterOptions.push_back(suppressions);
|
|
|
|
}
|
|
|
|
std::string outputFile = "--log-file=" + this->MemoryTesterOutputFile;
|
2013-08-08 00:25:48 +04:00
|
|
|
this->MemoryTesterDynamicOptions.push_back(outputFile);
|
2012-09-30 22:53:27 +04:00
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
case cmCTestMemCheckHandler::PURIFY: {
|
2012-09-30 22:53:27 +04:00
|
|
|
std::string outputFile;
|
|
|
|
#ifdef _WIN32
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
|
|
|
|
.size()) {
|
|
|
|
if (!cmSystemTools::FileExists(
|
|
|
|
this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
|
|
|
|
.c_str())) {
|
|
|
|
cmCTestLog(
|
|
|
|
this->CTest, ERROR_MESSAGE,
|
|
|
|
"Cannot find memory checker suppression file: "
|
|
|
|
<< this->CTest
|
|
|
|
->GetCTestConfiguration("MemoryCheckSuppressionFile")
|
|
|
|
.c_str()
|
|
|
|
<< std::endl);
|
2012-09-30 22:53:27 +04:00
|
|
|
return false;
|
2009-05-27 19:14:08 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string filterFiles = "/FilterFiles=" +
|
|
|
|
this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile");
|
|
|
|
this->MemoryTesterOptions.push_back(filterFiles);
|
|
|
|
}
|
2012-09-30 22:53:27 +04:00
|
|
|
outputFile = "/SAVETEXTDATA=";
|
2005-01-27 23:54:47 +03:00
|
|
|
#else
|
2012-09-30 22:53:27 +04:00
|
|
|
outputFile = "-log-file=";
|
2005-01-27 23:54:47 +03:00
|
|
|
#endif
|
2012-09-30 22:53:27 +04:00
|
|
|
outputFile += this->MemoryTesterOutputFile;
|
2013-08-08 00:25:48 +04:00
|
|
|
this->MemoryTesterDynamicOptions.push_back(outputFile);
|
2012-09-30 22:53:27 +04:00
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
case cmCTestMemCheckHandler::BOUNDS_CHECKER: {
|
2012-09-30 22:53:27 +04:00
|
|
|
this->BoundsCheckerXMLFile = this->MemoryTesterOutputFile;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string dpbdFile = this->CTest->GetBinaryDir() +
|
|
|
|
"/Testing/Temporary/MemoryChecker.??.DPbd";
|
2012-09-30 22:53:27 +04:00
|
|
|
this->BoundsCheckerDPBDFile = dpbdFile;
|
2013-08-08 00:25:48 +04:00
|
|
|
this->MemoryTesterDynamicOptions.push_back("/B");
|
|
|
|
this->MemoryTesterDynamicOptions.push_back(dpbdFile);
|
|
|
|
this->MemoryTesterDynamicOptions.push_back("/X");
|
|
|
|
this->MemoryTesterDynamicOptions.push_back(this->MemoryTesterOutputFile);
|
2012-09-30 22:53:27 +04:00
|
|
|
this->MemoryTesterOptions.push_back("/M");
|
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
// these are almost the same but the env var used is different
|
2014-07-15 01:01:47 +04:00
|
|
|
case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
|
2014-07-07 23:58:02 +04:00
|
|
|
case cmCTestMemCheckHandler::THREAD_SANITIZER:
|
2014-10-07 19:34:53 +04:00
|
|
|
case cmCTestMemCheckHandler::MEMORY_SANITIZER:
|
2016-05-16 17:34:04 +03:00
|
|
|
case cmCTestMemCheckHandler::UB_SANITIZER: {
|
2014-07-07 23:58:02 +04:00
|
|
|
// To pass arguments to ThreadSanitizer the environment variable
|
|
|
|
// TSAN_OPTIONS is used. This is done with the cmake -E env command.
|
|
|
|
// The MemoryTesterDynamicOptions is setup with the -E env
|
|
|
|
// Then the MemoryTesterEnvironmentVariable gets the
|
|
|
|
// TSAN_OPTIONS string with the log_path in it.
|
|
|
|
this->MemoryTesterDynamicOptions.push_back("-E");
|
|
|
|
this->MemoryTesterDynamicOptions.push_back("env");
|
2014-10-03 21:45:07 +04:00
|
|
|
std::string envVar;
|
|
|
|
std::string extraOptions =
|
|
|
|
this->CTest->GetCTestConfiguration("MemoryCheckSanitizerOptions");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->MemoryTesterStyle ==
|
|
|
|
cmCTestMemCheckHandler::ADDRESS_SANITIZER) {
|
2014-10-07 23:14:20 +04:00
|
|
|
envVar = "ASAN_OPTIONS";
|
|
|
|
extraOptions += " detect_leaks=1";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->MemoryTesterStyle ==
|
|
|
|
cmCTestMemCheckHandler::THREAD_SANITIZER) {
|
2014-10-07 23:14:20 +04:00
|
|
|
envVar = "TSAN_OPTIONS";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->MemoryTesterStyle ==
|
|
|
|
cmCTestMemCheckHandler::MEMORY_SANITIZER) {
|
2014-10-07 19:34:53 +04:00
|
|
|
envVar = "MSAN_OPTIONS";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->MemoryTesterStyle ==
|
|
|
|
cmCTestMemCheckHandler::UB_SANITIZER) {
|
2014-10-03 21:46:18 +04:00
|
|
|
envVar = "UBSAN_OPTIONS";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
std::string outputFile =
|
|
|
|
envVar + "=log_path=\"" + this->MemoryTesterOutputFile + "\" ";
|
2014-07-15 01:01:47 +04:00
|
|
|
this->MemoryTesterEnvironmentVariable = outputFile + extraOptions;
|
2014-07-07 23:58:02 +04:00
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-30 22:53:27 +04:00
|
|
|
default:
|
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Do not understand memory checker: " << this->MemoryTester
|
|
|
|
<< std::endl);
|
2012-09-30 22:53:27 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
|
2014-07-07 23:58:02 +04:00
|
|
|
this->InitializeResultsVectors();
|
|
|
|
// std::vector<std::string>::size_type cc;
|
|
|
|
// for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
|
|
|
|
// {
|
|
|
|
// this->MemoryTesterGlobalResults[cc] = 0;
|
|
|
|
// }
|
2005-01-27 23:54:47 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCTestMemCheckHandler::ProcessMemCheckOutput(const std::string& str,
|
|
|
|
std::string& log,
|
|
|
|
std::vector<int>& results)
|
2005-01-27 23:54:47 +03:00
|
|
|
{
|
2016-08-18 21:04:21 +03:00
|
|
|
switch (this->MemoryTesterStyle) {
|
|
|
|
case cmCTestMemCheckHandler::VALGRIND:
|
|
|
|
return this->ProcessMemCheckValgrindOutput(str, log, results);
|
|
|
|
case cmCTestMemCheckHandler::PURIFY:
|
|
|
|
return this->ProcessMemCheckPurifyOutput(str, log, results);
|
|
|
|
case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
|
|
|
|
case cmCTestMemCheckHandler::THREAD_SANITIZER:
|
|
|
|
case cmCTestMemCheckHandler::MEMORY_SANITIZER:
|
|
|
|
case cmCTestMemCheckHandler::UB_SANITIZER:
|
|
|
|
return this->ProcessMemCheckSanitizerOutput(str, log, results);
|
|
|
|
case cmCTestMemCheckHandler::BOUNDS_CHECKER:
|
|
|
|
return this->ProcessMemCheckBoundsCheckerOutput(str, log, results);
|
|
|
|
default:
|
|
|
|
log.append("\nMemory checking style used was: ");
|
|
|
|
log.append("None that I know");
|
|
|
|
log = str;
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
|
|
|
|
2014-07-07 23:58:02 +04:00
|
|
|
std::vector<int>::size_type cmCTestMemCheckHandler::FindOrAddWarning(
|
|
|
|
const std::string& warning)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::size_type i = 0;
|
|
|
|
i < this->ResultStrings.size(); ++i) {
|
|
|
|
if (this->ResultStrings[i] == warning) {
|
2014-07-07 23:58:02 +04:00
|
|
|
return i;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
this->GlobalResults.push_back(0); // this must stay the same size
|
|
|
|
this->ResultStrings.push_back(warning);
|
|
|
|
this->ResultStringsLong.push_back(warning);
|
2016-05-16 17:34:04 +03:00
|
|
|
return this->ResultStrings.size() - 1;
|
2014-07-07 23:58:02 +04:00
|
|
|
}
|
2014-07-15 01:01:47 +04:00
|
|
|
bool cmCTestMemCheckHandler::ProcessMemCheckSanitizerOutput(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& str, std::string& log, std::vector<int>& result)
|
2014-07-07 23:58:02 +04:00
|
|
|
{
|
2014-07-15 01:01:47 +04:00
|
|
|
std::string regex;
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (this->MemoryTesterStyle) {
|
2014-10-07 23:14:20 +04:00
|
|
|
case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
|
|
|
|
regex = "ERROR: AddressSanitizer: (.*) on.*";
|
|
|
|
break;
|
|
|
|
case cmCTestMemCheckHandler::THREAD_SANITIZER:
|
|
|
|
regex = "WARNING: ThreadSanitizer: (.*) \\(pid=.*\\)";
|
|
|
|
break;
|
2014-10-07 19:34:53 +04:00
|
|
|
case cmCTestMemCheckHandler::MEMORY_SANITIZER:
|
|
|
|
regex = "WARNING: MemorySanitizer: (.*)";
|
|
|
|
break;
|
2014-10-03 21:46:18 +04:00
|
|
|
case cmCTestMemCheckHandler::UB_SANITIZER:
|
|
|
|
regex = "runtime error: (.*)";
|
|
|
|
break;
|
2014-10-07 23:14:20 +04:00
|
|
|
default:
|
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-15 01:01:47 +04:00
|
|
|
cmsys::RegularExpression sanitizerWarning(regex);
|
|
|
|
cmsys::RegularExpression leakWarning("(Direct|Indirect) leak of .*");
|
2014-07-07 23:58:02 +04:00
|
|
|
int defects = 0;
|
|
|
|
std::vector<std::string> lines;
|
|
|
|
cmSystemTools::Split(str.c_str(), lines);
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream ostr;
|
2014-07-07 23:58:02 +04:00
|
|
|
log = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = lines.begin(); i != lines.end();
|
|
|
|
++i) {
|
2014-07-15 01:01:47 +04:00
|
|
|
std::string resultFound;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (leakWarning.find(*i)) {
|
|
|
|
resultFound = leakWarning.match(1) + " leak";
|
|
|
|
} else if (sanitizerWarning.find(*i)) {
|
2014-07-15 01:01:47 +04:00
|
|
|
resultFound = sanitizerWarning.match(1);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!resultFound.empty()) {
|
2014-07-15 01:01:47 +04:00
|
|
|
std::vector<int>::size_type idx = this->FindOrAddWarning(resultFound);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (result.empty() || idx > result.size() - 1) {
|
2014-07-07 23:58:02 +04:00
|
|
|
result.push_back(1);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-07-07 23:58:02 +04:00
|
|
|
result[idx]++;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
defects++;
|
|
|
|
ostr << "<b>" << this->ResultStrings[idx] << "</b> ";
|
2014-07-07 23:58:02 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
ostr << *i << std::endl;
|
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
log = ostr.str();
|
2016-06-02 00:29:53 +03:00
|
|
|
return defects == 0;
|
2014-07-07 23:58:02 +04:00
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& str, std::string& log, std::vector<int>& results)
|
2012-08-13 21:42:58 +04:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::vector<std::string> lines;
|
2012-08-13 21:42:58 +04:00
|
|
|
cmSystemTools::Split(str.c_str(), lines);
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream ostr;
|
2005-01-27 23:54:47 +03:00
|
|
|
log = "";
|
|
|
|
|
|
|
|
cmsys::RegularExpression pfW("^\\[[WEI]\\] ([A-Z][A-Z][A-Z][A-Z]*): ");
|
|
|
|
|
|
|
|
int defects = 0;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = lines.begin(); i != lines.end();
|
|
|
|
++i) {
|
2014-07-07 23:58:02 +04:00
|
|
|
std::vector<int>::size_type failure = this->ResultStrings.size();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pfW.find(*i)) {
|
2014-07-07 23:58:02 +04:00
|
|
|
std::vector<int>::size_type cc;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cc = 0; cc < this->ResultStrings.size(); cc++) {
|
|
|
|
if (pfW.match(1) == this->ResultStrings[cc]) {
|
2005-01-27 23:54:47 +03:00
|
|
|
failure = cc;
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (cc == this->ResultStrings.size()) {
|
2006-03-10 23:03:09 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown Purify memory fault: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< pfW.match(1) << std::endl);
|
2006-03-09 19:17:10 +03:00
|
|
|
ostr << "*** Unknown Purify memory fault: " << pfW.match(1)
|
2016-05-16 17:34:04 +03:00
|
|
|
<< std::endl;
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (failure != this->ResultStrings.size()) {
|
|
|
|
ostr << "<b>" << this->ResultStrings[failure] << "</b> ";
|
|
|
|
results[failure]++;
|
|
|
|
defects++;
|
|
|
|
}
|
|
|
|
ostr << *i << std::endl;
|
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
|
|
|
|
log = ostr.str();
|
2016-06-02 00:29:53 +03:00
|
|
|
return defects == 0;
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& str, std::string& log, std::vector<int>& results)
|
2005-01-27 23:54:47 +03:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::vector<std::string> lines;
|
2005-01-27 23:54:47 +03:00
|
|
|
cmSystemTools::Split(str.c_str(), lines);
|
2007-07-27 00:38:00 +04:00
|
|
|
bool unlimitedOutput = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (str.find("CTEST_FULL_OUTPUT") != str.npos ||
|
|
|
|
this->CustomMaximumFailedTestOutputSize == 0) {
|
2007-07-27 00:38:00 +04:00
|
|
|
unlimitedOutput = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2005-01-27 23:54:47 +03:00
|
|
|
std::string::size_type cc;
|
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream ostr;
|
2005-01-27 23:54:47 +03:00
|
|
|
log = "";
|
|
|
|
|
|
|
|
int defects = 0;
|
|
|
|
|
|
|
|
cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
|
|
|
|
|
|
|
|
cmsys::RegularExpression vgFIM(
|
|
|
|
"== .*Invalid free\\(\\) / delete / delete\\[\\]");
|
|
|
|
cmsys::RegularExpression vgFMM(
|
|
|
|
"== .*Mismatched free\\(\\) / delete / delete \\[\\]");
|
2009-10-29 15:38:04 +03:00
|
|
|
cmsys::RegularExpression vgMLK1(
|
2011-06-09 16:15:43 +04:00
|
|
|
"== .*[0-9,]+ bytes in [0-9,]+ blocks are definitely lost"
|
2016-05-16 17:34:04 +03:00
|
|
|
" in loss record [0-9,]+ of [0-9,]+");
|
2009-10-29 15:38:04 +03:00
|
|
|
cmsys::RegularExpression vgMLK2(
|
2011-06-09 16:15:43 +04:00
|
|
|
"== .*[0-9,]+ \\([0-9,]+ direct, [0-9,]+ indirect\\)"
|
|
|
|
" bytes in [0-9,]+ blocks are definitely lost"
|
|
|
|
" in loss record [0-9,]+ of [0-9,]+");
|
2005-01-27 23:54:47 +03:00
|
|
|
cmsys::RegularExpression vgPAR(
|
2012-02-13 08:26:05 +04:00
|
|
|
"== .*Syscall param .* (contains|points to) unaddressable byte\\(s\\)");
|
2005-01-27 23:54:47 +03:00
|
|
|
cmsys::RegularExpression vgMPK1(
|
2011-06-09 16:15:43 +04:00
|
|
|
"== .*[0-9,]+ bytes in [0-9,]+ blocks are possibly lost in"
|
|
|
|
" loss record [0-9,]+ of [0-9,]+");
|
2005-01-27 23:54:47 +03:00
|
|
|
cmsys::RegularExpression vgMPK2(
|
2011-06-09 16:15:43 +04:00
|
|
|
"== .*[0-9,]+ bytes in [0-9,]+ blocks are still reachable"
|
|
|
|
" in loss record [0-9,]+ of [0-9,]+");
|
2005-01-27 23:54:47 +03:00
|
|
|
cmsys::RegularExpression vgUMC(
|
|
|
|
"== .*Conditional jump or move depends on uninitialised value\\(s\\)");
|
2006-03-09 19:17:10 +03:00
|
|
|
cmsys::RegularExpression vgUMR1(
|
2011-06-09 16:15:43 +04:00
|
|
|
"== .*Use of uninitialised value of size [0-9,]+");
|
|
|
|
cmsys::RegularExpression vgUMR2("== .*Invalid read of size [0-9,]+");
|
2005-01-27 23:54:47 +03:00
|
|
|
cmsys::RegularExpression vgUMR3("== .*Jump to the invalid address ");
|
2016-05-16 17:34:04 +03:00
|
|
|
cmsys::RegularExpression vgUMR4(
|
|
|
|
"== .*Syscall param .* contains "
|
2006-03-09 19:17:10 +03:00
|
|
|
"uninitialised or unaddressable byte\\(s\\)");
|
2007-08-04 00:35:22 +04:00
|
|
|
cmsys::RegularExpression vgUMR5("== .*Syscall param .* uninitialised");
|
2011-06-09 16:15:43 +04:00
|
|
|
cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9,]+");
|
2006-03-09 19:17:10 +03:00
|
|
|
cmsys::RegularExpression vgABR("== .*pthread_mutex_unlock: mutex is "
|
2016-05-16 17:34:04 +03:00
|
|
|
"locked by a different thread");
|
2007-07-27 00:38:00 +04:00
|
|
|
std::vector<std::string::size_type> nonValGrindOutput;
|
2005-06-01 01:32:40 +04:00
|
|
|
double sttime = cmSystemTools::GetTime();
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, DEBUG,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Start test: " << lines.size() << std::endl, this->Quiet);
|
2007-07-27 00:38:00 +04:00
|
|
|
std::string::size_type totalOutputSize = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cc = 0; cc < lines.size(); cc++) {
|
|
|
|
cmCTestOptionalLog(this->CTest, DEBUG,
|
|
|
|
"test line " << lines[cc] << std::endl, this->Quiet);
|
2007-08-11 00:28:48 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (valgrindLine.find(lines[cc])) {
|
|
|
|
cmCTestOptionalLog(this->CTest, DEBUG,
|
|
|
|
"valgrind line " << lines[cc] << std::endl,
|
|
|
|
this->Quiet);
|
2005-01-27 23:54:47 +03:00
|
|
|
int failure = cmCTestMemCheckHandler::NO_MEMORY_FAULT;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (vgFIM.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::FIM;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgFMM.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::FMM;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgMLK1.find(lines[cc])) {
|
2009-10-29 15:38:04 +03:00
|
|
|
failure = cmCTestMemCheckHandler::MLK;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgMLK2.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::MLK;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgPAR.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::PAR;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgMPK1.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::MPK;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgMPK2.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::MPK;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgUMC.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::UMC;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgUMR1.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::UMR;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgUMR2.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::UMR;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgUMR3.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::UMR;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgUMR4.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::UMR;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgUMR5.find(lines[cc])) {
|
2007-08-04 00:35:22 +04:00
|
|
|
failure = cmCTestMemCheckHandler::UMR;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgIPW.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::IPW;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (vgABR.find(lines[cc])) {
|
2006-03-09 19:17:10 +03:00
|
|
|
failure = cmCTestMemCheckHandler::ABR;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-01-27 23:54:47 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (failure != cmCTestMemCheckHandler::NO_MEMORY_FAULT) {
|
2014-07-07 23:58:02 +04:00
|
|
|
ostr << "<b>" << this->ResultStrings[failure] << "</b> ";
|
2016-05-16 17:34:04 +03:00
|
|
|
results[failure]++;
|
|
|
|
defects++;
|
|
|
|
}
|
2007-08-11 00:28:48 +04:00
|
|
|
totalOutputSize += lines[cc].size();
|
2015-07-16 22:48:00 +03:00
|
|
|
ostr << lines[cc] << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2007-07-27 00:38:00 +04:00
|
|
|
nonValGrindOutput.push_back(cc);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-27 00:38:00 +04:00
|
|
|
// Now put all all the non valgrind output into the test output
|
2014-08-04 23:28:48 +04:00
|
|
|
// This should be last in case it gets truncated by the output
|
|
|
|
// limiting code
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string::size_type>::iterator i =
|
|
|
|
nonValGrindOutput.begin();
|
|
|
|
i != nonValGrindOutput.end(); ++i) {
|
2014-08-04 23:28:48 +04:00
|
|
|
totalOutputSize += lines[*i].size();
|
2015-07-16 22:48:00 +03:00
|
|
|
ostr << lines[*i] << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!unlimitedOutput &&
|
|
|
|
totalOutputSize >
|
|
|
|
static_cast<size_t>(this->CustomMaximumFailedTestOutputSize)) {
|
2014-08-04 23:28:48 +04:00
|
|
|
ostr << "....\n";
|
|
|
|
ostr << "Test Output for this test has been truncated see testing"
|
2016-05-16 17:34:04 +03:00
|
|
|
" machine logs for full output,\n";
|
2014-08-04 23:28:48 +04:00
|
|
|
ostr << "or put CTEST_FULL_OUTPUT in the output of "
|
2016-05-16 17:34:04 +03:00
|
|
|
"this test program.\n";
|
|
|
|
break; // stop the copy of output if we are full
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, DEBUG, "End test (elapsed: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< (cmSystemTools::GetTime() - sttime) << std::endl,
|
|
|
|
this->Quiet);
|
2005-01-27 23:54:47 +03:00
|
|
|
log = ostr.str();
|
2016-06-02 00:29:53 +03:00
|
|
|
return defects == 0;
|
2005-01-27 23:54:47 +03:00
|
|
|
}
|
2007-07-24 22:43:31 +04:00
|
|
|
|
|
|
|
bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& str, std::string& log, std::vector<int>& results)
|
2007-07-24 22:43:31 +04:00
|
|
|
{
|
|
|
|
log = "";
|
|
|
|
double sttime = cmSystemTools::GetTime();
|
2014-02-10 09:21:34 +04:00
|
|
|
std::vector<std::string> lines;
|
2012-08-13 21:42:58 +04:00
|
|
|
cmSystemTools::Split(str.c_str(), lines);
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, DEBUG,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Start test: " << lines.size() << std::endl, this->Quiet);
|
2014-02-10 09:21:34 +04:00
|
|
|
std::vector<std::string>::size_type cc;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cc = 0; cc < lines.size(); cc++) {
|
|
|
|
if (lines[cc] == BOUNDS_CHECKER_MARKER) {
|
2007-07-24 22:43:31 +04:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-24 22:43:31 +04:00
|
|
|
cmBoundsCheckerParser parser(this->CTest);
|
|
|
|
parser.InitializeParser();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cc < lines.size()) {
|
|
|
|
for (cc++; cc < lines.size(); ++cc) {
|
2007-07-24 22:43:31 +04:00
|
|
|
std::string& theLine = lines[cc];
|
|
|
|
// check for command line arguments that are not escaped
|
|
|
|
// correctly by BC
|
2016-05-16 17:34:04 +03:00
|
|
|
if (theLine.find("TargetArgs=") != theLine.npos) {
|
2007-07-24 22:43:31 +04:00
|
|
|
// skip this because BC gets it wrong and we can't parse it
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!parser.ParseChunk(theLine.c_str(), theLine.size())) {
|
2007-07-24 22:43:31 +04:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Error in ParseChunk: " << theLine << std::endl);
|
2007-07-24 22:43:31 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-24 22:43:31 +04:00
|
|
|
int defects = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cc = 0; cc < parser.Errors.size(); ++cc) {
|
2007-07-24 22:43:31 +04:00
|
|
|
results[parser.Errors[cc]]++;
|
|
|
|
defects++;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, DEBUG, "End test (elapsed: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< (cmSystemTools::GetTime() - sttime) << std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
if (defects) {
|
2007-07-24 22:43:31 +04:00
|
|
|
// only put the output of Bounds Checker if there were
|
|
|
|
// errors or leaks detected
|
|
|
|
log = parser.Log;
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-24 22:43:31 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-07 23:58:02 +04:00
|
|
|
// PostProcessTest memcheck results
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCTestMemCheckHandler::PostProcessTest(cmCTestTestResult& res, int test)
|
2014-07-07 23:58:02 +04:00
|
|
|
{
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 17:34:04 +03:00
|
|
|
"PostProcessTest memcheck results for : " << res.Name
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
|
|
|
if (this->MemoryTesterStyle == cmCTestMemCheckHandler::BOUNDS_CHECKER) {
|
2014-07-07 23:58:02 +04:00
|
|
|
this->PostProcessBoundsCheckerTest(res, test);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-07-24 19:25:59 +04:00
|
|
|
std::vector<std::string> files;
|
|
|
|
this->TestOutputFileNames(test, files);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = files.begin();
|
|
|
|
i != files.end(); ++i) {
|
2014-07-24 19:25:59 +04:00
|
|
|
this->AppendMemTesterOutput(res, *i);
|
2014-07-07 23:58:02 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
}
|
|
|
|
|
2007-07-24 22:43:31 +04:00
|
|
|
// This method puts the bounds checker output file into the output
|
|
|
|
// for the test
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(
|
|
|
|
cmCTestTestResult& res, int test)
|
2012-08-13 21:42:58 +04:00
|
|
|
{
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 17:34:04 +03:00
|
|
|
"PostProcessBoundsCheckerTest for : " << res.Name
|
|
|
|
<< std::endl,
|
|
|
|
this->Quiet);
|
2014-07-24 19:25:59 +04:00
|
|
|
std::vector<std::string> files;
|
|
|
|
this->TestOutputFileNames(test, files);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (files.empty()) {
|
2007-07-24 22:43:31 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-24 19:25:59 +04:00
|
|
|
std::string ofile = files[0];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ofile.empty()) {
|
2014-12-16 21:47:35 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-24 22:43:31 +04:00
|
|
|
// put a scope around this to close ifs so the file can be removed
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmsys::ifstream ifs(ofile.c_str());
|
|
|
|
if (!ifs) {
|
|
|
|
std::string log = "Cannot read memory tester output file: " + ofile;
|
2016-06-07 00:53:32 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
|
2016-05-16 17:34:04 +03:00
|
|
|
return;
|
2012-08-13 21:42:58 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
res.Output += BOUNDS_CHECKER_MARKER;
|
2007-07-24 22:43:31 +04:00
|
|
|
res.Output += "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string line;
|
|
|
|
while (cmSystemTools::GetLineFromStream(ifs, line)) {
|
|
|
|
res.Output += line;
|
|
|
|
res.Output += "\n";
|
2007-07-24 22:43:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cmSystemTools::Delay(1000);
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(this->BoundsCheckerDPBDFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"Remove: " << this->BoundsCheckerDPBDFile << std::endl,
|
|
|
|
this->Quiet);
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(this->BoundsCheckerXMLFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
|
|
|
"Remove: " << this->BoundsCheckerXMLFile << std::endl,
|
|
|
|
this->Quiet);
|
2007-07-24 22:43:31 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCTestMemCheckHandler::AppendMemTesterOutput(cmCTestTestResult& res,
|
|
|
|
std::string const& ofile)
|
2013-05-04 21:03:26 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ofile.empty()) {
|
2007-07-24 22:43:31 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
// put ifs in scope so file can be deleted if needed
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmsys::ifstream ifs(ofile.c_str());
|
|
|
|
if (!ifs) {
|
|
|
|
std::string log = "Cannot read memory tester output file: " + ofile;
|
2016-06-07 00:53:32 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
|
2016-05-16 17:34:04 +03:00
|
|
|
return;
|
2012-08-13 21:42:58 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string line;
|
|
|
|
while (cmSystemTools::GetLineFromStream(ifs, line)) {
|
|
|
|
res.Output += line;
|
|
|
|
res.Output += "\n";
|
2007-07-24 22:43:31 +04:00
|
|
|
}
|
2014-07-07 23:58:02 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->LogWithPID) {
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(ofile);
|
2015-02-18 01:15:00 +03:00
|
|
|
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Remove: " << ofile << "\n", this->Quiet);
|
|
|
|
}
|
2007-07-24 22:43:31 +04:00
|
|
|
}
|
2013-08-08 00:25:48 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCTestMemCheckHandler::TestOutputFileNames(
|
|
|
|
int test, std::vector<std::string>& files)
|
2013-08-08 00:25:48 +04:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::string index;
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream stream;
|
2013-08-08 00:25:48 +04:00
|
|
|
stream << test;
|
|
|
|
index = stream.str();
|
2014-02-10 09:21:34 +04:00
|
|
|
std::string ofile = this->MemoryTesterOutputFile;
|
|
|
|
std::string::size_type pos = ofile.find("??");
|
2013-08-08 00:25:48 +04:00
|
|
|
ofile.replace(pos, 2, index);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->LogWithPID) {
|
2014-07-07 23:58:02 +04:00
|
|
|
ofile += ".*";
|
|
|
|
cmsys::Glob g;
|
|
|
|
g.FindFiles(ofile);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (g.GetFiles().empty()) {
|
|
|
|
std::string log = "Cannot find memory tester output file: " + ofile;
|
2016-06-07 00:53:32 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
|
2014-07-07 23:58:02 +04:00
|
|
|
ofile = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-07-24 19:25:59 +04:00
|
|
|
files = g.GetFiles();
|
|
|
|
return;
|
2014-07-07 23:58:02 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!cmSystemTools::FileExists(ofile.c_str())) {
|
|
|
|
std::string log = "Cannot find memory tester output file: " + ofile;
|
2016-06-07 00:53:32 +03:00
|
|
|
cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
|
2013-08-08 00:25:48 +04:00
|
|
|
ofile = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-07-24 19:25:59 +04:00
|
|
|
files.push_back(ofile);
|
2013-08-08 00:25:48 +04:00
|
|
|
}
|