aboutsummaryrefslogtreecommitdiff
path: root/tests/docker/Makefile.include
diff options
context:
space:
mode:
Diffstat (limited to 'tests/docker/Makefile.include')
-rw-r--r--tests/docker/Makefile.include203
1 files changed, 66 insertions, 137 deletions
diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
index ff5d732889..8df50a0ca0 100644
--- a/tests/docker/Makefile.include
+++ b/tests/docker/Makefile.include
@@ -6,30 +6,18 @@ NULL :=
SPACE := $(NULL) #
COMMA := ,
-HOST_ARCH = $(if $(ARCH),$(ARCH),$(shell uname -m))
+HOST_ARCH = $(shell uname -m)
+USER = $(if $(NOUSER),,$(shell id -un))
+UID = $(if $(NOUSER),,$(shell id -u))
-DOCKER_SUFFIX := .docker
DOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles
-# we don't run tests on intermediate images (used as base by another image)
-DOCKER_PARTIAL_IMAGES := debian10 debian11 debian-bootstrap empty
-DOCKER_IMAGES := $(sort $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker))))
-DOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES))
-# Use a global constant ccache directory to speed up repetitive builds
-DOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
ifeq ($(HOST_ARCH),x86_64)
DOCKER_DEFAULT_REGISTRY := registry.gitlab.com/qemu-project/qemu
endif
DOCKER_REGISTRY := $(if $(REGISTRY),$(REGISTRY),$(DOCKER_DEFAULT_REGISTRY))
-DOCKER_TESTS := $(notdir $(shell \
- find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
-
-ENGINE := auto
-
-DOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(ENGINE)
-
-TESTS ?= %
-IMAGES ?= %
+RUNC ?= $(if $(shell command -v docker), docker, podman)
+DOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(RUNC)
CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
DOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME)
@@ -47,27 +35,19 @@ $(DOCKER_SRC_COPY):
docker-qemu-src: $(DOCKER_SRC_COPY)
-docker-image: ${DOCKER_TARGETS}
-
-# General rule for building docker images. If we are a sub-make
-# invoked with SKIP_DOCKER_BUILD we still check the image is up to date
-# though
-ifdef SKIP_DOCKER_BUILD
-docker-image-%: $(DOCKER_FILES_DIR)/%.docker
- $(call quiet-command, \
- $(DOCKER_SCRIPT) check --quiet qemu/$* $<, \
- "CHECK", "$*")
-else
+# General rule for building docker images.
docker-image-%: $(DOCKER_FILES_DIR)/%.docker
- $(call quiet-command,\
- $(DOCKER_SCRIPT) build -t qemu/$* -f $< \
- $(if $V,,--quiet) \
- $(if $(NOCACHE),--no-cache, \
- $(if $(DOCKER_REGISTRY),--registry $(DOCKER_REGISTRY))) \
- $(if $(NOUSER),,--add-current-user) \
- $(if $(EXTRA_FILES),--extra-files $(EXTRA_FILES))\
- $(if $(EXECUTABLE),--include-executable=$(EXECUTABLE)),\
- "BUILD","$*")
+ $(call quiet-command, \
+ DOCKER_BUILDKIT=1 $(RUNC) build \
+ $(if $V,,--quiet) \
+ $(if $(NOCACHE),--no-cache, \
+ $(if $(DOCKER_REGISTRY),--cache-from $(DOCKER_REGISTRY)/qemu/$*)) \
+ --build-arg BUILDKIT_INLINE_CACHE=1 \
+ $(if $(NOUSER),, \
+ --build-arg USER=$(USER) \
+ --build-arg UID=$(UID)) \
+ -t qemu/$* - < $< $(if $V,,> /dev/null),\
+ "BUILD", $*)
# Special rule for debootstraped binfmt linux-user images
docker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker
@@ -93,110 +73,66 @@ docker-binfmt-image-debian-%: $(DOCKER_FILES_DIR)/debian-bootstrap.docker
{ echo "You will need to build $(EXECUTABLE)"; exit 1;},\
"CHECK", "debian-$* exists"))
-# These are test targets
-USER_TCG_TARGETS=$(patsubst %-linux-user,qemu-%,$(filter %-linux-user,$(TARGET_DIRS)))
-EXEC_COPY_TESTS=$(patsubst %,docker-exec-copy-test-%, $(USER_TCG_TARGETS))
-
-$(EXEC_COPY_TESTS): docker-exec-copy-test-%: $(DOCKER_FILES_DIR)/empty.docker
- $(call quiet-command, \
- $(DOCKER_SCRIPT) build -t qemu/exec-copy-test-$* -f $< \
- $(if $V,,--quiet) --no-cache \
- --include-executable=$* \
- --skip-binfmt, \
- "TEST","copy $* to container")
- $(call quiet-command, \
- $(DOCKER_SCRIPT) run qemu/exec-copy-test-$* \
- /$* -version > tests/docker-exec-copy-test-$*.out, \
- "TEST","check $* works in container")
-
-docker-exec-copy-test: $(EXEC_COPY_TESTS)
-
-endif
-
-# Enforce dependencies for composite images
+# Special case cross-compiling x86_64 on non-x86_64 systems.
ifeq ($(HOST_ARCH),x86_64)
-docker-image-debian-amd64: docker-image-debian10
DOCKER_PARTIAL_IMAGES += debian-amd64-cross
else
-docker-image-debian-amd64-cross: docker-image-debian10
DOCKER_PARTIAL_IMAGES += debian-amd64
endif
# For non-x86 hosts not all cross-compilers have been packaged
ifneq ($(HOST_ARCH),x86_64)
-DOCKER_PARTIAL_IMAGES += debian-mips-cross debian-mipsel-cross debian-mips64el-cross
+DOCKER_PARTIAL_IMAGES += debian-mipsel-cross debian-mips64el-cross
DOCKER_PARTIAL_IMAGES += debian-ppc64el-cross
DOCKER_PARTIAL_IMAGES += debian-s390x-cross
DOCKER_PARTIAL_IMAGES += fedora
endif
-docker-image-debian-alpha-cross: docker-image-debian10
-docker-image-debian-arm64-cross: docker-image-debian10
-docker-image-debian-armel-cross: docker-image-debian10
-docker-image-debian-armhf-cross: docker-image-debian10
-docker-image-debian-hppa-cross: docker-image-debian10
-docker-image-debian-m68k-cross: docker-image-debian10
-docker-image-debian-mips-cross: docker-image-debian10
-docker-image-debian-mips64-cross: docker-image-debian10
-docker-image-debian-mips64el-cross: docker-image-debian10
-docker-image-debian-mipsel-cross: docker-image-debian10
-docker-image-debian-ppc64el-cross: docker-image-debian10
-docker-image-debian-riscv64-cross: docker-image-debian10
-docker-image-debian-s390x-cross: docker-image-debian10
-docker-image-debian-sh4-cross: docker-image-debian10
-docker-image-debian-sparc64-cross: docker-image-debian10
+# alpine has no adduser
+docker-image-alpine: NOUSER=1
-#
-# The build rule for hexagon-cross is special in so far for most of
-# the time we don't want to build it. While dockers caching does avoid
-# this most of the time sometimes we want to force the issue.
-#
-docker-image-debian-hexagon-cross: $(DOCKER_FILES_DIR)/debian-hexagon-cross.docker
- $(if $(NOCACHE), \
- $(call quiet-command, \
- $(DOCKER_SCRIPT) build -t qemu/debian-hexagon-cross -f $< \
- $(if $V,,--quiet) --no-cache \
- --registry $(DOCKER_REGISTRY) --extra-files \
- $(DOCKER_FILES_DIR)/debian-hexagon-cross.docker.d/build-toolchain.sh, \
- "BUILD", "debian-hexagon-cross"), \
- $(call quiet-command, \
- $(DOCKER_SCRIPT) fetch $(if $V,,--quiet) \
- qemu/debian-hexagon-cross $(DOCKER_REGISTRY), \
- "FETCH", "debian-hexagon-cross") \
- $(call quiet-command, \
- $(DOCKER_SCRIPT) update $(if $V,,--quiet) \
- qemu/debian-hexagon-cross --add-current-user, \
- "PREPARE", "debian-hexagon-cross"))
+debian-toolchain-run = \
+ $(if $(NOCACHE), \
+ $(call quiet-command, \
+ $(DOCKER_SCRIPT) build -t qemu/$1 -f $< \
+ $(if $V,,--quiet) --no-cache \
+ --registry $(DOCKER_REGISTRY) --extra-files \
+ $(DOCKER_FILES_DIR)/$1.d/build-toolchain.sh, \
+ "BUILD", $1), \
+ $(call quiet-command, \
+ $(DOCKER_SCRIPT) fetch $(if $V,,--quiet) \
+ qemu/$1 $(DOCKER_REGISTRY), \
+ "FETCH", $1) \
+ $(call quiet-command, \
+ $(DOCKER_SCRIPT) update $(if $V,,--quiet) \
+ qemu/$1 \
+ $(if $(NOUSER),,--add-current-user) \
+ "PREPARE", $1))
+debian-toolchain = $(call debian-toolchain-run,$(patsubst docker-image-%,%,$1))
-# Specialist build images, sometimes very limited tools
-docker-image-debian-tricore-cross: docker-image-debian10
-docker-image-debian-all-test-cross: docker-image-debian10
-docker-image-debian-arm64-test-cross: docker-image-debian11
-docker-image-debian-powerpc-test-cross: docker-image-debian11
+docker-image-debian-microblaze-cross: $(DOCKER_FILES_DIR)/debian-toolchain.docker \
+ $(DOCKER_FILES_DIR)/debian-microblaze-cross.d/build-toolchain.sh
+ $(call debian-toolchain, $@)
# These images may be good enough for building tests but not for test builds
-DOCKER_PARTIAL_IMAGES += debian-alpha-cross
-DOCKER_PARTIAL_IMAGES += debian-arm64-test-cross
-DOCKER_PARTIAL_IMAGES += debian-powerpc-test-cross
-DOCKER_PARTIAL_IMAGES += debian-hppa-cross
-DOCKER_PARTIAL_IMAGES += debian-m68k-cross debian-mips64-cross
-DOCKER_PARTIAL_IMAGES += debian-riscv64-cross
-DOCKER_PARTIAL_IMAGES += debian-sh4-cross debian-sparc64-cross
-DOCKER_PARTIAL_IMAGES += debian-tricore-cross
+DOCKER_PARTIAL_IMAGES += debian-microblaze-cross
DOCKER_PARTIAL_IMAGES += debian-xtensa-cross
-DOCKER_PARTIAL_IMAGES += fedora-i386-cross fedora-cris-cross
+DOCKER_PARTIAL_IMAGES += fedora-cris-cross
-# Rules for building linux-user powered images
-#
-# These are slower than using native cross compiler setups but can
-# work around issues with poorly working multi-arch systems and broken
-# packages.
+# images that are only used to build other images
+DOCKER_VIRTUAL_IMAGES := debian-bootstrap debian-toolchain
+
+__IMAGES := $(sort $(filter-out $(DOCKER_VIRTUAL_IMAGES), $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker)))))
+DOCKER_IMAGES := $(if $(IMAGES), $(filter $(IMAGES), $(__IMAGES)), $(__IMAGES))
+
+__TESTS := $(notdir $(shell find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f))
+DOCKER_TESTS := $(if $(TESTS), $(filter $(TESTS), $(__TESTS)), $(__TESTS))
# Expand all the pre-requistes for each docker image and test combination
$(foreach i,$(filter-out $(DOCKER_PARTIAL_IMAGES),$(DOCKER_IMAGES)), \
$(foreach t,$(DOCKER_TESTS), \
$(eval .PHONY: docker-$t@$i) \
- $(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
+ $(eval docker-$t@$i: docker-image-$i; @$(MAKE) docker-run TEST=$t IMAGE=qemu/$i) \
) \
$(foreach t,$(DOCKER_TESTS), \
$(eval docker-all-tests: docker-$t@$i) \
@@ -205,7 +141,7 @@ $(foreach i,$(filter-out $(DOCKER_PARTIAL_IMAGES),$(DOCKER_IMAGES)), \
)
docker:
- @echo 'Build QEMU and run tests inside Docker or Podman containers'
+ @echo 'Build QEMU and run tests inside $(RUNC) containers'
@echo
@echo 'Available targets:'
@echo
@@ -223,11 +159,6 @@ docker:
@echo
@echo 'Available container images:'
@echo ' $(DOCKER_IMAGES)'
-ifneq ($(DOCKER_USER_IMAGES),)
- @echo
- @echo 'Available linux-user images (docker-binfmt-image-debian-%):'
- @echo ' $(DOCKER_USER_IMAGES)'
-endif
@echo
@echo 'Available tests:'
@echo ' $(DOCKER_TESTS)'
@@ -236,8 +167,9 @@ endif
@echo ' TARGET_LIST=a,b,c Override target list in builds.'
@echo ' EXTRA_CONFIGURE_OPTS="..."'
@echo ' Extra configure options.'
- @echo ' IMAGES="a b c ..": Filters which images to build or run.'
- @echo ' TESTS="x y z .." Filters which tests to run (for docker-test).'
+ @echo ' TEST_COMMAND="..." Override the default `make check` target.'
+ @echo ' IMAGES="a b c ..": Restrict available images to subset.'
+ @echo ' TESTS="x y z .." Restrict available tests to subset.'
@echo ' J=[0..9]* Overrides the -jN parameter for make commands'
@echo ' (default is 1)'
@echo ' DEBUG=1 Stop and drop to shell in the created container'
@@ -249,15 +181,16 @@ endif
@echo ' EXECUTABLE=<path> Include executable in image.'
@echo ' EXTRA_FILES="<path> [... <path>]"'
@echo ' Include extra files in image.'
- @echo ' ENGINE=auto/docker/podman'
- @echo ' Specify which container engine to run.'
@echo ' REGISTRY=url Cache builds from registry (default:$(DOCKER_REGISTRY))'
docker-help: docker
+# Use a global constant ccache directory to speed up repetitive builds
+DOCKER_CCACHE_DIR := $$HOME/.cache/qemu-docker-ccache
+
# This rule if for directly running against an arbitrary docker target.
# It is called by the expanded docker targets (e.g. make
-# docker-test-foo@bar) which will do additional verification.
+# docker-test-foo@bar) which will also ensure the image is up to date.
#
# For example: make docker-run TEST="test-quick" IMAGE="debian:arm64" EXECUTABLE=./aarch64-linux-user/qemu-aarch64
#
@@ -272,13 +205,15 @@ docker-run: docker-qemu-src
$(IMAGE) --executable $(EXECUTABLE), \
" COPYING $(EXECUTABLE) to $(IMAGE)"))
$(call quiet-command, \
- $(DOCKER_SCRIPT) run \
- $(if $(NOUSER),,--run-as-current-user) \
+ $(RUNC) run \
+ --rm \
+ $(if $(NOUSER),,-u $(UID)) \
--security-opt seccomp=unconfined \
$(if $(DEBUG),-ti,) \
$(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \
-e TARGET_LIST=$(subst $(SPACE),$(COMMA),$(TARGET_LIST)) \
-e EXTRA_CONFIGURE_OPTS="$(EXTRA_CONFIGURE_OPTS)" \
+ -e TEST_COMMAND="$(TEST_COMMAND)" \
-e V=$V -e J=$J -e DEBUG=$(DEBUG) \
-e SHOW_ENV=$(SHOW_ENV) \
$(if $(NOUSER),, \
@@ -292,13 +227,7 @@ docker-run: docker-qemu-src
$(call quiet-command, rm -r $(DOCKER_SRC_COPY), \
" CLEANUP $(DOCKER_SRC_COPY)")
-# Run targets:
-#
-# Of the form docker-TEST-FOO@IMAGE-BAR which will then be expanded into a call to "make docker-run"
-docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
-docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
-docker-run-%:
- @$(MAKE) docker-run TEST=$(CMD) IMAGE=qemu/$(IMAGE)
+docker-image: ${DOCKER_IMAGES:%=docker-image-%}
docker-clean:
$(call quiet-command, $(DOCKER_SCRIPT) clean)