qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests
@ 2016-02-05  9:24 Fam Zheng
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 01/12] tests: Add utilities for docker testing Fam Zheng
                   ` (13 more replies)
  0 siblings, 14 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

v1: Since RFC, addressed comments from reviewers, and improved a lot of things.
    Thanks to Daniel, Eric, Paolo, Stefan, for the feedback.

This series adds a new "docker" make target family to run tests in created
docker containers.

To begin with, this can be a place to store standard env/command combinations to
build and test QEMU.

Secondly, CI usually provides "docker" capability (such as travis [1]), where
we define standard/repeatable test environments, and run tests in them.
However, what tests to cover is better maintained in-tree, in order to keep in
sync with the code development.

Lastly, this makes it very simple for developers to replicate such tests
themselves.

[1]: https://docs.travis-ci.com/user/docker/

Fam Zheng (12):
  tests: Add utilities for docker testing
  Makefile: Rules for docker testing
  docker: Add images
  docker: Add test runner
  docker: Add common.rc
  docker: Add basic test
  docker: Add clang test
  docker: Add mingw test
  docker: Add travis tool
  docs: Add text for tests/docker in build-system.txt
  .gitignore: Ignore temporary dockerfile
  MAINTAINERS: Add tests/docker

 .gitignore                    |   1 +
 MAINTAINERS                   |   7 +++
 Makefile                      |   4 +-
 docs/build-system.txt         |   5 ++
 tests/docker/Makefile.include |  88 ++++++++++++++++++++++++++++++++++
 tests/docker/centos6.docker   |   5 ++
 tests/docker/common.rc        |  28 +++++++++++
 tests/docker/docker.py        | 108 ++++++++++++++++++++++++++++++++++++++++++
 tests/docker/docker_build     |  42 ++++++++++++++++
 tests/docker/docker_clean     |  22 +++++++++
 tests/docker/docker_run       |  28 +++++++++++
 tests/docker/fedora.docker    |   7 +++
 tests/docker/run              |  23 +++++++++
 tests/docker/test-basic.sh    |  22 +++++++++
 tests/docker/test-clang.sh    |  26 ++++++++++
 tests/docker/test-mingw.sh    |  34 +++++++++++++
 tests/docker/travis.py        |  53 +++++++++++++++++++++
 tests/docker/travis.sh        |  20 ++++++++
 tests/docker/ubuntu.docker    |   9 ++++
 19 files changed, 531 insertions(+), 1 deletion(-)
 create mode 100644 tests/docker/Makefile.include
 create mode 100644 tests/docker/centos6.docker
 create mode 100755 tests/docker/common.rc
 create mode 100755 tests/docker/docker.py
 create mode 100755 tests/docker/docker_build
 create mode 100755 tests/docker/docker_clean
 create mode 100755 tests/docker/docker_run
 create mode 100644 tests/docker/fedora.docker
 create mode 100755 tests/docker/run
 create mode 100755 tests/docker/test-basic.sh
 create mode 100755 tests/docker/test-clang.sh
 create mode 100755 tests/docker/test-mingw.sh
 create mode 100755 tests/docker/travis.py
 create mode 100755 tests/docker/travis.sh
 create mode 100644 tests/docker/ubuntu.docker

-- 
2.4.3

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 01/12] tests: Add utilities for docker testing
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-08 21:49   ` John Snow
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 02/12] Makefile: Rules " Fam Zheng
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

docker_run: A wrapper for "docker run" (or "sudo -n docker run" if
necessary), which takes care of killing and removing the running
container at SIGINT.

docker_clean: A tool to tear down all the containers including inactive
ones that are started by docker_run.

docker_build: A tool to compare an image from given dockerfile and
rebuild it if they're different.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 tests/docker/docker.py    | 108 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/docker/docker_build |  42 ++++++++++++++++++
 tests/docker/docker_clean |  22 ++++++++++
 tests/docker/docker_run   |  28 ++++++++++++
 4 files changed, 200 insertions(+)
 create mode 100755 tests/docker/docker.py
 create mode 100755 tests/docker/docker_build
 create mode 100755 tests/docker/docker_clean
 create mode 100755 tests/docker/docker_run

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
new file mode 100755
index 0000000..e513da0
--- /dev/null
+++ b/tests/docker/docker.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python2 -B
+#
+# Docker controlling module
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+import os
+import subprocess
+import json
+import hashlib
+import atexit
+import time
+import uuid
+
+class ContainerTerminated(Exception):
+    pass
+
+class Docker(object):
+    def __init__(self):
+        self._command = self._guess_command()
+        self._instances = []
+        atexit.register(self._kill_instances)
+
+    def _do(self, cmd, quiet=True, **kwargs):
+        if quiet:
+            kwargs["stdout"] = subprocess.PIPE
+        return subprocess.call(self._command + cmd, **kwargs)
+
+    def _do_kill_instances(self, only_known, only_active=True):
+        cmd = ["ps", "-q"]
+        if not only_active:
+            cmd.append("-a")
+        for i in self._output(cmd).split():
+            r = self._output(["inspect", i])
+            labels = json.loads(r)[0]["Config"]["Labels"]
+            active = json.loads(r)[0]["State"]["Running"]
+            if not labels:
+                continue
+            u = labels.get("com.qemu.instance.uuid", None)
+            if not u:
+                continue
+            if only_known and u not in self._instances:
+                continue
+            print "Terminating", i
+            if active:
+                self._do(["kill", i])
+            self._do(["rm", i])
+
+    def clean(self):
+        self._do_kill_instances(False, False)
+        return 0
+
+    def _kill_instances(self):
+        return self._do_kill_instances(True)
+
+    def _output(self, cmd, **kwargs):
+        return subprocess.check_output(self._command + cmd,
+                                       stderr=subprocess.STDOUT,
+                                       **kwargs)
+
+    def _guess_command(self):
+        for c in [["docker"], ["sudo", "-n", "docker"]]:
+            if subprocess.call(c + ["images"],
+                               stdout=subprocess.PIPE,
+                               stderr=subprocess.PIPE) == 0:
+                return c
+        raise Exception("Cannot find working docker command")
+
+    def get_image_dockerfile_checksum(self, tag):
+        resp = self._output(["inspect", tag])
+        t = json.loads(resp)[0]
+        return t["Config"].get("Labels", {}).get("com.qemu.dockerfile-checksum", "")
+
+    def checksum(self, text):
+        return hashlib.sha1(text).hexdigest()
+
+    def build_image(self, tag, dockerfile, df, quiet=True):
+        tmp = dockerfile + "\n" + \
+              "LABEL com.qemu.dockerfile-checksum=%s" % self.checksum(dockerfile)
+        tmp_df = df + ".tmp"
+        f = open(tmp_df, "wb")
+        f.write(tmp)
+        f.close()
+        self._do(["build", "-t", tag, "-f", tmp_df, os.path.dirname(df)],
+                 quiet=quiet)
+        os.unlink(tmp_df)
+
+    def image_matches_dockerfile(self, tag, dockerfile):
+        try:
+            a = self.get_image_dockerfile_checksum(tag)
+        except:
+            return False
+        return a == self.checksum(dockerfile)
+
+    def run(self, cmd, quiet, **kwargs):
+        label = uuid.uuid1().hex
+        self._instances.append(label)
+        r = self._do(["run", "--label", "com.qemu.instance.uuid=" + label] + cmd, quiet=quiet)
+        self._instances.remove(label)
+        return r
+
diff --git a/tests/docker/docker_build b/tests/docker/docker_build
new file mode 100755
index 0000000..b4f0dec
--- /dev/null
+++ b/tests/docker/docker_build
@@ -0,0 +1,42 @@
+#!/usr/bin/env python2
+#
+# Compare to Dockerfile and rebuild a docker image if necessary.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+import sys
+import docker
+import argparse
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("tag",
+                        help="Image Tag")
+    parser.add_argument("dockerfile",
+                        help="Dockerfile name")
+    parser.add_argument("--verbose", "-v", action="store_true",
+                        help="Print verbose information")
+    args = parser.parse_args()
+
+    dockerfile = open(args.dockerfile, "rb").read()
+    tag = args.tag
+
+    d = docker.Docker()
+    if d.image_matches_dockerfile(tag, dockerfile):
+        if args.verbose:
+            print "Image is up to date."
+        return 0
+
+    quiet = not args.verbose
+    d.build_image(tag, dockerfile, args.dockerfile, quiet=quiet)
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())
diff --git a/tests/docker/docker_clean b/tests/docker/docker_clean
new file mode 100755
index 0000000..88cdba6
--- /dev/null
+++ b/tests/docker/docker_clean
@@ -0,0 +1,22 @@
+#!/usr/bin/env python2
+#
+# Clean up uselsee containers.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+import sys
+import docker
+
+def main():
+    docker.Docker().clean()
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())
diff --git a/tests/docker/docker_run b/tests/docker/docker_run
new file mode 100755
index 0000000..5cf9d04
--- /dev/null
+++ b/tests/docker/docker_run
@@ -0,0 +1,28 @@
+#!/usr/bin/env python2
+#
+# Wrapper for "docker run" with automatical clean up if the execution is
+# iterrupted.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+import os
+import sys
+import argparse
+import docker
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--quiet", action="store_true",
+                        help="Run quietly unless an error occured")
+    args, argv = parser.parse_known_args()
+    return docker.Docker().run(argv, quiet=args.quiet)
+
+if __name__ == "__main__":
+    sys.exit(main())
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 02/12] Makefile: Rules for docker testing
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 01/12] tests: Add utilities for docker testing Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-15 10:06   ` Alex Bennée
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 03/12] docker: Add images Fam Zheng
                   ` (11 subsequent siblings)
  13 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

This adds a group of make targets to run docker tests, all are available
in source tree without running ./configure.

The usage is shown by "make docker".

Besides the fixed ones, dynamic targets for building each image and
running each test in each image are generated automatically by make,
scanning $(SRC_PATH)/tests/docker/ files with specific patterns.

Alternative to manually list particular targets (docker-run-FOO@BAR)
set, you can control which tests/images to run by filtering variables,
TESTS= and IMAGES=, which are expressed in Makefile pattern syntax,
"foo% %bar ...". For example:

    $ make docker-run IMAGES="ubuntu fedora"

Unfortunately, it's impossible to propagate "-j $JOBS" into make in
containers, however since each combination is made a first class target
is the top Makefile, "make -j$N docker-run" still parallels the tests
coarsely.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 Makefile                      |  4 +-
 tests/docker/Makefile.include | 88 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 1 deletion(-)
 create mode 100644 tests/docker/Makefile.include

