| 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 collections | 5 import collections |
| 6 import itertools | 6 import itertools |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import posixpath | 9 import posixpath |
| 10 | 10 |
| 11 from devil.android import device_errors | 11 from devil.android import device_errors |
| 12 from devil.android import device_temp_file | 12 from devil.android import device_temp_file |
| 13 from devil.android import ports | 13 from devil.android import ports |
| 14 from devil.utils import reraiser_thread | 14 from devil.utils import reraiser_thread |
| 15 from pylib import constants | 15 from pylib import constants |
| 16 from pylib.base import base_test_result | 16 from pylib.base import base_test_result |
| 17 from pylib.gtest import gtest_test_instance | 17 from pylib.gtest import gtest_test_instance |
| 18 from pylib.local import local_test_server_spawner | 18 from pylib.local import local_test_server_spawner |
| 19 from pylib.local.device import local_device_environment | 19 from pylib.local.device import local_device_environment |
| 20 from pylib.local.device import local_device_test_run | 20 from pylib.local.device import local_device_test_run |
| 21 import tombstones | 21 import tombstones |
| 22 | 22 |
| 23 _MAX_INLINE_FLAGS_LENGTH = 50 # Arbitrarily chosen. | 23 _MAX_INLINE_FLAGS_LENGTH = 50 # Arbitrarily chosen. |
| 24 _EXTRA_COMMAND_LINE_FILE = ( | 24 _EXTRA_COMMAND_LINE_FILE = ( |
| 25 'org.chromium.native_test.NativeTest.CommandLineFile') | 25 'org.chromium.native_test.NativeTest.CommandLineFile') |
| 26 _EXTRA_COMMAND_LINE_FLAGS = ( | 26 _EXTRA_COMMAND_LINE_FLAGS = ( |
| 27 'org.chromium.native_test.NativeTest.CommandLineFlags') | 27 'org.chromium.native_test.NativeTest.CommandLineFlags') |
| 28 _EXTRA_STDOUT_FILE = ( |
| 29 'org.chromium.native_test.NativeTestInstrumentationTestRunner' |
| 30 '.StdoutFile') |
| 31 _EXTRA_TEST = ( |
| 32 'org.chromium.native_test.NativeTestInstrumentationTestRunner' |
| 33 '.Test') |
| 28 _EXTRA_TEST_LIST = ( | 34 _EXTRA_TEST_LIST = ( |
| 29 'org.chromium.native_test.NativeTestInstrumentationTestRunner' | 35 'org.chromium.native_test.NativeTestInstrumentationTestRunner' |
| 30 '.TestList') | 36 '.TestList') |
| 31 _EXTRA_TEST = ( | |
| 32 'org.chromium.native_test.NativeTestInstrumentationTestRunner' | |
| 33 '.Test') | |
| 34 | 37 |
| 35 _MAX_SHARD_SIZE = 256 | 38 _MAX_SHARD_SIZE = 256 |
| 36 _SECONDS_TO_NANOS = int(1e9) | 39 _SECONDS_TO_NANOS = int(1e9) |
| 37 | 40 |
| 38 # The amount of time a test executable may run before it gets killed. | 41 # The amount of time a test executable may run before it gets killed. |
| 39 _TEST_TIMEOUT_SECONDS = 30*60 | 42 _TEST_TIMEOUT_SECONDS = 30*60 |
| 40 | 43 |
| 41 # TODO(jbudorick): Move this up to the test instance if the net test server is | 44 # TODO(jbudorick): Move this up to the test instance if the net test server is |
| 42 # handled outside of the APK for the remote_device environment. | 45 # handled outside of the APK for the remote_device environment. |
| 43 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ | 46 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 149 |
| 147 test_list_file = _NullContextManager() | 150 test_list_file = _NullContextManager() |
| 148 if test: | 151 if test: |
| 149 if len(test) > 1: | 152 if len(test) > 1: |
| 150 test_list_file = device_temp_file.DeviceTempFile(device.adb) | 153 test_list_file = device_temp_file.DeviceTempFile(device.adb) |
| 151 device.WriteFile(test_list_file.name, '\n'.join(test)) | 154 device.WriteFile(test_list_file.name, '\n'.join(test)) |
| 152 extras[_EXTRA_TEST_LIST] = test_list_file.name | 155 extras[_EXTRA_TEST_LIST] = test_list_file.name |
| 153 else: | 156 else: |
| 154 extras[_EXTRA_TEST] = test[0] | 157 extras[_EXTRA_TEST] = test[0] |
| 155 | 158 |
| 156 with command_line_file, test_list_file: | 159 stdout_file = device_temp_file.DeviceTempFile( |
| 160 device.adb, dir=device.GetExternalStoragePath(), suffix='.gtest_out') |
| 161 extras[_EXTRA_STDOUT_FILE] = stdout_file.name |
| 162 |
| 163 with command_line_file, test_list_file, stdout_file: |
| 157 try: | 164 try: |
| 158 return device.StartInstrumentation( | 165 device.StartInstrumentation( |
| 159 self._component, extras=extras, raw=False, **kwargs) | 166 self._component, extras=extras, raw=False, **kwargs) |
| 167 except device_errors.CommandFailedError: |
| 168 logging.exception('gtest shard failed.') |
| 169 except device_errors.CommandTimeoutError: |
| 170 logging.exception('gtest shard timed out.') |
| 160 except Exception: | 171 except Exception: |
| 161 device.ForceStop(self._package) | 172 device.ForceStop(self._package) |
| 162 raise | 173 raise |
| 174 return device.ReadFile(stdout_file.name).splitlines() |
| 163 | 175 |
| 164 def PullAppFiles(self, device, files, directory): | 176 def PullAppFiles(self, device, files, directory): |
| 165 PullAppFilesImpl(device, self._package, files, directory) | 177 PullAppFilesImpl(device, self._package, files, directory) |
| 166 | 178 |
| 167 def Clear(self, device): | 179 def Clear(self, device): |
| 168 device.ClearApplicationState(self._package, permissions=self._permissions) | 180 device.ClearApplicationState(self._package, permissions=self._permissions) |
| 169 | 181 |
| 170 | 182 |
| 171 class _ExeDelegate(object): | 183 class _ExeDelegate(object): |
| 172 def __init__(self, tr, dist_dir): | 184 def __init__(self, tr, dist_dir): |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 def TearDown(self): | 428 def TearDown(self): |
| 417 @local_device_environment.handle_shard_failures | 429 @local_device_environment.handle_shard_failures |
| 418 def individual_device_tear_down(dev): | 430 def individual_device_tear_down(dev): |
| 419 for s in self._servers.get(str(dev), []): | 431 for s in self._servers.get(str(dev), []): |
| 420 s.TearDown() | 432 s.TearDown() |
| 421 | 433 |
| 422 tool = self.GetTool(dev) | 434 tool = self.GetTool(dev) |
| 423 tool.CleanUpEnvironment() | 435 tool.CleanUpEnvironment() |
| 424 | 436 |
| 425 self._env.parallel_devices.pMap(individual_device_tear_down) | 437 self._env.parallel_devices.pMap(individual_device_tear_down) |
| OLD | NEW |