Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Unified Diff: sandbox/linux/services/syscall_wrappers_unittest.cc

Issue 800183004: Add a ForkWithFlags wrapper using the libc clone wrapper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/linux/services/syscall_wrappers.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/services/syscall_wrappers_unittest.cc
diff --git a/sandbox/linux/services/syscall_wrappers_unittest.cc b/sandbox/linux/services/syscall_wrappers_unittest.cc
index 861dd5feb1c02aa7ece96186694f6b7b675a19f1..bac3881ae06c11809b6fe0ebd4b9db46cb883016 100644
--- a/sandbox/linux/services/syscall_wrappers_unittest.cc
+++ b/sandbox/linux/services/syscall_wrappers_unittest.cc
@@ -11,8 +11,10 @@
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
+#include "base/third_party/valgrind/valgrind.h"
#include "build/build_config.h"
#include "sandbox/linux/tests/test_utils.h"
+#include "sandbox/linux/tests/unit_tests.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace sandbox {
@@ -58,6 +60,35 @@ TEST(SyscallWrappers, CloneChildSettid) {
EXPECT_EQ(kSuccessExit, WEXITSTATUS(status));
}
+TEST(SyscallWrappers, ForkWithFlagsUpdatesPidCache) {
+ // The libc clone function, which allows ForkWithFlags to keep the pid cache
+ // up to date, does not work on Valgrind.
+ if (IsRunningOnValgrind()) {
+ return;
+ }
+
+ // Warm up the libc pid cache, if there is one.
+ ASSERT_EQ(sys_getpid(), getpid());
+
+ pid_t ctid = 0;
+ pid_t pid = ForkWithFlags(CLONE_CHILD_SETTID | SIGCHLD, nullptr, &ctid);
+
+ const int kSuccessExit = 0;
+ if (0 == pid) {
+ // In child. Check both the raw getpid syscall and the libc getpid wrapper
+ // (which may rely on a pid cache).
+ if (sys_getpid() == ctid && getpid() == ctid)
+ _exit(kSuccessExit);
+ _exit(1);
+ }
+
+ ASSERT_NE(-1, pid);
+ int status = 0;
+ ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0)));
+ ASSERT_TRUE(WIFEXITED(status));
+ EXPECT_EQ(kSuccessExit, WEXITSTATUS(status));
+}
+
} // namespace
} // namespace sandbox
« no previous file with comments | « sandbox/linux/services/syscall_wrappers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698