Skip to contentSkip to conversation

Automation for running Coverity Scan builds

PATCH In review Peter Maydell 5 participants 11 messages Nov 13, 2018 – Nov 14, 2018

lore
Share & tools
lore
#0 lore raw

cover Automation for running Coverity Scan builds

This patchset is an attempt to automate the process of running a Coverity Scan build and uploading it to the website. (I had a go at this last year; the scripts here are based on my older attempt, with some changes.)

Patch 1 is a script which will do a build-and-upload. It requires that you have a Fedora 28 host with all the relevant -devel packages installed, and that you run it in a clean directory.

Patch 2 improves on that by using Docker to set up the build environment, so you can run it on any host and get the same results, and it doesn't trash your source tree with an in-place build.

Patch 1 I'm generally pretty happy with. Paolo, if you could check the configure options against what you use at the moment for uploads that would be very helpful. These are the set that you gave me last time I asked, but I think that was long enough ago that they may be a little out of date.

Patch 2 is a bit more RFC-ish -- it does work and you can do a complete build-and-upload with it, but I was thrashing about trying to get Docker to do what I wanted and I'm pretty sure there are better ways to do it. In particular I was expecting that once the script has run once and done the "set up F28, download the coverity tools and unpack them", that a second run would reuse a cached copy of that image, but the docker build seems to repeat the download-and-unpack part.
NB that you need the bleeding-edge Docker 18.09 for the --secret option which lets us pass the coverity magic token into the build stage safely. Review from people who know Docker welcomed.

I would eventually like to set up Travis so it does the build-and-upload automatically, but I think getting to a point where coverity uploads are done with a process that can be repeated reliably by anybody with maintainer rights is useful in itself even if we don't want to do it via Travis.

thanks
-- PMM

Peter Maydell (2):
scripts/run-coverity-scan: Script to run Coverity Scan build scripts/coverity-scan: Add Docker support

 MAINTAINERS                                |   5 +
 scripts/coverity-scan/coverity-scan.docker | 120 +++++++
 scripts/coverity-scan/run-coverity-scan    | 350 +++++++++++++++++++++
 3 files changed, 475 insertions(+)
 create mode 100644 scripts/coverity-scan/coverity-scan.docker
 create mode 100755 scripts/coverity-scan/run-coverity-scan
Signature · 1 line
2.19.1
#1 lore raw

PATCH 1/2 scripts/run-coverity-scan: Script to run Coverity Scan build

Add a new script to automate the process of running the Coverity Scan build tools and uploading the resulting tarball to the website.

This is intended eventually to be driven from Travis, but it can be run locally, if you are a maintainer of the QEMU project on the Coverity Scan website and have the secret upload token.

The script must be run directly on a Fedora 28 system.

---
 MAINTAINERS                             |   5 +
 scripts/coverity-scan/run-coverity-scan | 292 ++++++++++++++++++++++++
 2 files changed, 297 insertions(+)
 create mode 100755 scripts/coverity-scan/run-coverity-scan
MAINTAINERS +5 -0
index 126fe0be7eb..5f107d99061 100644
@@ -1553,6 +1553,11 @@ M: Markus Armbruster <[email protected]>
 S: Supported
 F: scripts/coverity-model.c
 
+Coverity Scan integration
+M: Peter Maydell <[email protected]>
+S: Maintained
+F: scripts/coverity-scan/
+
 CPU
 L: [email protected]
 S: Supported
scripts/coverity-scan/run-coverity-scan new file +292 -0

292 lines not on this page · raw message

Signature · 1 line
2.19.1
#5 lore raw

PATCH 2/2 scripts/coverity-scan: Add Docker support

In reply to Peter Maydell

Add support for running the Coverity Scan tools inside a Docker container rather than directly on the host system.

---
 scripts/coverity-scan/coverity-scan.docker | 120 +++++++++++++++++++++
 scripts/coverity-scan/run-coverity-scan    |  58 ++++++++++
 2 files changed, 178 insertions(+)
 create mode 100644 scripts/coverity-scan/coverity-scan.docker
