[Cmake-commits] CMake branch, next, updated. v2.8.11.2-4308-g5cf00ba

Zack Galbreath zack.galbreath at kitware.com
Tue Sep 24 14:25:04 EDT 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  5cf00baaf0e6f2a5299da5c3fcead01f941d7dd3 (commit)
       via  0db752eb77942d4bf4a82baa756b62fbd66a4cdd (commit)
      from  24d6354e4d28c5e8e8ce3c2aeef5d6bcfae89b24 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5cf00baaf0e6f2a5299da5c3fcead01f941d7dd3
commit 5cf00baaf0e6f2a5299da5c3fcead01f941d7dd3
Merge: 24d6354 0db752e
Author:     Zack Galbreath <zack.galbreath at kitware.com>
AuthorDate: Tue Sep 24 14:25:00 2013 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Tue Sep 24 14:25:00 2013 -0400

    Merge topic 'ctest_rerun_failed' into next
    
    0db752e new ctest command line argument: --rerun-failed


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0db752eb77942d4bf4a82baa756b62fbd66a4cdd
commit 0db752eb77942d4bf4a82baa756b62fbd66a4cdd
Author:     Zack Galbreath <zack.galbreath at kitware.com>
AuthorDate: Tue Sep 24 14:20:38 2013 -0400
Commit:     Zack Galbreath <zack.galbreath at kitware.com>
CommitDate: Tue Sep 24 14:20:38 2013 -0400

    new ctest command line argument: --rerun-failed
    
    Add a new command line argument to ctest.  This allows users to
    rerun tests that failed during the previous call to ctest.  This
    is accomplished by analyzing the most recently modified file named
    "^LastTestsFailed*" in the Testing/Temporary subdirectory of the
    project's binary directory.

diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index 497774d..1145b88 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -20,6 +20,7 @@
 #include <cmsys/Process.h>
 #include <cmsys/RegularExpression.hxx>
 #include <cmsys/Base64.h>
+#include <cmsys/Directory.hxx>
 #include "cmMakefile.h"
 #include "cmGlobalGenerator.h"
 #include "cmLocalGenerator.h"
@@ -537,6 +538,7 @@ int cmCTestTestHandler::ProcessHandler()
     this->UseExcludeRegExp();
     this->SetExcludeRegExp(val);
     }
+  this->SetRerunFailed(cmSystemTools::IsOn(this->GetOption("RerunFailed")));
 
   this->TestResults.clear();
 
@@ -819,6 +821,13 @@ void cmCTestTestHandler::ComputeTestList()
 {
   this->TestList.clear(); // clear list of test
   this->GetListOfTests();
+
+  if (this->RerunFailed)
+    {
+    this->ComputeTestListForRerunFailed();
+    return;
+    }
+
   cmCTestTestHandler::ListOfTests::size_type tmsize = this->TestList.size();
   // how many tests are in based on RegExp?
   int inREcnt = 0;
@@ -881,9 +890,47 @@ void cmCTestTestHandler::ComputeTestList()
   this->TotalNumberOfTests = this->TestList.size();
   // Set the TestList to the final list of all test
   this->TestList = finalList;
+
+  this->UpdateMaxTestNameWidth();
+}
+
+void cmCTestTestHandler::ComputeTestListForRerunFailed()
+{
+  this->ExpandTestsToRunInformationForRerunFailed();
+
+  cmCTestTestHandler::ListOfTests::iterator it;
+  ListOfTests finalList;
+  int cnt = 0;
+  for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
+    {
+    cnt ++;
+
+    // if this test is not in our list of tests to run, then skip it.
+    if ((this->TestsToRun.size() &&
+         std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt)
+         == this->TestsToRun.end()))
+      {
+      continue;
+      }
+
+    it->Index = cnt;
+    finalList.push_back(*it);
+    }
+
+  // Save the total number of tests before exclusions
+  this->TotalNumberOfTests = this->TestList.size();
+
+  // Set the TestList to the list of failed tests to rerun
+  this->TestList = finalList;
+
+  this->UpdateMaxTestNameWidth();
+}
+
+void cmCTestTestHandler::UpdateMaxTestNameWidth()
+{
   std::string::size_type max = this->CTest->GetMaxTestNameWidth();
-  for (it = this->TestList.begin();
-       it != this->TestList.end(); it ++ )
+  for ( cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin();
+        it != this->TestList.end(); it ++ )
     {
     cmCTestTestProperties& p = *it;
     if(max < p.Name.size())
@@ -1708,6 +1755,88 @@ void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests)
   this->TestsToRun.erase(new_end, this->TestsToRun.end());
 }
 
