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

Side by Side Diff: sandbox/linux/services/syscall_wrappers_unittest.cc

Issue 801033002: Use the libc clone wrapper in sys_clone. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use macros from build_config.h Created 6 years 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 21 matching lines...) Expand all
32 TEST(SyscallWrappers, CloneParentSettid) { 32 TEST(SyscallWrappers, CloneParentSettid) {
33 pid_t ptid = 0; 33 pid_t ptid = 0;
34 pid_t child = sys_clone(CLONE_PARENT_SETTID | SIGCHLD, nullptr, &ptid, 34 pid_t child = sys_clone(CLONE_PARENT_SETTID | SIGCHLD, nullptr, &ptid,
35 nullptr, nullptr); 35 nullptr, nullptr);
36 TestUtils::HandlePostForkReturn(child); 36 TestUtils::HandlePostForkReturn(child);
37 EXPECT_LT(0, child); 37 EXPECT_LT(0, child);
38 EXPECT_EQ(child, ptid); 38 EXPECT_EQ(child, ptid);
39 } 39 }
40 40
41 TEST(SyscallWrappers, CloneChildSettid) { 41 TEST(SyscallWrappers, CloneChildSettid) {
42 // Warm up the libc pid cache, if there is one.
43 ASSERT_EQ(sys_getpid(), getpid());
44
42 pid_t ctid = 0; 45 pid_t ctid = 0;
43 pid_t pid = 46 pid_t pid =
44 sys_clone(CLONE_CHILD_SETTID | SIGCHLD, nullptr, nullptr, &ctid, nullptr); 47 sys_clone(CLONE_CHILD_SETTID | SIGCHLD, nullptr, nullptr, &ctid, nullptr);
45 48
46 const int kSuccessExit = 0; 49 const int kSuccessExit = 0;
47 if (0 == pid) { 50 if (0 == pid) {
48 // In child. 51 // In child. Check both the raw getpid syscall and the libc getpid wrapper
49 if (sys_getpid() == ctid) 52 // (which may rely on a pid cache).
53 if (sys_getpid() == ctid && getpid() == ctid)
50 _exit(kSuccessExit); 54 _exit(kSuccessExit);
51 _exit(1); 55 _exit(1);
52 } 56 }
53 57
54 ASSERT_NE(-1, pid); 58 ASSERT_NE(-1, pid);
55 int status = 0; 59 int status = 0;
56 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); 60 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0)));
57 ASSERT_TRUE(WIFEXITED(status)); 61 ASSERT_TRUE(WIFEXITED(status));
58 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status)); 62 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status));
59 } 63 }
60 64
61 } // namespace 65 } // namespace
62 66
63 } // namespace sandbox 67 } // 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