• 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 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "build/build_config.h"
12 
13 namespace base {
14 
15 #if !defined(OS_ANDROID) && !defined(__ANDROID__) && !defined(__ANDROID_HOST__)
SpawnMultiProcessTestChild(const std::string & procname,const CommandLine & base_command_line,const LaunchOptions & options)16 Process SpawnMultiProcessTestChild(
17     const std::string& procname,
18     const CommandLine& base_command_line,
19     const LaunchOptions& options) {
20   CommandLine command_line(base_command_line);
21   // TODO(viettrungluu): See comment above |MakeCmdLine()| in the header file.
22   // This is a temporary hack, since |MakeCmdLine()| has to provide a full
23   // command line.
24   if (!command_line.HasSwitch(switches::kTestChildProcess))
25     command_line.AppendSwitchASCII(switches::kTestChildProcess, procname);
26 
27   return LaunchProcess(command_line, options);
28 }
29 #endif  // !OS_ANDROID && !__ANDROID__ && !__ANDROID_HOST__
30 
GetMultiProcessTestChildBaseCommandLine()31 CommandLine GetMultiProcessTestChildBaseCommandLine() {
32   CommandLine cmd_line = *CommandLine::ForCurrentProcess();
33   cmd_line.SetProgram(MakeAbsoluteFilePath(cmd_line.GetProgram()));
34   return cmd_line;
35 }
36 
37 // MultiProcessTest ------------------------------------------------------------
38 
MultiProcessTest()39 MultiProcessTest::MultiProcessTest() {
40 }
41 
SpawnChild(const std::string & procname)42 Process MultiProcessTest::SpawnChild(const std::string& procname) {
43   LaunchOptions options;
44 #if defined(OS_WIN)
45   options.start_hidden = true;
46 #endif
47   return SpawnChildWithOptions(procname, options);
48 }
49 
SpawnChildWithOptions(const std::string & procname,const LaunchOptions & options)50 Process MultiProcessTest::SpawnChildWithOptions(
51     const std::string& procname,
52     const LaunchOptions& options) {
53   return SpawnMultiProcessTestChild(procname, MakeCmdLine(procname), options);
54 }
55 
MakeCmdLine(const std::string & procname)56 CommandLine MultiProcessTest::MakeCmdLine(const std::string& procname) {
57   CommandLine command_line = GetMultiProcessTestChildBaseCommandLine();
58   command_line.AppendSwitchASCII(switches::kTestChildProcess, procname);
59   return command_line;
60 }
61 
62 }  // namespace base
63