tests/docker: Add debian-microblaze-cross image
[qemu/ar7.git] / tests / docker / Makefile.include
blobc72cddbde3d6ea0df6d827938ec2bf5fe53fd9f7
1 # Makefile for Docker tests
3 .PHONY: docker docker-help docker-test docker-clean docker-image docker-qemu-src
5 NULL :=
6 SPACE := $(NULL) #
7 COMMA := ,
9 HOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m))
11 DOCKER_SUFFIX := .docker
12 DOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles
13 # we don't run tests on intermediate images (used as base by another image)
14 DOCKER_PARTIAL_IMAGES := debian10 debian11 debian-bootstrap empty
15 DOCKER_IMAGES := $(sort $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker))))
16 DOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES))
17 # Use a global constant ccache directory to speed up repetitive builds
18 DOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
19 ifeq ($(HOST_ARCH),x86_64)
20 DOCKER_DEFAULT_REGISTRY := registry.gitlab.com/qemu-project/qemu
21 endif
22 DOCKER_REGISTRY := $(if $(REGISTRY),$(REGISTRY),$(DOCKER_DEFAULT_REGISTRY))
24 DOCKER_TESTS := $(notdir $(shell \
25         find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
27 ENGINE := auto
29 DOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(ENGINE)
31 TESTS ?= %
32 IMAGES ?= %
34 CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
35 DOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME)
37 .DELETE_ON_ERROR: $(DOCKER_SRC_COPY)
38 $(DOCKER_SRC_COPY):
39         @mkdir $@
40         $(if $(SRC_ARCHIVE), \
41                 $(call quiet-command, cp "$(SRC_ARCHIVE)" $@/qemu.tar, \
42                         "CP", "$@/qemu.tar"), \
43                 $(call quiet-command, cd $(SRC_PATH) && scripts/archive-source.sh $@/qemu.tar, \
44                         "GEN", "$@/qemu.tar"))
45         $(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \
46                 "COPY","RUNNER")
48 docker-qemu-src: $(DOCKER_SRC_COPY)
50 docker-image: ${DOCKER_TARGETS}
52 # General rule for building docker images. If we are a sub-make
53 # invoked with SKIP_DOCKER_BUILD we still check the image is up to date
54 # though
55 ifdef SKIP_DOCKER_BUILD
56 docker-image-%: $(DOCKER_FILES_DIR)/%.docker
57         $(call quiet-command, \
58                 $(DOCKER_SCRIPT) check --quiet qemu/$* $<, \
59                 "CHECK", "$*")
60 else
61 docker-image-%: $(DOCKER_FILES_DIR)/%.docker
62         $(call quiet-command,\
63                 $(DOCKER_SCRIPT) build -t qemu/$* -f $< \
64                 $(if $V,,--quiet) \
65                 $(if $(NOCACHE),--no-cache, \
66                         $(if $(DOCKER_REGISTRY),--registry $(DOCKER_REGISTRY))) \
67                 $(if $(NOUSER),,--add-current-user) \
68                 $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\
69                 $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\
70                 "BUILD","$*")
72 # Special rule for debootstraped binfmt linux-user images
73 docker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker
74         $(if $(EXECUTABLE),,\
75                 $(error EXECUTABLE not set, debootstrap of debian-$* would fail))
76         $(if $(DEB_ARCH),,\
77                 $(error DEB_ARCH not set, debootstrap of debian-$* would fail))
78         $(if $(DEB_TYPE),,\
79                 $(error DEB_TYPE not set, debootstrap of debian-$* would fail))
80         $(if $(wildcard $(EXECUTABLE)),                                         \
81                 $(call quiet-command,                                           \
82                         DEB_ARCH=$(DEB_ARCH)                                    \
83                         DEB_TYPE=$(DEB_TYPE)                                    \
84                         $(if $(DEB_URL),DEB_URL=$(DEB_URL),)                    \
85                         $(DOCKER_SCRIPT) build -t qemu/debian-$* -f $<          \
86                         $(if $V,,--quiet) $(if $(NOCACHE),--no-cache)           \
87                         $(if $(NOUSER),,--add-current-user)                     \
88                         $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))       \
89                         $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)), \
90                         "BUILD","binfmt debian-$* (debootstrapped)"),           \
91                 $(call quiet-command,                                           \
92                         $(DOCKER_SCRIPT) check --quiet qemu/debian-$* $< ||     \
93                         { echo "You will need to build $(EXECUTABLE)"; exit 1;},\
94                         "CHECK", "debian-$* exists"))
96 # These are test targets
97 USER_TCG_TARGETS=$(patsubst %-linux-user,qemu-%,$(filter %-linux-user,$(TARGET_DIRS)))
98 EXEC_COPY_TESTS=$(patsubst %,docker-exec-copy-test-%, $(USER_TCG_TARGETS))
100 $(EXEC_COPY_TESTS): docker-exec-copy-test-%: $(DOCKER_FILES_DIR)/empty.docker
101         $(call quiet-command,                                                   \
102                 $(DOCKER_SCRIPT) build -t qemu/exec-copy-test-$* -f $<          \
103                         $(if $V,,--quiet) --no-cache                            \
104                         --include-executable=$*                                 \
105                         --skip-binfmt,                                          \
106                         "TEST","copy $* to container")
107         $(call quiet-command,                                                   \
108                 $(DOCKER_SCRIPT) run qemu/exec-copy-test-$*                     \
109                         /$* -version > tests/docker-exec-copy-test-$*.out,      \
110                         "TEST","check $* works in container")
112 docker-exec-copy-test: $(EXEC_COPY_TESTS)
114 endif
116 # Enforce dependencies for composite images
117 ifeq ($(HOST_ARCH),x86_64)
118 docker-image-debian-amd64: docker-image-debian10
119 DOCKER_PARTIAL_IMAGES += debian-amd64-cross
120 else
121 docker-image-debian-amd64-cross: docker-image-debian10
122 DOCKER_PARTIAL_IMAGES += debian-amd64
123 endif
125 # For non-x86 hosts not all cross-compilers have been packaged
126 ifneq ($(HOST_ARCH),x86_64)
127 DOCKER_PARTIAL_IMAGES += debian-mips-cross debian-mipsel-cross debian-mips64el-cross
128 DOCKER_PARTIAL_IMAGES += debian-ppc64el-cross
129 DOCKER_PARTIAL_IMAGES += debian-s390x-cross
130 DOCKER_PARTIAL_IMAGES += fedora
131 endif
133 docker-image-debian-alpha-cross: docker-image-debian10
134 docker-image-debian-arm64-cross: docker-image-debian10
135 docker-image-debian-armel-cross: docker-image-debian10
136 docker-image-debian-armhf-cross: docker-image-debian10
137 docker-image-debian-hppa-cross: docker-image-debian10
138 docker-image-debian-m68k-cross: docker-image-debian10
139 docker-image-debian-mips-cross: docker-image-debian10
140 docker-image-debian-mips64-cross: docker-image-debian10
141 docker-image-debian-mips64el-cross: docker-image-debian10
142 docker-image-debian-mipsel-cross: docker-image-debian10
143 docker-image-debian-ppc64el-cross: docker-image-debian10
144 docker-image-debian-s390x-cross: docker-image-debian10
145 docker-image-debian-sh4-cross: docker-image-debian10
146 docker-image-debian-sparc64-cross: docker-image-debian10
148 # The native build should never use the registry
149 docker-image-debian-native: DOCKER_REGISTRY=
153 # The build rule for hexagon-cross is special in so far for most of
154 # the time we don't want to build it. While dockers caching does avoid
155 # this most of the time sometimes we want to force the issue.
157 docker-image-debian-hexagon-cross: $(DOCKER_FILES_DIR)/debian-hexagon-cross.docker
158         $(if $(NOCACHE),                                                                \
159                 $(call quiet-command,                                                   \
160                         $(DOCKER_SCRIPT) build -t qemu/debian-hexagon-cross -f $<       \
161                         $(if $V,,--quiet) --no-cache                                    \
162                         --registry $(DOCKER_REGISTRY) --extra-files                     \
163                         $(DOCKER_FILES_DIR)/debian-hexagon-cross.docker.d/build-toolchain.sh, \
164                         "BUILD", "debian-hexagon-cross"),                               \
165                 $(call quiet-command,                                                   \
166                         $(DOCKER_SCRIPT) fetch $(if $V,,--quiet)                        \
167                                 qemu/debian-hexagon-cross $(DOCKER_REGISTRY),           \
168                         "FETCH", "debian-hexagon-cross")                                \
169                 $(call quiet-command,                                                   \
170                         $(DOCKER_SCRIPT) update $(if $V,,--quiet)                       \
171                                 qemu/debian-hexagon-cross --add-current-user,           \
172                         "PREPARE", "debian-hexagon-cross"))
174 debian-toolchain-run = \
175         $(if $(NOCACHE),                                                \
176                 $(call quiet-command,                                   \
177                         $(DOCKER_SCRIPT) build -t qemu/$1 -f $<         \
178                         $(if $V,,--quiet) --no-cache                    \
179                         --registry $(DOCKER_REGISTRY) --extra-files     \
180                         $(DOCKER_FILES_DIR)/$1.d/build-toolchain.sh,    \
181                         "BUILD", $1),                                   \
182                 $(call quiet-command,                                   \
183                         $(DOCKER_SCRIPT) fetch $(if $V,,--quiet)        \
184                                 qemu/$1 $(DOCKER_REGISTRY),             \
185                         "FETCH", $1)                                    \
186                 $(call quiet-command,                                   \
187                         $(DOCKER_SCRIPT) update $(if $V,,--quiet)       \
188                                 qemu/$1                                 \
189                                 $(if $(NOUSER),,--add-current-user)     \
190                         "PREPARE", $1))
191 debian-toolchain = $(call debian-toolchain-run,$(patsubst docker-image-%,%,$1))
193 docker-image-debian-microblaze-cross: $(DOCKER_FILES_DIR)/debian-toolchain.docker \
194     $(DOCKER_FILES_DIR)/debian-microblaze-cross.d/build-toolchain.sh
195         $(call debian-toolchain, $@)
197 docker-image-debian-nios2-cross: $(DOCKER_FILES_DIR)/debian-toolchain.docker \
198     $(DOCKER_FILES_DIR)/debian-nios2-cross.d/build-toolchain.sh
199         $(call debian-toolchain, $@)
201 # Specialist build images, sometimes very limited tools
202 docker-image-debian-tricore-cross: docker-image-debian10
203 docker-image-debian-all-test-cross: docker-image-debian10
204 docker-image-debian-arm64-test-cross: docker-image-debian11
205 docker-image-debian-microblaze-cross: docker-image-debian10
206 docker-image-debian-nios2-cross: docker-image-debian10
207 docker-image-debian-powerpc-test-cross: docker-image-debian11
209 # These images may be good enough for building tests but not for test builds
210 DOCKER_PARTIAL_IMAGES += debian-alpha-cross
211 DOCKER_PARTIAL_IMAGES += debian-arm64-test-cross
212 DOCKER_PARTIAL_IMAGES += debian-powerpc-test-cross
213 DOCKER_PARTIAL_IMAGES += debian-hppa-cross
214 DOCKER_PARTIAL_IMAGES += debian-m68k-cross debian-mips64-cross
215 DOCKER_PARTIAL_IMAGES += debian-microblaze-cross
216 DOCKER_PARTIAL_IMAGES += debian-nios2-cross
217 DOCKER_PARTIAL_IMAGES += debian-sh4-cross debian-sparc64-cross
218 DOCKER_PARTIAL_IMAGES += debian-tricore-cross
219 DOCKER_PARTIAL_IMAGES += debian-xtensa-cross
220 DOCKER_PARTIAL_IMAGES += fedora-cris-cross
222 # Rules for building linux-user powered images
224 # These are slower than using native cross compiler setups but can
225 # work around issues with poorly working multi-arch systems and broken
226 # packages.
228 # Expand all the pre-requistes for each docker image and test combination
229 $(foreach i,$(filter-out $(DOCKER_PARTIAL_IMAGES),$(DOCKER_IMAGES)), \
230         $(foreach t,$(DOCKER_TESTS), \
231                 $(eval .PHONY: docker-$t@$i) \
232                 $(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
233         ) \
234         $(foreach t,$(DOCKER_TESTS), \
235                 $(eval docker-all-tests: docker-$t@$i) \
236                 $(eval docker-$t: docker-$t@$i) \
237         ) \
240 docker:
241         @echo 'Build QEMU and run tests inside Docker or Podman containers'
242         @echo
243         @echo 'Available targets:'
244         @echo
245         @echo '    docker:              Print this help.'
246         @echo '    docker-all-tests:    Run all image/test combinations.'
247         @echo '    docker-TEST:         Run "TEST" on all image combinations.'
248         @echo '    docker-clean:        Kill and remove residual docker testing containers.'
249         @echo '    docker-TEST@IMAGE:   Run "TEST" in container "IMAGE".'
250         @echo '                         Note: "TEST" is one of the listed test name,'
251         @echo '                         or a script name under $$QEMU_SRC/tests/docker/;'
252         @echo '                         "IMAGE" is one of the listed container name.'
253         @echo '    docker-image:        Build all images.'
254         @echo '    docker-image-IMAGE:  Build image "IMAGE".'
255         @echo '    docker-run:          For manually running a "TEST" with "IMAGE".'
256         @echo
257         @echo 'Available container images:'
258         @echo '    $(DOCKER_IMAGES)'
259 ifneq ($(DOCKER_USER_IMAGES),)
260         @echo
261         @echo 'Available linux-user images (docker-binfmt-image-debian-%):'
262         @echo '    $(DOCKER_USER_IMAGES)'
263 endif
264         @echo
265         @echo 'Available tests:'
266         @echo '    $(DOCKER_TESTS)'
267         @echo
268         @echo 'Special variables:'
269         @echo '    TARGET_LIST=a,b,c    Override target list in builds.'
270         @echo '    EXTRA_CONFIGURE_OPTS="..."'
271         @echo '                         Extra configure options.'
272         @echo '    IMAGES="a b c ..":   Filters which images to build or run.'
273         @echo '    TESTS="x y z .."     Filters which tests to run (for docker-test).'
274         @echo '    J=[0..9]*            Overrides the -jN parameter for make commands'
275         @echo '                         (default is 1)'
276         @echo '    DEBUG=1              Stop and drop to shell in the created container'
277         @echo '                         before running the command.'
278         @echo '    NETWORK=1            Enable virtual network interface with default backend.'
279         @echo '    NETWORK=$$BACKEND     Enable virtual network interface with $$BACKEND.'
280         @echo '    NOUSER=1             Define to disable adding current user to containers passwd.'
281         @echo '    NOCACHE=1            Ignore cache when build images.'
282         @echo '    EXECUTABLE=<path>    Include executable in image.'
283         @echo '    EXTRA_FILES="<path> [... <path>]"'
284         @echo '                         Include extra files in image.'
285         @echo '    ENGINE=auto/docker/podman'
286         @echo '                         Specify which container engine to run.'
287         @echo '    REGISTRY=url         Cache builds from registry (default:$(DOCKER_REGISTRY))'
289 docker-help: docker
291 # This rule if for directly running against an arbitrary docker target.
292 # It is called by the expanded docker targets (e.g. make
293 # docker-test-foo@bar) which will do additional verification.
295 # For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
297 docker-run: docker-qemu-src
298         @mkdir -p "$(DOCKER_CCACHE_DIR)"
299         @if test -z "$(IMAGE)" || test -z "$(TEST)"; \
300                 then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
301         fi
302         $(if $(EXECUTABLE),                                             \
303                 $(call quiet-command,                                   \
304                         $(DOCKER_SCRIPT) update                         \
305                         $(IMAGE) --executable $(EXECUTABLE),            \
306                         "  COPYING $(EXECUTABLE) to $(IMAGE)"))
307         $(call quiet-command,                                           \
308                 $(DOCKER_SCRIPT) run                                    \
309                         $(if $(NOUSER),,--run-as-current-user)          \
310                         --security-opt seccomp=unconfined               \
311                         $(if $(DEBUG),-ti,)                             \
312                         $(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \
313                         -e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST))        \
314                         -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
315                         -e V=$V -e J=$J -e DEBUG=$(DEBUG)               \
316                         -e SHOW_ENV=$(SHOW_ENV)                         \
317                         $(if $(NOUSER),,                                \
318                                 -e CCACHE_DIR=/var/tmp/ccache           \
319                                 -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
320                         )                                               \
321                         -v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
322                         $(IMAGE)                                        \
323                         /var/tmp/qemu/run                               \
324                         $(TEST), "  RUN $(TEST) in ${IMAGE}")
325         $(call quiet-command, rm -r $(DOCKER_SRC_COPY), \
326                 "  CLEANUP $(DOCKER_SRC_COPY)")
328 # Run targets:
330 # Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run"
331 docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
332 docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
333 docker-run-%:
334         @$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu/$(IMAGE)
336 docker-clean:
337         $(call quiet-command, $(DOCKER_SCRIPT) clean)