scripts/coverity-scan/coverity-scan.docker new file +120 -0
new file mode 100644
index 00000000000..81f69459954
@@ -0,0 +1,120 @@
+# syntax=docker/dockerfile:1.0.0-experimental
+#
+# Docker setup for running the "Coverity Scan" tools over the source
+# tree and uploading them to the website, as per
+# https://scan.coverity.com/projects/qemu/builds/new
+# We do this on a fixed config (currently Fedora 28 with a known
+# set of dependencies and a configure command that enables a specific
+# set of options) so that random changes don't result in our accidentally
+# dropping some files from the scan.
+# The work of actually doing the build is handled by the
+# run-coverity-scan script.
+
+
+FROM fedora:28
+ENV PACKAGES \
+    alsa-lib-devel \
+    bc \
+    bison \
+    bluez-libs-devel \
+    brlapi-devel \
+    bzip2 \
+    bzip2-devel \
+    ccache \
+    clang \
+    curl \
+    cyrus-sasl-devel \
+    device-mapper-multipath-devel \
+    findutils \
+    flex \
+    gcc \
+    gcc-c++ \
+    gettext \
+    git \
+    glib2-devel \
+    glusterfs-api-devel \
+    gnutls-devel \
+    gtk3-devel \
+    hostname \
+    libaio-devel \
+    libasan \
+    libattr-devel \
+    libcap-devel \
+    libcap-ng-devel \
+    libcurl-devel \
+    libepoxy-devel \
+    libfdt-devel \
+    libgbm-devel \
+    libiscsi-devel \
+    libjpeg-devel \
+    libnfs-devel \
+    libpng-devel \
+    librbd-devel \
+    libseccomp-devel \
+    libssh2-devel \
+    libubsan \
+    libudev-devel \
+    libusbx-devel \
+    libxml2-devel \
+    llvm \
+    lzo-devel \
+    make \
+    mingw32-bzip2 \
+    mingw32-curl \
+    mingw32-glib2 \
+    mingw32-gmp \
+    mingw32-gnutls \
+    mingw32-gtk3 \
+    mingw32-libjpeg-turbo \
+    mingw32-libpng \
+    mingw32-libssh2 \
+    mingw32-libtasn1 \
+    mingw32-nettle \
+    mingw32-pixman \
+    mingw32-pkg-config \
+    mingw32-SDL2 \
+    mingw64-bzip2 \
+    mingw64-curl \
+    mingw64-glib2 \
+    mingw64-gmp \
+    mingw64-gnutls \
+    mingw64-gtk3 \
+    mingw64-libjpeg-turbo \
+    mingw64-libpng \
+    mingw64-libssh2 \
+    mingw64-libtasn1 \
+    mingw64-nettle \
+    mingw64-pixman \
+    mingw64-pkg-config \
+    mingw64-SDL2 \
+    ncurses-devel \
+    nettle-devel \
+    nss-devel \
+    numactl-devel \
+    perl \
+    pixman-devel \
+    pulseaudio-libs-devel \
+    python3 \
+    PyYAML \
+    rdma-core-devel \
+    SDL2-devel \
+    snappy-devel \
+    sparse \
+    spice-server-devel \
+    systemtap-sdt-devel \
+    tar \
+    usbredir-devel \
+    virglrenderer-devel \
+    vte3-devel \
+    wget \
+    which \
+    xen-devel \
+    xfsprogs-devel \
+    zlib-devel
+ENV QEMU_CONFIGURE_OPTS --python=/usr/bin/python3
+
+RUN dnf install -y $PACKAGES
+RUN rpm -q $PACKAGES | sort > /packages.txt
+ENV COVERITY_TOOL_BASE=/coverity-tools
+COPY run-coverity-scan run-coverity-scan
+RUN --mount=type=secret,id=coverity.token,required ./run-coverity-scan --update-tools-only --tokenfile /run/secrets/coverity.token
scripts/coverity-scan/run-coverity-scan +58 -0

88 lines not on this page · raw message

Signature · 1 line
2.19.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] scripts/run-coverity-scan: Script to run Coverity Scan build

In reply to Peter Maydell
Quoted 16 lines · Peter Maydell

Add a new script to automate the process of running the Coverity Scan build tools and uploading the resulting tarball to the website.

This is intended eventually to be driven from Travis, but it can be run locally, if you are a maintainer of the QEMU project on the Coverity Scan website and have the secret upload token.

The script must be run directly on a Fedora 28 system.

---

+++ b/scripts/coverity-scan/run-coverity-scan

scripts/coverity-scan/run-coverity-scan line 1

Quoted 1 line
scripts/coverity-scan/run-coverity-scan new file +1 -0
@@ -0,0 +1,292 @@
+#!/bin/sh -e

set -e...

scripts/coverity-scan/run-coverity-scan line 50

Quoted 1 line
scripts/coverity-scan/run-coverity-scan new file +1 -0
+check_upload_permissions() {

...and shell functions do NOT intuitively do what you would think. It's almost always better to use explicit error checking than to rely on set -e as a crutch, because then you don't get surprises.

Quoted 18 lines
scripts/coverity-scan/run-coverity-scan new file +18 -0
+    # Check whether we can do an upload to the server; will exit the script
+    # with status 1 if the check failed (usually a bad token);
+    # will exit the script with status 0 if the check indicated that we
+    # can't upload yet (ie we are at quota)
+    # Assumes that PROJTOKEN, PROJNAME and DRYRUN have been initialized.
+
+    echo "Checking upload permissions..."
+
+    if ! up_perm="$(wget https://scan.coverity.com/api/upload_permitted --post-data "token=$PROJTOKEN&project=$PROJNAME" -q -O -)"; then
+        echo "Coverity Scan API access denied: bad token?"
+        exit 1
+    fi
+
+    # Really up_perm is a JSON response with either
+    # {upload_permitted:true} or {next_upload_permitted_at:<date>}
+    # We do some hacky string parsing instead of properly parsing it.
+    case "$up_perm" in
+        *upload_permitted*true*)

scripts/coverity-scan/run-coverity-scan line 78

Quoted 10 lines
scripts/coverity-scan/run-coverity-scan new file +10 -0
+            echo "Coverity Scan: upload permitted"
+            ;;
+        *next_upload_permitted_at*)
+            if [ "$DRYRUN" = yes ]; then
+                echo "Coverity Scan: upload quota reached; stopping here"
+                # Exit success as this isn't a build error.
+                exit 0
+            else
+                echo "Coverity Scan: upload quota reached, continuing dry run"
+            fi

Did you get the logic backwards on this if? Based on the error message, I was guessing the intended condition was [ "$DRYRUN" != yes ]

