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) 9272e551bSPhilippe Mathieu-DaudéDOCKER_INTERMEDIATE_IMAGES := debian8 debian9 debian8-mxe debian-ports debian-sid 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 28324027c2SFam Zheng$(DOCKER_SRC_COPY): 29324027c2SFam Zheng @mkdir $@ 30bc739b8eSPaolo Bonzini $(call quiet-command, cd $(SRC_PATH) && scripts/archive-source.sh $@/qemu.tar, \ 31b7f40420SFam Zheng "GEN", "$@/qemu.tar") 32324027c2SFam Zheng $(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \ 330bdb12c7SPeter Maydell "COPY","RUNNER") 34324027c2SFam Zheng 35324027c2SFam Zhengdocker-qemu-src: $(DOCKER_SRC_COPY) 36324027c2SFam Zheng 37324027c2SFam Zhengdocker-image: ${DOCKER_TARGETS} 38324027c2SFam Zheng 39cff54773SAlex Bennée# General rule for building docker images. If we are a sub-make 40cff54773SAlex Bennée# invoked with SKIP_DOCKER_BUILD we still check the image is upto date 41cff54773SAlex Bennée# though 42cff54773SAlex Bennéeifdef SKIP_DOCKER_BUILD 43cff54773SAlex Bennéedocker-image-%: $(DOCKER_FILES_DIR)/%.docker 44cff54773SAlex Bennée $(call quiet-command, \ 45cff54773SAlex Bennée $(DOCKER_SCRIPT) check --quiet qemu:$* $<, \ 46cff54773SAlex Bennée "CHECK", "$*") 47cff54773SAlex Bennéeelse 48324027c2SFam Zhengdocker-image-%: $(DOCKER_FILES_DIR)/%.docker 49324027c2SFam Zheng $(call quiet-command,\ 50e27cae26SAlex Bennée $(DOCKER_SCRIPT) build qemu:$* $< \ 51b7c851b2SAlex Bennée $(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \ 52414a8ce5SAlex Bennée $(if $(NOUSER),,--add-current-user) \ 534c84f662SPhilippe Mathieu-Daudé $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\ 54b7c851b2SAlex Bennée $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\ 550bdb12c7SPeter Maydell "BUILD","$*") 56dc338fdbSAlex Bennée 57dc338fdbSAlex Bennée# Special rule for debootstraped binfmt linux-user images 58dc338fdbSAlex Bennéedocker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker 59dc338fdbSAlex Bennée $(if $(EXECUTABLE),,\ 60dc338fdbSAlex Bennée $(error EXECUTABLE not set, debootstrap of debian-$* would fail)) 61dc338fdbSAlex Bennée $(if $(wildcard $(EXECUTABLE)),,\ 62dc338fdbSAlex Bennée $(error Please build $(EXECUTABLE) first)) 63dc338fdbSAlex Bennée $(if $(DEB_ARCH),,\ 64dc338fdbSAlex Bennée $(error DEB_ARCH not set, debootstrap of debian-$* would fail)) 65dc338fdbSAlex Bennée $(if $(DEB_TYPE),,\ 66dc338fdbSAlex Bennée $(error DEB_TYPE not set, debootstrap of debian-$* would fail)) 67*19c9a18fSAlex Bennée $(if $(filter $(QEMU_TARGET),$(TARGET_DIRS)), \ 68dc338fdbSAlex Bennée $(call quiet-command, \ 69dc338fdbSAlex Bennée DEB_ARCH=$(DEB_ARCH) \ 70dc338fdbSAlex Bennée DEB_TYPE=$(DEB_TYPE) \ 71dc338fdbSAlex Bennée $(DOCKER_SCRIPT) build qemu:debian-$* $< \ 72dc338fdbSAlex Bennée $(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \ 73dc338fdbSAlex Bennée $(if $(NOUSER),,--add-current-user) \ 74dc338fdbSAlex Bennée $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES)) \ 75dc338fdbSAlex Bennée $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)), \ 76*19c9a18fSAlex Bennée "BUILD","binfmt debian-$* (debootstrapped)"), \ 77*19c9a18fSAlex Bennée $(call quiet-command, \ 78*19c9a18fSAlex Bennée $(DOCKER_SCRIPT) check --quiet qemu:debian-$* $<, \ 79*19c9a18fSAlex Bennée "CHECK", "debian-$* exists")) 80dc338fdbSAlex Bennée 81cff54773SAlex Bennéeendif 82324027c2SFam Zheng 839d5e546aSPhilippe Mathieu-Daudé# Enforce dependencies for composite images 843e119749SPhilippe Mathieu-Daudédocker-image-debian: docker-image-debian9 85982e758aSPhilippe Mathieu-Daudédocker-image-debian8-mxe: docker-image-debian8 8615288046SPhilippe Mathieu-Daudédocker-image-debian-amd64: docker-image-debian9 8731e205d1SPhilippe Mathieu-Daudédocker-image-debian-armel-cross: docker-image-debian9 8824044d48SPhilippe Mathieu-Daudédocker-image-debian-armhf-cross: docker-image-debian9 8924044d48SPhilippe Mathieu-Daudédocker-image-debian-arm64-cross: docker-image-debian9 904319db7bSPhilippe Mathieu-Daudédocker-image-debian-mips-cross: docker-image-debian9 916bf77518SAlex Bennéedocker-image-debian-mipsel-cross: docker-image-debian9 92fd7b284dSPhilippe Mathieu-Daudédocker-image-debian-mips64el-cross: docker-image-debian9 932b1c10bdSPhilippe Mathieu-Daudédocker-image-debian-ppc64el-cross: docker-image-debian9 947d2bcf23SPhilippe Mathieu-Daudédocker-image-debian-s390x-cross: docker-image-debian9 95982e758aSPhilippe Mathieu-Daudédocker-image-debian-win32-cross: docker-image-debian8-mxe 96982e758aSPhilippe Mathieu-Daudédocker-image-debian-win64-cross: docker-image-debian8-mxe 97409c1c9cSAlex Bennée 98409c1c9cSAlex Bennée# Debian SID images - we are tracking a rolling distro so we want to 99409c1c9cSAlex Bennée# force a re-build of the base image if we ever need to build one of 100409c1c9cSAlex Bennée# its children. 101cff54773SAlex Bennéeifndef SKIP_DOCKER_BUILD 1025499fa9eSAlex Bennéeifeq ($(HAVE_USER_DOCKER),y) 1035499fa9eSAlex BennéeSID_AGE=$(shell $(DOCKER_SCRIPT) check --checktype=age --olderthan=180 --quiet qemu:debian-sid) 1045499fa9eSAlex Bennéeifeq ($(SID_AGE),) 1055499fa9eSAlex Bennéeelse 106409c1c9cSAlex Bennéedocker-image-debian-sid: NOCACHE=1 107cff54773SAlex Bennéeendif 1085499fa9eSAlex Bennéeendif 1095499fa9eSAlex Bennéeendif 110409c1c9cSAlex Bennée 111409c1c9cSAlex Bennéedocker-image-debian-alpha-cross: docker-image-debian-sid 1123ae8a100SAlex Bennéedocker-image-debian-hppa-cross: docker-image-debian-sid 11321d71c8cSAlex Bennéedocker-image-debian-m68k-cross: docker-image-debian-sid 114a5ec3e36SAlex Bennéedocker-image-debian-sh4-cross: docker-image-debian-sid 115cc6c7365SAlex Bennéedocker-image-debian-sparc64-cross: docker-image-debian-sid 11633b2c4b5SAlex Bennéedocker-image-debian-mips64-cross: docker-image-debian-sid 117e100a967SAlex Bennéedocker-image-debian-riscv64-cross: docker-image-debian-sid 11808f56d8cSAlex Bennéedocker-image-debian-powerpc-cross: docker-image-debian-sid 1191fddbf7cSAlex Bennéedocker-image-travis: NOUSER=1 12024e0131fSAlex Bennée 12136dc5fedSPhilippe Mathieu-Daudé# Specialist build images, sometimes very limited tools 12236dc5fedSPhilippe Mathieu-Daudédocker-image-tricore-cross: docker-image-debian9 12336dc5fedSPhilippe Mathieu-Daudé 124*19c9a18fSAlex Bennée# Rules for building linux-user powered images 125*19c9a18fSAlex Bennée# 126*19c9a18fSAlex Bennée# These are slower than using native cross compiler setups but can 127*19c9a18fSAlex Bennée# work around issues with poorly working multi-arch systems and broken 128*19c9a18fSAlex Bennée# packages. 129*19c9a18fSAlex Bennée 130*19c9a18fSAlex Bennée# Jessie is the last supported release for powerpc, but multi-arch is 131*19c9a18fSAlex Bennée# broken so we need a qemu-linux-user for this target 132*19c9a18fSAlex Bennéedocker-binfmt-image-debian-powerpc-user: DEB_ARCH = powerpc 133*19c9a18fSAlex Bennéedocker-binfmt-image-debian-powerpc-user: DEB_TYPE = jessie 134*19c9a18fSAlex Bennéedocker-binfmt-image-debian-powerpc-user: QEMU_TARGET = ppc-linux-user 135*19c9a18fSAlex Bennéedocker-binfmt-image-debian-powerpc-user: EXECUTABLE = ${BUILD_DIR}/ppc-linux-user/qemu-ppc 136*19c9a18fSAlex Bennéedocker-image-debian-powerpc-user-cross: docker-binfmt-image-debian-powerpc-user 137*19c9a18fSAlex BennéeDOCKER_USER_IMAGES += debian-powerpc-user 138*19c9a18fSAlex Bennée 139324027c2SFam Zheng# Expand all the pre-requistes for each docker image and test combination 140272e551bSPhilippe Mathieu-Daudé$(foreach i,$(filter-out $(DOCKER_INTERMEDIATE_IMAGES),$(DOCKER_IMAGES) $(DOCKER_DEPRECATED_IMAGES)), \ 141324027c2SFam Zheng $(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \ 142324027c2SFam Zheng $(eval .PHONY: docker-$t@$i) \ 143324027c2SFam Zheng $(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \ 144324027c2SFam Zheng ) \ 145324027c2SFam Zheng $(foreach t,$(DOCKER_TESTS), \ 146324027c2SFam Zheng $(eval docker-test: docker-$t@$i) \ 147324027c2SFam Zheng ) \ 148324027c2SFam Zheng) 149324027c2SFam Zheng 150324027c2SFam Zhengdocker: 151324027c2SFam Zheng @echo 'Build QEMU and run tests inside Docker containers' 152324027c2SFam Zheng @echo 153324027c2SFam Zheng @echo 'Available targets:' 154324027c2SFam Zheng @echo 155324027c2SFam Zheng @echo ' docker: Print this help.' 156324027c2SFam Zheng @echo ' docker-test: Run all image/test combinations.' 157324027c2SFam Zheng @echo ' docker-clean: Kill and remove residual docker testing containers.' 158324027c2SFam Zheng @echo ' docker-TEST@IMAGE: Run "TEST" in container "IMAGE".' 159324027c2SFam Zheng @echo ' Note: "TEST" is one of the listed test name,' 160324027c2SFam Zheng @echo ' or a script name under $$QEMU_SRC/tests/docker/;' 161324027c2SFam Zheng @echo ' "IMAGE" is one of the listed container name."' 162324027c2SFam Zheng @echo ' docker-image: Build all images.' 163324027c2SFam Zheng @echo ' docker-image-IMAGE: Build image "IMAGE".' 164e86c9a64SAlex Bennée @echo ' docker-run: For manually running a "TEST" with "IMAGE"' 165324027c2SFam Zheng @echo 166324027c2SFam Zheng @echo 'Available container images:' 167324027c2SFam Zheng @echo ' $(DOCKER_IMAGES)' 168*19c9a18fSAlex Bennéeifneq ($(DOCKER_USER_IMAGES),) 169*19c9a18fSAlex Bennée @echo 170*19c9a18fSAlex Bennée @echo 'Available linux-user images (docker-binfmt-image-debian-%):' 171*19c9a18fSAlex Bennée @echo ' $(DOCKER_USER_IMAGES)' 172*19c9a18fSAlex Bennéeendif 173324027c2SFam Zheng @echo 174324027c2SFam Zheng @echo 'Available tests:' 175324027c2SFam Zheng @echo ' $(DOCKER_TESTS)' 176324027c2SFam Zheng @echo 177324027c2SFam Zheng @echo 'Available tools:' 178324027c2SFam Zheng @echo ' $(DOCKER_TOOLS)' 179324027c2SFam Zheng @echo 180324027c2SFam Zheng @echo 'Special variables:' 181324027c2SFam Zheng @echo ' TARGET_LIST=a,b,c Override target list in builds.' 18235e0f959SFam Zheng @echo ' EXTRA_CONFIGURE_OPTS="..."' 18335e0f959SFam Zheng @echo ' Extra configure options.' 184324027c2SFam Zheng @echo ' IMAGES="a b c ..": Filters which images to build or run.' 185324027c2SFam Zheng @echo ' TESTS="x y z .." Filters which tests to run (for docker-test).' 186324027c2SFam Zheng @echo ' J=[0..9]* Overrides the -jN parameter for make commands' 187324027c2SFam Zheng @echo ' (default is 1)' 188324027c2SFam Zheng @echo ' DEBUG=1 Stop and drop to shell in the created container' 189324027c2SFam Zheng @echo ' before running the command.' 1908a2390a4SDaniel P. Berrange @echo ' NETWORK=1 Enable virtual network interface with default backend.' 1916423795eSPhilippe Mathieu-Daudé @echo ' NETWORK=$$BACKEND Enable virtual network interface with $$BACKEND.' 192414a8ce5SAlex Bennée @echo ' NOUSER Define to disable adding current user to containers passwd.' 193324027c2SFam Zheng @echo ' NOCACHE=1 Ignore cache when build images.' 194b7c851b2SAlex Bennée @echo ' EXECUTABLE=<path> Include executable in image.' 1954c84f662SPhilippe Mathieu-Daudé @echo ' EXTRA_FILES="<path> [... <path>]"' 1964c84f662SPhilippe Mathieu-Daudé @echo ' Include extra files in image.' 197324027c2SFam Zheng 198e86c9a64SAlex Bennée# This rule if for directly running against an arbitrary docker target. 199e86c9a64SAlex Bennée# It is called by the expanded docker targets (e.g. make 200e86c9a64SAlex Bennée# docker-test-foo@bar) which will do additional verification. 201e86c9a64SAlex Bennée# 202e86c9a64SAlex Bennée# For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64 203e86c9a64SAlex Bennée# 204e86c9a64SAlex Bennéedocker-run: docker-qemu-src 205324027c2SFam Zheng @mkdir -p "$(DOCKER_CCACHE_DIR)" 206e86c9a64SAlex Bennée @if test -z "$(IMAGE)" || test -z "$(TEST)"; \ 207e86c9a64SAlex Bennée then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \ 208324027c2SFam Zheng fi 209e86c9a64SAlex Bennée $(if $(EXECUTABLE), \ 210324027c2SFam Zheng $(call quiet-command, \ 211e27cae26SAlex Bennée $(DOCKER_SCRIPT) update \ 212e86c9a64SAlex Bennée $(IMAGE) $(EXECUTABLE), \ 213e86c9a64SAlex Bennée " COPYING $(EXECUTABLE) to $(IMAGE)")) 214e86c9a64SAlex Bennée $(call quiet-command, \ 215e27cae26SAlex Bennée $(DOCKER_SCRIPT) run \ 2164b2c6bc5SFam Zheng $(if $(NOUSER),,-u $(shell id -u)) \ 21744707491SFam Zheng --security-opt seccomp=unconfined \ 218e86c9a64SAlex Bennée $(if $V,,--rm) \ 2194b2c6bc5SFam Zheng $(if $(DEBUG),-ti,) \ 2208a2390a4SDaniel P. Berrange $(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \ 2215609c512SAlex Bennée -e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST)) \ 222e86c9a64SAlex Bennée -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \ 223e86c9a64SAlex Bennée -e V=$V -e J=$J -e DEBUG=$(DEBUG) \ 224e86c9a64SAlex Bennée -e SHOW_ENV=$(SHOW_ENV) \ 22536ac78e6SFam Zheng $(if $(NOUSER),, \ 226324027c2SFam Zheng -e CCACHE_DIR=/var/tmp/ccache \ 227324027c2SFam Zheng -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \ 22836ac78e6SFam Zheng ) \ 22936ac78e6SFam Zheng -v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \ 230e86c9a64SAlex Bennée $(IMAGE) \ 231c8158513SFam Zheng /var/tmp/qemu/run \ 232e86c9a64SAlex Bennée $(TEST), " RUN $(TEST) in ${IMAGE}") 23308c3f6d5SPeter Xu $(call quiet-command, rm -r $(DOCKER_SRC_COPY), \ 23408c3f6d5SPeter Xu " CLEANUP $(DOCKER_SRC_COPY)") 235e86c9a64SAlex Bennée 236e86c9a64SAlex Bennée# Run targets: 237e86c9a64SAlex Bennée# 238e86c9a64SAlex Bennée# Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run" 239e86c9a64SAlex Bennéedocker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/') 240e86c9a64SAlex Bennéedocker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/') 241e86c9a64SAlex Bennéedocker-run-%: 242e86c9a64SAlex Bennée @$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu:$(IMAGE) 243324027c2SFam Zheng 244324027c2SFam Zhengdocker-clean: 245e27cae26SAlex Bennée $(call quiet-command, $(DOCKER_SCRIPT) clean) 246