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 8bcaf4577SPhilippe Mathieu-DaudéDOCKER_IMAGES := $(filter-out $(DOCKER_DEPRECATED_IMAGES),$(sort $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker))))) 9324027c2SFam ZhengDOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES)) 10324027c2SFam Zheng# Use a global constant ccache directory to speed up repetitive builds 11324027c2SFam ZhengDOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache 12324027c2SFam Zheng 13324027c2SFam ZhengDOCKER_TESTS := $(notdir $(shell \ 14324027c2SFam Zheng find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f)) 15324027c2SFam Zheng 16324027c2SFam ZhengDOCKER_TOOLS := travis 17324027c2SFam Zheng 18e27cae26SAlex BennéeDOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py 19e27cae26SAlex Bennée 20324027c2SFam ZhengTESTS ?= % 21324027c2SFam ZhengIMAGES ?= % 22324027c2SFam Zheng 23324027c2SFam ZhengCUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$) 24bc739b8eSPaolo BonziniDOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME) 25324027c2SFam Zheng 26324027c2SFam Zheng$(DOCKER_SRC_COPY): 27324027c2SFam Zheng @mkdir $@ 28bc739b8eSPaolo Bonzini $(call quiet-command, cd $(SRC_PATH) && scripts/archive-source.sh $@/qemu.tar, \ 29b7f40420SFam Zheng "GEN", "$@/qemu.tar") 30324027c2SFam Zheng $(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \ 310bdb12c7SPeter Maydell "COPY","RUNNER") 32324027c2SFam Zheng 33324027c2SFam Zhengdocker-qemu-src: $(DOCKER_SRC_COPY) 34324027c2SFam Zheng 35324027c2SFam Zhengdocker-image: ${DOCKER_TARGETS} 36324027c2SFam Zheng 37*cff54773SAlex Bennée# General rule for building docker images. If we are a sub-make 38*cff54773SAlex Bennée# invoked with SKIP_DOCKER_BUILD we still check the image is upto date 39*cff54773SAlex Bennée# though 40*cff54773SAlex Bennéeifdef SKIP_DOCKER_BUILD 41*cff54773SAlex Bennéedocker-image-%: $(DOCKER_FILES_DIR)/%.docker 42*cff54773SAlex Bennée $(call quiet-command, \ 43*cff54773SAlex Bennée $(DOCKER_SCRIPT) check --quiet qemu:$* $<, \ 44*cff54773SAlex Bennée "CHECK", "$*") 45*cff54773SAlex Bennéeelse 46324027c2SFam Zhengdocker-image-%: $(DOCKER_FILES_DIR)/%.docker 47a351b4b0SSascha Silbe @if test "$@" = docker-image-debian-bootstrap -a -z "$(EXECUTABLE)"; then \ 48a351b4b0SSascha Silbe echo WARNING: EXECUTABLE is not set, debootstrap may fail. 2>&1 ; \ 49a351b4b0SSascha Silbe fi 50324027c2SFam Zheng $(call quiet-command,\ 51e27cae26SAlex Bennée $(DOCKER_SCRIPT) build qemu:$* $< \ 52b7c851b2SAlex Bennée $(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \ 53414a8ce5SAlex Bennée $(if $(NOUSER),,--add-current-user) \ 544c84f662SPhilippe Mathieu-Daudé $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\ 55b7c851b2SAlex Bennée $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\ 560bdb12c7SPeter Maydell "BUILD","$*") 57*cff54773SAlex Bennéeendif 58324027c2SFam Zheng 599d5e546aSPhilippe Mathieu-Daudé# Enforce dependencies for composite images 603e119749SPhilippe Mathieu-Daudédocker-image-debian: docker-image-debian9 61982e758aSPhilippe Mathieu-Daudédocker-image-debian8-mxe: docker-image-debian8 6215288046SPhilippe Mathieu-Daudédocker-image-debian-amd64: docker-image-debian9 6331e205d1SPhilippe Mathieu-Daudédocker-image-debian-armel-cross: docker-image-debian9 6424044d48SPhilippe Mathieu-Daudédocker-image-debian-armhf-cross: docker-image-debian9 6524044d48SPhilippe Mathieu-Daudédocker-image-debian-arm64-cross: docker-image-debian9 664319db7bSPhilippe Mathieu-Daudédocker-image-debian-mips-cross: docker-image-debian9 676bf77518SAlex Bennéedocker-image-debian-mipsel-cross: docker-image-debian9 68fd7b284dSPhilippe Mathieu-Daudédocker-image-debian-mips64el-cross: docker-image-debian9 692b1c10bdSPhilippe Mathieu-Daudédocker-image-debian-ppc64el-cross: docker-image-debian9 707d2bcf23SPhilippe Mathieu-Daudédocker-image-debian-s390x-cross: docker-image-debian9 71982e758aSPhilippe Mathieu-Daudédocker-image-debian-win32-cross: docker-image-debian8-mxe 72982e758aSPhilippe Mathieu-Daudédocker-image-debian-win64-cross: docker-image-debian8-mxe 73409c1c9cSAlex Bennée 74409c1c9cSAlex Bennée# Debian SID images - we are tracking a rolling distro so we want to 75409c1c9cSAlex Bennée# force a re-build of the base image if we ever need to build one of 76409c1c9cSAlex Bennée# its children. 77*cff54773SAlex Bennéeifndef SKIP_DOCKER_BUILD 78409c1c9cSAlex Bennéedocker-image-debian-sid: NOCACHE=1 79*cff54773SAlex Bennéeendif 80409c1c9cSAlex Bennée 81409c1c9cSAlex Bennéedocker-image-debian-alpha-cross: docker-image-debian-sid 823ae8a100SAlex Bennéedocker-image-debian-hppa-cross: docker-image-debian-sid 8321d71c8cSAlex Bennéedocker-image-debian-m68k-cross: docker-image-debian-sid 84a5ec3e36SAlex Bennéedocker-image-debian-sh4-cross: docker-image-debian-sid 85cc6c7365SAlex Bennéedocker-image-debian-sparc64-cross: docker-image-debian-sid 8633b2c4b5SAlex Bennéedocker-image-debian-mips64-cross: docker-image-debian-sid 87e100a967SAlex Bennéedocker-image-debian-riscv64-cross: docker-image-debian-sid 8808f56d8cSAlex Bennéedocker-image-debian-powerpc-cross: docker-image-debian-sid 891fddbf7cSAlex Bennéedocker-image-travis: NOUSER=1 9024e0131fSAlex Bennée 9136dc5fedSPhilippe Mathieu-Daudé# Specialist build images, sometimes very limited tools 9236dc5fedSPhilippe Mathieu-Daudédocker-image-tricore-cross: docker-image-debian9 9336dc5fedSPhilippe Mathieu-Daudé 94324027c2SFam Zheng# Expand all the pre-requistes for each docker image and test combination 95bcaf4577SPhilippe Mathieu-Daudé$(foreach i,$(DOCKER_IMAGES) $(DOCKER_DEPRECATED_IMAGES), \ 96324027c2SFam Zheng $(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \ 97324027c2SFam Zheng $(eval .PHONY: docker-$t@$i) \ 98324027c2SFam Zheng $(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \ 99324027c2SFam Zheng ) \ 100324027c2SFam Zheng $(foreach t,$(DOCKER_TESTS), \ 101324027c2SFam Zheng $(eval docker-test: docker-$t@$i) \ 102324027c2SFam Zheng ) \ 103324027c2SFam Zheng) 104324027c2SFam Zheng 105324027c2SFam Zhengdocker: 106324027c2SFam Zheng @echo 'Build QEMU and run tests inside Docker containers' 107324027c2SFam Zheng @echo 108324027c2SFam Zheng @echo 'Available targets:' 109324027c2SFam Zheng @echo 110324027c2SFam Zheng @echo ' docker: Print this help.' 111324027c2SFam Zheng @echo ' docker-test: Run all image/test combinations.' 112324027c2SFam Zheng @echo ' docker-clean: Kill and remove residual docker testing containers.' 113324027c2SFam Zheng @echo ' docker-TEST@IMAGE: Run "TEST" in container "IMAGE".' 114324027c2SFam Zheng @echo ' Note: "TEST" is one of the listed test name,' 115324027c2SFam Zheng @echo ' or a script name under $$QEMU_SRC/tests/docker/;' 116324027c2SFam Zheng @echo ' "IMAGE" is one of the listed container name."' 117324027c2SFam Zheng @echo ' docker-image: Build all images.' 118324027c2SFam Zheng @echo ' docker-image-IMAGE: Build image "IMAGE".' 119e86c9a64SAlex Bennée @echo ' docker-run: For manually running a "TEST" with "IMAGE"' 120324027c2SFam Zheng @echo 121324027c2SFam Zheng @echo 'Available container images:' 122324027c2SFam Zheng @echo ' $(DOCKER_IMAGES)' 123324027c2SFam Zheng @echo 124324027c2SFam Zheng @echo 'Available tests:' 125324027c2SFam Zheng @echo ' $(DOCKER_TESTS)' 126324027c2SFam Zheng @echo 127324027c2SFam Zheng @echo 'Available tools:' 128324027c2SFam Zheng @echo ' $(DOCKER_TOOLS)' 129324027c2SFam Zheng @echo 130324027c2SFam Zheng @echo 'Special variables:' 131324027c2SFam Zheng @echo ' TARGET_LIST=a,b,c Override target list in builds.' 13235e0f959SFam Zheng @echo ' EXTRA_CONFIGURE_OPTS="..."' 13335e0f959SFam Zheng @echo ' Extra configure options.' 134324027c2SFam Zheng @echo ' IMAGES="a b c ..": Filters which images to build or run.' 135324027c2SFam Zheng @echo ' TESTS="x y z .." Filters which tests to run (for docker-test).' 136324027c2SFam Zheng @echo ' J=[0..9]* Overrides the -jN parameter for make commands' 137324027c2SFam Zheng @echo ' (default is 1)' 138324027c2SFam Zheng @echo ' DEBUG=1 Stop and drop to shell in the created container' 139324027c2SFam Zheng @echo ' before running the command.' 1408a2390a4SDaniel P. Berrange @echo ' NETWORK=1 Enable virtual network interface with default backend.' 1416423795eSPhilippe Mathieu-Daudé @echo ' NETWORK=$$BACKEND Enable virtual network interface with $$BACKEND.' 142414a8ce5SAlex Bennée @echo ' NOUSER Define to disable adding current user to containers passwd.' 143324027c2SFam Zheng @echo ' NOCACHE=1 Ignore cache when build images.' 144b7c851b2SAlex Bennée @echo ' EXECUTABLE=<path> Include executable in image.' 1454c84f662SPhilippe Mathieu-Daudé @echo ' EXTRA_FILES="<path> [... <path>]"' 1464c84f662SPhilippe Mathieu-Daudé @echo ' Include extra files in image.' 147324027c2SFam Zheng 148e86c9a64SAlex Bennée# This rule if for directly running against an arbitrary docker target. 149e86c9a64SAlex Bennée# It is called by the expanded docker targets (e.g. make 150e86c9a64SAlex Bennée# docker-test-foo@bar) which will do additional verification. 151e86c9a64SAlex Bennée# 152e86c9a64SAlex Bennée# For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64 153e86c9a64SAlex Bennée# 154e86c9a64SAlex Bennéedocker-run: docker-qemu-src 155324027c2SFam Zheng @mkdir -p "$(DOCKER_CCACHE_DIR)" 156e86c9a64SAlex Bennée @if test -z "$(IMAGE)" || test -z "$(TEST)"; \ 157e86c9a64SAlex Bennée then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \ 158324027c2SFam Zheng fi 159e86c9a64SAlex Bennée $(if $(EXECUTABLE), \ 160324027c2SFam Zheng $(call quiet-command, \ 161e27cae26SAlex Bennée $(DOCKER_SCRIPT) update \ 162e86c9a64SAlex Bennée $(IMAGE) $(EXECUTABLE), \ 163e86c9a64SAlex Bennée " COPYING $(EXECUTABLE) to $(IMAGE)")) 164e86c9a64SAlex Bennée $(call quiet-command, \ 165e27cae26SAlex Bennée $(DOCKER_SCRIPT) run \ 1664b2c6bc5SFam Zheng $(if $(NOUSER),,-u $(shell id -u)) \ 16744707491SFam Zheng --security-opt seccomp=unconfined \ 168e86c9a64SAlex Bennée $(if $V,,--rm) \ 1694b2c6bc5SFam Zheng $(if $(DEBUG),-ti,) \ 1708a2390a4SDaniel P. Berrange $(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \ 1715609c512SAlex Bennée -e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST)) \ 172e86c9a64SAlex Bennée -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \ 173e86c9a64SAlex Bennée -e V=$V -e J=$J -e DEBUG=$(DEBUG) \ 174e86c9a64SAlex Bennée -e SHOW_ENV=$(SHOW_ENV) \ 17536ac78e6SFam Zheng $(if $(NOUSER),, \ 176324027c2SFam Zheng -e CCACHE_DIR=/var/tmp/ccache \ 177324027c2SFam Zheng -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \ 17836ac78e6SFam Zheng ) \ 17936ac78e6SFam Zheng -v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \ 180e86c9a64SAlex Bennée $(IMAGE) \ 181c8158513SFam Zheng /var/tmp/qemu/run \ 182e86c9a64SAlex Bennée $(TEST), " RUN $(TEST) in ${IMAGE}") 18308c3f6d5SPeter Xu $(call quiet-command, rm -r $(DOCKER_SRC_COPY), \ 18408c3f6d5SPeter Xu " CLEANUP $(DOCKER_SRC_COPY)") 185e86c9a64SAlex Bennée 186e86c9a64SAlex Bennée# Run targets: 187e86c9a64SAlex Bennée# 188e86c9a64SAlex Bennée# Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run" 189e86c9a64SAlex Bennéedocker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/') 190e86c9a64SAlex Bennéedocker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/') 191e86c9a64SAlex Bennéedocker-run-%: 192e86c9a64SAlex Bennée @$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu:$(IMAGE) 193324027c2SFam Zheng 194324027c2SFam Zhengdocker-clean: 195e27cae26SAlex Bennée $(call quiet-command, $(DOCKER_SCRIPT) clean) 196