xref: /cloud-hypervisor/scripts/run_integration_tests_aarch64.sh (revision 6f8bd27cf7629733582d930519e98d19e90afb16)
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    JAMMY_OS_RAW_IMAGE_NAME="jammy-server-cloudimg-arm64-custom-20220329-0.raw"
99    JAMMY_OS_RAW_IMAGE_DOWNLOAD_URL="https://cloud-hypervisor.azureedge.net/$JAMMY_OS_RAW_IMAGE_NAME"
100    JAMMY_OS_RAW_IMAGE="$WORKLOADS_DIR/$JAMMY_OS_RAW_IMAGE_NAME"
101    if [ ! -f "$JAMMY_OS_RAW_IMAGE" ]; then
102        pushd $WORKLOADS_DIR
103        time wget --quiet $JAMMY_OS_RAW_IMAGE_DOWNLOAD_URL || exit 1
104        popd
105    fi
106
107    JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME="jammy-server-cloudimg-arm64-custom-20220329-0.qcow2"
108    JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL="https://cloud-hypervisor.azureedge.net/$JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME"
109    JAMMY_OS_QCOW2_UNCOMPRESSED_IMAGE="$WORKLOADS_DIR/$JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME"
110    if [ ! -f "$JAMMY_OS_QCOW2_UNCOMPRESSED_IMAGE" ]; then
111        pushd $WORKLOADS_DIR
112        time wget --quiet $JAMMY_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL || exit 1
113        popd
114    fi
115
116    ALPINE_MINIROOTFS_URL="http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/aarch64/alpine-minirootfs-3.11.3-aarch64.tar.gz"
117    ALPINE_MINIROOTFS_TARBALL="$WORKLOADS_DIR/alpine-minirootfs-aarch64.tar.gz"
118    if [ ! -f "$ALPINE_MINIROOTFS_TARBALL" ]; then
119        pushd $WORKLOADS_DIR
120        time wget --quiet $ALPINE_MINIROOTFS_URL -O $ALPINE_MINIROOTFS_TARBALL || exit 1
121        popd
122    fi
123
124    ALPINE_INITRAMFS_IMAGE="$WORKLOADS_DIR/alpine_initramfs.img"
125    if [ ! -f "$ALPINE_INITRAMFS_IMAGE" ]; then
126        pushd $WORKLOADS_DIR
127        mkdir alpine-minirootfs
128        tar xf "$ALPINE_MINIROOTFS_TARBALL" -C alpine-minirootfs
129        cat > alpine-minirootfs/init <<-EOF
130			#! /bin/sh
131			mount -t devtmpfs dev /dev
132			echo \$TEST_STRING > /dev/console
133			poweroff -f
134		EOF
135        chmod +x alpine-minirootfs/init
136        cd alpine-minirootfs
137        find . -print0 |
138            cpio --null --create --verbose --owner root:root --format=newc > "$ALPINE_INITRAMFS_IMAGE"
139        popd
140    fi
141
142    pushd $WORKLOADS_DIR
143    sha1sum sha1sums-aarch64 --check
144    if [ $? -ne 0 ]; then
145        echo "sha1sum validation of images failed, remove invalid images to fix the issue."
146        exit 1
147    fi
148    popd
149
150    # Download Cloud Hypervisor binary from its last stable release
151    LAST_RELEASE_VERSION="v26.0"
152    CH_RELEASE_URL="https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/$LAST_RELEASE_VERSION/cloud-hypervisor-static-aarch64"
153    CH_RELEASE_NAME="cloud-hypervisor-static-aarch64"
154    pushd $WORKLOADS_DIR
155    time wget --quiet $CH_RELEASE_URL -O "$CH_RELEASE_NAME" || exit 1
156    chmod +x $CH_RELEASE_NAME
157    popd
158
159    # Build custom kernel for guest VMs
160    build_custom_linux
161
162    # Update the kernel in the cloud image for some tests that requires recent kernel version
163    FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_NAME="focal-server-cloudimg-arm64-custom-20210929-0-update-kernel.raw"
164    cp "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_NAME" "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_NAME"
165    FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR="$WORKLOADS_DIR/focal-server-cloudimg-root"
166    mkdir -p "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR"
167    # Mount the 'raw' image, replace the compressed kernel file and umount the working folder
168    guestmount -a "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_NAME" -m /dev/sda1 "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR" || exit 1
169    cp "$WORKLOADS_DIR"/Image.gz "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR"/boot/vmlinuz
170    guestunmount "$FOCAL_OS_RAW_IMAGE_UPDATE_KERNEL_ROOT_DIR"
171
172    # Build virtiofsd
173    build_virtiofsd
174
175    BLK_IMAGE="$WORKLOADS_DIR/blk.img"
176    MNT_DIR="mount_image"
177    if [ ! -f "$BLK_IMAGE" ]; then
178        pushd $WORKLOADS_DIR
179        fallocate -l 16M $BLK_IMAGE
180        mkfs.ext4 -j $BLK_IMAGE
181        mkdir $MNT_DIR
182        sudo mount -t ext4 $BLK_IMAGE $MNT_DIR
183        sudo bash -c "echo bar > $MNT_DIR/foo" || exit 1
184        sudo umount $BLK_IMAGE
185        rm -r $MNT_DIR
186        popd
187    fi
188
189    SHARED_DIR="$WORKLOADS_DIR/shared_dir"
190    if [ ! -d "$SHARED_DIR" ]; then
191        mkdir -p $SHARED_DIR
192        echo "foo" > "$SHARED_DIR/file1"
193        echo "bar" > "$SHARED_DIR/file3" || exit 1
194    fi
195
196    # Checkout and build SPDK NVMe
197    build_spdk_nvme
198
199    # Checkout and build EDK2
200    build_edk2
201}
202
203process_common_args "$@"
204
205# aarch64 not supported for MSHV
206if [[ "$hypervisor" = "mshv" ]]; then
207    echo "AArch64 is not supported in Microsoft Hypervisor"
208    exit 1
209fi
210
211
212# lock the workloads folder to avoid parallel updating by different containers
213(
214    echo "try to lock $WORKLOADS_DIR folder and update"
215    flock -x 12 && update_workloads
216) 12>$WORKLOADS_LOCK
217
218# Check if there is any error in the execution of `update_workloads`.
219# If there is any error, then kill the shell. Otherwise the script will continue
220# running even if the `update_workloads` function was failed.
221RES=$?
222if [ $RES -ne 0 ]; then
223    exit 1
224fi
225
226BUILD_TARGET="aarch64-unknown-linux-${CH_LIBC}"
227if [[ "${BUILD_TARGET}" == "aarch64-unknown-linux-musl" ]]; then
228export TARGET_CC="musl-gcc"
229export RUSTFLAGS="-C link-arg=-lgcc -C link_arg=-specs -C link_arg=/usr/lib/aarch64-linux-musl/musl-gcc.specs"
230fi
231
232export RUST_BACKTRACE=1
233
234cargo build --all --release --target $BUILD_TARGET
235
236# Enable KSM with some reasonable parameters so that it won't take too long
237# for the memory to be merged between two processes.
238sudo bash -c "echo 1000000 > /sys/kernel/mm/ksm/pages_to_scan"
239sudo bash -c "echo 10 > /sys/kernel/mm/ksm/sleep_millisecs"
240sudo bash -c "echo 1 > /sys/kernel/mm/ksm/run"
241
242# Both test_vfio and ovs-dpdk rely on hugepages
243echo 6144 | sudo tee /proc/sys/vm/nr_hugepages
244sudo chmod a+rwX /dev/hugepages
245
246# Run all direct kernel boot (Device Tree) test cases in mod `parallel`
247time cargo test "common_parallel::$test_filter" --target $BUILD_TARGET -- ${test_binary_args[*]}
248RES=$?
249
250# Run some tests in sequence since the result could be affected by other tests
251# running in parallel.
252if [ $RES -eq 0 ]; then
253    time cargo test "common_sequential::$test_filter" --target $BUILD_TARGET -- --test-threads=1 ${test_binary_args[*]}
254    RES=$?
255else
256    exit $RES
257fi
258
259# Run all ACPI test cases
260if [ $RES -eq 0 ]; then
261    time cargo test "aarch64_acpi::$test_filter" --target $BUILD_TARGET -- ${test_binary_args[*]}
262    RES=$?
263else
264    exit $RES
265fi
266
267# Run all test cases related to live migration
268if [ $RES -eq 0 ]; then
269    time cargo test "live_migration_parallel::$test_filter" --target $BUILD_TARGET -- ${test_binary_args[*]}
270    RES=$?
271else
272    exit $RES
273fi
274
275if [ $RES -eq 0 ]; then
276    time cargo test "live_migration_sequential::$test_filter" --target $BUILD_TARGET -- --test-threads=1 ${test_binary_args[*]}
277    RES=$?
278else
279    exit $RES
280fi
281
282exit $RES
283