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