1#!/bin/bash 2set -x 3 4source $HOME/.cargo/env 5source $(dirname "$0")/test-util.sh 6 7process_common_args "$@" 8# For now these values are default for kvm 9features="" 10 11if [ "$hypervisor" = "mshv" ] ; then 12 features="--no-default-features --features mshv" 13fi 14WIN_IMAGE_FILE="/root/workloads/windows-server-2019.raw" 15 16WORKLOADS_DIR="/root/workloads" 17OVMF_FW_URL=$(curl --silent https://api.github.com/repos/cloud-hypervisor/edk2/releases/latest | grep "browser_download_url" | grep -o 'https://.*[^ "]') 18OVMF_FW="$WORKLOADS_DIR/CLOUDHV.fd" 19if [ ! -f "$OVMF_FW" ]; then 20 pushd $WORKLOADS_DIR 21 time wget --quiet $OVMF_FW_URL || exit 1 22 popd 23fi 24 25BUILD_TARGET="$(uname -m)-unknown-linux-${CH_LIBC}" 26CFLAGS="" 27TARGET_CC="" 28if [[ "${BUILD_TARGET}" == "x86_64-unknown-linux-musl" ]]; then 29TARGET_CC="musl-gcc" 30CFLAGS="-I /usr/include/x86_64-linux-musl/ -idirafter /usr/include/" 31fi 32 33# Check if the images are present 34if [[ ! -f ${WIN_IMAGE_FILE} || ! -f ${OVMF_FW} ]]; then 35 echo "Windows image/firmware not present in the host" 36 exit 1 37fi 38 39# Use device mapper to create a snapshot of the Windows image 40img_blk_size=$(du -b -B 512 ${WIN_IMAGE_FILE} | awk '{print $1;}') 41loop_device=$(losetup --find --show --read-only ${WIN_IMAGE_FILE}) 42dmsetup create windows-base --table "0 $img_blk_size linear $loop_device 0" 43dmsetup mknodes 44dmsetup create windows-snapshot-base --table "0 $img_blk_size snapshot-origin /dev/mapper/windows-base" 45dmsetup mknodes 46 47cargo build --all --release $features --target $BUILD_TARGET 48strip target/$BUILD_TARGET/release/cloud-hypervisor 49 50export RUST_BACKTRACE=1 51 52# Only run with 1 thread to avoid tests interfering with one another because 53# Windows has a static IP configured 54time cargo test $features "windows::$test_filter" -- ${test_binary_args[*]} 55RES=$? 56 57dmsetup remove_all -f 58losetup -D 59 60exit $RES 61