Revert of Reland: Introduce sys_sigprocmask and sys_sigaction. (patchset #5 id:160001...
[chromium-blink-merge.git] / sandbox / linux / services / syscall_wrappers_unittest.cc
blob6a70beb673bcefe62b0bdd2bb98d741b5b7e4c54
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.
5 #include "sandbox/linux/services/syscall_wrappers.h"
7 #include <sys/syscall.h>
8 #include <sys/types.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
12 #include "base/logging.h"
13 #include "base/posix/eintr_wrapper.h"
14 #include "base/third_party/valgrind/valgrind.h"
15 #include "build/build_config.h"
16 #include "sandbox/linux/tests/test_utils.h"
17 #include "sandbox/linux/tests/unit_tests.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 namespace sandbox {
22 namespace {
24 TEST(SyscallWrappers, BasicSyscalls) {
25 EXPECT_EQ(getpid(), sys_getpid());
28 TEST(SyscallWrappers, CloneBasic) {
29 pid_t child = sys_clone(SIGCHLD);
30 TestUtils::HandlePostForkReturn(child);
31 EXPECT_LT(0, child);
34 TEST(SyscallWrappers, CloneParentSettid) {
35 pid_t ptid = 0;
36 pid_t child = sys_clone(CLONE_PARENT_SETTID | SIGCHLD, nullptr, &ptid,
37 nullptr, nullptr);
38 TestUtils::HandlePostForkReturn(child);
39 EXPECT_LT(0, child);
40 EXPECT_EQ(child, ptid);
43 TEST(SyscallWrappers, CloneChildSettid) {
44 pid_t ctid = 0;
45 pid_t pid =
46 sys_clone(CLONE_CHILD_SETTID | SIGCHLD, nullptr, nullptr, &ctid, nullptr);
48 const int kSuccessExit = 0;
49 if (0 == pid) {
50 // In child.
51 if (sys_getpid() == ctid)
52 _exit(kSuccessExit);
53 _exit(1);
56 ASSERT_NE(-1, pid);
57 int status = 0;
58 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0)));
59 ASSERT_TRUE(WIFEXITED(status));
60 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status));
63 TEST(SyscallWrappers, GetRESUid) {
64 uid_t ruid, euid, suid;
65 uid_t sys_ruid, sys_euid, sys_suid;
66 ASSERT_EQ(0, getresuid(&ruid, &euid, &suid));
67 ASSERT_EQ(0, sys_getresuid(&sys_ruid, &sys_euid, &sys_suid));
68 EXPECT_EQ(ruid, sys_ruid);
69 EXPECT_EQ(euid, sys_euid);
70 EXPECT_EQ(suid, sys_suid);
73 TEST(SyscallWrappers, GetRESGid) {
74 gid_t rgid, egid, sgid;
75 gid_t sys_rgid, sys_egid, sys_sgid;
76 ASSERT_EQ(0, getresgid(&rgid, &egid, &sgid));
77 ASSERT_EQ(0, sys_getresgid(&sys_rgid, &sys_egid, &sys_sgid));
78 EXPECT_EQ(rgid, sys_rgid);
79 EXPECT_EQ(egid, sys_egid);
80 EXPECT_EQ(sgid, sys_sgid);
83 } // namespace
85 } // namespace sandbox