Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 1 | # Makefile for Docker tests |
| 2 | |
| 3 | .PHONY: docker docker-test docker-clean docker-image docker-qemu-src |
| 4 | |
| 5 | DOCKER_SUFFIX := .docker |
| 6 | DOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles |
Philippe Mathieu-Daudé | bcaf457 | 2018-01-15 11:34:53 -0300 | [diff] [blame] | 7 | DOCKER_DEPRECATED_IMAGES := debian |
| 8 | DOCKER_IMAGES := $(filter-out $(DOCKER_DEPRECATED_IMAGES),$(sort $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker))))) |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 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 |
| 12 | |
| 13 | DOCKER_TESTS := $(notdir $(shell \ |
| 14 | find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f)) |
| 15 | |
| 16 | DOCKER_TOOLS := travis |
| 17 | |
| 18 | TESTS ?= % |
| 19 | IMAGES ?= % |
| 20 | |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 21 | CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$) |
Paolo Bonzini | bc739b8 | 2017-10-18 15:06:29 +0200 | [diff] [blame] | 22 | DOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME) |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 23 | |
| 24 | $(DOCKER_SRC_COPY): |
| 25 | @mkdir $@ |
Paolo Bonzini | bc739b8 | 2017-10-18 15:06:29 +0200 | [diff] [blame] | 26 | $(call quiet-command, cd $(SRC_PATH) && scripts/archive-source.sh $@/qemu.tar, \ |
Fam Zheng | b7f4042 | 2017-09-05 10:12:01 +0800 | [diff] [blame] | 27 | "GEN", "$@/qemu.tar") |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 28 | $(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \ |
Peter Maydell | 0bdb12c | 2016-10-04 17:27:21 +0100 | [diff] [blame] | 29 | "COPY","RUNNER") |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 30 | |
| 31 | docker-qemu-src: $(DOCKER_SRC_COPY) |
| 32 | |
| 33 | docker-image: ${DOCKER_TARGETS} |
| 34 | |
| 35 | # General rule for building docker images |
| 36 | docker-image-%: $(DOCKER_FILES_DIR)/%.docker |
Sascha Silbe | a351b4b | 2016-09-06 22:05:48 +0200 | [diff] [blame] | 37 | @if test "$@" = docker-image-debian-bootstrap -a -z "$(EXECUTABLE)"; then \ |
| 38 | echo WARNING: EXECUTABLE is not set, debootstrap may fail. 2>&1 ; \ |
| 39 | fi |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 40 | $(call quiet-command,\ |
| 41 | $(SRC_PATH)/tests/docker/docker.py build qemu:$* $< \ |
Alex Bennée | b7c851b | 2016-07-19 21:20:45 +0800 | [diff] [blame] | 42 | $(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \ |
Alex Bennée | 414a8ce | 2017-02-20 10:51:36 +0000 | [diff] [blame] | 43 | $(if $(NOUSER),,--add-current-user) \ |
Philippe Mathieu-Daudé | 4c84f66 | 2017-06-02 15:56:08 -0300 | [diff] [blame] | 44 | $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\ |
Alex Bennée | b7c851b | 2016-07-19 21:20:45 +0800 | [diff] [blame] | 45 | $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\ |
Peter Maydell | 0bdb12c | 2016-10-04 17:27:21 +0100 | [diff] [blame] | 46 | "BUILD","$*") |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 47 | |
Greg Kurz | 1dc1700 | 2017-10-19 13:40:42 +0200 | [diff] [blame] | 48 | docker-image-debian-powerpc-cross: EXTRA_FILES:=$(SRC_PATH)/tests/docker/dockerfiles/debian-apt-fake.sh |
Alex Bennée | 16dcece | 2017-07-17 21:31:51 -0300 | [diff] [blame] | 49 | |
Philippe Mathieu-Daudé | 9d5e546 | 2018-05-08 11:43:58 -0300 | [diff] [blame] | 50 | # Enforce dependencies for composite images |
Philippe Mathieu-Daudé | 3e11974 | 2017-07-17 23:47:12 -0300 | [diff] [blame] | 51 | docker-image-debian: docker-image-debian9 |
Philippe Mathieu-Daudé | 982e758 | 2017-07-17 23:47:09 -0300 | [diff] [blame] | 52 | docker-image-debian8-mxe: docker-image-debian8 |
Philippe Mathieu-Daudé | 1528804 | 2017-07-17 21:31:40 -0300 | [diff] [blame] | 53 | docker-image-debian-amd64: docker-image-debian9 |
Philippe Mathieu-Daudé | 31e205d | 2017-07-17 21:31:38 -0300 | [diff] [blame] | 54 | docker-image-debian-armel-cross: docker-image-debian9 |
Philippe Mathieu-Daudé | 24044d4 | 2017-07-17 21:31:33 -0300 | [diff] [blame] | 55 | docker-image-debian-armhf-cross: docker-image-debian9 |
| 56 | docker-image-debian-arm64-cross: docker-image-debian9 |
Philippe Mathieu-Daudé | 4319db7 | 2017-07-17 21:31:53 -0300 | [diff] [blame] | 57 | docker-image-debian-mips-cross: docker-image-debian9 |
Philippe Mathieu-Daudé | fd7b284 | 2017-07-17 21:31:55 -0300 | [diff] [blame] | 58 | docker-image-debian-mips64el-cross: docker-image-debian9 |
Alex Bennée | 16dcece | 2017-07-17 21:31:51 -0300 | [diff] [blame] | 59 | docker-image-debian-powerpc-cross: docker-image-debian8 |
Philippe Mathieu-Daudé | 2b1c10b | 2017-07-17 21:31:39 -0300 | [diff] [blame] | 60 | docker-image-debian-ppc64el-cross: docker-image-debian9 |
Philippe Mathieu-Daudé | 7d2bcf2 | 2017-07-17 21:31:35 -0300 | [diff] [blame] | 61 | docker-image-debian-s390x-cross: docker-image-debian9 |
Philippe Mathieu-Daudé | 982e758 | 2017-07-17 23:47:09 -0300 | [diff] [blame] | 62 | docker-image-debian-win32-cross: docker-image-debian8-mxe |
| 63 | docker-image-debian-win64-cross: docker-image-debian8-mxe |
Alex Bennée | 1fddbf7 | 2017-07-25 14:34:20 +0100 | [diff] [blame] | 64 | docker-image-travis: NOUSER=1 |
Alex Bennée | 24e0131 | 2017-02-20 10:51:37 +0000 | [diff] [blame] | 65 | |
Philippe Mathieu-Daudé | 36dc5fe | 2018-05-01 21:21:43 -0300 | [diff] [blame] | 66 | # Specialist build images, sometimes very limited tools |
| 67 | docker-image-tricore-cross: docker-image-debian9 |
| 68 | |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 69 | # Expand all the pre-requistes for each docker image and test combination |
Philippe Mathieu-Daudé | bcaf457 | 2018-01-15 11:34:53 -0300 | [diff] [blame] | 70 | $(foreach i,$(DOCKER_IMAGES) $(DOCKER_DEPRECATED_IMAGES), \ |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 71 | $(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \ |
| 72 | $(eval .PHONY: docker-$t@$i) \ |
| 73 | $(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \ |
| 74 | ) \ |
| 75 | $(foreach t,$(DOCKER_TESTS), \ |
| 76 | $(eval docker-test: docker-$t@$i) \ |
| 77 | ) \ |
| 78 | ) |
| 79 | |
| 80 | docker: |
| 81 | @echo 'Build QEMU and run tests inside Docker containers' |
| 82 | @echo |
| 83 | @echo 'Available targets:' |
| 84 | @echo |
| 85 | @echo ' docker: Print this help.' |
| 86 | @echo ' docker-test: Run all image/test combinations.' |
| 87 | @echo ' docker-clean: Kill and remove residual docker testing containers.' |
| 88 | @echo ' docker-TEST@IMAGE: Run "TEST" in container "IMAGE".' |
| 89 | @echo ' Note: "TEST" is one of the listed test name,' |
| 90 | @echo ' or a script name under $$QEMU_SRC/tests/docker/;' |
| 91 | @echo ' "IMAGE" is one of the listed container name."' |
| 92 | @echo ' docker-image: Build all images.' |
| 93 | @echo ' docker-image-IMAGE: Build image "IMAGE".' |
Alex Bennée | e86c9a6 | 2016-10-11 17:16:24 +0100 | [diff] [blame] | 94 | @echo ' docker-run: For manually running a "TEST" with "IMAGE"' |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 95 | @echo |
| 96 | @echo 'Available container images:' |
| 97 | @echo ' $(DOCKER_IMAGES)' |
| 98 | @echo |
| 99 | @echo 'Available tests:' |
| 100 | @echo ' $(DOCKER_TESTS)' |
| 101 | @echo |
| 102 | @echo 'Available tools:' |
| 103 | @echo ' $(DOCKER_TOOLS)' |
| 104 | @echo |
| 105 | @echo 'Special variables:' |
| 106 | @echo ' TARGET_LIST=a,b,c Override target list in builds.' |
Fam Zheng | 35e0f95 | 2016-06-01 12:25:27 +0800 | [diff] [blame] | 107 | @echo ' EXTRA_CONFIGURE_OPTS="..."' |
| 108 | @echo ' Extra configure options.' |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 109 | @echo ' IMAGES="a b c ..": Filters which images to build or run.' |
| 110 | @echo ' TESTS="x y z .." Filters which tests to run (for docker-test).' |
| 111 | @echo ' J=[0..9]* Overrides the -jN parameter for make commands' |
| 112 | @echo ' (default is 1)' |
| 113 | @echo ' DEBUG=1 Stop and drop to shell in the created container' |
| 114 | @echo ' before running the command.' |
Daniel P. Berrange | 8a2390a | 2017-07-13 15:43:52 +0100 | [diff] [blame] | 115 | @echo ' NETWORK=1 Enable virtual network interface with default backend.' |
Philippe Mathieu-Daudé | 6423795 | 2017-11-07 23:47:19 -0300 | [diff] [blame] | 116 | @echo ' NETWORK=$$BACKEND Enable virtual network interface with $$BACKEND.' |
Alex Bennée | 414a8ce | 2017-02-20 10:51:36 +0000 | [diff] [blame] | 117 | @echo ' NOUSER Define to disable adding current user to containers passwd.' |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 118 | @echo ' NOCACHE=1 Ignore cache when build images.' |
Alex Bennée | b7c851b | 2016-07-19 21:20:45 +0800 | [diff] [blame] | 119 | @echo ' EXECUTABLE=<path> Include executable in image.' |
Philippe Mathieu-Daudé | 4c84f66 | 2017-06-02 15:56:08 -0300 | [diff] [blame] | 120 | @echo ' EXTRA_FILES="<path> [... <path>]"' |
| 121 | @echo ' Include extra files in image.' |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 122 | |
Alex Bennée | e86c9a6 | 2016-10-11 17:16:24 +0100 | [diff] [blame] | 123 | # This rule if for directly running against an arbitrary docker target. |
| 124 | # It is called by the expanded docker targets (e.g. make |
| 125 | # docker-test-foo@bar) which will do additional verification. |
| 126 | # |
| 127 | # For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64 |
| 128 | # |
| 129 | docker-run: docker-qemu-src |
| 130 | @mkdir -p "$(DOCKER_CCACHE_DIR)" |
| 131 | @if test -z "$(IMAGE)" || test -z "$(TEST)"; \ |
| 132 | then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \ |
| 133 | fi |
| 134 | $(if $(EXECUTABLE), \ |
| 135 | $(call quiet-command, \ |
| 136 | $(SRC_PATH)/tests/docker/docker.py update \ |
| 137 | $(IMAGE) $(EXECUTABLE), \ |
| 138 | " COPYING $(EXECUTABLE) to $(IMAGE)")) |
| 139 | $(call quiet-command, \ |
| 140 | $(SRC_PATH)/tests/docker/docker.py run \ |
Fam Zheng | 4b2c6bc | 2017-10-13 09:19:54 +0800 | [diff] [blame] | 141 | $(if $(NOUSER),,-u $(shell id -u)) \ |
Fam Zheng | 4470749 | 2017-09-05 10:56:11 +0800 | [diff] [blame] | 142 | --security-opt seccomp=unconfined \ |
Alex Bennée | e86c9a6 | 2016-10-11 17:16:24 +0100 | [diff] [blame] | 143 | $(if $V,,--rm) \ |
Fam Zheng | 4b2c6bc | 2017-10-13 09:19:54 +0800 | [diff] [blame] | 144 | $(if $(DEBUG),-ti,) \ |
Daniel P. Berrange | 8a2390a | 2017-07-13 15:43:52 +0100 | [diff] [blame] | 145 | $(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \ |
Alex Bennée | 5609c51 | 2018-05-21 11:35:04 +0100 | [diff] [blame] | 146 | -e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST)) \ |
Alex Bennée | e86c9a6 | 2016-10-11 17:16:24 +0100 | [diff] [blame] | 147 | -e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \ |
| 148 | -e V=$V -e J=$J -e DEBUG=$(DEBUG) \ |
| 149 | -e SHOW_ENV=$(SHOW_ENV) \ |
Fam Zheng | 36ac78e | 2017-09-25 15:54:58 +0800 | [diff] [blame] | 150 | $(if $(NOUSER),, \ |
| 151 | -e CCACHE_DIR=/var/tmp/ccache \ |
| 152 | -v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z \ |
| 153 | ) \ |
Alex Bennée | e86c9a6 | 2016-10-11 17:16:24 +0100 | [diff] [blame] | 154 | -v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \ |
Alex Bennée | e86c9a6 | 2016-10-11 17:16:24 +0100 | [diff] [blame] | 155 | $(IMAGE) \ |
| 156 | /var/tmp/qemu/run \ |
| 157 | $(TEST), " RUN $(TEST) in ${IMAGE}") |
Peter Xu | 08c3f6d | 2017-10-17 15:12:46 +0800 | [diff] [blame] | 158 | $(call quiet-command, rm -r $(DOCKER_SRC_COPY), \ |
| 159 | " CLEANUP $(DOCKER_SRC_COPY)") |
Alex Bennée | e86c9a6 | 2016-10-11 17:16:24 +0100 | [diff] [blame] | 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" |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 164 | docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/') |
| 165 | docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/') |
Alex Bennée | e86c9a6 | 2016-10-11 17:16:24 +0100 | [diff] [blame] | 166 | docker-run-%: |
| 167 | @$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu:$(IMAGE) |
Fam Zheng | 324027c | 2016-06-01 12:25:17 +0800 | [diff] [blame] | 168 | |
| 169 | docker-clean: |
| 170 | $(call quiet-command, $(SRC_PATH)/tests/docker/docker.py clean) |