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

Side by Side Diff: sandbox/linux/services/syscall_wrappers_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 | « sandbox/linux/services/syscall_wrappers.cc ('k') | no next file » | 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 "sandbox/linux/services/syscall_wrappers.h" 5 #include "sandbox/linux/services/syscall_wrappers.h"
6 6
7 #include <sys/syscall.h> 7 #include <sys/syscall.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <sys/wait.h> 9 #include <sys/wait.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 _exit(1); 53 _exit(1);
54 } 54 }
55 55
56 ASSERT_NE(-1, pid); 56 ASSERT_NE(-1, pid);
57 int status = 0; 57 int status = 0;
58 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); 58 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0)));
59 ASSERT_TRUE(WIFEXITED(status)); 59 ASSERT_TRUE(WIFEXITED(status));
60 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status)); 60 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status));
61 } 61 }
62 62
63 TEST(SyscallWrappers, ForkWithFlagsUpdatesPidCache) {
64 // The libc clone function, which allows ForkWithFlags to keep the pid cache
65 // up to date, does not work on Valgrind.
66 if (IsRunningOnValgrind()) {
67 return;
68 }
69
70 // Warm up the libc pid cache, if there is one.
71 ASSERT_EQ(sys_getpid(), getpid());
72
73 pid_t ctid = 0;
74 pid_t pid = ForkWithFlags(CLONE_CHILD_SETTID | SIGCHLD, nullptr, &ctid);
75
76 const int kSuccessExit = 0;
77 if (0 == pid) {
78 // In child. Check both the raw getpid syscall and the libc getpid wrapper
79 // (which may rely on a pid cache).
80 if (sys_getpid() == ctid && getpid() == ctid)
81 _exit(kSuccessExit);
82 _exit(1);
83 }
84
85 ASSERT_NE(-1, pid);
86 int status = 0;
87 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0)));
88 ASSERT_TRUE(WIFEXITED(status));
89 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status));
90 }
91
92 } // namespace 63 } // namespace
93 64
94 } // namespace sandbox 65 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/services/syscall_wrappers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698