llvm.org GIT mirror llvm / bfe1740
Fix the behavior of ExecuteAndWait with a non-zero timeout. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209951 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 6 years ago
2 changed file(s) with 32 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
3333 if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
3434 if (ExecutionFailed)
3535 *ExecutionFailed = false;
36 ProcessInfo Result = Wait(PI, secondsToWait, true, ErrMsg);
36 ProcessInfo Result = Wait(
37 PI, secondsToWait, /*WaitUntilTerminates=*/secondsToWait == 0, ErrMsg);
3738 return Result.ReturnCode;
3839 }
3940
161161 ASSERT_GT(LoopCount, 1u) << "LoopCount should be >1";
162162 }
163163
164 TEST(ProgramTest, TestExecuteAndWaitTimeout) {
165 using namespace llvm::sys;
166
167 if (getenv("LLVM_PROGRAM_TEST_TIMEOUT")) {
168 sleep_for(/*seconds*/ 10);
169 exit(0);
170 }
171
172 std::string Executable =
173 sys::fs::getMainExecutable(TestMainArgv0, &ProgramTestStringArg1);
174 const char *argv[] = {
175 Executable.c_str(),
176 "--gtest_filter=ProgramTest.TestExecuteAndWaitTimeout",
177 0
178 };
179
180 // Add LLVM_PROGRAM_TEST_TIMEOUT to the environment of the child.
181 std::vector envp;
182 CopyEnvironment(envp);
183 envp.push_back("LLVM_PROGRAM_TEST_TIMEOUT=1");
184 envp.push_back(0);
185
186 std::string Error;
187 bool ExecutionFailed;
188 int RetCode =
189 ExecuteAndWait(Executable, argv, &envp[0], 0, /*secondsToWait=*/1, 0,
190 &Error, &ExecutionFailed);
191 ASSERT_EQ(-2, RetCode);
192 }
193
164194 TEST(ProgramTest, TestExecuteNegative) {
165195 std::string Executable = "i_dont_exist";
166196 const char *argv[] = { Executable.c_str(), 0 };