Skip direct map from apk check for Samsung Mega.
[chromium-blink-merge.git] / sandbox / linux / services / syscall_wrappers_unittest.cc
bloba8b48fe586f04677a4add441b47a5dd2f42986d4
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 } // namespace
65 } // namespace sandbox