1b1fb9a63SFam Zheng# Makefile for VM tests 2b1fb9a63SFam Zheng 3ebe95fa0SFam Zheng.PHONY: vm-build-all vm-clean-all 4b1fb9a63SFam Zheng 539d87c8cSAlex BennéeIMAGES := freebsd netbsd openbsd centos fedora 639d87c8cSAlex Bennéeifneq ($(GENISOIMAGE),) 739d87c8cSAlex BennéeIMAGES += ubuntu.i386 centos 813336606SRobert Foleyifneq ($(EFI_AARCH64),) 9*d322fe2dSRobert FoleyIMAGES += ubuntu.aarch64 centos.aarch64 1013336606SRobert Foleyendif 1139d87c8cSAlex Bennéeendif 1239d87c8cSAlex Bennée 13bd1497dcSGerd HoffmannIMAGES_DIR := $(HOME)/.cache/qemu-vm/images 14bd1497dcSGerd HoffmannIMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES)) 15b1fb9a63SFam Zheng 16b1fb9a63SFam Zheng.PRECIOUS: $(IMAGE_FILES) 17b1fb9a63SFam Zheng 184f2f6276SPhilippe Mathieu-Daudé# 'vm-help' target was historically named 'vm-test' 194f2f6276SPhilippe Mathieu-Daudévm-help vm-test: 204f2f6276SPhilippe Mathieu-Daudé @echo "vm-help: Test QEMU in preconfigured virtual machines" 21b1fb9a63SFam Zheng @echo 22b1fb9a63SFam Zheng @echo " vm-build-freebsd - Build QEMU in FreeBSD VM" 23b1fb9a63SFam Zheng @echo " vm-build-netbsd - Build QEMU in NetBSD VM" 24b1fb9a63SFam Zheng @echo " vm-build-openbsd - Build QEMU in OpenBSD VM" 2560136e06SGerd Hoffmann @echo " vm-build-fedora - Build QEMU in Fedora VM" 2639d87c8cSAlex Bennéeifneq ($(GENISOIMAGE),) 2739d87c8cSAlex Bennée @echo " vm-build-centos - Build QEMU in CentOS VM, with Docker" 2839d87c8cSAlex Bennée @echo " vm-build-ubuntu.i386 - Build QEMU in ubuntu i386 VM" 2913336606SRobert Foleyifneq ($(EFI_AARCH64),) 3013336606SRobert Foley @echo " vm-build-ubuntu.aarch64 - Build QEMU in ubuntu aarch64 VM" 31*d322fe2dSRobert Foley @echo " vm-build-centos.aarch64 - Build QEMU in CentOS aarch64 VM" 3213336606SRobert Foleyelse 3313336606SRobert Foley @echo " (to build centos/ubuntu aarch64 images use configure --efi-aarch64)" 3413336606SRobert Foleyendif 3539d87c8cSAlex Bennéeelse 3639d87c8cSAlex Bennée @echo " (install genisoimage to build centos/ubuntu images)" 3739d87c8cSAlex Bennéeendif 38af7e9168SFam Zheng @echo "" 39af7e9168SFam Zheng @echo " vm-build-all - Build QEMU in all VMs" 40af7e9168SFam Zheng @echo " vm-clean-all - Clean up VM images" 41ddafa31fSAlex Bennée @echo 42b1210f02SGerd Hoffmann @echo "For trouble-shooting:" 43b1210f02SGerd Hoffmann @echo " vm-boot-serial-<guest> - Boot guest, serial console on stdio" 44b1210f02SGerd Hoffmann @echo " vm-boot-ssh-<guest> - Boot guest and login via ssh" 45b1210f02SGerd Hoffmann @echo 46ddafa31fSAlex Bennée @echo "Special variables:" 47eec4b30aSWainer dos Santos Moschetta @echo " BUILD_TARGET=foo - Override the build target" 48eec4b30aSWainer dos Santos Moschetta @echo " TARGET_LIST=a,b,c - Override target list in builds" 49ddafa31fSAlex Bennée @echo ' EXTRA_CONFIGURE_OPTS="..."' 50eec4b30aSWainer dos Santos Moschetta @echo " J=[0..9]* - Override the -jN parameter for make commands" 51eec4b30aSWainer dos Santos Moschetta @echo " DEBUG=1 - Enable verbose output on host and interactive debugging" 52eec4b30aSWainer dos Santos Moschetta @echo " V=1 - Enable verbose ouput on host and guest commands" 53e56c4504SRobert Foley @echo " QEMU_LOCAL=1 - Use QEMU binary local to this build." 54eec4b30aSWainer dos Santos Moschetta @echo " QEMU=/path/to/qemu - Change path to QEMU binary" 551e48931cSWainer dos Santos Moschetta @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool" 563f1e8137SRobert Foleyifeq ($(PYTHON_YAML),yes) 573f1e8137SRobert Foley @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file." 583f1e8137SRobert Foleyelse 593f1e8137SRobert Foley @echo " (install python3-yaml to enable support for yaml file to configure a VM.)" 603f1e8137SRobert Foleyendif 613f1e8137SRobert Foley @echo " See conf_example_*.yml for file format details." 62b1fb9a63SFam Zheng 63b1fb9a63SFam Zhengvm-build-all: $(addprefix vm-build-, $(IMAGES)) 64b1fb9a63SFam Zheng 65ebe95fa0SFam Zhengvm-clean-all: 66ebe95fa0SFam Zheng rm -f $(IMAGE_FILES) 67ebe95fa0SFam Zheng 68bd1497dcSGerd Hoffmann$(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \ 69b1fb9a63SFam Zheng $(SRC_PATH)/tests/vm/basevm.py \ 70b1fb9a63SFam Zheng $(SRC_PATH)/tests/vm/Makefile.include 71bd1497dcSGerd Hoffmann @mkdir -p $(IMAGES_DIR) 72b1fb9a63SFam Zheng $(call quiet-command, \ 73b0040fa1SWainer dos Santos Moschetta $(PYTHON) $< \ 74b1fb9a63SFam Zheng $(if $(V)$(DEBUG), --debug) \ 7592fecad3SAlex Bennée $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \ 76e56c4504SRobert Foley $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 7713336606SRobert Foley $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 78b1fb9a63SFam Zheng --image "$@" \ 79b1fb9a63SFam Zheng --force \ 80b1fb9a63SFam Zheng --build-image $@, \ 81b1fb9a63SFam Zheng " VM-IMAGE $*") 82b1fb9a63SFam Zheng 83b1fb9a63SFam Zheng 84b1fb9a63SFam Zheng# Build in VM $(IMAGE) 85bd1497dcSGerd Hoffmannvm-build-%: $(IMAGES_DIR)/%.img 86b1fb9a63SFam Zheng $(call quiet-command, \ 87b0040fa1SWainer dos Santos Moschetta $(PYTHON) $(SRC_PATH)/tests/vm/$* \ 88b1fb9a63SFam Zheng $(if $(V)$(DEBUG), --debug) \ 89b1fb9a63SFam Zheng $(if $(DEBUG), --interactive) \ 90b1fb9a63SFam Zheng $(if $(J),--jobs $(J)) \ 9141e3340aSPeter Maydell $(if $(V),--verbose) \ 92e56c4504SRobert Foley $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 9313336606SRobert Foley $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 94b1fb9a63SFam Zheng --image "$<" \ 95ddafa31fSAlex Bennée $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \ 967f71d505SGerd Hoffmann --snapshot \ 97ddafa31fSAlex Bennée --build-qemu $(SRC_PATH) -- \ 98ddafa31fSAlex Bennée $(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \ 99ddafa31fSAlex Bennée $(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \ 100b1fb9a63SFam Zheng " VM-BUILD $*") 101b1fb9a63SFam Zheng 102b1210f02SGerd Hoffmannvm-boot-serial-%: $(IMAGES_DIR)/%.img 103b1210f02SGerd Hoffmann qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \ 104b1210f02SGerd Hoffmann -drive if=none,id=vblk,cache=writeback,file="$<" \ 105b1210f02SGerd Hoffmann -netdev user,id=vnet \ 106b1210f02SGerd Hoffmann -device virtio-blk-pci,drive=vblk \ 107b1210f02SGerd Hoffmann -device virtio-net-pci,netdev=vnet \ 108b1210f02SGerd Hoffmann || true 109b1210f02SGerd Hoffmann 110b1210f02SGerd Hoffmannvm-boot-ssh-%: $(IMAGES_DIR)/%.img 111b1210f02SGerd Hoffmann $(call quiet-command, \ 1120bc72f90SRobert Foley $(PYTHON) $(SRC_PATH)/tests/vm/$* \ 11346313326SThomas Huth $(if $(J),--jobs $(J)) \ 114d5326a24SRobert Foley $(if $(V)$(DEBUG), --debug) \ 115e56c4504SRobert Foley $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 11613336606SRobert Foley $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \ 117b1210f02SGerd Hoffmann --image "$<" \ 118b1210f02SGerd Hoffmann --interactive \ 119b1210f02SGerd Hoffmann false, \ 120b1210f02SGerd Hoffmann " VM-BOOT-SSH $*") || true 121