xref: /openbmc/qemu/tests/vm/Makefile.include (revision 13336606a5ef9d6beeb8c0763ac0a9d11c249cac)
1b1fb9a63SFam Zheng# Makefile for VM tests
2b1fb9a63SFam Zheng
3ebe95fa0SFam Zheng.PHONY: vm-build-all vm-clean-all
4b1fb9a63SFam Zheng
539d87c8cSAlex BennéeIMAGES := freebsd netbsd openbsd centos fedora
639d87c8cSAlex Bennéeifneq ($(GENISOIMAGE),)
739d87c8cSAlex BennéeIMAGES += ubuntu.i386 centos
8*13336606SRobert Foleyifneq ($(EFI_AARCH64),)
9*13336606SRobert FoleyIMAGES += ubuntu.aarch64
10*13336606SRobert Foleyendif
1139d87c8cSAlex Bennéeendif
1239d87c8cSAlex Bennée
13bd1497dcSGerd HoffmannIMAGES_DIR := $(HOME)/.cache/qemu-vm/images
14bd1497dcSGerd HoffmannIMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
15b1fb9a63SFam Zheng
16b1fb9a63SFam Zheng.PRECIOUS: $(IMAGE_FILES)
17b1fb9a63SFam Zheng
184f2f6276SPhilippe Mathieu-Daudé# 'vm-help' target was historically named 'vm-test'
194f2f6276SPhilippe Mathieu-Daudévm-help vm-test:
204f2f6276SPhilippe Mathieu-Daudé	@echo "vm-help: Test QEMU in preconfigured virtual machines"
21b1fb9a63SFam Zheng	@echo
22b1fb9a63SFam Zheng	@echo "  vm-build-freebsd                - Build QEMU in FreeBSD VM"
23b1fb9a63SFam Zheng	@echo "  vm-build-netbsd                 - Build QEMU in NetBSD VM"
24b1fb9a63SFam Zheng	@echo "  vm-build-openbsd                - Build QEMU in OpenBSD VM"
2560136e06SGerd Hoffmann	@echo "  vm-build-fedora                 - Build QEMU in Fedora VM"
2639d87c8cSAlex Bennéeifneq ($(GENISOIMAGE),)
2739d87c8cSAlex Bennée	@echo "  vm-build-centos                 - Build QEMU in CentOS VM, with Docker"
2839d87c8cSAlex Bennée	@echo "  vm-build-ubuntu.i386            - Build QEMU in ubuntu i386 VM"
29*13336606SRobert Foleyifneq ($(EFI_AARCH64),)
30*13336606SRobert Foley	@echo "  vm-build-ubuntu.aarch64         - Build QEMU in ubuntu aarch64 VM"
31*13336606SRobert Foleyelse
32*13336606SRobert Foley	@echo "  (to build centos/ubuntu aarch64 images use configure --efi-aarch64)"
33*13336606SRobert Foleyendif
3439d87c8cSAlex Bennéeelse
3539d87c8cSAlex Bennée	@echo "  (install genisoimage to build centos/ubuntu images)"
3639d87c8cSAlex Bennéeendif
37af7e9168SFam Zheng	@echo ""
38af7e9168SFam Zheng	@echo "  vm-build-all                    - Build QEMU in all VMs"
39af7e9168SFam Zheng	@echo "  vm-clean-all                    - Clean up VM images"
40ddafa31fSAlex Bennée	@echo
41b1210f02SGerd Hoffmann	@echo "For trouble-shooting:"
42b1210f02SGerd Hoffmann	@echo "  vm-boot-serial-<guest>          - Boot guest, serial console on stdio"
43b1210f02SGerd Hoffmann	@echo "  vm-boot-ssh-<guest>             - Boot guest and login via ssh"
44b1210f02SGerd Hoffmann	@echo
45ddafa31fSAlex Bennée	@echo "Special variables:"
46eec4b30aSWainer dos Santos Moschetta	@echo "    BUILD_TARGET=foo		 - Override the build target"
47eec4b30aSWainer dos Santos Moschetta	@echo "    TARGET_LIST=a,b,c    	 - Override target list in builds"
48ddafa31fSAlex Bennée	@echo '    EXTRA_CONFIGURE_OPTS="..."'
49eec4b30aSWainer dos Santos Moschetta	@echo "    J=[0..9]*            	 - Override the -jN parameter for make commands"
50eec4b30aSWainer dos Santos Moschetta	@echo "    DEBUG=1              	 - Enable verbose output on host and interactive debugging"
51eec4b30aSWainer dos Santos Moschetta	@echo "    V=1				 - Enable verbose ouput on host and guest commands"
52e56c4504SRobert Foley	@echo "    QEMU_LOCAL=1                 - Use QEMU binary local to this build."
53eec4b30aSWainer dos Santos Moschetta	@echo "    QEMU=/path/to/qemu		 - Change path to QEMU binary"
541e48931cSWainer dos Santos Moschetta	@echo "    QEMU_IMG=/path/to/qemu-img	 - Change path to qemu-img tool"
553f1e8137SRobert Foleyifeq ($(PYTHON_YAML),yes)
563f1e8137SRobert Foley	@echo "    QEMU_CONFIG=/path/conf.yml   - Change path to VM configuration .yml file."
573f1e8137SRobert Foleyelse
583f1e8137SRobert Foley	@echo "    (install python3-yaml to enable support for yaml file to configure a VM.)"
593f1e8137SRobert Foleyendif
603f1e8137SRobert Foley	@echo "                                   See conf_example_*.yml for file format details."
61b1fb9a63SFam Zheng
62b1fb9a63SFam Zhengvm-build-all: $(addprefix vm-build-, $(IMAGES))
63b1fb9a63SFam Zheng
64ebe95fa0SFam Zhengvm-clean-all:
65ebe95fa0SFam Zheng	rm -f $(IMAGE_FILES)
66ebe95fa0SFam Zheng
67bd1497dcSGerd Hoffmann$(IMAGES_DIR)/%.img:	$(SRC_PATH)/tests/vm/% \
68b1fb9a63SFam Zheng			$(SRC_PATH)/tests/vm/basevm.py \
69b1fb9a63SFam Zheng			$(SRC_PATH)/tests/vm/Makefile.include
70bd1497dcSGerd Hoffmann	@mkdir -p $(IMAGES_DIR)
71b1fb9a63SFam Zheng	$(call quiet-command, \
72b0040fa1SWainer dos Santos Moschetta		$(PYTHON) $< \
73b1fb9a63SFam Zheng		$(if $(V)$(DEBUG), --debug) \
7492fecad3SAlex Bennée		$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
75e56c4504SRobert Foley		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
76*13336606SRobert Foley		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
77b1fb9a63SFam Zheng		--image "$@" \
78b1fb9a63SFam Zheng		--force \
79b1fb9a63SFam Zheng		--build-image $@, \
80b1fb9a63SFam Zheng		"  VM-IMAGE $*")
81b1fb9a63SFam Zheng
82b1fb9a63SFam Zheng
83b1fb9a63SFam Zheng# Build in VM $(IMAGE)
84bd1497dcSGerd Hoffmannvm-build-%: $(IMAGES_DIR)/%.img
85b1fb9a63SFam Zheng	$(call quiet-command, \
86b0040fa1SWainer dos Santos Moschetta		$(PYTHON) $(SRC_PATH)/tests/vm/$* \
87b1fb9a63SFam Zheng		$(if $(V)$(DEBUG), --debug) \
88b1fb9a63SFam Zheng		$(if $(DEBUG), --interactive) \
89b1fb9a63SFam Zheng		$(if $(J),--jobs $(J)) \
9041e3340aSPeter Maydell		$(if $(V),--verbose) \
91e56c4504SRobert Foley		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
92*13336606SRobert Foley		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
93b1fb9a63SFam Zheng		--image "$<" \
94ddafa31fSAlex Bennée		$(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
957f71d505SGerd Hoffmann		--snapshot \
96ddafa31fSAlex Bennée		--build-qemu $(SRC_PATH) -- \
97ddafa31fSAlex Bennée		$(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \
98ddafa31fSAlex Bennée		$(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \
99b1fb9a63SFam Zheng		"  VM-BUILD $*")
100b1fb9a63SFam Zheng
101b1210f02SGerd Hoffmannvm-boot-serial-%: $(IMAGES_DIR)/%.img
102b1210f02SGerd Hoffmann	qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \
103b1210f02SGerd Hoffmann		-drive if=none,id=vblk,cache=writeback,file="$<" \
104b1210f02SGerd Hoffmann		-netdev user,id=vnet \
105b1210f02SGerd Hoffmann		-device virtio-blk-pci,drive=vblk \
106b1210f02SGerd Hoffmann		-device virtio-net-pci,netdev=vnet \
107b1210f02SGerd Hoffmann	|| true
108b1210f02SGerd Hoffmann
109b1210f02SGerd Hoffmannvm-boot-ssh-%: $(IMAGES_DIR)/%.img
110b1210f02SGerd Hoffmann	$(call quiet-command, \
1110bc72f90SRobert Foley		$(PYTHON) $(SRC_PATH)/tests/vm/$* \
11246313326SThomas Huth		$(if $(J),--jobs $(J)) \
113d5326a24SRobert Foley		$(if $(V)$(DEBUG), --debug) \
114e56c4504SRobert Foley		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
115*13336606SRobert Foley		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
116b1210f02SGerd Hoffmann		--image "$<" \
117b1210f02SGerd Hoffmann		--interactive \
118b1210f02SGerd Hoffmann		false, \
119b1210f02SGerd Hoffmann		"  VM-BOOT-SSH $*") || true
120