1# Makefile for VM tests 2 3.PHONY: vm-build-all vm-clean-all 4 5IMAGES := freebsd netbsd openbsd centos fedora 6ifneq ($(GENISOIMAGE),) 7IMAGES += ubuntu.i386 centos 8ifneq ($(EFI_AARCH64),) 9IMAGES += ubuntu.aarch64 centos.aarch64 10endif 11endif 12 13IMAGES_DIR := $(HOME)/.cache/qemu-vm/images 14IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES)) 15 16.PRECIOUS: $(IMAGE_FILES) 17 18# 'vm-help' target was historically named 'vm-test' 19vm-help vm-test: 20 @echo "vm-help: Test QEMU in preconfigured virtual machines" 21 @echo 22 @echo " vm-build-freebsd - Build QEMU in FreeBSD VM" 23 @echo " vm-build-netbsd - Build QEMU in NetBSD VM" 24 @echo " vm-build-openbsd - Build QEMU in OpenBSD VM" 25 @echo " vm-build-fedora - Build QEMU in Fedora VM" 26ifneq ($(GENISOIMAGE),) 27 @echo " vm-build-centos - Build QEMU in CentOS VM, with Docker" 28 @echo " vm-build-ubuntu.i386 - Build QEMU in ubuntu i386 VM" 29ifneq ($(EFI_AARCH64),) 30 @echo " vm-build-ubuntu.aarch64 - Build QEMU in ubuntu aarch64 VM" 31 @echo " vm-build-centos.aarch64 - Build QEMU in CentOS aarch64 VM" 32else 33 @echo " (to build centos/ubuntu aarch64 images use configure --efi-aarch64)" 34endif 35else 36 @echo " (install genisoimage to build centos/ubuntu images)" 37endif 38 @echo "" 39 @echo " vm-build-all - Build QEMU in all VMs" 40 @echo " vm-clean-all - Clean up VM images" 41 @echo 42 @echo "For trouble-shooting:" 43 @echo " vm-boot-serial-<guest> - Boot guest, serial console on stdio" 44 @echo " vm-boot-ssh-<guest> - Boot guest and login via ssh" 45 @echo 46 @echo "Special variables:" 47 @echo " BUILD_TARGET=foo - Override the build target" 48 @echo " TARGET_LIST=a,b,c - Override target list in builds" 49 @echo ' EXTRA_CONFIGURE_OPTS="..."' 50 @echo " J=[0..9]* - Override the -jN parameter for make commands" 51 @echo " DEBUG=1 - Enable verbose output on host and interactive debugging" 52 @echo " V=1 - Enable verbose ouput on host and guest commands" 53 @echo " QEMU_LOCAL=1 - Use QEMU binary local to this build." 54 @echo " QEMU=/path/to/qemu - Change path to QEMU binary" 55 @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool" 56ifeq ($(PYTHON_YAML),yes) 57 @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file." 58else 59 @echo " (install python3-yaml to enable support for yaml file to configure a VM.)" 60endif 61 @echo " See conf_example_*.yml for file format details." 62 63vm-build-all: $(addprefix vm-build-, $(IMAGES)) 64 65vm-clean-all: 66 rm -f $(IMAGE_FILES) 67 68$(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \ 69 $(SRC_PATH)/tests/vm/basevm.py \ 70 $(SRC_PATH)/tests/vm/Makefile.include 71 @mkdir -p $(IMAGES_DIR) 72 $(call quiet-command, \ 73 $(PYTHON) $< \ 74 $(if $(V)$(DEBUG), --debug) \ 75 $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \ 76 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 77 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 78 --image "$@" \ 79 --force \ 80 --build-image $@, \ 81 " VM-IMAGE $*") 82 83 84# Build in VM $(IMAGE) 85vm-build-%: $(IMAGES_DIR)/%.img 86 $(call quiet-command, \ 87 $(PYTHON) $(SRC_PATH)/tests/vm/$* \ 88 $(if $(V)$(DEBUG), --debug) \ 89 $(if $(DEBUG), --interactive) \ 90 $(if $(J),--jobs $(J)) \ 91 $(if $(V),--verbose) \ 92 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 93 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 94 --image "$<" \ 95 $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \ 96 --snapshot \ 97 --build-qemu $(SRC_PATH) -- \ 98 $(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \ 99 $(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \ 100 " VM-BUILD $*") 101 102vm-boot-serial-%: $(IMAGES_DIR)/%.img 103 qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \ 104 -drive if=none,id=vblk,cache=writeback,file="$<" \ 105 -netdev user,id=vnet \ 106 -device virtio-blk-pci,drive=vblk \ 107 -device virtio-net-pci,netdev=vnet \ 108 || true 109 110vm-boot-ssh-%: $(IMAGES_DIR)/%.img 111 $(call quiet-command, \ 112 $(PYTHON) $(SRC_PATH)/tests/vm/$* \ 113 $(if $(J),--jobs $(J)) \ 114 $(if $(V)$(DEBUG), --debug) \ 115 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 116 $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 117 --image "$<" \ 118 --interactive \ 119 false, \ 120 " VM-BOOT-SSH $*") || true 121