[Cmake-commits] [cmake-commits] zach.mullen committed cmCTestTestHandler.cxx 1.132 1.133 cmCTestTestHandler.h 1.52 1.53

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Dec 15 12:07:14 EST 2009


Update of /cvsroot/CMake/CMake/Source/CTest
In directory public:/mounts/ram/cvs-serv25146/CTest

Modified Files:
	cmCTestTestHandler.cxx cmCTestTestHandler.h 
Log Message:
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.


Index: cmCTestTestHandler.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestTestHandler.cxx,v
retrieving revision 1.132
retrieving revision 1.133
diff -C 2 -d -r1.132 -r1.133
*** cmCTestTestHandler.cxx	10 Dec 2009 20:36:58 -0000	1.132
--- cmCTestTestHandler.cxx	15 Dec 2009 17:07:04 -0000	1.133
***************
*** 1193,1196 ****
--- 1193,1198 ----
        << "\t\t\t</Measurement>\n"
        << "\t\t</Results>\n";
+ 
+     this->AttachFiles(os, result);
      this->WriteTestResultFooter(os, result);
      }
***************
*** 1254,1257 ****
--- 1256,1327 ----
  }
  
+ 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<AttachedFiles encoding=\"base64\" compression=\"tar/gzip\">\n"
+      << base64 << "\n"
+      << "\t\t</AttachedFiles>\n";
+ }
+ 
+ //----------------------------------------------------------------------
+ std::string cmCTestTestHandler::EncodeFiles(cmCTestTestResult* result)
+ {
+   //create the temp tar file
+   std::string tarFile = result->Name + "_attached.tar.gz";
+   std::vector<cmStdString> files;
+ 
+   for(std::vector<std::string>::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<char*>(file_buffer), len);
+   ifs.close();
+   cmSystemTools::RemoveFile(tarFile.c_str());
+ 
+   unsigned char *encoded_buffer
+     = new unsigned char [ static_cast<int>(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<cmStdString>& vec)
***************
*** 2006,2009 ****
--- 2076,2090 ----
              rtit->WillFail = cmSystemTools::IsOn(val.c_str());
              }
+           if ( key == "ATTACHED_FILES" )
+             {
+             std::vector<std::string> lval;
+             cmSystemTools::ExpandListArgument(val.c_str(), lval);
+ 
+             for(std::vector<std::string>::iterator f = lval.begin();
+                 f != lval.end(); ++f)
+               {
+               rtit->AttachedFiles.push_back(*f);
+               }
+             }
            if ( key == "TIMEOUT" )
              {
***************
*** 2014,2020 ****
              rtit->Cost = static_cast<float>(atof(val.c_str()));
              }
!           if ( key == "REQUIRED_FILE" )
              {
!             rtit->RequiredFiles.push_back(val);
              }
            if ( key == "RUN_SERIAL" )
--- 2095,2108 ----
              rtit->Cost = static_cast<float>(atof(val.c_str()));
              }
!           if ( key == "REQUIRED_FILES" )
              {
!             std::vector<std::string> lval;
!             cmSystemTools::ExpandListArgument(val.c_str(), lval);
! 
!             for(std::vector<std::string>::iterator f = lval.begin();
!                 f != lval.end(); ++f)
!               {
!               rtit->RequiredFiles.push_back(*f);
!               }
              }
            if ( key == "RUN_SERIAL" )

Index: cmCTestTestHandler.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestTestHandler.h,v
retrieving revision 1.52
retrieving revision 1.53
diff -C 2 -d -r1.52 -r1.53
*** cmCTestTestHandler.h	10 Dec 2009 20:37:04 -0000	1.52
--- cmCTestTestHandler.h	15 Dec 2009 17:07:07 -0000	1.53
***************
*** 87,90 ****
--- 87,91 ----
      std::vector<std::string> RequiredFiles;
      std::vector<std::string> Depends;
+     std::vector<std::string> AttachedFiles;
      std::vector<std::pair<cmsys::RegularExpression,
                            std::string> > ErrorRegularExpressions;
***************
*** 144,147 ****
--- 145,152 ----
    void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
    void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);
+   // Write attached test files into the xml
+   void AttachFiles(std::ostream& os, cmCTestTestResult* result);
+   // Helper function to encode attached test files
+   std::string EncodeFiles(cmCTestTestResult* result);
  
    //! Clean test output to specified length



More information about the Cmake-commits mailing list