Skip to content

Commit

Permalink
Fix the behavior of ExecuteAndWait with a non-zero timeout.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209951 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
pcc committed May 31, 2014
1 parent c3648ce commit bfe1740
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Support/Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
30 changes: 30 additions & 0 deletions unittests/Support/ProgramTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *> 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 };
Expand Down

0 comments on commit bfe1740

Please sign in to comment.