From: Peter Collingbourne Date: Sat, 31 May 2014 01:36:02 +0000 (+0000) Subject: Fix the behavior of ExecuteAndWait with a non-zero timeout. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec1aacaf5c9b5a9ff7ca7ab7a99b4c6bbdfb6fca;p=platform%2Fupstream%2Fllvm.git Fix the behavior of ExecuteAndWait with a non-zero timeout. llvm-svn: 209951 --- diff --git a/llvm/lib/Support/Program.cpp b/llvm/lib/Support/Program.cpp index 83f2ec4..913c099 100644 --- a/llvm/lib/Support/Program.cpp +++ b/llvm/lib/Support/Program.cpp @@ -34,7 +34,8 @@ int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp, if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) { if (ExecutionFailed) *ExecutionFailed = false; - ProcessInfo Result = Wait(PI, secondsToWait, true, ErrMsg); + ProcessInfo Result = Wait( + PI, secondsToWait, /*WaitUntilTerminates=*/secondsToWait == 0, ErrMsg); return Result.ReturnCode; } diff --git a/llvm/unittests/Support/ProgramTest.cpp b/llvm/unittests/Support/ProgramTest.cpp index 800df14..d8cb42a 100644 --- a/llvm/unittests/Support/ProgramTest.cpp +++ b/llvm/unittests/Support/ProgramTest.cpp @@ -162,6 +162,36 @@ TEST(ProgramTest, TestExecuteNoWait) { ASSERT_GT(LoopCount, 1u) << "LoopCount should be >1"; } +TEST(ProgramTest, TestExecuteAndWaitTimeout) { + using namespace llvm::sys; + + if (getenv("LLVM_PROGRAM_TEST_TIMEOUT")) { + sleep_for(/*seconds*/ 10); + exit(0); + } + + std::string Executable = + sys::fs::getMainExecutable(TestMainArgv0, &ProgramTestStringArg1); + const char *argv[] = { + Executable.c_str(), + "--gtest_filter=ProgramTest.TestExecuteAndWaitTimeout", + 0 + }; + + // Add LLVM_PROGRAM_TEST_TIMEOUT to the environment of the child. + std::vector envp; + CopyEnvironment(envp); + envp.push_back("LLVM_PROGRAM_TEST_TIMEOUT=1"); + envp.push_back(0); + + std::string Error; + bool ExecutionFailed; + int RetCode = + ExecuteAndWait(Executable, argv, &envp[0], 0, /*secondsToWait=*/1, 0, + &Error, &ExecutionFailed); + ASSERT_EQ(-2, RetCode); +} + TEST(ProgramTest, TestExecuteNegative) { std::string Executable = "i_dont_exist"; const char *argv[] = { Executable.c_str(), 0 };