From fa389066641ac7f92b220ef232f23e757704318d Mon Sep 17 00:00:00 2001 From: Luis Fernando Pino Duque Date: Tue, 18 Oct 2016 14:28:42 +0000 Subject: [PATCH] Create a proper wrapper script for executing "bazel" in the integration tests. Currently a call to "bazel" in an integration test means calling a (quite hidden) function in test-setup.sh which actually calls "$bazel" defined in "shell/bazel/testenv.sh" which is equal to "$(rlocation io_bazel/src/bazel)". This is extremely confusing and error prone. The new mechanism is to add a wrapper script to shell/bin called bazel and export this directory to the PATH. Moreover, not every test loads the same test environment, for instance consider how bazel_query_test loads the test environment: - Load shell/integration/testenv.sh which loads, - shell/bazel/test-setup.sh which loads, - shell/bazel/testenv.sh which loads, - shell/unittest.bash which loads, - shell/testenv.sh Again this is error prone and specially hard to understand, in fact each test writer needs to decide which of these testenv to load. This change fixes all of this by having only one testenv.sh and summarizing the test setup in integration_test_setup.sh. Namely, for any new integration test, the developer needs to load integration_test_setup to get the environment set up including the unittest framework (also it helps to attract contributions). This change also allows to open sourcing client_sigint_test: Since bazel was a function client_sigint_test was using a wrong process id to interrupt the build. The problem is that $! returns bash's id instead of the id of the process running in the background when using a function instead of an executable. A few tests needed to be adapted to the new infrastructure. -- MOS_MIGRATED_REVID=136470360 --- src/test/shell/BUILD | 6 + src/test/shell/bazel/BUILD | 12 +- .../shell/bazel/apple/bazel_apple_test.sh | 7 +- src/test/shell/bazel/apple/bazel_objc_test.sh | 7 +- src/test/shell/bazel/bazel_example_test.sh | 7 +- src/test/shell/bazel/bazel_execute_testlog.sh | 7 +- src/test/shell/bazel/bazel_java_test.sh | 7 +- src/test/shell/bazel/bazel_localtest_test.sh | 7 +- src/test/shell/bazel/bazel_rules_test.sh | 11 +- .../shell/bazel/bazel_sandboxing_cpp_test.sh | 10 +- src/test/shell/bazel/bazel_sandboxing_test.sh | 11 +- src/test/shell/bazel/bazel_test_test.sh | 7 +- src/test/shell/bazel/bazel_toolchain_test.sh | 7 +- src/test/shell/bazel/bazel_tools_test.sh | 7 +- .../shell/bazel/bazel_windows_example_test.sh | 7 +- src/test/shell/bazel/bazel_worker_test.sh | 7 +- .../bazel/bazel_workspace_status_test.sh | 7 +- src/test/shell/bazel/bound_targets_test.sh | 7 +- src/test/shell/bazel/cc_inc_library_test.sh | 7 +- src/test/shell/bazel/client_test.sh | 7 +- src/test/shell/bazel/empty_package.sh | 7 +- src/test/shell/bazel/execroot_test.sh | 7 +- .../shell/bazel/external_correctness_test.sh | 6 +- .../shell/bazel/external_integration_test.sh | 10 +- .../shell/bazel/external_skylark_load_test.sh | 7 +- .../shell/bazel/generate_workspace_test.sh | 10 +- src/test/shell/bazel/git_repository_test.sh | 7 +- src/test/shell/bazel/help_test.sh | 7 +- src/test/shell/bazel/linux-sandbox_test.sh | 10 +- src/test/shell/bazel/local_repository_test.sh | 7 +- .../shell/bazel/local_repository_test_jdk8.sh | 7 +- src/test/shell/bazel/location_test.sh | 7 +- src/test/shell/bazel/maven_skylark_test.sh | 10 +- src/test/shell/bazel/maven_test.sh | 10 +- src/test/shell/bazel/process-wrapper_test.sh | 10 +- src/test/shell/bazel/remote_execution_test.sh | 8 +- src/test/shell/bazel/runfiles_test.sh | 7 +- .../shell/bazel/skylark_repository_test.sh | 10 +- src/test/shell/bazel/test-setup.sh | 267 -------- src/test/shell/bazel/testenv.sh | 234 ------- src/test/shell/bazel/workspace_test.sh | 7 +- src/test/shell/bin/bazel | 20 + src/test/shell/integration/BUILD | 11 +- src/test/shell/integration/action_env_test.sh | 53 +- .../integration/bazel_command_log_test.sh | 13 +- .../shell/integration/bazel_javabase_test.sh | 12 +- .../shell/integration/bazel_query_test.sh | 13 +- .../shell/integration/bazel_testjobs_test.sh | 14 +- .../shell/integration/client_sigint_test.sh | 87 +++ .../discard_analysis_cache_test.sh | 12 +- .../integration/discard_graph_edges_test.sh | 11 +- .../shell/integration/experimental_ui_test.sh | 46 +- .../shell/integration/ide_info_generation.sh | 61 +- .../integration/java_integration_test.sh | 47 +- .../shell/integration/loading_phase_tests.sh | 28 +- .../shell/integration/output_filter_test.sh | 11 +- .../integration/progress_reporting_test.sh | 19 +- src/test/shell/integration/rc_options_test.sh | 11 +- src/test/shell/integration/run_test.sh | 43 +- src/test/shell/integration/runfiles_test.sh | 11 +- .../shell/integration/startup_options_test.sh | 15 +- .../integration/stub_finds_runfiles_test.sh | 31 +- src/test/shell/integration/testenv.sh | 47 -- src/test/shell/integration/ui_test.sh | 11 +- src/test/shell/integration_test_setup.sh | 31 + src/test/shell/testenv.sh | 573 ++++++++++++++---- src/test/shell/unittest.bash | 143 ++++- 67 files changed, 1139 insertions(+), 1045 deletions(-) delete mode 100755 src/test/shell/bazel/test-setup.sh delete mode 100755 src/test/shell/bazel/testenv.sh create mode 100755 src/test/shell/bin/bazel create mode 100755 src/test/shell/integration/client_sigint_test.sh delete mode 100755 src/test/shell/integration/testenv.sh create mode 100755 src/test/shell/integration_test_setup.sh diff --git a/src/test/shell/BUILD b/src/test/shell/BUILD index 9db5e5bb6edc89..ed233cb28cb92a 100644 --- a/src/test/shell/BUILD +++ b/src/test/shell/BUILD @@ -1,5 +1,11 @@ package(default_visibility = ["//visibility:private"]) +exports_files([ + "bin/bazel", + "testenv.sh", + "integration_test_setup.sh", +]) + filegroup( name = "srcs", srcs = glob(["**"]) + [ diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index d815e5e97a9c69..3d70474b933cde 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -24,8 +24,6 @@ filegroup( srcs = [ "bazel_sandboxing_test_utils.sh", "remote_helpers.sh", - "test-setup.sh", - "testenv.sh", "testing_server.py", ":langtools-copy", "//examples:srcs", @@ -40,6 +38,9 @@ filegroup( "//src/main/tools:linux-sandbox", "//src/main/tools:process-wrapper", "//src/test/shell:bashunit", + "//src/test/shell:bin/bazel", + "//src/test/shell:integration_test_setup.sh", + "//src/test/shell:testenv.sh", "//third_party:srcs", "//third_party/ijar", "//third_party/java/jdk/langtools:test-srcs", @@ -271,12 +272,7 @@ sh_test( name = "process_wrapper_test", size = "small", srcs = ["process-wrapper_test.sh"], - data = [ - "test-setup.sh", - "testenv.sh", - "//src/main/tools:process-wrapper", - "//src/test/shell:bashunit", - ], + data = [":test-deps"], ) sh_test( diff --git a/src/test/shell/bazel/apple/bazel_apple_test.sh b/src/test/shell/bazel/apple/bazel_apple_test.sh index abf199bdcbf199..a2546b3de77248 100755 --- a/src/test/shell/bazel/apple/bazel_apple_test.sh +++ b/src/test/shell/bazel/apple/bazel_apple_test.sh @@ -17,9 +17,10 @@ # Tests the examples provided in Bazel # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } if [ "${PLATFORM}" != "darwin" ]; then echo "This test suite requires running on OS X" >&2 diff --git a/src/test/shell/bazel/apple/bazel_objc_test.sh b/src/test/shell/bazel/apple/bazel_objc_test.sh index 3b5edb895a67f1..325cb0b0c95ace 100755 --- a/src/test/shell/bazel/apple/bazel_objc_test.sh +++ b/src/test/shell/bazel/apple/bazel_objc_test.sh @@ -14,9 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } if [ "${PLATFORM}" != "darwin" ]; then echo "This test suite requires running on OS X" >&2 diff --git a/src/test/shell/bazel/bazel_example_test.sh b/src/test/shell/bazel/bazel_example_test.sh index c440a6eeaeee4b..b28c860e60fa0a 100755 --- a/src/test/shell/bazel/bazel_example_test.sh +++ b/src/test/shell/bazel/bazel_example_test.sh @@ -17,9 +17,10 @@ # Tests the examples provided in Bazel # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function set_up() { copy_examples diff --git a/src/test/shell/bazel/bazel_execute_testlog.sh b/src/test/shell/bazel/bazel_execute_testlog.sh index 9c9c2b4b7ec893..1c3bb952b30716 100755 --- a/src/test/shell/bazel/bazel_execute_testlog.sh +++ b/src/test/shell/bazel/bazel_execute_testlog.sh @@ -17,9 +17,10 @@ # Test the execution of test logs # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_execute_testlog() { mkdir dir diff --git a/src/test/shell/bazel/bazel_java_test.sh b/src/test/shell/bazel/bazel_java_test.sh index 8bc7bef8fdfa8e..d2d1346a16b154 100755 --- a/src/test/shell/bazel/bazel_java_test.sh +++ b/src/test/shell/bazel/bazel_java_test.sh @@ -17,9 +17,10 @@ # Tests the examples provided in Bazel # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function write_hello_library_files() { mkdir -p java/main diff --git a/src/test/shell/bazel/bazel_localtest_test.sh b/src/test/shell/bazel/bazel_localtest_test.sh index 0034d47eb6e63c..ea592a4ec77475 100755 --- a/src/test/shell/bazel/bazel_localtest_test.sh +++ b/src/test/shell/bazel/bazel_localtest_test.sh @@ -16,9 +16,10 @@ set -eu -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_run_local() { mkdir -p dir diff --git a/src/test/shell/bazel/bazel_rules_test.sh b/src/test/shell/bazel/bazel_rules_test.sh index b34a26bb772a68..93bfa4101d13ab 100755 --- a/src/test/shell/bazel/bazel_rules_test.sh +++ b/src/test/shell/bazel/bazel_rules_test.sh @@ -17,9 +17,10 @@ # Test rules provided in Bazel not tested by examples # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_sh_test() { mkdir -p a @@ -234,11 +235,11 @@ EOF local new_tmpdir="$(mktemp -d "${TEST_TMPDIR}/newfancytmpdirXXXXXX")" [ -d "${new_tmpdir}" ] || \ fail "Could not create new temporary directory ${new_tmpdir}" - export PATH="/bin:/usr/bin:/random/path" + export PATH="$PATH_TO_BAZEL_WRAPPER:/bin:/usr/bin:/random/path" export TMPDIR="${new_tmpdir}" # batch mode to force reload of the environment bazel --batch build //pkg:test || fail "Failed to build //pkg:test" - assert_contains "PATH=/bin:/usr/bin:/random/path" \ + assert_contains "PATH=$PATH_TO_BAZEL_WRAPPER:/bin:/usr/bin:/random/path" \ bazel-genfiles/pkg/test.out assert_contains "TMPDIR=.*newfancytmpdir" \ bazel-genfiles/pkg/test.out diff --git a/src/test/shell/bazel/bazel_sandboxing_cpp_test.sh b/src/test/shell/bazel/bazel_sandboxing_cpp_test.sh index 2c2710bf136c0d..272351da181c39 100755 --- a/src/test/shell/bazel/bazel_sandboxing_cpp_test.sh +++ b/src/test/shell/bazel/bazel_sandboxing_cpp_test.sh @@ -17,11 +17,11 @@ # Test C++ builds with the sandboxing spawn strategy. # -# Load test environment -src_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -source ${src_dir}/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } -source ${src_dir}/bazel_sandboxing_test_utils.sh \ +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +source ${CURRENT_DIR}/bazel_sandboxing_test_utils.sh \ || { echo "bazel_sandboxing_test_utils.sh not found!" >&2; exit 1; } function set_up { diff --git a/src/test/shell/bazel/bazel_sandboxing_test.sh b/src/test/shell/bazel/bazel_sandboxing_test.sh index 0b796683ed2e87..f827420a8ff583 100755 --- a/src/test/shell/bazel/bazel_sandboxing_test.sh +++ b/src/test/shell/bazel/bazel_sandboxing_test.sh @@ -18,12 +18,13 @@ # # Load test environment -src_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -source ${src_dir}/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } -source ${src_dir}/bazel_sandboxing_test_utils.sh \ +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +source ${CURRENT_DIR}/bazel_sandboxing_test_utils.sh \ || { echo "bazel_sandboxing_test_utils.sh not found!" >&2; exit 1; } -source ${src_dir}/remote_helpers.sh \ +source ${CURRENT_DIR}/remote_helpers.sh \ || { echo "remote_helpers.sh not found!" >&2; exit 1; } cat >>$TEST_TMPDIR/bazelrc <<'EOF' diff --git a/src/test/shell/bazel/bazel_test_test.sh b/src/test/shell/bazel/bazel_test_test.sh index b82562d6e72910..d62fa2c0845756 100755 --- a/src/test/shell/bazel/bazel_test_test.sh +++ b/src/test/shell/bazel/bazel_test_test.sh @@ -16,9 +16,10 @@ set -eu -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function set_up_jobcount() { tmp=$(mktemp -d ${TEST_TMPDIR}/testjobs.XXXXXXXX) diff --git a/src/test/shell/bazel/bazel_toolchain_test.sh b/src/test/shell/bazel/bazel_toolchain_test.sh index 1c6ac1e3e1ef72..67a5ac6dcf442a 100755 --- a/src/test/shell/bazel/bazel_toolchain_test.sh +++ b/src/test/shell/bazel/bazel_toolchain_test.sh @@ -17,9 +17,10 @@ # Tests compiling using an external Linaro toolchain on a Linux machine # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } if [ "${PLATFORM-}" = "darwin" ]; then echo "Skipping test: linaro toolchain is not supported on darwin host." diff --git a/src/test/shell/bazel/bazel_tools_test.sh b/src/test/shell/bazel/bazel_tools_test.sh index 30f4c2b0ec88ab..354a6c9e6a5f38 100755 --- a/src/test/shell/bazel/bazel_tools_test.sh +++ b/src/test/shell/bazel/bazel_tools_test.sh @@ -14,9 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_build_objc_tools() { # TODO(cparsons): Test building tools/objc/... diff --git a/src/test/shell/bazel/bazel_windows_example_test.sh b/src/test/shell/bazel/bazel_windows_example_test.sh index 2d62c57007c8c7..d5d22d010c0eaa 100755 --- a/src/test/shell/bazel/bazel_windows_example_test.sh +++ b/src/test/shell/bazel/bazel_windows_example_test.sh @@ -22,9 +22,10 @@ if ! type rlocation &> /dev/null; then exit 0 fi -# Load test environment -source $(rlocation io_bazel/src/test/shell/bazel/test-setup.sh) \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } if ! is_windows; then echo "This test suite requires running on Windows. But now is ${PLATFORM}" >&2 diff --git a/src/test/shell/bazel/bazel_worker_test.sh b/src/test/shell/bazel/bazel_worker_test.sh index 4256b1bfd9df56..aeb59eaae5fd30 100755 --- a/src/test/shell/bazel/bazel_worker_test.sh +++ b/src/test/shell/bazel/bazel_worker_test.sh @@ -22,9 +22,10 @@ ADDITIONAL_BUILD_FLAGS=$1 WORKER_TYPE_LOG_STRING=$2 shift 2 -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } # TODO(philwo): Change this so the path to the custom worker gets passed in as an argument to the # test, once the bug that makes using the "args" attribute with sh_tests in Bazel impossible is diff --git a/src/test/shell/bazel/bazel_workspace_status_test.sh b/src/test/shell/bazel/bazel_workspace_status_test.sh index 23fb5741d562c7..3823b463c04e38 100755 --- a/src/test/shell/bazel/bazel_workspace_status_test.sh +++ b/src/test/shell/bazel/bazel_workspace_status_test.sh @@ -14,9 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_workspace_status_invalidation() { create_new_workspace diff --git a/src/test/shell/bazel/bound_targets_test.sh b/src/test/shell/bazel/bound_targets_test.sh index a516ede00b62b4..d7da26a029dd29 100755 --- a/src/test/shell/bazel/bound_targets_test.sh +++ b/src/test/shell/bazel/bound_targets_test.sh @@ -14,9 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } if [ "${PLATFORM}" != "darwin" ]; then echo "This test suite requires running on OS X" >&2 diff --git a/src/test/shell/bazel/cc_inc_library_test.sh b/src/test/shell/bazel/cc_inc_library_test.sh index 379c0c82f1fcb4..8ee50fd5a6aa76 100755 --- a/src/test/shell/bazel/cc_inc_library_test.sh +++ b/src/test/shell/bazel/cc_inc_library_test.sh @@ -16,9 +16,10 @@ # # Tests the behavior of cc_inc_library. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function set_up() { rm -rf package diff --git a/src/test/shell/bazel/client_test.sh b/src/test/shell/bazel/client_test.sh index 8e72d39fe189f9..e3eb6f52655146 100755 --- a/src/test/shell/bazel/client_test.sh +++ b/src/test/shell/bazel/client_test.sh @@ -16,9 +16,10 @@ # Integration tests for Bazel client. # -# Load test environment -source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_product_name_with_bazel_info() { bazel info >& "$TEST_log" || fail "Expected zero exit" diff --git a/src/test/shell/bazel/empty_package.sh b/src/test/shell/bazel/empty_package.sh index 4f292afc40ad55..d6476522de2014 100755 --- a/src/test/shell/bazel/empty_package.sh +++ b/src/test/shell/bazel/empty_package.sh @@ -17,9 +17,10 @@ # Test top-level package # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_empty_package() { cat > BUILD <&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_execroot_structure() { ws_name="dooby_dooby_doo" diff --git a/src/test/shell/bazel/external_correctness_test.sh b/src/test/shell/bazel/external_correctness_test.sh index 6d79320fe63981..ea8ad05eb26bbc 100755 --- a/src/test/shell/bazel/external_correctness_test.sh +++ b/src/test/shell/bazel/external_correctness_test.sh @@ -14,8 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function set_up() { LOCAL=$(pwd) diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh index 477e1653eece1d..a78871f4736912 100755 --- a/src/test/shell/bazel/external_integration_test.sh +++ b/src/test/shell/bazel/external_integration_test.sh @@ -17,11 +17,11 @@ # Test //external mechanisms # -# Load test environment -src=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -source $src/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } -source $src/remote_helpers.sh \ +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +source "${CURRENT_DIR}/remote_helpers.sh" \ || { echo "remote_helpers.sh not found!" >&2; exit 1; } function set_up() { diff --git a/src/test/shell/bazel/external_skylark_load_test.sh b/src/test/shell/bazel/external_skylark_load_test.sh index a198371595f3b3..49c603ebdded28 100755 --- a/src/test/shell/bazel/external_skylark_load_test.sh +++ b/src/test/shell/bazel/external_skylark_load_test.sh @@ -17,9 +17,10 @@ # Test handling of Skylark loads from and in external repositories. # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } # The following tests build an instance of a Skylark macro loaded from a # local_repository, which in turns loads another Skylark file either from diff --git a/src/test/shell/bazel/generate_workspace_test.sh b/src/test/shell/bazel/generate_workspace_test.sh index 584f3e04d84fdd..f7638fe9b86a76 100755 --- a/src/test/shell/bazel/generate_workspace_test.sh +++ b/src/test/shell/bazel/generate_workspace_test.sh @@ -17,11 +17,11 @@ # Test //external mechanisms # -# Load test environment -src_dir=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd) -source $src_dir/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } -source $src_dir/remote_helpers.sh \ +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +source "${CURRENT_DIR}/remote_helpers.sh" \ || { echo "remote_helpers.sh not found!" >&2; exit 1; } function set_up() { diff --git a/src/test/shell/bazel/git_repository_test.sh b/src/test/shell/bazel/git_repository_test.sh index 2c862b7f7e4c1d..033a6831a26758 100755 --- a/src/test/shell/bazel/git_repository_test.sh +++ b/src/test/shell/bazel/git_repository_test.sh @@ -17,9 +17,10 @@ # Test git_repository and new_git_repository workspace rules. # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } # Global test setup. # diff --git a/src/test/shell/bazel/help_test.sh b/src/test/shell/bazel/help_test.sh index c6a4a7b6acff47..3e2570337f4ddf 100755 --- a/src/test/shell/bazel/help_test.sh +++ b/src/test/shell/bazel/help_test.sh @@ -16,9 +16,10 @@ # # Test the help command. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_info_keys() { bazel help info-keys >& $TEST_log || fail "help failed" diff --git a/src/test/shell/bazel/linux-sandbox_test.sh b/src/test/shell/bazel/linux-sandbox_test.sh index 9009d72bb5fa73..549f84fe88f637 100755 --- a/src/test/shell/bazel/linux-sandbox_test.sh +++ b/src/test/shell/bazel/linux-sandbox_test.sh @@ -17,11 +17,11 @@ # Test sandboxing spawn strategy # -# Load test environment -src_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -source ${src_dir}/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } -source ${src_dir}/bazel_sandboxing_test_utils.sh \ +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +source "${CURRENT_DIR}/bazel_sandboxing_test_utils.sh" \ || { echo "bazel_sandboxing_test_utils.sh not found!" >&2; exit 1; } readonly OUT_DIR="${TEST_TMPDIR}/out" diff --git a/src/test/shell/bazel/local_repository_test.sh b/src/test/shell/bazel/local_repository_test.sh index b14ba4fd4dea32..8a495c76e827bf 100755 --- a/src/test/shell/bazel/local_repository_test.sh +++ b/src/test/shell/bazel/local_repository_test.sh @@ -17,9 +17,10 @@ # Test the local_repository binding # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_glob_local_repository_dangling_symlink() { create_new_workspace diff --git a/src/test/shell/bazel/local_repository_test_jdk8.sh b/src/test/shell/bazel/local_repository_test_jdk8.sh index a8f37176c90790..469d4021717abc 100755 --- a/src/test/shell/bazel/local_repository_test_jdk8.sh +++ b/src/test/shell/bazel/local_repository_test_jdk8.sh @@ -17,9 +17,10 @@ # Test parts of the local_repository binding which are broken with jdk7 # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } # Creates an indirect dependency on X from A and make sure the error message # refers to the correct label, both in an external repository and not. diff --git a/src/test/shell/bazel/location_test.sh b/src/test/shell/bazel/location_test.sh index 495d09185a0c71..2435dcc4a1dfe8 100755 --- a/src/test/shell/bazel/location_test.sh +++ b/src/test/shell/bazel/location_test.sh @@ -14,9 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_external_location() { cat > WORKSPACE <&2; exit 1; } -source $src/remote_helpers.sh \ +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +source ${CURRENT_DIR}/remote_helpers.sh \ || { echo "remote_helpers.sh not found!" >&2; exit 1; } function setup_zoo() { diff --git a/src/test/shell/bazel/maven_test.sh b/src/test/shell/bazel/maven_test.sh index 9768bdab0e4084..3e50d6d2044079 100755 --- a/src/test/shell/bazel/maven_test.sh +++ b/src/test/shell/bazel/maven_test.sh @@ -17,11 +17,11 @@ # Test //external mechanisms # -# Load test environment -src=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd) -source $src/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } -source $src/remote_helpers.sh \ +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +source "${CURRENT_DIR}/remote_helpers.sh" \ || { echo "remote_helpers.sh not found!" >&2; exit 1; } function setup_zoo() { diff --git a/src/test/shell/bazel/process-wrapper_test.sh b/src/test/shell/bazel/process-wrapper_test.sh index a46b4500aad726..b720ab8dbd47cb 100755 --- a/src/test/shell/bazel/process-wrapper_test.sh +++ b/src/test/shell/bazel/process-wrapper_test.sh @@ -17,10 +17,10 @@ # Test sandboxing spawn strategy # -# Load test environment - -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } readonly OUT_DIR="${TEST_TMPDIR}/out" readonly OUT="${OUT_DIR}/outfile" @@ -82,7 +82,7 @@ function test_basic_timeout() { function test_timeout_grace() { local code=0 $process_wrapper 1 10 $OUT $ERR /bin/bash -c \ - 'trap "echo -n before; sleep 1; echo after; exit 0" SIGINT SIGTERM SIGALRM; sleep 10' \ + 'trap "echo -n "before"; sleep 1; echo "after"; exit 0" SIGINT SIGTERM SIGALRM; sleep 10' \ &> $TEST_log || code=$? assert_equals 142 "$code" # SIGNAL_BASE + SIGALRM = 128 + 14 assert_stdout "beforeafter" diff --git a/src/test/shell/bazel/remote_execution_test.sh b/src/test/shell/bazel/remote_execution_test.sh index c6ec0844f40599..75bef52e9a3ff0 100755 --- a/src/test/shell/bazel/remote_execution_test.sh +++ b/src/test/shell/bazel/remote_execution_test.sh @@ -17,10 +17,10 @@ # Tests remote execution and caching. # -# Load test environment -src_dir=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd) -source $src_dir/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function set_up() { mkdir -p a diff --git a/src/test/shell/bazel/runfiles_test.sh b/src/test/shell/bazel/runfiles_test.sh index ded1184fcb2ec3..e0ac79b8d978aa 100755 --- a/src/test/shell/bazel/runfiles_test.sh +++ b/src/test/shell/bazel/runfiles_test.sh @@ -17,9 +17,10 @@ # Test runfiles creation # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } # Make sure runfiles are created under a custom-named subdirectory when # workspace() is specified in the WORKSPACE file. diff --git a/src/test/shell/bazel/skylark_repository_test.sh b/src/test/shell/bazel/skylark_repository_test.sh index 0e8ef1652d26cd..5fc420b9994215 100755 --- a/src/test/shell/bazel/skylark_repository_test.sh +++ b/src/test/shell/bazel/skylark_repository_test.sh @@ -17,11 +17,11 @@ # Test the local_repository binding # -# Load test environment -src_dir=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd) -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } -source "$src_dir/remote_helpers.sh" \ +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +source "${CURRENT_DIR}/remote_helpers.sh" \ || { echo "remote_helpers.sh not found!" >&2; exit 1; } # Basic test. diff --git a/src/test/shell/bazel/test-setup.sh b/src/test/shell/bazel/test-setup.sh deleted file mode 100755 index 7577d155852058..00000000000000 --- a/src/test/shell/bazel/test-setup.sh +++ /dev/null @@ -1,267 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 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. -# -# Setup bazel for integration tests -# - -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -# OS X has a limit in the pipe length, so force the root to a shorter one -bazel_root="${TEST_TMPDIR}/root" -mkdir -p "${bazel_root}" - -bazel_javabase="${jdk_dir}" - -echo "bazel binary is at $bazel" - -# Here we unset variable that were set by the invoking Blaze instance -unset JAVA_RUNFILES - -function setup_bazelrc() { - cat >$TEST_TMPDIR/bazelrc <> WORKSPACE <third_party/BUILD -package(default_visibility = ["//visibility:public"]) -EOF - fi - - [ -e third_party/junit.jar ] || ln -s ${junit_jar} third_party/junit.jar - [ -e third_party/hamcrest.jar ] \ - || ln -s ${hamcrest_jar} third_party/hamcrest.jar -} - -function setup_javatest_support() { - setup_javatest_common - grep -q 'name = "junit4"' third_party/BUILD \ - || cat <>third_party/BUILD -java_import( - name = "junit4", - jars = [ - "junit.jar", - "hamcrest.jar", - ], -) -EOF -} - -function setup_skylark_javatest_support() { - setup_javatest_common - grep -q "name = \"junit4-jars\"" third_party/BUILD \ - || cat <>third_party/BUILD -filegroup( - name = "junit4-jars", - srcs = [ - "junit.jar", - "hamcrest.jar", - ], -) -EOF -} - -function setup_iossim() { - mkdir -p third_party/iossim - ln -sv ${iossim_path} third_party/iossim/iossim - - cat <>third_party/iossim/BUILD -licenses(["unencumbered"]) -package(default_visibility = ["//visibility:public"]) - -exports_files(["iossim"]) -EOF -} - -# Sets up Objective-C tools. Mac only. -function setup_objc_test_support() { - IOS_SDK_VERSION=$(xcrun --sdk iphoneos --show-sdk-version) -} - -workspaces=() -# Set-up a new, clean workspace with only the tools installed. -function create_new_workspace() { - new_workspace_dir=${1:-$(mktemp -d ${TEST_TMPDIR}/workspace.XXXXXXXX)} - rm -fr ${new_workspace_dir} - mkdir -p ${new_workspace_dir} - workspaces+=(${new_workspace_dir}) - cd ${new_workspace_dir} - mkdir tools - mkdir -p third_party/java/jdk/langtools - - copy_tools_directory - - [ -e third_party/java/jdk/langtools/javac.jar ] \ - || ln -s "${langtools_path}" third_party/java/jdk/langtools/javac.jar - - touch WORKSPACE -} - -# Set-up a clean default workspace. -function setup_clean_workspace() { - export WORKSPACE_DIR=${TEST_TMPDIR}/workspace - echo "setting up client in ${WORKSPACE_DIR}" > $TEST_log - rm -fr ${WORKSPACE_DIR} - create_new_workspace ${WORKSPACE_DIR} - [ "${new_workspace_dir}" = "${WORKSPACE_DIR}" ] || \ - { echo "Failed to create workspace" >&2; exit 1; } - export BAZEL_INSTALL_BASE=$(bazel info install_base) - export BAZEL_GENFILES_DIR=$(bazel info bazel-genfiles) - export BAZEL_BIN_DIR=$(bazel info bazel-bin) - if is_windows; then - export BAZEL_SH="$(cygpath --windows /bin/bash)" - fi -} - -# Clean up all files that are not in tools directories, to restart -# from a clean workspace -function cleanup_workspace() { - if [ -d "${WORKSPACE_DIR:-}" ]; then - echo "Cleaning up workspace" > $TEST_log - cd ${WORKSPACE_DIR} - bazel clean >& $TEST_log # Clean up the output base - - for i in $(ls); do - if ! is_tools_directory "$i"; then - rm -fr "$i" - fi - done - touch WORKSPACE - fi - for i in ${workspaces}; do - if [ "$i" != "${WORKSPACE_DIR:-}" ]; then - rm -fr $i - fi - done - workspaces=() -} - -# Clean-up the bazel install base -function cleanup() { - if [ -d "${BAZEL_INSTALL_BASE:-__does_not_exists__}" ]; then - rm -fr "${BAZEL_INSTALL_BASE}" - fi -} - -function tear_down() { - cleanup_workspace -} - -# -# Simples assert to make the tests more readable -# -function assert_build() { - bazel build -s --verbose_failures $* || fail "Failed to build $*" -} - -function assert_build_output() { - local OUTPUT=$1 - shift - assert_build "$*" - test -f "$OUTPUT" || fail "Output $OUTPUT not found for target $*" -} - -function assert_build_fails() { - bazel build -s $1 >& $TEST_log \ - && fail "Test $1 succeed while expecting failure" \ - || true - if [ -n "${2:-}" ]; then - expect_log "$2" - fi -} - -function assert_test_ok() { - bazel test --test_output=errors $* >& $TEST_log \ - || fail "Test $1 failed while expecting success" -} - -function assert_test_fails() { - bazel test --test_output=errors $* >& $TEST_log \ - && fail "Test $* succeed while expecting failure" \ - || true - expect_log "$1.*FAILED" -} - -function assert_binary_run() { - $1 >& $TEST_log || fail "Failed to run $1" - [ -z "${2:-}" ] || expect_log "$2" -} - -function assert_bazel_run() { - bazel run $1 >& $TEST_log || fail "Failed to run $1" - [ -z "${2:-}" ] || expect_log "$2" - - assert_binary_run "./bazel-bin/$(echo "$1" | sed 's|^//||' | sed 's|:|/|')" "${2:-}" -} - -setup_bazelrc -setup_clean_workspace diff --git a/src/test/shell/bazel/testenv.sh b/src/test/shell/bazel/testenv.sh deleted file mode 100755 index 2f5a247086666f..00000000000000 --- a/src/test/shell/bazel/testenv.sh +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 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. -# -# Setting up the environment for Bazel integration tests. -# -[ -z "$TEST_SRCDIR" ] && { echo "TEST_SRCDIR not set!" >&2; exit 1; } -BAZEL_RUNFILES="$TEST_SRCDIR/io_bazel" - -if ! type rlocation &> /dev/null; then - function rlocation() { - if [[ "$1" = /* ]]; then - echo $1 - else - echo "$TEST_SRCDIR/$1" - fi - } - export -f rlocation -fi - -# Load the unit-testing framework -source "$(rlocation io_bazel/src/test/shell/unittest.bash)" || \ - { echo "Failed to source unittest.bash" >&2; exit 1; } - -# WORKSPACE file -workspace_file="${BAZEL_RUNFILES}/WORKSPACE" - -# Bazel -bazel_tree="$(rlocation io_bazel/src/test/shell/bazel/doc-srcs.zip)" -bazel="$(rlocation io_bazel/src/bazel)" -bazel_data="${BAZEL_RUNFILES}" - -# Windows -PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" -function is_windows() { - # On windows, the shell test actually running on msys - if [[ "${PLATFORM}" =~ msys_nt* ]]; then - true - else - false - fi -} - -# Java -if is_windows; then - jdk_dir="$(cygpath -m $(cd $(rlocation local_jdk/bin/java.exe)/../..; pwd))" -else - jdk_dir="${TEST_SRCDIR}/local_jdk" -fi -langtools="$(rlocation io_bazel/src/test/shell/bazel/langtools.jar)" - -# Tools directory location -tools_dir="$(dirname $(rlocation io_bazel/tools/BUILD))" -langtools_dir="$(dirname $(rlocation io_bazel/third_party/java/jdk/langtools/BUILD))" -EXTRA_BAZELRC="build --ios_sdk_version=8.4" - -# Java tooling -javabuilder_path="$(find ${BAZEL_RUNFILES} -name JavaBuilder_*.jar)" -langtools_path="${BAZEL_RUNFILES}/third_party/java/jdk/langtools/javac.jar" -singlejar_path="${BAZEL_RUNFILES}/src/java_tools/singlejar/SingleJar_deploy.jar" -genclass_path="${BAZEL_RUNFILES}/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass_deploy.jar" -junitrunner_path="${BAZEL_RUNFILES}/src/java_tools/junitrunner/java/com/google/testing/junit/runner/Runner_deploy.jar" -ijar_path="${BAZEL_RUNFILES}/third_party/ijar/ijar" - -# Sandbox tools -process_wrapper="${BAZEL_RUNFILES}/src/main/tools/process-wrapper" -linux_sandbox="${BAZEL_RUNFILES}/src/main/tools/linux-sandbox" - -# iOS and Objective-C tooling -iossim_path="${BAZEL_RUNFILES}/third_party/iossim/iossim" -actoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/actoolwrapper/actoolwrapper.sh" -ibtoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/ibtoolwrapper/ibtoolwrapper.sh" -swiftstdlibtoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/swiftstdlibtoolwrapper/swiftstdlibtoolwrapper.sh" -momcwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/momcwrapper/momcwrapper.sh" -bundlemerge_path="${BAZEL_RUNFILES}/src/objc_tools/bundlemerge/bundlemerge_deploy.jar" -plmerge_path="${BAZEL_RUNFILES}/src/objc_tools/plmerge/plmerge_deploy.jar" -xcodegen_path="${BAZEL_RUNFILES}/src/objc_tools/xcodegen/xcodegen_deploy.jar" -stdredirect_path="${BAZEL_RUNFILES}/src/tools/xcode/stdredirect/StdRedirect.dylib" -realpath_path="${BAZEL_RUNFILES}/src/tools/xcode/realpath/realpath" -environment_plist_path="${BAZEL_RUNFILES}/src/tools/xcode/environment/environment_plist.sh" -xcrunwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh" - -# Test data -testdata_path=${BAZEL_RUNFILES}/src/test/shell/bazel/testdata -python_server="${BAZEL_RUNFILES}/src/test/shell/bazel/testing_server.py" - -# Third-party -MACHINE_TYPE="$(uname -m)" -MACHINE_IS_64BIT='no' -if [ "${MACHINE_TYPE}" = 'amd64' -o "${MACHINE_TYPE}" = 'x86_64' -o "${MACHINE_TYPE}" = 's390x' ]; then - MACHINE_IS_64BIT='yes' -fi - -MACHINE_IS_Z='no' -if [ "${MACHINE_TYPE}" = 's390x' ]; then - MACHINE_IS_Z='yes' -fi - -case "${PLATFORM}" in - darwin) - if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then - protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-osx-x86_64.exe" - else - protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-osx-x86_32.exe" - fi - ;; - *) - if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then - if [ "${MACHINE_IS_Z}" = 'yes' ]; then - protoc_compiler="${BAZEL_RUNFILES}//third_party/protobuf/protoc-linux-s390x_64.exe" - else - protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-linux-x86_64.exe" - fi - else - protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-linux-x86_32.exe" - fi - ;; -esac - -if [ -z ${RUNFILES_MANIFEST_ONLY+x} ]; then - protoc_jar="${BAZEL_RUNFILES}/third_party/protobuf/protobuf-*.jar" - junit_jar="${BAZEL_RUNFILES}/third_party/junit/junit-*.jar" - hamcrest_jar="${BAZEL_RUNFILES}/third_party/hamcrest/hamcrest-*.jar" -else - protoc_jar=$(rlocation io_bazel/third_party/protobuf/protobuf-.*.jar) - junit_jar=$(rlocation io_bazel/third_party/junit/junit-.*.jar) - hamcrest_jar=$(rlocation io_bazel/third_party/hamcrest/hamcrest-.*.jar) -fi - -# This function copies the tools directory from Bazel. -function copy_tools_directory() { - cp -RL ${tools_dir}/* tools - # tools/jdk/BUILD file for JDK 7 is generated. - if [ -f tools/jdk/BUILD.* ]; then - cp tools/jdk/BUILD.* tools/jdk/BUILD - chmod +w tools/jdk/BUILD - fi - # To support custom langtools - cp ${langtools} tools/jdk/langtools.jar - cat >>tools/jdk/BUILD <<'EOF' -filegroup(name = "test-langtools", srcs = ["langtools.jar"]) -EOF - - mkdir -p third_party/java/jdk/langtools - cp -R ${langtools_dir}/* third_party/java/jdk/langtools - - chmod -R +w . - mkdir -p tools/defaults - touch tools/defaults/BUILD - - mkdir -p third_party/py/gflags - cat > third_party/py/gflags/BUILD <&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } export JAVA_RUNFILES=$BAZEL_RUNFILES diff --git a/src/test/shell/bin/bazel b/src/test/shell/bin/bazel new file mode 100755 index 00000000000000..27975618ee62a8 --- /dev/null +++ b/src/test/shell/bin/bazel @@ -0,0 +1,20 @@ +#!/bin/bash +# +# Copyright 2016 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. +# +# Wrapper script to run bazel in the tests. Any change to this file will +# affect all our integration tests. +# +exec $(rlocation io_bazel/src/bazel) --bazelrc=$TEST_TMPDIR/bazelrc "$@" \ No newline at end of file diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD index 85497580132760..eb131b11c6ee50 100644 --- a/src/test/shell/integration/BUILD +++ b/src/test/shell/integration/BUILD @@ -10,7 +10,6 @@ filegroup( name = "test-deps", testonly = 1, srcs = [ - "testenv.sh", "//src/test/shell/bazel:test-deps", ], ) @@ -125,6 +124,16 @@ sh_test( data = [":test-deps"], ) +sh_test( + name = "client_sigint_test", + size = "medium", + srcs = ["client_sigint_test.sh"], + data = [":test-deps"], + # This test doesn't work with the sandbox on, see the source file + # for details. + tags = ["local"], +) + sh_test( name = "ide_info_generation", size = "large", diff --git a/src/test/shell/integration/action_env_test.sh b/src/test/shell/integration/action_env_test.sh index 6228247fcea721..52d0e2b541b7c5 100755 --- a/src/test/shell/integration/action_env_test.sh +++ b/src/test/shell/integration/action_env_test.sh @@ -17,14 +17,10 @@ # An end-to-end test that Bazel's provides the correct environment variables # to actions. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -create_and_cd_client -put_bazel_on_path -write_default_bazelrc - +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } #### SETUP ############################################################# @@ -46,7 +42,8 @@ EOF function test_simple() { export FOO=baz bazel build --action_env=FOO=bar pkg:showenv \ - || fail "bazel build showenv failed" + || fail "${PRODUCT_NAME} build showenv failed" + cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log expect_log "FOO=bar" } @@ -56,7 +53,8 @@ function test_simple_latest_wins() { export BAR=environmentbar bazel build --action_env=FOO=foo \ --action_env=BAR=willbeoverridden --action_env=BAR=bar pkg:showenv \ - || fail "bazel build showenv failed" + || fail "${PRODUCT_NAME} build showenv failed" + cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log expect_log "FOO=foo" expect_log "BAR=bar" @@ -65,9 +63,11 @@ function test_simple_latest_wins() { function test_client_env() { export FOO=startup_foo bazel clean --expunge - bazel help build > /dev/null || fail "bazel help failed" + bazel help build > /dev/null || fail "${PRODUCT_NAME} help failed" export FOO=client_foo - bazel build --action_env=FOO pkg:showenv || fail "bazel build showenv failed" + bazel build --action_env=FOO pkg:showenv || \ + fail "${PRODUCT_NAME} build showenv failed" + cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log expect_log "FOO=client_foo" } @@ -75,27 +75,29 @@ function test_client_env() { function test_redo_action() { export FOO=initial_foo export UNRELATED=some_value - bazel build --action_env=FOO pkg:showenv || fail "bazel build showenv failed" + bazel build --action_env=FOO pkg:showenv \ + || fail "${PRODUCT_NAME} build showenv failed" + cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log expect_log "FOO=initial_foo" # If an unrelated value changes, we expect the action not to be executed again export UNRELATED=some_other_value bazel build --action_env=FOO -s --experimental_ui pkg:showenv 2> $TEST_log \ - || fail "bazel build showenv failed" + || fail "${PRODUCT_NAME} build showenv failed" expect_not_log '^SUBCOMMAND.*pkg:showenv' # However, if a used variable changes, we expect the change to be propagated export FOO=changed_foo bazel build --action_env=FOO -s --experimental_ui pkg:showenv 2> $TEST_log \ - || fail "bazel build showenv failed" + || fail "${PRODUCT_NAME} build showenv failed" expect_log '^SUBCOMMAND.*pkg:showenv' cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log expect_log "FOO=changed_foo" # But repeating the build with no further changes, no action should happen bazel build --action_env=FOO -s --experimental_ui pkg:showenv 2> $TEST_log \ - || fail "bazel build showenv failed" + || fail "${PRODUCT_NAME} build showenv failed" expect_not_log '^SUBCOMMAND.*pkg:showenv' } @@ -103,7 +105,8 @@ function test_latest_wins_arg() { export FOO=bar export BAR=baz bazel build --action_env=BAR --action_env=FOO --action_env=FOO=foo \ - pkg:showenv || fail "bazel build showenv failed" + pkg:showenv || fail "${PRODUCT_NAME} build showenv failed" + cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log expect_log "FOO=foo" expect_log "BAR=baz" @@ -114,7 +117,8 @@ function test_latest_wins_env() { export FOO=bar export BAR=baz bazel build --action_env=BAR --action_env=FOO=foo --action_env=FOO \ - pkg:showenv || fail "bazel build showenv failed" + pkg:showenv || fail "${PRODUCT_NAME} build showenv failed" + cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log expect_log "FOO=bar" expect_log "BAR=baz" @@ -122,19 +126,18 @@ function test_latest_wins_env() { } function test_env_freezing() { - cat > .${PRODUCT_NAME}rc < $TEST_log + bazel info --action_env=FREEZE_TEST_BAZ client-env > $TEST_log + expect_log "build --action_env=FREEZE_TEST_FOO=client_foo" expect_not_log "FREEZE_TEST_BAR" expect_log "build --action_env=FREEZE_TEST_BAZ=client_baz" diff --git a/src/test/shell/integration/bazel_command_log_test.sh b/src/test/shell/integration/bazel_command_log_test.sh index 431c648842fbe8..195590857e18e3 100755 --- a/src/test/shell/integration/bazel_command_log_test.sh +++ b/src/test/shell/integration/bazel_command_log_test.sh @@ -14,13 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -create_and_cd_client -put_bazel_on_path -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } log="$(bazel --batch info command_log)" @@ -102,4 +99,4 @@ function test_client_server_mode_with_logging_flag() { assert_equals "" "$(diff $TEST_log $log 2>&1)" } -run_suite "Integration tests of Blaze command log." +run_suite "Integration tests of ${PRODUCT_NAME} command log." diff --git a/src/test/shell/integration/bazel_javabase_test.sh b/src/test/shell/integration/bazel_javabase_test.sh index bd2804ed114690..fecf82c89db8a8 100755 --- a/src/test/shell/integration/bazel_javabase_test.sh +++ b/src/test/shell/integration/bazel_javabase_test.sh @@ -15,15 +15,13 @@ # Tests that our --host_javabase startup selection algorithm works. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -put_bazel_on_path -create_and_cd_client +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_use_depot_javabase() { - bazel --batch version >& $TEST_log || fail "Couldn't run Bazel" + bazel --batch version >& $TEST_log || fail "Couldn't run ${PRODUCT_NAME}" expect_not_log "Couldn't find java at" expect_not_log "Problem with java installation" } diff --git a/src/test/shell/integration/bazel_query_test.sh b/src/test/shell/integration/bazel_query_test.sh index 9138b683dc4620..b009adb1477a3f 100755 --- a/src/test/shell/integration/bazel_query_test.sh +++ b/src/test/shell/integration/bazel_query_test.sh @@ -16,13 +16,10 @@ # # bazel_query_test.sh: integration tests for bazel query -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -put_bazel_on_path -create_and_cd_client -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } add_to_bazelrc "build --package_path=%workspace%" @@ -260,4 +257,4 @@ EOF expect_log "//peach:harken" } -run_suite "bazel query tests" +run_suite "${PRODUCT_NAME} query tests" diff --git a/src/test/shell/integration/bazel_testjobs_test.sh b/src/test/shell/integration/bazel_testjobs_test.sh index 12aca468787253..7a1b2de5a06ad5 100755 --- a/src/test/shell/integration/bazel_testjobs_test.sh +++ b/src/test/shell/integration/bazel_testjobs_test.sh @@ -14,14 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -create_and_cd_client -put_bazel_on_path -EXTRA_BAZELRC="test --nocache_test_results" -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + +add_to_bazelrc "test --nocache_test_results" # End of preamble. diff --git a/src/test/shell/integration/client_sigint_test.sh b/src/test/shell/integration/client_sigint_test.sh new file mode 100755 index 00000000000000..88d9ad9f1b41fa --- /dev/null +++ b/src/test/shell/integration/client_sigint_test.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# +# Copyright 2016 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. +# +# Test of client/server SIGINT handling. This test proves that the server +# gracefully handles SIGINT. + +NO_SIGNAL_OVERRIDE=1 +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + +# This function doesn't work well with the sandbox because testfifo and +# sleepyfifo are created outside the genrule. +# TODO(bazel-team): Make this test compliant with the behavior of the sandbox +function runbazel() { + startup_opt=$1; shift + + local sleepyfifo=x/sleepyfifo + local testfifo=x/testfifo + mkdir -p x || fail "Can't create x" + cat > x/BUILD << EOF +genrule( + name = "sleepy", + srcs = [], + outs = ["sleepy.out"], + local = 1, + cmd = "echo 'hi test' > $testfifo; cat $sleepyfifo; sleep 9999" +) +EOF + + mkfifo $testfifo $sleepyfifo || fail "Couldn't create FIFOs under x" + + set -m + bazel $startup_opt build --package_path . //x:sleepy >& $TEST_log & + local pid=$! + + echo "${PRODUCT_NAME} running in background with pid $pid" + local testfifocontents=$(cat $testfifo) + echo "hi sleepy" > $sleepyfifo + echo "Interrupting pid $pid" + kill -INT $pid; sleep 3 + + status=0 + # We expect the wait instruction to fail given that the build is interrupted. + wait $pid || status=$? + assert_equals 8 $status # Interruption exit code + assert_equals "hi test" "$testfifocontents" + set +m +} + +function tear_down() { + bazel shutdown + rm -rf x +} + +function assert_sigint_stops_build() { + runbazel $1 + + # Must have loaded package 'x': + expect_log 'Loading package: x' + expect_log 'Elapsed time' + expect_log 'build interrupted' +} + +function test_sigint_server_mode() { + assert_sigint_stops_build "--nobatch" +} + +function test_sigint_batch_mode() { + assert_sigint_stops_build "--batch" +} + +run_suite "Tests of SIGINT on ${PRODUCT_NAME}" diff --git a/src/test/shell/integration/discard_analysis_cache_test.sh b/src/test/shell/integration/discard_analysis_cache_test.sh index 425ffbf2fa9210..9ba865a7c4e7be 100755 --- a/src/test/shell/integration/discard_analysis_cache_test.sh +++ b/src/test/shell/integration/discard_analysis_cache_test.sh @@ -16,14 +16,10 @@ # # A test for --discard_analysis_cache. - -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -put_bazel_on_path -create_and_cd_client -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function write_hello_world_files() { mkdir -p hello || fail "mkdir hello failed" diff --git a/src/test/shell/integration/discard_graph_edges_test.sh b/src/test/shell/integration/discard_graph_edges_test.sh index c2212c34a435e9..472d8daac875fe 100755 --- a/src/test/shell/integration/discard_graph_edges_test.sh +++ b/src/test/shell/integration/discard_graph_edges_test.sh @@ -16,13 +16,10 @@ # # discard_graph_edges_test.sh: basic tests for the --discard_graph_edges flag. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -create_and_cd_client -put_bazel_on_path -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } #### SETUP ############################################################# diff --git a/src/test/shell/integration/experimental_ui_test.sh b/src/test/shell/integration/experimental_ui_test.sh index ad6ff654dbcb2f..e3265a788d0865 100755 --- a/src/test/shell/integration/experimental_ui_test.sh +++ b/src/test/shell/integration/experimental_ui_test.sh @@ -16,13 +16,10 @@ # # An end-to-end test that Bazel's experimental UI produces reasonable output. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -create_and_cd_client -put_bazel_on_path -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } #### SETUP ############################################################# @@ -82,7 +79,8 @@ EOF #### TESTS ############################################################# function test_basic_progress() { - bazel test --experimental_ui --curses=yes --color=yes pkg:true 2>$TEST_log || fail "bazel test failed" + bazel test --experimental_ui --curses=yes --color=yes pkg:true 2>$TEST_log \ + || fail "${PRODUCT_NAME} test failed" # some progress indicator is shown expect_log '\[[0-9,]* / [0-9,]*\]' # curses are used to delete at least one line @@ -94,7 +92,7 @@ function test_basic_progress() { function test_noshow_progress() { bazel test --experimental_ui --noshow_progress --curses=yes --color=yes \ - pkg:true 2>$TEST_log || fail "bazel test failed" + pkg:true 2>$TEST_log || fail "${PRODUCT_NAME} test failed" # Info messages should still go through expect_log 'Elapsed time' # no progress indicator is shown @@ -103,7 +101,7 @@ function test_noshow_progress() { function test_basic_progress_no_curses() { bazel test --experimental_ui --curses=no --color=yes pkg:true 2>$TEST_log \ - || fail "bazel test failed" + || fail "${PRODUCT_NAME} test failed" # some progress indicator is shown expect_log '\[[0-9,]* / [0-9,]*\]' # cursor is not moved up @@ -116,26 +114,28 @@ function test_basic_progress_no_curses() { function test_no_curses_no_linebreak() { bazel test --experimental_ui --curses=no --color=yes --terminal_columns=9 \ - pkg:true 2>$TEST_log || fail "bazel test failed" + pkg:true 2>$TEST_log || fail "${PRODUCT_NAME} test failed" # expect a long-ish status line expect_log '\[[0-9,]* / [0-9,]*\]......' } function test_pass() { - bazel test --experimental_ui --curses=yes --color=yes pkg:true >$TEST_log || fail "bazel test failed" + bazel test --experimental_ui --curses=yes --color=yes pkg:true >$TEST_log \ + || fail "${PRODUCT_NAME} test failed" # PASS is written in green on the same line as the test target expect_log 'pkg:true.*'$'\x1b\[32m''.*PASS' } function test_fail() { - bazel test --experimental_ui --curses=yes --color=yes pkg:false >$TEST_log && fail "expected failure" + bazel test --experimental_ui --curses=yes --color=yes pkg:false >$TEST_log \ + && fail "expected failure" # FAIL is written in red bold on the same line as the test target expect_log 'pkg:false.*'$'\x1b\[31m\x1b\[1m''.*FAIL' } function test_timestamp() { bazel test --experimental_ui --show_timestamps pkg:true 2>$TEST_log \ - || fail "bazel test failed" + || fail "${PRODUCT_NAME} test failed" # expect something that looks like HH:mm:ss expect_log '[0-2][0-9]:[0-5][0-9]:[0-6][0-9]' } @@ -145,7 +145,7 @@ function test_info_spacing() { # in particular free carriage-return characters. BAZEL_INFO_OUTPUT=XXX`bazel info --experimental_ui workspace`XXX echo "$BAZEL_INFO_OUTPUT" | grep -q 'XXX[^'$'\r'']*XXX' \ - || fail "bazel info output spaced as $BAZEL_INFO_OUTPUT" + || fail "${PRODUCT_NAME} info output spaced as $BAZEL_INFO_OUTPUT" } function test_query_spacing() { @@ -195,30 +195,30 @@ function test_version_nobuild { } function test_subcommand { - bazel clean || fail "bazel clean failed" + bazel clean || fail "${PRODUCT_NAME} clean failed" bazel build --experimental_ui -s pkg:gentext 2>$TEST_log \ || fail "bazel build failed" expect_log "here be dragons" } function test_subcommand_notdefault { - bazel clean || fail "bazel clean failed" + bazel clean || fail "${PRODUCT_NAME} clean failed" bazel build --experimental_ui pkg:gentext 2>$TEST_log \ || fail "bazel build failed" expect_not_log "dragons" } function test_loading_progress { - bazel clean || fail "bazel clean failed" + bazel clean || fail "${PRODUCT_NAME} clean failed" bazel test --experimental_ui \ --experimental_skyframe_target_pattern_evaluator pkg:true 2>$TEST_log \ - || fail "bazel test failed" + || fail "${PRODUCT_NAME} test failed" # some progress indicator is shown during loading expect_log 'Loading.*[0-9,]* packages' } function test_failure_scrollback_buffer_curses { - bazel clean || fail "bazel clean failed" + bazel clean || fail "${PRODUCT_NAME} clean failed" bazel test --experimental_ui --curses=yes --color=yes \ --nocache_test_results pkg:false pkg:slow 2>$TEST_log \ && fail "expected failure" @@ -228,13 +228,13 @@ function test_failure_scrollback_buffer_curses { function test_terminal_title { bazel test --experimental_ui --progress_in_terminal_title pkg:true \ - 2>$TEST_log || fail "bazel test failed" + 2>$TEST_log || fail "${PRODUCT_NAME} test failed" # The terminal title is changed expect_log $'\x1b\]0;.*\x07' } function test_failure_scrollback_buffer { - bazel clean || fail "bazel clean failed" + bazel clean || fail "${PRODUCT_NAME} clean failed" bazel test --experimental_ui --curses=no --color=yes \ --nocache_test_results pkg:false pkg:slow 2>$TEST_log \ && fail "expected failure" @@ -249,4 +249,4 @@ function test_streamed { expect_log 'foobar' } -run_suite "Integration tests for bazel's experimental UI" +run_suite "Integration tests for ${PRODUCT_NAME}'s experimental UI" diff --git a/src/test/shell/integration/ide_info_generation.sh b/src/test/shell/integration/ide_info_generation.sh index 516945aff47ac0..9cd215a8eb6e4f 100755 --- a/src/test/shell/integration/ide_info_generation.sh +++ b/src/test/shell/integration/ide_info_generation.sh @@ -16,17 +16,12 @@ # # Integration tests for IDE build info generation. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -create_and_cd_client -put_bazel_on_path -write_default_bazelrc -add_to_bazelrc "build --embed_changelist=none --noshow_progress" - - -##### TESTS +add_to_bazelrc "build --noshow_progress" function test_ide_build_file_generation() { mkdir -p com/google/example/simple @@ -68,10 +63,10 @@ EOF bazel build //com/google/example:complex \ --aspects AndroidStudioInfoAspect --output_groups "ide-info" \ || fail "Expected success" - [ -e bazel-bin/com/google/example/simple.aswb-build ] \ - || fail "bazel-bin/com/google/example/simple.aswb-build not found" - [ -e bazel-bin/com/google/example/complex.aswb-build ] \ - || fail "bazel-bin/com/google/example/complex.aswb-build not found" + SIMPLE_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/simple.aswb-build" + [ -e $SIMPLE_ASWB_BUILD ] || fail "$SIMPLE_ASWB_BUILD not found" + COMPLEX_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/complex.aswb-build" + [ -e $COMPLEX_ASWB_BUILD ] || fail "$COMPLEX_ASWB_BUILD not found" } function test_detailed_result() { @@ -119,10 +114,10 @@ EOF --aspects AndroidStudioInfoAspect --output_groups "ide-info" \ --experimental_show_artifacts 2> $TEST_log \ || fail "Expected success" - [ -e bazel-bin/com/google/example/simple.aswb-build ] \ - || fail "bazel-bin/com/google/example/simple.aswb-build not found" - [ -e bazel-bin/com/google/example/complex.aswb-build ] \ - || fail "bazel-bin/com/google/example/complex.aswb-build not found" + SIMPLE_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/simple.aswb-build" + [ -e $SIMPLE_ASWB_BUILD ] || fail "$SIMPLE_ASWB_BUILD not found" + COMPLEX_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/complex.aswb-build" + [ -e $COMPLEX_ASWB_BUILD ] || fail "$COMPLEX_ASWB_BUILD not found" expect_log '^Build artifacts:' expect_log "^>>>.*/com/google/example/complex.aswb-build" @@ -178,10 +173,10 @@ EOF bazel build //com/google/example:complex \ --aspects AndroidStudioInfoAspect --output_groups "ide-resolve" \ || fail "Expected success" - [ -e bazel-bin/com/google/example/libsimple.jar ] \ - || fail "bazel-bin/com/google/example/libsimple.jar not found" - [ -e bazel-bin/com/google/example/libcomplex.jar ] \ - || fail "bazel-bin/com/google/example/libcomplex.jar not found" + [ -e ${PRODUCT_NAME}-bin/com/google/example/libsimple.jar ] \ + || fail "${PRODUCT_NAME}-bin/com/google/example/libsimple.jar not found" + [ -e ${PRODUCT_NAME}-bin/com/google/example/libcomplex.jar ] \ + || fail "${PRODUCT_NAME}-bin/com/google/example/libcomplex.jar not found" } function test_filtered_gen_jar_generation() { @@ -204,14 +199,16 @@ java_library( EOF bazel build //com/google/example:test \ - --aspects AndroidStudioInfoAspect --output_groups "ide-resolve" --experimental_show_artifacts \ + --aspects AndroidStudioInfoAspect --output_groups "ide-resolve" \ + --experimental_show_artifacts \ || fail "Expected success" - [ -e bazel-bin/com/google/example/libtest.jar ] \ - || fail "bazel-bin/com/google/example/libtest.jar not found" - [ -e bazel-bin/com/google/example/test-filtered-gen.jar ] \ - || fail "bazel-bin/com/google/example/test-filtered-gen.jar not found" + EXAMPLE_DIR="${PRODUCT_NAME}-bin/com/google/example" + [ -e "${EXAMPLE_DIR}/libtest.jar" ] \ + || fail "${EXAMPLE_DIR}/libtest.jar not found" + [ -e "${EXAMPLE_DIR}/test-filtered-gen.jar" ] \ + || fail "${EXAMPLE_DIR}/test-filtered-gen.jar not found" - unzip bazel-bin/com/google/example/test-filtered-gen.jar + unzip "${EXAMPLE_DIR}/test-filtered-gen.jar" [ -e gen/Gen.class ] \ || fail "Filtered gen jar does not contain Gen.class" [ ! -e com/google/example/Test.class ] \ @@ -258,10 +255,10 @@ EOF bazel build //com/google/example:complex \ --aspects AndroidStudioInfoAspect --output_groups "ide-info-text" \ || fail "Expected success" - [ -e bazel-bin/com/google/example/simple.aswb-build.txt ] \ - || fail "bazel-bin/com/google/example/simple.aswb-build.txt not found" - [ -e bazel-bin/com/google/example/complex.aswb-build.txt ] \ - || fail "bazel-bin/com/google/example/complex.aswb-build.txt not found" + SIMPLE_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/simple.aswb-build.txt" + [ -e $SIMPLE_ASWB_BUILD ] || fail "$SIMPLE_ASWB_BUILD not found" + COMPLEX_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/complex.aswb-build.txt" + [ -e $COMPLEX_ASWB_BUILD ] || fail "$COMPLEX_ASWB_BUILD not found" } run_suite "Test IDE info files generation" diff --git a/src/test/shell/integration/java_integration_test.sh b/src/test/shell/integration/java_integration_test.sh index 3ed4a18263a563..a8041ceeace219 100755 --- a/src/test/shell/integration/java_integration_test.sh +++ b/src/test/shell/integration/java_integration_test.sh @@ -15,23 +15,18 @@ # limitations under the License. # # These are end to end tests for building Java. - -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -source $(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/shell_utils.sh \ +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../shell_utils.sh" \ || { echo "shell_utils.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + set -eu declare -r runfiles_relative_javabase="$1" - -create_and_cd_client -put_bazel_on_path - -write_default_bazelrc -add_to_bazelrc "build --package_path=%workspace% --embed_changelist=none" +add_to_bazelrc "build --package_path=%workspace%" #### HELPER FUNCTIONS ################################################## @@ -199,16 +194,24 @@ function test_compiles_hello_world_from_deploy_jar() { write_hello_world_files "$pkg" bazel build //$pkg/java/hello:hello_deploy.jar || fail "build failed" - function check_deploy_jar_works() { - "$@" | grep -q 'Hello, World!' || fail "comparison failed" - } - function check_arglists() { - check_deploy_jar_works "$@" --singlejar - check_deploy_jar_works "$@" --wrapper_script_flag=--singlejar - check_deploy_jar_works "$@" REGULAR_ARG --wrapper_script_flag=--singlejar - } - check_arglists bazel run //$pkg/java/hello:hello -- - check_arglists ${PRODUCT_NAME}-bin/$pkg/java/hello/hello + + bazel run //$pkg/java/hello:hello -- --singlejar | grep -q 'Hello, World!' \ + || fail "comparison failed" + ${PRODUCT_NAME}-bin/$pkg/java/hello/hello -- --singlejar | \ + grep -q 'Hello, World!' || fail "comparison failed" + + bazel run //$pkg/java/hello:hello -- --wrapper_script_flag=--singlejar \ + | grep -q 'Hello, World!' || fail "comparison failed" + ${PRODUCT_NAME}-bin/$pkg/java/hello/hello -- \ + --wrapper_script_flag=--singlejar | grep -q 'Hello, World!' \ + || fail "comparison failed" + + bazel run //$pkg/java/hello:hello -- REGULAR_ARG \ + --wrapper_script_flag=--singlejar | grep -q 'Hello, World!' \ + || fail "comparison failed" + ${PRODUCT_NAME}-bin/$pkg/java/hello/hello -- REGULAR_ARG \ + --wrapper_script_flag=--singlejar | grep -q 'Hello, World!' \ + || fail "comparison failed" } function test_explicit_bogus_wrapper_args_are_rejected() { diff --git a/src/test/shell/integration/loading_phase_tests.sh b/src/test/shell/integration/loading_phase_tests.sh index b9d10dd23d784f..cba257afbd497f 100755 --- a/src/test/shell/integration/loading_phase_tests.sh +++ b/src/test/shell/integration/loading_phase_tests.sh @@ -18,15 +18,13 @@ # that use only the loading or analysis phases. # -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -create_and_cd_client -put_bazel_on_path # Our tests use the static crosstool, so make it the default. -EXTRA_BAZELRC="build --crosstool_top=@bazel_tools//tools/cpp:default-toolchain" -write_default_bazelrc +add_to_bazelrc "build --crosstool_top=@bazel_tools//tools/cpp:default-toolchain" + +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } output_base=$TEST_TMPDIR/out TEST_stderr=$(dirname $TEST_log)/stderr @@ -111,16 +109,16 @@ function test_options_errors() { function test_bazelrc_option() { cp ${bazelrc} ${new_workspace_dir}/.${PRODUCT_NAME}rc - echo "build --cpu=piii" >>.${PRODUCT_NAME}rc # default bazelrc - $bazel info >/dev/null 2>$TEST_log + echo "build --cpu=armeabi-v7a" >>.${PRODUCT_NAME}rc # default bazelrc + $PATH_TO_BAZEL_BIN info >/dev/null 2>$TEST_log expect_log "Reading.*$(pwd)/.${PRODUCT_NAME}rc: -.*--cpu=piii" +.*--cpu=armeabi-v7a" cp .${PRODUCT_NAME}rc foo - echo "build --cpu=k8" >>foo # non-default bazelrc - $bazel --${PRODUCT_NAME}rc=foo info >/dev/null 2>$TEST_log + echo "build --cpu=armeabi-v7a" >>foo # non-default bazelrc + $PATH_TO_BAZEL_BIN --${PRODUCT_NAME}rc=foo info >/dev/null 2>$TEST_log expect_log "Reading.*$(pwd)/foo: -.*--cpu=k8" +.*--cpu=armeabi-v7a" } # This exercises the production-code assertion in AbstractCommand.java @@ -317,4 +315,4 @@ function test_incremental_deleting_package_roots() { expect_not_log "//a:external" } -run_suite "Miscellaneous integration tests of bazel, using loading/analysis phases." +run_suite "Integration tests of ${PRODUCT_NAME} using loading/analysis phases." diff --git a/src/test/shell/integration/output_filter_test.sh b/src/test/shell/integration/output_filter_test.sh index 2007e367ae92c9..588183e3863b68 100755 --- a/src/test/shell/integration/output_filter_test.sh +++ b/src/test/shell/integration/output_filter_test.sh @@ -17,13 +17,10 @@ # output_filter_test.sh: a couple of end to end tests for the warning # filter functionality. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -create_and_cd_client -put_bazel_on_path -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_output_filter_cc() { # "test warning filter for C compilation" diff --git a/src/test/shell/integration/progress_reporting_test.sh b/src/test/shell/integration/progress_reporting_test.sh index 7d46b4842edb74..f84b61aefce0a4 100755 --- a/src/test/shell/integration/progress_reporting_test.sh +++ b/src/test/shell/integration/progress_reporting_test.sh @@ -16,21 +16,16 @@ # # This test exercises action progress reporting. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } set -eu -create_and_cd_client -put_bazel_on_path -write_default_bazelrc - -cat >>"$bazelrc" <&2; exit 1; } - -create_and_cd_client -put_bazel_on_path -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } #### SETUP ############################################################# diff --git a/src/test/shell/integration/run_test.sh b/src/test/shell/integration/run_test.sh index ad986930c709a4..a2919db5ac480a 100755 --- a/src/test/shell/integration/run_test.sh +++ b/src/test/shell/integration/run_test.sh @@ -16,15 +16,12 @@ # # Integration tests for "bazel run" -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } +NO_SIGNAL_OVERRIDE=1 +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -create_and_cd_client -NO_SIGNAL_OVERRIDE=1 put_bazel_on_path - -write_default_bazelrc -add_to_bazelrc "build --embed_changelist=none" add_to_bazelrc "test --notest_loasd" #### HELPER FUNCTIONS ################################################## @@ -97,10 +94,12 @@ function test_runfiles_present_cc_binary() { Hello, kitty. EOF - bazel run --nobuild_runfile_links //cc:kitty > output || fail "Bazel run failed." + bazel run --nobuild_runfile_links //cc:kitty > output \ + || fail "${PRODUCT_NAME} run failed." assert_contains "Hello, kitty" output || fail "Output is not OK." - bazel run --nobuild_runfile_links //cc:kitty > output2 || fail "Second Bazel run failed." + bazel run --nobuild_runfile_links //cc:kitty > output2 \ + || fail "Second ${PRODUCT_NAME} run failed." assert_contains "Hello, kitty" output2 || fail "Output is not OK." } @@ -111,7 +110,8 @@ function test_runfiles_updated_correctly_with_nobuild_runfile_links { Hello, kitty. EOF - bazel run --nobuild_runfile_links //cc:kitty > output || fail "Bazel run failed." + bazel run --nobuild_runfile_links //cc:kitty > output \ + || fail "${PRODUCT_NAME} run failed." assert_contains "Hello, kitty" output || fail "Output is not OK." rm cc/hello_kitty.txt @@ -119,7 +119,8 @@ EOF A pussycat. EOF - bazel run --nobuild_runfile_links //cc:kitty > output || fail "Bazel run failed." + bazel run --nobuild_runfile_links //cc:kitty > output \ + || fail "${PRODUCT_NAME} run failed." assert_contains "pussycat" output || fail "Output is not OK." } @@ -130,9 +131,9 @@ function test_script_file_generation { chmod +x fubar/fubar.sh bazel run --script_path=$(pwd)/fubar/output.sh //fubar \ - || fail "Bazel run failed (--script_path)." + || fail "${PRODUCT_NAME} run failed (--script_path)." grep "fubar \"\$\@\"" ./fubar/output.sh \ - || fail "Bazel run --script_path output was incorrect." + || fail "${PRODUCT_NAME} run --script_path output was incorrect." $(pwd)/fubar/output.sh a "b c" d > ./fubar/fubar.output \ || fail "Generated script exited with an error." @@ -159,15 +160,15 @@ function test_consistent_command_line_encoding { chmod +x foo/foo.sh bazel run //foo -- "$arg" > output \ - || fail "Bazel run failed." + || fail "${PRODUCT_NAME} run failed." bazel test //foo:foo_test --test_arg="$arg" \ - || fail "Bazel test failed" + || fail "${PRODUCT_NAME} test failed" bazel --batch run //foo -- "$arg" > output \ - || fail "Bazel run failed (--batch)." + || fail "${PRODUCT_NAME} run failed (--batch)." bazel --batch test //foo:foo_test --test_arg="$arg" \ - || fail "Bazel test failed (--batch)" + || fail "${PRODUCT_NAME} test failed (--batch)" } function test_interrupt_kills_child() { @@ -181,13 +182,13 @@ function test_interrupt_kills_child() { # be run in "monitor mode" (with the command set -m) for bazel or the server to receive SIGINT. local serverpid=$(bazel info server_pid) if [ -z $serverpid ]; then - fail "Couldn't get Bazel server PID" + fail "Couldn't get ${PRODUCT_NAME} server PID" fi (bazel run //foo:sleep-minute || true) & local sleeppid read sleeppid &2; exit 1; } - -create_and_cd_client -put_bazel_on_path -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } #### SETUP ############################################################# diff --git a/src/test/shell/integration/startup_options_test.sh b/src/test/shell/integration/startup_options_test.sh index 1534ef15913b56..68dca09c107835 100755 --- a/src/test/shell/integration/startup_options_test.sh +++ b/src/test/shell/integration/startup_options_test.sh @@ -16,17 +16,14 @@ # # Test of Bazel's startup option handling. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -put_bazel_on_path -create_and_cd_client -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_different_startup_options() { pid=$(bazel info server_pid 2> $TEST_log) - [[ -n $pid ]] || fail "Couldn't run bazel" + [[ -n $pid ]] || fail "Couldn't run ${PRODUCT_NAME}" newpid=$(bazel --batch info server_pid 2> $TEST_log) expect_log "WARNING: Running B\\(azel\\|laze\\) server needs to be killed, because the startup options are different." [[ "$newpid" != "$pid" ]] || fail "pid $pid was the same!" @@ -35,4 +32,4 @@ function test_different_startup_options() { true } -run_suite "bazel startup options test" +run_suite "${PRODUCT_NAME} startup options test" diff --git a/src/test/shell/integration/stub_finds_runfiles_test.sh b/src/test/shell/integration/stub_finds_runfiles_test.sh index 1806cce21cd049..a608625fa23683 100755 --- a/src/test/shell/integration/stub_finds_runfiles_test.sh +++ b/src/test/shell/integration/stub_finds_runfiles_test.sh @@ -19,9 +19,10 @@ set -eu -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } test_strategy="standalone" genrule_strategy="local" @@ -31,10 +32,6 @@ if [ $# -ge 1 ]; then shift fi -create_and_cd_client -put_bazel_on_path -write_default_bazelrc - #### TESTS ############################################################# mkdir pkg pkg/java @@ -101,36 +98,36 @@ chmod +x pkg/*.sh unset TEST_SRCDIR bazel build //pkg:javabin -bazel-bin/pkg/javabin +${PRODUCT_NAME}-bin/pkg/javabin bazel run //pkg:javabin -bazel-bin/pkg/javabin.runfiles/*/pkg/javabin +${PRODUCT_NAME}-bin/pkg/javabin.runfiles/*/pkg/javabin bazel build //pkg:javatest -bazel-bin/pkg/javatest +${PRODUCT_NAME}-bin/pkg/javatest bazel run //pkg:javatest -bazel-bin/pkg/javatest.runfiles/*/pkg/javatest +${PRODUCT_NAME}-bin/pkg/javatest.runfiles/*/pkg/javatest bazel test --test_strategy="$test_strategy" //pkg:javatest bazel build //pkg:pybin -bazel-bin/pkg/pybin +${PRODUCT_NAME}-bin/pkg/pybin bazel run //pkg:pybin -bazel-bin/pkg/pybin.runfiles/*/pkg/pybin +${PRODUCT_NAME}-bin/pkg/pybin.runfiles/*/pkg/pybin bazel build //pkg:pytest -bazel-bin/pkg/pytest +${PRODUCT_NAME}-bin/pkg/pytest bazel run //pkg:pytest -bazel-bin/pkg/pytest.runfiles/*/pkg/pytest +${PRODUCT_NAME}-bin/pkg/pytest.runfiles/*/pkg/pytest bazel test --test_strategy="$test_strategy" //pkg:pytest bazel build //pkg:sh_runs_javabin -bazel-bin/pkg/sh_runs_javabin +${PRODUCT_NAME}-bin/pkg/sh_runs_javabin bazel run //pkg:sh_runs_javabin bazel build //pkg:sh_runs_javatest bazel test --test_strategy="$test_strategy" //pkg:sh_runs_javatest bazel build //pkg:sh_runs_pybin -bazel-bin/pkg/sh_runs_pybin +${PRODUCT_NAME}-bin/pkg/sh_runs_pybin bazel run //pkg:sh_runs_pybin bazel build //pkg:sh_runs_pytest diff --git a/src/test/shell/integration/testenv.sh b/src/test/shell/integration/testenv.sh deleted file mode 100755 index e7b484c3cd7de0..00000000000000 --- a/src/test/shell/integration/testenv.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 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. -# -# Setting up the environment for our legacy integration tests. -# -source $(cd "$(dirname $(dirname "${BASH_SOURCE[0]}"))" && pwd)/bazel/test-setup.sh \ - || { echo "test-setup.sh not found!" >&2; exit 1; } - -PRODUCT_NAME=bazel -WORKSPACE_NAME=main -bazelrc=$TEST_TMPDIR/bazelrc - -function put_bazel_on_path() { - put_blaze_on_path "$@" -} - -function put_bazel_on_path() { - # do nothing as test-setup already does that - true -} - -function write_default_bazelrc() { - setup_bazelrc -} - -function add_to_bazelrc() { - echo "$@" >> .bazelrc -} - -function create_and_cd_client() { - setup_clean_workspace - echo "workspace(name = '$WORKSPACE_NAME')" >WORKSPACE - touch .bazelrc -} diff --git a/src/test/shell/integration/ui_test.sh b/src/test/shell/integration/ui_test.sh index 6ab0d9453ac671..c3651cd7eb50d9 100755 --- a/src/test/shell/integration/ui_test.sh +++ b/src/test/shell/integration/ui_test.sh @@ -16,13 +16,10 @@ # # An end-to-end test that Bazel's experimental UI produces reasonable output. -# Load test environment -source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \ - || { echo "testenv.sh not found!" >&2; exit 1; } - -create_and_cd_client -put_bazel_on_path -write_default_bazelrc +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } #### SETUP ############################################################# diff --git a/src/test/shell/integration_test_setup.sh b/src/test/shell/integration_test_setup.sh new file mode 100755 index 00000000000000..73f7c925e8ee78 --- /dev/null +++ b/src/test/shell/integration_test_setup.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Copyright 2016 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 print_message_and_exit() { + echo $1 >&2; exit 1; +} + +CURRENT_SCRIPT=${BASH_SOURCE[0]} +# Go to the directory where the script is running +cd "$(dirname ${CURRENT_SCRIPT})" \ + || print_message_and_exit "Unable to access "$(dirname ${CURRENT_SCRIPT})"" + +DIR=$(pwd) +# Load the unit test framework +source "$DIR/unittest.bash" || print_message_and_exit "unittest.bash not found!" +# Load the test environment +source "$DIR/testenv.sh" || print_message_and_exit "testenv.sh not found!" diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh index 7843f9a6547660..0e7d1506a54a34 100755 --- a/src/test/shell/testenv.sh +++ b/src/test/shell/testenv.sh @@ -14,146 +14,507 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# Common utility file for Bazel shell tests +# Testing environment for the Bazel integration tests # +# TODO(bazel-team): This file is currently an append of the old testenv.sh and +# test-setup.sh files. This must be cleaned up eventually. -# Enable errexit with pretty stack traces. -enable_errexit - -# Print message in "$1" then exit with status "$2" -die () { - # second argument is optional, defaulting to 1 - local status_code=${2:-1} - # Stop capturing stdout/stderr, and dump captured output - if [ "$CAPTURED_STD_ERR" -ne 0 -o "$CAPTURED_STD_OUT" -ne 0 ]; then - restore_outputs - if [ "$CAPTURED_STD_OUT" -ne 0 ]; then - cat "${TEST_TMPDIR}/captured.out" - CAPTURED_STD_OUT=0 - fi - if [ "$CAPTURED_STD_ERR" -ne 0 ]; then - cat "${TEST_TMPDIR}/captured.err" 1>&2 - CAPTURED_STD_ERR=0 - fi - fi +# Make the command "bazel" available for tests. +PATH_TO_BAZEL_BIN=$(rlocation io_bazel/src/bazel) +PATH_TO_BAZEL_WRAPPER="${TEST_SRCDIR}/io_bazel/src/test/shell/bin" +if [ ! -f "${PATH_TO_BAZEL_WRAPPER}/bazel" ]; +then + echo "Unable to find the Bazel binary at $PATH_TO_BAZEL_WRAPPER/bazel" >&2 + exit 1; +fi +export PATH="$PATH_TO_BAZEL_WRAPPER:$PATH" + +################### shell/bazel/testenv ################################## +# Setting up the environment for Bazel integration tests. +# +[ -z "$TEST_SRCDIR" ] && { echo "TEST_SRCDIR not set!" >&2; exit 1; } +BAZEL_RUNFILES="$TEST_SRCDIR/io_bazel" - if [ -n "${1-}" ] ; then - echo "$1" 1>&2 +if ! type rlocation &> /dev/null; then + function rlocation() { + if [[ "$1" = /* ]]; then + echo $1 + else + echo "$TEST_SRCDIR/$1" fi - if [ -n "${BASH-}" ]; then - local caller_n=0 - while [ $caller_n -lt 4 ] && caller_out=$(caller $caller_n 2>/dev/null); do - test $caller_n -eq 0 && echo "CALLER stack (max 4):" - echo " $caller_out" - let caller_n=caller_n+1 - done 1>&2 + } + export -f rlocation +fi + +# WORKSPACE file +workspace_file="${BAZEL_RUNFILES}/WORKSPACE" + +# Bazel +bazel_tree="$(rlocation io_bazel/src/test/shell/bazel/doc-srcs.zip)" +bazel_data="${BAZEL_RUNFILES}" + +# Windows +PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" +function is_windows() { + # On windows, the shell test actually running on msys + if [[ "${PLATFORM}" =~ msys_nt* ]]; then + true + else + false + fi +} + +# Java +if is_windows; then + jdk_dir="$(cygpath -m $(cd $(rlocation local_jdk/bin/java.exe)/../..; pwd))" +else + jdk_dir="${TEST_SRCDIR}/local_jdk" +fi +langtools="$(rlocation io_bazel/src/test/shell/bazel/langtools.jar)" + +# Tools directory location +tools_dir="$(dirname $(rlocation io_bazel/tools/BUILD))" +langtools_dir="$(dirname $(rlocation io_bazel/third_party/java/jdk/langtools/BUILD))" +EXTRA_BAZELRC="build --ios_sdk_version=8.4" + +# Java tooling +javabuilder_path="$(find ${BAZEL_RUNFILES} -name JavaBuilder_*.jar)" +langtools_path="${BAZEL_RUNFILES}/third_party/java/jdk/langtools/javac.jar" +singlejar_path="${BAZEL_RUNFILES}/src/java_tools/singlejar/SingleJar_deploy.jar" +genclass_path="${BAZEL_RUNFILES}/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass_deploy.jar" +junitrunner_path="${BAZEL_RUNFILES}/src/java_tools/junitrunner/java/com/google/testing/junit/runner/Runner_deploy.jar" +ijar_path="${BAZEL_RUNFILES}/third_party/ijar/ijar" + +# Sandbox tools +process_wrapper="${BAZEL_RUNFILES}/src/main/tools/process-wrapper" +linux_sandbox="${BAZEL_RUNFILES}/src/main/tools/linux-sandbox" + +# iOS and Objective-C tooling +iossim_path="${BAZEL_RUNFILES}/third_party/iossim/iossim" +actoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/actoolwrapper/actoolwrapper.sh" +ibtoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/ibtoolwrapper/ibtoolwrapper.sh" +swiftstdlibtoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/swiftstdlibtoolwrapper/swiftstdlibtoolwrapper.sh" +momcwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/momcwrapper/momcwrapper.sh" +bundlemerge_path="${BAZEL_RUNFILES}/src/objc_tools/bundlemerge/bundlemerge_deploy.jar" +plmerge_path="${BAZEL_RUNFILES}/src/objc_tools/plmerge/plmerge_deploy.jar" +xcodegen_path="${BAZEL_RUNFILES}/src/objc_tools/xcodegen/xcodegen_deploy.jar" +stdredirect_path="${BAZEL_RUNFILES}/src/tools/xcode/stdredirect/StdRedirect.dylib" +realpath_path="${BAZEL_RUNFILES}/src/tools/xcode/realpath/realpath" +environment_plist_path="${BAZEL_RUNFILES}/src/tools/xcode/environment/environment_plist.sh" +xcrunwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh" + +# Test data +testdata_path=${BAZEL_RUNFILES}/src/test/shell/bazel/testdata +python_server="${BAZEL_RUNFILES}/src/test/shell/bazel/testing_server.py" + +# Third-party +MACHINE_TYPE="$(uname -m)" +MACHINE_IS_64BIT='no' +if [ "${MACHINE_TYPE}" = 'amd64' -o "${MACHINE_TYPE}" = 'x86_64' -o "${MACHINE_TYPE}" = 's390x' ]; then + MACHINE_IS_64BIT='yes' +fi + +MACHINE_IS_Z='no' +if [ "${MACHINE_TYPE}" = 's390x' ]; then + MACHINE_IS_Z='yes' +fi + +case "${PLATFORM}" in + darwin) + if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then + protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-osx-x86_64.exe" + else + protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-osx-x86_32.exe" fi - if [ x"$status_code" != x -a x"$status_code" != x"0" ]; then - exit "$status_code" + ;; + *) + if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then + if [ "${MACHINE_IS_Z}" = 'yes' ]; then + protoc_compiler="${BAZEL_RUNFILES}//third_party/protobuf/protoc-linux-s390x_64.exe" + else + protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-linux-x86_64.exe" + fi else - exit 1 + protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-linux-x86_32.exe" fi + ;; +esac + +if [ -z ${RUNFILES_MANIFEST_ONLY+x} ]; then + protoc_jar="${BAZEL_RUNFILES}/third_party/protobuf/protobuf-*.jar" + junit_jar="${BAZEL_RUNFILES}/third_party/junit/junit-*.jar" + hamcrest_jar="${BAZEL_RUNFILES}/third_party/hamcrest/hamcrest-*.jar" +else + protoc_jar=$(rlocation io_bazel/third_party/protobuf/protobuf-.*.jar) + junit_jar=$(rlocation io_bazel/third_party/junit/junit-.*.jar) + hamcrest_jar=$(rlocation io_bazel/third_party/hamcrest/hamcrest-.*.jar) +fi + +# This function copies the tools directory from Bazel. +function copy_tools_directory() { + cp -RL ${tools_dir}/* tools + # tools/jdk/BUILD file for JDK 7 is generated. + if [ -f tools/jdk/BUILD.* ]; then + cp tools/jdk/BUILD.* tools/jdk/BUILD + chmod +w tools/jdk/BUILD + fi + # To support custom langtools + cp ${langtools} tools/jdk/langtools.jar + cat >>tools/jdk/BUILD <<'EOF' +filegroup(name = "test-langtools", srcs = ["langtools.jar"]) +EOF + + mkdir -p third_party/java/jdk/langtools + cp -R ${langtools_dir}/* third_party/java/jdk/langtools + + chmod -R +w . + mkdir -p tools/defaults + touch tools/defaults/BUILD + + mkdir -p third_party/py/gflags + cat > third_party/py/gflags/BUILD <&2 - fi - ERROR_COUNT=$(($ERROR_COUNT + 1)) +# Report whether a given directory name corresponds to a tools directory. +function is_tools_directory() { + case "$1" in + third_party|tools|src) + true + ;; + *) + false + ;; + esac +} + +# Copy the examples of the base workspace +function copy_examples() { + EXAMPLE="$(cd $(dirname $(rlocation io_bazel/examples/cpp/BUILD))/..; pwd)" + cp -RL ${EXAMPLE} . + chmod -R +w . +} + +# +# Find a random unused TCP port +# +pick_random_unused_tcp_port () { + perl -MSocket -e ' +sub CheckPort { + my ($port) = @_; + socket(TCP_SOCK, PF_INET, SOCK_STREAM, getprotobyname("tcp")) + || die "socket(TCP): $!"; + setsockopt(TCP_SOCK, SOL_SOCKET, SO_REUSEADDR, 1) + || die "setsockopt(TCP): $!"; + return 0 unless bind(TCP_SOCK, sockaddr_in($port, INADDR_ANY)); + socket(UDP_SOCK, PF_INET, SOCK_DGRAM, getprotobyname("udp")) + || die "socket(UDP): $!"; + return 0 unless bind(UDP_SOCK, sockaddr_in($port, INADDR_ANY)); + return 1; +} +for (1 .. 128) { + my ($port) = int(rand() * 27000 + 32760); + if (CheckPort($port)) { + print "$port\n"; + exit 0; + } +} +print "NO_FREE_PORT_FOUND\n"; +exit 1; +' +} + +# +# A uniform SHA-256 commands that works accross platform +# +case "${PLATFORM}" in + darwin) + function sha256sum() { + cat "$1" | shasum -a 256 | cut -f 1 -d " " + } + ;; + *) + # Under linux sha256sum should exists + ;; +esac + +################### shell/bazel/test-setup ############################### +# Setup bazel for integration tests +# + +# OS X has a limit in the pipe length, so force the root to a shorter one +bazel_root="${TEST_TMPDIR}/root" +mkdir -p "${bazel_root}" + +bazel_javabase="${jdk_dir}" + +echo "bazel binary is at $PATH_TO_BAZEL_WRAPPER" + +# Here we unset variable that were set by the invoking Blaze instance +unset JAVA_RUNFILES + +function setup_bazelrc() { + cat >$TEST_TMPDIR/bazelrc <> WORKSPACE <third_party/BUILD +package(default_visibility = ["//visibility:public"]) +EOF + fi + + [ -e third_party/junit.jar ] || ln -s ${junit_jar} third_party/junit.jar + [ -e third_party/hamcrest.jar ] \ + || ln -s ${hamcrest_jar} third_party/hamcrest.jar } -# The structure of the following if statements is such that if '[' fails -# (e.g., a non-number was passed in) then the check will fail. +function setup_javatest_support() { + setup_javatest_common + grep -q 'name = "junit4"' third_party/BUILD \ + || cat <>third_party/BUILD +java_import( + name = "junit4", + jars = [ + "junit.jar", + "hamcrest.jar", + ], +) +EOF +} -# Die if "$1" > "$2", print $3 as death reason -check_le () { - [ "$1" -gt "$2" ] || die "Check failed: '$1' <= '$2' ${3:+ ($3)}" +function setup_skylark_javatest_support() { + setup_javatest_common + grep -q "name = \"junit4-jars\"" third_party/BUILD \ + || cat <>third_party/BUILD +filegroup( + name = "junit4-jars", + srcs = [ + "junit.jar", + "hamcrest.jar", + ], +) +EOF } -# Die if "$1" >= "$2", print $3 as death reason -check_lt () { - [ "$1" -lt "$2" ] || die "Check failed: '$1' < '$2' ${3:+ ($3)}" +function setup_iossim() { + mkdir -p third_party/iossim + ln -sv ${iossim_path} third_party/iossim/iossim + + cat <>third_party/iossim/BUILD +licenses(["unencumbered"]) +package(default_visibility = ["//visibility:public"]) + +exports_files(["iossim"]) +EOF } -# Die if "$1" < "$2", print $3 as death reason -check_ge () { - [ "$1" -ge "$2" ] || die "Check failed: '$1' >= '$2' ${3:+ ($3)}" +# Sets up Objective-C tools. Mac only. +function setup_objc_test_support() { + IOS_SDK_VERSION=$(xcrun --sdk iphoneos --show-sdk-version) } -# Die if "$1" <= "$2", print $3 as death reason -check_gt () { - [ "$1" -gt "$2" ] || die "Check failed: '$1' > '$2' ${3:+ ($3)}" +workspaces=() +# Set-up a new, clean workspace with only the tools installed. +function create_new_workspace() { + new_workspace_dir=${1:-$(mktemp -d ${TEST_TMPDIR}/workspace.XXXXXXXX)} + rm -fr ${new_workspace_dir} + mkdir -p ${new_workspace_dir} + workspaces+=(${new_workspace_dir}) + cd ${new_workspace_dir} + mkdir tools + mkdir -p third_party/java/jdk/langtools + + copy_tools_directory + + [ -e third_party/java/jdk/langtools/javac.jar ] \ + || ln -s "${langtools_path}" third_party/java/jdk/langtools/javac.jar + + touch WORKSPACE } -# Die if $2 !~ $1; print $3 as death reason -check_match () -{ - expr match "$2" "$1" >/dev/null || \ - die "Check failed: '$2' does not match regex '$1' ${3:+ ($3)}" +# Set-up a clean default workspace. +function setup_clean_workspace() { + export WORKSPACE_DIR=${TEST_TMPDIR}/workspace + echo "setting up client in ${WORKSPACE_DIR}" > $TEST_log + rm -fr ${WORKSPACE_DIR} + create_new_workspace ${WORKSPACE_DIR} + [ "${new_workspace_dir}" = "${WORKSPACE_DIR}" ] || \ + { echo "Failed to create workspace" >&2; exit 1; } + export BAZEL_INSTALL_BASE=$(bazel info install_base) + export BAZEL_GENFILES_DIR=$(bazel info bazel-genfiles) + export BAZEL_BIN_DIR=$(bazel info bazel-bin) + if is_windows; then + export BAZEL_SH="$(cygpath --windows /bin/bash)" + fi } -# Run command "$1" at exit. Like "trap" but multiple atexits don't -# overwrite each other. Will break if someone does call trap -# directly. So, don't do that. -ATEXIT="${ATEXIT-}" -atexit () { - if [ -z "$ATEXIT" ]; then - ATEXIT="$1" - else - ATEXIT="$1 ; $ATEXIT" +# Clean up all files that are not in tools directories, to restart +# from a clean workspace +function cleanup_workspace() { + if [ -d "${WORKSPACE_DIR:-}" ]; then + echo "Cleaning up workspace" > $TEST_log + cd ${WORKSPACE_DIR} + bazel clean >& $TEST_log # Clean up the output base + + for i in $(ls); do + if ! is_tools_directory "$i"; then + rm -fr "$i" + fi + done + touch WORKSPACE + fi + for i in ${workspaces}; do + if [ "$i" != "${WORKSPACE_DIR:-}" ]; then + rm -fr $i fi - trap "$ATEXIT" EXIT + done + workspaces=() } -## TEST_TMPDIR -if [ -z "${TEST_TMPDIR:-}" ]; then - export TEST_TMPDIR="$(mktemp -d ${TMPDIR:-/tmp}/bazel-test.XXXXXXXX)" -fi -if [ ! -e "${TEST_TMPDIR}" ]; then - mkdir -p -m 0700 "${TEST_TMPDIR}" - # Clean TEST_TMPDIR on exit - atexit "rm -fr ${TEST_TMPDIR}" -fi +# Clean-up the bazel install base +function cleanup() { + if [ -d "${BAZEL_INSTALL_BASE:-__does_not_exists__}" ]; then + rm -fr "${BAZEL_INSTALL_BASE}" + fi +} -# Functions to compare the actual output of a test to the expected -# (golden) output. +function tear_down() { + cleanup_workspace +} + +# +# Simples assert to make the tests more readable # -# Usage: -# capture_test_stdout -# ... do something ... -# diff_test_stdout "$TEST_SRCDIR/path/to/golden.out" +function assert_build() { + bazel build -s --verbose_failures $* || fail "Failed to build $*" +} -# Redirect a file descriptor to a file. -CAPTURED_STD_OUT="${CAPTURED_STD_OUT:-0}" -CAPTURED_STD_ERR="${CAPTURED_STD_ERR:-0}" +function assert_build_output() { + local OUTPUT=$1 + shift + assert_build "$*" + test -f "$OUTPUT" || fail "Output $OUTPUT not found for target $*" +} -capture_test_stdout () { - exec 3>&1 # Save stdout as fd 3 - exec 4>"${TEST_TMPDIR}/captured.out" - exec 1>&4 - CAPTURED_STD_OUT=1 +function assert_build_fails() { + bazel build -s $1 >& $TEST_log \ + && fail "Test $1 succeed while expecting failure" \ + || true + if [ -n "${2:-}" ]; then + expect_log "$2" + fi } -capture_test_stderr () { - exec 6>&2 # Save stderr as fd 6 - exec 7>"${TEST_TMPDIR}/captured.err" - exec 2>&7 - CAPTURED_STD_ERR=1 +function assert_test_ok() { + bazel test --test_output=errors $* >& $TEST_log \ + || fail "Test $1 failed while expecting success" } -# Force XML_OUTPUT_FILE to an existing path -if [ -z "${XML_OUTPUT_FILE:-}" ]; then - XML_OUTPUT_FILE=${TEST_TMPDIR}/ouput.xml -fi +function assert_test_fails() { + bazel test --test_output=errors $* >& $TEST_log \ + && fail "Test $* succeed while expecting failure" \ + || true + expect_log "$1.*FAILED" +} + +function assert_binary_run() { + $1 >& $TEST_log || fail "Failed to run $1" + [ -z "${2:-}" ] || expect_log "$2" +} + +function assert_bazel_run() { + bazel run $1 >& $TEST_log || fail "Failed to run $1" + [ -z "${2:-}" ] || expect_log "$2" + + assert_binary_run "./bazel-bin/$(echo "$1" | sed 's|^//||' | sed 's|:|/|')" "${2:-}" +} + +setup_bazelrc +setup_clean_workspace + +################### shell/integration/testenv ############################ +# Setting up the environment for our legacy integration tests. +# +PRODUCT_NAME=bazel +WORKSPACE_NAME=main +bazelrc=$TEST_TMPDIR/bazelrc + +function put_bazel_on_path() { + # do nothing as test-setup already does that + true +} + +function write_default_bazelrc() { + setup_bazelrc +} + +function add_to_bazelrc() { + echo "$@" >> $bazelrc +} + +function create_and_cd_client() { + setup_clean_workspace + echo "workspace(name = '$WORKSPACE_NAME')" >WORKSPACE + touch .bazelrc +} + +################### Extra ############################ +# Functions that need to be called before each test. +create_and_cd_client \ No newline at end of file diff --git a/src/test/shell/unittest.bash b/src/test/shell/unittest.bash index c78f4912703a28..2da9cd3092fc54 100644 --- a/src/test/shell/unittest.bash +++ b/src/test/shell/unittest.bash @@ -98,7 +98,148 @@ function disable_errexit() { trap - ERR } -source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; } +#### Set up the test environment, branched from the old shell/testenv.sh + +# Enable errexit with pretty stack traces. +enable_errexit + +# Print message in "$1" then exit with status "$2" +die () { + # second argument is optional, defaulting to 1 + local status_code=${2:-1} + # Stop capturing stdout/stderr, and dump captured output + if [ "$CAPTURED_STD_ERR" -ne 0 -o "$CAPTURED_STD_OUT" -ne 0 ]; then + restore_outputs + if [ "$CAPTURED_STD_OUT" -ne 0 ]; then + cat "${TEST_TMPDIR}/captured.out" + CAPTURED_STD_OUT=0 + fi + if [ "$CAPTURED_STD_ERR" -ne 0 ]; then + cat "${TEST_TMPDIR}/captured.err" 1>&2 + CAPTURED_STD_ERR=0 + fi + fi + + if [ -n "${1-}" ] ; then + echo "$1" 1>&2 + fi + if [ -n "${BASH-}" ]; then + local caller_n=0 + while [ $caller_n -lt 4 ] && caller_out=$(caller $caller_n 2>/dev/null); do + test $caller_n -eq 0 && echo "CALLER stack (max 4):" + echo " $caller_out" + let caller_n=caller_n+1 + done 1>&2 + fi + if [ x"$status_code" != x -a x"$status_code" != x"0" ]; then + exit "$status_code" + else + exit 1 + fi +} + +# Print message in "$1" then record that a non-fatal error occurred in ERROR_COUNT +ERROR_COUNT="${ERROR_COUNT:-0}" +error () { + if [ -n "$1" ] ; then + echo "$1" 1>&2 + fi + ERROR_COUNT=$(($ERROR_COUNT + 1)) +} + +# Die if "$1" != "$2", print $3 as death reason +check_eq () { + [ "$1" = "$2" ] || die "Check failed: '$1' == '$2' ${3:+ ($3)}" +} + +# Die if "$1" == "$2", print $3 as death reason +check_ne () { + [ "$1" != "$2" ] || die "Check failed: '$1' != '$2' ${3:+ ($3)}" +} + +# The structure of the following if statements is such that if '[' fails +# (e.g., a non-number was passed in) then the check will fail. + +# Die if "$1" > "$2", print $3 as death reason +check_le () { + [ "$1" -gt "$2" ] || die "Check failed: '$1' <= '$2' ${3:+ ($3)}" +} + +# Die if "$1" >= "$2", print $3 as death reason +check_lt () { + [ "$1" -lt "$2" ] || die "Check failed: '$1' < '$2' ${3:+ ($3)}" +} + +# Die if "$1" < "$2", print $3 as death reason +check_ge () { + [ "$1" -ge "$2" ] || die "Check failed: '$1' >= '$2' ${3:+ ($3)}" +} + +# Die if "$1" <= "$2", print $3 as death reason +check_gt () { + [ "$1" -gt "$2" ] || die "Check failed: '$1' > '$2' ${3:+ ($3)}" +} + +# Die if $2 !~ $1; print $3 as death reason +check_match () +{ + expr match "$2" "$1" >/dev/null || \ + die "Check failed: '$2' does not match regex '$1' ${3:+ ($3)}" +} + +# Run command "$1" at exit. Like "trap" but multiple atexits don't +# overwrite each other. Will break if someone does call trap +# directly. So, don't do that. +ATEXIT="${ATEXIT-}" +atexit () { + if [ -z "$ATEXIT" ]; then + ATEXIT="$1" + else + ATEXIT="$1 ; $ATEXIT" + fi + trap "$ATEXIT" EXIT +} + +## TEST_TMPDIR +if [ -z "${TEST_TMPDIR:-}" ]; then + export TEST_TMPDIR="$(mktemp -d ${TMPDIR:-/tmp}/bazel-test.XXXXXXXX)" +fi +if [ ! -e "${TEST_TMPDIR}" ]; then + mkdir -p -m 0700 "${TEST_TMPDIR}" + # Clean TEST_TMPDIR on exit + atexit "rm -fr ${TEST_TMPDIR}" +fi + +# Functions to compare the actual output of a test to the expected +# (golden) output. +# +# Usage: +# capture_test_stdout +# ... do something ... +# diff_test_stdout "$TEST_SRCDIR/path/to/golden.out" + +# Redirect a file descriptor to a file. +CAPTURED_STD_OUT="${CAPTURED_STD_OUT:-0}" +CAPTURED_STD_ERR="${CAPTURED_STD_ERR:-0}" + +capture_test_stdout () { + exec 3>&1 # Save stdout as fd 3 + exec 4>"${TEST_TMPDIR}/captured.out" + exec 1>&4 + CAPTURED_STD_OUT=1 +} + +capture_test_stderr () { + exec 6>&2 # Save stderr as fd 6 + exec 7>"${TEST_TMPDIR}/captured.err" + exec 2>&7 + CAPTURED_STD_ERR=1 +} + +# Force XML_OUTPUT_FILE to an existing path +if [ -z "${XML_OUTPUT_FILE:-}" ]; then + XML_OUTPUT_FILE=${TEST_TMPDIR}/ouput.xml +fi #### Global variables: