xref: /openbmc/qemu/tests/docker/Makefile.include (revision 7d2bcf23)
1324027c2SFam Zheng# Makefile for Docker tests
2324027c2SFam Zheng
3324027c2SFam Zheng.PHONY: docker docker-test docker-clean docker-image docker-qemu-src
4324027c2SFam Zheng
5324027c2SFam ZhengDOCKER_SUFFIX := .docker
6324027c2SFam ZhengDOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles
7324027c2SFam ZhengDOCKER_IMAGES := $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker)))
8324027c2SFam ZhengDOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES))
9324027c2SFam Zheng# Use a global constant ccache directory to speed up repetitive builds
10324027c2SFam ZhengDOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
11324027c2SFam Zheng
12324027c2SFam ZhengDOCKER_TESTS := $(notdir $(shell \
13324027c2SFam Zheng	find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
14324027c2SFam Zheng
15324027c2SFam ZhengDOCKER_TOOLS := travis
16324027c2SFam Zheng
17324027c2SFam ZhengTESTS ?= %
18324027c2SFam ZhengIMAGES ?= %
19324027c2SFam Zheng
20324027c2SFam Zheng# Make archive from git repo $1 to tar.gz $2
21324027c2SFam Zhengmake-archive-maybe = $(if $(wildcard $1/*), \
22324027c2SFam Zheng	$(call quiet-command, \
23324027c2SFam Zheng		(cd $1; if git diff-index --quiet HEAD -- &>/dev/null; then \
2434c98c54SPaolo Bonzini			git archive -1 HEAD --format=tar.gz; \
25324027c2SFam Zheng		else \
2634c98c54SPaolo Bonzini			git archive -1 $$(git stash create) --format=tar.gz; \
2734c98c54SPaolo Bonzini		fi) > $2, \
280bdb12c7SPeter Maydell		"ARCHIVE","$(notdir $2)"))
29324027c2SFam Zheng
30324027c2SFam ZhengCUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
31d5aebef8SEduardo HabkostDOCKER_SRC_COPY := docker-src.$(CUR_TIME)
32324027c2SFam Zheng
33324027c2SFam Zheng$(DOCKER_SRC_COPY):
34324027c2SFam Zheng	@mkdir $@
35324027c2SFam Zheng	$(call make-archive-maybe, $(SRC_PATH), $@/qemu.tgz)
36324027c2SFam Zheng	$(call make-archive-maybe, $(SRC_PATH)/dtc, $@/dtc.tgz)
37324027c2SFam Zheng	$(call make-archive-maybe, $(SRC_PATH)/pixman, $@/pixman.tgz)
38324027c2SFam Zheng	$(call quiet-command, cp $(SRC_PATH)/tests/docker/run $@/run, \
390bdb12c7SPeter Maydell		"COPY","RUNNER")
40324027c2SFam Zheng
41324027c2SFam Zhengdocker-qemu-src: $(DOCKER_SRC_COPY)
42324027c2SFam Zheng
43324027c2SFam Zhengdocker-image: ${DOCKER_TARGETS}
44324027c2SFam Zheng
45324027c2SFam Zheng# General rule for building docker images
46324027c2SFam Zhengdocker-image-%: $(DOCKER_FILES_DIR)/%.docker
47a351b4b0SSascha Silbe	@if test "$@" = docker-image-debian-bootstrap -a -z "$(EXECUTABLE)"; then \
48a351b4b0SSascha Silbe		echo WARNING: EXECUTABLE is not set, debootstrap may fail. 2>&1 ; \
49a351b4b0SSascha Silbe	fi
50324027c2SFam Zheng	$(call quiet-command,\
51324027c2SFam Zheng		$(SRC_PATH)/tests/docker/docker.py build qemu:$* $< \
52b7c851b2SAlex Bennée		$(if $V,,--quiet) $(if $(NOCACHE),--no-cache) \
53414a8ce5SAlex Bennée		$(if $(NOUSER),,--add-current-user) \
544c84f662SPhilippe Mathieu-Daudé		$(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\
55b7c851b2SAlex Bennée		$(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\
560bdb12c7SPeter Maydell		"BUILD","$*")
57324027c2SFam Zheng
5824e0131fSAlex Bennée# Enforce dependancies for composite images
5924044d48SPhilippe Mathieu-Daudédocker-image-debian-armhf-cross: docker-image-debian9
6024044d48SPhilippe Mathieu-Daudédocker-image-debian-arm64-cross: docker-image-debian9
6124044d48SPhilippe Mathieu-Daudédocker-image-debian-mipsel-cross: docker-image-debian9
62*7d2bcf23SPhilippe Mathieu-Daudédocker-image-debian-s390x-cross: docker-image-debian9
6324e0131fSAlex Bennée
64324027c2SFam Zheng# Expand all the pre-requistes for each docker image and test combination
65324027c2SFam Zheng$(foreach i,$(DOCKER_IMAGES), \
66324027c2SFam Zheng	$(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
67324027c2SFam Zheng		$(eval .PHONY: docker-$t@$i) \
68324027c2SFam Zheng		$(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
69324027c2SFam Zheng	) \
70324027c2SFam Zheng	$(foreach t,$(DOCKER_TESTS), \
71324027c2SFam Zheng		$(eval docker-test: docker-$t@$i) \
72324027c2SFam Zheng	) \
73324027c2SFam Zheng)
74324027c2SFam Zheng
75324027c2SFam Zhengdocker:
76324027c2SFam Zheng	@echo 'Build QEMU and run tests inside Docker containers'
77324027c2SFam Zheng	@echo
78324027c2SFam Zheng	@echo 'Available targets:'
79324027c2SFam Zheng	@echo
80324027c2SFam Zheng	@echo '    docker:              Print this help.'
81324027c2SFam Zheng	@echo '    docker-test:         Run all image/test combinations.'
82324027c2SFam Zheng	@echo '    docker-clean:        Kill and remove residual docker testing containers.'
83324027c2SFam Zheng	@echo '    docker-TEST@IMAGE:   Run "TEST" in container "IMAGE".'
84324027c2SFam Zheng	@echo '                         Note: "TEST" is one of the listed test name,'
85324027c2SFam Zheng	@echo '                         or a script name under $$QEMU_SRC/tests/docker/;'
86324027c2SFam Zheng	@echo '                         "IMAGE" is one of the listed container name."'
87324027c2SFam Zheng	@echo '    docker-image:        Build all images.'
88324027c2SFam Zheng	@echo '    docker-image-IMAGE:  Build image "IMAGE".'
89e86c9a64SAlex Bennée	@echo '    docker-run:          For manually running a "TEST" with "IMAGE"'
90324027c2SFam Zheng	@echo
91324027c2SFam Zheng	@echo 'Available container images:'
92324027c2SFam Zheng	@echo '    $(DOCKER_IMAGES)'
93324027c2SFam Zheng	@echo
94324027c2SFam Zheng	@echo 'Available tests:'
95324027c2SFam Zheng	@echo '    $(DOCKER_TESTS)'
96324027c2SFam Zheng	@echo
97324027c2SFam Zheng	@echo 'Available tools:'
98324027c2SFam Zheng	@echo '    $(DOCKER_TOOLS)'
99324027c2SFam Zheng	@echo
100324027c2SFam Zheng	@echo 'Special variables:'
101324027c2SFam Zheng	@echo '    TARGET_LIST=a,b,c    Override target list in builds.'
10235e0f959SFam Zheng	@echo '    EXTRA_CONFIGURE_OPTS="..."'
10335e0f959SFam Zheng	@echo '                         Extra configure options.'
104324027c2SFam Zheng	@echo '    IMAGES="a b c ..":   Filters which images to build or run.'
105324027c2SFam Zheng	@echo '    TESTS="x y z .."     Filters which tests to run (for docker-test).'
106324027c2SFam Zheng	@echo '    J=[0..9]*            Overrides the -jN parameter for make commands'
107324027c2SFam Zheng	@echo '                         (default is 1)'
108324027c2SFam Zheng	@echo '    DEBUG=1              Stop and drop to shell in the created container'
109324027c2SFam Zheng	@echo '                         before running the command.'
1108a2390a4SDaniel P. Berrange	@echo '    NETWORK=1            Enable virtual network interface with default backend.'
1118a2390a4SDaniel P. Berrange	@echo '    NETWORK=$BACKEND     Enable virtual network interface with $BACKEND.'
112414a8ce5SAlex Bennée	@echo '    NOUSER               Define to disable adding current user to containers passwd.'
113324027c2SFam Zheng	@echo '    NOCACHE=1            Ignore cache when build images.'
114b7c851b2SAlex Bennée	@echo '    EXECUTABLE=<path>    Include executable in image.'
1154c84f662SPhilippe Mathieu-Daudé	@echo '    EXTRA_FILES="<path> [... <path>]"'
1164c84f662SPhilippe Mathieu-Daudé	@echo '                         Include extra files in image.'
117324027c2SFam Zheng
118e86c9a64SAlex Bennée# This rule if for directly running against an arbitrary docker target.
119e86c9a64SAlex Bennée# It is called by the expanded docker targets (e.g. make
120e86c9a64SAlex Bennée# docker-test-foo@bar) which will do additional verification.
121e86c9a64SAlex Bennée#
122e86c9a64SAlex Bennée# For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
123e86c9a64SAlex Bennée#
124e86c9a64SAlex Bennéedocker-run: docker-qemu-src
125324027c2SFam Zheng	@mkdir -p "$(DOCKER_CCACHE_DIR)"
126e86c9a64SAlex Bennée	@if test -z "$(IMAGE)" || test -z "$(TEST)"; \
127e86c9a64SAlex Bennée		then echo "Invalid target $(IMAGE)/$(TEST)"; exit 1; \
128324027c2SFam Zheng	fi
129e86c9a64SAlex Bennée	$(if $(EXECUTABLE),						\
130324027c2SFam Zheng		$(call quiet-command,					\
131e86c9a64SAlex Bennée			$(SRC_PATH)/tests/docker/docker.py update 	\
132e86c9a64SAlex Bennée			$(IMAGE) $(EXECUTABLE),				\
133e86c9a64SAlex Bennée			"  COPYING $(EXECUTABLE) to $(IMAGE)"))
134e86c9a64SAlex Bennée	$(call quiet-command,						\
135e86c9a64SAlex Bennée		$(SRC_PATH)/tests/docker/docker.py run 			\
136f9f65a4aSFam Zheng			$(if $(NOUSER),,-u $(shell id -u)) -t 		\
137e86c9a64SAlex Bennée			$(if $V,,--rm) 					\
1388a2390a4SDaniel P. Berrange			$(if $(DEBUG),-i,)				\
1398a2390a4SDaniel P. Berrange			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \
140324027c2SFam Zheng			-e TARGET_LIST=$(TARGET_LIST) 			\
141e86c9a64SAlex Bennée			-e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
142e86c9a64SAlex Bennée			-e V=$V -e J=$J -e DEBUG=$(DEBUG)		\
143e86c9a64SAlex Bennée			-e SHOW_ENV=$(SHOW_ENV) 			\
144324027c2SFam Zheng			-e CCACHE_DIR=/var/tmp/ccache 			\
14508f4e8d2SSascha Silbe			-v $$(readlink -e $(DOCKER_SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
146324027c2SFam Zheng			-v $(DOCKER_CCACHE_DIR):/var/tmp/ccache:z 	\
147e86c9a64SAlex Bennée			$(IMAGE) 					\
148c8158513SFam Zheng			/var/tmp/qemu/run 				\
149e86c9a64SAlex Bennée			$(TEST), "  RUN $(TEST) in ${IMAGE}")
150e86c9a64SAlex Bennée
151e86c9a64SAlex Bennée# Run targets:
152e86c9a64SAlex Bennée#
153e86c9a64SAlex Bennée# Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run"
154e86c9a64SAlex Bennéedocker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
155e86c9a64SAlex Bennéedocker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
156e86c9a64SAlex Bennéedocker-run-%:
157e86c9a64SAlex Bennée	@$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu:$(IMAGE)
158324027c2SFam Zheng
159324027c2SFam Zhengdocker-clean:
160324027c2SFam Zheng	$(call quiet-command, $(SRC_PATH)/tests/docker/docker.py clean)
161