X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FSupport%2FProgramTest.cpp;h=4e7316fb3ace5f3f37ac9642e1cf51f6ba325075;hb=d52e9a143f254be7ac1f2e648f3c3dbe278f4711;hp=800df14234d3af8006f8868cf07ee9b1dfe1520d;hpb=974a445bd90795248274493eda5cdbf6721910f7;p=oota-llvm.git diff --git a/unittests/Support/ProgramTest.cpp b/unittests/Support/ProgramTest.cpp index 800df14234d..4e7316fb3ac 100644 --- a/unittests/Support/ProgramTest.cpp +++ b/unittests/Support/ProgramTest.cpp @@ -54,7 +54,7 @@ static void CopyEnvironment(std::vector &out) { // environ seems to work for Windows and most other Unices. char **envp = environ; #endif - while (*envp != 0) { + while (*envp != nullptr) { out.push_back(*envp); ++envp; } @@ -76,14 +76,14 @@ TEST(ProgramTest, CreateProcessTrailingSlash) { "--gtest_filter=ProgramTest.CreateProcessTrailingSlash", "-program-test-string-arg1", "has\\\\ trailing\\", "-program-test-string-arg2", "has\\\\ trailing\\", - 0 + nullptr }; // Add LLVM_PROGRAM_TEST_CHILD to the environment of the child. std::vector envp; CopyEnvironment(envp); envp.push_back("LLVM_PROGRAM_TEST_CHILD=1"); - envp.push_back(0); + envp.push_back(nullptr); std::string error; bool ExecutionFailed; @@ -93,7 +93,7 @@ TEST(ProgramTest, CreateProcessTrailingSlash) { #else StringRef nul("/dev/null"); #endif - const StringRef *redirects[] = { &nul, &nul, 0 }; + const StringRef *redirects[] = { &nul, &nul, nullptr }; int rc = ExecuteAndWait(my_exe, argv, &envp[0], redirects, /*secondsToWait=*/ 10, /*memoryLimit=*/ 0, &error, &ExecutionFailed); @@ -114,19 +114,19 @@ TEST(ProgramTest, TestExecuteNoWait) { const char *argv[] = { Executable.c_str(), "--gtest_filter=ProgramTest.TestExecuteNoWait", - 0 + nullptr }; // Add LLVM_PROGRAM_TEST_EXECUTE_NO_WAIT to the environment of the child. std::vector envp; CopyEnvironment(envp); envp.push_back("LLVM_PROGRAM_TEST_EXECUTE_NO_WAIT=1"); - envp.push_back(0); + envp.push_back(nullptr); std::string Error; bool ExecutionFailed; - ProcessInfo PI1 = - ExecuteNoWait(Executable, argv, &envp[0], 0, 0, &Error, &ExecutionFailed); + ProcessInfo PI1 = ExecuteNoWait(Executable, argv, &envp[0], nullptr, 0, + &Error, &ExecutionFailed); ASSERT_FALSE(ExecutionFailed) << Error; ASSERT_NE(PI1.Pid, 0) << "Invalid process id"; @@ -144,8 +144,8 @@ TEST(ProgramTest, TestExecuteNoWait) { EXPECT_EQ(LoopCount, 1u) << "LoopCount should be 1"; - ProcessInfo PI2 = - ExecuteNoWait(Executable, argv, &envp[0], 0, 0, &Error, &ExecutionFailed); + ProcessInfo PI2 = ExecuteNoWait(Executable, argv, &envp[0], nullptr, 0, + &Error, &ExecutionFailed); ASSERT_FALSE(ExecutionFailed) << Error; ASSERT_NE(PI2.Pid, 0) << "Invalid process id"; @@ -162,15 +162,45 @@ 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", + nullptr + }; + + // 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(nullptr); + + std::string Error; + bool ExecutionFailed; + int RetCode = + ExecuteAndWait(Executable, argv, &envp[0], nullptr, /*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 }; + const char *argv[] = { Executable.c_str(), nullptr }; { std::string Error; bool ExecutionFailed; - int RetCode = - ExecuteAndWait(Executable, argv, 0, 0, 0, 0, &Error, &ExecutionFailed); + int RetCode = ExecuteAndWait(Executable, argv, nullptr, nullptr, 0, 0, + &Error, &ExecutionFailed); ASSERT_TRUE(RetCode < 0) << "On error ExecuteAndWait should return 0 or " "positive value indicating the result code"; ASSERT_TRUE(ExecutionFailed); @@ -180,8 +210,8 @@ TEST(ProgramTest, TestExecuteNegative) { { std::string Error; bool ExecutionFailed; - ProcessInfo PI = - ExecuteNoWait(Executable, argv, 0, 0, 0, &Error, &ExecutionFailed); + ProcessInfo PI = ExecuteNoWait(Executable, argv, nullptr, nullptr, 0, + &Error, &ExecutionFailed); ASSERT_EQ(PI.Pid, 0) << "On error ExecuteNoWait should return an invalid ProcessInfo"; ASSERT_TRUE(ExecutionFailed);