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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 int* exit_code) { | 97 int* exit_code) { |
98 // Now we wait until the result is something other than STILL_RUNNING. | 98 // Now we wait until the result is something other than STILL_RUNNING. |
99 base::TerminationStatus status = base::TERMINATION_STATUS_STILL_RUNNING; | 99 base::TerminationStatus status = base::TERMINATION_STATUS_STILL_RUNNING; |
100 const base::TimeDelta kInterval = base::TimeDelta::FromMilliseconds(20); | 100 const base::TimeDelta kInterval = base::TimeDelta::FromMilliseconds(20); |
101 base::TimeDelta waited; | 101 base::TimeDelta waited; |
102 do { | 102 do { |
103 status = base::GetTerminationStatus(handle, exit_code); | 103 status = base::GetTerminationStatus(handle, exit_code); |
104 base::PlatformThread::Sleep(kInterval); | 104 base::PlatformThread::Sleep(kInterval); |
105 waited += kInterval; | 105 waited += kInterval; |
106 } while (status == base::TERMINATION_STATUS_STILL_RUNNING && | 106 } while (status == base::TERMINATION_STATUS_STILL_RUNNING && |
107 waited.InMilliseconds() < TestTimeouts::action_max_timeout_ms()); | 107 waited < TestTimeouts::action_max_timeout()); |
108 | 108 |
109 return status; | 109 return status; |
110 } | 110 } |
111 | 111 |
112 } // namespace | 112 } // namespace |
113 | 113 |
114 class ProcessUtilTest : public base::MultiProcessTest { | 114 class ProcessUtilTest : public base::MultiProcessTest { |
115 public: | 115 public: |
116 #if defined(OS_POSIX) | 116 #if defined(OS_POSIX) |
117 // Spawn a child process that counts how many file descriptors are open. | 117 // Spawn a child process that counts how many file descriptors are open. |
(...skipping 16 matching lines...) Expand all Loading... |
134 } | 134 } |
135 | 135 |
136 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { | 136 MULTIPROCESS_TEST_MAIN(SimpleChildProcess) { |
137 return 0; | 137 return 0; |
138 } | 138 } |
139 | 139 |
140 TEST_F(ProcessUtilTest, SpawnChild) { | 140 TEST_F(ProcessUtilTest, SpawnChild) { |
141 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false); | 141 base::ProcessHandle handle = this->SpawnChild("SimpleChildProcess", false); |
142 ASSERT_NE(base::kNullProcessHandle, handle); | 142 ASSERT_NE(base::kNullProcessHandle, handle); |
143 EXPECT_TRUE(base::WaitForSingleProcess( | 143 EXPECT_TRUE(base::WaitForSingleProcess( |
144 handle, TestTimeouts::action_max_timeout_ms())); | 144 handle, TestTimeouts::action_max_timeout())); |
145 base::CloseProcessHandle(handle); | 145 base::CloseProcessHandle(handle); |
146 } | 146 } |
147 | 147 |
148 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { | 148 MULTIPROCESS_TEST_MAIN(SlowChildProcess) { |
149 WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileSlow).c_str()); | 149 WaitToDie(ProcessUtilTest::GetSignalFilePath(kSignalFileSlow).c_str()); |
150 return 0; | 150 return 0; |
151 } | 151 } |
152 | 152 |
153 TEST_F(ProcessUtilTest, KillSlowChild) { | 153 TEST_F(ProcessUtilTest, KillSlowChild) { |
154 const std::string signal_file = | 154 const std::string signal_file = |
155 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); | 155 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); |
156 remove(signal_file.c_str()); | 156 remove(signal_file.c_str()); |
157 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); | 157 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); |
158 ASSERT_NE(base::kNullProcessHandle, handle); | 158 ASSERT_NE(base::kNullProcessHandle, handle); |
159 SignalChildren(signal_file.c_str()); | 159 SignalChildren(signal_file.c_str()); |
160 EXPECT_TRUE(base::WaitForSingleProcess( | 160 EXPECT_TRUE(base::WaitForSingleProcess( |
161 handle, TestTimeouts::action_max_timeout_ms())); | 161 handle, TestTimeouts::action_max_timeout())); |
162 base::CloseProcessHandle(handle); | 162 base::CloseProcessHandle(handle); |
163 remove(signal_file.c_str()); | 163 remove(signal_file.c_str()); |
164 } | 164 } |
165 | 165 |
166 // Times out on Linux and Win, flakes on other platforms, http://crbug.com/95058 | 166 // Times out on Linux and Win, flakes on other platforms, http://crbug.com/95058 |
167 TEST_F(ProcessUtilTest, DISABLED_GetTerminationStatusExit) { | 167 TEST_F(ProcessUtilTest, DISABLED_GetTerminationStatusExit) { |
168 const std::string signal_file = | 168 const std::string signal_file = |
169 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); | 169 ProcessUtilTest::GetSignalFilePath(kSignalFileSlow); |
170 remove(signal_file.c_str()); | 170 remove(signal_file.c_str()); |
171 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); | 171 base::ProcessHandle handle = this->SpawnChild("SlowChildProcess", false); |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 CHECK(handle); | 581 CHECK(handle); |
582 int ret = HANDLE_EINTR(close(fds[1])); | 582 int ret = HANDLE_EINTR(close(fds[1])); |
583 DPCHECK(ret == 0); | 583 DPCHECK(ret == 0); |
584 | 584 |
585 // Read number of open files in client process from pipe; | 585 // Read number of open files in client process from pipe; |
586 int num_open_files = -1; | 586 int num_open_files = -1; |
587 ssize_t bytes_read = | 587 ssize_t bytes_read = |
588 HANDLE_EINTR(read(fds[0], &num_open_files, sizeof(num_open_files))); | 588 HANDLE_EINTR(read(fds[0], &num_open_files, sizeof(num_open_files))); |
589 CHECK_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); | 589 CHECK_EQ(bytes_read, static_cast<ssize_t>(sizeof(num_open_files))); |
590 | 590 |
591 CHECK(base::WaitForSingleProcess(handle, 1000)); | 591 CHECK(base::WaitForSingleProcess(handle, base::TimeDelta::FromSeconds(1))); |
592 base::CloseProcessHandle(handle); | 592 base::CloseProcessHandle(handle); |
593 ret = HANDLE_EINTR(close(fds[0])); | 593 ret = HANDLE_EINTR(close(fds[0])); |
594 DPCHECK(ret == 0); | 594 DPCHECK(ret == 0); |
595 | 595 |
596 return num_open_files; | 596 return num_open_files; |
597 } | 597 } |
598 | 598 |
599 TEST_F(ProcessUtilTest, FDRemapping) { | 599 TEST_F(ProcessUtilTest, FDRemapping) { |
600 int fds_before = CountOpenFDsInChild(); | 600 int fds_before = CountOpenFDsInChild(); |
601 | 601 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 // we'll get a nice value for errno which we can test for. | 923 // we'll get a nice value for errno which we can test for. |
924 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); | 924 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); |
925 return result == -1 && errno == ECHILD; | 925 return result == -1 && errno == ECHILD; |
926 } | 926 } |
927 | 927 |
928 TEST_F(ProcessUtilTest, DelayedTermination) { | 928 TEST_F(ProcessUtilTest, DelayedTermination) { |
929 base::ProcessHandle child_process = | 929 base::ProcessHandle child_process = |
930 SpawnChild("process_util_test_never_die", false); | 930 SpawnChild("process_util_test_never_die", false); |
931 ASSERT_TRUE(child_process); | 931 ASSERT_TRUE(child_process); |
932 base::EnsureProcessTerminated(child_process); | 932 base::EnsureProcessTerminated(child_process); |
933 base::WaitForSingleProcess(child_process, 5000); | 933 base::WaitForSingleProcess(child_process, base::TimeDelta::FromSeconds(5)); |
934 | 934 |
935 // Check that process was really killed. | 935 // Check that process was really killed. |
936 EXPECT_TRUE(IsProcessDead(child_process)); | 936 EXPECT_TRUE(IsProcessDead(child_process)); |
937 base::CloseProcessHandle(child_process); | 937 base::CloseProcessHandle(child_process); |
938 } | 938 } |
939 | 939 |
940 MULTIPROCESS_TEST_MAIN(process_util_test_never_die) { | 940 MULTIPROCESS_TEST_MAIN(process_util_test_never_die) { |
941 while (1) { | 941 while (1) { |
942 sleep(500); | 942 sleep(500); |
943 } | 943 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 SetUpInDeathAssert(); | 1206 SetUpInDeathAssert(); |
1207 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 1207 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
1208 }, ""); | 1208 }, ""); |
1209 } | 1209 } |
1210 | 1210 |
1211 #endif // !ARCH_CPU_64_BITS | 1211 #endif // !ARCH_CPU_64_BITS |
1212 #endif // OS_MACOSX | 1212 #endif // OS_MACOSX |
1213 | 1213 |
1214 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && | 1214 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && |
1215 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) | 1215 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) |
OLD | NEW |