xref: /cloud-hypervisor/scripts/run_integration_tests_aarch64.sh (revision f67b3f79ea19c9a66e04074cbbf5d292f6529e43)
1#!/bin/bash
2set -x
3
4source $HOME/.cargo/env
5source $(dirname "$0")/test-util.sh
6
7export BUILD_TARGET=${BUILD_TARGET-aarch64-unknown-linux-gnu}
8
9WORKLOADS_DIR="$HOME/workloads"
10WORKLOADS_LOCK="$WORKLOADS_DIR/integration_test.lock"
11EDK2_BUILD_DIR="$WORKLOADS_DIR/edk2_build"
12
13mkdir -p "$WORKLOADS_DIR"
14
15build_edk2() {
16    EDK2_REPO="https://github.com/tianocore/edk2.git"
17    EDK2_DIR="edk2"
18    EDK2_BRANCH="master"
19    EDK2_PLAT_REPO="https://github.com/tianocore/edk2-platforms.git"
20    EDK2_PLAT_DIR="edk2-platforms"
21    ACPICA_REPO="https://github.com/acpica/acpica.git"
22    ACPICA_DIR="acpica"
23
24    export WORKSPACE="$EDK2_BUILD_DIR"
25    export PACKAGES_PATH="$WORKSPACE/$EDK2_DIR:$WORKSPACE/$EDK2_PLAT_DIR"
26    export IASL_PREFIX="$WORKSPACE/acpica/generate/unix/bin/"
27
28    cd "$WORKLOADS_DIR"
29    if [ ! -d "$WORKSPACE" ]; then
30        mkdir -p "$WORKSPACE"
31    fi
32
33    pushd "$WORKSPACE"
34
35    # Check whether the local HEAD commit same as the remote HEAD or not. Remove the folder if they are different.
36    if [ -d "$EDK2_DIR" ]; then
37        pushd $EDK2_DIR
38        git fetch
39        EDK2_LOCAL_HEAD=$(git rev-parse HEAD)
40        EDK2_REMOTE_HEAD=$(git rev-parse remotes/origin/$EDK2_BRANCH)
41        popd
42        if [ "$EDK2_LOCAL_HEAD" != "$EDK2_REMOTE_HEAD" ]; then
43            # If EDK2 code is out of date, remove and rebuild all
44            rm -rf "$EDK2_DIR"
45            rm -rf "$EDK2_PLAT_DIR"
46            rm -rf "$ACPICA_DIR"
47        fi
48    fi
49
50    if [ ! -d "$EDK2_DIR" ]; then
51        time git clone --depth 1 "$EDK2_REPO" -b "$EDK2_BRANCH" "$EDK2_DIR"
52        pushd $EDK2_DIR
53        git submodule update --init
54        popd
55    fi
56
57    if [ ! -d "$EDK2_PLAT_DIR" ]; then
58        time git clone --depth 1 "$EDK2_PLAT_REPO" -b master "$EDK2_PLAT_DIR"
59    fi
60
61    if [ ! -d "$ACPICA_DIR" ]; then
62        time git clone --depth 1 "$ACPICA_REPO" -b master "$ACPICA_DIR"
63    fi
64
65    make -C "$ACPICA_DIR"/
66
67    source edk2/edksetup.sh
68    make -C edk2/BaseTools
69
70    build -a AARCH64 -t GCC5 -p ArmVirtPkg/ArmVirtCloudHv.dsc -b RELEASE
71    cp Build/ArmVirtCloudHv-AARCH64/RELEASE_GCC5/FV/CLOUDHV_EFI.fd "$WORKLOADS_DIR"
72
73    echo "Info: build UEFI successfully"
74
75    popd
76}
77
78update_workloads() {
79    cp scripts/sha1sums-aarch64 $WORKLOADS_DIR
80
81    BIONIC_OS_IMAGE_DOWNLOAD_NAME="bionic-server-cloudimg-arm64.img"
82    BIONIC_OS_IMAGE_DOWNLOAD_URL="https://cloud-hypervisor.azureedge.net/$BIONIC_OS_IMAGE_DOWNLOAD_NAME"
83    BIONIC_OS_DOWNLOAD_IMAGE="$WORKLOADS_DIR/$BIONIC_OS_IMAGE_DOWNLOAD_NAME"
84    if [ ! -f "$BIONIC_OS_DOWNLOAD_IMAGE" ]; then
85        pushd $WORKLOADS_DIR
86        time wget --quiet $BIONIC_OS_IMAGE_DOWNLOAD_URL || exit 1
87        popd
88    fi
89
90    BIONIC_OS_RAW_IMAGE_NAME="bionic-server-cloudimg-arm64.raw"
91    BIONIC_OS_RAW_IMAGE="$WORKLOADS_DIR/$BIONIC_OS_RAW_IMAGE_NAME"
92    if [ ! -f "$BIONIC_OS_RAW_IMAGE" ]; then
93        pushd $WORKLOADS_DIR
94        time qemu-img convert -p -f qcow2 -O raw $BIONIC_OS_IMAGE_DOWNLOAD_NAME $BIONIC_OS_RAW_IMAGE_NAME || exit 1
95        popd
96    fi
97
98    # Convert the raw image to qcow2 image to remove compressed blocks from the disk. Therefore letting the
99    # qcow2 format image can be directly used in the integration test.
100    BIONIC_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME="bionic-server-cloudimg-arm64.qcow2"
101    BIONIC_OS_QCOW2_UNCOMPRESSED_IMAGE="$WORKLOADS_DIR/$BIONIC_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME"
102    if [ ! -f "$BIONIC_OS_QCOW2_UNCOMPRESSED_IMAGE" ]; then
103        pushd $WORKLOADS_DIR
104        time qemu-img convert -p -f raw -O qcow2 $BIONIC_OS_RAW_IMAGE_NAME $BIONIC_OS_QCOW2_UNCOMPRESSED_IMAGE || exit 1
105        popd
106    fi
107
108    FOCAL_OS_RAW_IMAGE_NAME="focal-server-cloudimg-arm64-custom.raw"
109    FOCAL_OS_RAW_IMAGE_DOWNLOAD_URL="https://cloud-hypervisor.azureedge.net/$FOCAL_OS_RAW_IMAGE_NAME"
110    FOCAL_OS_RAW_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_NAME"
111    if [ ! -f "$FOCAL_OS_RAW_IMAGE" ]; then
112        pushd $WORKLOADS_DIR
113        time wget --quiet $FOCAL_OS_RAW_IMAGE_DOWNLOAD_URL || exit 1
114        popd
115    fi
116
117    # Convert the raw image to qcow2 image to remove compressed blocks from the disk. Therefore letting the
118    # qcow2 format image can be directly used in the integration test.
119    FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME="focal-server-cloudimg-arm64-custom.qcow2"
120    FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL="https://cloud-hypervisor.azureedge.net/$FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME"
121    FOCAL_OS_QCOW2_UNCOMPRESSED_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_NAME"
122    if [ ! -f "$FOCAL_OS_QCOW2_UNCOMPRESSED_IMAGE" ]; then
123        pushd $WORKLOADS_DIR
124        time wget --quiet $FOCAL_OS_QCOW2_IMAGE_UNCOMPRESSED_DOWNLOAD_URL || exit 1
125        popd
126    fi
127
128    ALPINE_MINIROOTFS_URL="http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/aarch64/alpine-minirootfs-3.11.3-aarch64.tar.gz"
129    ALPINE_MINIROOTFS_TARBALL="$WORKLOADS_DIR/alpine-minirootfs-aarch64.tar.gz"
130    if [ ! -f "$ALPINE_MINIROOTFS_TARBALL" ]; then
131        pushd $WORKLOADS_DIR
132        time wget --quiet $ALPINE_MINIROOTFS_URL -O $ALPINE_MINIROOTFS_TARBALL || exit 1
133        popd
134    fi
135
136    ALPINE_INITRAMFS_IMAGE="$WORKLOADS_DIR/alpine_initramfs.img"
137    if [ ! -f "$ALPINE_INITRAMFS_IMAGE" ]; then
138        pushd $WORKLOADS_DIR
139        mkdir alpine-minirootfs
140        tar xf "$ALPINE_MINIROOTFS_TARBALL" -C alpine-minirootfs
141        cat > alpine-minirootfs/init <<-EOF
142			#! /bin/sh
143			mount -t devtmpfs dev /dev
144			echo \$TEST_STRING > /dev/console
145			poweroff -f
146		EOF
147        chmod +x alpine-minirootfs/init
148        cd alpine-minirootfs
149        find . -print0 |
150            cpio --null --create --verbose --owner root:root --format=newc > "$ALPINE_INITRAMFS_IMAGE"
151        popd
152    fi
153
154    pushd $WORKLOADS_DIR
155    sha1sum sha1sums-aarch64 --check
156    if [ $? -ne 0 ]; then
157        echo "sha1sum validation of images failed, remove invalid images to fix the issue."
158        exit 1
159    fi
160    popd
161
162    # Build custom kernel based on virtio-pmem and virtio-fs upstream patches
163    PE_IMAGE="$WORKLOADS_DIR/Image"
164    LINUX_CUSTOM_DIR="$WORKLOADS_DIR/linux-custom"
165
166    build_custom_linux_kernel() {
167        pushd $LINUX_CUSTOM_DIR
168        time make -j `nproc`
169        cp arch/arm64/boot/Image $WORKLOADS_DIR/Image || exit 1
170        popd
171    }
172
173    SRCDIR=$PWD
174    LINUX_CUSTOM_BRANCH="ch-5.14"
175
176    # Check whether the local HEAD commit same as the remote HEAD or not. Remove the folder if they are different.
177    if [ -d "$LINUX_CUSTOM_DIR" ]; then
178        pushd $LINUX_CUSTOM_DIR
179        git fetch
180        LINUX_CUSTOM_LOCAL_HEAD=$(git rev-parse HEAD)
181        LINUX_CUSTOM_REMOTE_HEAD=$(git rev-parse remotes/origin/$LINUX_CUSTOM_BRANCH)
182        popd
183        if [ "$LINUX_CUSTOM_LOCAL_HEAD" != "$LINUX_CUSTOM_REMOTE_HEAD" ]; then
184            rm -rf "$LINUX_CUSTOM_DIR"
185        fi
186    fi
187
188    if [ ! -d "$LINUX_CUSTOM_DIR" ]; then
189        time git clone --depth 1 "https://github.com/cloud-hypervisor/linux.git" -b $LINUX_CUSTOM_BRANCH $LINUX_CUSTOM_DIR
190    fi
191
192    cp $SRCDIR/resources/linux-config-aarch64 $LINUX_CUSTOM_DIR/.config
193    build_custom_linux_kernel
194
195    VIRTIOFSD="$WORKLOADS_DIR/virtiofsd"
196    QEMU_DIR="qemu_build"
197
198    if [ ! -f "$VIRTIOFSD" ]; then
199        pushd $WORKLOADS_DIR
200        git clone --depth 1 "https://gitlab.com/virtio-fs/qemu.git" -b "qemu5.0-virtiofs-dax" $QEMU_DIR
201        pushd $QEMU_DIR
202        time ./configure --prefix=$PWD --target-list=aarch64-softmmu
203        time make virtiofsd -j `nproc`
204        cp virtiofsd $VIRTIOFSD || exit 1
205        popd
206        rm -rf $QEMU_DIR
207        popd
208    fi
209
210    VIRTIOFSD_RS="$WORKLOADS_DIR/virtiofsd-rs"
211    VIRTIOFSD_RS_DIR="virtiofsd_rs_build"
212    if [ ! -f "$VIRTIOFSD_RS" ]; then
213        pushd $WORKLOADS_DIR
214        git clone --depth 1 "https://gitlab.com/virtio-fs/virtiofsd-rs.git" $VIRTIOFSD_RS_DIR
215        pushd $VIRTIOFSD_RS_DIR
216        time cargo build --release
217        cp target/release/virtiofsd-rs $VIRTIOFSD_RS || exit 1
218        popd
219        rm -rf $VIRTIOFSD_RS_DIR
220        popd
221    fi
222
223    BLK_IMAGE="$WORKLOADS_DIR/blk.img"
224    MNT_DIR="mount_image"
225    if [ ! -f "$BLK_IMAGE" ]; then
226        pushd $WORKLOADS_DIR
227        fallocate -l 16M $BLK_IMAGE
228        mkfs.ext4 -j $BLK_IMAGE
229        mkdir $MNT_DIR
230        sudo mount -t ext4 $BLK_IMAGE $MNT_DIR
231        sudo bash -c "echo bar > $MNT_DIR/foo" || exit 1
232        sudo umount $BLK_IMAGE
233        rm -r $MNT_DIR
234        popd
235    fi
236
237    SHARED_DIR="$WORKLOADS_DIR/shared_dir"
238    if [ ! -d "$SHARED_DIR" ]; then
239        mkdir -p $SHARED_DIR
240        echo "foo" > "$SHARED_DIR/file1"
241        echo "bar" > "$SHARED_DIR/file3" || exit 1
242    fi
243
244    # Check and build EDK2 binary
245    build_edk2
246}
247
248process_common_args "$@"
249
250# aarch64 not supported for MSHV
251if [[ "$hypervisor" = "mshv" ]]; then
252    echo "AArch64 is not supported in Microsoft Hypervisor"
253    exit 1
254fi
255
256features_build=""
257features_test="--features integration_tests"
258
259# lock the workloads folder to avoid parallel updating by different containers
260(
261    echo "try to lock $WORKLOADS_DIR folder and update"
262    flock -x 12 && update_workloads
263) 12>$WORKLOADS_LOCK
264
265# Check if there is any error in the execution of `update_workloads`.
266# If there is any error, then kill the shell. Otherwise the script will continue
267# running even if the `update_workloads` function was failed.
268RES=$?
269if [ $RES -ne 0 ]; then
270    exit 1
271fi
272
273BUILD_TARGET="aarch64-unknown-linux-${CH_LIBC}"
274CFLAGS=""
275TARGET_CC=""
276if [[ "${BUILD_TARGET}" == "aarch64-unknown-linux-musl" ]]; then
277TARGET_CC="musl-gcc"
278CFLAGS="-I /usr/include/aarch64-linux-musl/ -idirafter /usr/include/"
279fi
280
281export RUST_BACKTRACE=1
282
283# Test without ACPI
284cargo build --all --release $features_build --target $BUILD_TARGET
285strip target/$BUILD_TARGET/release/cloud-hypervisor
286strip target/$BUILD_TARGET/release/vhost_user_net
287strip target/$BUILD_TARGET/release/ch-remote
288
289# Enable KSM with some reasonable parameters so that it won't take too long
290# for the memory to be merged between two processes.
291sudo bash -c "echo 1000000 > /sys/kernel/mm/ksm/pages_to_scan"
292sudo bash -c "echo 10 > /sys/kernel/mm/ksm/sleep_millisecs"
293sudo bash -c "echo 1 > /sys/kernel/mm/ksm/run"
294
295# Setup huge-pages for ovs-dpdk
296echo 2048 | sudo tee /proc/sys/vm/nr_hugepages
297
298# Run all direct kernel boot (Device Tree) test cases in mod `parallel`
299time cargo test $features_test "tests::parallel::$test_filter"
300RES=$?
301
302# Run some tests in sequence since the result could be affected by other tests
303# running in parallel.
304if [ $RES -eq 0 ]; then
305    time cargo test $features_test "tests::sequential::$test_filter" -- --test-threads=1
306    RES=$?
307else
308    exit $RES
309fi
310
311# Run all ACPI test cases
312if [ $RES -eq 0 ]; then
313    time cargo test $features_test "tests::aarch64_acpi::$test_filter"
314    RES=$?
315else
316    exit $RES
317fi
318
319# Run all test cases related to live migration
320if [ $RES -eq 0 ]; then
321    time cargo test $features_test "tests::live_migration::$test_filter" -- --test-threads=1
322    RES=$?
323else
324    exit $RES
325fi
326
327exit $RES
328