Quoted 25 lines
scripts/coverity-scan/run-coverity-scan new file +25 -0
+            ;;
+        *)
+            echo "Coverity Scan upload check: unexpected result $up_perm"
+            exit 1
+            ;;
+    esac
+}
+
+
+update_coverity_tools () {
+    # Check for whether we need to download the Coverity tools
+    # (either because we don't have a copy, or because it's out of date)
+    # Assumes that COVERITY_TOOL_BASE, PROJTOKEN and PROJNAME are set.
+
+    mkdir -p "$COVERITY_TOOL_BASE"
+    cd "$COVERITY_TOOL_BASE"
+
+    echo "Checking for new version of coverity build tools..."
+    wget https://scan.coverity.com/download/linux64 --post-data "token=$PROJTOKEN&project=$PROJNAME&md5=1" -O coverity_tool.md5.new
+
+    if ! cmp -s coverity_tool.md5 coverity_tool.md5.new; then
+        # out of date md5 or no md5: download new build tool
+        # blow away the old build tool
+        echo "Downloading coverity build tools..."
+        rm -rf coverity_tool coverity_tool.tgz

scripts/coverity-scan/run-coverity-scan line 113

Quoted 10 lines
scripts/coverity-scan/run-coverity-scan new file +10 -0
+        wget https://scan.coverity.com/download/linux64 --post-data "token=$PROJTOKEN&project=$PROJNAME" -O coverity_tool.tgz
+        if ! (cat coverity_tool.md5.new; echo "  coverity_tool.tgz") | md5sum -c --status; then
+            echo "Downloaded tarball didn't match md5sum!"
+            exit 1
+        fi
+        # extract the new one, keeping it corralled in a 'coverity_tool' directory
+        echo "Unpacking coverity build tools..."
+        mkdir -p coverity_tool
+        cd coverity_tool
+        tar xf ../coverity_tool.tgz

Assumes GNU tar, with its auto-decompression. But then again, you said the entire script assumes Fedora 28, so that's not necessarily bad.

scripts/coverity-scan/run-coverity-scan line 115

Quoted 2 lines
scripts/coverity-scan/run-coverity-scan new file +2 -0
+        cd ..
+        mv coverity_tool.md5.new coverity_tool.md5

Here's an example of where 'set -e' could bite - if tar or mv fails (perhaps due to ENOSPC), the decision of whether the shell function immediately stops or continues on to the next line (without handling the error) is dependent on the context that the caller used when calling update_coverity_tools (that is, 'update_coverity_tools' and 'update_coverity_tools || fail' behave differently).

Quoted 12 lines
scripts/coverity-scan/run-coverity-scan new file +11 -0
+    fi
+
+    rm -f coverity_tool.md5.new
+}
+
+
+# Check user-provided environment variables and arguments
+DRYRUN=no
+UPDATE_ONLY=no
+
+while [ "$#" -ge 1 ]; do
 

scripts/coverity-scan/run-coverity-scan line 186

Quoted 10 lines
scripts/coverity-scan/run-coverity-scan new file +10 -0
+done
+
+if [ -z "$COVERITY_TOKEN" ]; then
+    echo "COVERITY_TOKEN environment variable not set"
+    exit 1
+fi
+
+if [ -z "$COVERITY_BUILD_CMD" ]; then
+    echo "COVERITY_BUILD_CMD: using default 'make -j8'"
+    COVERITY_BUILD_CMD="make -j8"

Should this query 'nproc' instead of hard-coding -j8?

scripts/coverity-scan/run-coverity-scan line 195

Quoted 9 lines
scripts/coverity-scan/run-coverity-scan new file +9 -0
+fi
+
+if [ -z "$COVERITY_TOOL_BASE" ]; then
+    echo "COVERITY_TOOL_BASE: using default /tmp/coverity-tools"
+    COVERITY_TOOL_BASE=/tmp/coverity-tools
+fi
+
+if [ -z "$SRCDIR" ]; then
+    SRCDIR="$(pwd)"

Why not save a process, and just use SRCDIR="$PWD"

Quoted 31 lines
scripts/coverity-scan/run-coverity-scan new file +31 -0
+fi
+
+PROJTOKEN="$COVERITY_TOKEN"
+PROJNAME=QEMU
+TARBALL=cov-int.tar.xz
+
+
+if [ "$UPDATE_ONLY" = yes ]; then
+    # Just do the tools update; we don't need to check whether
+    # we are in a source tree or have upload rights for this,
+    # so do it before some of the command line and source tree checks.
+    update_coverity_tools
+    exit 0
+fi
+
+cd "$SRCDIR"
+
+echo "Checking this is a QEMU source tree..."
+if ! [ -e "$SRCDIR/VERSION" ]; then
+    echo "Not in a QEMU source tree?"
+    exit 1
+fi
+
+# Fill in defaults used by the non-update-only process
+if [ -z "$VERSION" ]; then
+    VERSION="$(git describe --always HEAD)"
+fi
+
+if [ -z "$DESCRIPTION" ]; then
+    DESCRIPTION="$(git rev-parse HEAD)"
+fi

scripts/coverity-scan/run-coverity-scan line 236

Quoted 10 lines
scripts/coverity-scan/run-coverity-scan new file +10 -0
+
+if [ -z "$COVERITY_EMAIL" ]; then
+    COVERITY_EMAIL="$(git config user.email)"
+fi
+
+check_upload_permissions
+
+update_coverity_tools
+
+TOOLBIN="$(cd "$COVERITY_TOOL_BASE" && echo $(pwd)/coverity_tool/cov-analysis-*/bin)"

If $CDPATH is set and $COVERITY_TOOL_BASE does not contain /, this could result in garbage being prepended to TOOLBIN as output from the 'cd'. Also, $PWD is nicer than $(pwd); but are you sure the glob in cov-analysis-* won't select too many files?

