2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Wrapper around chrome.
8 Replaces all the child processes (renderer, GPU, plugins and utility) with the
9 IPC fuzzer. The fuzzer will then play back a specified testcase.
11 Depends on ipc_fuzzer being available on the same directory as chrome.
20 CHROME_BINARY_FOR_PLATFORM_DICT
= {
22 'MAC': 'Chromium.app/Contents/MacOS/Chromium',
23 'WINDOWS': 'chrome.exe',
28 if sys
.platform
.startswith('win'):
30 elif sys
.platform
.startswith('linux'):
32 elif sys
.platform
== 'darwin':
35 assert platform
is not None
39 desc
= 'Wrapper to run chrome with child processes replaced by IPC fuzzers'
40 parser
= argparse
.ArgumentParser(description
=desc
)
41 parser
.add_argument('--out-dir', dest
='out_dir', default
='out',
42 help='output directory under src/ directory')
43 parser
.add_argument('--build-type', dest
='build_type', default
='Release',
44 help='Debug vs. Release build')
45 parser
.add_argument('--gdb-browser', dest
='gdb_browser', default
=False,
47 help='run browser process inside gdb')
48 parser
.add_argument('testcase',
49 help='IPC file to be replayed')
50 parser
.add_argument('chrome_args',
51 nargs
=argparse
.REMAINDER
,
52 help='any additional arguments are passed to chrome')
53 args
= parser
.parse_args()
55 platform
= GetPlatform()
56 chrome_binary
= CHROME_BINARY_FOR_PLATFORM_DICT
[platform
]
57 fuzzer_binary
= 'ipc_fuzzer_replay'
58 if platform
== 'WINDOWS':
59 fuzzer_binary
+= '.exe'
61 script_path
= os
.path
.realpath(__file__
)
62 ipc_fuzzer_dir
= os
.path
.dirname(script_path
)
63 src_dir
= os
.path
.abspath(os
.path
.join(ipc_fuzzer_dir
, os
.pardir
, os
.pardir
))
64 out_dir
= os
.path
.join(src_dir
, args
.out_dir
)
65 build_dir
= os
.path
.join(out_dir
, args
.build_type
)
67 chrome_path
= os
.path
.join(build_dir
, chrome_binary
)
68 if not os
.path
.exists(chrome_path
):
69 print 'chrome executable not found at ', chrome_path
72 fuzzer_path
= os
.path
.join(build_dir
, fuzzer_binary
)
73 if not os
.path
.exists(fuzzer_path
):
74 print 'fuzzer executable not found at ', fuzzer_path
75 print ('ensure GYP_DEFINES="enable_ipc_fuzzer=1" and build target ' +
80 '--renderer-cmd-prefix',
83 '--ppapi-plugin-launcher',
84 '--utility-cmd-prefix',
89 '--ipc-fuzzer-testcase=' + args
.testcase
,
91 '--disable-kill-after-bad-ipc',
92 '--disable-mojo-channel',
96 chrome_command
= ['gdb', '--args'] + chrome_command
99 for prefix
in prefixes
:
100 launchers
[prefix
] = fuzzer_path
102 for arg
in args
.chrome_args
:
103 if arg
.find('=') != -1:
104 switch
, value
= arg
.split('=', 1)
105 if switch
in prefixes
:
106 launchers
[switch
] = value
+ ' ' + launchers
[switch
]
108 chrome_command
.append(arg
)
110 for switch
, value
in launchers
.items():
111 chrome_command
.append(switch
+ '=' + value
)
113 command_line
= ' '.join(['\'' + arg
+ '\'' for arg
in chrome_command
])
114 print 'Executing: ' + command_line
116 return subprocess
.call(chrome_command
)
119 if __name__
== "__main__":