tests: Introducing docker tests
v5 cover tests: Introducing docker tests
v5: Use docker run's selinux option "z" on passed volume, drop --privileged.
Allow overriding "TARGET_LIST" in clang-test.
Add Alex's r-b lines in patches 1, 3, 9, 11 and 13.
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 (14):
tests: Add utilities for docker testing rules.mak: Add "COMMA" constant
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
docker: Add EXTRA_CONFIGURE_OPTS
MAINTAINERS: Add tests/docker
MAINTAINERS | 7 ++ Makefile | 4 +- docs/build-system.txt | 5 + rules.mak | 2 + tests/docker/Makefile.include | 124 +++++++++++++++++++++ tests/docker/common.rc | 32 ++++++ tests/docker/docker.py | 191 ++++++++++++++++++++++++++++++++ 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 | 26 +++++ 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, 611 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.8.2
PATCH v5 1/14 tests: Add utilities for docker testing
docker.py is added with a number of useful subcommands to manager docker images and instances for QEMU docker testing. Subcommands are:
run: A wrapper of "docker run" (or "sudo -n docker run" if necessary), which takes care of killing and removing the running container at SIGINT.
clean: Tear down all the containers including inactive ones that are started by docker_run.
build: Compare an image from given dockerfile and rebuild it if they're different.
--- tests/docker/docker.py | 191 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100755 tests/docker/docker.py
tests/docker/docker.py new file +191 -0
@@ -0,0 +1,191 @@ +#!/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 +import tempfile + +def _text_checksum(text): + """Calculate a digest string unique to the text content""" + return hashlib.sha1(text).hexdigest() + +def _guess_docker_command(): + """ Guess a working docker command or raise exception if not found""" + 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) + +class Docker(object): + """ Running Docker commands """ + def __init__(self): + self._command = _guess_docker_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 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 build_image(self, tag, dockerfile, df_path, quiet=True, argv=None): + if argv == None: + argv = [] + tmp = dockerfile + "\n" + \ + "LABEL com.qemu.dockerfile-checksum=%s" % \ + _text_checksum(dockerfile) + dirname = os.path.dirname(df_path) + tmp_df = tempfile.NamedTemporaryFile(dir=dirname) + tmp_df.write(tmp) + tmp_df.flush() + self._do(["build", "-t", tag, "-f", tmp_df.name] + argv + \ + [dirname], + quiet=quiet) + + def image_matches_dockerfile(self, tag, dockerfile): + try: + checksum = self.get_image_dockerfile_checksum(tag) + except Exception: + return False + return checksum == _text_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 shared_args(self, parser): + parser.add_argument("--quiet", action="store_true", + help="Run quietly unless an error occured") + + 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 command completes") + def run(self, args, argv): + return Docker().run(argv, args.keep, quiet=args.quiet) + +class BuildCommand(SubCommand): + """ Build docker image out of a dockerfile. Arguments: <tag> <dockerfile>""" + name = "build" + def args(self, parser): + parser.add_argument("tag", + help="Image Tag") + parser.add_argument("dockerfile", + help="Dockerfile name") + + def run(self, args, argv): + dockerfile = open(args.dockerfile, "rb").read() + tag = args.tag + + dkr = Docker() + if dkr.image_matches_dockerfile(tag, dockerfile): + if not args.quiet: + print "Image is up to date." + return 0 + + dkr.build_image(tag, dockerfile, args.dockerfile, + quiet=args.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(description="A Docker helper", + usage="%s <subcommand> ..." % os.path.basename(sys.argv[0])) + subparsers = parser.add_subparsers(title="subcommands", help=None) + for cls in SubCommand.__subclasses__(): + cmd = cls() + subp = subparsers.add_parser(cmd.name, help=cmd.__doc__) + cmd.shared_args(subp) + 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.8.2
Re: [Qemu-devel] [PATCH v5 01/14] tests: Add utilities for docker testing
Quoted 117 lines · Fam Zheng
docker.pyis added with a number of useful subcommands to manager docker images and instances for QEMU docker testing. Subcommands are:run: A wrapper of "docker run" (or "sudo -n docker run" if necessary), which takes care of killing and removing the running container at SIGINT.
clean: Tear down all the containers including inactive ones that are started by
docker_run.build: Compare an image from given dockerfile and rebuild it if they're different.
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Fam Zheng <[email protected]>--- tests/docker/docker.py | 191 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100755 tests/docker/docker.pytests/docker/docker.py new file +91
-0@@ -0,0 +1,191 @@ +#!/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 +import tempfile + +def _text_checksum(text): + """Calculate a digest string unique to the text content""" + return hashlib.sha1(text).hexdigest() + +def _guess_docker_command(): + """ Guess a working docker command or raise exception if not found""" + 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) + +class Docker(object): + """ Running Docker commands """ + def __init__(self): + self._command = _guess_docker_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 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 build_image(self, tag, dockerfile, df_path, quiet=True, argv=None): + if argv == None: + argv = []
tests/docker/docker.py line 101
Quoted 10 lines
tests/docker/docker.py new file +10
-0+ tmp = dockerfile + "\n" + \ + "LABEL com.qemu.dockerfile-checksum=%s" % \ + _text_checksum(dockerfile) + dirname = os.path.dirname(df_path) + tmp_df = tempfile.NamedTemporaryFile(dir=dirname) + tmp_df.write(tmp) + tmp_df.flush() + self._do(["build", "-t", tag, "-f", tmp_df.name] + argv + \ + [dirname], + quiet=quiet)
I've been doing some hacking to build qemu-$arch enabled docker images and I think we should use a clean temp dir for the build. Along the lines of:
def build_image(self, tag, dockerfile, quiet=True, qemu=None, argv=None):
if argv == None:
argv = []
tmp = dockerfile + "\n" + \
"LABEL com.qemu.dockerfile-checksum=%s" % \
_text_checksum(dockerfile)
tmp_dir = tempfile.mkdtemp(prefix="docker_build")
tmp_df = tempfile.NamedTemporaryFile(dir=tmp_dir, suffix=".docker")
print "dirname=%s tmp_df=%s" % (tmp_dir, tmp_df.name)
tmp_df.write(tmp)
tmp_df.flush()
self._do(["build", "-t", tag, "-f", tmp_df.name] + argv + \
[tmp_dir],
quiet=quiet)Having a clean empty dir means I can use this to dump stuff in (debootstrap output, qemu binaries) without having to worry about polluting the source tree. Also it is one less parameter to pass to build_image ;-)
Otherwise I think the series is looking good.
Quoted 80 lines
tests/docker/docker.py new file +80
-0+ + def image_matches_dockerfile(self, tag, dockerfile): + try: + checksum = self.get_image_dockerfile_checksum(tag) + except Exception: + return False + return checksum == _text_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 shared_args(self, parser): + parser.add_argument("--quiet", action="store_true", + help="Run quietly unless an error occured") + + 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 command completes") + def run(self, args, argv): + return Docker().run(argv, args.keep, quiet=args.quiet) + +class BuildCommand(SubCommand): + """ Build docker image out of a dockerfile. Arguments: <tag> <dockerfile>""" + name = "build" + def args(self, parser): + parser.add_argument("tag", + help="Image Tag") + parser.add_argument("dockerfile", + help="Dockerfile name") + + def run(self, args, argv): + dockerfile = open(args.dockerfile, "rb").read() + tag = args.tag + + dkr = Docker() + if dkr.image_matches_dockerfile(tag, dockerfile): + if not args.quiet: + print "Image is up to date." + return 0 + + dkr.build_image(tag, dockerfile, args.dockerfile, + quiet=args.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(description="A Docker helper", + usage="%s <subcommand> ..." % os.path.basename(sys.argv[0])) + subparsers = parser.add_subparsers(title="subcommands", help=None) + for cls in SubCommand.__subclasses__():
tests/docker/docker.py line 191
Quoted 10 lines
tests/docker/docker.py new file +10
-0+ cmd = cls() + subp = subparsers.add_parser(cmd.name, help=cmd.__doc__) + cmd.shared_args(subp) + 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())
--
Alex Bennée
PATCH v5 2/14 rules.mak: Add "COMMA" constant
In reply to Fam ZhengUsing "," literal in $(call quiet-command, ...) arguments is awkward. Add this constant to make it at least doable.
--- rules.mak | 2 ++ 1 file changed, 2 insertions(+)
rules.mak +2 -0
@@ -1,4 +1,6 @@ +COMMA := , + # Don't use implicit rules or variables # we have explicit rules for everything MAKEFLAGS += -rR
Signature · 1 line
2.8.2
PATCH v5 3/14 Makefile: Rules for docker testing
In reply to Fam ZhengThis adds a group of make targets to run docker tests, all are available in source tree without running ./configure.
The usage is shown with "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-TEST@IMAGE) 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-test 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 in the top Makefile, "make -j$N docker-test" still parallels the tests coarsely.
Still, $J is made a magic variable to let all make invocations in containers to use -j$J.
Instead of providing a live version of the source tree to the docker container we snapshot it with git-archive. This ensures 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
@@ -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.8.2
PATCH v5 4/14 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
@@ -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
@@ -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
@@ -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.8.2
PATCH v5 5/14 docker: Add test runner
In reply to Fam ZhengIt'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
@@ -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.8.2
PATCH v5 6/14 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.
"build_qemu" is the central routine to compile QEMU for tests to call.
--- 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
@@ -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.8.2
PATCH v5 7/14 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
@@ -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.8.2
PATCH v5 8/14 docker: Add full test
In reply to Fam ZhengThis 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
@@ -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.8.2
Re: [Qemu-devel] [PATCH v5 08/14] docker: Add full test
Quoted 3 lines · Fam Zheng
This builds all available targets.
Signed-off-by Fam Zheng <[email protected]>
Quoted 18 lines
--- tests/docker/test-full | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 tests/docker/test-fulltests/docker/test-full new file +7
-0@@ -0,0 +1,17 @@ +#!/bin/bash -e +# +# Compile all the targets. +# +# Copyright (c) 2016 Red Hat Inc. +# +# Authors:
tests/docker/test-full line 17
Quoted 10 lines
tests/docker/test-full new file +10
-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. + +. common.rc + +build_qemu +make check $MAKEFLAGS
--
Alex Bennée
PATCH v5 9/14 docker: Add clang test
In reply to Fam ZhengThe (currently partially commented out) configure options are suggested by John Snow <[email protected]>.
--- tests/docker/test-clang | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/docker/test-clang
tests/docker/test-clang new file +26 -0
@@ -0,0 +1,26 @@ +#!/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" +DEF_TARGET_LIST="$(echo {x86_64,aarch64}-softmmu)" +TARGET_LIST=${TARGET_LIST:-$DEF_TARGET_LIST} \ +build_qemu $OPTS +make $MAKEFLAGS check
Signature · 1 line
2.8.2
Re: [Qemu-devel] [PATCH v5 09/14] docker: Add clang test
Quoted 4 lines · Fam Zheng
The (currently partially commented out) configure options are suggested by John Snow <[email protected]>.
Signed-off-by Fam Zheng <[email protected]>
Quoted 27 lines
--- tests/docker/test-clang | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/docker/test-clangtests/docker/test-clang new file +16
-0@@ -0,0 +1,26 @@ +#!/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
tests/docker/test-clang line 26
Quoted 10 lines
tests/docker/test-clang new file +10
-0+ +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" +DEF_TARGET_LIST="$(echo {x86_64,aarch64}-softmmu)" +TARGET_LIST=${TARGET_LIST:-$DEF_TARGET_LIST} \ +build_qemu $OPTS +make $MAKEFLAGS check
--
Alex Bennée
Re: [Qemu-devel] [PATCH v5 09/14] docker: Add clang test
In reply to Fam ZhengQuoted 4 lines · Fam Zheng
The (currently partially commented out) configure options are suggested by John Snow <[email protected]>.
Signed-off-by Fam Zheng <[email protected]>
Quoted 27 lines
--- tests/docker/test-clang | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/docker/test-clangtests/docker/test-clang new file +16
-0@@ -0,0 +1,26 @@ +#!/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
tests/docker/test-clang line 26
Quoted 10 lines
tests/docker/test-clang new file +10
-0+ +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" +DEF_TARGET_LIST="$(echo {x86_64,aarch64}-softmmu)" +TARGET_LIST=${TARGET_LIST:-$DEF_TARGET_LIST} \ +build_qemu $OPTS +make $MAKEFLAGS check
--
Alex Bennée
PATCH v5 10/14 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
@@ -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.8.2
PATCH v5 11/14 docker: Add travis tool
In reply to Fam ZhengThe script is not prefixed with test- so it won't run with "make docker-test", because it can take too long.
Run it with "make docker-travis@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
@@ -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.8.2
PATCH v5 12/14 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
@@ -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.8.2
PATCH v5 13/14 docker: Add EXTRA_CONFIGURE_OPTS
In reply to Fam ZhengWhatever passed in this variable will be appended to all configure commands.
--- tests/docker/Makefile.include | 3 +++ tests/docker/common.rc | 1 + 2 files changed, 4 insertions(+)
tests/docker/Makefile.include +3 -0
@@ -86,6 +86,8 @@ docker: @echo @echo 'Special variables:' @echo ' TARGET_LIST=a,b,c Override target list in builds.' + @echo ' EXTRA_CONFIGURE_OPTS="..."' + @echo ' Extra configure options.' @echo ' IMAGES="a b c ..": Filters which images to build or run.' @echo ' TESTS="x y z .." Filters which tests to run (for docker-test).' @echo ' J=[0..9]* Overrides the -jN parameter for make commands'
@@ -106,6 +108,7 @@ docker-run-%: docker-qemu-src -t \ $(if $(DEBUG),-i,--net=none) \ -e TARGET_LIST=$(TARGET_LIST) \ + -e EXTRA_CONFIGURE_OPTS=$(EXTRA_CONFIGURE_OPTS) \ -e V=$V -e J=$J -e DEBUG=$(DEBUG)\ -e CCACHE_DIR=/var/tmp/ccache \ -v $$(realpath $(SRC_COPY)):/var/tmp/qemu:z$(COMMA)ro \
tests/docker/common.rc +1 -0
@@ -26,6 +26,7 @@ build_qemu() $QEMU_SRC/configure \ --target-list="${TARGET_LIST}" \ --prefix="$PWD/install" \ + $EXTRA_CONFIGURE_OPTS \ "$@" make $MAKEFLAGS }
Signature · 1 line
2.8.2
PATCH v5 14/14 MAINTAINERS: Add tests/docker
In reply to Fam Zheng--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -1616,3 +1616,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.8.2
Quoted 10 lines · Fam Zheng
v5: Use docker run's selinux option "z" on passed volume, drop --privileged.
Allow overriding "TARGET_LIST" in clang-test.
Add Alex's r-b lines in patches 1, 3, 9, 11 and 13.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.
Quoted 7 lines
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.
Aside from the minor quibble on docker.py (which I can fix up on later patches if you want) I think this series it ready to be merged. Are you going to submit a PULL REQ to Peter?
Quoted 41 lines
Fam Zheng (14):
tests: Add utilities for docker testing rules.mak: Add "COMMA" constant
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
docker: AddEXTRA_CONFIGURE_OPTS
MAINTAINERS: Add tests/dockerMAINTAINERS | 7 ++ Makefile | 4 +- docs/build-system.txt | 5 + rules.mak | 2 + tests/docker/Makefile.include | 124 +++++++++++++++++++++ tests/docker/common.rc | 32 ++++++ tests/docker/docker.py | 191 ++++++++++++++++++++++++++++++++ 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 | 26 +++++ 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, 611 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
Quoted 18 lines · Alex Bennée
Quoted 15 lines · Fam Zheng
v5: Use docker run's selinux option "z" on passed volume, drop --privileged.
Allow overriding "TARGET_LIST" in clang-test.
Add Alex's r-b lines in patches 1, 3, 9, 11 and 13.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.
Quoted 6 lines
Quoted 2 lines
Lastly, this makes it very simple for developers to replicate such tests themselves.
Aside from the minor quibble on
docker.py(which I can fix up on later patches if you want) I think this series it ready to be merged. Are you going to submit a PULL REQ to Peter?
Yes, I'll send one today.
Thanks,
Fam
Quoted 54 lines
Quoted 42 lines
Fam Zheng (14):
tests: Add utilities for docker testing rules.mak: Add "COMMA" constant
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
docker: AddEXTRA_CONFIGURE_OPTS
MAINTAINERS: Add tests/dockerMAINTAINERS | 7 ++ Makefile | 4 +- docs/build-system.txt | 5 + rules.mak | 2 + tests/docker/Makefile.include | 124 +++++++++++++++++++++ tests/docker/common.rc | 32 ++++++ tests/docker/docker.py | 191 ++++++++++++++++++++++++++++++++ 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 | 26 +++++ 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, 611 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.dockerQuoted 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