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