| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 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 """A Windows-only end-to-end integration test for Kasko, Chrome and Crashpad. | 6 """Integration test for Kasko.""" |
| 7 | |
| 8 This test ensures that the interface between Kasko and Chrome and Crashpad works | |
| 9 as expected. The test causes Kasko to set certain crash keys and invoke a crash | |
| 10 report, which is in turn delivered to a locally hosted test crash server. If the | |
| 11 crash report is received intact with the expected crash keys then all is well. | |
| 12 | |
| 13 Note that this test only works against non-component Release and Official builds | |
| 14 of Chrome with Chrome branding, and attempting to use it with anything else will | |
| 15 most likely lead to constant failures. | |
| 16 | |
| 17 Typical usage (assuming in root 'src' directory): | |
| 18 | |
| 19 - generate project files with the following GYP variables: | |
| 20 syzyasan=1 win_z7=0 chromium_win_pch=0 | |
| 21 - build the release Chrome binaries: | |
| 22 ninja -C out\Release chrome.exe | |
| 23 - run the test: | |
| 24 python chrome/test/kasko/kasko_integration_test.py | |
| 25 """ | |
| 26 | 7 |
| 27 import logging | 8 import logging |
| 28 import os | 9 import os |
| 29 import sys | 10 import optparse |
| 30 | 11 |
| 31 # Bring in the Kasko module. | |
| 32 KASKO_DIR = os.path.join(os.path.dirname(__file__), 'py') | |
| 33 sys.path.append(KASKO_DIR) | |
| 34 import kasko | 12 import kasko |
| 35 | 13 |
| 36 | 14 |
| 37 _LOGGER = logging.getLogger(os.path.basename(__file__)) | 15 _LOGGER = logging.getLogger(os.path.basename(__file__)) |
| 38 | 16 |
| 39 | 17 |
| 40 def Main(): | 18 def RunTest(options, url, timeout, expected_keys): |
| 41 options = kasko.config.ParseCommandLine() | 19 """Runs an integration test for Kasko crash reports. |
| 20 |
| 21 Launches both test server and a Chrome instance and then navigates |
| 22 to the test |url|. The visited |url| is expected to generate a |
| 23 Kasko report within the |timeout| allowed. The report is finally |
| 24 verified against expected crash keys. |
| 25 |
| 26 This test raises an exception on error. |
| 27 |
| 28 Args: |
| 29 options The options used to modify the test behavior. Call |
| 30 kasko.config.ParseCommandLine() to generate them. |
| 31 url The URL that the browser will be navigated to in order to |
| 32 cause a crash. |
| 33 timeout The time, in seconds, in which the crash is expected to |
| 34 be processed. |
| 35 expected_keys A dictionary containing the keys that are expected |
| 36 to be present in the crash keys of the report. The value is an |
| 37 optional string to give an indication of what is the probable |
| 38 cause of the missing key. |
| 39 """ |
| 42 | 40 |
| 43 # Generate a temporary directory for use in the tests. | 41 # Generate a temporary directory for use in the tests. |
| 44 with kasko.util.ScopedTempDir() as temp_dir: | 42 with kasko.util.ScopedTempDir() as temp_dir: |
| 45 # Prevent the temporary directory from self cleaning if requested. | 43 # Prevent the temporary directory from self cleaning if requested. |
| 46 if options.keep_temp_dirs: | 44 if options.keep_temp_dirs: |
| 47 temp_dir_path = temp_dir.release() | 45 temp_dir_path = temp_dir.release() |
| 48 else: | 46 else: |
| 49 temp_dir_path = temp_dir.path | 47 temp_dir_path = temp_dir.path |
| 50 | 48 |
| 51 # Use the specified user data directory if requested. | 49 # Use the specified user data directory if requested. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 64 | 62 |
| 65 # Configure the environment so Chrome can find the test crash server. | 63 # Configure the environment so Chrome can find the test crash server. |
| 66 os.environ['KASKO_CRASH_SERVER_URL'] = ( | 64 os.environ['KASKO_CRASH_SERVER_URL'] = ( |
| 67 'http://127.0.0.1:%d/crash' % server.port) | 65 'http://127.0.0.1:%d/crash' % server.port) |
| 68 | 66 |
| 69 # Launch Chrome and navigate it to the test URL. | 67 # Launch Chrome and navigate it to the test URL. |
| 70 chrome = kasko.process.ChromeInstance(options.chromedriver, | 68 chrome = kasko.process.ChromeInstance(options.chromedriver, |
| 71 options.chrome, user_data_dir) | 69 options.chrome, user_data_dir) |
| 72 with kasko.util.ScopedStartStop(chrome): | 70 with kasko.util.ScopedStartStop(chrome): |
| 73 _LOGGER.info('Navigating to Kasko debug URL') | 71 _LOGGER.info('Navigating to Kasko debug URL') |
| 74 chrome.navigate_to('chrome://kasko/send-report') | 72 chrome.navigate_to(url) |
| 75 | 73 |
| 76 _LOGGER.info('Waiting for Kasko report') | 74 _LOGGER.info('Waiting for Kasko report') |
| 77 if not server.wait_for_report(10): | 75 if not server.wait_for_report(timeout): |
| 78 raise Exception('No Kasko report received.') | 76 raise Exception('No Kasko report received.') |
| 79 | 77 |
| 78 # Verify a few crash keys. |
| 80 report = server.crash(0) | 79 report = server.crash(0) |
| 81 kasko.report.LogCrashKeys(report) | 80 kasko.report.LogCrashKeys(report) |
| 82 kasko.report.ValidateCrashReport(report, | 81 kasko.report.ValidateCrashReport(report, expected_keys) |
| 83 {'kasko-set-crash-key-value-impl': 'SetCrashKeyValueImpl'}) | |
| 84 | |
| 85 return 0 | |
| 86 | |
| 87 | |
| 88 if __name__ == '__main__': | |
| 89 sys.exit(Main()) | |
| OLD | NEW |