xref: /openbmc/qemu/tests/vm/Makefile.include (revision ee48fef0)
1# Makefile for VM tests
2
3# Hack to allow running in an unconfigured build tree
4ifeq ($(realpath $(SRC_PATH)),$(realpath .))
5VM_PYTHON = PYTHONPATH=$(SRC_PATH)/python /usr/bin/env python3
6VM_VENV =
7else
8VM_PYTHON = $(PYTHON)
9VM_VENV = check-venv
10endif
11
12.PHONY: vm-build-all vm-clean-all
13
14EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd)
15
16X86_IMAGES := freebsd netbsd openbsd haiku.x86_64
17ifneq ($(GENISOIMAGE),)
18X86_IMAGES += centos
19ifneq ($(EFI_AARCH64),)
20ARM64_IMAGES += ubuntu.aarch64 centos.aarch64
21endif
22endif
23
24HOST_ARCH = $(shell uname -m)
25ifeq ($(HOST_ARCH),x86_64)
26IMAGES=$(X86_IMAGES) $(if $(USE_TCG),$(ARM64_IMAGES))
27else ifeq ($(HOST_ARCH),aarch64)
28IMAGES=$(ARM64_IMAGES) $(if $(USE_TCG),$(X86_IMAGES))
29endif
30
31IMAGES_DIR := $(HOME)/.cache/qemu-vm/images
32IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
33
34.PRECIOUS: $(IMAGE_FILES)
35
36ifneq ($(PYTHON),)
37HAVE_PYTHON_YAML = $(shell $(PYTHON) -c "import yaml" 2> /dev/null && echo yes)
38endif
39
40# 'vm-help' target was historically named 'vm-test'
41vm-help vm-test:
42	@echo "vm-help: Test QEMU in preconfigured virtual machines"
43	@echo
44	@echo "  vm-build-freebsd                - Build QEMU in FreeBSD VM"
45	@echo "  vm-build-netbsd                 - Build QEMU in NetBSD VM"
46	@echo "  vm-build-openbsd                - Build QEMU in OpenBSD VM"
47ifneq ($(GENISOIMAGE),)
48ifneq ($(EFI_AARCH64),)
49	@echo "  vm-build-ubuntu.aarch64         - Build QEMU in ubuntu aarch64 VM"
50	@echo "  vm-build-centos.aarch64         - Build QEMU in CentOS aarch64 VM"
51else
52	@echo "  (to build centos/ubuntu aarch64 images use configure --efi-aarch64)"
53endif
54else
55	@echo "  (install genisoimage to build centos/ubuntu images)"
56endif
57	@echo "  vm-build-haiku.x86_64           - Build QEMU in Haiku VM"
58	@echo ""
59	@echo "  vm-build-all                    - Build QEMU in: $(IMAGES)"
60	@echo "  vm-clean-all                    - Clean up VM images"
61	@echo
62	@echo "For trouble-shooting:"
63	@echo "  vm-boot-serial-<guest>          - Boot guest, serial console on stdio"
64	@echo "  vm-boot-ssh-<guest>             - Boot guest and login via ssh"
65	@echo
66	@echo "Special variables:"
67	@echo "    BUILD_TARGET=foo		 - Override the build target"
68	@echo "    DEBUG=1              	 - Enable verbose output on host and interactive debugging"
69	@echo '    EXTRA_CONFIGURE_OPTS="..."   - Pass to configure step'
70	@echo "    J=[0..9]*            	 - Override the -jN parameter for make commands"
71	@echo "    LOG_CONSOLE=1        	 - Log console to file in: ~/.cache/qemu-vm "
72	@echo "    USE_TCG=1        	         - Use TCG for cross-arch images"
73	@echo "    QEMU=/path/to/qemu		 - Change path to QEMU binary"
74ifeq ($(HAVE_PYTHON_YAML),yes)
75	@echo "    QEMU_CONFIG=/path/conf.yml   - Change path to VM configuration .yml file."
76else
77	@echo "    (install python3-yaml to enable support for yaml file to configure a VM.)"
78endif
79	@echo "                                   See conf_example_*.yml for file format details."
80	@echo "    QEMU_IMG=/path/to/qemu-img	 - Change path to qemu-img tool"
81	@echo "    QEMU_LOCAL=1                 - Use QEMU binary local to this build."
82	@echo "    TARGET_LIST=a,b,c    	 - Override target list in builds"
83	@echo "    V=1				 - Enable verbose output on host and guest commands"
84
85vm-build-all: $(addprefix vm-build-, $(IMAGES))
86
87vm-clean-all:
88	rm -f $(IMAGE_FILES)
89
90$(IMAGES_DIR)/%.img:	$(SRC_PATH)/tests/vm/% \
91			$(SRC_PATH)/tests/vm/basevm.py \
92			$(SRC_PATH)/tests/vm/Makefile.include \
93			$(VM_VENV)
94	@mkdir -p $(IMAGES_DIR)
95	$(call quiet-command, \
96		$(VM_PYTHON) $< \
97		$(if $(V)$(DEBUG), --debug) \
98		$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
99		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
100		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
101		$(if $(LOG_CONSOLE),--log-console) \
102		--source-path $(SRC_PATH) \
103		--image "$@" \
104		$(if $(filter-out check-venv, $?), --force) \
105		--build-image $@, \
106		"  VM-IMAGE $*")
107
108# Build in VM $(IMAGE)
109vm-build-%: $(IMAGES_DIR)/%.img $(VM_VENV)
110	$(call quiet-command, \
111		$(VM_PYTHON) $(SRC_PATH)/tests/vm/$* \
112		$(if $(V)$(DEBUG), --debug) \
113		$(if $(DEBUG), --interactive) \
114		$(if $(J),--jobs $(J)) \
115		$(if $(V),--verbose) \
116		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
117		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
118		$(if $(LOG_CONSOLE),--log-console) \
119		--image "$<" \
120		$(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
121		--snapshot \
122		--build-qemu $(SRC_PATH) -- \
123		$(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \
124		$(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \
125		"  VM-BUILD $*")
126
127vm-boot-serial-%: $(IMAGES_DIR)/%.img
128	qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \
129		-drive if=none,id=vblk,cache=writeback,file="$<" \
130		-netdev user,id=vnet \
131		-device virtio-blk-pci,drive=vblk \
132		-device virtio-net-pci,netdev=vnet \
133	|| true
134
135vm-boot-ssh-%: $(IMAGES_DIR)/%.img $(VM_VENV)
136	$(call quiet-command, \
137		$(VM_PYTHON) $(SRC_PATH)/tests/vm/$* \
138		$(if $(J),--jobs $(J)) \
139		$(if $(V)$(DEBUG), --debug) \
140		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
141		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
142		$(if $(LOG_CONSOLE),--log-console) \
143		--image "$<" \
144		--interactive \
145		false, \
146		"  VM-BOOT-SSH $*") || true
147