xref: /cloud-hypervisor/scripts/run_integration_tests_live_migration.sh (revision 2b05753716936506ed440863fe6a29dfc7a427e2)
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="v39.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-x86_64"
58if [ ! -f "$VMLINUX_IMAGE" ]; then
59    # Prepare linux image (build from source or download pre-built)
60    prepare_linux
61fi
62
63CFLAGS=""
64if [[ "${BUILD_TARGET}" == "x86_64-unknown-linux-musl" ]]; then
65    # shellcheck disable=SC2034
66    CFLAGS="-I /usr/include/x86_64-linux-musl/ -idirafter /usr/include/"
67fi
68
69cargo build --features mshv --all --release --target "$BUILD_TARGET"
70
71# Test ovs-dpdk relies on hugepages
72HUGEPAGESIZE=$(grep Hugepagesize /proc/meminfo | awk '{print $2}')
73PAGE_NUM=$((12288 * 1024 / HUGEPAGESIZE))
74echo "$PAGE_NUM" | sudo tee /proc/sys/vm/nr_hugepages
75sudo chmod a+rwX /dev/hugepages
76
77export RUST_BACKTRACE=1
78time cargo test $test_features "live_migration_parallel::$test_filter" -- ${test_binary_args[*]}
79RES=$?
80
81# Run some tests in sequence since the result could be affected by other tests
82# running in parallel.
83if [ $RES -eq 0 ]; then
84    export RUST_BACKTRACE=1
85    time cargo test $test_features "live_migration_sequential::$test_filter" -- --test-threads=1 ${test_binary_args[*]}
86    RES=$?
87fi
88
89exit $RES
90