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

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

Issue 745793002: Add AMP support to test runner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments on previous 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
new file mode 100644
index 0000000000000000000000000000000000000000..bb4ec7b81d33e3e6063f9f73f071bddd5e8e2290
--- /dev/null
+++ b/build/android/pylib/remote/device/remote_device_test_run.py
@@ -0,0 +1,153 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Run specific test on specific environment."""
+
+import logging
+import os
+import sys
+import tempfile
+import time
+
+from pylib import constants
+from pylib.base import test_run
+from pylib.remote.device import remote_device_helper
+
+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."""
+
+ WAIT_TIME = 5
+ COMPLETE = 'complete'
+
+ def __init__(self, env, test_instance):
+ """Constructor.
+
+ Args:
+ env: Environment the tests will run in.
+ test_instance: The test that will be run.
+ """
+ super(RemoteDeviceTestRun, self).__init__(env, test_instance)
+ self._env = env
+ self._test_instance = test_instance
+ self._app_id = ''
+ self._test_id = ''
+ self._results = ''
+
+ def TestPackage(self):
+ pass
+
+ def SetUp(self):
jbudorick 2014/12/03 22:46:09 This is unnecessary if it's not implemented.
rnephew (Reviews Here) 2014/12/03 23:49:25 This is the base class that uirobot_runner and gte
jbudorick 2014/12/03 23:54:39 This inherits from TestRun, which has already defi
+ """Setup the test run."""
+ raise NotImplementedError
+
+ #override
+ def RunTest(self):
+ """Run the test."""
+ test_start_res = appurify.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']
+ #TODO(rnephew): Need to seperate invoking from results gather.
jbudorick 2014/12/03 22:46:09 Here's what I'm thinking with this: - Figure out
rnephew (Reviews Here) 2014/12/03 23:49:25 The only thing that should be required is the test
jbudorick 2014/12/03 23:54:39 Both will need to take a file parameter, but yeah,
+ self.WaitForTest(test_run_id)
+ self.DownloadTestResults(self._env.results_path)
+ return self._results
+
+ #override
+ def TearDown(self):
+ """Teardown the test run."""
jbudorick 2014/12/03 22:46:09 nit: "Teardown" -> "Tear down"
rnephew (Reviews Here) 2014/12/03 23:49:26 Done.
+ pass
+
+ def __enter__(self):
+ """Runs when entering with with keyword."""
jbudorick 2014/12/03 22:46:09 reword: "Set up the test run when used as a contex
rnephew (Reviews Here) 2014/12/03 23:49:25 Done.
+ self.SetUp()
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ """Runs when exiting with with keyword."""
jbudorick 2014/12/03 22:46:09 Similarly, "Tear down the test run when used as a
rnephew (Reviews Here) 2014/12/03 23:49:25 Done.
+ self.TearDown()
+
+ def GetTestByName(self, test_name):
jbudorick 2014/12/03 22:46:09 Do we anticipate calling this beyond uirobot? If n
rnephew (Reviews Here) 2014/12/03 23:49:26 Currently I do not plan on it. But if we can someh
jbudorick 2014/12/03 23:54:39 Going to have to talk to you more about this one.
+ """Gets test_id for specific test.
+
+ Args:
+ test_name: Test to find the ID of.
+ """
+ test_list_res = appurify.api.tests_list(self._env.token)
+ remote_device_helper.TestHttpResponse(test_list_res,
+ 'Unable to get tests list.')
jbudorick 2014/12/03 22:46:09 nit: one more space
rnephew (Reviews Here) 2014/12/03 23:49:25 Done.
+ for test in test_list_res.json()['response']:
+ if test['test_type'] == test_name:
+ return test['test_id']
jbudorick 2014/12/03 22:46:09 nit: only one space between "return" and "test" I
rnephew (Reviews Here) 2014/12/03 23:49:25 Done.
+ raise remote_device_helper.RemoteDeviceError(
+ 'No test found with name %s' % (test_name))
+
+ def DownloadTestResults(self, results_path):
+ """Download the test results from remote device service.
+
+ Args:
+ results_path: path to download results to.
+ """
+ if results_path:
+ if not os.path.exists(os.path.basename(results_path)):
+ os.makedirs(os.path.basename(results_path))
+ appurify.utils.wget(self._results['url'], results_path)
+
+ def WaitForTest(self, test_run_id):
+ """Wait for remote service to have results of test.
+
+ Args:
+ test_run_id: id of test to wait for results of.
+ """
+ test_status = 'in-progress'
+ while test_status != self.COMPLETE:
+ time.sleep(self.WAIT_TIME)
+ test_check_res = appurify.api.tests_check_result(self._env.token,
+ test_run_id)
+ remote_device_helper.TestHttpResponse(test_check_res,
+ 'Unable to get test status.')
+ test_status = test_check_res.json()['response']['status']
+ self._results = test_check_res.json()['response']['results']
+
+ def UploadAppToDevice(self):
+ """Upload app to device."""
+ apk_name = os.path.basename(self._test_instance.apk)
+ with open(self._test_instance.apk_under_test, 'rb') as apk_src:
+ upload_results = appurify.api.apps_upload(self._env.token,
+ apk_src, 'raw', name=apk_name)
+ remote_device_helper.TestHttpResponse(upload_results,
+ 'Unable to upload %s.' %(self._test_instance.apk_under_test))
+ return upload_results.json()['response']['app_id']
+
+ def UploadTestToDevice(self, test_type):
+ """Upload test to device
+ Args:
+ test_type: Type of test that is being uploaded. Ex. uirobot, gtest..
+ """
+ with open(self._test_instance.apk, 'rb') as test_src:
jbudorick 2014/12/03 22:46:09 yeesh. Do we have to have an open file handle? Can
rnephew (Reviews Here) 2014/12/03 23:49:25 Unfortunately that's how they do it. It fails if I
jbudorick 2014/12/03 23:54:39 :(
+ upload_results = appurify.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))
+ return upload_results.json()['response']['test_id']
+
+ def SetTestConfig(self, runner_type, body):
+ """Generates and uploads config file for test.
+ Args:
+ extras: Extra arguments to set in the config file.
+ """
+ config = tempfile.TemporaryFile()
+ config_data = ['[appurify]\n', '[' + runner_type + ']\n']
jbudorick 2014/12/03 22:46:09 nit: leave off the '\n' here and below and just do
rnephew (Reviews Here) 2014/12/03 23:49:25 Done.
+ config_data.extend('%s=%s\n' % (k, v) for k, v in body.iteritems())
+ config.writelines(config_data)
+ config.seek(0)
+ config_response = appurify.api.config_upload(self._env.token,
jbudorick 2014/12/03 22:46:09 Again, do we have to pass an open file handle?
rnephew (Reviews Here) 2014/12/03 23:49:25 See above.
+ config, self._test_id)
+ config.close()
+ remote_device_helper.TestHttpResponse(config_response,
+ 'Unable to upload test config.')

Powered by Google App Engine
This is Rietveld 408576698