Infobar material design refresh: bg color
[chromium-blink-merge.git] / sandbox / linux / services / syscall_wrappers_unittest.cc
blob1878ff3fe792afb9d5a83b0d7a9558c2ae56080a
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>
11 #include <cstring>
13 #include "base/logging.h"
14 #include "base/posix/eintr_wrapper.h"
15 #include "base/third_party/valgrind/valgrind.h"
16 #include "build/build_config.h"
17 #include "sandbox/linux/system_headers/linux_signal.h"
18 #include "sandbox/linux/tests/test_utils.h"
19 #include "sandbox/linux/tests/unit_tests.h"
20 #include "testing/gtest/include/gtest/gtest.h"
22 namespace sandbox {
24 namespace {
26 TEST(SyscallWrappers, BasicSyscalls) {
27 EXPECT_EQ(getpid(), sys_getpid());
30 TEST(SyscallWrappers, CloneBasic) {
31 pid_t child = sys_clone(SIGCHLD);
32 TestUtils::HandlePostForkReturn(child);
33 EXPECT_LT(0, child);
36 TEST(SyscallWrappers, CloneParentSettid) {
37 pid_t ptid = 0;
38 pid_t child = sys_clone(CLONE_PARENT_SETTID | SIGCHLD, nullptr, &ptid,
39 nullptr, nullptr);
40 TestUtils::HandlePostForkReturn(child);
41 EXPECT_LT(0, child);
42 EXPECT_EQ(child, ptid);
45 TEST(SyscallWrappers, CloneChildSettid) {
46 pid_t ctid = 0;
47 pid_t pid =
48 sys_clone(CLONE_CHILD_SETTID | SIGCHLD, nullptr, nullptr, &ctid, nullptr);
50 const int kSuccessExit = 0;
51 if (0 == pid) {
52 // In child.
53 if (sys_getpid() == ctid)
54 _exit(kSuccessExit);
55 _exit(1);
58 ASSERT_NE(-1, pid);
59 int status = 0;
60 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0)));
61 ASSERT_TRUE(WIFEXITED(status));
62 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status));
65 TEST(SyscallWrappers, GetRESUid) {
66 uid_t ruid, euid, suid;
67 uid_t sys_ruid, sys_euid, sys_suid;
68 ASSERT_EQ(0, getresuid(&ruid, &euid, &suid));
69 ASSERT_EQ(0, sys_getresuid(&sys_ruid, &sys_euid, &sys_suid));
70 EXPECT_EQ(ruid, sys_ruid);
71 EXPECT_EQ(euid, sys_euid);
72 EXPECT_EQ(suid, sys_suid);
75 TEST(SyscallWrappers, GetRESGid) {
76 gid_t rgid, egid, sgid;
77 gid_t sys_rgid, sys_egid, sys_sgid;
78 ASSERT_EQ(0, getresgid(&rgid, &egid, &sgid));
79 ASSERT_EQ(0, sys_getresgid(&sys_rgid, &sys_egid, &sys_sgid));
80 EXPECT_EQ(rgid, sys_rgid);
81 EXPECT_EQ(egid, sys_egid);
82 EXPECT_EQ(sgid, sys_sgid);
85 TEST(SyscallWrappers, LinuxSigSet) {
86 sigset_t sigset;
87 ASSERT_EQ(0, sigemptyset(&sigset));
88 ASSERT_EQ(0, sigaddset(&sigset, LINUX_SIGSEGV));
89 ASSERT_EQ(0, sigaddset(&sigset, LINUX_SIGBUS));
90 uint64_t linux_sigset = 0;
91 std::memcpy(&linux_sigset, &sigset,
92 std::min(sizeof(sigset), sizeof(linux_sigset)));
93 EXPECT_EQ((1ULL << (LINUX_SIGSEGV - 1)) | (1ULL << (LINUX_SIGBUS - 1)),
94 linux_sigset);
97 } // namespace
99 } // namespace sandbox