diff options
author | jbudorick <jbudorick@chromium.org> | 2015-05-19 10:09:11 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-19 17:09:13 +0000 |
commit | 581d25e509e4a2b1e8927c6d8accc0c90ea86090 (patch) | |
tree | f8786614edb85c0ebeeed5c0f026d9f99b02bc00 /build/android | |
parent | 5a4fd7ca1f00be3a761dee42df4da84064a9f81f (diff) | |
download | chromium_src-581d25e509e4a2b1e8927c6d8accc0c90ea86090.zip chromium_src-581d25e509e4a2b1e8927c6d8accc0c90ea86090.tar.gz chromium_src-581d25e509e4a2b1e8927c6d8accc0c90ea86090.tar.bz2 |
[Android] Refactor the native test wrappers.
BUG=476410
Review URL: https://codereview.chromium.org/1126543009
Cr-Commit-Position: refs/heads/master@{#330531}
Diffstat (limited to 'build/android')
-rw-r--r-- | build/android/pylib/constants/__init__.py | 6 | ||||
-rw-r--r-- | build/android/pylib/gtest/gtest_test_instance.py | 19 | ||||
-rw-r--r-- | build/android/pylib/gtest/local_device_gtest_run.py | 34 | ||||
-rw-r--r-- | build/android/pylib/gtest/setup.py | 4 | ||||
-rw-r--r-- | build/android/pylib/gtest/test_package_apk.py | 10 | ||||
-rw-r--r-- | build/android/pylib/gtest/test_runner.py | 1 | ||||
-rw-r--r-- | build/android/pylib/instrumentation/instrumentation_test_instance.py | 12 | ||||
-rw-r--r-- | build/android/pylib/utils/apk_helper.py | 73 |
8 files changed, 103 insertions, 56 deletions
diff --git a/build/android/pylib/constants/__init__.py b/build/android/pylib/constants/__init__.py index cb5f899..4523188 100644 --- a/build/android/pylib/constants/__init__.py +++ b/build/android/pylib/constants/__init__.py @@ -102,7 +102,7 @@ PACKAGE_INFO = { 'org.chromium.android_webview.test'), 'gtest': PackageInfo( 'org.chromium.native_test', - 'org.chromium.native_test.NativeTestActivity', + 'org.chromium.native_test.NativeUnitTestActivity', '/data/local/tmp/chrome-native-tests-command-line', None, None), @@ -110,13 +110,13 @@ PACKAGE_INFO = { 'org.chromium.components_browsertests_apk', ('org.chromium.components_browsertests_apk' + '.ComponentsBrowserTestsActivity'), - '/data/local/tmp/components-browser-tests-command-line', + '/data/local/tmp/chrome-native-tests-command-line', None, None), 'content_browsertests': PackageInfo( 'org.chromium.content_browsertests_apk', 'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity', - '/data/local/tmp/content-browser-tests-command-line', + '/data/local/tmp/chrome-native-tests-command-line', None, None), 'chromedriver_webview_shell': PackageInfo( diff --git a/build/android/pylib/gtest/gtest_test_instance.py b/build/android/pylib/gtest/gtest_test_instance.py index b6f83b3..cea5016 100644 --- a/build/android/pylib/gtest/gtest_test_instance.py +++ b/build/android/pylib/gtest/gtest_test_instance.py @@ -17,6 +17,12 @@ sys.path.append(os.path.join( import unittest_util +BROWSER_TEST_SUITES = [ + 'components_browsertests', + 'content_browsertests', +] + + # Used for filtering large data deps at a finer grain than what's allowed in # isolate files since pushing deps to devices is expensive. # Wildcards are allowed. @@ -92,16 +98,9 @@ class GtestTestInstance(test_instance.TestInstance): raise ValueError('Platform mode currently supports only 1 gtest suite') self._suite = args.suite_name[0] - if (self._suite == 'content_browsertests' or - self._suite == 'components_browsertests'): - error_func('%s are not currently supported ' - 'in platform mode.' % self._suite) - self._apk_path = os.path.join( - constants.GetOutDirectory(), 'apks', '%s.apk' % self._suite) - else: - self._apk_path = os.path.join( - constants.GetOutDirectory(), '%s_apk' % self._suite, - '%s-debug.apk' % self._suite) + self._apk_path = os.path.join( + constants.GetOutDirectory(), '%s_apk' % self._suite, + '%s-debug.apk' % self._suite) self._exe_path = os.path.join(constants.GetOutDirectory(), self._suite) if not os.path.exists(self._apk_path): diff --git a/build/android/pylib/gtest/local_device_gtest_run.py b/build/android/pylib/gtest/local_device_gtest_run.py index 4241e85..15a58a4 100644 --- a/build/android/pylib/gtest/local_device_gtest_run.py +++ b/build/android/pylib/gtest/local_device_gtest_run.py @@ -24,6 +24,9 @@ _EXTRA_COMMAND_LINE_FILE = ( 'org.chromium.native_test.NativeTestActivity.CommandLineFile') _EXTRA_COMMAND_LINE_FLAGS = ( 'org.chromium.native_test.NativeTestActivity.CommandLineFlags') +_EXTRA_NATIVE_TEST_ACTIVITY = ( + 'org.chromium.native_test.NativeTestInstrumentationTestRunner' + '.NativeTestActivity') _MAX_SHARD_SIZE = 256 @@ -37,8 +40,11 @@ _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ class _ApkDelegate(object): def __init__(self, apk): self._apk = apk - self._package = apk_helper.GetPackageName(self._apk) - self._runner = apk_helper.GetInstrumentationName(self._apk) + + helper = apk_helper.ApkHelper(self._apk) + self._activity = helper.GetActivityName() + self._package = helper.GetPackageName() + self._runner = helper.GetInstrumentationName() self._component = '%s/%s' % (self._package, self._runner) self._enable_test_server_spawner = False @@ -51,6 +57,7 @@ class _ApkDelegate(object): extras = { _EXTRA_COMMAND_LINE_FILE: command_line_file.name, + _EXTRA_NATIVE_TEST_ACTIVITY: self._activity, } return device.StartInstrumentation( @@ -132,7 +139,7 @@ class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun): #override def TestPackage(self): - return self._test_instance._suite + return self._test_instance.suite #override def SetUp(self): @@ -166,13 +173,16 @@ class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun): #override def _CreateShards(self, tests): - device_count = len(self._env.devices) - shards = [] - for i in xrange(0, device_count): - unbounded_shard = tests[i::device_count] - shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] - for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] - return [':'.join(s) for s in shards] + if self._test_instance.suite in gtest_test_instance.BROWSER_TEST_SUITES: + return tests + else: + device_count = len(self._env.devices) + shards = [] + for i in xrange(0, device_count): + unbounded_shard = tests[i::device_count] + shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] + for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] + return [':'.join(s) for s in shards] #override def _GetTests(self): @@ -185,8 +195,8 @@ class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun): #override def _RunTest(self, device, test): # Run the test. - output = self._delegate.RunWithFlags(device, '--gtest_filter=%s' % test, - timeout=900, retries=0) + output = self._delegate.RunWithFlags( + device, '--gtest_filter=%s' % test, timeout=900, retries=0) for s in self._servers[str(device)]: s.Reset() self._delegate.Clear(device) diff --git a/build/android/pylib/gtest/setup.py b/build/android/pylib/gtest/setup.py index d51b90e..8ba9a8d 100644 --- a/build/android/pylib/gtest/setup.py +++ b/build/android/pylib/gtest/setup.py @@ -15,6 +15,7 @@ from pylib.base import base_setup from pylib.base import base_test_result from pylib.base import test_dispatcher from pylib.device import device_utils +from pylib.gtest import gtest_test_instance from pylib.gtest import test_package_apk from pylib.gtest import test_package_exe from pylib.gtest import test_runner @@ -240,8 +241,7 @@ def Setup(test_options, devices): tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter) # Coalesce unit tests into a single test per device - if (test_options.suite_name != 'content_browsertests' and - test_options.suite_name != 'components_browsertests'): + if test_options.suite_name not in gtest_test_instance.BROWSER_TEST_SUITES: num_devices = len(devices) tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] tests = [t for t in tests if t] diff --git a/build/android/pylib/gtest/test_package_apk.py b/build/android/pylib/gtest/test_package_apk.py index 9672f7a..6447820 100644 --- a/build/android/pylib/gtest/test_package_apk.py +++ b/build/android/pylib/gtest/test_package_apk.py @@ -30,18 +30,14 @@ class TestPackageApk(TestPackage): suite_name: Name of the test suite (e.g. base_unittests). """ TestPackage.__init__(self, suite_name) + self.suite_path = os.path.join( + constants.GetOutDirectory(), '%s_apk' % suite_name, + '%s-debug.apk' % suite_name) if suite_name == 'content_browsertests': - self.suite_path = os.path.join( - constants.GetOutDirectory(), 'apks', '%s.apk' % suite_name) self._package_info = constants.PACKAGE_INFO['content_browsertests'] elif suite_name == 'components_browsertests': - self.suite_path = os.path.join( - constants.GetOutDirectory(), 'apks', '%s.apk' % suite_name) self._package_info = constants.PACKAGE_INFO['components_browsertests'] else: - self.suite_path = os.path.join( - constants.GetOutDirectory(), '%s_apk' % suite_name, - '%s-debug.apk' % suite_name) self._package_info = constants.PACKAGE_INFO['gtest'] def _CreateCommandLineFileOnDevice(self, device, options): diff --git a/build/android/pylib/gtest/test_runner.py b/build/android/pylib/gtest/test_runner.py index 4926388..6d01990 100644 --- a/build/android/pylib/gtest/test_runner.py +++ b/build/android/pylib/gtest/test_runner.py @@ -11,6 +11,7 @@ from pylib import ports from pylib.base import base_test_result from pylib.base import base_test_runner from pylib.device import device_errors +from pylib.gtest import gtest_test_instance from pylib.local import local_test_server_spawner from pylib.perf import perf_control diff --git a/build/android/pylib/instrumentation/instrumentation_test_instance.py b/build/android/pylib/instrumentation/instrumentation_test_instance.py index 0633f14..f9957b0 100644 --- a/build/android/pylib/instrumentation/instrumentation_test_instance.py +++ b/build/android/pylib/instrumentation/instrumentation_test_instance.py @@ -201,8 +201,9 @@ class InstrumentationTestInstance(test_instance.TestInstance): if not os.path.exists(self._test_jar): error_func('Unable to find test JAR: %s' % self._test_jar) - self._test_package = apk_helper.GetPackageName(self.test_apk) - self._test_runner = apk_helper.GetInstrumentationName(self.test_apk) + apk = apk_helper.ApkHelper(self.test_apk) + self._test_package = apk.GetPackageName() + self._test_runner = apk.GetInstrumentationName() self._package_info = None for package_info in constants.PACKAGE_INFO.itervalues(): @@ -274,10 +275,9 @@ class InstrumentationTestInstance(test_instance.TestInstance): constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, 'OnDeviceInstrumentationDriver.apk') if os.path.exists(self._driver_apk): - self._driver_package = apk_helper.GetPackageName( - self._driver_apk) - self._driver_name = apk_helper.GetInstrumentationName( - self._driver_apk) + driver_apk = apk_helper.ApkHelper(self._driver_apk) + self._driver_package = driver_apk.GetPackageName() + self._driver_name = driver_apk.GetInstrumentationName() else: self._driver_apk = None diff --git a/build/android/pylib/utils/apk_helper.py b/build/android/pylib/utils/apk_helper.py index f5e9cd3..6dd209e 100644 --- a/build/android/pylib/utils/apk_helper.py +++ b/build/android/pylib/utils/apk_helper.py @@ -19,14 +19,14 @@ _MANIFEST_ELEMENT_RE = re.compile(r'\s*(?:E|N): (\S*) .*$') def GetPackageName(apk_path): """Returns the package name of the apk.""" - aapt_cmd = [_AAPT_PATH, 'dump', 'badging', apk_path] - aapt_output = cmd_helper.GetCmdOutput(aapt_cmd).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) + return ApkHelper(apk_path).GetPackageName() + + +# TODO(jbudorick): Deprecate and remove this function once callers have been +# converted to ApkHelper.GetInstrumentationName +def GetInstrumentationName(apk_path): + """Returns the name of the Instrumentation in the apk.""" + return ApkHelper(apk_path).GetInstrumentationName() def _ParseManifestFromApk(apk_path): @@ -65,12 +65,53 @@ def _ParseManifestFromApk(apk_path): return parsed_manifest -def GetInstrumentationName( - apk_path, default='android.test.InstrumentationTestRunner'): - """Returns the name of the Instrumentation in the apk.""" +class ApkHelper(object): + def __init__(self, apk_path): + self._apk_path = apk_path + self._manifest = None + self._package_name = None + + def GetActivityName(self): + """Returns the name of the Activity in the apk.""" + manifest_info = self._GetManifest() + try: + activity = ( + manifest_info['manifest']['application']['activity'] + ['android:name'][0]) + except KeyError: + return None + if '.' not in activity: + activity = '%s.%s' % (self.GetPackageName(), activity) + elif activity.startswith('.'): + activity = '%s%s' % (self.GetPackageName(), activity) + return activity + + def GetInstrumentationName( + self, default='android.test.InstrumentationTestRunner'): + """Returns the name of the Instrumentation in the apk.""" + manifest_info = self._GetManifest() + try: + return manifest_info['manifest']['instrumentation']['android:name'][0] + except KeyError: + return default + + def GetPackageName(self): + """Returns the package name of the apk.""" + if self._package_name: + return self._package_name + + aapt_cmd = [_AAPT_PATH, 'dump', 'badging', self._apk_path] + aapt_output = cmd_helper.GetCmdOutput(aapt_cmd).split('\n') + package_name_re = re.compile(r'package: .*name=\'(\S*)\'') + for line in aapt_output: + m = package_name_re.match(line) + if m: + self._package_name = m.group(1) + return self._package_name + raise Exception('Failed to determine package name of %s' % self._apk_path) + + def _GetManifest(self): + if not self._manifest: + self._manifest = _ParseManifestFromApk(self._apk_path) + return self._manifest - try: - manifest_info = _ParseManifestFromApk(apk_path) - return manifest_info['manifest']['instrumentation']['android:name'][0] - except KeyError: - return default |