[Cmake-commits] [cmake-commits] zach.mullen committed cmCTestRunTest.cxx 1.33 1.34 cmCTestRunTest.h 1.14 1.15 cmCTestTestHandler.cxx 1.135 1.136 cmCTestTestHandler.h 1.55 1.56

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Dec 17 11:14:52 EST 2009


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

Modified Files:
	cmCTestRunTest.cxx cmCTestRunTest.h cmCTestTestHandler.cxx 
	cmCTestTestHandler.h 
Log Message:
CTest output submitted to the dashboard is now compressed by default.


Index: cmCTestTestHandler.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestTestHandler.cxx,v
retrieving revision 1.135
retrieving revision 1.136
diff -C 2 -d -r1.135 -r1.136
*** cmCTestTestHandler.cxx	16 Dec 2009 19:50:16 -0000	1.135
--- cmCTestTestHandler.cxx	17 Dec 2009 16:14:49 -0000	1.136
***************
*** 1187,1191 ****
      os
        << "\t\t\t<Measurement>\n"
!       << "\t\t\t\t<Value>";
      os << cmXMLSafe(result->Output);
      os
--- 1187,1194 ----
      os
        << "\t\t\t<Measurement>\n"
!       << "\t\t\t\t<Value"
!       << (result->CompressOutput ? 
!       " encoding=\"base64\" compression=\"gzip\">"
!       : ">");
      os << cmXMLSafe(result->Output);
      os

Index: cmCTestTestHandler.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestTestHandler.h,v
retrieving revision 1.55
retrieving revision 1.56
diff -C 2 -d -r1.55 -r1.56
*** cmCTestTestHandler.h	16 Dec 2009 19:50:16 -0000	1.55
--- cmCTestTestHandler.h	17 Dec 2009 16:14:49 -0000	1.56
***************
*** 115,118 ****
--- 115,119 ----
      int         ReturnValue;
      int         Status;
+     bool        CompressOutput;
      std::string CompletionStatus;
      std::string Output;

Index: cmCTestRunTest.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestRunTest.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -C 2 -d -r1.14 -r1.15
*** cmCTestRunTest.h	10 Dec 2009 19:38:32 -0000	1.14
--- cmCTestRunTest.h	17 Dec 2009 16:14:49 -0000	1.15
***************
*** 46,49 ****
--- 46,52 ----
    bool CheckOutput();
  
+   // Compresses the output, writing to CompressedOutput
+   void CompressOutput();
+ 
    //launch the test process, return whether it started correctly
    bool StartTest(size_t total);
***************
*** 80,83 ****
--- 83,88 ----
    std::vector<std::string> OrigEnv;
    std::string ProcessOutput;
+   std::string CompressedOutput;
+   double CompressionRatio;
    //The test results
    cmCTestTestHandler::cmCTestTestResult TestResult;

Index: cmCTestRunTest.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CTest/cmCTestRunTest.cxx,v
retrieving revision 1.33
retrieving revision 1.34
diff -C 2 -d -r1.33 -r1.34
*** cmCTestRunTest.cxx	10 Dec 2009 20:51:56 -0000	1.33
--- cmCTestRunTest.cxx	17 Dec 2009 16:14:48 -0000	1.34
***************
*** 16,19 ****
--- 16,22 ----
  #include "cmSystemTools.h"
  
+ #include <cm_zlib.h>
+ #include <cmsys/Base64.h>
+ 
  cmCTestRunTest::cmCTestRunTest(cmCTestTestHandler* handler)
  {
***************
*** 27,30 ****
--- 30,36 ----
    this->TestResult.TestCount = 0;
    this->TestResult.Properties = 0;
+   this->ProcessOutput = "";
+   this->CompressedOutput = "";
+   this->CompressionRatio = 2;
  }
  
***************
*** 53,57 ****
        // Store this line of output.
        cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
!                  this->GetIndex() << ": " << line << std::endl);
        this->ProcessOutput += line;
        this->ProcessOutput += "\n";
--- 59,63 ----
        // Store this line of output.
        cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
!                  this->GetIndex() << ": " << line << std::endl);  
        this->ProcessOutput += line;
        this->ProcessOutput += "\n";
***************
*** 66,71 ****
--- 72,140 ----
  
  //---------------------------------------------------------
+ // Streamed compression of test output.  The compressed data
+ // is appended to this->CompressedOutput
+ void cmCTestRunTest::CompressOutput()
+ {
+   int ret;
+   z_stream strm;
+ 
+   unsigned char* in = 
+     reinterpret_cast<unsigned char*>(
+     const_cast<char*>(this->ProcessOutput.c_str()));
+   //zlib makes the guarantee that this is the maximum output size
+   int outSize = static_cast<int>(this->ProcessOutput.size() * 1.001 + 13);
+   unsigned char* out = new unsigned char[outSize];
+ 
+   strm.zalloc = Z_NULL;
+   strm.zfree = Z_NULL;
+   strm.opaque = Z_NULL;
+   ret = deflateInit(&strm, -1); //default compression level
+   if (ret != Z_OK)
+     {
+     //log deflate init error?
+     return;
+     }
+ 
+   strm.avail_in = this->ProcessOutput.size();
+   strm.next_in = in;
+   strm.avail_out = outSize;
+   strm.next_out = out;
+   ret = deflate(&strm, Z_FINISH);
+ 
+   if(ret == Z_STREAM_ERROR || ret != Z_STREAM_END)
+     {
+     cmCTestLog(this->CTest, ERROR_MESSAGE, "Error initializing stream "
+       "compression. Sending uncompressed output." << std::endl);
+     return;
+     }
+ 
+   (void)deflateEnd(&strm);
+   
+   unsigned char *encoded_buffer
+     = new unsigned char[static_cast<int>(outSize * 1.5)];
+ 
+   unsigned long rlen
+     = cmsysBase64_Encode(out, strm.total_out, encoded_buffer, 1);
+   
+   for(unsigned long i = 0; i < rlen; i++)
+     {
+     this->CompressedOutput += encoded_buffer[i];
+     }
+ 
+   this->CompressionRatio = static_cast<double>(strm.total_out) /
+                            static_cast<double>(strm.total_in);
+ 
+   delete [] encoded_buffer;
+   delete [] out;
+ }
+ 
+ //---------------------------------------------------------
  bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
  {
+   if (this->CTest->ShouldCompressTestOutput())
+     {
+     this->CompressOutput();
+     }
+ 
    //restore the old environment
    if (this->ModifyEnv)
***************
*** 262,266 ****
    if(started)
      {
!     this->TestResult.Output = this->ProcessOutput;
      this->TestResult.ReturnValue = this->TestProcess->GetExitValue();
      this->TestResult.CompletionStatus = "Completed";
--- 331,339 ----
    if(started)
      {
!     bool compress = this->CompressionRatio < 1 &&
!       this->CTest->ShouldCompressTestOutput();
!     this->TestResult.Output = compress ? this->CompressedOutput 
!       : this->ProcessOutput;
!     this->TestResult.CompressOutput = compress;
      this->TestResult.ReturnValue = this->TestProcess->GetExitValue();
      this->TestResult.CompletionStatus = "Completed";
***************
*** 311,314 ****
--- 384,388 ----
    this->TestResult.Properties = this->TestProperties;
    this->TestResult.ExecutionTime = 0;
+   this->TestResult.CompressOutput = false;
    this->TestResult.ReturnValue = -1;
    this->TestResult.CompletionStatus = "Failed to start";



More information about the Cmake-commits mailing list