OLD | NEW |
---|---|
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging | 5 import logging |
6 import os | 6 import os |
7 import posixpath | 7 import posixpath |
8 import re | 8 import re |
9 import time | 9 import time |
10 | 10 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 def TestPackage(self): | 69 def TestPackage(self): |
70 return self._test_instance.suite | 70 return self._test_instance.suite |
71 | 71 |
72 #override | 72 #override |
73 def SetUp(self): | 73 def SetUp(self): |
74 @local_device_environment.handle_shard_failures_with( | 74 @local_device_environment.handle_shard_failures_with( |
75 self._env.BlacklistDevice) | 75 self._env.BlacklistDevice) |
76 @trace_event.traced | 76 @trace_event.traced |
77 def individual_device_set_up(dev, host_device_tuples): | 77 def individual_device_set_up(dev, host_device_tuples): |
78 steps = [] | 78 steps = [] |
79 | |
79 def install_helper(apk, permissions): | 80 def install_helper(apk, permissions): |
80 return lambda: dev.Install(apk, permissions=permissions) | 81 @trace_event.traced("apk_path") |
82 def install_helper_internal(apk_path=apk.path): | |
shenghuazhang
2017/04/21 19:17:22
Add the internal function with apk.path argument s
jbudorick
2017/04/21 20:41:08
Why am I not surprised that ChromePublic.apk takes
| |
83 # pylint: disable=unused-argument | |
84 dev.Install(apk, permissions=permissions) | |
85 return install_helper_internal | |
86 | |
81 def incremental_install_helper(dev, apk, script): | 87 def incremental_install_helper(dev, apk, script): |
82 return lambda: local_device_test_run.IncrementalInstall( | 88 @trace_event.traced("apk_path") |
83 dev, apk, script) | 89 def incremental_install_helper_internal(apk_path=apk.path): |
90 # pylint: disable=unused-argument | |
91 local_device_test_run.IncrementalInstall( | |
92 dev, apk, script) | |
93 return incremental_install_helper_internal | |
84 | 94 |
85 if self._test_instance.apk_under_test: | 95 if self._test_instance.apk_under_test: |
86 if self._test_instance.apk_under_test_incremental_install_script: | 96 if self._test_instance.apk_under_test_incremental_install_script: |
87 steps.append(incremental_install_helper( | 97 steps.append(incremental_install_helper( |
88 dev, | 98 dev, |
89 self._test_instance.apk_under_test, | 99 self._test_instance.apk_under_test, |
90 self._test_instance. | 100 self._test_instance. |
91 apk_under_test_incremental_install_script)) | 101 apk_under_test_incremental_install_script)) |
92 else: | 102 else: |
93 permissions = self._test_instance.apk_under_test.GetPermissions() | 103 permissions = self._test_instance.apk_under_test.GetPermissions() |
94 steps.append(install_helper(self._test_instance.apk_under_test, | 104 steps.append(install_helper(self._test_instance.apk_under_test, |
95 permissions)) | 105 permissions)) |
96 | 106 |
97 if self._test_instance.test_apk_incremental_install_script: | 107 if self._test_instance.test_apk_incremental_install_script: |
98 steps.append(incremental_install_helper( | 108 steps.append(incremental_install_helper( |
99 dev, | 109 dev, |
100 self._test_instance.test_apk, | 110 self._test_instance.test_apk, |
101 self._test_instance. | 111 self._test_instance. |
102 test_apk_incremental_install_script)) | 112 test_apk_incremental_install_script)) |
103 else: | 113 else: |
104 permissions = self._test_instance.test_apk.GetPermissions() | 114 permissions = self._test_instance.test_apk.GetPermissions() |
105 steps.append(install_helper(self._test_instance.test_apk, | 115 steps.append(install_helper(self._test_instance.test_apk, |
106 permissions)) | 116 permissions)) |
107 | 117 |
108 steps.extend(install_helper(apk, None) | 118 steps.extend(install_helper(apk, None) |
109 for apk in self._test_instance.additional_apks) | 119 for apk in self._test_instance.additional_apks) |
110 | 120 |
121 @trace_event.traced | |
111 def set_debug_app(): | 122 def set_debug_app(): |
112 # Set debug app in order to enable reading command line flags on user | 123 # Set debug app in order to enable reading command line flags on user |
113 # builds | 124 # builds |
114 if self._test_instance.flags: | 125 if self._test_instance.flags: |
115 if not self._test_instance.package_info: | 126 if not self._test_instance.package_info: |
116 logging.error("Couldn't set debug app: no package info") | 127 logging.error("Couldn't set debug app: no package info") |
117 elif not self._test_instance.package_info.package: | 128 elif not self._test_instance.package_info.package: |
118 logging.error("Couldn't set debug app: no package defined") | 129 logging.error("Couldn't set debug app: no package defined") |
119 else: | 130 else: |
120 dev.RunShellCommand(['am', 'set-debug-app', '--persistent', | 131 dev.RunShellCommand(['am', 'set-debug-app', '--persistent', |
121 self._test_instance.package_info.package], | 132 self._test_instance.package_info.package], |
122 check_return=True) | 133 check_return=True) |
123 | 134 @trace_event.traced |
124 def edit_shared_prefs(): | 135 def edit_shared_prefs(): |
125 for pref in self._test_instance.edit_shared_prefs: | 136 for pref in self._test_instance.edit_shared_prefs: |
126 prefs = shared_prefs.SharedPrefs(dev, pref['package'], | 137 prefs = shared_prefs.SharedPrefs(dev, pref['package'], |
127 pref['filename']) | 138 pref['filename']) |
128 prefs.Load() | 139 prefs.Load() |
129 for key in pref.get('remove', []): | 140 for key in pref.get('remove', []): |
130 try: | 141 try: |
131 prefs.Remove(key) | 142 prefs.Remove(key) |
132 except KeyError: | 143 except KeyError: |
133 logging.warning("Attempted to remove non-existent key %s", key) | 144 logging.warning("Attempted to remove non-existent key %s", key) |
134 for key, value in pref.get('set', {}).iteritems(): | 145 for key, value in pref.get('set', {}).iteritems(): |
135 if isinstance(value, bool): | 146 if isinstance(value, bool): |
136 prefs.SetBoolean(key, value) | 147 prefs.SetBoolean(key, value) |
137 elif isinstance(value, basestring): | 148 elif isinstance(value, basestring): |
138 prefs.SetString(key, value) | 149 prefs.SetString(key, value) |
139 elif isinstance(value, long) or isinstance(value, int): | 150 elif isinstance(value, long) or isinstance(value, int): |
140 prefs.SetLong(key, value) | 151 prefs.SetLong(key, value) |
141 elif isinstance(value, list): | 152 elif isinstance(value, list): |
142 prefs.SetStringSet(key, value) | 153 prefs.SetStringSet(key, value) |
143 else: | 154 else: |
144 raise ValueError("Given invalid value type %s for key %s" % ( | 155 raise ValueError("Given invalid value type %s for key %s" % ( |
145 str(type(value)), key)) | 156 str(type(value)), key)) |
146 prefs.Commit() | 157 prefs.Commit() |
147 | 158 |
159 @trace_event.traced | |
148 def push_test_data(): | 160 def push_test_data(): |
149 device_root = posixpath.join(dev.GetExternalStoragePath(), | 161 device_root = posixpath.join(dev.GetExternalStoragePath(), |
150 'chromium_tests_root') | 162 'chromium_tests_root') |
151 host_device_tuples_substituted = [ | 163 host_device_tuples_substituted = [ |
152 (h, local_device_test_run.SubstituteDeviceRoot(d, device_root)) | 164 (h, local_device_test_run.SubstituteDeviceRoot(d, device_root)) |
153 for h, d in host_device_tuples] | 165 for h, d in host_device_tuples] |
154 logging.info('instrumentation data deps:') | 166 logging.info('instrumentation data deps:') |
155 for h, d in host_device_tuples_substituted: | 167 for h, d in host_device_tuples_substituted: |
156 logging.info('%r -> %r', h, d) | 168 logging.info('%r -> %r', h, d) |
157 dev.PushChangedFiles(host_device_tuples_substituted, | 169 dev.PushChangedFiles(host_device_tuples_substituted, |
158 delete_device_stale=True) | 170 delete_device_stale=True) |
159 if not host_device_tuples_substituted: | 171 if not host_device_tuples_substituted: |
160 dev.RunShellCommand(['rm', '-rf', device_root], check_return=True) | 172 dev.RunShellCommand(['rm', '-rf', device_root], check_return=True) |
161 dev.RunShellCommand(['mkdir', '-p', device_root], check_return=True) | 173 dev.RunShellCommand(['mkdir', '-p', device_root], check_return=True) |
162 | 174 |
175 @trace_event.traced | |
163 def create_flag_changer(): | 176 def create_flag_changer(): |
164 if self._test_instance.flags: | 177 if self._test_instance.flags: |
165 if not self._test_instance.package_info: | 178 if not self._test_instance.package_info: |
166 logging.error("Couldn't set flags: no package info") | 179 logging.error("Couldn't set flags: no package info") |
167 elif not self._test_instance.package_info.cmdline_file: | 180 elif not self._test_instance.package_info.cmdline_file: |
168 logging.error("Couldn't set flags: no cmdline_file") | 181 logging.error("Couldn't set flags: no cmdline_file") |
169 else: | 182 else: |
170 self._CreateFlagChangerIfNeeded(dev) | 183 self._CreateFlagChangerIfNeeded(dev) |
171 logging.debug('Attempting to set flags: %r', | 184 logging.debug('Attempting to set flags: %r', |
172 self._test_instance.flags) | 185 self._test_instance.flags) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 if k in annotations: | 454 if k in annotations: |
442 timeout = v | 455 timeout = v |
443 break | 456 break |
444 else: | 457 else: |
445 logging.warning('Using default 1 minute timeout for %s', test_name) | 458 logging.warning('Using default 1 minute timeout for %s', test_name) |
446 timeout = 60 | 459 timeout = 60 |
447 | 460 |
448 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) | 461 timeout *= cls._GetTimeoutScaleFromAnnotations(annotations) |
449 | 462 |
450 return timeout | 463 return timeout |
OLD | NEW |