Skip to contentSkip to conversation

tests: Introducing docker tests

PATCH Superseded Fam Zheng 2 participants 32 messages Feb 16, 2016 – Mar 2, 2016 Kbuild

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

v2 cover tests: Introducing docker tests

v2: - Fix a few coding style warnings of shellcheck and pylint.
[Marc-André Lureau]
- Rename make targets:
docker-run => docker-test
docker-build => docker-image docker-run-$TEST.sh@$IMAGE => docker-$TEST@$IMAGE
- In help, document the magic makefile vars which are "IMAGES=", "TESTS=", "J=" and "PAUSE="
- Rename test-basic => test-quick
- Move docker files to tests/docker/dockerfiles/
- Add "test-full" that builds all targets
- Workaround broken clang for fedora 23
- Add commit log for .gitignore changes [Alex]
- Add "rev-by" in patch 13. [Alex]
- Add patch 14 to make debugging easier [Alex]
- Adopt Alex's "git archive" idea

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, where we specify 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.

Alex Bennée (1):
tests/docker/Makefile.include: snapshot the src for docker

Fam Zheng (14):
tests: Add utilities for docker testing
Makefile: Rules for docker testing
docker: Add images
docker: Add test runner
docker: Add common.rc
docker: Add quick test
docker: Add full 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
docker: Support interactive shell for debugging

 .gitignore                              |   1 +
 MAINTAINERS                             |   7 ++
 Makefile                                |   4 +-
 docs/build-system.txt                   |   5 ++
 tests/docker/Makefile.include           | 110 +++++++++++++++++++++++++++++++
 tests/docker/common.rc                  |  29 ++++++++
 tests/docker/docker.py                  | 113 ++++++++++++++++++++++++++++++++
 tests/docker/docker_build               |  42 ++++++++++++
 tests/docker/docker_clean               |  22 +++++++
 tests/docker/docker_run                 |  29 ++++++++
 tests/docker/dockerfiles/centos6.docker |   5 ++
 tests/docker/dockerfiles/fedora.docker  |   7 ++
 tests/docker/dockerfiles/ubuntu.docker  |   9 +++
 tests/docker/run                        |  34 ++++++++++
 tests/docker/test-clang                 |  28 ++++++++
 tests/docker/test-full                  |  21 ++++++
 tests/docker/test-mingw                 |  36 ++++++++++
 tests/docker/test-quick                 |  23 +++++++
 tests/docker/travis                     |  23 +++++++
 tests/docker/travis.py                  |  48 ++++++++++++++
 20 files changed, 595 insertions(+), 1 deletion(-)
 create mode 100644 tests/docker/Makefile.include
 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/dockerfiles/centos6.docker
 create mode 100644 tests/docker/dockerfiles/fedora.docker
 create mode 100644 tests/docker/dockerfiles/ubuntu.docker
 create mode 100755 tests/docker/run
 create mode 100755 tests/docker/test-clang
 create mode 100755 tests/docker/test-full
 create mode 100755 tests/docker/test-mingw
 create mode 100755 tests/docker/test-quick
 create mode 100755 tests/docker/travis
 create mode 100755 tests/docker/travis.py
Signature · 1 line
2.4.3
author
#1 lore raw

PATCH v2 1/15 tests: Add utilities for docker testing

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.

---
 tests/docker/docker.py    | 113 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/docker/docker_build |  42 +++++++++++++++++
 tests/docker/docker_clean |  22 +++++++++
 tests/docker/docker_run   |  29 ++++++++++++
 4 files changed, 206 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
tests/docker/docker.py new file +113 -0
new file mode 100755
index 0000000..d175a86
@@ -0,0 +1,113 @@
+#!/usr/bin/env python2 -B
+#
+# Docker controlling module
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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 uuid
+
+class ContainerTerminated(Exception):
+    """ Raised if the container has already existed """
+    pass
+
+class Docker(object):
+    """ Running Docker commands """
+    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():
+            resp = self._output(["inspect", i])
+            labels = json.loads(resp)[0]["Config"]["Labels"]
+            active = json.loads(resp)[0]["State"]["Running"]
+            if not labels:
+                continue
+            instance_uuid = labels.get("com.qemu.instance.uuid", None)
+            if not instance_uuid:
+                continue
+            if only_known and instance_uuid 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):
+        commands = [["docker"], ["sudo", "-n", "docker"]]
+        for cmd in commands:
+            if subprocess.call(cmd + ["images"],
+                               stdout=subprocess.PIPE,
+                               stderr=subprocess.PIPE) == 0:
+                return cmd
+        commands_txt = "\n".join(["  " + " ".join(x) for x in commands])
+        raise Exception("Cannot find working docker command. Tried:\n%s" % commands_txt)
+
+    def get_image_dockerfile_checksum(self, tag):
+        resp = self._output(["inspect", tag])
+        labels = json.loads(resp)[0]["Config"].get("Labels", {})
+        return 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"
+        tmp_file = open(tmp_df, "wb")
+        tmp_file.write(tmp)
+        tmp_file.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:
+            checksum = self.get_image_dockerfile_checksum(tag)
+        except:
+            return False
+        return checksum == self.checksum(dockerfile)
+
+    def run(self, cmd, keep, quiet):
+        label = uuid.uuid1().hex
+        if not keep:
+            self._instances.append(label)
+        ret = self._do(["run", "--label", "com.qemu.instance.uuid=" + label] + cmd, quiet=quiet)
+        if not keep:
+            self._instances.remove(label)
+        return ret
+
tests/docker/docker_build new file +42 -0

42 lines not on this page · raw message

tests/docker/docker_clean new file +22 -0
new file mode 100755
index 0000000..88cdba6
@@ -0,0 +1,22 @@
+#!/usr/bin/env python2
+#
+# Clean up uselsee containers.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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())
tests/docker/docker_run new file +29 -0
new file mode 100755
index 0000000..4c46d90
@@ -0,0 +1,29 @@
+#!/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 <[email protected]>
+#
+# 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 argparse
+import docker
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--keep", action="store_true",
+                        help="Don't remove image when the command completes")
+    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, args.keep, quiet=args.quiet)
+
+if __name__ == "__main__":
+    sys.exit(main())
Signature · 1 line
2.4.3
#2 lore raw

Re: [Qemu-devel] [PATCH v2 01/15] tests: Add utilities for docker testing

Quoted 56 lines · Fam Zheng

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.

---
 tests/docker/docker.py    | 113 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/docker/docker_build |  42 +++++++++++++++++
 tests/docker/docker_clean |  22 +++++++++
 tests/docker/docker_run   |  29 ++++++++++++
 4 files changed, 206 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
tests/docker/docker.py new file +28 -0
new file mode 100755
index 0000000..d175a86
@@ -0,0 +1,113 @@
+#!/usr/bin/env python2 -B
+#
+# Docker controlling module
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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 uuid
+
+class ContainerTerminated(Exception):
+    """ Raised if the container has already existed """
+    pass
+
+class Docker(object):
+    """ Running Docker commands """
+    def __init__(self):
+        self._command = self._guess_command()

tests/docker/docker.py line 38

Quoted 10 lines
tests/docker/docker.py new file +10 -0
+        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"]

Hmm ps -q barfs on my command line:

16:04 alex@zen/x86_64 [qemu.git/mttcg/multi_tcg_v8_ajb-r2] >ps -q
error: unsupported SysV option

Is there not a more portable way of doing this, even if it is a standard library?

Quoted 64 lines
tests/docker/docker.py new file +64 -0
+        if not only_active:
+            cmd.append("-a")
+        for i in self._output(cmd).split():
+            resp = self._output(["inspect", i])
+            labels = json.loads(resp)[0]["Config"]["Labels"]
+            active = json.loads(resp)[0]["State"]["Running"]
+            if not labels:
+                continue
+            instance_uuid = labels.get("com.qemu.instance.uuid", None)
+            if not instance_uuid:
+                continue
+            if only_known and instance_uuid 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):
+        commands = [["docker"], ["sudo", "-n", "docker"]]
+        for cmd in commands:
+            if subprocess.call(cmd + ["images"],
+                               stdout=subprocess.PIPE,
+                               stderr=subprocess.PIPE) == 0:
+                return cmd
+        commands_txt = "\n".join(["  " + " ".join(x) for x in commands])
+        raise Exception("Cannot find working docker command. Tried:\n%s" % commands_txt)
+
+    def get_image_dockerfile_checksum(self, tag):
+        resp = self._output(["inspect", tag])
+        labels = json.loads(resp)[0]["Config"].get("Labels", {})
+        return 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"
+        tmp_file = open(tmp_df, "wb")
+        tmp_file.write(tmp)
+        tmp_file.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:
+            checksum = self.get_image_dockerfile_checksum(tag)
+        except:
+            return False

