Mac: Only allow NSOpenGLContext displaying on the main display
[chromium-blink-merge.git] / tools / ipc_fuzzer / scripts / play_testcase.py
blob69354479dee5c9edb94f3bce3794d0c581f43dda
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.join(os.path.dirname(script_path), os.pardir)
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',
92 '--disable-mojo-channel',
95 if args.gdb_browser:
96 chrome_command = ['gdb', '--args'] + chrome_command
98 launchers = {}
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]
107 continue
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__":
120 sys.exit(main())