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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_unittest.cc
diff --git a/base/process/process_unittest.cc b/base/process/process_unittest.cc
index 5180f64c55a8111a5db6456570d1ac4d38f2776e..c2726d8f539f877f5a14f2571cfdc65adfc03166 100644
--- a/base/process/process_unittest.cc
+++ b/base/process/process_unittest.cc
@@ -7,10 +7,18 @@
#include "base/process/kill.h"
#include "base/test/multiprocess_test.h"
#include "base/test/test_timeouts.h"
+#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/platform_thread.h"
+#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
+#if defined(OS_LINUX)
+#include <errno.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+#endif
namespace {
@@ -201,4 +209,41 @@ TEST_F(ProcessTest, SetProcessBackgroundedSelf) {
EXPECT_EQ(old_priority, new_priority);
}
+#if defined(OS_LINUX)
+const int kSuccess = 0;
+const int kFail = 1;
+
+MULTIPROCESS_TEST_MAIN(CheckPidProcess) {
+ const pid_t kInitPid = 1;
+ const pid_t pid = syscall(__NR_getpid);
+ if (pid != kInitPid) {
+ return kFail;
+ }
+
+ if (!RunningOnValgrind() && getpid() != pid) {
+ return kFail;
+ }
+
+ return kSuccess;
+}
+
+TEST_F(ProcessTest, CloneFlags) {
+ LaunchOptions options;
+ options.clone_flags = CLONE_NEWUSER | CLONE_NEWPID | CLONE_NEWNET;
+
+ const ProcessHandle proc = SpawnChildWithOptions("CheckPidProcess", options);
+ if (proc == kNullProcessHandle && errno == EINVAL) {
+ // Some of the namespace types are not supported.
+ return;
+ }
+
+ Process process(proc);
+ ASSERT_TRUE(process.IsValid());
+
+ int exit_code = kFail;
+ EXPECT_TRUE(process.WaitForExit(&exit_code));
+ EXPECT_EQ(kSuccess, exit_code);
+}
+#endif
+
} // namespace base
« 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