summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rw-r--r--build/android/pylib/constants/__init__.py6
-rw-r--r--build/android/pylib/gtest/gtest_test_instance.py19
-rw-r--r--build/android/pylib/gtest/local_device_gtest_run.py34
-rw-r--r--build/android/pylib/gtest/setup.py4
-rw-r--r--build/android/pylib/gtest/test_package_apk.py10
-rw-r--r--build/android/pylib/gtest/test_runner.py1
-rw-r--r--build/android/pylib/instrumentation/instrumentation_test_instance.py12
-rw-r--r--build/android/pylib/utils/apk_helper.py73
-rw-r--r--build/apk_browsertest.gypi43
-rw-r--r--build/config/android/rules.gni2
10 files changed, 148 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
diff --git a/build/apk_browsertest.gypi b/build/apk_browsertest.gypi
new file mode 100644
index 0000000..316f52f
--- /dev/null
+++ b/build/apk_browsertest.gypi
@@ -0,0 +1,43 @@
+# 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.
+
+# This file is meant to be included into a target to provide a rule
+# to build APK-based browser test suites.
+#
+# To use this, create a gyp target with the following form:
+# {
+# 'target_name': 'test_suite_name_apk',
+# 'type': 'none',
+# 'variables': {
+# 'test_suite_name': 'test_suite_name', # string
+# 'java_in_dir': 'path/to/java/dir',
+# },
+# 'includes': ['path/to/this/gypi/file'],
+# }
+#
+
+{
+ 'dependencies': [
+ '<(DEPTH)/base/base.gyp:base_java',
+ '<(DEPTH)/build/android/pylib/device/commands/commands.gyp:chromium_commands',
+ '<(DEPTH)/build/android/pylib/remote/device/dummy/dummy.gyp:remote_device_dummy_apk',
+ '<(DEPTH)/testing/android/appurify_support.gyp:appurify_support_java',
+ '<(DEPTH)/testing/android/native_test.gyp:native_test_java',
+ '<(DEPTH)/tools/android/android_tools.gyp:android_tools',
+ ],
+ 'conditions': [
+ ['OS == "android"', {
+ 'variables': {
+ # These are used to configure java_apk.gypi included below.
+ 'apk_name': '<(test_suite_name)',
+ 'intermediate_dir': '<(PRODUCT_DIR)/<(test_suite_name)_apk',
+ 'final_apk_path': '<(intermediate_dir)/<(test_suite_name)-debug.apk',
+ 'native_lib_target': 'lib<(test_suite_name)',
+ # TODO(yfriedman, cjhopman): Support managed installs for gtests.
+ 'gyp_managed_install': 0,
+ },
+ 'includes': [ 'java_apk.gypi' ],
+ }], # 'OS == "android"
+ ], # conditions
+}
diff --git a/build/config/android/rules.gni b/build/config/android/rules.gni
index 488d972..11137e7 100644
--- a/build/config/android/rules.gni
+++ b/build/config/android/rules.gni
@@ -1608,7 +1608,9 @@ template("unittest_apk") {
android_apk(target_name) {
final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
java_files = [
+ "//testing/android/native_test/java/src/org/chromium/native_test/NativeBrowserTestActivity.java",
"//testing/android/native_test/java/src/org/chromium/native_test/NativeTestActivity.java",
+ "//testing/android/native_test/java/src/org/chromium/native_test/NativeUnitTestActivity.java",
"//testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java",
]
android_manifest = "//testing/android/native_test/java/AndroidManifest.xml"