From eea8c05ec4d6597a08be31eab82d64f2d6bdbe98 Mon Sep 17 00:00:00 2001 From: "Jorge E. Moreira" Date: Thu, 29 Feb 2024 15:07:24 -0800 Subject: [PATCH] Scafolding for cuttlefish e2e testing with bazel includes testing aosp-main phone x86_64 --- e2etests/BUILD | 8 +++++ e2etests/MODULE.bazel | 6 ++++ e2etests/boot_tests.bzl | 13 +++++++ e2etests/launch_cvd_boot_test.sh | 60 ++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 e2etests/BUILD create mode 100644 e2etests/MODULE.bazel create mode 100644 e2etests/boot_tests.bzl create mode 100755 e2etests/launch_cvd_boot_test.sh diff --git a/e2etests/BUILD b/e2etests/BUILD new file mode 100644 index 0000000000..f46881674d --- /dev/null +++ b/e2etests/BUILD @@ -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" +) + diff --git a/e2etests/MODULE.bazel b/e2etests/MODULE.bazel new file mode 100644 index 0000000000..00bb18361f --- /dev/null +++ b/e2etests/MODULE.bazel @@ -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 +############################################################################### diff --git a/e2etests/boot_tests.bzl b/e2etests/boot_tests.bzl new file mode 100644 index 0000000000..24df173e29 --- /dev/null +++ b/e2etests/boot_tests.bzl @@ -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", + ], + ) + diff --git a/e2etests/launch_cvd_boot_test.sh b/e2etests/launch_cvd_boot_test.sh new file mode 100755 index 0000000000..beaf1589ad --- /dev/null +++ b/e2etests/launch_cvd_boot_test.sh @@ -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 +)