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>
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"
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
);
34 TEST(SyscallWrappers
, CloneParentSettid
) {
36 pid_t child
= sys_clone(CLONE_PARENT_SETTID
| SIGCHLD
, nullptr, &ptid
,
38 TestUtils::HandlePostForkReturn(child
);
40 EXPECT_EQ(child
, ptid
);
43 TEST(SyscallWrappers
, CloneChildSettid
) {
46 sys_clone(CLONE_CHILD_SETTID
| SIGCHLD
, nullptr, nullptr, &ctid
, nullptr);
48 const int kSuccessExit
= 0;
51 if (sys_getpid() == ctid
)
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
);
85 } // namespace sandbox