diff mbox

[RFC,1/4] tests: Introduce Docker based tests

Message ID 1454510164-6278-2-git-send-email-famz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Fam Zheng Feb. 3, 2016, 2:36 p.m. UTC
A new group of targets to spawn docker instances for testing is added:

- "make docker" will spawn each available docker image and run all
  available tests under tests/docker.

- "make docker-foo" will spawn image foo and run all available tests.

- "make docker X=bar" or "make docker-foo X=bar" will limit the tests to
  only matching pattern "bar".

If the docker images (tagged like qemu:foo) don't exist, the make
command will automatically build them with foo.docker.

MAKEFLAGS is passed into the container.

Breaking down the tests/docker directory:

- *.docker in Dockerfile format define the environment in which tests
  are run.

- *.sh are testing scripts to be executed by "run".

- "run" is the entry script to run inside the container.

- Anything else are indirectly used or documents.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 Makefile                     | 33 ++++++++++++++++++++++++++++++++-
 tests/docker/basic.sh        | 11 +++++++++++
 tests/docker/centos6.docker  |  5 +++++
 tests/docker/fedora22.docker |  6 ++++++
 tests/docker/run             | 20 ++++++++++++++++++++
 tests/docker/ubuntu.docker   |  9 +++++++++
 6 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100755 tests/docker/basic.sh
 create mode 100644 tests/docker/centos6.docker
 create mode 100644 tests/docker/fedora22.docker
 create mode 100755 tests/docker/run
 create mode 100644 tests/docker/ubuntu.docker

Comments

Daniel P. Berrangé Feb. 4, 2016, 11:58 a.m. UTC | #1
On Wed, Feb 03, 2016 at 10:36:01PM +0800, Fam Zheng wrote:

> diff --git a/tests/docker/fedora22.docker b/tests/docker/fedora22.docker
> new file mode 100644
> index 0000000..5fd48d6
> --- /dev/null
> +++ b/tests/docker/fedora22.docker

Fedora 22 will go end of life in June. I think we should at least
start with the current Fedora 23 since that's the current preferred
Fedora release.

> @@ -0,0 +1,6 @@
> +FROM fedora:22
> +RUN dnf install -y \
> +    ccache git mingw{32,64}-{pixman,glib2,gmp,SDL,pkg-config} \
> +    glib2-devel pixman-devel zlib-devel SDL-devel \
> +    gcc g++ clang make perl which bc findutils

That's a pretty minimal set of mingw packages - many features will
end up disabled with that. Add mingw{32,64} packages for gtk2, gtk3,
gnutls, nettle, libtasn1, libjpeg-turbo, libpng, curl, libssh2,
bzip2 too, which is everything Fedora mingw is capable of providing
for QEMU


Regards,
Daniel
Fam Zheng Feb. 5, 2016, 6:17 a.m. UTC | #2
On Thu, 02/04 11:58, Daniel P. Berrange wrote:
> On Wed, Feb 03, 2016 at 10:36:01PM +0800, Fam Zheng wrote:
> 
> > diff --git a/tests/docker/fedora22.docker b/tests/docker/fedora22.docker
> > new file mode 100644
> > index 0000000..5fd48d6
> > --- /dev/null
> > +++ b/tests/docker/fedora22.docker
> 
> Fedora 22 will go end of life in June. I think we should at least
> start with the current Fedora 23 since that's the current preferred
> Fedora release.

Yes, will switch to 23.

> 
> > @@ -0,0 +1,6 @@
> > +FROM fedora:22
> > +RUN dnf install -y \
> > +    ccache git mingw{32,64}-{pixman,glib2,gmp,SDL,pkg-config} \
> > +    glib2-devel pixman-devel zlib-devel SDL-devel \
> > +    gcc g++ clang make perl which bc findutils
> 
> That's a pretty minimal set of mingw packages - many features will
> end up disabled with that. Add mingw{32,64} packages for gtk2, gtk3,
> gnutls, nettle, libtasn1, libjpeg-turbo, libpng, curl, libssh2,
> bzip2 too, which is everything Fedora mingw is capable of providing
> for QEMU

Okay!

Fam
diff mbox

Patch

diff --git a/Makefile b/Makefile
index d0de2d4..91be64f 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@  BUILD_DIR=$(CURDIR)
 # Before including a proper config-host.mak, assume we are in the source tree
 SRC_PATH=.
 
-UNCHECKED_GOALS := %clean TAGS cscope ctags
+UNCHECKED_GOALS := %clean TAGS cscope ctags docker docker-%
 
 # All following code might depend on configuration variables
 ifneq ($(wildcard config-host.mak),)
