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