2023-12-15 20:33:46 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-11-18 00:37:27 +00:00
|
|
|
hypervisor="kvm"
|
2021-01-25 15:55:34 +00:00
|
|
|
test_filter=""
|
|
|
|
|
2022-03-18 03:00:02 +00:00
|
|
|
# Checkout source code of a GIT repo with specified branch and commit
|
|
|
|
# Args:
|
|
|
|
# $1: Target directory
|
|
|
|
# $2: GIT URL of the repo
|
|
|
|
# $3: Required branch
|
|
|
|
# $4: Required commit (optional)
|
|
|
|
checkout_repo() {
|
|
|
|
SRC_DIR="$1"
|
|
|
|
GIT_URL="$2"
|
|
|
|
GIT_BRANCH="$3"
|
|
|
|
GIT_COMMIT="$4"
|
|
|
|
|
|
|
|
# Check whether the local HEAD commit same as the requested commit or not.
|
|
|
|
# If commit is not specified, compare local HEAD and remote HEAD.
|
|
|
|
# Remove the folder if there is difference.
|
|
|
|
if [ -d "$SRC_DIR" ]; then
|
2024-01-29 15:38:44 +00:00
|
|
|
pushd "$SRC_DIR" || exit
|
2022-03-18 03:00:02 +00:00
|
|
|
git fetch
|
|
|
|
SRC_LOCAL_COMMIT=$(git rev-parse HEAD)
|
|
|
|
if [ -z "$GIT_COMMIT" ]; then
|
|
|
|
GIT_COMMIT=$(git rev-parse remotes/origin/"$GIT_BRANCH")
|
|
|
|
fi
|
2024-01-29 15:38:44 +00:00
|
|
|
popd || exit
|
2022-03-18 03:00:02 +00:00
|
|
|
if [ "$SRC_LOCAL_COMMIT" != "$GIT_COMMIT" ]; then
|
|
|
|
rm -rf "$SRC_DIR"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Checkout the specified branch and commit (if required)
|
|
|
|
if [ ! -d "$SRC_DIR" ]; then
|
|
|
|
git clone --depth 1 "$GIT_URL" -b "$GIT_BRANCH" "$SRC_DIR"
|
|
|
|
if [ "$GIT_COMMIT" ]; then
|
2024-01-29 15:38:44 +00:00
|
|
|
pushd "$SRC_DIR" || exit
|
2022-03-18 03:00:02 +00:00
|
|
|
git fetch --depth 1 origin "$GIT_COMMIT"
|
|
|
|
git reset --hard FETCH_HEAD
|
2024-01-29 15:38:44 +00:00
|
|
|
popd || exit
|
2022-03-18 03:00:02 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-03-26 04:37:21 +00:00
|
|
|
build_custom_linux() {
|
|
|
|
ARCH=$(uname -m)
|
|
|
|
SRCDIR=$PWD
|
|
|
|
LINUX_CUSTOM_DIR="$WORKLOADS_DIR/linux-custom"
|
2023-03-08 23:14:33 +00:00
|
|
|
LINUX_CUSTOM_BRANCH="ch-6.2"
|
2022-03-26 04:37:21 +00:00
|
|
|
LINUX_CUSTOM_URL="https://github.com/cloud-hypervisor/linux.git"
|
|
|
|
|
|
|
|
checkout_repo "$LINUX_CUSTOM_DIR" "$LINUX_CUSTOM_URL" "$LINUX_CUSTOM_BRANCH"
|
|
|
|
|
2024-01-29 15:38:44 +00:00
|
|
|
cp "$SRCDIR"/resources/linux-config-"${ARCH}" "$LINUX_CUSTOM_DIR"/.config
|
2022-03-26 04:37:21 +00:00
|
|
|
|
2024-01-29 15:38:44 +00:00
|
|
|
pushd "$LINUX_CUSTOM_DIR" || exit
|
|
|
|
make -j "$(nproc)"
|
|
|
|
if [ "${ARCH}" == "x86_64" ]; then
|
2024-01-26 15:30:32 +00:00
|
|
|
cp vmlinux "$WORKLOADS_DIR/" || exit 1
|
2024-02-15 14:08:31 +00:00
|
|
|
cp arch/x86/boot/bzImage "$WORKLOADS_DIR/" || exit 1
|
2024-01-29 15:38:44 +00:00
|
|
|
elif [ "${ARCH}" == "aarch64" ]; then
|
2024-01-26 15:30:32 +00:00
|
|
|
cp arch/arm64/boot/Image "$WORKLOADS_DIR/" || exit 1
|
|
|
|
cp arch/arm64/boot/Image.gz "$WORKLOADS_DIR/" || exit 1
|
2022-03-26 04:37:21 +00:00
|
|
|
fi
|
2024-01-29 15:38:44 +00:00
|
|
|
popd || exit
|
2022-03-26 04:37:21 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 00:37:27 +00:00
|
|
|
cmd_help() {
|
|
|
|
echo ""
|
2024-01-29 15:38:44 +00:00
|
|
|
echo "Cloud Hypervisor $(basename "$0")"
|
|
|
|
echo "Usage: $(basename "$0") [<args>]"
|
2020-11-18 00:37:27 +00:00
|
|
|
echo ""
|
|
|
|
echo "Available arguments:"
|
|
|
|
echo ""
|
|
|
|
echo " --hypervisor Underlying hypervisor. Options kvm, mshv"
|
2021-01-25 15:55:34 +00:00
|
|
|
echo " --test-filter Tests to run"
|
2020-11-18 00:37:27 +00:00
|
|
|
echo ""
|
|
|
|
echo " --help Display this help message."
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
process_common_args() {
|
|
|
|
while [ $# -gt 0 ]; do
|
2024-01-26 15:30:32 +00:00
|
|
|
case "$1" in
|
|
|
|
"-h" | "--help") {
|
|
|
|
cmd_help
|
|
|
|
exit 1
|
|
|
|
} ;;
|
|
|
|
"--hypervisor")
|
|
|
|
shift
|
|
|
|
hypervisor="$1"
|
|
|
|
;;
|
|
|
|
"--test-filter")
|
|
|
|
shift
|
2024-01-29 15:38:44 +00:00
|
|
|
# shellcheck disable=SC2034
|
2024-01-26 15:30:32 +00:00
|
|
|
test_filter="$1"
|
|
|
|
;;
|
|
|
|
"--") {
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
} ;;
|
|
|
|
*)
|
|
|
|
echo "Unknown test scripts argument: $1. Please use '-- --help' for help."
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2020-11-18 00:37:27 +00:00
|
|
|
done
|
2024-01-26 15:30:32 +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
|
2024-01-29 15:38:44 +00:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
test_binary_args=("$@")
|
2021-01-25 15:55:34 +00:00
|
|
|
}
|
2023-11-07 13:42:55 +00:00
|
|
|
|
|
|
|
download_hypervisor_fw() {
|
2023-11-08 06:36:23 +00:00
|
|
|
if [ -n "$AUTH_DOWNLOAD_TOKEN" ]; then
|
2023-11-07 13:55:35 +00:00
|
|
|
echo "Using authenticated download from GitHub"
|
|
|
|
FW_URL=$(curl --silent https://api.github.com/repos/cloud-hypervisor/rust-hypervisor-firmware/releases/latest \
|
2024-01-26 15:30:32 +00:00
|
|
|
--header "Authorization: Token $AUTH_DOWNLOAD_TOKEN" \
|
|
|
|
--header "X-GitHub-Api-Version: 2022-11-28" | grep "browser_download_url" | grep -o 'https://.*[^ "]')
|
2023-11-07 13:55:35 +00:00
|
|
|
else
|
|
|
|
echo "Using anonymous download from GitHub"
|
|
|
|
FW_URL=$(curl --silent https://api.github.com/repos/cloud-hypervisor/rust-hypervisor-firmware/releases/latest | grep "browser_download_url" | grep -o 'https://.*[^ "]')
|
|
|
|
fi
|
2023-11-07 13:42:55 +00:00
|
|
|
FW="$WORKLOADS_DIR/hypervisor-fw"
|
2024-01-29 15:38:44 +00:00
|
|
|
pushd "$WORKLOADS_DIR" || exit
|
|
|
|
rm -f "$FW"
|
|
|
|
time wget --quiet "$FW_URL" || exit 1
|
|
|
|
popd || exit
|
2023-11-07 13:42:55 +00:00
|
|
|
}
|
2024-01-18 18:50:11 +00:00
|
|
|
|
|
|
|
download_ovmf() {
|
|
|
|
OVMF_FW_TAG="ch-6624aa331f"
|
|
|
|
OVMF_FW_URL="https://github.com/cloud-hypervisor/edk2/releases/download/$OVMF_FW_TAG/CLOUDHV.fd"
|
|
|
|
OVMF_FW="$WORKLOADS_DIR/CLOUDHV.fd"
|
2024-01-29 15:38:44 +00:00
|
|
|
pushd "$WORKLOADS_DIR" || exit
|
|
|
|
rm -f "$OVMF_FW"
|
2024-01-18 18:50:11 +00:00
|
|
|
time wget --quiet $OVMF_FW_URL || exit 1
|
2024-01-29 15:38:44 +00:00
|
|
|
popd || exit
|
2024-01-18 18:50:11 +00:00
|
|
|
}
|