]> git.proxmox.com Git - mirror_qemu.git/blob - tests/docker/Makefile.include
Merge tag 'pull-aspeed-20220525' of https://github.com/legoater/qemu into staging
[mirror_qemu.git] / tests / docker / Makefile.include
1 # Makefile for Docker tests
2
3 .PHONY: docker docker-help docker-test docker-clean docker-image docker-qemu-src
4
5 NULL :=
6 SPACE := $(NULL) #
7 COMMA := ,
8
9 HOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m))
10
11 DOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles
12 ifeq ($(HOST_ARCH),x86_64)
13 DOCKER_DEFAULT_REGISTRY := registry.gitlab.com/qemu-project/qemu
14 endif
15 DOCKER_REGISTRY := $(if $(REGISTRY),$(REGISTRY),$(DOCKER_DEFAULT_REGISTRY))
16
17 ENGINE := auto
18 DOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(ENGINE)
19
20 CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
21 DOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME)
22
23 .DELETE_ON_ERROR: $(DOCKER_SRC_COPY)
24 $(DOCKER_SRC_COPY):
25 @mkdir $@
26 $(if $(SRC_ARCHIVE), \
27 $(call quiet-command, cp "$(SRC_ARCHIVE)" $@/qemu.tar, \
28 "CP", "$@/qemu.tar"), \
29 $(call quiet-command, cd $(SRC_PATH) && scripts/archive-source.sh $@/qemu.tar, \
30 "GEN", "$@/qemu.tar"))
31 $(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \
32 "COPY","RUNNER")
33
34 docker-qemu-src: $(DOCKER_SRC_COPY)
35
36 # General rule for building docker images.
37 docker-image-%: $(DOCKER_FILES_DIR)/%.docker
38 $(call quiet-command,\
39 $(DOCKER_SCRIPT) build -t qemu/$* -f $< \
40 $(if $V,,--quiet) \
41 $(if $(NOCACHE),--no-cache, \
42 $(if $(DOCKER_REGISTRY),--registry $(DOCKER_REGISTRY))) \
43 $(if $(NOUSER),,--add-current-user) \
44 $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\
45 $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\
46 "BUILD","$*")
47
48 # Special rule for debootstraped binfmt linux-user images
49 docker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker
50 $(if $(EXECUTABLE),,\
51 $(error EXECUTABLE not set, debootstrap of debian-$* would fail))
52 $(if $(DEB_ARCH),,\
53 $(error DEB_ARCH not set, debootstrap of debian-$* would fail))
54 $(if $(DEB_TYPE),,\
55 $(error DEB_TYPE not set, debootstrap of debian-$* would fail))
56 $(if $(wildcard $(EXECUTABLE)), \
57 $(call quiet-command, \
58 DEB_ARCH=$(DEB_ARCH) \
59 DEB_TYPE=$(DEB_TYPE) \
60 $(if $(DEB_URL),DEB_URL=$(DEB_URL),) \
61 $(DOCKER_SCRIPT) build -t qemu/debian-$* -f $< \
62 $(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \
63 $(if $(NOUSER),,--add-current-user) \
64 $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES)) \
65 $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)), \
66 "BUILD","binfmt debian-$* (debootstrapped)"), \
67 $(call quiet-command, \
68 $(DOCKER_SCRIPT) check --quiet qemu/debian-$* $< || \
69 { echo "You will need to build $(EXECUTABLE)"; exit 1;},\
70 "CHECK", "debian-$* exists"))
71
72 # Enforce dependencies for composite images
73 # we don't run tests on intermediate images (used as base by another image)
74 DOCKER_PARTIAL_IMAGES := debian10 debian11
75 ifeq ($(HOST_ARCH),x86_64)
76 docker-image-debian-amd64: docker-image-debian10
77 DOCKER_PARTIAL_IMAGES += debian-amd64-cross
78 else
79 docker-image-debian-amd64-cross: docker-image-debian10
80 DOCKER_PARTIAL_IMAGES += debian-amd64
81 endif
82
83 # For non-x86 hosts not all cross-compilers have been packaged
84 ifneq ($(HOST_ARCH),x86_64)
85 DOCKER_PARTIAL_IMAGES += debian-mips-cross debian-mipsel-cross debian-mips64el-cross
86 DOCKER_PARTIAL_IMAGES += debian-ppc64el-cross
87 DOCKER_PARTIAL_IMAGES += debian-s390x-cross
88 DOCKER_PARTIAL_IMAGES += fedora
89 endif
90
91 docker-image-debian-alpha-cross: docker-image-debian10
92 docker-image-debian-armel-cross: docker-image-debian10
93 docker-image-debian-armhf-cross: docker-image-debian10
94 docker-image-debian-hppa-cross: docker-image-debian10
95 docker-image-debian-m68k-cross: docker-image-debian10
96 docker-image-debian-mips-cross: docker-image-debian10
97 docker-image-debian-mips64-cross: docker-image-debian10
98 docker-image-debian-mips64el-cross: docker-image-debian10
99 docker-image-debian-mipsel-cross: docker-image-debian10
100 docker-image-debian-ppc64el-cross: docker-image-debian10
101 docker-image-debian-sh4-cross: docker-image-debian10
102 docker-image-debian-sparc64-cross: docker-image-debian10
103
104 # The native build should never use the registry
105 docker-image-debian-native: DOCKER_REGISTRY=
106
107 # base images should not add a local user
108 docker-image-debian10: NOUSER=1
109 docker-image-debian11: NOUSER=1
110
111 # alpine has no adduser
112 docker-image-alpine: NOUSER=1
113
114 debian-toolchain-run = \
115 $(if $(NOCACHE), \
116 $(call quiet-command, \
117 $(DOCKER_SCRIPT) build -t qemu/$1 -f $< \
118 $(if $V,,--quiet) --no-cache \
119 --registry $(DOCKER_REGISTRY) --extra-files \
120 $(DOCKER_FILES_DIR)/$1.d/build-toolchain.sh, \
121 "BUILD", $1), \
122 $(call quiet-command, \
123 $(DOCKER_SCRIPT) fetch $(if $V,,--quiet) \
124 qemu/$1 $(DOCKER_REGISTRY), \
125 "FETCH", $1) \
126 $(call quiet-command, \
127 $(DOCKER_SCRIPT) update $(if $V,,--quiet) \
128 qemu/$1 \
129 $(if $(NOUSER),,--add-current-user) \
130 "PREPARE", $1))
131 debian-toolchain = $(call debian-toolchain-run,$(patsubst docker-image-%,%,$1))
132
133 docker-image-debian-hexagon-cross: $(DOCKER_FILES_DIR)/debian-hexagon-cross.docker \
134 $(DOCKER_FILES_DIR)/debian-hexagon-cross.d/build-toolchain.sh
135 $(call debian-toolchain, $@)
136
137 docker-image-debian-microblaze-cross: $(DOCKER_FILES_DIR)/debian-toolchain.docker \
138 $(DOCKER_FILES_DIR)/debian-microblaze-cross.d/build-toolchain.sh
139 $(call debian-toolchain, $@)
140
141 docker-image-debian-nios2-cross: $(DOCKER_FILES_DIR)/debian-toolchain.docker \
142 $(DOCKER_FILES_DIR)/debian-nios2-cross.d/build-toolchain.sh
143 $(call debian-toolchain, $@)
144
145 # Specialist build images, sometimes very limited tools
146 docker-image-debian-tricore-cross: docker-image-debian10
147 docker-image-debian-all-test-cross: docker-image-debian10
148 docker-image-debian-microblaze-cross: docker-image-debian10
149 docker-image-debian-nios2-cross: docker-image-debian10
150 docker-image-debian-powerpc-test-cross: docker-image-debian11
151 docker-image-debian-riscv64-test-cross: docker-image-debian11
152
153 # These images may be good enough for building tests but not for test builds
154 DOCKER_PARTIAL_IMAGES += debian-alpha-cross
155 DOCKER_PARTIAL_IMAGES += debian-powerpc-test-cross
156 DOCKER_PARTIAL_IMAGES += debian-hppa-cross
157 DOCKER_PARTIAL_IMAGES += debian-m68k-cross debian-mips64-cross
158 DOCKER_PARTIAL_IMAGES += debian-microblaze-cross
159 DOCKER_PARTIAL_IMAGES += debian-nios2-cross
160 DOCKER_PARTIAL_IMAGES += debian-riscv64-test-cross
161 DOCKER_PARTIAL_IMAGES += debian-sh4-cross debian-sparc64-cross
162 DOCKER_PARTIAL_IMAGES += debian-tricore-cross
163 DOCKER_PARTIAL_IMAGES += debian-xtensa-cross
164 DOCKER_PARTIAL_IMAGES += fedora-cris-cross
165
166 # images that are only used to build other images
167 DOCKER_VIRTUAL_IMAGES := debian-bootstrap debian-toolchain
168
169 __IMAGES := $(sort $(filter-out $(DOCKER_VIRTUAL_IMAGES), $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker)))))
170 DOCKER_IMAGES := $(if $(IMAGES), $(filter $(IMAGES), $(__IMAGES)), $(__IMAGES))
171
172 __TESTS := $(notdir $(shell find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
173 DOCKER_TESTS := $(if $(TESTS), $(filter $(TESTS), $(__TESTS)), $(__TESTS))
174
175 # Expand all the pre-requistes for each docker image and test combination
176 $(foreach i,$(filter-out $(DOCKER_PARTIAL_IMAGES),$(DOCKER_IMAGES)), \
177 $(foreach t,$(DOCKER_TESTS), \
178 $(eval .PHONY: docker-$t@$i) \
179 $(eval docker-$t@$i: docker-image-$i; @$(MAKE) docker-run TEST=$t IMAGE=$i) \
180 ) \
181 $(foreach t,$(DOCKER_TESTS), \
182 $(eval docker-all-tests: docker-$t@$i) \
183 $(eval docker-$t: docker-$t@$i) \
184 ) \
185 )
186
187 docker:
188 @echo 'Build QEMU and run tests inside Docker or Podman containers'
189 @echo
190 @echo 'Available targets:'
191 @echo
192 @echo ' docker: Print this help.'
193 @echo ' docker-all-tests: Run all image/test combinations.'
194 @echo ' docker-TEST: Run "TEST" on all image combinations.'
195 @echo ' docker-clean: Kill and remove residual docker testing containers.'
196 @echo ' docker-TEST@IMAGE: Run "TEST" in container "IMAGE".'
197 @echo ' Note: "TEST" is one of the listed test name,'
198 @echo ' or a script name under $$QEMU_SRC/tests/docker/;'
199 @echo ' "IMAGE" is one of the listed container name.'
200 @echo ' docker-image: Build all images.'
201 @echo ' docker-image-IMAGE: Build image "IMAGE".'
202 @echo ' docker-run: For manually running a "TEST" with "IMAGE".'
203 @echo
204 @echo 'Available container images:'
205 @echo ' $(DOCKER_IMAGES)'
206 @echo
207 @echo 'Available tests:'
208 @echo ' $(DOCKER_TESTS)'
209 @echo
210 @echo 'Special variables:'
211 @echo ' TARGET_LIST=a,b,c Override target list in builds.'
212 @echo ' EXTRA_CONFIGURE_OPTS="..."'
213 @echo ' Extra configure options.'
214 @echo ' IMAGES="a b c ..": Restrict available images to subset.'
215 @echo ' TESTS="x y z .." Restrict available tests to subset.'
216 @echo ' J=[0..9]* Overrides the -jN parameter for make commands'
217 @echo ' (default is 1)'
218 @echo ' DEBUG=1 Stop and drop to shell in the created container'
219 @echo ' before running the command.'
220 @echo ' NETWORK=1 Enable virtual network interface with default backend.'
221 @echo ' NETWORK=$$BACKEND Enable virtual network interface with $$BACKEND.'
222 @echo ' NOUSER=1 Define to disable adding current user to containers passwd.'
223 @echo ' NOCACHE=1 Ignore cache when build images.'
224 @echo ' EXECUTABLE=<path> Include executable in image.'
225 @echo ' EXTRA_FILES="<path> [... <path>]"'
226 @echo ' Include extra files in image.'
227 @echo ' ENGINE=auto/docker/podman'
228 @echo ' Specify which container engine to run.'
229 @echo ' REGISTRY=url Cache builds from registry (default:$(DOCKER_REGISTRY))'
230
231 docker-help: docker
232
233 # Use a global constant ccache directory to speed up repetitive builds
234 DOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
235
236 # This rule if for directly running against an arbitrary docker target.
237 # It is called by the expanded docker targets (e.g. make
238 # docker-test-foo@bar) which will also ensure the image is up to date.
239 #
240 # For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
241 #
242 docker-run: docker-qemu-src
243 @mkdir -p "$(DOCKER_CCACHE_DIR)"
244 @if test -z "$(IMAGE)" || test -z "$(TEST)"; \
245 then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
246 fi
247 $(if $(EXECUTABLE), \
248 $(call quiet-command, \
249 $(DOCKER_SCRIPT) update \
250 $(IMAGE) --executable $(EXECUTABLE), \
251 " COPYING $(EXECUTABLE) to $(IMAGE)"))
252 $(call quiet-command, \
253 $(DOCKER_SCRIPT) run \
254 $(if $(NOUSER),,--run-as-current-user) \
255 --security-opt seccomp=unconfined \
256 $(if $(DEBUG),-ti,) \
257 $(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \
258 -e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST)) \
259 -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
260 -e V=$V -e J=$J -e DEBUG=$(DEBUG) \
261 -e SHOW_ENV=$(SHOW_ENV) \
262 $(if $(NOUSER),, \
263 -e CCACHE_DIR=/var/tmp/ccache \
264 -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
265 ) \
266 -v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
267 $(IMAGE) \
268 /var/tmp/qemu/run \
269 $(TEST), " RUN $(TEST) in ${IMAGE}")
270 $(call quiet-command, rm -r $(DOCKER_SRC_COPY), \
271 " CLEANUP $(DOCKER_SRC_COPY)")
272
273 docker-image: ${DOCKER_IMAGES:%=docker-image-%}
274
275 docker-clean:
276 $(call quiet-command, $(DOCKER_SCRIPT) clean)