Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: base/process/process_unittest.cc

Issue 831373002: Move ForkWithFlags from sandbox/ to base/ and plug it into LaunchProcess. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/process_linux.cc ('k') | base/process/process_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
12 #include "build/build_config.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/multiprocess_func_list.h" 14 #include "testing/multiprocess_func_list.h"
13 15
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
14 22
15 namespace { 23 namespace {
16 24
17 #if defined(OS_WIN) 25 #if defined(OS_WIN)
18 const int kExpectedStillRunningExitCode = 0x102; 26 const int kExpectedStillRunningExitCode = 0x102;
19 #else 27 #else
20 const int kExpectedStillRunningExitCode = 0; 28 const int kExpectedStillRunningExitCode = 0;
21 #endif 29 #endif
22 30
23 } // namespace 31 } // namespace
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EXPECT_TRUE(process.SetProcessBackgrounded(false)); 202 EXPECT_TRUE(process.SetProcessBackgrounded(false));
195 EXPECT_FALSE(process.IsProcessBackgrounded()); 203 EXPECT_FALSE(process.IsProcessBackgrounded());
196 #else 204 #else
197 process.SetProcessBackgrounded(true); 205 process.SetProcessBackgrounded(true);
198 process.SetProcessBackgrounded(false); 206 process.SetProcessBackgrounded(false);
199 #endif 207 #endif
200 int new_priority = process.GetPriority(); 208 int new_priority = process.GetPriority();
201 EXPECT_EQ(old_priority, new_priority); 209 EXPECT_EQ(old_priority, new_priority);
202 } 210 }
203 211
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
204 } // namespace base 249 } // namespace base
OLDNEW
« no previous file with comments | « base/process/process_linux.cc ('k') | base/process/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698