anitazha / rpms / systemd

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