Skip to contentSkip to conversation

tests: Introducing docker tests

PATCH Superseded Fam Zheng 3 participants 42 messages Mar 4, 2016 – Mar 17, 2016 Kbuild

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

v3 cover tests: Introducing docker tests

v3 changes:
- Merge all docker_* tools into docker.py as subcommands, and add simple help texts; clean up docker.py a bit.
- For ease of management of the series, squashed Alex's COPY_SRC patch into patch 2.
- Pick up Alex's tweaks on Makefile changes.
- Change the way we copy source. Now we send source tarballs to the container, and untar it there. Beside qemu.tgz, also copy dtc.tgz and pixman.tgz if submodules are initialized in the tree. The first is required by mingw test.
- Update test runner to adapt to above change.
- Tweak "make docker" help text. Dropped "docker-@IMAGE" because it is equivalent to "make docker-test IMAGES=XXX". Too many targets will be hard to memorize, and we can always add more shortcuts if desired.
- Drop "PAUSE=1" env and add "DEBUG=1", which will also enable networking, and drop to shell when test fails.
- Add "NOCACHE=1" env var to add "--no-cache" to "docker build" command, which is useful in certain cases to workaround image build failure. For example in ubuntu when "apt-get update" is cached, "apt-get install xxx" can get 404.
- Add libfdt-devel to images.
- Add epel, and ccache in centos6.
- Add "TARGET_LIST=" env var.
- Add "sparse" from multiverse for ubuntu, which is used by travis tool.

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.

Fam Zheng (13):
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

 .gitignore                              |   1 +
 MAINTAINERS                             |   7 ++
 Makefile                                |   4 +-
 docs/build-system.txt                   |   5 +
 tests/docker/Makefile.include           | 121 +++++++++++++++++++++
 tests/docker/common.rc                  |  31 ++++++
 tests/docker/docker.py                  | 180 ++++++++++++++++++++++++++++++++
 tests/docker/dockerfiles/centos6.docker |   6 ++
 tests/docker/dockerfiles/fedora.docker  |   7 ++
 tests/docker/dockerfiles/ubuntu.docker  |  11 ++
 tests/docker/run                        |  58 ++++++++++
 tests/docker/test-clang                 |  25 +++++
 tests/docker/test-full                  |  17 +++
 tests/docker/test-mingw                 |  34 ++++++
 tests/docker/test-quick                 |  19 ++++
 tests/docker/travis                     |  21 ++++
 tests/docker/travis.py                  |  48 +++++++++
 17 files changed, 594 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 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 v3 1/13 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 | 180 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 180 insertions(+)
 create mode 100755 tests/docker/docker.py
tests/docker/docker.py new file +180 -0
new file mode 100755
index 0000000..22f537c
@@ -0,0 +1,180 @@
+#!/usr/bin/env python2
+#
+# 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 sys
+import subprocess
+import json
+import hashlib
+import atexit
+import uuid
+import argparse
+
+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, argv=[]):
+        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] + argv + [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
+
+class SubCommand(object):
+    """A SubCommand template base class"""
+    name = None # Subcommand name
+    def args(self, parser):
+        """Setup argument parser"""
+        pass
+    def run(self, args, argv):
+        """Run command.
+        args: parsed argument by argument parser.
+        argv: remaining arguments from sys.argv.
+        """
+        pass
+
+class RunCommand(SubCommand):
+    """Invoke docker run and take care of cleaning up"""
+    name = "run"
+    def args(self, parser):
+        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")
+    def run(self, args, argv):
+        return Docker().run(argv, args.keep, quiet=args.quiet)
+
+class BuildCommand(SubCommand):
+    """ Build docker image out of a dockerfile"""
+    name = "build"
+    def args(self, parser):
+        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")
+
+    def run(self, args, argv):
+        dockerfile = open(args.dockerfile, "rb").read()
+        tag = args.tag
+
+        dkr = 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, argv=argv)
+        return 0
+
+class CleanCommand(SubCommand):
+    """Clean up docker instances"""
+    name = "clean"
+    def run(self, args, argv):
+        Docker().clean()
+        return 0
+
+def main():
+    parser = argparse.ArgumentParser()
+    subparsers = parser.add_subparsers()
+    for cls in SubCommand.__subclasses__():
+        cmd = cls()
+        subp = subparsers.add_parser(cmd.name, help=cmd.__doc__)
+        cmd.args(subp)
+        subp.set_defaults(cmdobj=cmd)
+    args, argv = parser.parse_known_args()
+    return args.cmdobj.run(args, argv)
+
+if __name__ == "__main__":
+    sys.exit(main())
Signature · 1 line
2.4.3
#2 lore raw

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

Quoted 9 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.

This commit text needs updating with the actual calling conventions.

Quoted 15 lines
---
 tests/docker/docker.py | 180 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 180 insertions(+)
 create mode 100755 tests/docker/docker.py
tests/docker/docker.py new file +2 -0
new file mode 100755
index 0000000..22f537c
@@ -0,0 +1,180 @@
+#!/usr/bin/env python2
+#

tests/docker/docker.py line 12

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

It's worth running pylint over this file. There are a number of missing newlines/spaces/long lines that aren't PEP friendly.

Quoted 72 lines
tests/docker/docker.py new file +72 -0
+
+import os
+import sys
+import subprocess
+import json
+import hashlib
+import atexit
+import uuid
+import argparse
+
+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()
+

tests/docker/docker.py line 94

Quoted 10 lines
tests/docker/docker.py new file +10 -0
+    def build_image(self, tag, dockerfile, df, quiet=True, argv=[]):
+        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] + argv + [os.path.dirname(df)],
+                 quiet=quiet)
+        os.unlink(tmp_df)

Use python's tempfile to do this. It handles all the lifetime issues for you automatically - the file gets removed when the object goes out of scope.

Quoted 38 lines
tests/docker/docker.py new file +38 -0
+
+    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
+
+class SubCommand(object):
+    """A SubCommand template base class"""
+    name = None # Subcommand name
+    def args(self, parser):
+        """Setup argument parser"""
+        pass
+    def run(self, args, argv):
+        """Run command.
+        args: parsed argument by argument parser.
+        argv: remaining arguments from sys.argv.
+        """
+        pass
+
+class RunCommand(SubCommand):
+    """Invoke docker run and take care of cleaning up"""
+    name = "run"
+    def args(self, parser):
+        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
Quoted 1 line

occured")

I suspect --quiet should be a shared global flag.

Also it would be worth adding help text to show the remaining args are passed "as is" to the docker command line.

tests/docker/docker.py line 145

Quoted 13 lines
tests/docker/docker.py new file +13 -0
+    def run(self, args, argv):
+        return Docker().run(argv, args.keep, quiet=args.quiet)
+
+class BuildCommand(SubCommand):
+    """ Build docker image out of a dockerfile"""
+    name = "build"
+    def args(self, parser):
+        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")

I suspect --verbose should be a shared global flag.

