2019-05-23 15:45:13 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -x
|
|
|
|
|
|
|
|
source $HOME/.cargo/env
|
|
|
|
|
|
|
|
WORKLOADS_DIR="$HOME/workloads"
|
|
|
|
mkdir -p "$WORKLOADS_DIR"
|
|
|
|
|
2020-03-03 08:48:32 +00:00
|
|
|
cp scripts/sha1sums $WORKLOADS_DIR
|
|
|
|
|
2019-11-21 10:05:30 +00:00
|
|
|
FW_URL=$(curl --silent https://api.github.com/repos/cloud-hypervisor/rust-hypervisor-firmware/releases/latest | grep "browser_download_url" | grep -o 'https://.*[^ "]')
|
2019-05-23 15:45:13 +00:00
|
|
|
FW="$WORKLOADS_DIR/hypervisor-fw"
|
|
|
|
if [ ! -f "$FW" ]; then
|
|
|
|
pushd $WORKLOADS_DIR
|
2019-12-13 12:39:14 +00:00
|
|
|
time wget --quiet $FW_URL
|
2019-05-23 15:45:13 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2020-03-03 08:48:32 +00:00
|
|
|
CLEAR_OS_IMAGE_NAME="clear-31311-cloudguest.img"
|
2019-09-10 22:53:45 +00:00
|
|
|
CLEAR_OS_IMAGE_URL="https://cloudhypervisorstorage.blob.core.windows.net/images/$CLEAR_OS_IMAGE_NAME"
|
2019-07-30 16:41:05 +00:00
|
|
|
CLEAR_OS_IMAGE="$WORKLOADS_DIR/$CLEAR_OS_IMAGE_NAME"
|
|
|
|
if [ ! -f "$CLEAR_OS_IMAGE" ]; then
|
2019-05-23 15:45:13 +00:00
|
|
|
pushd $WORKLOADS_DIR
|
2019-12-13 12:39:14 +00:00
|
|
|
time wget --quiet $CLEAR_OS_IMAGE_URL
|
2019-06-10 13:59:04 +00:00
|
|
|
popd
|
2019-05-23 15:45:13 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-03 08:48:32 +00:00
|
|
|
CLEAR_OS_RAW_IMAGE_NAME="clear-31311-cloudguest-raw.img"
|
2019-07-30 16:41:05 +00:00
|
|
|
CLEAR_OS_RAW_IMAGE="$WORKLOADS_DIR/$CLEAR_OS_RAW_IMAGE_NAME"
|
|
|
|
if [ ! -f "$CLEAR_OS_RAW_IMAGE" ]; then
|
2019-06-20 20:26:11 +00:00
|
|
|
pushd $WORKLOADS_DIR
|
2019-12-13 12:39:14 +00:00
|
|
|
time qemu-img convert -p -f qcow2 -O raw $CLEAR_OS_IMAGE_NAME $CLEAR_OS_RAW_IMAGE_NAME
|
2019-07-30 16:41:05 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
|
|
|
BIONIC_OS_IMAGE_NAME="bionic-server-cloudimg-amd64.img"
|
2019-08-15 17:27:14 +00:00
|
|
|
BIONIC_OS_IMAGE_URL="https://cloudhypervisorstorage.blob.core.windows.net/images/$BIONIC_OS_IMAGE_NAME"
|
2019-07-30 16:41:05 +00:00
|
|
|
BIONIC_OS_IMAGE="$WORKLOADS_DIR/$BIONIC_OS_IMAGE_NAME"
|
|
|
|
if [ ! -f "$BIONIC_OS_IMAGE" ]; then
|
|
|
|
pushd $WORKLOADS_DIR
|
2019-12-13 12:39:14 +00:00
|
|
|
time wget --quiet $BIONIC_OS_IMAGE_URL
|
2019-07-30 16:41:05 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
|
|
|
BIONIC_OS_RAW_IMAGE_NAME="bionic-server-cloudimg-amd64-raw.img"
|
|
|
|
BIONIC_OS_RAW_IMAGE="$WORKLOADS_DIR/$BIONIC_OS_RAW_IMAGE_NAME"
|
|
|
|
if [ ! -f "$BIONIC_OS_RAW_IMAGE" ]; then
|
|
|
|
pushd $WORKLOADS_DIR
|
2019-12-13 12:39:14 +00:00
|
|
|
time qemu-img convert -p -f qcow2 -O raw $BIONIC_OS_IMAGE_NAME $BIONIC_OS_RAW_IMAGE_NAME
|
2019-06-20 20:26:11 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2019-07-16 10:12:53 +00:00
|
|
|
|
2019-10-01 15:57:41 +00:00
|
|
|
EOAN_OS_IMAGE_NAME="eoan-server-cloudimg-amd64.img"
|
|
|
|
EOAN_OS_IMAGE_URL="https://cloudhypervisorstorage.blob.core.windows.net/images/$EOAN_OS_IMAGE_NAME"
|
|
|
|
EOAN_OS_IMAGE="$WORKLOADS_DIR/$EOAN_OS_IMAGE_NAME"
|
|
|
|
if [ ! -f "$EOAN_OS_IMAGE" ]; then
|
|
|
|
pushd $WORKLOADS_DIR
|
2019-12-13 12:39:14 +00:00
|
|
|
time wget --quiet $EOAN_OS_IMAGE_URL
|
2019-10-01 15:57:41 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
|
|
|
EOAN_OS_RAW_IMAGE_NAME="eoan-server-cloudimg-amd64-raw.img"
|
|
|
|
EOAN_OS_RAW_IMAGE="$WORKLOADS_DIR/$EOAN_OS_RAW_IMAGE_NAME"
|
|
|
|
if [ ! -f "$EOAN_OS_RAW_IMAGE" ]; then
|
|
|
|
pushd $WORKLOADS_DIR
|
2019-12-13 12:39:14 +00:00
|
|
|
time qemu-img convert -p -f qcow2 -O raw $EOAN_OS_IMAGE_NAME $EOAN_OS_RAW_IMAGE_NAME
|
2019-10-01 15:57:41 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2020-01-23 15:35:00 +00:00
|
|
|
pushd $WORKLOADS_DIR
|
2020-03-04 16:18:50 +00:00
|
|
|
sha1sum sha1sums --check
|
2020-01-23 15:35:00 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "sha1sum validation of images failed, remove invalid images to fix the issue."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
popd
|
2019-10-01 15:57:41 +00:00
|
|
|
|
2019-07-16 10:12:53 +00:00
|
|
|
# Build custom kernel based on virtio-pmem and virtio-fs upstream patches
|
2019-06-10 14:02:53 +00:00
|
|
|
VMLINUX_IMAGE="$WORKLOADS_DIR/vmlinux"
|
|
|
|
BZIMAGE_IMAGE="$WORKLOADS_DIR/bzImage"
|
|
|
|
|
2019-06-15 00:41:13 +00:00
|
|
|
LINUX_CUSTOM_DIR="linux-custom"
|
|
|
|
|
2019-07-16 10:12:53 +00:00
|
|
|
if [ ! -f "$VMLINUX_IMAGE" ]; then
|
2019-06-15 00:41:13 +00:00
|
|
|
SRCDIR=$PWD
|
|
|
|
pushd $WORKLOADS_DIR
|
2020-01-29 17:31:02 +00:00
|
|
|
time git clone --depth 1 "https://github.com/cloud-hypervisor/linux.git" -b "virtio-fs-virtio-iommu-topo-5.5-rc1" $LINUX_CUSTOM_DIR
|
2019-06-15 00:41:13 +00:00
|
|
|
pushd $LINUX_CUSTOM_DIR
|
2019-10-09 16:53:37 +00:00
|
|
|
cp $SRCDIR/resources/linux-virtio-fs-virtio-iommu-config .config
|
2019-12-13 12:39:14 +00:00
|
|
|
time make bzImage -j `nproc`
|
2019-07-16 10:12:53 +00:00
|
|
|
cp vmlinux $VMLINUX_IMAGE
|
|
|
|
cp arch/x86/boot/bzImage $BZIMAGE_IMAGE
|
2019-06-15 00:41:13 +00:00
|
|
|
popd
|
2019-08-16 13:35:41 +00:00
|
|
|
rm -rf $LINUX_CUSTOM_DIR
|
2019-06-15 00:41:13 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
|
|
|
VIRTIOFSD="$WORKLOADS_DIR/virtiofsd"
|
2019-08-16 13:39:46 +00:00
|
|
|
QEMU_DIR="qemu_build"
|
2019-10-24 18:31:03 +00:00
|
|
|
if [ ! -f "$VIRTIOFSD" ]; then
|
2019-06-15 00:41:13 +00:00
|
|
|
pushd $WORKLOADS_DIR
|
2020-01-13 15:25:57 +00:00
|
|
|
git clone --depth 1 "https://github.com/sboeuf/qemu.git" -b "virtio-fs" $QEMU_DIR
|
2019-08-16 13:39:46 +00:00
|
|
|
pushd $QEMU_DIR
|
2019-12-13 12:39:14 +00:00
|
|
|
time ./configure --prefix=$PWD --target-list=x86_64-softmmu
|
|
|
|
time make virtiofsd -j `nproc`
|
2019-08-12 17:34:47 +00:00
|
|
|
cp virtiofsd $VIRTIOFSD
|
|
|
|
popd
|
2019-08-16 13:39:46 +00:00
|
|
|
rm -rf $QEMU_DIR
|
2019-08-20 15:30:32 +00:00
|
|
|
sudo setcap cap_dac_override,cap_sys_admin+epi "virtiofsd"
|
2019-06-15 00:41:13 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2019-09-18 20:23:02 +00:00
|
|
|
BLK_IMAGE="$WORKLOADS_DIR/blk.img"
|
|
|
|
MNT_DIR="mount_image"
|
|
|
|
if [ ! -f "$BLK_IMAGE" ]; then
|
2019-09-18 02:47:33 +00:00
|
|
|
pushd $WORKLOADS_DIR
|
2019-09-18 20:23:02 +00:00
|
|
|
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"
|
|
|
|
sudo umount $BLK_IMAGE
|
|
|
|
rm -r $MNT_DIR
|
2019-09-18 02:47:33 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2019-06-15 00:41:13 +00:00
|
|
|
SHARED_DIR="$WORKLOADS_DIR/shared_dir"
|
|
|
|
if [ ! -d "$SHARED_DIR" ]; then
|
|
|
|
mkdir -p $SHARED_DIR
|
|
|
|
echo "foo" > "$SHARED_DIR/file1"
|
|
|
|
echo "bar" > "$SHARED_DIR/file3"
|
|
|
|
fi
|
2019-06-10 14:02:53 +00:00
|
|
|
|
2019-07-19 08:26:13 +00:00
|
|
|
VFIO_DIR="$WORKLOADS_DIR/vfio"
|
2020-02-13 15:26:35 +00:00
|
|
|
rm -rf $VFIO_DIR
|
|
|
|
mkdir -p $VFIO_DIR
|
|
|
|
cp $CLEAR_OS_IMAGE $VFIO_DIR
|
|
|
|
cp $FW $VFIO_DIR
|
|
|
|
cp $VMLINUX_IMAGE $VFIO_DIR
|
2019-07-19 08:26:13 +00:00
|
|
|
|
|
|
|
# VFIO test network setup.
|
2019-10-10 17:48:41 +00:00
|
|
|
# We reserve a different IP class for it: 172.17.0.0/24.
|
2019-07-19 08:26:13 +00:00
|
|
|
sudo ip link add name vfio-br0 type bridge
|
|
|
|
sudo ip link set vfio-br0 up
|
2019-10-10 17:48:41 +00:00
|
|
|
sudo ip addr add 172.17.0.1/24 dev vfio-br0
|
2019-07-19 08:26:13 +00:00
|
|
|
|
|
|
|
sudo ip tuntap add vfio-tap0 mode tap
|
|
|
|
sudo ip link set vfio-tap0 master vfio-br0
|
|
|
|
sudo ip link set vfio-tap0 up
|
|
|
|
|
|
|
|
sudo ip tuntap add vfio-tap1 mode tap
|
|
|
|
sudo ip link set vfio-tap1 master vfio-br0
|
|
|
|
sudo ip link set vfio-tap1 up
|
|
|
|
|
2019-12-06 19:38:56 +00:00
|
|
|
sudo ip tuntap add vfio-tap2 mode tap
|
|
|
|
sudo ip link set vfio-tap2 master vfio-br0
|
|
|
|
sudo ip link set vfio-tap2 up
|
|
|
|
|
2020-03-03 07:42:13 +00:00
|
|
|
sudo ip tuntap add vfio-tap3 mode tap
|
|
|
|
sudo ip link set vfio-tap3 master vfio-br0
|
|
|
|
sudo ip link set vfio-tap3 up
|
|
|
|
|
2019-10-24 15:24:13 +00:00
|
|
|
cargo build --release
|
|
|
|
sudo setcap cap_net_admin+ep target/release/cloud-hypervisor
|
|
|
|
sudo setcap cap_net_admin+ep target/release/vhost_user_net
|
2019-05-23 15:45:13 +00:00
|
|
|
|
2019-07-19 08:26:13 +00:00
|
|
|
# We always copy a fresh version of our binary for our L2 guest.
|
2019-10-24 15:24:13 +00:00
|
|
|
cp target/release/cloud-hypervisor $VFIO_DIR
|
2019-07-19 08:26:13 +00:00
|
|
|
|
2019-11-20 04:34:42 +00:00
|
|
|
# Enable KSM with some reasonable parameters so that it won't take too long
|
|
|
|
# for the memory to be merged between two processes.
|
2019-12-20 13:06:09 +00:00
|
|
|
sudo bash -c "echo 1000000 > /sys/kernel/mm/ksm/pages_to_scan"
|
2019-11-20 04:34:42 +00:00
|
|
|
sudo bash -c "echo 10 > /sys/kernel/mm/ksm/sleep_millisecs"
|
|
|
|
sudo bash -c "echo 1 > /sys/kernel/mm/ksm/run"
|
|
|
|
|
2019-11-21 17:35:44 +00:00
|
|
|
# Ensure test binary has the same caps as the cloud-hypervisor one
|
2019-12-13 12:39:14 +00:00
|
|
|
time cargo test --no-run --features "integration_tests" -- --nocapture
|
2019-11-23 19:03:49 +00:00
|
|
|
ls target/debug/deps/cloud_hypervisor-* | xargs -n 1 sudo setcap cap_net_admin+ep
|
2019-11-21 17:35:44 +00:00
|
|
|
|
2020-02-13 14:32:24 +00:00
|
|
|
# test_vfio relies on hugepages
|
|
|
|
echo 4096 | sudo tee /proc/sys/vm/nr_hugepages
|
|
|
|
sudo chmod a+rwX /dev/hugepages
|
|
|
|
|
2019-07-19 08:26:13 +00:00
|
|
|
sudo adduser $USER kvm
|
|
|
|
newgrp kvm << EOF
|
2019-08-16 15:08:16 +00:00
|
|
|
export RUST_BACKTRACE=1
|
2020-02-04 13:49:21 +00:00
|
|
|
time cargo test --features "integration_tests" "$@" -- --nocapture
|
2019-07-19 08:26:13 +00:00
|
|
|
EOF
|
2019-08-07 08:36:37 +00:00
|
|
|
RES=$?
|
2019-07-19 08:26:13 +00:00
|
|
|
|
2019-09-12 10:57:04 +00:00
|
|
|
if [ $RES -eq 0 ]; then
|
|
|
|
# virtio-mmio based testing
|
2019-10-24 15:24:13 +00:00
|
|
|
cargo build --release --no-default-features --features "mmio"
|
|
|
|
sudo setcap cap_net_admin+ep target/release/cloud-hypervisor
|
2019-09-12 10:57:04 +00:00
|
|
|
|
|
|
|
newgrp kvm << EOF
|
|
|
|
export RUST_BACKTRACE=1
|
2020-02-04 13:49:21 +00:00
|
|
|
time cargo test --features "integration_tests,mmio" "$@" -- --nocapture
|
2019-09-12 10:57:04 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
RES=$?
|
|
|
|
fi
|
|
|
|
|
2019-07-19 08:26:13 +00:00
|
|
|
# Tear VFIO test network down
|
|
|
|
sudo ip link del vfio-br0
|
|
|
|
sudo ip link del vfio-tap0
|
|
|
|
sudo ip link del vfio-tap1
|
2019-12-06 19:38:56 +00:00
|
|
|
sudo ip link del vfio-tap2
|
2020-03-03 07:42:13 +00:00
|
|
|
sudo ip link del vfio-tap3
|
2019-08-07 08:36:37 +00:00
|
|
|
|
|
|
|
exit $RES
|