diff options
author | 2015-06-09 13:45:28 +0000 | |
---|---|---|
committer | 2015-06-10 16:02:10 +0000 | |
commit | 43c483d9102cc577ed70873c890084b035fc0110 (patch) | |
tree | 627dd0597e34d29faf5bd9a6375da4dc7bacccf6 /src/test/shell | |
parent | c820c70bdd527ac1f065c2fe4320dc06bbe9eaf5 (diff) |
Bazel: Add an integration test for the persistent JavaBuilder as a Worker process.
--
MOS_MIGRATED_REVID=95531532
Diffstat (limited to 'src/test/shell')
-rw-r--r-- | src/test/shell/bazel/BUILD | 6 | ||||
-rwxr-xr-x | src/test/shell/bazel/bazel_worker_test.sh | 79 |
2 files changed, 85 insertions, 0 deletions
diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index 94ac78c2f7..9b976d9d8a 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -119,6 +119,12 @@ sh_test( tags = ["manual"], # Test is still flaky. ) +sh_test( + name = "bazel_worker_test", + srcs = ["bazel_worker_test.sh"], + data = [":test-deps"], +) + test_suite( name = "all_tests", visibility = ["//visibility:public"], diff --git a/src/test/shell/bazel/bazel_worker_test.sh b/src/test/shell/bazel/bazel_worker_test.sh new file mode 100755 index 0000000000..d2856c3e47 --- /dev/null +++ b/src/test/shell/bazel/bazel_worker_test.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# +# Copyright 2015 Google Inc. 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 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; } + +function write_hello_library_files() { + mkdir -p java/main + cat >java/main/BUILD <<EOF +java_binary(name = 'main', + deps = ['//java/hello_library'], + srcs = ['Main.java'], + main_class = 'main.Main') +EOF + + cat >java/main/Main.java <<EOF +package main; +import hello_library.HelloLibrary; +public class Main { + public static void main(String[] args) { + HelloLibrary.funcHelloLibrary(); + System.out.println("Hello, World!"); + } +} +EOF + + mkdir -p java/hello_library + cat >java/hello_library/BUILD <<EOF +package(default_visibility=['//visibility:public']) +java_library(name = 'hello_library', + srcs = ['HelloLibrary.java']); +EOF + + cat >java/hello_library/HelloLibrary.java <<EOF +package hello_library; +public class HelloLibrary { + public static void funcHelloLibrary() { + System.out.print("Hello, Library!;"); + } +} +EOF +} + +function test_compiles_hello_library_using_persistent_javac() { + write_hello_library_files + bazel --batch clean + bazel build --experimental_persistent_javac //java/main:main || fail "build failed" + bazel-bin/java/main/main | grep -q "Hello, Library!;Hello, World!" \ + || fail "comparison failed" + bazel_pid=$(bazel info | fgrep server_pid | cut -d' ' -f2) + # DANGER. This contains arcane shell wizardry that was carefully crafted to be compatible with + # both BSD and GNU tools so that this works under Linux and OS X. + bazel_children=$(ps ax -o ppid,pid | awk '{$1=$1};1' | egrep "^${bazel_pid} " | cut -d' ' -f2) + bazel shutdown || fail "shutdown failed" + sleep 3 + unkilled_children=$(for pid in $bazel_children; do ps -p $pid | sed 1d; done) + if [ ! -z "$unkilled_children" ]; then + fail "Worker processes were still running: ${unkilled_children}" + fi +} + +run_suite "Worker integration tests" |