Quoted 57 lines
scripts/coverity-scan/run-coverity-scan new file +56 -0
+
+if ! test -x "$TOOLBIN/cov-build"; then
+    echo "Couldn't find cov-build in the coverity build-tool directory??"
+    exit 1
+fi
+
+export PATH="$TOOLBIN:$PATH"
+
+cd "$SRCDIR"
+
+echo "Doing make distclean..."
+make distclean
+
+echo "Configuring..."
+# We configure with a fixed set of enables here to ensure that we don't
+# accidentally reduce the scope of the analysis by doing the build on
+# the system that's missing a dependency that we need to build part of
+# the codebase.
+./configure --disable-modules --enable-sdl --with-sdlabi=2.0 --enable-gtk \
+    --enable-opengl --enable-vte --enable-gnutls \
+    --enable-nettle --enable-curses --enable-curl \
+    --audio-drv-list=oss,alsa,sdl,pa --enable-virtfs \
+    --enable-vnc --enable-vnc-sasl --enable-vnc-jpeg --enable-vnc-png \
+    --enable-xen --enable-brlapi --enable-bluez \
+    --disable-vde --enable-linux-aio --enable-attr \
+    --enable-cap-ng --enable-trace-backends=log --enable-spice --enable-rbd \
+    --enable-xfsctl --enable-libusb --enable-usb-redir \
+    --enable-libiscsi --enable-libnfs --enable-seccomp \
+    --enable-tpm --enable-libssh2 --enable-lzo --enable-snappy --enable-bzip2 \
+    --enable-numa --enable-rdma --enable-smartcard --enable-virglrenderer \
+    --enable-mpath --enable-libxml2 --enable-glusterfs
+
+echo "Making libqemustub.a..."
+make libqemustub.a
+
+echo "Running cov-build..."
+rm -rf cov-int
+mkdir cov-int
+cov-build --dir cov-int $COVERITY_BUILD_CMD
+
+echo "Creating results tarball..."
+tar cvf - cov-int | xz > "$TARBALL"
+
+echo "Uploading results tarball..."
+
+if [ "$DRYRUN" = yes ]; then
+    echo "Dry run only, not uploading $TARBALL"
+    exit 0
+fi
+
+curl --form token="$PROJTOKEN" --form email="$COVERITY_EMAIL" \
+     --form file=@"$TARBALL" --form version="$VERSION" \
+     --form description="$DESCRIPTION" \
+     https://scan.coverity.com/builds?project="$PROJNAME"
+
+echo "Done."
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] scripts/run-coverity-scan: Script to run Coverity Scan build

Quoted 11 lines · Eric Blake
Quoted 10 lines · Peter Maydell

Add a new script to automate the process of running the Coverity Scan build tools and uploading the resulting tarball to the website.

This is intended eventually to be driven from Travis, but it can be run locally, if you are a maintainer of the QEMU project on the Coverity Scan website and have the secret upload token.

Quoted 4 lines
Quoted 4 lines

The script must be run directly on a Fedora 28 system.

---

Thanks for the code review -- my shell scripting has some bad habits in it.

Quoted 8 lines

scripts/coverity-scan/run-coverity-scan line 1

Quoted 4 lines

+++ b/scripts/coverity-scan/run-coverity-scan

scripts/coverity-scan/run-coverity-scan new file +1 -0
@@ -0,0 +1,292 @@
+#!/bin/sh -e

set -e...

Quoted 6 lines

scripts/coverity-scan/run-coverity-scan line 50

Quoted 1 line
scripts/coverity-scan/run-coverity-scan new file +1 -0
+check_upload_permissions() {

...and shell functions do NOT intuitively do what you would think. It's almost always better to use explicit error checking than to rely on set -e as a crutch, because then you don't get surprises.

I think we had this conversation with last year's version
of this script too :-) As you say, the use of functions makes it maybe better to use explicit error checking -- but is there a standard syntax for that that doesn't make
basic
foo
bar
baz
"do these things in order" code look weird and require special care? At least with set -e you do get error checking, whereas scripts without it tend to just plough on regardless (look at configure, which doesn't use set -e but doesn't have explicit checking either).

Quoted 27 lines
Quoted 27 lines
(quoted diff) +1 -0
+    # Check whether we can do an upload to the server; will exit the

script

scripts/coverity-scan/run-coverity-scan new file +24 -1
+    # with status 1 if the check failed (usually a bad token);
+    # will exit the script with status 0 if the check indicated that we
+    # can't upload yet (ie we are at quota)
+    # Assumes that PROJTOKEN, PROJNAME and DRYRUN have been initialized.
+
+    echo "Checking upload permissions..."
+
+    if ! up_perm="$(wget https://scan.coverity.com/api/upload_permitted
--post-data "token=$PROJTOKEN&project=$PROJNAME" -q -O -)"; then
+        echo "Coverity Scan API access denied: bad token?"
+        exit 1
+    fi
+
+    # Really up_perm is a JSON response with either
+    # {upload_permitted:true} or {next_upload_permitted_at:<date>}
+    # We do some hacky string parsing instead of properly parsing it.
+    case "$up_perm" in
+        *upload_permitted*true*)
+            echo "Coverity Scan: upload permitted"
+            ;;
+        *next_upload_permitted_at*)
+            if [ "$DRYRUN" = yes ]; then
+                echo "Coverity Scan: upload quota reached; stopping here"
+                # Exit success as this isn't a build error.
+                exit 0
Quoted 8 lines
Quoted 4 lines
(quoted diff) +2 -0
+            else
+                echo "Coverity Scan: upload quota reached, continuing dry

run"
+ fi

Did you get the logic backwards on this if? Based on the error message, I was guessing the intended condition was [ "$DRYRUN" != yes ]

Yes, I did (I flipped the way I was doing checks from "unset means no" to "check if it is yes", and didn't get it right; I caught another instance of this later, but missed this one.)

Quoted 5 lines
Quoted 5 lines
scripts/coverity-scan/run-coverity-scan new file +5 -0
+done
+
+if [ -z "$COVERITY_TOKEN" ]; then
+    echo "COVERITY_TOKEN environment variable not set"
+    exit 1
Quoted 8 lines

scripts/coverity-scan/run-coverity-scan line 186

Quoted 5 lines
scripts/coverity-scan/run-coverity-scan new file +5 -0
+fi
+
+if [ -z "$COVERITY_BUILD_CMD" ]; then
+    echo "COVERITY_BUILD_CMD: using default 'make -j8'"
+    COVERITY_BUILD_CMD="make -j8"

Should this query 'nproc' instead of hard-coding -j8?

Probably. Legacy of this thing developing from a local hack into something a bit more 'production'.

Quoted 4 lines
Quoted 4 lines
scripts/coverity-scan/run-coverity-scan new file +4 -0
+fi
+
+if [ -z "$COVERITY_TOOL_BASE" ]; then
+    echo "COVERITY_TOOL_BASE: using default /tmp/coverity-tools"
Quoted 8 lines

scripts/coverity-scan/run-coverity-scan line 195

Quoted 5 lines
scripts/coverity-scan/run-coverity-scan new file +5 -0
+    COVERITY_TOOL_BASE=/tmp/coverity-tools
+fi
+
+if [ -z "$SRCDIR" ]; then
+    SRCDIR="$(pwd)"

Why not save a process, and just use SRCDIR="$PWD"

I never remember that $PWD exists, because when I'm doing things on a shell command line I always use 'pwd'. But it would be better, yes.

Quoted 8 lines
Quoted 2 lines

+TOOLBIN="$(cd "$COVERITY_TOOL_BASE" && echo
$(pwd)/coverity_tool/cov-analysis-*/bin)"

