2021-03-16 15:11:00 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -x
|
|
|
|
|
|
|
|
source $HOME/.cargo/env
|
|
|
|
source $(dirname "$0")/test-util.sh
|
|
|
|
|
|
|
|
process_common_args "$@"
|
|
|
|
|
2022-08-03 15:28:53 +00:00
|
|
|
WORKLOADS_DIR="$HOME/workloads"
|
2023-06-14 10:58:09 +00:00
|
|
|
mkdir -p "$WORKLOADS_DIR"
|
|
|
|
|
|
|
|
cp scripts/sha1sums-x86_64 $WORKLOADS_DIR
|
|
|
|
|
|
|
|
FW_URL=$(curl --silent https://api.github.com/repos/cloud-hypervisor/rust-hypervisor-firmware/releases/latest | grep "browser_download_url" | grep -o 'https://.*[^ "]')
|
2022-08-03 15:28:53 +00:00
|
|
|
FW="$WORKLOADS_DIR/hypervisor-fw"
|
2023-06-14 10:58:09 +00:00
|
|
|
if [ ! -f "$FW" ]; then
|
|
|
|
pushd $WORKLOADS_DIR
|
|
|
|
time wget --quiet $FW_URL || exit 1
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
|
|
|
FOCAL_OS_IMAGE_NAME="focal-server-cloudimg-amd64-custom-20210609-0.qcow2"
|
|
|
|
FOCAL_OS_IMAGE_URL="https://cloud-hypervisor.azureedge.net/$FOCAL_OS_IMAGE_NAME"
|
|
|
|
FOCAL_OS_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_IMAGE_NAME"
|
|
|
|
if [ ! -f "$FOCAL_OS_IMAGE" ]; then
|
|
|
|
pushd $WORKLOADS_DIR
|
|
|
|
time wget --quiet $FOCAL_OS_IMAGE_URL || exit 1
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
|
|
|
FOCAL_OS_RAW_IMAGE_NAME="focal-server-cloudimg-amd64-custom-20210609-0.raw"
|
|
|
|
FOCAL_OS_RAW_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_NAME"
|
|
|
|
if [ ! -f "$FOCAL_OS_RAW_IMAGE" ]; then
|
|
|
|
pushd $WORKLOADS_DIR
|
|
|
|
time qemu-img convert -p -f qcow2 -O raw $FOCAL_OS_IMAGE_NAME $FOCAL_OS_RAW_IMAGE_NAME || exit 1
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
|
|
|
pushd $WORKLOADS_DIR
|
|
|
|
sha1sum sha1sums-x86_64 --check --ignore-missing
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "sha1sum validation of images failed, remove invalid images to fix the issue."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
popd
|
2022-11-24 16:27:20 +00:00
|
|
|
|
2022-08-03 15:28:53 +00:00
|
|
|
VMLINUX_IMAGE="$WORKLOADS_DIR/vmlinux"
|
2023-03-09 00:05:31 +00:00
|
|
|
build_custom_linux
|
2022-08-03 15:28:53 +00:00
|
|
|
|
|
|
|
BLK_IMAGE="$WORKLOADS_DIR/blk.img"
|
|
|
|
MNT_DIR="mount_image"
|
|
|
|
rm -rf $BLK_IMAGE
|
|
|
|
pushd $WORKLOADS_DIR
|
|
|
|
fallocate -l 16M $BLK_IMAGE
|
|
|
|
mkfs.ext4 -j $BLK_IMAGE
|
|
|
|
mkdir $MNT_DIR
|
|
|
|
sudo mount -t ext4 $BLK_IMAGE $MNT_DIR
|
|
|
|
sudo bash -c "echo bar > $MNT_DIR/foo" || exit 1
|
|
|
|
sudo umount $BLK_IMAGE
|
|
|
|
rm -r $MNT_DIR
|
|
|
|
popd
|
|
|
|
|
|
|
|
VFIO_DIR="$WORKLOADS_DIR/vfio"
|
|
|
|
VFIO_DISK_IMAGE="$WORKLOADS_DIR/vfio.img"
|
|
|
|
rm -rf $VFIO_DIR $VFIO_DISK_IMAGE
|
|
|
|
mkdir -p $VFIO_DIR
|
2023-06-14 10:58:09 +00:00
|
|
|
cp $FOCAL_OS_RAW_IMAGE $VFIO_DIR
|
2022-08-03 15:28:53 +00:00
|
|
|
cp $FW $VFIO_DIR
|
|
|
|
cp $VMLINUX_IMAGE $VFIO_DIR || exit 1
|
|
|
|
|
2021-03-16 15:11:00 +00:00
|
|
|
BUILD_TARGET="$(uname -m)-unknown-linux-${CH_LIBC}"
|
|
|
|
CFLAGS=""
|
|
|
|
TARGET_CC=""
|
|
|
|
if [[ "${BUILD_TARGET}" == "x86_64-unknown-linux-musl" ]]; then
|
|
|
|
TARGET_CC="musl-gcc"
|
|
|
|
CFLAGS="-I /usr/include/x86_64-linux-musl/ -idirafter /usr/include/"
|
|
|
|
fi
|
|
|
|
|
2022-11-24 14:42:07 +00:00
|
|
|
cargo build --no-default-features --features "kvm,mshv" --all --release --target $BUILD_TARGET
|
2021-03-16 15:11:00 +00:00
|
|
|
|
2022-08-03 15:28:53 +00:00
|
|
|
# We always copy a fresh version of our binary for our L2 guest.
|
|
|
|
cp target/$BUILD_TARGET/release/cloud-hypervisor $VFIO_DIR
|
|
|
|
cp target/$BUILD_TARGET/release/ch-remote $VFIO_DIR
|
2021-03-16 15:11:00 +00:00
|
|
|
|
2022-08-03 15:28:53 +00:00
|
|
|
# test_vfio rely on hugepages
|
2023-03-07 06:28:02 +00:00
|
|
|
HUGEPAGESIZE=`grep Hugepagesize /proc/meminfo | awk '{print $2}'`
|
|
|
|
PAGE_NUM=`echo $((12288 * 1024 / $HUGEPAGESIZE))`
|
|
|
|
echo $PAGE_NUM | sudo tee /proc/sys/vm/nr_hugepages
|
2022-08-03 15:28:53 +00:00
|
|
|
sudo chmod a+rwX /dev/hugepages
|
|
|
|
|
|
|
|
export RUST_BACKTRACE=1
|
2023-02-15 11:18:32 +00:00
|
|
|
time cargo test "vfio::test_nvidia" -- --test-threads=1 ${test_binary_args[*]}
|
2021-03-16 15:11:00 +00:00
|
|
|
RES=$?
|
|
|
|
|
|
|
|
exit $RES
|