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 839d87c8cSAlex Bennéeendif 939d87c8cSAlex Bennée 10bd1497dcSGerd HoffmannIMAGES_DIR := $(HOME)/.cache/qemu-vm/images 11bd1497dcSGerd HoffmannIMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES)) 12b1fb9a63SFam Zheng 13b1fb9a63SFam Zheng.PRECIOUS: $(IMAGE_FILES) 14b1fb9a63SFam Zheng 154f2f6276SPhilippe Mathieu-Daudé# 'vm-help' target was historically named 'vm-test' 164f2f6276SPhilippe Mathieu-Daudévm-help vm-test: 174f2f6276SPhilippe Mathieu-Daudé @echo "vm-help: Test QEMU in preconfigured virtual machines" 18b1fb9a63SFam Zheng @echo 19b1fb9a63SFam Zheng @echo " vm-build-freebsd - Build QEMU in FreeBSD VM" 20b1fb9a63SFam Zheng @echo " vm-build-netbsd - Build QEMU in NetBSD VM" 21b1fb9a63SFam Zheng @echo " vm-build-openbsd - Build QEMU in OpenBSD VM" 2260136e06SGerd Hoffmann @echo " vm-build-fedora - Build QEMU in Fedora VM" 2339d87c8cSAlex Bennéeifneq ($(GENISOIMAGE),) 2439d87c8cSAlex Bennée @echo " vm-build-centos - Build QEMU in CentOS VM, with Docker" 2539d87c8cSAlex Bennée @echo " vm-build-ubuntu.i386 - Build QEMU in ubuntu i386 VM" 2639d87c8cSAlex Bennéeelse 2739d87c8cSAlex Bennée @echo " (install genisoimage to build centos/ubuntu images)" 2839d87c8cSAlex Bennéeendif 29af7e9168SFam Zheng @echo "" 30af7e9168SFam Zheng @echo " vm-build-all - Build QEMU in all VMs" 31af7e9168SFam Zheng @echo " vm-clean-all - Clean up VM images" 32ddafa31fSAlex Bennée @echo 33b1210f02SGerd Hoffmann @echo "For trouble-shooting:" 34b1210f02SGerd Hoffmann @echo " vm-boot-serial-<guest> - Boot guest, serial console on stdio" 35b1210f02SGerd Hoffmann @echo " vm-boot-ssh-<guest> - Boot guest and login via ssh" 36b1210f02SGerd Hoffmann @echo 37ddafa31fSAlex Bennée @echo "Special variables:" 38eec4b30aSWainer dos Santos Moschetta @echo " BUILD_TARGET=foo - Override the build target" 39eec4b30aSWainer dos Santos Moschetta @echo " TARGET_LIST=a,b,c - Override target list in builds" 40ddafa31fSAlex Bennée @echo ' EXTRA_CONFIGURE_OPTS="..."' 41eec4b30aSWainer dos Santos Moschetta @echo " J=[0..9]* - Override the -jN parameter for make commands" 42eec4b30aSWainer dos Santos Moschetta @echo " DEBUG=1 - Enable verbose output on host and interactive debugging" 43eec4b30aSWainer dos Santos Moschetta @echo " V=1 - Enable verbose ouput on host and guest commands" 44e56c4504SRobert Foley @echo " QEMU_LOCAL=1 - Use QEMU binary local to this build." 45eec4b30aSWainer dos Santos Moschetta @echo " QEMU=/path/to/qemu - Change path to QEMU binary" 461e48931cSWainer dos Santos Moschetta @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool" 47*3f1e8137SRobert Foleyifeq ($(PYTHON_YAML),yes) 48*3f1e8137SRobert Foley @echo " QEMU_CONFIG=/path/conf.yml - Change path to VM configuration .yml file." 49*3f1e8137SRobert Foleyelse 50*3f1e8137SRobert Foley @echo " (install python3-yaml to enable support for yaml file to configure a VM.)" 51*3f1e8137SRobert Foleyendif 52*3f1e8137SRobert Foley @echo " See conf_example_*.yml for file format details." 53b1fb9a63SFam Zheng 54b1fb9a63SFam Zhengvm-build-all: $(addprefix vm-build-, $(IMAGES)) 55b1fb9a63SFam Zheng 56ebe95fa0SFam Zhengvm-clean-all: 57ebe95fa0SFam Zheng rm -f $(IMAGE_FILES) 58ebe95fa0SFam Zheng 59bd1497dcSGerd Hoffmann$(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \ 60b1fb9a63SFam Zheng $(SRC_PATH)/tests/vm/basevm.py \ 61b1fb9a63SFam Zheng $(SRC_PATH)/tests/vm/Makefile.include 62bd1497dcSGerd Hoffmann @mkdir -p $(IMAGES_DIR) 63b1fb9a63SFam Zheng $(call quiet-command, \ 64b0040fa1SWainer dos Santos Moschetta $(PYTHON) $< \ 65b1fb9a63SFam Zheng $(if $(V)$(DEBUG), --debug) \ 6692fecad3SAlex Bennée $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \ 67e56c4504SRobert Foley $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 68b1fb9a63SFam Zheng --image "$@" \ 69b1fb9a63SFam Zheng --force \ 70b1fb9a63SFam Zheng --build-image $@, \ 71b1fb9a63SFam Zheng " VM-IMAGE $*") 72b1fb9a63SFam Zheng 73b1fb9a63SFam Zheng 74b1fb9a63SFam Zheng# Build in VM $(IMAGE) 75bd1497dcSGerd Hoffmannvm-build-%: $(IMAGES_DIR)/%.img 76b1fb9a63SFam Zheng $(call quiet-command, \ 77b0040fa1SWainer dos Santos Moschetta $(PYTHON) $(SRC_PATH)/tests/vm/$* \ 78b1fb9a63SFam Zheng $(if $(V)$(DEBUG), --debug) \ 79b1fb9a63SFam Zheng $(if $(DEBUG), --interactive) \ 80b1fb9a63SFam Zheng $(if $(J),--jobs $(J)) \ 8141e3340aSPeter Maydell $(if $(V),--verbose) \ 82e56c4504SRobert Foley $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 83b1fb9a63SFam Zheng --image "$<" \ 84ddafa31fSAlex Bennée $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \ 857f71d505SGerd Hoffmann --snapshot \ 86ddafa31fSAlex Bennée --build-qemu $(SRC_PATH) -- \ 87ddafa31fSAlex Bennée $(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \ 88ddafa31fSAlex Bennée $(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \ 89b1fb9a63SFam Zheng " VM-BUILD $*") 90b1fb9a63SFam Zheng 91b1210f02SGerd Hoffmannvm-boot-serial-%: $(IMAGES_DIR)/%.img 92b1210f02SGerd Hoffmann qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \ 93b1210f02SGerd Hoffmann -drive if=none,id=vblk,cache=writeback,file="$<" \ 94b1210f02SGerd Hoffmann -netdev user,id=vnet \ 95b1210f02SGerd Hoffmann -device virtio-blk-pci,drive=vblk \ 96b1210f02SGerd Hoffmann -device virtio-net-pci,netdev=vnet \ 97b1210f02SGerd Hoffmann || true 98b1210f02SGerd Hoffmann 99b1210f02SGerd Hoffmannvm-boot-ssh-%: $(IMAGES_DIR)/%.img 100b1210f02SGerd Hoffmann $(call quiet-command, \ 1010bc72f90SRobert Foley $(PYTHON) $(SRC_PATH)/tests/vm/$* \ 10246313326SThomas Huth $(if $(J),--jobs $(J)) \ 103d5326a24SRobert Foley $(if $(V)$(DEBUG), --debug) \ 104e56c4504SRobert Foley $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \ 105b1210f02SGerd Hoffmann --image "$<" \ 106b1210f02SGerd Hoffmann --interactive \ 107b1210f02SGerd Hoffmann false, \ 108b1210f02SGerd Hoffmann " VM-BOOT-SSH $*") || true 109