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