1#!/bin/bash
2
3set -ex
4
5# Name of the XTF test
6xtf_test=$1
7
8# Message returned by XTF in case of success
9passed="Test result: SUCCESS"
10
11# XXX QEMU looks for "efi-virtio.rom" even if it is unneeded
12curl -fsSLO https://github.com/qemu/qemu/raw/v5.2.0/pc-bios/efi-virtio.rom
13./binaries/qemu-system-aarch64 \
14   -machine virtualization=true \
15   -cpu cortex-a57 -machine type=virt \
16   -m 2048 -smp 2 -display none \
17   -machine dumpdtb=binaries/virt-gicv2.dtb
18
19# XTF
20# Build a single XTF test passed as a first parameter to the script.
21# Build XTF with GICv2 support to match Qemu configuration and with SBSA UART
22# support, so that the test will use an emulated UART for printing messages.
23# This will allow us to run the test on both debug and non-debug Xen builds.
24rm -rf xtf
25git clone https://gitlab.com/xen-project/fusa/xtf.git -b xtf-arm
26make -C xtf TESTS=tests/${xtf_test} CONFIG_SBSA_UART=y CONFIG_GICV2=y -j$(nproc)
27cp xtf/tests/${xtf_test}/test-mmu64le-${xtf_test} binaries/xtf-test
28
29# ImageBuilder
30echo 'MEMORY_START="0x40000000"
31MEMORY_END="0xC0000000"
32
33XEN="xen"
34DEVICE_TREE="virt-gicv2.dtb"
35
36XEN_CMD="console=dtuart console_timestamps=boot"
37
38DOMU_KERNEL[0]="xtf-test"
39DOMU_MEM[0]="128"
40
41NUM_DOMUS=1
42
43LOAD_CMD="tftpb"
44UBOOT_SOURCE="boot.source"
45UBOOT_SCRIPT="boot.scr"' > binaries/config
46
47rm -rf imagebuilder
48git clone --depth 1 https://gitlab.com/xen-project/imagebuilder.git
49bash imagebuilder/scripts/uboot-script-gen -t tftp -d binaries/ -c binaries/config
50
51# Run the test
52rm -f smoke.serial
53set +e
54echo "  virtio scan; dhcp; tftpb 0x40000000 boot.scr; source 0x40000000"| \
55timeout -k 1 120 \
56./binaries/qemu-system-aarch64 \
57    -machine virtualization=true \
58    -cpu cortex-a57 -machine type=virt \
59    -m 2048 -monitor none -serial stdio \
60    -smp 2 \
61    -no-reboot \
62    -device virtio-net-pci,netdev=n0 \
63    -netdev user,id=n0,tftp=binaries \
64    -bios /usr/lib/u-boot/qemu_arm64/u-boot.bin |& \
65        tee smoke.serial | sed 's/\r//'
66
67set -e
68(grep -q "${passed}" smoke.serial) || exit 1
69exit 0
70