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