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

Unified Diff: build/android/pylib/device/device_utils.py

Issue 839893004: Refactor test scripts for android to improve performance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cache application paths Created 5 years, 11 months 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
« no previous file with comments | « no previous file | build/android/pylib/gtest/test_package_apk.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/device_utils.py
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py
index fe9d2c64324ecb378bf43b4c63aa8e1d13a94acc..54f9a5dd505581394b8e5bd85a366a742454bd5a 100644
--- a/build/android/pylib/device/device_utils.py
+++ b/build/android/pylib/device/device_utils.py
@@ -126,6 +126,7 @@ class DeviceUtils(object):
self._default_timeout = default_timeout
self._default_retries = default_retries
self._cache = {}
+ self._cache['application_paths'] = {}
assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR)
assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR)
@@ -279,6 +280,10 @@ class DeviceUtils(object):
# in Lollipop.
# TODO(jbudorick): Check if this is fixed as new Android versions are
# released to put an upper bound on this.
+ application_paths = self._cache['application_paths']
jbudorick 2015/01/21 22:54:09 If we stay with the cache, please move this above
+ if package in application_paths:
+ return application_paths[package]
+
should_check_return = (self.build_version_sdk <
jbudorick 2015/01/21 22:54:09 w.r.t. my tuning suggestion: we already have some
constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP)
output = self.RunShellCommand(['pm', 'path', package], single_line=True,
@@ -288,7 +293,8 @@ class DeviceUtils(object):
if not output.startswith('package:'):
raise device_errors.CommandFailedError('pm path returned: %r' % output,
str(self))
- return output[len('package:'):]
+ application_paths[package] = output[len('package:'):]
+ return application_paths[package]
@decorators.WithTimeoutAndRetriesFromInstance()
def WaitUntilFullyBooted(self, wifi=False, timeout=None, retries=None):
@@ -359,6 +365,7 @@ class DeviceUtils(object):
self.adb.Reboot()
self._cache = {}
+ self._cache['application_paths'] = {}
timeout_retry.WaitFor(device_offline, wait_period=1)
if block:
self.WaitUntilFullyBooted()
@@ -396,6 +403,10 @@ class DeviceUtils(object):
if should_install:
self.adb.Install(apk_path, reinstall=reinstall)
+ application_paths = self._cache['application_paths']
+ if package_name in application_paths:
+ del application_paths[package_name]
+
@decorators.WithTimeoutAndRetriesFromInstance()
def RunShellCommand(self, cmd, check_return=False, cwd=None, env=None,
as_root=False, single_line=False,
@@ -421,6 +432,9 @@ class DeviceUtils(object):
TODO(perezju) Change the default of |check_return| to True when callers
have switched to the new behaviour.
+ TODO(jaekyun) Should clear some of non-RO cache items if this command
+ affects them.
+
Args:
cmd: A string with the full command to run on the device, or a sequence
containing the command and its arguments.
@@ -456,6 +470,10 @@ class DeviceUtils(object):
if not isinstance(cmd, basestring):
cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd)
+
+ if cmd.startswith('pm install') or cmd.startswith('pm uninstall'):
jbudorick 2015/01/21 22:54:09 O_O This looks _extremely_ dangerous / flaky / te
+ self._cache['application_paths'] = {}
+
if env:
env = ' '.join(env_quote(k, v) for k, v in env.iteritems())
cmd = '%s %s' % (env, cmd)
« no previous file with comments | « no previous file | build/android/pylib/gtest/test_package_apk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698