-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
218 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/bash | ||
|
||
set -e -x | ||
|
||
function install_debuild_dependencies() { | ||
echo "Installing debuild dependencies" | ||
sudo apt-get update | ||
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \ | ||
-o Dpkg::Options::="--force-confold" \ | ||
-o Dpkg::Options::="--force-confdef" \ | ||
upgrade | ||
sudo apt-get install -y devscripts config-package-dev debhelper-compat equivs bazel | ||
} | ||
|
||
function install_bazel() { | ||
# From https://bazel.build/install/ubuntu | ||
echo "Installing bazel" | ||
sudo apt install apt-transport-https curl gnupg -y | ||
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg | ||
sudo mv bazel-archive-keyring.gpg /usr/share/keyrings | ||
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list | ||
sudo apt-get update && sudo apt install bazel | ||
} | ||
|
||
function build_and_install_pkgs() { | ||
local pkgdir="$1" | ||
shift | ||
pushd "${pkgdir}" | ||
echo "Installing dependencies for: $@" | ||
sudo mk-build-deps -i -t 'apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y' | ||
echo "Building packages: $@" | ||
debuild -i -uc -us -b | ||
for pkg in "$@"; do | ||
echo "Installing package: ${pkg}" | ||
sudo apt-get install -y ../"${pkg}"_*_*64.deb | ||
done | ||
popd | ||
} | ||
|
||
function check_service_started() { | ||
local service="$1" | ||
echo "Checking service ${service} status" | ||
systemctl is-active "${service}" | ||
} | ||
|
||
function load_kernel_modules() { | ||
echo "Loading kernel modules" | ||
sudo modprobe "$@" | ||
} | ||
|
||
function create_test_user() { | ||
local username=$1 | ||
local groups="kvm,cvdnetwork" | ||
if [[ "$2" != "" ]]; then | ||
groups="${groups},$2" | ||
fi | ||
echo "Creating user: ${username}" | ||
sudo useradd -G "${groups}" -m "${username}" | ||
sudo chmod a+rx "/home/${username}" | ||
} | ||
|
||
|
||
REPO_DIR="$(realpath "$(dirname "$0")/..")" | ||
TEST_USER="" | ||
EXTRA_GROUPS="" | ||
while getopts "d:u:g:" opt; do | ||
case "${opt}" in | ||
u) | ||
TEST_USER="${OPTARG}" | ||
;; | ||
g) | ||
EXTRA_GROUPS="${OPTARG}" | ||
;; | ||
*) | ||
echo "Invalid option: -${opt}" | ||
echo "Usage: $0 [-u TEST_USER [-g EXTRA_GROUPS]]" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
if [[ "${REPO_DIR}" == "" ]] || ! [[ -f "${REPO_DIR}" ]]; then | ||
echo "Invalid repo directory: ${REPO_DIR}" | ||
exit 1 | ||
fi | ||
|
||
build_and_install_pkgs "${REPO_DIR}/base" cuttlefish-base | ||
check_service_started cuttlefish-host-resources | ||
load_kernel_modules kvm vhost-vsock vhost-net | ||
|
||
build_and_install_pkgs "${REPO_DIR}/frontend" cuttlefish-user | ||
check_service_started cuttlefish-operator | ||
|
||
if [[ "${TEST_SER}" != "" ]]; then | ||
create_test_user "${TEST_USER}" "${EXTRA_GROUPS}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
TOOL_DIR="$(realpath "$(dirname "$0")")" | ||
|
||
# Add test user to the kokoro group so it has access to the source dir | ||
"${TOOL_DIR}/setup_host.sh" -u testrunner -g kokoro | ||
|
||
sudo -u testrunner "${TOOL_DIR}/runtests.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,66 @@ | ||
#!/bin/bash | ||
|
||
# Fail on errors | ||
set -e | ||
set -e -x | ||
|
||
echo "Cuttlefish debian package build and testing placeholder script for kokoro" | ||
function test_results() { | ||
echo "Cuttlefish debian package build and testing placeholder script for kokoro" | ||
|
||
echo "current directory:" | ||
pwd | ||
echo "current directory:" | ||
pwd | ||
echo "Current directory stats" | ||
stat . | ||
|
||
echo "contents of github/android-cuttlefish" | ||
ls github/android-cuttlefish | ||
echo "contents of github/android-cuttlefish" | ||
ls -l github/android-cuttlefish | ||
|
||
echo "producing placeholder xUnit test results" | ||
mkdir -p test_results | ||
cp github/android-cuttlefish/.kokoro/demo_result.xml test_results/sponge_log.xml | ||
echo "placeholder log" > test_results/sponge_log.log | ||
echo "producing placeholder xUnit test results" | ||
cp github/android-cuttlefish/.kokoro/demo_result.xml "$1" | ||
|
||
echo "done" | ||
echo "Current user: $(whoami)" | ||
echo "Current groups: $(groups)" | ||
|
||
echo "done" | ||
sudo echo "running as root?" | ||
sudo whoami | ||
} | ||
|
||
function run_test() { | ||
test_name="$1" | ||
shift | ||
# Run the test function with: | ||
# The xml output file as first parameter | ||
# The other arguments passed to this function | ||
# stderr and stdout redirected to the log file | ||
mkdir -p "${test_name}" | ||
"${test_name}" \ | ||
"${test_name}/sponge_log.xml" \ | ||
"$@" \ | ||
1>&2 2>"${test_name}/sponge_log.log" | ||
} | ||
|
||
run_test test_results | ||
|
||
cat >test_results/sponge_log.xml <<EOF | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites tests="1" failures="0" disabled="0" errors="0" time="0" timestamp="2024-02-23T23:56:49.153" name="AllTests"> | ||
<testsuite name="HelloTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="0" timestamp="2024-02-23T23:56:49.153"> | ||
<testcase name="BasicAssertions" file="hello_test.cc" line="4" status="run" result="completed" time="0" timestamp="2024-02-23T23:56:49.153" classname="HelloTest" /> | ||
</testsuite> | ||
</testsuites> | ||
EOF | ||
|
||
github/android-cuttlefish/.kokoro/setup_host.sh github/android-cuttlefish | ||
|
||
pushd github/android-cuttlefish/e2etests | ||
# Don't exit the script, even if the tests fail | ||
sudo -u testrunner bazel test ... || true | ||
popd | ||
|
||
|
||
for d in github/android-cuttlefish/e2etests/bazel-testlogs/*; do | ||
dir="$(basename "$d")" | ||
mkdir -p $dir | ||
cp $d/test.log $dir/sponge_log.log | ||
cp $d/test.xml $dir/sponge_log.xml | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
set -x -e | ||
|
||
REPO_DIR="$(realpath "$(dirname "$0")/..")" | ||
OUTPUT_DIR="$(pwd)" | ||
|
||
function gather_test_results() { | ||
for d in ./bazel-testlogs/*; do | ||
dir="${OUTPUT_DIR}/$(basename "$d")" | ||
mkdir -p "${dir}" | ||
cp "${d}/test.log" "${dir}/sponge_log.log" | ||
cp "${d}/test.xml" "${dir}/sponge_log.xml" | ||
# Make sure everyone has access to the output files | ||
chmod a+rw "${dir}"/sponge_log.* | ||
done | ||
} | ||
|
||
trap gather_test_results EXIT | ||
|
||
cd "${REPO_DIR}/e2etests" | ||
# Don't exit on error: need to gather errors into output directory | ||
bazel test ... || true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# TODO add a bazel macro to reduce duplication | ||
sh_test( | ||
name = "first_test", | ||
size = "medium", | ||
srcs = ["cvd_boot_test.sh"], | ||
args = ["-baosp-main", "-taosp_cf_x86_phone-trunk_staging-userdebug"], | ||
) | ||
|
||
sh_test( | ||
name = "second_test", | ||
size = "medium", | ||
srcs = ["cvd_boot_test.sh"], | ||
args = ["-baosp-main"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
############################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
set -e -x | ||
|
||
echo >&2 "$@" | ||
|
||
if [[ "$#" -lt 2 ]]; then | ||
echo >&2 "Not enough args" | ||
exit 1 | ||
fi |