Organize Soong's integration tests:

- Move them into a new directory
- Split tests by theme and add a library file
- Add a shell script that runs them all

Test: Manually ran build/soong/run_integration_tests.sh .
Change-Id: I758b91d679f41aee47d15472cc02547ce89f6386
This commit is contained in:
Lukacs T. Berki 2021-04-08 13:21:13 +02:00
parent f247ff73ae
commit 3b730c4bc8
4 changed files with 114 additions and 95 deletions

View File

@ -3,106 +3,13 @@
# This test exercises the bootstrapping process of the build system
# in a source tree that only contains enough files for Bazel and Soong to work.
HARDWIRED_MOCK_TOP=
# Uncomment this to be able to view the source tree after a test is run
# HARDWIRED_MOCK_TOP=/tmp/td
REAL_TOP="$(readlink -f "$(dirname "$0")"/../..)"
function fail {
echo ERROR: $1
exit 1
}
function copy_directory() {
local dir="$1"
local parent="$(dirname "$dir")"
mkdir -p "$MOCK_TOP/$parent"
cp -R "$REAL_TOP/$dir" "$MOCK_TOP/$parent"
}
function symlink_file() {
local file="$1"
mkdir -p "$MOCK_TOP/$(dirname "$file")"
ln -s "$REAL_TOP/$file" "$MOCK_TOP/$file"
}
function symlink_directory() {
local dir="$1"
mkdir -p "$MOCK_TOP/$dir"
# We need to symlink the contents of the directory individually instead of
# using one symlink for the whole directory because finder.go doesn't follow
# symlinks when looking for Android.bp files
for i in $(ls "$REAL_TOP/$dir"); do
local target="$MOCK_TOP/$dir/$i"
local source="$REAL_TOP/$dir/$i"
if [[ -e "$target" ]]; then
if [[ ! -d "$source" || ! -d "$target" ]]; then
fail "Trying to symlink $dir twice"
fi
else
ln -s "$REAL_TOP/$dir/$i" "$MOCK_TOP/$dir/$i";
fi
done
}
function setup_bazel() {
copy_directory build/bazel
symlink_directory prebuilts/bazel
symlink_directory prebuilts/jdk
symlink_file WORKSPACE
symlink_file tools/bazel
}
function setup() {
if [[ ! -z "$HARDWIRED_MOCK_TOP" ]]; then
MOCK_TOP="$HARDWIRED_MOCK_TOP"
rm -fr "$MOCK_TOP"
mkdir -p "$MOCK_TOP"
else
MOCK_TOP=$(mktemp -t -d st.XXXXX)
trap 'echo cd / && echo rm -fr "$MOCK_TOP"' EXIT
fi
echo "Test case: ${FUNCNAME[1]}, mock top path: $MOCK_TOP"
cd "$MOCK_TOP"
copy_directory build/blueprint
copy_directory build/soong
symlink_directory prebuilts/go
symlink_directory prebuilts/build-tools
symlink_directory external/golang-protobuf
touch "$MOCK_TOP/Android.bp"
export ALLOW_MISSING_DEPENDENCIES=true
mkdir -p out/soong
}
function run_soong() {
build/soong/soong_ui.bash --make-mode --skip-ninja --skip-make --skip-soong-tests
}
source "$(dirname "$0")/lib.sh"
function test_smoke {
setup
run_soong
}
function test_bazel_smoke {
setup
setup_bazel
tools/bazel info
}
function test_null_build() {
setup
run_soong
@ -410,7 +317,6 @@ function test_dump_json_module_graph() {
fi
}
test_bazel_smoke
test_smoke
test_null_build
test_null_build_after_docs

79
tests/lib.sh Normal file
View File

@ -0,0 +1,79 @@
#!/bin/bash -eu
HARDWIRED_MOCK_TOP=
# Uncomment this to be able to view the source tree after a test is run
# HARDWIRED_MOCK_TOP=/tmp/td
REAL_TOP="$(readlink -f "$(dirname "$0")"/../../..)"
function fail {
echo ERROR: $1
exit 1
}
function copy_directory() {
local dir="$1"
local parent="$(dirname "$dir")"
mkdir -p "$MOCK_TOP/$parent"
cp -R "$REAL_TOP/$dir" "$MOCK_TOP/$parent"
}
function symlink_file() {
local file="$1"
mkdir -p "$MOCK_TOP/$(dirname "$file")"
ln -s "$REAL_TOP/$file" "$MOCK_TOP/$file"
}
function symlink_directory() {
local dir="$1"
mkdir -p "$MOCK_TOP/$dir"
# We need to symlink the contents of the directory individually instead of
# using one symlink for the whole directory because finder.go doesn't follow
# symlinks when looking for Android.bp files
for i in $(ls "$REAL_TOP/$dir"); do
local target="$MOCK_TOP/$dir/$i"
local source="$REAL_TOP/$dir/$i"
if [[ -e "$target" ]]; then
if [[ ! -d "$source" || ! -d "$target" ]]; then
fail "Trying to symlink $dir twice"
fi
else
ln -s "$REAL_TOP/$dir/$i" "$MOCK_TOP/$dir/$i";
fi
done
}
function setup() {
if [[ ! -z "$HARDWIRED_MOCK_TOP" ]]; then
MOCK_TOP="$HARDWIRED_MOCK_TOP"
rm -fr "$MOCK_TOP"
mkdir -p "$MOCK_TOP"
else
MOCK_TOP=$(mktemp -t -d st.XXXXX)
trap 'echo cd / && echo rm -fr "$MOCK_TOP"' EXIT
fi
echo "Test case: ${FUNCNAME[1]}, mock top path: $MOCK_TOP"
cd "$MOCK_TOP"
copy_directory build/blueprint
copy_directory build/soong
symlink_directory prebuilts/go
symlink_directory prebuilts/build-tools
symlink_directory external/golang-protobuf
touch "$MOCK_TOP/Android.bp"
export ALLOW_MISSING_DEPENDENCIES=true
mkdir -p out/soong
}
function run_soong() {
build/soong/soong_ui.bash --make-mode --skip-ninja --skip-make --skip-soong-tests
}

28
tests/mixed_mode_test.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/bash -eu
# This test exercises mixed builds where Soong and Bazel cooperate in building
# Android.
#
# When the execroot is deleted, the Bazel server process will automatically
# terminate itself.
source "$(dirname "$0")/lib.sh"
function setup_bazel() {
copy_directory build/bazel
symlink_directory prebuilts/bazel
symlink_directory prebuilts/jdk
symlink_file WORKSPACE
symlink_file tools/bazel
}
function test_bazel_smoke {
setup
setup_bazel
tools/bazel info
}
test_bazel_smoke

6
tests/run_integration_tests.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
TOP="$(readlink -f "$(dirname "$0")"/../../..)"
"$TOP/build/soong/tests/bootstrap_test.sh"
"$TOP/build/soong/tests/mixed_mode_test.sh"