dcavalca / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
ff6046
From d84b1c62b9739e9c043a717aecec2da181eb9df7 Mon Sep 17 00:00:00 2001
ff6046
From: Frantisek Sumsal <fsumsal@redhat.com>
ff6046
Date: Sat, 23 Feb 2019 17:10:55 +0100
ff6046
Subject: [PATCH] travis: enable ASan and UBSan on RHEL8
ff6046
ff6046
Resolves: #1683319
ff6046
rhel-only
ff6046
---
ff6046
 .travis.yml               |  23 ++++++-
ff6046
 ci/travis-centos-rhel8.sh | 138 +++++++++++++++++++++++---------------
ff6046
 2 files changed, 105 insertions(+), 56 deletions(-)
ff6046
ff6046
diff --git a/.travis.yml b/.travis.yml
ff6046
index c5c9c345a9..67677bdf06 100644
ff6046
--- a/.travis.yml
ff6046
+++ b/.travis.yml
ff6046
@@ -8,8 +8,7 @@ env:
ff6046
 
ff6046
 jobs:
ff6046
     include:
ff6046
-        - stage: Build & test
ff6046
-          name: CentOS 7
ff6046
+        - name: CentOS 7
ff6046
           language: bash
ff6046
           env:
ff6046
               - CENTOS_RELEASE="centos7"
ff6046
@@ -28,3 +27,23 @@ jobs:
ff6046
               - set +e
ff6046
           after_script:
ff6046
               - $CI_ROOT/travis-centos-${RHEL_VERSION}.sh CLEANUP
