OLD | NEW |
(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 |
OLD | NEW |