1# Makefile for VM tests 2 3.PHONY: vm-build-all vm-clean-all 4 5HOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m)) 6 7EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd) 8 9X86_IMAGES := freebsd netbsd openbsd centos fedora haiku.x86_64 10ifneq ($(GENISOIMAGE),) 11X86_IMAGES += ubuntu.i386 centos 12ifneq ($(EFI_AARCH64),) 13ARM64_IMAGES += ubuntu.aarch64 centos.aarch64 14endif 15endif 16 17ifeq ($(HOST_ARCH),x86_64) 18IMAGES=$(X86_IMAGES) $(if $(USE_TCG),$(ARM64_IMAGES)) 19else ifeq ($(HOST_ARCH),aarch64) 20IMAGES=$(ARM64_IMAGES) $(if $(USE_TCG),$(X86_IMAGES)) 21endif 22 23IMAGES_DIR := $(HOME)/.cache/qemu-vm/images 24IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES)) 25 26.PRECIOUS: $(IMAGE_FILES) 27 28ifneq ($(PYTHON),) 29HAVE_PYTHON_YAML = $(shell $(PYTHON) -c "import yaml" 2> /dev/null && echo yes) 30endif 31 32# 'vm-help' target was historically named 'vm-test' 33vm-help vm-test: 34 @echo "vm-help: Test QEMU in preconfigured virtual machines" 35 @echo 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" 40ifneq ($(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" 43ifneq ($(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" 46else 47 @echo " (to build centos/ubuntu aarch64 images use configure --efi-aarch64)" 48endif 49else 50 @echo " (install genisoimage to build centos/ubuntu images)" 51endif 52 @echo " vm-build-haiku.x86_64 - Build QEMU in Haiku VM" 53 @echo "" 54 @echo " vm-build-all - Build QEMU in: $(IMAGES)" 55 @echo " vm-clean-all - Clean up VM images" 56 @echo 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" 60 @echo 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" 69ifeq ($(HAVE_PYTHON_YAML),yes) 70 @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file." 71else 72 @echo " (install python3-yaml to enable support for yaml file to configure a VM.)" 73endif 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" 79 80vm-build-all: $(addprefix vm-build-, $(IMAGES)) 81 82vm-clean-all: 83 rm -f $(IMAGE_FILES) 84 85$(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \ 86 $(SRC_PATH)/tests/vm/basevm.py \ 87 $(SRC_PATH)/tests/vm/Makefile.include \ 88 check-venv 89 @mkdir -p $(IMAGES_DIR) 90 $(call quiet-command, \ 91 $(TESTS_PYTHON) $< \ 92 $(if $(V)$(DEBUG), --debug) \ 93 $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \ 94 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 95 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 96 $(if $(LOG_CONSOLE),--log-console) \ 97 --source-path $(SRC_PATH) \ 98 --image "$@" \ 99 --force \ 100 --build-image $@, \ 101 " VM-IMAGE $*") 102 103 104# Build in VM $(IMAGE) 105vm-build-%: $(IMAGES_DIR)/%.img check-venv 106 $(call quiet-command, \ 107 $(TESTS_PYTHON) $(SRC_PATH)/tests/vm/$* \ 108 $(if $(V)$(DEBUG), --debug) \ 109 $(if $(DEBUG), --interactive) \ 110 $(if $(J),--jobs $(J)) \ 111 $(if $(V),--verbose) \ 112 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 113 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 114 $(if $(LOG_CONSOLE),--log-console) \ 115 --image "$<" \ 116 $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \ 117 --snapshot \ 118 --build-qemu $(SRC_PATH) -- \ 119 $(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \ 120 $(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \ 121 " VM-BUILD $*") 122 123vm-boot-serial-%: $(IMAGES_DIR)/%.img 124 qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \ 125 -drive if=none,id=vblk,cache=writeback,file="$<" \ 126 -netdev user,id=vnet \ 127 -device virtio-blk-pci,drive=vblk \ 128 -device virtio-net-pci,netdev=vnet \ 129 || true 130 131vm-boot-ssh-%: $(IMAGES_DIR)/%.img check-venv 132 $(call quiet-command, \ 133 $(TESTS_PYTHON) $(SRC_PATH)/tests/vm/$* \ 134 $(if $(J),--jobs $(J)) \ 135 $(if $(V)$(DEBUG), --debug) \ 136 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 137 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 138 $(if $(LOG_CONSOLE),--log-console) \ 139 --image "$<" \ 140 --interactive \ 141 false, \ 142 " VM-BOOT-SSH $*") || true 143