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