| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Class for running instrumentation tests on a single device.""" | 5 """Class for running instrumentation tests on a single device.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import sys | 10 import sys |
| 11 import time | 11 import time |
| 12 | 12 |
| 13 from pylib import constants | 13 from pylib import constants |
| 14 from pylib import flag_changer | 14 from pylib import flag_changer |
| 15 from pylib import valgrind_tools | 15 from pylib import valgrind_tools |
| 16 from pylib.base import base_test_result | 16 from pylib.base import base_test_result |
| 17 from pylib.base import base_test_runner | 17 from pylib.base import base_test_runner |
| 18 from pylib.device import device_errors | 18 from pylib.device import device_errors |
| 19 from pylib.instrumentation import json_perf_parser | 19 from pylib.instrumentation import json_perf_parser |
| 20 from pylib.instrumentation import test_result | 20 from pylib.instrumentation import test_result |
| 21 | 21 |
| 22 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', | 22 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', |
| 23 'common')) | 23 'common')) |
| 24 import perf_tests_results_helper # pylint: disable=F0401 | 24 import perf_tests_results_helper # pylint: disable=F0401 |
| 25 | 25 |
| 26 | 26 |
| 27 _PERF_TEST_ANNOTATION = 'PerfTest' | 27 _PERF_TEST_ANNOTATION = 'PerfTest' |
| 28 | 28 |
| 29 | 29 |
| 30 def _GetDataFilesForTestSuite(suite_basename): | |
| 31 """Returns a list of data files/dirs needed by the test suite. | |
| 32 | |
| 33 Args: | |
| 34 suite_basename: The test suite basename for which to return file paths. | |
| 35 | |
| 36 Returns: | |
| 37 A list of test file and directory paths. | |
| 38 """ | |
| 39 test_files = [] | |
| 40 if suite_basename in ['ChromeTest', 'ContentShellTest']: | |
| 41 test_files += [ | |
| 42 'net/data/ssl/certificates/', | |
| 43 ] | |
| 44 return test_files | |
| 45 | |
| 46 | |
| 47 class TestRunner(base_test_runner.BaseTestRunner): | 30 class TestRunner(base_test_runner.BaseTestRunner): |
| 48 """Responsible for running a series of tests connected to a single device.""" | 31 """Responsible for running a series of tests connected to a single device.""" |
| 49 | 32 |
| 50 _DEVICE_DATA_DIR = 'chrome/test/data' | |
| 51 _DEVICE_COVERAGE_DIR = 'chrome/test/coverage' | 33 _DEVICE_COVERAGE_DIR = 'chrome/test/coverage' |
| 52 _HOSTMACHINE_PERF_OUTPUT_FILE = '/tmp/chrome-profile' | 34 _HOSTMACHINE_PERF_OUTPUT_FILE = '/tmp/chrome-profile' |
| 53 _DEVICE_PERF_OUTPUT_SEARCH_PREFIX = (constants.DEVICE_PERF_OUTPUT_DIR + | 35 _DEVICE_PERF_OUTPUT_SEARCH_PREFIX = (constants.DEVICE_PERF_OUTPUT_DIR + |
| 54 '/chrome-profile*') | 36 '/chrome-profile*') |
| 55 _DEVICE_HAS_TEST_FILES = {} | |
| 56 | 37 |
| 57 def __init__(self, test_options, device, shard_index, test_pkg, | 38 def __init__(self, test_options, device, shard_index, test_pkg, |
| 58 additional_flags=None): | 39 additional_flags=None): |
| 59 """Create a new TestRunner. | 40 """Create a new TestRunner. |
| 60 | 41 |
| 61 Args: | 42 Args: |
| 62 test_options: An InstrumentationOptions object. | 43 test_options: An InstrumentationOptions object. |
| 63 device: Attached android device. | 44 device: Attached android device. |
| 64 shard_index: Shard index. | 45 shard_index: Shard index. |
| 65 test_pkg: A TestPackage object. | 46 test_pkg: A TestPackage object. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 83 self.flags = flag_changer.FlagChanger(self.device, cmdline_file[0]) | 64 self.flags = flag_changer.FlagChanger(self.device, cmdline_file[0]) |
| 84 if additional_flags: | 65 if additional_flags: |
| 85 self.flags.AddFlags(additional_flags) | 66 self.flags.AddFlags(additional_flags) |
| 86 else: | 67 else: |
| 87 self.flags = None | 68 self.flags = None |
| 88 | 69 |
| 89 #override | 70 #override |
| 90 def InstallTestPackage(self): | 71 def InstallTestPackage(self): |
| 91 self.test_pkg.Install(self.device) | 72 self.test_pkg.Install(self.device) |
| 92 | 73 |
| 93 #override | |
| 94 def PushDataDeps(self): | |
| 95 # TODO(frankf): Implement a general approach for copying/installing | |
| 96 # once across test runners. | |
| 97 if TestRunner._DEVICE_HAS_TEST_FILES.get(self.device, False): | |
| 98 logging.warning('Already copied test files to device %s, skipping.', | |
| 99 str(self.device)) | |
| 100 return | |
| 101 | |
| 102 host_device_file_tuples = [] | |
| 103 test_data = _GetDataFilesForTestSuite(self.test_pkg.GetApkName()) | |
| 104 if test_data: | |
| 105 # Make sure SD card is ready. | |
| 106 self.device.WaitUntilFullyBooted(timeout=20) | |
| 107 host_device_file_tuples += [ | |
| 108 (os.path.join(constants.DIR_SOURCE_ROOT, p), | |
| 109 os.path.join(self.device.GetExternalStoragePath(), p)) | |
| 110 for p in test_data] | |
| 111 | |
| 112 # TODO(frankf): Specify test data in this file as opposed to passing | |
| 113 # as command-line. | |
| 114 for dest_host_pair in self.options.test_data: | |
| 115 dst_src = dest_host_pair.split(':', 1) | |
| 116 dst_layer = dst_src[0] | |
| 117 host_src = dst_src[1] | |
| 118 host_test_files_path = os.path.join(constants.DIR_SOURCE_ROOT, | |
| 119 host_src) | |
| 120 if os.path.exists(host_test_files_path): | |
| 121 host_device_file_tuples += [( | |
| 122 host_test_files_path, | |
| 123 '%s/%s/%s' % ( | |
| 124 self.device.GetExternalStoragePath(), | |
| 125 TestRunner._DEVICE_DATA_DIR, | |
| 126 dst_layer))] | |
| 127 if host_device_file_tuples: | |
| 128 self.device.PushChangedFiles(host_device_file_tuples) | |
| 129 self.tool.CopyFiles(self.device) | |
| 130 TestRunner._DEVICE_HAS_TEST_FILES[str(self.device)] = True | |
| 131 | |
| 132 def _GetInstrumentationArgs(self): | 74 def _GetInstrumentationArgs(self): |
| 133 ret = {} | 75 ret = {} |
| 134 if self.options.wait_for_debugger: | 76 if self.options.wait_for_debugger: |
| 135 ret['debug'] = 'true' | 77 ret['debug'] = 'true' |
| 136 if self.coverage_dir: | 78 if self.coverage_dir: |
| 137 ret['coverage'] = 'true' | 79 ret['coverage'] = 'true' |
| 138 ret['coverageFile'] = self.coverage_device_file | 80 ret['coverageFile'] = self.coverage_device_file |
| 139 | 81 |
| 140 return ret | 82 return ret |
| 141 | 83 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 except device_errors.CommandTimeoutError as e: | 450 except device_errors.CommandTimeoutError as e: |
| 509 results.AddResult(test_result.InstrumentationTestResult( | 451 results.AddResult(test_result.InstrumentationTestResult( |
| 510 test, base_test_result.ResultType.TIMEOUT, start_ms, duration_ms, | 452 test, base_test_result.ResultType.TIMEOUT, start_ms, duration_ms, |
| 511 log=str(e) or 'No information')) | 453 log=str(e) or 'No information')) |
| 512 except device_errors.DeviceUnreachableError as e: | 454 except device_errors.DeviceUnreachableError as e: |
| 513 results.AddResult(test_result.InstrumentationTestResult( | 455 results.AddResult(test_result.InstrumentationTestResult( |
| 514 test, base_test_result.ResultType.CRASH, start_ms, duration_ms, | 456 test, base_test_result.ResultType.CRASH, start_ms, duration_ms, |
| 515 log=str(e) or 'No information')) | 457 log=str(e) or 'No information')) |
| 516 self.TestTeardown(test, results) | 458 self.TestTeardown(test, results) |
| 517 return (results, None if results.DidRunPass() else test) | 459 return (results, None if results.DidRunPass() else test) |
| OLD | NEW |