Index: build/android/pylib/remote/device/remote_device_test_run.py |
diff --git a/build/android/pylib/remote/device/remote_device_test_run.py b/build/android/pylib/remote/device/remote_device_test_run.py |
index e5d05d7d66fe6e66d5e3ae12ee6dc4d4e8dcc4bf..2144e2471348822b4413b07ab06656c67ab6f320 100644 |
--- a/build/android/pylib/remote/device/remote_device_test_run.py |
+++ b/build/android/pylib/remote/device/remote_device_test_run.py |
@@ -9,11 +9,13 @@ import os |
import sys |
import tempfile |
import time |
+import zipfile |
from pylib import constants |
from pylib.base import test_run |
from pylib.remote.device import appurify_sanitized |
from pylib.remote.device import remote_device_helper |
+from pylib.utils import zip_utils |
class RemoteDeviceTestRun(test_run.TestRun): |
"""Run gtests and uirobot tests on a remote device.""" |
@@ -35,13 +37,16 @@ class RemoteDeviceTestRun(test_run.TestRun): |
self._test_id = '' |
self._results = '' |
self._test_run_id = '' |
+ self._current_status = '' |
#override |
def RunTests(self): |
"""Run the test.""" |
if self._env.trigger: |
- test_start_res = appurify_sanitized.api.tests_run( |
- self._env.token, self._env.device, self._app_id, self._test_id) |
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
+ logging.WARNING): |
+ test_start_res = appurify_sanitized.api.tests_run( |
+ self._env.token, self._env.device, self._app_id, self._test_id) |
remote_device_helper.TestHttpResponse( |
test_start_res, 'Unable to run test.') |
self._test_run_id = test_start_res.json()['response']['test_run_id'] |
@@ -66,10 +71,12 @@ class RemoteDeviceTestRun(test_run.TestRun): |
#override |
def TearDown(self): |
"""Tear down the test run.""" |
- if (self._GetTestStatus(self._test_run_id) != self.COMPLETE |
- and self._env.collect): |
- test_abort_res = appurify_sanitized.api.tests_abort( |
- self._env.token, self._test_run_id, reason='Test runner exiting.') |
+ if (self._env.collect |
+ and self._GetTestStatus(self._test_run_id) != self.COMPLETE): |
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
+ logging.WARNING): |
+ test_abort_res = appurify_sanitized.api.tests_abort( |
+ self._env.token, self._test_run_id, reason='Test runner exiting.') |
remote_device_helper.TestHttpResponse(test_abort_res, |
'Unable to abort test.') |
@@ -101,7 +108,9 @@ class RemoteDeviceTestRun(test_run.TestRun): |
Args: |
test_name: Test to find the ID of. |
""" |
- test_list_res = appurify_sanitized.api.tests_list(self._env.token) |
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
+ logging.WARNING): |
+ test_list_res = appurify_sanitized.api.tests_list(self._env.token) |
remote_device_helper.TestHttpResponse(test_list_res, |
'Unable to get tests list.') |
for test in test_list_res.json()['response']: |
@@ -120,8 +129,10 @@ class RemoteDeviceTestRun(test_run.TestRun): |
logging.info('Downloading results to %s.' % results_path) |
if not os.path.exists(os.path.basename(results_path)): |
os.makedirs(os.path.basename(results_path)) |
- appurify_sanitized.utils.wget(self._results['results']['url'], |
- results_path) |
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
+ logging.WARNING): |
+ appurify_sanitized.utils.wget(self._results['results']['url'], |
+ results_path) |
def _GetTestStatus(self, test_run_id): |
"""Checks the state of the test, and sets self._results |
@@ -130,36 +141,72 @@ class RemoteDeviceTestRun(test_run.TestRun): |
test_run_id: Id of test on on remote service. |
""" |
- test_check_res = appurify_sanitized.api.tests_check_result(self._env.token, |
- test_run_id) |
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
+ logging.WARNING): |
+ test_check_res = appurify_sanitized.api.tests_check_result( |
+ self._env.token, test_run_id) |
remote_device_helper.TestHttpResponse(test_check_res, |
'Unable to get test status.') |
self._results = test_check_res.json()['response'] |
- logging.info('Test status: %s' % self._results['detailed_status']) |
+ if self._results['detailed_status'] != self._current_status: |
+ logging.info('Test status: %s', self._results['detailed_status']) |
+ self._current_status = self._results['detailed_status'] |
return self._results['status'] |
- def _UploadAppToDevice(self, apk_path): |
+ def _AmInstrumentTestSetup(self, app_path, test_path, runner_package): |
+ config = {'runner': runner_package} |
+ |
+ self._app_id = self._UploadAppToDevice(app_path) |
+ |
+ data_deps = self._test_instance.GetDataDependencies() |
+ if data_deps: |
+ with tempfile.NamedTemporaryFile(suffix='.zip') as test_with_deps: |
+ sdcard_files = [] |
+ host_test = os.path.basename(test_path) |
+ with zipfile.ZipFile(test_with_deps.name, 'w') as zip_file: |
+ zip_file.write(test_path, host_test, zipfile.ZIP_DEFLATED) |
+ for h, _ in data_deps: |
+ zip_utils.WriteToZipFile(zip_file, h, '.') |
+ if os.path.isdir(h): |
+ sdcard_files.extend(os.listdir(h)) |
+ else: |
+ sdcard_files.extend(h) |
+ config['sdcard_files'] = ','.join(sdcard_files) |
+ config['host_test'] = host_test |
+ self._test_id = self._UploadTestToDevice( |
+ 'robotium', test_with_deps.name) |
+ else: |
+ self._test_id = self._UploadTestToDevice('robotium', test_path) |
+ |
+ logging.info('Setting config: %s' % config) |
+ self._SetTestConfig('robotium', config) |
+ |
+ def _UploadAppToDevice(self, app_path): |
"""Upload app to device.""" |
- logging.info('Upload %s to remote service.' % apk_path) |
- apk_name = os.path.basename(apk_path) |
- with open(apk_path, 'rb') as apk_src: |
- upload_results = appurify_sanitized.api.apps_upload(self._env.token, |
- apk_src, 'raw', name=apk_name) |
+ logging.info('Uploading %s to remote service.', app_path) |
+ apk_name = os.path.basename(app_path) |
+ with open(app_path, 'rb') as apk_src: |
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
+ logging.WARNING): |
+ upload_results = appurify_sanitized.api.apps_upload( |
+ self._env.token, apk_src, 'raw', name=apk_name) |
remote_device_helper.TestHttpResponse( |
- upload_results, 'Unable to upload %s.' %(apk_path)) |
+ upload_results, 'Unable to upload %s.' % app_path) |
return upload_results.json()['response']['app_id'] |
- def _UploadTestToDevice(self, test_type): |
+ def _UploadTestToDevice(self, test_type, test_path): |
"""Upload test to device |
Args: |
test_type: Type of test that is being uploaded. Ex. uirobot, gtest.. |
""" |
- logging.info('Uploading %s to remote service.' % self._test_instance.apk) |
- with open(self._test_instance.apk, 'rb') as test_src: |
- upload_results = appurify_sanitized.api.tests_upload( |
- self._env.token, test_src, 'raw', test_type, app_id=self._app_id) |
+ logging.info('Uploading %s to remote service.' % test_path) |
+ with open(test_path, 'rb') as test_src: |
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
+ logging.WARNING): |
+ upload_results = appurify_sanitized.api.tests_upload( |
+ self._env.token, test_src, 'raw', test_type) |
remote_device_helper.TestHttpResponse(upload_results, |
- 'Unable to upload %s.' %(self._test_instance.apk)) |
+ 'Unable to upload %s.' % test_path) |
return upload_results.json()['response']['test_id'] |
def _SetTestConfig(self, runner_type, body): |
@@ -174,7 +221,9 @@ class RemoteDeviceTestRun(test_run.TestRun): |
config.write(''.join('%s\n' % l for l in config_data)) |
config.flush() |
config.seek(0) |
- config_response = appurify_sanitized.api.config_upload(self._env.token, |
- config, self._test_id) |
- remote_device_helper.TestHttpResponse(config_response, |
- 'Unable to upload test config.') |
+ with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
+ logging.WARNING): |
+ config_response = appurify_sanitized.api.config_upload( |
+ self._env.token, config, self._test_id) |
+ remote_device_helper.TestHttpResponse( |
+ config_response, 'Unable to upload test config.') |