If $CDPATH is set and $COVERITY_TOOL_BASE does not contain /, this could result in garbage being prepended to TOOLBIN as output from the 'cd'. Also, $PWD is nicer than $(pwd); but are you sure the glob in cov-analysis-* won't select too many files?

The glob is not great, but it is necessary to make the script robust over new versions of the tools, which put the version number in the cov-analysis-whatever directory name. If we do ever get more than one file then the "test -x" below will fail, and we'll be able to investigate and fix up the script.

CDPATH sounds like a horrific misfeature designed for breaking scripts, so I'm not very interested in trying to work around it. We don't seem to worry about this in configure either. (I suppose we could just unset it at the start of the script.)

thanks
-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] scripts/coverity-scan: Add Docker support

In reply to Peter Maydell
Quoted 126 lines · Peter Maydell

Add support for running the Coverity Scan tools inside a Docker container rather than directly on the host system.

---
  scripts/coverity-scan/coverity-scan.docker | 120 +++++++++++++++++++++
  scripts/coverity-scan/run-coverity-scan    |  58 ++++++++++
  2 files changed, 178 insertions(+)

create mode 100644 scripts/coverity-scan/coverity-scan.docker

scripts/coverity-scan/coverity-scan.docker new file +110 -0
new file mode 100644
index 00000000000..81f69459954
@@ -0,0 +1,120 @@
+# syntax=docker/dockerfile:1.0.0-experimental
+#
+# Docker setup for running the "Coverity Scan" tools over the source
+# tree and uploading them to the website, as per
+# https://scan.coverity.com/projects/qemu/builds/new
+# We do this on a fixed config (currently Fedora 28 with a known
+# set of dependencies and a configure command that enables a specific
+# set of options) so that random changes don't result in our accidentally
+# dropping some files from the scan.
+# The work of actually doing the build is handled by the
+# run-coverity-scan script.
+
+
+FROM fedora:28
+ENV PACKAGES \
+    alsa-lib-devel \
+    bc \
+    bison \
+    bluez-libs-devel \
+    brlapi-devel \
+    bzip2 \
+    bzip2-devel \
+    ccache \
+    clang \
+    curl \
+    cyrus-sasl-devel \
+    device-mapper-multipath-devel \
+    findutils \
+    flex \
+    gcc \
+    gcc-c++ \
+    gettext \
+    git \
+    glib2-devel \
+    glusterfs-api-devel \
+    gnutls-devel \
+    gtk3-devel \
+    hostname \
+    libaio-devel \
+    libasan \
+    libattr-devel \
+    libcap-devel \
+    libcap-ng-devel \
+    libcurl-devel \
+    libepoxy-devel \
+    libfdt-devel \
+    libgbm-devel \
+    libiscsi-devel \
+    libjpeg-devel \
+    libnfs-devel \
+    libpng-devel \
+    librbd-devel \
+    libseccomp-devel \
+    libssh2-devel \
+    libubsan \
+    libudev-devel \
+    libusbx-devel \
+    libxml2-devel \
+    llvm \
+    lzo-devel \
+    make \
+    mingw32-bzip2 \
+    mingw32-curl \
+    mingw32-glib2 \
+    mingw32-gmp \
+    mingw32-gnutls \
+    mingw32-gtk3 \
+    mingw32-libjpeg-turbo \
+    mingw32-libpng \
+    mingw32-libssh2 \
+    mingw32-libtasn1 \
+    mingw32-nettle \
+    mingw32-pixman \
+    mingw32-pkg-config \
+    mingw32-SDL2 \
+    mingw64-bzip2 \
+    mingw64-curl \
+    mingw64-glib2 \
+    mingw64-gmp \
+    mingw64-gnutls \
+    mingw64-gtk3 \
+    mingw64-libjpeg-turbo \
+    mingw64-libpng \
+    mingw64-libssh2 \
+    mingw64-libtasn1 \
+    mingw64-nettle \
+    mingw64-pixman \
+    mingw64-pkg-config \
+    mingw64-SDL2 \
+    ncurses-devel \
+    nettle-devel \
+    nss-devel \
+    numactl-devel \
+    perl \
+    pixman-devel \
+    pulseaudio-libs-devel \
+    python3 \
+    PyYAML \
+    rdma-core-devel \
+    SDL2-devel \
+    snappy-devel \
+    sparse \
+    spice-server-devel \
+    systemtap-sdt-devel \
+    tar \
+    usbredir-devel \
+    virglrenderer-devel \
+    vte3-devel \
+    wget \
+    which \

scripts/coverity-scan/coverity-scan.docker line 120

Quoted 10 lines
scripts/coverity-scan/coverity-scan.docker new file +10 -0
+    xen-devel \
+    xfsprogs-devel \
+    zlib-devel
+ENV QEMU_CONFIGURE_OPTS --python=/usr/bin/python3
+
+RUN dnf install -y $PACKAGES
+RUN rpm -q $PACKAGES | sort > /packages.txt
+ENV COVERITY_TOOL_BASE=/coverity-tools
+COPY run-coverity-scan run-coverity-scan
+RUN --mount=type=secret,id=coverity.token,required ./run-coverity-scan --update-tools-only --tokenfile /run/secrets/coverity.token

Calling "make docket-image-fedora" you can reduce this script to:

-- >8 --
FROM qemu:fedora

