1 # Makefile for VM tests
3 .PHONY: vm-build-all vm-clean-all
5 HOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m))
7 EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd)
9 X86_IMAGES := freebsd netbsd openbsd centos fedora haiku.x86_64
10 ifneq ($(GENISOIMAGE),)
11 X86_IMAGES += ubuntu.i386 centos
12 ifneq ($(EFI_AARCH64),)
13 ARM64_IMAGES += ubuntu.aarch64 centos.aarch64
17 ifeq ($(HOST_ARCH),x86_64)
18 IMAGES=$(X86_IMAGES) $(if $(USE_TCG),$(ARM64_IMAGES))
19 else ifeq ($(HOST_ARCH),aarch64)
20 IMAGES=$(ARM64_IMAGES) $(if $(USE_TCG),$(X86_IMAGES))
23 IMAGES_DIR := $(HOME)/.cache/qemu-vm/images
24 IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
26 .PRECIOUS: $(IMAGE_FILES)
29 HAVE_PYTHON_YAML = $(shell $(PYTHON) -c "import yaml" 2> /dev/null && echo yes)
32 # 'vm-help' target was historically named 'vm-test'
34 @echo "vm-help: Test QEMU in preconfigured virtual machines"
36 @echo " vm-build-freebsd - Build QEMU in FreeBSD VM"
37 @echo " vm-build-netbsd - Build QEMU in NetBSD VM"
38 @echo " vm-build-openbsd - Build QEMU in OpenBSD VM"
39 @echo " vm-build-fedora - Build QEMU in Fedora VM"
40 ifneq ($(GENISOIMAGE),)
41 @echo " vm-build-centos - Build QEMU in CentOS VM, with Docker"
42 @echo " vm-build-ubuntu.i386 - Build QEMU in ubuntu i386 VM"
43 ifneq ($(EFI_AARCH64),)
44 @echo " vm-build-ubuntu.aarch64 - Build QEMU in ubuntu aarch64 VM"
45 @echo " vm-build-centos.aarch64 - Build QEMU in CentOS aarch64 VM"
47 @echo " (to build centos/ubuntu aarch64 images use configure --efi-aarch64)"
50 @echo " (install genisoimage to build centos/ubuntu images)"
52 @echo " vm-build-haiku.x86_64 - Build QEMU in Haiku VM"
54 @echo " vm-build-all - Build QEMU in: $(IMAGES)"
55 @echo " vm-clean-all - Clean up VM images"
57 @echo "For trouble-shooting:"
58 @echo " vm-boot-serial-<guest> - Boot guest, serial console on stdio"
59 @echo " vm-boot-ssh-<guest> - Boot guest and login via ssh"
61 @echo "Special variables:"
62 @echo " BUILD_TARGET=foo - Override the build target"
63 @echo " DEBUG=1 - Enable verbose output on host and interactive debugging"
64 @echo ' EXTRA_CONFIGURE_OPTS="..." - Pass to configure step'
65 @echo " J=[0..9]* - Override the -jN parameter for make commands"
66 @echo " LOG_CONSOLE=1 - Log console to file in: ~/.cache/qemu-vm "
67 @echo " USE_TCG=1 - Use TCG for cross-arch images"
68 @echo " QEMU=/path/to/qemu - Change path to QEMU binary"
69 ifeq ($(HAVE_PYTHON_YAML),yes)
70 @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file."
72 @echo " (install python3-yaml to enable support for yaml file to configure a VM.)"
74 @echo " See conf_example_*.yml for file format details."
75 @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool"
76 @echo " QEMU_LOCAL=1 - Use QEMU binary local to this build."
77 @echo " TARGET_LIST=a,b,c - Override target list in builds"
78 @echo " V=1 - Enable verbose ouput on host and guest commands"
80 vm-build-all: $(addprefix vm-build-, $(IMAGES))
85 $(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \
86 $(SRC_PATH)/tests/vm/basevm.py \
87 $(SRC_PATH)/tests/vm/Makefile.include
88 @mkdir -p $(IMAGES_DIR)
89 $(call quiet-command, \
91 $(if $(V)$(DEBUG), --debug) \
92 $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
93 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
94 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
95 $(if $(LOG_CONSOLE),--log-console) \
96 --source-path $(SRC_PATH) \
103 # Build in VM $(IMAGE)
104 vm-build-%: $(IMAGES_DIR)/%.img
105 $(call quiet-command, \
106 $(PYTHON) $(SRC_PATH)/tests/vm/$* \
107 $(if $(V)$(DEBUG), --debug) \
108 $(if $(DEBUG), --interactive) \
109 $(if $(J),--jobs $(J)) \
110 $(if $(V),--verbose) \
111 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
112 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
113 $(if $(LOG_CONSOLE),--log-console) \
115 $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
117 --build-qemu $(SRC_PATH) -- \
118 $(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \
119 $(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \
122 vm-boot-serial-%: $(IMAGES_DIR)/%.img
123 qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \
124 -drive if=none,id=vblk,cache=writeback,file="$<" \
125 -netdev user,id=vnet \
126 -device virtio-blk-pci,drive=vblk \
127 -device virtio-net-pci,netdev=vnet \
130 vm-boot-ssh-%: $(IMAGES_DIR)/%.img
131 $(call quiet-command, \
132 $(PYTHON) $(SRC_PATH)/tests/vm/$* \
133 $(if $(J),--jobs $(J)) \
134 $(if $(V)$(DEBUG), --debug) \
135 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
136 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
137 $(if $(LOG_CONSOLE),--log-console) \
141 " VM-BOOT-SSH $*") || true