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_IMAGES := $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker))) 8DOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES)) 9# Use a global constant ccache directory to speed up repetitive builds 10DOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache 11 12DOCKER_TESTS := $(notdir $(shell \ 13 find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f)) 14 15DOCKER_TOOLS := travis 16 17TESTS ?= % 18IMAGES ?= % 19 20# Make archive from git repo $1 to tar.gz $2 21make-archive-maybe = $(if $(wildcard $1/*), \ 22 $(call quiet-command, \ 23 (cd $1; if git diff-index --quiet HEAD -- &>/dev/null; then \ 24 git archive -1 HEAD --format=tar.gz; \ 25 else \ 26 git archive -1 $$(git stash create) --format=tar.gz; \ 27 fi) > $2, \ 28 "ARCHIVE","$(notdir $2)")) 29 30CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$) 31DOCKER_SRC_COPY := docker-src.$(CUR_TIME) 32 33$(DOCKER_SRC_COPY): 34 @mkdir $@ 35 $(call make-archive-maybe, $(SRC_PATH), $@/qemu.tgz) 36 $(call make-archive-maybe, $(SRC_PATH)/dtc, $@/dtc.tgz) 37 $(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \ 38 "COPY","RUNNER") 39 40docker-qemu-src: $(DOCKER_SRC_COPY) 41 42docker-image: ${DOCKER_TARGETS} 43 44# General rule for building docker images 45docker-image-%: $(DOCKER_FILES_DIR)/%.docker 46 @if test "$@" = docker-image-debian-bootstrap -a -z "$(EXECUTABLE)"; then \ 47 echo WARNING: EXECUTABLE is not set, debootstrap may fail. 2>&1 ; \ 48 fi 49 $(call quiet-command,\ 50 $(SRC_PATH)/tests/docker/docker.py build qemu:$* $< \ 51 $(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \ 52 $(if $(NOUSER),,--add-current-user) \ 53 $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\ 54 $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\ 55 "BUILD","$*") 56 57docker-image-debian-powerpc-cross: EXTRA_FILES:=tests/docker/dockerfiles/debian-apt-fake.sh 58 59# Enforce dependancies 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-mips64el-cross: docker-image-debian9 68docker-image-debian-powerpc-cross: docker-image-debian8 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# Expand all the pre-requistes for each docker image and test combination 75$(foreach i,$(DOCKER_IMAGES), \ 76 $(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \ 77 $(eval .PHONY: docker-$t@$i) \ 78 $(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \ 79 ) \ 80 $(foreach t,$(DOCKER_TESTS), \ 81 $(eval docker-test: docker-$t@$i) \ 82 ) \ 83) 84 85docker: 86 @echo 'Build QEMU and run tests inside Docker containers' 87 @echo 88 @echo 'Available targets:' 89 @echo 90 @echo ' docker: Print this help.' 91 @echo ' docker-test: Run all image/test combinations.' 92 @echo ' docker-clean: Kill and remove residual docker testing containers.' 93 @echo ' docker-TEST@IMAGE: Run "TEST" in container "IMAGE".' 94 @echo ' Note: "TEST" is one of the listed test name,' 95 @echo ' or a script name under $$QEMU_SRC/tests/docker/;' 96 @echo ' "IMAGE" is one of the listed container name."' 97 @echo ' docker-image: Build all images.' 98 @echo ' docker-image-IMAGE: Build image "IMAGE".' 99 @echo ' docker-run: For manually running a "TEST" with "IMAGE"' 100 @echo 101 @echo 'Available container images:' 102 @echo ' $(DOCKER_IMAGES)' 103 @echo 104 @echo 'Available tests:' 105 @echo ' $(DOCKER_TESTS)' 106 @echo 107 @echo 'Available tools:' 108 @echo ' $(DOCKER_TOOLS)' 109 @echo 110 @echo 'Special variables:' 111 @echo ' TARGET_LIST=a,b,c Override target list in builds.' 112 @echo ' EXTRA_CONFIGURE_OPTS="..."' 113 @echo ' Extra configure options.' 114 @echo ' IMAGES="a b c ..": Filters which images to build or run.' 115 @echo ' TESTS="x y z .." Filters which tests to run (for docker-test).' 116 @echo ' J=[0..9]* Overrides the -jN parameter for make commands' 117 @echo ' (default is 1)' 118 @echo ' DEBUG=1 Stop and drop to shell in the created container' 119 @echo ' before running the command.' 120 @echo ' NETWORK=1 Enable virtual network interface with default backend.' 121 @echo ' NETWORK=$BACKEND Enable virtual network interface with $BACKEND.' 122 @echo ' NOUSER Define to disable adding current user to containers passwd.' 123 @echo ' NOCACHE=1 Ignore cache when build images.' 124 @echo ' EXECUTABLE=<path> Include executable in image.' 125 @echo ' EXTRA_FILES="<path> [... <path>]"' 126 @echo ' Include extra files in image.' 127 128# This rule if for directly running against an arbitrary docker target. 129# It is called by the expanded docker targets (e.g. make 130# docker-test-foo@bar) which will do additional verification. 131# 132# For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64 133# 134docker-run: docker-qemu-src 135 @mkdir -p "$(DOCKER_CCACHE_DIR)" 136 @if test -z "$(IMAGE)" || test -z "$(TEST)"; \ 137 then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \ 138 fi 139 $(if $(EXECUTABLE), \ 140 $(call quiet-command, \ 141 $(SRC_PATH)/tests/docker/docker.py update \ 142 $(IMAGE) $(EXECUTABLE), \ 143 " COPYING $(EXECUTABLE) to $(IMAGE)")) 144 $(call quiet-command, \ 145 $(SRC_PATH)/tests/docker/docker.py run \ 146 $(if $(NOUSER),,-u $(shell id -u)) -t \ 147 $(if $V,,--rm) \ 148 $(if $(DEBUG),-i,) \ 149 $(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \ 150 -e TARGET_LIST=$(TARGET_LIST) \ 151 -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \ 152 -e V=$V -e J=$J -e DEBUG=$(DEBUG) \ 153 -e SHOW_ENV=$(SHOW_ENV) \ 154 -e CCACHE_DIR=/var/tmp/ccache \ 155 -v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \ 156 -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \ 157 $(IMAGE) \ 158 /var/tmp/qemu/run \ 159 $(TEST), " RUN $(TEST) in ${IMAGE}") 160 161# Run targets: 162# 163# Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run" 164docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/') 165docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/') 166docker-run-%: 167 @$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu:$(IMAGE) 168 169docker-clean: 170 $(call quiet-command, $(SRC_PATH)/tests/docker/docker.py clean) 171