| 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 import itertools | 5 import itertools |
| 6 import os | 6 import os |
| 7 import posixpath | 7 import posixpath |
| 8 | 8 |
| 9 from devil.android import device_errors | 9 from devil.android import device_errors |
| 10 from devil.android import device_temp_file | 10 from devil.android import device_temp_file |
| 11 from devil.android import ports | 11 from devil.android import ports |
| 12 from pylib import constants | 12 from pylib import constants |
| 13 from pylib.gtest import gtest_test_instance | 13 from pylib.gtest import gtest_test_instance |
| 14 from pylib.local import local_test_server_spawner | 14 from pylib.local import local_test_server_spawner |
| 15 from pylib.local.device import local_device_environment | 15 from pylib.local.device import local_device_environment |
| 16 from pylib.local.device import local_device_test_run | 16 from pylib.local.device import local_device_test_run |
| 17 | 17 |
| 18 _COMMAND_LINE_FLAGS_SUPPORTED = True | 18 _COMMAND_LINE_FLAGS_SUPPORTED = True |
| 19 | 19 |
| 20 _EXTRA_COMMAND_LINE_FILE = ( | 20 _EXTRA_COMMAND_LINE_FILE = ( |
| 21 'org.chromium.native_test.NativeTestActivity.CommandLineFile') | 21 'org.chromium.native_test.NativeTestActivity.CommandLineFile') |
| 22 _EXTRA_COMMAND_LINE_FLAGS = ( | 22 _EXTRA_COMMAND_LINE_FLAGS = ( |
| 23 'org.chromium.native_test.NativeTestActivity.CommandLineFlags') | 23 'org.chromium.native_test.NativeTestActivity.CommandLineFlags') |
| 24 _EXTRA_SHARD_NANO_TIMEOUT = ( |
| 25 'org.chromium.native_test.NativeTestInstrumentationTestRunner' |
| 26 '.ShardNanoTimeout') |
| 24 _EXTRA_TEST_LIST = ( | 27 _EXTRA_TEST_LIST = ( |
| 25 'org.chromium.native_test.NativeTestInstrumentationTestRunner' | 28 'org.chromium.native_test.NativeTestInstrumentationTestRunner' |
| 26 '.TestList') | 29 '.TestList') |
| 27 | 30 |
| 28 _MAX_SHARD_SIZE = 256 | 31 _MAX_SHARD_SIZE = 256 |
| 32 _SECONDS_TO_NANOS = int(1e9) |
| 29 | 33 |
| 30 # 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 |
| 31 # handled outside of the APK for the remote_device environment. | 35 # handled outside of the APK for the remote_device environment. |
| 32 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ | 36 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ |
| 33 'components_browsertests', 'content_unittests', 'content_browsertests', | 37 'components_browsertests', 'content_unittests', 'content_browsertests', |
| 34 'net_unittests', 'unit_tests' | 38 'net_unittests', 'unit_tests' |
| 35 ] | 39 ] |
| 36 | 40 |
| 37 # TODO(jbudorick): Move this inside _ApkDelegate once TestPackageApk is gone. | 41 # TODO(jbudorick): Move this inside _ApkDelegate once TestPackageApk is gone. |
| 38 def PullAppFilesImpl(device, package, files, directory): | 42 def PullAppFilesImpl(device, package, files, directory): |
| (...skipping 19 matching lines...) Expand all Loading... |
| 58 | 62 |
| 59 self._component = '%s/%s' % (self._package, self._runner) | 63 self._component = '%s/%s' % (self._package, self._runner) |
| 60 self._extras = test_instance.extras | 64 self._extras = test_instance.extras |
| 61 | 65 |
| 62 def Install(self, device): | 66 def Install(self, device): |
| 63 device.Install(self._apk, permissions=self._permissions) | 67 device.Install(self._apk, permissions=self._permissions) |
| 64 | 68 |
| 65 def Run(self, test, device, flags=None, **kwargs): | 69 def Run(self, test, device, flags=None, **kwargs): |
| 66 extras = dict(self._extras) | 70 extras = dict(self._extras) |
| 67 | 71 |
| 72 if 'timeout' in kwargs: |
| 73 # Make sure the instrumentation doesn't kill the test before the |
| 74 # scripts do. The provided timeout value is in seconds, but the |
| 75 # instrumentation deals with nanoseconds because that's how Android |
| 76 # handles time. |
| 77 extras[_EXTRA_SHARD_NANO_TIMEOUT] = int( |
| 78 kwargs['timeout'] * _SECONDS_TO_NANOS) |
| 79 |
| 68 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: | 80 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: |
| 69 device.WriteFile(command_line_file.name, '_ %s' % flags if flags else '_') | 81 device.WriteFile(command_line_file.name, '_ %s' % flags if flags else '_') |
| 70 extras[_EXTRA_COMMAND_LINE_FILE] = command_line_file.name | 82 extras[_EXTRA_COMMAND_LINE_FILE] = command_line_file.name |
| 71 | 83 |
| 72 with device_temp_file.DeviceTempFile(device.adb) as test_list_file: | 84 with device_temp_file.DeviceTempFile(device.adb) as test_list_file: |
| 73 if test: | 85 if test: |
| 74 device.WriteFile(test_list_file.name, '\n'.join(test)) | 86 device.WriteFile(test_list_file.name, '\n'.join(test)) |
| 75 extras[_EXTRA_TEST_LIST] = test_list_file.name | 87 extras[_EXTRA_TEST_LIST] = test_list_file.name |
| 76 | 88 |
| 77 return device.StartInstrumentation( | 89 return device.StartInstrumentation( |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 243 |
| 232 # Parse the output. | 244 # Parse the output. |
| 233 # TODO(jbudorick): Transition test scripts away from parsing stdout. | 245 # TODO(jbudorick): Transition test scripts away from parsing stdout. |
| 234 results = self._test_instance.ParseGTestOutput(output) | 246 results = self._test_instance.ParseGTestOutput(output) |
| 235 return results | 247 return results |
| 236 | 248 |
| 237 #override | 249 #override |
| 238 def TearDown(self): | 250 def TearDown(self): |
| 239 @local_device_test_run.handle_shard_failures | 251 @local_device_test_run.handle_shard_failures |
| 240 def individual_device_tear_down(dev): | 252 def individual_device_tear_down(dev): |
| 241 for s in self._servers[str(dev)]: | 253 for s in self._servers.get(str(dev), []): |
| 242 s.TearDown() | 254 s.TearDown() |
| 243 | 255 |
| 244 self._env.parallel_devices.pMap(individual_device_tear_down) | 256 self._env.parallel_devices.pMap(individual_device_tear_down) |
| 245 | 257 |
| OLD | NEW |