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/third_party/dynamic_annotations/dynamic_annotations.h" | |
11 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
12 #include "build/build_config.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "testing/multiprocess_func_list.h" | 12 #include "testing/multiprocess_func_list.h" |
15 | 13 |
16 #if defined(OS_LINUX) | |
17 #include <errno.h> | |
18 #include <sys/syscall.h> | |
19 #include <sys/types.h> | |
20 #include <unistd.h> | |
21 #endif | |
22 | 14 |
23 namespace { | 15 namespace { |
24 | 16 |
25 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
26 const int kExpectedStillRunningExitCode = 0x102; | 18 const int kExpectedStillRunningExitCode = 0x102; |
27 #else | 19 #else |
28 const int kExpectedStillRunningExitCode = 0; | 20 const int kExpectedStillRunningExitCode = 0; |
29 #endif | 21 #endif |
30 | 22 |
31 } // namespace | 23 } // namespace |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 EXPECT_TRUE(process.SetProcessBackgrounded(false)); | 194 EXPECT_TRUE(process.SetProcessBackgrounded(false)); |
203 EXPECT_FALSE(process.IsProcessBackgrounded()); | 195 EXPECT_FALSE(process.IsProcessBackgrounded()); |
204 #else | 196 #else |
205 process.SetProcessBackgrounded(true); | 197 process.SetProcessBackgrounded(true); |
206 process.SetProcessBackgrounded(false); | 198 process.SetProcessBackgrounded(false); |
207 #endif | 199 #endif |
208 int new_priority = process.GetPriority(); | 200 int new_priority = process.GetPriority(); |
209 EXPECT_EQ(old_priority, new_priority); | 201 EXPECT_EQ(old_priority, new_priority); |
210 } | 202 } |
211 | 203 |
212 #if defined(OS_LINUX) | |
213 const int kSuccess = 0; | |
214 const int kFail = 1; | |
215 | |
216 MULTIPROCESS_TEST_MAIN(CheckPidProcess) { | |
217 const pid_t kInitPid = 1; | |
218 const pid_t pid = syscall(__NR_getpid); | |
219 if (pid != kInitPid) { | |
220 return kFail; | |
221 } | |
222 | |
223 if (!RunningOnValgrind() && getpid() != pid) { | |
224 return kFail; | |
225 } | |
226 | |
227 return kSuccess; | |
228 } | |
229 | |
230 TEST_F(ProcessTest, CloneFlags) { | |
231 LaunchOptions options; | |
232 options.clone_flags = CLONE_NEWUSER | CLONE_NEWPID | CLONE_NEWNET; | |
233 | |
234 const ProcessHandle proc = SpawnChildWithOptions("CheckPidProcess", options); | |
235 if (proc == kNullProcessHandle && errno == EINVAL) { | |
236 // Some of the namespace types are not supported. | |
237 return; | |
238 } | |
239 | |
240 Process process(proc); | |
241 ASSERT_TRUE(process.IsValid()); | |
242 | |
243 int exit_code = kFail; | |
244 EXPECT_TRUE(process.WaitForExit(&exit_code)); | |
245 EXPECT_EQ(kSuccess, exit_code); | |
246 } | |
247 #endif | |
248 | |
249 } // namespace base | 204 } // namespace base |
OLD | NEW |