qapi: add 'if' to alternate members
[qemu/ar7.git] / tests / docker / Makefile.include
blob9467e9d088971080a72f1239abce64ba5fd5ea05
1 # Makefile for Docker tests
3 .PHONY: docker docker-test docker-clean docker-image docker-qemu-src
5 DOCKER_SUFFIX := .docker
6 DOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles
7 DOCKER_DEPRECATED_IMAGES := debian
8 # we don't run tests on intermediate images (used as base by another image)
9 DOCKER_PARTIAL_IMAGES := debian debian8 debian9 debian8-mxe debian-ports debian-sid debian-bootstrap
10 DOCKER_IMAGES := $(filter-out $(DOCKER_DEPRECATED_IMAGES),$(sort $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker)))))
11 DOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES))
12 # Use a global constant ccache directory to speed up repetitive builds
13 DOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
15 DOCKER_TESTS := $(notdir $(shell \
16         find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
18 DOCKER_TOOLS := travis
20 DOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py
22 TESTS ?= %
23 IMAGES ?= %
25 CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
26 DOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME)
28 .DELETE_ON_ERROR: $(DOCKER_SRC_COPY)
29 $(DOCKER_SRC_COPY):
30         @mkdir $@
31         $(if $(SRC_ARCHIVE), \
32                 $(call quiet-command, cp "$(SRC_ARCHIVE)" $@/qemu.tar, \
33                         "CP", "$@/qemu.tar"), \
34                 $(call quiet-command, cd $(SRC_PATH) && scripts/archive-source.sh $@/qemu.tar, \
35                         "GEN", "$@/qemu.tar"))
36         $(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \
37                 "COPY","RUNNER")
39 docker-qemu-src: $(DOCKER_SRC_COPY)
41 docker-image: ${DOCKER_TARGETS}
43 # General rule for building docker images. If we are a sub-make
44 # invoked with SKIP_DOCKER_BUILD we still check the image is up to date
45 # though
46 ifdef SKIP_DOCKER_BUILD
47 docker-image-%: $(DOCKER_FILES_DIR)/%.docker
48         $(call quiet-command, \
49                 $(DOCKER_SCRIPT) check --quiet qemu:$* $<, \
50                 "CHECK", "$*")
51 else
52 docker-image-%: $(DOCKER_FILES_DIR)/%.docker
53         $(call quiet-command,\
54                 $(DOCKER_SCRIPT) build qemu:$* $< \
55                 $(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \
56                 $(if $(NOUSER),,--add-current-user) \
57                 $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\
58                 $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\
59                 "BUILD","$*")
61 # Special rule for debootstraped binfmt linux-user images
62 docker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker
63         $(if $(EXECUTABLE),,\
64                 $(error EXECUTABLE not set, debootstrap of debian-$* would fail))
65         $(if $(DEB_ARCH),,\
66                 $(error DEB_ARCH not set, debootstrap of debian-$* would fail))
67         $(if $(DEB_TYPE),,\
68                 $(error DEB_TYPE not set, debootstrap of debian-$* would fail))
69         $(if $(wildcard $(EXECUTABLE)),                                         \
70                 $(call quiet-command,                                           \
71                         DEB_ARCH=$(DEB_ARCH)                                    \
72                         DEB_TYPE=$(DEB_TYPE)                                    \
73                         $(DOCKER_SCRIPT) build qemu:debian-$* $<                \
74                         $(if $V,,--quiet) $(if $(NOCACHE),--no-cache)           \
75                         $(if $(NOUSER),,--add-current-user)                     \
76                         $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))       \
77                         $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)), \
78                         "BUILD","binfmt debian-$* (debootstrapped)"),           \
79                 $(call quiet-command,                                           \
80                         $(DOCKER_SCRIPT) check --quiet qemu:debian-$* $< ||     \
81                         { echo "You will need to build $(EXECUTABLE)"; exit 1;},\
82                         "CHECK", "debian-$* exists"))
84 endif
86 # Enforce dependencies for composite images
87 docker-image-debian: docker-image-debian9
88 docker-image-debian8-mxe: docker-image-debian8
89 docker-image-debian-amd64: docker-image-debian9
90 docker-image-debian-armel-cross: docker-image-debian9
91 docker-image-debian-armhf-cross: docker-image-debian9
92 docker-image-debian-arm64-cross: docker-image-debian9
93 docker-image-debian-mips-cross: docker-image-debian9
94 docker-image-debian-mipsel-cross: docker-image-debian9
95 docker-image-debian-mips64el-cross: docker-image-debian9
96 docker-image-debian-ppc64el-cross: docker-image-debian9
97 docker-image-debian-s390x-cross: docker-image-debian9
98 docker-image-debian-win32-cross: docker-image-debian8-mxe
99 docker-image-debian-win64-cross: docker-image-debian8-mxe
101 # Debian SID images - we are tracking a rolling distro so we want to
102 # force a re-build of the base image if we ever need to build one of
103 # its children.
104 ifndef SKIP_DOCKER_BUILD
105 ifeq ($(HAVE_USER_DOCKER),y)
106 SID_AGE=$(shell $(DOCKER_SCRIPT) check --checktype=age --olderthan=180 --quiet qemu:debian-sid)
107 ifeq ($(SID_AGE),)
108 else
109 docker-image-debian-sid: NOCACHE=1
110 endif
111 endif
112 endif
114 docker-image-debian-alpha-cross: docker-image-debian-sid
115 docker-image-debian-hppa-cross: docker-image-debian-sid
116 docker-image-debian-m68k-cross: docker-image-debian-sid
117 docker-image-debian-sh4-cross: docker-image-debian-sid
118 docker-image-debian-sparc64-cross: docker-image-debian-sid
119 docker-image-debian-mips64-cross: docker-image-debian-sid
120 docker-image-debian-riscv64-cross: docker-image-debian-sid
121 docker-image-debian-powerpc-cross: docker-image-debian-sid
122 docker-image-travis: NOUSER=1
124 # Specialist build images, sometimes very limited tools
125 docker-image-tricore-cross: docker-image-debian9
127 # These images may be good enough for building tests but not for test builds
128 DOCKER_PARTIAL_IMAGES += debian-alpha-cross debian-hppa-cross debian-m68k-cross debian-sh4-cross
129 DOCKER_PARTIAL_IMAGES += debian-sparc64-cross debian-mips64-cross debian-riscv64-cross
130 DOCKER_PARTIAL_IMAGES += debian-tricore-cross debian-powerpc-cross fedora-i386-cross
132 # Rules for building linux-user powered images
134 # These are slower than using native cross compiler setups but can
135 # work around issues with poorly working multi-arch systems and broken
136 # packages.
138 # Jessie is the last supported release for powerpc, but multi-arch is
139 # broken so we need a qemu-linux-user for this target
140 docker-binfmt-image-debian-powerpc-user: DEB_ARCH = powerpc
141 docker-binfmt-image-debian-powerpc-user: DEB_TYPE = jessie
142 docker-binfmt-image-debian-powerpc-user: EXECUTABLE = ${BUILD_DIR}/ppc-linux-user/qemu-ppc
143 docker-image-debian-powerpc-user-cross: docker-binfmt-image-debian-powerpc-user
144 DOCKER_USER_IMAGES += debian-powerpc-user
146 # Expand all the pre-requistes for each docker image and test combination
147 $(foreach i,$(filter-out $(DOCKER_PARTIAL_IMAGES),$(DOCKER_IMAGES) $(DOCKER_DEPRECATED_IMAGES)), \
148         $(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
149                 $(eval .PHONY: docker-$t@$i) \
150                 $(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
151         ) \
152         $(foreach t,$(DOCKER_TESTS), \
153                 $(eval docker-all-tests: docker-$t@$i) \
154                 $(eval docker-$t: docker-$t@$i) \
155         ) \
158 docker:
159         @echo 'Build QEMU and run tests inside Docker containers'
160         @echo
161         @echo 'Available targets:'
162         @echo
163         @echo '    docker:              Print this help.'
164         @echo '    docker-all-tests:    Run all image/test combinations.'
165         @echo '    docker-TEST:         Run TEST on all image combinations.'
166         @echo '    docker-clean:        Kill and remove residual docker testing containers.'
167         @echo '    docker-TEST@IMAGE:   Run "TEST" in container "IMAGE".'
168         @echo '                         Note: "TEST" is one of the listed test name,'
169         @echo '                         or a script name under $$QEMU_SRC/tests/docker/;'
170         @echo '                         "IMAGE" is one of the listed container name."'
171         @echo '    docker-image:        Build all images.'
172         @echo '    docker-image-IMAGE:  Build image "IMAGE".'
173         @echo '    docker-run:          For manually running a "TEST" with "IMAGE"'
174         @echo
175         @echo 'Available container images:'
176         @echo '    $(DOCKER_IMAGES)'
177 ifneq ($(DOCKER_USER_IMAGES),)
178         @echo
179         @echo 'Available linux-user images (docker-binfmt-image-debian-%):'
180         @echo '    $(DOCKER_USER_IMAGES)'
181 endif
182         @echo
183         @echo 'Available tests:'
184         @echo '    $(DOCKER_TESTS)'
185         @echo
186         @echo 'Available tools:'
187         @echo '    $(DOCKER_TOOLS)'
188         @echo
189         @echo 'Special variables:'
190         @echo '    TARGET_LIST=a,b,c    Override target list in builds.'
191         @echo '    EXTRA_CONFIGURE_OPTS="..."'
192         @echo '                         Extra configure options.'
193         @echo '    IMAGES="a b c ..":   Filters which images to build or run.'
194         @echo '    TESTS="x y z .."     Filters which tests to run (for docker-test).'
195         @echo '    J=[0..9]*            Overrides the -jN parameter for make commands'
196         @echo '                         (default is 1)'
197         @echo '    DEBUG=1              Stop and drop to shell in the created container'
198         @echo '                         before running the command.'
199         @echo '    NETWORK=1            Enable virtual network interface with default backend.'
200         @echo '    NETWORK=$$BACKEND     Enable virtual network interface with $$BACKEND.'
201         @echo '    NOUSER               Define to disable adding current user to containers passwd.'
202         @echo '    NOCACHE=1            Ignore cache when build images.'
203         @echo '    EXECUTABLE=<path>    Include executable in image.'
204         @echo '    EXTRA_FILES="<path> [... <path>]"'
205         @echo '                         Include extra files in image.'
207 # This rule if for directly running against an arbitrary docker target.
208 # It is called by the expanded docker targets (e.g. make
209 # docker-test-foo@bar) which will do additional verification.
211 # For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
213 docker-run: docker-qemu-src
214         @mkdir -p "$(DOCKER_CCACHE_DIR)"
215         @if test -z "$(IMAGE)" || test -z "$(TEST)"; \
216                 then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
217         fi
218         $(if $(EXECUTABLE),                                             \
219                 $(call quiet-command,                                   \
220                         $(DOCKER_SCRIPT) update                         \
221                         $(IMAGE) $(EXECUTABLE),                         \
222                         "  COPYING $(EXECUTABLE) to $(IMAGE)"))
223         $(call quiet-command,                                           \
224                 $(DOCKER_SCRIPT) run                                    \
225                         $(if $(NOUSER),,-u $(shell id -u))              \
226                         --security-opt seccomp=unconfined               \
227                         $(if $V,,--rm)                                  \
228                         $(if $(DEBUG),-ti,)                             \
229                         $(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \
230                         -e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST))        \
231                         -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
232                         -e V=$V -e J=$J -e DEBUG=$(DEBUG)               \
233                         -e SHOW_ENV=$(SHOW_ENV)                         \
234                         $(if $(NOUSER),,                                \
235                                 -e CCACHE_DIR=/var/tmp/ccache           \
236                                 -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
237                         )                                               \
238                         -v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
239                         $(IMAGE)                                        \
240                         /var/tmp/qemu/run                               \
241                         $(TEST), "  RUN $(TEST) in ${IMAGE}")
242         $(call quiet-command, rm -r $(DOCKER_SRC_COPY), \
243                 "  CLEANUP $(DOCKER_SRC_COPY)")
245 # Run targets:
247 # Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run"
248 docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
249 docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
250 docker-run-%:
251         @$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu:$(IMAGE)
253 docker-clean:
254         $(call quiet-command, $(DOCKER_SCRIPT) clean)