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