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

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

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sandbox/linux/services/syscall_wrappers.h"
6
7 #include <sys/syscall.h>
8 #include <sys/types.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
11
12 #include "base/logging.h"
13 #include "base/posix/eintr_wrapper.h"
14 #include "build/build_config.h"
15 #include "sandbox/linux/tests/test_utils.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace sandbox {
19
20 namespace {
21
22 TEST(SyscallWrappers, BasicSyscalls) {
23 EXPECT_EQ(getpid(), sys_getpid());
24 }
25
26 TEST(SyscallWrappers, CloneBasic) {
27 pid_t child = sys_clone(SIGCHLD);
28 TestUtils::HandlePostForkReturn(child);
29 EXPECT_LT(0, child);
30 }
31
32 TEST(SyscallWrappers, CloneParentSettid) {
33 pid_t ptid = 0;
34 pid_t child = sys_clone(CLONE_PARENT_SETTID | SIGCHLD, nullptr, &ptid,
35 nullptr, nullptr);
36 TestUtils::HandlePostForkReturn(child);
37 EXPECT_LT(0, child);
38 EXPECT_EQ(child, ptid);
39 }
40
41 TEST(SyscallWrappers, CloneChildSettid) {
42 pid_t ctid = 0;
43 pid_t pid =
44 sys_clone(CLONE_CHILD_SETTID | SIGCHLD, nullptr, nullptr, &ctid, nullptr);
45
46 const int kSuccessExit = 0;
47 if (0 == pid) {
48 // In child.
49 if (sys_getpid() == ctid)
50 _exit(kSuccessExit);
51 _exit(1);
52 }
53
54 ASSERT_NE(-1, pid);
55 int status = 0;
56 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0)));
57 ASSERT_TRUE(WIFEXITED(status));
58 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status));
59 }
60
61 } // namespace
62
63 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/services/syscall_wrappers.cc ('k') | sandbox/linux/services/unix_domain_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698