Merge tag 'pull-block-2022-07-12' of https://gitlab.com/hreitz/qemu into staging
[qemu/ar7.git] / tests / vm / Makefile.include
blob5f5b1fbfe689fd8693ce2e371290044482d9e1d5
1 # Makefile for VM tests
3 # Hack to allow running in an unconfigured build tree
4 ifeq ($(wildcard $(SRC_PATH)/config-host.mak),)
5 VM_PYTHON = PYTHONPATH=$(SRC_PATH)/python /usr/bin/env python3
6 VM_VENV =
7 HOST_ARCH := $(shell uname -m)
8 else
9 VM_PYTHON = $(TESTS_PYTHON)
10 VM_VENV = check-venv
11 HOST_ARCH = $(ARCH)
12 endif
14 .PHONY: vm-build-all vm-clean-all
16 EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd)
18 X86_IMAGES := freebsd netbsd openbsd centos fedora haiku.x86_64
19 ifneq ($(GENISOIMAGE),)
20 X86_IMAGES += ubuntu.i386 centos
21 ifneq ($(EFI_AARCH64),)
22 ARM64_IMAGES += ubuntu.aarch64 centos.aarch64
23 endif
24 endif
26 ifeq ($(HOST_ARCH),x86_64)
27 IMAGES=$(X86_IMAGES) $(if $(USE_TCG),$(ARM64_IMAGES))
28 else ifeq ($(HOST_ARCH),aarch64)
29 IMAGES=$(ARM64_IMAGES) $(if $(USE_TCG),$(X86_IMAGES))
30 endif
32 IMAGES_DIR := $(HOME)/.cache/qemu-vm/images
33 IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
35 .PRECIOUS: $(IMAGE_FILES)
37 ifneq ($(PYTHON),)
38 HAVE_PYTHON_YAML = $(shell $(PYTHON) -c "import yaml" 2> /dev/null && echo yes)
39 endif
41 # 'vm-help' target was historically named 'vm-test'
42 vm-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"
49 ifneq ($(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"
52 ifneq ($(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"
55 else
56         @echo "  (to build centos/ubuntu aarch64 images use configure --efi-aarch64)"
57 endif
58 else
59         @echo "  (install genisoimage to build centos/ubuntu images)"
60 endif
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"
78 ifeq ($(HAVE_PYTHON_YAML),yes)
79         @echo "    QEMU_CONFIG=/path/conf.yml   - Change path to VM configuration .yml file."
80 else
81         @echo "    (install python3-yaml to enable support for yaml file to configure a VM.)"
82 endif
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"
89 vm-build-all: $(addprefix vm-build-, $(IMAGES))
91 vm-clean-all:
92         rm -f $(IMAGE_FILES)
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 $*")
112 # Build in VM $(IMAGE)
113 vm-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 $*")
131 vm-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
139 vm-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