diff options
author | frankf@google.com <frankf@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-04 22:42:20 +0000 |
---|---|---|
committer | frankf@google.com <frankf@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-04 22:42:20 +0000 |
commit | 31b74c8fa9b736ef8fc4086985654f0dd64fd0f4 (patch) | |
tree | d303a8fc9434b768ff9741c8ff6db3270119d9fa | |
parent | 2ccc010493a244af13a08fa96451a385faa4afca (diff) | |
download | chromium_src-31b74c8fa9b736ef8fc4086985654f0dd64fd0f4.zip chromium_src-31b74c8fa9b736ef8fc4086985654f0dd64fd0f4.tar.gz chromium_src-31b74c8fa9b736ef8fc4086985654f0dd64fd0f4.tar.bz2 |
[Android] Revert 175082
> Separate apk_info and jar_info and move to utils dir.
>
> This is in preparation for adding uiautomator test runner
> which runs tests without an apk.
>
> BUG=167331
>
> Review URL: https://codereview.chromium.org/11741025
TBR=craigdh@chromium.org
These will be replaced with concept of test packages.
Review URL: https://codereview.chromium.org/11780003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175218 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | build/android/adb_install_apk.py | 2 | ||||
-rw-r--r-- | build/android/pylib/apk_info.py (renamed from build/android/pylib/utils/jar_info.py) | 37 | ||||
-rw-r--r-- | build/android/pylib/python_test_base.py | 6 | ||||
-rw-r--r-- | build/android/pylib/run_java_tests.py | 11 | ||||
-rw-r--r-- | build/android/pylib/run_python_tests.py | 5 | ||||
-rw-r--r-- | build/android/pylib/utils/apk_and_jar_info.py | 22 | ||||
-rw-r--r-- | build/android/pylib/utils/apk_info.py | 41 | ||||
-rwxr-xr-x | build/android/run_instrumentation_tests.py | 5 |
8 files changed, 43 insertions, 86 deletions
diff --git a/build/android/adb_install_apk.py b/build/android/adb_install_apk.py index fc13845..db2c62c 100755 --- a/build/android/adb_install_apk.py +++ b/build/android/adb_install_apk.py @@ -10,9 +10,9 @@ import os import sys from pylib import android_commands +from pylib import apk_info from pylib import constants from pylib import test_options_parser -from pylib.utils import apk_info def _InstallApk(args): diff --git a/build/android/pylib/utils/jar_info.py b/build/android/pylib/apk_info.py index 9927db5..00b30dd 100644 --- a/build/android/pylib/utils/jar_info.py +++ b/build/android/pylib/apk_info.py @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -"""Gathers information about JARs such as test methods and annotations.""" +"""Gathers information about APKs.""" import collections import logging @@ -10,17 +10,27 @@ import os import pickle import re -# TODO(frankf): Move cmd_helper to utils. -from pylib import cmd_helper +import cmd_helper # If you change the cached output of proguard, increment this number PICKLE_FORMAT_VERSION = 1 +def GetPackageNameForApk(apk_path): + """Returns the package name of the apk file.""" + aapt_output = cmd_helper.GetCmdOutput( + ['aapt', 'dump', 'badging', apk_path]).split('\n') + package_name_re = re.compile(r'package: .*name=\'(\S*)\'') + for line in aapt_output: + m = package_name_re.match(line) + if m: + return m.group(1) + raise Exception('Failed to determine package name of %s' % apk_path) -class JarInfo(object): - """Helper class for inspecting Jars.""" - def __init__(self, jar_path): +class ApkInfo(object): + """Helper class for inspecting APKs.""" + + def __init__(self, apk_path, jar_path): self._PROGUARD_PATH = os.path.join(os.environ['ANDROID_SDK_ROOT'], 'tools/proguard/bin/proguard.sh') if not os.path.exists(self._PROGUARD_PATH): @@ -33,12 +43,18 @@ class JarInfo(object): re.compile(r'\s*?- Constant element value.*$')) self._PROGUARD_ANNOTATION_VALUE_RE = re.compile(r'\s*?- \S+? \[(.*)\]$') + if not os.path.exists(apk_path): + raise Exception('%s not found, please build it' % apk_path) + self._apk_path = apk_path if not os.path.exists(jar_path): raise Exception('%s not found, please build it' % jar_path) self._jar_path = jar_path self._annotation_map = collections.defaultdict(list) self._pickled_proguard_name = self._jar_path + '-proguard.pickle' self._test_methods = [] + self._Initialize() + + def _Initialize(self): if not self._GetCachedProguardData(): self._GetProguardData() @@ -126,6 +142,13 @@ class JarInfo(object): class_name, method = test.split('#') return class_name.endswith('Test') and method.startswith('test') + def GetApkPath(self): + return self._apk_path + + def GetPackageName(self): + """Returns the package name of this APK.""" + return GetPackageNameForApk(self._apk_path) + def GetTestAnnotations(self, test): """Returns a list of all annotations for the given |test|. May be empty.""" if not self._IsTestMethod(test): @@ -155,7 +178,7 @@ class JarInfo(object): annotation_filter_list, annotations)] def GetTestMethods(self): - """Returns a list of all test methods in this jar as Class#testMethod.""" + """Returns a list of all test methods in this apk as Class#testMethod.""" return self._test_methods @staticmethod diff --git a/build/android/pylib/python_test_base.py b/build/android/pylib/python_test_base.py index 1b7f76c..d2cdfb0 100644 --- a/build/android/pylib/python_test_base.py +++ b/build/android/pylib/python_test_base.py @@ -24,9 +24,9 @@ import os import time import android_commands +import apk_info from run_java_tests import TestRunner from test_result import SingleTestResult, TestResults -from utils import apk_and_jar_info # aka the parent of com.google.android @@ -75,8 +75,8 @@ class PythonTestBase(object): TestResults object with a single test result. """ test = self._ComposeFullTestName(fname, suite, test) - apks = [apk_and_jar_info.ApkAndJarInfo(self.options.test_apk_path, - self.options.test_apk_jar_path)] + apks = [apk_info.ApkInfo(self.options.test_apk_path, + self.options.test_apk_jar_path)] java_test_runner = TestRunner(self.options, self.device_id, [test], False, self.shard_index, apks, diff --git a/build/android/pylib/run_java_tests.py b/build/android/pylib/run_java_tests.py index 5425a44..07b45e0 100644 --- a/build/android/pylib/run_java_tests.py +++ b/build/android/pylib/run_java_tests.py @@ -13,6 +13,7 @@ import sys import time import android_commands +import apk_info from base_test_runner import BaseTestRunner from base_test_sharder import BaseTestSharder, SetTestsContainer import cmd_helper @@ -23,8 +24,6 @@ from json_perf_parser import GetAverageRunInfoFromJSONString from perf_tests_helper import PrintPerfResult import sharded_tests_queue from test_result import SingleTestResult, TestResults -from utils import apk_and_jar_info -from utils import jar_info import valgrind_tools _PERF_TEST_ANNOTATION = 'PerfTest' @@ -114,8 +113,8 @@ class TestRunner(BaseTestRunner): self, device, options.tool, shard_index, options.build_type) if not apks: - apks = [apk_and_jar_info.ApkAndJarInfo(options.test_apk_path, - options.test_apk_jar_path)] + apks = [apk_info.ApkInfo(options.test_apk_path, + options.test_apk_jar_path)] self.build_type = options.build_type self.install_apk = options.install_apk @@ -541,7 +540,7 @@ def DispatchJavaTests(options, apks): for test_method in test_apk.GetTestMethods(): annotations = frozenset(test_apk.GetTestAnnotations(test_method)) if (annotations.isdisjoint(test_size_annotations) and - not jar_info.JarInfo.IsPythonDrivenTest(test_method)): + not apk_info.ApkInfo.IsPythonDrivenTest(test_method)): tests_missing_annotations.append(test_method) return sorted(tests_missing_annotations) @@ -557,7 +556,7 @@ def DispatchJavaTests(options, apks): available_tests += tests_missing_annotations else: available_tests = [m for m in test_apk.GetTestMethods() - if not jar_info.JarInfo.IsPythonDrivenTest(m)] + if not apk_info.ApkInfo.IsPythonDrivenTest(m)] coverage = os.environ.get('EMMA_INSTRUMENT') == 'true' tests = [] diff --git a/build/android/pylib/run_python_tests.py b/build/android/pylib/run_python_tests.py index eebfcd6..7d39f48 100644 --- a/build/android/pylib/run_python_tests.py +++ b/build/android/pylib/run_python_tests.py @@ -10,6 +10,7 @@ import sys import types import android_commands +import apk_info import constants import python_test_base from python_test_caller import CallPythonTest @@ -18,7 +19,6 @@ import run_java_tests from run_java_tests import FatalTestException from test_info_collection import TestInfoCollection from test_result import TestResults -from utils import apk_and_jar_info def _GetPythonFiles(root, files): @@ -84,8 +84,7 @@ def DispatchPythonTests(options): # Copy files to each device before running any tests. for device_id in attached_devices: logging.debug('Pushing files to device %s', device_id) - apks = [apk_and_jar_info.ApkAndJarInfo(options.test_apk_path, - options.test_apk_jar_path)] + apks = [apk_info.ApkInfo(options.test_apk_path, options.test_apk_jar_path)] test_files_copier = run_java_tests.TestRunner(options, device_id, None, False, 0, apks, []) test_files_copier.CopyTestFilesOnce() diff --git a/build/android/pylib/utils/apk_and_jar_info.py b/build/android/pylib/utils/apk_and_jar_info.py deleted file mode 100644 index 45c850b..0000000 --- a/build/android/pylib/utils/apk_and_jar_info.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2012 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. - -"""Gathers information about APKs/JARs.""" - -import logging -import os -import re - -from pylib import cmd_helper - -import apk_info -import jar_info - -class ApkAndJarInfo(apk_info.ApkInfo, jar_info.JarInfo): - """Helper class for for wrapping ApkInfo/JarInfo.""" - - def __init__(self, apk_path, jar_path): - apk_info.ApkInfo.__init__(self, apk_path) - jar_info.JarInfo.__init__(self, jar_path) - diff --git a/build/android/pylib/utils/apk_info.py b/build/android/pylib/utils/apk_info.py deleted file mode 100644 index fdcf9edc5..0000000 --- a/build/android/pylib/utils/apk_info.py +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) 2012 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. - -"""Gathers information about APKs.""" - -import logging -import os -import re - -# TODO(frankf): Move cmd_helper to utils. -from pylib import cmd_helper - - -def GetPackageNameForApk(apk_path): - """Returns the package name of this APK.""" - aapt_output = cmd_helper.GetCmdOutput( - ['aapt', 'dump', 'badging', apk_path]).split('\n') - package_name_re = re.compile(r'package: .*name=\'(\S*)\'') - for line in aapt_output: - m = package_name_re.match(line) - if m: - return m.group(1) - raise Exception('Failed to determine package name of %s' % apk_path) - - -class ApkInfo(object): - """Helper class for inspecting APKs.""" - - def __init__(self, apk_path): - if not os.path.exists(apk_path): - raise Exception('%s not found, please build it' % apk_path) - self._apk_path = apk_path - - def GetApkPath(self): - return self._apk_path - - def GetPackageName(self): - """Returns the package name of this APK.""" - return GetPackageNameForApk(self._apk_path) - diff --git a/build/android/run_instrumentation_tests.py b/build/android/run_instrumentation_tests.py index 1a68626..f484dac 100755 --- a/build/android/run_instrumentation_tests.py +++ b/build/android/run_instrumentation_tests.py @@ -11,6 +11,7 @@ import os import sys import time +from pylib import apk_info from pylib import buildbot_report from pylib import constants from pylib import ports @@ -19,7 +20,6 @@ from pylib import run_python_tests from pylib import run_tests_helper from pylib import test_options_parser from pylib.test_result import TestResults -from pylib.utils import apk_and_jar_info def DispatchInstrumentationTests(options): @@ -49,8 +49,7 @@ def DispatchInstrumentationTests(options): if options.run_java_tests: java_results = run_java_tests.DispatchJavaTests( options, - [apk_and_jar_info.ApkAndJarInfo(options.test_apk_path, - options.test_apk_jar_path)]) + [apk_info.ApkInfo(options.test_apk_path, options.test_apk_jar_path)]) if options.run_python_tests: python_results = run_python_tests.DispatchPythonTests(options) |