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