 Chromium Code Reviews
 Chromium Code Reviews Issue 1415533007:
  [Android] Add sharding for AMP instrumentation tests.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1415533007:
  [Android] Add sharding for AMP instrumentation tests.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: build/android/pylib/remote/device/remote_device_gtest_run.py | 
| diff --git a/build/android/pylib/remote/device/remote_device_gtest_run.py b/build/android/pylib/remote/device/remote_device_gtest_run.py | 
| index 0cfe717615bbd85a06c4481459b4f717f9094e62..e9295fdbb2832f8bbbfbf7335f444d1fa55ce41b 100644 | 
| --- a/build/android/pylib/remote/device/remote_device_gtest_run.py | 
| +++ b/build/android/pylib/remote/device/remote_device_gtest_run.py | 
| @@ -7,7 +7,10 @@ | 
| import logging | 
| import os | 
| import tempfile | 
| +import zipfile | 
| +from devil.utils import reraiser_thread | 
| +from devil.utils import zip_utils | 
| from pylib import constants | 
| from pylib.base import base_test_result | 
| from pylib.gtest import gtest_test_instance | 
| @@ -23,19 +26,32 @@ class RemoteDeviceGtestTestRun(remote_device_test_run.RemoteDeviceTestRun): | 
| DEFAULT_RUNNER_PACKAGE = ( | 
| 'org.chromium.native_test.NativeTestInstrumentationTestRunner') | 
| + _INSTRUMENTATION_STREAM_LEADER = 'INSTRUMENTATION_STATUS: stream=' | 
| #override | 
| def TestPackage(self): | 
| return self._test_instance.suite | 
| #override | 
| - def _TriggerSetUp(self): | 
| - """Set up the triggering of a test run.""" | 
| - logging.info('Triggering test run.') | 
| + def _GetAppPath(self): | 
| + return os.path.join( | 
| + constants.GetOutDirectory(), 'apks', 'remote_device_dummy.apk') | 
| + | 
| + #override | 
| + def _GetTestFramework(self): | 
| + if self._env.test_framework: | 
| + logging.warning('Ignoring configured test_framework "%s"', | 
| + self._env.test_framework) | 
| + return 'robotium' | 
| + | 
| + #override | 
| + def _ShouldShard(self): | 
| + return False | 
| 
rnephew (Wrong account)
2015/11/04 22:22:02
Instead of having remote_device_run.py have this r
 
mikecase (-- gone --)
2015/11/05 23:17:41
Done.
 | 
| - if self._env.runner_type: | 
| - logging.warning('Ignoring configured runner_type "%s"', | 
| - self._env.runner_type) | 
| + # pylint: disable=protected-access | 
| + #override | 
| + def _SetupTestShards(self, num_shards): | 
| + test_ids = [] | 
| if not self._env.runner_package: | 
| runner_package = self.DEFAULT_RUNNER_PACKAGE | 
| @@ -44,10 +60,6 @@ class RemoteDeviceGtestTestRun(remote_device_test_run.RemoteDeviceTestRun): | 
| else: | 
| runner_package = self._env.runner_package | 
| - dummy_app_path = os.path.join( | 
| - constants.GetOutDirectory(), 'apks', 'remote_device_dummy.apk') | 
| - | 
| - # pylint: disable=protected-access | 
| with tempfile.NamedTemporaryFile(suffix='.flags.txt') as flag_file: | 
| env_vars = dict(self._test_instance.extras) | 
| if gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT not in env_vars: | 
| @@ -67,23 +79,57 @@ class RemoteDeviceGtestTestRun(remote_device_test_run.RemoteDeviceTestRun): | 
| flag_file.write('_ ' + ' '.join(flags)) | 
| flag_file.flush() | 
| env_vars[_EXTRA_COMMAND_LINE_FILE] = os.path.basename(flag_file.name) | 
| - self._test_instance._data_deps.append( | 
| - (os.path.abspath(flag_file.name), None)) | 
| - self._AmInstrumentTestSetup( | 
| - dummy_app_path, self._test_instance.apk, runner_package, | 
| - environment_variables=env_vars) | 
| - _INSTRUMENTATION_STREAM_LEADER = 'INSTRUMENTATION_STATUS: stream=' | 
| + with tempfile.NamedTemporaryFile(suffix='.zip') as test_package: | 
| + data_deps = (self._test_instance.GetDataDependencies() + | 
| + [(os.path.abspath(flag_file.name), None)]) | 
| + | 
| + sdcard_files = [] | 
| + host_test = os.path.basename(self._test_instance.apk) | 
| + with zipfile.ZipFile(test_package.name, 'w') as zip_file: | 
| + zip_file.write( | 
| + self._test_instance.apk, host_test, zipfile.ZIP_DEFLATED) | 
| + for h, _ in data_deps: | 
| + if os.path.isdir(h): | 
| + zip_utils.WriteToZipFile(zip_file, h, '.') | 
| + sdcard_files.extend(os.listdir(h)) | 
| + else: | 
| + zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h)) | 
| + sdcard_files.append(os.path.basename(h)) | 
| + | 
| + framework_configs = { | 
| + 'runner': runner_package, | 
| + 'sdcard_files': ','.join(sdcard_files), | 
| + 'host_test': host_test, | 
| + 'environment_vars': ','.join( | 
| + '%s=%s' % (k, v) for k, v in env_vars.iteritems()) | 
| + } | 
| + | 
| + def upload_test_shards(): | 
| + test_id = self._UploadTestToDevice(test_package.name) | 
| + self._UploadTestConfigToDevice( | 
| + test_id, framework_configs, self._appurify_configs) | 
| + test_ids.append(test_id) | 
| + | 
| + workers = reraiser_thread.ReraiserThreadGroup( | 
| + [reraiser_thread.ReraiserThread( | 
| + upload_test_shards, | 
| + name='upload test shard %d' % i) | 
| + for i in xrange(num_shards)]) | 
| + workers.StartAll() | 
| + workers.JoinAll() | 
| + return test_ids | 
| #override | 
| - def _ParseTestResults(self): | 
| + def _ParseTestResults(self, test_output, results_zip): | 
| logging.info('Parsing results from stdout.') | 
| results = base_test_result.TestRunResults() | 
| - output = self._results['results']['output'].splitlines() | 
| + output = test_output['results']['output'].splitlines() | 
| output = (l[len(self._INSTRUMENTATION_STREAM_LEADER):] for l in output | 
| if l.startswith(self._INSTRUMENTATION_STREAM_LEADER)) | 
| results_list = self._test_instance.ParseGTestOutput(output) | 
| results.AddResults(results_list) | 
| - self._DetectPlatformErrors(results) | 
| + remote_device_test_run.DetectPlatformErrors( | 
| + results, test_output, results_zip) | 
| return results |