1 # Makefile for VM tests
3 .PHONY: vm-build-all vm-clean-all
5 EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd)
7 IMAGES := freebsd netbsd openbsd centos fedora haiku.x86_64
8 ifneq ($(GENISOIMAGE),)
9 IMAGES += ubuntu.i386 centos
10 ifneq ($(EFI_AARCH64),)
11 IMAGES += ubuntu.aarch64 centos.aarch64
15 IMAGES_DIR := $(HOME)/.cache/qemu-vm/images
16 IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
18 .PRECIOUS: $(IMAGE_FILES)
21 HAVE_PYTHON_YAML = $(shell $(PYTHON) -c "import yaml" 2> /dev/null && echo yes)
24 # 'vm-help' target was historically named 'vm-test'
26 @echo "vm-help: Test QEMU in preconfigured virtual machines"
28 @echo " vm-build-freebsd - Build QEMU in FreeBSD VM"
29 @echo " vm-build-netbsd - Build QEMU in NetBSD VM"
30 @echo " vm-build-openbsd - Build QEMU in OpenBSD VM"
31 @echo " vm-build-fedora - Build QEMU in Fedora VM"
32 ifneq ($(GENISOIMAGE),)
33 @echo " vm-build-centos - Build QEMU in CentOS VM, with Docker"
34 @echo " vm-build-ubuntu.i386 - Build QEMU in ubuntu i386 VM"
35 ifneq ($(EFI_AARCH64),)
36 @echo " vm-build-ubuntu.aarch64 - Build QEMU in ubuntu aarch64 VM"
37 @echo " vm-build-centos.aarch64 - Build QEMU in CentOS aarch64 VM"
39 @echo " (to build centos/ubuntu aarch64 images use configure --efi-aarch64)"
42 @echo " (install genisoimage to build centos/ubuntu images)"
44 @echo " vm-build-haiku.x86_64 - Build QEMU in Haiku VM"
46 @echo " vm-build-all - Build QEMU in all VMs"
47 @echo " vm-clean-all - Clean up VM images"
49 @echo "For trouble-shooting:"
50 @echo " vm-boot-serial-<guest> - Boot guest, serial console on stdio"
51 @echo " vm-boot-ssh-<guest> - Boot guest and login via ssh"
53 @echo "Special variables:"
54 @echo " BUILD_TARGET=foo - Override the build target"
55 @echo " TARGET_LIST=a,b,c - Override target list in builds"
56 @echo ' EXTRA_CONFIGURE_OPTS="..."'
57 @echo " J=[0..9]* - Override the -jN parameter for make commands"
58 @echo " DEBUG=1 - Enable verbose output on host and interactive debugging"
59 @echo " LOG_CONSOLE=1 - Log console to file in: ~/.cache/qemu-vm "
60 @echo " V=1 - Enable verbose ouput on host and guest commands"
61 @echo " QEMU_LOCAL=1 - Use QEMU binary local to this build."
62 @echo " QEMU=/path/to/qemu - Change path to QEMU binary"
63 @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool"
64 ifeq ($(HAVE_PYTHON_YAML),yes)
65 @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file."
67 @echo " (install python3-yaml to enable support for yaml file to configure a VM.)"
69 @echo " See conf_example_*.yml for file format details."
71 vm-build-all: $(addprefix vm-build-, $(IMAGES))
76 $(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \
77 $(SRC_PATH)/tests/vm/basevm.py \
78 $(SRC_PATH)/tests/vm/Makefile.include
79 @mkdir -p $(IMAGES_DIR)
80 $(call quiet-command, \
82 $(if $(V)$(DEBUG), --debug) \
83 $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
84 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
85 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
86 $(if $(LOG_CONSOLE),--log-console) \
93 # Build in VM $(IMAGE)
94 vm-build-%: $(IMAGES_DIR)/%.img
95 $(call quiet-command, \
96 $(PYTHON) $(SRC_PATH)/tests/vm/$* \
97 $(if $(V)$(DEBUG), --debug) \
98 $(if $(DEBUG), --interactive) \
99 $(if $(J),--jobs $(J)) \
100 $(if $(V),--verbose) \
101 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
102 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
103 $(if $(LOG_CONSOLE),--log-console) \
105 $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
107 --build-qemu $(SRC_PATH) -- \
108 $(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \
109 $(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \
112 vm-boot-serial-%: $(IMAGES_DIR)/%.img
113 qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \
114 -drive if=none,id=vblk,cache=writeback,file="$<" \
115 -netdev user,id=vnet \
116 -device virtio-blk-pci,drive=vblk \
117 -device virtio-net-pci,netdev=vnet \
120 vm-boot-ssh-%: $(IMAGES_DIR)/%.img
121 $(call quiet-command, \
122 $(PYTHON) $(SRC_PATH)/tests/vm/$* \
123 $(if $(J),--jobs $(J)) \
124 $(if $(V)$(DEBUG), --debug) \
125 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
126 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
127 $(if $(LOG_CONSOLE),--log-console) \
131 " VM-BOOT-SSH $*") || true