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