1# Makefile for VM tests 2 3.PHONY: vm-build-all vm-clean-all 4 5EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd) 6 7IMAGES := freebsd netbsd openbsd centos fedora haiku.x86_64 8ifneq ($(GENISOIMAGE),) 9IMAGES += ubuntu.i386 centos 10ifneq ($(EFI_AARCH64),) 11IMAGES += ubuntu.aarch64 centos.aarch64 12endif 13endif 14 15IMAGES_DIR := $(HOME)/.cache/qemu-vm/images 16IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES)) 17 18.PRECIOUS: $(IMAGE_FILES) 19 20ifneq ($(PYTHON),) 21HAVE_PYTHON_YAML = $(shell $(PYTHON) -c "import yaml" 2> /dev/null && echo yes) 22endif 23 24# 'vm-help' target was historically named 'vm-test' 25vm-help vm-test: 26 @echo "vm-help: Test QEMU in preconfigured virtual machines" 27 @echo 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" 32ifneq ($(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" 35ifneq ($(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" 38else 39 @echo " (to build centos/ubuntu aarch64 images use configure --efi-aarch64)" 40endif 41else 42 @echo " (install genisoimage to build centos/ubuntu images)" 43endif 44 @echo " vm-build-haiku.x86_64 - Build QEMU in Haiku VM" 45 @echo "" 46 @echo " vm-build-all - Build QEMU in all VMs" 47 @echo " vm-clean-all - Clean up VM images" 48 @echo 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" 52 @echo 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" 64ifeq ($(HAVE_PYTHON_YAML),yes) 65 @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file." 66else 67 @echo " (install python3-yaml to enable support for yaml file to configure a VM.)" 68endif 69 @echo " See conf_example_*.yml for file format details." 70 71vm-build-all: $(addprefix vm-build-, $(IMAGES)) 72 73vm-clean-all: 74 rm -f $(IMAGE_FILES) 75 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, \ 81 $(PYTHON) $< \ 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) \ 87 --image "$@" \ 88 --force \ 89 --build-image $@, \ 90 " VM-IMAGE $*") 91 92 93# Build in VM $(IMAGE) 94vm-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) \ 104 --image "$<" \ 105 $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \ 106 --snapshot \ 107 --build-qemu $(SRC_PATH) -- \ 108 $(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \ 109 $(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \ 110 " VM-BUILD $*") 111 112vm-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 \ 118 || true 119 120vm-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) \ 128 --image "$<" \ 129 --interactive \ 130 false, \ 131 " VM-BOOT-SSH $*") || true 132