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
));
65 } // namespace sandbox