From dc66139f7c03a348fca8f7771ebc3e23eb9361d3 Mon Sep 17 00:00:00 2001 From: Zach Mullen Date: Tue, 15 Dec 2009 12:07:15 -0500 Subject: CTest-side changes to allow users to attach arbitrary files to test results that will be submitted to cdash using the ATTACHED_FILES test property. --- Source/CTest/cmCTestTestHandler.cxx | 92 +++++++++++++++++++++++++++++++++++- Source/CTest/cmCTestTestHandler.h | 5 ++ Source/cmSetTestsPropertiesCommand.h | 7 ++- 3 files changed, 100 insertions(+), 4 deletions(-) diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index dd99268..da78815 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1192,6 +1192,8 @@ void cmCTestTestHandler::GenerateDartOutput(std::ostream& os) << "\n" << "\t\t\t\n" << "\t\t\n"; + + this->AttachFiles(os, result); this->WriteTestResultFooter(os, result); } @@ -1253,6 +1255,74 @@ void cmCTestTestHandler::WriteTestResultFooter(std::ostream& os, << "\t" << std::endl; } +void cmCTestTestHandler::AttachFiles(std::ostream& os, + cmCTestTestResult* result) +{ + if(result->Properties->AttachedFiles.empty()) + { + return; + } + + std::string base64 = this->EncodeFiles(result); + if(base64 == "") + { + return; + } + os << "\t\t\n" + << base64 << "\n" + << "\t\t\n"; +} + +//---------------------------------------------------------------------- +std::string cmCTestTestHandler::EncodeFiles(cmCTestTestResult* result) +{ + //create the temp tar file + std::string tarFile = result->Name + "_attached.tar.gz"; + std::vector files; + + for(std::vector::iterator f = + result->Properties->AttachedFiles.begin(); + f != result->Properties->AttachedFiles.end(); ++f) + { + const cmStdString fname = f->c_str(); + files.push_back(fname); + } + + if(!cmSystemTools::CreateTar(tarFile.c_str(), files, true, false, false)) + { + cmCTestLog(this->CTest, ERROR_MESSAGE, "Error creating tar while " + "attaching files to the following test: " << result->Name << std::endl); + return ""; + } + + long len = cmSystemTools::FileLength(tarFile.c_str()); + std::ifstream ifs(tarFile.c_str(), std::ios::in +#ifdef _WIN32 + | std::ios::binary +#endif + ); + unsigned char *file_buffer = new unsigned char [ len + 1 ]; + ifs.read(reinterpret_cast(file_buffer), len); + ifs.close(); + cmSystemTools::RemoveFile(tarFile.c_str()); + + unsigned char *encoded_buffer + = new unsigned char [ static_cast(len * 1.5 + 5) ]; + + unsigned long rlen + = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1); + + std::string base64 = ""; + for(unsigned long i = 0; i < rlen; i++) + { + base64 += encoded_buffer[i]; + } + delete [] file_buffer; + delete [] encoded_buffer; + + return base64; +} + //---------------------------------------------------------------------- int cmCTestTestHandler::ExecuteCommands(std::vector& vec) { @@ -2005,6 +2075,17 @@ bool cmCTestTestHandler::SetTestsProperties( { rtit->WillFail = cmSystemTools::IsOn(val.c_str()); } + if ( key == "ATTACHED_FILES" ) + { + std::vector lval; + cmSystemTools::ExpandListArgument(val.c_str(), lval); + + for(std::vector::iterator f = lval.begin(); + f != lval.end(); ++f) + { + rtit->AttachedFiles.push_back(*f); + } + } if ( key == "TIMEOUT" ) { rtit->Timeout = atof(val.c_str()); @@ -2013,9 +2094,16 @@ bool cmCTestTestHandler::SetTestsProperties( { rtit->Cost = static_cast(atof(val.c_str())); } - if ( key == "REQUIRED_FILE" ) + if ( key == "REQUIRED_FILES" ) { - rtit->RequiredFiles.push_back(val); + std::vector lval; + cmSystemTools::ExpandListArgument(val.c_str(), lval); + + for(std::vector::iterator f = lval.begin(); + f != lval.end(); ++f) + { + rtit->RequiredFiles.push_back(*f); + } } if ( key == "RUN_SERIAL" ) { diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 1afa3d3..0e0cffd 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -86,6 +86,7 @@ public: std::vector Args; std::vector RequiredFiles; std::vector Depends; + std::vector AttachedFiles; std::vector > ErrorRegularExpressions; std::vector