Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / tools / ipc_fuzzer / play_testcase.py
blob4f3b43965e21a91a3706627510675928801e1084
1 #!/usr/bin/env python
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.
12 """
14 import argparse
15 import os
16 import platform
17 import subprocess
18 import sys
20 CHROME_BINARY_FOR_PLATFORM_DICT = {
21 'LINUX': 'chrome',
22 'MAC': 'Chromium.app/Contents/MacOS/Chromium',
23 'WINDOWS': 'chrome.exe',
26 def GetPlatform():
27 platform = None
28 if sys.platform.startswith('win'):
29 platform = 'WINDOWS'
30 elif sys.platform.startswith('linux'):
31 platform = 'LINUX'
32 elif sys.platform == 'darwin':
33 platform = 'MAC'
35 assert platform is not None
36 return platform
38 def main():
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,
46 action='store_true',
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
70 return 1
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 ' +
76 fuzzer_binary + '.')
77 return 1
79 prefixes = {
80 '--renderer-cmd-prefix',
81 '--gpu-launcher',
82 '--plugin-launcher',
83 '--ppapi-plugin-launcher',
84 '--utility-cmd-prefix',
87 chrome_command = [
88 chrome_path,
89 '--ipc-fuzzer-testcase=' + args.testcase,
90 '--no-sandbox',
91 '--disable-kill-after-bad-ipc',
94 if args.gdb_browser:
95 chrome_command = ['gdb', '--args'] + chrome_command
97 launchers = {}
98 for prefix in prefixes:
99 launchers[prefix] = fuzzer_path
101 for arg in args.chrome_args:
102 if arg.find('=') != -1:
103 switch, value = arg.split('=', 1)
104 if switch in prefixes:
105 launchers[switch] = value + ' ' + launchers[switch]
106 continue
107 chrome_command.append(arg)
109 for switch, value in launchers.items():
110 chrome_command.append(switch + '=' + value)
112 command_line = ' '.join(['\'' + arg + '\'' for arg in chrome_command])
113 print 'Executing: ' + command_line
115 return subprocess.call(chrome_command)
118 if __name__ == "__main__":
119 sys.exit(main())