Chromium Code Reviews| 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 """Run specific test on specific environment.""" | 5 """Run specific test on specific environment.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import tempfile | 9 import tempfile |
| 10 import zipfile | |
| 10 | 11 |
| 12 from devil.utils import zip_utils | |
| 11 from pylib import constants | 13 from pylib import constants |
| 12 from pylib.base import base_test_result | 14 from pylib.base import base_test_result |
| 13 from pylib.gtest import gtest_test_instance | 15 from pylib.gtest import gtest_test_instance |
| 14 from pylib.remote.device import remote_device_test_run | 16 from pylib.remote.device import remote_device_test_run |
| 15 | 17 |
| 16 | 18 |
| 17 _EXTRA_COMMAND_LINE_FILE = ( | 19 _EXTRA_COMMAND_LINE_FILE = ( |
| 18 'org.chromium.native_test.NativeTestActivity.CommandLineFile') | 20 'org.chromium.native_test.NativeTestActivity.CommandLineFile') |
| 19 | 21 |
| 20 | 22 |
| 21 class RemoteDeviceGtestTestRun(remote_device_test_run.RemoteDeviceTestRun): | 23 class RemoteDeviceGtestTestRun(remote_device_test_run.RemoteDeviceTestRun): |
| 22 """Run gtests and uirobot tests on a remote device.""" | 24 """Run gtests and uirobot tests on a remote device.""" |
| 23 | 25 |
| 24 DEFAULT_RUNNER_PACKAGE = ( | 26 DEFAULT_RUNNER_PACKAGE = ( |
| 25 'org.chromium.native_test.NativeTestInstrumentationTestRunner') | 27 'org.chromium.native_test.NativeTestInstrumentationTestRunner') |
| 28 _INSTRUMENTATION_STREAM_LEADER = 'INSTRUMENTATION_STATUS: stream=' | |
| 26 | 29 |
| 27 #override | 30 #override |
| 28 def TestPackage(self): | 31 def TestPackage(self): |
| 29 return self._test_instance.suite | 32 return self._test_instance.suite |
| 30 | 33 |
| 31 #override | 34 #override |
| 32 def _TriggerSetUp(self): | 35 def _GetAppPath(self): |
| 33 """Set up the triggering of a test run.""" | 36 return os.path.join( |
| 34 logging.info('Triggering test run.') | 37 constants.GetOutDirectory(), 'apks', 'remote_device_dummy.apk') |
| 35 | 38 |
| 36 if self._env.runner_type: | 39 #override |
| 37 logging.warning('Ignoring configured runner_type "%s"', | 40 def _GetTestFramework(self): |
| 38 self._env.runner_type) | 41 if self._env.test_framework: |
| 42 logging.warning('Ignoring configured test_framework "%s"', | |
| 43 self._env.test_framework) | |
| 44 return 'robotium' | |
| 45 | |
| 46 # pylint: disable=protected-access | |
| 47 #override | |
| 48 def _SetupTestShards(self, num_shards): | |
| 49 test_ids = [] | |
| 39 | 50 |
| 40 if not self._env.runner_package: | 51 if not self._env.runner_package: |
| 41 runner_package = self.DEFAULT_RUNNER_PACKAGE | 52 runner_package = self.DEFAULT_RUNNER_PACKAGE |
| 42 logging.info('Using default runner package: %s', | 53 logging.info('Using default runner package: %s', |
| 43 self.DEFAULT_RUNNER_PACKAGE) | 54 self.DEFAULT_RUNNER_PACKAGE) |
| 44 else: | 55 else: |
| 45 runner_package = self._env.runner_package | 56 runner_package = self._env.runner_package |
| 46 | 57 |
| 47 dummy_app_path = os.path.join( | |
| 48 constants.GetOutDirectory(), 'apks', 'remote_device_dummy.apk') | |
| 49 | |
| 50 # pylint: disable=protected-access | |
| 51 with tempfile.NamedTemporaryFile(suffix='.flags.txt') as flag_file: | 58 with tempfile.NamedTemporaryFile(suffix='.flags.txt') as flag_file: |
| 52 env_vars = dict(self._test_instance.extras) | 59 env_vars = dict(self._test_instance.extras) |
| 53 if gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT not in env_vars: | 60 if gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT not in env_vars: |
| 54 env_vars[gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT] = int( | 61 env_vars[gtest_test_instance.EXTRA_SHARD_NANO_TIMEOUT] = int( |
| 55 self._test_instance.shard_timeout * 1e9) | 62 self._test_instance.shard_timeout * 1e9) |
| 56 | 63 |
| 57 flags = [] | 64 flags = [] |
| 58 | 65 |
| 59 filter_string = self._test_instance._GenerateDisabledFilterString(None) | 66 filter_string = self._test_instance._GenerateDisabledFilterString(None) |
| 60 if filter_string: | 67 if filter_string: |
| 61 flags.append('--gtest_filter=%s' % filter_string) | 68 flags.append('--gtest_filter=%s' % filter_string) |
| 62 | 69 |
| 63 if self._test_instance.test_arguments: | 70 if self._test_instance.test_arguments: |
| 64 flags.append(self._test_instance.test_arguments) | 71 flags.append(self._test_instance.test_arguments) |
| 65 | 72 |
| 66 if flags: | 73 if flags: |
| 67 flag_file.write('_ ' + ' '.join(flags)) | 74 flag_file.write('_ ' + ' '.join(flags)) |
| 68 flag_file.flush() | 75 flag_file.flush() |
| 69 env_vars[_EXTRA_COMMAND_LINE_FILE] = os.path.basename(flag_file.name) | 76 env_vars[_EXTRA_COMMAND_LINE_FILE] = os.path.basename(flag_file.name) |
| 70 self._test_instance._data_deps.append( | |
| 71 (os.path.abspath(flag_file.name), None)) | |
| 72 self._AmInstrumentTestSetup( | |
| 73 dummy_app_path, self._test_instance.apk, runner_package, | |
| 74 environment_variables=env_vars) | |
| 75 | 77 |
| 76 _INSTRUMENTATION_STREAM_LEADER = 'INSTRUMENTATION_STATUS: stream=' | 78 with tempfile.NamedTemporaryFile(suffix='.zip') as test_package: |
| 79 data_deps = (self._test_instance.GetDataDependencies() + | |
| 80 [(os.path.abspath(flag_file.name), None)]) | |
| 81 | |
| 82 sdcard_files = [] | |
| 83 host_test = os.path.basename(self._test_instance.apk) | |
| 84 with zipfile.ZipFile(test_package.name, 'w') as zip_file: | |
|
jbudorick
2015/11/17 18:04:46
Why is zip creation moving down here...?
mikecase (-- gone --)
2015/11/19 01:35:37
Reorganizing.
| |
| 85 zip_file.write( | |
| 86 self._test_instance.apk, host_test, zipfile.ZIP_DEFLATED) | |
| 87 for h, _ in data_deps: | |
| 88 if os.path.isdir(h): | |
| 89 zip_utils.WriteToZipFile(zip_file, h, '.') | |
| 90 sdcard_files.extend(os.listdir(h)) | |
| 91 else: | |
| 92 zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h)) | |
| 93 sdcard_files.append(os.path.basename(h)) | |
| 94 | |
| 95 framework_configs = { | |
| 96 'runner': runner_package, | |
| 97 'sdcard_files': ','.join(sdcard_files), | |
| 98 'host_test': host_test, | |
| 99 'environment_vars': ','.join( | |
| 100 '%s=%s' % (k, v) for k, v in env_vars.iteritems()) | |
| 101 } | |
| 102 | |
| 103 test_id = self._UploadTestToDevice(test_package.name) | |
| 104 self._UploadTestConfigToDevice( | |
| 105 test_id, framework_configs, self._appurify_configs) | |
| 106 test_ids.append(test_id) | |
| 107 | |
| 108 return test_ids | |
| 77 | 109 |
| 78 #override | 110 #override |
| 79 def _ParseTestResults(self): | 111 def _ParseTestResults(self, test_output, results_zip): |
| 80 logging.info('Parsing results from stdout.') | 112 logging.info('Parsing results from stdout.') |
| 81 results = base_test_result.TestRunResults() | 113 results = base_test_result.TestRunResults() |
| 82 output = self._results['results']['output'].splitlines() | 114 output = test_output['results']['output'].splitlines() |
| 83 output = (l[len(self._INSTRUMENTATION_STREAM_LEADER):] for l in output | 115 output = (l[len(self._INSTRUMENTATION_STREAM_LEADER):] for l in output |
| 84 if l.startswith(self._INSTRUMENTATION_STREAM_LEADER)) | 116 if l.startswith(self._INSTRUMENTATION_STREAM_LEADER)) |
| 85 results_list = self._test_instance.ParseGTestOutput(output) | 117 results_list = self._test_instance.ParseGTestOutput(output) |
| 86 results.AddResults(results_list) | 118 results.AddResults(results_list) |
| 87 | 119 |
| 88 self._DetectPlatformErrors(results) | 120 remote_device_test_run.DetectPlatformErrors( |
| 121 results, test_output, results_zip) | |
| 89 return results | 122 return results |
| OLD | NEW |