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