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

Unified Diff: base/process/process_unittest.cc

Issue 831363002: Add the ability to run a callback between fork and exec. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months 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
« base/process/launch.h ('K') | « base/process/launch_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_unittest.cc
diff --git a/base/process/process_unittest.cc b/base/process/process_unittest.cc
index 5180f64c55a8111a5db6456570d1ac4d38f2776e..14a934c123511c09056be6ee9614ed06d5dcf4ae 100644
--- a/base/process/process_unittest.cc
+++ b/base/process/process_unittest.cc
@@ -4,6 +4,8 @@
#include "base/process/process.h"
+#include "base/bind.h"
+#include "base/posix/eintr_wrapper.h"
#include "base/process/kill.h"
#include "base/test/multiprocess_test.h"
#include "base/test/test_timeouts.h"
@@ -201,4 +203,40 @@ TEST_F(ProcessTest, SetProcessBackgroundedSelf) {
EXPECT_EQ(old_priority, new_priority);
}
+#if defined(OS_POSIX)
+const char kPipeValue = '\xcc';
+
+void ReadFromPipe(int fd) {
+ char c;
+ RAW_CHECK(HANDLE_EINTR(read(fd, &c, 1)) == 1);
+ RAW_CHECK(IGNORE_EINTR(close(fd)) == 0);
+ RAW_CHECK(c == kPipeValue);
+}
+
+TEST_F(ProcessTest, PreExecHook) {
+ int pipe_fds[2];
+ ASSERT_EQ(0, pipe(pipe_fds));
+
+ int read_fd = pipe_fds[0];
+ int write_fd = pipe_fds[1];
+ base::FileHandleMappingVector fds_to_remap;
+ fds_to_remap.push_back(std::make_pair(read_fd, read_fd));
+
+ LaunchOptions options;
+ options.fds_to_remap = &fds_to_remap;
+ options.pre_exec_hook = base::Bind(&ReadFromPipe, read_fd);
+ Process process(SpawnChildWithOptions("SimpleChildProcess", options));
+ ASSERT_TRUE(process.IsValid());
+
+ ASSERT_EQ(0, IGNORE_EINTR(close(read_fd)));
+ ASSERT_EQ(1, HANDLE_EINTR(write(write_fd, &kPipeValue, 1)));
+ ASSERT_EQ(0, IGNORE_EINTR(close(write_fd)));
+
+ const int kDummyExitCode = 42;
+ int exit_code = kDummyExitCode;
jln (very slow on Chromium) 2015/01/06 00:43:36 = 42?
+ EXPECT_TRUE(process.WaitForExit(&exit_code));
+ EXPECT_EQ(0, exit_code);
+}
+#endif
+
} // namespace base
« base/process/launch.h ('K') | « base/process/launch_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698