Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Aug 31, 2023
1 parent d34ee04 commit f38db1e
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,14 @@ sh_test(
deps = ["@bazel_tools//tools/bash/runfiles"],
)

sh_test(
name = "path_mapping_test",
srcs = ["path_mapping_test.sh"],
data = [":test-deps"],
tags = ["no_windows"],
deps = ["@bazel_tools//tools/bash/runfiles"],
)

sh_test(
name = "platforms_test",
srcs = ["platforms_test.sh"],
Expand Down
130 changes: 130 additions & 0 deletions src/test/shell/bazel/path_mapping_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash
#
# Copyright 2023 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.
#
# Tests remote execution and caching.

set -euo pipefail

# --- begin runfiles.bash initialization ---
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
if [[ -f "$0.runfiles_manifest" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
export RUNFILES_DIR="$0.runfiles"
fi
fi
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
else
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
exit 1
fi
# --- end runfiles.bash initialization ---

source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

function set_up() {
mkdir -p src/main/java/com/example
cat > src/main/java/com/example/BUILD <<'EOF'
java_binary(
name = "Main",
srcs = ["Main.java"],
deps = [":lib"],
)
java_library(
name = "lib",
srcs = ["Lib.java"],
)
EOF
cat > src/main/java/com/example/Main.java <<'EOF'
package com.example;
public class Main {
public static void main(String[] args) {
System.out.println(Lib.getGreeting());
}
}
EOF
cat > src/main/java/com/example/Lib.java <<'EOF'
package com.example;
public class Lib {
public static String getGreeting() {
return String.format("Hello, %s!", System.getenv("COMPILATION_MODE"));
}
}
EOF
}

function test_path_stripping_sandboxed() {
cache_dir=$(mktemp -d)

COMPILATION_MODE=fastbuild \
bazel run -c fastbuild \
--disk_cache=$cache_dir \
--experimental_output_paths=strip \
--strategy=Javac=sandboxed \
//src/main/java/com/example:Main &> $TEST_log || fail "run failed unexpectedly"
expect_log "Hello, fastbuild!"
expect_log '5 \(linux\|darwin\|processwrapper\)-sandbox'
expect_not_log "disk cache hit"

COMPILATION_MODE=opt \
bazel run -c opt \
--disk_cache=$cache_dir \
--experimental_output_paths=strip \
--strategy=Javac=sandboxed \
//src/main/java/com/example:Main &> $TEST_log || fail "run failed unexpectedly"
expect_log "Hello, opt!"
expect_log "5 disk cache hit"
expect_not_log '[0-9] \(linux\|darwin\|processwrapper\)-sandbox'
}

function test_path_stripping_singleplex_worker() {
cache_dir=$(mktemp -d)

COMPILATION_MODE=fastbuild \
bazel run -c fastbuild \
--disk_cache=$cache_dir \
--experimental_output_paths=strip \
--strategy=Javac=worker \
--worker_sandboxing \
--noexperimental_worker_multiplex \
//src/main/java/com/example:Main &> $TEST_log || fail "run failed unexpectedly"
expect_log "Hello, fastbuild!"
expect_log '3 \(linux\|darwin\|processwrapper\)-sandbox'
expect_log '2 worker'
expect_not_log "disk cache hit"

COMPILATION_MODE=opt \
bazel run -c opt \
--disk_cache=$cache_dir \
--experimental_output_paths=strip \
--strategy=Javac=worker \
--worker_sandboxing \
--noexperimental_worker_multiplex \
//src/main/java/com/example:Main &> $TEST_log || fail "run failed unexpectedly"
expect_log "Hello, opt!"
expect_log "5 disk cache hit"
expect_not_log '[0-9] \(linux\|darwin\|processwrapper\)-sandbox'
expect_not_log '[0-9] worker'
}

run_suite "path mapping tests"

0 comments on commit f38db1e

Please sign in to comment.