Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 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 | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """Integration test for breakpad in content shell. | |
| 8 | |
| 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.""" | |
| 11 | |
| 12 | |
| 13 import glob | |
| 14 import optparse | |
| 15 import os | |
| 16 import shutil | |
| 17 import subprocess | |
| 18 import sys | |
| 19 import tempfile | |
| 20 | |
| 21 | |
| 22 CONCURRENT_TASKS=4 | |
| 23 | |
| 24 | |
| 25 def main(): | |
| 26 parser = optparse.OptionParser() | |
| 27 parser.add_option('', '--build-dir', default='', | |
| 28 help='The build output directory.') | |
| 29 parser.add_option('', '--binary', default='', | |
| 30 help='The path of the binary to generate symbols for.') | |
| 31 parser.add_option('', '--no-symbols', default=False, action='store_true', | |
| 32 help='Symbols are not expected to work.') | |
| 33 parser.add_option('-j', '--jobs', default=CONCURRENT_TASKS, action='store', | |
| 34 type='int', help='Number of parallel tasks to run.') | |
| 35 parser.add_option('-v', '--verbose', action='store_true', | |
| 36 help='Print verbose status output.') | |
| 37 | |
| 38 (options, _) = parser.parse_args() | |
| 39 | |
| 40 if not options.build_dir: | |
| 41 print "Required option --build-dir missing." | |
| 42 return 1 | |
| 43 | |
| 44 if not options.binary: | |
| 45 print "Required option --binary missing." | |
| 46 return 1 | |
| 47 | |
| 48 if not os.access(options.binary, os.X_OK): | |
| 49 print "Cannot find %s." % options.binary | |
| 50 return 1 | |
| 51 | |
| 52 failure = '' | |
| 53 | |
| 54 # Create a temporary directory to store the crash dumps and symbols in. | |
| 55 crash_dir = tempfile.mkdtemp() | |
| 56 | |
| 57 try: | |
| 58 print "# Generate symbols." | |
| 59 generate_symbols = os.path.join( | |
| 60 os.path.dirname(os.path.dirname(options.build_dir)), | |
| 61 'components', 'breakpad', 'tools', 'generate_breakpad_symbols.py') | |
|
Lei Zhang
2014/05/23 03:13:53
this should be relative to breakpad_integration_te
jochen (gone - plz use gerrit)
2014/05/23 07:22:22
Done.
| |
| 62 symbols_dir = os.path.join(crash_dir, 'symbols') | |
| 63 cmd = [generate_symbols, | |
| 64 '--build-dir=%s' % options.build_dir, | |
| 65 '--binary=%s' % options.binary, | |
| 66 '--symbols-dir=%s' % symbols_dir, | |
| 67 '--jobs=%d' % options.jobs] | |
| 68 if options.verbose: | |
| 69 cmd.append('--verbose') | |
| 70 print ' '.join(cmd) | |
| 71 failure = 'Failed to run generate_breakpad_symbols.py.' | |
| 72 subprocess.check_call(cmd) | |
| 73 | |
| 74 print "# Run content_shell and make it crash." | |
| 75 cmd = [options.binary, | |
| 76 '--dump-render-tree', | |
| 77 'chrome://crash', | |
| 78 '--enable-crash-reporter', | |
|
Lei Zhang
2014/05/23 05:22:51
Oh, please use --enable-crash-reporter-for-testing
jochen (gone - plz use gerrit)
2014/05/23 07:22:22
--enable-crash-reporter-for-testing is a linux onl
| |
| 79 '--crash-dumps-dir=%s' % crash_dir] | |
| 80 if options.verbose: | |
| 81 print ' '.join(cmd) | |
| 82 failure = 'Failed to run content_shell.' | |
| 83 if options.verbose: | |
| 84 subprocess.check_call(cmd) | |
| 85 else: | |
| 86 with open(os.devnull, 'w') as devnull: | |
| 87 subprocess.check_call(cmd, stdout=devnull, stderr=devnull) | |
| 88 | |
| 89 print "# Retrieve crash dump." | |
| 90 dmp_files = glob.glob(os.path.join(crash_dir, '*.dmp')) | |
| 91 failure = 'Could not find a single crash dump.' | |
|
Lei Zhang
2014/05/23 03:13:53
This is slightly confusing, maybe change it to: 'E
jochen (gone - plz use gerrit)
2014/05/23 07:22:22
Done.
| |
| 92 if len(dmp_files) != 1: | |
| 93 raise Exception(failure) | |
| 94 dmp_file = dmp_files[0] | |
| 95 minidump = os.path.join(crash_dir, 'minidump') | |
| 96 | |
| 97 dmp_to_minidump = os.path.join( | |
| 98 os.path.dirname(os.path.dirname(options.build_dir)), | |
| 99 'components', 'breakpad', 'tools', 'dmp2minidump.py') | |
|
Lei Zhang
2014/05/23 03:13:53
same comment as line 61
jochen (gone - plz use gerrit)
2014/05/23 07:22:22
Done.
| |
| 100 cmd = [dmp_to_minidump, dmp_file, minidump] | |
| 101 if options.verbose: | |
| 102 print ' '.join(cmd) | |
| 103 failure = 'Failed to run dmp_to_minidump.' | |
| 104 subprocess.check_call(cmd) | |
| 105 | |
| 106 print "# Symbolize crash dump." | |
| 107 minidump_stackwalk = os.path.join(options.build_dir, 'minidump_stackwalk') | |
| 108 cmd = [minidump_stackwalk, minidump, symbols_dir] | |
| 109 if options.verbose: | |
| 110 print ' '.join(cmd) | |
| 111 failure = 'Failed to run minidump_stackwalk.' | |
| 112 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| 113 stack = proc.communicate()[0] | |
| 114 | |
| 115 # Check whether the stack contains a CrashIntentionally symbol. | |
| 116 found_symbol = stack.find('CrashIntentionally') != -1 | |
| 117 | |
| 118 if options.no_symbols: | |
| 119 if found_symbol: | |
| 120 if options.verbose: | |
| 121 print stack | |
| 122 failure = 'Found unexpected reference to CrashIntentionally in stack' | |
| 123 raise Exception(failure) | |
| 124 else: | |
| 125 if not found_symbol: | |
| 126 if options.verbose: | |
| 127 print stack | |
| 128 failure = 'Could not find reference to CrashIntentionally in stack.' | |
| 129 raise Exception(failure) | |
| 130 | |
| 131 except: | |
| 132 try: | |
| 133 shutil.rmtree(crash_dir) | |
| 134 except: | |
| 135 print 'Failed to delete temp directory.' | |
| 136 | |
| 137 print "FAIL: %s" % failure | |
| 138 return 1 | |
| 139 | |
| 140 try: | |
|
Lei Zhang
2014/05/23 03:13:53
put the above rmtree() attempt inside finally: and
jochen (gone - plz use gerrit)
2014/05/23 07:22:22
Done.
| |
| 141 shutil.rmtree(crash_dir) | |
| 142 except: | |
| 143 print 'Failed to delete temp directory.' | |
| 144 | |
| 145 print "PASS: Breakpad integration test ran successfully." | |
| 146 return 0 | |
| 147 | |
| 148 | |
| 149 if '__main__' == __name__: | |
| 150 sys.exit(main()) | |
| OLD | NEW |