+void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
+{
+
+  std::string dirName = this->CTest->GetBinaryDir() + "/Testing/Temporary";
+
+  cmsys::Directory directory;
+  if (directory.Load(dirName.c_str()) == 0)
+    {
+    cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to read the contents of "
+      << dirName << std::endl);
+    return;
+    }
+
+  int numFiles = static_cast<int>
+    (cmsys::Directory::GetNumberOfFilesInDirectory(dirName.c_str()));
+  std::string pattern = "LastTestsFailed";
+  std::string logName = "";
+
+  for (int i = 0; i < numFiles; ++i)
+    {
+    std::string fileName = directory.GetFile(i);
+    if (fileName.compare(0, pattern.length(), pattern) != 0)
+      {
+      continue;
+      }
+    if (logName == "")
+      {
+      logName = fileName;
+      }
+    else
+      {
+      // if multiple matching logs were found we use the most recently
+      // modified one.
+      int res;
+      cmSystemTools::FileTimeCompare(logName.c_str(), fileName.c_str(), &res);
+      if (res == -1)
+        {
+        logName = fileName;
+        }
+      }
+    }
+
+  std::string lastTestsFailedLog = this->CTest->GetBinaryDir()
+    + "/Testing/Temporary/" + logName;
+
+  if ( !cmSystemTools::FileExists(lastTestsFailedLog.c_str()) )
+    {
+    if ( !this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels() )
+      {
+      cmCTestLog(this->CTest, ERROR_MESSAGE, lastTestsFailedLog
+        << " does not exist!" << std::endl);
+      }
+    return;
+    }
+
+  // parse the list of tests to rerun from LastTestsFailed.log
+  std::ifstream ifs(lastTestsFailedLog.c_str());
+  if ( ifs )
+    {
+    std::string line;
+    std::string::size_type pos;
+    while ( cmSystemTools::GetLineFromStream(ifs, line) )
+      {
+      pos = line.find(':', 0);
+      if (pos == line.npos)
+        {
+        continue;
+        }
+
+      int val = atoi(line.substr(0, pos).c_str());
+      this->TestsToRun.push_back(val);
+      }
+    ifs.close();
+    }
+  else if ( !this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels() )
+    {
+    cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem reading file: "
+      << lastTestsFailedLog.c_str() <<
+      " while generating list of previously failed tests." << std::endl);
+    }
+}
+
 //----------------------------------------------------------------------
 // Just for convenience
 #define SPACE_REGEX "[ \t\r\n]"
diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h
index 93b793b..398f052 100644
--- a/Source/CTest/cmCTestTestHandler.h
+++ b/Source/CTest/cmCTestTestHandler.h
@@ -44,6 +44,12 @@ public:
   void SetUseUnion(bool val) { this->UseUnion = val; }
 
   /**
+   * Set whether or not CTest should only execute the tests that failed
+   * on the previous run.  By default this is false.
+   */
+  void SetRerunFailed(bool val) { this->RerunFailed = val; }
+
+  /**
    * This method is called when reading CTest custom file
    */
   void PopulateCustomVectors(cmMakefile *mf);
@@ -213,6 +219,12 @@ private:
   // based on union regex and -I stuff
   void ComputeTestList();
 
