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