diff options
author | tonyg@chromium.org <tonyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-02 07:56:31 +0000 |
---|---|---|
committer | tonyg@chromium.org <tonyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-02 07:56:31 +0000 |
commit | 95b24415a2bbb10fad6c9078193365245a9efea0 (patch) | |
tree | 32b0e563ee9e83beae79c372798dd5059c329323 | |
parent | 10dc72b1cde6227d5c1262c5c0fd6c9fd4cb0c67 (diff) | |
download | chromium_src-95b24415a2bbb10fad6c9078193365245a9efea0.zip chromium_src-95b24415a2bbb10fad6c9078193365245a9efea0.tar.gz chromium_src-95b24415a2bbb10fad6c9078193365245a9efea0.tar.bz2 |
[Telemetry] Fix android unittests that run after AndroidBrowserFinderTest.
It was leaving the CanFindAvailableBrowsers method in a bad state.
BUG=337829
Review URL: https://codereview.chromium.org/436963003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287184 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | tools/telemetry/telemetry/core/backends/chrome/android_browser_finder.py | 58 | ||||
-rw-r--r-- | tools/telemetry/telemetry/core/backends/chrome/android_browser_finder_unittest.py | 21 |
2 files changed, 35 insertions, 44 deletions
diff --git a/tools/telemetry/telemetry/core/backends/chrome/android_browser_finder.py b/tools/telemetry/telemetry/core/backends/chrome/android_browser_finder.py index 7389452..8c4adb1 100644 --- a/tools/telemetry/telemetry/core/backends/chrome/android_browser_finder.py +++ b/tools/telemetry/telemetry/core/backends/chrome/android_browser_finder.py @@ -63,11 +63,6 @@ CHROME_PACKAGE_NAMES = { ALL_BROWSER_TYPES = CHROME_PACKAGE_NAMES.keys() -# adb shell pm list packages -# adb -# intents to run (pass -D url for the rest) -# com.android.chrome/.Main -# com.google.android.apps.chrome/.Main class PossibleAndroidBrowser(possible_browser.PossibleBrowser): """A launchable android browser instance.""" @@ -137,6 +132,7 @@ class PossibleAndroidBrowser(possible_browser.PossibleBrowser): return os.path.getmtime(self._local_apk) return -1 + def SelectDefaultBrowser(possible_browsers): local_builds_by_date = sorted(possible_browsers, key=lambda b: b.last_modification_time()) @@ -146,41 +142,35 @@ def SelectDefaultBrowser(possible_browsers): return newest_browser return None -adb_works = None + +@decorators.Cache def CanFindAvailableBrowsers(logging=real_logging): if not adb_commands.IsAndroidSupported(): logging.info('Android build commands unavailable on this machine. Have ' 'you installed Android build dependencies?') return False - global adb_works - - if adb_works == None: - try: - with open(os.devnull, 'w') as devnull: - proc = subprocess.Popen(['adb', 'devices'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - stdin=devnull) - stdout, _ = proc.communicate() - if re.search(re.escape('????????????\tno permissions'), stdout) != None: - logging.warn( - ('adb devices reported a permissions error. Consider ' - 'restarting adb as root:')) - logging.warn(' adb kill-server') - logging.warn(' sudo `which adb` devices\n\n') - adb_works = True - except OSError: - platform_tools_path = os.path.join(util.GetChromiumSrcDir(), - 'third_party', 'android_tools', 'sdk', 'platform-tools') - if (sys.platform.startswith('linux') and - os.path.exists(os.path.join(platform_tools_path, 'adb'))): - os.environ['PATH'] = os.pathsep.join([platform_tools_path, - os.environ['PATH']]) - adb_works = True - else: - adb_works = False - return adb_works + try: + with open(os.devnull, 'w') as devnull: + proc = subprocess.Popen( + ['adb', 'devices'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=devnull) + stdout, _ = proc.communicate() + if re.search(re.escape('????????????\tno permissions'), stdout) != None: + logging.warn('adb devices reported a permissions error. Consider ' + 'restarting adb as root:') + logging.warn(' adb kill-server') + logging.warn(' sudo `which adb` devices\n\n') + return True + except OSError: + platform_tools_path = os.path.join(util.GetChromiumSrcDir(), + 'third_party', 'android_tools', 'sdk', 'platform-tools') + if (sys.platform.startswith('linux') and + os.path.exists(os.path.join(platform_tools_path, 'adb'))): + os.environ['PATH'] = os.pathsep.join([platform_tools_path, + os.environ['PATH']]) + return True + return False def FindAllAvailableBrowsers(finder_options, logging=real_logging): diff --git a/tools/telemetry/telemetry/core/backends/chrome/android_browser_finder_unittest.py b/tools/telemetry/telemetry/core/backends/chrome/android_browser_finder_unittest.py index af26584..de9e72a 100644 --- a/tools/telemetry/telemetry/core/backends/chrome/android_browser_finder_unittest.py +++ b/tools/telemetry/telemetry/core/backends/chrome/android_browser_finder_unittest.py @@ -25,7 +25,7 @@ class AndroidBrowserFinderTest(unittest.TestCase): def setUp(self): self._stubs = system_stub.Override(android_browser_finder, ['adb_commands', 'os', 'subprocess']) - android_browser_finder.adb_works = None # Blow cache between runs. + self._log_stub = LoggingStub() def tearDown(self): self._stubs.Restore() @@ -36,13 +36,15 @@ class AndroidBrowserFinderTest(unittest.TestCase): def NoAdb(*args, **kargs): # pylint: disable=W0613 raise OSError('not found') self._stubs.subprocess.Popen = NoAdb - browsers = android_browser_finder.FindAllAvailableBrowsers(finder_options) + browsers = android_browser_finder.FindAllAvailableBrowsers( + finder_options, self._log_stub) self.assertEquals(0, len(browsers)) def test_adb_no_devices(self): finder_options = browser_options.BrowserFinderOptions() - browsers = android_browser_finder.FindAllAvailableBrowsers(finder_options) + browsers = android_browser_finder.FindAllAvailableBrowsers( + finder_options, self._log_stub) self.assertEquals(0, len(browsers)) def test_adb_permissions_error(self): @@ -55,10 +57,9 @@ class AndroidBrowserFinderTest(unittest.TestCase): * daemon started successfully * """) - log_stub = LoggingStub() browsers = android_browser_finder.FindAllAvailableBrowsers( - finder_options, log_stub) - self.assertEquals(3, len(log_stub.warnings)) + finder_options, self._log_stub) + self.assertEquals(3, len(self._log_stub.warnings)) self.assertEquals(0, len(browsers)) def test_adb_two_devices(self): @@ -67,10 +68,9 @@ class AndroidBrowserFinderTest(unittest.TestCase): self._stubs.adb_commands.attached_devices = ['015d14fec128220c', '015d14fec128220d'] - log_stub = LoggingStub() browsers = android_browser_finder.FindAllAvailableBrowsers( - finder_options, log_stub) - self.assertEquals(1, len(log_stub.warnings)) + finder_options, self._log_stub) + self.assertEquals(1, len(self._log_stub.warnings)) self.assertEquals(0, len(browsers)) @benchmark.Disabled('chromeos') @@ -88,5 +88,6 @@ class AndroidBrowserFinderTest(unittest.TestCase): self._stubs.adb_commands.shell_command_handlers['pm'] = OnPM - browsers = android_browser_finder.FindAllAvailableBrowsers(finder_options) + browsers = android_browser_finder.FindAllAvailableBrowsers( + finder_options, self._log_stub) self.assertEquals(1, len(browsers)) |