Quoted 4 lines
tests/docker/docker.py new file +4 -0
+
+    def run(self, args, argv):
+        dockerfile = open(args.dockerfile, "rb").read()
+        tag = args.tag

tests/docker/docker.py line 159

Quoted 10 lines
tests/docker/docker.py new file +10 -0
+
+        dkr = 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, argv=argv)
+        return 0

I've seen this hang. Do builds always succeed?

Quoted 8 lines
tests/docker/docker.py new file +8 -0
+
+class CleanCommand(SubCommand):
+    """Clean up docker instances"""
+    name = "clean"
+    def run(self, args, argv):
+        Docker().clean()
+        return 0
+

tests/docker/docker.py line 177

Quoted 10 lines
tests/docker/docker.py new file +10 -0
+def main():
+    parser = argparse.ArgumentParser()
+    subparsers = parser.add_subparsers()
+    for cls in SubCommand.__subclasses__():
+        cmd = cls()
+        subp = subparsers.add_parser(cmd.name, help=cmd.__doc__)
+        cmd.args(subp)
+        subp.set_defaults(cmdobj=cmd)
+    args, argv = parser.parse_known_args()
+    return args.cmdobj.run(args, argv)

There are some niggles with help:

14:40 alex@zen/x86_64 [qemu.git/review/docker-v3]>./tests/docker/docker.py --help
usage: docker.py [-h] {run,build,clean} ...

positional arguments:
{run,build,clean}

Positional? Really. You can only have one command at a time.

      run              Invoke docker run and take care of cleaning up
      build            Build docker image out of a dockerfile
      clean            Clean up docker instances

optional arguments:
-h, --help show this help message and exit

OK that's useful, but do we have args for build?

14:43 alex@zen/x86_64 [qemu.git/review/docker-v3]>./tests/docker/docker.py --help build
usage: docker.py [-h] {run,build,clean} ...

positional arguments:
{run,build,clean}

      run              Invoke docker run and take care of cleaning up
      build            Build docker image out of a dockerfile
      clean            Clean up docker instances

optional arguments:
-h, --help show this help message and exit

Hmm same result. We have to call like this:

14:43 alex@zen/x86_64 [qemu.git/review/docker-v3] >./tests/docker/docker.py build --help
usage: docker.py build [-h] [--verbose] tag dockerfile

positional arguments:
tag Image Tag
dockerfile Dockerfile name

optional arguments:
-h, --help show this help message and exit
--verbose, -v Print verbose information

Maybe there is someway to make this clearer.

tests/docker/docker.py line 180

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

--
Alex Bennée

author
#3 lore raw

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

Quoted 7 lines · Alex Bennée
Quoted 4 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.

Quoted 7 lines
Quoted 5 lines

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.

This commit text needs updating with the actual calling conventions.

Will do.

Quoted 21 lines
Quoted 21 lines
---
 tests/docker/docker.py | 180 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 180 insertions(+)
 create mode 100755 tests/docker/docker.py
tests/docker/docker.py new file +7 -0
new file mode 100755
index 0000000..22f537c
@@ -0,0 +1,180 @@
+#!/usr/bin/env python2
+#
+# Docker controlling module
+#
+# Copyright (c) 2016 Red Hat Inc.
+#
+# Authors:
Quoted 8 lines

tests/docker/docker.py line 12

Quoted 5 lines
tests/docker/docker.py new file +5 -0
+#  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.

It's worth running pylint over this file. There are a number of missing newlines/spaces/long lines that aren't PEP friendly.

I'll run this through pylint.

Quoted 78 lines
Quoted 78 lines
tests/docker/docker.py new file +77 -0
+
+import os
+import sys
+import subprocess
+import json
+import hashlib
+import atexit
+import uuid
+import argparse
+
+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, argv=[]):
+        tmp = dockerfile + "\n" + \
+              "LABEL com.qemu.dockerfile-checksum=%s" % self.checksum(dockerfile)
+        tmp_df = df + ".tmp"
+        tmp_file = open(tmp_df, "wb")
Quoted 8 lines

tests/docker/docker.py line 94

Quoted 5 lines
tests/docker/docker.py new file +5 -0
+        tmp_file.write(tmp)
+        tmp_file.close()
+        self._do(["build", "-t", tag, "-f", tmp_df] + argv + [os.path.dirname(df)],
+                 quiet=quiet)
+        os.unlink(tmp_df)

Use python's tempfile to do this. It handles all the lifetime issues for you automatically - the file gets removed when the object goes out of scope.

Okay, will do.

Quoted 34 lines
Quoted 34 lines
tests/docker/docker.py new file +33 -0
+
+    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
+
+class SubCommand(object):
+    """A SubCommand template base class"""
+    name = None # Subcommand name
+    def args(self, parser):
+        """Setup argument parser"""
+        pass
+    def run(self, args, argv):
+        """Run command.
+        args: parsed argument by argument parser.
+        argv: remaining arguments from sys.argv.
+        """
+        pass
+
+class RunCommand(SubCommand):
+    """Invoke docker run and take care of cleaning up"""
+    name = "run"
Quoted 8 lines
Quoted 6 lines
tests/docker/docker.py new file +5 -0
+    def args(self, parser):
+        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")

I suspect --quiet should be a shared global flag.

Will change, so the --verbose in build subcommand below will be expressed in !quiet.

Quoted 3 lines

Also it would be worth adding help text to show the remaining args are passed "as is" to the docker command line.

Yes, good point.

Quoted 17 lines
Quoted 4 lines
tests/docker/docker.py new file +3 -0
+    def run(self, args, argv):
+        return Docker().run(argv, args.keep, quiet=args.quiet)
+

tests/docker/docker.py line 145

Quoted 10 lines
tests/docker/docker.py new file +10 -0
+class BuildCommand(SubCommand):
+    """ Build docker image out of a dockerfile"""
+    name = "build"
+    def args(self, parser):
+        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")

I suspect --verbose should be a shared global flag.

Quoted 16 lines
Quoted 4 lines
tests/docker/docker.py new file +4 -0
+
+    def run(self, args, argv):
+        dockerfile = open(args.dockerfile, "rb").read()
+        tag = args.tag

tests/docker/docker.py line 159

Quoted 10 lines
tests/docker/docker.py new file +10 -0
+
+        dkr = 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, argv=argv)
+        return 0

I've seen this hang. Do builds always succeed?

It does "{apt-get,yum,dnf} install", which could block due to network issues.

Quoted 22 lines
Quoted 9 lines
tests/docker/docker.py new file +8 -0
+
+class CleanCommand(SubCommand):
+    """Clean up docker instances"""
+    name = "clean"
+    def run(self, args, argv):
+        Docker().clean()
+        return 0
+

tests/docker/docker.py line 177