ff6046
+
ff6046
+        - name: CentOS 7 (ASan+UBSan)
ff6046
+          language: bash
ff6046
+          env:
ff6046
+              - CENTOS_RELEASE="centos7"
ff6046
+              - CONT_NAME="systemd-centos-$CENTOS_RELEASE"
ff6046
+              - DOCKER_EXEC="docker exec -ti $CONT_NAME"
ff6046
+          before_install:
ff6046
+              - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
ff6046
+              - docker --version
ff6046
+          install:
ff6046
+              - if [ -f meson.build ]; then RHEL_VERSION=rhel8; else RHEL_VERSION=rhel7; fi
ff6046
+              - $CI_ROOT/travis-centos-${RHEL_VERSION}.sh SETUP
ff6046
+          script:
ff6046
+              - set -e
ff6046
+              # Build systemd
ff6046
+              - $CI_ROOT/travis-centos-${RHEL_VERSION}.sh RUN_ASAN
ff6046
+              - set +e
ff6046
+          after_script:
ff6046
+              - $CI_ROOT/travis-centos-${RHEL_VERSION}.sh CLEANUP
ff6046
diff --git a/ci/travis-centos-rhel8.sh b/ci/travis-centos-rhel8.sh
ff6046
index 1f72d984e0..c3d1018682 100755
ff6046
--- a/ci/travis-centos-rhel8.sh
ff6046
+++ b/ci/travis-centos-rhel8.sh
ff6046
@@ -19,6 +19,60 @@ ADDITIONAL_DEPS=(systemd-ci-environment libidn2-devel python-lxml python36 ninja
ff6046
 # Repo with additional depencencies to compile newer systemd on CentOS 7
ff6046
 COPR_REPO="https://copr.fedorainfracloud.org/coprs/mrc0mmand/systemd-centos-ci/repo/epel-7/mrc0mmand-systemd-centos-ci-epel-7.repo"
ff6046
 COPR_REPO_PATH="/etc/yum.repos.d/${COPR_REPO##*/}"
ff6046
+# RHEL8 options
ff6046
+CONFIGURE_OPTS=(
ff6046
+    -Dsysvinit-path=/etc/rc.d/init.d
ff6046
+    -Drc-local=/etc/rc.d/rc.local
ff6046
+    -Ddns-servers=''
ff6046
+    -Ddev-kvm-mode=0666
ff6046
+    -Dkmod=true
ff6046
+    -Dxkbcommon=true
ff6046
+    -Dblkid=true
ff6046
+    -Dseccomp=true
ff6046
+    -Dima=true
ff6046
+    -Dselinux=true
ff6046
+    -Dapparmor=false
ff6046
+    -Dpolkit=true
ff6046
+    -Dxz=true
ff6046
+    -Dzlib=true
ff6046
+    -Dbzip2=true
ff6046
+    -Dlz4=true
ff6046
+    -Dpam=true
ff6046
+    -Dacl=true
ff6046
+    -Dsmack=true
ff6046
+    -Dgcrypt=true
ff6046
+    -Daudit=true
ff6046
+    -Delfutils=true
ff6046
+    -Dlibcryptsetup=true
ff6046
+    -Delfutils=true
ff6046
+    -Dqrencode=false
ff6046
+    -Dgnutls=true
ff6046
+    -Dmicrohttpd=true
ff6046
+    -Dlibidn2=true
ff6046
+    -Dlibiptc=true
ff6046
+    -Dlibcurl=true
ff6046
+    -Defi=true
ff6046
+    -Dtpm=true
ff6046
+    -Dhwdb=true
ff6046
+    -Dsysusers=true
ff6046
+    -Ddefault-kill-user-processes=false
ff6046
+    -Dtests=unsafe
ff6046
+    -Dinstall-tests=true
ff6046
+    -Dtty-gid=5
ff6046
+    -Dusers-gid=100
ff6046
+    -Dnobody-user=nobody
ff6046
+    -Dnobody-group=nobody
ff6046
+    -Dsplit-usr=false
ff6046
+    -Dsplit-bin=true
ff6046
+    -Db_lto=false
ff6046
+    -Dnetworkd=false
ff6046
+    -Dtimesyncd=false
ff6046
+    -Ddefault-hierarchy=legacy
ff6046
+    # Custom options
ff6046
+    -Dslow-tests=true
ff6046
+    -Dtests=unsafe
ff6046
+    -Dinstall-tests=true
ff6046
+)
ff6046
 
ff6046
 function info() {
ff6046
     echo -e "\033[33;1m$1\033[0m"
ff6046
@@ -57,60 +111,6 @@ for phase in "${PHASES[@]}"; do
ff6046
         RUN)
ff6046
             info "Run phase"
ff6046
             # Build systemd
ff6046
-            CONFIGURE_OPTS=(
ff6046
-                # RHEL8 options
ff6046
-                -Dsysvinit-path=/etc/rc.d/init.d
ff6046
-                -Drc-local=/etc/rc.d/rc.local
ff6046
-                -Ddns-servers=''
ff6046
-                -Ddev-kvm-mode=0666
ff6046
-                -Dkmod=true
ff6046
-                -Dxkbcommon=true
ff6046
-                -Dblkid=true
ff6046
-                -Dseccomp=true
ff6046
-                -Dima=true
ff6046
-                -Dselinux=true
ff6046
-                -Dapparmor=false
ff6046
-                -Dpolkit=true
ff6046
-                -Dxz=true
ff6046
-                -Dzlib=true
ff6046
-                -Dbzip2=true
ff6046
-                -Dlz4=true
ff6046
-                -Dpam=true
ff6046
-                -Dacl=true
ff6046
-                -Dsmack=true
ff6046
-                -Dgcrypt=true
ff6046
-                -Daudit=true
ff6046
-                -Delfutils=true
ff6046
-                -Dlibcryptsetup=true
ff6046
-                -Delfutils=true
ff6046
-                -Dqrencode=false
ff6046
-                -Dgnutls=true
ff6046
-                -Dmicrohttpd=true
ff6046
-                -Dlibidn2=true
ff6046
-                -Dlibiptc=true
ff6046
-                -Dlibcurl=true
ff6046
-                -Defi=true
ff6046
-                -Dtpm=true
ff6046
-                -Dhwdb=true
ff6046
-                -Dsysusers=true
ff6046
-                -Ddefault-kill-user-processes=false
ff6046
-                -Dtests=unsafe
ff6046
-                -Dinstall-tests=true
ff6046
-                -Dtty-gid=5
ff6046
-                -Dusers-gid=100
ff6046
-                -Dnobody-user=nobody
ff6046
-                -Dnobody-group=nobody
ff6046
-                -Dsplit-usr=false
ff6046
-                -Dsplit-bin=true
ff6046
-                -Db_lto=false
ff6046
-                -Dnetworkd=false
ff6046
-                -Dtimesyncd=false
ff6046
-                -Ddefault-hierarchy=legacy
ff6046
-                # Custom options
ff6046
-                -Dslow-tests=true
ff6046
-                -Dtests=unsafe
ff6046
-                -Dinstall-tests=true
ff6046
-            )
ff6046
             docker exec -it -e CFLAGS='-g -O0 -ftrapv' $CONT_NAME meson build "${CONFIGURE_OPTS[@]}"
ff6046
             $DOCKER_EXEC ninja -v -C build
ff6046
             # Let's install the new systemd and "reboot" the container to avoid
ff6046
@@ -122,6 +122,36 @@ for phase in "${PHASES[@]}"; do
ff6046
             echo -ne "#!/usr/bin/perl\nexit(0);\n" > "test/udev-test.pl"
ff6046
             $DOCKER_EXEC ninja -C build test
ff6046
             ;;
ff6046
+        RUN_ASAN|RUN_CLANG_ASAN)
ff6046
+            # Let's install newer gcc for proper ASan/UBSan support
ff6046
+            $DOCKER_EXEC yum -y install centos-release-scl
ff6046
+            $DOCKER_EXEC yum -y install devtoolset-8 devtoolset-8-libasan-devel libasan5 devtoolset-8-libubsan-devel libubsan1
ff6046
+            $DOCKER_EXEC bash -c "echo 'source scl_source enable devtoolset-8' >> /root/.bashrc"
ff6046
+            # Note to my future frustrated self: docker exec runs the given command
ff6046
+            # as sh -c 'command' - which means both .bash_profile and .bashrc will
ff6046
+            # be ignored. That's because .bash_profile is sourced for LOGIN shells (i.e.
ff6046
+            # sh -l), whereas .bashrc is sourced for NON-LOGIN INTERACTIVE shells
ff6046
+            # (i.e. sh -i).
ff6046
+            # As the default docker exec command lacks either of those options,
ff6046
+            # we need to use a wrapper command which runs the wanted command
ff6046
+            # under an explicit bash -i, so the SCL source above works properly.
ff6046
+            docker exec -it $CONT_NAME bash -ic 'gcc --version'
ff6046
+
ff6046
+            if [[ "$phase" = "RUN_CLANG_ASAN" ]]; then
ff6046
+                ENV_VARS="-e CC=clang -e CXX=clang++"
ff6046
+                MESON_ARGS="-Db_lundef=false" # See https://github.com/mesonbuild/meson/issues/764
ff6046
+            fi
ff6046
+            docker exec $ENV_VARS -it $CONT_NAME bash -ic "meson build --werror -Dtests=unsafe -Db_sanitize=address,undefined $MESON_ARGS ${CONFIGURE_OPTS[@]}"
ff6046
+            docker exec -it $CONT_NAME bash -ic 'ninja -v -C build'
ff6046
+
ff6046
+            # Never remove halt_on_error from UBSAN_OPTIONS. See https://github.com/systemd/systemd/commit/2614d83aa06592aedb.
ff6046
+            travis_wait docker exec --interactive=false \
ff6046
+                -e UBSAN_OPTIONS=print_stacktrace=1:print_summary=1:halt_on_error=1 \
ff6046
+                -e ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1 \
ff6046
+                -e "TRAVIS=$TRAVIS" \
ff6046
+                -t $CONT_NAME \
ff6046
+                bash -ic 'meson test --timeout-multiplier=3 -C ./build/ --print-errorlogs'
ff6046
+            ;;
ff6046
         CLEANUP)
ff6046
             info "Cleanup phase"
ff6046
             docker stop $CONT_NAME