xref: /openbmc/qemu/tests/vm/Makefile.include (revision f4c66f17051f0dee0e6070c6b78a78e7425b5c96)
1b1fb9a63SFam Zheng# Makefile for VM tests
2b1fb9a63SFam Zheng
3ebe95fa0SFam Zheng.PHONY: vm-build-all vm-clean-all
4b1fb9a63SFam Zheng
5ebd654aaSAlex BennéeHOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m))
6ebd654aaSAlex Bennée
7f5c73069SPaolo BonziniEFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd)
8f5c73069SPaolo Bonzini
9ebd654aaSAlex BennéeX86_IMAGES := freebsd netbsd openbsd centos fedora haiku.x86_64
1039d87c8cSAlex Bennéeifneq ($(GENISOIMAGE),)
11ebd654aaSAlex BennéeX86_IMAGES += ubuntu.i386 centos
1213336606SRobert Foleyifneq ($(EFI_AARCH64),)
13ebd654aaSAlex BennéeARM64_IMAGES += ubuntu.aarch64 centos.aarch64
1413336606SRobert Foleyendif
1539d87c8cSAlex Bennéeendif
1639d87c8cSAlex Bennée
17ebd654aaSAlex Bennéeifeq ($(HOST_ARCH),x86_64)
18ebd654aaSAlex BennéeIMAGES=$(X86_IMAGES) $(if $(USE_TCG),$(ARM64_IMAGES))
19ebd654aaSAlex Bennéeelse ifeq ($(HOST_ARCH),aarch64)
20ebd654aaSAlex BennéeIMAGES=$(ARM64_IMAGES) $(if $(USE_TCG),$(X86_IMAGES))
21ebd654aaSAlex Bennéeendif
22ebd654aaSAlex Bennée
23bd1497dcSGerd HoffmannIMAGES_DIR := $(HOME)/.cache/qemu-vm/images
24bd1497dcSGerd HoffmannIMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
25b1fb9a63SFam Zheng
26b1fb9a63SFam Zheng.PRECIOUS: $(IMAGE_FILES)
27b1fb9a63SFam Zheng
2800eb3db0SPaolo Bonziniifneq ($(PYTHON),)
2900eb3db0SPaolo BonziniHAVE_PYTHON_YAML = $(shell $(PYTHON) -c "import yaml" 2> /dev/null && echo yes)
3000eb3db0SPaolo Bonziniendif
3100eb3db0SPaolo Bonzini
324f2f6276SPhilippe Mathieu-Daudé# 'vm-help' target was historically named 'vm-test'
334f2f6276SPhilippe Mathieu-Daudévm-help vm-test:
344f2f6276SPhilippe Mathieu-Daudé	@echo "vm-help: Test QEMU in preconfigured virtual machines"
35b1fb9a63SFam Zheng	@echo
36b1fb9a63SFam Zheng	@echo "  vm-build-freebsd                - Build QEMU in FreeBSD VM"
37b1fb9a63SFam Zheng	@echo "  vm-build-netbsd                 - Build QEMU in NetBSD VM"
38b1fb9a63SFam Zheng	@echo "  vm-build-openbsd                - Build QEMU in OpenBSD VM"
3960136e06SGerd Hoffmann	@echo "  vm-build-fedora                 - Build QEMU in Fedora VM"
4039d87c8cSAlex Bennéeifneq ($(GENISOIMAGE),)
4139d87c8cSAlex Bennée	@echo "  vm-build-centos                 - Build QEMU in CentOS VM, with Docker"
4239d87c8cSAlex Bennée	@echo "  vm-build-ubuntu.i386            - Build QEMU in ubuntu i386 VM"
4313336606SRobert Foleyifneq ($(EFI_AARCH64),)
4413336606SRobert Foley	@echo "  vm-build-ubuntu.aarch64         - Build QEMU in ubuntu aarch64 VM"
45d322fe2dSRobert Foley	@echo "  vm-build-centos.aarch64         - Build QEMU in CentOS aarch64 VM"
4613336606SRobert Foleyelse
4713336606SRobert Foley	@echo "  (to build centos/ubuntu aarch64 images use configure --efi-aarch64)"
4813336606SRobert Foleyendif
4939d87c8cSAlex Bennéeelse
5039d87c8cSAlex Bennée	@echo "  (install genisoimage to build centos/ubuntu images)"
5139d87c8cSAlex Bennéeendif
529fc33bf4SAlexander von Gluck IV	@echo "  vm-build-haiku.x86_64           - Build QEMU in Haiku VM"
53af7e9168SFam Zheng	@echo ""
54ebd654aaSAlex Bennée	@echo "  vm-build-all                    - Build QEMU in: $(IMAGES)"
55af7e9168SFam Zheng	@echo "  vm-clean-all                    - Clean up VM images"
56ddafa31fSAlex Bennée	@echo
57b1210f02SGerd Hoffmann	@echo "For trouble-shooting:"
58b1210f02SGerd Hoffmann	@echo "  vm-boot-serial-<guest>          - Boot guest, serial console on stdio"
59b1210f02SGerd Hoffmann	@echo "  vm-boot-ssh-<guest>             - Boot guest and login via ssh"
60b1210f02SGerd Hoffmann	@echo
61ddafa31fSAlex Bennée	@echo "Special variables:"
62eec4b30aSWainer dos Santos Moschetta	@echo "    BUILD_TARGET=foo		 - Override the build target"
63eec4b30aSWainer dos Santos Moschetta	@echo "    DEBUG=1              	 - Enable verbose output on host and interactive debugging"
6481c9b06eSAlex Bennée	@echo '    EXTRA_CONFIGURE_OPTS="..."   - Pass to configure step'
6581c9b06eSAlex Bennée	@echo "    J=[0..9]*            	 - Override the -jN parameter for make commands"
66ff14ab0cSRobert Foley	@echo "    LOG_CONSOLE=1        	 - Log console to file in: ~/.cache/qemu-vm "
67ebd654aaSAlex Bennée	@echo "    USE_TCG=1        	         - Use TCG for cross-arch images"
68eec4b30aSWainer dos Santos Moschetta	@echo "    QEMU=/path/to/qemu		 - Change path to QEMU binary"
6900eb3db0SPaolo Bonziniifeq ($(HAVE_PYTHON_YAML),yes)
703f1e8137SRobert Foley	@echo "    QEMU_CONFIG=/path/conf.yml   - Change path to VM configuration .yml file."
713f1e8137SRobert Foleyelse
723f1e8137SRobert Foley	@echo "    (install python3-yaml to enable support for yaml file to configure a VM.)"
733f1e8137SRobert Foleyendif
743f1e8137SRobert Foley	@echo "                                   See conf_example_*.yml for file format details."
7581c9b06eSAlex Bennée	@echo "    QEMU_IMG=/path/to/qemu-img	 - Change path to qemu-img tool"
7681c9b06eSAlex Bennée	@echo "    QEMU_LOCAL=1                 - Use QEMU binary local to this build."
7781c9b06eSAlex Bennée	@echo "    TARGET_LIST=a,b,c    	 - Override target list in builds"
7881c9b06eSAlex Bennée	@echo "    V=1				 - Enable verbose ouput on host and guest commands"
79b1fb9a63SFam Zheng
80b1fb9a63SFam Zhengvm-build-all: $(addprefix vm-build-, $(IMAGES))
81b1fb9a63SFam Zheng
82ebe95fa0SFam Zhengvm-clean-all:
83ebe95fa0SFam Zheng	rm -f $(IMAGE_FILES)
84ebe95fa0SFam Zheng
85bd1497dcSGerd Hoffmann$(IMAGES_DIR)/%.img:	$(SRC_PATH)/tests/vm/% \
86b1fb9a63SFam Zheng			$(SRC_PATH)/tests/vm/basevm.py \
87*f4c66f17SJohn Snow			$(SRC_PATH)/tests/vm/Makefile.include \
88*f4c66f17SJohn Snow			check-venv
89bd1497dcSGerd Hoffmann	@mkdir -p $(IMAGES_DIR)
90b1fb9a63SFam Zheng	$(call quiet-command, \
91*f4c66f17SJohn Snow		$(TESTS_PYTHON) $< \
92b1fb9a63SFam Zheng		$(if $(V)$(DEBUG), --debug) \
9392fecad3SAlex Bennée		$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
94e56c4504SRobert Foley		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
9513336606SRobert Foley		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
96ff14ab0cSRobert Foley		$(if $(LOG_CONSOLE),--log-console) \
977bb17a92SAlex Bennée		--source-path $(SRC_PATH) \
98b1fb9a63SFam Zheng		--image "$@" \
99b1fb9a63SFam Zheng		--force \
100b1fb9a63SFam Zheng		--build-image $@, \
101b1fb9a63SFam Zheng		"  VM-IMAGE $*")
102b1fb9a63SFam Zheng
103b1fb9a63SFam Zheng
104b1fb9a63SFam Zheng# Build in VM $(IMAGE)
105*f4c66f17SJohn Snowvm-build-%: $(IMAGES_DIR)/%.img check-venv
106b1fb9a63SFam Zheng	$(call quiet-command, \
107*f4c66f17SJohn Snow		$(TESTS_PYTHON) $(SRC_PATH)/tests/vm/$* \
108b1fb9a63SFam Zheng		$(if $(V)$(DEBUG), --debug) \
109b1fb9a63SFam Zheng		$(if $(DEBUG), --interactive) \
110b1fb9a63SFam Zheng		$(if $(J),--jobs $(J)) \
11141e3340aSPeter Maydell		$(if $(V),--verbose) \
112e56c4504SRobert Foley		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
11313336606SRobert Foley		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
114ff14ab0cSRobert Foley		$(if $(LOG_CONSOLE),--log-console) \
115b1fb9a63SFam Zheng		--image "$<" \
116ddafa31fSAlex Bennée		$(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
1177f71d505SGerd Hoffmann		--snapshot \
118ddafa31fSAlex Bennée		--build-qemu $(SRC_PATH) -- \
119ddafa31fSAlex Bennée		$(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \
120ddafa31fSAlex Bennée		$(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \
121b1fb9a63SFam Zheng		"  VM-BUILD $*")
122b1fb9a63SFam Zheng
123b1210f02SGerd Hoffmannvm-boot-serial-%: $(IMAGES_DIR)/%.img
124b1210f02SGerd Hoffmann	qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \
125b1210f02SGerd Hoffmann		-drive if=none,id=vblk,cache=writeback,file="$<" \
126b1210f02SGerd Hoffmann		-netdev user,id=vnet \
127b1210f02SGerd Hoffmann		-device virtio-blk-pci,drive=vblk \
128b1210f02SGerd Hoffmann		-device virtio-net-pci,netdev=vnet \
129b1210f02SGerd Hoffmann	|| true
130b1210f02SGerd Hoffmann
131*f4c66f17SJohn Snowvm-boot-ssh-%: $(IMAGES_DIR)/%.img check-venv
132b1210f02SGerd Hoffmann	$(call quiet-command, \
133*f4c66f17SJohn Snow		$(TESTS_PYTHON) $(SRC_PATH)/tests/vm/$* \
13446313326SThomas Huth		$(if $(J),--jobs $(J)) \
135d5326a24SRobert Foley		$(if $(V)$(DEBUG), --debug) \
136e56c4504SRobert Foley		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
13713336606SRobert Foley		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
138ff14ab0cSRobert Foley		$(if $(LOG_CONSOLE),--log-console) \
139b1210f02SGerd Hoffmann		--image "$<" \
140b1210f02SGerd Hoffmann		--interactive \
141b1210f02SGerd Hoffmann		false, \
142b1210f02SGerd Hoffmann		"  VM-BOOT-SSH $*") || true
143