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

Side by Side 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 unified diff | Download patch
« base/process/launch.h ('K') | « base/process/launch_posix.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/process/process.h" 5 #include "base/process/process.h"
6 6
7 #include "base/bind.h"
8 #include "base/posix/eintr_wrapper.h"
7 #include "base/process/kill.h" 9 #include "base/process/kill.h"
8 #include "base/test/multiprocess_test.h" 10 #include "base/test/multiprocess_test.h"
9 #include "base/test/test_timeouts.h" 11 #include "base/test/test_timeouts.h"
10 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/multiprocess_func_list.h" 14 #include "testing/multiprocess_func_list.h"
13 15
14 16
15 namespace { 17 namespace {
16 18
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EXPECT_TRUE(process.SetProcessBackgrounded(false)); 196 EXPECT_TRUE(process.SetProcessBackgrounded(false));
195 EXPECT_FALSE(process.IsProcessBackgrounded()); 197 EXPECT_FALSE(process.IsProcessBackgrounded());
196 #else 198 #else
197 process.SetProcessBackgrounded(true); 199 process.SetProcessBackgrounded(true);
198 process.SetProcessBackgrounded(false); 200 process.SetProcessBackgrounded(false);
199 #endif 201 #endif
200 int new_priority = process.GetPriority(); 202 int new_priority = process.GetPriority();
201 EXPECT_EQ(old_priority, new_priority); 203 EXPECT_EQ(old_priority, new_priority);
202 } 204 }
203 205
206 #if defined(OS_POSIX)
207 const char kPipeValue = '\xcc';
208
209 void ReadFromPipe(int fd) {
210 char c;
211 RAW_CHECK(HANDLE_EINTR(read(fd, &c, 1)) == 1);
212 RAW_CHECK(IGNORE_EINTR(close(fd)) == 0);
213 RAW_CHECK(c == kPipeValue);
214 }
215
216 TEST_F(ProcessTest, PreExecHook) {
217 int pipe_fds[2];
218 ASSERT_EQ(0, pipe(pipe_fds));
219
220 int read_fd = pipe_fds[0];
221 int write_fd = pipe_fds[1];
222 base::FileHandleMappingVector fds_to_remap;
223 fds_to_remap.push_back(std::make_pair(read_fd, read_fd));
224
225 LaunchOptions options;
226 options.fds_to_remap = &fds_to_remap;
227 options.pre_exec_hook = base::Bind(&ReadFromPipe, read_fd);
228 Process process(SpawnChildWithOptions("SimpleChildProcess", options));
229 ASSERT_TRUE(process.IsValid());
230
231 ASSERT_EQ(0, IGNORE_EINTR(close(read_fd)));
232 ASSERT_EQ(1, HANDLE_EINTR(write(write_fd, &kPipeValue, 1)));
233 ASSERT_EQ(0, IGNORE_EINTR(close(write_fd)));
234
235 const int kDummyExitCode = 42;
236 int exit_code = kDummyExitCode;
jln (very slow on Chromium) 2015/01/06 00:43:36 = 42?
237 EXPECT_TRUE(process.WaitForExit(&exit_code));
238 EXPECT_EQ(0, exit_code);
239 }
240 #endif
241
204 } // namespace base 242 } // namespace base
OLDNEW
« 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