xref: /cloud-hypervisor/scripts/run_integration_tests_aarch64.sh (revision 4d7a4c598ac247aaf770b00dfb057cdac891f67d)
1#!/bin/bash
2set -x
3
4source $HOME/.cargo/env
5source $(dirname "$0")/test-util.sh
6source $(dirname "$0")/common-aarch64.sh
7
8WORKLOADS_LOCK="$WORKLOADS_DIR/integration_test.lock"
9
10build_spdk_nvme() {
11    SPDK_DIR="$WORKLOADS_DIR/spdk"
12    SPDK_REPO="https://github.com/spdk/spdk.git"
13    SPDK_DEPLOY_DIR="/usr/local/bin/spdk-nvme"
14    checkout_repo "$SPDK_DIR" "$SPDK_REPO" master "ef8bcce58f3f02b79c0619a297e4f17e81e62b24"
15
16    if [ ! -f "$SPDK_DIR/.built" ]; then
17        pushd $SPDK_DIR
18        git submodule update --init
19        apt-get update
20        sed -i "/grpcio/d" scripts/pkgdep/debian.sh
21        ./scripts/pkgdep.sh
22        ./configure --with-vfio-user
23        chmod +x /usr/local/lib/python3.8/dist-packages/ninja/data/bin/ninja
24        make -j `nproc` || exit 1
25        touch .built
26        popd
27    fi
28    if [ ! -d "/usr/local/bin/spdk-nvme" ]; then
29        mkdir -p $SPDK_DEPLOY_DIR
30    fi
31    cp "$WORKLOADS_DIR/spdk/build/bin/nvmf_tgt" $SPDK_DEPLOY_DIR/nvmf_tgt
32    cp "$WORKLOADS_DIR/spdk/scripts/rpc.py" $SPDK_DEPLOY_DIR/rpc.py
33    cp -r "$WORKLOADS_DIR/spdk/scripts/rpc" $SPDK_DEPLOY_DIR/rpc
34    cp -r "$WORKLOADS_DIR/spdk/python" $SPDK_DEPLOY_DIR/../
35}
36
37build_virtiofsd() {
38    VIRTIOFSD_DIR="$WORKLOADS_DIR/virtiofsd_build"
39    VIRTIOFSD_REPO="https://gitlab.com/virtio-fs/virtiofsd.git"
40
41    checkout_repo "$VIRTIOFSD_DIR" "$VIRTIOFSD_REPO" v1.1.0 "220405d7a2606c92636d31992b5cb3036a41047b"
42
43    if [ ! -f "$VIRTIOFSD_DIR/.built" ]; then
44        pushd $VIRTIOFSD_DIR
45        rm -rf target/
46        time RUSTFLAGS="" TARGET_CC="" cargo build --release
47        cp target/release/virtiofsd "$WORKLOADS_DIR/" || exit 1
48        touch .built
49        popd
50    fi
51}
52
53update_workloads() {
54    cp scripts/sha1sums-aarch64 $WORKLOADS_DIR
55
56    BIONIC_OS_IMAGE_DOWNLOAD_NAME="bionic-server-cloudimg-arm64.img"
57    BIONIC_OS_IMAGE_DOWNLOAD_URL="https://cloud-hypervisor.azureedge.net/$BIONIC_OS_IMAGE_DOWNLOAD_NAME"
58    BIONIC_OS_DOWNLOAD_IMAGE="$WORKLOADS_DIR/$BIONIC_OS_IMAGE_DOWNLOAD_NAME"
59    if [ ! -f "$BIONIC_OS_DOWNLOAD_IMAGE" ]; then
60        pushd $WORKLOADS_DIR
61        time wget --quiet $BIONIC_OS_IMAGE_DOWNLOAD_URL || exit 1
62        popd
63    fi
64
65    BIONIC_OS_RAW_IMAGE_NAME="bionic-server-cloudimg-arm64.raw"
66    BIONIC_OS_RAW_IMAGE="$WORKLOADS_DIR/$BIONIC_OS_RAW_IMAGE_NAME"
67    if [ ! -f "$BIONIC_OS_RAW_IMAGE" ]; then
68        pushd $WORKLOADS_DIR
69        time qemu-img convert -p -f qcow2 -O raw $BIONIC_OS_IMAGE_DOWNLOAD_NAME $BIONIC_OS_RAW_IMAGE_NAME || exit 1
70        popd
71    fi
72
73    # Convert the raw image to qcow2 image to remove compressed blocks from the disk. Therefore letting the
74    # qcow2 format image can be directly used in the integration test.
75    BIONIC_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME="bionic-server-cloudimg-arm64.qcow2"
76    BIONIC_OS_QCOW2_UNCOMPRESSED_IMAGE="$WORKLOADS_DIR/$BIONIC_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME"
77    if [ ! -f "$BIONIC_OS_QCOW2_UNCOMPRESSED_IMAGE" ]; then
78        pushd $WORKLOADS_DIR
79        time qemu-img convert -p -f raw -O qcow2 $BIONIC_OS_RAW_IMAGE_NAME $BIONIC_OS_QCOW2_UNCOMPRESSED_IMAGE || exit 1
80        popd
81    fi
82
83    FOCAL_OS_RAW_IMAGE_NAME="focal-server-cloudimg-arm64-custom-20210929-0.raw"
84    FOCAL_OS_RAW_IMAGE_DOWNLOAD_URL="https://cloud-hypervisor.azureedge.net/$FOCAL_OS_RAW_IMAGE_NAME"
85    FOCAL_OS_RAW_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_NAME"
86    if [ ! -f "$FOCAL_OS_RAW_IMAGE" ]; then
87        pushd $WORKLOADS_DIR
88        time wget --quiet $FOCAL_OS_RAW_IMAGE_DOWNLOAD_URL || exit 1
89        popd
90    fi
91
92    FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME="focal-server-cloudimg-arm64-custom-20210929-0.qcow2"
93    FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL="https://cloud-hypervisor.azureedge.net/$FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME"
94    FOCAL_OS_QCOW2_UNCOMPRESSED_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME"
95    if [ ! -f "$FOCAL_OS_QCOW2_UNCOMPRESSED_IMAGE" ]; then
96        pushd $WORKLOADS_DIR
97        time wget --quiet $FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL || exit 1
98        popd
99    fi
100
101    FOCAL_OS_QCOW2_IMAGE_BACKING_FILE_NAME="focal-server-cloudimg-arm64-custom-20210929-0-backing.qcow2"
102    FOCAL_OS_QCOW2_BACKING_FILE_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_QCOW2_IMAGE_BACKING_FILE_NAME"
103    if [ ! -f "$FOCAL_OS_QCOW2_BACKING_FILE_IMAGE" ]; then
104        pushd $WORKLOADS_DIR
105        time qemu-img create -f qcow2 -b $FOCAL_OS_QCOW2_UNCOMPRESSED_IMAGE -F qcow2 $FOCAL_OS_QCOW2_IMAGE_BACKING_FILE_NAME
106        popd
107    fi
108
109    JAMMY_OS_RAW_IMAGE_NAME="jammy-server-cloudimg-arm64-custom-20220329-0.raw"
110    JAMMY_OS_RAW_IMAGE_DOWNLOAD_URL="https://cloud-hypervisor.azureedge.net/$JAMMY_OS_RAW_IMAGE_NAME"
111    JAMMY_OS_RAW_IMAGE="$WORKLOADS_DIR/$JAMMY_OS_RAW_IMAGE_NAME"
112    if [ ! -f "$JAMMY_OS_RAW_IMAGE" ]; then
113        pushd $WORKLOADS_DIR
114        time wget --quiet $JAMMY_OS_RAW_IMAGE_DOWNLOAD_URL || exit 1
115        popd
116    fi
117
118    JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME="jammy-server-cloudimg-arm64-custom-20220329-0.qcow2"
119    JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL="https://cloud-hypervisor.azureedge.net/$JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME"
120    JAMMY_OS_QCOW2_UNCOMPRESSED_IMAGE="$WORKLOADS_DIR/$JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME"
121    if [ ! -f "$JAMMY_OS_QCOW2_UNCOMPRESSED_IMAGE" ]; then
122        pushd $WORKLOADS_DIR
123        time wget --quiet $JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL || exit 1
124        popd
125    fi
126
127    ALPINE_MINIROOTFS_URL="http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/aarch64/alpine-minirootfs-3.11.3-aarch64.tar.gz"
128    ALPINE_MINIROOTFS_TARBALL="$WORKLOADS_DIR/alpine-minirootfs-aarch64.tar.gz"
129    if [ ! -f "$ALPINE_MINIROOTFS_TARBALL" ]; then
130        pushd $WORKLOADS_DIR
131        time wget --quiet $ALPINE_MINIROOTFS_URL -O $ALPINE_MINIROOTFS_TARBALL || exit 1
132        popd
133    fi
134
135    ALPINE_INITRAMFS_IMAGE="$WORKLOADS_DIR/alpine_initramfs.img"
136    if [ ! -f "$ALPINE_INITRAMFS_IMAGE" ]; then
137        pushd $WORKLOADS_DIR
138        mkdir alpine-minirootfs
139        tar xf "$ALPINE_MINIROOTFS_TARBALL" -C alpine-minirootfs
140        cat > alpine-minirootfs/init <<-EOF
141			#! /bin/sh
142			mount -t devtmpfs dev /dev
143			echo \$TEST_STRING > /dev/console
144			poweroff -f
145		EOF
146        chmod +x alpine-minirootfs/init
147        cd alpine-minirootfs
148        find . -print0 |
149            cpio --null --create --verbose --owner root:root --format=newc > "$ALPINE_INITRAMFS_IMAGE"
150        popd
151    fi
152
153    pushd $WORKLOADS_DIR
154    sha1sum sha1sums-aarch64 --check
155    if [ $? -ne 0 ]; then
156        echo "sha1sum validation of images failed, remove invalid images to fix the issue."
157        exit 1
158    fi
159    popd
160
161    # Download Cloud Hypervisor binary from its last stable release
162    LAST_RELEASE_VERSION="v34.0"
163    CH_RELEASE_URL="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/$LAST_RELEASE_VERSION/cloud-hypervisor-static-aarch64"
164    CH_RELEASE_NAME="cloud-hypervisor-static-aarch64"
165    pushd $WORKLOADS_DIR
166    time wget --quiet $CH_RELEASE_URL -O "$CH_RELEASE_NAME" || exit 1
167    chmod +x $CH_RELEASE_NAME
168    popd
169
170    # Build custom kernel for guest VMs
171    build_custom_linux
172
173    # Update the kernel in the cloud image for some tests that requires recent kernel version
174    FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_NAME="focal-server-cloudimg-arm64-custom-20210929-0-update-kernel.raw"
175    cp "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_NAME" "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_NAME"
176    FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR="$WORKLOADS_DIR/focal-server-cloudimg-root"
177    mkdir -p "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR"
178    # Mount the 'raw' image, replace the compressed kernel file and umount the working folder
179    guestmount -a "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_NAME" -m /dev/sda1 "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR" || exit 1
180    cp "$WORKLOADS_DIR"/Image.gz "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR"/boot/vmlinuz
181    guestunmount "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR"
182
183    # Build virtiofsd
184    build_virtiofsd
185
186    BLK_IMAGE="$WORKLOADS_DIR/blk.img"
187    MNT_DIR="mount_image"
188    if [ ! -f "$BLK_IMAGE" ]; then
189        pushd $WORKLOADS_DIR
190        fallocate -l 16M $BLK_IMAGE
191        mkfs.ext4 -j $BLK_IMAGE
192        mkdir $MNT_DIR
193        sudo mount -t ext4 $BLK_IMAGE $MNT_DIR
194        sudo bash -c "echo bar > $MNT_DIR/foo" || exit 1
195        sudo umount $BLK_IMAGE
196        rm -r $MNT_DIR
197        popd
198    fi
199
200    SHARED_DIR="$WORKLOADS_DIR/shared_dir"
201    if [ ! -d "$SHARED_DIR" ]; then
202        mkdir -p $SHARED_DIR
203        echo "foo" > "$SHARED_DIR/file1"
204        echo "bar" > "$SHARED_DIR/file3" || exit 1
205    fi
206
207    # Checkout and build SPDK NVMe
208    build_spdk_nvme
209
210    # Checkout and build EDK2
211    build_edk2
212}
213
214process_common_args "$@"
215
216# aarch64 not supported for MSHV
217if [[ "$hypervisor" = "mshv" ]]; then
218    echo "AArch64 is not supported in Microsoft Hypervisor"
219    exit 1
220fi
221
222
223# lock the workloads folder to avoid parallel updating by different containers
224(
225    echo "try to lock $WORKLOADS_DIR folder and update"
226    flock -x 12 && update_workloads
227) 12>$WORKLOADS_LOCK
228
229# Check if there is any error in the execution of `update_workloads`.
230# If there is any error, then kill the shell. Otherwise the script will continue
231# running even if the `update_workloads` function was failed.
232RES=$?
233if [ $RES -ne 0 ]; then
234    exit 1
235fi
236
237export RUST_BACKTRACE=1
238
239cargo build --all --release --target $BUILD_TARGET
240
241# Enable KSM with some reasonable parameters so that it won't take too long
242# for the memory to be merged between two processes.
243sudo bash -c "echo 1000000 > /sys/kernel/mm/ksm/pages_to_scan"
244sudo bash -c "echo 10 > /sys/kernel/mm/ksm/sleep_millisecs"
245sudo bash -c "echo 1 > /sys/kernel/mm/ksm/run"
246
247# Both test_vfio and ovs-dpdk rely on hugepages
248HUGEPAGESIZE=`grep Hugepagesize /proc/meminfo | awk '{print $2}'`
249PAGE_NUM=`echo $((12288 * 1024 / $HUGEPAGESIZE))`
250echo $PAGE_NUM | sudo tee /proc/sys/vm/nr_hugepages
251sudo chmod a+rwX /dev/hugepages
252
253# Run all direct kernel boot (Device Tree) test cases in mod `parallel`
254time cargo test "common_parallel::$test_filter" --target $BUILD_TARGET -- ${test_binary_args[*]}
255RES=$?
256
257# Run some tests in sequence since the result could be affected by other tests
258# running in parallel.
259if [ $RES -eq 0 ]; then
260    time cargo test "common_sequential::$test_filter" --target $BUILD_TARGET -- --test-threads=1 ${test_binary_args[*]}
261    RES=$?
262else
263    exit $RES
264fi
265
266# Run all ACPI test cases
267if [ $RES -eq 0 ]; then
268    time cargo test "aarch64_acpi::$test_filter" --target $BUILD_TARGET -- ${test_binary_args[*]}
269    RES=$?
270else
271    exit $RES
272fi
273
274# Run all test cases related to live migration
275if [ $RES -eq 0 ]; then
276    time cargo test "live_migration_parallel::$test_filter" --target $BUILD_TARGET -- ${test_binary_args[*]}
277    RES=$?
278else
279    exit $RES
280fi
281
282if [ $RES -eq 0 ]; then
283    time cargo test "live_migration_sequential::$test_filter" --target $BUILD_TARGET -- --test-threads=1 ${test_binary_args[*]}
284    RES=$?
285else
286    exit $RES
287fi
288
289# Run tests on dbus_api
290if [ $RES -eq 0 ]; then
291    cargo build --features "dbus_api" --all --release --target $BUILD_TARGET
292    export RUST_BACKTRACE=1
293    time cargo test "dbus_api::$test_filter" --target $BUILD_TARGET -- ${test_binary_args[*]}
294    RES=$?
295fi
296
297exit $RES
298