Index: build/android/pylib/base/remote_device_test_run.py |
diff --git a/build/android/pylib/base/remote_device_test_run.py b/build/android/pylib/base/remote_device_test_run.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ce8c4e34a6d898a1b3e2db916d3da23485f0556b |
--- /dev/null |
+++ b/build/android/pylib/base/remote_device_test_run.py |
@@ -0,0 +1,123 @@ |
+# 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 os |
+import time |
+ |
+ |
+# TODO(rnephew): When appurify is added to 3rd party switch these. |
+from pylib import appurify_api |
+from pylib import appurify_utils |
+from pylib.base import remote_device_config |
+from pylib.base import test_run |
+ |
+class RemoteDeviceTestRun(test_run.TestRun): |
+ """Run gtests and uirobot tests on a remote device.""" |
+ |
+ def __init__(self, env, test_instance): |
+ super(RemoteDeviceTestRun, self).__init__(env, test_instance) |
+ self._env = env |
+ self._test_instance = test_instance |
+ self._wait_time = 5 |
jbudorick
2014/11/21 00:17:25
This should just be a constant (i.e. _WAIT_TIME),
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ self._device = self.SelectDevice() |
jbudorick
2014/11/21 00:17:25
Both SelectDevice and UploadAppToDevice should be
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ self._app_id = self.UploadAppToDevice() |
+ self._test_id = '' |
+ self._results = '' |
+ |
+ def TestPackage(self): |
+ pass |
+ |
+ #override |
+ def SetUp(self): |
+ if self._test_instance.TestType() == 'gtest': |
+ self.UploadTestToDevice('robotium') |
+ self.SetTestConfig() |
+ |
+ if self._test_instance.TestType() == 'uirobot': |
jbudorick
2014/11/21 00:17:25
elif?
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ self.GetTestByName('android_robot') |
+ self.SetTestConfig(extras={'duration': self._env.options.minutes}) |
+ |
+ #override |
+ def RunTest(self): |
+ test_start_res = appurify_api.tests_run( |
+ self._env.token, self._device, self._app_id, self._test_id) |
+ self.TestHttpResponse(test_start_res, 'Unable to run test.') |
+ test_run_id = test_start_res.json()['response']['test_run_id'] |
+ self.WaitForTest(test_run_id) |
+ self.DownloadTestResults(self._env.options.results_path) |
+ return self._results |
+ |
+ #override |
+ def TearDown(self): |
+ pass |
+ |
+ def __enter__(self): |
+ self.SetUp() |
+ return self |
+ |
+ def __exit__(self, exc_type, exc_val, exc_tb): |
+ self.TearDown() |
+ |
+ def GetTestByName(self, test_name): |
jbudorick
2014/11/21 00:17:25
All of these functions need docstrings.
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ test_list_res = appurify_api.tests_list(self._env.token) |
+ self.TestHttpResponse(test_list_res, 'Unable to get tests list.') |
+ for test in test_list_res.json()['response']: |
+ if test['test_type'] == test_name: |
+ self._test_id = test['test_id'] |
+ return |
+ |
+ def DownloadTestResults(self, results_path): |
+ 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): |
+ test_status = 'in-progress' |
+ while test_status != 'complete': |
jbudorick
2014/11/21 00:17:25
'complete' should be const'd.
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ time.sleep(self._wait_time) |
+ test_check_res = appurify_api.tests_check_result(self._env.token, |
+ test_run_id) |
+ self.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 SelectDevice(self): |
+ for device in self._env.devices: |
jbudorick
2014/11/21 00:17:25
This would seem like an environment level function
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ if (device['name'] == self._env.options.remote_device and |
+ device['os_version'] == self._env.options.remote_device_os): |
+ return device['device_type_id'] |
+ self._env.error_func('No device found: %s %s' %( |
+ self._env.options.remote_device, self._env.options.remote_device_os)) |
+ |
+ def UploadAppToDevice(self): |
+ 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) |
jbudorick
2014/11/21 00:17:25
They need an open file instead of a path? That's .
rnephew (Reviews Here)
2014/11/21 18:26:47
Yep. Thats how they do it on their client too. I t
|
+ self.TestHttpResponse(upload_results, 'Unable to upload Chrome.') |
jbudorick
2014/11/21 00:17:25
s/Chrome/<apk under test name>/
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ return upload_results.json()['response']['app_id'] |
+ |
+ def UploadTestToDevice(self, test_type): |
+ with open(self._test_instance.apk, 'rb') as test_src: |
+ upload_results = appurify_api.tests_upload( |
+ self._env.token, test_src, 'raw', test_type, |
+ app_id=self._app_id, name=self._test_instance.TestType()) |
+ self.TestHttpResponse(upload_results, 'Unable to upload test.') |
jbudorick
2014/11/21 00:17:25
s/ test./ <test apk name>./
rnephew (Reviews Here)
2014/11/21 18:26:47
Done.
|
+ self._test_id = upload_results.json()['response']['test_id'] |
+ |
+ def SetTestConfig(self, extras=None): |
+ with remote_device_config.RemoteDeviceConfig( |
jbudorick
2014/11/21 00:17:25
I'm wondering if we should just use tempfile and d
rnephew (Reviews Here)
2014/11/21 18:26:47
Working on this, wont be in the next upload; but w
|
+ self._test_instance.TestType(), self._test_instance.apk_under_test, |
+ extras=extras) as config: |
+ with open(config.path, 'rb') as config_src: |
+ config_response = appurify_api.config_upload(self._env.token, |
+ config_src, self._test_id) |
+ self.TestHttpResponse(config_response, 'Unable to upload test config.') |
+ |
+ def TestHttpResponse(self, response, error_msg): |
+ if response.status_code != 200: |
+ self._env.error_func(error_msg) |