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