ENV PACKAGES \
    $PACKAGES \
    alsa-lib-devel \
    curl \
    cyrus-sasl-devel \
    libepoxy-devel \
    libgbm-devel \
    libiscsi-devel \
    libnfs-devel \
    libseccomp-devel \
    libudev-devel \
    pulseaudio-libs-devel \
    rdma-core-devel \
    wget \
    xfsprogs-devel

RUN dnf install -y $PACKAGES
RUN rpm -q $PACKAGES | sort > /packages.txt
ENV COVERITY_TOOL_BASE=/coverity-tools
COPY run-coverity-scan run-coverity-scan
RUN --mount=type=secret,id=coverity.token,required ./run-coverity-scan --update-tools-only --tokenfile /run/secrets/coverity.token
---

sharing a big docker layer.

#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] scripts/run-coverity-scan: Script to run Coverity Scan build

In reply to Peter Maydell
Quoted 10 lines · Peter Maydell
Quoted 9 lines

set -e...

Quoted 1 line

+check_upload_permissions() {

...and shell functions do NOT intuitively do what you would think. It's almost always better to use explicit error checking than to rely on set -e as a crutch, because then you don't get surprises.

Quoted 12 lines

I think we had this conversation with last year's version
of this script too :-) As you say, the use of functions makes it maybe better to use explicit error checking -- but is there a standard syntax for that that doesn't make
basic
foo
bar
baz
"do these things in order" code look weird and require special care? At least with set -e you do get error checking, whereas scripts without it tend to just plough on regardless (look at configure, which doesn't use set -e but doesn't have explicit checking either).

I've seen both:

foo &&
bar &&
baz

and

foo || fail
bar || fail
baz || fail

for some variation of a 'fail' function. But yeah, once you start having to worry about checking everything yourself (or realizing which lines don't need checking), you find out how much of a crutch 'set -e' tries to be, and then wonder how it ever worked (for the number of cases where 'set -e' does not actually catch failure, and cannot be re-enabled in smaller scopes).

Quoted 9 lines
Quoted 8 lines
Quoted 2 lines

+TOOLBIN="$(cd "$COVERITY_TOOL_BASE" && echo
$(pwd)/coverity_tool/cov-analysis-*/bin)"

If $CDPATH is set and $COVERITY_TOOL_BASE does not contain /, this could result in garbage being prepended to TOOLBIN as output from the 'cd'. Also, $PWD is nicer than $(pwd); but are you sure the glob in cov-analysis-* won't select too many files?

Quoted 5 lines

The glob is not great, but it is necessary to make the script robust over new versions of the tools, which put the version number in the cov-analysis-whatever directory name. If we do ever get more than one file then the "test -x" below will fail, and we'll be able to investigate and fix up the script.

Yeah, I think you're okay on that front.

Quoted 5 lines

CDPATH sounds like a horrific misfeature designed for breaking scripts, so I'm not very interested in trying to work around it. We don't seem to worry about this in configure either. (I suppose we could just unset it at the start of the script.)

Autoconf 'configure' scripts do just that (unset CDPATH up front). If someone ever complains that it actually broke for them, we'll make the fix; until then, I can live with the risk.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] scripts/coverity-scan: Add Docker support

In reply to Philippe Mathieu-Daudé
Quoted 131 lines · Philippe Mathieu-Daudé
Quoted 130 lines · Peter Maydell

Add support for running the Coverity Scan tools inside a Docker container rather than directly on the host system.

---
  scripts/coverity-scan/coverity-scan.docker | 120 +++++++++++++++++++++
  scripts/coverity-scan/run-coverity-scan    |  58 ++++++++++
  2 files changed, 178 insertions(+)

create mode 100644 scripts/coverity-scan/coverity-scan.docker

scripts/coverity-scan/coverity-scan.docker new file +114 -0
new file mode 100644
index 00000000000..81f69459954
@@ -0,0 +1,120 @@
+# syntax=docker/dockerfile:1.0.0-experimental
+#
+# Docker setup for running the "Coverity Scan" tools over the source
+# tree and uploading them to the website, as per
+# https://scan.coverity.com/projects/qemu/builds/new
+# We do this on a fixed config (currently Fedora 28 with a known
+# set of dependencies and a configure command that enables a specific
+# set of options) so that random changes don't result in our accidentally
+# dropping some files from the scan.
+# The work of actually doing the build is handled by the
+# run-coverity-scan script.
+
+
+FROM fedora:28
+ENV PACKAGES \
+    alsa-lib-devel \
+    bc \
+    bison \
+    bluez-libs-devel \
+    brlapi-devel \
+    bzip2 \
+    bzip2-devel \
+    ccache \
+    clang \
+    curl \
+    cyrus-sasl-devel \
+    device-mapper-multipath-devel \
+    findutils \
+    flex \
+    gcc \
+    gcc-c++ \
+    gettext \
+    git \
+    glib2-devel \
+    glusterfs-api-devel \
+    gnutls-devel \
+    gtk3-devel \
+    hostname \
+    libaio-devel \
+    libasan \
+    libattr-devel \
+    libcap-devel \
+    libcap-ng-devel \
+    libcurl-devel \
+    libepoxy-devel \
+    libfdt-devel \
+    libgbm-devel \
+    libiscsi-devel \
+    libjpeg-devel \
+    libnfs-devel \
+    libpng-devel \
+    librbd-devel \
+    libseccomp-devel \
+    libssh2-devel \
+    libubsan \
+    libudev-devel \
+    libusbx-devel \
+    libxml2-devel \
+    llvm \
+    lzo-devel \
+    make \
+    mingw32-bzip2 \
+    mingw32-curl \
+    mingw32-glib2 \
+    mingw32-gmp \
+    mingw32-gnutls \
+    mingw32-gtk3 \
+    mingw32-libjpeg-turbo \
+    mingw32-libpng \
+    mingw32-libssh2 \
+    mingw32-libtasn1 \
+    mingw32-nettle \
+    mingw32-pixman \
+    mingw32-pkg-config \
+    mingw32-SDL2 \
+    mingw64-bzip2 \
+    mingw64-curl \
+    mingw64-glib2 \
+    mingw64-gmp \
+    mingw64-gnutls \
+    mingw64-gtk3 \
+    mingw64-libjpeg-turbo \
+    mingw64-libpng \
+    mingw64-libssh2 \
+    mingw64-libtasn1 \
+    mingw64-nettle \
+    mingw64-pixman \
+    mingw64-pkg-config \
+    mingw64-SDL2 \
+    ncurses-devel \
+    nettle-devel \
+    nss-devel \
+    numactl-devel \
+    perl \
+    pixman-devel \
+    pulseaudio-libs-devel \
+    python3 \
+    PyYAML \
+    rdma-core-devel \
+    SDL2-devel \
+    snappy-devel \
+    sparse \
+    spice-server-devel \
+    systemtap-sdt-devel \
+    tar \
+    usbredir-devel \
+    virglrenderer-devel \
+    vte3-devel \
+    wget \
+    which \
+    xen-devel \
+    xfsprogs-devel \
+    zlib-devel
+ENV QEMU_CONFIGURE_OPTS --python=/usr/bin/python3
Quoted 8 lines

