xref: /openbmc/qemu/tests/docker/Makefile.include (revision c10aaaab)
1324027c2SFam Zheng# Makefile for Docker tests
2324027c2SFam Zheng
3324027c2SFam Zheng.PHONY: docker docker-test docker-clean docker-image docker-qemu-src
4324027c2SFam Zheng
5324027c2SFam ZhengDOCKER_SUFFIX := .docker
6324027c2SFam ZhengDOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles
7bcaf4577SPhilippe Mathieu-DaudéDOCKER_DEPRECATED_IMAGES := debian
8272e551bSPhilippe Mathieu-Daudé# we don't run tests on intermediate images (used as base by another image)
977b08f73SAlex BennéeDOCKER_PARTIAL_IMAGES := debian debian8 debian9 debian8-mxe debian-ports debian-sid debian-bootstrap
10bcaf4577SPhilippe Mathieu-DaudéDOCKER_IMAGES := $(filter-out $(DOCKER_DEPRECATED_IMAGES),$(sort $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker)))))
11324027c2SFam ZhengDOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES))
12324027c2SFam Zheng# Use a global constant ccache directory to speed up repetitive builds
13324027c2SFam ZhengDOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
14324027c2SFam Zheng
15324027c2SFam ZhengDOCKER_TESTS := $(notdir $(shell \
16324027c2SFam Zheng	find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
17324027c2SFam Zheng
18324027c2SFam ZhengDOCKER_TOOLS := travis
19324027c2SFam Zheng
20e27cae26SAlex BennéeDOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py
21e27cae26SAlex Bennée
22324027c2SFam ZhengTESTS ?= %
23324027c2SFam ZhengIMAGES ?= %
24324027c2SFam Zheng
25324027c2SFam ZhengCUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
26bc739b8eSPaolo BonziniDOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME)
27324027c2SFam Zheng
28b28ef6b9SPhilippe Mathieu-Daudé.DELETE_ON_ERROR: $(DOCKER_SRC_COPY)
29324027c2SFam Zheng$(DOCKER_SRC_COPY):
30324027c2SFam Zheng	@mkdir $@
3173fb4f1dSFam Zheng	$(if $(SRC_ARCHIVE), \
3273fb4f1dSFam Zheng		$(call quiet-command, cp "$(SRC_ARCHIVE)" $@/qemu.tar, \
3373fb4f1dSFam Zheng			"CP", "$@/qemu.tar"), \
34bc739b8eSPaolo Bonzini		$(call quiet-command, cd $(SRC_PATH) && scripts/archive-source.sh $@/qemu.tar, \
3573fb4f1dSFam Zheng			"GEN", "$@/qemu.tar"))
36324027c2SFam Zheng	$(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \
370bdb12c7SPeter Maydell		"COPY","RUNNER")
38324027c2SFam Zheng
39324027c2SFam Zhengdocker-qemu-src: $(DOCKER_SRC_COPY)
40324027c2SFam Zheng
41324027c2SFam Zhengdocker-image: ${DOCKER_TARGETS}
42324027c2SFam Zheng
43cff54773SAlex Bennée# General rule for building docker images. If we are a sub-make
44cff54773SAlex Bennée# invoked with SKIP_DOCKER_BUILD we still check the image is up to date
45cff54773SAlex Bennée# though
46cff54773SAlex Bennéeifdef SKIP_DOCKER_BUILD
47cff54773SAlex Bennéedocker-image-%: $(DOCKER_FILES_DIR)/%.docker
48cff54773SAlex Bennée	$(call quiet-command, \
49cff54773SAlex Bennée		$(DOCKER_SCRIPT) check --quiet qemu:$* $<, \
50cff54773SAlex Bennée		"CHECK", "$*")
51cff54773SAlex Bennéeelse
52324027c2SFam Zhengdocker-image-%: $(DOCKER_FILES_DIR)/%.docker
53324027c2SFam Zheng	$(call quiet-command,\
54e27cae26SAlex Bennée		$(DOCKER_SCRIPT) build qemu:$* $< \
55b7c851b2SAlex Bennée		$(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \
56414a8ce5SAlex Bennée		$(if $(NOUSER),,--add-current-user) \
574c84f662SPhilippe Mathieu-Daudé		$(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\
58b7c851b2SAlex Bennée		$(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\
590bdb12c7SPeter Maydell		"BUILD","$*")
60dc338fdbSAlex Bennée
61dc338fdbSAlex Bennée# Special rule for debootstraped binfmt linux-user images
62dc338fdbSAlex Bennéedocker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker
63dc338fdbSAlex Bennée	$(if $(EXECUTABLE),,\
64dc338fdbSAlex Bennée		$(error EXECUTABLE not set, debootstrap of debian-$* would fail))
65dc338fdbSAlex Bennée	$(if $(DEB_ARCH),,\
66dc338fdbSAlex Bennée		$(error DEB_ARCH not set, debootstrap of debian-$* would fail))
67dc338fdbSAlex Bennée	$(if $(DEB_TYPE),,\
68dc338fdbSAlex Bennée		$(error DEB_TYPE not set, debootstrap of debian-$* would fail))
6927963460SAlex Bennée	$(if $(wildcard $(EXECUTABLE)),						\
70dc338fdbSAlex Bennée		$(call quiet-command,						\
71dc338fdbSAlex Bennée			DEB_ARCH=$(DEB_ARCH)					\
72dc338fdbSAlex Bennée			DEB_TYPE=$(DEB_TYPE)					\
73dc338fdbSAlex Bennée			$(DOCKER_SCRIPT) build qemu:debian-$* $< 		\
74dc338fdbSAlex Bennée			$(if $V,,--quiet) $(if $(NOCACHE),--no-cache) 		\
75dc338fdbSAlex Bennée			$(if $(NOUSER),,--add-current-user) 			\
76dc338fdbSAlex Bennée			$(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))	\
77dc338fdbSAlex Bennée			$(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)), \
7819c9a18fSAlex Bennée			"BUILD","binfmt debian-$* (debootstrapped)"),		\
7919c9a18fSAlex Bennée		$(call quiet-command,						\
80d19f5fc0SAlex Bennée			$(DOCKER_SCRIPT) check --quiet qemu:debian-$* $< || 	\
81d19f5fc0SAlex Bennée			{ echo "You will need to build $(EXECUTABLE)"; exit 1;},\
8219c9a18fSAlex Bennée			"CHECK", "debian-$* exists"))
83dc338fdbSAlex Bennée
84cff54773SAlex Bennéeendif
85324027c2SFam Zheng
869d5e546aSPhilippe Mathieu-Daudé# Enforce dependencies for composite images
873e119749SPhilippe Mathieu-Daudédocker-image-debian: docker-image-debian9
88982e758aSPhilippe Mathieu-Daudédocker-image-debian8-mxe: docker-image-debian8
8915288046SPhilippe Mathieu-Daudédocker-image-debian-amd64: docker-image-debian9
9031e205d1SPhilippe Mathieu-Daudédocker-image-debian-armel-cross: docker-image-debian9
9124044d48SPhilippe Mathieu-Daudédocker-image-debian-armhf-cross: docker-image-debian9
9224044d48SPhilippe Mathieu-Daudédocker-image-debian-arm64-cross: docker-image-debian9
93d6db2a1cSAlex Bennéedocker-image-debian-buster-arm64-cross: docker-image-debian10
944319db7bSPhilippe Mathieu-Daudédocker-image-debian-mips-cross: docker-image-debian9
956bf77518SAlex Bennéedocker-image-debian-mipsel-cross: docker-image-debian9
96fd7b284dSPhilippe Mathieu-Daudédocker-image-debian-mips64el-cross: docker-image-debian9
972b1c10bdSPhilippe Mathieu-Daudédocker-image-debian-ppc64el-cross: docker-image-debian9
987d2bcf23SPhilippe Mathieu-Daudédocker-image-debian-s390x-cross: docker-image-debian9
99982e758aSPhilippe Mathieu-Daudédocker-image-debian-win32-cross: docker-image-debian8-mxe
100982e758aSPhilippe Mathieu-Daudédocker-image-debian-win64-cross: docker-image-debian8-mxe
101409c1c9cSAlex Bennée
102409c1c9cSAlex Bennéedocker-image-debian-alpha-cross: docker-image-debian-sid
1033ae8a100SAlex Bennéedocker-image-debian-hppa-cross: docker-image-debian-sid
10421d71c8cSAlex Bennéedocker-image-debian-m68k-cross: docker-image-debian-sid
105a5ec3e36SAlex Bennéedocker-image-debian-sh4-cross: docker-image-debian-sid
106cc6c7365SAlex Bennéedocker-image-debian-sparc64-cross: docker-image-debian-sid
10733b2c4b5SAlex Bennéedocker-image-debian-mips64-cross: docker-image-debian-sid
108e100a967SAlex Bennéedocker-image-debian-riscv64-cross: docker-image-debian-sid
10908f56d8cSAlex Bennéedocker-image-debian-powerpc-cross: docker-image-debian-sid
110*c10aaaabSDavid Gibsondocker-image-debian-ppc64-cross: docker-image-debian-sid
1111fddbf7cSAlex Bennéedocker-image-travis: NOUSER=1
11224e0131fSAlex Bennée
11336dc5fedSPhilippe Mathieu-Daudé# Specialist build images, sometimes very limited tools
11436dc5fedSPhilippe Mathieu-Daudédocker-image-tricore-cross: docker-image-debian9
11536dc5fedSPhilippe Mathieu-Daudé
11677b08f73SAlex Bennée# These images may be good enough for building tests but not for test builds
11777b08f73SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-alpha-cross debian-hppa-cross debian-m68k-cross debian-sh4-cross
11877b08f73SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-sparc64-cross debian-mips64-cross debian-riscv64-cross
11977b08f73SAlex BennéeDOCKER_PARTIAL_IMAGES += debian-tricore-cross debian-powerpc-cross fedora-i386-cross
120d72132c0SAlex BennéeDOCKER_PARTIAL_IMAGES += fedora-cris-cross
12177b08f73SAlex Bennée
12219c9a18fSAlex Bennée# Rules for building linux-user powered images
12319c9a18fSAlex Bennée#
12419c9a18fSAlex Bennée# These are slower than using native cross compiler setups but can
12519c9a18fSAlex Bennée# work around issues with poorly working multi-arch systems and broken
12619c9a18fSAlex Bennée# packages.
12719c9a18fSAlex Bennée
12819c9a18fSAlex Bennée# Jessie is the last supported release for powerpc, but multi-arch is
12919c9a18fSAlex Bennée# broken so we need a qemu-linux-user for this target
13019c9a18fSAlex Bennéedocker-binfmt-image-debian-powerpc-user: DEB_ARCH = powerpc
13119c9a18fSAlex Bennéedocker-binfmt-image-debian-powerpc-user: DEB_TYPE = jessie
13219c9a18fSAlex Bennéedocker-binfmt-image-debian-powerpc-user: EXECUTABLE = ${BUILD_DIR}/ppc-linux-user/qemu-ppc
13319c9a18fSAlex Bennéedocker-image-debian-powerpc-user-cross: docker-binfmt-image-debian-powerpc-user
13419c9a18fSAlex BennéeDOCKER_USER_IMAGES += debian-powerpc-user
13519c9a18fSAlex Bennée
136324027c2SFam Zheng# Expand all the pre-requistes for each docker image and test combination
13777b08f73SAlex Bennée$(foreach i,$(filter-out $(DOCKER_PARTIAL_IMAGES),$(DOCKER_IMAGES) $(DOCKER_DEPRECATED_IMAGES)), \
138324027c2SFam Zheng	$(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
139324027c2SFam Zheng		$(eval .PHONY: docker-$t@$i) \
140324027c2SFam Zheng		$(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
141324027c2SFam Zheng	) \
142324027c2SFam Zheng	$(foreach t,$(DOCKER_TESTS), \
143ff1a3902SAlex Bennée		$(eval docker-all-tests: docker-$t@$i) \
144ff1a3902SAlex Bennée		$(eval docker-$t: docker-$t@$i) \
145324027c2SFam Zheng	) \
146324027c2SFam Zheng)
147324027c2SFam Zheng
148324027c2SFam Zhengdocker:
149324027c2SFam Zheng	@echo 'Build QEMU and run tests inside Docker containers'
150324027c2SFam Zheng	@echo
151324027c2SFam Zheng	@echo 'Available targets:'
152324027c2SFam Zheng	@echo
153324027c2SFam Zheng	@echo '    docker:              Print this help.'
154ff1a3902SAlex Bennée	@echo '    docker-all-tests:    Run all image/test combinations.'
15587db9018SWainer dos Santos Moschetta	@echo '    docker-TEST:         Run "TEST" on all image combinations.'
156324027c2SFam Zheng	@echo '    docker-clean:        Kill and remove residual docker testing containers.'
157324027c2SFam Zheng	@echo '    docker-TEST@IMAGE:   Run "TEST" in container "IMAGE".'
158324027c2SFam Zheng	@echo '                         Note: "TEST" is one of the listed test name,'
159324027c2SFam Zheng	@echo '                         or a script name under $$QEMU_SRC/tests/docker/;'
16087db9018SWainer dos Santos Moschetta	@echo '                         "IMAGE" is one of the listed container name.'
161324027c2SFam Zheng	@echo '    docker-image:        Build all images.'
162324027c2SFam Zheng	@echo '    docker-image-IMAGE:  Build image "IMAGE".'
16387db9018SWainer dos Santos Moschetta	@echo '    docker-run:          For manually running a "TEST" with "IMAGE".'
164324027c2SFam Zheng	@echo
165324027c2SFam Zheng	@echo 'Available container images:'
166324027c2SFam Zheng	@echo '    $(DOCKER_IMAGES)'
16719c9a18fSAlex Bennéeifneq ($(DOCKER_USER_IMAGES),)
16819c9a18fSAlex Bennée	@echo
16919c9a18fSAlex Bennée	@echo 'Available linux-user images (docker-binfmt-image-debian-%):'
17019c9a18fSAlex Bennée	@echo '    $(DOCKER_USER_IMAGES)'
17119c9a18fSAlex Bennéeendif
172324027c2SFam Zheng	@echo
173324027c2SFam Zheng	@echo 'Available tests:'
174324027c2SFam Zheng	@echo '    $(DOCKER_TESTS)'
175324027c2SFam Zheng	@echo
176324027c2SFam Zheng	@echo 'Available tools:'
177324027c2SFam Zheng	@echo '    $(DOCKER_TOOLS)'
178324027c2SFam Zheng	@echo
179324027c2SFam Zheng	@echo 'Special variables:'
180324027c2SFam Zheng	@echo '    TARGET_LIST=a,b,c    Override target list in builds.'
18135e0f959SFam Zheng	@echo '    EXTRA_CONFIGURE_OPTS="..."'
18235e0f959SFam Zheng	@echo '                         Extra configure options.'
183324027c2SFam Zheng	@echo '    IMAGES="a b c ..":   Filters which images to build or run.'
184324027c2SFam Zheng	@echo '    TESTS="x y z .."     Filters which tests to run (for docker-test).'
185324027c2SFam Zheng	@echo '    J=[0..9]*            Overrides the -jN parameter for make commands'
186324027c2SFam Zheng	@echo '                         (default is 1)'
187324027c2SFam Zheng	@echo '    DEBUG=1              Stop and drop to shell in the created container'
188324027c2SFam Zheng	@echo '                         before running the command.'
1898a2390a4SDaniel P. Berrange	@echo '    NETWORK=1            Enable virtual network interface with default backend.'
1906423795eSPhilippe Mathieu-Daudé	@echo '    NETWORK=$$BACKEND     Enable virtual network interface with $$BACKEND.'
191414a8ce5SAlex Bennée	@echo '    NOUSER               Define to disable adding current user to containers passwd.'
192324027c2SFam Zheng	@echo '    NOCACHE=1            Ignore cache when build images.'
193b7c851b2SAlex Bennée	@echo '    EXECUTABLE=<path>    Include executable in image.'
1944c84f662SPhilippe Mathieu-Daudé	@echo '    EXTRA_FILES="<path> [... <path>]"'
1954c84f662SPhilippe Mathieu-Daudé	@echo '                         Include extra files in image.'
196324027c2SFam Zheng
197e86c9a64SAlex Bennée# This rule if for directly running against an arbitrary docker target.
198e86c9a64SAlex Bennée# It is called by the expanded docker targets (e.g. make
199e86c9a64SAlex Bennée# docker-test-foo@bar) which will do additional verification.
200e86c9a64SAlex Bennée#
201e86c9a64SAlex Bennée# For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
202e86c9a64SAlex Bennée#
203e86c9a64SAlex Bennéedocker-run: docker-qemu-src
204324027c2SFam Zheng	@mkdir -p "$(DOCKER_CCACHE_DIR)"
205e86c9a64SAlex Bennée	@if test -z "$(IMAGE)" || test -z "$(TEST)"; \
206e86c9a64SAlex Bennée		then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
207324027c2SFam Zheng	fi
208e86c9a64SAlex Bennée	$(if $(EXECUTABLE),						\
209324027c2SFam Zheng		$(call quiet-command,					\
210e27cae26SAlex Bennée			$(DOCKER_SCRIPT) update 			\
211e86c9a64SAlex Bennée			$(IMAGE) $(EXECUTABLE),				\
212e86c9a64SAlex Bennée			"  COPYING $(EXECUTABLE) to $(IMAGE)"))
213e86c9a64SAlex Bennée	$(call quiet-command,						\
214e27cae26SAlex Bennée		$(DOCKER_SCRIPT) run 					\
2154b2c6bc5SFam Zheng			$(if $(NOUSER),,-u $(shell id -u)) 		\
21644707491SFam Zheng			--security-opt seccomp=unconfined		\
217e86c9a64SAlex Bennée			$(if $V,,--rm) 					\
2184b2c6bc5SFam Zheng			$(if $(DEBUG),-ti,)				\
2198a2390a4SDaniel P. Berrange			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \
2205609c512SAlex Bennée			-e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST))	\
221e86c9a64SAlex Bennée			-e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
222e86c9a64SAlex Bennée			-e V=$V -e J=$J -e DEBUG=$(DEBUG)		\
223e86c9a64SAlex Bennée			-e SHOW_ENV=$(SHOW_ENV) 			\
22436ac78e6SFam Zheng			$(if $(NOUSER),,				\
225324027c2SFam Zheng				-e CCACHE_DIR=/var/tmp/ccache 		\
226324027c2SFam Zheng				-v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
22736ac78e6SFam Zheng			)						\
22836ac78e6SFam Zheng			-v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
229e86c9a64SAlex Bennée			$(IMAGE) 					\
230c8158513SFam Zheng			/var/tmp/qemu/run 				\
231e86c9a64SAlex Bennée			$(TEST), "  RUN $(TEST) in ${IMAGE}")
23208c3f6d5SPeter Xu	$(call quiet-command, rm -r $(DOCKER_SRC_COPY), \
23308c3f6d5SPeter Xu		"  CLEANUP $(DOCKER_SRC_COPY)")
234e86c9a64SAlex Bennée
235e86c9a64SAlex Bennée# Run targets:
236e86c9a64SAlex Bennée#
237e86c9a64SAlex Bennée# Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run"
238e86c9a64SAlex Bennéedocker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
239e86c9a64SAlex Bennéedocker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
240e86c9a64SAlex Bennéedocker-run-%:
241e86c9a64SAlex Bennée	@$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu:$(IMAGE)
242324027c2SFam Zheng
243324027c2SFam Zhengdocker-clean:
244e27cae26SAlex Bennée	$(call quiet-command, $(DOCKER_SCRIPT) clean)
245