hw/riscv: virt: Add device plug support
[qemu/kevin.git] / tests / vm / Makefile.include
blobae91f5043e506d2a3e46edfe827c794be656c325
1 # Makefile for VM tests
3 .PHONY: vm-build-all vm-clean-all
5 HOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m))
7 EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd)
9 X86_IMAGES := freebsd netbsd openbsd centos fedora haiku.x86_64
10 ifneq ($(GENISOIMAGE),)
11 X86_IMAGES += ubuntu.i386 centos
12 ifneq ($(EFI_AARCH64),)
13 ARM64_IMAGES += ubuntu.aarch64 centos.aarch64
14 endif
15 endif
17 ifeq ($(HOST_ARCH),x86_64)
18 IMAGES=$(X86_IMAGES) $(if $(USE_TCG),$(ARM64_IMAGES))
19 else ifeq ($(HOST_ARCH),aarch64)
20 IMAGES=$(ARM64_IMAGES) $(if $(USE_TCG),$(X86_IMAGES))
21 endif
23 IMAGES_DIR := $(HOME)/.cache/qemu-vm/images
24 IMAGE_FILES := $(patsubst %, $(IMAGES_DIR)/%.img, $(IMAGES))
26 .PRECIOUS: $(IMAGE_FILES)
28 ifneq ($(PYTHON),)
29 HAVE_PYTHON_YAML = $(shell $(PYTHON) -c "import yaml" 2> /dev/null && echo yes)
30 endif
32 # 'vm-help' target was historically named 'vm-test'
33 vm-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"
40 ifneq ($(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"
43 ifneq ($(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"
46 else
47         @echo "  (to build centos/ubuntu aarch64 images use configure --efi-aarch64)"
48 endif
49 else
50         @echo "  (install genisoimage to build centos/ubuntu images)"
51 endif
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"
69 ifeq ($(HAVE_PYTHON_YAML),yes)
70         @echo "    QEMU_CONFIG=/path/conf.yml   - Change path to VM configuration .yml file."
71 else
72         @echo "    (install python3-yaml to enable support for yaml file to configure a VM.)"
73 endif
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"
80 vm-build-all: $(addprefix vm-build-, $(IMAGES))
82 vm-clean-all:
83         rm -f $(IMAGE_FILES)
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 $*")
103 # Build in VM $(IMAGE)
104 vm-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 $*")
122 vm-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
130 vm-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