| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 144 } |
| 145 | 145 |
| 146 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { | 146 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { |
| 147 return 0; | 147 return 0; |
| 148 } | 148 } |
| 149 | 149 |
| 150 // TODO(viettrungluu): This should be in a "MultiProcessTestTest". | 150 // TODO(viettrungluu): This should be in a "MultiProcessTestTest". |
| 151 TEST_F(ProcessUtilTest, SpawnChild) { | 151 TEST_F(ProcessUtilTest, SpawnChild) { |
| 152 base::Process process = SpawnChild("SimpleChildProcess"); | 152 base::Process process = SpawnChild("SimpleChildProcess"); |
| 153 ASSERT_TRUE(process.IsValid()); | 153 ASSERT_TRUE(process.IsValid()); |
| 154 EXPECT_TRUE(base::WaitForSingleProcess(process.Handle(), | 154 int exit_code; |
| 155 TestTimeouts::action_max_timeout())); | 155 EXPECT_TRUE(process.WaitForExitWithTimeout( |
| 156 TestTimeouts::action_max_timeout(), &exit_code)); |
| 156 } | 157 } |
| 157 | 158 |
| 158 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { | 159 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { |
| 159 WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileSlow).c_str()); | 160 WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileSlow).c_str()); |
| 160 return 0; | 161 return 0; |
| 161 } | 162 } |
| 162 | 163 |
| 163 TEST_F(ProcessUtilTest, KillSlowChild) { | 164 TEST_F(ProcessUtilTest, KillSlowChild) { |
| 164 const std::string signal_file = | 165 const std::string signal_file = |
| 165 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); | 166 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); |
| 166 remove(signal_file.c_str()); | 167 remove(signal_file.c_str()); |
| 167 base::Process process = SpawnChild("SlowChildProcess"); | 168 base::Process process = SpawnChild("SlowChildProcess"); |
| 168 ASSERT_TRUE(process.IsValid()); | 169 ASSERT_TRUE(process.IsValid()); |
| 169 SignalChildren(signal_file.c_str()); | 170 SignalChildren(signal_file.c_str()); |
| 170 EXPECT_TRUE(base::WaitForSingleProcess(process.Handle(), | 171 int exit_code; |
| 171 TestTimeouts::action_max_timeout())); | 172 EXPECT_TRUE(process.WaitForExitWithTimeout( |
| 173 TestTimeouts::action_max_timeout(), &exit_code)); |
| 172 remove(signal_file.c_str()); | 174 remove(signal_file.c_str()); |
| 173 } | 175 } |
| 174 | 176 |
| 175 // Times out on Linux and Win, flakes on other platforms, http://crbug.com/95058 | 177 // Times out on Linux and Win, flakes on other platforms, http://crbug.com/95058 |
| 176 TEST_F(ProcessUtilTest, DISABLED_GetTerminationStatusExit) { | 178 TEST_F(ProcessUtilTest, DISABLED_GetTerminationStatusExit) { |
| 177 const std::string signal_file = | 179 const std::string signal_file = |
| 178 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); | 180 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); |
| 179 remove(signal_file.c_str()); | 181 remove(signal_file.c_str()); |
| 180 base::Process process = SpawnChild("SlowChildProcess"); | 182 base::Process process = SpawnChild("SlowChildProcess"); |
| 181 ASSERT_TRUE(process.IsValid()); | 183 ASSERT_TRUE(process.IsValid()); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 DPCHECK(ret == 0); | 545 DPCHECK(ret == 0); |
| 544 | 546 |
| 545 // Read number of open files in client process from pipe; | 547 // Read number of open files in client process from pipe; |
| 546 int num_open_files = -1; | 548 int num_open_files = -1; |
| 547 ssize_t bytes_read = | 549 ssize_t bytes_read = |
| 548 HANDLE_EINTR(read(fds[0], &num_open_files, sizeof(num_open_files))); | 550 HANDLE_EINTR(read(fds[0], &num_open_files, sizeof(num_open_files))); |
| 549 CHECK_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); | 551 CHECK_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); |
| 550 | 552 |
| 551 #if defined(THREAD_SANITIZER) | 553 #if defined(THREAD_SANITIZER) |
| 552 // Compiler-based ThreadSanitizer makes this test slow. | 554 // Compiler-based ThreadSanitizer makes this test slow. |
| 553 CHECK(base::WaitForSingleProcess(process.Handle(), | 555 base::TimeDelta timeout = base::TimeDelta::FromSeconds(3); |
| 554 base::TimeDelta::FromSeconds(3))); | |
| 555 #else | 556 #else |
| 556 CHECK(base::WaitForSingleProcess(process.Handle(), | 557 base::TimeDelta timeout = base::TimeDelta::FromSeconds(1); |
| 557 base::TimeDelta::FromSeconds(1))); | |
| 558 #endif | 558 #endif |
| 559 int exit_code; |
| 560 CHECK(process.WaitForExitWithTimeout(timeout, &exit_code)); |
| 559 ret = IGNORE_EINTR(close(fds[0])); | 561 ret = IGNORE_EINTR(close(fds[0])); |
| 560 DPCHECK(ret == 0); | 562 DPCHECK(ret == 0); |
| 561 | 563 |
| 562 return num_open_files; | 564 return num_open_files; |
| 563 } | 565 } |
| 564 | 566 |
| 565 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) | 567 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) |
| 566 // ProcessUtilTest.FDRemapping is flaky when ran under xvfb-run on Precise. | 568 // ProcessUtilTest.FDRemapping is flaky when ran under xvfb-run on Precise. |
| 567 // The problem is 100% reproducible with both ASan and TSan. | 569 // The problem is 100% reproducible with both ASan and TSan. |
| 568 // See http://crbug.com/136720. | 570 // See http://crbug.com/136720. |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 // want to test for. The good thing is that if it can't find the process | 886 // want to test for. The good thing is that if it can't find the process |
| 885 // we'll get a nice value for errno which we can test for. | 887 // we'll get a nice value for errno which we can test for. |
| 886 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); | 888 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); |
| 887 return result == -1 && errno == ECHILD; | 889 return result == -1 && errno == ECHILD; |
| 888 } | 890 } |
| 889 | 891 |
| 890 TEST_F(ProcessUtilTest, DelayedTermination) { | 892 TEST_F(ProcessUtilTest, DelayedTermination) { |
| 891 base::Process child_process = SpawnChild("process_util_test_never_die"); | 893 base::Process child_process = SpawnChild("process_util_test_never_die"); |
| 892 ASSERT_TRUE(child_process.IsValid()); | 894 ASSERT_TRUE(child_process.IsValid()); |
| 893 base::EnsureProcessTerminated(child_process.Duplicate()); | 895 base::EnsureProcessTerminated(child_process.Duplicate()); |
| 894 base::WaitForSingleProcess(child_process.Handle(), | 896 int exit_code; |
| 895 base::TimeDelta::FromSeconds(5)); | 897 child_process.WaitForExitWithTimeout(base::TimeDelta::FromSeconds(5), |
| 898 &exit_code); |
| 896 | 899 |
| 897 // Check that process was really killed. | 900 // Check that process was really killed. |
| 898 EXPECT_TRUE(IsProcessDead(child_process.Handle())); | 901 EXPECT_TRUE(IsProcessDead(child_process.Handle())); |
| 899 } | 902 } |
| 900 | 903 |
| 901 MULTIPROCESS_TEST_MAIN(process_util_test_never_die) { | 904 MULTIPROCESS_TEST_MAIN(process_util_test_never_die) { |
| 902 while (1) { | 905 while (1) { |
| 903 sleep(500); | 906 sleep(500); |
| 904 } | 907 } |
| 905 return 0; | 908 return 0; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 options.current_directory = base::FilePath("/dev/null"); | 1058 options.current_directory = base::FilePath("/dev/null"); |
| 1056 | 1059 |
| 1057 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options)); | 1060 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options)); |
| 1058 ASSERT_TRUE(process.IsValid()); | 1061 ASSERT_TRUE(process.IsValid()); |
| 1059 | 1062 |
| 1060 int exit_code = kSuccess; | 1063 int exit_code = kSuccess; |
| 1061 EXPECT_TRUE(process.WaitForExit(&exit_code)); | 1064 EXPECT_TRUE(process.WaitForExit(&exit_code)); |
| 1062 EXPECT_NE(kSuccess, exit_code); | 1065 EXPECT_NE(kSuccess, exit_code); |
| 1063 } | 1066 } |
| 1064 #endif | 1067 #endif |
| OLD | NEW |