OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "base/process/process.h" | 5 #include "base/process/process.h" |
6 | 6 |
7 #include "base/process/kill.h" | 7 #include "base/process/kill.h" |
8 #include "base/test/multiprocess_test.h" | 8 #include "base/test/multiprocess_test.h" |
9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 WaitForSingleProcess(process.Handle(), TestTimeouts::action_max_timeout()); | 128 WaitForSingleProcess(process.Handle(), TestTimeouts::action_max_timeout()); |
129 | 129 |
130 EXPECT_NE(TERMINATION_STATUS_STILL_RUNNING, | 130 EXPECT_NE(TERMINATION_STATUS_STILL_RUNNING, |
131 GetTerminationStatus(process.Handle(), &exit_code)); | 131 GetTerminationStatus(process.Handle(), &exit_code)); |
132 #if !defined(OS_POSIX) | 132 #if !defined(OS_POSIX) |
133 // The POSIX implementation actually ignores the exit_code. | 133 // The POSIX implementation actually ignores the exit_code. |
134 EXPECT_EQ(kExpectedExitCode, exit_code); | 134 EXPECT_EQ(kExpectedExitCode, exit_code); |
135 #endif | 135 #endif |
136 } | 136 } |
137 | 137 |
| 138 MULTIPROCESS_TEST_MAIN(FastSleepyChildProcess) { |
| 139 PlatformThread::Sleep(TestTimeouts::tiny_timeout() * 10); |
| 140 return 0; |
| 141 } |
| 142 |
| 143 TEST_F(ProcessTest, WaitForExit) { |
| 144 Process process(SpawnChild("FastSleepyChildProcess")); |
| 145 ASSERT_TRUE(process.IsValid()); |
| 146 |
| 147 const int kDummyExitCode = 42; |
| 148 int exit_code = kDummyExitCode; |
| 149 EXPECT_TRUE(process.WaitForExit(&exit_code)); |
| 150 EXPECT_EQ(0, exit_code); |
| 151 } |
| 152 |
| 153 TEST_F(ProcessTest, WaitForExitWithTimeout) { |
| 154 Process process(SpawnChild("SleepyChildProcess")); |
| 155 ASSERT_TRUE(process.IsValid()); |
| 156 |
| 157 const int kDummyExitCode = 42; |
| 158 int exit_code = kDummyExitCode; |
| 159 TimeDelta timeout = TestTimeouts::tiny_timeout(); |
| 160 EXPECT_FALSE(process.WaitForExitWithTimeout(timeout, &exit_code)); |
| 161 EXPECT_EQ(kDummyExitCode, exit_code); |
| 162 |
| 163 process.Terminate(kDummyExitCode); |
| 164 } |
| 165 |
138 // Ensure that the priority of a process is restored correctly after | 166 // Ensure that the priority of a process is restored correctly after |
139 // backgrounding and restoring. | 167 // backgrounding and restoring. |
140 // Note: a platform may not be willing or able to lower the priority of | 168 // Note: a platform may not be willing or able to lower the priority of |
141 // a process. The calls to SetProcessBackground should be noops then. | 169 // a process. The calls to SetProcessBackground should be noops then. |
142 TEST_F(ProcessTest, SetProcessBackgrounded) { | 170 TEST_F(ProcessTest, SetProcessBackgrounded) { |
143 Process process(SpawnChild("SimpleChildProcess")); | 171 Process process(SpawnChild("SimpleChildProcess")); |
144 int old_priority = process.GetPriority(); | 172 int old_priority = process.GetPriority(); |
145 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
146 EXPECT_TRUE(process.SetProcessBackgrounded(true)); | 174 EXPECT_TRUE(process.SetProcessBackgrounded(true)); |
147 EXPECT_TRUE(process.IsProcessBackgrounded()); | 175 EXPECT_TRUE(process.IsProcessBackgrounded()); |
(...skipping 19 matching lines...) Expand all Loading... |
167 EXPECT_FALSE(process.IsProcessBackgrounded()); | 195 EXPECT_FALSE(process.IsProcessBackgrounded()); |
168 #else | 196 #else |
169 process.SetProcessBackgrounded(true); | 197 process.SetProcessBackgrounded(true); |
170 process.SetProcessBackgrounded(false); | 198 process.SetProcessBackgrounded(false); |
171 #endif | 199 #endif |
172 int new_priority = process.GetPriority(); | 200 int new_priority = process.GetPriority(); |
173 EXPECT_EQ(old_priority, new_priority); | 201 EXPECT_EQ(old_priority, new_priority); |
174 } | 202 } |
175 | 203 |
176 } // namespace base | 204 } // namespace base |
OLD | NEW |