xref: /cloud-hypervisor/scripts/run_integration_tests_x86_64.sh (revision 9af2968a7dc47b89bf07ea9dc5e735084efcfa3a)
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 deafult for kvm
15features_build=""
16features_test="--features integration_tests"
17
18cp scripts/sha1sums-x86_64 $WORKLOADS_DIR
19
20FW_URL=$(curl --silent https://api.github.com/repos/cloud-hypervisor/rust-hypervisor-firmware/releases/latest | grep "browser_download_url" | grep -o 'https://.*[^ "]')
21FW="$WORKLOADS_DIR/hypervisor-fw"
22if [ ! -f "$FW" ]; then
23    pushd $WORKLOADS_DIR
24    time wget --quiet $FW_URL || exit 1
25    popd
26fi
27
28BIONIC_OS_IMAGE_NAME="bionic-server-cloudimg-amd64.qcow2"
29BIONIC_OS_IMAGE_URL="https://cloud-hypervisor.azureedge.net/$BIONIC_OS_IMAGE_NAME"
30BIONIC_OS_IMAGE="$WORKLOADS_DIR/$BIONIC_OS_IMAGE_NAME"
31if [ ! -f "$BIONIC_OS_IMAGE" ]; then
32    pushd $WORKLOADS_DIR
33    time wget --quiet $BIONIC_OS_IMAGE_URL || exit 1
34    popd
35fi
36
37BIONIC_OS_RAW_IMAGE_NAME="bionic-server-cloudimg-amd64.raw"
38BIONIC_OS_RAW_IMAGE="$WORKLOADS_DIR/$BIONIC_OS_RAW_IMAGE_NAME"
39if [ ! -f "$BIONIC_OS_RAW_IMAGE" ]; then
40    pushd $WORKLOADS_DIR
41    time qemu-img convert -p -f qcow2 -O raw $BIONIC_OS_IMAGE_NAME $BIONIC_OS_RAW_IMAGE_NAME || exit 1
42    popd
43fi
44
45
46FOCAL_OS_IMAGE_NAME="focal-server-cloudimg-amd64-custom-20210609-0.qcow2"
47FOCAL_OS_IMAGE_URL="https://cloud-hypervisor.azureedge.net/$FOCAL_OS_IMAGE_NAME"
48FOCAL_OS_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_IMAGE_NAME"
49if [ ! -f "$FOCAL_OS_IMAGE" ]; then
50    pushd $WORKLOADS_DIR
51    time wget --quiet $FOCAL_OS_IMAGE_URL || exit 1
52    popd
53fi
54
55FOCAL_OS_RAW_IMAGE_NAME="focal-server-cloudimg-amd64-custom-20210609-0.raw"
56FOCAL_OS_RAW_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_NAME"
57if [ ! -f "$FOCAL_OS_RAW_IMAGE" ]; then
58    pushd $WORKLOADS_DIR
59    time qemu-img convert -p -f qcow2 -O raw $FOCAL_OS_IMAGE_NAME $FOCAL_OS_RAW_IMAGE_NAME || exit 1
60    popd
61fi
62
63ALPINE_MINIROOTFS_URL="http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-minirootfs-3.11.3-x86_64.tar.gz"
64ALPINE_MINIROOTFS_TARBALL="$WORKLOADS_DIR/alpine-minirootfs-x86_64.tar.gz"
65if [ ! -f "$ALPINE_MINIROOTFS_TARBALL" ]; then
66    pushd $WORKLOADS_DIR
67    time wget --quiet $ALPINE_MINIROOTFS_URL -O $ALPINE_MINIROOTFS_TARBALL || exit 1
68    popd
69fi
70
71ALPINE_INITRAMFS_IMAGE="$WORKLOADS_DIR/alpine_initramfs.img"
72if [ ! -f "$ALPINE_INITRAMFS_IMAGE" ]; then
73    pushd $WORKLOADS_DIR
74    mkdir alpine-minirootfs
75    tar xf "$ALPINE_MINIROOTFS_TARBALL" -C alpine-minirootfs
76    cat > alpine-minirootfs/init <<-EOF
77		#! /bin/sh
78		mount -t devtmpfs dev /dev
79		echo \$TEST_STRING > /dev/console
80		poweroff -f
81	EOF
82    chmod +x alpine-minirootfs/init
83    cd alpine-minirootfs
84    find . -print0 |
85        cpio --null --create --verbose --owner root:root --format=newc > "$ALPINE_INITRAMFS_IMAGE"
86    popd
87fi
88
89pushd $WORKLOADS_DIR
90sha1sum sha1sums-x86_64 --check
91if [ $? -ne 0 ]; then
92    echo "sha1sum validation of images failed, remove invalid images to fix the issue."
93    exit 1
94fi
95popd
96
97# Build custom kernel based on virtio-pmem and virtio-fs upstream patches
98VMLINUX_IMAGE="$WORKLOADS_DIR/vmlinux"
99
100LINUX_CUSTOM_DIR="$WORKLOADS_DIR/linux-custom"
101
102if [ ! -f "$VMLINUX_IMAGE" ]; then
103    SRCDIR=$PWD
104    pushd $WORKLOADS_DIR
105    time git clone --depth 1 "https://github.com/cloud-hypervisor/linux.git" -b "ch-5.13-rc5" $LINUX_CUSTOM_DIR
106    cp $SRCDIR/resources/linux-config-x86_64 $LINUX_CUSTOM_DIR/.config
107    popd
108fi
109
110if [ ! -f "$VMLINUX_IMAGE" ]; then
111    pushd $LINUX_CUSTOM_DIR
112    time make bzImage -j `nproc`
113    cp vmlinux $VMLINUX_IMAGE || exit 1
114    popd
115fi
116
117if [ -d "$LINUX_CUSTOM_DIR" ]; then
118    rm -rf $LINUX_CUSTOM_DIR
119fi
120
121VIRTIOFSD="$WORKLOADS_DIR/virtiofsd"
122QEMU_DIR="qemu_build"
123if [ ! -f "$VIRTIOFSD" ]; then
124    pushd $WORKLOADS_DIR
125    git clone --depth 1 "https://gitlab.com/virtio-fs/qemu.git" -b "qemu5.0-virtiofs-dax" $QEMU_DIR
126    pushd $QEMU_DIR
127    time ./configure --prefix=$PWD --target-list=x86_64-softmmu
128    time make virtiofsd -j `nproc`
129    cp virtiofsd $VIRTIOFSD || exit 1
130    popd
131    rm -rf $QEMU_DIR
132    popd
133fi
134
135VIRTIOFSD_RS="$WORKLOADS_DIR/virtiofsd-rs"
136VIRTIOFSD_RS_DIR="virtiofsd_rs_build"
137if [ ! -f "$VIRTIOFSD_RS" ]; then
138    pushd $WORKLOADS_DIR
139    git clone --depth 1 "https://gitlab.com/virtio-fs/virtiofsd-rs.git" $VIRTIOFSD_RS_DIR
140    pushd $VIRTIOFSD_RS_DIR
141    time cargo build --release
142    cp target/release/virtiofsd-rs $VIRTIOFSD_RS || exit 1
143    popd
144    rm -rf $VIRTIOFSD_RS_DIR
145    popd
146fi
147
148
149BLK_IMAGE="$WORKLOADS_DIR/blk.img"
150MNT_DIR="mount_image"
151if [ ! -f "$BLK_IMAGE" ]; then
152   pushd $WORKLOADS_DIR
153   fallocate -l 16M $BLK_IMAGE
154   mkfs.ext4 -j $BLK_IMAGE
155   mkdir $MNT_DIR
156   sudo mount -t ext4 $BLK_IMAGE $MNT_DIR
157   sudo bash -c "echo bar > $MNT_DIR/foo" || exit 1
158   sudo umount $BLK_IMAGE
159   rm -r $MNT_DIR
160   popd
161fi
162
163SHARED_DIR="$WORKLOADS_DIR/shared_dir"
164if [ ! -d "$SHARED_DIR" ]; then
165    mkdir -p $SHARED_DIR
166    echo "foo" > "$SHARED_DIR/file1"
167    echo "bar" > "$SHARED_DIR/file3" || exit 1
168fi
169
170VFIO_DIR="$WORKLOADS_DIR/vfio"
171VFIO_DISK_IMAGE="$WORKLOADS_DIR/vfio.img"
172rm -rf $VFIO_DIR $VFIO_DISK_IMAGE
173mkdir -p $VFIO_DIR
174cp $FOCAL_OS_IMAGE $VFIO_DIR
175cp $FW $VFIO_DIR
176cp $VMLINUX_IMAGE $VFIO_DIR || exit 1
177
178BUILD_TARGET="$(uname -m)-unknown-linux-${CH_LIBC}"
179CFLAGS=""
180TARGET_CC=""
181if [[ "${BUILD_TARGET}" == "x86_64-unknown-linux-musl" ]]; then
182TARGET_CC="musl-gcc"
183CFLAGS="-I /usr/include/x86_64-linux-musl/ -idirafter /usr/include/"
184fi
185
186cargo build --all  --release $features_build --target $BUILD_TARGET
187strip target/$BUILD_TARGET/release/cloud-hypervisor
188strip target/$BUILD_TARGET/release/vhost_user_net
189strip target/$BUILD_TARGET/release/ch-remote
190
191# We always copy a fresh version of our binary for our L2 guest.
192cp target/$BUILD_TARGET/release/cloud-hypervisor $VFIO_DIR
193cp target/$BUILD_TARGET/release/ch-remote $VFIO_DIR
194
195# Enable KSM with some reasonable parameters so that it won't take too long
196# for the memory to be merged between two processes.
197sudo bash -c "echo 1000000 > /sys/kernel/mm/ksm/pages_to_scan"
198sudo bash -c "echo 10 > /sys/kernel/mm/ksm/sleep_millisecs"
199sudo bash -c "echo 1 > /sys/kernel/mm/ksm/run"
200
201# Both test_vfio and ovs-dpdk rely on hugepages
202echo 6144 | sudo tee /proc/sys/vm/nr_hugepages
203sudo chmod a+rwX /dev/hugepages
204
205# Setup ovs-dpdk
206service openvswitch-switch start
207ovs-vsctl init
208ovs-vsctl set Open_vSwitch . other_config:dpdk-init=true
209service openvswitch-switch restart
210
211export RUST_BACKTRACE=1
212time cargo test $features_test "tests::parallel::$test_filter"
213RES=$?
214
215# Run some tests in sequence since the result could be affected by other tests
216# running in parallel.
217if [ $RES -eq 0 ]; then
218    export RUST_BACKTRACE=1
219    time cargo test $features_test "tests::sequential::$test_filter" -- --test-threads=1
220    RES=$?
221fi
222
223exit $RES
224