Quoted 10 lines
tests/docker/docker.py new file +10 -0
+def main():
+    parser = argparse.ArgumentParser()
+    subparsers = parser.add_subparsers()
+    for cls in SubCommand.__subclasses__():
+        cmd = cls()
+        subp = subparsers.add_parser(cmd.name, help=cmd.__doc__)
+        cmd.args(subp)
+        subp.set_defaults(cmdobj=cmd)
+    args, argv = parser.parse_known_args()
+    return args.cmdobj.run(args, argv)

There are some niggles with help:

Quoted 7 lines

14:40 alex@zen/x86_64 [qemu.git/review/docker-v3]>./tests/docker/docker.py --help
usage: docker.py [-h] {run,build,clean} ...

positional arguments:
{run,build,clean}

Positional? Really. You can only have one command at a time.

That's the default output of Python's argparse module.

Quoted 31 lines
      run              Invoke docker run and take care of cleaning up
      build            Build docker image out of a dockerfile
      clean            Clean up docker instances

optional arguments:
-h, --help show this help message and exit

OK that's useful, but do we have args for build?

14:43 alex@zen/x86_64 [qemu.git/review/docker-v3]>./tests/docker/docker.py --help build
usage: docker.py [-h] {run,build,clean} ...

positional arguments:
{run,build,clean}

      run              Invoke docker run and take care of cleaning up
      build            Build docker image out of a dockerfile
      clean            Clean up docker instances

optional arguments:
-h, --help show this help message and exit

Hmm same result. We have to call like this:

14:43 alex@zen/x86_64 [qemu.git/review/docker-v3] >./tests/docker/docker.py build --help
usage: docker.py build [-h] [--verbose] tag dockerfile

positional arguments:
tag Image Tag
dockerfile Dockerfile name

Quoted 5 lines

optional arguments:
-h, --help show this help message and exit
--verbose, -v Print verbose information

Maybe there is someway to make this clearer.

I'll try. Thanks for your input!

Fam

Quoted 8 lines

tests/docker/docker.py line 180

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

--
Alex Bennée

author
#4 lore raw

PATCH v3 2/13 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.

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.

---
 Makefile                      |   4 +-
 tests/docker/Makefile.include | 121 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+), 1 deletion(-)
 create mode 100644 tests/docker/Makefile.include
Makefile +3 -1
index 70e3ebc..b0dccc5 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 +121 -0

121 lines not on this page · raw message

Signature · 1 line
2.4.3
Reviewed-by on v3 2/13
#5 lore raw

Re: [Qemu-devel] [PATCH v3 02/13] 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"

I thought I mentioned this last time, it needs fixing in the commit message:

15:05 alex@zen/x86_64 [qemu.git/review/docker-v3] >make docker-run IMAGES="ubuntu fedora"
make: *** No rule to make target `docker-run'. Stop.

Quoted 11 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.

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.

fix the commit message and have a:

Quoted 142 lines
---
 Makefile                      |   4 +-
 tests/docker/Makefile.include | 121 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+), 1 deletion(-)
 create mode 100644 tests/docker/Makefile.include
Makefile +3 -1
index 70e3ebc..b0dccc5 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 +111 -0
new file mode 100644
index 0000000..4ca84c9
@@ -0,0 +1,121 @@
+# Makefile for Docker tests
+
+$(if $(quiet-command),,$(eval include $(SRC_PATH)/rules.mak))
+
+.PHONY: docker docker-test docker-clean docker-image docker-qemu-src
+
+DOCKER_SUFFIX := .docker
+DOCKER_FILES_DIR := $(SRC_PATH)/tests/docker/dockerfiles
+DOCKER_IMAGES := $(notdir $(basename $(wildcard $(DOCKER_FILES_DIR)/*.docker)))
+DOCKER_TARGETS := $(patsubst %,docker-image-%,$(DOCKER_IMAGES))
+# Use a global constant ccache directory to speed up repetitive builds
+DOCKER_CCACHE_DIR := /var/tmp/qemu-docker-ccache
+
+DOCKER_TESTS := $(notdir $(shell \
+	find $(SRC_PATH)/tests/docker/ -name 'test-*' -type f -executable))
+
+DOCKER_TOOLS := travis
+
+TESTS ?= %
+IMAGES ?= %
+SRC_COPY := $(shell mktemp -u /tmp/qemu-src.XXXXX)
+
+# Make archive from git repo $1 to tar.gz $2
+make-archive-maybe = $(if $(wildcard $1/*), \
+	$(call quiet-command, \
+		(cd $1; if git diff-index --quiet HEAD -- &>/dev/null; then \
+			git archive -1 HEAD --format=tar.gz -o $2; \
+		else \
+			git archive -1 $$(git stash create) --format=tar.gz -o $2; \
+		fi), \
+		"  ARCHIVE $(notdir $2)"))
+
+$(SRC_COPY):
+	@mkdir -p $@
+	$(call make-archive-maybe, $(SRC_PATH), $(SRC_COPY)/qemu.tgz)
+	$(call make-archive-maybe, $(SRC_PATH)/dtc, $(SRC_COPY)/dtc.tgz)
+	$(call make-archive-maybe, $(SRC_PATH)/pixman, $(SRC_COPY)/pixman.tgz)
+	$(call quiet-command, cp "$(SRC_PATH)/tests/docker/run" "$(SRC_COPY)/run", \
+		"  COPY RUNNER")
+
+docker-qemu-src: $(SRC_COPY)
+
+docker-image: ${DOCKER_TARGETS}
+
+# General rule for building docker images
+docker-image-%: $(DOCKER_FILES_DIR)/%.docker
+	$(call quiet-command,\
+		$(SRC_PATH)/tests/docker/docker.py build qemu:$* $< \
+		$(if $V,-v,) $(if $(NOCACHE),--no-cache),\
+		"  BUILD $*")
+
+# Expand all the pre-requistes for each docker image and test combination
+$(foreach i,$(DOCKER_IMAGES), \
+	$(foreach t,$(DOCKER_TESTS) $(DOCKER_TOOLS), \
+		$(eval .PHONY: docker-$t@$i) \
+		$(eval docker-$t@$i: docker-image-$i docker-run-$t@$i) \
+	) \
+	$(foreach t,$(DOCKER_TESTS), \
+		$(eval docker-test: docker-$t@$i) \
+	) \
+)
+
+docker:
+	@echo 'Build QEMU and run 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:        Build all images.'
+	@echo '    docker-image-IMAGE:  Build image "IMG".'
+	@echo
+	@echo 'Available container images:'
+	@echo '    $(DOCKER_IMAGES)'
+	@echo
+	@echo 'Available tests:'
+	@echo '    $(DOCKER_TESTS)'
+	@echo
+	@echo 'Available tools:'
+	@echo '    $(DOCKER_TOOLS)'
+	@echo
+	@echo 'Special variables:'
+	@echo '    TARGET_LIST=a,b,c    Override target list in builds.'
+	@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)'
+	@echo '    DEBUG=1              Stop and drop to shell in the created container'
+	@echo '                         before running the command.'
+	@echo '    NOCACHE=1            Ignore cache when build images.'
+
+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-qemu-src
+	@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.py run $(if $V,,--rm) \
+				--privileged -t \
+				$(if $(DEBUG),-i,--net=none) \
+				-e TARGET_LIST=$(TARGET_LIST) \
+				-e V=$V -e J=$J -e DEBUG=$(DEBUG)\
+				-e CCACHE_DIR=/var/tmp/ccache \
+				-v $$(realpath $(SRC_COPY)):/var/tmp/qemu:ro \

tests/docker/Makefile.include line 121

Quoted 10 lines
tests/docker/Makefile.include new file +10 -0
+				-v $(DOCKER_CCACHE_DIR):/var/tmp/ccache \
+				-w /var/tmp/qemu \
+				qemu:$(IMAGE) \
+				$(if $V,/bin/bash -x ,) \
+				./run \
+				$(CMD); \
+			, "  RUN $(CMD) in $(IMAGE)")))
+
+docker-clean:
+	$(call quiet-command, $(SRC_PATH)/tests/docker/docker.py clean)

--
Alex Bennée

author
#6 lore raw

Re: [Qemu-devel] [PATCH v3 02/13] Makefile: Rules for docker testing

Quoted 17 lines · Alex Bennée
Quoted 14 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.

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:

Quoted 8 lines
Quoted 1 line
    $ make docker-run IMAGES="ubuntu fedora"

I thought I mentioned this last time, it needs fixing in the commit message:

15:05 alex@zen/x86_64 [qemu.git/review/docker-v3] >make docker-run IMAGES="ubuntu fedora"
make: *** No rule to make target `docker-run'. Stop.

