2023-12-15 20:33:46 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-01-29 11:48:46 +00:00
|
|
|
|
|
|
|
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
|
# Copyright © 2020 Intel Corporation
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
CLI_NAME="Cloud Hypervisor"
|
|
|
|
|
2023-03-15 17:27:51 +00:00
|
|
|
CTR_IMAGE_TAG="ghcr.io/cloud-hypervisor/cloud-hypervisor"
|
2023-10-23 12:54:13 +00:00
|
|
|
CTR_IMAGE_VERSION="20231220-0"
|
2023-08-03 14:38:53 +00:00
|
|
|
: "${CTR_IMAGE:=${CTR_IMAGE_TAG}:${CTR_IMAGE_VERSION}}"
|
2020-01-29 11:48:46 +00:00
|
|
|
|
|
|
|
DOCKER_RUNTIME="docker"
|
|
|
|
|
|
|
|
# Host paths
|
|
|
|
CLH_SCRIPTS_DIR=$(cd "$(dirname "$0")" && pwd)
|
|
|
|
CLH_ROOT_DIR=$(cd "${CLH_SCRIPTS_DIR}/.." && pwd)
|
|
|
|
CLH_BUILD_DIR="${CLH_ROOT_DIR}/build"
|
|
|
|
CLH_CARGO_TARGET="${CLH_BUILD_DIR}/cargo_target"
|
|
|
|
CLH_DOCKERFILE="${CLH_SCRIPTS_DIR}/../resources/Dockerfile"
|
|
|
|
CLH_CTR_BUILD_DIR="/tmp/cloud-hypervisor/ctr-build"
|
|
|
|
CLH_INTEGRATION_WORKLOADS="${HOME}/workloads"
|
|
|
|
|
|
|
|
# Container paths
|
|
|
|
CTR_CLH_ROOT_DIR="/cloud-hypervisor"
|
2020-02-07 20:25:10 +00:00
|
|
|
CTR_CLH_CARGO_BUILT_DIR="${CTR_CLH_ROOT_DIR}/build"
|
|
|
|
CTR_CLH_CARGO_TARGET="${CTR_CLH_CARGO_BUILT_DIR}/cargo_target"
|
2020-01-29 11:48:46 +00:00
|
|
|
CTR_CLH_INTEGRATION_WORKLOADS="/root/workloads"
|
|
|
|
|
2020-07-29 00:10:13 +00:00
|
|
|
# Container networking option
|
2021-01-11 10:36:42 +00:00
|
|
|
CTR_CLH_NET="bridge"
|
2020-07-29 00:10:13 +00:00
|
|
|
|
2020-01-29 11:48:46 +00:00
|
|
|
# Cargo paths
|
|
|
|
# Full path to the cargo registry dir on the host. This appears on the host
|
|
|
|
# because we want to persist the cargo registry across container invocations.
|
|
|
|
# Otherwise, any rust crates from crates.io would be downloaded again each time
|
|
|
|
# we build or test.
|
|
|
|
CARGO_REGISTRY_DIR="${CLH_BUILD_DIR}/cargo_registry"
|
|
|
|
|
|
|
|
# Full path to the cargo git registry on the host. This serves the same purpose
|
|
|
|
# as CARGO_REGISTRY_DIR, for crates downloaded from GitHub repos instead of
|
|
|
|
# crates.io.
|
|
|
|
CARGO_GIT_REGISTRY_DIR="${CLH_BUILD_DIR}/cargo_git_registry"
|
|
|
|
|
|
|
|
# Full path to the cargo target dir on the host.
|
|
|
|
CARGO_TARGET_DIR="${CLH_BUILD_DIR}/cargo_target"
|
|
|
|
|
|
|
|
# Send a decorated message to stdout, followed by a new line
|
|
|
|
#
|
|
|
|
say() {
|
2022-02-21 11:04:19 +00:00
|
|
|
[ -t 1 ] && [ -n "$TERM" ] &&
|
|
|
|
echo "$(tput setaf 2)[$CLI_NAME]$(tput sgr0) $*" ||
|
|
|
|
echo "[$CLI_NAME] $*"
|
2020-01-29 11:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Send a decorated message to stdout, without a trailing new line
|
|
|
|
#
|
|
|
|
say_noln() {
|
2022-02-21 11:04:19 +00:00
|
|
|
[ -t 1 ] && [ -n "$TERM" ] &&
|
|
|
|
echo -n "$(tput setaf 2)[$CLI_NAME]$(tput sgr0) $*" ||
|
|
|
|
echo "[$CLI_NAME] $*"
|
2020-01-29 11:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Send a text message to stderr
|
|
|
|
#
|
|
|
|
say_err() {
|
2022-02-21 11:04:19 +00:00
|
|
|
[ -t 2 ] && [ -n "$TERM" ] &&
|
|
|
|
echo "$(tput setaf 1)[$CLI_NAME] $*$(tput sgr0)" 1>&2 ||
|
|
|
|
echo "[$CLI_NAME] $*" 1>&2
|
2020-01-29 11:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Send a warning-highlighted text to stdout
|
|
|
|
say_warn() {
|
2022-02-21 11:04:19 +00:00
|
|
|
[ -t 1 ] && [ -n "$TERM" ] &&
|
|
|
|
echo "$(tput setaf 3)[$CLI_NAME] $*$(tput sgr0)" ||
|
|
|
|
echo "[$CLI_NAME] $*"
|
2020-01-29 11:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Exit with an error message and (optional) code
|
|
|
|
# Usage: die [-c <error code>] <error message>
|
|
|
|
#
|
|
|
|
die() {
|
|
|
|
code=1
|
|
|
|
[[ "$1" = "-c" ]] && {
|
|
|
|
code="$2"
|
|
|
|
shift 2
|
|
|
|
}
|
|
|
|
say_err "$@"
|
2022-02-21 11:02:53 +00:00
|
|
|
exit "$code"
|
2020-01-29 11:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Exit with an error message if the last exit code is not 0
|
|
|
|
#
|
|
|
|
ok_or_die() {
|
|
|
|
code=$?
|
|
|
|
[[ $code -eq 0 ]] || die -c $code "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make sure the build/ dirs are available. Exit if we can't create them.
|
|
|
|
# Upon returning from this call, the caller can be certain the build/ dirs exist.
|
|
|
|
#
|
|
|
|
ensure_build_dir() {
|
|
|
|
for dir in "$CLH_BUILD_DIR" \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CLH_INTEGRATION_WORKLOADS" \
|
|
|
|
"$CLH_CTR_BUILD_DIR" \
|
|
|
|
"$CARGO_TARGET_DIR" \
|
|
|
|
"$CARGO_REGISTRY_DIR" \
|
|
|
|
"$CARGO_GIT_REGISTRY_DIR"; do
|
2020-01-29 11:48:46 +00:00
|
|
|
mkdir -p "$dir" || die "Error: cannot create dir $dir"
|
2022-02-21 11:04:19 +00:00
|
|
|
[ -x "$dir" ] && [ -w "$dir" ] ||
|
2020-01-29 11:48:46 +00:00
|
|
|
{
|
|
|
|
say "Wrong permissions for $dir. Attempting to fix them ..."
|
|
|
|
chmod +x+w "$dir"
|
2022-02-21 11:04:19 +00:00
|
|
|
} ||
|
2020-01-29 11:48:46 +00:00
|
|
|
die "Error: wrong permissions for $dir. Should be +x+w"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-03-23 18:13:49 +00:00
|
|
|
# Make sure we're using the latest dev container, by just pulling it.
|
|
|
|
ensure_latest_ctr() {
|
2022-02-21 11:29:18 +00:00
|
|
|
if [ "$CTR_IMAGE_VERSION" = "local" ]; then
|
|
|
|
build_container
|
|
|
|
else
|
2024-01-29 15:38:44 +00:00
|
|
|
if ! $DOCKER_RUNTIME pull "$CTR_IMAGE"; then
|
2022-02-21 11:29:18 +00:00
|
|
|
build_container
|
|
|
|
fi
|
|
|
|
|
|
|
|
ok_or_die "Error pulling/building container image. Aborting."
|
|
|
|
fi
|
2020-03-23 18:13:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 15:40:10 +00:00
|
|
|
# Fix main directory permissions after a container ran as root.
|
2020-02-07 20:25:10 +00:00
|
|
|
# Since the container ran as root, any files it creates will be owned by root.
|
2020-02-13 15:40:10 +00:00
|
|
|
# This fixes that by recursively changing the ownership of /cloud-hypervisor to the
|
2020-02-07 20:25:10 +00:00
|
|
|
# current user.
|
|
|
|
#
|
2020-02-13 15:40:10 +00:00
|
|
|
fix_dir_perms() {
|
2020-02-07 20:25:10 +00:00
|
|
|
# Yes, running Docker to get elevated privileges, just to chown some files
|
|
|
|
# is a dirty hack.
|
|
|
|
$DOCKER_RUNTIME run \
|
2022-02-21 11:04:19 +00:00
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--volume /dev:/dev \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CTR_IMAGE" \
|
|
|
|
chown -R "$(id -u):$(id -g)" "$CTR_CLH_ROOT_DIR"
|
2020-02-07 20:25:10 +00:00
|
|
|
|
2022-02-21 11:02:53 +00:00
|
|
|
return "$1"
|
2020-02-07 20:25:10 +00:00
|
|
|
}
|
2020-10-23 19:09:44 +00:00
|
|
|
# Process exported volumes argument, separate the volumes and make docker compatible
|
|
|
|
# Sample input: --volumes /a:/a#/b:/b
|
|
|
|
# Sample output: --volume /a:/a --volume /b:/b
|
|
|
|
#
|
|
|
|
process_volumes_args() {
|
|
|
|
if [ -z "$arg_vols" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
exported_volumes=""
|
2024-01-29 15:38:44 +00:00
|
|
|
arr_vols=("${arg_vols//#/ }")
|
2022-02-21 11:04:19 +00:00
|
|
|
for var in "${arr_vols[@]}"; do
|
2024-01-29 15:38:44 +00:00
|
|
|
parts=("${var//:/ }")
|
2020-10-23 19:09:44 +00:00
|
|
|
if [[ ! -e "${parts[0]}" ]]; then
|
|
|
|
echo "The volume ${parts[0]} does not exist."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
exported_volumes="$exported_volumes --volume $var"
|
|
|
|
done
|
|
|
|
}
|
2023-02-16 15:45:45 +00:00
|
|
|
|
2020-01-29 11:48:46 +00:00
|
|
|
cmd_help() {
|
|
|
|
echo ""
|
2022-02-21 11:02:53 +00:00
|
|
|
echo "Cloud Hypervisor $(basename "$0")"
|
2023-03-28 10:49:29 +00:00
|
|
|
echo "Usage: $(basename "$0") [flags] <command> [<command args>]"
|
|
|
|
echo ""
|
|
|
|
echo "Available flags":
|
|
|
|
echo ""
|
|
|
|
echo " --local Set the container image version being used to \"local\"."
|
2020-01-29 11:48:46 +00:00
|
|
|
echo ""
|
|
|
|
echo "Available commands:"
|
|
|
|
echo ""
|
2020-04-28 11:26:01 +00:00
|
|
|
echo " build [--debug|--release] [--libc musl|gnu] [-- [<cargo args>]]"
|
2020-01-29 11:48:46 +00:00
|
|
|
echo " Build the Cloud Hypervisor binaries."
|
|
|
|
echo " --debug Build the debug binaries. This is the default."
|
|
|
|
echo " --release Build the release binaries."
|
2020-04-28 11:26:01 +00:00
|
|
|
echo " --libc Select the C library Cloud Hypervisor will be built against. Default is gnu"
|
2020-10-23 19:09:44 +00:00
|
|
|
echo " --volumes Hash separated volumes to be exported. Example --volumes /mnt:/mnt#/myvol:/myvol"
|
2020-11-18 00:37:27 +00:00
|
|
|
echo " --hypervisor Underlying hypervisor. Options kvm, mshv"
|
2020-01-29 11:48:46 +00:00
|
|
|
echo ""
|
2022-03-28 10:24:26 +00:00
|
|
|
echo " tests [<test type (see below)>] [--libc musl|gnu] [-- [<test scripts args>] [-- [<test binary args>]]] "
|
2020-01-29 11:48:46 +00:00
|
|
|
echo " Run the Cloud Hypervisor tests."
|
2021-08-27 22:30:28 +00:00
|
|
|
echo " --unit Run the unit tests."
|
|
|
|
echo " --integration Run the integration tests."
|
|
|
|
echo " --integration-sgx Run the SGX integration tests."
|
|
|
|
echo " --integration-vfio Run the VFIO integration tests."
|
|
|
|
echo " --integration-windows Run the Windows guest integration tests."
|
|
|
|
echo " --integration-live-migration Run the live-migration integration tests."
|
2022-08-30 01:22:47 +00:00
|
|
|
echo " --integration-rate-limiter Run the rate-limiter integration tests."
|
2021-08-27 22:30:28 +00:00
|
|
|
echo " --libc Select the C library Cloud Hypervisor will be built against. Default is gnu"
|
2022-02-05 00:14:40 +00:00
|
|
|
echo " --metrics Generate performance metrics"
|
2021-08-27 22:30:28 +00:00
|
|
|
echo " --volumes Hash separated volumes to be exported. Example --volumes /mnt:/mnt#/myvol:/myvol"
|
|
|
|
echo " --hypervisor Underlying hypervisor. Options kvm, mshv"
|
|
|
|
echo " --all Run all tests."
|
2020-01-29 11:48:46 +00:00
|
|
|
echo ""
|
|
|
|
echo " build-container [--type]"
|
|
|
|
echo " Build the Cloud Hypervisor container."
|
|
|
|
echo ""
|
2020-01-30 23:40:25 +00:00
|
|
|
echo " clean [<cargo args>]]"
|
|
|
|
echo " Remove the Cloud Hypervisor artifacts."
|
|
|
|
echo ""
|
2020-06-25 17:16:01 +00:00
|
|
|
echo " shell"
|
|
|
|
echo " Run the development container into an interactive, privileged BASH shell."
|
2021-07-14 18:29:02 +00:00
|
|
|
echo " --volumes Hash separated volumes to be exported. Example --volumes /mnt:/mnt#/myvol:/myvol"
|
2020-06-25 17:16:01 +00:00
|
|
|
echo ""
|
2020-01-29 11:48:46 +00:00
|
|
|
echo " help"
|
|
|
|
echo " Display this help message."
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_build() {
|
|
|
|
build="debug"
|
2020-04-28 11:26:01 +00:00
|
|
|
libc="gnu"
|
2020-11-18 00:37:27 +00:00
|
|
|
hypervisor="kvm"
|
2024-02-28 16:31:15 +00:00
|
|
|
features_build=()
|
2021-01-11 23:09:02 +00:00
|
|
|
exported_device="/dev/kvm"
|
2020-01-29 11:48:46 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
2022-02-21 11:04:19 +00:00
|
|
|
case "$1" in
|
|
|
|
"-h" | "--help") {
|
|
|
|
cmd_help
|
|
|
|
exit 1
|
|
|
|
} ;;
|
|
|
|
"--debug") { build="debug"; } ;;
|
|
|
|
"--release") { build="release"; } ;;
|
2022-08-30 01:22:47 +00:00
|
|
|
"--runtime")
|
2024-01-26 15:30:32 +00:00
|
|
|
shift
|
|
|
|
DOCKER_RUNTIME="$1"
|
|
|
|
export DOCKER_RUNTIME
|
|
|
|
;;
|
2022-02-21 11:04:19 +00:00
|
|
|
"--libc")
|
|
|
|
shift
|
|
|
|
[[ "$1" =~ ^(musl|gnu)$ ]] ||
|
|
|
|
die "Invalid libc: $1. Valid options are \"musl\" and \"gnu\"."
|
|
|
|
libc="$1"
|
|
|
|
;;
|
|
|
|
"--volumes")
|
|
|
|
shift
|
|
|
|
arg_vols="$1"
|
|
|
|
;;
|
|
|
|
"--hypervisor")
|
|
|
|
shift
|
|
|
|
hypervisor="$1"
|
|
|
|
;;
|
2022-02-25 11:40:44 +00:00
|
|
|
"--features")
|
|
|
|
shift
|
2024-02-28 16:31:15 +00:00
|
|
|
features_build=(--features "$1")
|
2022-02-25 11:40:44 +00:00
|
|
|
;;
|
2022-02-21 11:04:19 +00:00
|
|
|
"--") {
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
} ;;
|
|
|
|
*)
|
|
|
|
die "Unknown build argument: $1. Please use --help for help."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2020-01-29 11:48:46 +00:00
|
|
|
done
|
2021-01-26 11:15:24 +00:00
|
|
|
|
|
|
|
ensure_build_dir
|
2021-08-26 11:40:52 +00:00
|
|
|
ensure_latest_ctr
|
2021-01-26 11:15:24 +00:00
|
|
|
|
2020-10-23 19:09:44 +00:00
|
|
|
process_volumes_args
|
2022-02-21 11:04:19 +00:00
|
|
|
if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then
|
2021-09-23 21:50:26 +00:00
|
|
|
die "Hypervisor value must be kvm or mshv"
|
2020-11-18 00:37:27 +00:00
|
|
|
fi
|
2021-01-11 23:09:02 +00:00
|
|
|
if [[ "$hypervisor" = "mshv" ]]; then
|
|
|
|
exported_device="/dev/mshv"
|
|
|
|
fi
|
2020-04-28 11:26:01 +00:00
|
|
|
target="$(uname -m)-unknown-linux-${libc}"
|
|
|
|
|
2020-01-29 11:48:46 +00:00
|
|
|
cargo_args=("$@")
|
|
|
|
[ $build = "release" ] && cargo_args+=("--release")
|
2020-04-28 11:26:01 +00:00
|
|
|
cargo_args+=(--target "$target")
|
2020-04-16 02:02:42 +00:00
|
|
|
|
2024-01-29 15:38:44 +00:00
|
|
|
# shellcheck disable=SC2153
|
2023-10-19 21:17:47 +00:00
|
|
|
rustflags="$RUSTFLAGS"
|
2022-02-28 16:21:05 +00:00
|
|
|
target_cc=""
|
2022-02-21 11:04:19 +00:00
|
|
|
if [ "$(uname -m)" = "aarch64" ] && [ "$libc" = "musl" ]; then
|
2023-10-23 12:54:13 +00:00
|
|
|
rustflags="$rustflags -C link-args=-Wl,-Bstatic -C link-args=-lc"
|
2020-04-16 02:02:42 +00:00
|
|
|
fi
|
2020-01-29 11:48:46 +00:00
|
|
|
|
|
|
|
$DOCKER_RUNTIME run \
|
2022-02-21 11:04:19 +00:00
|
|
|
--user "$(id -u):$(id -g)" \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--volume $exported_device \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
--env RUSTFLAGS="$rustflags" \
|
2022-02-28 16:21:05 +00:00
|
|
|
--env TARGET_CC="$target_cc" \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CTR_IMAGE" \
|
2024-02-28 16:31:15 +00:00
|
|
|
cargo build --all "${features_build[@]}" \
|
2022-02-21 11:04:19 +00:00
|
|
|
--target-dir "$CTR_CLH_CARGO_TARGET" \
|
|
|
|
"${cargo_args[@]}" && say "Binaries placed under $CLH_CARGO_TARGET/$target/$build"
|
2020-01-29 11:48:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-30 23:40:25 +00:00
|
|
|
cmd_clean() {
|
|
|
|
cargo_args=("$@")
|
|
|
|
|
2021-01-26 11:15:24 +00:00
|
|
|
ensure_build_dir
|
2021-08-26 11:40:52 +00:00
|
|
|
ensure_latest_ctr
|
2021-01-26 11:15:24 +00:00
|
|
|
|
2020-01-30 23:40:25 +00:00
|
|
|
$DOCKER_RUNTIME run \
|
2022-02-21 11:04:19 +00:00
|
|
|
--user "$(id -u):$(id -g)" \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CTR_IMAGE" \
|
|
|
|
cargo clean \
|
|
|
|
--target-dir "$CTR_CLH_CARGO_TARGET" \
|
|
|
|
"${cargo_args[@]}"
|
|
|
|
}
|
2020-01-30 23:40:25 +00:00
|
|
|
|
2020-01-29 11:48:46 +00:00
|
|
|
cmd_tests() {
|
|
|
|
unit=false
|
|
|
|
integration=false
|
2020-09-08 12:20:26 +00:00
|
|
|
integration_sgx=false
|
2021-03-16 15:11:00 +00:00
|
|
|
integration_vfio=false
|
2020-10-07 14:34:18 +00:00
|
|
|
integration_windows=false
|
2021-08-27 22:30:28 +00:00
|
|
|
integration_live_migration=false
|
2022-08-30 01:22:47 +00:00
|
|
|
integration_rate_limiter=false
|
2022-02-05 00:14:40 +00:00
|
|
|
metrics=false
|
2020-04-28 11:26:01 +00:00
|
|
|
libc="gnu"
|
2020-10-23 19:09:44 +00:00
|
|
|
arg_vols=""
|
2020-11-18 00:37:27 +00:00
|
|
|
hypervisor="kvm"
|
2021-01-11 23:09:02 +00:00
|
|
|
exported_device="/dev/kvm"
|
2020-01-29 11:48:46 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
2022-02-21 11:04:19 +00:00
|
|
|
case "$1" in
|
|
|
|
"-h" | "--help") {
|
|
|
|
cmd_help
|
|
|
|
exit 1
|
|
|
|
} ;;
|
|
|
|
"--unit") { unit=true; } ;;
|
|
|
|
"--integration") { integration=true; } ;;
|
|
|
|
"--integration-sgx") { integration_sgx=true; } ;;
|
|
|
|
"--integration-vfio") { integration_vfio=true; } ;;
|
|
|
|
"--integration-windows") { integration_windows=true; } ;;
|
|
|
|
"--integration-live-migration") { integration_live_migration=true; } ;;
|
2022-08-30 01:22:47 +00:00
|
|
|
"--integration-rate-limiter") { integration_rate_limiter=true; } ;;
|
2022-02-21 11:04:19 +00:00
|
|
|
"--metrics") { metrics=true; } ;;
|
|
|
|
"--libc")
|
|
|
|
shift
|
|
|
|
[[ "$1" =~ ^(musl|gnu)$ ]] ||
|
|
|
|
die "Invalid libc: $1. Valid options are \"musl\" and \"gnu\"."
|
|
|
|
libc="$1"
|
|
|
|
;;
|
|
|
|
"--volumes")
|
|
|
|
shift
|
|
|
|
arg_vols="$1"
|
|
|
|
;;
|
|
|
|
"--hypervisor")
|
|
|
|
shift
|
|
|
|
hypervisor="$1"
|
|
|
|
;;
|
|
|
|
"--all") {
|
|
|
|
unit=true
|
|
|
|
integration=true
|
|
|
|
} ;;
|
|
|
|
"--") {
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
} ;;
|
|
|
|
*)
|
|
|
|
die "Unknown tests argument: $1. Please use --help for help."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2020-01-29 11:48:46 +00:00
|
|
|
done
|
2022-02-21 11:04:19 +00:00
|
|
|
if [[ ! ("$hypervisor" = "kvm" || "$hypervisor" = "mshv") ]]; then
|
2021-09-23 21:50:26 +00:00
|
|
|
die "Hypervisor value must be kvm or mshv"
|
2020-11-18 00:37:27 +00:00
|
|
|
fi
|
2021-09-23 21:50:26 +00:00
|
|
|
|
2021-01-11 23:09:02 +00:00
|
|
|
if [[ "$hypervisor" = "mshv" ]]; then
|
|
|
|
exported_device="/dev/mshv"
|
|
|
|
fi
|
2021-09-23 21:50:26 +00:00
|
|
|
|
2024-01-26 15:30:32 +00:00
|
|
|
if [ ! -e "${exported_device}" ]; then
|
2023-01-26 00:58:41 +00:00
|
|
|
die "${exported_device} does not exist on the system"
|
|
|
|
fi
|
|
|
|
|
2022-02-22 17:05:32 +00:00
|
|
|
set -- '--hypervisor' "$hypervisor" "$@"
|
2020-12-02 20:46:02 +00:00
|
|
|
|
2021-01-26 11:15:24 +00:00
|
|
|
ensure_build_dir
|
2021-08-26 11:40:52 +00:00
|
|
|
ensure_latest_ctr
|
2021-01-26 11:15:24 +00:00
|
|
|
|
2020-10-23 19:09:44 +00:00
|
|
|
process_volumes_args
|
2020-04-28 11:26:01 +00:00
|
|
|
target="$(uname -m)-unknown-linux-${libc}"
|
|
|
|
|
2023-10-19 22:08:39 +00:00
|
|
|
rustflags="$RUSTFLAGS"
|
|
|
|
target_cc=""
|
|
|
|
if [ "$(uname -m)" = "aarch64" ] && [ "$libc" = "musl" ]; then
|
2023-10-23 12:54:13 +00:00
|
|
|
rustflags="$rustflags -C link-args=-Wl,-Bstatic -C link-args=-lc"
|
2023-10-19 22:08:39 +00:00
|
|
|
fi
|
|
|
|
|
2022-02-21 11:04:19 +00:00
|
|
|
if [[ "$unit" = true ]]; then
|
|
|
|
say "Running unit tests for $target..."
|
|
|
|
$DOCKER_RUNTIME run \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--device $exported_device \
|
|
|
|
--device /dev/net/tun \
|
|
|
|
--cap-add net_admin \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
--env BUILD_TARGET="$target" \
|
2023-10-19 22:08:39 +00:00
|
|
|
--env RUSTFLAGS="$rustflags" \
|
|
|
|
--env TARGET_CC="$target_cc" \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CTR_IMAGE" \
|
|
|
|
./scripts/run_unit_tests.sh "$@" || fix_dir_perms $? || exit $?
|
2020-01-29 11:48:46 +00:00
|
|
|
fi
|
|
|
|
|
2022-02-21 11:04:19 +00:00
|
|
|
if [ "$integration" = true ]; then
|
|
|
|
say "Running integration tests for $target..."
|
|
|
|
$DOCKER_RUNTIME run \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--privileged \
|
|
|
|
--security-opt seccomp=unconfined \
|
|
|
|
--ipc=host \
|
|
|
|
--net="$CTR_CLH_NET" \
|
|
|
|
--mount type=tmpfs,destination=/tmp \
|
|
|
|
--volume /dev:/dev \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
|
|
|
|
--env USER="root" \
|
2023-10-19 21:23:16 +00:00
|
|
|
--env BUILD_TARGET="$target" \
|
2023-10-19 22:08:39 +00:00
|
|
|
--env RUSTFLAGS="$rustflags" \
|
|
|
|
--env TARGET_CC="$target_cc" \
|
2023-11-07 14:50:06 +00:00
|
|
|
--env AUTH_DOWNLOAD_TOKEN="$AUTH_DOWNLOAD_TOKEN" \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CTR_IMAGE" \
|
2023-03-30 20:47:21 +00:00
|
|
|
dbus-run-session ./scripts/run_integration_tests_"$(uname -m)".sh "$@" || fix_dir_perms $? || exit $?
|
2020-01-29 11:48:46 +00:00
|
|
|
fi
|
2020-02-07 20:25:10 +00:00
|
|
|
|
2022-02-21 11:04:19 +00:00
|
|
|
if [ "$integration_sgx" = true ]; then
|
|
|
|
say "Running SGX integration tests for $target..."
|
|
|
|
$DOCKER_RUNTIME run \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--privileged \
|
|
|
|
--security-opt seccomp=unconfined \
|
|
|
|
--ipc=host \
|
|
|
|
--net="$CTR_CLH_NET" \
|
|
|
|
--mount type=tmpfs,destination=/tmp \
|
|
|
|
--volume /dev:/dev \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
|
|
|
|
--env USER="root" \
|
2023-10-19 21:23:16 +00:00
|
|
|
--env BUILD_TARGET="$target" \
|
2023-10-19 22:08:39 +00:00
|
|
|
--env RUSTFLAGS="$rustflags" \
|
|
|
|
--env TARGET_CC="$target_cc" \
|
2023-11-07 14:50:06 +00:00
|
|
|
--env AUTH_DOWNLOAD_TOKEN="$AUTH_DOWNLOAD_TOKEN" \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CTR_IMAGE" \
|
|
|
|
./scripts/run_integration_tests_sgx.sh "$@" || fix_dir_perms $? || exit $?
|
2020-09-08 12:20:26 +00:00
|
|
|
fi
|
|
|
|
|
2022-02-21 11:04:19 +00:00
|
|
|
if [ "$integration_vfio" = true ]; then
|
|
|
|
say "Running VFIO integration tests for $target..."
|
|
|
|
$DOCKER_RUNTIME run \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--privileged \
|
|
|
|
--security-opt seccomp=unconfined \
|
|
|
|
--ipc=host \
|
|
|
|
--net="$CTR_CLH_NET" \
|
|
|
|
--mount type=tmpfs,destination=/tmp \
|
|
|
|
--volume /dev:/dev \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
|
|
|
|
--env USER="root" \
|
2023-10-19 21:23:16 +00:00
|
|
|
--env BUILD_TARGET="$target" \
|
2023-10-19 22:08:39 +00:00
|
|
|
--env RUSTFLAGS="$rustflags" \
|
|
|
|
--env TARGET_CC="$target_cc" \
|
2023-11-07 14:50:06 +00:00
|
|
|
--env AUTH_DOWNLOAD_TOKEN="$AUTH_DOWNLOAD_TOKEN" \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CTR_IMAGE" \
|
|
|
|
./scripts/run_integration_tests_vfio.sh "$@" || fix_dir_perms $? || exit $?
|
2021-03-16 15:11:00 +00:00
|
|
|
fi
|
|
|
|
|
2022-02-21 11:04:19 +00:00
|
|
|
if [ "$integration_windows" = true ]; then
|
|
|
|
say "Running Windows integration tests for $target..."
|
|
|
|
$DOCKER_RUNTIME run \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--privileged \
|
|
|
|
--security-opt seccomp=unconfined \
|
|
|
|
--ipc=host \
|
|
|
|
--net="$CTR_CLH_NET" \
|
|
|
|
--mount type=tmpfs,destination=/tmp \
|
|
|
|
--volume /dev:/dev \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
|
|
|
|
--env USER="root" \
|
2023-10-19 21:23:16 +00:00
|
|
|
--env BUILD_TARGET="$target" \
|
2023-10-19 22:08:39 +00:00
|
|
|
--env RUSTFLAGS="$rustflags" \
|
|
|
|
--env TARGET_CC="$target_cc" \
|
2023-11-07 14:50:06 +00:00
|
|
|
--env AUTH_DOWNLOAD_TOKEN="$AUTH_DOWNLOAD_TOKEN" \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CTR_IMAGE" \
|
2022-08-03 21:52:53 +00:00
|
|
|
./scripts/run_integration_tests_windows_"$(uname -m)".sh "$@" || fix_dir_perms $? || exit $?
|
2020-10-07 14:34:18 +00:00
|
|
|
fi
|
2021-08-27 22:30:28 +00:00
|
|
|
|
2022-02-21 11:04:19 +00:00
|
|
|
if [ "$integration_live_migration" = true ]; then
|
|
|
|
say "Running 'live migration' integration tests for $target..."
|
|
|
|
$DOCKER_RUNTIME run \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--privileged \
|
|
|
|
--security-opt seccomp=unconfined \
|
|
|
|
--ipc=host \
|
|
|
|
--net="$CTR_CLH_NET" \
|
|
|
|
--mount type=tmpfs,destination=/tmp \
|
|
|
|
--volume /dev:/dev \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
|
|
|
|
--env USER="root" \
|
2023-10-19 21:23:16 +00:00
|
|
|
--env BUILD_TARGET="$target" \
|
2023-10-19 22:08:39 +00:00
|
|
|
--env RUSTFLAGS="$rustflags" \
|
|
|
|
--env TARGET_CC="$target_cc" \
|
2023-11-07 14:50:06 +00:00
|
|
|
--env AUTH_DOWNLOAD_TOKEN="$AUTH_DOWNLOAD_TOKEN" \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CTR_IMAGE" \
|
|
|
|
./scripts/run_integration_tests_live_migration.sh "$@" || fix_dir_perms $? || exit $?
|
2021-08-27 22:30:28 +00:00
|
|
|
fi
|
2022-02-05 00:14:40 +00:00
|
|
|
|
2022-08-30 01:22:47 +00:00
|
|
|
if [ "$integration_rate_limiter" = true ]; then
|
|
|
|
say "Running 'rate limiter' integration tests for $target..."
|
|
|
|
$DOCKER_RUNTIME run \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--privileged \
|
|
|
|
--security-opt seccomp=unconfined \
|
|
|
|
--ipc=host \
|
|
|
|
--net="$CTR_CLH_NET" \
|
|
|
|
--mount type=tmpfs,destination=/tmp \
|
|
|
|
--volume /dev:/dev \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-08-30 01:22:47 +00:00
|
|
|
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
|
|
|
|
--env USER="root" \
|
2023-10-19 21:23:16 +00:00
|
|
|
--env BUILD_TARGET="$target" \
|
2023-10-19 22:08:39 +00:00
|
|
|
--env RUSTFLAGS="$rustflags" \
|
|
|
|
--env TARGET_CC="$target_cc" \
|
2023-11-07 14:50:06 +00:00
|
|
|
--env AUTH_DOWNLOAD_TOKEN="$AUTH_DOWNLOAD_TOKEN" \
|
2022-08-30 01:22:47 +00:00
|
|
|
"$CTR_IMAGE" \
|
|
|
|
./scripts/run_integration_tests_rate_limiter.sh "$@" || fix_dir_perms $? || exit $?
|
|
|
|
fi
|
|
|
|
|
2022-02-21 11:04:19 +00:00
|
|
|
if [ "$metrics" = true ]; then
|
|
|
|
say "Generating performance metrics for $target..."
|
|
|
|
$DOCKER_RUNTIME run \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--privileged \
|
|
|
|
--security-opt seccomp=unconfined \
|
|
|
|
--ipc=host \
|
|
|
|
--net="$CTR_CLH_NET" \
|
|
|
|
--mount type=tmpfs,destination=/tmp \
|
|
|
|
--volume /dev:/dev \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
|
|
|
|
--env USER="root" \
|
2023-10-19 21:23:16 +00:00
|
|
|
--env BUILD_TARGET="$target" \
|
2023-10-19 22:08:39 +00:00
|
|
|
--env RUSTFLAGS="$rustflags" \
|
|
|
|
--env TARGET_CC="$target_cc" \
|
2023-04-10 14:19:50 +00:00
|
|
|
--env RUST_BACKTRACE="${RUST_BACKTRACE}" \
|
2023-11-07 14:50:06 +00:00
|
|
|
--env AUTH_DOWNLOAD_TOKEN="$AUTH_DOWNLOAD_TOKEN" \
|
2022-02-21 11:04:19 +00:00
|
|
|
"$CTR_IMAGE" \
|
|
|
|
./scripts/run_metrics.sh "$@" || fix_dir_perms $? || exit $?
|
2022-02-05 00:14:40 +00:00
|
|
|
fi
|
|
|
|
|
2020-02-13 15:40:10 +00:00
|
|
|
fix_dir_perms $?
|
2020-01-29 11:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:29:18 +00:00
|
|
|
build_container() {
|
|
|
|
ensure_build_dir
|
|
|
|
|
|
|
|
BUILD_DIR=/tmp/cloud-hypervisor/container/
|
|
|
|
|
|
|
|
mkdir -p $BUILD_DIR
|
|
|
|
cp "$CLH_DOCKERFILE" $BUILD_DIR
|
2020-01-29 11:48:46 +00:00
|
|
|
|
2022-02-21 11:29:18 +00:00
|
|
|
[ "$(uname -m)" = "aarch64" ] && TARGETARCH="arm64"
|
|
|
|
[ "$(uname -m)" = "x86_64" ] && TARGETARCH="amd64"
|
|
|
|
|
|
|
|
$DOCKER_RUNTIME build \
|
|
|
|
--target dev \
|
2024-01-29 15:38:44 +00:00
|
|
|
-t "$CTR_IMAGE" \
|
2022-02-21 11:29:18 +00:00
|
|
|
-f $BUILD_DIR/Dockerfile \
|
2024-01-29 15:38:44 +00:00
|
|
|
--build-arg TARGETARCH="$TARGETARCH" \
|
2022-02-21 11:29:18 +00:00
|
|
|
$BUILD_DIR
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_build-container() {
|
2020-01-29 11:48:46 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
2022-02-21 11:04:19 +00:00
|
|
|
case "$1" in
|
|
|
|
"-h" | "--help") {
|
|
|
|
cmd_help
|
|
|
|
exit 1
|
|
|
|
} ;;
|
|
|
|
"--") {
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
} ;;
|
|
|
|
*)
|
|
|
|
die "Unknown build-container argument: $1. Please use --help for help."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2020-01-29 11:48:46 +00:00
|
|
|
done
|
|
|
|
|
2022-02-21 11:29:18 +00:00
|
|
|
build_container
|
2020-01-29 11:48:46 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 17:16:01 +00:00
|
|
|
cmd_shell() {
|
2021-07-14 18:29:02 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
2022-02-21 11:04:19 +00:00
|
|
|
case "$1" in
|
|
|
|
"-h" | "--help") {
|
|
|
|
cmd_help
|
|
|
|
exit 1
|
|
|
|
} ;;
|
|
|
|
"--volumes")
|
|
|
|
shift
|
|
|
|
arg_vols="$1"
|
|
|
|
;;
|
|
|
|
"--") {
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
} ;;
|
|
|
|
*) ;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
shift
|
2021-07-14 18:29:02 +00:00
|
|
|
done
|
2021-01-26 11:15:24 +00:00
|
|
|
ensure_build_dir
|
2021-08-26 11:40:52 +00:00
|
|
|
ensure_latest_ctr
|
2021-07-14 18:29:02 +00:00
|
|
|
process_volumes_args
|
2020-06-25 17:16:01 +00:00
|
|
|
say_warn "Starting a privileged shell prompt as root ..."
|
|
|
|
say_warn "WARNING: Your $CLH_ROOT_DIR folder will be bind-mounted in the container under $CTR_CLH_ROOT_DIR"
|
|
|
|
$DOCKER_RUNTIME run \
|
2022-02-21 11:04:19 +00:00
|
|
|
-ti \
|
|
|
|
--workdir "$CTR_CLH_ROOT_DIR" \
|
|
|
|
--rm \
|
|
|
|
--privileged \
|
|
|
|
--security-opt seccomp=unconfined \
|
|
|
|
--ipc=host \
|
|
|
|
--net="$CTR_CLH_NET" \
|
|
|
|
--tmpfs /tmp:exec \
|
|
|
|
--volume /dev:/dev \
|
2024-01-29 15:38:44 +00:00
|
|
|
--volume "$CLH_ROOT_DIR:$CTR_CLH_ROOT_DIR" \
|
|
|
|
${exported_volumes:+"$exported_volumes"} \
|
2022-02-21 11:04:19 +00:00
|
|
|
--volume "$CLH_INTEGRATION_WORKLOADS:$CTR_CLH_INTEGRATION_WORKLOADS" \
|
|
|
|
--env USER="root" \
|
|
|
|
--entrypoint bash \
|
|
|
|
"$CTR_IMAGE"
|
2020-06-25 17:16:01 +00:00
|
|
|
|
|
|
|
fix_dir_perms $?
|
|
|
|
}
|
|
|
|
|
2023-02-16 15:45:45 +00:00
|
|
|
if [ $# = 0 ]; then
|
|
|
|
cmd_help
|
|
|
|
say_err "Please specify command to run!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-01-29 11:48:46 +00:00
|
|
|
# Parse main command line args.
|
|
|
|
#
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
2022-02-21 11:04:19 +00:00
|
|
|
-h | --help) {
|
|
|
|
cmd_help
|
|
|
|
exit 1
|
|
|
|
} ;;
|
2022-02-21 11:29:18 +00:00
|
|
|
--local) {
|
|
|
|
CTR_IMAGE_VERSION="local"
|
|
|
|
CTR_IMAGE="${CTR_IMAGE_TAG}:${CTR_IMAGE_VERSION}"
|
|
|
|
} ;;
|
2022-02-21 11:04:19 +00:00
|
|
|
-*)
|
|
|
|
die "Unknown arg: $1. Please use \`$0 help\` for help."
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
2020-01-29 11:48:46 +00:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
# $1 is now a command name. Check if it is a valid command and, if so,
|
|
|
|
# run it.
|
|
|
|
#
|
2022-02-21 11:04:19 +00:00
|
|
|
declare -f "cmd_$1" >/dev/null
|
2020-01-29 11:48:46 +00:00
|
|
|
ok_or_die "Unknown command: $1. Please use \`$0 help\` for help."
|
|
|
|
|
|
|
|
cmd=cmd_$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
$cmd "$@"
|