tests/docker/docker.py line 112

Quoted 10 lines
tests/docker/docker.py new file +10 -0
+        return checksum == self.checksum(dockerfile)
+
+    def run(self, cmd, keep, quiet):
+        label = uuid.uuid1().hex
+        if not keep:
+            self._instances.append(label)
+        ret = self._do(["run", "--label", "com.qemu.instance.uuid=" + label] + cmd, quiet=quiet)
+        if not keep:
+            self._instances.remove(label)
+        return ret

I think it might be useful to catch some arguments here for testing things. It is likely to be the first script someone runs while poking around so some help text would be useful even if it just points at the other commands.

In fact I'm not sure why all the various commands aren't in one script for now given this does most of the heavy lifting.

Quoted 67 lines
tests/docker/docker.py new file +1 -0
+
tests/docker/docker_build new file +42 -0
new file mode 100755
index 0000000..6948e2c
@@ -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 <[email protected]>
+#
+# 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
+
+    dkr = docker.Docker()
+    if dkr.image_matches_dockerfile(tag, dockerfile):
+        if args.verbose:
+            print "Image is up to date."
+        return 0
+
+    quiet = not args.verbose
+    dkr.build_image(tag, dockerfile, args.dockerfile, quiet=quiet)
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())
tests/docker/docker_clean new file +12 -0
new file mode 100755
index 0000000..88cdba6
@@ -0,0 +1,22 @@
+#!/usr/bin/env python2
+#
+# Clean up uselsee containers.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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.

tests/docker/docker_clean line 22

Quoted 10 lines
tests/docker/docker_clean new file +10 -0
+
+import sys
+import docker
+
+def main():
+    docker.Docker().clean()
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())

Of all the scripts run if you call with --help this just does something straight away. It should at least attempt a usage() text to prevent accidents.

Quoted 25 lines
tests/docker/docker_run new file +19 -0
new file mode 100755
index 0000000..4c46d90
@@ -0,0 +1,29 @@
+#!/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 <[email protected]>
+#
+# 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 argparse
+import docker
+
+def main():

tests/docker/docker_run line 29

Quoted 10 lines
tests/docker/docker_run new file +10 -0
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--keep", action="store_true",
+                        help="Don't remove image when the command completes")
+    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, args.keep, quiet=args.quiet)
+
+if __name__ == "__main__":
+    sys.exit(main())

--
Alex Bennée

author
#3 lore raw

Re: [Qemu-devel] [PATCH v2 01/15] tests: Add utilities for docker testing

Quoted 72 lines · Alex Bennée
Quoted 56 lines · Fam Zheng

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.

---
 tests/docker/docker.py    | 113 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/docker/docker_build |  42 +++++++++++++++++
 tests/docker/docker_clean |  22 +++++++++
 tests/docker/docker_run   |  29 ++++++++++++
 4 files changed, 206 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
tests/docker/docker.py new file +28 -0
new file mode 100755
index 0000000..d175a86
@@ -0,0 +1,113 @@
+#!/usr/bin/env python2 -B
+#
+# Docker controlling module
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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 uuid
+
+class ContainerTerminated(Exception):
+    """ Raised if the container has already existed """
+    pass
+
+class Docker(object):
+    """ Running Docker commands """
+    def __init__(self):
+        self._command = self._guess_command()

tests/docker/docker.py line 38

Quoted 10 lines
tests/docker/docker.py new file +10 -0
+        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"]

Hmm ps -q barfs on my command line:

Quoted 5 lines

16:04 alex@zen/x86_64 [qemu.git/mttcg/multi_tcg_v8_ajb-r2] >ps -q
error: unsupported SysV option

Is there not a more portable way of doing this, even if it is a standard library?

Down the road this is "sudo docker ps" command. :)

Quoted 72 lines
Quoted 72 lines
tests/docker/docker.py new file +71 -0
+        if not only_active:
+            cmd.append("-a")
+        for i in self._output(cmd).split():
+            resp = self._output(["inspect", i])
+            labels = json.loads(resp)[0]["Config"]["Labels"]
+            active = json.loads(resp)[0]["State"]["Running"]
+            if not labels:
+                continue
+            instance_uuid = labels.get("com.qemu.instance.uuid", None)
+            if not instance_uuid:
+                continue
+            if only_known and instance_uuid 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):
+        commands = [["docker"], ["sudo", "-n", "docker"]]
+        for cmd in commands:
+            if subprocess.call(cmd + ["images"],
+                               stdout=subprocess.PIPE,
+                               stderr=subprocess.PIPE) == 0:
+                return cmd
+        commands_txt = "\n".join(["  " + " ".join(x) for x in commands])
+        raise Exception("Cannot find working docker command. Tried:\n%s" % commands_txt)
+
+    def get_image_dockerfile_checksum(self, tag):
+        resp = self._output(["inspect", tag])
+        labels = json.loads(resp)[0]["Config"].get("Labels", {})
+        return 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"
+        tmp_file = open(tmp_df, "wb")
+        tmp_file.write(tmp)
+        tmp_file.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:
+            checksum = self.get_image_dockerfile_checksum(tag)
+        except:
+            return False
+        return checksum == self.checksum(dockerfile)
+
+    def run(self, cmd, keep, quiet):
+        label = uuid.uuid1().hex
+        if not keep:
+            self._instances.append(label)
+        ret = self._do(["run", "--label", "com.qemu.instance.uuid=" + label] + cmd, quiet=quiet)
Quoted 8 lines

tests/docker/docker.py line 112

Quoted 3 lines
tests/docker/docker.py new file +3 -0
+        if not keep:
+            self._instances.remove(label)
+        return ret

I think it might be useful to catch some arguments here for testing things. It is likely to be the first script someone runs while poking around so some help text would be useful even if it just points at the other commands.

Sure, I can do that.

Quoted 3 lines

In fact I'm not sure why all the various commands aren't in one script for now given this does most of the heavy lifting.

OK, I can merge them into one script.

Quoted 74 lines
Quoted 74 lines
tests/docker/docker.py new file +1 -0
+
tests/docker/docker_build new file +42 -0
new file mode 100755
index 0000000..6948e2c
@@ -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 <[email protected]>
+#
+# 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
+
+    dkr = docker.Docker()
+    if dkr.image_matches_dockerfile(tag, dockerfile):
+        if args.verbose:
+            print "Image is up to date."
+        return 0
+
+    quiet = not args.verbose
+    dkr.build_image(tag, dockerfile, args.dockerfile, quiet=quiet)
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())
tests/docker/docker_clean new file +18 -0
new file mode 100755
index 0000000..88cdba6
@@ -0,0 +1,22 @@
+#!/usr/bin/env python2
+#
+# Clean up uselsee containers.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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()
Quoted 8 lines

tests/docker/docker_clean line 22

Quoted 4 lines
tests/docker/docker_clean new file +4 -0
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())

Of all the scripts run if you call with --help this just does something straight away. It should at least attempt a usage() text to prevent accidents.

Yes. Will address.

Fam

Quoted 40 lines
Quoted 26 lines
tests/docker/docker_run new file +19 -0
new file mode 100755
index 0000000..4c46d90
@@ -0,0 +1,29 @@
+#!/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 <[email protected]>
+#
+# 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 argparse
+import docker
+
+def main():

tests/docker/docker_run line 29

Quoted 10 lines
tests/docker/docker_run new file +10 -0
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--keep", action="store_true",
+                        help="Don't remove image when the command completes")
+    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, args.keep, quiet=args.quiet)
+
+if __name__ == "__main__":
+    sys.exit(main())

--
Alex Bennée

author
#4 lore raw

PATCH v2 2/15 Makefile: Rules for docker testing