My bad!

Quoted 15 lines
Quoted 15 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.

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.

Quoted 6 lines
Quoted 2 lines

fix the commit message and have a:

Thanks!

Fam

author
#7 lore raw

PATCH v3 3/13 docker: Add images

In reply to Fam Zheng
---
 tests/docker/dockerfiles/centos6.docker |  6 ++++++
 tests/docker/dockerfiles/fedora.docker  |  7 +++++++
 tests/docker/dockerfiles/ubuntu.docker  | 11 +++++++++++
 3 files changed, 24 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 +6 -0
new file mode 100644
index 0000000..8f4fe46
@@ -0,0 +1,6 @@
+FROM centos:6
+RUN yum install -y \
+    tar git make gcc g++ \
+    zlib-devel glib2-devel SDL-devel pixman-devel \
+    epel-release
+RUN yum install -y libfdt-devel ccache
tests/docker/dockerfiles/fedora.docker new file +7 -0
new file mode 100644
index 0000000..6251e45
@@ -0,0 +1,7 @@
+FROM fedora:23
+RUN dnf install -y \
+    ccache git tar \
+    glib2-devel pixman-devel zlib-devel SDL-devel libfdt-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 +11 -0
new file mode 100644
index 0000000..725a7ca
@@ -0,0 +1,11 @@
+FROM ubuntu:14.04
+RUN echo "deb http://archive.ubuntu.com/ubuntu/ trusty universe multiverse" >> \
+    /etc/apt/sources.list
+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 libfdt-dev \
+    libgtk-3-dev libvte-2.90-dev libsdl1.2-dev libpng12-dev libpixman-1-dev \
+    git make ccache python-yaml gcc clang sparse
+ENV FEATURES clang ccache pyyaml
Signature · 1 line
2.4.3
Reviewed-by on v3 3/13
#8 lore raw

Re: [Qemu-devel] [PATCH v3 03/13] docker: Add images

Quoted 1 line · Fam Zheng
Quoted 41 lines
---
 tests/docker/dockerfiles/centos6.docker |  6 ++++++
 tests/docker/dockerfiles/fedora.docker  |  7 +++++++
 tests/docker/dockerfiles/ubuntu.docker  | 11 +++++++++++
 3 files changed, 24 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 +6 -0
new file mode 100644
index 0000000..8f4fe46
@@ -0,0 +1,6 @@
+FROM centos:6
+RUN yum install -y \
+    tar git make gcc g++ \
+    zlib-devel glib2-devel SDL-devel pixman-devel \
+    epel-release
+RUN yum install -y libfdt-devel ccache
tests/docker/dockerfiles/fedora.docker new file +7 -0
new file mode 100644
index 0000000..6251e45
@@ -0,0 +1,7 @@
+FROM fedora:23
+RUN dnf install -y \
+    ccache git tar \
+    glib2-devel pixman-devel zlib-devel SDL-devel libfdt-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 +1 -0
new file mode 100644
index 0000000..725a7ca
@@ -0,0 +1,11 @@
+FROM ubuntu:14.04

tests/docker/dockerfiles/ubuntu.docker line 11

Quoted 10 lines
tests/docker/dockerfiles/ubuntu.docker new file +10 -0
+RUN echo "deb http://archive.ubuntu.com/ubuntu/ trusty universe multiverse" >> \
+    /etc/apt/sources.list
+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 libfdt-dev \
+    libgtk-3-dev libvte-2.90-dev libsdl1.2-dev libpng12-dev libpixman-1-dev \
+    git make ccache python-yaml gcc clang sparse
+ENV FEATURES clang ccache pyyaml

--
Alex Bennée

author
#9 lore raw

PATCH v3 4/13 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.

If "DEBUG=1" a shell prompt will show up before the test runs.

---
 tests/docker/run | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100755 tests/docker/run
tests/docker/run new file +58 -0
new file mode 100755
index 0000000..ec3d119
@@ -0,0 +1,58 @@
+#!/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
+
+if test -n "$J"; then
+    export MAKEFLAGS="$MAKEFLAGS -j$J"
+fi
+
+# We are in the container so the whole file system belong to us
+export TEST_DIR=/tmp/qemu-test
+mkdir -p $TEST_DIR/{src,build,install}
+
+# Extract the source tarballs
+tar -C $TEST_DIR/src -xzf qemu.tgz
+for p in dtc pixman; do
+    if test -f $p.tgz; then
+        tar -C $TEST_DIR/src/$p -xzf $p.tgz
+        export FEATURES="$FEATURES $p"
+    fi
+done
+
+export QEMU_SRC="$TEST_DIR/src"
+
+cd "$QEMU_SRC/tests/docker"
+
+CMD="$QEMU_SRC/tests/docker/$@"
+
+if test -n "$DEBUG"; then
+    echo "* Prepared to run command:"
+    echo "  $CMD"
+    echo "* Hit Ctrl-D to continue, or type 'exit 1' to abort"
+    echo
+    $SHELL
+fi
+
+if "$CMD"; then
+    exit 0
+elif test -n "$DEBUG"; then
+    echo "* Command failed:"
+    echo "  $CMD"
+    echo "* Hit Ctrl-D to exit"
+    echo
+    # Force error after shell exits
+    $SHELL && exit 1
+fi
Signature · 1 line
2.4.3
Reviewed-by on v3 4/13
#10 lore raw