+  // compute the lists of tests that will actually run
+  // based on LastTestFailed.log
+  void ComputeTestListForRerunFailed();
+
+  void UpdateMaxTestNameWidth();
+
   bool GetValue(const char* tag,
                 std::string& value,
                 std::ifstream& fin);
@@ -235,6 +247,7 @@ private:
 
   const char* GetTestStatus(int status);
   void ExpandTestsToRunInformation(size_t numPossibleTests);
+  void ExpandTestsToRunInformationForRerunFailed();
 
   std::vector<cmStdString> CustomPreTest;
   std::vector<cmStdString> CustomPostTest;
@@ -268,6 +281,8 @@ private:
   cmsys::RegularExpression DartStuff;
 
   std::ostream* LogFile;
+
+  bool RerunFailed;
 };
 
 #endif
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 14e1f50..feae61a 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -2187,6 +2187,12 @@ void cmCTest::HandleCommandLineArguments(size_t &i,
     this->GetHandler("memcheck")->
       SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
     }
+
+  if(this->CheckArgument(arg, "--rerun-failed"))
+    {
+    this->GetHandler("test")->SetPersistentOption("RerunFailed", "true");
+    this->GetHandler("memcheck")->SetPersistentOption("RerunFailed", "true");
+    }
 }
 
 //----------------------------------------------------------------------
diff --git a/Source/ctest.cxx b/Source/ctest.cxx
index e767a16..ece68f5 100644
--- a/Source/ctest.cxx
+++ b/Source/ctest.cxx
@@ -150,6 +150,13 @@ static const char * cmDocumentationOptions[][3] =
   {"-U, --union", "Take the Union of -I and -R",
    "When both -R and -I are specified by default the intersection of "
    "tests are run. By specifying -U the union of tests is run instead."},
+  {"--rerun-failed", "Run only the tests that failed previously",
+   "This option tells ctest to perform only the tests that failed during its "
+   "previous run. When this option is specified, ctest ignores all other "
+   "options intended to modify the list of tests to run "
+   "(-L, -R, -E, -LE, -I, etc). In the event that CTest runs and no tests "
+   "fail, subsequent calls to ctest with the --rerun-failed option will "
+   "run the set of tests that most recently failed (if any)."},
   {"--max-width <width>", "Set the max width for a test name to output",
    "Set the maximum width for each test name to show in the output.  This "
    "allows the user to widen the output to avoid clipping the test name which "
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 9c3ed59..f2d23cb 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -2139,6 +2139,13 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
   set_tests_properties(CTestTestTimeout PROPERTIES
     PASS_REGULAR_EXPRESSION "TestTimeout *\\.+ *\\*\\*\\*Timeout.*CheckChild *\\.+ *Passed")
 
+  add_test(
+    NAME CTestTestRerunFailed
+    COMMAND ${CMAKE_CTEST_COMMAND} --rerun-failed
+    WORKING_DIRECTORY ${CMake_BINARY_DIR}/Tests/CTestTestTimeout)
+  set_tests_properties(CTestTestRerunFailed PROPERTIES
+    PASS_REGULAR_EXPRESSION "1 tests failed out of 1" DEPENDS CTestTestTimeout)
+
   configure_file(
     "${CMake_SOURCE_DIR}/Tests/CTestTestZeroTimeout/test.cmake.in"
     "${CMake_BINARY_DIR}/Tests/CTestTestZeroTimeout/test.cmake"

-----------------------------------------------------------------------

Summary of changes:
 Source/CTest/cmCTestTestHandler.cxx |  133 ++++++++++++++++++++++++++++++++++-
 Source/CTest/cmCTestTestHandler.h   |   15 ++++
 Source/cmCTest.cxx                  |    6 ++
 Source/ctest.cxx                    |    7 ++
 Tests/CMakeLists.txt                |    7 ++
 5 files changed, 166 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list