xref: /openbmc/qemu/tests/vm/Makefile.include (revision 5aa62804)
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		$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
60		--image "$@" \
61		--force \
62		--build-image $@, \
63		"  VM-IMAGE $*")
64
65
66# Build in VM $(IMAGE)
67vm-build-%: $(IMAGES_DIR)/%.img
68	$(call quiet-command, \
69		$(PYTHON) $(SRC_PATH)/tests/vm/$* \
70		$(if $(V)$(DEBUG), --debug) \
71		$(if $(DEBUG), --interactive) \
72		$(if $(J),--jobs $(J)) \
73		$(if $(V),--verbose) \
74		--image "$<" \
75		$(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
76		--snapshot \
77		--build-qemu $(SRC_PATH) -- \
78		$(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \
79		$(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \
80		"  VM-BUILD $*")
81
82vm-boot-serial-%: $(IMAGES_DIR)/%.img
83	qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \
84		-drive if=none,id=vblk,cache=writeback,file="$<" \
85		-netdev user,id=vnet \
86		-device virtio-blk-pci,drive=vblk \
87		-device virtio-net-pci,netdev=vnet \
88	|| true
89
90vm-boot-ssh-%: $(IMAGES_DIR)/%.img
91	$(call quiet-command, \
92		$(PYTHON) $(SRC_PATH)/tests/vm/$* \
93		$(if $(J),--jobs $(J)) \
94		--image "$<" \
95		--interactive \
96		false, \
97		"  VM-BOOT-SSH $*") || true
98