Re: [Qemu-devel] [PATCH v3 04/13] docker: Add test runner

Quoted 6 lines · Fam Zheng

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

If "DEBUG=1" a shell prompt will show up before the test runs.

Quoted 59 lines
---
 tests/docker/run | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100755 tests/docker/run
tests/docker/run new file +48 -0
new file mode 100755
index 0000000..ec3d119
@@ -0,0 +1,58 @@
+#!/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
+
+if test -n "$J"; then
+    export MAKEFLAGS="$MAKEFLAGS -j$J"
+fi
+
+# We are in the container so the whole file system belong to us
+export TEST_DIR=/tmp/qemu-test
+mkdir -p $TEST_DIR/{src,build,install}
+
+# Extract the source tarballs
+tar -C $TEST_DIR/src -xzf qemu.tgz
+for p in dtc pixman; do
+    if test -f $p.tgz; then
+        tar -C $TEST_DIR/src/$p -xzf $p.tgz
+        export FEATURES="$FEATURES $p"
+    fi
+done
+
+export QEMU_SRC="$TEST_DIR/src"
+
+cd "$QEMU_SRC/tests/docker"
+
+CMD="$QEMU_SRC/tests/docker/$@"
+
+if test -n "$DEBUG"; then
+    echo "* Prepared to run command:"
+    echo "  $CMD"
+    echo "* Hit Ctrl-D to continue, or type 'exit 1' to abort"
+    echo
+    $SHELL
+fi
+

tests/docker/run line 58

Quoted 10 lines
tests/docker/run new file +10 -0
+if "$CMD"; then
+    exit 0
+elif test -n "$DEBUG"; then
+    echo "* Command failed:"
+    echo "  $CMD"
+    echo "* Hit Ctrl-D to exit"
+    echo
+    # Force error after shell exits
+    $SHELL && exit 1
+fi

--
Alex Bennée

author
#11 lore raw

PATCH v3 5/13 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 | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100755 tests/docker/common.rc
tests/docker/common.rc new file +31 -0
new file mode 100755
index 0000000..74b89d6
@@ -0,0 +1,31 @@
+#!/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()
+{
+    $QEMU_SRC/configure \
+        --target-list="${TARGET_LIST}" \
+        --prefix="$PWD/install" \
+        "$@"
+    make $MAKEFLAGS
+}
Signature · 1 line
2.4.3
Reviewed-by on v3 5/13
#12 lore raw

Re: [Qemu-devel] [PATCH v3 05/13] docker: Add common.rc

Quoted 2 lines · Fam Zheng

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

You also add a build_qemu function which you should mention.

Otherwise have a:

Quoted 34 lines
---
 tests/docker/common.rc | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100755 tests/docker/common.rc
tests/docker/common.rc new file +21 -0
new file mode 100755
index 0000000..74b89d6
@@ -0,0 +1,31 @@
+#!/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

tests/docker/common.rc line 31

Quoted 10 lines
tests/docker/common.rc new file +10 -0
+}
+
+build_qemu()
+{
+    $QEMU_SRC/configure \
+        --target-list="${TARGET_LIST}" \
+        --prefix="$PWD/install" \
+        "$@"
+    make $MAKEFLAGS
+}

--
Alex Bennée

author
#13 lore raw

Re: [Qemu-devel] [PATCH v3 05/13] docker: Add common.rc

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

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

You also add a build_qemu function which you should mention.

Will mention it.

Thanks,

Fam

Quoted 5 lines

Otherwise have a:

author
#14 lore raw

PATCH v3 6/13 docker: Add quick test

In reply to Fam Zheng
---
 tests/docker/test-quick | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100755 tests/docker/test-quick
tests/docker/test-quick new file +19 -0
new file mode 100755
index 0000000..07cdc59
@@ -0,0 +1,19 @@
+#!/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
+
+DEF_TARGET_LIST="$(echo {x86_64,aarch64}-softmmu)"
+TARGET_LIST=${TARGET_LIST:-$DEF_TARGET_LIST} \
+build_qemu
+make check $MAKEFLAGS
Signature · 1 line
2.4.3
Reviewed-by on v3 6/13
#15 lore raw

Re: [Qemu-devel] [PATCH v3 06/13] docker: Add quick test

Quoted 18 lines · Fam Zheng
---
 tests/docker/test-quick | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100755 tests/docker/test-quick
tests/docker/test-quick new file +6 -0
new file mode 100755
index 0000000..07cdc59
@@ -0,0 +1,19 @@
+#!/bin/bash -e
+#
+# Quick compiling test that everyone already does. But why not automate it?
+#
+# Copyright (c) 2016 Red Hat Inc.
+#

tests/docker/test-quick line 16

Quoted 10 lines
tests/docker/test-quick new file +10 -0
+# 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
+
+DEF_TARGET_LIST="$(echo {x86_64,aarch64}-softmmu)"

The default target list seems a little arbitrary but whatever:

tests/docker/test-quick line 19

Quoted 3 lines
tests/docker/test-quick new file +3 -0
+TARGET_LIST=${TARGET_LIST:-$DEF_TARGET_LIST} \
+build_qemu
+make check $MAKEFLAGS

--
Alex Bennée

author
#16 lore raw

PATCH v3 7/13 docker: Add full test

In reply to Fam Zheng

This builds all available targets.

---
 tests/docker/test-full | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100755 tests/docker/test-full
tests/docker/test-full new file +17 -0
new file mode 100755
index 0000000..fd9b798
@@ -0,0 +1,17 @@
+#!/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
+
+build_qemu
+make check $MAKEFLAGS
Signature · 1 line
2.4.3
#17 lore raw

Re: [Qemu-devel] [PATCH v3 07/13] docker: Add full test

Quoted 20 lines · Fam Zheng

This builds all available targets.

---
 tests/docker/test-full | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100755 tests/docker/test-full
tests/docker/test-full new file +6 -0
new file mode 100755
index 0000000..fd9b798
@@ -0,0 +1,17 @@
+#!/bin/bash -e
+#
+# Compile all the targets.
+#
+# Copyright (c) 2016 Red Hat Inc.
+#

tests/docker/test-full line 16

Quoted 10 lines
tests/docker/test-full new file +10 -0
+# 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
+
+build_qemu

If this is the full featured test how can we pass additional configure flags to the build?

tests/docker/test-full line 17

Quoted 1 line
tests/docker/test-full new file +1 -0
+make check $MAKEFLAGS

--
Alex Bennée

author
#18 lore raw

Re: [Qemu-devel] [PATCH v3 07/13] docker: Add full test

Quoted 28 lines · Alex Bennée
Quoted 25 lines · Fam Zheng

This builds all available targets.

---
 tests/docker/test-full | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100755 tests/docker/test-full
tests/docker/test-full new file +11 -0
new file mode 100755
index 0000000..fd9b798
@@ -0,0 +1,17 @@
+#!/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
Quoted 8 lines

tests/docker/test-full line 16

