xref: /kvm-unit-tests/x86/efi/run (revision e526bc786e9878c3880ae4b09b01a4572756e492)
1#!/bin/bash
2
3set -e
4
5if [ $# -eq 0 ]; then
6	echo "Usage $0 TEST_CASE [QEMU_ARGS]"
7	exit 2
8fi
9
10if [ ! -f config.mak ]; then
11	echo "run './configure --enable-efi && make' first. See ./configure -h"
12	exit 2
13fi
14source config.mak
15
16: "${EFI_SRC:=$TEST_DIR}"
17: "${EFI_UEFI:=/usr/share/ovmf/OVMF.fd}"
18: "${EFI_TEST:=efi-tests}"
19: "${EFI_SMP:=1}"
20: "${EFI_CASE:=$(basename $1 .efi)}"
21
22if [ ! -f "$EFI_UEFI" ]; then
23	echo "UEFI firmware not found: $EFI_UEFI"
24	echo "Please install the UEFI firmware to this path"
25	echo "Or specify the correct path with the env variable EFI_UEFI"
26	exit 2
27fi
28
29# Remove the TEST_CASE from $@
30shift 1
31
32if [ "$EFI_CASE" = "_NO_FILE_4Uhere_" ]; then
33	EFI_CASE=dummy
34fi
35
36# Prepare EFI boot file system
37#   - Copy .efi file to host dir $EFI_TEST/$EFI_CASE/EFI/BOOT/BOOTX64.EFI
38#     This host dir will be loaded by QEMU as a FAT32 image
39#   - UEFI firmware by default loads the file EFI/BOOT/BOOTX64.EFI
40: "${EFI_CASE_DIR:="$EFI_TEST/$EFI_CASE/EFI/BOOT"}"
41: "${EFI_CASE_BINARY:="$EFI_CASE_DIR/BOOTX64.EFI"}"
42
43mkdir -p "$EFI_CASE_DIR"
44cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_BINARY"
45
46# Run test case with 256MiB QEMU memory. QEMU default memory size is 128MiB.
47# After UEFI boot up and we call `LibMemoryMap()`, the largest consecutive
48# memory region is ~42MiB. Although this is sufficient for many test cases to
49# run in UEFI, some test cases, e.g. `x86/pmu.c`, require more free memory. A
50# simple fix is to increase the QEMU default memory size to 256MiB so that
51# UEFI's largest allocatable memory region is large enough.
52#
53# Also, pass in an EFI-specific smp count (i.e., `-smp 1`) as the last argument
54# to x86/run. This `smp` flag overrides any previous `smp` flags (e.g.,
55# `-smp 4`). This is necessary because KVM-Unit-Tests do not currently support
56# SMP under UEFI. This last flag should be removed when this issue is resolved.
57"$TEST_DIR/run" \
58	-drive file="$EFI_UEFI",format=raw,if=pflash,readonly=on \
59	-drive file.dir="$EFI_TEST/$EFI_CASE/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \
60	-net none \
61	-nographic \
62	-m 256 \
63	"$@" \
64	-smp "$EFI_SMP"
65