scripts/coverity-scan/coverity-scan.docker line 120

Quoted 6 lines
scripts/coverity-scan/coverity-scan.docker new file +6 -0
+
+RUN dnf install -y $PACKAGES
+RUN rpm -q $PACKAGES | sort > /packages.txt
+ENV COVERITY_TOOL_BASE=/coverity-tools
+COPY run-coverity-scan run-coverity-scan
+RUN --mount=type=secret,id=coverity.token,required ./run-coverity-scan --update-tools-only --tokenfile /run/secrets/coverity.token

Calling "make docket-image-fedora" you can reduce this script to:

Remember for this to work we need to enforce the dependencies in the tests/docker/Makefile.include and integrate into our make machinery. Currently this dockerfile lives outside of the rest of our make machinery.

We've talked about having Docker environments for building test pieces before so I wonder if this is a good fit for expanding the make system support for these sort of jobs?

Quoted 27 lines

-- >8 --
FROM qemu:fedora

ENV PACKAGES \
    $PACKAGES \
    alsa-lib-devel \
    curl \
    cyrus-sasl-devel \
    libepoxy-devel \
    libgbm-devel \
    libiscsi-devel \
    libnfs-devel \
    libseccomp-devel \
    libudev-devel \
    pulseaudio-libs-devel \
    rdma-core-devel \
    wget \
    xfsprogs-devel

RUN dnf install -y $PACKAGES
RUN rpm -q $PACKAGES | sort > /packages.txt
ENV COVERITY_TOOL_BASE=/coverity-tools
COPY run-coverity-scan run-coverity-scan
RUN --mount=type=secret,id=coverity.token,required ./run-coverity-scan --update-tools-only --tokenfile /run/secrets/coverity.token
---

Quoted 1 line

sharing a big docker layer.

--
Alex Bennée

#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] scripts/coverity-scan: Add Docker support

Quoted 141 lines · Alex Bennée
Quoted 131 lines · Philippe Mathieu-Daudé
Quoted 130 lines · Peter Maydell

Add support for running the Coverity Scan tools inside a Docker container rather than directly on the host system.

---
   scripts/coverity-scan/coverity-scan.docker | 120 +++++++++++++++++++++
   scripts/coverity-scan/run-coverity-scan    |  58 ++++++++++
   2 files changed, 178 insertions(+)

create mode 100644 scripts/coverity-scan/coverity-scan.docker

scripts/coverity-scan/coverity-scan.docker new file +114 -0
new file mode 100644
index 00000000000..81f69459954
@@ -0,0 +1,120 @@
+# syntax=docker/dockerfile:1.0.0-experimental
+#
+# Docker setup for running the "Coverity Scan" tools over the source
+# tree and uploading them to the website, as per
+# https://scan.coverity.com/projects/qemu/builds/new
+# We do this on a fixed config (currently Fedora 28 with a known
+# set of dependencies and a configure command that enables a specific
+# set of options) so that random changes don't result in our accidentally
+# dropping some files from the scan.
+# The work of actually doing the build is handled by the
+# run-coverity-scan script.
+
+
+FROM fedora:28
+ENV PACKAGES \
+    alsa-lib-devel \
+    bc \
+    bison \
+    bluez-libs-devel \
+    brlapi-devel \
+    bzip2 \
+    bzip2-devel \
+    ccache \
+    clang \
+    curl \
+    cyrus-sasl-devel \
+    device-mapper-multipath-devel \
+    findutils \
+    flex \
+    gcc \
+    gcc-c++ \
+    gettext \
+    git \
+    glib2-devel \
+    glusterfs-api-devel \
+    gnutls-devel \
+    gtk3-devel \
+    hostname \
+    libaio-devel \
+    libasan \
+    libattr-devel \
+    libcap-devel \
+    libcap-ng-devel \
+    libcurl-devel \
+    libepoxy-devel \
+    libfdt-devel \
+    libgbm-devel \
+    libiscsi-devel \
+    libjpeg-devel \
+    libnfs-devel \
+    libpng-devel \
+    librbd-devel \
+    libseccomp-devel \
+    libssh2-devel \
+    libubsan \
+    libudev-devel \
+    libusbx-devel \
+    libxml2-devel \
+    llvm \
+    lzo-devel \
+    make \
+    mingw32-bzip2 \
+    mingw32-curl \
+    mingw32-glib2 \
+    mingw32-gmp \
+    mingw32-gnutls \
+    mingw32-gtk3 \
+    mingw32-libjpeg-turbo \
+    mingw32-libpng \
+    mingw32-libssh2 \
+    mingw32-libtasn1 \
+    mingw32-nettle \
+    mingw32-pixman \
+    mingw32-pkg-config \
+    mingw32-SDL2 \
+    mingw64-bzip2 \
+    mingw64-curl \
+    mingw64-glib2 \
+    mingw64-gmp \
+    mingw64-gnutls \
+    mingw64-gtk3 \
+    mingw64-libjpeg-turbo \
+    mingw64-libpng \
+    mingw64-libssh2 \
+    mingw64-libtasn1 \
+    mingw64-nettle \
+    mingw64-pixman \
+    mingw64-pkg-config \
+    mingw64-SDL2 \
+    ncurses-devel \
+    nettle-devel \
+    nss-devel \
+    numactl-devel \
+    perl \
+    pixman-devel \
+    pulseaudio-libs-devel \
+    python3 \
+    PyYAML \
+    rdma-core-devel \
+    SDL2-devel \
+    snappy-devel \
+    sparse \
+    spice-server-devel \
+    systemtap-sdt-devel \
+    tar \
+    usbredir-devel \
+    virglrenderer-devel \
+    vte3-devel \
+    wget \
+    which \
+    xen-devel \
+    xfsprogs-devel \
+    zlib-devel
+ENV QEMU_CONFIGURE_OPTS --python=/usr/bin/python3
Quoted 8 lines