Quoted 5 lines
tests/docker/test-full new file +5 -0
+# the top-level directory.
+
+. common.rc
+
+build_qemu

If this is the full featured test how can we pass additional configure flags to the build?

Let's add an EXTRA_CONFIGURE_OPTS and use it in build_qemu. Works for you?

Quoted 6 lines

tests/docker/test-full line 17

Quoted 2 lines
tests/docker/test-full new file +1 -0
+make check $MAKEFLAGS

--
Alex Bennée

#19 lore raw

Re: [Qemu-devel] [PATCH v3 07/13] docker: Add full test

Quoted 38 lines · Fam Zheng
Quoted 28 lines · Alex Bennée
Quoted 25 lines · Fam Zheng

This builds all available targets.

---
 tests/docker/test-full | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100755 tests/docker/test-full
tests/docker/test-full new file +11 -0
new file mode 100755
index 0000000..fd9b798
@@ -0,0 +1,17 @@
+#!/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
Quoted 8 lines

tests/docker/test-full line 16

Quoted 5 lines
tests/docker/test-full new file +5 -0
+# the top-level directory.
+
+. common.rc
+
+build_qemu

If this is the full featured test how can we pass additional configure flags to the build?

Quoted 2 lines

Let's add an EXTRA_CONFIGURE_OPTS and use it in build_qemu. Works for you?

Sounds good to me.

Quoted 7 lines
Quoted 7 lines

tests/docker/test-full line 17

Quoted 3 lines
tests/docker/test-full new file +1 -0
+make check $MAKEFLAGS

--
Alex Bennée

--
Alex Bennée

author
#20 lore raw

PATCH v3 8/13 docker: Add clang test

In reply to Fam Zheng

The (currently partially commented out) configure options are suggested by John Snow <[email protected]>.

---
 tests/docker/test-clang | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100755 tests/docker/test-clang
tests/docker/test-clang new file +25 -0
new file mode 100755
index 0000000..7b5e65e
@@ -0,0 +1,25 @@
+#!/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
+
+OPTS="--enable-debug --cxx=clang++ --cc=clang --host-cc=clang"
+# -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"
+TARGET_LIST=x86_64-softmmu,aarch64-softmmu
+build_qemu $OPTS
+make $MAKEFLAGS check
Signature · 1 line
2.4.3
Reviewed-by on v3 8/13
#21 lore raw

Re: [Qemu-devel] [PATCH v3 08/13] docker: Add clang test

Quoted 4 lines · Fam Zheng

The (currently partially commented out) configure options are suggested by John Snow <[email protected]>.

Quoted 26 lines
---
 tests/docker/test-clang | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100755 tests/docker/test-clang
tests/docker/test-clang new file +15 -0
new file mode 100755
index 0000000..7b5e65e
@@ -0,0 +1,25 @@
+#!/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
+

tests/docker/test-clang line 25

Quoted 10 lines
tests/docker/test-clang new file +10 -0
+requires clang
+
+OPTS="--enable-debug --cxx=clang++ --cc=clang --host-cc=clang"
+# -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"
+TARGET_LIST=x86_64-softmmu,aarch64-softmmu
+build_qemu $OPTS
+make $MAKEFLAGS check

--
Alex Bennée

author
#22 lore raw

PATCH v3 9/13 docker: Add mingw test

In reply to Fam Zheng
---
 tests/docker/test-mingw | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100755 tests/docker/test-mingw
tests/docker/test-mingw new file +34 -0
new file mode 100755
index 0000000..c03757a
@@ -0,0 +1,34 @@
+#!/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 dtc
+
+for prefix in x86_64-w64-mingw32- i686-w64-mingw32-; do
+    TARGET_LIST=x86_64-softmmu,aarch64-softmmu \
+        build_qemu --cross-prefix=$prefix \
+        --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
Reviewed-by on v3 9/13
#23 lore raw

Re: [Qemu-devel] [PATCH v3 09/13] docker: Add mingw test

Quoted 1 line · Fam Zheng
Quoted 35 lines
---
 tests/docker/test-mingw | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100755 tests/docker/test-mingw
tests/docker/test-mingw new file +24 -0
new file mode 100755
index 0000000..c03757a
@@ -0,0 +1,34 @@
+#!/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 dtc
+
+for prefix in x86_64-w64-mingw32- i686-w64-mingw32-; do
+    TARGET_LIST=x86_64-softmmu,aarch64-softmmu \
+        build_qemu --cross-prefix=$prefix \
+        --enable-trace-backends=simple \
+        --enable-debug \
+        --enable-gnutls \
+        --enable-nettle \

tests/docker/test-mingw line 34

Quoted 10 lines
tests/docker/test-mingw new file +10 -0
+        --enable-curl \
+        --enable-vnc \
+        --enable-bzip2 \
+        --enable-guest-agent \
+        --with-sdlabi=1.2 \
+        --with-gtkabi=2.0
+    make clean
+
+done
+

--
Alex Bennée

author
#24 lore raw

PATCH v3 10/13 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    | 21 +++++++++++++++++++++
 tests/docker/travis.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100755 tests/docker/travis
 create mode 100755 tests/docker/travis.py
tests/docker/travis new file +21 -0
new file mode 100755
index 0000000..d345393
@@ -0,0 +1,21 @@
+#!/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
+cmdfile=/tmp/travis_cmd_list.sh
+$QEMU_SRC/tests/docker/travis.py $QEMU_SRC/.travis.yml > $cmdfile
+chmod +x $cmdfile
+cd "$QEMU_SRC"
+$cmdfile
tests/docker/travis.py new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.4.3
#25 lore raw

Re: [Qemu-devel] [PATCH v3 10/13] docker: Add travis tool

Quoted 4 lines · 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".

16:08 alex@zen/x86_64 [qemu.git/review/docker-v3] >make docker-run-travis.sh@ubuntu ARCHIVE qemu.tgz
COPY RUNNER
RUN travis.sh in ubuntu
./run: line 49: /tmp/qemu-test/src/tests/docker/travis.sh: No such file or directory

Quoted 80 lines
---
 tests/docker/travis    | 21 +++++++++++++++++++++
 tests/docker/travis.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100755 tests/docker/travis
 create mode 100755 tests/docker/travis.py
tests/docker/travis new file +21 -0
new file mode 100755
index 0000000..d345393
@@ -0,0 +1,21 @@
+#!/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
+cmdfile=/tmp/travis_cmd_list.sh
+$QEMU_SRC/tests/docker/travis.py $QEMU_SRC/.travis.yml > $cmdfile
+chmod +x $cmdfile
+cd "$QEMU_SRC"
+$cmdfile
tests/docker/travis.py new file +38 -0
new file mode 100755
index 0000000..8dcc964
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+#
+# Travis YAML config parser
+#
+# 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 yaml
+import itertools
+
+def load_yaml(fname):
+    return yaml.load(open(fname, "r").read())
+
+def conf_iter(conf):
+    def env_to_list(env):
+        return env if isinstance(env, list) else [env]
+    global_env = conf["env"]["global"]
+    for entry in conf["matrix"]["include"]:
+        yield {"env": global_env + env_to_list(entry["env"]),
+               "compiler": entry["compiler"]}
+    for entry in itertools.product(conf["compiler"],
+                                   conf["env"]["matrix"]):
+        yield {"env": global_env + env_to_list(entry[1]),
+               "compiler": entry[0]}
+
+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):

