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..f026773a66a3414cb304c64a6e13d7108fbc797c 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,12 @@ class LocalDeviceInstrumentationTestRun( |
| #override |
| def _GetTests(self): |
| - tests = self._test_instance.GetTests() |
| + tests = None |
| + if self._test_instance.junit4_runner_class: |
| + raw_tests = self._GetTestsFromRunner() |
| + tests = self._test_instance.ProcessRawTests(raw_tests) |
| + else: |
| + tests = self._test_instance.GetTests() |
| tests = self._ApplyExternalSharding( |
| tests, self._test_instance.external_shard_index, |
| self._test_instance.total_external_shards) |
| @@ -371,10 +380,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 +561,56 @@ 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) |
| + def list_tests(dev): |
|
jbudorick
2017/07/24 22:24:38
nit: this is a lot to do in an exception; could yo
the real yoland
2017/07/24 23:25:42
Done
|
| + with device_temp_file.DeviceTempFile( |
| + dev.adb, suffix='.json', |
| + dir=dev.GetExternalStoragePath()) as dev_test_list_json: |
| + extras = {} |
| + extras['log'] = 'true' |
| + extras['package'] = '.'.join( |
| + self._test_instance.test_package.split('.')[:2]) |
| + extras[_EXTRA_TEST_LIST] = dev_test_list_json.name |
| + target = '%s/%s' % (test_package, junit4_runner_class) |
| + output_string = ''.join(dev.StartInstrumentation( |
| + target, extras=extras)) |
| + if output_string: |
| + raise device_errors.CommandFailedError( |
| + ('Test listing through %s failed on dev:\n%s. Are you using' |
|
jbudorick
2017/07/24 22:24:38
nit: for a multi-line string like this with multip
the real yoland
2017/07/24 23:25:42
Done
|
| + + ' the right JUnit runner (org.chromium.base.test.' |
| + + 'BaseChromiumAndroidJUnitRunner)?') % ( |
| + junit4_runner_class, output_string), dev.serial) |
| + with tempfile_ext.NamedTemporaryDirectory() as host_dir: |
| + host_file = os.path.join(host_dir, 'list_tests.json') |
| + dev.PullFile(dev_test_list_json.name, host_file) |
| + with open(host_file, 'r') as host_file: |
| + return json.load(host_file) |
| + |
| + raw_test_lists = self._env.parallel_devices.pMap(list_tests).pGet(None) |
| + |
| + # If all devices failed to list tests, raise an exception. |
| + # Check that tl is not None and is not empty. |
| + if all(not tl for tl in raw_test_lists): |
| + raise device_errors.CommandFailedError( |
| + 'Failed to list tests on any device') |
| + |
| + raw_tests = [tl for tl in raw_test_lists if tl][0] |
|
the real yoland
2017/07/24 21:08:34
Here I am simply getting the first viable raw test
|
| + |
| + 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: |