xref: /openbmc/qemu/tests/vm/Makefile.include (revision ca27b5eb)
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_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"
47
48vm-build-all: $(addprefix vm-build-, $(IMAGES))
49
50vm-clean-all:
51	rm -f $(IMAGE_FILES)
52
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, \
58		$(PYTHON) $< \
59		$(if $(V)$(DEBUG), --debug) \
60		$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
61		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
62		--image "$@" \
63		--force \
64		--build-image $@, \
65		"  VM-IMAGE $*")
66
67
68# Build in VM $(IMAGE)
69vm-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)) \
77		--image "$<" \
78		$(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
79		--snapshot \
80		--build-qemu $(SRC_PATH) -- \
81		$(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \
82		$(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \
83		"  VM-BUILD $*")
84
85vm-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 \
91	|| true
92
93vm-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)) \
99		--image "$<" \
100		--interactive \
101		false, \
102		"  VM-BOOT-SSH $*") || true
103