tests/docker/travis.py line 48

Quoted 10 lines
tests/docker/travis.py new file +10 -0
+        print "("
+        print "\n".join(config["env"])
+        print "alias cc=" + config["compiler"]
+        print "\n".join(conf["before_script"])
+        print "\n".join(conf["script"])
+        print ")"
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())

--
Alex Bennée

author
#26 lore raw

Re: [Qemu-devel] [PATCH v3 10/13] docker: Add travis tool

Quoted 6 lines · Alex Bennée
Quoted 3 lines · 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.

Quoted 7 lines
Quoted 1 line

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

16:08 alex@zen/x86_64 [qemu.git/review/docker-v3] >make docker-run-travis.sh@ubuntu ARCHIVE qemu.tgz
COPY RUNNER
RUN travis.sh in ubuntu
./run: line 49: /tmp/qemu-test/src/tests/docker/travis.sh: No such file or directory

Will update the commit message.

Fam

#27 lore raw

Re: [Qemu-devel] [PATCH v3 10/13] docker: Add travis tool

Quoted 9 lines · Fam Zheng
Quoted 8 lines · Alex Bennée
Quoted 4 lines · 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".

Quoted 7 lines
Quoted 5 lines

16:08 alex@zen/x86_64 [qemu.git/review/docker-v3] >make docker-run-travis.sh@ubuntu ARCHIVE qemu.tgz
COPY RUNNER
RUN travis.sh in ubuntu
./run: line 49: /tmp/qemu-test/src/tests/docker/travis.sh: No such file or directory

Will update the commit message.

I had a bit of a further play with this while trying to help with the recent Travis breakage. I realised we need to be clearer about what this does. It's not the same as running on travis, just a way of iterating through the travis build matrix on whatever image you happen to be on.

It would be nice to have a travis image for local debug but that seems to be harder to do than I thought. I couldn't find any such images on the hub.

Quoted 2 lines

Fam

--
Alex Bennée

author
#28 lore raw

Re: [Qemu-devel] [PATCH v3 10/13] docker: Add travis tool

Quoted 18 lines · Alex Bennée
Quoted 15 lines · Fam Zheng
Quoted 13 lines · Alex Bennée
Quoted 4 lines · 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".

16:08 alex@zen/x86_64 [qemu.git/review/docker-v3] >make docker-run-travis.sh@ubuntu ARCHIVE qemu.tgz
COPY RUNNER
RUN travis.sh in ubuntu
./run: line 49: /tmp/qemu-test/src/tests/docker/travis.sh: No such file or directory

Quoted 4 lines
Quoted 1 line

Will update the commit message.

I had a bit of a further play with this while trying to help with the recent Travis breakage.

Did this help?

Quoted 3 lines

I realised we need to be clearer about what this
does. It's not the same as running on travis, just a way of iterating through the travis build matrix on whatever image you happen to be on.

Right. I have no idea how to precisely replicate travis environment, and I ignored python version, packages etc for simplicity, only the command matrix was simulated. But are there any major differences you are noticing? At least we are also on Ubuntu Trusty, the same as:

https://docs.travis-ci.com/user/ci-environment/

Fam

Quoted 4 lines

It would be nice to have a travis image for local debug but that seems to be harder to do than I thought. I couldn't find any such images on the hub.

#29 lore raw

Re: [Qemu-devel] [PATCH v3 10/13] docker: Add travis tool

Quoted 19 lines · Fam Zheng
Quoted 18 lines · Alex Bennée
Quoted 15 lines · Fam Zheng
Quoted 13 lines · Alex Bennée
Quoted 4 lines · 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".

16:08 alex@zen/x86_64 [qemu.git/review/docker-v3] >make docker-run-travis.sh@ubuntu ARCHIVE qemu.tgz
COPY RUNNER
RUN travis.sh in ubuntu
./run: line 49: /tmp/qemu-test/src/tests/docker/travis.sh: No such file or directory

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Will update the commit message.

I had a bit of a further play with this while trying to help with the recent Travis breakage.

Did this help?

Daniel fixed it before I could get something up and running.

Quoted 11 lines
Quoted 4 lines

I realised we need to be clearer about what this
does. It's not the same as running on travis, just a way of iterating through the travis build matrix on whatever image you happen to be on.

Right. I have no idea how to precisely replicate travis environment, and I ignored python version, packages etc for simplicity, only the command matrix was simulated. But are there any major differences you are noticing? At least we are also on Ubuntu Trusty, the same as:

https://docs.travis-ci.com/user/ci-environment/

No the current container based CI environment is Precise (Trusty is in beta). I tried creating a precise image from scratch but apt got confused about having both i386 and amd64 packages in package lists and I didn't get the bottom of it before upstream was fixed.

Quoted 7 lines

Fam

Quoted 4 lines

It would be nice to have a travis image for local debug but that seems to be harder to do than I thought. I couldn't find any such images on the hub.

--
Alex Bennée

author
#30 lore raw

PATCH v3 11/13 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
Reviewed-by on v3 11/13
#31 lore raw

Re: [Qemu-devel] [PATCH v3 11/13] docs: Add text for tests/docker in build-system.txt

Quoted 1 line · Fam Zheng
Quoted 9 lines
---
 docs/build-system.txt | 5 +++++
 1 file changed, 5 insertions(+)
docs/build-system.txt +0 -0
index 5ddddea..2af1e66 100644

docs/build-system.txt top level Makefile, so anything defined in this file will influence the · line 447

Quoted 10 lines
docs/build-system.txt +5 -0
@@ -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

--
Alex Bennée

author
#32 lore raw

PATCH v3 12/13 .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
#33 lore raw

Re: [Qemu-devel] [PATCH v3 12/13] .gitignore: Ignore temporary dockerfile

Quoted 6 lines · 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.

I think the need for this will go away if you use python's tempfile.

Quoted 11 lines
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)
.gitignore +0 -0
index 88a80ff..a335b7b 100644

.gitignore cscope.* · line 112

Quoted 4 lines
.gitignore +1 -0
@@ -109,3 +109,4 @@ cscope.*
 tags
 TAGS
 *~
