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 12 MultiProcessTest::MultiProcessTest() { 13 } 14 15 ProcessHandle MultiProcessTest::SpawnChild(const std::string& procname, 16 bool debug_on_start) { 17 FileHandleMappingVector empty_file_list; 18 return SpawnChildImpl(procname, empty_file_list, debug_on_start); 19 } 20 21 #if defined(OS_POSIX) 22 ProcessHandle MultiProcessTest::SpawnChild( 23 const std::string& procname, 24 const FileHandleMappingVector& fds_to_map, 25 bool debug_on_start) { 26 return SpawnChildImpl(procname, fds_to_map, debug_on_start); 27 } 28 #endif 29 30 CommandLine MultiProcessTest::MakeCmdLine(const std::string& procname, 31 bool debug_on_start) { 32 CommandLine cl(*CommandLine::ForCurrentProcess()); 33 cl.AppendSwitchASCII(switches::kTestChildProcess, procname); 34 if (debug_on_start) 35 cl.AppendSwitch(switches::kDebugOnStart); 36 return cl; 37 } 38 39 #if !defined(OS_ANDROID) 40 ProcessHandle MultiProcessTest::SpawnChildImpl( 41 const std::string& procname, 42 const FileHandleMappingVector& fds_to_map, 43 bool debug_on_start) { 44 ProcessHandle handle = kNullProcessHandle; 45 base::LaunchOptions options; 46 #if defined(OS_WIN) 47 options.start_hidden = true; 48 #else 49 options.fds_to_remap = &fds_to_map; 50 #endif 51 base::LaunchProcess(MakeCmdLine(procname, debug_on_start), options, &handle); 52 return handle; 53 } 54 #endif // !defined(OS_ANDROID) 55 56 } // namespace base 57