Skip to content

Commit

Permalink
[Android] Fix generated scripts for junit tests.
Browse files Browse the repository at this point in the history
Adding scripts to make it easy to run junit test. These are named
out/bin/run_<junit_suite_name>.

Moving the helper scripts that our test runner uses to run the
junit test suites. These scripts are not meant to be run except
by the test runner. Moving them into out/bin/helper/<script_names>
so people don't accidently try to run them.

BUG=511999

Review URL: https://codereview.chromium.org/1674353004

Cr-Commit-Position: refs/heads/master@{#375603}
  • Loading branch information
case540 authored and Commit bot committed Feb 16, 2016
1 parent b999865 commit 713185d
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 17 deletions.
18 changes: 11 additions & 7 deletions base/base.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,13 +1545,17 @@
'../testing/android/junit/junit_test.gyp:junit_test_support',
],
'variables': {
'main_class': 'org.chromium.testing.local.JunitTestMain',
'src_paths': [
'../base/android/junit/',
'../base/test/android/junit/src/org/chromium/base/test/util/DisableIfTest.java',
],
},
'includes': [ '../build/host_jar.gypi' ],
'main_class': 'org.chromium.testing.local.JunitTestMain',
'src_paths': [
'../base/android/junit/',
'../base/test/android/junit/src/org/chromium/base/test/util/DisableIfTest.java',
],
'test_type': 'junit',
},
'includes': [
'../build/android/test_runner.gypi',
'../build/host_jar.gypi',
],
},
{
# GN: //base:base_javatests
Expand Down
2 changes: 1 addition & 1 deletion build/android/pylib/junit/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def RunTest(self, _test):
"""Runs junit tests from |self._test_suite|."""
with tempfile.NamedTemporaryFile() as json_file:
java_script = os.path.join(
constants.GetOutDirectory(), 'bin', self._test_suite)
constants.GetOutDirectory(), 'bin', 'helper', self._test_suite)
command = [java_script,
'-test-jars', self._test_suite + '.jar',
'-json-results-file', json_file.name]
Expand Down
13 changes: 13 additions & 0 deletions build/android/test_runner.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
# 'includes': ['path/to/this/gypi/file'],
# }
#
# {
# 'target_name': 'junit_test',
# 'type': 'none',
# 'variables': {
# 'test_type': 'junit', # string
# },
# 'includes': ['path/to/this/gypi/file'],
# }
#

{
'variables': {
Expand Down Expand Up @@ -55,6 +64,10 @@
}],
],
}],
['test_type == "junit"', {
'test_runner_args': ['--test-suite', '<(_target_name)'],
'script_name': 'run_<(_target_name)',
}],
['additional_apks != []', {
'test_runner_args': ['--additional-apk-list', '>(additional_apks)'],
}],
Expand Down
20 changes: 18 additions & 2 deletions build/config/android/internal_rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ template("java_binary_script") {
action(target_name) {
script = "//build/android/gyp/create_java_binary_script.py"
depfile = "$target_gen_dir/$_script_name.d"
java_script = "$root_build_dir/bin/$_script_name"
java_script = "$root_build_dir/bin/helper/$_script_name"
inputs = [
_build_config,
]
Expand Down Expand Up @@ -1303,6 +1303,9 @@ template("java_prebuilt_impl") {
build_config = _build_config
jar_path = _jar_path
script_name = _template_name
if (defined(invoker.wrapper_script_name)) {
script_name = invoker.wrapper_script_name
}
deps = [
":$_build_config_target_name",
]
Expand Down Expand Up @@ -1540,8 +1543,12 @@ template("java_library_impl") {

# Jar files can be needed at runtime (by Robolectric tests or java binaries),
# so do not put them under gen/.
_jar_name = target_name
if (defined(invoker.jar_name)) {
_jar_name = invoker.jar_name
}
target_dir_name = get_label_info(":$target_name", "dir")
_jar_path = "$root_out_dir/lib.java$target_dir_name/$target_name.jar"
_jar_path = "$root_out_dir/lib.java$target_dir_name/$_jar_name.jar"
if (defined(invoker.jar_path)) {
_jar_path = invoker.jar_path
}
Expand Down Expand Up @@ -1696,6 +1703,9 @@ template("java_library_impl") {
build_config = _build_config
jar_path = _jar_path
script_name = _template_name
if (defined(invoker.wrapper_script_name)) {
script_name = invoker.wrapper_script_name
}
deps = build_config_deps
}
}
Expand Down Expand Up @@ -2097,6 +2107,12 @@ template("test_runner_script") {
rebase_path("$root_out_dir/coverage", root_build_dir),
]
}
} else if (_test_type == "junit") {
assert(defined(invoker.test_suite))
test_runner_args += [
"--test-suite",
invoker.test_suite,
]
} else {
assert(false, "Invalid test type: $_test_type.")
}
Expand Down
26 changes: 20 additions & 6 deletions build/config/android/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -953,17 +953,25 @@ template("java_binary") {
# }
template("junit_binary") {
set_sources_assignment_filter([])
testonly = true

_java_binary_target_name = "${target_name}__java_binary"
_test_runner_target_name = "${target_name}__test_runner_script"

test_runner_script(_test_runner_target_name) {
test_name = invoker.target_name
test_suite = invoker.target_name
test_type = "junit"
}

java_binary(target_name) {
java_binary(_java_binary_target_name) {
deps = []
jar_name = invoker.target_name
forward_variables_from(invoker, "*")
testonly = true
bypass_platform_checks = true
main_class = "org.chromium.testing.local.JunitTestMain"
wrapper_script_args = [
"-test-jars",
"$target_name.jar",
]
testonly = true
wrapper_script_name = "$target_name"

deps += [
"//testing/android/junit:junit_test_support",
Expand All @@ -973,6 +981,12 @@ template("junit_binary") {
"//third_party/robolectric:robolectric_java",
]
}
group(target_name) {
public_deps = [
":$_java_binary_target_name",
":$_test_runner_target_name",
]
}
}

# Declare a java library target
Expand Down
2 changes: 1 addition & 1 deletion build/host_jar.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
'action_name': 'create_java_binary_script_<(_target_name)',
'message': 'Creating java binary script <(_target_name)',
'variables': {
'output': '<(PRODUCT_DIR)/bin/<(_target_name)',
'output': '<(PRODUCT_DIR)/bin/helper/<(_target_name)',
},
'inputs': [
'<(DEPTH)/build/android/gyp/create_java_binary_script.py',
Expand Down
2 changes: 2 additions & 0 deletions chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -3130,8 +3130,10 @@
'src_paths': [
'android/junit/',
],
'test_type': 'junit',
},
'includes': [
'../build/android/test_runner.gypi',
'../build/host_jar.gypi',
],
},
Expand Down
2 changes: 2 additions & 0 deletions content/content_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -2185,8 +2185,10 @@
'src_paths': [
'public/android/junit/',
],
'test_type': 'junit',
},
'includes': [
'../build/android/test_runner.gypi',
'../build/host_jar.gypi',
],
},
Expand Down
2 changes: 2 additions & 0 deletions net/net.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1646,8 +1646,10 @@
'src_paths': [
'android/junit/',
],
'test_type': 'junit',
},
'includes': [
'../build/android/test_runner.gypi',
'../build/host_jar.gypi',
],
},
Expand Down
2 changes: 2 additions & 0 deletions ui/android/ui_android.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@
'src_paths': [
'junit/',
],
'test_type': 'junit',
},
'includes': [
'../../build/android/test_runner.gypi',
'../../build/host_jar.gypi',
],
},
Expand Down

0 comments on commit 713185d

Please sign in to comment.