+/tests/docker/*.docker.tmp

--
Alex Bennée

author
#34 lore raw

Re: [Qemu-devel] [PATCH v3 12/13] .gitignore: Ignore temporary dockerfile

Quoted 11 lines · Alex Bennée
Quoted 6 lines · 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.

I think the need for this will go away if you use python's tempfile.

Yes, I'll drop it.

Fam

Quoted 20 lines
Quoted 12 lines
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)
.gitignore +0 -0
index 88a80ff..a335b7b 100644

.gitignore cscope.* · line 112

Quoted 4 lines
.gitignore +1 -0
@@ -109,3 +109,4 @@ cscope.*
 tags
 TAGS
 *~
+/tests/docker/*.docker.tmp

--
Alex Bennée

author
#35 lore raw

PATCH v3 13/13 MAINTAINERS: Add tests/docker

In reply to Fam Zheng
---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 13d1b4d..b463f6a 100644
@@ -1604,3 +1604,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
#36 lore raw
In reply to Fam Zheng
Quoted 1 line · Fam Zheng

v3 changes:

I think we are almost there. There a just a few tweaks to be made to help text and prompts. Can you ensure that all examples in commit messages and help text actually do run as expected?

Is it proposed this goes through Daniel's treee?

Quoted 77 lines

- Merge all docker_* tools into docker.py as subcommands, and add simple help texts; clean up docker.py a bit.
- For ease of management of the series, squashed Alex's COPY_SRC patch into patch 2.
- Pick up Alex's tweaks on Makefile changes.
- Change the way we copy source. Now we send source tarballs to the container, and untar it there. Beside qemu.tgz, also copy dtc.tgz and pixman.tgz if submodules are initialized in the tree. The first is required by mingw test.
- Update test runner to adapt to above change.
- Tweak "make docker" help text. Dropped "docker-@IMAGE" because it is equivalent to "make docker-test IMAGES=XXX". Too many targets will be hard to memorize, and we can always add more shortcuts if desired.
- Drop "PAUSE=1" env and add "DEBUG=1", which will also enable networking, and drop to shell when test fails.
- Add "NOCACHE=1" env var to add "--no-cache" to "docker build" command, which is useful in certain cases to workaround image build failure. For example in ubuntu when "apt-get update" is cached, "apt-get install xxx" can get 404.
- Add libfdt-devel to images.
- Add epel, and ccache in centos6.
- Add "TARGET_LIST=" env var.
- Add "sparse" from multiverse for ubuntu, which is used by travis tool.

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.

Fam Zheng (13):
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

 .gitignore                              |   1 +
 MAINTAINERS                             |   7 ++
 Makefile                                |   4 +-
 docs/build-system.txt                   |   5 +
 tests/docker/Makefile.include           | 121 +++++++++++++++++++++
 tests/docker/common.rc                  |  31 ++++++
 tests/docker/docker.py                  | 180 ++++++++++++++++++++++++++++++++
 tests/docker/dockerfiles/centos6.docker |   6 ++
 tests/docker/dockerfiles/fedora.docker  |   7 ++
 tests/docker/dockerfiles/ubuntu.docker  |  11 ++
 tests/docker/run                        |  58 ++++++++++
 tests/docker/test-clang                 |  25 +++++
 tests/docker/test-full                  |  17 +++
 tests/docker/test-mingw                 |  34 ++++++
 tests/docker/test-quick                 |  19 ++++
 tests/docker/travis                     |  21 ++++
 tests/docker/travis.py                  |  48 +++++++++
 17 files changed, 594 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 100644 tests/docker/dockerfiles/centos6.docker
 create mode 100644 tests/docker/dockerfiles/fedora.docker
Quoted 8 lines
 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

--
Alex Bennée

author
#37 lore raw
Quoted 8 lines · Alex Bennée
Quoted 1 line · Fam Zheng

v3 changes:

I think we are almost there. There a just a few tweaks to be made to help text and prompts. Can you ensure that all examples in commit messages and help text actually do run as expected?

OK, I'm fixing these now and will send v4 very soon.

Quoted 2 lines

Is it proposed this goes through Daniel's treee?

I'm fine with that. So should I add Daniel in the MAINTAINERS patch? I can also send a pull req my self if that's okay - I will then sign my gpg key with Jason Wang.

Fam

#38 lore raw
Quoted 10 lines · Fam Zheng
Quoted 8 lines · Alex Bennée
Quoted 1 line · Fam Zheng

v3 changes:

I think we are almost there. There a just a few tweaks to be made to help text and prompts. Can you ensure that all examples in commit messages and help text actually do run as expected?

Quoted 8 lines

OK, I'm fixing these now and will send v4 very soon.

Quoted 2 lines

Is it proposed this goes through Daniel's treee?

I'm fine with that. So should I add Daniel in the MAINTAINERS patch? I can also send a pull req my self if that's okay - I will then sign my gpg key with Jason Wang.

It depends if Peter is happy to take the first pull request directly?

--
Alex Bennée

#39 lore raw
In reply to Alex Bennée
Quoted 10 lines · Alex Bennée
Quoted 1 line · Fam Zheng

v3 changes:

I think we are almost there. There a just a few tweaks to be made to help text and prompts. Can you ensure that all examples in commit messages and help text actually do run as expected?

Is it proposed this goes through Daniel's treee?

What tree is that you're referring to ? I certainly don't consider myself the maintainer of all tests in QEMU :-) I'd say that Fam is maintainer of tests/docker/ and should thus just send PULL for it request(s) directly

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#40 lore raw
Quoted 10 lines · Daniel P. Berrange
Quoted 9 lines · Alex Bennée
Quoted 1 line · Fam Zheng

v3 changes:

I think we are almost there. There a just a few tweaks to be made to help text and prompts. Can you ensure that all examples in commit messages and help text actually do run as expected?

Quoted 6 lines
Quoted 1 line

Is it proposed this goes through Daniel's treee?

What tree is that you're referring to ? I certainly don't consider myself the maintainer of all tests in QEMU :-) I'd say that Fam is maintainer of tests/docker/ and should thus just send PULL for it request(s) directly

You are right of course. I picked your name up as the master of the build system but really this is all new stuff. I just wasn't sure if the process for new functionality was to go direct to Peter or via a related tree and then take over the specific bits.

Quoted 4 lines

Regards,
Daniel

--
Alex Bennée

author
#41 lore raw
Quoted 20 lines · Alex Bennée
Quoted 10 lines · Daniel P. Berrange
Quoted 9 lines · Alex Bennée
Quoted 1 line · Fam Zheng

v3 changes:

I think we are almost there. There a just a few tweaks to be made to help text and prompts. Can you ensure that all examples in commit messages and help text actually do run as expected?

Quoted 6 lines
Quoted 1 line

Is it proposed this goes through Daniel's treee?

What tree is that you're referring to ? I certainly don't consider myself the maintainer of all tests in QEMU :-) I'd say that Fam is maintainer of tests/docker/ and should thus just send PULL for it request(s) directly

Quoted 4 lines

You are right of course. I picked your name up as the master of the build system but really this is all new stuff. I just wasn't sure if the process for new functionality was to go direct to Peter or via a related tree and then take over the specific bits.

If a fellow maintainer wants to take this under his umbrella it would be great, otherwise I'd volunteer this and send a pull req when the patches are ready.

Fam