xref: /cloud-hypervisor/scripts/run_integration_tests_live_migration.sh (revision 6f8bd27cf7629733582d930519e98d19e90afb16)
1#!/bin/bash
2set -x
3
4source $HOME/.cargo/env
5source $(dirname "$0")/test-util.sh
6
7export BUILD_TARGET=${BUILD_TARGET-x86_64-unknown-linux-gnu}
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="--no-default-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://cloud-hypervisor.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
28    time wget --quiet $FOCAL_OS_IMAGE_URL || exit 1
29    popd
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
36    time qemu-img convert -p -f qcow2 -O raw $FOCAL_OS_IMAGE_NAME $FOCAL_OS_RAW_IMAGE_NAME || exit 1
37    popd
38fi
39
40pushd $WORKLOADS_DIR
41grep focal sha1sums-x86_64 | sha1sum --check
42if [ $? -ne 0 ]; then
43    echo "sha1sum validation of images failed, remove invalid images to fix the issue."
44    exit 1
45fi
46popd
47
48# Download Cloud Hypervisor binary from its last stable release
49LAST_RELEASE_VERSION="v26.0"
50CH_RELEASE_URL="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/$LAST_RELEASE_VERSION/cloud-hypervisor-static"
51CH_RELEASE_NAME="cloud-hypervisor-static"
52pushd $WORKLOADS_DIR
53time wget --quiet $CH_RELEASE_URL -O "$CH_RELEASE_NAME" || exit 1
54chmod +x $CH_RELEASE_NAME
55popd
56
57# Build custom kernel based on virtio-pmem and virtio-fs upstream patches
58VMLINUX_IMAGE="$WORKLOADS_DIR/vmlinux"
59
60LINUX_CUSTOM_DIR="$WORKLOADS_DIR/linux-custom"
61
62if [ ! -f "$VMLINUX_IMAGE" ]; then
63    SRCDIR=$PWD
64    pushd $WORKLOADS_DIR
65    time git clone --depth 1 "https://github.com/cloud-hypervisor/linux.git" -b "ch-5.15.12" $LINUX_CUSTOM_DIR
66    cp $SRCDIR/resources/linux-config-x86_64 $LINUX_CUSTOM_DIR/.config
67    popd
68fi
69
70if [ ! -f "$VMLINUX_IMAGE" ]; then
71    pushd $LINUX_CUSTOM_DIR
72    time make bzImage -j `nproc`
73    cp vmlinux $VMLINUX_IMAGE || exit 1
74    popd
75fi
76
77if [ -d "$LINUX_CUSTOM_DIR" ]; then
78    rm -rf $LINUX_CUSTOM_DIR
79fi
80
81BUILD_TARGET="$(uname -m)-unknown-linux-${CH_LIBC}"
82CFLAGS=""
83TARGET_CC=""
84if [[ "${BUILD_TARGET}" == "x86_64-unknown-linux-musl" ]]; then
85    TARGET_CC="musl-gcc"
86    CFLAGS="-I /usr/include/x86_64-linux-musl/ -idirafter /usr/include/"
87fi
88
89cargo build --no-default-features --features "kvm,mshv" --all --release --target $BUILD_TARGET
90
91# Test ovs-dpdk relies on hugepages
92echo 6144 | sudo tee /proc/sys/vm/nr_hugepages
93sudo chmod a+rwX /dev/hugepages
94
95export RUST_BACKTRACE=1
96time cargo test $test_features "live_migration_parallel::$test_filter" -- ${test_binary_args[*]}
97RES=$?
98
99# Run some tests in sequence since the result could be affected by other tests
100# running in parallel.
101if [ $RES -eq 0 ]; then
102    export RUST_BACKTRACE=1
103    time cargo test $test_features "live_migration_sequential::$test_filter" -- --test-threads=1 ${test_binary_args[*]}
104    RES=$?
105fi
106
107exit $RES
108