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

Side by Side Diff: build/android/pylib/remote/device/remote_device_environment.py

Issue 745793002: Add AMP support to test runner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix pylint in pylib/instrumentation/t_r 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 """Environment setup and teardown for remote devices."""
6
7 import os
8 import sys
9
10 from pylib import constants
11 from pylib.base import environment
12 from pylib.remote.device import remote_device_helper
13
14 sys.path.append(os.path.join(
15 constants.DIR_SOURCE_ROOT, 'third_party', 'requests', 'src'))
16 sys.path.append(os.path.join(
17 constants.DIR_SOURCE_ROOT, 'third_party', 'appurify-python', 'src'))
18 import appurify.api
19
20
21 class RemoteDeviceEnvironment(environment.Environment):
22 """An environment for running on remote devices."""
23
24 def __init__(self, args, error_func):
25 """Constructor.
26
27 Args:
28 args: Command line arguments.
29 error_func: error to show when using bad command line arguments.
30 """
31 super(RemoteDeviceEnvironment, self).__init__()
32
33 if args.api_key_file:
34 with open(args.api_key_file) as api_key_file:
35 self._api_key = api_key_file.read().strip()
36 elif args.api_key:
37 self._api_key = args.api_key
38 else:
39 error_func('Must set api key with --api-key or --api-key-file')
40
41 if args.api_secret_file:
42 with open(args.api_secret_file) as api_secret_file:
43 self._api_secret = api_secret_file.read().strip()
44 elif args.api_secret:
45 self._api_secret = args.api_secret
46 else:
47 error_func('Must set api secret with --api-secret or --api-secret-file')
48
49 self._api_protocol = args.api_protocol
50 self._api_address = args.api_address
51 self._api_port = args.api_port
52 self._access_token = ''
53 self._results_path = args.results_path
54 self._remote_device = args.remote_device
55 self._remote_device_os = args.remote_device_os
56 self._runner_package = args.runner_package
57 self._runner_type = args.runner_type
58 self._device = ''
59 if not args.trigger and not args.collect:
60 self._trigger = True
61 self._collect = True
62 else:
63 self._trigger = args.trigger
64 self._collect = args.collect
65
66 def SetUp(self):
67 """Set up the test environment."""
68 os.environ['APPURIFY_API_PROTO'] = self._api_protocol
69 os.environ['APPURIFY_API_HOST'] = self._api_address
70 os.environ['APPURIFY_API_PORT'] = self._api_port
71 self._GetAccessToken()
72 if self._trigger:
73 self._device = self._SelectDevice()
74
75 def TearDown(self):
76 """Teardown the test environment."""
77 self._RevokeAccessToken()
78
79 def __enter__(self):
80 """Set up the test run when used as a context manager."""
81 self.SetUp()
82 return self
83
84 def __exit__(self, exc_type, exc_val, exc_tb):
85 """Tears down the test run when used as a context manager."""
86 self.TearDown()
87
88 def _GetAccessToken(self):
89 """Generates access token for remote device service."""
90 access_token_results = appurify.api.access_token_generate(
91 self._api_key, self._api_secret)
92 remote_device_helper.TestHttpResponse(access_token_results,
93 'Unable to generate access token.')
94 self._access_token = access_token_results.json()['response']['access_token']
95
96 def _RevokeAccessToken(self):
97 """Destroys access token for remote device service."""
98 revoke_token_results = appurify.api.access_token_revoke(self._access_token)
99 remote_device_helper.TestHttpResponse(revoke_token_results,
100 'Unable to revoke access token.')
101
102 def _SelectDevice(self):
103 """Select which device to use."""
104 dev_list_res = appurify.api.devices_list(self._access_token)
105 remote_device_helper.TestHttpResponse(dev_list_res,
106 'Unable to generate access token.')
107 device_list = dev_list_res.json()['response']
108 for device in device_list:
109 if (device['name'] == self._remote_device
110 and device['os_version'] == self._remote_device_os):
111 return device['device_type_id']
112 raise remote_device_helper.RemoteDeviceError(
113 'No device found: %s %s' % (self._remote_device,
114 self._remote_device_os))
115
116 @property
117 def device(self):
118 return self._device
119
120 @property
121 def token(self):
122 return self._access_token
123
124 @property
125 def results_path(self):
126 return self._results_path
127
128 @property
129 def runner_type(self):
130 return self._runner_type
131
132 @property
133 def runner_package(self):
134 return self._runner_package
135
136 @property
137 def trigger(self):
138 return self._trigger
139
140 @property
141 def collect(self):
142 return self._collect
OLDNEW
« no previous file with comments | « build/android/pylib/remote/device/__init__.py ('k') | build/android/pylib/remote/device/remote_device_gtest_run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698