xref: /kvm-unit-tests/x86/run (revision 361f623cb12e71ef56727cabefc273508ef29950)
1#!/usr/bin/env bash
2
3if [ -z "$KUT_STANDALONE" ]; then
4	if [ ! -f config.mak ]; then
5		echo "run ./configure && make first. See ./configure -h"
6		exit 2
7	fi
8	source config.mak
9	source scripts/arch-run.bash
10fi
11
12set_qemu_accelerator || exit $?
13
14qemu=$(search_qemu_binary) ||
15	exit $?
16
17if ! ${qemu} -device '?' 2>&1 | grep -F -e \"testdev\" -e \"pc-testdev\" > /dev/null;
18then
19    echo "No Qemu test device support found"
20    exit 2
21fi
22
23if
24	${qemu} -device '?' 2>&1 | grep -F "pci-testdev" > /dev/null;
25then
26	pci_testdev="-device pci-testdev"
27else
28	pci_testdev=""
29fi
30
31if
32	${qemu} -device '?' 2>&1 | grep -F "pc-testdev" > /dev/null;
33then
34	pc_testdev="-device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4"
35else
36	pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out"
37fi
38
39if
40	${qemu} -vnc '?' 2>&1 | grep -F "vnc options" > /dev/null;
41then
42	vnc_none="-vnc none"
43else
44	vnc_none=""
45fi
46
47# Discard lost ticks from the Programmable Interval Timer (PIT, a.k.a 8254), as
48# enabling KVM's re-injection mode inhibits (x2)AVIC, i.e. prevents validating
49# (x2)AVIC.  Note, the realmode test relies on the PIT, but not re-injection.
50pit="-global kvm-pit.lost_tick_policy=discard"
51
52command="${qemu} --no-reboot -nodefaults $pit $pc_testdev $vnc_none -serial stdio $pci_testdev"
53command+=" -machine accel=$ACCEL$ACCEL_PROPS"
54if [ "${CONFIG_EFI}" != y ]; then
55	command+=" -kernel"
56fi
57command="$(timeout_cmd) $command"
58
59if [ "${CONFIG_EFI}" = y ]; then
60	# Set ENVIRON_DEFAULT=n to remove '-initrd' flag for QEMU (see
61	# 'scripts/arch-run.bash' for more details). This is because when using
62	# UEFI, the test case binaries are passed to QEMU through the disk
63	# image, not through the '-kernel' flag. And QEMU reports an error if it
64	# gets '-initrd' without a '-kernel'
65	ENVIRON_DEFAULT=n run_qemu ${command} "$@"
66else
67	run_qemu ${command} "$@"
68fi
69