Skip to content

Commit

Permalink
Clean up test setup for sandboxing tests
Browse files Browse the repository at this point in the history
Sandboxing tests should always run with Bazel defaults, which include no tmpfs path.

Work towards bazelbuild#21215
  • Loading branch information
fmeum committed Apr 15, 2024
1 parent ac091a8 commit bf38edf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
18 changes: 3 additions & 15 deletions src/test/shell/bazel/bazel_sandboxing_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ source ${CURRENT_DIR}/../sandboxing_test_utils.sh \
function set_up {
add_to_bazelrc "build --spawn_strategy=sandboxed"
add_to_bazelrc "build --genrule_strategy=sandboxed"

# Enabled in testenv.sh.tmpl, but not in Bazel by default.
sed -i.bak '/sandbox_tmpfs_path/d' "$bazelrc"
}

function test_sandboxed_tooldir() {
Expand Down Expand Up @@ -314,8 +317,6 @@ function test_add_mount_pair_tmp_source() {

create_workspace_with_default_repos WORKSPACE

sed -i.bak '/sandbox_tmpfs_path/d' $TEST_TMPDIR/bazelrc

local mounted=$(mktemp -d "/tmp/bazel_mounted.XXXXXXXX")
trap "rm -fr $mounted" EXIT
echo GOOD > "$mounted/data.txt"
Expand Down Expand Up @@ -343,8 +344,6 @@ function test_add_mount_pair_tmp_target() {

create_workspace_with_default_repos WORKSPACE

sed -i.bak '/sandbox_tmpfs_path/d' $TEST_TMPDIR/bazelrc

local source_dir=$(mktemp -d "/tmp/bazel_mounted.XXXXXXXX")
trap "rm -fr $source_dir" EXIT
echo BAD > "$source_dir/data.txt"
Expand Down Expand Up @@ -373,8 +372,6 @@ function test_add_mount_pair_tmp_target_and_source() {

create_workspace_with_default_repos WORKSPACE

sed -i.bak '/sandbox_tmpfs_path/d' $TEST_TMPDIR/bazelrc

local mounted=$(mktemp -d "/tmp/bazel_mounted.XXXXXXXX")
trap "rm -fr $mounted" EXIT
echo GOOD > "$mounted/data.txt"
Expand Down Expand Up @@ -405,8 +402,6 @@ function test_symlink_with_output_base_under_tmp() {

create_workspace_with_default_repos WORKSPACE

sed -i.bak '/sandbox_tmpfs_path/d' $TEST_TMPDIR/bazelrc

mkdir -p pkg
cat > pkg/BUILD <<'EOF'
load(":r.bzl", "symlink_rule")
Expand Down Expand Up @@ -443,9 +438,6 @@ function test_symlink_to_directory_absolute_path() {

create_workspace_with_default_repos WORKSPACE

sed -i.bak '/sandbox_tmpfs_path/d' $TEST_TMPDIR/bazelrc


mkdir -p /tmp/tree/{a,b}
touch /tmp/tree/{a,b}/file

Expand Down Expand Up @@ -493,8 +485,6 @@ function test_symlink_to_directory_with_output_base_under_tmp() {

create_workspace_with_default_repos WORKSPACE

sed -i.bak '/sandbox_tmpfs_path/d' $TEST_TMPDIR/bazelrc

mkdir -p pkg
cat > pkg/BUILD <<'EOF'
load(":r.bzl", "symlink_rule", "tree_rule")
Expand Down Expand Up @@ -544,8 +534,6 @@ function test_tmpfs_path_under_tmp() {

create_workspace_with_default_repos WORKSPACE

sed -i.bak '/sandbox_tmpfs_path/d' $TEST_TMPDIR/bazelrc

local tmp_file=$(mktemp "/tmp/bazel_tmp.XXXXXXXX")
trap "rm $tmp_file" EXIT
echo BAD > "$tmp_file"
Expand Down
7 changes: 3 additions & 4 deletions src/test/shell/integration/sandboxing_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ disable_bzlmod
function set_up() {
add_to_bazelrc "build --spawn_strategy=sandboxed"
add_to_bazelrc "build --genrule_strategy=sandboxed"

# Enabled in testenv.sh.tmpl, but not in Bazel by default.
sed -i.bak '/sandbox_tmpfs_path/d' "$bazelrc"
}

function tear_down() {
Expand Down Expand Up @@ -693,7 +696,6 @@ EOF
}

function test_read_non_hermetic_tmp {
sed -i.bak '/sandbox_tmpfs_path/d' "$bazelrc"
temp_dir=$(mktemp -d /tmp/test.XXXXXX)
trap 'rm -rf ${temp_dir}' EXIT

Expand Down Expand Up @@ -748,7 +750,6 @@ function test_read_hermetic_tmp_user_override {
echo "Skipping test: --incompatible_sandbox_hermetic_tmp is only supported in Linux" 1>&2
return 0
fi
sed -i.bak '/sandbox_tmpfs_path/d' "$bazelrc"

temp_dir=$(mktemp -d /tmp/test.XXXXXX)
trap 'rm -rf ${temp_dir}' EXIT
Expand All @@ -772,7 +773,6 @@ EOF
}

function test_write_non_hermetic_tmp {
sed -i.bak '/sandbox_tmpfs_path/d' "$bazelrc"
temp_dir=$(mktemp -d /tmp/test.XXXXXX)
trap 'rm -rf ${temp_dir}' EXIT

Expand Down Expand Up @@ -828,7 +828,6 @@ function test_write_hermetic_tmp_user_override {
echo "Skipping test: --incompatible_sandbox_hermetic_tmp is only supported in Linux" 1>&2
return 0
fi
sed -i.bak '/sandbox_tmpfs_path/d' "$bazelrc"

temp_dir=$(mktemp -d /tmp/test.XXXXXX)
trap 'rm -rf ${temp_dir}' EXIT
Expand Down

0 comments on commit bf38edf

Please sign in to comment.