From a13ac58a88dff1e0ddc35107af77aee46f240f6f Mon Sep 17 00:00:00 2001 From: jingwen Date: Fri, 17 Nov 2017 12:28:22 -0800 Subject: Shard android_integration_test's sdk, proguard and aar tests out to improve performance. Shaves ~30-40 seconds off the critical path. The critical path is now dominated by the NDK test, but that's out of scope for this change. See below for data. BEFORE: $ bazel test //src/test/shell/bazel/android:android_integration_test INFO: Analysed target //src/test/shell/bazel/android:android_integration_test (0 packages loaded). INFO: Found 1 test target... [4 / 5] Testing //src/test/shell/bazel/android:android_integration_test; 23s linux-sandbox Target //src/test/shell/bazel/android:android_integration_test up-to-date: /tmp/bazel-bin/src/test/shell/bazel/android/android_integration_test INFO: Elapsed time: 93.696s, Critical Path: 93.37s INFO: Build completed successfully, 2 total actions //src/test/shell/bazel/android:android_integration_test PASSED in 93.4s AFTER: $ bazel test :all --nocache_test_results WARNING: The major revision of the Android NDK referenced by android_ndk_repository rule 'androidndk' is 15. The major revisions supported by Bazel are [10, 11, 12, 13, 14]. Defaulting to revision 14. WARNING: API level 26 specified by android_ndk_repository 'androidndk' is not available. Using latest known API level 25 INFO: Analysed 9 targets (0 packages loaded). INFO: Found 2 targets and 7 test targets... INFO: Elapsed time: 106.452s, Critical Path: 105.66s INFO: Build completed successfully, 8 total actions //src/test/shell/bazel/android:aidl_integration_test PASSED in 43.9s //src/test/shell/bazel/android:android_integration_test PASSED in 55.1s //src/test/shell/bazel/android:android_ndk_integration_test PASSED in 105.6s //src/test/shell/bazel/android:android_sdk_integration_test PASSED in 68.4s //src/test/shell/bazel/android:desugarer_integration_test PASSED in 43.9s //src/test/shell/bazel/android:proguard_integration_test PASSED in 43.7s //src/test/shell/bazel/android:resources_integration_test PASSED in 51.4s Executed 7 out of 7 tests: 7 tests pass. RELNOTES: None. PiperOrigin-RevId: 176144822 --- src/test/shell/bazel/android/BUILD | 52 ++++- .../shell/bazel/android/aar_integration_test.sh | 81 ++++++++ .../shell/bazel/android/aidl_integration_test.sh | 10 +- src/test/shell/bazel/android/android_helper.sh | 84 ++++++++ .../bazel/android/android_integration_test.sh | 227 +-------------------- .../bazel/android/android_ndk_integration_test.sh | 20 +- .../bazel/android/android_sdk_integration_test.sh | 104 ++++++++++ .../bazel/android/desugarer_integration_test.sh | 10 +- .../bazel/android/proguard_integration_test.sh | 88 ++++++++ 9 files changed, 425 insertions(+), 251 deletions(-) create mode 100755 src/test/shell/bazel/android/aar_integration_test.sh create mode 100755 src/test/shell/bazel/android/android_helper.sh create mode 100755 src/test/shell/bazel/android/android_sdk_integration_test.sh create mode 100755 src/test/shell/bazel/android/proguard_integration_test.sh (limited to 'src') diff --git a/src/test/shell/bazel/android/BUILD b/src/test/shell/bazel/android/BUILD index f8928ddd16..d371b041ac 100644 --- a/src/test/shell/bazel/android/BUILD +++ b/src/test/shell/bazel/android/BUILD @@ -17,12 +17,51 @@ filegroup( # tools/android/android_sdk_repository_template.bzl and # src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_ndk_build_file_template.txt +sh_library( + name = "android_helper", + srcs = ["android_helper.sh"], + data = ["sample.aar"], +) + sh_test( name = "android_integration_test", - size = "large", + size = "medium", srcs = ["android_integration_test.sh"], data = [ - "sample.aar", + ":android_helper", + "//external:android_sdk_for_testing", + "//src/test/shell/bazel:test-deps", + ], +) + +sh_test( + name = "aar_integration_test", + size = "medium", + srcs = ["aar_integration_test.sh"], + data = [ + ":android_helper", + "//external:android_sdk_for_testing", + "//src/test/shell/bazel:test-deps", + ], +) + +sh_test( + name = "proguard_integration_test", + size = "medium", + srcs = ["proguard_integration_test.sh"], + data = [ + ":android_helper", + "//external:android_sdk_for_testing", + "//src/test/shell/bazel:test-deps", + ], +) + +sh_test( + name = "android_sdk_integration_test", + size = "medium", + srcs = ["android_sdk_integration_test.sh"], + data = [ + ":android_helper", "//external:android_sdk_for_testing", "//src/test/shell/bazel:test-deps", ], @@ -30,9 +69,10 @@ sh_test( sh_test( name = "android_ndk_integration_test", - size = "large", + size = "medium", srcs = ["android_ndk_integration_test.sh"], data = [ + ":android_helper", "//external:android_ndk_for_testing", "//external:android_sdk_for_testing", "//src/test/shell/bazel:test-deps", @@ -41,9 +81,10 @@ sh_test( sh_test( name = "aidl_integration_test", - size = "large", + size = "medium", srcs = ["aidl_integration_test.sh"], data = [ + ":android_helper", "//external:android_sdk_for_testing", "//src/test/shell/bazel:test-deps", ], @@ -51,9 +92,10 @@ sh_test( sh_test( name = "desugarer_integration_test", - size = "large", + size = "medium", srcs = ["desugarer_integration_test.sh"], data = [ + ":android_helper", "//external:android_sdk_for_testing", "//src/test/shell/bazel:test-deps", ], diff --git a/src/test/shell/bazel/android/aar_integration_test.sh b/src/test/shell/bazel/android/aar_integration_test.sh new file mode 100755 index 0000000000..7ecd3c08a2 --- /dev/null +++ b/src/test/shell/bazel/android/aar_integration_test.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For these tests to run do the following: +# +# 1. Install an Android SDK from https://developer.android.com +# 2. Set the $ANDROID_HOME environment variable +# 3. Uncomment the line in WORKSPACE containing android_sdk_repository +# +# Note that if the environment is not set up as above android_integration_test +# will silently be ignored and will be shown as passing. + +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${CURRENT_DIR}/android_helper.sh" \ + || { echo "android_helper.sh not found!" >&2; exit 1; } +fail_if_no_android_sdk + +source "${CURRENT_DIR}/../../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + +# Regression test for https://github.com/bazelbuild/bazel/issues/1928. +function test_empty_tree_artifact_action_inputs_mount_empty_directories() { + create_new_workspace + setup_android_sdk_support + cat > AndroidManifest.xml < +EOF + mkdir res + zip test.aar AndroidManifest.xml res/ + cat > BUILD < AndroidManifest.xml < +EOF + mkdir -p res/values + cat > res/values/values.xml < + + +EOF + zip test.aar AndroidManifest.xml res/values/values.xml + cat > BUILD <&2; exit 1; } +fail_if_no_android_sdk + source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } @@ -64,9 +69,4 @@ EOF || fail "build failed" } -if [[ ! -r "${TEST_SRCDIR}/androidsdk" ]]; then - echo "Not running Android tests due to lack of an Android SDK." - exit 0 -fi - run_suite "Android IDL tests" diff --git a/src/test/shell/bazel/android/android_helper.sh b/src/test/shell/bazel/android/android_helper.sh new file mode 100755 index 0000000000..826d966297 --- /dev/null +++ b/src/test/shell/bazel/android/android_helper.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +function fail_if_no_android_sdk() { + if [[ ! -d "${TEST_SRCDIR}/androidsdk" ]]; then + echo "Not running Android tests due to lack of an Android SDK." + exit 1 + fi +} + +function fail_if_no_android_ndk() { + # ndk r10 and earlier + if [[ ! -r "${TEST_SRCDIR}/androidndk/ndk/RELEASE.TXT" ]]; then + # ndk r11 and later + if [[ ! -r "${TEST_SRCDIR}/androidndk/ndk/source.properties" ]]; then + echo "Not running Android NDK tests due to lack of an Android NDK." + exit 1 + fi + fi +} + +function create_android_binary() { + mkdir -p java/bazel + cat > java/bazel/BUILD < java/bazel/AndroidManifest.xml < +EOF + + cat > java/bazel/Lib.java < java/bazel/MainActivity.java <&2; exit 1; } - - -function create_android_binary() { - mkdir -p java/bazel - cat > java/bazel/BUILD < java/bazel/AndroidManifest.xml < -EOF - - cat > java/bazel/Lib.java < java/bazel/MainActivity.java <&2; exit 1; } +fail_if_no_android_sdk -public class MainActivity extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } -} -EOF -} +source "${CURRENT_DIR}/../../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_sdk_library_deps() { create_new_workspace @@ -95,119 +48,6 @@ EOF bazel build --nobuild //java/a:a || fail "build failed" } -# Regression test for https://github.com/bazelbuild/bazel/issues/1928. -function test_empty_tree_artifact_action_inputs_mount_empty_directories() { - create_new_workspace - setup_android_sdk_support - cat > AndroidManifest.xml < -EOF - mkdir res - zip test.aar AndroidManifest.xml res/ - cat > BUILD < AndroidManifest.xml < -EOF - mkdir -p res/values - cat > res/values/values.xml < - - -EOF - zip test.aar AndroidManifest.xml res/values/values.xml - cat > BUILD < WORKSPACE < WORKSPACE <& $TEST_log && fail "Should have failed" - expect_log "Either the path attribute of android_sdk_repository" -} - -function test_android_sdk_repository_wrong_path() { - create_new_workspace - mkdir "$TEST_SRCDIR/some_dir" - cat > WORKSPACE <& $TEST_log && fail "Should have failed" - expect_log "Unable to read the Android SDK at $TEST_SRCDIR/some_dir, the path may be invalid." \ - " Is the path in android_sdk_repository() or \$ANDROID_SDK_HOME set correctly?" -} - -# Check that the build succeeds if an android_sdk is specified with --android_sdk -function test_specifying_android_sdk_flag() { - create_new_workspace - setup_android_sdk_support - create_android_binary - cat > WORKSPACE < java/com/bin/BUILD < java/com/bin/AndroidManifest.xml < -EOF - cat > java/com/bin/Bin.java < java/com/bin/NotUsed.java < java/com/bin/Lib.java < java/com/bin/proguard.config <&2; exit 1; } +fail_if_no_android_sdk +fail_if_no_android_ndk + source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } @@ -298,18 +304,4 @@ EOF " Is the path in android_ndk_repository() or \$ANDROID_NDK_HOME set correctly?" } -# ndk r10 and earlier -if [[ ! -r "${TEST_SRCDIR}/androidndk/ndk/RELEASE.TXT" ]]; then - # ndk r11 and later - if [[ ! -r "${TEST_SRCDIR}/androidndk/ndk/source.properties" ]]; then - echo "Not running Android NDK tests due to lack of an Android NDK." - exit 0 - fi -fi - -if [[ ! -d "${TEST_SRCDIR}/androidsdk" ]]; then - echo "Not running Android NDK tests due to lack of an Android SDK." - exit 0 -fi - run_suite "Android NDK integration tests" diff --git a/src/test/shell/bazel/android/android_sdk_integration_test.sh b/src/test/shell/bazel/android/android_sdk_integration_test.sh new file mode 100755 index 0000000000..27f1905e7b --- /dev/null +++ b/src/test/shell/bazel/android/android_sdk_integration_test.sh @@ -0,0 +1,104 @@ +#!/bin/bash +# +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For these tests to run do the following: +# +# 1. Install an Android SDK from https://developer.android.com +# 2. Set the $ANDROID_HOME environment variable +# 3. Uncomment the line in WORKSPACE containing android_sdk_repository +# +# Note that if the environment is not set up as above android_integration_test +# will silently be ignored and will be shown as passing. + +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${CURRENT_DIR}/android_helper.sh" \ + || { echo "android_helper.sh not found!" >&2; exit 1; } +fail_if_no_android_sdk + +source "${CURRENT_DIR}/../../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + +function test_android_sdk_repository_path_from_environment() { + create_new_workspace + setup_android_sdk_support + # Overwrite WORKSPACE that was created by setup_android_sdk_support with one + # that does not set the path attribute of android_sdk_repository. + cat > WORKSPACE < WORKSPACE <& $TEST_log && fail "Should have failed" + expect_log "Either the path attribute of android_sdk_repository" +} + +function test_android_sdk_repository_wrong_path() { + create_new_workspace + mkdir "$TEST_SRCDIR/some_dir" + cat > WORKSPACE <& $TEST_log && fail "Should have failed" + expect_log "Unable to read the Android SDK at $TEST_SRCDIR/some_dir, the path may be invalid." \ + " Is the path in android_sdk_repository() or \$ANDROID_SDK_HOME set correctly?" +} + +# Check that the build succeeds if an android_sdk is specified with --android_sdk +function test_specifying_android_sdk_flag() { + create_new_workspace + setup_android_sdk_support + create_android_binary + cat > WORKSPACE <&2; exit 1; } +fail_if_no_android_sdk + source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } @@ -81,9 +86,4 @@ function test_java_8_android_binary() { || fail "build failed" } -if [[ ! -d "${TEST_SRCDIR}/androidsdk" ]]; then - echo "Not running Android desugarer tests due to lack of an Android SDK." - exit 0 -fi - run_suite "Android desugarer integration tests" diff --git a/src/test/shell/bazel/android/proguard_integration_test.sh b/src/test/shell/bazel/android/proguard_integration_test.sh new file mode 100755 index 0000000000..0fb1e2eb1f --- /dev/null +++ b/src/test/shell/bazel/android/proguard_integration_test.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For these tests to run do the following: +# +# 1. Install an Android SDK from https://developer.android.com +# 2. Set the $ANDROID_HOME environment variable +# 3. Uncomment the line in WORKSPACE containing android_sdk_repository +# +# Note that if the environment is not set up as above android_integration_test +# will silently be ignored and will be shown as passing. + +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${CURRENT_DIR}/android_helper.sh" \ + || { echo "android_helper.sh not found!" >&2; exit 1; } +fail_if_no_android_sdk + +source "${CURRENT_DIR}/../../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + +function test_proguard() { + create_new_workspace + setup_android_sdk_support + mkdir -p java/com/bin + cat > java/com/bin/BUILD < java/com/bin/AndroidManifest.xml < +EOF + cat > java/com/bin/Bin.java < java/com/bin/NotUsed.java < java/com/bin/Lib.java < java/com/bin/proguard.config <