1 # Makefile for VM tests
3 # Hack to allow running in an unconfigured build tree
4 ifeq ($(realpath $(SRC_PATH)),$(realpath .))
5 VM_PYTHON = PYTHONPATH=$(SRC_PATH)/python /usr/bin/env python3
12 .PHONY: vm-build-all vm-clean-all
14 EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd)
16 X86_IMAGES := freebsd netbsd openbsd haiku.x86_64
17 ifneq ($(GENISOIMAGE),)
19 ifneq ($(EFI_AARCH64),)
20 ARM64_IMAGES += ubuntu.aarch64 centos.aarch64
24 HOST_ARCH = $(shell uname -m)
25 ifeq ($(HOST_ARCH),x86_64)
26 IMAGES=$(X86_IMAGES) $(if $(USE_TCG),$(ARM64_IMAGES))
27 else ifeq ($(HOST_ARCH),aarch64)
28 IMAGES=$(ARM64_IMAGES) $(if $(USE_TCG),$(X86_IMAGES))
31 IMAGES_DIR := $(HOME)/.cache/qemu-vm/images
32 IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
34 .PRECIOUS: $(IMAGE_FILES)
37 HAVE_PYTHON_YAML = $(shell $(PYTHON) -c "import yaml" 2> /dev/null && echo yes)
40 # 'vm-help' target was historically named 'vm-test'
42 @echo "vm-help: Test QEMU in preconfigured virtual machines"
44 @echo " vm-build-freebsd - Build QEMU in FreeBSD VM"
45 @echo " vm-build-netbsd - Build QEMU in NetBSD VM"
46 @echo " vm-build-openbsd - Build QEMU in OpenBSD VM"
47 ifneq ($(GENISOIMAGE),)
48 ifneq ($(EFI_AARCH64),)
49 @echo " vm-build-ubuntu.aarch64 - Build QEMU in ubuntu aarch64 VM"
50 @echo " vm-build-centos.aarch64 - Build QEMU in CentOS aarch64 VM"
52 @echo " (to build centos/ubuntu aarch64 images use configure --efi-aarch64)"
55 @echo " (install genisoimage to build centos/ubuntu images)"
57 @echo " vm-build-haiku.x86_64 - Build QEMU in Haiku VM"
59 @echo " vm-build-all - Build QEMU in: $(IMAGES)"
60 @echo " vm-clean-all - Clean up VM images"
62 @echo "For trouble-shooting:"
63 @echo " vm-boot-serial-<guest> - Boot guest, serial console on stdio"
64 @echo " vm-boot-ssh-<guest> - Boot guest and login via ssh"
66 @echo "Special variables:"
67 @echo " BUILD_TARGET=foo - Override the build target"
68 @echo " DEBUG=1 - Enable verbose output on host and interactive debugging"
69 @echo ' EXTRA_CONFIGURE_OPTS="..." - Pass to configure step'
70 @echo " J=[0..9]* - Override the -jN parameter for make commands"
71 @echo " LOG_CONSOLE=1 - Log console to file in: ~/.cache/qemu-vm "
72 @echo " USE_TCG=1 - Use TCG for cross-arch images"
73 @echo " QEMU=/path/to/qemu - Change path to QEMU binary"
74 ifeq ($(HAVE_PYTHON_YAML),yes)
75 @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file."
77 @echo " (install python3-yaml to enable support for yaml file to configure a VM.)"
79 @echo " See conf_example_*.yml for file format details."
80 @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool"
81 @echo " QEMU_LOCAL=1 - Use QEMU binary local to this build."
82 @echo " TARGET_LIST=a,b,c - Override target list in builds"
83 @echo " V=1 - Enable verbose output on host and guest commands"
85 vm-build-all: $(addprefix vm-build-, $(IMAGES))
90 $(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \
91 $(SRC_PATH)/tests/vm/basevm.py \
92 $(SRC_PATH)/tests/vm/Makefile.include \
94 @mkdir -p $(IMAGES_DIR)
95 $(call quiet-command, \
97 $(if $(V)$(DEBUG), --debug) \
98 $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
99 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
100 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
101 $(if $(LOG_CONSOLE),--log-console) \
102 --source-path $(SRC_PATH) \
104 $(if $(filter-out check-venv, $?), --force) \
108 # Build in VM $(IMAGE)
109 vm-build-%: $(IMAGES_DIR)/%.img $(VM_VENV)
110 $(call quiet-command, \
111 $(VM_PYTHON) $(SRC_PATH)/tests/vm/$* \
112 $(if $(V)$(DEBUG), --debug) \
113 $(if $(DEBUG), --interactive) \
114 $(if $(J),--jobs $(J)) \
115 $(if $(V),--verbose) \
116 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
117 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
118 $(if $(LOG_CONSOLE),--log-console) \
120 $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
122 --build-qemu $(SRC_PATH) -- \
123 $(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \
124 $(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \
127 vm-boot-serial-%: $(IMAGES_DIR)/%.img
128 qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \
129 -drive if=none,id=vblk,cache=writeback,file="$<" \
130 -netdev user,id=vnet \
131 -device virtio-blk-pci,drive=vblk \
132 -device virtio-net-pci,netdev=vnet \
135 vm-boot-ssh-%: $(IMAGES_DIR)/%.img $(VM_VENV)
136 $(call quiet-command, \
137 $(VM_PYTHON) $(SRC_PATH)/tests/vm/$* \
138 $(if $(J),--jobs $(J)) \
139 $(if $(V)$(DEBUG), --debug) \
140 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
141 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
142 $(if $(LOG_CONSOLE),--log-console) \
146 " VM-BOOT-SSH $*") || true