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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 ASSERT_TRUE(process.IsValid()); | 116 ASSERT_TRUE(process.IsValid()); |
117 | 117 |
118 const int kDummyExitCode = 42; | 118 const int kDummyExitCode = 42; |
119 int exit_code = kDummyExitCode; | 119 int exit_code = kDummyExitCode; |
120 EXPECT_EQ(TERMINATION_STATUS_STILL_RUNNING, | 120 EXPECT_EQ(TERMINATION_STATUS_STILL_RUNNING, |
121 GetTerminationStatus(process.Handle(), &exit_code)); | 121 GetTerminationStatus(process.Handle(), &exit_code)); |
122 EXPECT_EQ(kExpectedStillRunningExitCode, exit_code); | 122 EXPECT_EQ(kExpectedStillRunningExitCode, exit_code); |
123 | 123 |
124 exit_code = kDummyExitCode; | 124 exit_code = kDummyExitCode; |
125 int kExpectedExitCode = 250; | 125 int kExpectedExitCode = 250; |
126 process.Terminate(kExpectedExitCode); | 126 process.Terminate(kExpectedExitCode, false); |
127 process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), | 127 process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), |
128 &exit_code); | 128 &exit_code); |
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 } |
(...skipping 16 matching lines...) Expand all Loading... |
153 TEST_F(ProcessTest, WaitForExitWithTimeout) { | 153 TEST_F(ProcessTest, WaitForExitWithTimeout) { |
154 Process process(SpawnChild("SleepyChildProcess")); | 154 Process process(SpawnChild("SleepyChildProcess")); |
155 ASSERT_TRUE(process.IsValid()); | 155 ASSERT_TRUE(process.IsValid()); |
156 | 156 |
157 const int kDummyExitCode = 42; | 157 const int kDummyExitCode = 42; |
158 int exit_code = kDummyExitCode; | 158 int exit_code = kDummyExitCode; |
159 TimeDelta timeout = TestTimeouts::tiny_timeout(); | 159 TimeDelta timeout = TestTimeouts::tiny_timeout(); |
160 EXPECT_FALSE(process.WaitForExitWithTimeout(timeout, &exit_code)); | 160 EXPECT_FALSE(process.WaitForExitWithTimeout(timeout, &exit_code)); |
161 EXPECT_EQ(kDummyExitCode, exit_code); | 161 EXPECT_EQ(kDummyExitCode, exit_code); |
162 | 162 |
163 process.Terminate(kDummyExitCode); | 163 process.Terminate(kDummyExitCode, false); |
164 } | 164 } |
165 | 165 |
166 // Ensure that the priority of a process is restored correctly after | 166 // Ensure that the priority of a process is restored correctly after |
167 // backgrounding and restoring. | 167 // backgrounding and restoring. |
168 // 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 |
169 // a process. The calls to SetProcessBackground should be noops then. | 169 // a process. The calls to SetProcessBackground should be noops then. |
170 TEST_F(ProcessTest, SetProcessBackgrounded) { | 170 TEST_F(ProcessTest, SetProcessBackgrounded) { |
171 Process process(SpawnChild("SimpleChildProcess")); | 171 Process process(SpawnChild("SimpleChildProcess")); |
172 int old_priority = process.GetPriority(); | 172 int old_priority = process.GetPriority(); |
173 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
(...skipping 21 matching lines...) Expand all Loading... |
195 EXPECT_FALSE(process.IsProcessBackgrounded()); | 195 EXPECT_FALSE(process.IsProcessBackgrounded()); |
196 #else | 196 #else |
197 process.SetProcessBackgrounded(true); | 197 process.SetProcessBackgrounded(true); |
198 process.SetProcessBackgrounded(false); | 198 process.SetProcessBackgrounded(false); |
199 #endif | 199 #endif |
200 int new_priority = process.GetPriority(); | 200 int new_priority = process.GetPriority(); |
201 EXPECT_EQ(old_priority, new_priority); | 201 EXPECT_EQ(old_priority, new_priority); |
202 } | 202 } |
203 | 203 |
204 } // namespace base | 204 } // namespace base |
OLD | NEW |