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_IMAGES := $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker)))
8 DOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES))
9 # Use a global constant ccache directory to speed up repetitive builds
10 DOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
12 DOCKER_TESTS := $(notdir $(shell \
13 find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
15 DOCKER_TOOLS := travis
20 # Make archive from git repo $1 to tar.gz $2
21 make-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; \
26 git archive -1 $$(git stash create) --format=tar.gz; \
28 "ARCHIVE","$(notdir $2)"))
30 CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
31 DOCKER_SRC_COPY := docker-src.$(CUR_TIME)
35 $(call make-archive-maybe, $(SRC_PATH), $@/qemu.tgz)
36 $(call make-archive-maybe, $(SRC_PATH)/dtc, $@/dtc.tgz)
37 $(call make-archive-maybe, $(SRC_PATH)/pixman, $@/pixman.tgz)
38 $(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \
41 docker-qemu-src: $(DOCKER_SRC_COPY)
43 docker-image: ${DOCKER_TARGETS}
45 # General rule for building docker images
46 docker-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 ; \
50 $(call quiet-command,\
51 $(SRC_PATH)/tests/docker/docker.py 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)),\
58 docker-image-debian-powerpc-cross: EXTRA_FILES:=tests/docker/dockerfiles/debian-apt-fake.sh
60 # Enforce dependancies for composite images
61 docker-image-debian: docker-image-debian9
62 docker-image-debian8-mxe: docker-image-debian8
63 docker-image-debian-amd64: docker-image-debian9
64 docker-image-debian-armel-cross: docker-image-debian9
65 docker-image-debian-armhf-cross: docker-image-debian9
66 docker-image-debian-arm64-cross: docker-image-debian9
67 docker-image-debian-mips-cross: docker-image-debian9
68 docker-image-debian-mips64el-cross: docker-image-debian9
69 docker-image-debian-powerpc-cross: docker-image-debian8
70 docker-image-debian-ppc64el-cross: docker-image-debian9
71 docker-image-debian-s390x-cross: docker-image-debian9
72 docker-image-debian-win32-cross: docker-image-debian8-mxe
73 docker-image-debian-win64-cross: docker-image-debian8-mxe
75 # Expand all the pre-requistes for each docker image and test combination
76 $(foreach i,$(DOCKER_IMAGES), \
77 $(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
78 $(eval .PHONY: docker-$t@$i) \
79 $(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
81 $(foreach t,$(DOCKER_TESTS), \
82 $(eval docker-test: docker-$t@$i) \
87 @echo 'Build QEMU and run tests inside Docker containers'
89 @echo 'Available targets:'
91 @echo ' docker: Print this help.'
92 @echo ' docker-test: Run all image/test combinations.'
93 @echo ' docker-clean: Kill and remove residual docker testing containers.'
94 @echo ' docker-TEST@IMAGE: Run "TEST" in container "IMAGE".'
95 @echo ' Note: "TEST" is one of the listed test name,'
96 @echo ' or a script name under $$QEMU_SRC/tests/docker/;'
97 @echo ' "IMAGE" is one of the listed container name."'
98 @echo ' docker-image: Build all images.'
99 @echo ' docker-image-IMAGE: Build image "IMAGE".'
100 @echo ' docker-run: For manually running a "TEST" with "IMAGE"'
102 @echo 'Available container images:'
103 @echo ' $(DOCKER_IMAGES)'
105 @echo 'Available tests:'
106 @echo ' $(DOCKER_TESTS)'
108 @echo 'Available tools:'
109 @echo ' $(DOCKER_TOOLS)'
111 @echo 'Special variables:'
112 @echo ' TARGET_LIST=a,b,c Override target list in builds.'
113 @echo ' EXTRA_CONFIGURE_OPTS="..."'
114 @echo ' Extra configure options.'
115 @echo ' IMAGES="a b c ..": Filters which images to build or run.'
116 @echo ' TESTS="x y z .." Filters which tests to run (for docker-test).'
117 @echo ' J=[0..9]* Overrides the -jN parameter for make commands'
118 @echo ' (default is 1)'
119 @echo ' DEBUG=1 Stop and drop to shell in the created container'
120 @echo ' before running the command.'
121 @echo ' NETWORK=1 Enable virtual network interface with default backend.'
122 @echo ' NETWORK=$BACKEND Enable virtual network interface with $BACKEND.'
123 @echo ' NOUSER Define to disable adding current user to containers passwd.'
124 @echo ' NOCACHE=1 Ignore cache when build images.'
125 @echo ' EXECUTABLE=<path> Include executable in image.'
126 @echo ' EXTRA_FILES="<path> [... <path>]"'
127 @echo ' Include extra files in image.'
129 # This rule if for directly running against an arbitrary docker target.
130 # It is called by the expanded docker targets (e.g. make
131 # docker-test-foo@bar) which will do additional verification.
133 # For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
135 docker-run: docker-qemu-src
136 @mkdir -p "$(DOCKER_CCACHE_DIR)"
137 @if test -z "$(IMAGE)" || test -z "$(TEST)"; \
138 then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
140 $(if $(EXECUTABLE), \
141 $(call quiet-command, \
142 $(SRC_PATH)/tests/docker/docker.py update \
143 $(IMAGE) $(EXECUTABLE), \
144 " COPYING $(EXECUTABLE) to $(IMAGE)"))
145 $(call quiet-command, \
146 $(SRC_PATH)/tests/docker/docker.py run \
147 $(if $(NOUSER),,-u $(shell id -u)) -t \
150 $(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \
151 -e TARGET_LIST=$(TARGET_LIST) \
152 -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
153 -e V=$V -e J=$J -e DEBUG=$(DEBUG) \
154 -e SHOW_ENV=$(SHOW_ENV) \
155 -e CCACHE_DIR=/var/tmp/ccache \
156 -v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
157 -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \
160 $(TEST), " RUN $(TEST) in ${IMAGE}")
164 # Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run"
165 docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
166 docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
168 @$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu:$(IMAGE)
171 $(call quiet-command, $(SRC_PATH)/tests/docker/docker.py clean)