| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Integration test for breakpad in content shell. | 7 """Integration test for breakpad in content shell. |
| 8 | 8 |
| 9 This test checks that content shell and breakpad are correctly hooked up, as | 9 This test checks that content shell and breakpad are correctly hooked up, as |
| 10 well as that the tools can symbolize a stack trace.""" | 10 well as that the tools can symbolize a stack trace.""" |
| 11 | 11 |
| 12 | 12 |
| 13 import glob | 13 import glob |
| 14 import json | 14 import json |
| 15 import optparse | 15 import optparse |
| 16 import os | 16 import os |
| 17 import shutil | 17 import shutil |
| 18 import subprocess | 18 import subprocess |
| 19 import sys | 19 import sys |
| 20 import tempfile | 20 import tempfile |
| 21 import time |
| 21 | 22 |
| 22 | 23 |
| 23 CONCURRENT_TASKS=4 | 24 CONCURRENT_TASKS=4 |
| 24 | 25 |
| 25 | 26 |
| 26 def main(): | 27 def main(): |
| 27 parser = optparse.OptionParser() | 28 parser = optparse.OptionParser() |
| 28 parser.add_option('', '--build-dir', default='', | 29 parser.add_option('', '--build-dir', default='', |
| 29 help='The build output directory.') | 30 help='The build output directory.') |
| 30 parser.add_option('', '--binary', default='', | 31 parser.add_option('', '--binary', default='', |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 try: | 63 try: |
| 63 if sys.platform == 'win32': | 64 if sys.platform == 'win32': |
| 64 print "# Starting crash service." | 65 print "# Starting crash service." |
| 65 crash_service_exe = os.path.join(options.build_dir, | 66 crash_service_exe = os.path.join(options.build_dir, |
| 66 'content_shell_crash_service.exe') | 67 'content_shell_crash_service.exe') |
| 67 cmd = [crash_service_exe, '--dumps-dir=%s' % crash_dir] | 68 cmd = [crash_service_exe, '--dumps-dir=%s' % crash_dir] |
| 68 if options.verbose: | 69 if options.verbose: |
| 69 print ' '.join(cmd) | 70 print ' '.join(cmd) |
| 70 failure = 'Failed to start crash service.' | 71 failure = 'Failed to start crash service.' |
| 71 crash_service = subprocess.Popen(cmd) | 72 crash_service = subprocess.Popen(cmd) |
| 73 # We add a delay here to give the crash service some time to create |
| 74 # the pipe it uses to communicate with the content shell. |
| 75 time.sleep(1) |
| 72 else: | 76 else: |
| 73 print "# Generate symbols." | 77 print "# Generate symbols." |
| 74 breakpad_tools_dir = os.path.join( | 78 breakpad_tools_dir = os.path.join( |
| 75 os.path.dirname(__file__), '..', '..', '..', | 79 os.path.dirname(__file__), '..', '..', '..', |
| 76 'components', 'crash', 'content', 'tools') | 80 'components', 'crash', 'content', 'tools') |
| 77 generate_symbols = os.path.join( | 81 generate_symbols = os.path.join( |
| 78 breakpad_tools_dir, 'generate_breakpad_symbols.py') | 82 breakpad_tools_dir, 'generate_breakpad_symbols.py') |
| 79 symbols_dir = os.path.join(crash_dir, 'symbols') | 83 symbols_dir = os.path.join(crash_dir, 'symbols') |
| 80 cmd = [generate_symbols, | 84 cmd = [generate_symbols, |
| 81 '--build-dir=%s' % options.build_dir, | 85 '--build-dir=%s' % options.build_dir, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 96 '--crash-dumps-dir=%s' % crash_dir] | 100 '--crash-dumps-dir=%s' % crash_dir] |
| 97 if options.verbose: | 101 if options.verbose: |
| 98 print ' '.join(cmd) | 102 print ' '.join(cmd) |
| 99 failure = 'Failed to run content_shell.' | 103 failure = 'Failed to run content_shell.' |
| 100 if options.verbose: | 104 if options.verbose: |
| 101 subprocess.check_call(cmd) | 105 subprocess.check_call(cmd) |
| 102 else: | 106 else: |
| 103 with open(os.devnull, 'w') as devnull: | 107 with open(os.devnull, 'w') as devnull: |
| 104 subprocess.check_call(cmd, stdout=devnull, stderr=devnull) | 108 subprocess.check_call(cmd, stdout=devnull, stderr=devnull) |
| 105 | 109 |
| 106 if sys.platform == 'win32': | |
| 107 print "# Stopping crash service" | |
| 108 failure = 'Failed to stop crash service.' | |
| 109 crash_service.terminate() | |
| 110 crash_service = None | |
| 111 | |
| 112 print "# Retrieve crash dump." | 110 print "# Retrieve crash dump." |
| 113 dmp_files = glob.glob(os.path.join(crash_dir, '*.dmp')) | 111 dmp_files = glob.glob(os.path.join(crash_dir, '*.dmp')) |
| 114 failure = 'Expected 1 crash dump, found %d.' % len(dmp_files) | 112 failure = 'Expected 1 crash dump, found %d.' % len(dmp_files) |
| 115 if len(dmp_files) != 1: | 113 if len(dmp_files) != 1: |
| 116 raise Exception(failure) | 114 raise Exception(failure) |
| 117 dmp_file = dmp_files[0] | 115 dmp_file = dmp_files[0] |
| 118 | 116 |
| 119 if sys.platform != 'win32': | 117 if sys.platform != 'win32': |
| 120 minidump = os.path.join(crash_dir, 'minidump') | 118 minidump = os.path.join(crash_dir, 'minidump') |
| 121 dmp_to_minidump = os.path.join(breakpad_tools_dir, 'dmp2minidump.py') | 119 dmp_to_minidump = os.path.join(breakpad_tools_dir, 'dmp2minidump.py') |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 else: | 171 else: |
| 174 print "PASS: Breakpad integration test ran successfully." | 172 print "PASS: Breakpad integration test ran successfully." |
| 175 if options.json: | 173 if options.json: |
| 176 with open(options.json, 'w') as json_file: | 174 with open(options.json, 'w') as json_file: |
| 177 json.dump([], json_file) | 175 json.dump([], json_file) |
| 178 return 0 | 176 return 0 |
| 179 | 177 |
| 180 finally: | 178 finally: |
| 181 if crash_service: | 179 if crash_service: |
| 182 crash_service.terminate() | 180 crash_service.terminate() |
| 181 crash_service.wait() |
| 183 try: | 182 try: |
| 184 shutil.rmtree(crash_dir) | 183 shutil.rmtree(crash_dir) |
| 185 except: | 184 except: |
| 186 print 'Failed to delete temp directory "%s".' % crash_dir | 185 print 'Failed to delete temp directory "%s".' % crash_dir |
| 187 | 186 |
| 188 | 187 |
| 189 if '__main__' == __name__: | 188 if '__main__' == __name__: |
| 190 sys.exit(main()) | 189 sys.exit(main()) |
| OLD | NEW |