diff --git a/Makefile b/Makefile
index d0de2d4..7da70f4 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,5 @@ endif
 # Include automatically generated dependency files
 # Dependencies in Makefile.objs files come from our recursive subdir rules
 -include $(wildcard *.d tests/*.d)
+
+include $(SRC_PATH)/tests/docker/Makefile.include
diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
new file mode 100644
index 0000000..ca84c35
--- /dev/null
+++ b/tests/docker/Makefile.include
@@ -0,0 +1,88 @@
+# Makefile for Docker tests
+
+$(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
+
+.PHONY: docker docker-build docker-run docker-clean
+
+DOCKER_SUFFIX = .docker
+
+DOCKER_IMAGES := $(patsubst %$(DOCKER_SUFFIX),%, $(shell \
+	ls $(SRC_PATH)/tests/docker/ | grep '$(DOCKER_SUFFIX)$$'))
+
+DOCKER_SCRIPTS := $(shell ls $(SRC_PATH)/tests/docker/ | grep '\.sh$$')
+DOCKER_TESTS := $(filter test-%, $(DOCKER_SCRIPTS))
+DOCKER_TOOLS := $(filter-out test-%, $(DOCKER_SCRIPTS))
+
+TESTS ?= %
+IMAGES ?= %
+
+$(foreach i,$(DOCKER_IMAGES), \
+	$(eval docker-build: docker-build-$i) \
+	$(foreach t,$(DOCKER_SCRIPTS), \
+		$(eval docker-build-$i docker-run-$t@$i: IMAGE=$i) \
+		$(eval docker-run-$t@$i: SCRIPT=$t) \
+		$(eval docker-run-$t@$i: docker-build-$i) \
+		$(if $(filter test-%,$t), \
+			$(eval docker-run: docker-run-$t@$i) \
+			$(eval docker-run-$t@: docker-run-$t@$i) \
+			$(eval docker-run-@$i: docker-run-$t@$i)) \
+))
+
+docker:
+	@echo 'Building QEMU and running tests or tools inside Docker containers'
+	@echo
+	@echo 'Available targets:'
+	@echo
+	@echo '    docker:              Print this help.'
+	@echo '    docker-run:          Run all image/test combinations.'
+	@echo '                         You can override the test cases to run by providing'
+	@echo '                         TESTS="foo bar" in the make command, and the image set'
+	@echo '                         by providing IMAGES="baz qux".'
+	@echo '    docker-clean:        Kill and remove residual docker testing containers.'
+	@echo '    docker-build:        Build all images.'
+	@echo '    docker-build-IMG:    Build image "IMG".'
+	@echo '                         "IMG" is one of the listed image name."'
+	@echo '    docker-run-FOO@BAR:  Run "FOO" in container "BAR".'
+	@echo '                         "FOO" must be one of the listed test/tool name."'
+	@echo '                         "BAR" must be one of the listed image name."'
+	@echo '    docker-run-FOO@:     Run "FOO" in all containers.'
+	@echo '                         "FOO" must be one of the listed test name."'
+	@echo '    docker-run-@BAR:     Run all tests in container "BAR".'
+	@echo '                         "BAR" must be one of the listed image name."'
+	@echo
+	@echo 'Available images:'
+	@echo '    $(DOCKER_IMAGES)'
+	@echo
+	@echo 'Available tests:'
+	@echo '    $(DOCKER_TESTS)'
+	@echo
+	@echo 'Available tools:'
+	@echo '    $(DOCKER_TOOLS)'
+
+docker-build-%:
+	@if test -z "$(IMAGE)"; then echo "Invalid target"; exit 1; fi
+	$(if $(filter $(IMAGES),$(IMAGE)), $(call quiet-command,\
+		$(SRC_PATH)/tests/docker/docker_build qemu:$(IMAGE) \
+			$(SRC_PATH)/tests/docker/$(IMAGE).docker \
+			$(if $V,-v,), "  BUILD $(IMAGE)"))
+
+docker-run-%:
+	@if test -z "$(IMAGE)" || test -z "$(SCRIPT)"; \
+		then echo "Invalid target"; exit 1; \
+	fi
+	$(if $(filter $(TESTS),$(SCRIPT)),$(if $(filter $(IMAGES),$(IMAGE)), \
+		$(call quiet-command,\
+			$(SRC_PATH)/tests/docker/docker_run \
+				--privileged -t --rm --net=none \
+				-v $$(realpath $(SRC_PATH)):/var/tmp/qemu \
+				-e QEMU_SRC=/var/tmp/qemu \
+				-e V=$(V) \
+				-v /var/tmp/qemu-docker-ccache:/var/tmp/ccache \
+				-e CCACHE_DIR=/var/tmp/ccache \
+				qemu:$(IMAGE) \
+				/var/tmp/qemu/tests/docker/run \
+				/var/tmp/qemu/tests/docker/$(SCRIPT); \
+			, "  RUN $(SCRIPT) in $(IMAGE)")))
+
+docker-clean:
+	$(call quiet-command, $(SRC_PATH)/tests/docker/docker_clean)
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 03/12] docker: Add images
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 01/12] tests: Add utilities for docker testing Fam Zheng
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 02/12] Makefile: Rules " Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-15 10:15   ` Alex Bennée
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 04/12] docker: Add test runner Fam Zheng
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 tests/docker/centos6.docker | 5 +++++
 tests/docker/fedora.docker  | 7 +++++++
 tests/docker/ubuntu.docker  | 9 +++++++++
 3 files changed, 21 insertions(+)
 create mode 100644 tests/docker/centos6.docker
 create mode 100644 tests/docker/fedora.docker
 create mode 100644 tests/docker/ubuntu.docker

diff --git a/tests/docker/centos6.docker b/tests/docker/centos6.docker
new file mode 100644
index 0000000..7daa2fb
--- /dev/null
+++ b/tests/docker/centos6.docker
@@ -0,0 +1,5 @@
+FROM centos:6
+RUN yum install -y \
+    git make gcc g++ \
+    zlib-devel glib2-devel SDL-devel pixman-devel
+
diff --git a/tests/docker/fedora.docker b/tests/docker/fedora.docker
new file mode 100644
index 0000000..81091b7
--- /dev/null
+++ b/tests/docker/fedora.docker
@@ -0,0 +1,7 @@
+FROM fedora:23
+RUN dnf install -y \
+    ccache git \
+    glib2-devel pixman-devel zlib-devel SDL-devel \
+    gcc gcc-c++ clang make perl which bc findutils \
+    mingw{32,64}-{pixman,glib2,gmp,SDL,pkg-config,gtk2,gtk3,gnutls,nettle,libtasn1,libjpeg-turbo,libpng,curl,libssh2,bzip2}
+ENV FEATURES mingw clang
diff --git a/tests/docker/ubuntu.docker b/tests/docker/ubuntu.docker
new file mode 100644
index 0000000..f1dc518
--- /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
+ENV FEATURES clang ccache pyyaml
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 04/12] docker: Add test runner
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (2 preceding siblings ...)
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 03/12] docker: Add images Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-15 10:55   ` Alex Bennée
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 05/12] docker: Add common.rc Fam Zheng
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

It's better to have a launcher for all tests, to make it easier to
initialize and manage the environment.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 tests/docker/run | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100755 tests/docker/run

diff --git a/tests/docker/run b/tests/docker/run
new file mode 100755
index 0000000..739ecf9
--- /dev/null
+++ b/tests/docker/run
@@ -0,0 +1,23 @@
+#!/bin/bash -e
+#
+# Docker test runner
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+# Prepare the environment
+. /etc/profile || true
+export PATH=/usr/lib/ccache:$PATH
+
+tmp=$QEMU_SRC
+QEMU_SRC=/var/tmp/qemu.tmp
+cp -r $tmp $QEMU_SRC
+
+cd $QEMU_SRC/tests/docker
+"$@"
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 05/12] docker: Add common.rc
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (3 preceding siblings ...)
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 04/12] docker: Add test runner Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 06/12] docker: Add basic test Fam Zheng
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

"requires" checks the "FEATURE" environment for specified prerequisits,
and skip the execution of test if not found.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 tests/docker/common.rc | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100755 tests/docker/common.rc

diff --git a/tests/docker/common.rc b/tests/docker/common.rc
new file mode 100755
index 0000000..5ad8ddc
--- /dev/null
+++ b/tests/docker/common.rc
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+# Common routines for docker test scripts.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+requires()
+{
+    for c in $@; do
+        if ! echo "$FEATURES" | grep -wq -e "$c"; then
+            echo "Prerequisite '$c' not present, skip"
+            exit 0
+        fi
+    done
+}
+
+build_qemu()
+{
+    $QEMU_SRC/configure "$@"
+    make $MAKEFLAGS
+}
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 06/12] docker: Add basic test
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (4 preceding siblings ...)
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 05/12] docker: Add common.rc Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-15 14:34   ` Alex Bennée
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 07/12] docker: Add clang test Fam Zheng
                   ` (7 subsequent siblings)
  13 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 tests/docker/test-basic.sh | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100755 tests/docker/test-basic.sh

diff --git a/tests/docker/test-basic.sh b/tests/docker/test-basic.sh
new file mode 100755
index 0000000..c2b32ad
--- /dev/null
+++ b/tests/docker/test-basic.sh
@@ -0,0 +1,22 @@
+#!/bin/bash -e
+#
+# Basic compiling test that everyone already does. But why not automate it?
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+. common.rc
+
+cd $(mktemp -d)
+mkdir build
+mkdir install
+cd build
+build_qemu --target-list=x86_64-softmmu --prefix="${pwd}/install"
+make check $MAKEFLAGS
+make install
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 07/12] docker: Add clang test
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (5 preceding siblings ...)
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 06/12] docker: Add basic test Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 08/12] docker: Add mingw test Fam Zheng
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

The configure options are suggested by John Snow <jsnow@redhat.com>.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 tests/docker/test-clang.sh | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100755 tests/docker/test-clang.sh

diff --git a/tests/docker/test-clang.sh b/tests/docker/test-clang.sh
new file mode 100755
index 0000000..9660778
--- /dev/null
+++ b/tests/docker/test-clang.sh
@@ -0,0 +1,26 @@
+#!/bin/bash -e
+#
+# Compile and check with clang.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+. common.rc
+
+requires clang
+
+cd $(mktemp -d)
+build_qemu \
+    --target-list=x86_64-softmmu,aarch64-softmmu \
+    --enable-debug \
+    --cxx=clang++ --cc=clang --host-cc=clang \
+    --extra-cflags=-Werror --extra-cflags=-fsanitize=undefined \
+    --extra-cflags=-Wno-deprecated-declarations \
+    --extra-cflags=-fno-sanitize=float-divide-by-zero
+make $MAKEFLAGS check
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 08/12] docker: Add mingw test
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (6 preceding siblings ...)
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 07/12] docker: Add clang test Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 09/12] docker: Add travis tool Fam Zheng
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 tests/docker/test-mingw.sh | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100755 tests/docker/test-mingw.sh

diff --git a/tests/docker/test-mingw.sh b/tests/docker/test-mingw.sh
new file mode 100755
index 0000000..22e7579
--- /dev/null
+++ b/tests/docker/test-mingw.sh
@@ -0,0 +1,34 @@
+#!/bin/bash -e
+#
+# Cross compile QEMU with mingw toolchain on Linux.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+. common.rc
+
+requires mingw
+
+cd $(mktemp -d)
+for prefix in x86_64-w64-mingw32- i686-w64-mingw32-; do
+    build_qemu --cross-prefix=$prefix \
+        --target-list=x86_64-softmmu,aarch64-softmmu \
+        --enable-trace-backends=simple \
+        --enable-debug \
+        --enable-gnutls \
+        --enable-nettle \
+        --enable-curl \
+        --enable-vnc \
+        --enable-bzip2 \
+        --enable-guest-agent \
+        --with-sdlabi=1.2 \
+        --with-gtkabi=2.0
+
+done
+
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 09/12] docker: Add travis tool
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (7 preceding siblings ...)
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 08/12] docker: Add mingw test Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 10/12] docs: Add text for tests/docker in build-system.txt Fam Zheng
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

The script is not named test-travis.sh so it won't run with "make
docker-run", because it can take too long.

Run it with "make docker-run-travis.sh@ubuntu".

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 tests/docker/travis.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/docker/travis.sh | 20 +++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100755 tests/docker/travis.py
 create mode 100755 tests/docker/travis.sh

diff --git a/tests/docker/travis.py b/tests/docker/travis.py
new file mode 100755
index 0000000..75f0267
--- /dev/null
+++ b/tests/docker/travis.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python2 -B
+#
+# Travis YAML config parser
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+import sys
+import yaml
+import json
+import itertools
+
+def load_yaml(fname):
+    return yaml.load(open(sys.argv[1], "r").read())
+
+def conf_iter(conf):
+    def env_list(e):
+        return e if type(e) is list else [e]
+    global_env = conf["env"]["global"]
+    for c in conf["matrix"]["include"]:
+        a = { "env": global_env + env_list(c["env"]),
+              "compiler": c["compiler"]
+            }
+        yield a
+    for c in itertools.product(conf["compiler"],
+                               conf["env"]["matrix"]):
+        a = { "env": global_env + env_list(c[1]),
+              "compiler": c[0]
+            }
+        yield a
+
+def main():
+    if len(sys.argv) < 2:
+        sys.stderr.write("Usage: %s <travis-file>\n" % sys.argv[0])
+        return 1
+    conf = load_yaml(sys.argv[1])
+    for config in conf_iter(conf):
+        print "("
+        print "\n".join(config["env"])
+        print "CC=" + config["compiler"]
+        print "\n".join(conf["before_script"])
+        print "\n".join(conf["script"])
+        print ")"
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())
diff --git a/tests/docker/travis.sh b/tests/docker/travis.sh
new file mode 100755
index 0000000..bfc9bf4
--- /dev/null
+++ b/tests/docker/travis.sh
@@ -0,0 +1,20 @@
+#!/bin/bash -e
+#
+# Mimic a travis testing matrix of environment
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <famz@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or (at your option) any later version. See the COPYING file in
+# the top-level directory.
+
+. common.rc
+
+requires pyyaml
+
+cd $(mktemp -d)
+$QEMU_SRC/tests/docker/travis.py $QEMU_SRC/.travis.yml > travis_command_list
+. travis_command_list
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 10/12] docs: Add text for tests/docker in build-system.txt
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (8 preceding siblings ...)
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 09/12] docker: Add travis tool Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 11/12] .gitignore: Ignore temporary dockerfile Fam Zheng
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 docs/build-system.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/docs/build-system.txt b/docs/build-system.txt
index 5ddddea..2af1e66 100644
--- a/docs/build-system.txt
+++ b/docs/build-system.txt
@@ -438,6 +438,11 @@ top level Makefile, so anything defined in this file will influence the
 entire build system. Care needs to be taken when writing rules for tests
 to ensure they only apply to the unit test execution / build.
 
+- tests/docker/Makefile.include
+
+Rules for Docker tests. Like tests/Makefile, this file is included
+directly by the top level Makefile, anything defined in this file will
+influence the entire build system.
 
 - po/Makefile
 
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 11/12] .gitignore: Ignore temporary dockerfile
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (9 preceding siblings ...)
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 10/12] docs: Add text for tests/docker in build-system.txt Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-15 14:42   ` Alex Bennée
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 12/12] MAINTAINERS: Add tests/docker Fam Zheng
                   ` (2 subsequent siblings)
  13 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 88a80ff..a335b7b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -109,3 +109,4 @@ cscope.*
 tags
 TAGS
 *~
+/tests/docker/*.docker.tmp
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [Qemu-devel] [PATCH 12/12] MAINTAINERS: Add tests/docker
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (10 preceding siblings ...)
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 11/12] .gitignore: Ignore temporary dockerfile Fam Zheng
@ 2016-02-05  9:24 ` Fam Zheng
  2016-02-15 14:36   ` Alex Bennée
  2016-02-10 11:23 ` [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Alex Bennée
  2016-02-15 17:59 ` Alex Bennée
  13 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-05  9:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, peter.maydell, jsnow, stefanha, sw, Paolo Bonzini,
	Alex Bennée, david

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index b6ed87a..f24a449 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1573,3 +1573,10 @@ Build system architecture
 M: Daniel P. Berrange <berrange@redhat.com>
 S: Odd Fixes
 F: docs/build-system.txt
+
+Docker testing
+--------------
+Docker based testing framework and cases
+M: Fam Zheng <famz@redhat.com>
+S: Maintained
+F: tests/docker/
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 01/12] tests: Add utilities for docker testing
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 01/12] tests: Add utilities for docker testing Fam Zheng
@ 2016-02-08 21:49   ` John Snow
  2016-02-09  2:01     ` Fam Zheng
  0 siblings, 1 reply; 41+ messages in thread
From: John Snow @ 2016-02-08 21:49 UTC (permalink / raw)
  To: Fam Zheng, qemu-devel
  Cc: kwolf, peter.maydell, sw, stefanha, Paolo Bonzini,
	Alex Bennée, david



On 02/05/2016 04:24 AM, Fam Zheng wrote:
> docker_run: A wrapper for "docker run" (or "sudo -n docker run" if
> necessary), which takes care of killing and removing the running
> container at SIGINT.
> 
> docker_clean: A tool to tear down all the containers including inactive
> ones that are started by docker_run.
> 
> docker_build: A tool to compare an image from given dockerfile and
> rebuild it if they're different.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  tests/docker/docker.py    | 108 ++++++++++++++++++++++++++++++++++++++++++++++
>  tests/docker/docker_build |  42 ++++++++++++++++++
>  tests/docker/docker_clean |  22 ++++++++++
>  tests/docker/docker_run   |  28 ++++++++++++
>  4 files changed, 200 insertions(+)
>  create mode 100755 tests/docker/docker.py
>  create mode 100755 tests/docker/docker_build
>  create mode 100755 tests/docker/docker_clean
>  create mode 100755 tests/docker/docker_run
> 
> diff --git a/tests/docker/docker.py b/tests/docker/docker.py
> new file mode 100755
> index 0000000..e513da0
> --- /dev/null
> +++ b/tests/docker/docker.py
> @@ -0,0 +1,108 @@
> +#!/usr/bin/env python2 -B
> +#
> +# Docker controlling module
> +#
> +# Copyright (c) 2016 Red Hat Inc.
> +#
> +# Authors:
> +#  Fam Zheng <famz@redhat.com>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2
> +# or (at your option) any later version. See the COPYING file in
> +# the top-level directory.
> +
> +import os
> +import subprocess
> +import json
> +import hashlib
> +import atexit
> +import time
> +import uuid
> +
> +class ContainerTerminated(Exception):
> +    pass
> +
> +class Docker(object):
> +    def __init__(self):
> +        self._command = self._guess_command()
> +        self._instances = []
> +        atexit.register(self._kill_instances)
> +
> +    def _do(self, cmd, quiet=True, **kwargs):
> +        if quiet:
> +            kwargs["stdout"] = subprocess.PIPE
> +        return subprocess.call(self._command + cmd, **kwargs)
> +
> +    def _do_kill_instances(self, only_known, only_active=True):
> +        cmd = ["ps", "-q"]
> +        if not only_active:
> +            cmd.append("-a")
> +        for i in self._output(cmd).split():
> +            r = self._output(["inspect", i])
> +            labels = json.loads(r)[0]["Config"]["Labels"]
> +            active = json.loads(r)[0]["State"]["Running"]
> +            if not labels:
> +                continue
> +            u = labels.get("com.qemu.instance.uuid", None)
> +            if not u:
> +                continue
> +            if only_known and u not in self._instances:
> +                continue
> +            print "Terminating", i
> +            if active:
> +                self._do(["kill", i])
> +            self._do(["rm", i])
> +
> +    def clean(self):
> +        self._do_kill_instances(False, False)
> +        return 0
> +
> +    def _kill_instances(self):
> +        return self._do_kill_instances(True)
> +
> +    def _output(self, cmd, **kwargs):
> +        return subprocess.check_output(self._command + cmd,
> +                                       stderr=subprocess.STDOUT,
> +                                       **kwargs)
> +
> +    def _guess_command(self):
> +        for c in [["docker"], ["sudo", "-n", "docker"]]:

If the sudo version fails (Say, because a password prompt shows up) we
get the unhelpful error "Cannot find working docker command."

Does your sudo not prompt you in your dev environment?

> +            if subprocess.call(c + ["images"],
> +                               stdout=subprocess.PIPE,
> +                               stderr=subprocess.PIPE) == 0:
> +                return c
> +        raise Exception("Cannot find working docker command")
> +
> +    def get_image_dockerfile_checksum(self, tag):
> +        resp = self._output(["inspect", tag])
> +        t = json.loads(resp)[0]
> +        return t["Config"].get("Labels", {}).get("com.qemu.dockerfile-checksum", "")
> +
> +    def checksum(self, text):
> +        return hashlib.sha1(text).hexdigest()
> +
> +    def build_image(self, tag, dockerfile, df, quiet=True):
> +        tmp = dockerfile + "\n" + \
> +              "LABEL com.qemu.dockerfile-checksum=%s" % self.checksum(dockerfile)
> +        tmp_df = df + ".tmp"
> +        f = open(tmp_df, "wb")
> +        f.write(tmp)
> +        f.close()
> +        self._do(["build", "-t", tag, "-f", tmp_df, os.path.dirname(df)],
> +                 quiet=quiet)
> +        os.unlink(tmp_df)
> +
> +    def image_matches_dockerfile(self, tag, dockerfile):
> +        try:
> +            a = self.get_image_dockerfile_checksum(tag)
> +        except:
> +            return False
> +        return a == self.checksum(dockerfile)
> +
> +    def run(self, cmd, quiet, **kwargs):
> +        label = uuid.uuid1().hex
> +        self._instances.append(label)
> +        r = self._do(["run", "--label", "com.qemu.instance.uuid=" + label] + cmd, quiet=quiet)
> +        self._instances.remove(label)
> +        return r
> +
> diff --git a/tests/docker/docker_build b/tests/docker/docker_build
> new file mode 100755
> index 0000000..b4f0dec
> --- /dev/null
> +++ b/tests/docker/docker_build
> @@ -0,0 +1,42 @@
> +#!/usr/bin/env python2
> +#
> +# Compare to Dockerfile and rebuild a docker image if necessary.
> +#
> +# Copyright (c) 2016 Red Hat Inc.
> +#
> +# Authors:
> +#  Fam Zheng <famz@redhat.com>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2
> +# or (at your option) any later version. See the COPYING file in
> +# the top-level directory.
> +
> +import sys
> +import docker
> +import argparse
> +
> +def main():
> +    parser = argparse.ArgumentParser()
> +    parser.add_argument("tag",
> +                        help="Image Tag")
> +    parser.add_argument("dockerfile",
> +                        help="Dockerfile name")
> +    parser.add_argument("--verbose", "-v", action="store_true",
> +                        help="Print verbose information")
> +    args = parser.parse_args()
> +
> +    dockerfile = open(args.dockerfile, "rb").read()
> +    tag = args.tag
> +
> +    d = docker.Docker()
> +    if d.image_matches_dockerfile(tag, dockerfile):
> +        if args.verbose:
> +            print "Image is up to date."
> +        return 0
> +
> +    quiet = not args.verbose
> +    d.build_image(tag, dockerfile, args.dockerfile, quiet=quiet)
> +    return 0
> +
> +if __name__ == "__main__":
> +    sys.exit(main())
> diff --git a/tests/docker/docker_clean b/tests/docker/docker_clean
> new file mode 100755
> index 0000000..88cdba6
> --- /dev/null
> +++ b/tests/docker/docker_clean
> @@ -0,0 +1,22 @@
> +#!/usr/bin/env python2
> +#
> +# Clean up uselsee containers.
> +#
> +# Copyright (c) 2016 Red Hat Inc.
> +#
> +# Authors:
> +#  Fam Zheng <famz@redhat.com>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2
> +# or (at your option) any later version. See the COPYING file in
> +# the top-level directory.
> +
> +import sys
> +import docker
> +
> +def main():
> +    docker.Docker().clean()
> +    return 0
> +
> +if __name__ == "__main__":
> +    sys.exit(main())
> diff --git a/tests/docker/docker_run b/tests/docker/docker_run
> new file mode 100755
> index 0000000..5cf9d04
> --- /dev/null
> +++ b/tests/docker/docker_run
> @@ -0,0 +1,28 @@
> +#!/usr/bin/env python2
> +#
> +# Wrapper for "docker run" with automatical clean up if the execution is
> +# iterrupted.
> +#
> +# Copyright (c) 2016 Red Hat Inc.
> +#
> +# Authors:
> +#  Fam Zheng <famz@redhat.com>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2
> +# or (at your option) any later version. See the COPYING file in
> +# the top-level directory.
> +
> +import os
> +import sys
> +import argparse
> +import docker
> +
> +def main():
> +    parser = argparse.ArgumentParser()
> +    parser.add_argument("--quiet", action="store_true",
> +                        help="Run quietly unless an error occured")
> +    args, argv = parser.parse_known_args()
> +    return docker.Docker().run(argv, quiet=args.quiet)
> +
> +if __name__ == "__main__":
> +    sys.exit(main())
> 

-- 
—js

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 01/12] tests: Add utilities for docker testing
  2016-02-08 21:49   ` John Snow
@ 2016-02-09  2:01     ` Fam Zheng
  2016-02-09 23:16       ` John Snow
  0 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-09  2:01 UTC (permalink / raw)
  To: John Snow
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	Alex Bennée, david

On Mon, 02/08 16:49, John Snow wrote:
> > +    def _guess_command(self):
> > +        for c in [["docker"], ["sudo", "-n", "docker"]]:
> 
> If the sudo version fails (Say, because a password prompt shows up) we
> get the unhelpful error "Cannot find working docker command."

If you have previously "sudo $something" and typed in the password, this will
work.

You can also specify passworless for docker only:

    fam ALL=(ALL) NOPASSWD: /usr/bin/docker

Fam

> 
> > +            if subprocess.call(c + ["images"],
> > +                               stdout=subprocess.PIPE,
> > +                               stderr=subprocess.PIPE) == 0:
> > +                return c
> > +        raise Exception("Cannot find working docker command")
> > +
> > +    def get_image_dockerfile_checksum(self, tag):
> > +        resp = self._output(["inspect", tag])
> > +        t = json.loads(resp)[0]
> > +        return t["Config"].get("Labels", {}).get("com.qemu.dockerfile-checksum", "")
> > +
> > +    def checksum(self, text):
> > +        return hashlib.sha1(text).hexdigest()
> > +
> > +    def build_image(self, tag, dockerfile, df, quiet=True):
> > +        tmp = dockerfile + "\n" + \
> > +              "LABEL com.qemu.dockerfile-checksum=%s" % self.checksum(dockerfile)
> > +        tmp_df = df + ".tmp"
> > +        f = open(tmp_df, "wb")
> > +        f.write(tmp)
> > +        f.close()
> > +        self._do(["build", "-t", tag, "-f", tmp_df, os.path.dirname(df)],
> > +                 quiet=quiet)
> > +        os.unlink(tmp_df)
> > +
> > +    def image_matches_dockerfile(self, tag, dockerfile):
> > +        try:
> > +            a = self.get_image_dockerfile_checksum(tag)
> > +        except:
> > +            return False
> > +        return a == self.checksum(dockerfile)
> > +
> > +    def run(self, cmd, quiet, **kwargs):
> > +        label = uuid.uuid1().hex
> > +        self._instances.append(label)
> > +        r = self._do(["run", "--label", "com.qemu.instance.uuid=" + label] + cmd, quiet=quiet)
> > +        self._instances.remove(label)
> > +        return r
> > +
> > diff --git a/tests/docker/docker_build b/tests/docker/docker_build
> > new file mode 100755
> > index 0000000..b4f0dec
> > --- /dev/null
> > +++ b/tests/docker/docker_build
> > @@ -0,0 +1,42 @@
> > +#!/usr/bin/env python2
> > +#
> > +# Compare to Dockerfile and rebuild a docker image if necessary.
> > +#
> > +# Copyright (c) 2016 Red Hat Inc.
> > +#
> > +# Authors:
> > +#  Fam Zheng <famz@redhat.com>
> > +#
> > +# This work is licensed under the terms of the GNU GPL, version 2
> > +# or (at your option) any later version. See the COPYING file in
> > +# the top-level directory.
> > +
> > +import sys
> > +import docker
> > +import argparse
> > +
> > +def main():
> > +    parser = argparse.ArgumentParser()
> > +    parser.add_argument("tag",
> > +                        help="Image Tag")
> > +    parser.add_argument("dockerfile",
> > +                        help="Dockerfile name")
> > +    parser.add_argument("--verbose", "-v", action="store_true",
> > +                        help="Print verbose information")
> > +    args = parser.parse_args()
> > +
> > +    dockerfile = open(args.dockerfile, "rb").read()
> > +    tag = args.tag
> > +
> > +    d = docker.Docker()
> > +    if d.image_matches_dockerfile(tag, dockerfile):
> > +        if args.verbose:
> > +            print "Image is up to date."
> > +        return 0
> > +
> > +    quiet = not args.verbose
> > +    d.build_image(tag, dockerfile, args.dockerfile, quiet=quiet)
> > +    return 0
> > +
> > +if __name__ == "__main__":
> > +    sys.exit(main())
> > diff --git a/tests/docker/docker_clean b/tests/docker/docker_clean
> > new file mode 100755
> > index 0000000..88cdba6
> > --- /dev/null
> > +++ b/tests/docker/docker_clean
> > @@ -0,0 +1,22 @@
> > +#!/usr/bin/env python2
> > +#
> > +# Clean up uselsee containers.
> > +#
> > +# Copyright (c) 2016 Red Hat Inc.
> > +#
> > +# Authors:
> > +#  Fam Zheng <famz@redhat.com>
> > +#
> > +# This work is licensed under the terms of the GNU GPL, version 2
> > +# or (at your option) any later version. See the COPYING file in
> > +# the top-level directory.
> > +
> > +import sys
> > +import docker
> > +
> > +def main():
> > +    docker.Docker().clean()
> > +    return 0
> > +
> > +if __name__ == "__main__":
> > +    sys.exit(main())
> > diff --git a/tests/docker/docker_run b/tests/docker/docker_run
> > new file mode 100755
> > index 0000000..5cf9d04
> > --- /dev/null
> > +++ b/tests/docker/docker_run
> > @@ -0,0 +1,28 @@
> > +#!/usr/bin/env python2
> > +#
> > +# Wrapper for "docker run" with automatical clean up if the execution is
> > +# iterrupted.
> > +#
> > +# Copyright (c) 2016 Red Hat Inc.
> > +#
> > +# Authors:
> > +#  Fam Zheng <famz@redhat.com>
> > +#
> > +# This work is licensed under the terms of the GNU GPL, version 2
> > +# or (at your option) any later version. See the COPYING file in
> > +# the top-level directory.
> > +
> > +import os
> > +import sys
> > +import argparse
> > +import docker
> > +
> > +def main():
> > +    parser = argparse.ArgumentParser()
> > +    parser.add_argument("--quiet", action="store_true",
> > +                        help="Run quietly unless an error occured")
> > +    args, argv = parser.parse_known_args()
> > +    return docker.Docker().run(argv, quiet=args.quiet)
> > +
> > +if __name__ == "__main__":
> > +    sys.exit(main())
> > 
> 
> -- 
> —js

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 01/12] tests: Add utilities for docker testing
  2016-02-09  2:01     ` Fam Zheng
@ 2016-02-09 23:16       ` John Snow
  2016-02-14  5:10         ` Fam Zheng
  0 siblings, 1 reply; 41+ messages in thread
From: John Snow @ 2016-02-09 23:16 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	Alex Bennée, david



On 02/08/2016 09:01 PM, Fam Zheng wrote:
> On Mon, 02/08 16:49, John Snow wrote:
>>> +    def _guess_command(self):
>>> +        for c in [["docker"], ["sudo", "-n", "docker"]]:
>>
>> If the sudo version fails (Say, because a password prompt shows up) we
>> get the unhelpful error "Cannot find working docker command."
> 
> If you have previously "sudo $something" and typed in the password, this will
> work.
> 
> You can also specify passworless for docker only:
> 
>     fam ALL=(ALL) NOPASSWD: /usr/bin/docker
> 
> Fam
> 

Sure, but the failure here is not particularly obvious, because it makes
it seem as if docker has failed instead of a sudo privilege situation.

--js

>>
>>> +            if subprocess.call(c + ["images"],
>>> +                               stdout=subprocess.PIPE,
>>> +                               stderr=subprocess.PIPE) == 0:
>>> +                return c
>>> +        raise Exception("Cannot find working docker command")
>>> +
>>> +    def get_image_dockerfile_checksum(self, tag):
>>> +        resp = self._output(["inspect", tag])
>>> +        t = json.loads(resp)[0]
>>> +        return t["Config"].get("Labels", {}).get("com.qemu.dockerfile-checksum", "")
>>> +
>>> +    def checksum(self, text):
>>> +        return hashlib.sha1(text).hexdigest()
>>> +
>>> +    def build_image(self, tag, dockerfile, df, quiet=True):
>>> +        tmp = dockerfile + "\n" + \
>>> +              "LABEL com.qemu.dockerfile-checksum=%s" % self.checksum(dockerfile)
>>> +        tmp_df = df + ".tmp"
>>> +        f = open(tmp_df, "wb")
>>> +        f.write(tmp)
>>> +        f.close()
>>> +        self._do(["build", "-t", tag, "-f", tmp_df, os.path.dirname(df)],
>>> +                 quiet=quiet)
>>> +        os.unlink(tmp_df)
>>> +
>>> +    def image_matches_dockerfile(self, tag, dockerfile):
>>> +        try:
>>> +            a = self.get_image_dockerfile_checksum(tag)
>>> +        except:
>>> +            return False
>>> +        return a == self.checksum(dockerfile)
>>> +
>>> +    def run(self, cmd, quiet, **kwargs):
>>> +        label = uuid.uuid1().hex
>>> +        self._instances.append(label)
>>> +        r = self._do(["run", "--label", "com.qemu.instance.uuid=" + label] + cmd, quiet=quiet)
>>> +        self._instances.remove(label)
>>> +        return r
>>> +
>>> diff --git a/tests/docker/docker_build b/tests/docker/docker_build
>>> new file mode 100755
>>> index 0000000..b4f0dec
>>> --- /dev/null
>>> +++ b/tests/docker/docker_build
>>> @@ -0,0 +1,42 @@
>>> +#!/usr/bin/env python2
>>> +#
>>> +# Compare to Dockerfile and rebuild a docker image if necessary.
>>> +#
>>> +# Copyright (c) 2016 Red Hat Inc.
>>> +#
>>> +# Authors:
>>> +#  Fam Zheng <famz@redhat.com>
>>> +#
>>> +# This work is licensed under the terms of the GNU GPL, version 2
>>> +# or (at your option) any later version. See the COPYING file in
>>> +# the top-level directory.
>>> +
>>> +import sys
>>> +import docker
>>> +import argparse
>>> +
>>> +def main():
>>> +    parser = argparse.ArgumentParser()
>>> +    parser.add_argument("tag",
>>> +                        help="Image Tag")
>>> +    parser.add_argument("dockerfile",
>>> +                        help="Dockerfile name")
>>> +    parser.add_argument("--verbose", "-v", action="store_true",
>>> +                        help="Print verbose information")
>>> +    args = parser.parse_args()
>>> +
>>> +    dockerfile = open(args.dockerfile, "rb").read()
>>> +    tag = args.tag
>>> +
>>> +    d = docker.Docker()
>>> +    if d.image_matches_dockerfile(tag, dockerfile):
>>> +        if args.verbose:
>>> +            print "Image is up to date."
>>> +        return 0
>>> +
>>> +    quiet = not args.verbose
>>> +    d.build_image(tag, dockerfile, args.dockerfile, quiet=quiet)
>>> +    return 0
>>> +
>>> +if __name__ == "__main__":
>>> +    sys.exit(main())
>>> diff --git a/tests/docker/docker_clean b/tests/docker/docker_clean
>>> new file mode 100755
>>> index 0000000..88cdba6
>>> --- /dev/null
>>> +++ b/tests/docker/docker_clean
>>> @@ -0,0 +1,22 @@
>>> +#!/usr/bin/env python2
>>> +#
>>> +# Clean up uselsee containers.
>>> +#
>>> +# Copyright (c) 2016 Red Hat Inc.
>>> +#
>>> +# Authors:
>>> +#  Fam Zheng <famz@redhat.com>
>>> +#
>>> +# This work is licensed under the terms of the GNU GPL, version 2
>>> +# or (at your option) any later version. See the COPYING file in
>>> +# the top-level directory.
>>> +
>>> +import sys
>>> +import docker
>>> +
>>> +def main():
>>> +    docker.Docker().clean()
>>> +    return 0
>>> +
>>> +if __name__ == "__main__":
>>> +    sys.exit(main())
>>> diff --git a/tests/docker/docker_run b/tests/docker/docker_run
>>> new file mode 100755
>>> index 0000000..5cf9d04
>>> --- /dev/null
>>> +++ b/tests/docker/docker_run
>>> @@ -0,0 +1,28 @@
>>> +#!/usr/bin/env python2
>>> +#
>>> +# Wrapper for "docker run" with automatical clean up if the execution is
>>> +# iterrupted.
>>> +#
>>> +# Copyright (c) 2016 Red Hat Inc.
>>> +#
>>> +# Authors:
>>> +#  Fam Zheng <famz@redhat.com>
>>> +#
>>> +# This work is licensed under the terms of the GNU GPL, version 2
>>> +# or (at your option) any later version. See the COPYING file in
>>> +# the top-level directory.
>>> +
>>> +import os
>>> +import sys
>>> +import argparse
>>> +import docker
>>> +
>>> +def main():
>>> +    parser = argparse.ArgumentParser()
>>> +    parser.add_argument("--quiet", action="store_true",
>>> +                        help="Run quietly unless an error occured")
>>> +    args, argv = parser.parse_known_args()
>>> +    return docker.Docker().run(argv, quiet=args.quiet)
>>> +
>>> +if __name__ == "__main__":
>>> +    sys.exit(main())
>>>
>>
>> -- 
>> —js

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (11 preceding siblings ...)
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 12/12] MAINTAINERS: Add tests/docker Fam Zheng
@ 2016-02-10 11:23 ` Alex Bennée
  2016-02-14  5:22   ` Fam Zheng
  2016-02-15 17:59 ` Alex Bennée
  13 siblings, 1 reply; 41+ messages in thread
From: Alex Bennée @ 2016-02-10 11:23 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> v1: Since RFC, addressed comments from reviewers, and improved a lot of things.
>     Thanks to Daniel, Eric, Paolo, Stefan, for the feedback.
>
> This series adds a new "docker" make target family to run tests in created
> docker containers.
>
> To begin with, this can be a place to store standard env/command combinations to
> build and test QEMU.
>
> Secondly, CI usually provides "docker" capability (such as travis [1]), where
> we define standard/repeatable test environments, and run tests in them.
> However, what tests to cover is better maintained in-tree, in order to keep in
> sync with the code development.

We've actually just switched to using Travis' containers for our builds
which I think don't allow the use of docker. This is because Travis has
more build capacity with the container infrastructure compared to the
old VM based solution.

That said that we could switch back.

>
> Lastly, this makes it very simple for developers to replicate such tests
> themselves.

However I think this is the most useful part. Making it easier for
developers to run tests on something other than their desktop. I shall
have a look through. Thanks!

>
> [1]: https://docs.travis-ci.com/user/docker/
>
> Fam Zheng (12):
>   tests: Add utilities for docker testing
>   Makefile: Rules for docker testing
>   docker: Add images
>   docker: Add test runner
>   docker: Add common.rc
>   docker: Add basic test
>   docker: Add clang test
>   docker: Add mingw test
>   docker: Add travis tool
>   docs: Add text for tests/docker in build-system.txt
>   .gitignore: Ignore temporary dockerfile
>   MAINTAINERS: Add tests/docker
>
>  .gitignore                    |   1 +
>  MAINTAINERS                   |   7 +++
>  Makefile                      |   4 +-
>  docs/build-system.txt         |   5 ++
>  tests/docker/Makefile.include |  88 ++++++++++++++++++++++++++++++++++
>  tests/docker/centos6.docker   |   5 ++
>  tests/docker/common.rc        |  28 +++++++++++
>  tests/docker/docker.py        | 108 ++++++++++++++++++++++++++++++++++++++++++
>  tests/docker/docker_build     |  42 ++++++++++++++++
>  tests/docker/docker_clean     |  22 +++++++++
>  tests/docker/docker_run       |  28 +++++++++++
>  tests/docker/fedora.docker    |   7 +++
>  tests/docker/run              |  23 +++++++++
>  tests/docker/test-basic.sh    |  22 +++++++++
>  tests/docker/test-clang.sh    |  26 ++++++++++
>  tests/docker/test-mingw.sh    |  34 +++++++++++++
>  tests/docker/travis.py        |  53 +++++++++++++++++++++
>  tests/docker/travis.sh        |  20 ++++++++
>  tests/docker/ubuntu.docker    |   9 ++++
>  19 files changed, 531 insertions(+), 1 deletion(-)
>  create mode 100644 tests/docker/Makefile.include
>  create mode 100644 tests/docker/centos6.docker
>  create mode 100755 tests/docker/common.rc
>  create mode 100755 tests/docker/docker.py
>  create mode 100755 tests/docker/docker_build
>  create mode 100755 tests/docker/docker_clean
>  create mode 100755 tests/docker/docker_run
>  create mode 100644 tests/docker/fedora.docker
>  create mode 100755 tests/docker/run
>  create mode 100755 tests/docker/test-basic.sh
>  create mode 100755 tests/docker/test-clang.sh
>  create mode 100755 tests/docker/test-mingw.sh
>  create mode 100755 tests/docker/travis.py
>  create mode 100755 tests/docker/travis.sh
>  create mode 100644 tests/docker/ubuntu.docker


--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 01/12] tests: Add utilities for docker testing
  2016-02-09 23:16       ` John Snow
@ 2016-02-14  5:10         ` Fam Zheng
  0 siblings, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-14  5:10 UTC (permalink / raw)
  To: John Snow
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	Alex Bennée, david

On Tue, 02/09 18:16, John Snow wrote:
> Sure, but the failure here is not particularly obvious, because it makes
> it seem as if docker has failed instead of a sudo privilege situation.

Of course you're right, I'll improve the error message.  Thanks!

Fam

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests
  2016-02-10 11:23 ` [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Alex Bennée
@ 2016-02-14  5:22   ` Fam Zheng
  0 siblings, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-14  5:22 UTC (permalink / raw)
  To: Alex Bennée
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david

On Wed, 02/10 11:23, Alex Bennée wrote:
> > To begin with, this can be a place to store standard env/command combinations to
> > build and test QEMU.
> >
> > Secondly, CI usually provides "docker" capability (such as travis [1]), where
> > we define standard/repeatable test environments, and run tests in them.
> > However, what tests to cover is better maintained in-tree, in order to keep in
> > sync with the code development.
> 
> We've actually just switched to using Travis' containers for our builds
> which I think don't allow the use of docker. This is because Travis has
> more build capacity with the container infrastructure compared to the
> old VM based solution.

Sure, we should still keep testing matrix for Travis in .travis.yml.

The actual background of this is I'm trying to make progress on Patchew
(apologies, it's going slow), for which I still want all the build flags to be
maintained in qemu.git, hence the "make docker" commands.

> >
> > Lastly, this makes it very simple for developers to replicate such tests
> > themselves.
> 
> However I think this is the most useful part. Making it easier for
> developers to run tests on something other than their desktop. I shall
> have a look through. Thanks!

Especially so when a patch contributor gets an automatical reply to their
patches about a build/test failure and he/she is up to fix it.

Fam

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 02/12] Makefile: Rules for docker testing
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 02/12] Makefile: Rules " Fam Zheng
@ 2016-02-15 10:06   ` Alex Bennée
  2016-02-15 13:52     ` Fam Zheng
  0 siblings, 1 reply; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 10:06 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> This adds a group of make targets to run docker tests, all are available
> in source tree without running ./configure.
>
> The usage is shown by "make docker".
>
> Besides the fixed ones, dynamic targets for building each image and
> running each test in each image are generated automatically by make,
> scanning $(SRC_PATH)/tests/docker/ files with specific patterns.
>
> Alternative to manually list particular targets (docker-run-FOO@BAR)
> set, you can control which tests/images to run by filtering variables,
> TESTS= and IMAGES=, which are expressed in Makefile pattern syntax,
> "foo% %bar ...". For example:
>
>     $ make docker-run IMAGES="ubuntu fedora"

This could do with repeating in the docs so that you don't need to
search commits for example invocations.

>
> Unfortunately, it's impossible to propagate "-j $JOBS" into make in
> containers, however since each combination is made a first class target
> is the top Makefile, "make -j$N docker-run" still parallels the tests
> coarsely.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  Makefile                      |  4 +-
>  tests/docker/Makefile.include | 88 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 91 insertions(+), 1 deletion(-)
>  create mode 100644 tests/docker/Makefile.include
>
> diff --git a/Makefile b/Makefile
> index d0de2d4..7da70f4 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,5 @@ endif
>  # Include automatically generated dependency files
>  # Dependencies in Makefile.objs files come from our recursive subdir rules
>  -include $(wildcard *.d tests/*.d)
> +
> +include $(SRC_PATH)/tests/docker/Makefile.include
> diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
> new file mode 100644
> index 0000000..ca84c35
> --- /dev/null
> +++ b/tests/docker/Makefile.include
> @@ -0,0 +1,88 @@
> +# Makefile for Docker tests
> +
> +$(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
> +
> +.PHONY: docker docker-build docker-run docker-clean
> +
> +DOCKER_SUFFIX = .docker
> +
> +DOCKER_IMAGES := $(patsubst %$(DOCKER_SUFFIX),%, $(shell \
> +	ls $(SRC_PATH)/tests/docker/ | grep '$(DOCKER_SUFFIX)$$'))
> +
> +DOCKER_SCRIPTS := $(shell ls $(SRC_PATH)/tests/docker/ | grep '\.sh$$')
> +DOCKER_TESTS := $(filter test-%, $(DOCKER_SCRIPTS))
> +DOCKER_TOOLS := $(filter-out test-%, $(DOCKER_SCRIPTS))
> +
> +TESTS ?= %
> +IMAGES ?= %
> +
> +$(foreach i,$(DOCKER_IMAGES), \
> +	$(eval docker-build: docker-build-$i) \
> +	$(foreach t,$(DOCKER_SCRIPTS), \
> +		$(eval docker-build-$i docker-run-$t@$i: IMAGE=$i) \
> +		$(eval docker-run-$t@$i: SCRIPT=$t) \
> +		$(eval docker-run-$t@$i: docker-build-$i) \
> +		$(if $(filter test-%,$t), \
> +			$(eval docker-run: docker-run-$t@$i) \
> +			$(eval docker-run-$t@: docker-run-$t@$i) \
> +			$(eval docker-run-@$i: docker-run-$t@$i)) \
> +))
> +
> +docker:
> +	@echo 'Building QEMU and running tests or tools inside Docker containers'
> +	@echo
> +	@echo 'Available targets:'
> +	@echo
> +	@echo '    docker:              Print this help.'
> +	@echo '    docker-run:          Run all image/test combinations.'
> +	@echo '                         You can override the test cases to run by providing'
> +	@echo '                         TESTS="foo bar" in the make command, and the image set'
> +	@echo '                         by providing IMAGES="baz qux".'
> +	@echo '    docker-clean:        Kill and remove residual docker testing containers.'
> +	@echo '    docker-build:        Build all images.'
> +	@echo '    docker-build-IMG:    Build image "IMG".'
> +	@echo '                         "IMG" is one of the listed image name."'
> +	@echo '    docker-run-FOO@BAR:  Run "FOO" in container "BAR".'
> +	@echo '                         "FOO" must be one of the listed test/tool name."'
> +	@echo '                         "BAR" must be one of the listed image name."'
> +	@echo '    docker-run-FOO@:     Run "FOO" in all containers.'
> +	@echo '                         "FOO" must be one of the listed test name."'
> +	@echo '    docker-run-@BAR:     Run all tests in container "BAR".'
> +	@echo '                         "BAR" must be one of the listed image name."'
> +	@echo
> +	@echo 'Available images:'
> +	@echo '    $(DOCKER_IMAGES)'
> +	@echo
> +	@echo 'Available tests:'
> +	@echo '    $(DOCKER_TESTS)'
> +	@echo
> +	@echo 'Available tools:'
> +	@echo '    $(DOCKER_TOOLS)'

I commend the addition of help ;-)

Perhaps replace FOO and BAR with TEST and IMAGE to cement the actual
rather than the abstract in the readers mind.

Also I expected this to work:

$ make docker-run-basic@fedora
Invalid target
make: *** [docker-run-basic@fedora] Error 1

The help gives:

  Available images:
      centos6 fedora ubuntu

  Available tests:
      test-basic.sh test-clang.sh test-mingw.sh

  Available tools:
      travis.sh

The test and .sh seem superfluous to the user wanting to invoke things.
We know they are tests and the implementation detail of the shell should
be irrelevant to the user.


> +
> +docker-build-%:
> +	@if test -z "$(IMAGE)"; then echo "Invalid target"; exit 1; fi
> +	$(if $(filter $(IMAGES),$(IMAGE)), $(call quiet-command,\
> +		$(SRC_PATH)/tests/docker/docker_build qemu:$(IMAGE) \
> +			$(SRC_PATH)/tests/docker/$(IMAGE).docker \
> +			$(if $V,-v,), "  BUILD $(IMAGE)"))
> +
> +docker-run-%:
> +	@if test -z "$(IMAGE)" || test -z "$(SCRIPT)"; \
> +		then echo "Invalid target"; exit 1; \
> +	fi
> +	$(if $(filter $(TESTS),$(SCRIPT)),$(if $(filter $(IMAGES),$(IMAGE)), \
> +		$(call quiet-command,\
> +			$(SRC_PATH)/tests/docker/docker_run \
> +				--privileged -t --rm --net=none \
> +				-v $$(realpath $(SRC_PATH)):/var/tmp/qemu \
> +				-e QEMU_SRC=/var/tmp/qemu \
> +				-e V=$(V) \
> +				-v /var/tmp/qemu-docker-ccache:/var/tmp/ccache \
> +				-e CCACHE_DIR=/var/tmp/ccache \
> +				qemu:$(IMAGE) \
> +				/var/tmp/qemu/tests/docker/run \
> +				/var/tmp/qemu/tests/docker/$(SCRIPT); \
> +			, "  RUN $(SCRIPT) in $(IMAGE)")))
> +
> +docker-clean:
> +	$(call quiet-command, $(SRC_PATH)/tests/docker/docker_clean)

Otherwise looking good. Thanks!

--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 03/12] docker: Add images
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 03/12] docker: Add images Fam Zheng
@ 2016-02-15 10:15   ` Alex Bennée
  2016-02-15 13:44     ` Fam Zheng
  0 siblings, 1 reply; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 10:15 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  tests/docker/centos6.docker | 5 +++++
>  tests/docker/fedora.docker  | 7 +++++++
>  tests/docker/ubuntu.docker  | 9 +++++++++
>  3 files changed, 21 insertions(+)
>  create mode 100644 tests/docker/centos6.docker
>  create mode 100644 tests/docker/fedora.docker
>  create mode 100644 tests/docker/ubuntu.docker
>
> diff --git a/tests/docker/centos6.docker b/tests/docker/centos6.docker
> new file mode 100644
> index 0000000..7daa2fb
> --- /dev/null
> +++ b/tests/docker/centos6.docker
> @@ -0,0 +1,5 @@
> +FROM centos:6
> +RUN yum install -y \
> +    git make gcc g++ \
> +    zlib-devel glib2-devel SDL-devel pixman-devel
> +
> diff --git a/tests/docker/fedora.docker b/tests/docker/fedora.docker
> new file mode 100644
> index 0000000..81091b7
> --- /dev/null
> +++ b/tests/docker/fedora.docker
> @@ -0,0 +1,7 @@
> +FROM fedora:23
> +RUN dnf install -y \
> +    ccache git \
> +    glib2-devel pixman-devel zlib-devel SDL-devel \
> +    gcc gcc-c++ clang make perl which bc findutils \
> +    mingw{32,64}-{pixman,glib2,gmp,SDL,pkg-config,gtk2,gtk3,gnutls,nettle,libtasn1,libjpeg-turbo,libpng,curl,libssh2,bzip2}
> +ENV FEATURES mingw clang
> diff --git a/tests/docker/ubuntu.docker b/tests/docker/ubuntu.docker
> new file mode 100644
> index 0000000..f1dc518
> --- /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
> +ENV FEATURES clang ccache pyyaml


How are we going to approach naming and upgrading of containers?

Here centos6 is named so explicitly where as fedora (which is a faster
moving project) will be replaced at some point. The ubuntu image is the
current LTS which will have a new release in a few months although the
LTS will be supported for some time.

Maybe we should call them fedora-current and ubuntu-lts?

--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 04/12] docker: Add test runner
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 04/12] docker: Add test runner Fam Zheng
@ 2016-02-15 10:55   ` Alex Bennée
  2016-02-15 12:45     ` Alex Bennée
  0 siblings, 1 reply; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 10:55 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> It's better to have a launcher for all tests, to make it easier to
> initialize and manage the environment.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  tests/docker/run | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>  create mode 100755 tests/docker/run
>
> diff --git a/tests/docker/run b/tests/docker/run
> new file mode 100755
> index 0000000..739ecf9
> --- /dev/null
> +++ b/tests/docker/run
> @@ -0,0 +1,23 @@
> +#!/bin/bash -e
> +#
> +# Docker test runner
> +#
> +# Copyright (c) 2016 Red Hat Inc.
> +#
> +# Authors:
> +#  Fam Zheng <famz@redhat.com>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2
> +# or (at your option) any later version. See the COPYING file in
> +# the top-level directory.
> +
> +# Prepare the environment
> +. /etc/profile || true
> +export PATH=/usr/lib/ccache:$PATH
> +
> +tmp=$QEMU_SRC
> +QEMU_SRC=/var/tmp/qemu.tmp
> +cp -r $tmp $QEMU_SRC

The first time I ran the fedora target it seems to hang, the second time
with V=1 it reported my source tree was an in-tree build.

Could we perhaps use git-archive to grab a pristine copy of the tree?
Something like:

STATUS=`git stash create`
git archive -1 ${STATUS} -o ${TAR}

Would give a clean source tree with current unstaged/uncommited files.
Unfortunately this wouldn't include new files yet to be committed in any
form to the source tree but using git stash save -u might include a
bunch of unwanted stuff.

> +
> +cd $QEMU_SRC/tests/docker
> +"$@"


--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 04/12] docker: Add test runner
  2016-02-15 10:55   ` Alex Bennée
@ 2016-02-15 12:45     ` Alex Bennée
  2016-02-15 13:29       ` Fam Zheng
  0 siblings, 1 reply; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 12:45 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Alex Bennée <alex.bennee@linaro.org> writes:

> Fam Zheng <famz@redhat.com> writes:
>
>> It's better to have a launcher for all tests, to make it easier to
>> initialize and manage the environment.
>>
>> Signed-off-by: Fam Zheng <famz@redhat.com>
>> ---
>>  tests/docker/run | 23 +++++++++++++++++++++++
>>  1 file changed, 23 insertions(+)
>>  create mode 100755 tests/docker/run
>>
>> diff --git a/tests/docker/run b/tests/docker/run
>> new file mode 100755
>> index 0000000..739ecf9
>> --- /dev/null
>> +++ b/tests/docker/run
>> @@ -0,0 +1,23 @@
>> +#!/bin/bash -e
>> +#
>> +# Docker test runner
>> +#
>> +# Copyright (c) 2016 Red Hat Inc.
>> +#
>> +# Authors:
>> +#  Fam Zheng <famz@redhat.com>
>> +#
>> +# This work is licensed under the terms of the GNU GPL, version 2
>> +# or (at your option) any later version. See the COPYING file in
>> +# the top-level directory.
>> +
>> +# Prepare the environment
>> +. /etc/profile || true
>> +export PATH=/usr/lib/ccache:$PATH
>> +
>> +tmp=$QEMU_SRC
>> +QEMU_SRC=/var/tmp/qemu.tmp
>> +cp -r $tmp $QEMU_SRC
>
> The first time I ran the fedora target it seems to hang, the second time
> with V=1 it reported my source tree was an in-tree build.
>
> Could we perhaps use git-archive to grab a pristine copy of the tree?
> Something like:
>
> STATUS=`git stash create`
> git archive -1 ${STATUS} -o ${TAR}
>
> Would give a clean source tree with current unstaged/uncommited files.
> Unfortunately this wouldn't include new files yet to be committed in any
> form to the source tree but using git stash save -u might include a
> bunch of unwanted stuff.

OK that won't work if you have alternates in your git setup. It seems to
me the creation of the pristine tree for docker should be done before we
enter the docker environment.

There is a slight wrinkle as to what happens if the user wants to enter
an interactive session for debugging. However that doesn't seem possible
via the makefile and perhaps that is just as well. Perhaps that should
be a helper script for the user?

>
>> +
>> +cd $QEMU_SRC/tests/docker
>> +"$@"


--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 04/12] docker: Add test runner
  2016-02-15 12:45     ` Alex Bennée
@ 2016-02-15 13:29       ` Fam Zheng
  2016-02-15 14:10         ` Alex Bennée
  0 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-15 13:29 UTC (permalink / raw)
  To: Alex Bennée
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david

On Mon, 02/15 12:45, Alex Bennée wrote:
> 
> Alex Bennée <alex.bennee@linaro.org> writes:
> 
> > Fam Zheng <famz@redhat.com> writes:
> >
> >> It's better to have a launcher for all tests, to make it easier to
> >> initialize and manage the environment.
> >>
> >> Signed-off-by: Fam Zheng <famz@redhat.com>
> >> ---
> >>  tests/docker/run | 23 +++++++++++++++++++++++
> >>  1 file changed, 23 insertions(+)
> >>  create mode 100755 tests/docker/run
> >>
> >> diff --git a/tests/docker/run b/tests/docker/run
> >> new file mode 100755
> >> index 0000000..739ecf9
> >> --- /dev/null
> >> +++ b/tests/docker/run
> >> @@ -0,0 +1,23 @@
> >> +#!/bin/bash -e
> >> +#
> >> +# Docker test runner
> >> +#
> >> +# Copyright (c) 2016 Red Hat Inc.
> >> +#
> >> +# Authors:
> >> +#  Fam Zheng <famz@redhat.com>
> >> +#
> >> +# This work is licensed under the terms of the GNU GPL, version 2
> >> +# or (at your option) any later version. See the COPYING file in
> >> +# the top-level directory.
> >> +
> >> +# Prepare the environment
> >> +. /etc/profile || true
> >> +export PATH=/usr/lib/ccache:$PATH
> >> +
> >> +tmp=$QEMU_SRC
> >> +QEMU_SRC=/var/tmp/qemu.tmp
> >> +cp -r $tmp $QEMU_SRC
> >
> > The first time I ran the fedora target it seems to hang, the second time
> > with V=1 it reported my source tree was an in-tree build.
> >
> > Could we perhaps use git-archive to grab a pristine copy of the tree?
> > Something like:
> >
> > STATUS=`git stash create`
> > git archive -1 ${STATUS} -o ${TAR}
> >
> > Would give a clean source tree with current unstaged/uncommited files.
> > Unfortunately this wouldn't include new files yet to be committed in any
> > form to the source tree but using git stash save -u might include a
> > bunch of unwanted stuff.
> 
> OK that won't work if you have alternates in your git setup. It seems to
> me the creation of the pristine tree for docker should be done before we
> enter the docker environment.
> 
> There is a slight wrinkle as to what happens if the user wants to enter
> an interactive session for debugging. However that doesn't seem possible
> via the makefile and perhaps that is just as well. Perhaps that should
> be a helper script for the user?

We can use "make distclean" in the copied tree.

Fam

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 03/12] docker: Add images
  2016-02-15 10:15   ` Alex Bennée
@ 2016-02-15 13:44     ` Fam Zheng
  2016-02-15 14:12       ` Alex Bennée
  0 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-15 13:44 UTC (permalink / raw)
  To: Alex Bennée
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david

On Mon, 02/15 10:15, Alex Bennée wrote:
> 
> Fam Zheng <famz@redhat.com> writes:
> 
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  tests/docker/centos6.docker | 5 +++++
> >  tests/docker/fedora.docker  | 7 +++++++
> >  tests/docker/ubuntu.docker  | 9 +++++++++
> >  3 files changed, 21 insertions(+)
> >  create mode 100644 tests/docker/centos6.docker
> >  create mode 100644 tests/docker/fedora.docker
> >  create mode 100644 tests/docker/ubuntu.docker
> >
> > diff --git a/tests/docker/centos6.docker b/tests/docker/centos6.docker
> > new file mode 100644
> > index 0000000..7daa2fb
> > --- /dev/null
> > +++ b/tests/docker/centos6.docker
> > @@ -0,0 +1,5 @@
> > +FROM centos:6
> > +RUN yum install -y \
> > +    git make gcc g++ \
> > +    zlib-devel glib2-devel SDL-devel pixman-devel
> > +
> > diff --git a/tests/docker/fedora.docker b/tests/docker/fedora.docker
> > new file mode 100644
> > index 0000000..81091b7
> > --- /dev/null
> > +++ b/tests/docker/fedora.docker
> > @@ -0,0 +1,7 @@
> > +FROM fedora:23
> > +RUN dnf install -y \
> > +    ccache git \
> > +    glib2-devel pixman-devel zlib-devel SDL-devel \
> > +    gcc gcc-c++ clang make perl which bc findutils \
> > +    mingw{32,64}-{pixman,glib2,gmp,SDL,pkg-config,gtk2,gtk3,gnutls,nettle,libtasn1,libjpeg-turbo,libpng,curl,libssh2,bzip2}
> > +ENV FEATURES mingw clang
> > diff --git a/tests/docker/ubuntu.docker b/tests/docker/ubuntu.docker
> > new file mode 100644
> > index 0000000..f1dc518
> > --- /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
> > +ENV FEATURES clang ccache pyyaml
> 
> 
> How are we going to approach naming and upgrading of containers?
> 
> Here centos6 is named so explicitly where as fedora (which is a faster
> moving project) will be replaced at some point. The ubuntu image is the
> current LTS which will have a new release in a few months although the
> LTS will be supported for some time.
> 
> Maybe we should call them fedora-current and ubuntu-lts?

I wanted to make the names short and easy to remember.  For now I think
diversity is more interesting than variations in one distro family, that's why
I didn't really care whether it is ubuntu-latest or LTS, and chose 14.04
arbitrarily.

Replacing fedora 23 with future versions only takes one line change in
fedora.docker, and a subsequent "make docker-test-*@fedora" will make sure the
container image is rebuilt. (It's what tests/docker/docker_build does.)

After all x64 Linuxs are very alike when Mac, Windows and non-x86 hosts are
also in the picture, and it would be great if we could cover at least some of
them here.

Fam

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 02/12] Makefile: Rules for docker testing
  2016-02-15 10:06   ` Alex Bennée
@ 2016-02-15 13:52     ` Fam Zheng
  2016-02-15 14:13       ` Alex Bennée
  0 siblings, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-15 13:52 UTC (permalink / raw)
  To: Alex Bennée
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david

On Mon, 02/15 10:06, Alex Bennée wrote:
> 
> Fam Zheng <famz@redhat.com> writes:
> 
> > This adds a group of make targets to run docker tests, all are available
> > in source tree without running ./configure.
> >
> > The usage is shown by "make docker".
> >
> > Besides the fixed ones, dynamic targets for building each image and
> > running each test in each image are generated automatically by make,
> > scanning $(SRC_PATH)/tests/docker/ files with specific patterns.
> >
> > Alternative to manually list particular targets (docker-run-FOO@BAR)
> > set, you can control which tests/images to run by filtering variables,
> > TESTS= and IMAGES=, which are expressed in Makefile pattern syntax,
> > "foo% %bar ...". For example:
> >
> >     $ make docker-run IMAGES="ubuntu fedora"
> 
> This could do with repeating in the docs so that you don't need to
> search commits for example invocations.

Okay.

> 
> >
> > Unfortunately, it's impossible to propagate "-j $JOBS" into make in
> > containers, however since each combination is made a first class target
> > is the top Makefile, "make -j$N docker-run" still parallels the tests
> > coarsely.
> >
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  Makefile                      |  4 +-
> >  tests/docker/Makefile.include | 88 +++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 91 insertions(+), 1 deletion(-)
> >  create mode 100644 tests/docker/Makefile.include
> >
> > diff --git a/Makefile b/Makefile
> > index d0de2d4..7da70f4 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,5 @@ endif
> >  # Include automatically generated dependency files
> >  # Dependencies in Makefile.objs files come from our recursive subdir rules
> >  -include $(wildcard *.d tests/*.d)
> > +
> > +include $(SRC_PATH)/tests/docker/Makefile.include
> > diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
> > new file mode 100644
> > index 0000000..ca84c35
> > --- /dev/null
> > +++ b/tests/docker/Makefile.include
> > @@ -0,0 +1,88 @@
> > +# Makefile for Docker tests
> > +
> > +$(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
> > +
> > +.PHONY: docker docker-build docker-run docker-clean
> > +
> > +DOCKER_SUFFIX = .docker
> > +
> > +DOCKER_IMAGES := $(patsubst %$(DOCKER_SUFFIX),%, $(shell \
> > +	ls $(SRC_PATH)/tests/docker/ | grep '$(DOCKER_SUFFIX)$$'))
> > +
> > +DOCKER_SCRIPTS := $(shell ls $(SRC_PATH)/tests/docker/ | grep '\.sh$$')
> > +DOCKER_TESTS := $(filter test-%, $(DOCKER_SCRIPTS))
> > +DOCKER_TOOLS := $(filter-out test-%, $(DOCKER_SCRIPTS))
> > +
> > +TESTS ?= %
> > +IMAGES ?= %
> > +
> > +$(foreach i,$(DOCKER_IMAGES), \
> > +	$(eval docker-build: docker-build-$i) \
> > +	$(foreach t,$(DOCKER_SCRIPTS), \
> > +		$(eval docker-build-$i docker-run-$t@$i: IMAGE=$i) \
> > +		$(eval docker-run-$t@$i: SCRIPT=$t) \
> > +		$(eval docker-run-$t@$i: docker-build-$i) \
> > +		$(if $(filter test-%,$t), \
> > +			$(eval docker-run: docker-run-$t@$i) \
> > +			$(eval docker-run-$t@: docker-run-$t@$i) \
> > +			$(eval docker-run-@$i: docker-run-$t@$i)) \
> > +))
> > +
> > +docker:
> > +	@echo 'Building QEMU and running tests or tools inside Docker containers'
> > +	@echo
> > +	@echo 'Available targets:'
> > +	@echo
> > +	@echo '    docker:              Print this help.'
> > +	@echo '    docker-run:          Run all image/test combinations.'
> > +	@echo '                         You can override the test cases to run by providing'
> > +	@echo '                         TESTS="foo bar" in the make command, and the image set'
> > +	@echo '                         by providing IMAGES="baz qux".'
> > +	@echo '    docker-clean:        Kill and remove residual docker testing containers.'
> > +	@echo '    docker-build:        Build all images.'
> > +	@echo '    docker-build-IMG:    Build image "IMG".'
> > +	@echo '                         "IMG" is one of the listed image name."'
> > +	@echo '    docker-run-FOO@BAR:  Run "FOO" in container "BAR".'
> > +	@echo '                         "FOO" must be one of the listed test/tool name."'
> > +	@echo '                         "BAR" must be one of the listed image name."'
> > +	@echo '    docker-run-FOO@:     Run "FOO" in all containers.'
> > +	@echo '                         "FOO" must be one of the listed test name."'
> > +	@echo '    docker-run-@BAR:     Run all tests in container "BAR".'
> > +	@echo '                         "BAR" must be one of the listed image name."'
> > +	@echo
> > +	@echo 'Available images:'
> > +	@echo '    $(DOCKER_IMAGES)'
> > +	@echo
> > +	@echo 'Available tests:'
> > +	@echo '    $(DOCKER_TESTS)'
> > +	@echo
> > +	@echo 'Available tools:'
> > +	@echo '    $(DOCKER_TOOLS)'
> 
> I commend the addition of help ;-)
> 
> Perhaps replace FOO and BAR with TEST and IMAGE to cement the actual
> rather than the abstract in the readers mind.

OK!

> 
> Also I expected this to work:
> 
> $ make docker-run-basic@fedora
> Invalid target
> make: *** [docker-run-basic@fedora] Error 1
> 
> The help gives:
> 
>   Available images:
>       centos6 fedora ubuntu
> 
>   Available tests:
>       test-basic.sh test-clang.sh test-mingw.sh
> 
>   Available tools:
>       travis.sh
> 
> The test and .sh seem superfluous to the user wanting to invoke things.
> We know they are tests and the implementation detail of the shell should
> be irrelevant to the user.

I want to distinguish tests from usual tools by prefix (test-).  Tools
shouldn't be invoked by "make docker-run".

I'll remove the .sh suffixes, and "s/docker-run-FOO/docker-FOO/". Then you
just:

    $ make docker-test-basic@fedora
    $ make docker-travis@fedora

Thanks,
Fam

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 04/12] docker: Add test runner
  2016-02-15 13:29       ` Fam Zheng
@ 2016-02-15 14:10         ` Alex Bennée
  2016-02-16  2:52           ` Fam Zheng
  2016-02-16  6:00           ` Fam Zheng
  0 siblings, 2 replies; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 14:10 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> On Mon, 02/15 12:45, Alex Bennée wrote:
>>
>> Alex Bennée <alex.bennee@linaro.org> writes:
>>
>> > Fam Zheng <famz@redhat.com> writes:
>> >
>> >> It's better to have a launcher for all tests, to make it easier to
>> >> initialize and manage the environment.
>> >>
>> >> Signed-off-by: Fam Zheng <famz@redhat.com>
>> >> ---
>> >>  tests/docker/run | 23 +++++++++++++++++++++++
>> >>  1 file changed, 23 insertions(+)
>> >>  create mode 100755 tests/docker/run
>> >>
<snip>
>> OK that won't work if you have alternates in your git setup. It seems to
>> me the creation of the pristine tree for docker should be done before we
>> enter the docker environment.
>>
>> There is a slight wrinkle as to what happens if the user wants to enter
>> an interactive session for debugging. However that doesn't seem possible
>> via the makefile and perhaps that is just as well. Perhaps that should
>> be a helper script for the user?
>
> We can use "make distclean" in the copied tree.

I wouldn't - distclean isn't always that clean due to *mumble mumble*
makefile reasons. You could try this approach:

commit f838d3bbe2f71c731dfe172f1c3286084de203c8
Author: Alex Bennée <alex.bennee@linaro.org>
Date:   Mon Feb 15 12:52:21 2016 +0000

    tests/docker/Makefile.include: snapshot the src for docker

    Instead of providing a live version of the source tree to the docker
    container we snapshot it with git-archive. This ensure the tree is in a
    pristine state for whatever operations the container is going to run on
    them.

    Uncommitted changes known to files known by the git index will be
    included in the snapshot if there are any.

    Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
index ca84c35..63a799c 100644
--- a/tests/docker/Makefile.include
+++ b/tests/docker/Makefile.include
@@ -2,7 +2,7 @@

 $(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))

-.PHONY: docker docker-build docker-run docker-clean
+.PHONY: docker docker-build docker-qemu-src docker-run docker-clean

 DOCKER_SUFFIX = .docker

@@ -16,12 +16,17 @@ DOCKER_TOOLS := $(filter-out test-%, $(DOCKER_SCRIPTS))
 TESTS ?= %
 IMAGES ?= %

+docker-qemu-src:
+	$(if git diff-index --quiet HEAD --, 										\
+		git archive -1 HEAD --prefix=qemu-docker-snapshot/ --format=tar.gz | tar -xz -C /tmp,			\
+		git archive -1 `git stash create` --prefix=qemu-docker-snapshot/ --format=tar.gz | tar -xz -C /tmp)
+
 $(foreach i,$(DOCKER_IMAGES), \
        $(eval docker-build: docker-build-$i) \
        $(foreach t,$(DOCKER_SCRIPTS), \
                $(eval docker-build-$i docker-run-$t@$i: IMAGE=$i) \
                $(eval docker-run-$t@$i: SCRIPT=$t) \
-		$(eval docker-run-$t@$i: docker-build-$i) \
+		$(eval docker-run-$t@$i: docker-build-$i docker-qemu-src) \
                $(if $(filter test-%,$t), \
                        $(eval docker-run: docker-run-$t@$i) \
                        $(eval docker-run-$t@: docker-run-$t@$i) \
@@ -74,7 +79,7 @@ docker-run-%:
                $(call quiet-command,\
                        $(SRC_PATH)/tests/docker/docker_run \
                                --privileged -t --rm --net=none \
-				-v $$(realpath $(SRC_PATH)):/var/tmp/qemu \
+				-v $$(realpath /tmp/qemu-docker-snapshot/):/var/tmp/qemu \
                                -e QEMU_SRC=/var/tmp/qemu \
                                -e V=$(V) \
                                -v /var/tmp/qemu-docker-ccache:/var/tmp/ccache \


>
> Fam


--
Alex Bennée

^ permalink raw reply related	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 03/12] docker: Add images
  2016-02-15 13:44     ` Fam Zheng
@ 2016-02-15 14:12       ` Alex Bennée
  0 siblings, 0 replies; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 14:12 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> On Mon, 02/15 10:15, Alex Bennée wrote:
>>
>> Fam Zheng <famz@redhat.com> writes:
>>
>> > Signed-off-by: Fam Zheng <famz@redhat.com>
>> > ---
>> >  tests/docker/centos6.docker | 5 +++++
>> >  tests/docker/fedora.docker  | 7 +++++++
>> >  tests/docker/ubuntu.docker  | 9 +++++++++
>> >  3 files changed, 21 insertions(+)
>> >  create mode 100644 tests/docker/centos6.docker
>> >  create mode 100644 tests/docker/fedora.docker
>> >  create mode 100644 tests/docker/ubuntu.docker
>> >
>> > diff --git a/tests/docker/centos6.docker b/tests/docker/centos6.docker
>> > new file mode 100644
>> > index 0000000..7daa2fb
>> > --- /dev/null
>> > +++ b/tests/docker/centos6.docker
>> > @@ -0,0 +1,5 @@
>> > +FROM centos:6
>> > +RUN yum install -y \
>> > +    git make gcc g++ \
>> > +    zlib-devel glib2-devel SDL-devel pixman-devel
>> > +
>> > diff --git a/tests/docker/fedora.docker b/tests/docker/fedora.docker
>> > new file mode 100644
>> > index 0000000..81091b7
>> > --- /dev/null
>> > +++ b/tests/docker/fedora.docker
>> > @@ -0,0 +1,7 @@
>> > +FROM fedora:23
>> > +RUN dnf install -y \
>> > +    ccache git \
>> > +    glib2-devel pixman-devel zlib-devel SDL-devel \
>> > +    gcc gcc-c++ clang make perl which bc findutils \
>> > +    mingw{32,64}-{pixman,glib2,gmp,SDL,pkg-config,gtk2,gtk3,gnutls,nettle,libtasn1,libjpeg-turbo,libpng,curl,libssh2,bzip2}
>> > +ENV FEATURES mingw clang
>> > diff --git a/tests/docker/ubuntu.docker b/tests/docker/ubuntu.docker
>> > new file mode 100644
>> > index 0000000..f1dc518
>> > --- /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
>> > +ENV FEATURES clang ccache pyyaml
>>
>>
>> How are we going to approach naming and upgrading of containers?
>>
>> Here centos6 is named so explicitly where as fedora (which is a faster
>> moving project) will be replaced at some point. The ubuntu image is the
>> current LTS which will have a new release in a few months although the
>> LTS will be supported for some time.
>>
>> Maybe we should call them fedora-current and ubuntu-lts?
>
> I wanted to make the names short and easy to remember.  For now I think
> diversity is more interesting than variations in one distro family, that's why
> I didn't really care whether it is ubuntu-latest or LTS, and chose 14.04
> arbitrarily.

Well we care enough for centos. I would at least like to check against
debian-stable and debian-testing because a testing target would give us
advanced notice of distro breaking changes.

>
> Replacing fedora 23 with future versions only takes one line change in
> fedora.docker, and a subsequent "make docker-test-*@fedora" will make sure the
> container image is rebuilt. (It's what tests/docker/docker_build does.)
>
> After all x64 Linuxs are very alike when Mac, Windows and non-x86 hosts are
> also in the picture, and it would be great if we could cover at least some of
> them here.

I'm experimenting with docker on aarch64 ATM so I'll see what happens
with these scripts there ;-)

>
> Fam


--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 02/12] Makefile: Rules for docker testing
  2016-02-15 13:52     ` Fam Zheng
@ 2016-02-15 14:13       ` Alex Bennée
  0 siblings, 0 replies; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 14:13 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> On Mon, 02/15 10:06, Alex Bennée wrote:
>>
>> Fam Zheng <famz@redhat.com> writes:
>>
<snip>
>
> I want to distinguish tests from usual tools by prefix (test-).  Tools
> shouldn't be invoked by "make docker-run".

OK fair enough.

>
> I'll remove the .sh suffixes, and "s/docker-run-FOO/docker-FOO/". Then you
> just:
>
>     $ make docker-test-basic@fedora
>     $ make docker-travis@fedora

Sounds great, thanks ;-)

>
> Thanks,
> Fam


--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 06/12] docker: Add basic test
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 06/12] docker: Add basic test Fam Zheng
@ 2016-02-15 14:34   ` Alex Bennée
  2016-02-15 14:42     ` Peter Maydell
  0 siblings, 1 reply; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 14:34 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  tests/docker/test-basic.sh | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>  create mode 100755 tests/docker/test-basic.sh
>
> diff --git a/tests/docker/test-basic.sh b/tests/docker/test-basic.sh
> new file mode 100755
> index 0000000..c2b32ad
> --- /dev/null
> +++ b/tests/docker/test-basic.sh
> @@ -0,0 +1,22 @@
> +#!/bin/bash -e
> +#
> +# Basic compiling test that everyone already does. But why not automate it?
> +#
> +# Copyright (c) 2016 Red Hat Inc.
> +#
> +# Authors:
> +#  Fam Zheng <famz@redhat.com>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2
> +# or (at your option) any later version. See the COPYING file in
> +# the top-level directory.
> +
> +. common.rc
> +
> +cd $(mktemp -d)
> +mkdir build
> +mkdir install
> +cd build
> +build_qemu --target-list=x86_64-softmmu --prefix="${pwd}/install"
> +make check $MAKEFLAGS
> +make install

>From my excursions last week into the tests directory I discovered the
unit tests are built for a number of different qtest binaries. For
completeness we should probably include the whole list:

#+name: qtest-targets
#+begin_src sh :dir ~/lsrc/qemu/qemu.git :results scalar
grep -E "check-qtest-[[:alnum:]]+-y " tests/Makefile | cut -d " " -f 1 | sort -u
#+end_src

#+RESULTS: qtest-targets
#+begin_example
check-qtest-arm-y
check-qtest-generic-y
check-qtest-i386-y
check-qtest-ipack-y
check-qtest-microblazeel-y
check-qtest-mips64el-y
check-qtest-mips64-y
check-qtest-mips-y
check-qtest-pci-y
check-qtest-ppc64-y
check-qtest-ppc-y
check-qtest-sh4eb-y
check-qtest-sh4-y
#check-qtest-sparc64-y
check-qtest-sparc64-y
#check-qtest-sparc-y
check-qtest-virtioserial-y
check-qtest-virtio-y
check-qtest-x86_64-y
check-qtest-xtensaeb-y
check-qtest-y
#+end_example


--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 12/12] MAINTAINERS: Add tests/docker
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 12/12] MAINTAINERS: Add tests/docker Fam Zheng
@ 2016-02-15 14:36   ` Alex Bennée
  0 siblings, 0 replies; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 14:36 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  MAINTAINERS | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index b6ed87a..f24a449 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1573,3 +1573,10 @@ Build system architecture
>  M: Daniel P. Berrange <berrange@redhat.com>
>  S: Odd Fixes
>  F: docs/build-system.txt
> +
> +Docker testing
> +--------------
> +Docker based testing framework and cases
> +M: Fam Zheng <famz@redhat.com>
> +S: Maintained
> +F: tests/docker/

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 11/12] .gitignore: Ignore temporary dockerfile
  2016-02-05  9:24 ` [Qemu-devel] [PATCH 11/12] .gitignore: Ignore temporary dockerfile Fam Zheng
@ 2016-02-15 14:42   ` Alex Bennée
  2016-02-16  2:43     ` Fam Zheng
  0 siblings, 1 reply; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 14:42 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  .gitignore | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/.gitignore b/.gitignore
> index 88a80ff..a335b7b 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -109,3 +109,4 @@ cscope.*
>  tags
>  TAGS
>  *~
> +/tests/docker/*.docker.tmp

Is this left over from the python bindings called in docker_build? If so
can we say so in the commit if we can't persuade the bindings to not
clutter up the tree?

--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 06/12] docker: Add basic test
  2016-02-15 14:34   ` Alex Bennée
@ 2016-02-15 14:42     ` Peter Maydell
  2016-02-15 14:52       ` Alex Bennée
  0 siblings, 1 reply; 41+ messages in thread
From: Peter Maydell @ 2016-02-15 14:42 UTC (permalink / raw)
  To: Alex Bennée
  Cc: Kevin Wolf, Fam Zheng, Stefan Weil, QEMU Developers,
	Stefan Hajnoczi, Paolo Bonzini, John Snow, David Gibson

On 15 February 2016 at 14:34, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> Fam Zheng <famz@redhat.com> writes:
>> +cd $(mktemp -d)
>> +mkdir build
>> +mkdir install
>> +cd build
>> +build_qemu --target-list=x86_64-softmmu --prefix="${pwd}/install"

Why restrict the target list ?

>> +make check $MAKEFLAGS
>> +make install
>
> From my excursions last week into the tests directory I discovered the
> unit tests are built for a number of different qtest binaries. For
> completeness we should probably include the whole list:
>
> #+name: qtest-targets
> #+begin_src sh :dir ~/lsrc/qemu/qemu.git :results scalar
> grep -E "check-qtest-[[:alnum:]]+-y " tests/Makefile | cut -d " " -f 1 | sort -u
> #+end_src
>
> #+RESULTS: qtest-targets
> #+begin_example
> check-qtest-arm-y
> check-qtest-generic-y
> check-qtest-i386-y
> check-qtest-ipack-y
> check-qtest-microblazeel-y
> check-qtest-mips64el-y
> check-qtest-mips64-y
> check-qtest-mips-y
> check-qtest-pci-y
> check-qtest-ppc64-y
> check-qtest-ppc-y
> check-qtest-sh4eb-y
> check-qtest-sh4-y
> #check-qtest-sparc64-y
> check-qtest-sparc64-y
> #check-qtest-sparc-y
> check-qtest-virtioserial-y
> check-qtest-virtio-y
> check-qtest-x86_64-y
> check-qtest-xtensaeb-y
> check-qtest-y
> #+end_example

I'm having difficulty figuring out what you're proposing here,
but it looks like you're suggesting listing all the check-qtest-*
test names again here, which seems worth avoiding. We should
just do a build and make check and let that take care of
running all the tests.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 06/12] docker: Add basic test
  2016-02-15 14:42     ` Peter Maydell
@ 2016-02-15 14:52       ` Alex Bennée
  2016-02-16  1:15         ` Fam Zheng
  0 siblings, 1 reply; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 14:52 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Kevin Wolf, Fam Zheng, Stefan Weil, QEMU Developers,
	Stefan Hajnoczi, Paolo Bonzini, John Snow, David Gibson


Peter Maydell <peter.maydell@linaro.org> writes:

> On 15 February 2016 at 14:34, Alex Bennée <alex.bennee@linaro.org> wrote:
>>
>> Fam Zheng <famz@redhat.com> writes:
>>> +cd $(mktemp -d)
>>> +mkdir build
>>> +mkdir install
>>> +cd build
>>> +build_qemu --target-list=x86_64-softmmu --prefix="${pwd}/install"
>
> Why restrict the target list ?
>
>>> +make check $MAKEFLAGS
>>> +make install
>>
>> From my excursions last week into the tests directory I discovered the
>> unit tests are built for a number of different qtest binaries. For
>> completeness we should probably include the whole list:
>>
>> #+name: qtest-targets
>> #+begin_src sh :dir ~/lsrc/qemu/qemu.git :results scalar
>> grep -E "check-qtest-[[:alnum:]]+-y " tests/Makefile | cut -d " " -f 1 | sort -u
>> #+end_src
>>
>> #+RESULTS: qtest-targets
>> #+begin_example
>> check-qtest-arm-y
>> check-qtest-generic-y
>> check-qtest-i386-y
>> check-qtest-ipack-y
>> check-qtest-microblazeel-y
>> check-qtest-mips64el-y
>> check-qtest-mips64-y
>> check-qtest-mips-y
>> check-qtest-pci-y
>> check-qtest-ppc64-y
>> check-qtest-ppc-y
>> check-qtest-sh4eb-y
>> check-qtest-sh4-y
>> #check-qtest-sparc64-y
>> check-qtest-sparc64-y
>> #check-qtest-sparc-y
>> check-qtest-virtioserial-y
>> check-qtest-virtio-y
>> check-qtest-x86_64-y
>> check-qtest-xtensaeb-y
>> check-qtest-y
>> #+end_example
>
> I'm having difficulty figuring out what you're proposing here,
> but it looks like you're suggesting listing all the check-qtest-*
> test names again here, which seems worth avoiding. We should
> just do a build and make check and let that take care of
> running all the tests.

Well there is a halfway house between building one target and building
all possible targets. Not all the softmmu targets include additional
tests. Having said that it is probably simpler as you say to just build
everything.

>
> thanks
> -- PMM


--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests
  2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
                   ` (12 preceding siblings ...)
  2016-02-10 11:23 ` [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Alex Bennée
@ 2016-02-15 17:59 ` Alex Bennée
  2016-02-16  2:42   ` Fam Zheng
  13 siblings, 1 reply; 41+ messages in thread
From: Alex Bennée @ 2016-02-15 17:59 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> v1: Since RFC, addressed comments from reviewers, and improved a lot of things.
>     Thanks to Daniel, Eric, Paolo, Stefan, for the feedback.
>
> This series adds a new "docker" make target family to run tests in created
> docker containers.
>
> To begin with, this can be a place to store standard env/command combinations to
> build and test QEMU.

I think I'm done for this review pass. Please CC me on your next
version.

I've run a quick test on my ARM64 Debian Jessie box which predictably
failed. It looks like this is a docker hub issue for one thing as:

  docker pull debian:stable

creates an x86_64 image on the arm64 box which predictably fails. I
suspect the only solution is going to be storing our own built images on
the docker hub and tweaking the tooling to take host architecture into
account.

Do you have any non-x86 boxes to test against or are you going to need
some help with non-x86 support?

Cheers,

--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 06/12] docker: Add basic test
  2016-02-15 14:52       ` Alex Bennée
@ 2016-02-16  1:15         ` Fam Zheng
  0 siblings, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-16  1:15 UTC (permalink / raw)
  To: Peter Maydell, Alex Bennée
  Cc: Kevin Wolf, Stefan Weil, QEMU Developers, Stefan Hajnoczi,
	Paolo Bonzini, John Snow, David Gibson

On Mon, 02/15 14:52, Alex Bennée wrote:
> 
> Peter Maydell <peter.maydell@linaro.org> writes:
> 
> > On 15 February 2016 at 14:34, Alex Bennée <alex.bennee@linaro.org> wrote:
> >>
> >> Fam Zheng <famz@redhat.com> writes:
> >>> +cd $(mktemp -d)
> >>> +mkdir build
> >>> +mkdir install
> >>> +cd build
> >>> +build_qemu --target-list=x86_64-softmmu --prefix="${pwd}/install"
> >
> > Why restrict the target list ?

There is no particular reason, just I wanted to keep the "basic test" basic.
I'll rename it to "quick".

That said, this is only one of many possible tests, multiplied by the number of
images we ship. We need to be careful with the matrix, because the point of
having these tests is to run them frequently (either manually by developers or
automatically by CI on every patch series or even every patch). 10+ minutes for
a single test/image combination just makes that hard.

> >
> >>> +make check $MAKEFLAGS
> >>> +make install
> >>
> >> From my excursions last week into the tests directory I discovered the
> >> unit tests are built for a number of different qtest binaries. For
> >> completeness we should probably include the whole list:
> >>
> >> #+name: qtest-targets
> >> #+begin_src sh :dir ~/lsrc/qemu/qemu.git :results scalar
> >> grep -E "check-qtest-[[:alnum:]]+-y " tests/Makefile | cut -d " " -f 1 | sort -u
> >> #+end_src
> >>
> >> #+RESULTS: qtest-targets
> >> #+begin_example
> >> check-qtest-arm-y
> >> check-qtest-generic-y
> >> check-qtest-i386-y
> >> check-qtest-ipack-y
> >> check-qtest-microblazeel-y
> >> check-qtest-mips64el-y
> >> check-qtest-mips64-y
> >> check-qtest-mips-y
> >> check-qtest-pci-y
> >> check-qtest-ppc64-y
> >> check-qtest-ppc-y
> >> check-qtest-sh4eb-y
> >> check-qtest-sh4-y
> >> #check-qtest-sparc64-y
> >> check-qtest-sparc64-y
> >> #check-qtest-sparc-y
> >> check-qtest-virtioserial-y
> >> check-qtest-virtio-y
> >> check-qtest-x86_64-y
> >> check-qtest-xtensaeb-y
> >> check-qtest-y
> >> #+end_example
> >
> > I'm having difficulty figuring out what you're proposing here,
> > but it looks like you're suggesting listing all the check-qtest-*
> > test names again here, which seems worth avoiding. We should
> > just do a build and make check and let that take care of
> > running all the tests.
> 
> Well there is a halfway house between building one target and building
> all possible targets. Not all the softmmu targets include additional
> tests. Having said that it is probably simpler as you say to just build
> everything.

Sure, but I'd create a separate "full" test for that.

Fam

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests
  2016-02-15 17:59 ` Alex Bennée
@ 2016-02-16  2:42   ` Fam Zheng
  0 siblings, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-16  2:42 UTC (permalink / raw)
  To: Alex Bennée
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david

On Mon, 02/15 17:59, Alex Bennée wrote:
> 
> Fam Zheng <famz@redhat.com> writes:
> 
> > v1: Since RFC, addressed comments from reviewers, and improved a lot of things.
> >     Thanks to Daniel, Eric, Paolo, Stefan, for the feedback.
> >
> > This series adds a new "docker" make target family to run tests in created
> > docker containers.
> >
> > To begin with, this can be a place to store standard env/command combinations to
> > build and test QEMU.
> 
> I think I'm done for this review pass. Please CC me on your next
> version.

Sure!

> 
> I've run a quick test on my ARM64 Debian Jessie box which predictably
> failed. It looks like this is a docker hub issue for one thing as:
> 
>   docker pull debian:stable
> 
> creates an x86_64 image on the arm64 box which predictably fails. I
> suspect the only solution is going to be storing our own built images on
> the docker hub and tweaking the tooling to take host architecture into
> account.

Yes I think that makes sense.

> 
> Do you have any non-x86 boxes to test against or are you going to need
> some help with non-x86 support?

You're right docker isn't platform aware. At the moment  I don't have a non-x86
box to test, it is great if you can help.

Thanks!

Fam

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 11/12] .gitignore: Ignore temporary dockerfile
  2016-02-15 14:42   ` Alex Bennée
@ 2016-02-16  2:43     ` Fam Zheng
  0 siblings, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-16  2:43 UTC (permalink / raw)
  To: Alex Bennée
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david

On Mon, 02/15 14:42, Alex Bennée wrote:
> 
> Fam Zheng <famz@redhat.com> writes:
> 
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  .gitignore | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/.gitignore b/.gitignore
> > index 88a80ff..a335b7b 100644
> > --- a/.gitignore
> > +++ b/.gitignore
> > @@ -109,3 +109,4 @@ cscope.*
> >  tags
> >  TAGS
> >  *~
> > +/tests/docker/*.docker.tmp
> 
> Is this left over from the python bindings called in docker_build? If so
> can we say so in the commit if we can't persuade the bindings to not
> clutter up the tree?

Okay, it has to be in the tree because of the "docker build context".
docker_build should remove this file at exit but this is just in case it fails
to.

I'll update the commit message.

Fam

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 04/12] docker: Add test runner
  2016-02-15 14:10         ` Alex Bennée
@ 2016-02-16  2:52           ` Fam Zheng
  2016-02-16  6:00           ` Fam Zheng
  1 sibling, 0 replies; 41+ messages in thread
From: Fam Zheng @ 2016-02-16  2:52 UTC (permalink / raw)
  To: Alex Bennée
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david

On Mon, 02/15 14:10, Alex Bennée wrote:
> >> There is a slight wrinkle as to what happens if the user wants to enter
> >> an interactive session for debugging. However that doesn't seem possible
> >> via the makefile and perhaps that is just as well. Perhaps that should
> >> be a helper script for the user?

Good idea.  The "docker run" invocation should be able to drop stdio into an
interactive shell, with Makefile. I'll take a look in v2.

Fam

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 04/12] docker: Add test runner
  2016-02-15 14:10         ` Alex Bennée
  2016-02-16  2:52           ` Fam Zheng
@ 2016-02-16  6:00           ` Fam Zheng
  2016-02-16  8:20             ` Alex Bennée
  1 sibling, 1 reply; 41+ messages in thread
From: Fam Zheng @ 2016-02-16  6:00 UTC (permalink / raw)
  To: Alex Bennée
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david

On Mon, 02/15 14:10, Alex Bennée wrote:
> 
> Fam Zheng <famz@redhat.com> writes:
> 
> > On Mon, 02/15 12:45, Alex Bennée wrote:
> >>
> >> Alex Bennée <alex.bennee@linaro.org> writes:
> >>
> >> > Fam Zheng <famz@redhat.com> writes:
> >> >
> >> >> It's better to have a launcher for all tests, to make it easier to
> >> >> initialize and manage the environment.
> >> >>
> >> >> Signed-off-by: Fam Zheng <famz@redhat.com>
> >> >> ---
> >> >>  tests/docker/run | 23 +++++++++++++++++++++++
> >> >>  1 file changed, 23 insertions(+)
> >> >>  create mode 100755 tests/docker/run
> >> >>
> <snip>
> >> OK that won't work if you have alternates in your git setup. It seems to
> >> me the creation of the pristine tree for docker should be done before we
> >> enter the docker environment.
> >>
> >> There is a slight wrinkle as to what happens if the user wants to enter
> >> an interactive session for debugging. However that doesn't seem possible
> >> via the makefile and perhaps that is just as well. Perhaps that should
> >> be a helper script for the user?
> >
> > We can use "make distclean" in the copied tree.
> 
> I wouldn't - distclean isn't always that clean due to *mumble mumble*
> makefile reasons. You could try this approach:
> 
> commit f838d3bbe2f71c731dfe172f1c3286084de203c8
> Author: Alex Bennée <alex.bennee@linaro.org>
> Date:   Mon Feb 15 12:52:21 2016 +0000
> 
>     tests/docker/Makefile.include: snapshot the src for docker
> 
>     Instead of providing a live version of the source tree to the docker
>     container we snapshot it with git-archive. This ensure the tree is in a
>     pristine state for whatever operations the container is going to run on
>     them.
> 
>     Uncommitted changes known to files known by the git index will be
>     included in the snapshot if there are any.
> 
>     Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> 
> diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
> index ca84c35..63a799c 100644
> --- a/tests/docker/Makefile.include
> +++ b/tests/docker/Makefile.include
> @@ -2,7 +2,7 @@
> 
>  $(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
> 
> -.PHONY: docker docker-build docker-run docker-clean
> +.PHONY: docker docker-build docker-qemu-src docker-run docker-clean
> 
>  DOCKER_SUFFIX = .docker
> 
> @@ -16,12 +16,17 @@ DOCKER_TOOLS := $(filter-out test-%, $(DOCKER_SCRIPTS))
>  TESTS ?= %
>  IMAGES ?= %
> 
> +docker-qemu-src:
> +	$(if git diff-index --quiet HEAD --, 										\
> +		git archive -1 HEAD --prefix=qemu-docker-snapshot/ --format=tar.gz | tar -xz -C /tmp,			\
> +		git archive -1 `git stash create` --prefix=qemu-docker-snapshot/ --format=tar.gz | tar -xz -C /tmp)

Does this clutter the user's git stash list? Or we can just error out if the
working tree is not clean.

Fam

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [Qemu-devel] [PATCH 04/12] docker: Add test runner
  2016-02-16  6:00           ` Fam Zheng
@ 2016-02-16  8:20             ` Alex Bennée
  0 siblings, 0 replies; 41+ messages in thread
From: Alex Bennée @ 2016-02-16  8:20 UTC (permalink / raw)
  To: Fam Zheng
  Cc: kwolf, peter.maydell, sw, qemu-devel, stefanha, Paolo Bonzini,
	jsnow, david


Fam Zheng <famz@redhat.com> writes:

> On Mon, 02/15 14:10, Alex Bennée wrote:
>>
>> Fam Zheng <famz@redhat.com> writes:
>>
>> > On Mon, 02/15 12:45, Alex Bennée wrote:
>> >>
>> >> Alex Bennée <alex.bennee@linaro.org> writes:
>> >>
>> >> > Fam Zheng <famz@redhat.com> writes:
>> >> >
>> >> >> It's better to have a launcher for all tests, to make it easier to
>> >> >> initialize and manage the environment.
>> >> >>
>> >> >> Signed-off-by: Fam Zheng <famz@redhat.com>
>> >> >> ---
>> >> >>  tests/docker/run | 23 +++++++++++++++++++++++
>> >> >>  1 file changed, 23 insertions(+)
>> >> >>  create mode 100755 tests/docker/run
>> >> >>
>> <snip>
>> >> OK that won't work if you have alternates in your git setup. It seems to
>> >> me the creation of the pristine tree for docker should be done before we
>> >> enter the docker environment.
>> >>
>> >> There is a slight wrinkle as to what happens if the user wants to enter
>> >> an interactive session for debugging. However that doesn't seem possible
>> >> via the makefile and perhaps that is just as well. Perhaps that should
>> >> be a helper script for the user?
>> >
>> > We can use "make distclean" in the copied tree.
>>
>> I wouldn't - distclean isn't always that clean due to *mumble mumble*
>> makefile reasons. You could try this approach:
>>
>> commit f838d3bbe2f71c731dfe172f1c3286084de203c8
>> Author: Alex Bennée <alex.bennee@linaro.org>
>> Date:   Mon Feb 15 12:52:21 2016 +0000
>>
>>     tests/docker/Makefile.include: snapshot the src for docker
>>
>>     Instead of providing a live version of the source tree to the docker
>>     container we snapshot it with git-archive. This ensure the tree is in a
>>     pristine state for whatever operations the container is going to run on
>>     them.
>>
>>     Uncommitted changes known to files known by the git index will be
>>     included in the snapshot if there are any.
>>
>>     Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>
>> diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
>> index ca84c35..63a799c 100644
>> --- a/tests/docker/Makefile.include
>> +++ b/tests/docker/Makefile.include
>> @@ -2,7 +2,7 @@
>>
>>  $(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
>>
>> -.PHONY: docker docker-build docker-run docker-clean
>> +.PHONY: docker docker-build docker-qemu-src docker-run docker-clean
>>
>>  DOCKER_SUFFIX = .docker
>>
>> @@ -16,12 +16,17 @@ DOCKER_TOOLS := $(filter-out test-%, $(DOCKER_SCRIPTS))
>>  TESTS ?= %
>>  IMAGES ?= %
>>
>> +docker-qemu-src:
>> +	$(if git diff-index --quiet HEAD --, 										\
>> +		git archive -1 HEAD --prefix=qemu-docker-snapshot/ --format=tar.gz | tar -xz -C /tmp,			\
>> +		git archive -1 `git stash create` --prefix=qemu-docker-snapshot/ --format=tar.gz | tar -xz -C /tmp)
>
> Does this clutter the user's git stash list? Or we can just error out if the
> working tree is not clean.

No it doesn't, it is a temporary dangling object, quoth the manual:

       create
           Create a stash (which is a regular commit object) and return its object name, without storing it anywhere in the ref
           namespace. This is intended to be useful for scripts. It is probably not the command you want to use; see "save" above.

>
> Fam


--
Alex Bennée

^ permalink raw reply	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2016-02-16  8:20 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-05  9:24 [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Fam Zheng
2016-02-05  9:24 ` [Qemu-devel] [PATCH 01/12] tests: Add utilities for docker testing Fam Zheng
2016-02-08 21:49   ` John Snow
2016-02-09  2:01     ` Fam Zheng
2016-02-09 23:16       ` John Snow
2016-02-14  5:10         ` Fam Zheng
2016-02-05  9:24 ` [Qemu-devel] [PATCH 02/12] Makefile: Rules " Fam Zheng
2016-02-15 10:06   ` Alex Bennée
2016-02-15 13:52     ` Fam Zheng
2016-02-15 14:13       ` Alex Bennée
2016-02-05  9:24 ` [Qemu-devel] [PATCH 03/12] docker: Add images Fam Zheng
2016-02-15 10:15   ` Alex Bennée
2016-02-15 13:44     ` Fam Zheng
2016-02-15 14:12       ` Alex Bennée
2016-02-05  9:24 ` [Qemu-devel] [PATCH 04/12] docker: Add test runner Fam Zheng
2016-02-15 10:55   ` Alex Bennée
2016-02-15 12:45     ` Alex Bennée
2016-02-15 13:29       ` Fam Zheng
2016-02-15 14:10         ` Alex Bennée
2016-02-16  2:52           ` Fam Zheng
2016-02-16  6:00           ` Fam Zheng
2016-02-16  8:20             ` Alex Bennée
2016-02-05  9:24 ` [Qemu-devel] [PATCH 05/12] docker: Add common.rc Fam Zheng
2016-02-05  9:24 ` [Qemu-devel] [PATCH 06/12] docker: Add basic test Fam Zheng
2016-02-15 14:34   ` Alex Bennée
2016-02-15 14:42     ` Peter Maydell
2016-02-15 14:52       ` Alex Bennée
2016-02-16  1:15         ` Fam Zheng
2016-02-05  9:24 ` [Qemu-devel] [PATCH 07/12] docker: Add clang test Fam Zheng
2016-02-05  9:24 ` [Qemu-devel] [PATCH 08/12] docker: Add mingw test Fam Zheng
2016-02-05  9:24 ` [Qemu-devel] [PATCH 09/12] docker: Add travis tool Fam Zheng
2016-02-05  9:24 ` [Qemu-devel] [PATCH 10/12] docs: Add text for tests/docker in build-system.txt Fam Zheng
2016-02-05  9:24 ` [Qemu-devel] [PATCH 11/12] .gitignore: Ignore temporary dockerfile Fam Zheng
2016-02-15 14:42   ` Alex Bennée
2016-02-16  2:43     ` Fam Zheng
2016-02-05  9:24 ` [Qemu-devel] [PATCH 12/12] MAINTAINERS: Add tests/docker Fam Zheng
2016-02-15 14:36   ` Alex Bennée
2016-02-10 11:23 ` [Qemu-devel] [PATCH 00/12] tests: Introducing docker tests Alex Bennée
2016-02-14  5:22   ` Fam Zheng
2016-02-15 17:59 ` Alex Bennée
2016-02-16  2:42   ` Fam Zheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).