Skip to content

Commit

Permalink
Scafolding for cuttlefish e2e testing with bazel
Browse files Browse the repository at this point in the history
includes testing aosp-main phone x86_64
  • Loading branch information
jemoreira committed Mar 7, 2024
1 parent 55f14ec commit eea8c05
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
8 changes: 8 additions & 0 deletions e2etests/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("boot_tests.bzl", "launch_cvd_boot_test")

launch_cvd_boot_test(
name="aosp_main_x64_phone",
branch="aosp-main",
target="aosp_cf_x86_64_phone-trunk_staging-userdebug"
)

6 changes: 6 additions & 0 deletions e2etests/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################
13 changes: 13 additions & 0 deletions e2etests/boot_tests.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def launch_cvd_boot_test(name, branch, target):
native.sh_test(
name = name,
size = "medium",
srcs = ["launch_cvd_boot_test.sh"],
args = ["-b", branch, "-t", target],
tags = [
"exclusive",
"external",
"no-sandbox",
],
)

60 changes: 60 additions & 0 deletions e2etests/launch_cvd_boot_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

set -e -x

BRANCH=""
TARGET=""

while getopts "b:t:" opt; do
case "${opt}" in
b)
BRANCH="${OPTARG}"
;;
t)
TARGET="${OPTARG}"
;;
*)
echo "Unknown flag: -${opt}" >&2
echo "Usage: $0 -b BRANCH -t TARGET"
exit 1
esac
done

if [[ "${BRANCH}" == "" ]]; then
echo "Missing required -b argument"
fi

if [[ "${TARGET}" == "" ]]; then
echo "Missing required -t argument"
fi

workdir="$(mktemp -d -t cvd_boot_test.XXXXXX)"

function collect_logs_and_cleanup() {
# Don't immediately exit on failure anymore
set +e
if [[ -n "${TEST_UNDECLARED_OUTPUTS_DIR}" ]] && [[ -d "${TEST_UNDECLARED_OUTPUTS_DIR}" ]]; then
cp "${workdir}"/*.log "${TEST_UNDECLARED_OUTPUTS_DIR}"
cp "${workdir}"/cuttlefish_runtime/*.log "${TEST_UNDECLARED_OUTPUTS_DIR}"
cp "${workdir}"/cuttlefish_runtime/logcat "${TEST_UNDECLARED_OUTPUTS_DIR}"
cp "${workdir}"/cuttlefish_runtime/cuttlefish_config.json "${TEST_UNDECLARED_OUTPUTS_DIR}"
fi
rm -rf "${workdir}"
# Be nice, dont' leave a server or devices behind.
cvd reset -y
}

# Regardless of whether and when a failure occurs logs must collected
trap collect_logs_and_cleanup EXIT

# Make sure the server isn't running. Bazel tries to sandbox tests, but the cvd
# client can still connect to the server outside the sandbox and cause issues.
cvd reset -y

cvd fetch --default_build="${BRANCH}/${TARGET}" --target_directory="${workdir}"

(
cd "${workdir}"
HOME=$(pwd) bin/launch_cvd --daemon --report_anonymous_usage_stats=y
HOME=$(pwd) bin/stop_cvd
)

0 comments on commit eea8c05

Please sign in to comment.