@@ -651,3 +651,34 @@  endif
 # Include automatically generated dependency files
 # Dependencies in Makefile.objs files come from our recursive subdir rules
 -include $(wildcard *.d tests/*.d)
+
+# Detect the working docker command
+DOCKER = $(shell for cmd in "docker" "sudo -n docker"; do \
+                    if $$cmd images &>/dev/null; then \
+                        echo $$cmd; \
+                    fi; done)
+
+docker: $(addprefix docker-,\
+            centos6 \
+            fedora22 \
+            ubuntu \
+        )
+docker-%: T=$(@:docker-%=%)
+docker-%:
+	@if test -z "$(DOCKER)"; then \
+		echo 'Docker not found.' \
+			'Tried "docker" and "sudo -n docker"'; \
+	fi
+	@if ! $(DOCKER) inspect qemu:$T &>/dev/null; then \
+		$(DOCKER) build -t qemu:$T -f $(SRC_PATH)/tests/docker/$T.docker \
+			$(SRC_PATH)/tests/docker; \
+	fi
+	$(DOCKER) run --privileged -t -i --rm --net=none \
+		-e IMAGE_TAG=$T \
+		-e MAKEFLAGS="$(MAKEFLAGS)" \
+		-e X="$X" \
+		-v $$(realpath $(SRC_PATH)):/var/tmp/qemu \
+		-e QEMU_SRC=/var/tmp/qemu \
+		-v /var/tmp/qemu-docker-ccache:/var/tmp/ccache \
+		-e CCACHE_DIR=/var/tmp/ccache \
+		qemu:$T sh - /var/tmp/qemu/tests/docker/run
diff --git a/tests/docker/basic.sh b/tests/docker/basic.sh
new file mode 100755
index 0000000..e51b718
--- /dev/null
+++ b/tests/docker/basic.sh
@@ -0,0 +1,11 @@ 
+#!/bin/bash
+
+cd $(mktemp -d)
+mkdir build
+mkdir install
+cd build
+$QEMU_SRC/configure --target-list=x86_64-softmmu
+    --prefix="${pwd}/install"
+make $MAKEFLAGS
+make check $MAKEFLAGS
+make install
diff --git a/tests/docker/centos6.docker b/tests/docker/centos6.docker
new file mode 100644
index 0000000..802ca79
--- /dev/null
+++ b/tests/docker/centos6.docker
@@ -0,0 +1,5 @@ 
+FROM centos:6
+RUN yum install -y \
+    git make gcc \
+    zlib-devel glib2-devel SDL-devel pixman-devel
+
diff --git a/tests/docker/fedora22.docker b/tests/docker/fedora22.docker
new file mode 100644
index 0000000..5fd48d6
--- /dev/null
+++ b/tests/docker/fedora22.docker
@@ -0,0 +1,6 @@ 
+FROM fedora:22
+RUN dnf install -y \
+    ccache git mingw{32,64}-{pixman,glib2,gmp,SDL,pkg-config} \
+    glib2-devel pixman-devel zlib-devel SDL-devel \
+    gcc g++ clang make perl which bc findutils
+
diff --git a/tests/docker/run b/tests/docker/run
new file mode 100755
index 0000000..8267766
--- /dev/null
+++ b/tests/docker/run
@@ -0,0 +1,20 @@ 
+#!/bin/sh
+
+set -e
+# Prepare the environment
+. /etc/profile || true
+export PATH=/usr/lib/ccache:$PATH
+
+save=$QEMU_SRC
+QEMU_SRC=/var/tmp/qemu.tmp
+cp -r $save $QEMU_SRC
+
+filter_test()
+{
+    grep $(for p in ${X:-.}; do echo " -e $p"; done)
+}
+
+for t in $(cd $QEMU_SRC/tests/docker/; ls *.sh | filter_test); do
+    echo "Running $t ..."
+    $QEMU_SRC/tests/docker/$t || break
+done
diff --git a/tests/docker/ubuntu.docker b/tests/docker/ubuntu.docker
new file mode 100644
index 0000000..004201d
--- /dev/null
+++ b/tests/docker/ubuntu.docker
@@ -0,0 +1,9 @@ 
+FROM ubuntu:14.04
+RUN apt-get update
+RUN apt-get -y install \
+    libusb-1.0-0-dev libiscsi-dev librados-dev libncurses5-dev \
+    libseccomp-dev libgnutls-dev libssh2-1-dev  libspice-server-dev \
+    libspice-protocol-dev libnss3-dev \
+    libgtk-3-dev libvte-2.90-dev libsdl1.2-dev libpng12-dev libpixman-1-dev \
+    git make ccache python-yaml gcc clang
+