Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2744)

Unified Diff: build/android/pylib/remote/device/remote_device_test_run.py

Issue 816543004: Update from https://crrev.com/308996 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 97e44b0951c3a283289ce862f59905096cea6978..e5d05d7d66fe6e66d5e3ae12ee6dc4d4e8dcc4bf 100644
--- a/build/android/pylib/remote/device/remote_device_test_run.py
+++ b/build/android/pylib/remote/device/remote_device_test_run.py
@@ -12,15 +12,9 @@ import time
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
-sys.path.append(os.path.join(
- constants.DIR_SOURCE_ROOT, 'third_party', 'requests', 'src'))
-sys.path.append(os.path.join(
- constants.DIR_SOURCE_ROOT, 'third_party', 'appurify-python', 'src'))
-import appurify.api
-import appurify.utils
-
class RemoteDeviceTestRun(test_run.TestRun):
"""Run gtests and uirobot tests on a remote device."""
@@ -40,32 +34,31 @@ class RemoteDeviceTestRun(test_run.TestRun):
self._app_id = ''
self._test_id = ''
self._results = ''
-
- def TestPackage(self):
- pass
+ self._test_run_id = ''
#override
def RunTests(self):
"""Run the test."""
if self._env.trigger:
- test_start_res = appurify.api.tests_run(
+ 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.')
- test_run_id = test_start_res.json()['response']['test_run_id']
+ self._test_run_id = test_start_res.json()['response']['test_run_id']
+ logging.info('Test run id: %s' % self._test_run_id)
if not self._env.collect:
assert isinstance(self._env.trigger, basestring), (
'File for storing test_run_id must be a string.')
with open(self._env.trigger, 'w') as test_run_id_file:
- test_run_id_file.write(test_run_id)
+ test_run_id_file.write(self._test_run_id)
if self._env.collect:
if not self._env.trigger:
assert isinstance(self._env.trigger, basestring), (
'File for storing test_run_id must be a string.')
with open(self._env.collect, 'r') as test_run_id_file:
- test_run_id = test_run_id_file.read()
- while self._GetTestStatus(test_run_id) != self.COMPLETE:
+ self._test_run_id = test_run_id_file.read().strip()
+ while self._GetTestStatus(self._test_run_id) != self.COMPLETE:
time.sleep(self.WAIT_TIME)
self._DownloadTestResults(self._env.results_path)
return self._ParseTestResults()
@@ -73,7 +66,12 @@ class RemoteDeviceTestRun(test_run.TestRun):
#override
def TearDown(self):
"""Tear down the test run."""
- pass
+ 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.')
+ remote_device_helper.TestHttpResponse(test_abort_res,
+ 'Unable to abort test.')
def __enter__(self):
"""Set up the test run when used as a context manager."""
@@ -103,7 +101,7 @@ class RemoteDeviceTestRun(test_run.TestRun):
Args:
test_name: Test to find the ID of.
"""
- test_list_res = appurify.api.tests_list(self._env.token)
+ 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']:
@@ -119,9 +117,11 @@ class RemoteDeviceTestRun(test_run.TestRun):
results_path: path to download results to.
"""
if results_path:
+ 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.utils.wget(self._results['results']['url'], results_path)
+ 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,18 +130,20 @@ class RemoteDeviceTestRun(test_run.TestRun):
test_run_id: Id of test on on remote service.
"""
- test_check_res = appurify.api.tests_check_result(self._env.token,
+ 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'])
return self._results['status']
def _UploadAppToDevice(self, apk_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.api.apps_upload(self._env.token,
+ 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))
@@ -152,8 +154,9 @@ class RemoteDeviceTestRun(test_run.TestRun):
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.api.tests_upload(
+ upload_results = appurify_sanitized.api.tests_upload(
self._env.token, test_src, 'raw', test_type, app_id=self._app_id)
remote_device_helper.TestHttpResponse(upload_results,
'Unable to upload %s.' %(self._test_instance.apk))
@@ -164,13 +167,14 @@ class RemoteDeviceTestRun(test_run.TestRun):
Args:
extras: Extra arguments to set in the config file.
"""
+ logging.info('Generating config file for test.')
with tempfile.TemporaryFile() as config:
config_data = ['[appurify]', '[%s]' % runner_type]
config_data.extend('%s=%s' % (k, v) for k, v in body.iteritems())
config.write(''.join('%s\n' % l for l in config_data))
config.flush()
config.seek(0)
- config_response = appurify.api.config_upload(self._env.token,
+ 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.')

Powered by Google App Engine
This is Rietveld 408576698