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 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 "" 45 @echo " vm-build-all - Build QEMU in all VMs" 46 @echo " vm-clean-all - Clean up VM images" 47 @echo 48 @echo "For trouble-shooting:" 49 @echo " vm-boot-serial-<guest> - Boot guest, serial console on stdio" 50 @echo " vm-boot-ssh-<guest> - Boot guest and login via ssh" 51 @echo 52 @echo "Special variables:" 53 @echo " BUILD_TARGET=foo - Override the build target" 54 @echo " TARGET_LIST=a,b,c - Override target list in builds" 55 @echo ' EXTRA_CONFIGURE_OPTS="..."' 56 @echo " J=[0..9]* - Override the -jN parameter for make commands" 57 @echo " DEBUG=1 - Enable verbose output on host and interactive debugging" 58 @echo " LOG_CONSOLE=1 - Log console to file in: ~/.cache/qemu-vm " 59 @echo " V=1 - Enable verbose ouput on host and guest commands" 60 @echo " QEMU_LOCAL=1 - Use QEMU binary local to this build." 61 @echo " QEMU=/path/to/qemu - Change path to QEMU binary" 62 @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool" 63ifeq ($(HAVE_PYTHON_YAML),yes) 64 @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file." 65else 66 @echo " (install python3-yaml to enable support for yaml file to configure a VM.)" 67endif 68 @echo " See conf_example_*.yml for file format details." 69 70vm-build-all: $(addprefix vm-build-, $(IMAGES)) 71 72vm-clean-all: 73 rm -f $(IMAGE_FILES) 74 75$(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \ 76 $(SRC_PATH)/tests/vm/basevm.py \ 77 $(SRC_PATH)/tests/vm/Makefile.include 78 @mkdir -p $(IMAGES_DIR) 79 $(call quiet-command, \ 80 $(PYTHON) $< \ 81 $(if $(V)$(DEBUG), --debug) \ 82 $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \ 83 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 84 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 85 $(if $(LOG_CONSOLE),--log-console) \ 86 --image "$@" \ 87 --force \ 88 --build-image $@, \ 89 " VM-IMAGE $*") 90 91 92# Build in VM $(IMAGE) 93vm-build-%: $(IMAGES_DIR)/%.img 94 $(call quiet-command, \ 95 $(PYTHON) $(SRC_PATH)/tests/vm/$* \ 96 $(if $(V)$(DEBUG), --debug) \ 97 $(if $(DEBUG), --interactive) \ 98 $(if $(J),--jobs $(J)) \ 99 $(if $(V),--verbose) \ 100 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 101 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 102 $(if $(LOG_CONSOLE),--log-console) \ 103 --image "$<" \ 104 $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \ 105 --snapshot \ 106 --build-qemu $(SRC_PATH) -- \ 107 $(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \ 108 $(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \ 109 " VM-BUILD $*") 110 111vm-boot-serial-%: $(IMAGES_DIR)/%.img 112 qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \ 113 -drive if=none,id=vblk,cache=writeback,file="$<" \ 114 -netdev user,id=vnet \ 115 -device virtio-blk-pci,drive=vblk \ 116 -device virtio-net-pci,netdev=vnet \ 117 || true 118 119vm-boot-ssh-%: $(IMAGES_DIR)/%.img 120 $(call quiet-command, \ 121 $(PYTHON) $(SRC_PATH)/tests/vm/$* \ 122 $(if $(J),--jobs $(J)) \ 123 $(if $(V)$(DEBUG), --debug) \ 124 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 125 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 126 $(if $(LOG_CONSOLE),--log-console) \ 127 --image "$<" \ 128 --interactive \ 129 false, \ 130 " VM-BOOT-SSH $*") || true 131