scripts/coverity-scan/coverity-scan.docker line 120

Quoted 6 lines
scripts/coverity-scan/coverity-scan.docker new file +6 -0
+
+RUN dnf install -y $PACKAGES
+RUN rpm -q $PACKAGES | sort > /packages.txt
+ENV COVERITY_TOOL_BASE=/coverity-tools
+COPY run-coverity-scan run-coverity-scan
+RUN --mount=type=secret,id=coverity.token,required ./run-coverity-scan --update-tools-only --tokenfile /run/secrets/coverity.token

Calling "make docket-image-fedora" you can reduce this script to:

Quoted 4 lines

Remember for this to work we need to enforce the dependencies in the tests/docker/Makefile.include and integrate into our make machinery. Currently this dockerfile lives outside of the rest of our make machinery.

Yes, but since this image is ran via a script which calls "docker build ..." it could previously call "make docket-image-fedora".

Currenty the qemu:fedora layer takes a bit more than 2GB, space worth on laptop SSD ;)

Quoted 4 lines

We've talked about having Docker environments for building test pieces before so I wonder if this is a good fit for expanding the make system support for these sort of jobs?

I am not sure which of the various Docker talk you are thinking of...

For this particular case this is probably not worth integrating it into the make system.

However it makes sense to me to have the qemu:fedora and this image pushed. Probably worth another thread although.

Quoted 34 lines
Quoted 28 lines

-- >8 --
FROM qemu:fedora

ENV PACKAGES \
     $PACKAGES \
     alsa-lib-devel \
     curl \
     cyrus-sasl-devel \
     libepoxy-devel \
     libgbm-devel \
     libiscsi-devel \
     libnfs-devel \
     libseccomp-devel \
     libudev-devel \
     pulseaudio-libs-devel \
     rdma-core-devel \
     wget \
     xfsprogs-devel

RUN dnf install -y $PACKAGES
RUN rpm -q $PACKAGES | sort > /packages.txt
ENV COVERITY_TOOL_BASE=/coverity-tools
COPY run-coverity-scan run-coverity-scan
RUN --mount=type=secret,id=coverity.token,required ./run-coverity-scan --update-tools-only --tokenfile /run/secrets/coverity.token
---

Quoted 1 line

sharing a big docker layer.

--
Alex Bennée

#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] scripts/coverity-scan: Add Docker support

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Calling "make docket-image-fedora" you can reduce this script to:

-- >8 --
FROM qemu:fedora
ENV PACKAGES \
    $PACKAGES \
    alsa-lib-devel \
    curl \
    cyrus-sasl-devel \
    libepoxy-devel \
    libgbm-devel \

Quoted 8 lines

    libiscsi-devel \
    libnfs-devel \
    libseccomp-devel \
    libudev-devel \
    pulseaudio-libs-devel \
    rdma-core-devel \
    wget \
    xfsprogs-devel

... these can actually be moved to tests/docker/dockerfiles/fedora.docker, improving the coverage...

Quoted 3 lines

RUN dnf install -y $PACKAGES
RUN rpm -q $PACKAGES | sort > /packages.txt

... and removing the need for these two.

Quoted 4 lines

ENV COVERITY_TOOL_BASE=/coverity-tools
COPY run-coverity-scan run-coverity-scan
RUN --mount=type=secret,id=coverity.token,required ./run-coverity-scan --update-tools-only --tokenfile /run/secrets/coverity.token

If the tokenfile is not needed when updating the tools, you could also move the Dockerfile to tests/docker/dockerfiles/fedora-coverity.docker and just do "make docker-image-fedora-coverity"

scripts/coverity-scan/run-coverity-scan if [ -z "$COVERITY_EMAIL" ]; then · line 265

Quoted 2 lines
scripts/coverity-scan/run-coverity-scan +2 -0
+    # TODO: how do you get 'docker build' to print the output of the
+    # commands it is running to its stdout? This would be useful for debug.

With make docker-image-*, you can just pass V=1.

Paolo

#10 lore raw

Re: [Qemu-devel] [PATCH 2/2] scripts/coverity-scan: Add Docker support

Quoted 8 lines · Paolo Bonzini
Quoted 4 lines

ENV COVERITY_TOOL_BASE=/coverity-tools
COPY run-coverity-scan run-coverity-scan
RUN --mount=type=secret,id=coverity.token,required ./run-coverity-scan --update-tools-only --tokenfile /run/secrets/coverity.token

If the tokenfile is not needed when updating the tools, you could also move the Dockerfile to tests/docker/dockerfiles/fedora-coverity.docker and just do "make docker-image-fedora-coverity"

It is needed when updating the tools, which is why I had to mess around with the secrets to pass it in. (Specifically, you have to pass the token to the Coverity web site to be able to download the tools zipfile.)

thanks
-- PMM