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