In reply to Fam Zheng

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.

---
 Makefile                      |  4 +-
 tests/docker/Makefile.include | 93 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 tests/docker/Makefile.include
Makefile +3 -1
index f9fae3a..f104a08 100644
@@ -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
tests/docker/Makefile.include new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.4.3
#5 lore raw

Re: [Qemu-devel] [PATCH v2 02/15] Makefile: Rules for docker testing

Quoted 9 lines · Fam Zheng

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.

Quoted 6 lines

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 doesn't seem to work for me:

16:49 alex@zen/x86_64 [qemu.git/review/docker-tests-v2] >make docker-run IMAGES="ubuntu" V=1 /home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: overriding commands for target clean-timestamp' /home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: ignoring old commands for target clean-timestamp'
make: *** No rule to make target `docker-run'. Stop.
`

Quoted 90 lines

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.

---
 Makefile                      |  4 +-
 tests/docker/Makefile.include | 93 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 tests/docker/Makefile.include
Makefile +3 -1
index f9fae3a..f104a08 100644
@@ -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
tests/docker/Makefile.include new file +52 -0
new file mode 100644
index 0000000..d8c55c3
@@ -0,0 +1,93 @@
+# Makefile for Docker tests
+
+$(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
+
+.PHONY: docker docker-test docker-clean docker-image
+
+DOCKER_SUFFIX := .docker
+
+DOCKER_IMAGES := $(notdir $(basename \
+	$(wildcard $(SRC_PATH)/tests/docker/dockerfiles/*)))
+
+DOCKER_TESTS := $(notdir $(shell \
+	find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f -executable))
+
+DOCKER_TOOLS := travis
+
+TESTS ?= %
+IMAGES ?= %
+
+$(foreach i,$(DOCKER_IMAGES), \
+	$(eval docker-image: docker-image-$i) \
+	$(eval docker-image-$i: IMAGE = $i) \
+	$(eval .PHONY: docker-image-$i docker-@$i) \
+	$(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
+		$(eval .PHONY: docker-$t@$i) \
+		$(eval docker-$t@$i: docker-image-$i) \
+		$(eval docker-$t@$i: docker-run-$t@$i) \
+		$(eval docker-@$i: docker-$t@$i) \
+		$(eval docker-test: docker-run-$t@$i) \
+	) \
+)
+
+docker:
+	@echo 'Building QEMU and running tests inside Docker containers'
+	@echo
+	@echo 'Available targets:'
+	@echo
+	@echo '    docker:              Print this help.'
+	@echo '    docker-test:         Run all image/test combinations.'
+	@echo '    docker-clean:        Kill and remove residual docker testing containers.'
+	@echo '    docker-TEST@IMAGE:   Run "TEST" in container "IMAGE".'
+	@echo '                         Note: "TEST" is one of the listed test name,'
+	@echo '                         or a script name under $$QEMU_SRC/tests/docker/;'
+	@echo '                         "IMAGE" is one of the listed container name."'
+	@echo '    docker-@IMAGE:       Run all tests in container "IMAGE".'
+	@echo '    docker-image:        Build all images.'
+	@echo '    docker-image-IMAGE:  Build image "IMG".'
+	@echo
+	@echo 'Available container images:'
+	@echo '    $(DOCKER_IMAGES)'
+	@echo
+	@echo 'Available tests:'

tests/docker/Makefile.include line 62

Quoted 10 lines
tests/docker/Makefile.include new file +10 -0
+	@echo '    $(DOCKER_TESTS)'
+	@echo
+	@echo 'Available tools:'
+	@echo '    $(DOCKER_TOOLS)'
+	@echo
+	@echo 'Special variables:'
+	@echo '    IMAGES="a b c ..":   Filters which images to build or run.'
+	@echo '    TESTS="x y z .."     Filters which tests to run (for docker-test).'
+	@echo '    J=[0..9]*            Overrides the -jN parameter for make commands'
+	@echo '                         (default is 1)'

OK none of these test targets seem to be working for me:

COPY SRC /tmp/qemu-src.JCUng
RUN test-clang in centos6
Prerequisite 'clang' not present, skip
RUN test-mingw in centos6
Prerequisite 'mingw' not present, skip
RUN test-quick in centos6
make: *** [docker-run-test-quick@centos6] Error 2

Running with V=1 doesn't elucidate me much further:

/home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: overriding commands for target `clean-timestamp'
/home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: ignoring old commands for target `clean-timestamp'
mkdir -p /tmp/qemu-src.HtY32 && (if git diff-index --quiet HEAD -- &>/dev/null; then git archive -1 HEAD --format=tar.gz; else git archive -1 $(git stash create) --format=tar.gz; fi) | tar -xz -C /tmp/qemu-src.HtY32
/home/alex/lsrc/qemu/qemu.git/tests/docker/docker_run --rm --privileged -t --net=none -v $(realpath /home/alex/lsrc/qemu/qemu.git):/var/tmp/qemu -e QEMU_SRC=/var/tmp/qemu -e V=1 -e J= -e PAUSE= -v /var/tmp/qemu-docker-ccache:/var/tmp/ccache -e CCACHE_DIR=/var/tmp/ccache qemu:centos6 /var/tmp/qemu/tests/docker/run /var/tmp/qemu/tests/docker/test-clang; Prerequisite 'clang' not present, skip
/home/alex/lsrc/qemu/qemu.git/tests/docker/docker_run --rm --privileged -t --net=none -v $(realpath /home/alex/lsrc/qemu/qemu.git):/var/tmp/qemu -e QEMU_SRC=/var/tmp/qemu -e V=1 -e J= -e PAUSE= -v /var/tmp/qemu-docker-ccache:/var/tmp/ccache -e CCACHE_DIR=/var/tmp/ccache qemu:centos6 /var/tmp/qemu/tests/docker/run /var/tmp/qemu/tests/docker/test-mingw; Prerequisite 'mingw' not present, skip
/home/alex/lsrc/qemu/qemu.git/tests/docker/docker_run --rm --privileged -t --net=none -v $(realpath /home/alex/lsrc/qemu/qemu.git):/var/tmp/qemu -e QEMU_SRC=/var/tmp/qemu -e V=1 -e J= -e PAUSE= -v /var/tmp/qemu-docker-ccache:/var/tmp/ccache -e CCACHE_DIR=/var/tmp/ccache qemu:centos6 /var/tmp/qemu/tests/docker/run /var/tmp/qemu/tests/docker/test-quick;
make: *** [docker-run-test-quick@centos6] Error 2

If I drop to the shell using:

make docker-test-quick@centos6 V=1 PAUSE=1

And run:

/var/tmp/qemu/tests/docker/test-quick

I get a cryptic silent fail. I think we need more verbosity (select-able when required) to see whats going on in the depths.

Quoted 21 lines
tests/docker/Makefile.include new file +21 -0
+
+docker-image-%:
+	@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/dockerfiles/$(IMAGE).docker \
+			$(if $V,-v,), "  BUILD $(IMAGE)"))
+
+
+docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
+docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
+docker-run-%:
+	@if test -z "$(IMAGE)" || test -z "$(CMD)"; \
+		then echo "Invalid target"; exit 1; \
+	fi
+	$(if $(filter $(TESTS),$(CMD)),$(if $(filter $(IMAGES),$(IMAGE)), \
+		$(call quiet-command,\
+			$(SRC_PATH)/tests/docker/docker_run $(if $(KEEP),,--rm) \
+				--privileged -t --net=none \
+				-v $$(realpath $(SRC_PATH)):/var/tmp/qemu \
+				-e QEMU_SRC=/var/tmp/qemu \

tests/docker/Makefile.include line 93

Quoted 10 lines
tests/docker/Makefile.include new file +10 -0
+				-e V=$V -e J=$J \
+				-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/$(CMD); \
+			, "  RUN $(CMD) in $(IMAGE)")))
+
+docker-clean:
+	$(call quiet-command, $(SRC_PATH)/tests/docker/docker_clean)

--
Alex Bennée

author
#6 lore raw

Re: [Qemu-devel] [PATCH v2 02/15] Makefile: Rules for docker testing

Quoted 21 lines · Alex Bennée
Quoted 9 lines · Fam Zheng

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.

Quoted 6 lines

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 doesn't seem to work for me:

Quoted 7 lines

16:49 alex@zen/x86_64 [qemu.git/review/docker-tests-v2] >make docker-run IMAGES="ubuntu" V=1 /home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: overriding commands for target clean-timestamp' /home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: ignoring old commands for target clean-timestamp'
make: *** No rule to make target `docker-run'. Stop.

The commit message is stale, as the help text, the target is now "docker-test" which is more intuitive.

Fam

Quoted 171 lines

`

Quoted 90 lines

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.

---
 Makefile                      |  4 +-
 tests/docker/Makefile.include | 93 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 tests/docker/Makefile.include
Makefile +3 -1
index f9fae3a..f104a08 100644
@@ -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
tests/docker/Makefile.include new file +52 -0
new file mode 100644
index 0000000..d8c55c3
@@ -0,0 +1,93 @@
+# Makefile for Docker tests
+
+$(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
+
+.PHONY: docker docker-test docker-clean docker-image
+
+DOCKER_SUFFIX := .docker
+
+DOCKER_IMAGES := $(notdir $(basename \
+	$(wildcard $(SRC_PATH)/tests/docker/dockerfiles/*)))
+
+DOCKER_TESTS := $(notdir $(shell \
+	find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f -executable))
+
+DOCKER_TOOLS := travis
+
+TESTS ?= %
+IMAGES ?= %
+
+$(foreach i,$(DOCKER_IMAGES), \
+	$(eval docker-image: docker-image-$i) \
+	$(eval docker-image-$i: IMAGE = $i) \
+	$(eval .PHONY: docker-image-$i docker-@$i) \
+	$(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
+		$(eval .PHONY: docker-$t@$i) \
+		$(eval docker-$t@$i: docker-image-$i) \
+		$(eval docker-$t@$i: docker-run-$t@$i) \
+		$(eval docker-@$i: docker-$t@$i) \
+		$(eval docker-test: docker-run-$t@$i) \
+	) \
+)
+
+docker:
+	@echo 'Building QEMU and running tests inside Docker containers'
+	@echo
+	@echo 'Available targets:'
+	@echo
+	@echo '    docker:              Print this help.'
+	@echo '    docker-test:         Run all image/test combinations.'
+	@echo '    docker-clean:        Kill and remove residual docker testing containers.'
+	@echo '    docker-TEST@IMAGE:   Run "TEST" in container "IMAGE".'
+	@echo '                         Note: "TEST" is one of the listed test name,'
+	@echo '                         or a script name under $$QEMU_SRC/tests/docker/;'
+	@echo '                         "IMAGE" is one of the listed container name."'
+	@echo '    docker-@IMAGE:       Run all tests in container "IMAGE".'
+	@echo '    docker-image:        Build all images.'
+	@echo '    docker-image-IMAGE:  Build image "IMG".'
+	@echo
+	@echo 'Available container images:'
+	@echo '    $(DOCKER_IMAGES)'
+	@echo
+	@echo 'Available tests:'

tests/docker/Makefile.include line 62

Quoted 10 lines
tests/docker/Makefile.include new file +10 -0
+	@echo '    $(DOCKER_TESTS)'
+	@echo
+	@echo 'Available tools:'
+	@echo '    $(DOCKER_TOOLS)'
+	@echo
+	@echo 'Special variables:'
+	@echo '    IMAGES="a b c ..":   Filters which images to build or run.'
+	@echo '    TESTS="x y z .."     Filters which tests to run (for docker-test).'
+	@echo '    J=[0..9]*            Overrides the -jN parameter for make commands'
+	@echo '                         (default is 1)'

OK none of these test targets seem to be working for me:

COPY SRC /tmp/qemu-src.JCUng
RUN test-clang in centos6
Prerequisite 'clang' not present, skip
RUN test-mingw in centos6
Prerequisite 'mingw' not present, skip
RUN test-quick in centos6
make: *** [docker-run-test-quick@centos6] Error 2

Running with V=1 doesn't elucidate me much further:

/home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: overriding commands for target `clean-timestamp'
/home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: ignoring old commands for target `clean-timestamp'
mkdir -p /tmp/qemu-src.HtY32 && (if git diff-index --quiet HEAD -- &>/dev/null; then git archive -1 HEAD --format=tar.gz; else git archive -1 $(git stash create) --format=tar.gz; fi) | tar -xz -C /tmp/qemu-src.HtY32
/home/alex/lsrc/qemu/qemu.git/tests/docker/docker_run --rm --privileged -t --net=none -v $(realpath /home/alex/lsrc/qemu/qemu.git):/var/tmp/qemu -e QEMU_SRC=/var/tmp/qemu -e V=1 -e J= -e PAUSE= -v /var/tmp/qemu-docker-ccache:/var/tmp/ccache -e CCACHE_DIR=/var/tmp/ccache qemu:centos6 /var/tmp/qemu/tests/docker/run /var/tmp/qemu/tests/docker/test-clang; Prerequisite 'clang' not present, skip
/home/alex/lsrc/qemu/qemu.git/tests/docker/docker_run --rm --privileged -t --net=none -v $(realpath /home/alex/lsrc/qemu/qemu.git):/var/tmp/qemu -e QEMU_SRC=/var/tmp/qemu -e V=1 -e J= -e PAUSE= -v /var/tmp/qemu-docker-ccache:/var/tmp/ccache -e CCACHE_DIR=/var/tmp/ccache qemu:centos6 /var/tmp/qemu/tests/docker/run /var/tmp/qemu/tests/docker/test-mingw; Prerequisite 'mingw' not present, skip
/home/alex/lsrc/qemu/qemu.git/tests/docker/docker_run --rm --privileged -t --net=none -v $(realpath /home/alex/lsrc/qemu/qemu.git):/var/tmp/qemu -e QEMU_SRC=/var/tmp/qemu -e V=1 -e J= -e PAUSE= -v /var/tmp/qemu-docker-ccache:/var/tmp/ccache -e CCACHE_DIR=/var/tmp/ccache qemu:centos6 /var/tmp/qemu/tests/docker/run /var/tmp/qemu/tests/docker/test-quick;
make: *** [docker-run-test-quick@centos6] Error 2

If I drop to the shell using:

make docker-test-quick@centos6 V=1 PAUSE=1

And run:

/var/tmp/qemu/tests/docker/test-quick

I get a cryptic silent fail. I think we need more verbosity (select-able when required) to see whats going on in the depths.

Quoted 21 lines
tests/docker/Makefile.include new file +21 -0
+
+docker-image-%:
+	@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/dockerfiles/$(IMAGE).docker \
+			$(if $V,-v,), "  BUILD $(IMAGE)"))
+
+
+docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
+docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
+docker-run-%:
+	@if test -z "$(IMAGE)" || test -z "$(CMD)"; \
+		then echo "Invalid target"; exit 1; \
+	fi
+	$(if $(filter $(TESTS),$(CMD)),$(if $(filter $(IMAGES),$(IMAGE)), \
+		$(call quiet-command,\
+			$(SRC_PATH)/tests/docker/docker_run $(if $(KEEP),,--rm) \
+				--privileged -t --net=none \
+				-v $$(realpath $(SRC_PATH)):/var/tmp/qemu \
+				-e QEMU_SRC=/var/tmp/qemu \

tests/docker/Makefile.include line 93

Quoted 10 lines
tests/docker/Makefile.include new file +10 -0
+				-e V=$V -e J=$J \
+				-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/$(CMD); \
+			, "  RUN $(CMD) in $(IMAGE)")))
+
+docker-clean:
+	$(call quiet-command, $(SRC_PATH)/tests/docker/docker_clean)

--
Alex Bennée

#7 lore raw

Re: [Qemu-devel] [PATCH v2 02/15] Makefile: Rules for docker testing

Quoted 98 lines · Fam Zheng
Quoted 21 lines · Alex Bennée
Quoted 9 lines · Fam Zheng

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.

Quoted 6 lines

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 doesn't seem to work for me:

Quoted 7 lines

16:49 alex@zen/x86_64 [qemu.git/review/docker-tests-v2] >make docker-run IMAGES="ubuntu" V=1 /home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: overriding commands for target clean-timestamp' /home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: ignoring old commands for target clean-timestamp'
make: *** No rule to make target `docker-run'. Stop.

The commit message is stale, as the help text, the target is now "docker-test" which is more intuitive.

Fam

Quoted 63 lines

`

Quoted 61 lines

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.

---
 Makefile                      |  4 +-
 tests/docker/Makefile.include | 93 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 tests/docker/Makefile.include
Makefile +3 -1
index f9fae3a..f104a08 100644
@@ -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
tests/docker/Makefile.include new file +23 -0
new file mode 100644
index 0000000..d8c55c3
@@ -0,0 +1,93 @@
+# Makefile for Docker tests
+
+$(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
+
+.PHONY: docker docker-test docker-clean docker-image
+
+DOCKER_SUFFIX := .docker
+
+DOCKER_IMAGES := $(notdir $(basename \
+	$(wildcard $(SRC_PATH)/tests/docker/dockerfiles/*)))
+
+DOCKER_TESTS := $(notdir $(shell \
+	find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f -executable))
+
+DOCKER_TOOLS := travis
+
+TESTS ?= %
+IMAGES ?= %
+
+$(foreach i,$(DOCKER_IMAGES), \
+	$(eval docker-image: docker-image-$i) \
+	$(eval docker-image-$i: IMAGE = $i) \
+	$(eval .PHONY: docker-image-$i docker-@$i) \
Quoted 8 lines
Quoted 8 lines

tests/docker/Makefile.include line 31

Quoted 8 lines
tests/docker/Makefile.include new file +8 -0
+	$(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
+		$(eval .PHONY: docker-$t@$i) \
+		$(eval docker-$t@$i: docker-image-$i) \
+		$(eval docker-$t@$i: docker-run-$t@$i) \
+		$(eval docker-@$i: docker-$t@$i) \
+		$(eval docker-test: docker-run-$t@$i) \
+	) \
+)

Also I think you need rules for updating the images here. I just updated ubuntu.docker to add libfdt-dev but on running on the command line:

09:53 alex@zen/x86_64 [qemu.git/review/docker-tests-v2] >make docker-image-ubuntu V=1 /home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: overriding commands for target clean-timestamp' /home/alex/lsrc/qemu/qemu.git/rules.mak:178: warning: ignoring old commands for target clean-timestamp'
make: Nothing to be done for `docker-image-ubuntu'.

--
Alex Bennée

#8 lore raw

Re: [Qemu-devel] [PATCH v2 02/15] Makefile: Rules for docker testing

In reply to Fam Zheng
Quoted 5 lines · Fam Zheng

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".

<snip>

OK I've made some tweaks which I think improve the generation and allow for re-creation of containers when the rules change. I still need an easy way to see the failed build when it does fail. I think this requires "docker logs" magic.

Anyway the current state of my Makefile.include attached:

--
Alex Bennée

author
#9 lore raw

PATCH v2 3/15 docker: Add images

In reply to Fam Zheng
---
 tests/docker/dockerfiles/centos6.docker | 5 +++++
 tests/docker/dockerfiles/fedora.docker  | 7 +++++++
 tests/docker/dockerfiles/ubuntu.docker  | 9 +++++++++
 3 files changed, 21 insertions(+)
 create mode 100644 tests/docker/dockerfiles/centos6.docker
 create mode 100644 tests/docker/dockerfiles/fedora.docker
 create mode 100644 tests/docker/dockerfiles/ubuntu.docker
tests/docker/dockerfiles/centos6.docker new file +5 -0
new file mode 100644
index 0000000..7daa2fb
@@ -0,0 +1,5 @@
+FROM centos:6
+RUN yum install -y \
+    git make gcc g++ \
+    zlib-devel glib2-devel SDL-devel pixman-devel
+
tests/docker/dockerfiles/fedora.docker new file +7 -0
new file mode 100644
index 0000000..81091b7
@@ -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
tests/docker/dockerfiles/ubuntu.docker new file +9 -0
new file mode 100644
index 0000000..f1dc518
@@ -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
Signature · 1 line
2.4.3
#10 lore raw

Re: [Qemu-devel] [PATCH v2 03/15] docker: Add images

Quoted 1 line · Fam Zheng

I think we need to include the dtc libs in here unless we need to ship all submodules in the tree as well.

Is there a way to get a plain install shell? PAUSE=1 on the test shells doesn't seem to allow me to install anything.

Quoted 39 lines
---
 tests/docker/dockerfiles/centos6.docker | 5 +++++
 tests/docker/dockerfiles/fedora.docker  | 7 +++++++
 tests/docker/dockerfiles/ubuntu.docker  | 9 +++++++++
 3 files changed, 21 insertions(+)
 create mode 100644 tests/docker/dockerfiles/centos6.docker
 create mode 100644 tests/docker/dockerfiles/fedora.docker
 create mode 100644 tests/docker/dockerfiles/ubuntu.docker
tests/docker/dockerfiles/centos6.docker new file +5 -0
new file mode 100644
index 0000000..7daa2fb
@@ -0,0 +1,5 @@
+FROM centos:6
+RUN yum install -y \
+    git make gcc g++ \
+    zlib-devel glib2-devel SDL-devel pixman-devel
+
tests/docker/dockerfiles/fedora.docker new file +7 -0
new file mode 100644
index 0000000..81091b7
@@ -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
tests/docker/dockerfiles/ubuntu.docker new file +0 -0
new file mode 100644
index 0000000..f1dc518

tests/docker/dockerfiles/ubuntu.docker line 9

Quoted 9 lines
tests/docker/dockerfiles/ubuntu.docker new file +9 -0
@@ -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

--
Alex Bennée

author
#11 lore raw

Re: [Qemu-devel] [PATCH v2 03/15] docker: Add images

Quoted 7 lines · Alex Bennée
Quoted 1 line · Fam Zheng

I think we need to include the dtc libs in here unless we need to ship all submodules in the tree as well.

OK, will take a look.

Quoted 3 lines

Is there a way to get a plain install shell? PAUSE=1 on the test shells doesn't seem to allow me to install anything.

What is the error when you install things? I think it is an unmodified shell and "yum" or "apt-get" should just work. It's just that when the container exits the changes will be discarded.

Fam

#12 lore raw

Re: [Qemu-devel] [PATCH v2 03/15] docker: Add images

Quoted 12 lines · Fam Zheng
Quoted 7 lines · Alex Bennée
Quoted 1 line · Fam Zheng

I think we need to include the dtc libs in here unless we need to ship all submodules in the tree as well.

OK, will take a look.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

Is there a way to get a plain install shell? PAUSE=1 on the test shells doesn't seem to allow me to install anything.

What is the error when you install things? I think it is an unmodified shell and "yum" or "apt-get" should just work. It's just that when the container exits the changes will be discarded.

So running:

make docker-test-quick@ubuntu PAUSE=1

And I got a shell I wanted to try and get working:

root@72d09615d5b2:/var/tmp/qemu.tmp# ./configure

ERROR: DTC (libfdt) version >= 1.4.0 not present. Your options:
(1) Preferred: Install the DTC (libfdt) devel package
(2) Fetch the DTC submodule, using:
git submodule update --init dtc

root@72d09615d5b2:/var/tmp/qemu.tmp# apt-cache search libfdt
libfdt-dev - Flat Device Trees manipulation library - development
files
libfdt1 - Flat Device Trees manipulation library
root@72d09615d5b2:/var/tmp/qemu.tmp# apt-get install libfdt-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libfdt1
The following NEW packages will be installed:
libfdt-dev libfdt1
0 upgraded, 2 newly installed, 0 to remove and 10 not upgraded.
Need to get 37.8 kB of archives.
After this operation, 216 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Err http://archive.ubuntu.com/ubuntu/ trusty/main libfdt1 amd64
1.4.0+dfsg-1
Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com/ubuntu/ trusty/main libfdt-dev amd64
1.4.0+dfsg-1
Could not resolve 'archive.ubuntu.com'
E: Failed to fetch
http://archive.ubuntu.com/ubuntu/pool/main/d/device-tree-compiler/libfdt1_1.4.0+dfsg-1_amd64.deb
Could not resolve 'archive.ubuntu.com'

E: Failed to fetch
http://archive.ubuntu.com/ubuntu/pool/main/d/device-tree-compiler/libfdt-dev_1.4.0+dfsg-1_amd64.deb
Could not resolve 'archive.ubuntu.com'

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

root@72d09615d5b2:/var/tmp/qemu.tmp# apt-get update
Err http://archive.ubuntu.com trusty InRelease

Err http://archive.ubuntu.com trusty-updates InRelease

Err http://archive.ubuntu.com trusty-security InRelease

Err http://archive.ubuntu.com trusty Release.gpg Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-updates Release.gpg Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-security Release.gpg Could not resolve 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-security/InRelease

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg Could not resolve 'archive.ubuntu.com'

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg
Could not resolve 'archive.ubuntu.com'

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg
Could not resolve 'archive.ubuntu.com'

W: Some index files failed to download. They have been ignored, or old ones used instead.

So it looks like networking isn't working in the test images. For debugging problems I think we need to be able to install stuff on a running image so we can then fix the base recipes.

Quoted 2 lines

Fam

--
Alex Bennée

author
#13 lore raw

Re: [Qemu-devel] [PATCH v2 03/15] docker: Add images

Quoted 102 lines · Alex Bennée
Quoted 12 lines · Fam Zheng
Quoted 7 lines · Alex Bennée
Quoted 1 line · Fam Zheng

I think we need to include the dtc libs in here unless we need to ship all submodules in the tree as well.

OK, will take a look.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

Is there a way to get a plain install shell? PAUSE=1 on the test shells doesn't seem to allow me to install anything.

What is the error when you install things? I think it is an unmodified shell and "yum" or "apt-get" should just work. It's just that when the container exits the changes will be discarded.

So running:

make docker-test-quick@ubuntu PAUSE=1

And I got a shell I wanted to try and get working:

root@72d09615d5b2:/var/tmp/qemu.tmp# ./configure

ERROR: DTC (libfdt) version >= 1.4.0 not present. Your options:
(1) Preferred: Install the DTC (libfdt) devel package
(2) Fetch the DTC submodule, using:
git submodule update --init dtc

root@72d09615d5b2:/var/tmp/qemu.tmp# apt-cache search libfdt
libfdt-dev - Flat Device Trees manipulation library - development
files
libfdt1 - Flat Device Trees manipulation library
root@72d09615d5b2:/var/tmp/qemu.tmp# apt-get install libfdt-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libfdt1
The following NEW packages will be installed:
libfdt-dev libfdt1
0 upgraded, 2 newly installed, 0 to remove and 10 not upgraded.
Need to get 37.8 kB of archives.
After this operation, 216 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Err http://archive.ubuntu.com/ubuntu/ trusty/main libfdt1 amd64
1.4.0+dfsg-1
Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com/ubuntu/ trusty/main libfdt-dev amd64
1.4.0+dfsg-1
Could not resolve 'archive.ubuntu.com'
E: Failed to fetch
http://archive.ubuntu.com/ubuntu/pool/main/d/device-tree-compiler/libfdt1_1.4.0+dfsg-1_amd64.deb
Could not resolve 'archive.ubuntu.com'

E: Failed to fetch
http://archive.ubuntu.com/ubuntu/pool/main/d/device-tree-compiler/libfdt-dev_1.4.0+dfsg-1_amd64.deb
Could not resolve 'archive.ubuntu.com'

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

root@72d09615d5b2:/var/tmp/qemu.tmp# apt-get update
Err http://archive.ubuntu.com trusty InRelease

Err http://archive.ubuntu.com trusty-updates InRelease

Err http://archive.ubuntu.com trusty-security InRelease

Err http://archive.ubuntu.com trusty Release.gpg Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-updates Release.gpg Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-security Release.gpg Could not resolve 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-security/InRelease

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg Could not resolve 'archive.ubuntu.com'

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg
Could not resolve 'archive.ubuntu.com'

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg
Could not resolve 'archive.ubuntu.com'

Quoted 7 lines

W: Some index files failed to download. They have been ignored, or old ones used instead.

So it looks like networking isn't working in the test images. For debugging problems I think we need to be able to install stuff on a running image so we can then fix the base recipes.

Oh yes, I added "-net=none" to the "docker run" command for better isolation. So in this case we should enable it. Let's rename PAUSE=1 to DEBUG=1 and enable network.

Fam

#14 lore raw

Re: [Qemu-devel] [PATCH v2 03/15] docker: Add images

Quoted 107 lines · Fam Zheng
Quoted 106 lines · Alex Bennée
Quoted 12 lines · Fam Zheng
Quoted 7 lines · Alex Bennée
Quoted 1 line · Fam Zheng

I think we need to include the dtc libs in here unless we need to ship all submodules in the tree as well.

OK, will take a look.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

Is there a way to get a plain install shell? PAUSE=1 on the test shells doesn't seem to allow me to install anything.

What is the error when you install things? I think it is an unmodified shell and "yum" or "apt-get" should just work. It's just that when the container exits the changes will be discarded.

So running:

make docker-test-quick@ubuntu PAUSE=1

And I got a shell I wanted to try and get working:

root@72d09615d5b2:/var/tmp/qemu.tmp# ./configure

ERROR: DTC (libfdt) version >= 1.4.0 not present. Your options:
(1) Preferred: Install the DTC (libfdt) devel package
(2) Fetch the DTC submodule, using:
git submodule update --init dtc

root@72d09615d5b2:/var/tmp/qemu.tmp# apt-cache search libfdt
libfdt-dev - Flat Device Trees manipulation library - development
files
libfdt1 - Flat Device Trees manipulation library
root@72d09615d5b2:/var/tmp/qemu.tmp# apt-get install libfdt-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libfdt1
The following NEW packages will be installed:
libfdt-dev libfdt1
0 upgraded, 2 newly installed, 0 to remove and 10 not upgraded.
Need to get 37.8 kB of archives.
After this operation, 216 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Err http://archive.ubuntu.com/ubuntu/ trusty/main libfdt1 amd64
1.4.0+dfsg-1
Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com/ubuntu/ trusty/main libfdt-dev amd64
1.4.0+dfsg-1
Could not resolve 'archive.ubuntu.com'
E: Failed to fetch
http://archive.ubuntu.com/ubuntu/pool/main/d/device-tree-compiler/libfdt1_1.4.0+dfsg-1_amd64.deb
Could not resolve 'archive.ubuntu.com'

E: Failed to fetch
http://archive.ubuntu.com/ubuntu/pool/main/d/device-tree-compiler/libfdt-dev_1.4.0+dfsg-1_amd64.deb
Could not resolve 'archive.ubuntu.com'

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

root@72d09615d5b2:/var/tmp/qemu.tmp# apt-get update
Err http://archive.ubuntu.com trusty InRelease

Err http://archive.ubuntu.com trusty-updates InRelease

Err http://archive.ubuntu.com trusty-security InRelease

Err http://archive.ubuntu.com trusty Release.gpg Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-updates Release.gpg Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-security Release.gpg Could not resolve 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-security/InRelease

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg Could not resolve 'archive.ubuntu.com'

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg
Could not resolve 'archive.ubuntu.com'

W: Failed to fetch
http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg
Could not resolve 'archive.ubuntu.com'

W: Some index files failed to download. They have been ignored, or old ones used instead.

Quoted 7 lines
Quoted 3 lines

So it looks like networking isn't working in the test images. For debugging problems I think we need to be able to install stuff on a running image so we can then fix the base recipes.

Oh yes, I added "-net=none" to the "docker run" command for better isolation. So in this case we should enable it. Let's rename PAUSE=1 to DEBUG=1 and enable network.

Sounds good.

Quoted 2 lines

Fam

--
Alex Bennée

author
#15 lore raw

PATCH v2 4/15 docker: Add test runner

In reply to Fam Zheng

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

---
 tests/docker/run | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100755 tests/docker/run
tests/docker/run new file +26 -0
new file mode 100755
index 0000000..55b2737
@@ -0,0 +1,26 @@
+#!/bin/bash -e
+#
+# Docker test runner
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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"
+if test -n "$J"; then
+    export MAKEFLAGS="$MAKEFLAGS -j$J"
+fi
+
+cd $QEMU_SRC/tests/docker
+"$@"
Signature · 1 line
2.4.3
author
#16 lore raw

PATCH v2 5/15 docker: Add common.rc

In reply to Fam Zheng

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

---
 tests/docker/common.rc | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100755 tests/docker/common.rc
tests/docker/common.rc new file +29 -0
new file mode 100755
index 0000000..34b009e
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# Common routines for docker test scripts.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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()
+{
+    make -C $QEMU_SRC distclean &>/dev/null
+    $QEMU_SRC/configure "$@"
+    make $MAKEFLAGS
+}
Signature · 1 line
2.4.3
author
#17 lore raw

PATCH v2 6/15 docker: Add quick test

In reply to Fam Zheng
---
 tests/docker/test-quick | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100755 tests/docker/test-quick
tests/docker/test-quick new file +23 -0
new file mode 100755
index 0000000..ce3cc99
@@ -0,0 +1,23 @@
+#!/bin/bash -e
+#
+# Quick compiling test that everyone already does. But why not automate it?
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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
+
+mkdir build
+mkdir install
+cd build
+build_qemu \
+    --prefix="${pwd}/install" \
+    --target-list="$(echo {x86_64,i386,arm,aarch64}-{softmmu,linux-user})"
+make check $MAKEFLAGS
+make install
Signature · 1 line
2.4.3
author
#18 lore raw

PATCH v2 7/15 docker: Add full test

In reply to Fam Zheng

This builds all available targets.

---
 tests/docker/test-full | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100755 tests/docker/test-full
tests/docker/test-full new file +21 -0
new file mode 100755
index 0000000..5708d0b
@@ -0,0 +1,21 @@
+#!/bin/bash -e
+#
+# Compile all the targets.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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
+
+mkdir build
+mkdir install
+cd build
+build_qemu --prefix="${pwd}/install"
+make check $MAKEFLAGS
+make install
Signature · 1 line
2.4.3
author
#19 lore raw

PATCH v2 8/15 docker: Add clang test

In reply to Fam Zheng

The configure options are suggested by John Snow <[email protected]>.

---
 tests/docker/test-clang | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100755 tests/docker/test-clang
tests/docker/test-clang new file +28 -0
new file mode 100755
index 0000000..212f481
@@ -0,0 +1,28 @@
+#!/bin/bash -e
+#
+# Compile and check with clang.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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
+
+mkdir build
+cd build
+# -fsanitize=undefined is broken on Fedora 23, skip it for now
+# See also: https://bugzilla.redhat.com/show_bug.cgi?id=1263834
+#OPTS="$OPTS --extra-cflags=-fsanitize=undefined \
+    #--extra-cflags=-fno-sanitize=float-divide-by-zero"
+build_qemu \
+    --target-list=x86_64-softmmu,aarch64-softmmu \
+    --enable-debug --cxx=clang++ --cc=clang --host-cc=clang \
+    $OPTS
+make $MAKEFLAGS check
Signature · 1 line
2.4.3
author
#20 lore raw

PATCH v2 9/15 docker: Add mingw test

In reply to Fam Zheng
---
 tests/docker/test-mingw | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100755 tests/docker/test-mingw
tests/docker/test-mingw new file +36 -0
new file mode 100755
index 0000000..25afa64
@@ -0,0 +1,36 @@
+#!/bin/bash -e
+#
+# Cross compile QEMU with mingw toolchain on Linux.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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
+
+mkdir build
+cd build
+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
+    make clean
+
+done
+
Signature · 1 line
2.4.3
author
#21 lore raw

PATCH v2 10/15 docker: Add travis tool

In reply to Fam Zheng

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".

---
 tests/docker/travis    | 23 +++++++++++++++++++++++
 tests/docker/travis.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100755 tests/docker/travis
 create mode 100755 tests/docker/travis.py
tests/docker/travis new file +23 -0
new file mode 100755
index 0000000..dfea61f
@@ -0,0 +1,23 @@
+#!/bin/bash -e
+#
+# Mimic a travis testing matrix
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
+#  Fam Zheng <[email protected]>
+#
+# 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 "$QEMU_SRC"
+
+cmdfile=/tmp/travis_cmd_list.sh
+
+./tests/docker/travis.py .travis.yml > $cmdfile
+. $cmdfile
tests/docker/travis.py new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.4.3
author
#22 lore raw

PATCH v2 11/15 docs: Add text for tests/docker in build-system.txt

In reply to Fam Zheng
---
 docs/build-system.txt | 5 +++++
 1 file changed, 5 insertions(+)
docs/build-system.txt +5 -0
index 5ddddea..2af1e66 100644
@@ -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
 
Signature · 1 line
2.4.3
author
#23 lore raw

PATCH v2 12/15 .gitignore: Ignore temporary dockerfile

In reply to Fam Zheng

Docker build requires a "context" directory and we use the $QEMU_SRC/tests/docker/ directory, and the temoprary dockerfile has to be in the context.

docker_build normally cleans up this file but let's add an entry here just in case it fails to.

---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)
.gitignore +1 -0
index 88a80ff..a335b7b 100644
@@ -109,3 +109,4 @@ cscope.*
 tags
 TAGS
 *~
+/tests/docker/*.docker.tmp
Signature · 1 line
2.4.3
author
#24 lore raw

PATCH v2 13/15 MAINTAINERS: Add tests/docker

In reply to Fam Zheng
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 02710f8..15b8b93 100644
@@ -1584,3 +1584,10 @@ Build system architecture
 M: Daniel P. Berrange <[email protected]>
 S: Odd Fixes
 F: docs/build-system.txt
+
+Docker testing
+--------------
+Docker based testing framework and cases
+M: Fam Zheng <[email protected]>
+S: Maintained
+F: tests/docker/
Signature · 1 line
2.4.3
author
#25 lore raw

PATCH v2 14/15 docker: Support interactive shell for debugging

In reply to Fam Zheng

Specify "PAUSE=1" when invoking make docker-%, and a shell prompt will show up before the test runs.

---
 tests/docker/Makefile.include | 5 ++++-
 tests/docker/run              | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
tests/docker/Makefile.include +4 -1
index d8c55c3..aaf7d23 100644
@@ -60,6 +60,8 @@ docker:
 	@echo '    TESTS="x y z .."     Filters which tests to run (for docker-test).'
 	@echo '    J=[0..9]*            Overrides the -jN parameter for make commands'
 	@echo '                         (default is 1)'
+	@echo '    PAUSE=1              Stop and drop to shell in the created container'
+	@echo '                         before running the command.'
 
 docker-image-%:
 	@if test -z "$(IMAGE)"; then echo "Invalid target"; exit 1; fi
@@ -79,9 +81,10 @@ docker-run-%:
 		$(call quiet-command,\
 			$(SRC_PATH)/tests/docker/docker_run $(if $(KEEP),,--rm) \
 				--privileged -t --net=none \
+				$(if $(PAUSE),-i) \
 				-v $$(realpath $(SRC_PATH)):/var/tmp/qemu \
 				-e QEMU_SRC=/var/tmp/qemu \
-				-e V=$V -e J=$J \
+				-e V=$V -e J=$J -e PAUSE=$(PAUSE)\
 				-v /var/tmp/qemu-docker-ccache:/var/tmp/ccache \
 				-e CCACHE_DIR=/var/tmp/ccache \
 				qemu:$(IMAGE) \
tests/docker/run +8 -0
index 55b2737..cc8d246 100755
@@ -23,4 +23,12 @@ if test -n "$J"; then
 fi
 
 cd $QEMU_SRC/tests/docker
+
+if test -n "$PAUSE"; then
+    echo "* Prepared to run command:"
+    echo "  $@"
+    echo "* Hit Ctrl-D to continue, or type 'exit 1' to quit"
+    echo
+    $SHELL
+fi
 "$@"
Signature · 1 line
2.4.3
author
#26 lore raw

PATCH v2 15/15 tests/docker/Makefile.include: snapshot the src for docker

In reply to Fam Zheng

From: Alex Bennée <[email protected]>

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.

[Generate an unique directory under /tmp/ - Fam Zheng]
---
 tests/docker/Makefile.include | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
tests/docker/Makefile.include +18 -4
index aaf7d23..7cc2130 100644
@@ -2,7 +2,7 @@
 
 $(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
 
-.PHONY: docker docker-test docker-clean docker-image
+.PHONY: docker docker-test docker-clean docker-image docker-qemu-src
 
 DOCKER_SUFFIX := .docker
 
@@ -16,6 +16,21 @@ DOCKER_TOOLS := travis
 
 TESTS ?= %
 IMAGES ?= %
+SRC_COPY := $(shell mktemp -u /tmp/qemu-src.XXXXX)
+
+.PHONY: $(SRC_COPY)
+
+$(SRC_COPY):
+	@mkdir -p $@
+	$(call quiet-command, \
+		mkdir -p $@ && (if git diff-index --quiet HEAD -- &>/dev/null; then \
+			git archive -1 HEAD --format=tar.gz; \
+		else \
+			git archive -1 $$(git stash create) --format=tar.gz; \
+		fi) | tar -xz -C $@, \
+		"  COPY SRC $@")
+
+docker-qemu-src: $(SRC_COPY)
 
 $(foreach i,$(DOCKER_IMAGES), \
 	$(eval docker-image: docker-image-$i) \
@@ -23,8 +38,7 @@ $(foreach i,$(DOCKER_IMAGES), \
 	$(eval .PHONY: docker-image-$i docker-@$i) \
 	$(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
 		$(eval .PHONY: docker-$t@$i) \
-		$(eval docker-$t@$i: docker-image-$i) \
-		$(eval docker-$t@$i: docker-run-$t@$i) \
+		$(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
 		$(eval docker-@$i: docker-$t@$i) \
 		$(eval docker-test: docker-run-$t@$i) \
 	) \
@@ -73,7 +87,7 @@ docker-image-%:
 
 docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
 docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
-docker-run-%:
+docker-run-%: docker-qemu-src
 	@if test -z "$(IMAGE)" || test -z "$(CMD)"; \
 		then echo "Invalid target"; exit 1; \
 	fi
Signature · 1 line
2.4.3
#27 lore raw

Re: [Qemu-devel] [PATCH v2 15/15] tests/docker/Makefile.include: snapshot the src for docker

Quoted 7 lines · Fam Zheng

From: Alex Bennée <[email protected]>

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.

Quoted 5 lines

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

[Generate an unique directory under /tmp/ - Fam Zheng]

But the docker-run-% rule never uses the source copy we just made.

Quoted 51 lines
---
 tests/docker/Makefile.include | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
tests/docker/Makefile.include +17 -3
index aaf7d23..7cc2130 100644
@@ -2,7 +2,7 @@
 
 $(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
 
-.PHONY: docker docker-test docker-clean docker-image
+.PHONY: docker docker-test docker-clean docker-image docker-qemu-src
 
 DOCKER_SUFFIX := .docker
 
@@ -16,6 +16,21 @@ DOCKER_TOOLS := travis
 
 TESTS ?= %
 IMAGES ?= %
+SRC_COPY := $(shell mktemp -u /tmp/qemu-src.XXXXX)
+
+.PHONY: $(SRC_COPY)
+
+$(SRC_COPY):
+	@mkdir -p $@
+	$(call quiet-command, \
+		mkdir -p $@ && (if git diff-index --quiet HEAD -- &>/dev/null; then \
+			git archive -1 HEAD --format=tar.gz; \
+		else \
+			git archive -1 $$(git stash create) --format=tar.gz; \
+		fi) | tar -xz -C $@, \
+		"  COPY SRC $@")
+
+docker-qemu-src: $(SRC_COPY)
 
 $(foreach i,$(DOCKER_IMAGES), \
 	$(eval docker-image: docker-image-$i) \
@@ -23,8 +38,7 @@ $(foreach i,$(DOCKER_IMAGES), \
 	$(eval .PHONY: docker-image-$i docker-@$i) \
 	$(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
 		$(eval .PHONY: docker-$t@$i) \
-		$(eval docker-$t@$i: docker-image-$i) \
-		$(eval docker-$t@$i: docker-run-$t@$i) \
+		$(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
 		$(eval docker-@$i: docker-$t@$i) \
 		$(eval docker-test: docker-run-$t@$i) \
 	) \

tests/docker/Makefile.include docker-image-%: · line 93

Quoted 8 lines
tests/docker/Makefile.include +1 -1
@@ -73,7 +87,7 @@ docker-image-%:
 
 docker-run-%: CMD = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\1/')
 docker-run-%: IMAGE = $(shell echo '$@' | sed -e 's/docker-run-\([^@]*\)@\(.*\)/\2/')
-docker-run-%:
+docker-run-%: docker-qemu-src
 	@if test -z "$(IMAGE)" || test -z "$(CMD)"; \
 		then echo "Invalid target"; exit 1; \
 	fi

--
Alex Bennée

author
#28 lore raw

Re: [Qemu-devel] [PATCH v2 15/15] tests/docker/Makefile.include: snapshot the src for docker

Quoted 10 lines · Alex Bennée
Quoted 7 lines · Fam Zheng

From: Alex Bennée <[email protected]>

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.

Quoted 7 lines
Quoted 5 lines

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

[Generate an unique directory under /tmp/ - Fam Zheng]

But the docker-run-% rule never uses the source copy we just made.

I failed in Makefile magic: pattern rules and dynamically generated rules mustn't be used mixed, otherwise the former will be ignored. Will fix.

Fam

author
#29 lore raw
In reply to Fam Zheng
Quoted 8 lines · Fam Zheng

v2: - Fix a few coding style warnings of shellcheck and pylint.
[Marc-André Lureau]
- Rename make targets:
docker-run => docker-test
docker-build => docker-image docker-run-$TEST.sh@$IMAGE => docker-$TEST@$IMAGE
- In help, document the magic makefile vars which are "IMAGES=", "TESTS=", "J=" and "PAUSE="

Quoted 8 lines

- Rename test-basic => test-quick
- Move docker files to tests/docker/dockerfiles/
- Add "test-full" that builds all targets
- Workaround broken clang for fedora 23
- Add commit log for .gitignore changes [Alex]
- Add "rev-by" in patch 13. [Alex]
- Add patch 14 to make debugging easier [Alex]
- Adopt Alex's "git archive" idea

Alex, any comments on this?

Fam

#30 lore raw
Quoted 18 lines · Fam Zheng
Quoted 8 lines · Fam Zheng

v2: - Fix a few coding style warnings of shellcheck and pylint.
[Marc-André Lureau]
- Rename make targets:
docker-run => docker-test
docker-build => docker-image docker-run-$TEST.sh@$IMAGE => docker-$TEST@$IMAGE
- In help, document the magic makefile vars which are "IMAGES=", "TESTS=", "J=" and "PAUSE="

Quoted 8 lines

- Rename test-basic => test-quick
- Move docker files to tests/docker/dockerfiles/
- Add "test-full" that builds all targets
- Workaround broken clang for fedora 23
- Add commit log for .gitignore changes [Alex]
- Add "rev-by" in patch 13. [Alex]
- Add patch 14 to make debugging easier [Alex]
- Adopt Alex's "git archive" idea

Quoted 1 line

Alex, any comments on this?

Yeah sorry for the delay, I'm just starting on this now.

--
Alex Bennée

#31 lore raw
Quoted 20 lines · Alex Bennée
Quoted 18 lines · Fam Zheng
Quoted 16 lines · Fam Zheng

v2: - Fix a few coding style warnings of shellcheck and pylint.
[Marc-André Lureau]
- Rename make targets:
docker-run => docker-test
docker-build => docker-image docker-run-$TEST.sh@$IMAGE => docker-$TEST@$IMAGE
- In help, document the magic makefile vars which are "IMAGES=", "TESTS=", "J=" and "PAUSE="
- Rename test-basic => test-quick
- Move docker files to tests/docker/dockerfiles/
- Add "test-full" that builds all targets
- Workaround broken clang for fedora 23
- Add commit log for .gitignore changes [Alex]
- Add "rev-by" in patch 13. [Alex]
- Add patch 14 to make debugging easier [Alex]
- Adopt Alex's "git archive" idea

Quoted 3 lines
Quoted 1 line

Alex, any comments on this?

Yeah sorry for the delay, I'm just starting on this now.

OK I'm not sure I can go on without an easier way off seeing where it is failing when it fails. Can we pass optional verbosity down to the final build and tests?

--
Alex Bennée