9 # $3:- Test Data Directory
10 # $4:- CPU Mask String (e.g. "5,6,7,8")
11 # $5:- Guest MEM in Gibibytes (e.g. 2G)
13 if [[ -z "${1:-}" ]]; then
14 echo "ERROR: A non-empty test selection is required to run
19 TEST_JOBS=${TEST_JOBS:-1}
21 # Init RAM disk image to boot the QEMU VM
25 TEST_DATA_DIR=${3:-"/tmp/vpp-vm-tests"}
26 if [[ ! -d ${TEST_DATA_DIR} ]]; then
27 mkdir -p ${TEST_DATA_DIR}
30 # CPU Affinity for taskset
31 CPU_MASK=${4:-"5,6,7,8"}
32 IFS=',' read -r -a CPU_MASK_ARRAY <<< ${CPU_MASK}
33 CPUS=${#CPU_MASK_ARRAY[@]}
35 # Guest MEM (Default 2G)
38 # Set the QEMU executable for the OS pkg.
39 os_VENDOR=$(lsb_release -i -s)
40 if [[ $os_VENDOR =~ (Debian|Ubuntu) ]]; then
42 QEMU=${QEMU:-"qemu-system-x86_64"}
45 QEMU=${QEMU:-"qemu-kvm"}
48 # Exit if the ${QEMU} executable is not available
49 if ! command -v ${QEMU} &> /dev/null; then
50 echo "Error: ${QEMU} is required, but could not be found."
54 # Download the Generic Linux Kernel, if needed
55 if [[ -z "${2:-}" ]] || [[ ! -f "${2:-}" ]]; then
56 if [[ $os_PACKAGE == "deb" ]]; then
59 PKG="linux-image-$(uname -r)"
60 echo "Getting the Linux Kernel image..${PKG}"
61 apt-get download ${PKG}
62 dpkg --fsys-tarfile ${PKG}_*.deb | tar xvf - ./boot
63 KERNEL_BIN=$(ls ${TEST_DATA_DIR}/boot/vmlinuz-*-generic)
66 echo "ERROR: Kernel Image selection is required for RPM pkgs."
73 ## Create initrd with 9p drivers, if ${INITRD} is null
75 if [[ -z "${INITRD}" ]] && [[ ! -d "/etc/initramfs-tools" ]]; then
76 echo "To boot the QEMU VM, an initial RAM disk with 9p drivers is needed"
77 echo "Install the initramfs-tools package or set env var INITRD to the RAM disk path"
79 elif [[ -z "${INITRD}" ]]; then
80 if [[ -f "/etc/initramfs-tools/modules" ]]; then
81 DRIVERS_9P=$(grep 9p /etc/initramfs-tools/modules | awk '{print $1}' | cut -d$'\n' -f1)
83 if [[ -z "${DRIVERS_9P}" ]]; then
84 echo "You'll need to update the file /etc/initramfs-tools/modules with the below 9p drivers"
85 echo "9p >> /etc/initramfs-tools/modules"
86 echo "9pnet >> /etc/initramfs-tools/modules"
87 echo "9pnet_virtio >> /etc/initramfs-tools/modules"
90 # Generate the initramfs image, if the we haven't generated one yet
91 if ! ls ${TEST_DATA_DIR}/boot/initrd.img-*-generic &> /dev/null; then
92 echo "Generating a bootable initramfs image in ${TEST_DATA_DIR}/boot/"
93 update-initramfs -c -k $(uname -r) -b ${TEST_DATA_DIR}/boot >/dev/null 2>&1
94 echo "Generated the INITRD image"
96 INITRD=$(ls ${TEST_DATA_DIR}/boot/initrd.img-*-generic)
98 echo "Using INITRD=${TEST_DATA_DIR}/boot/${INITRD} for booting the QEMU VM"
101 ## Install iperf into ${TEST_DATA_DIR}
102 IPERF=${TEST_DATA_DIR}/usr/bin/iperf
103 if [[ ! -x ${IPERF} ]] && [[ $os_PACKAGE == "deb" ]]; then
104 echo "Installing iperf: ${IPERF}"
107 IPRF_PKG="iperf_2.0.5+dfsg1-2_amd64.deb"
108 wget https://iperf.fr/download/ubuntu/${IPRF_PKG}
109 dpkg --fsys-tarfile ${IPRF_PKG} | tar xvf -
110 if [[ -x ${IPERF} ]]; then
111 echo "${IPERF} installed successfully"
113 echo "ERROR: iperf executable ${IPERF} installation failed"
117 elif [[ ! -x ${IPERF} ]] && [[ $os_PACKAGE != "deb" ]]; then
118 echo "ERROR: install iperf: ${IPERF} before running QEMU tests"
122 FAILED_DIR=${FAILED_DIR:-"/tmp/vpp-failed-unittests/"}
123 if [[ ! -d ${FAILED_DIR} ]]; then
124 mkdir -p ${FAILED_DIR}
127 HUGEPAGES=${HUGEPAGES:-256}
129 # Ensure all required Env vars are bound to non-zero values
130 EnvVarArray=("WS_ROOT=${WS_ROOT:-}"
131 "RND_SEED=${RND_SEED:-}"
133 "VENV_PATH=${VENV_PATH:-}"
134 "VPP_BUILD_DIR=${VPP_BUILD_DIR:-}"
135 "VPP_BIN=${VPP_BIN:-}"
136 "VPP_PLUGIN_PATH=${VPP_PLUGIN_PATH:-}"
137 "VPP_TEST_PLUGIN_PATH=${VPP_TEST_PLUGIN_PATH:-}"
138 "VPP_INSTALL_PATH=${VPP_INSTALL_PATH:-}"
139 "LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}")
141 for envVar in ${EnvVarArray[*]}; do
142 var_name=$(echo $envVar | cut -d= -f1)
143 var_val=$(echo $envVar | cut -d= -f2)
144 if [[ -z "$var_val" ]]; then
145 echo "ERROR: Env var: $var_name is not set"
150 # Boot QEMU VM and run the test
152 INIT=$(mktemp -p ${TEST_DATA_DIR})
153 cat > ${INIT} << _EOF_
156 mount -t tmpfs -o rw,nosuid,nodev tmpfs /dev/shm
157 mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
158 mount -t tmpfs -o "noexec,nosuid,size=10%,mode=0755" tmpfs /run
159 mount -t 9p /dev/vpp9p ${WS_ROOT}
160 mount -t 9p tmp9p /tmp
161 modprobe -a vhost_net
162 ${VENV_PATH}/bin/python3 ${WS_ROOT}/test/run_tests.py --filter=${TEST} --jobs=${TEST_JOBS} \
163 --failed-dir=${FAILED_DIR} --venv-dir=${VENV_PATH} --vpp-ws-dir=${WS_ROOT} --extended \
164 --vpp-tag=vpp_debug --cache-vpp-output
170 sudo taskset -c ${CPU_MASK} ${QEMU} \
172 -name test_$(basename $INIT) \
173 -chardev stdio,mux=on,id=char0 \
174 -mon chardev=char0,mode=readline \
175 -serial chardev:char0 \
176 -machine pc,accel=kvm,usb=off,mem-merge=off \
178 -smp ${CPUS},sockets=1,cores=${CPUS},threads=1 \
181 -kernel ${KERNEL_BIN} \
183 -fsdev local,id=root9p,path=/,security_model=none,multidevs=remap \
184 -device virtio-9p-pci,fsdev=root9p,mount_tag=fsRoot \
185 -virtfs local,path=${WS_ROOT},mount_tag=/dev/vpp9p,security_model=none,id=vpp9p,multidevs=remap \
186 -virtfs local,path=/tmp,mount_tag=tmp9p,security_model=passthrough,id=tmp9p,multidevs=remap \
187 -netdev tap,id=net0,vhost=on \
188 -device virtio-net-pci,netdev=net0,mac=52:54:00:de:64:01 \
190 -append "ro root=fsRoot rootfstype=9p rootflags=trans=virtio,cache=mmap console=ttyS0 hugepages=${HUGEPAGES} init=${INIT}"