From 49085f7fedfe467211129205349edaeb9b195a18 Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Tue, 30 Jan 2007 11:35:17 -0500 Subject: [PATCH] BUG: fixes so that --build-and-test will honor timeouts --- Source/CMakeLists.txt | 11 ++++++ Source/CTest/cmCTestBuildAndTestHandler.cxx | 42 +++++++++++++++++++-- Source/cmGlobalGenerator.cxx | 12 +++--- Source/cmGlobalGenerator.h | 5 ++- Source/ctest.cxx | 4 +- 5 files changed, 62 insertions(+), 12 deletions(-) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index ff2638288..73676e410 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -383,6 +383,13 @@ IF(BUILD_TESTING) OPTION(CMAKE_RUN_LONG_TESTS "Should the long tests be run (such as Bootstrap)." ON) MARK_AS_ADVANCED(CMAKE_RUN_LONG_TESTS) + IF (CMAKE_RUN_LONG_TESTS) + OPTION(CTEST_TEST_CTEST + "Should the tests that run a full sub ctest process be run?" + OFF) + MARK_AS_ADVANCED(CTEST_TEST_CTEST) + ENDIF (CMAKE_RUN_LONG_TESTS) + ADD_TEST(CommandLineTest ${CMAKE_CTEST_COMMAND} --build-and-test "${CMake_SOURCE_DIR}/Tests/CommandLineTest" @@ -1071,6 +1078,10 @@ IF(BUILD_TESTING) -S "${CMake_BINARY_DIR}/Tests/CTestTest3/test.cmake" -V --output-log "${CMake_BINARY_DIR}/Tests/CTestTest3/testOutput.log" ) + # these tests take a log time, make sure they have it + SET_TESTS_PROPERTIES ( CTestTest CTestTest2 CTestTest3 + PROPERTIES TIMEOUT 1500 + ) ENDIF (CTEST_TEST_CTEST AND CMAKE_RUN_LONG_TESTS) IF("${CMAKE_TEST_GENERATOR}" MATCHES Xcode) diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx index f7b74810c..c47029980 100644 --- a/Source/CTest/cmCTestBuildAndTestHandler.cxx +++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx @@ -161,6 +161,10 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) return 1; } + // we need to honor the timeout specified, the timeout include cmake, build + // and test time + double clock_start = cmSystemTools::GetTime(); + // make sure the binary dir is there std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); out << "Internal cmake changing into directory: " @@ -178,7 +182,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) if(!this->BuildNoCMake) { - // do the cmake step + // do the cmake step, no timeout here since it is not a sub process if (this->RunCMake(outstring,out,cmakeOutString,cwd,&cm)) { return 1; @@ -194,12 +198,27 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) for ( tarIt = this->BuildTargets.begin(); tarIt != this->BuildTargets.end(); ++ tarIt ) { + double remainingTime = 0; + if (this->Timeout) + { + remainingTime = this->Timeout - cmSystemTools::GetTime() + clock_start; + if (remainingTime <= 0) + { + if(outstring) + { + *outstring = "--build-and-test timeout exceeded. "; + } + return 1; + } + } std::string output; int retVal = cm.GetGlobalGenerator()->Build( this->SourceDir.c_str(), this->BinaryDir.c_str(), this->BuildProject.c_str(), tarIt->c_str(), &output, this->BuildMakeProgram.c_str(), - this->CTest->GetConfigType().c_str(),!this->BuildNoClean, false); + this->CTest->GetConfigType().c_str(), + !this->BuildNoClean, + false, remainingTime); out << output; // if the build failed then return @@ -361,8 +380,25 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring) out << this->TestCommandArgs[k] << " "; } out << "\n"; + + // how much time is remaining + double remainingTime = 0; + if (this->Timeout) + { + remainingTime = this->Timeout - cmSystemTools::GetTime() + clock_start; + if (remainingTime <= 0) + { + if(outstring) + { + *outstring = "--build-and-test timeout exceeded. "; + } + return 1; + } + } + int runTestRes = this->CTest->RunTest(testCommand, &outs, &retval, 0, - this->Timeout); + remainingTime); + if(runTestRes != cmsysProcess_State_Exited || retval != 0) { out << "Failed to run test command: " << testCommand[0] << "\n"; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 62d1b2ff8..e554de739 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -28,8 +28,6 @@ #include -int cmGlobalGenerator::s_TryCompileTimeout = 0; - cmGlobalGenerator::cmGlobalGenerator() { // By default the .SYMBOLIC dependency is not needed on symbolic rules. @@ -49,6 +47,9 @@ cmGlobalGenerator::cmGlobalGenerator() // Whether an install target is needed. this->InstallTargetEnabled = false; + + // how long to let try compiles run + this->TryCompileTimeout = 0; } cmGlobalGenerator::~cmGlobalGenerator() @@ -808,7 +809,8 @@ int cmGlobalGenerator::TryCompile(const char *srcdir, const char *bindir, const char* config = mf->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION"); return this->Build(srcdir,bindir,projectName, newTarget.c_str(), - output,makeCommand.c_str(),config,false,true); + output,makeCommand.c_str(),config,false,true, + this->TryCompileTimeout); } std::string cmGlobalGenerator @@ -852,7 +854,8 @@ int cmGlobalGenerator::Build( std::string *output, const char *makeCommandCSTR, const char *config, - bool clean, bool fast) + bool clean, bool fast, + double timeout) { *output += "\nTesting TryCompileWithoutMakefile\n"; @@ -863,7 +866,6 @@ int cmGlobalGenerator::Build( cmSystemTools::ChangeDirectory(bindir); int retVal; - int timeout = cmGlobalGenerator::s_TryCompileTimeout; bool hideconsole = cmSystemTools::GetRunCommandHideConsole(); cmSystemTools::SetRunCommandHideConsole(true); diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 90a907e44..bccf8fa62 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -100,7 +100,8 @@ public: const char *projectName, const char *targetName, std::string *output, const char *makeProgram, const char *config, - bool clean, bool fast); + bool clean, bool fast, + double timeout); virtual std::string GenerateBuildCommand (const char* makeProgram, const char *projectName, const char* additionalOptions, @@ -125,7 +126,7 @@ public: void AddInstallComponent(const char* component); void EnableInstallTarget(); - static int s_TryCompileTimeout; + int TryCompileTimeout; bool GetForceUnixPaths() {return this->ForceUnixPaths;} bool GetToolSupportsColor() { return this->ToolSupportsColor; } diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 77d9fee82..864ae2688 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -148,7 +148,7 @@ static const cmDocumentationEntry cmDocumentationOptions[] = "complete. Other options that affect this mode are --build-target " "--build-nocmake, --build-run-dir, " "--build-two-config, --build-exe-dir, --build-project," - "--build-noclean, --build-options, --test-timeout"}, + "--build-noclean, --build-options"}, {"--build-target", "Specify a specific target to build.", "This option goes with the --build-and-test option, if left out the all " "target is built." }, @@ -168,7 +168,7 @@ static const cmDocumentationEntry cmDocumentationOptions[] = {"--test-command", "The test to run with the --build-and-test option.", "" }, - {"--test-timeout", "The time limit in seconds for --test-command.", "" + {"--test-timeout", "The time limit in seconds, internal use only.", "" }, {"--tomorrow-tag", "Nightly or experimental starts with next day tag.", "This is useful if the build will not finish in one day." },