| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 | 5 import itertools |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import posixpath |
| 8 | 9 |
| 9 from pylib import constants | 10 from pylib import constants |
| 10 from pylib import ports | 11 from pylib import ports |
| 11 from pylib.base import test_run | 12 from pylib.base import test_run |
| 12 from pylib.device import device_errors | 13 from pylib.device import device_errors |
| 13 from pylib.gtest import gtest_test_instance | 14 from pylib.gtest import gtest_test_instance |
| 14 | 15 |
| 15 from pylib.local import local_test_server_spawner | 16 from pylib.local import local_test_server_spawner |
| 16 from pylib.local.device import local_device_environment | 17 from pylib.local.device import local_device_environment |
| 17 from pylib.local.device import local_device_test_run | 18 from pylib.local.device import local_device_test_run |
| (...skipping 12 matching lines...) Expand all Loading... |
| 30 | 31 |
| 31 _MAX_SHARD_SIZE = 256 | 32 _MAX_SHARD_SIZE = 256 |
| 32 | 33 |
| 33 # TODO(jbudorick): Move this up to the test instance if the net test server is | 34 # TODO(jbudorick): Move this up to the test instance if the net test server is |
| 34 # handled outside of the APK for the remote_device environment. | 35 # handled outside of the APK for the remote_device environment. |
| 35 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ | 36 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ |
| 36 'components_browsertests', 'content_unittests', 'content_browsertests', | 37 'components_browsertests', 'content_unittests', 'content_browsertests', |
| 37 'net_unittests', 'unit_tests' | 38 'net_unittests', 'unit_tests' |
| 38 ] | 39 ] |
| 39 | 40 |
| 41 # TODO(jbudorick): Move this inside _ApkDelegate once TestPackageApk is gone. |
| 42 def PullAppFilesImpl(device, package, files, directory): |
| 43 device_dir = device.GetApplicationDataDirectory(package) |
| 44 host_dir = os.path.join(directory, str(device)) |
| 45 for f in files: |
| 46 device_file = posixpath.join(device_dir, f) |
| 47 host_file = os.path.join(host_dir, *f.split(posixpath.sep)) |
| 48 host_file_base, ext = os.path.splitext(host_file) |
| 49 for i in itertools.count(): |
| 50 host_file = '%s_%d%s' % (host_file_base, i, ext) |
| 51 if not os.path.exists(host_file): |
| 52 break |
| 53 device.PullFile(device_file, host_file) |
| 54 |
| 40 class _ApkDelegate(object): | 55 class _ApkDelegate(object): |
| 41 def __init__(self, apk): | 56 def __init__(self, apk): |
| 42 self._apk = apk | 57 self._apk = apk |
| 43 | 58 |
| 44 helper = apk_helper.ApkHelper(self._apk) | 59 helper = apk_helper.ApkHelper(self._apk) |
| 45 self._activity = helper.GetActivityName() | 60 self._activity = helper.GetActivityName() |
| 46 self._package = helper.GetPackageName() | 61 self._package = helper.GetPackageName() |
| 47 self._runner = helper.GetInstrumentationName() | 62 self._runner = helper.GetInstrumentationName() |
| 48 self._component = '%s/%s' % (self._package, self._runner) | 63 self._component = '%s/%s' % (self._package, self._runner) |
| 49 self._enable_test_server_spawner = False | 64 self._enable_test_server_spawner = False |
| 50 | 65 |
| 51 def Install(self, device): | 66 def Install(self, device): |
| 52 device.Install(self._apk) | 67 device.Install(self._apk) |
| 53 | 68 |
| 54 def RunWithFlags(self, device, flags, **kwargs): | 69 def RunWithFlags(self, device, flags, **kwargs): |
| 55 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: | 70 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: |
| 56 device.WriteFile(command_line_file.name, '_ %s' % flags) | 71 device.WriteFile(command_line_file.name, '_ %s' % flags) |
| 57 | 72 |
| 58 extras = { | 73 extras = { |
| 59 _EXTRA_COMMAND_LINE_FILE: command_line_file.name, | 74 _EXTRA_COMMAND_LINE_FILE: command_line_file.name, |
| 60 _EXTRA_NATIVE_TEST_ACTIVITY: self._activity, | 75 _EXTRA_NATIVE_TEST_ACTIVITY: self._activity, |
| 61 } | 76 } |
| 62 | 77 |
| 63 return device.StartInstrumentation( | 78 return device.StartInstrumentation( |
| 64 self._component, extras=extras, raw=False, **kwargs) | 79 self._component, extras=extras, raw=False, **kwargs) |
| 65 | 80 |
| 81 def PullAppFiles(self, device, files, directory): |
| 82 PullAppFilesImpl(device, self._package, files, directory) |
| 83 |
| 66 def Clear(self, device): | 84 def Clear(self, device): |
| 67 device.ClearApplicationState(self._package) | 85 device.ClearApplicationState(self._package) |
| 68 | 86 |
| 69 | 87 |
| 70 class _ExeDelegate(object): | 88 class _ExeDelegate(object): |
| 71 def __init__(self, exe, tr): | 89 def __init__(self, exe, tr): |
| 72 self._exe_host_path = exe | 90 self._exe_host_path = exe |
| 73 self._exe_file_name = os.path.split(exe)[-1] | 91 self._exe_file_name = os.path.split(exe)[-1] |
| 74 self._exe_device_path = '%s/%s' % ( | 92 self._exe_device_path = '%s/%s' % ( |
| 75 constants.TEST_EXECUTABLE_DIR, self._exe_file_name) | 93 constants.TEST_EXECUTABLE_DIR, self._exe_file_name) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 # TODO(jbudorick): Switch to just RunShellCommand once perezju@'s CL | 130 # TODO(jbudorick): Switch to just RunShellCommand once perezju@'s CL |
| 113 # for long shell commands lands. | 131 # for long shell commands lands. |
| 114 with device_temp_file.DeviceTempFile(device.adb) as script_file: | 132 with device_temp_file.DeviceTempFile(device.adb) as script_file: |
| 115 script_contents = ' '.join(cmd) | 133 script_contents = ' '.join(cmd) |
| 116 logging.info('script contents: %r' % script_contents) | 134 logging.info('script contents: %r' % script_contents) |
| 117 device.WriteFile(script_file.name, script_contents) | 135 device.WriteFile(script_file.name, script_contents) |
| 118 output = device.RunShellCommand(['sh', script_file.name], cwd=cwd, | 136 output = device.RunShellCommand(['sh', script_file.name], cwd=cwd, |
| 119 env=env, **kwargs) | 137 env=env, **kwargs) |
| 120 return output | 138 return output |
| 121 | 139 |
| 140 def PullAppFiles(self, device, files, directory): |
| 141 pass |
| 142 |
| 122 def Clear(self, device): | 143 def Clear(self, device): |
| 123 device.KillAll(self._exe_file_name, blocking=True, timeout=30, quiet=True) | 144 device.KillAll(self._exe_file_name, blocking=True, timeout=30, quiet=True) |
| 124 | 145 |
| 125 | 146 |
| 126 class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun): | 147 class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun): |
| 127 | 148 |
| 128 def __init__(self, env, test_instance): | 149 def __init__(self, env, test_instance): |
| 129 assert isinstance(env, local_device_environment.LocalDeviceEnvironment) | 150 assert isinstance(env, local_device_environment.LocalDeviceEnvironment) |
| 130 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance) | 151 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance) |
| 131 super(LocalDeviceGtestRun, self).__init__(env, test_instance) | 152 super(LocalDeviceGtestRun, self).__init__(env, test_instance) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 tests = self._test_instance.FilterTests(tests) | 213 tests = self._test_instance.FilterTests(tests) |
| 193 return tests | 214 return tests |
| 194 | 215 |
| 195 #override | 216 #override |
| 196 def _RunTest(self, device, test): | 217 def _RunTest(self, device, test): |
| 197 # Run the test. | 218 # Run the test. |
| 198 output = self._delegate.RunWithFlags( | 219 output = self._delegate.RunWithFlags( |
| 199 device, '--gtest_filter=%s' % test, timeout=900, retries=0) | 220 device, '--gtest_filter=%s' % test, timeout=900, retries=0) |
| 200 for s in self._servers[str(device)]: | 221 for s in self._servers[str(device)]: |
| 201 s.Reset() | 222 s.Reset() |
| 223 if self._test_instance.app_files: |
| 224 self._delegate.PullAppFiles(device, self._test_instance.app_files, |
| 225 self._test_instance.app_file_dir) |
| 202 self._delegate.Clear(device) | 226 self._delegate.Clear(device) |
| 203 | 227 |
| 204 # Parse the output. | 228 # Parse the output. |
| 205 # TODO(jbudorick): Transition test scripts away from parsing stdout. | 229 # TODO(jbudorick): Transition test scripts away from parsing stdout. |
| 206 results = self._test_instance.ParseGTestOutput(output) | 230 results = self._test_instance.ParseGTestOutput(output) |
| 207 return results | 231 return results |
| 208 | 232 |
| 209 #override | 233 #override |
| 210 def TearDown(self): | 234 def TearDown(self): |
| 211 def individual_device_tear_down(dev): | 235 def individual_device_tear_down(dev): |
| 212 for s in self._servers[str(dev)]: | 236 for s in self._servers[str(dev)]: |
| 213 s.TearDown() | 237 s.TearDown() |
| 214 | 238 |
| 215 self._env.parallel_devices.pMap(individual_device_tear_down) | 239 self._env.parallel_devices.pMap(individual_device_tear_down) |
| 216 | 240 |
| OLD | NEW |