• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 "base/test/multiprocess_test.h"
6 
7 #include "base/base_switches.h"
8 #include "base/command_line.h"
9 
10 namespace base {
11 
MultiProcessTest()12 MultiProcessTest::MultiProcessTest() {
13 }
14 
SpawnChild(const std::string & procname,bool debug_on_start)15 ProcessHandle MultiProcessTest::SpawnChild(const std::string& procname,
16                                            bool debug_on_start) {
17   LaunchOptions options;
18 #if defined(OS_WIN)
19   options.start_hidden = true;
20 #endif
21   return SpawnChildWithOptions(procname, options, debug_on_start);
22 }
23 
24 #if !defined(OS_ANDROID)
SpawnChildWithOptions(const std::string & procname,const LaunchOptions & options,bool debug_on_start)25 ProcessHandle MultiProcessTest::SpawnChildWithOptions(
26     const std::string& procname,
27     const LaunchOptions& options,
28     bool debug_on_start) {
29   ProcessHandle handle = kNullProcessHandle;
30   LaunchProcess(MakeCmdLine(procname, debug_on_start), options, &handle);
31   return handle;
32 }
33 #endif
34 
35 #if defined(OS_POSIX)
SpawnChild(const std::string & procname,const FileHandleMappingVector & fds_to_map,bool debug_on_start)36 ProcessHandle MultiProcessTest::SpawnChild(
37     const std::string& procname,
38     const FileHandleMappingVector& fds_to_map,
39     bool debug_on_start) {
40   LaunchOptions options;
41   options.fds_to_remap = &fds_to_map;
42   return SpawnChildWithOptions(procname, options, debug_on_start);
43 }
44 #endif
45 
MakeCmdLine(const std::string & procname,bool debug_on_start)46 CommandLine MultiProcessTest::MakeCmdLine(const std::string& procname,
47                                           bool debug_on_start) {
48   CommandLine cl(*CommandLine::ForCurrentProcess());
49   cl.AppendSwitchASCII(switches::kTestChildProcess, procname);
50   if (debug_on_start)
51     cl.AppendSwitch(switches::kDebugOnStart);
52   return cl;
53 }
54 
55 }  // namespace base
56