xref: /openbmc/qemu/tests/vm/Makefile.include (revision fb08790b)
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 centos fedora haiku.x86_64
19ifneq ($(GENISOIMAGE),)
20X86_IMAGES += ubuntu.i386 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"
48	@echo "  vm-build-fedora                 - Build QEMU in Fedora VM"
49ifneq ($(GENISOIMAGE),)
50	@echo "  vm-build-centos                 - Build QEMU in CentOS VM, with Docker"
51	@echo "  vm-build-ubuntu.i386            - Build QEMU in ubuntu i386 VM"
52ifneq ($(EFI_AARCH64),)
53	@echo "  vm-build-ubuntu.aarch64         - Build QEMU in ubuntu aarch64 VM"
54	@echo "  vm-build-centos.aarch64         - Build QEMU in CentOS aarch64 VM"
55else
56	@echo "  (to build centos/ubuntu aarch64 images use configure --efi-aarch64)"
57endif
58else
59	@echo "  (install genisoimage to build centos/ubuntu images)"
60endif
61	@echo "  vm-build-haiku.x86_64           - Build QEMU in Haiku VM"
62	@echo ""
63	@echo "  vm-build-all                    - Build QEMU in: $(IMAGES)"
64	@echo "  vm-clean-all                    - Clean up VM images"
65	@echo
66	@echo "For trouble-shooting:"
67	@echo "  vm-boot-serial-<guest>          - Boot guest, serial console on stdio"
68	@echo "  vm-boot-ssh-<guest>             - Boot guest and login via ssh"
69	@echo
70	@echo "Special variables:"
71	@echo "    BUILD_TARGET=foo		 - Override the build target"
72	@echo "    DEBUG=1              	 - Enable verbose output on host and interactive debugging"
73	@echo '    EXTRA_CONFIGURE_OPTS="..."   - Pass to configure step'
74	@echo "    J=[0..9]*            	 - Override the -jN parameter for make commands"
75	@echo "    LOG_CONSOLE=1        	 - Log console to file in: ~/.cache/qemu-vm "
76	@echo "    USE_TCG=1        	         - Use TCG for cross-arch images"
77	@echo "    QEMU=/path/to/qemu		 - Change path to QEMU binary"
78ifeq ($(HAVE_PYTHON_YAML),yes)
79	@echo "    QEMU_CONFIG=/path/conf.yml   - Change path to VM configuration .yml file."
80else
81	@echo "    (install python3-yaml to enable support for yaml file to configure a VM.)"
82endif
83	@echo "                                   See conf_example_*.yml for file format details."
84	@echo "    QEMU_IMG=/path/to/qemu-img	 - Change path to qemu-img tool"
85	@echo "    QEMU_LOCAL=1                 - Use QEMU binary local to this build."
86	@echo "    TARGET_LIST=a,b,c    	 - Override target list in builds"
87	@echo "    V=1				 - Enable verbose ouput on host and guest commands"
88
89vm-build-all: $(addprefix vm-build-, $(IMAGES))
90
91vm-clean-all:
92	rm -f $(IMAGE_FILES)
93
94$(IMAGES_DIR)/%.img:	$(SRC_PATH)/tests/vm/% \
95			$(SRC_PATH)/tests/vm/basevm.py \
96			$(SRC_PATH)/tests/vm/Makefile.include \
97			$(VM_VENV)
98	@mkdir -p $(IMAGES_DIR)
99	$(call quiet-command, \
100		$(VM_PYTHON) $< \
101		$(if $(V)$(DEBUG), --debug) \
102		$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
103		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
104		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
105		$(if $(LOG_CONSOLE),--log-console) \
106		--source-path $(SRC_PATH) \
107		--image "$@" \
108		--force \
109		--build-image $@, \
110		"  VM-IMAGE $*")
111
112# Build in VM $(IMAGE)
113vm-build-%: $(IMAGES_DIR)/%.img $(VM_VENV)
114	$(call quiet-command, \
115		$(VM_PYTHON) $(SRC_PATH)/tests/vm/$* \
116		$(if $(V)$(DEBUG), --debug) \
117		$(if $(DEBUG), --interactive) \
118		$(if $(J),--jobs $(J)) \
119		$(if $(V),--verbose) \
120		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
121		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
122		$(if $(LOG_CONSOLE),--log-console) \
123		--image "$<" \
124		$(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
125		--snapshot \
126		--build-qemu $(SRC_PATH) -- \
127		$(if $(TARGET_LIST),--target-list=$(TARGET_LIST)) \
128		$(if $(EXTRA_CONFIGURE_OPTS),$(EXTRA_CONFIGURE_OPTS)), \
129		"  VM-BUILD $*")
130
131vm-boot-serial-%: $(IMAGES_DIR)/%.img
132	qemu-system-x86_64 -enable-kvm -m 4G -smp 2 -nographic \
133		-drive if=none,id=vblk,cache=writeback,file="$<" \
134		-netdev user,id=vnet \
135		-device virtio-blk-pci,drive=vblk \
136		-device virtio-net-pci,netdev=vnet \
137	|| true
138
139vm-boot-ssh-%: $(IMAGES_DIR)/%.img $(VM_VENV)
140	$(call quiet-command, \
141		$(VM_PYTHON) $(SRC_PATH)/tests/vm/$* \
142		$(if $(J),--jobs $(J)) \
143		$(if $(V)$(DEBUG), --debug) \
144		$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
145		$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
146		$(if $(LOG_CONSOLE),--log-console) \
147		--image "$<" \
148		--interactive \
149		false, \
150		"  VM-BOOT-SSH $*") || true
151