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

Unified Diff: tools/telemetry/telemetry/internal/backends/mandoline/android_mandoline_finder.py

Issue 1252253003: Support Telemetry tests on Android Mandoline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@7_android_tele
Patch Set: Created 5 years, 4 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
Index: tools/telemetry/telemetry/internal/backends/mandoline/android_mandoline_finder.py
diff --git a/tools/telemetry/telemetry/internal/backends/mandoline/desktop_mandoline_finder.py b/tools/telemetry/telemetry/internal/backends/mandoline/android_mandoline_finder.py
similarity index 29%
copy from tools/telemetry/telemetry/internal/backends/mandoline/desktop_mandoline_finder.py
copy to tools/telemetry/telemetry/internal/backends/mandoline/android_mandoline_finder.py
index ea1e4f782a269ef05783f8df521df99ed2d5da4f..35e5859a5c7f84373cf6192609d2269db36cfd4c 100644
--- a/tools/telemetry/telemetry/internal/backends/mandoline/desktop_mandoline_finder.py
+++ b/tools/telemetry/telemetry/internal/backends/mandoline/android_mandoline_finder.py
@@ -1,53 +1,52 @@
# Copyright 2015 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.
-"""Finds desktop mandoline browsers that can be controlled by telemetry."""
+
+"""Finds android mandoline browsers that can be controlled by telemetry."""
import os
-import sys
-from telemetry.core import exceptions
-from telemetry.core import platform as platform_module
-from telemetry.internal.backends.mandoline import desktop_mandoline_backend
+from telemetry.core import platform
+from telemetry.core import util
+from telemetry.internal.backends.mandoline import android_mandoline_backend
from telemetry.internal.browser import browser
from telemetry.internal.browser import possible_browser
-from telemetry.internal.platform import desktop_device
+from telemetry.internal.platform import android_device
from telemetry.internal.util import path
+util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android')
+from pylib.utils import apk_helper
+
-class PossibleDesktopMandolineBrowser(possible_browser.PossibleBrowser):
- """A desktop mandoline browser that can be controlled."""
+class PossibleAndroidMandolineBrowser(possible_browser.PossibleBrowser):
+ """A launchable android mandoline browser instance."""
- def __init__(self, browser_type, finder_options, executable,
- browser_directory):
- target_os = sys.platform.lower()
- super(PossibleDesktopMandolineBrowser, self).__init__(
- browser_type, target_os, supports_tab_control=False)
+ def __init__(self, browser_type, finder_options, android_platform, build_path,
+ local_apk):
+ super(PossibleAndroidMandolineBrowser, self).__init__(
+ browser_type, 'android', supports_tab_control=False)
assert browser_type in FindAllBrowserTypes(finder_options), (
- 'Please add %s to desktop_mandoline_finder.FindAllBrowserTypes' %
- browser_type)
- self._local_executable = executable
- self._browser_directory = browser_directory
+ 'Please add %s to android_mandoline_finder.FindAllBrowserTypes' %
+ browser_type)
+ self._platform = android_platform
+ self._platform_backend = (
+ android_platform._platform_backend) # pylint: disable=W0212
+ self._build_path = build_path
+ self._local_apk = local_apk
def __repr__(self):
- return 'PossibleDesktopMandolineBrowser(type=%s, executable=%s)' % (
- self.browser_type, self._local_executable)
+ return ('PossibleAndroidMandolineBrowser(browser_type=%s)' %
+ self.browser_type)
def _InitPlatformIfNeeded(self):
- if self._platform:
- return
-
- self._platform = platform_module.GetHostPlatform()
-
- # pylint: disable=W0212
- self._platform_backend = self._platform._platform_backend
+ pass
def Create(self, finder_options):
self._InitPlatformIfNeeded()
-
- mandoline_backend = desktop_mandoline_backend.DesktopMandolineBackend(
+ mandoline_backend = android_mandoline_backend.AndroidMandolineBackend(
self._platform_backend, finder_options.browser_options,
- self._local_executable, self._browser_directory)
+ finder_options.target_arch, self.browser_type, self._build_path,
+ apk_helper.GetPackageName(self._local_apk))
return browser.Browser(
mandoline_backend, self._platform_backend, self._credentials_path)
@@ -56,88 +55,65 @@ class PossibleDesktopMandolineBrowser(possible_browser.PossibleBrowser):
return False
return True
+ def HaveLocalAPK(self):
+ return self._local_apk and os.path.exists(self._local_apk)
+
def UpdateExecutableIfNeeded(self):
pass
def last_modification_time(self):
- if os.path.exists(self._local_executable):
- return os.path.getmtime(self._local_executable)
+ if self.HaveLocalAPK():
+ return os.path.getmtime(self._local_apk)
return -1
+
def SelectDefaultBrowser(possible_browsers):
+ """Returns the newest possible browser."""
if not possible_browsers:
return None
return max(possible_browsers, key=lambda b: b.last_modification_time())
+
def CanFindAvailableBrowsers():
- os_name = platform_module.GetHostPlatform().GetOSName()
- return os_name == 'win' or os_name == 'linux'
-
-def CanPossiblyHandlePath(target_path):
- _, extension = os.path.splitext(target_path.lower())
- if sys.platform.startswith('linux'):
- return not extension
- elif sys.platform.startswith('win'):
- return extension == '.exe'
- return False
-
-def FindAllBrowserTypes(_):
- return [
- 'mandoline-debug',
- 'mandoline-debug_x64',
- 'mandoline-release',
- 'mandoline-release_x64',]
+ return android_device.CanDiscoverDevices()
-def FindAllAvailableBrowsers(finder_options, device):
- """Finds all the desktop mandoline browsers available on this machine."""
- if not isinstance(device, desktop_device.DesktopDevice):
- return []
- browsers = []
+def FindAllBrowserTypes(_options):
+ return [
+ 'android-mandoline-debug',
+ 'android-mandoline-release',]
+
- if not CanFindAvailableBrowsers():
+def _FindAllPossibleBrowsers(finder_options, android_platform):
+ if not android_platform or not CanFindAvailableBrowsers():
return []
- # Look for a browser in the standard chrome build locations.
+ possible_browsers = []
+
if finder_options.chrome_root:
chrome_root = finder_options.chrome_root
else:
chrome_root = path.GetChromiumSrcDir()
- if sys.platform.startswith('linux'):
- mandoline_app_name = 'mandoline'
- elif sys.platform.startswith('win'):
- mandoline_app_name = 'mandoline.exe'
- else:
- raise Exception('Platform not recognized')
-
- # Add the explicit browser executable if given and we can handle it.
- if (finder_options.browser_executable and
- CanPossiblyHandlePath(finder_options.browser_executable)):
- normalized_executable = os.path.expanduser(
- finder_options.browser_executable)
- if path.IsExecutable(normalized_executable):
- browser_directory = os.path.dirname(finder_options.browser_executable)
- browsers.append(PossibleDesktopMandolineBrowser('exact', finder_options,
- normalized_executable,
- browser_directory))
- else:
- raise exceptions.PathMissingError(
- '%s specified by --browser-executable does not exist',
- normalized_executable)
-
- def AddIfFound(browser_type, build_dir, type_dir, app_name):
- browser_directory = os.path.join(chrome_root, build_dir, type_dir)
- app = os.path.join(browser_directory, app_name)
- if path.IsExecutable(app):
- browsers.append(PossibleDesktopMandolineBrowser(
- browser_type, finder_options, app, browser_directory))
- return True
- return False
-
# Add local builds.
for build_dir, build_type in path.GetBuildDirectories():
- AddIfFound('mandoline-' + build_type.lower(), build_dir, build_type,
- mandoline_app_name)
+ build_path = os.path.join(chrome_root, build_dir, build_type)
+ local_apk = os.path.join(build_path, 'apks', 'Mandoline.apk')
+ if os.path.exists(local_apk):
+ possible_browsers.append(PossibleAndroidMandolineBrowser(
+ 'android-mandoline-' + build_type.lower(), finder_options,
+ android_platform, build_path, local_apk))
- return browsers
+ return possible_browsers
+
+
+def FindAllAvailableBrowsers(finder_options, device):
+ """Finds all the possible browsers to run on the device.
+
+ The device is either the only device on the host platform,
+ or |finder_options| specifies a particular device.
+ """
+ if not isinstance(device, android_device.AndroidDevice):
+ return []
+ android_platform = platform.GetPlatformForDevice(device, finder_options)
+ return _FindAllPossibleBrowsers(finder_options, android_platform)

Powered by Google App Engine
This is Rietveld 408576698