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