191fe48d5SPhilipp Schuster#!/usr/bin/env bash 22b2d0065SRuslan Mstoi# shellcheck disable=SC2048,SC2086 32ce23137SHenry Wangset -x 42ce23137SHenry Wang 52b2d0065SRuslan Mstoi# shellcheck source=/dev/null 62b2d0065SRuslan Mstoisource "$HOME"/.cargo/env 72b2d0065SRuslan Mstoisource "$(dirname "$0")"/test-util.sh 82b2d0065SRuslan Mstoisource "$(dirname "$0")"/common-aarch64.sh 92ce23137SHenry Wang 107e3cbf04SMichael ZhaoWORKLOADS_LOCK="$WORKLOADS_DIR/integration_test.lock" 117e3cbf04SMichael Zhao 120fa71ddfSHenry Wangbuild_virtiofsd() { 130fa71ddfSHenry Wang VIRTIOFSD_DIR="$WORKLOADS_DIR/virtiofsd_build" 140fa71ddfSHenry Wang VIRTIOFSD_REPO="https://gitlab.com/virtio-fs/virtiofsd.git" 150fa71ddfSHenry Wang 1624f384d2SRavi kumar Veeramally checkout_repo "$VIRTIOFSD_DIR" "$VIRTIOFSD_REPO" v1.8.0 "97ea7908fe7f9bc59916671a771bdcfaf4044b45" 170fa71ddfSHenry Wang 180fa71ddfSHenry Wang if [ ! -f "$VIRTIOFSD_DIR/.built" ]; then 192b2d0065SRuslan Mstoi pushd "$VIRTIOFSD_DIR" || exit 202b607da2SRob Bradford rm -rf target/ 212b607da2SRob Bradford time RUSTFLAGS="" TARGET_CC="" cargo build --release 220fa71ddfSHenry Wang cp target/release/virtiofsd "$WORKLOADS_DIR/" || exit 1 230fa71ddfSHenry Wang touch .built 242b2d0065SRuslan Mstoi popd || exit 250fa71ddfSHenry Wang fi 267a42ce93SHenry Wang} 277a42ce93SHenry Wang 287e3cbf04SMichael Zhaoupdate_workloads() { 292b2d0065SRuslan Mstoi cp scripts/sha1sums-aarch64 "$WORKLOADS_DIR" 302ce23137SHenry Wang 311511cbdaSRob Bradford FOCAL_OS_RAW_IMAGE_NAME="focal-server-cloudimg-arm64-custom-20210929-0.raw" 3205ec6190SRavi kumar Veeramally FOCAL_OS_RAW_IMAGE_DOWNLOAD_URL="https://ch-images.azureedge.net/$FOCAL_OS_RAW_IMAGE_NAME" 332ce23137SHenry Wang FOCAL_OS_RAW_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_NAME" 342ce23137SHenry Wang if [ ! -f "$FOCAL_OS_RAW_IMAGE" ]; then 352b2d0065SRuslan Mstoi pushd "$WORKLOADS_DIR" || exit 36a47da515SHenry Wang time wget --quiet $FOCAL_OS_RAW_IMAGE_DOWNLOAD_URL || exit 1 372b2d0065SRuslan Mstoi popd || exit 382ce23137SHenry Wang fi 392ce23137SHenry Wang 401511cbdaSRob Bradford FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME="focal-server-cloudimg-arm64-custom-20210929-0.qcow2" 4105ec6190SRavi kumar Veeramally FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL="https://ch-images.azureedge.net/$FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME" 422ce23137SHenry Wang FOCAL_OS_QCOW2_UNCOMPRESSED_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME" 432ce23137SHenry Wang if [ ! -f "$FOCAL_OS_QCOW2_UNCOMPRESSED_IMAGE" ]; then 442b2d0065SRuslan Mstoi pushd "$WORKLOADS_DIR" || exit 45a47da515SHenry Wang time wget --quiet $FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL || exit 1 462b2d0065SRuslan Mstoi popd || exit 472ce23137SHenry Wang fi 482ce23137SHenry Wang 494ef388b6SYu Li FOCAL_OS_QCOW2_IMAGE_BACKING_FILE_NAME="focal-server-cloudimg-arm64-custom-20210929-0-backing.qcow2" 504ef388b6SYu Li FOCAL_OS_QCOW2_BACKING_FILE_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_QCOW2_IMAGE_BACKING_FILE_NAME" 514ef388b6SYu Li if [ ! -f "$FOCAL_OS_QCOW2_BACKING_FILE_IMAGE" ]; then 522b2d0065SRuslan Mstoi pushd "$WORKLOADS_DIR" || exit 532b2d0065SRuslan Mstoi time qemu-img create -f qcow2 -b "$FOCAL_OS_QCOW2_UNCOMPRESSED_IMAGE" -F qcow2 $FOCAL_OS_QCOW2_IMAGE_BACKING_FILE_NAME 542b2d0065SRuslan Mstoi popd || exit 554ef388b6SYu Li fi 564ef388b6SYu Li 574af04d8fSBo Chen JAMMY_OS_RAW_IMAGE_NAME="jammy-server-cloudimg-arm64-custom-20220329-0.raw" 5805ec6190SRavi kumar Veeramally JAMMY_OS_RAW_IMAGE_DOWNLOAD_URL="https://ch-images.azureedge.net/$JAMMY_OS_RAW_IMAGE_NAME" 594af04d8fSBo Chen JAMMY_OS_RAW_IMAGE="$WORKLOADS_DIR/$JAMMY_OS_RAW_IMAGE_NAME" 604af04d8fSBo Chen if [ ! -f "$JAMMY_OS_RAW_IMAGE" ]; then 612b2d0065SRuslan Mstoi pushd "$WORKLOADS_DIR" || exit 624af04d8fSBo Chen time wget --quiet $JAMMY_OS_RAW_IMAGE_DOWNLOAD_URL || exit 1 632b2d0065SRuslan Mstoi popd || exit 644af04d8fSBo Chen fi 654af04d8fSBo Chen 664af04d8fSBo Chen JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME="jammy-server-cloudimg-arm64-custom-20220329-0.qcow2" 6705ec6190SRavi kumar Veeramally JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL="https://ch-images.azureedge.net/$JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME" 684af04d8fSBo Chen JAMMY_OS_QCOW2_UNCOMPRESSED_IMAGE="$WORKLOADS_DIR/$JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME" 694af04d8fSBo Chen if [ ! -f "$JAMMY_OS_QCOW2_UNCOMPRESSED_IMAGE" ]; then 702b2d0065SRuslan Mstoi pushd "$WORKLOADS_DIR" || exit 714af04d8fSBo Chen time wget --quiet $JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL || exit 1 722b2d0065SRuslan Mstoi popd || exit 734af04d8fSBo Chen fi 744af04d8fSBo Chen 752ce23137SHenry Wang ALPINE_MINIROOTFS_URL="http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/aarch64/alpine-minirootfs-3.11.3-aarch64.tar.gz" 762ce23137SHenry Wang ALPINE_MINIROOTFS_TARBALL="$WORKLOADS_DIR/alpine-minirootfs-aarch64.tar.gz" 772ce23137SHenry Wang if [ ! -f "$ALPINE_MINIROOTFS_TARBALL" ]; then 782b2d0065SRuslan Mstoi pushd "$WORKLOADS_DIR" || exit 792b2d0065SRuslan Mstoi time wget --quiet $ALPINE_MINIROOTFS_URL -O "$ALPINE_MINIROOTFS_TARBALL" || exit 1 802b2d0065SRuslan Mstoi popd || exit 812ce23137SHenry Wang fi 822ce23137SHenry Wang 832ce23137SHenry Wang ALPINE_INITRAMFS_IMAGE="$WORKLOADS_DIR/alpine_initramfs.img" 842ce23137SHenry Wang if [ ! -f "$ALPINE_INITRAMFS_IMAGE" ]; then 852b2d0065SRuslan Mstoi pushd "$WORKLOADS_DIR" || exit 862ce23137SHenry Wang mkdir alpine-minirootfs 872ce23137SHenry Wang tar xf "$ALPINE_MINIROOTFS_TARBALL" -C alpine-minirootfs 882ce23137SHenry Wang cat >alpine-minirootfs/init <<-EOF 892ce23137SHenry Wang #! /bin/sh 902ce23137SHenry Wang mount -t devtmpfs dev /dev 912ce23137SHenry Wang echo \$TEST_STRING > /dev/console 922ce23137SHenry Wang poweroff -f 932ce23137SHenry Wang EOF 942ce23137SHenry Wang chmod +x alpine-minirootfs/init 952b2d0065SRuslan Mstoi cd alpine-minirootfs || exit 962ce23137SHenry Wang find . -print0 | 972ce23137SHenry Wang cpio --null --create --verbose --owner root:root --format=newc >"$ALPINE_INITRAMFS_IMAGE" 982b2d0065SRuslan Mstoi popd || exit 992ce23137SHenry Wang fi 1002ce23137SHenry Wang 1012b2d0065SRuslan Mstoi pushd "$WORKLOADS_DIR" || exit 1022b2d0065SRuslan Mstoi 1032b2d0065SRuslan Mstoi if ! sha1sum sha1sums-aarch64 --check; then 1042ce23137SHenry Wang echo "sha1sum validation of images failed, remove invalid images to fix the issue." 1052ce23137SHenry Wang exit 1 1062ce23137SHenry Wang fi 1072b2d0065SRuslan Mstoi popd || exit 1082ce23137SHenry Wang 109edca82c4SBo Chen # Download Cloud Hypervisor binary from its last stable release 110f5abb168SRob Bradford LAST_RELEASE_VERSION="v39.0" 111edca82c4SBo Chen CH_RELEASE_URL="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/$LAST_RELEASE_VERSION/cloud-hypervisor-static-aarch64" 112edca82c4SBo Chen CH_RELEASE_NAME="cloud-hypervisor-static-aarch64" 1132b2d0065SRuslan Mstoi pushd "$WORKLOADS_DIR" || exit 114f0c5592bSMichael Zhao # Repeat a few times to workaround a random wget failure 115f0c5592bSMichael Zhao WGET_RETRY_MAX=10 116f0c5592bSMichael Zhao wget_retry=0 117f0c5592bSMichael Zhao 118318caeb9SRuslan Mstoi until [ "$wget_retry" -ge "$WGET_RETRY_MAX" ]; do 119f0c5592bSMichael Zhao time wget $CH_RELEASE_URL -O "$CH_RELEASE_NAME" && break 120f0c5592bSMichael Zhao wget_retry=$((wget_retry + 1)) 121f0c5592bSMichael Zhao done 122f0c5592bSMichael Zhao 123f0c5592bSMichael Zhao if [ $wget_retry -ge "$WGET_RETRY_MAX" ]; then 124f0c5592bSMichael Zhao exit 1 125f0c5592bSMichael Zhao else 126edca82c4SBo Chen chmod +x $CH_RELEASE_NAME 127f0c5592bSMichael Zhao fi 1282b2d0065SRuslan Mstoi popd || exit 129edca82c4SBo Chen 1303c05626aSRuoqing He # Prepare linux image (build from source or download pre-built) 1313c05626aSRuoqing He prepare_linux 1322ce23137SHenry Wang 133d76d04e2SMichael Zhao # Update the kernel in the cloud image for some tests that requires recent kernel version 1341511cbdaSRob Bradford FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_NAME="focal-server-cloudimg-arm64-custom-20210929-0-update-kernel.raw" 135d76d04e2SMichael Zhao cp "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_NAME" "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_NAME" 136d76d04e2SMichael Zhao FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR="$WORKLOADS_DIR/focal-server-cloudimg-root" 137d76d04e2SMichael Zhao mkdir -p "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR" 138d76d04e2SMichael Zhao # Mount the 'raw' image, replace the compressed kernel file and umount the working folder 139d76d04e2SMichael Zhao guestmount -a "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_NAME" -m /dev/sda1 "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR" || exit 1 140*2b057537SBo Chen cp "$WORKLOADS_DIR"/Image-arm64.gz "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR"/boot/vmlinuz 141d76d04e2SMichael Zhao guestunmount "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR" 142d76d04e2SMichael Zhao 143d76d04e2SMichael Zhao # Build virtiofsd 1440fa71ddfSHenry Wang build_virtiofsd 1451908f488SRob Bradford 1462ce23137SHenry Wang BLK_IMAGE="$WORKLOADS_DIR/blk.img" 1472ce23137SHenry Wang MNT_DIR="mount_image" 1482ce23137SHenry Wang if [ ! -f "$BLK_IMAGE" ]; then 1492b2d0065SRuslan Mstoi pushd "$WORKLOADS_DIR" || exit 1502b2d0065SRuslan Mstoi fallocate -l 16M "$BLK_IMAGE" 1512b2d0065SRuslan Mstoi mkfs.ext4 -j "$BLK_IMAGE" 1522ce23137SHenry Wang mkdir $MNT_DIR 1532b2d0065SRuslan Mstoi sudo mount -t ext4 "$BLK_IMAGE" $MNT_DIR 1542ce23137SHenry Wang sudo bash -c "echo bar > $MNT_DIR/foo" || exit 1 1552b2d0065SRuslan Mstoi sudo umount "$BLK_IMAGE" 1562ce23137SHenry Wang rm -r $MNT_DIR 1572b2d0065SRuslan Mstoi popd || exit 1582ce23137SHenry Wang fi 1592ce23137SHenry Wang 1602ce23137SHenry Wang SHARED_DIR="$WORKLOADS_DIR/shared_dir" 1612ce23137SHenry Wang if [ ! -d "$SHARED_DIR" ]; then 1622b2d0065SRuslan Mstoi mkdir -p "$SHARED_DIR" 1632ce23137SHenry Wang echo "foo" >"$SHARED_DIR/file1" 1642ce23137SHenry Wang echo "bar" >"$SHARED_DIR/file3" || exit 1 1652ce23137SHenry Wang fi 1663cb2b72eSHenry Wang 1670fa71ddfSHenry Wang # Checkout and build EDK2 1683cb2b72eSHenry Wang build_edk2 1697e3cbf04SMichael Zhao} 1707e3cbf04SMichael Zhao 17127b5f8d7SMuminul Islamprocess_common_args "$@" 172c4fb0f36SMuminul Islam 173024675d1SMuminul Islam# aarch64 not supported for MSHV 174024675d1SMuminul Islamif [[ "$hypervisor" = "mshv" ]]; then 1755d536487SHenry Wang echo "AArch64 is not supported in Microsoft Hypervisor" 176024675d1SMuminul Islam exit 1 177024675d1SMuminul Islamfi 178024675d1SMuminul Islam 1797e3cbf04SMichael Zhao# lock the workloads folder to avoid parallel updating by different containers 1807e3cbf04SMichael Zhao( 1817e3cbf04SMichael Zhao echo "try to lock $WORKLOADS_DIR folder and update" 1827e3cbf04SMichael Zhao flock -x 12 && update_workloads 1832b2d0065SRuslan Mstoi) 12>"$WORKLOADS_LOCK" 1847e3cbf04SMichael Zhao 1855807a91fSHenry Wang# Check if there is any error in the execution of `update_workloads`. 1865807a91fSHenry Wang# If there is any error, then kill the shell. Otherwise the script will continue 1875807a91fSHenry Wang# running even if the `update_workloads` function was failed. 1885807a91fSHenry WangRES=$? 1895807a91fSHenry Wangif [ $RES -ne 0 ]; then 1905807a91fSHenry Wang exit 1 1915807a91fSHenry Wangfi 1925807a91fSHenry Wang 193aca6fdbdSMichael Zhaoexport RUST_BACKTRACE=1 194aca6fdbdSMichael Zhao 1952b2d0065SRuslan Mstoicargo build --all --release --target "$BUILD_TARGET" 1962ce23137SHenry Wang 1972ce23137SHenry Wang# Enable KSM with some reasonable parameters so that it won't take too long 1982ce23137SHenry Wang# for the memory to be merged between two processes. 1992ce23137SHenry Wangsudo bash -c "echo 1000000 > /sys/kernel/mm/ksm/pages_to_scan" 2002ce23137SHenry Wangsudo bash -c "echo 10 > /sys/kernel/mm/ksm/sleep_millisecs" 2012ce23137SHenry Wangsudo bash -c "echo 1 > /sys/kernel/mm/ksm/run" 2022ce23137SHenry Wang 2031c18d124SHenry Wang# Both test_vfio and ovs-dpdk rely on hugepages 204318caeb9SRuslan MstoiHUGEPAGESIZE=$(grep Hugepagesize /proc/meminfo | awk '{print $2}') 2052b2d0065SRuslan MstoiPAGE_NUM=$((12288 * 1024 / HUGEPAGESIZE)) 2062b2d0065SRuslan Mstoiecho "$PAGE_NUM" | sudo tee /proc/sys/vm/nr_hugepages 2071c18d124SHenry Wangsudo chmod a+rwX /dev/hugepages 2084db7530fSSebastien Boeuf 209fb5cbd96SHenry Wang# Run all direct kernel boot (Device Tree) test cases in mod `parallel` 21072452707SRob Bradfordtime cargo test "common_parallel::$test_filter" --target "$BUILD_TARGET" -- --test-threads=$(($(nproc) / 8)) ${test_binary_args[*]} 2112ce23137SHenry WangRES=$? 2122ce23137SHenry Wang 213eed0c927SHenry Wang# Run some tests in sequence since the result could be affected by other tests 214eed0c927SHenry Wang# running in parallel. 215eed0c927SHenry Wangif [ $RES -eq 0 ]; then 2162b2d0065SRuslan Mstoi time cargo test "common_sequential::$test_filter" --target "$BUILD_TARGET" -- --test-threads=1 ${test_binary_args[*]} 217eed0c927SHenry Wang RES=$? 218eed0c927SHenry Wangelse 219eed0c927SHenry Wang exit $RES 220eed0c927SHenry Wangfi 221eed0c927SHenry Wang 222fb5cbd96SHenry Wang# Run all ACPI test cases 223fb5cbd96SHenry Wangif [ $RES -eq 0 ]; then 2242b2d0065SRuslan Mstoi time cargo test "aarch64_acpi::$test_filter" --target "$BUILD_TARGET" -- ${test_binary_args[*]} 225fb5cbd96SHenry Wang RES=$? 226fb5cbd96SHenry Wangelse 227fb5cbd96SHenry Wang exit $RES 228fb5cbd96SHenry Wangfi 229fb5cbd96SHenry Wang 230fb5cbd96SHenry Wang# Run all test cases related to live migration 2315d536487SHenry Wangif [ $RES -eq 0 ]; then 2322b2d0065SRuslan Mstoi time cargo test "live_migration_parallel::$test_filter" --target "$BUILD_TARGET" -- ${test_binary_args[*]} 2338f3462b3SBo Chen RES=$? 2348f3462b3SBo Chenelse 2358f3462b3SBo Chen exit $RES 2368f3462b3SBo Chenfi 2378f3462b3SBo Chen 2388f3462b3SBo Chenif [ $RES -eq 0 ]; then 2392b2d0065SRuslan Mstoi time cargo test "live_migration_sequential::$test_filter" --target "$BUILD_TARGET" -- --test-threads=1 ${test_binary_args[*]} 2405d536487SHenry Wang RES=$? 2415d536487SHenry Wangelse 2425d536487SHenry Wang exit $RES 2435d536487SHenry Wangfi 2445d536487SHenry Wang 2451faaa2cdSBo Chen# Run tests on dbus_api 2461faaa2cdSBo Chenif [ $RES -eq 0 ]; then 2472b2d0065SRuslan Mstoi cargo build --features "dbus_api" --all --release --target "$BUILD_TARGET" 2481faaa2cdSBo Chen export RUST_BACKTRACE=1 2492b2d0065SRuslan Mstoi time cargo test "dbus_api::$test_filter" --target "$BUILD_TARGET" -- ${test_binary_args[*]} 2501faaa2cdSBo Chen RES=$? 2511faaa2cdSBo Chenfi 2521faaa2cdSBo Chen 2532ce23137SHenry Wangexit $RES 254