| 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.""" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 if not os.access(options.binary, os.X_OK): | 51 if not os.access(options.binary, os.X_OK): |
| 52 print "Cannot find %s." % options.binary | 52 print "Cannot find %s." % options.binary |
| 53 return 1 | 53 return 1 |
| 54 | 54 |
| 55 failure = '' | 55 failure = '' |
| 56 | 56 |
| 57 # Create a temporary directory to store the crash dumps and symbols in. | 57 # Create a temporary directory to store the crash dumps and symbols in. |
| 58 crash_dir = tempfile.mkdtemp() | 58 crash_dir = tempfile.mkdtemp() |
| 59 | 59 |
| 60 crash_service = None |
| 61 |
| 60 try: | 62 try: |
| 61 print "# Generate symbols." | 63 if sys.platform == 'win32': |
| 62 breakpad_tools_dir = os.path.join( | 64 print "# Starting crash service." |
| 63 os.path.dirname(__file__), '..', '..', '..', | 65 crash_service_exe = os.path.join(options.build_dir, |
| 64 'components', 'crash', 'content', 'tools') | 66 'content_shell_crash_service.exe') |
| 65 generate_symbols = os.path.join( | 67 cmd = [crash_service_exe, '--dumps-dir=%s' % crash_dir] |
| 66 breakpad_tools_dir, 'generate_breakpad_symbols.py') | 68 if options.verbose: |
| 67 symbols_dir = os.path.join(crash_dir, 'symbols') | 69 print ' '.join(cmd) |
| 68 cmd = [generate_symbols, | 70 failure = 'Failed to start crash service.' |
| 69 '--build-dir=%s' % options.build_dir, | 71 crash_service = subprocess.Popen(cmd) |
| 70 '--binary=%s' % options.binary, | 72 else: |
| 71 '--symbols-dir=%s' % symbols_dir, | 73 print "# Generate symbols." |
| 72 '--jobs=%d' % options.jobs] | 74 breakpad_tools_dir = os.path.join( |
| 73 if options.verbose: | 75 os.path.dirname(__file__), '..', '..', '..', |
| 74 cmd.append('--verbose') | 76 'components', 'crash', 'content', 'tools') |
| 75 print ' '.join(cmd) | 77 generate_symbols = os.path.join( |
| 76 failure = 'Failed to run generate_breakpad_symbols.py.' | 78 breakpad_tools_dir, 'generate_breakpad_symbols.py') |
| 77 subprocess.check_call(cmd) | 79 symbols_dir = os.path.join(crash_dir, 'symbols') |
| 80 cmd = [generate_symbols, |
| 81 '--build-dir=%s' % options.build_dir, |
| 82 '--binary=%s' % options.binary, |
| 83 '--symbols-dir=%s' % symbols_dir, |
| 84 '--jobs=%d' % options.jobs] |
| 85 if options.verbose: |
| 86 cmd.append('--verbose') |
| 87 print ' '.join(cmd) |
| 88 failure = 'Failed to run generate_breakpad_symbols.py.' |
| 89 subprocess.check_call(cmd) |
| 78 | 90 |
| 79 print "# Run content_shell and make it crash." | 91 print "# Run content_shell and make it crash." |
| 80 cmd = [options.binary, | 92 cmd = [options.binary, |
| 81 '--run-layout-test', | 93 '--run-layout-test', |
| 82 'chrome://crash', | 94 'chrome://crash', |
| 83 '--enable-crash-reporter', | 95 '--enable-crash-reporter', |
| 84 '--crash-dumps-dir=%s' % crash_dir] | 96 '--crash-dumps-dir=%s' % crash_dir] |
| 85 if options.verbose: | 97 if options.verbose: |
| 86 print ' '.join(cmd) | 98 print ' '.join(cmd) |
| 87 failure = 'Failed to run content_shell.' | 99 failure = 'Failed to run content_shell.' |
| 88 if options.verbose: | 100 if options.verbose: |
| 89 subprocess.check_call(cmd) | 101 subprocess.check_call(cmd) |
| 90 else: | 102 else: |
| 91 with open(os.devnull, 'w') as devnull: | 103 with open(os.devnull, 'w') as devnull: |
| 92 subprocess.check_call(cmd, stdout=devnull, stderr=devnull) | 104 subprocess.check_call(cmd, stdout=devnull, stderr=devnull) |
| 93 | 105 |
| 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 |
| 94 print "# Retrieve crash dump." | 112 print "# Retrieve crash dump." |
| 95 dmp_files = glob.glob(os.path.join(crash_dir, '*.dmp')) | 113 dmp_files = glob.glob(os.path.join(crash_dir, '*.dmp')) |
| 96 failure = 'Expected 1 crash dump, found %d.' % len(dmp_files) | 114 failure = 'Expected 1 crash dump, found %d.' % len(dmp_files) |
| 97 if len(dmp_files) != 1: | 115 if len(dmp_files) != 1: |
| 98 raise Exception(failure) | 116 raise Exception(failure) |
| 99 dmp_file = dmp_files[0] | 117 dmp_file = dmp_files[0] |
| 100 minidump = os.path.join(crash_dir, 'minidump') | |
| 101 | 118 |
| 102 dmp_to_minidump = os.path.join(breakpad_tools_dir, 'dmp2minidump.py') | 119 if sys.platform != 'win32': |
| 103 cmd = [dmp_to_minidump, dmp_file, minidump] | 120 minidump = os.path.join(crash_dir, 'minidump') |
| 104 if options.verbose: | 121 dmp_to_minidump = os.path.join(breakpad_tools_dir, 'dmp2minidump.py') |
| 105 print ' '.join(cmd) | 122 cmd = [dmp_to_minidump, dmp_file, minidump] |
| 106 failure = 'Failed to run dmp_to_minidump.' | 123 if options.verbose: |
| 107 subprocess.check_call(cmd) | 124 print ' '.join(cmd) |
| 125 failure = 'Failed to run dmp_to_minidump.' |
| 126 subprocess.check_call(cmd) |
| 108 | 127 |
| 109 print "# Symbolize crash dump." | 128 print "# Symbolize crash dump." |
| 110 minidump_stackwalk = os.path.join(options.build_dir, 'minidump_stackwalk') | 129 if sys.platform == 'win32': |
| 111 cmd = [minidump_stackwalk, minidump, symbols_dir] | 130 cdb_exe = os.path.join(options.build_dir, 'cdb', 'cdb.exe') |
| 112 if options.verbose: | 131 cmd = [cdb_exe, '-y', options.build_dir, '-c', '.lines;.excr;k30;q', |
| 113 print ' '.join(cmd) | 132 '-z', dmp_file] |
| 114 failure = 'Failed to run minidump_stackwalk.' | 133 if options.verbose: |
| 115 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 134 print ' '.join(cmd) |
| 116 stack = proc.communicate()[0] | 135 failure = 'Failed to run cdb.exe.' |
| 136 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
| 137 stderr=subprocess.PIPE) |
| 138 stack = proc.communicate()[0] |
| 139 else: |
| 140 minidump_stackwalk = os.path.join(options.build_dir, 'minidump_stackwalk') |
| 141 cmd = [minidump_stackwalk, minidump, symbols_dir] |
| 142 if options.verbose: |
| 143 print ' '.join(cmd) |
| 144 failure = 'Failed to run minidump_stackwalk.' |
| 145 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, |
| 146 stderr=subprocess.PIPE) |
| 147 stack = proc.communicate()[0] |
| 117 | 148 |
| 118 # Check whether the stack contains a CrashIntentionally symbol. | 149 # Check whether the stack contains a CrashIntentionally symbol. |
| 119 found_symbol = 'CrashIntentionally' in stack | 150 found_symbol = 'CrashIntentionally' in stack |
| 120 | 151 |
| 121 if options.no_symbols: | 152 if options.no_symbols: |
| 122 if found_symbol: | 153 if found_symbol: |
| 123 if options.verbose: | 154 if options.verbose: |
| 124 print stack | 155 print stack |
| 125 failure = 'Found unexpected reference to CrashIntentionally in stack' | 156 failure = 'Found unexpected reference to CrashIntentionally in stack' |
| 126 raise Exception(failure) | 157 raise Exception(failure) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 140 return 1 | 171 return 1 |
| 141 | 172 |
| 142 else: | 173 else: |
| 143 print "PASS: Breakpad integration test ran successfully." | 174 print "PASS: Breakpad integration test ran successfully." |
| 144 if options.json: | 175 if options.json: |
| 145 with open(options.json, 'w') as json_file: | 176 with open(options.json, 'w') as json_file: |
| 146 json.dump([], json_file) | 177 json.dump([], json_file) |
| 147 return 0 | 178 return 0 |
| 148 | 179 |
| 149 finally: | 180 finally: |
| 181 if crash_service: |
| 182 crash_service.terminate() |
| 150 try: | 183 try: |
| 151 shutil.rmtree(crash_dir) | 184 shutil.rmtree(crash_dir) |
| 152 except: | 185 except: |
| 153 print 'Failed to delete temp directory "%s".' % crash_dir | 186 print 'Failed to delete temp directory "%s".' % crash_dir |
| 154 | 187 |
| 155 | 188 |
| 156 if '__main__' == __name__: | 189 if '__main__' == __name__: |
| 157 sys.exit(main()) | 190 sys.exit(main()) |
| OLD | NEW |