xref: /cloud-hypervisor/scripts/run_integration_tests_live_migration.sh (revision fa7a000dbe9637eb256af18ae8c3c4a8d5bf9c8f)
1#!/usr/bin/env bash
2# shellcheck disable=SC2048,SC2086
3set -x
4
5# shellcheck source=/dev/null
6source "$HOME"/.cargo/env
7source "$(dirname "$0")"/test-util.sh
8
9WORKLOADS_DIR="$HOME/workloads"
10mkdir -p "$WORKLOADS_DIR"
11
12process_common_args "$@"
13
14# For now these values are default for kvm
15test_features=""
16
17if [ "$hypervisor" = "mshv" ]; then
18    test_features="--features mshv"
19fi
20
21cp scripts/sha1sums-x86_64 "$WORKLOADS_DIR"
22
23FOCAL_OS_IMAGE_NAME="focal-server-cloudimg-amd64-custom-20210609-0.qcow2"
24FOCAL_OS_IMAGE_URL="https://ch-images.azureedge.net/$FOCAL_OS_IMAGE_NAME"
25FOCAL_OS_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_IMAGE_NAME"
26if [ ! -f "$FOCAL_OS_IMAGE" ]; then
27    pushd "$WORKLOADS_DIR" || exit
28    time wget --quiet $FOCAL_OS_IMAGE_URL || exit 1
29    popd || exit
30fi
31
32FOCAL_OS_RAW_IMAGE_NAME="focal-server-cloudimg-amd64-custom-20210609-0.raw"
33FOCAL_OS_RAW_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_NAME"
34if [ ! -f "$FOCAL_OS_RAW_IMAGE" ]; then
35    pushd "$WORKLOADS_DIR" || exit
36    time qemu-img convert -p -f qcow2 -O raw $FOCAL_OS_IMAGE_NAME $FOCAL_OS_RAW_IMAGE_NAME || exit 1
37    popd || exit
38fi
39
40pushd "$WORKLOADS_DIR" || exit
41if ! grep focal sha1sums-x86_64 | sha1sum --check; then
42    echo "sha1sum validation of images failed, remove invalid images to fix the issue."
43    exit 1
44fi
45popd || exit
46
47# Download Cloud Hypervisor binary from its last stable release
48LAST_RELEASE_VERSION="v36.0"
49CH_RELEASE_URL="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/$LAST_RELEASE_VERSION/cloud-hypervisor-static"
50CH_RELEASE_NAME="cloud-hypervisor-static"
51pushd "$WORKLOADS_DIR" || exit
52time wget --quiet $CH_RELEASE_URL -O "$CH_RELEASE_NAME" || exit 1
53chmod +x $CH_RELEASE_NAME
54popd || exit
55
56# Build custom kernel based on virtio-pmem and virtio-fs upstream patches
57VMLINUX_IMAGE="$WORKLOADS_DIR/vmlinux"
58if [ ! -f "$VMLINUX_IMAGE" ]; then
59    build_custom_linux
60fi
61
62CFLAGS=""
63if [[ "${BUILD_TARGET}" == "x86_64-unknown-linux-musl" ]]; then
64    # shellcheck disable=SC2034
65    CFLAGS="-I /usr/include/x86_64-linux-musl/ -idirafter /usr/include/"
66fi
67
68cargo build --features mshv --all --release --target "$BUILD_TARGET"
69
70# Test ovs-dpdk relies on hugepages
71HUGEPAGESIZE=$(grep Hugepagesize /proc/meminfo | awk '{print $2}')
72PAGE_NUM=$((12288 * 1024 / HUGEPAGESIZE))
73echo "$PAGE_NUM" | sudo tee /proc/sys/vm/nr_hugepages
74sudo chmod a+rwX /dev/hugepages
75
76export RUST_BACKTRACE=1
77time cargo test $test_features "live_migration_parallel::$test_filter" -- ${test_binary_args[*]}
78RES=$?
79
80# Run some tests in sequence since the result could be affected by other tests
81# running in parallel.
82if [ $RES -eq 0 ]; then
83    export RUST_BACKTRACE=1
84    time cargo test $test_features "live_migration_sequential::$test_filter" -- --test-threads=1 ${test_binary_args[*]}
85    RES=$?
86fi
87
88exit $RES
89