1 # Makefile for VM tests
3 .PHONY: vm-build-all vm-clean-all
5 IMAGES := freebsd netbsd openbsd centos fedora
6 ifneq ($(GENISOIMAGE),)
7 IMAGES += ubuntu.i386 centos
10 IMAGES_DIR := $(HOME)/.cache/qemu-vm/images
11 IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
13 .PRECIOUS: $(IMAGE_FILES)
15 # 'vm-help' target was historically named 'vm-test'
17 @echo "vm-help: Test QEMU in preconfigured virtual machines"
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"
23 ifneq ($(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"
27 @echo " (install genisoimage to build centos/ubuntu images)"
30 @echo " vm-build-all - Build QEMU in all VMs"
31 @echo " vm-clean-all - Clean up VM images"
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"
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_LOCAL=1 - Use QEMU binary local to this build."
45 @echo " QEMU=/path/to/qemu - Change path to QEMU binary"
46 @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool"
48 vm-build-all: $(addprefix vm-build-, $(IMAGES))
53 $(IMAGES_DIR)/%.img: $(SRC_PATH)/tests/vm/% \
54 $(SRC_PATH)/tests/vm/basevm.py \
55 $(SRC_PATH)/tests/vm/Makefile.include
56 @mkdir -p $(IMAGES_DIR)
57 $(call quiet-command, \
59 $(if $(V)$(DEBUG), --debug) \
60 $(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
61 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
68 # Build in VM $(IMAGE)
69 vm-build-%: $(IMAGES_DIR)/%.img
70 $(call quiet-command, \
71 $(PYTHON) $(SRC_PATH)/tests/vm/$* \
72 $(if $(V)$(DEBUG), --debug) \
73 $(if $(DEBUG), --interactive) \
74 $(if $(J),--jobs $(J)) \
75 $(if $(V),--verbose) \
76 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
78 $(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
80 --build-qemu $(SRC_PATH) -- \
81 $(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \
82 $(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \
85 vm-boot-serial-%: $(IMAGES_DIR)/%.img
86 qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \
87 -drive if=none,id=vblk,cache=writeback,file="$<" \
88 -netdev user,id=vnet \
89 -device virtio-blk-pci,drive=vblk \
90 -device virtio-net-pci,netdev=vnet \
93 vm-boot-ssh-%: $(IMAGES_DIR)/%.img
94 $(call quiet-command, \
95 $(PYTHON) $(SRC_PATH)/tests/vm/$* \
96 $(if $(J),--jobs $(J)) \
97 $(if $(V)$(DEBUG), --debug) \
98 $(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
102 " VM-BOOT-SSH $*") || true