Chromium Code Reviews| Index: build/android/pylib/local/device/local_device_instrumentation_test_run.py |
| diff --git a/build/android/pylib/local/device/local_device_instrumentation_test_run.py b/build/android/pylib/local/device/local_device_instrumentation_test_run.py |
| index 34e275d33fd53d0d36e64f5aea9ceb9ffb925a1c..d540b4d84f4f1cec37fef36f24b5f58e10f5ac23 100644 |
| --- a/build/android/pylib/local/device/local_device_instrumentation_test_run.py |
| +++ b/build/android/pylib/local/device/local_device_instrumentation_test_run.py |
| @@ -3,6 +3,7 @@ |
| # found in the LICENSE file. |
| import contextlib |
| +import json |
| import logging |
| import os |
| import posixpath |
| @@ -64,6 +65,9 @@ EXTRA_SCREENSHOT_FILE = ( |
| EXTRA_UI_CAPTURE_DIR = ( |
| 'org.chromium.base.test.util.Screenshooter.ScreenshotDir') |
| +_EXTRA_TEST_LIST = ( |
| + 'org.chromium.base.test.BaseChromiumAndroidJUnitRunner.TestList') |
| + |
| UI_CAPTURE_DIRS = ['chromium_tests_root', 'UiCapture'] |
| FEATURE_ANNOTATION = 'Feature' |
| @@ -88,8 +92,8 @@ def _LogTestEndpoints(device, test_name): |
| ['log', '-p', 'i', '-t', _TAG, 'END %s' % test_name], |
| check_return=True) |
| -# TODO(jbudorick): Make this private once the instrumentation test_runner is |
| -# deprecated. |
| +# TODO(jbudorick): Make this private once the instrumentation test_runner |
| +# is deprecated. |
| def DidPackageCrashOnDevice(package_name, device): |
| # Dismiss any error dialogs. Limit the number in case we have an error |
| # loop or we are failing to dismiss. |
| @@ -306,7 +310,10 @@ class LocalDeviceInstrumentationTestRun( |
| #override |
| def _GetTests(self): |
| - tests = self._test_instance.GetTests() |
| + raw_tests = None |
| + if self._test_instance.junit4_runner_class: |
| + raw_tests = self._GetTestsFromRunner() |
| + tests = self._test_instance.GetTests(raw_tests) |
| tests = self._ApplyExternalSharding( |
| tests, self._test_instance.external_shard_index, |
| self._test_instance.total_external_shards) |
| @@ -371,10 +378,11 @@ class LocalDeviceInstrumentationTestRun( |
| if test['is_junit4']: |
| target = '%s/%s' % ( |
| self._test_instance.test_package, |
| - self._test_instance.test_runner_junit4) |
| + self._test_instance.junit4_runner_class) |
| else: |
| target = '%s/%s' % ( |
| - self._test_instance.test_package, self._test_instance.test_runner) |
| + self._test_instance.test_package, |
| + self._test_instance.junit3_runner_class) |
| extras['class'] = test_name |
| if 'flags' in test and test['flags']: |
| flags_to_add.extend(test['flags']) |
| @@ -551,6 +559,44 @@ class LocalDeviceInstrumentationTestRun( |
| post_test_step_thread_group.JoinAll() |
| return results, None |
| + def _GetTestsFromRunner(self): |
| + test_apk_path = self._test_instance.test_apk.path |
| + pickle_path = '%s-runner.pickle' % test_apk_path |
| + try: |
| + raw_tests = instrumentation_test_instance.GetTestsFromPickle( |
| + pickle_path, test_apk_path) |
| + except instrumentation_test_instance.TestListPickleException as e: |
| + junit4_runner_class = self._test_instance.junit4_runner_class |
| + test_package = self._test_instance.test_package |
| + logging.info('Could not get tests from pickle: %s', e) |
| + logging.info('Getting tests by having %s list them.', |
| + self._test_instance.junit4_runner_class) |
| + device = self._env.devices[0] |
|
jbudorick
2017/07/24 04:01:06
We switched gtests over to using all devices a whi
the real yoland
2017/07/24 20:18:50
Cool, didn't know that
|
| + with device_temp_file.DeviceTempFile( |
| + device.adb, suffix='.json', |
| + dir=device.GetExternalStoragePath()) as device_test_list_json: |
| + extras = {} |
| + extras[_EXTRA_TEST_LIST] = device_test_list_json.name |
| + extras['log'] = 'true' |
| + extras['package'] = '.'.join( |
| + self._test_instance.test_package.split('.')[:2]) |
| + target = '%s/%s' % (test_package, junit4_runner_class) |
| + output_string = ''.join(device.StartInstrumentation( |
| + target, extras=extras)) |
| + if output_string: |
|
jbudorick
2017/07/24 04:01:06
Do we expect this to happen as part of normal oper
the real yoland
2017/07/24 20:18:50
It should never happen with BaseChromiumAndroidJUn
|
| + raise device_errors.CommandFailedError( |
| + 'Test listing through %s failed on device:\n%s' % ( |
| + junit4_runner_class, output_string), device.serial) |
| + with tempfile_ext.NamedTemporaryDirectory() as host_dir: |
| + host_file = os.path.join(host_dir, 'list_tests.json') |
| + device.PullFile(device_test_list_json.name, host_file) |
| + with open(host_file, 'r') as host_file: |
| + json_string = host_file.read() |
|
jbudorick
2017/07/24 04:01:06
nit: raw_tests = json.load(host_file)
the real yoland
2017/07/24 20:18:50
Done
|
| + raw_tests = json.loads(json_string) |
| + instrumentation_test_instance.SaveTestsToPickle( |
| + pickle_path, test_apk_path, raw_tests) |
| + return raw_tests |
| + |
| def _SaveScreenshot(self, device, screenshot_host_dir, screenshot_device_file, |
| test_name, results): |
| if screenshot_host_dir: |