| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Wrapper around chrome. | 6 """Wrapper around chrome. |
| 7 | 7 |
| 8 Replaces all the child processes (renderer, GPU, plugins and utility) with the | 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. | 9 IPC fuzzer. The fuzzer will then play back a specified testcase. |
| 10 | 10 |
| 11 Depends on ipc_fuzzer being available on the same directory as chrome. | 11 Depends on ipc_fuzzer being available on the same directory as chrome. |
| 12 """ | 12 """ |
| 13 | 13 |
| 14 import argparse | 14 import argparse |
| 15 import os | 15 import os |
| 16 import platform | 16 import platform |
| 17 import subprocess | 17 import subprocess |
| 18 import sys | 18 import sys |
| 19 | 19 |
| 20 CHROME_BINARY_FOR_PLATFORM_DICT = { |
| 21 'LINUX': 'chrome', |
| 22 'MAC': 'Chromium.app/Contents/MacOS/Chromium', |
| 23 'WINDOWS': 'chrome.exe', |
| 24 } |
| 25 |
| 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' |
| 34 |
| 35 assert platform is not None |
| 36 return platform |
| 37 |
| 20 def main(): | 38 def main(): |
| 21 desc = 'Wrapper to run chrome with child processes replaced by IPC fuzzers' | 39 desc = 'Wrapper to run chrome with child processes replaced by IPC fuzzers' |
| 22 parser = argparse.ArgumentParser(description=desc) | 40 parser = argparse.ArgumentParser(description=desc) |
| 23 parser.add_argument('--out-dir', dest='out_dir', default='out', | 41 parser.add_argument('--out-dir', dest='out_dir', default='out', |
| 24 help='output directory under src/ directory') | 42 help='output directory under src/ directory') |
| 25 parser.add_argument('--build-type', dest='build_type', default='Release', | 43 parser.add_argument('--build-type', dest='build_type', default='Release', |
| 26 help='Debug vs. Release build') | 44 help='Debug vs. Release build') |
| 27 parser.add_argument('--gdb-browser', dest='gdb_browser', default=False, | 45 parser.add_argument('--gdb-browser', dest='gdb_browser', default=False, |
| 28 action='store_true', | 46 action='store_true', |
| 29 help='run browser process inside gdb') | 47 help='run browser process inside gdb') |
| 30 parser.add_argument('testcase', | 48 parser.add_argument('testcase', |
| 31 help='IPC file to be replayed') | 49 help='IPC file to be replayed') |
| 32 parser.add_argument('chrome_args', | 50 parser.add_argument('chrome_args', |
| 33 nargs=argparse.REMAINDER, | 51 nargs=argparse.REMAINDER, |
| 34 help='any additional arguments are passed to chrome') | 52 help='any additional arguments are passed to chrome') |
| 35 args = parser.parse_args() | 53 args = parser.parse_args() |
| 36 | 54 |
| 37 chrome_binary = 'chrome' | 55 platform = GetPlatform() |
| 56 chrome_binary = CHROME_BINARY_FOR_PLATFORM_DICT[platform] |
| 38 fuzzer_binary = 'ipc_fuzzer_replay' | 57 fuzzer_binary = 'ipc_fuzzer_replay' |
| 58 if platform == 'WINDOWS': |
| 59 fuzzer_binary += '.exe' |
| 39 | 60 |
| 40 script_path = os.path.realpath(__file__) | 61 script_path = os.path.realpath(__file__) |
| 41 ipc_fuzzer_dir = os.path.dirname(script_path) | 62 ipc_fuzzer_dir = os.path.dirname(script_path) |
| 42 src_dir = os.path.abspath(os.path.join(ipc_fuzzer_dir, os.pardir, os.pardir)) | 63 src_dir = os.path.abspath(os.path.join(ipc_fuzzer_dir, os.pardir, os.pardir)) |
| 43 out_dir = os.path.join(src_dir, args.out_dir) | 64 out_dir = os.path.join(src_dir, args.out_dir) |
| 44 build_dir = os.path.join(out_dir, args.build_type) | 65 build_dir = os.path.join(out_dir, args.build_type) |
| 45 | 66 |
| 46 chrome_path = os.path.join(build_dir, chrome_binary) | 67 chrome_path = os.path.join(build_dir, chrome_binary) |
| 47 if not os.path.exists(chrome_path): | 68 if not os.path.exists(chrome_path): |
| 48 print 'chrome executable not found at ', chrome_path | 69 print 'chrome executable not found at ', chrome_path |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 chrome_command.append(switch + '=' + value) | 110 chrome_command.append(switch + '=' + value) |
| 90 | 111 |
| 91 command_line = ' '.join(['\'' + arg + '\'' for arg in chrome_command]) | 112 command_line = ' '.join(['\'' + arg + '\'' for arg in chrome_command]) |
| 92 print 'Executing: ' + command_line | 113 print 'Executing: ' + command_line |
| 93 | 114 |
| 94 return subprocess.call(chrome_command) | 115 return subprocess.call(chrome_command) |
| 95 | 116 |
| 96 | 117 |
| 97 if __name__ == "__main__": | 118 if __name__ == "__main__": |
| 98 sys.exit(main()) | 119 sys.exit(main()) |
| OLD | NEW |