From b04500a7259437dca9a2d8c8f0ce500b3bd2b057 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Sun, 24 May 2015 20:40:47 +0200 Subject: cmCTest{Test,MemCheck}Handler: Port to cmXMLWriter --- Source/CTest/cmCTestMemCheckHandler.cxx | 90 ++++----- Source/CTest/cmCTestMemCheckHandler.h | 3 +- Source/CTest/cmCTestTestHandler.cxx | 322 +++++++++++++++----------------- Source/CTest/cmCTestTestHandler.h | 11 +- 4 files changed, 202 insertions(+), 224 deletions(-) diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index 061f3fd..8f26716 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -21,7 +21,7 @@ #include #include #include "cmMakefile.h" -#include "cmXMLSafe.h" +#include "cmXMLWriter.h" #include #include @@ -352,55 +352,52 @@ void cmCTestMemCheckHandler::PopulateCustomVectors(cmMakefile *mf) } //---------------------------------------------------------------------- -void cmCTestMemCheckHandler::GenerateDartOutput(std::ostream& os) +void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml) { if ( !this->CTest->GetProduceXML() ) { return; } - this->CTest->StartXML(os, this->AppendXML); - os << "CTest->StartXML(xml, this->AppendXML); + xml.StartElement("DynamicAnalysis"); switch ( this->MemoryTesterStyle ) { case cmCTestMemCheckHandler::VALGRIND: - os << "Valgrind"; + xml.Attribute("Checker", "Valgrind"); break; case cmCTestMemCheckHandler::PURIFY: - os << "Purify"; + xml.Attribute("Checker", "Purify"); break; case cmCTestMemCheckHandler::BOUNDS_CHECKER: - os << "BoundsChecker"; + xml.Attribute("Checker", "BoundsChecker"); break; case cmCTestMemCheckHandler::ADDRESS_SANITIZER: - os << "AddressSanitizer"; + xml.Attribute("Checker", "AddressSanitizer"); break; case cmCTestMemCheckHandler::THREAD_SANITIZER: - os << "ThreadSanitizer"; + xml.Attribute("Checker", "ThreadSanitizer"); break; case cmCTestMemCheckHandler::MEMORY_SANITIZER: - os << "MemorySanitizer"; + xml.Attribute("Checker", "MemorySanitizer"); break; case cmCTestMemCheckHandler::UB_SANITIZER: - os << "UndefinedBehaviorSanitizer"; + xml.Attribute("Checker", "UndefinedBehaviorSanitizer"); break; default: - os << "Unknown"; + xml.Attribute("Checker", "Unknown"); } - os << "\">" << std::endl; - os << "\t" << this->StartTest << "\n" - << "\t" << this->StartTestTime << "\n" - << "\t\n"; + xml.Element("StartDateTime", this->StartTest); + xml.Element("StartTestTime", this->StartTestTime); + xml.StartElement("TestList"); cmCTestMemCheckHandler::TestResultsVector::size_type cc; for ( cc = 0; cc < this->TestResults.size(); cc ++ ) { cmCTestTestResult *result = &this->TestResults[cc]; std::string testPath = result->Path + "/" + result->Name; - os << "\t\t" << cmXMLSafe( - this->CTest->GetShortPathToFile(testPath.c_str())) - << "" << std::endl; + xml.Element("Test", this->CTest->GetShortPathToFile(testPath.c_str())); } - os << "\t\n"; + xml.EndElement(); // TestList cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "-- Processing memory checking output: ", this->Quiet); size_t total = this->TestResults.size(); @@ -419,37 +416,33 @@ void cmCTestMemCheckHandler::GenerateDartOutput(std::ostream& os) } this->CleanTestOutput(memcheckstr, static_cast(this->CustomMaximumFailedTestOutputSize)); - this->WriteTestResultHeader(os, result); - os << "\t\t" << std::endl; + this->WriteTestResultHeader(xml, result); + xml.StartElement("Results"); for(std::vector::size_type kk = 0; kk < memcheckresults.size(); ++kk) { if ( memcheckresults[kk] ) { - os << "\t\t\tResultStringsLong[kk] - << "\">" - << memcheckresults[kk] - << "" << std::endl; + xml.StartElement("Defect"); + xml.Attribute("type", this->ResultStringsLong[kk]); + xml.Content(memcheckresults[kk]); + xml.EndElement(); // Defect } this->GlobalResults[kk] += memcheckresults[kk]; } + xml.EndElement(); // Results - std::string logTag; + xml.StartElement("Log"); if(this->CTest->ShouldCompressMemCheckOutput()) { this->CTest->CompressString(memcheckstr); - logTag = "\t\n"; - } - else - { - logTag = "\t\n"; + xml.Attribute("compression", "gzip"); + xml.Attribute("encoding", "base64"); } + xml.Content(memcheckstr); + xml.EndElement(); // Log - os - << "\t\t\n" - << logTag << cmXMLSafe(memcheckstr) << std::endl - << "\t\n"; - this->WriteTestResultFooter(os, result); + this->WriteTestResultFooter(xml, result); if ( current < cc ) { cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "#" << std::flush, @@ -460,7 +453,7 @@ void cmCTestMemCheckHandler::GenerateDartOutput(std::ostream& os) cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, std::endl, this->Quiet); cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Memory checking results:" << std::endl, this->Quiet); - os << "\t" << std::endl; + xml.StartElement("DefectList"); for ( cc = 0; cc < this->GlobalResults.size(); cc ++ ) { if ( this->GlobalResults[cc] ) @@ -473,21 +466,20 @@ void cmCTestMemCheckHandler::GenerateDartOutput(std::ostream& os) cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, this->ResultStringsLong[cc] << " - " << this->GlobalResults[cc] << std::endl, this->Quiet); - os << "\t\tResultStringsLong[cc] - << "\"/>" << std::endl; + xml.StartElement("Defect"); + xml.Attribute("Type", this->ResultStringsLong[cc]); + xml.EndElement(); } } - os << "\t" << std::endl; + xml.EndElement(); // DefectList - os << "\t" << this->EndTest << "" << std::endl; - os << "\t" << this->EndTestTime - << "" << std::endl; - os << "" - << static_cast(this->ElapsedTestingTime/6)/10.0 - << "\n"; + xml.Element("EndDateTime", this->EndTest); + xml.Element("EndTestTime", this->EndTestTime); + xml.Element("ElapsedMinutes", + static_cast(this->ElapsedTestingTime/6)/10.0); - os << "" << std::endl; - this->CTest->EndXML(os); + xml.EndElement(); // DynamicAnalysis + this->CTest->EndXML(xml); } //---------------------------------------------------------------------- diff --git a/Source/CTest/cmCTestMemCheckHandler.h b/Source/CTest/cmCTestMemCheckHandler.h index 69fdd9f..f1ac794 100644 --- a/Source/CTest/cmCTestMemCheckHandler.h +++ b/Source/CTest/cmCTestMemCheckHandler.h @@ -21,6 +21,7 @@ #include class cmMakefile; +class cmXMLWriter; /** \class cmCTestMemCheckHandler * \brief A class that handles ctest -S invocations @@ -119,7 +120,7 @@ private: /** * Generate the Dart compatible output */ - void GenerateDartOutput(std::ostream& os); + void GenerateDartOutput(cmXMLWriter& xml); std::vector CustomPreMemCheck; std::vector CustomPostMemCheck; diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index aa68461..c0b9a65 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -27,7 +27,7 @@ #include "cmLocalGenerator.h" #include "cmCommand.h" #include "cmSystemTools.h" -#include "cmXMLSafe.h" +#include "cmXMLWriter.h" #include "cm_utf8.h" #include @@ -633,7 +633,8 @@ int cmCTestTestHandler::ProcessHandler() this->LogFile = 0; return 1; } - this->GenerateDartOutput(xmlfile); + cmXMLWriter xml(xmlfile); + this->GenerateDartOutput(xml); } if ( ! this->PostProcessHandler() ) @@ -1142,54 +1143,53 @@ void cmCTestTestHandler::GenerateTestCommand(std::vector&, int) } //---------------------------------------------------------------------- -void cmCTestTestHandler::GenerateDartOutput(std::ostream& os) +void cmCTestTestHandler::GenerateDartOutput(cmXMLWriter& xml) { if ( !this->CTest->GetProduceXML() ) { return; } - this->CTest->StartXML(os, this->AppendXML); - os << "\n" - << "\t" << this->StartTest << "\n" - << "\t" << this->StartTestTime << "\n" - << "\t\n"; + this->CTest->StartXML(xml, this->AppendXML); + xml.StartElement("Testing"); + xml.Element("StartDateTime", this->StartTest); + xml.Element("StartTestTime", this->StartTestTime); + xml.StartElement("TestList"); cmCTestTestHandler::TestResultsVector::size_type cc; for ( cc = 0; cc < this->TestResults.size(); cc ++ ) { cmCTestTestResult *result = &this->TestResults[cc]; std::string testPath = result->Path + "/" + result->Name; - os << "\t\t" << cmXMLSafe( - this->CTest->GetShortPathToFile(testPath.c_str())) - << "" << std::endl; + xml.Element("Test", this->CTest->GetShortPathToFile(testPath.c_str())); } - os << "\t\n"; + xml.EndElement(); // TestList for ( cc = 0; cc < this->TestResults.size(); cc ++ ) { cmCTestTestResult *result = &this->TestResults[cc]; - this->WriteTestResultHeader(os, result); - os << "\t\t" << std::endl; + this->WriteTestResultHeader(xml, result); + xml.StartElement("Results"); if ( result->Status != cmCTestTestHandler::NOT_RUN ) { if ( result->Status != cmCTestTestHandler::COMPLETED || result->ReturnValue ) { - os << "\t\t\t" - << cmXMLSafe(this->GetTestStatus(result->Status)) - << "" - "\n" - << "\t\t\t" - << result->ReturnValue - << "" - << std::endl; + xml.StartElement("NamedMeasurement"); + xml.Attribute("type", "text/string"); + xml.Attribute("name", "Exit Code"); + xml.Element("Value", this->GetTestStatus(result->Status)); + xml.EndElement(); // NamedMeasurement + xml.StartElement("NamedMeasurement"); + xml.Attribute("type", "text/string"); + xml.Attribute("name", "Exit Value"); + xml.Element("Value", result->ReturnValue); + xml.EndElement(); // NamedMeasurement } - this->GenerateRegressionImages(os, result->DartString); - os << "\t\t\t" - << result->ExecutionTime - << "\n"; + this->GenerateRegressionImages(xml, result->DartString); + xml.StartElement("NamedMeasurement"); + xml.Attribute("type", "numeric/double"); + xml.Attribute("name", "Execution Time"); + xml.Element("Value", result->ExecutionTime); + xml.EndElement(); // NamedMeasurement if(!result->Reason.empty()) { const char* reasonType = "Pass Reason"; @@ -1198,109 +1198,103 @@ void cmCTestTestHandler::GenerateDartOutput(std::ostream& os) { reasonType = "Fail Reason"; } - os << "\t\t\t" - << cmXMLSafe(result->Reason) - << "\n"; + xml.StartElement("NamedMeasurement"); + xml.Attribute("type", "text/string"); + xml.Attribute("name", reasonType); + xml.Element("Value", result->Reason); + xml.EndElement(); // NamedMeasurement } - os - << "\t\t\t" - << cmXMLSafe(result->CompletionStatus) - << "\n"; - } - os - << "\t\t\t" - << cmXMLSafe(result->FullCommandLine) - << "\n"; + xml.StartElement("NamedMeasurement"); + xml.Attribute("type", "text/string"); + xml.Attribute("name", "Completion Status"); + xml.Element("Value", result->CompletionStatus); + xml.EndElement(); // NamedMeasurement + } + xml.StartElement("NamedMeasurement"); + xml.Attribute("type", "text/string"); + xml.Attribute("name", "Command Line"); + xml.Element("Value", result->FullCommandLine); + xml.EndElement(); // NamedMeasurement std::map::iterator measureIt; for ( measureIt = result->Properties->Measurements.begin(); measureIt != result->Properties->Measurements.end(); ++ measureIt ) { - os - << "\t\t\tfirst << "\">" - << cmXMLSafe(measureIt->second) - << "\n"; - } - os - << "\t\t\t\n" - << "\t\t\t\tCompressOutput ? - " encoding=\"base64\" compression=\"gzip\">" - : ">"); - os << cmXMLSafe(result->Output); - os - << "\n" - << "\t\t\t\n" - << "\t\t\n"; - - this->AttachFiles(os, result); - this->WriteTestResultFooter(os, result); - } - - os << "\t" << this->EndTest << "\n" - << "\t" << this->EndTestTime << "\n" - << "" - << static_cast(this->ElapsedTestingTime/6)/10.0 - << "" - << "" << std::endl; - this->CTest->EndXML(os); + xml.StartElement("NamedMeasurement"); + xml.Attribute("type", "text/string"); + xml.Attribute("name", measureIt->first); + xml.Element("Value", measureIt->second); + xml.EndElement(); // NamedMeasurement + } + xml.StartElement("Measurement"); + xml.StartElement("Value"); + if (result->CompressOutput) + { + xml.Attribute("encoding", "base64"); + xml.Attribute("compression", "gzip"); + } + xml.Content(result->Output); + xml.EndElement(); // Value + xml.EndElement(); // Measurement + xml.EndElement(); // Results + + this->AttachFiles(xml, result); + this->WriteTestResultFooter(xml, result); + } + + xml.Element("EndDateTime", this->EndTest); + xml.Element("EndTestTime", this->EndTestTime); + xml.Element("ElapsedMinutes", + static_cast(this->ElapsedTestingTime/6)/10.0); + xml.EndElement(); // Testing + this->CTest->EndXML(xml); } //---------------------------------------------------------------------------- -void cmCTestTestHandler::WriteTestResultHeader(std::ostream& os, +void cmCTestTestHandler::WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result) { - os << "\tStatus == cmCTestTestHandler::COMPLETED ) { - os << "passed"; + xml.Attribute("Status", "passed"); } else if ( result->Status == cmCTestTestHandler::NOT_RUN ) { - os << "notrun"; + xml.Attribute("Status", "notrun"); } else { - os << "failed"; + xml.Attribute("Status", "failed"); } std::string testPath = result->Path + "/" + result->Name; - os << "\">\n" - << "\t\t" << cmXMLSafe(result->Name) << "\n" - << "\t\t" << cmXMLSafe( - this->CTest->GetShortPathToFile(result->Path.c_str())) << "\n" - << "\t\t" << cmXMLSafe( - this->CTest->GetShortPathToFile(testPath.c_str())) << "\n" - << "\t\t" - << cmXMLSafe(result->FullCommandLine) - << "\n"; + xml.Element("Name", result->Name); + xml.Element("Path", this->CTest->GetShortPathToFile(result->Path.c_str())); + xml.Element("FullName", this->CTest->GetShortPathToFile(testPath.c_str())); + xml.Element("FullCommandLine", result->FullCommandLine); } //---------------------------------------------------------------------------- -void cmCTestTestHandler::WriteTestResultFooter(std::ostream& os, +void cmCTestTestHandler::WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result) { if(!result->Properties->Labels.empty()) { - os << "\t\t\n"; + xml.StartElement("Labels"); std::vector const& labels = result->Properties->Labels; for(std::vector::const_iterator li = labels.begin(); li != labels.end(); ++li) { - os << "\t\t\t\n"; + xml.Element("Label", *li); } - os << "\t\t\n"; + xml.EndElement(); // Labels } - os - << "\t" << std::endl; + xml.EndElement(); // Test } //---------------------------------------------------------------------- -void cmCTestTestHandler::AttachFiles(std::ostream& os, +void cmCTestTestHandler::AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result) { if(result->Status != cmCTestTestHandler::COMPLETED @@ -1317,11 +1311,14 @@ void cmCTestTestHandler::AttachFiles(std::ostream& os, { const std::string &base64 = this->CTest->Base64GzipEncodeFile(*file); std::string fname = cmSystemTools::GetFilenameName(*file); - os << "\t\t" - "\n\t\t\t\n\t\t\t" - << base64 - << "\n\t\t\t\n\t\t\n"; + xml.StartElement("NamedMeasurement"); + xml.Attribute("name", "Attached File"); + xml.Attribute("encoding", "base64"); + xml.Attribute("compression", "tar/gzip"); + xml.Attribute("filename", fname); + xml.Attribute("type", "file"); + xml.Element("Value", base64); + xml.EndElement(); // NamedMeasurement } } @@ -1829,7 +1826,7 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed() #define SPACE_REGEX "[ \t\r\n]" //---------------------------------------------------------------------- void cmCTestTestHandler::GenerateRegressionImages( - std::ostream& ostr, const std::string& xml) + cmXMLWriter& xml, const std::string& dart) { cmsys::RegularExpression twoattributes( "([^<]*)"); bool done = false; - std::string cxml = xml; + std::string cxml = dart; while ( ! done ) { if ( twoattributes.find(cxml) ) { - ostr - << "\t\t\t" << twoattributes.match(5) - << "" - << std::endl; + xml.StartElement("NamedMeasurement"); + xml.Attribute(twoattributes.match(1).c_str(), + twoattributes.match(2)); + xml.Attribute(twoattributes.match(3).c_str(), + twoattributes.match(4)); + xml.Element("Value", twoattributes.match(5)); + xml.EndElement(); cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start()); } else if ( threeattributes.find(cxml) ) { - ostr - << "\t\t\t" << threeattributes.match(7) - << "" - << std::endl; + xml.StartElement("NamedMeasurement"); + xml.Attribute(threeattributes.match(1).c_str(), + threeattributes.match(2)); + xml.Attribute(threeattributes.match(3).c_str(), + threeattributes.match(4)); + xml.Attribute(threeattributes.match(5).c_str(), + threeattributes.match(6)); + xml.Element("Value", twoattributes.match(7)); + xml.EndElement(); cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start()); } else if ( fourattributes.find(cxml) ) { - ostr - << "\t\t\t" << fourattributes.match(9) - << "" - << std::endl; + xml.StartElement("NamedMeasurement"); + xml.Attribute(fourattributes.match(1).c_str(), + fourattributes.match(2)); + xml.Attribute(fourattributes.match(3).c_str(), + fourattributes.match(4)); + xml.Attribute(fourattributes.match(5).c_str(), + fourattributes.match(6)); + xml.Attribute(fourattributes.match(7).c_str(), + fourattributes.match(8)); + xml.Element("Value", twoattributes.match(9)); + xml.EndElement(); cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start()); } else if ( cdatastart.find(cxml) && cdataend.find(cxml) ) { - ostr - << "\t\t\t" - << std::endl; + xml.StartElement("NamedMeasurement"); + xml.Attribute(cdatastart.match(1).c_str(), cdatastart.match(2)); + xml.Attribute(cdatastart.match(3).c_str(), cdatastart.match(4)); + xml.StartElement("Value"); + xml.CData( + cxml.substr(cdatastart.end(), cdataend.start() - cdatastart.end())); + xml.EndElement(); // Value + xml.EndElement(); // NamedMeasurement cxml.erase(cdatastart.start(), cdataend.end() - cdatastart.start()); } @@ -1953,13 +1942,12 @@ void cmCTestTestHandler::GenerateRegressionImages( v2 = "text/string"; } - ostr - << "\t\t\tImage " << filename - << " is empty"; + xml.StartElement("NamedMeasurement"); + xml.Attribute(k1.c_str(), v1); + xml.Attribute(k2.c_str(), v2); + xml.Attribute("encoding", "none"); + xml.Element("Value", "Image " + filename + " is empty"); + xml.EndElement(); } else { @@ -1977,14 +1965,13 @@ void cmCTestTestHandler::GenerateRegressionImages( size_t rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1); - ostr - << "\t\t\t" << std::endl << "\t\t\t\t"; + xml.StartElement("NamedMeasurement"); + xml.Attribute(measurementfile.match(1).c_str(), + measurementfile.match(2)); + xml.Attribute(measurementfile.match(3).c_str(), + measurementfile.match(4)); + xml.Attribute("encoding", "base64"); + std::stringstream ostr; for (size_t cc = 0; cc < rlen; cc ++ ) { ostr << encoded_buffer[cc]; @@ -1993,9 +1980,8 @@ void cmCTestTestHandler::GenerateRegressionImages( ostr << std::endl; } } - ostr - << "" << std::endl << "\t\t\t" - << std::endl; + xml.Element("Value", ostr.str()); + xml.EndElement(); // NamedMeasurement delete [] file_buffer; delete [] encoded_buffer; } @@ -2007,13 +1993,11 @@ void cmCTestTestHandler::GenerateRegressionImages( { idx = 2; } - ostr - << "\t\t\tFile " << filename - << " not found" - << std::endl; + xml.StartElement("NamedMeasurement"); + xml.Attribute("name", measurementfile.match(idx)); + xml.Attribute("text", "text/string"); + xml.Element("Value", "File " + filename + " not found"); + xml.EndElement(); cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "File \"" << filename << "\" not found." << std::endl, this->Quiet); } diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 623c996..14067d5 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -18,6 +18,7 @@ #include class cmMakefile; +class cmXMLWriter; /** \class cmCTestTestHandler * \brief A class that handles ctest -S invocations @@ -164,10 +165,10 @@ protected: virtual void GenerateTestCommand(std::vector& args, int test); int ExecuteCommands(std::vector& vec); - void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result); - void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result); + void WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result); + void WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result); // Write attached test files into the xml - void AttachFiles(std::ostream& os, cmCTestTestResult* result); + void AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result); //! Clean test output to specified length bool CleanTestOutput(std::string& output, size_t length); @@ -204,7 +205,7 @@ private: /** * Generate the Dart compatible output */ - virtual void GenerateDartOutput(std::ostream& os); + virtual void GenerateDartOutput(cmXMLWriter& xml); void PrintLabelSummary(); /** @@ -270,7 +271,7 @@ private: cmsys::RegularExpression IncludeTestsRegularExpression; cmsys::RegularExpression ExcludeTestsRegularExpression; - void GenerateRegressionImages(std::ostream& ostr, const std::string& xml); + void GenerateRegressionImages(cmXMLWriter& xml, const std::string& dart); cmsys::RegularExpression DartStuff1; void CheckLabelFilter(cmCTestTestProperties& it); void CheckLabelFilterExclude(cmCTestTestProperties& it); -- cgit v0.12