| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/at_exit.h" |
| 9 #include "base/process/kill.h" | 10 #include "base/process/kill.h" |
| 10 #include "base/test/multiprocess_test.h" | 11 #include "base/test/multiprocess_test.h" |
| 11 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 12 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "base/threading/thread_local.h" |
| 13 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/multiprocess_func_list.h" | 17 #include "testing/multiprocess_func_list.h" |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 20 const int kExpectedStillRunningExitCode = 0x102; | 22 const int kExpectedStillRunningExitCode = 0x102; |
| 21 #else | 23 #else |
| 22 const int kExpectedStillRunningExitCode = 0; | 24 const int kExpectedStillRunningExitCode = 0; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 &exit_code); | 143 &exit_code); |
| 142 | 144 |
| 143 EXPECT_NE(TERMINATION_STATUS_STILL_RUNNING, | 145 EXPECT_NE(TERMINATION_STATUS_STILL_RUNNING, |
| 144 GetTerminationStatus(process.Handle(), &exit_code)); | 146 GetTerminationStatus(process.Handle(), &exit_code)); |
| 145 #if !defined(OS_POSIX) | 147 #if !defined(OS_POSIX) |
| 146 // The POSIX implementation actually ignores the exit_code. | 148 // The POSIX implementation actually ignores the exit_code. |
| 147 EXPECT_EQ(kExpectedExitCode, exit_code); | 149 EXPECT_EQ(kExpectedExitCode, exit_code); |
| 148 #endif | 150 #endif |
| 149 } | 151 } |
| 150 | 152 |
| 153 void AtExitHandler(void*) { |
| 154 // At-exit handler should not be called at |
| 155 // Process::TerminateCurrentProcessImmediately. |
| 156 DCHECK(false); |
| 157 } |
| 158 |
| 159 class ThreadLocalObject { |
| 160 ~ThreadLocalObject() { |
| 161 // Thread-local storage should not be destructed at |
| 162 // Process::TerminateCurrentProcessImmediately. |
| 163 DCHECK(false); |
| 164 } |
| 165 }; |
| 166 |
| 167 MULTIPROCESS_TEST_MAIN(TerminateCurrentProcessImmediatelyWithCode0) { |
| 168 base::ThreadLocalPointer<ThreadLocalObject> object; |
| 169 base::AtExitManager::RegisterCallback(&AtExitHandler, NULL); |
| 170 Process::TerminateCurrentProcessImmediately(0); |
| 171 NOTREACHED(); |
| 172 return 42; |
| 173 } |
| 174 |
| 175 TEST_F(ProcessTest, TerminateCurrentProcessImmediatelyWithZeroExitCode) { |
| 176 Process process(SpawnChild("TerminateCurrentProcessImmediatelyWithCode0")); |
| 177 ASSERT_TRUE(process.IsValid()); |
| 178 int exit_code = 42; |
| 179 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), |
| 180 &exit_code)); |
| 181 EXPECT_EQ(0, exit_code); |
| 182 } |
| 183 |
| 184 MULTIPROCESS_TEST_MAIN(TerminateCurrentProcessImmediatelyWithCode250) { |
| 185 Process::TerminateCurrentProcessImmediately(250); |
| 186 NOTREACHED(); |
| 187 return 42; |
| 188 } |
| 189 |
| 190 TEST_F(ProcessTest, TerminateCurrentProcessImmediatelyWithNonZeroExitCode) { |
| 191 Process process(SpawnChild("TerminateCurrentProcessImmediatelyWithCode250")); |
| 192 ASSERT_TRUE(process.IsValid()); |
| 193 int exit_code = 42; |
| 194 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), |
| 195 &exit_code)); |
| 196 EXPECT_EQ(250, exit_code); |
| 197 } |
| 198 |
| 151 MULTIPROCESS_TEST_MAIN(FastSleepyChildProcess) { | 199 MULTIPROCESS_TEST_MAIN(FastSleepyChildProcess) { |
| 152 PlatformThread::Sleep(TestTimeouts::tiny_timeout() * 10); | 200 PlatformThread::Sleep(TestTimeouts::tiny_timeout() * 10); |
| 153 return 0; | 201 return 0; |
| 154 } | 202 } |
| 155 | 203 |
| 156 TEST_F(ProcessTest, WaitForExit) { | 204 TEST_F(ProcessTest, WaitForExit) { |
| 157 Process process(SpawnChild("FastSleepyChildProcess")); | 205 Process process(SpawnChild("FastSleepyChildProcess")); |
| 158 ASSERT_TRUE(process.IsValid()); | 206 ASSERT_TRUE(process.IsValid()); |
| 159 | 207 |
| 160 const int kDummyExitCode = 42; | 208 const int kDummyExitCode = 42; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 "2:freezer:/chrome_renderers/to_be_frozen\n" | 295 "2:freezer:/chrome_renderers/to_be_frozen\n" |
| 248 "1:cpu:/chrome_renderers/background\n"; | 296 "1:cpu:/chrome_renderers/background\n"; |
| 249 | 297 |
| 250 EXPECT_FALSE(IsProcessBackgroundedCGroup(kNotBackgrounded)); | 298 EXPECT_FALSE(IsProcessBackgroundedCGroup(kNotBackgrounded)); |
| 251 EXPECT_TRUE(IsProcessBackgroundedCGroup(kBackgrounded)); | 299 EXPECT_TRUE(IsProcessBackgroundedCGroup(kBackgrounded)); |
| 252 } | 300 } |
| 253 | 301 |
| 254 #endif // defined(OS_CHROMEOS) | 302 #endif // defined(OS_CHROMEOS) |
| 255 | 303 |
| 256 } // namespace base | 304 } // namespace base |
| OLD | NEW |